Tizen 2.1 base
authorJinkun Jang <jinkun.jang@samsung.com>
Tue, 12 Mar 2013 17:05:53 +0000 (02:05 +0900)
committerJinkun Jang <jinkun.jang@samsung.com>
Tue, 12 Mar 2013 17:05:53 +0000 (02:05 +0900)
1222 files changed:
AUTHORS [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0755]
LICENSE [new file with mode: 0755]
LICENSE.APLv2 [new file with mode: 0644]
NOTICE [new file with mode: 0644]
clean.sh [new file with mode: 0755]
config.dtd [new file with mode: 0644]
debian_DEPRECATED/changelog [new file with mode: 0644]
debian_DEPRECATED/compat [new file with mode: 0755]
debian_DEPRECATED/control [new file with mode: 0755]
debian_DEPRECATED/rules [new file with mode: 0755]
debian_DEPRECATED/wrt-plugins-tizen.install.in [new file with mode: 0755]
packaging/wrt-plugins-tizen.spec [new file with mode: 0755]
src/CMakeLists.txt [new file with mode: 0644]
src/platform/API/Application/ApplicationCert.cpp [new file with mode: 0644]
src/platform/API/Application/ApplicationCert.h [new file with mode: 0644]
src/platform/API/Application/ApplicationContext.cpp [new file with mode: 0755]
src/platform/API/Application/ApplicationContext.h [new file with mode: 0755]
src/platform/API/Application/ApplicationControl.cpp [new file with mode: 0755]
src/platform/API/Application/ApplicationControl.h [new file with mode: 0755]
src/platform/API/Application/ApplicationControlData.cpp [new file with mode: 0755]
src/platform/API/Application/ApplicationControlData.h [new file with mode: 0755]
src/platform/API/Application/ApplicationFactory.cpp [new file with mode: 0755]
src/platform/API/Application/ApplicationFactory.h [new file with mode: 0755]
src/platform/API/Application/ApplicationInformation.cpp [new file with mode: 0755]
src/platform/API/Application/ApplicationInformation.h [new file with mode: 0755]
src/platform/API/Application/ApplicationInstallInfo.cpp [new file with mode: 0755]
src/platform/API/Application/ApplicationInstallInfo.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationAddAppInfoEventListener.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationAppInfoEventListener.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationFindAppControl.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationGetAppCerts.h [new file with mode: 0644]
src/platform/API/Application/EventApplicationGetAppContext.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationGetAppInfo.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationGetAppsContext.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationGetAppsInfo.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationGetCurrApp.h [new file with mode: 0644]
src/platform/API/Application/EventApplicationGetRequestedAppControl.h [new file with mode: 0644]
src/platform/API/Application/EventApplicationInstall.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationKill.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationLaunch.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationLaunchAppControl.h [new file with mode: 0755]
src/platform/API/Application/EventApplicationRemoveAppInfoEventListener.h [new file with mode: 0755]
src/platform/API/Application/IApplicationManager.cpp [new file with mode: 0644]
src/platform/API/Application/IApplicationManager.h [new file with mode: 0644]
src/platform/API/Application/RequestedApplicationControl.cpp [new file with mode: 0644]
src/platform/API/Application/RequestedApplicationControl.h [new file with mode: 0644]
src/platform/API/Application/config.cmake [new file with mode: 0755]
src/platform/API/Bluetooth/BTDevice.h [new file with mode: 0644]
src/platform/API/Bluetooth/BluetoothFactory.cpp [new file with mode: 0644]
src/platform/API/Bluetooth/BluetoothFactory.h [new file with mode: 0644]
src/platform/API/Bluetooth/BluetoothProperty.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTConnectToServiceByUUID.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTCreateDestroyBonding.cpp [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTCreateDestroyBonding.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTGetAdapter.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTGetDevice.cpp [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTGetDevice.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTGetKnownDevices.cpp [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTGetKnownDevices.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTOnDiscoveryDevices.cpp [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTOnDiscoveryDevices.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTRegisterRFCOMM.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTServiceOnConnect.cpp [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTServiceOnConnect.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTSetName.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTSetPowered.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTSetVisible.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTSocketNotification.cpp [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTSocketNotification.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTStopDiscovery.h [new file with mode: 0644]
src/platform/API/Bluetooth/EventBTUnregisterRFCOMM.h [new file with mode: 0644]
src/platform/API/Bluetooth/IBluetoothAdapterManager.cpp [new file with mode: 0644]
src/platform/API/Bluetooth/IBluetoothAdapterManager.h [new file with mode: 0644]
src/platform/API/Bluetooth/IBluetoothDeviceManager.cpp [new file with mode: 0644]
src/platform/API/Bluetooth/IBluetoothDeviceManager.h [new file with mode: 0644]
src/platform/API/Bluetooth/IBluetoothServiceHandlerManager.cpp [new file with mode: 0644]
src/platform/API/Bluetooth/IBluetoothServiceHandlerManager.h [new file with mode: 0644]
src/platform/API/Bluetooth/IBluetoothSocketManager.cpp [new file with mode: 0644]
src/platform/API/Bluetooth/IBluetoothSocketManager.h [new file with mode: 0644]
src/platform/API/Bluetooth/config.cmake [new file with mode: 0644]
src/platform/API/Calendar/CalendarEvent.cpp [new file with mode: 0755]
src/platform/API/Calendar/CalendarEvent.h [new file with mode: 0755]
src/platform/API/Calendar/CalendarFactory.cpp [new file with mode: 0755]
src/platform/API/Calendar/CalendarFactory.h [new file with mode: 0755]
src/platform/API/Calendar/EventAlarm.cpp [new file with mode: 0755]
src/platform/API/Calendar/EventAlarm.h [new file with mode: 0755]
src/platform/API/Calendar/EventAttendee.cpp [new file with mode: 0755]
src/platform/API/Calendar/EventAttendee.h [new file with mode: 0755]
src/platform/API/Calendar/EventId.cpp [new file with mode: 0755]
src/platform/API/Calendar/EventId.h [new file with mode: 0755]
src/platform/API/Calendar/EventRecurrenceRule.cpp [new file with mode: 0755]
src/platform/API/Calendar/EventRecurrenceRule.h [new file with mode: 0755]
src/platform/API/Calendar/ICalendar.cpp [new file with mode: 0755]
src/platform/API/Calendar/ICalendar.h [new file with mode: 0755]
src/platform/API/Calendar/ICalendarManager.cpp [new file with mode: 0755]
src/platform/API/Calendar/ICalendarManager.h [new file with mode: 0755]
src/platform/API/Calendar/IEventAddEvent.h [new file with mode: 0755]
src/platform/API/Calendar/IEventAddEvents.h [new file with mode: 0755]
src/platform/API/Calendar/IEventClearWatch.h [new file with mode: 0755]
src/platform/API/Calendar/IEventCreateEventFromString.h [new file with mode: 0755]
src/platform/API/Calendar/IEventDeleteEvent.h [new file with mode: 0755]
src/platform/API/Calendar/IEventDeleteEvents.h [new file with mode: 0755]
src/platform/API/Calendar/IEventExpandEventRecurrence.h [new file with mode: 0755]
src/platform/API/Calendar/IEventExportEventToString.h [new file with mode: 0755]
src/platform/API/Calendar/IEventFindEvents.h [new file with mode: 0755]
src/platform/API/Calendar/IEventGet.h [new file with mode: 0755]
src/platform/API/Calendar/IEventGetCalendar.h [new file with mode: 0755]
src/platform/API/Calendar/IEventGetCalendars.h [new file with mode: 0755]
src/platform/API/Calendar/IEventGetDefaultCalendar.h [new file with mode: 0755]
src/platform/API/Calendar/IEventUpdateEvent.h [new file with mode: 0755]
src/platform/API/Calendar/IEventUpdateEvents.h [new file with mode: 0755]
src/platform/API/Calendar/IEventWatchChanges.h [new file with mode: 0755]
src/platform/API/Calendar/OnEventsChanged.h [new file with mode: 0755]
src/platform/API/Calendar/config.cmake [new file with mode: 0755]
src/platform/API/Callhistory/CallHistoryDefine.h [new file with mode: 0755]
src/platform/API/Callhistory/CallHistoryEntryProperties.cpp [new file with mode: 0755]
src/platform/API/Callhistory/CallHistoryEntryProperties.h [new file with mode: 0755]
src/platform/API/Callhistory/CallHistoryFactory.cpp [new file with mode: 0755]
src/platform/API/Callhistory/CallHistoryFactory.h [new file with mode: 0755]
src/platform/API/Callhistory/EventCallHistory.h [new file with mode: 0755]
src/platform/API/Callhistory/EventCallHistoryListener.cpp [new file with mode: 0755]
src/platform/API/Callhistory/EventCallHistoryListener.h [new file with mode: 0755]
src/platform/API/Callhistory/EventCallHistoryTemplate.h [new file with mode: 0755]
src/platform/API/Callhistory/EventFindCallHistory.cpp [new file with mode: 0755]
src/platform/API/Callhistory/EventFindCallHistory.h [new file with mode: 0755]
src/platform/API/Callhistory/EventRemoveAll.h [new file with mode: 0755]
src/platform/API/Callhistory/EventRemoveBatch.h [new file with mode: 0755]
src/platform/API/Callhistory/ICallHistory.cpp [new file with mode: 0755]
src/platform/API/Callhistory/ICallHistory.h [new file with mode: 0755]
src/platform/API/Callhistory/ICallHistoryEntry.cpp [new file with mode: 0755]
src/platform/API/Callhistory/ICallHistoryEntry.h [new file with mode: 0755]
src/platform/API/Callhistory/RemoteParty.h [new file with mode: 0755]
src/platform/API/Callhistory/config.cmake [new file with mode: 0755]
src/platform/API/Contact/ContactAddress.cpp [new file with mode: 0755]
src/platform/API/Contact/ContactAddress.h [new file with mode: 0755]
src/platform/API/Contact/ContactAnniversary.cpp [new file with mode: 0755]
src/platform/API/Contact/ContactAnniversary.h [new file with mode: 0755]
src/platform/API/Contact/ContactEmailAddress.cpp [new file with mode: 0755]
src/platform/API/Contact/ContactEmailAddress.h [new file with mode: 0755]
src/platform/API/Contact/ContactFactory.cpp [new file with mode: 0755]
src/platform/API/Contact/ContactFactory.h [new file with mode: 0755]
src/platform/API/Contact/ContactGroup.cpp [new file with mode: 0755]
src/platform/API/Contact/ContactGroup.h [new file with mode: 0755]
src/platform/API/Contact/ContactName.cpp [new file with mode: 0755]
src/platform/API/Contact/ContactName.h [new file with mode: 0755]
src/platform/API/Contact/ContactOrganization.cpp [new file with mode: 0755]
src/platform/API/Contact/ContactOrganization.h [new file with mode: 0755]
src/platform/API/Contact/ContactPhoneNumber.cpp [new file with mode: 0755]
src/platform/API/Contact/ContactPhoneNumber.h [new file with mode: 0755]
src/platform/API/Contact/ContactRef.cpp [new file with mode: 0755]
src/platform/API/Contact/ContactRef.h [new file with mode: 0755]
src/platform/API/Contact/ContactTypes.h [new file with mode: 0755]
src/platform/API/Contact/ContactWebSite.cpp [new file with mode: 0755]
src/platform/API/Contact/ContactWebSite.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookAdd.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookAddBatch.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookAddChangeListener.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookAddGroup.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookChangeListener.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookFind.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookGet.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookGetGroup.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookGetGroups.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookRemove.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookRemoveBatch.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookRemoveChangeListener.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookRemoveGroup.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookUpdate.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookUpdateBatch.h [new file with mode: 0755]
src/platform/API/Contact/EventAddressBookUpdateGroup.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerAddChangeListener.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerChangeListener.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerFind.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerGet.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerGetAddressBook.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerGetAddressBooks.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerGetDefaultAddressBook.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerRemove.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerRemoveBatch.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerRemoveChangeListener.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerUpdate.h [new file with mode: 0755]
src/platform/API/Contact/EventContactManagerUpdateBatch.h [new file with mode: 0755]
src/platform/API/Contact/EventPersonLink.h [new file with mode: 0755]
src/platform/API/Contact/EventPersonUnlink.h [new file with mode: 0755]
src/platform/API/Contact/IAddressBook.cpp [new file with mode: 0755]
src/platform/API/Contact/IAddressBook.h [new file with mode: 0755]
src/platform/API/Contact/IContact.cpp [new file with mode: 0755]
src/platform/API/Contact/IContact.h [new file with mode: 0755]
src/platform/API/Contact/IContactEventPrivateData.h [new file with mode: 0755]
src/platform/API/Contact/IContactManager.cpp [new file with mode: 0755]
src/platform/API/Contact/IContactManager.h [new file with mode: 0755]
src/platform/API/Contact/IPerson.cpp [new file with mode: 0755]
src/platform/API/Contact/IPerson.h [new file with mode: 0755]
src/platform/API/Contact/config.cmake [new file with mode: 0755]
src/platform/API/Content/IEventBrowseFolder.h [new file with mode: 0755]
src/platform/API/Content/IEventFindFolder.h [new file with mode: 0755]
src/platform/API/Content/IEventFindMedia.h [new file with mode: 0755]
src/platform/API/Content/IEventUpdateMedia.h [new file with mode: 0755]
src/platform/API/Content/IEventUpdateMediaItems.h [new file with mode: 0755]
src/platform/API/Content/IMediacontentManager.cpp [new file with mode: 0755]
src/platform/API/Content/IMediacontentManager.h [new file with mode: 0755]
src/platform/API/Content/MediacontentAudio.cpp [new file with mode: 0755]
src/platform/API/Content/MediacontentAudio.h [new file with mode: 0755]
src/platform/API/Content/MediacontentFactory.cpp [new file with mode: 0755]
src/platform/API/Content/MediacontentFactory.h [new file with mode: 0755]
src/platform/API/Content/MediacontentFolder.cpp [new file with mode: 0755]
src/platform/API/Content/MediacontentFolder.h [new file with mode: 0755]
src/platform/API/Content/MediacontentImage.cpp [new file with mode: 0755]
src/platform/API/Content/MediacontentImage.h [new file with mode: 0755]
src/platform/API/Content/MediacontentLyrics.cpp [new file with mode: 0755]
src/platform/API/Content/MediacontentLyrics.h [new file with mode: 0755]
src/platform/API/Content/MediacontentMedia.cpp [new file with mode: 0755]
src/platform/API/Content/MediacontentMedia.h [new file with mode: 0755]
src/platform/API/Content/MediacontentVideo.cpp [new file with mode: 0755]
src/platform/API/Content/MediacontentVideo.h [new file with mode: 0755]
src/platform/API/Content/config.cmake [new file with mode: 0755]
src/platform/API/Download/DownloadRequest.cpp [new file with mode: 0644]
src/platform/API/Download/DownloadRequest.h [new file with mode: 0644]
src/platform/API/Download/IDownloadManager.cpp [new file with mode: 0755]
src/platform/API/Download/IDownloadManager.h [new file with mode: 0755]
src/platform/API/Download/IEventCancelDownload.h [new file with mode: 0644]
src/platform/API/Download/IEventGetDownloadRequest.h [new file with mode: 0644]
src/platform/API/Download/IEventGetMIMEType.h [new file with mode: 0644]
src/platform/API/Download/IEventGetState.h [new file with mode: 0755]
src/platform/API/Download/IEventPauseDownload.h [new file with mode: 0755]
src/platform/API/Download/IEventResumeDownload.h [new file with mode: 0755]
src/platform/API/Download/IEventSetListener.h [new file with mode: 0755]
src/platform/API/Download/IEventStartDownload.h [new file with mode: 0755]
src/platform/API/Download/OnDownloadStateChanged.h [new file with mode: 0755]
src/platform/API/Download/config.cmake [new file with mode: 0755]
src/platform/API/Filesystem/Enums.h [new file with mode: 0755]
src/platform/API/Filesystem/EventCopy.cpp [new file with mode: 0755]
src/platform/API/Filesystem/EventCopy.h [new file with mode: 0755]
src/platform/API/Filesystem/EventCreate.cpp [new file with mode: 0755]
src/platform/API/Filesystem/EventCreate.h [new file with mode: 0755]
src/platform/API/Filesystem/EventFind.cpp [new file with mode: 0755]
src/platform/API/Filesystem/EventFind.h [new file with mode: 0755]
src/platform/API/Filesystem/EventGetStorage.cpp [new file with mode: 0755]
src/platform/API/Filesystem/EventGetStorage.h [new file with mode: 0755]
src/platform/API/Filesystem/EventListNodes.cpp [new file with mode: 0755]
src/platform/API/Filesystem/EventListNodes.h [new file with mode: 0755]
src/platform/API/Filesystem/EventListStorages.cpp [new file with mode: 0755]
src/platform/API/Filesystem/EventListStorages.h [new file with mode: 0755]
src/platform/API/Filesystem/EventMove.cpp [new file with mode: 0755]
src/platform/API/Filesystem/EventMove.h [new file with mode: 0755]
src/platform/API/Filesystem/EventOpen.cpp [new file with mode: 0755]
src/platform/API/Filesystem/EventOpen.h [new file with mode: 0755]
src/platform/API/Filesystem/EventReadText.cpp [new file with mode: 0755]
src/platform/API/Filesystem/EventReadText.h [new file with mode: 0755]
src/platform/API/Filesystem/EventRemove.cpp [new file with mode: 0755]
src/platform/API/Filesystem/EventRemove.h [new file with mode: 0755]
src/platform/API/Filesystem/EventResolve.cpp [new file with mode: 0755]
src/platform/API/Filesystem/EventResolve.h [new file with mode: 0755]
src/platform/API/Filesystem/EventStorageStateChanged.h [new file with mode: 0755]
src/platform/API/Filesystem/EventStoragestateChanged.cpp [new file with mode: 0755]
src/platform/API/Filesystem/IManager.cpp [new file with mode: 0755]
src/platform/API/Filesystem/IManager.h [new file with mode: 0755]
src/platform/API/Filesystem/INode.cpp [new file with mode: 0755]
src/platform/API/Filesystem/INode.h [new file with mode: 0755]
src/platform/API/Filesystem/INodeTypes.h [new file with mode: 0755]
src/platform/API/Filesystem/IPath.cpp [new file with mode: 0755]
src/platform/API/Filesystem/IPath.h [new file with mode: 0755]
src/platform/API/Filesystem/IStream.cpp [new file with mode: 0755]
src/platform/API/Filesystem/IStream.h [new file with mode: 0755]
src/platform/API/Filesystem/NodeFilter.cpp [new file with mode: 0755]
src/platform/API/Filesystem/NodeFilter.h [new file with mode: 0755]
src/platform/API/Filesystem/PathUtils.cpp [new file with mode: 0755]
src/platform/API/Filesystem/PathUtils.h [new file with mode: 0755]
src/platform/API/Filesystem/StorageProperties.cpp [new file with mode: 0755]
src/platform/API/Filesystem/StorageProperties.h [new file with mode: 0755]
src/platform/API/Filesystem/config.cmake [new file with mode: 0755]
src/platform/API/Filter/AnyType.cpp [new file with mode: 0755]
src/platform/API/Filter/AnyType.h [new file with mode: 0755]
src/platform/API/Filter/AttributeFilter.cpp [new file with mode: 0644]
src/platform/API/Filter/AttributeFilter.h [new file with mode: 0644]
src/platform/API/Filter/AttributeRangeFilter.cpp [new file with mode: 0644]
src/platform/API/Filter/AttributeRangeFilter.h [new file with mode: 0644]
src/platform/API/Filter/CompositeFilter.cpp [new file with mode: 0644]
src/platform/API/Filter/CompositeFilter.h [new file with mode: 0644]
src/platform/API/Filter/FilterFactory.cpp [new file with mode: 0644]
src/platform/API/Filter/FilterFactory.h [new file with mode: 0644]
src/platform/API/Filter/FilterTypes.h [new file with mode: 0644]
src/platform/API/Filter/FilterValidator.cpp [new file with mode: 0644]
src/platform/API/Filter/FilterValidator.h [new file with mode: 0644]
src/platform/API/Filter/IFilter.cpp [new file with mode: 0644]
src/platform/API/Filter/IFilter.h [new file with mode: 0644]
src/platform/API/Filter/IFilterVisitor.cpp [new file with mode: 0644]
src/platform/API/Filter/IFilterVisitor.h [new file with mode: 0644]
src/platform/API/Filter/SimpleCoordinates.cpp [new file with mode: 0644]
src/platform/API/Filter/SimpleCoordinates.h [new file with mode: 0644]
src/platform/API/Filter/SortMode.cpp [new file with mode: 0644]
src/platform/API/Filter/SortMode.h [new file with mode: 0644]
src/platform/API/Filter/config.cmake [new file with mode: 0755]
src/platform/API/Messaging/AttachmentFactory.cpp [new file with mode: 0755]
src/platform/API/Messaging/AttachmentFactory.h [new file with mode: 0755]
src/platform/API/Messaging/Attachments.cpp [new file with mode: 0755]
src/platform/API/Messaging/Attachments.h [new file with mode: 0755]
src/platform/API/Messaging/BccRecipient.cpp [new file with mode: 0755]
src/platform/API/Messaging/BccRecipient.h [new file with mode: 0755]
src/platform/API/Messaging/Body.cpp [new file with mode: 0755]
src/platform/API/Messaging/Body.h [new file with mode: 0755]
src/platform/API/Messaging/CallbackNumber.cpp [new file with mode: 0755]
src/platform/API/Messaging/CallbackNumber.h [new file with mode: 0755]
src/platform/API/Messaging/CcRecipient.cpp [new file with mode: 0755]
src/platform/API/Messaging/CcRecipient.h [new file with mode: 0755]
src/platform/API/Messaging/ConversationFilterValidator.cpp [new file with mode: 0755]
src/platform/API/Messaging/ConversationFilterValidator.h [new file with mode: 0755]
src/platform/API/Messaging/ConversationFilterValidatorFactory.cpp [new file with mode: 0755]
src/platform/API/Messaging/ConversationFilterValidatorFactory.h [new file with mode: 0755]
src/platform/API/Messaging/EmailAccountInfo.cpp [new file with mode: 0755]
src/platform/API/Messaging/EmailAccountInfo.h [new file with mode: 0755]
src/platform/API/Messaging/EmitterConversationReceived.cpp [new file with mode: 0755]
src/platform/API/Messaging/EmitterConversationReceived.h [new file with mode: 0755]
src/platform/API/Messaging/EmitterFolderReceived.cpp [new file with mode: 0755]
src/platform/API/Messaging/EmitterFolderReceived.h [new file with mode: 0755]
src/platform/API/Messaging/EmitterMessageReceived.cpp [new file with mode: 0755]
src/platform/API/Messaging/EmitterMessageReceived.h [new file with mode: 0755]
src/platform/API/Messaging/EventAddDraftMessage.h [new file with mode: 0755]
src/platform/API/Messaging/EventDeleteConversations.h [new file with mode: 0755]
src/platform/API/Messaging/EventDeleteMessage.h [new file with mode: 0755]
src/platform/API/Messaging/EventDeleteMessages.h [new file with mode: 0755]
src/platform/API/Messaging/EventGetConversationId.h [new file with mode: 0755]
src/platform/API/Messaging/EventGetMessagingService.h [new file with mode: 0755]
src/platform/API/Messaging/EventMessageReceived.cpp [new file with mode: 0755]
src/platform/API/Messaging/EventMessageReceived.h [new file with mode: 0755]
src/platform/API/Messaging/EventMessagingService.h [new file with mode: 0755]
src/platform/API/Messaging/EventMessagingStorage.h [new file with mode: 0755]
src/platform/API/Messaging/EventOnSendingFailed.h [new file with mode: 0755]
src/platform/API/Messaging/EventQueryConversations.h [new file with mode: 0755]
src/platform/API/Messaging/EventQueryFolders.h [new file with mode: 0755]
src/platform/API/Messaging/EventQueryMessages.h [new file with mode: 0755]
src/platform/API/Messaging/EventSendMessage.h [new file with mode: 0755]
src/platform/API/Messaging/EventUpdateMessage.h [new file with mode: 0755]
src/platform/API/Messaging/EventUpdateMessages.h [new file with mode: 0755]
src/platform/API/Messaging/FolderFilterValidator.cpp [new file with mode: 0755]
src/platform/API/Messaging/FolderFilterValidator.h [new file with mode: 0755]
src/platform/API/Messaging/FolderFilterValidatorFactory.cpp [new file with mode: 0755]
src/platform/API/Messaging/FolderFilterValidatorFactory.h [new file with mode: 0755]
src/platform/API/Messaging/From.cpp [new file with mode: 0755]
src/platform/API/Messaging/From.h [new file with mode: 0755]
src/platform/API/Messaging/IAttachment.cpp [new file with mode: 0755]
src/platform/API/Messaging/IAttachment.h [new file with mode: 0755]
src/platform/API/Messaging/IBinarySms.cpp [new file with mode: 0755]
src/platform/API/Messaging/IBinarySms.h [new file with mode: 0755]
src/platform/API/Messaging/IConversation.h [new file with mode: 0755]
src/platform/API/Messaging/IEmail.cpp [new file with mode: 0755]
src/platform/API/Messaging/IEmail.h [new file with mode: 0755]
src/platform/API/Messaging/IEmailAccount.cpp [new file with mode: 0755]
src/platform/API/Messaging/IEmailAccount.h [new file with mode: 0755]
src/platform/API/Messaging/IEmptyMessage.cpp [new file with mode: 0755]
src/platform/API/Messaging/IEmptyMessage.h [new file with mode: 0755]
src/platform/API/Messaging/IMessage.cpp [new file with mode: 0755]
src/platform/API/Messaging/IMessage.h [new file with mode: 0755]
src/platform/API/Messaging/IMessageFolder.h [new file with mode: 0755]
src/platform/API/Messaging/IMessaging.cpp [new file with mode: 0755]
src/platform/API/Messaging/IMessaging.h [new file with mode: 0755]
src/platform/API/Messaging/IMessagingService.cpp [new file with mode: 0755]
src/platform/API/Messaging/IMessagingService.h [new file with mode: 0755]
src/platform/API/Messaging/IMessagingServiceManager.cpp [new file with mode: 0755]
src/platform/API/Messaging/IMessagingServiceManager.h [new file with mode: 0755]
src/platform/API/Messaging/IMessagingTypes.h [new file with mode: 0755]
src/platform/API/Messaging/IMms.cpp [new file with mode: 0755]
src/platform/API/Messaging/IMms.h [new file with mode: 0755]
src/platform/API/Messaging/IMmsSlide.h [new file with mode: 0755]
src/platform/API/Messaging/IMmsSlideProperties.h [new file with mode: 0755]
src/platform/API/Messaging/IMmsSlides.h [new file with mode: 0755]
src/platform/API/Messaging/ISms.cpp [new file with mode: 0755]
src/platform/API/Messaging/ISms.h [new file with mode: 0755]
src/platform/API/Messaging/MessageEventPrivateData.h [new file with mode: 0755]
src/platform/API/Messaging/MessageFactory.cpp [new file with mode: 0755]
src/platform/API/Messaging/MessageFactory.h [new file with mode: 0755]
src/platform/API/Messaging/MessageFilterValidator.cpp [new file with mode: 0755]
src/platform/API/Messaging/MessageFilterValidator.h [new file with mode: 0755]
src/platform/API/Messaging/MessageFilterValidatorFactory.cpp [new file with mode: 0755]
src/platform/API/Messaging/MessageFilterValidatorFactory.h [new file with mode: 0755]
src/platform/API/Messaging/MessagePriority.cpp [new file with mode: 0755]
src/platform/API/Messaging/MessagePriority.h [new file with mode: 0755]
src/platform/API/Messaging/MessageProperties.h [new file with mode: 0755]
src/platform/API/Messaging/MessageStorageFactory.cpp [new file with mode: 0755]
src/platform/API/Messaging/MessageStorageFactory.h [new file with mode: 0755]
src/platform/API/Messaging/MessagingFactory.cpp [new file with mode: 0755]
src/platform/API/Messaging/MessagingFactory.h [new file with mode: 0755]
src/platform/API/Messaging/MmsSlide.cpp [new file with mode: 0755]
src/platform/API/Messaging/MmsSlide.h [new file with mode: 0755]
src/platform/API/Messaging/MmsSlideProperty.cpp [new file with mode: 0755]
src/platform/API/Messaging/MmsSlideProperty.h [new file with mode: 0755]
src/platform/API/Messaging/MmsSlides.cpp [new file with mode: 0755]
src/platform/API/Messaging/MmsSlides.h [new file with mode: 0755]
src/platform/API/Messaging/Recipient.cpp [new file with mode: 0755]
src/platform/API/Messaging/Recipient.h [new file with mode: 0755]
src/platform/API/Messaging/ReqReceiverMessage.cpp [new file with mode: 0755]
src/platform/API/Messaging/ReqReceiverMessage.h [new file with mode: 0755]
src/platform/API/Messaging/SourceAddress.cpp [new file with mode: 0755]
src/platform/API/Messaging/SourceAddress.h [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesConversationFilterValidator.cpp [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesConversationFilterValidator.h [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesConversationFilterValidatorFactory.cpp [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesConversationFilterValidatorFactory.h [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesConversationGenerator.cpp [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesConversationGenerator.h [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesFolderFilterValidator.cpp [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesFolderFilterValidator.h [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesFolderFilterValidatorFactory.cpp [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesFolderFilterValidatorFactory.h [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesFolderGenerator.cpp [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesFolderGenerator.h [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesMessageFilterValidator.cpp [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesMessageFilterValidator.h [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesMessageFilterValidatorFactory.cpp [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesMessageFilterValidatorFactory.h [new file with mode: 0755]
src/platform/API/Messaging/StorageChangesMessageGenerator.cpp [new file with mode: 0644]
src/platform/API/Messaging/StorageChangesMessageGenerator.h [new file with mode: 0755]
src/platform/API/Messaging/Subject.cpp [new file with mode: 0755]
src/platform/API/Messaging/Subject.h [new file with mode: 0755]
src/platform/API/Messaging/ToRecipient.cpp [new file with mode: 0644]
src/platform/API/Messaging/ToRecipient.h [new file with mode: 0644]
src/platform/API/Messaging/ValidityPeriodHours.cpp [new file with mode: 0755]
src/platform/API/Messaging/ValidityPeriodHours.h [new file with mode: 0755]
src/platform/API/Messaging/VirtualMessage.cpp [new file with mode: 0755]
src/platform/API/Messaging/VirtualMessage.h [new file with mode: 0755]
src/platform/API/Messaging/config.cmake [new file with mode: 0755]
src/platform/API/Messaging/log.h [new file with mode: 0755]
src/platform/API/NFC/EventNFC.h [new file with mode: 0755]
src/platform/API/NFC/EventNFCChanged.h [new file with mode: 0755]
src/platform/API/NFC/EventTagAction.h [new file with mode: 0755]
src/platform/API/NFC/EventTargetAction.h [new file with mode: 0755]
src/platform/API/NFC/INFCAdapter.cpp [new file with mode: 0755]
src/platform/API/NFC/INFCAdapter.h [new file with mode: 0755]
src/platform/API/NFC/INFCTag.cpp [new file with mode: 0755]
src/platform/API/NFC/INFCTag.h [new file with mode: 0755]
src/platform/API/NFC/INFCTarget.cpp [new file with mode: 0755]
src/platform/API/NFC/INFCTarget.h [new file with mode: 0755]
src/platform/API/NFC/INdefMessage.h [new file with mode: 0755]
src/platform/API/NFC/INdefRecord.h [new file with mode: 0755]
src/platform/API/NFC/NFCFactory.cpp [new file with mode: 0755]
src/platform/API/NFC/NFCFactory.h [new file with mode: 0755]
src/platform/API/NFC/NFCTagProperties.h [new file with mode: 0755]
src/platform/API/NFC/NdefRecordProperties.h [new file with mode: 0755]
src/platform/API/NFC/TagFilter.cpp [new file with mode: 0755]
src/platform/API/NFC/TagFilter.h [new file with mode: 0755]
src/platform/API/NFC/config.cmake [new file with mode: 0755]
src/platform/API/NetworkBearerSelection/EventNetworkBearerRelease.h [new file with mode: 0755]
src/platform/API/NetworkBearerSelection/EventNetworkBearerSelection.h [new file with mode: 0755]
src/platform/API/NetworkBearerSelection/INetworkBearerSelection.cpp [new file with mode: 0755]
src/platform/API/NetworkBearerSelection/INetworkBearerSelection.h [new file with mode: 0755]
src/platform/API/NetworkBearerSelection/NetworkBearerSelectionFactory.cpp [new file with mode: 0755]
src/platform/API/NetworkBearerSelection/NetworkBearerSelectionFactory.h [new file with mode: 0755]
src/platform/API/NetworkBearerSelection/OnNetworkBearerSelectionStateChanged.h [new file with mode: 0755]
src/platform/API/NetworkBearerSelection/config.cmake [new file with mode: 0755]
src/platform/API/Notification/INotification.cpp [new file with mode: 0644]
src/platform/API/Notification/INotification.h [new file with mode: 0644]
src/platform/API/Notification/INotificationManager.cpp [new file with mode: 0644]
src/platform/API/Notification/INotificationManager.h [new file with mode: 0644]
src/platform/API/Notification/NotificationFactory.cpp [new file with mode: 0644]
src/platform/API/Notification/NotificationFactory.h [new file with mode: 0644]
src/platform/API/Notification/config.cmake [new file with mode: 0644]
src/platform/API/Power/IEventGetScreenBrightness.h [new file with mode: 0755]
src/platform/API/Power/IEventIsScreenOn.h [new file with mode: 0644]
src/platform/API/Power/IEventRelease.h [new file with mode: 0755]
src/platform/API/Power/IEventRequest.h [new file with mode: 0755]
src/platform/API/Power/IEventRestoreScreenBrightness.h [new file with mode: 0755]
src/platform/API/Power/IEventSetScreenBrightness.h [new file with mode: 0755]
src/platform/API/Power/IEventSetScreenStateChangeListener.h [new file with mode: 0755]
src/platform/API/Power/IEventTurnScreenOff.h [new file with mode: 0755]
src/platform/API/Power/IEventTurnScreenOn.h [new file with mode: 0755]
src/platform/API/Power/IEventUnsetScreenStateChangeListener.h [new file with mode: 0755]
src/platform/API/Power/IPowerManager.cpp [new file with mode: 0755]
src/platform/API/Power/IPowerManager.h [new file with mode: 0755]
src/platform/API/Power/OnPowerStateChanged.h [new file with mode: 0755]
src/platform/API/Power/PowerCommon.h [new file with mode: 0755]
src/platform/API/Power/config.cmake [new file with mode: 0755]
src/platform/API/SystemSetting/EventGetSetting.h [new file with mode: 0755]
src/platform/API/SystemSetting/EventSetRingtone.h [new file with mode: 0755]
src/platform/API/SystemSetting/EventSetSetting.h [new file with mode: 0755]
src/platform/API/SystemSetting/EventSetWallpaper.h [new file with mode: 0755]
src/platform/API/SystemSetting/ISystemSetting.cpp [new file with mode: 0755]
src/platform/API/SystemSetting/ISystemSetting.h [new file with mode: 0755]
src/platform/API/SystemSetting/ISystemSettingType.h [new file with mode: 0755]
src/platform/API/SystemSetting/SystemSettingFactory.cpp [new file with mode: 0755]
src/platform/API/SystemSetting/SystemSettingFactory.h [new file with mode: 0755]
src/platform/API/SystemSetting/config.cmake [new file with mode: 0644]
src/platform/API/Systeminfo/BaseProperties.h [new file with mode: 0755]
src/platform/API/Systeminfo/EventGetSysteminfo.cpp [new file with mode: 0755]
src/platform/API/Systeminfo/EventGetSysteminfo.h [new file with mode: 0755]
src/platform/API/Systeminfo/EventWatchSysteminfo.cpp [new file with mode: 0755]
src/platform/API/Systeminfo/EventWatchSysteminfo.h [new file with mode: 0755]
src/platform/API/Systeminfo/ISysteminfo.cpp [new file with mode: 0755]
src/platform/API/Systeminfo/ISysteminfo.h [new file with mode: 0755]
src/platform/API/Systeminfo/SysteminfoFactory.cpp [new file with mode: 0755]
src/platform/API/Systeminfo/SysteminfoFactory.h [new file with mode: 0755]
src/platform/API/Systeminfo/SysteminfoPropertyInfo.h [new file with mode: 0755]
src/platform/API/Systeminfo/config.cmake [new file with mode: 0755]
src/platform/API/TimeUtil/DurationProperties.h [new file with mode: 0755]
src/platform/API/TimeUtil/EventSetCurrentTZDate.h [new file with mode: 0755]
src/platform/API/TimeUtil/ITZDate.h [new file with mode: 0755]
src/platform/API/TimeUtil/ITimeUtil.h [new file with mode: 0755]
src/platform/API/TimeUtil/TZDateProperties.h [new file with mode: 0755]
src/platform/API/TimeUtil/TimeUtilFactory.cpp [new file with mode: 0755]
src/platform/API/TimeUtil/TimeUtilFactory.h [new file with mode: 0755]
src/platform/API/TimeUtil/TimezoneProperties.h [new file with mode: 0755]
src/platform/API/TimeUtil/config.cmake [new file with mode: 0755]
src/platform/API/config.cmake [new file with mode: 0755]
src/platform/CMakeLists.txt [new file with mode: 0644]
src/platform/Tizen/Application/AppManagerWrapper.cpp [new file with mode: 0644]
src/platform/Tizen/Application/AppManagerWrapper.h [new file with mode: 0644]
src/platform/Tizen/Application/Application.cpp [new file with mode: 0755]
src/platform/Tizen/Application/Application.h [new file with mode: 0644]
src/platform/Tizen/Application/ApplicationManager.cpp [new file with mode: 0644]
src/platform/Tizen/Application/ApplicationManager.h [new file with mode: 0644]
src/platform/Tizen/Application/config.cmake [new file with mode: 0755]
src/platform/Tizen/Bluetooth/BluetoothAdapterManager.cpp [new file with mode: 0755]
src/platform/Tizen/Bluetooth/BluetoothAdapterManager.h [new file with mode: 0644]
src/platform/Tizen/Bluetooth/BluetoothCBManager.cpp [new file with mode: 0644]
src/platform/Tizen/Bluetooth/BluetoothCBManager.h [new file with mode: 0644]
src/platform/Tizen/Bluetooth/BluetoothDeviceManager.cpp [new file with mode: 0644]
src/platform/Tizen/Bluetooth/BluetoothDeviceManager.h [new file with mode: 0644]
src/platform/Tizen/Bluetooth/BluetoothServiceHandlerManager.cpp [new file with mode: 0644]
src/platform/Tizen/Bluetooth/BluetoothServiceHandlerManager.h [new file with mode: 0644]
src/platform/Tizen/Bluetooth/BluetoothSocketManager.cpp [new file with mode: 0644]
src/platform/Tizen/Bluetooth/BluetoothSocketManager.h [new file with mode: 0644]
src/platform/Tizen/Bluetooth/config.cmake [new file with mode: 0644]
src/platform/Tizen/Calendar/Calendar.cpp [new file with mode: 0755]
src/platform/Tizen/Calendar/Calendar.h [new file with mode: 0755]
src/platform/Tizen/Calendar/CalendarFilter.cpp [new file with mode: 0755]
src/platform/Tizen/Calendar/CalendarFilter.h [new file with mode: 0755]
src/platform/Tizen/Calendar/CalendarFilterValidator.cpp [new file with mode: 0755]
src/platform/Tizen/Calendar/CalendarFilterValidator.h [new file with mode: 0755]
src/platform/Tizen/Calendar/CalendarManager.cpp [new file with mode: 0755]
src/platform/Tizen/Calendar/CalendarManager.h [new file with mode: 0755]
src/platform/Tizen/Calendar/EventWrapper.cpp [new file with mode: 0755]
src/platform/Tizen/Calendar/EventWrapper.h [new file with mode: 0755]
src/platform/Tizen/Calendar/config.cmake [new file with mode: 0755]
src/platform/Tizen/Callhistory/CallHistory.cpp [new file with mode: 0755]
src/platform/Tizen/Callhistory/CallHistory.h [new file with mode: 0755]
src/platform/Tizen/Callhistory/CallHistoryEntry.cpp [new file with mode: 0755]
src/platform/Tizen/Callhistory/CallHistoryEntry.h [new file with mode: 0755]
src/platform/Tizen/Callhistory/CallHistoryFilter.cpp [new file with mode: 0755]
src/platform/Tizen/Callhistory/CallHistoryFilter.h [new file with mode: 0755]
src/platform/Tizen/Callhistory/config.cmake [new file with mode: 0755]
src/platform/Tizen/Contact/AddressBook.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/AddressBook.h [new file with mode: 0755]
src/platform/Tizen/Contact/Contact.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/Contact.h [new file with mode: 0755]
src/platform/Tizen/Contact/ContactFilterValidator.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/ContactFilterValidator.h [new file with mode: 0755]
src/platform/Tizen/Contact/ContactImpl.h [new file with mode: 0755]
src/platform/Tizen/Contact/ContactManager.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/ContactManager.h [new file with mode: 0755]
src/platform/Tizen/Contact/ContactObjectA2PConverter.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/ContactObjectA2PConverter.h [new file with mode: 0755]
src/platform/Tizen/Contact/ContactObjectP2AConverter.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/ContactObjectP2AConverter.h [new file with mode: 0755]
src/platform/Tizen/Contact/ContactSearchEngine.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/ContactSearchEngine.h [new file with mode: 0755]
src/platform/Tizen/Contact/ContactUtility.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/ContactUtility.h [new file with mode: 0755]
src/platform/Tizen/Contact/ContactsSvcChangeListenerManager.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/ContactsSvcChangeListenerManager.h [new file with mode: 0755]
src/platform/Tizen/Contact/ContactsSvcObjectConverter.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/ContactsSvcObjectConverter.h [new file with mode: 0755]
src/platform/Tizen/Contact/ContactsSvcWrapper.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/ContactsSvcWrapper.h [new file with mode: 0755]
src/platform/Tizen/Contact/Person.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/Person.h [new file with mode: 0755]
src/platform/Tizen/Contact/PersonFilterValidator.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/PersonFilterValidator.h [new file with mode: 0755]
src/platform/Tizen/Contact/PersonSearchEngine.cpp [new file with mode: 0755]
src/platform/Tizen/Contact/PersonSearchEngine.h [new file with mode: 0755]
src/platform/Tizen/Contact/config.cmake [new file with mode: 0755]
src/platform/Tizen/Content/MediaFilterValidator.cpp [new file with mode: 0755]
src/platform/Tizen/Content/MediaFilterValidator.h [new file with mode: 0755]
src/platform/Tizen/Content/MediaSearchVisitor.cpp [new file with mode: 0755]
src/platform/Tizen/Content/MediaSearchVisitor.h [new file with mode: 0755]
src/platform/Tizen/Content/MediaWrapper.cpp [new file with mode: 0755]
src/platform/Tizen/Content/MediaWrapper.h [new file with mode: 0755]
src/platform/Tizen/Content/MediacontentManager.cpp [new file with mode: 0755]
src/platform/Tizen/Content/MediacontentManager.h [new file with mode: 0755]
src/platform/Tizen/Content/config.cmake [new file with mode: 0755]
src/platform/Tizen/DBus/Connection.cpp [new file with mode: 0755]
src/platform/Tizen/DBus/Connection.h [new file with mode: 0755]
src/platform/Tizen/DBus/Message.cpp [new file with mode: 0755]
src/platform/Tizen/DBus/Message.h [new file with mode: 0755]
src/platform/Tizen/DBus/MessageEvent.h [new file with mode: 0755]
src/platform/Tizen/DBus/config.cmake [new file with mode: 0644]
src/platform/Tizen/Download/DownloadManager.cpp [new file with mode: 0755]
src/platform/Tizen/Download/DownloadManager.h [new file with mode: 0755]
src/platform/Tizen/Download/config.cmake [new file with mode: 0755]
src/platform/Tizen/Filesystem/Manager.cpp [new file with mode: 0755]
src/platform/Tizen/Filesystem/Manager.h [new file with mode: 0755]
src/platform/Tizen/Filesystem/Node.cpp [new file with mode: 0755]
src/platform/Tizen/Filesystem/Node.h [new file with mode: 0755]
src/platform/Tizen/Filesystem/NodeFilterMatcher.cpp [new file with mode: 0755]
src/platform/Tizen/Filesystem/NodeFilterMatcher.h [new file with mode: 0755]
src/platform/Tizen/Filesystem/Path.cpp [new file with mode: 0755]
src/platform/Tizen/Filesystem/Path.h [new file with mode: 0755]
src/platform/Tizen/Filesystem/Stream.cpp [new file with mode: 0755]
src/platform/Tizen/Filesystem/Stream.h [new file with mode: 0755]
src/platform/Tizen/Filesystem/System.cpp [new file with mode: 0755]
src/platform/Tizen/Filesystem/System.h [new file with mode: 0755]
src/platform/Tizen/Filesystem/Utils.cpp [new file with mode: 0755]
src/platform/Tizen/Filesystem/Utils.h [new file with mode: 0755]
src/platform/Tizen/Filesystem/config.cmake [new file with mode: 0755]
src/platform/Tizen/Messaging/Attachment.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/Attachment.h [new file with mode: 0755]
src/platform/Tizen/Messaging/BinarySms.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/BinarySms.h [new file with mode: 0755]
src/platform/Tizen/Messaging/CallbackMgr.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/CallbackMgr.h [new file with mode: 0755]
src/platform/Tizen/Messaging/Conversation.cpp [new file with mode: 0644]
src/platform/Tizen/Messaging/Conversation.h [new file with mode: 0755]
src/platform/Tizen/Messaging/ConversationQueryGenerator.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/ConversationQueryGenerator.h [new file with mode: 0755]
src/platform/Tizen/Messaging/Email.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/Email.h [new file with mode: 0755]
src/platform/Tizen/Messaging/EmailConverter.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/EmailConverter.h [new file with mode: 0755]
src/platform/Tizen/Messaging/EmailService.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/EmailService.h [new file with mode: 0755]
src/platform/Tizen/Messaging/EmailUtils.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/EmailUtils.h [new file with mode: 0755]
src/platform/Tizen/Messaging/EmptyMessage.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/EmptyMessage.h [new file with mode: 0755]
src/platform/Tizen/Messaging/FolderQueryGenerator.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/FolderQueryGenerator.h [new file with mode: 0755]
src/platform/Tizen/Messaging/ISendingObserver.h [new file with mode: 0755]
src/platform/Tizen/Messaging/MailSender.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/MailSender.h [new file with mode: 0755]
src/platform/Tizen/Messaging/MailSync.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/MailSync.h [new file with mode: 0755]
src/platform/Tizen/Messaging/MessageFolder.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/MessageFolder.h [new file with mode: 0755]
src/platform/Tizen/Messaging/MessageQueryGenerator.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/MessageQueryGenerator.h [new file with mode: 0755]
src/platform/Tizen/Messaging/Messaging.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/Messaging.h [new file with mode: 0755]
src/platform/Tizen/Messaging/MessagingService.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/MessagingService.h [new file with mode: 0755]
src/platform/Tizen/Messaging/MessagingServiceManager.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/MessagingServiceManager.h [new file with mode: 0755]
src/platform/Tizen/Messaging/Mms.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/Mms.h [new file with mode: 0755]
src/platform/Tizen/Messaging/MmsSlide.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/MmsSlide.h [new file with mode: 0755]
src/platform/Tizen/Messaging/MsgServiceHandleMgr.h [new file with mode: 0755]
src/platform/Tizen/Messaging/NetworkStatus.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/NetworkStatus.h [new file with mode: 0755]
src/platform/Tizen/Messaging/ScopedMail.h [new file with mode: 0755]
src/platform/Tizen/Messaging/ScopedMailAttachment.h [new file with mode: 0755]
src/platform/Tizen/Messaging/ScopedMailbox.h [new file with mode: 0755]
src/platform/Tizen/Messaging/Sms.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/Sms.h [new file with mode: 0755]
src/platform/Tizen/Messaging/SyncNetworkStatus.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/SyncNetworkStatus.h [new file with mode: 0755]
src/platform/Tizen/Messaging/config.cmake [new file with mode: 0755]
src/platform/Tizen/Messaging/messageDB/MessageStorageReader.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/messageDB/MessageStorageReader.h [new file with mode: 0755]
src/platform/Tizen/Messaging/messageDB/MsgSqliteWrapper.cpp [new file with mode: 0755]
src/platform/Tizen/Messaging/messageDB/MsgSqliteWrapper.h [new file with mode: 0755]
src/platform/Tizen/NFC/NFCAdapter.cpp [new file with mode: 0755]
src/platform/Tizen/NFC/NFCAdapter.h [new file with mode: 0755]
src/platform/Tizen/NFC/NFCDefaultAdapter.cpp [new file with mode: 0755]
src/platform/Tizen/NFC/NFCDefaultAdapter.h [new file with mode: 0755]
src/platform/Tizen/NFC/NFCTag.cpp [new file with mode: 0755]
src/platform/Tizen/NFC/NFCTag.h [new file with mode: 0755]
src/platform/Tizen/NFC/NFCTarget.cpp [new file with mode: 0755]
src/platform/Tizen/NFC/NFCTarget.h [new file with mode: 0755]
src/platform/Tizen/NFC/NFCUtil.cpp [new file with mode: 0755]
src/platform/Tizen/NFC/NFCUtil.h [new file with mode: 0755]
src/platform/Tizen/NFC/NdefMessage.cpp [new file with mode: 0755]
src/platform/Tizen/NFC/NdefMessage.h [new file with mode: 0755]
src/platform/Tizen/NFC/NdefRecord.cpp [new file with mode: 0755]
src/platform/Tizen/NFC/NdefRecord.h [new file with mode: 0755]
src/platform/Tizen/NFC/config.cmake [new file with mode: 0755]
src/platform/Tizen/NetworkBearerSelection/NetworkBearerSelection.cpp [new file with mode: 0755]
src/platform/Tizen/NetworkBearerSelection/NetworkBearerSelection.h [new file with mode: 0755]
src/platform/Tizen/NetworkBearerSelection/config.cmake [new file with mode: 0755]
src/platform/Tizen/Notification/NotificationManager.cpp [new file with mode: 0644]
src/platform/Tizen/Notification/NotificationManager.h [new file with mode: 0644]
src/platform/Tizen/Notification/StatusNotification.cpp [new file with mode: 0644]
src/platform/Tizen/Notification/StatusNotification.h [new file with mode: 0644]
src/platform/Tizen/Notification/config.cmake [new file with mode: 0644]
src/platform/Tizen/Power/PowerManager.cpp [new file with mode: 0755]
src/platform/Tizen/Power/PowerManager.h [new file with mode: 0755]
src/platform/Tizen/Power/config.cmake [new file with mode: 0755]
src/platform/Tizen/SystemSetting/SystemSetting.cpp [new file with mode: 0755]
src/platform/Tizen/SystemSetting/SystemSetting.h [new file with mode: 0755]
src/platform/Tizen/SystemSetting/config.cmake [new file with mode: 0644]
src/platform/Tizen/Systeminfo/Systeminfo.cpp [new file with mode: 0755]
src/platform/Tizen/Systeminfo/Systeminfo.h [new file with mode: 0755]
src/platform/Tizen/Systeminfo/config.cmake [new file with mode: 0755]
src/platform/Tizen/TimeUtil/TZDate.cpp [new file with mode: 0755]
src/platform/Tizen/TimeUtil/TZDate.h [new file with mode: 0755]
src/platform/Tizen/TimeUtil/TimeUtil.cpp [new file with mode: 0755]
src/platform/Tizen/TimeUtil/TimeUtil.h [new file with mode: 0755]
src/platform/Tizen/TimeUtil/TimeUtilTools.cpp [new file with mode: 0755]
src/platform/Tizen/TimeUtil/TimeUtilTools.h [new file with mode: 0755]
src/platform/Tizen/TimeUtil/config.cmake [new file with mode: 0755]
src/platform/Tizen/config.cmake [new file with mode: 0644]
src/standards/CMakeLists.txt [new file with mode: 0644]
src/standards/Tizen/Alarm/AlarmAbsolute.cpp [new file with mode: 0755]
src/standards/Tizen/Alarm/AlarmAbsolute.h [new file with mode: 0755]
src/standards/Tizen/Alarm/AlarmConverter.cpp [new file with mode: 0755]
src/standards/Tizen/Alarm/AlarmConverter.h [new file with mode: 0755]
src/standards/Tizen/Alarm/AlarmRelative.cpp [new file with mode: 0755]
src/standards/Tizen/Alarm/AlarmRelative.h [new file with mode: 0755]
src/standards/Tizen/Alarm/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Alarm/JSAlarmAbsolute.cpp [new file with mode: 0755]
src/standards/Tizen/Alarm/JSAlarmAbsolute.h [new file with mode: 0755]
src/standards/Tizen/Alarm/JSAlarmManager.cpp [new file with mode: 0755]
src/standards/Tizen/Alarm/JSAlarmManager.h [new file with mode: 0755]
src/standards/Tizen/Alarm/JSAlarmRelative.cpp [new file with mode: 0755]
src/standards/Tizen/Alarm/JSAlarmRelative.h [new file with mode: 0755]
src/standards/Tizen/Alarm/alarm_common.h [new file with mode: 0755]
src/standards/Tizen/Alarm/config.xml [new file with mode: 0755]
src/standards/Tizen/Alarm/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Alarm/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Alarm/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/Application/ApplicationAsyncCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/Application/ApplicationAsyncCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Application/ApplicationController.cpp [new file with mode: 0755]
src/standards/Tizen/Application/ApplicationController.h [new file with mode: 0755]
src/standards/Tizen/Application/ApplicationConverter.cpp [new file with mode: 0755]
src/standards/Tizen/Application/ApplicationConverter.h [new file with mode: 0755]
src/standards/Tizen/Application/ApplicationInformationEventPrivateData.h [new file with mode: 0755]
src/standards/Tizen/Application/ApplicationListenerManager.cpp [new file with mode: 0755]
src/standards/Tizen/Application/ApplicationListenerManager.h [new file with mode: 0755]
src/standards/Tizen/Application/ApplicationUtil.cpp [new file with mode: 0755]
src/standards/Tizen/Application/ApplicationUtil.h [new file with mode: 0755]
src/standards/Tizen/Application/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Application/JSApplication.cpp [new file with mode: 0755]
src/standards/Tizen/Application/JSApplication.h [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationCert.cpp [new file with mode: 0644]
src/standards/Tizen/Application/JSApplicationCert.h [new file with mode: 0644]
src/standards/Tizen/Application/JSApplicationContext.cpp [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationContext.h [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationControl.cpp [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationControl.h [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationControlData.cpp [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationControlData.h [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationEventCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationEventCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationInformation.cpp [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationInformation.h [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationInstallInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationInstallInfo.h [new file with mode: 0755]
src/standards/Tizen/Application/JSApplicationManager.cpp [new file with mode: 0644]
src/standards/Tizen/Application/JSApplicationManager.h [new file with mode: 0644]
src/standards/Tizen/Application/JSRequestedApplicationControl.cpp [new file with mode: 0644]
src/standards/Tizen/Application/JSRequestedApplicationControl.h [new file with mode: 0644]
src/standards/Tizen/Application/config.xml [new file with mode: 0755]
src/standards/Tizen/Application/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Application/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Application/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/Bluetooth/BluetoothAdapterListener.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/BluetoothAdapterListener.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/BluetoothClass.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/BluetoothClass.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/BluetoothConverter.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/BluetoothConverter.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/BluetoothDeviceManagerListener.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/BluetoothDeviceManagerListener.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/BluetoothMultiCallback.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/BluetoothMultiCallback.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/BluetoothSocketListener.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/BluetoothSocketListener.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/CMakeLists.txt [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothAdapter.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothAdapter.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothClass.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothClass.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMajor.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMajor.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMinor.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMinor.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceService.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceService.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothDevice.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothDevice.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothManager.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothManager.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothServiceHandler.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothServiceHandler.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothSocket.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/JSBluetoothSocket.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/config.xml [new file with mode: 0644]
src/standards/Tizen/Bluetooth/plugin_config.cpp [new file with mode: 0644]
src/standards/Tizen/Bluetooth/plugin_config.h [new file with mode: 0644]
src/standards/Tizen/Bluetooth/plugin_initializer.cpp [new file with mode: 0644]
src/standards/Tizen/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Calendar/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Calendar/CalendarAsyncCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/CalendarAsyncCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Calendar/CalendarConverter.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/CalendarConverter.h [new file with mode: 0755]
src/standards/Tizen/Calendar/CalendarListenerManager.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/CalendarListenerManager.h [new file with mode: 0755]
src/standards/Tizen/Calendar/CalendarMultiCallback.h [new file with mode: 0755]
src/standards/Tizen/Calendar/CalendarResponseDispatcher.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/CalendarResponseDispatcher.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendar.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendar.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarAlarm.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarAlarm.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarAttendee.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarAttendee.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarEvent.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarEvent.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarEventId.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarEventId.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarItemProperties.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarItemProperties.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarManager.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarManager.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarRecurrenceRule.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarRecurrenceRule.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarTask.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSCalendarTask.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSNumberArray.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSNumberArray.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSStringArray.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSStringArray.h [new file with mode: 0755]
src/standards/Tizen/Calendar/JSTZDateArray.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/JSTZDateArray.h [new file with mode: 0755]
src/standards/Tizen/Calendar/config.xml [new file with mode: 0755]
src/standards/Tizen/Calendar/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Calendar/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Calendar/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/Callhistory/CMakeLists.txt [new file with mode: 0644]
src/standards/Tizen/Callhistory/CallHistoryAsyncCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/Callhistory/CallHistoryAsyncCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Callhistory/CallHistoryListenerManager.cpp [new file with mode: 0755]
src/standards/Tizen/Callhistory/CallHistoryListenerManager.h [new file with mode: 0755]
src/standards/Tizen/Callhistory/CallHistoryMultiCallback.cpp [new file with mode: 0755]
src/standards/Tizen/Callhistory/CallHistoryMultiCallback.h [new file with mode: 0755]
src/standards/Tizen/Callhistory/CallHistoryStaticController.cpp [new file with mode: 0755]
src/standards/Tizen/Callhistory/CallHistoryStaticController.h [new file with mode: 0755]
src/standards/Tizen/Callhistory/Converter.cpp [new file with mode: 0755]
src/standards/Tizen/Callhistory/Converter.h [new file with mode: 0755]
src/standards/Tizen/Callhistory/JSCallHistory.cpp [new file with mode: 0755]
src/standards/Tizen/Callhistory/JSCallHistory.h [new file with mode: 0755]
src/standards/Tizen/Callhistory/JSCallHistoryEntry.cpp [new file with mode: 0755]
src/standards/Tizen/Callhistory/JSCallHistoryEntry.h [new file with mode: 0755]
src/standards/Tizen/Callhistory/JSRemoteParty.cpp [new file with mode: 0755]
src/standards/Tizen/Callhistory/JSRemoteParty.h [new file with mode: 0755]
src/standards/Tizen/Callhistory/ResponseDispatcher.cpp [new file with mode: 0755]
src/standards/Tizen/Callhistory/ResponseDispatcher.h [new file with mode: 0755]
src/standards/Tizen/Callhistory/config.xml [new file with mode: 0755]
src/standards/Tizen/Callhistory/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Callhistory/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Callhistory/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/Common/AsyncCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Common/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Common/IListenerManager.h [new file with mode: 0755]
src/standards/Tizen/Common/JSTizenException.cpp [new file with mode: 0644]
src/standards/Tizen/Common/JSTizenException.h [new file with mode: 0644]
src/standards/Tizen/Common/JSTizenExceptionFactory.cpp [new file with mode: 0644]
src/standards/Tizen/Common/JSTizenExceptionFactory.h [new file with mode: 0644]
src/standards/Tizen/Common/JSWebAPIError.cpp [new file with mode: 0644]
src/standards/Tizen/Common/JSWebAPIError.h [new file with mode: 0644]
src/standards/Tizen/Common/SecurityExceptions.h [new file with mode: 0755]
src/standards/Tizen/Common/TizenExceptionData.cpp [new file with mode: 0644]
src/standards/Tizen/Common/TizenExceptionData.h [new file with mode: 0755]
src/standards/Tizen/Contact/AddressBookController.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/AddressBookController.h [new file with mode: 0755]
src/standards/Tizen/Contact/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Contact/ContactAsyncCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/ContactAsyncCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Contact/ContactConverter.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/ContactConverter.h [new file with mode: 0755]
src/standards/Tizen/Contact/ContactListenerManager.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/ContactListenerManager.h [new file with mode: 0755]
src/standards/Tizen/Contact/ContactManagerController.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/ContactManagerController.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSAddressBook.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSAddressBook.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSAddressBookArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSAddressBookArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSAddressBookChangeCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSAddressBookChangeCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSAttributesOfInterestArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSAttributesOfInterestArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContact.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContact.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactAddress.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactAddress.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactAddressArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactAddressArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactAddressTypeArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactAddressTypeArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactAnniversary.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactAnniversary.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactAnniversaryArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactAnniversaryArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactEmailAddress.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactEmailAddress.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactEmailAddressArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactEmailAddressArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactEmailAddressTypeArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactEmailAddressTypeArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactGroup.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactGroup.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactGroupArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactGroupArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactManager.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactManager.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactManagerChangeCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactManagerChangeCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactName.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactName.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactOrganization.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactOrganization.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactOrganizationArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactOrganizationArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactPhoneNumber.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactPhoneNumber.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactPhoneNumberArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactPhoneNumberArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactPhoneNumberTypeArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactPhoneNumberTypeArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactRef.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactRef.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactWebSite.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactWebSite.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactWebSiteArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSContactWebSiteArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSPerson.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSPerson.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSPersonArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSPersonArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/JSStringArray.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/JSStringArray.h [new file with mode: 0755]
src/standards/Tizen/Contact/config.xml [new file with mode: 0755]
src/standards/Tizen/Contact/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Contact/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Contact/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/Content/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Content/ContentAsyncCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/Content/ContentAsyncCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Content/ContentController.cpp [new file with mode: 0755]
src/standards/Tizen/Content/ContentController.h [new file with mode: 0755]
src/standards/Tizen/Content/ContentConverter.cpp [new file with mode: 0755]
src/standards/Tizen/Content/ContentConverter.h [new file with mode: 0755]
src/standards/Tizen/Content/JSAudio.cpp [new file with mode: 0755]
src/standards/Tizen/Content/JSAudio.h [new file with mode: 0755]
src/standards/Tizen/Content/JSContentManager.cpp [new file with mode: 0755]
src/standards/Tizen/Content/JSContentManager.h [new file with mode: 0755]
src/standards/Tizen/Content/JSFolder.cpp [new file with mode: 0755]
src/standards/Tizen/Content/JSFolder.h [new file with mode: 0755]
src/standards/Tizen/Content/JSImage.cpp [new file with mode: 0755]
src/standards/Tizen/Content/JSImage.h [new file with mode: 0755]
src/standards/Tizen/Content/JSMedia.cpp [new file with mode: 0755]
src/standards/Tizen/Content/JSMedia.h [new file with mode: 0755]
src/standards/Tizen/Content/JSMediaLyrics.cpp [new file with mode: 0755]
src/standards/Tizen/Content/JSMediaLyrics.h [new file with mode: 0755]
src/standards/Tizen/Content/JSVideo.cpp [new file with mode: 0755]
src/standards/Tizen/Content/JSVideo.h [new file with mode: 0755]
src/standards/Tizen/Content/MediaLyricsUtil.cpp [new file with mode: 0755]
src/standards/Tizen/Content/MediaLyricsUtil.h [new file with mode: 0755]
src/standards/Tizen/Content/config.xml [new file with mode: 0755]
src/standards/Tizen/Content/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Content/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Content/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/Download/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Download/DownloadConverter.cpp [new file with mode: 0755]
src/standards/Tizen/Download/DownloadConverter.h [new file with mode: 0755]
src/standards/Tizen/Download/DownloadListenerManager.cpp [new file with mode: 0755]
src/standards/Tizen/Download/DownloadListenerManager.h [new file with mode: 0755]
src/standards/Tizen/Download/DownloadMultiCallback.h [new file with mode: 0755]
src/standards/Tizen/Download/DownloadResponseDispatcher.cpp [new file with mode: 0755]
src/standards/Tizen/Download/DownloadResponseDispatcher.h [new file with mode: 0755]
src/standards/Tizen/Download/JSDownloadManager.cpp [new file with mode: 0755]
src/standards/Tizen/Download/JSDownloadManager.h [new file with mode: 0755]
src/standards/Tizen/Download/JSDownloadRequest.cpp [new file with mode: 0755]
src/standards/Tizen/Download/JSDownloadRequest.h [new file with mode: 0755]
src/standards/Tizen/Download/config.xml [new file with mode: 0755]
src/standards/Tizen/Download/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Download/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Download/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Filesystem/Converter.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/Converter.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/Encodings.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/Encodings.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/EventGetNodeData.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/EventGetNodeData.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/FilesystemAsyncCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/FilesystemAsyncCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/FilesystemListenerManager.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/FilesystemListenerManager.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/FilesystemUtils.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/FilesystemUtils.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/JSFile.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/JSFile.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/JSFilestream.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/JSFilestream.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/JSFilesystemManager.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/JSFilesystemManager.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/JSStorage.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/JSStorage.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/ResponseDispatcher.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/ResponseDispatcher.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/StorageStaticController.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/StorageStaticController.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/config.xml [new file with mode: 0755]
src/standards/Tizen/Filesystem/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Filesystem/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Filesystem/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Messaging/ConverterMessage.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/ConverterMessage.h [new file with mode: 0755]
src/standards/Tizen/Messaging/EventMessagingServicePrivateData.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/EventMessagingServicePrivateData.h [new file with mode: 0755]
src/standards/Tizen/Messaging/EventSendMessagePrivateData.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/EventSendMessagePrivateData.h [new file with mode: 0755]
src/standards/Tizen/Messaging/JSConversation.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/JSConversation.h [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessage.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessage.h [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessageAttachment.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessageAttachment.h [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessageBody.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessageBody.h [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessageFolder.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessageFolder.h [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessagePrivateObject.h [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessagingService.cpp [new file with mode: 0644]
src/standards/Tizen/Messaging/JSMessagingService.h [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessagingServiceManager.cpp [new file with mode: 0644]
src/standards/Tizen/Messaging/JSMessagingServiceManager.h [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessagingStorage.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/JSMessagingStorage.h [new file with mode: 0755]
src/standards/Tizen/Messaging/JSRecipientArray.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/JSRecipientArray.h [new file with mode: 0755]
src/standards/Tizen/Messaging/MessageAsyncCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/MessageAsyncCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Messaging/MessageListenerManager.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/MessageListenerManager.h [new file with mode: 0755]
src/standards/Tizen/Messaging/MessageSendCallback.h [new file with mode: 0755]
src/standards/Tizen/Messaging/MessagingController.cpp [new file with mode: 0644]
src/standards/Tizen/Messaging/MessagingController.h [new file with mode: 0755]
src/standards/Tizen/Messaging/MessagingErrorMsg.h [new file with mode: 0755]
src/standards/Tizen/Messaging/MessagingListener.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/MessagingListener.h [new file with mode: 0755]
src/standards/Tizen/Messaging/MessagingStorageMultiCallback.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/MessagingStorageMultiCallback.h [new file with mode: 0755]
src/standards/Tizen/Messaging/config.xml [new file with mode: 0755]
src/standards/Tizen/Messaging/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Messaging/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Messaging/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/NFC/EventNFCChangedPrivateData.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/EventNFCChangedPrivateData.h [new file with mode: 0755]
src/standards/Tizen/NFC/JSNFCAdapter.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/JSNFCAdapter.h [new file with mode: 0755]
src/standards/Tizen/NFC/JSNFCManager.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/JSNFCManager.h [new file with mode: 0755]
src/standards/Tizen/NFC/JSNFCTag.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/JSNFCTag.h [new file with mode: 0755]
src/standards/Tizen/NFC/JSNFCTarget.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/JSNFCTarget.h [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefMessage.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefMessage.h [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefRecord.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefRecord.h [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefRecordArray.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefRecordArray.h [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefRecordMedia.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefRecordMedia.h [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefRecordText.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefRecordText.h [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefRecordURI.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/JSNdefRecordURI.h [new file with mode: 0755]
src/standards/Tizen/NFC/NFCAsyncCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/NFCAsyncCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/NFC/NFCChangedCallback.h [new file with mode: 0755]
src/standards/Tizen/NFC/NFCConverter.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/NFCConverter.h [new file with mode: 0755]
src/standards/Tizen/NFC/NFCListenerManager.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/NFCListenerManager.h [new file with mode: 0755]
src/standards/Tizen/NFC/NFCStaticController.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/NFCStaticController.h [new file with mode: 0755]
src/standards/Tizen/NFC/ResponseDispatcher.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/ResponseDispatcher.h [new file with mode: 0755]
src/standards/Tizen/NFC/config.xml [new file with mode: 0755]
src/standards/Tizen/NFC/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/NFC/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/NFC/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/NetworkBearerSelection/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelection.cpp [new file with mode: 0755]
src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelection.h [new file with mode: 0755]
src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelectionCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelectionCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/NetworkBearerSelection/NetworkBearerSelectionResponseDispatcher.cpp [new file with mode: 0755]
src/standards/Tizen/NetworkBearerSelection/NetworkBearerSelectionResponseDispatcher.h [new file with mode: 0755]
src/standards/Tizen/NetworkBearerSelection/config.xml [new file with mode: 0755]
src/standards/Tizen/NetworkBearerSelection/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/NetworkBearerSelection/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/NetworkBearerSelection/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/Notification/CMakeLists.txt [new file with mode: 0644]
src/standards/Tizen/Notification/JSNotificationManager.cpp [new file with mode: 0644]
src/standards/Tizen/Notification/JSNotificationManager.h [new file with mode: 0644]
src/standards/Tizen/Notification/JSStatusNotification.cpp [new file with mode: 0644]
src/standards/Tizen/Notification/JSStatusNotification.h [new file with mode: 0644]
src/standards/Tizen/Notification/NotificationConverter.cpp [new file with mode: 0644]
src/standards/Tizen/Notification/NotificationConverter.h [new file with mode: 0644]
src/standards/Tizen/Notification/NotificationCoverter.cpp [new file with mode: 0644]
src/standards/Tizen/Notification/config.xml [new file with mode: 0644]
src/standards/Tizen/Notification/plugin_config.cpp [new file with mode: 0644]
src/standards/Tizen/Notification/plugin_config.h [new file with mode: 0644]
src/standards/Tizen/Notification/plugin_initializer.cpp [new file with mode: 0644]
src/standards/Tizen/Power/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Power/JSPowerManager.cpp [new file with mode: 0755]
src/standards/Tizen/Power/JSPowerManager.h [new file with mode: 0755]
src/standards/Tizen/Power/PowerConverter.cpp [new file with mode: 0755]
src/standards/Tizen/Power/PowerConverter.h [new file with mode: 0755]
src/standards/Tizen/Power/PowerListenerManager.cpp [new file with mode: 0755]
src/standards/Tizen/Power/PowerListenerManager.h [new file with mode: 0755]
src/standards/Tizen/Power/PowerResponseDispatcher.cpp [new file with mode: 0755]
src/standards/Tizen/Power/PowerResponseDispatcher.h [new file with mode: 0755]
src/standards/Tizen/Power/config.xml [new file with mode: 0755]
src/standards/Tizen/Power/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Power/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Power/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/SecureStorage/CMakeLists.txt [new file with mode: 0644]
src/standards/Tizen/SecureStorage/JSSecureStorageManager.cpp [new file with mode: 0644]
src/standards/Tizen/SecureStorage/JSSecureStorageManager.h [new file with mode: 0644]
src/standards/Tizen/SecureStorage/SecureStorageManager.cpp [new file with mode: 0644]
src/standards/Tizen/SecureStorage/SecureStorageManager.h [new file with mode: 0644]
src/standards/Tizen/SecureStorage/config.xml [new file with mode: 0644]
src/standards/Tizen/SecureStorage/plugin_config.cpp [new file with mode: 0644]
src/standards/Tizen/SecureStorage/plugin_config.h [new file with mode: 0644]
src/standards/Tizen/SecureStorage/plugin_initializer.cpp [new file with mode: 0644]
src/standards/Tizen/SystemSetting/CMakeLists.txt [new file with mode: 0644]
src/standards/Tizen/SystemSetting/ConverterSystemSetting.cpp [new file with mode: 0755]
src/standards/Tizen/SystemSetting/ConverterSystemSetting.h [new file with mode: 0755]
src/standards/Tizen/SystemSetting/JSSystemSetting.cpp [new file with mode: 0755]
src/standards/Tizen/SystemSetting/JSSystemSetting.h [new file with mode: 0755]
src/standards/Tizen/SystemSetting/SystemSettingAsyncCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/SystemSetting/SystemSettingAsyncCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/SystemSetting/SystemSettingResponseDispatcher.cpp [new file with mode: 0755]
src/standards/Tizen/SystemSetting/SystemSettingResponseDispatcher.h [new file with mode: 0755]
src/standards/Tizen/SystemSetting/config.xml [new file with mode: 0644]
src/standards/Tizen/SystemSetting/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/SystemSetting/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/SystemSetting/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSBatteryInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSBatteryInfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSBuildInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSBuildInfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSCellularNetworkInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSCellularNetworkInfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSCpuInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSCpuInfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSDeviceCapabilitiesInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSDeviceCapabilitiesInfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSDeviceOrientationInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSDeviceOrientationInfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSDisplayInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSDisplayInfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSNetworkInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSNetworkInfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSSIMInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSSIMInfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSStorageInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSStorageInfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSSysteminfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSSysteminfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSWifiNetworkInfo.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/JSWifiNetworkInfo.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/SysteminfoAsyncCallbackManager.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/SysteminfoAsyncCallbackManager.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/SysteminfoListener.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/SysteminfoListener.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/SysteminfoListenerManager.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/SysteminfoListenerManager.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/config.xml [new file with mode: 0755]
src/standards/Tizen/Systeminfo/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Systeminfo/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Systeminfo/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/TimeUtil/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/TimeUtil/JSTZDate.cpp [new file with mode: 0755]
src/standards/Tizen/TimeUtil/JSTZDate.h [new file with mode: 0755]
src/standards/Tizen/TimeUtil/JSTimeDuration.cpp [new file with mode: 0755]
src/standards/Tizen/TimeUtil/JSTimeDuration.h [new file with mode: 0755]
src/standards/Tizen/TimeUtil/JSTimeUtil.cpp [new file with mode: 0755]
src/standards/Tizen/TimeUtil/JSTimeUtil.h [new file with mode: 0755]
src/standards/Tizen/TimeUtil/TimeUtilConverter.cpp [new file with mode: 0755]
src/standards/Tizen/TimeUtil/TimeUtilConverter.h [new file with mode: 0755]
src/standards/Tizen/TimeUtil/config.xml [new file with mode: 0755]
src/standards/Tizen/TimeUtil/plugin_initializer.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/CMakeLists.txt [new file with mode: 0755]
src/standards/Tizen/Tizen/FilterConverter.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/FilterConverter.h [new file with mode: 0755]
src/standards/Tizen/Tizen/JSAbstractFilterArray.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/JSAbstractFilterArray.h [new file with mode: 0755]
src/standards/Tizen/Tizen/JSAttributeFilter.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/JSAttributeFilter.h [new file with mode: 0755]
src/standards/Tizen/Tizen/JSAttributeRangeFilter.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/JSAttributeRangeFilter.h [new file with mode: 0755]
src/standards/Tizen/Tizen/JSCompositeFilter.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/JSCompositeFilter.h [new file with mode: 0755]
src/standards/Tizen/Tizen/JSFeature.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/JSFeature.h [new file with mode: 0755]
src/standards/Tizen/Tizen/JSFeatureParam.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/JSFeatureParam.h [new file with mode: 0755]
src/standards/Tizen/Tizen/JSSimpleCoordinates.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/JSSimpleCoordinates.h [new file with mode: 0755]
src/standards/Tizen/Tizen/JSSortMode.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/JSSortMode.h [new file with mode: 0755]
src/standards/Tizen/Tizen/JSTizen.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/JSTizen.h [new file with mode: 0755]
src/standards/Tizen/Tizen/PluginOnDemandPriv.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/PluginOnDemandPriv.h [new file with mode: 0755]
src/standards/Tizen/Tizen/config.xml [new file with mode: 0755]
src/standards/Tizen/Tizen/plugin_config.cpp [new file with mode: 0755]
src/standards/Tizen/Tizen/plugin_config.h [new file with mode: 0755]
src/standards/Tizen/Tizen/plugin_initializer.cpp [new file with mode: 0755]
wrt-plugins-tizen.manifest [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..09276ca
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
+Keeduck Kim <keeduck.kim at samsung dot com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..b5a97d0
--- /dev/null
@@ -0,0 +1,129 @@
+cmake_minimum_required(VERSION 2.6)
+
+
+project(wrt-plugins-tizen)
+
+
+################################################################################
+# Required platform modules
+
+include(FindPkgConfig)
+
+pkg_search_module(webkit2 REQUIRED ewebkit2)
+pkg_search_module(dpl REQUIRED dpl-efl)
+pkg_search_module(dpl-event REQUIRED dpl-event-efl)
+pkg_search_module(wrt-plugins-types REQUIRED wrt-plugins-types)
+pkg_search_module(wrt-deviceapis-commons REQUIRED wrt-plugins-commons)
+pkg_search_module(wrt-deviceapis-commons-javascript REQUIRED wrt-plugins-commons-javascript)
+
+include_directories(
+  ${webkit2_INCLUDE_DIRS}
+  ${dpl_INCLUDE_DIRS}
+  ${wrt-plugins-types_INCLUDE_DIRS}
+  ${wrt-deviceapis-commons_INCLUDE_DIRS}
+  ${wrt-deviceapis-commons-javascript_INCLUDE_DIRS}
+)
+
+
+################################################################################
+# Build options
+
+#
+# Logs
+#
+
+OPTION(DPL_LOG "DPL logs status" ON)
+
+IF(DPL_LOG)
+    MESSAGE(STATUS "Logging enabled for DPL")
+    ADD_DEFINITIONS("-DDPL_LOGS_ENABLED")
+ELSE(DPL_LOG)
+    MESSAGE(STATUS "Logging disabled for DPL")
+ENDIF(DPL_LOG)
+
+###############################################################################
+# Set build type (Release by default)
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+     SET(CMAKE_BUILD_TYPE Release)
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+
+MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
+
+##############################################################################
+# Compiler flags
+SET(CMAKE_C_FLAGS_PROFILING    "-O0 -g -pg")
+SET(CMAKE_CXX_FLAGS_PROFILING  "-O0 -std=c++0x -g -pg")
+SET(CMAKE_C_FLAGS_DEBUG        "-O0 -g")
+SET(CMAKE_CXX_FLAGS_DEBUG      "-O0 -std=c++0x -g")
+SET(CMAKE_C_FLAGS_RELEASE      "-O2 -g")
+SET(CMAKE_CXX_FLAGS_RELEASE    "-O2 -std=c++0x -g")
+####
+
+ADD_DEFINITIONS("-DEXPORT_API=")
+ADD_DEFINITIONS("-Wall")
+#ADD_DEFINITIONS("-Werror")
+#ADD_DEFINITIONS("-Wextra")
+
+################################################################################
+# Miscellaneous variables
+
+set(CONFIG_FILE_NAME "config.cmake")
+set(DIR_COMMONS ${CMAKE_SOURCE_DIR}/src/commons)
+set(LIBS_COMMON
+    ${dpl_LDFLAGS}
+    ${dpl-event_LDFLAGS}
+    ${webkit2_LDFLAGS}
+    ${wrt-deviceapis-commons_LDFLAGS}
+    ${wrt-deviceapis-commons-javascript_LDFLAGS}
+    )
+
+
+################################################################################
+# Target platform
+
+if (NOT DEFINED PLATFORM)
+  set(PLATFORM "Tizen")
+endif ()
+
+include_directories(
+  ${CMAKE_CURRENT_SOURCE_DIR}/src
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/platform
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/${PLATFORM}
+  ${CMAKE_CURRENT_SOURCE_DIR}/src/standards
+)
+
+################################################################################
+# Schema of plugin's configuration file
+
+set(COMMON_CONFIG_DTD ${CMAKE_CURRENT_SOURCE_DIR}/config.dtd)
+set(COMMON_CONFIG_DTD_DST /usr/etc/tizen-apis)
+INSTALL(FILES ${COMMON_CONFIG_DTD} DESTINATION ${COMMON_CONFIG_DTD_DST})
+
+
+################################################################################
+# Macros used for including plugins from AL.
+
+function(add_subdir NAME)
+  message(STATUS "Building: ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}")
+  add_subdirectory(${NAME})
+endfunction()
+
+
+################################################################################
+# Subdirectories
+
+add_subdirectory(src)
+
+
+################################################################################
+# Cache
+
+set(PLATFORM "${PLATFORM}" CACHE STRING "Target platform" FORCE)
+set(CMAKE_CONFIG_FILE_NAME "${CMAKE_CONFIG_FILE_NAME}" CACHE
+    STRING "CMake configuration file name." FORCE)
+
+
+################################################################################
+# Summary
+
+message(STATUS "PLATFORM = ${PLATFORM}")
diff --git a/LICENSE b/LICENSE
new file mode 100755 (executable)
index 0000000..bbe9d02
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,206 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+\r
+                                 Apache License\r
+                           Version 2.0, January 2004\r
+                        http://www.apache.org/licenses/\r
+\r
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
+\r
+   1. Definitions.\r
+\r
+      "License" shall mean the terms and conditions for use, reproduction,\r
+      and distribution as defined by Sections 1 through 9 of this document.\r
+\r
+      "Licensor" shall mean the copyright owner or entity authorized by\r
+      the copyright owner that is granting the License.\r
+\r
+      "Legal Entity" shall mean the union of the acting entity and all\r
+      other entities that control, are controlled by, or are under common\r
+      control with that entity. For the purposes of this definition,\r
+      "control" means (i) the power, direct or indirect, to cause the\r
+      direction or management of such entity, whether by contract or\r
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
+      outstanding shares, or (iii) beneficial ownership of such entity.\r
+\r
+      "You" (or "Your") shall mean an individual or Legal Entity\r
+      exercising permissions granted by this License.\r
+\r
+      "Source" form shall mean the preferred form for making modifications,\r
+      including but not limited to software source code, documentation\r
+      source, and configuration files.\r
+\r
+      "Object" form shall mean any form resulting from mechanical\r
+      transformation or translation of a Source form, including but\r
+      not limited to compiled object code, generated documentation,\r
+      and conversions to other media types.\r
+\r
+      "Work" shall mean the work of authorship, whether in Source or\r
+      Object form, made available under the License, as indicated by a\r
+      copyright notice that is included in or attached to the work\r
+      (an example is provided in the Appendix below).\r
+\r
+      "Derivative Works" shall mean any work, whether in Source or Object\r
+      form, that is based on (or derived from) the Work and for which the\r
+      editorial revisions, annotations, elaborations, or other modifications\r
+      represent, as a whole, an original work of authorship. For the purposes\r
+      of this License, Derivative Works shall not include works that remain\r
+      separable from, or merely link (or bind by name) to the interfaces of,\r
+      the Work and Derivative Works thereof.\r
+\r
+      "Contribution" shall mean any work of authorship, including\r
+      the original version of the Work and any modifications or additions\r
+      to that Work or Derivative Works thereof, that is intentionally\r
+      submitted to Licensor for inclusion in the Work by the copyright owner\r
+      or by an individual or Legal Entity authorized to submit on behalf of\r
+      the copyright owner. For the purposes of this definition, "submitted"\r
+      means any form of electronic, verbal, or written communication sent\r
+      to the Licensor or its representatives, including but not limited to\r
+      communication on electronic mailing lists, source code control systems,\r
+      and issue tracking systems that are managed by, or on behalf of, the\r
+      Licensor for the purpose of discussing and improving the Work, but\r
+      excluding communication that is conspicuously marked or otherwise\r
+      designated in writing by the copyright owner as "Not a Contribution."\r
+\r
+      "Contributor" shall mean Licensor and any individual or Legal Entity\r
+      on behalf of whom a Contribution has been received by Licensor and\r
+      subsequently incorporated within the Work.\r
+\r
+   2. Grant of Copyright License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      copyright license to reproduce, prepare Derivative Works of,\r
+      publicly display, publicly perform, sublicense, and distribute the\r
+      Work and such Derivative Works in Source or Object form.\r
+\r
+   3. Grant of Patent License. Subject to the terms and conditions of\r
+      this License, each Contributor hereby grants to You a perpetual,\r
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
+      (except as stated in this section) patent license to make, have made,\r
+      use, offer to sell, sell, import, and otherwise transfer the Work,\r
+      where such license applies only to those patent claims licensable\r
+      by such Contributor that are necessarily infringed by their\r
+      Contribution(s) alone or by combination of their Contribution(s)\r
+      with the Work to which such Contribution(s) was submitted. If You\r
+      institute patent litigation against any entity (including a\r
+      cross-claim or counterclaim in a lawsuit) alleging that the Work\r
+      or a Contribution incorporated within the Work constitutes direct\r
+      or contributory patent infringement, then any patent licenses\r
+      granted to You under this License for that Work shall terminate\r
+      as of the date such litigation is filed.\r
+\r
+   4. Redistribution. You may reproduce and distribute copies of the\r
+      Work or Derivative Works thereof in any medium, with or without\r
+      modifications, and in Source or Object form, provided that You\r
+      meet the following conditions:\r
+\r
+      (a) You must give any other recipients of the Work or\r
+          Derivative Works a copy of this License; and\r
+\r
+      (b) You must cause any modified files to carry prominent notices\r
+          stating that You changed the files; and\r
+\r
+      (c) You must retain, in the Source form of any Derivative Works\r
+          that You distribute, all copyright, patent, trademark, and\r
+          attribution notices from the Source form of the Work,\r
+          excluding those notices that do not pertain to any part of\r
+          the Derivative Works; and\r
+\r
+      (d) If the Work includes a "NOTICE" text file as part of its\r
+          distribution, then any Derivative Works that You distribute must\r
+          include a readable copy of the attribution notices contained\r
+          within such NOTICE file, excluding those notices that do not\r
+          pertain to any part of the Derivative Works, in at least one\r
+          of the following places: within a NOTICE text file distributed\r
+          as part of the Derivative Works; within the Source form or\r
+          documentation, if provided along with the Derivative Works; or,\r
+          within a display generated by the Derivative Works, if and\r
+          wherever such third-party notices normally appear. The contents\r
+          of the NOTICE file are for informational purposes only and\r
+          do not modify the License. You may add Your own attribution\r
+          notices within Derivative Works that You distribute, alongside\r
+          or as an addendum to the NOTICE text from the Work, provided\r
+          that such additional attribution notices cannot be construed\r
+          as modifying the License.\r
+\r
+      You may add Your own copyright statement to Your modifications and\r
+      may provide additional or different license terms and conditions\r
+      for use, reproduction, or distribution of Your modifications, or\r
+      for any such Derivative Works as a whole, provided Your use,\r
+      reproduction, and distribution of the Work otherwise complies with\r
+      the conditions stated in this License.\r
+\r
+   5. Submission of Contributions. Unless You explicitly state otherwise,\r
+      any Contribution intentionally submitted for inclusion in the Work\r
+      by You to the Licensor shall be under the terms and conditions of\r
+      this License, without any additional terms or conditions.\r
+      Notwithstanding the above, nothing herein shall supersede or modify\r
+      the terms of any separate license agreement you may have executed\r
+      with Licensor regarding such Contributions.\r
+\r
+   6. Trademarks. This License does not grant permission to use the trade\r
+      names, trademarks, service marks, or product names of the Licensor,\r
+      except as required for reasonable and customary use in describing the\r
+      origin of the Work and reproducing the content of the NOTICE file.\r
+\r
+   7. Disclaimer of Warranty. Unless required by applicable law or\r
+      agreed to in writing, Licensor provides the Work (and each\r
+      Contributor provides its Contributions) on an "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
+      implied, including, without limitation, any warranties or conditions\r
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
+      PARTICULAR PURPOSE. You are solely responsible for determining the\r
+      appropriateness of using or redistributing the Work and assume any\r
+      risks associated with Your exercise of permissions under this License.\r
+\r
+   8. Limitation of Liability. In no event and under no legal theory,\r
+      whether in tort (including negligence), contract, or otherwise,\r
+      unless required by applicable law (such as deliberate and grossly\r
+      negligent acts) or agreed to in writing, shall any Contributor be\r
+      liable to You for damages, including any direct, indirect, special,\r
+      incidental, or consequential damages of any character arising as a\r
+      result of this License or out of the use or inability to use the\r
+      Work (including but not limited to damages for loss of goodwill,\r
+      work stoppage, computer failure or malfunction, or any and all\r
+      other commercial damages or losses), even if such Contributor\r
+      has been advised of the possibility of such damages.\r
+\r
+   9. Accepting Warranty or Additional Liability. While redistributing\r
+      the Work or Derivative Works thereof, You may choose to offer,\r
+      and charge a fee for, acceptance of support, warranty, indemnity,\r
+      or other liability obligations and/or rights consistent with this\r
+      License. However, in accepting such obligations, You may act only\r
+      on Your own behalf and on Your sole responsibility, not on behalf\r
+      of any other Contributor, and only if You agree to indemnify,\r
+      defend, and hold each Contributor harmless for any liability\r
+      incurred by, or claims asserted against, such Contributor by reason\r
+      of your accepting any such warranty or additional liability.\r
+\r
+   END OF TERMS AND CONDITIONS\r
+\r
+   APPENDIX: How to apply the Apache License to your work.\r
+\r
+      To apply the Apache License to your work, attach the following\r
+      boilerplate notice, with the fields enclosed by brackets "[]"\r
+      replaced with your own identifying information. (Don't include\r
+      the brackets!)  The text should be enclosed in the appropriate\r
+      comment syntax for the file format. We also recommend that a\r
+      file or class name and description of purpose be included on the\r
+      same "printed page" as the copyright notice for easier\r
+      identification within third-party archives.\r
+\r
+   Copyright [yyyy] [name of copyright owner]\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
+\r
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100644 (file)
index 0000000..c260a37
--- /dev/null
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+  Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. 
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/NOTICE b/NOTICE
new file mode 100644 (file)
index 0000000..b616854
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,3 @@
+Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE.APLv2 file for Apache License terms and conditions.
diff --git a/clean.sh b/clean.sh
new file mode 100755 (executable)
index 0000000..06dff1f
--- /dev/null
+++ b/clean.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+echo Performing clean
+
+function clean {
+               rm -rf CMakeCache.txt
+               rm -rf CMakeFiles
+               rm -rf cmake_install.cmake
+               rm -rf Makefile
+               rm -rf install_manifest.txt                     
+               rm -rf *.so
+
+               for i in `ls`; do
+                       if [ -d $i ]; then
+                               cd $i;
+                               clean;
+                               cd ..
+                       fi
+               done    
+       }
+
+       clean
+
+
+
diff --git a/config.dtd b/config.dtd
new file mode 100644 (file)
index 0000000..f1a1de4
--- /dev/null
@@ -0,0 +1,32 @@
+<!ELEMENT plugin-properties (library-name, feature-install-uri?,
+  feature-key-cn?, feature-root-cn?,
+  feature-root-fingerprint?, feature-set*, api-feature+) >
+
+<!ELEMENT library-name (#PCDATA)>
+
+<!ELEMENT feature-set (api-feature-ref+)>
+<!ATTLIST feature-set name CDATA #REQUIRED >
+
+<!ELEMENT api-feature-ref EMPTY>
+<!ATTLIST api-feature-ref name CDATA #REQUIRED >
+
+<!ELEMENT api-feature (name, device-capability*, Object*, Function*, Property* )>
+
+<!ELEMENT name (#PCDATA) >
+<!ELEMENT device-capability (#PCDATA )>
+
+<!ELEMENT Object (Function*, Property*)>
+<!ATTLIST Object name CDATA #REQUIRED >
+
+<!ELEMENT Function (#PCDATA )>
+<!ATTLIST Function name CDATA #REQUIRED >
+<!ATTLIST Function restricted CDATA #IMPLIED >
+
+<!ELEMENT Property (#PCDATA )>
+
+
+<!ELEMENT feature-install-uri (#PCDATA)>
+<!ELEMENT feature-key-cn (#PCDATA)>
+<!ELEMENT feature-root-cn (#PCDATA)>
+<!ELEMENT feature-root-fingerprint (#PCDATA)>
+
diff --git a/debian_DEPRECATED/changelog b/debian_DEPRECATED/changelog
new file mode 100644 (file)
index 0000000..d7ecb7d
--- /dev/null
@@ -0,0 +1,1198 @@
+wrt-plugins-tizen (0.2.99) unstable; urgency=low
+
+  * Bug fix on Bluetooth, Push, Calendar, NFC and FileSystem
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.99
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 19 Nov 2012 17:25:29 +0900
+
+wrt-plugins-tizen (0.2.98) unstable; urgency=low
+
+  * Bug fix on Calendar and AllShare
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.98
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 13 Nov 2012 22:05:56 +0900
+
+wrt-plugins-tizen (0.2.97) unstable; urgency=low
+
+  * Bug fix on Calendar and Bluetooth
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.97
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 08 Nov 2012 16:10:22 +0900
+
+wrt-plugins-tizen (0.2.96) unstable; urgency=low
+
+  * Bug fix on Messaging, TimeUtil, Filesystem, Application etc.
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.96
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 07 Nov 2012 20:15:31 +0900
+
+wrt-plugins-tizen (0.2.95) unstable; urgency=low
+
+  * Bug fix on Application, Push, Download etc.
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.95
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 01 Nov 2012 18:18:59 +0900
+
+wrt-plugins-tizen (0.2.94) unstable; urgency=low
+
+  * Change spec for Application
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.94
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 29 Oct 2012 11:22:07 +0900
+
+wrt-plugins-tizen (0.2.93) unstable; urgency=low
+
+  * Bug fix on Contact
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.93
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 24 Oct 2012 16:08:38 +0900
+
+wrt-plugins-tizen (0.2.92) unstable; urgency=low
+
+  * Bug fix on Messaging, TimeUtil and Contact
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.92
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 22 Oct 2012 16:45:17 +0900
+
+wrt-plugins-tizen (0.2.91) unstable; urgency=low
+
+  * Bug fix on Messaging, Alarm and Contact
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.91
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 19 Oct 2012 18:48:45 +0900
+
+wrt-plugins-tizen (0.2.90) unstable; urgency=low
+
+  * Change on Alarm
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.90
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 11 Oct 2012 15:37:52 +0900
+
+wrt-plugins-tizen (0.2.89) unstable; urgency=low
+
+  * Bug fix on Messaging.
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.89
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 09 Oct 2012 21:10:40 +0900
+
+wrt-plugins-tizen (0.2.88) unstable; urgency=low
+
+  * Bug fix on MediaContent, SecureElement, Messaging and Application.
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.88
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 05 Oct 2012 13:51:51 +0900
+
+wrt-plugins-tizen (0.2.87) unstable; urgency=low
+
+  * Bug fix on Messaging, Time, NFC, SystemInfo, MediaContent etc.
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.87
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 27 Sep 2012 22:05:11 +0900
+
+wrt-plugins-tizen (0.2.86) unstable; urgency=low
+
+  * Bug fix on Contact and TimeUtil
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.86
+
+ -- Taehee Lee <th219.lee@samsung.com>  Sat, 22 Sep 2012 16:51:01 +0900
+
+wrt-plugins-tizen (0.2.85) unstable; urgency=low
+
+  * Bug fix on Application
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.85
+
+ -- Dongjin Choi <milkelf.choi@samsung.com>  Sun, 16 Sep 2012 15:20:42 +0900
+
+wrt-plugins-tizen (0.2.84) unstable; urgency=low
+
+  * Bug fix on Application
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.84
+
+ -- Kisub Song <kisubs.song@samsung.com>  Sat, 15 Sep 2012 23:14:41 +0900
+
+wrt-plugins-tizen (0.2.83) unstable; urgency=low
+
+  * Bug fix on Application
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.83
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 12 Sep 2012 09:29:30 +0900
+
+wrt-plugins-tizen (0.2.82) unstable; urgency=low
+
+  * Bug fix on Calendar and TimeUtil
+  * Git : framework/web/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.82
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 11 Sep 2012 18:29:57 +0900
+
+wrt-plugins-tizen (0.2.81) unstable; urgency=low
+
+  * Bug fix on Device, Contact
+  * git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.81
+
+ -- Siwoo Lee <siwoo0.lee@samsung.com>  Sat, 08 Sep 2012 16:41:49 +0900
+
+wrt-plugins-tizen (0.2.80) unstable; urgency=low
+
+  * Bug fix on Systeminfo
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.80
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 07 Sep 2012 16:39:48 +0900
+
+wrt-plugins-tizen (0.2.79) unstable; urgency=low
+
+  * Bug fix on MediaContent
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.79
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 06 Sep 2012 13:57:59 +0900
+
+wrt-plugins-tizen (0.2.78) unstable; urgency=low
+
+  * Bug fix on LBS, Time and Alarm
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.78
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 05 Sep 2012 22:42:24 +0900
+
+wrt-plugins-tizen (0.2.77) unstable; urgency=low
+
+  * Bug fix on Power and MediaContent
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.77
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 04 Sep 2012 13:57:20 +0900
+
+wrt-plugins-tizen (0.2.76) unstable; urgency=low
+
+  * Bug fix on Power and MediaContent
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.76
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 03 Sep 2012 21:50:35 +0900
+
+wrt-plugins-tizen (0.2.75) unstable; urgency=low
+
+  * Bug fix on Messaging, Download, Systeminfo and Contact
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.75
+
+ -- Kisub Song <kisubs.song@samsung.com>  Sat, 01 Sep 2012 00:10:05 +0900
+
+wrt-plugins-tizen (0.2.74) unstable; urgency=low
+
+  * Bug fix on Messaging
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.74
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 29 Aug 2012 10:59:18 +0900
+
+wrt-plugins-tizen (0.2.73) unstable; urgency=low
+
+  * Bug fix on Messaging
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.73
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 28 Aug 2012 18:37:01 +0900
+
+wrt-plugins-tizen (0.2.72) unstable; urgency=low
+
+  * Bug fix on Messaging, Notification, Alarm, LBS and Contact
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.72
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 27 Aug 2012 19:36:19 +0900
+
+wrt-plugins-tizen (0.2.71) unstable; urgency=low
+
+  * Bug fix on Messaging, Calendar, Notification, Download, Contact, Filesystem and Application
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.71
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 24 Aug 2012 23:17:34 +0900
+
+wrt-plugins-tizen (0.2.70) unstable; urgency=low
+
+  * Bug fix on MediaContent, Application, Device and SystemInfo
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.70
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 23 Aug 2012 18:38:20 +0900
+
+wrt-plugins-tizen (0.2.69) unstable; urgency=low
+
+  * Fix Call, Notification, Messaging, Device, Application, Alarm, LBS and
+    Download Bug
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.69
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 22 Aug 2012 18:23:37 +0900
+
+wrt-plugins-tizen (0.2.68) unstable; urgency=low
+
+  * Fix Messaging, Alarm and Contact
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.68
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 20 Aug 2012 20:18:55 +0900
+
+wrt-plugins-tizen (0.2.67) unstable; urgency=low
+
+  * Fix Systeminfo bug
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.67
+
+ -- Si-Woo Lee <siwoo0.lee@samsung.com>  Fri, 17 Aug 2012 23:13:07 +0900
+
+wrt-plugins-tizen (0.2.66) unstable; urgency=low
+
+  * Fix Download, Messaging, Calendar bug
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.65
+
+ -- Taehee Lee <th219.lee@samsung.com>  Fri, 17 Aug 2012 21:41:47 +0900
+
+wrt-plugins-tizen (0.2.65) unstable; urgency=low
+
+  * Fix Messaging bug
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.65
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 17 Aug 2012 01:05:46 +0900
+
+wrt-plugins-tizen (0.2.64) unstable; urgency=low
+
+  * Fix MediaContent bug
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.64
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 16 Aug 2012 23:45:14 +0900
+
+wrt-plugins-tizen (0.2.63) unstable; urgency=low
+
+  * Fix Messaging, Contact, MediaContent, Download and Power bug
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.63
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 16 Aug 2012 22:41:06 +0900
+
+wrt-plugins-tizen (0.2.62) unstable; urgency=low
+
+  * Fix Messaging, Calendar and Download bug
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.62
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 14 Aug 2012 19:49:53 +0900
+
+wrt-plugins-tizen (0.2.61) unstable; urgency=low
+
+  * Fix Systeminfo bug
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.61
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 13 Aug 2012 22:56:16 +0900
+
+wrt-plugins-tizen (0.2.60) unstable; urgency=low
+
+  * Fix MediaContent bug, and etc.
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.60
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 10 Aug 2012 20:31:03 +0900
+
+wrt-plugins-tizen (0.2.59) unstable; urgency=low
+
+  * Change dependency to ewebkit2 fro ewebkit
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.59
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 09 Aug 2012 17:01:09 +0900
+
+wrt-plugins-tizen (0.2.58) unstable; urgency=low
+
+  * Fix Application and Download bug
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.58
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 08 Aug 2012 18:35:39 +0900
+
+wrt-plugins-tizen (0.2.57) unstable; urgency=low
+
+  * Apply new telephony API
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.57
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 08 Aug 2012 16:32:52 +0900
+
+wrt-plugins-tizen (0.2.56) unstable; urgency=low
+
+  * Apply new email-service API. Apply new appID policy.
+  * Bug fix on Systeminfo, MediaContent
+  * Initial commit for Notification
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.56
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 08 Aug 2012 10:02:01 +0900
+
+wrt-plugins-tizen (0.2.55) unstable; urgency=low
+
+  * Remove AllShare
+  * Apply new msg-service API
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.55
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 07 Aug 2012 14:01:19 +0900
+
+wrt-plugins-tizen (0.2.54) unstable; urgency=low
+
+  * Bug fix Call, Application and Messaging
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.54
+
+ -- Dongjin Choi <milkelf.choi@samsung.com>  Fri, 03 Aug 2012 17:56:57 +0900
+
+wrt-plugins-tizen (0.2.53) unstable; urgency=low
+
+  * Bug fix on SecureElement, Filesystem, Systeminfo and Application
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.53
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 31 Jul 2012 18:33:27 +0900
+
+wrt-plugins-tizen (0.2.52) unstable; urgency=low
+
+  * Bug fix on Bluetoot, NFC, Calendar, Messaging and Application
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.52
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 26 Jul 2012 19:29:27 +0900
+
+wrt-plugins-tizen (0.2.51) unstable; urgency=low
+
+  * Bug fix on NFC, Systeminfo and MediaContent
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.51
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 23 Jul 2012 21:01:54 +0900
+
+wrt-plugins-tizen (0.2.50) unstable; urgency=low
+
+  * Bug fix on Power, Application, Calendar, Call and SystemInfo
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.50
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 19 Jul 2012 11:59:16 +0900
+
+wrt-plugins-tizen (0.2.49) unstable; urgency=low
+
+  * Bug fix on Contact, Alarm, Application, NFC and MediaContent
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.49
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 17 Jul 2012 21:46:22 +0900
+
+wrt-plugins-tizen (0.2.48) unstable; urgency=low
+
+  * Bug fix on Calendar
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.48
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 09 Jul 2012 17:31:38 +0900
+
+wrt-plugins-tizen (0.2.47) unstable; urgency=low
+
+  * Application, Calendar, Systeminfo update
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.47
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 06 Jul 2012 09:14:45 +0900
+
+wrt-plugins-tizen (0.2.46) unstable; urgency=low
+
+  * Fix Calendar and Contact
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.46
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 04 Jul 2012 13:45:56 +0900
+
+wrt-plugins-tizen (0.2.45) unstable; urgency=low
+
+  * Apply new calendar api.
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.45
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 02 Jul 2012 11:48:13 +0900
+
+wrt-plugins-tizen (0.2.44) unstable; urgency=low
+
+  * Systeminfo, Messaging, POI, Power, Filesystem etc. Spec changed.
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.44
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 26 Jun 2012 17:28:54 +0900
+
+wrt-plugins-tizen (0.2.43) unstable; urgency=low
+
+  * NFC, Bluetooth, Calendar Bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.43
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 21 Jun 2012 13:42:44 +0900
+
+wrt-plugins-tizen (0.2.42) unstable; urgency=low
+
+  * Remove unresolved symbols.
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.42
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 04 Jun 2012 16:32:16 +0900
+
+wrt-plugins-tizen (0.2.41) unstable; urgency=low
+
+  * Contact, Application, AllShare bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.41
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 31 May 2012 23:11:59 +0900
+
+wrt-plugins-tizen (0.2.40) unstable; urgency=low
+
+  * Minor version update
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.40
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 25 May 2012 14:26:25 +0900
+
+wrt-plugins-tizen (0.2.39) unstable; urgency=low
+
+  * Allshare, Messaging, Time bug fix
+  * Apply WRT API change for iframe
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.39
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 24 May 2012 18:05:21 +0900
+
+wrt-plugins-tizen (0.2.38) unstable; urgency=low
+
+  * SecureStorage, Calendar, Messaging changed 
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.38
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Mon, 21 May 2012 09:11:25 +0900
+
+wrt-plugins-tizen (0.2.37) unstable; urgency=low
+
+  * add Allshare Module. Fix scheem callback bug
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.37
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Mon, 14 May 2012 16:50:23 +0900
+
+wrt-plugins-tizen (0.2.36) unstable; urgency=low
+
+  * Application, Messaging, Alarm Bugfix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.36
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 10 May 2012 17:15:42 +0900
+
+wrt-plugins-tizen (0.2.35) unstable; urgency=low
+
+  * Scheme callback function changed - orientation, application exit
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.35
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Mon, 07 May 2012 16:07:22 +0900
+
+wrt-plugins-tizen (0.2.34) unstable; urgency=low
+
+  * Messaging Bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.34
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 04 May 2012 16:14:14 +0900
+
+wrt-plugins-tizen (0.2.33) unstable; urgency=low
+
+  * [Calendar&Filter] Fix timezone conversion bugs: all time values converted from JS layer is based on UTC.
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.33
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 03 May 2012 15:16:49 +0900
+
+wrt-plugins-tizen (0.2.32) unstable; urgency=low
+
+  * Calendar, Contact Bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.32
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 26 Apr 2012 18:25:11 +0900
+
+wrt-plugins-tizen (0.2.31) unstable; urgency=low
+
+  * NFC Bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.31
+
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Mon, 23 Apr 2012 18:29:52 +0900
+
+wrt-plugins-tizen (0.2.30) unstable; urgency=low
+
+  * Fix Message build break
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.30
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Mon, 23 Apr 2012 17:04:31 +0900
+
+wrt-plugins-tizen (0.2.29) unstable; urgency=low
+
+  * Fix Application module bug
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.29
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Sun, 22 Apr 2012 20:15:07 +0900
+
+wrt-plugins-tizen (0.2.28) unstable; urgency=low
+
+  * Fix bug on BT, Calendar, Messaging and NFC
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.28
+
+ -- Kisub Song <kisubs.song@samsung.net>  Sat, 21 Apr 2012 19:48:50 +0900
+
+wrt-plugins-tizen (0.2.27) unstable; urgency=low
+
+  * Bug patch for Calendar API
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.27
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 20 Apr 2012 16:49:49 +0900
+
+wrt-plugins-tizen (0.2.26) unstable; urgency=low
+
+  * Apply API change on calendar-svc
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.26
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 20 Apr 2012 14:44:32 +0900
+
+wrt-plugins-tizen (0.2.25) unstable; urgency=low
+
+  * Fix bug on MediaContent
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.25
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 19 Apr 2012 16:44:55 +0900
+
+wrt-plugins-tizen (0.2.24) unstable; urgency=low
+
+  * Fix bug on MediaContent and Sensor
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.24
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 19 Apr 2012 14:59:55 +0900
+
+wrt-plugins-tizen (0.2.23) unstable; urgency=low
+
+  * Fix bug on Filesystem and Call
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.23
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 16 Apr 2012 22:43:00 +0900
+
+wrt-plugins-tizen (0.2.22) unstable; urgency=low
+
+  * Fix TC Bug on Contact, Calendar and Geocoder
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.22
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 16 Apr 2012 18:42:19 +0900
+
+wrt-plugins-tizen (0.2.21) unstable; urgency=low
+
+  * Raise version for public merge
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.21
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 12 Apr 2012 19:20:34 +0900
+
+wrt-plugins-tizen (0.2.20) unstable; urgency=low
+
+  * Bug fix on Calendar and Filesystem
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.20
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 12 Apr 2012 16:36:40 +0900
+
+wrt-plugins-tizen (0.2.19) unstable; urgency=low
+
+  * NFC, Calendar, MediaContents bugfix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.19
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Mon, 09 Apr 2012 15:12:23 +0900
+
+wrt-plugins-tizen (0.2.18) unstable; urgency=low
+
+  * Bug fix on NFC
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.18
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 06 Apr 2012 13:44:40 +0900
+
+wrt-plugins-tizen (0.2.17) unstable; urgency=low
+
+  * Bug fix on Application and Calendar
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.17
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 06 Apr 2012 13:27:41 +0900
+
+wrt-plugins-tizen (0.2.16) unstable; urgency=low
+
+  * Change WebAPIError
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.16
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 05 Apr 2012 17:12:29 +0900
+
+wrt-plugins-tizen (0.2.15) unstable; urgency=low
+
+  * Apply spec change on NFC
+  * Bug fix on Filesystem, Systeminfo and Application
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.15
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 05 Apr 2012 15:08:18 +0900
+
+wrt-plugins-tizen (0.2.14) unstable; urgency=low
+
+  * Bug fix on Calendar.
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.14
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 04 Apr 2012 16:54:51 +0900
+
+wrt-plugins-tizen (0.2.13) unstable; urgency=low
+
+  * Bug fix on NFC, Messaging, Bluetooth, MediaContent
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.13
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 03 Apr 2012 12:21:53 +0900
+
+wrt-plugins-tizen (0.2.12) unstable; urgency=low
+
+  * Contact, Calendar, Geocoder bug fix.
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.12
+
+ -- Kisub Song <kisubs.song@samsung.com>  Tue, 03 Apr 2012 00:05:59 +0900
+
+wrt-plugins-tizen (0.2.11) unstable; urgency=low
+
+  * POI, SystemInfo bug fix.
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.11
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 30 Mar 2012 14:48:39 +0900
+
+wrt-plugins-tizen (0.2.10) unstable; urgency=low
+
+  * Bug fix - Bluetooth, POI
+  * Remove PendingOperation
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.10
+
+ -- Kisub Song <kisubs.song@samsung.com>  Thu, 29 Mar 2012 15:59:32 +0900
+
+wrt-plugins-tizen (0.2.9) unstable; urgency=low
+
+  * Messaging error fix.
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.9
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 28 Mar 2012 16:44:48 +0900
+
+wrt-plugins-tizen (0.2.8) unstable; urgency=low
+
+  * Remove Account code from Call
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.8
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 28 Mar 2012 15:42:33 +0900
+
+wrt-plugins-tizen (0.2.7) unstable; urgency=low
+
+  * NFC, MediaContent applied new API style.
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.7
+
+ -- Kisub Song <kisubs.song@samsung.com>  Wed, 28 Mar 2012 13:46:22 +0900
+
+wrt-plugins-tizen (0.2.6) unstable; urgency=low
+
+  * POI Changed
+  * Apply new API styles
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.6
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 26 Mar 2012 22:47:36 +0900
+
+wrt-plugins-tizen (0.2.5) unstable; urgency=low
+
+  * Update Test Cases
+  * Bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.5
+
+ -- Kisub Song <kisubs.song@samsung.com>  Mon, 26 Mar 2012 12:03:53 +0900
+
+wrt-plugins-tizen (0.2.4) unstable; urgency=low
+
+  * NFC undated
+  * Argument checking rule changed
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.4
+
+ -- Kisub Song <kisubs.song@samsung.com>  Fri, 23 Mar 2012 13:19:16 +0900
+
+wrt-plugins-tizen (0.2.3) unstable; urgency=low
+
+  * Messaging, Time bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.3
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Wed, 21 Mar 2012 15:24:57 +0900
+
+wrt-plugins-tizen (0.2.2) unstable; urgency=low
+
+  * LBS, Messaging bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.2
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 20 Mar 2012 14:05:13 +0900
+
+wrt-plugins-tizen (0.2.1) unstable; urgency=low
+
+  * Change APIs to SEC style
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.1
+
+
+ -- Taehee Lee <th219.lee@samsung.com>  Fri, 16 Mar 2012 22:54:12 +0900
+
+wrt-plugins-tizen (0.2.0-20) unstable; urgency=low
+
+  * Change APIs to SEC style
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-20
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 15 Mar 2012 11:11:57 +0900
+
+wrt-plugins-tizen (0.2.0-19) unstable; urgency=low
+
+  * Apply changed interfaces regarding plugins start function and security check
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-19
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Wed, 14 Mar 2012 16:46:13 +0900
+
+wrt-plugins-tizen (0.2.0-18) unstable; urgency=low
+
+  * fix NFC Build error
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-18
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 13 Mar 2012 10:48:47 +0900
+
+wrt-plugins-tizen (0.2.0-17) unstable; urgency=low
+
+  * Call, Calendar bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-17
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Fri, 02 Mar 2012 15:41:29 +0900
+
+wrt-plugins-tizen (0.2.0-16) unstable; urgency=low
+
+  * fix build error. change dpl-efl dependency version
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-16
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Wed, 29 Feb 2012 14:55:06 +0900
+
+wrt-plugins-tizen (0.2.0-15) unstable; urgency=low
+
+  * Filesystem, Messaging, Mediacontents bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-15
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 28 Feb 2012 19:19:46 +0900
+
+wrt-plugins-tizen (0.2.0-14) unstable; urgency=low
+
+  * Apply wrt chages. remove plugins APIs
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-14
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Mon, 27 Feb 2012 11:09:30 +0900
+
+wrt-plugins-tizen (0.2.0-13) unstable; urgency=low
+
+  * Alarm bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-13
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Fri, 24 Feb 2012 10:23:20 +0900
+
+wrt-plugins-tizen (0.2.0-12) unstable; urgency=low
+
+  * Messaging and Calendar bug fix 
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-12
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 23 Feb 2012 15:07:02 +0900
+
+wrt-plugins-tizen (0.2.0-11) unstable; urgency=low
+
+  * Systeminfo bug fix 
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-11
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Wed, 22 Feb 2012 19:16:34 +0900
+
+wrt-plugins-tizen (0.2.0-10) unstable; urgency=low
+
+  * Callhistory bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-10
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Wed, 22 Feb 2012 16:13:04 +0900
+
+wrt-plugins-tizen (0.2.0-9) unstable; urgency=low
+
+  * Rangefilter bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-9
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Wed, 22 Feb 2012 15:20:31 +0900
+
+wrt-plugins-tizen (0.2.0-8) unstable; urgency=low
+
+  * Fix calendar build error
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-8
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Wed, 22 Feb 2012 13:55:22 +0900
+
+wrt-plugins-tizen (0.2.0-7) unstable; urgency=low
+
+  * applied Messaging service new API & function
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-7
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 21 Feb 2012 17:44:20 +0900
+
+wrt-plugins-tizen (0.2.0-6) unstable; urgency=low
+
+  * Application bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-6
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 21 Feb 2012 17:39:08 +0900
+
+wrt-plugins-tizen (0.2.0-5) unstable; urgency=low
+
+  * fix Calendar error
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-5
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 21 Feb 2012 12:01:28 +0900
+
+wrt-plugins-tizen (0.2.0-4) unstable; urgency=low
+
+  * Contact, Call, MediaContent bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-4
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 21 Feb 2012 10:38:25 +0900
+
+wrt-plugins-tizen (0.2.0-3) unstable; urgency=low
+
+  * update call api
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-3
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Fri, 17 Feb 2012 20:31:20 +0900
+
+wrt-plugins-tizen (0.2.0-2) unstable; urgency=low
+
+  * Add new Mediacontents APIs, Change createJSObject function to public
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-2
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Fri, 17 Feb 2012 16:28:39 +0900
+
+wrt-plugins-tizen (0.2.0-1) unstable; urgency=low
+
+  * Seperate common files to independent module
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-1
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 16 Feb 2012 12:19:32 +0900
+
+wrt-plugins-tizen (0.2.0-0) unstable; urgency=low
+
+  * prepare beta release
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.2.0-0
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Fri, 03 Feb 2012 16:37:23 +0900
+
+wrt-plugins-tizen (0.1.2-16) unstable; urgency=low
+
+  * wrt chanaging apply
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-16
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 02 Feb 2012 17:50:39 +0900
+
+wrt-plugins-tizen (0.1.2-15) unstable; urgency=low
+
+  * add Acount module, Message bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-15
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 02 Feb 2012 10:46:56 +0900
+
+wrt-plugins-tizen (0.1.2-14) unstable; urgency=low
+
+  * wrt-common changing apply
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-14
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Fri, 27 Jan 2012 17:39:02 +0900
+
+wrt-plugins-tizen (0.1.2-13) unstable; urgency=low
+
+  * wrt-plugins-common changing apply
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-13
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Mon, 16 Jan 2012 20:18:12 +0900
+
+wrt-plugins-tizen (0.1.2-12) unstable; urgency=low
+
+  * apply msg-service changing
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-12
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 12 Jan 2012 18:48:27 +0900
+
+wrt-plugins-tizen (0.1.2-11) oneiric; urgency=low
+
+  * Contact photoURI bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-11
+
+ -- Taehee Lee <th219.lee@samsung.com>  Fri, 06 Jan 2012 19:02:29 +0900
+
+wrt-plugins-tizen (0.1.2-10) unstable; urgency=low
+
+  * Application, Contact bug fix. UnitTest update
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-10
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 05 Jan 2012 13:50:04 +0900
+
+wrt-plugins-tizen (0.1.2-9) unstable; urgency=low
+  
+  * Calendar bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-9
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 29 Dec 2011 17:51:34 +0900
+
+wrt-plugins-tizen (0.1.2-8) unstable; urgency=low
+
+  * Canlendar, Application, NFC bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-8
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Wed, 28 Dec 2011 19:04:55 +0900
+
+wrt-plugins-tizen (0.1.2-7) unstable; urgency=low
+
+  * Sensor, Message, NFC, bug fix and enable FileSystem
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-7
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 27 Dec 2011 14:43:01 +0900
+
+wrt-plugins-tizen (0.1.2-6) unstable; urgency=low
+
+  * Bluetooth bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-6
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Fri, 23 Dec 2011 11:53:23 +0900
+
+wrt-plugins-tizen (0.1.2-5) unstable; urgency=low
+
+  * NFC, Message, Bluetooth bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-5
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 22 Dec 2011 17:15:00 +0900
+
+wrt-plugins-tizen (0.1.2-4) unstable; urgency=low
+
+  * Contact, Filesystem bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-4
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Wed, 21 Dec 2011 19:04:21 +0900
+
+wrt-plugins-tizen (0.1.2-3) unstable; urgency=low
+
+  * NFC, Messaging, Time bug fix
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-3
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 20 Dec 2011 17:45:38 +0900
+
+wrt-plugins-tizen (0.1.2-2) unstable; urgency=low
+
+  * add acount features property
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-2
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 20 Dec 2011 10:42:58 +0900
+
+wrt-plugins-tizen (0.1.2-1) unstable; urgency=low
+
+  * Enable Sensor module
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-1
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Mon, 19 Dec 2011 16:31:25 +0900
+
+wrt-plugins-tizen (0.1.2-0) unstable; urgency=low
+
+  * first private package
+  * Git : slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.2-0
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Mon, 19 Dec 2011 10:48:25 +0900
+
+wrt-plugins-tizen (0.1.1-5) unstable; urgency=low
+
+  * apply wrt name changing
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.1-5
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 08 Dec 2011 16:33:59 +0900
+
+wrt-plugins-tizen (0.1.1-4) unstable; urgency=low
+
+  *  revert package name changing
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.1-4
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Wed, 07 Dec 2011 20:07:24 +0900
+
+wrt-plugins-tizen (0.1.1-3) unstable; urgency=low
+
+  * merge slp-webapi
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.1-3
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 06 Dec 2011 21:56:13 +0900
+
+wrt-plugins-tizen (0.1.1-2) unstable; urgency=low
+
+  * add boiler plate
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.1-2
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Tue, 06 Dec 2011 15:39:58 +0900
+
+wrt-plugins-tizen (0.1.1-1) unstable; urgency=low
+
+  * add capi-network-nfc-dev
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.1-1
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 01 Dec 2011 17:53:42 +0900
+
+wrt-plugins-tizen (0.1.1-0) unstable; urgency=low
+
+  * inital upload new git repository
+  * Git : 165.213.180.234:slp/pkgs/w/wrt-plugins-tizen
+  * Tag : wrt-plugins-tizen_0.1.1-0
+
+
+
+ -- Sangtai Kim <sangtai.kim@samsung.com>  Thu, 01 Dec 2011 14:04:56 +0900
+
diff --git a/debian_DEPRECATED/compat b/debian_DEPRECATED/compat
new file mode 100755 (executable)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian_DEPRECATED/control b/debian_DEPRECATED/control
new file mode 100755 (executable)
index 0000000..48af26e
--- /dev/null
@@ -0,0 +1,18 @@
+Source: wrt-plugins-tizen
+Section: devel
+Priority: extra
+Maintainer: Taehee Lee <th219.lee@samsung.com>, Sangtai Kim <sangtai.kim@samsung.com>, Jaehyun Park <jaehyun77.park@samsung.com>, KeeDuck Kim <keeduck.kim@samsung.com>, Kisub Song <kisubs.song@samsung.com>
+Build-Depends: debhelper (>= 5), wrt-commons-dev (>=0.2.6), libwebkit-engine-dev, capi-location-manager-dev, capi-location-geocoder-dev, libmm-camcorder-dev, capi-network-bluetooth-dev, capi-appfw-app-manager-dev, capi-appfw-application-dev, libslp-calendar-dev, capi-system-sensor-dev, libappsvc-dev, email-service-dev, libslp-msg-service-dev (>=0.5.0), capi-telephony-call-dev, libicu-dev, libnetwork-dev, libslp-setting-dev, libdevman-dev, capi-social-call-log-dev, libdownload-agent-dev,libaccounts-svc-dev , libslp-tapi-dev, wrt-plugins-common-dev (>=0.3.17), capi-network-nfc-dev, libaul-1-dev, libmm-fileinfo-dev, libcontacts-service-dev, capi-system-power-dev, capi-system-device-dev, smartcard-service-dev, smartcard-service-common-dev, libss-client-dev, capi-location-poi-dev, capi-location-route-dev
+Uploaders: Sangtai Kim <sangtai.kim@samsung.com>, Kisub Song <kisubs.song@samsung.com>
+
+Package: wrt-plugins-tizen
+Architecture: any
+Section: libs
+Depends: ${shlibs:Depends}, ${misc:Depends}, wrt-commons (>=0.2.6), wrt-plugins-common (>=0.3.17)
+Description: JavaScript plugins for WebRuntime
+
+Package: wrt-plugins-tizen-dbg
+Architecture: any
+Section: debug
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: JavaScript plugins for WebRuntime - debug
diff --git a/debian_DEPRECATED/rules b/debian_DEPRECATED/rules
new file mode 100755 (executable)
index 0000000..15d7a3b
--- /dev/null
@@ -0,0 +1,135 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+
+# These are used for cross-compiling and for saving the configure script
+# from having to guess our platform (since we know it already)
+DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+
+CFLAGS ?= -Wall -g -fvisibility=hidden -fPIC
+CXXFLAGS ?=  -Wall -g -fPIC
+PREFIX ?= /usr/lib/wrt-plugins
+CONFIG_DTD ?= /usr/etc/tizen-apis
+DATADIR ?= /opt
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+       CFLAGS += -O0
+       CXXFLAGS += -O0
+else
+       CFLAGS += -O2
+       CXXFLAGS += -O2
+endif
+
+ifeq (,$(findstring no,$(DPL_LOG)))
+       DPL_LOGS_STATUS = "ON"
+else
+       DPL_LOGS_STATUS = "OFF"
+endif
+
+LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed -Wl,--hash-style=both# -Wl,--version-script=$(CURDIR)/wrt-plugins.map
+
+ifdef DEVPKG
+       CMAKEFLAGS += -DDEVPKG="$(DEVPKG)"
+endif
+
+configure: configure-stamp
+configure-stamp:
+               dh_testdir
+               # Add here commands to configure the package.
+               CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" cmake . -DCMAKE_INSTALL_PREFIX=$(PREFIX) $(CMAKEFLAGS) -DDPL_LOG=$(DPL_LOGS_STATUS) -DCMAKE_BUILD_TYPE="$(BUILD_TYPE)" 
+                       touch configure-stamp
+                        
+build: build-stamp
+
+build-stamp:  configure-stamp
+       dh_testdir
+
+       # Add here commands to compile the package.
+       $(MAKE) -j9 -l2.0
+       #docbook-to-man debian/ncurses.sgml > ncurses.1
+
+       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+               cat $$f > $${f%.in}; \
+               sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \
+                sed -i -e "s#@CONFIG_DTD@#$(CONFIG_DTD)#g" $${f%.in}; \
+               sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \
+       done
+
+       touch $@
+
+clean:
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp configure-stamp
+#      -$(MAKE) distclean
+       ./clean.sh
+
+ifneq "$(wildcard /usr/share/misc/config.sub)" ""
+       cp -f /usr/share/misc/config.sub config.sub
+endif
+ifneq "$(wildcard /usr/share/misc/config.guess)" ""
+       cp -f /usr/share/misc/config.guess config.guess
+endif
+
+       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
+               rm -f $${f%.in}; \
+       done
+
+       dh_clean 
+
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k 
+       dh_installdirs
+
+       # Add here commands to install the package into debian/ncurses.
+       $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+       dh_installchangelogs
+       dh_installdocs
+       dh_installexamples
+       dh_install --sourcedir=debian/tmp
+#      dh_installmenu
+#      dh_installdebconf       
+#      dh_installlogrotate
+#      dh_installemacsen
+#      dh_installpam
+#      dh_installmime
+#      dh_python
+#      dh_installinit
+#      dh_installcron
+#      dh_installinfo
+       dh_installman
+       dh_link
+       dh_strip --dbg-package=wrt-plugins-tizen-dbg
+       dh_compress
+       dh_fixperms
+#      dh_perl
+       dh_makeshlibs
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install 
diff --git a/debian_DEPRECATED/wrt-plugins-tizen.install.in b/debian_DEPRECATED/wrt-plugins-tizen.install.in
new file mode 100755 (executable)
index 0000000..a0c4cc5
--- /dev/null
@@ -0,0 +1,2 @@
+@PREFIX@/*
+@CONFIG_DTD@/*
diff --git a/packaging/wrt-plugins-tizen.spec b/packaging/wrt-plugins-tizen.spec
new file mode 100755 (executable)
index 0000000..15ac028
--- /dev/null
@@ -0,0 +1,92 @@
+Name:       wrt-plugins-tizen
+Summary:    JavaScript plugins for WebRuntime
+Version:    0.3.38
+Release:    0
+Group:      Development/Libraries
+License:    Apache License, Version 2.0
+Source0:    %{name}-%{version}.tar.gz
+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(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(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(osp-appfw)
+BuildRequires:  expat-devel
+BuildRequires:  cmake
+BuildRequires:  gettext-devel
+
+%description
+JavaScript plugins for WebRuntime
+
+
+%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/*
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644 (file)
index 0000000..2b23445
--- /dev/null
@@ -0,0 +1,26 @@
+# Includes CMake configuration file (*.cmake), preserving appropriate paths.
+macro(include_config_file INCLUDED_CONFIG_FILE_PATH)
+  get_filename_component(CURRENT_CONFIG_FILE_PATH ${CMAKE_CURRENT_LIST_FILE} PATH)
+  include(${CURRENT_CONFIG_FILE_PATH}/${INCLUDED_CONFIG_FILE_PATH}/${CONFIG_FILE_NAME} OPTIONAL)
+endmacro()
+
+# Gets actual path for CMake configuration file (*.cmake).
+# By default, if no argument is passed, current path will be set to variable
+# named CURRENT_PATH.
+# @param [Optional] Name of the variable to set with current path.
+macro(get_current_path)
+  set(VARIABLE "CURRENT_PATH")
+  if (${ARGC} GREATER 0)
+    set(VARIABLE ${ARGV0})
+  endif ()
+  get_filename_component(${VARIABLE} ${CMAKE_CURRENT_LIST_FILE} PATH)
+endmacro()
+
+set(HOST_ARCH $ENV{DEB_HOST_ARCH})
+if("${HOST_ARCH}" MATCHES "armel")
+    set(HOST_ARCH "armel")
+endif()
+
+add_subdirectory(platform)
+add_subdirectory(standards)
+
diff --git a/src/platform/API/Application/ApplicationCert.cpp b/src/platform/API/Application/ApplicationCert.cpp
new file mode 100644 (file)
index 0000000..a2326f5
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// 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 "ApplicationCert.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {        
+ApplicationCert::ApplicationCert()
+{
+}
+
+ApplicationCert::~ApplicationCert()
+{
+}
+
+std::string ApplicationCert::getType() const
+{
+       return m_type;
+}
+
+void ApplicationCert::setType(const std::string &type)
+{
+       m_type = type;
+}
+
+std::string ApplicationCert::getValue() const
+{
+       return m_value;
+}
+
+void ApplicationCert::setValue(const std::string &value)
+{
+       m_value = value;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Application/ApplicationCert.h b/src/platform/API/Application/ApplicationCert.h
new file mode 100644 (file)
index 0000000..37f4d79
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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_CERT_H_
+#define TIZENAPIS_API_APPLICATION_CERT_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class ApplicationCert;
+typedef DPL::SharedPtr<ApplicationCert> ApplicationCertPtr;
+
+typedef std::vector<ApplicationCertPtr> ApplicationCertArray;
+typedef DPL::SharedPtr<ApplicationCertArray> ApplicationCertArrayPtr;
+
+
+class ApplicationCert
+{
+  public:
+    ApplicationCert();
+    ~ApplicationCert();
+
+       std::string getType() const;
+       void setType(const std::string &type);
+       std::string getValue() const;
+       void setValue(const std::string &value);
+
+  private:
+    std::string        m_type;
+    std::string        m_value;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Application/ApplicationContext.cpp b/src/platform/API/Application/ApplicationContext.cpp
new file mode 100755 (executable)
index 0000000..4fdc5ad
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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 "ApplicationContext.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {        
+ApplicationContext::ApplicationContext()
+{
+}
+
+ApplicationContext::~ApplicationContext()
+{
+}
+
+std::string ApplicationContext::getAppId() const
+{
+       return m_appId;
+}
+void ApplicationContext::setAppId(const std::string &appId)
+{
+       m_appId = appId;
+}
+
+std::string ApplicationContext::getContextId() const
+{
+       return m_contextId;
+}
+void ApplicationContext::setContextId(const std::string &contextId)
+{
+       m_contextId = contextId;
+}
+
+
+}
+}
+}
diff --git a/src/platform/API/Application/ApplicationContext.h b/src/platform/API/Application/ApplicationContext.h
new file mode 100755 (executable)
index 0000000..c1c149a
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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_CONTEXT_H_
+#define TIZENAPIS_API_APPLICATION_CONTEXT_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class ApplicationContext;
+typedef DPL::SharedPtr<ApplicationContext> ApplicationContextPtr;
+
+typedef std::vector<ApplicationContextPtr> ApplicationContextArray;
+typedef DPL::SharedPtr<ApplicationContextArray> ApplicationContextArrayPtr;
+
+class ApplicationContext
+{
+  public:
+    ApplicationContext();
+    ~ApplicationContext();
+
+       std::string getAppId() const;
+       void setAppId(const std::string &appId);
+       std::string getContextId() const;
+       void setContextId(const std::string &contextId);
+
+
+  private:
+    std::string        m_appId;
+    std::string        m_contextId;
+
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Application/ApplicationControl.cpp b/src/platform/API/Application/ApplicationControl.cpp
new file mode 100755 (executable)
index 0000000..af8ddb1
--- /dev/null
@@ -0,0 +1,174 @@
+//
+// 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        ApplicationControl.cpp
+ * @author      Youngkyeong Yun (yk.yun@samsung.com)
+ * @version     0.1
+ */
+
+
+#include "ApplicationControl.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+ApplicationControl::ApplicationControl() :
+       m_appControl(NULL)
+{
+    LogDebug("entered");
+}
+
+ApplicationControl::ApplicationControl(const std::string &op, const std::string &uri,
+               const std::string &mime, const std::string &category,
+               std::vector<ApplicationControlDataPtr> &dataArray) :
+       m_appControl(NULL)
+{
+    LogDebug("entered");
+       m_operation = op;
+       m_uri = uri;
+       m_mime = mime;
+       m_category = category;  
+       m_appControlDataArray = dataArray;
+}
+
+ApplicationControl::~ApplicationControl()
+{
+    LogDebug("entered");
+}
+
+std::string ApplicationControl::getOperation() const
+{
+       return m_operation;
+}
+
+void ApplicationControl::setOperation(const std::string &operation)
+{
+       m_operation = operation;
+}
+
+std::string ApplicationControl::getUri() const
+{
+       return m_uri;
+}
+
+void ApplicationControl::setUri(const std::string &uri)
+{
+       m_uri = uri;
+}
+
+std::string ApplicationControl::getMime() const
+{
+       return m_mime;
+}
+
+void ApplicationControl::setMime(const std::string &mime)
+{
+       m_mime = mime;
+}
+
+std::string ApplicationControl::getCategory() const
+{
+       return m_category;
+}
+
+void ApplicationControl::setCategory(const std::string &category)
+{
+       m_category = category;
+}
+
+std::vector<ApplicationControlDataPtr> ApplicationControl::getAppControlDataArray() const
+{
+       return m_appControlDataArray;
+}
+
+void ApplicationControl::setAppControlDataArray(const std::vector<ApplicationControlDataPtr> &dataArray)
+{
+       m_appControlDataArray = dataArray;
+}
+
+void ApplicationControl::addAppControlData(const ApplicationControlDataPtr &data)
+{
+       m_appControlDataArray.push_back(data);
+       
+}
+
+service_h ApplicationControl::getService_h() const
+{
+       return m_appControl;
+}
+
+void ApplicationControl::setService_h(const service_h service)
+{
+       m_appControl = service;
+}
+
+
+#if 0
+void ApplicationControl::replyResult(std::vector<ApplicationControlDataPtr> &appControlDataArray)
+{
+       service_h reply;
+       service_create(&reply);
+
+       const char* key = NULL;
+       const char** arr = NULL;
+
+       if (!appControlDataArray.empty())
+       {
+               LogDebug("appControlDataArray.size() : "<<appControlDataArray.size());
+               for (size_t i = 0; i < appControlDataArray.size(); ++i) {
+                       key = appControlDataArray.at(i)->getKey().c_str();
+                       std::vector<std::string> valueArray = appControlDataArray.at(i)->getValue();
+                       
+                       arr = (const char**) calloc (sizeof(char*), valueArray.size());
+       
+                       for (size_t j = 0; j < valueArray.size(); j++) {
+                               arr[j] = valueArray.at(j).c_str();
+                       }
+                       service_add_extra_data_array(reply, key, arr, valueArray.size());
+               }
+       } else {
+               LogError("==[replyResult] appControlDataArray is empty");
+       }
+
+       service_reply_to_launch_request(reply, m_appControl, SERVICE_RESULT_SUCCEEDED);
+
+       service_destroy(reply);
+
+       if (arr) {
+               free (arr);
+       }
+       
+}
+
+void ApplicationControl::replyFailure()
+{
+       service_h reply;
+       service_create(&reply);
+
+       LogError("==[replyFailure] enter ApplicationControl::replyFailure");
+       service_reply_to_launch_request(reply, m_appControl, SERVICE_RESULT_FAILED);
+
+       service_destroy(reply);
+}
+#endif
+
+}
+}
+}
diff --git a/src/platform/API/Application/ApplicationControl.h b/src/platform/API/Application/ApplicationControl.h
new file mode 100755 (executable)
index 0000000..4033edb
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// 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_CONTROL_H_
+#define TIZENAPIS_API_APPLICATION_CONTROL_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <app_service.h>
+#include "ApplicationControlData.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class ApplicationControl;
+typedef DPL::SharedPtr<ApplicationControl> ApplicationControlPtr;
+
+/* This object represents a single extra data for service request and reply */
+class ApplicationControl
+{
+  public:
+    ApplicationControl();
+       ApplicationControl(const std::string &op, const std::string &uri, const std::string &mime,
+                       const std::string &category, std::vector<ApplicationControlDataPtr> &dataArray) ;
+    ~ApplicationControl();
+
+       std::string getOperation() const;
+       void setOperation(const std::string &operation);
+
+       std::string getUri() const;
+       void setUri(const std::string &uri);
+
+       std::string getMime() const;
+       void setMime(const std::string &uri);
+
+       std::string getCategory() const;
+       void setCategory(const std::string &category);
+
+       std::vector<ApplicationControlDataPtr> getAppControlDataArray() const;
+       void setAppControlDataArray(const std::vector<ApplicationControlDataPtr> &dataArray);
+       void addAppControlData(const ApplicationControlDataPtr &data);
+
+       service_h getService_h() const;
+       void setService_h(const service_h service);  
+
+#if 0
+       void replyResult(std::vector<ApplicationControlDataPtr> &appControlDataArray);
+       void replyFailure();
+#endif
+
+  private:
+       std::string m_operation;
+       std::string m_uri;
+       std::string m_mime;
+       std::string m_category;
+       std::vector<ApplicationControlDataPtr> m_appControlDataArray;
+       service_h m_appControl;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Application/ApplicationControlData.cpp b/src/platform/API/Application/ApplicationControlData.cpp
new file mode 100755 (executable)
index 0000000..bb3b495
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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 "ApplicationControlData.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+ApplicationControlData::ApplicationControlData()
+{
+    LogDebug("entered");
+}
+
+ApplicationControlData::~ApplicationControlData()
+{
+    //nothing to do in destructor
+    LogDebug("entered");
+}
+
+std::string ApplicationControlData::getKey() const
+{
+       return m_key;
+}
+
+void ApplicationControlData::setKey(const std::string &key)
+{
+       m_key = key;
+}
+
+std::vector<std::string> ApplicationControlData::getValue() const
+{
+       return m_value;
+}
+void ApplicationControlData::setValue(const std::vector<std::string> &value)
+{
+       m_value = value;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Application/ApplicationControlData.h b/src/platform/API/Application/ApplicationControlData.h
new file mode 100755 (executable)
index 0000000..3f5c7f1
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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_CONTROL_DATA_H_
+#define TIZENAPIS_API_APPLICATION_CONTROL_DATA_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class ApplicationControlData;
+typedef DPL::SharedPtr<ApplicationControlData> ApplicationControlDataPtr;
+
+typedef std::vector<ApplicationControlDataPtr> ApplicationControlDataArray;
+typedef DPL::SharedPtr<ApplicationControlDataArray> ApplicationControlDataArrayPtr;
+
+/* This object represents a single extra data for app control request and reply */
+class ApplicationControlData
+{
+  public:
+    ApplicationControlData();
+    ~ApplicationControlData();
+
+       std::string getKey() const;
+       void setKey(const std::string &key);
+
+       std::vector<std::string> getValue() const;
+       void setValue(const std::vector<std::string> &value);
+       
+  private:
+    std::string        m_key;
+       std::vector<std::string>        m_value;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Application/ApplicationFactory.cpp b/src/platform/API/Application/ApplicationFactory.cpp
new file mode 100755 (executable)
index 0000000..e1f4e1a
--- /dev/null
@@ -0,0 +1,41 @@
+//
+// 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 <Application/ApplicationManager.h>
+#include "ApplicationFactory.h"
+
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+IApplicationManagerPtr ApplicationFactory::createApplication() {
+       return IApplicationManagerPtr(new Platform::Application::ApplicationManager());
+}
+
+ApplicationFactory& ApplicationFactory::getInstance() {
+       static ApplicationFactory theInstance;
+       return theInstance;
+}
+
+ApplicationFactory::ApplicationFactory() {
+}
+
+}
+}
+}
diff --git a/src/platform/API/Application/ApplicationFactory.h b/src/platform/API/Application/ApplicationFactory.h
new file mode 100755 (executable)
index 0000000..4102c4f
--- /dev/null
@@ -0,0 +1,42 @@
+//
+// 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_FACTORY_H_
+#define TIZENAPIS_API_APPLICATION_FACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include "IApplicationManager.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class ApplicationFactory: DPL::Noncopyable {
+public:
+       IApplicationManagerPtr createApplication();
+       static ApplicationFactory& getInstance();
+
+protected:
+       ApplicationFactory();
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/API/Application/ApplicationInformation.cpp b/src/platform/API/Application/ApplicationInformation.cpp
new file mode 100755 (executable)
index 0000000..8efeda3
--- /dev/null
@@ -0,0 +1,118 @@
+//
+// 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 "ApplicationInformation.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {        
+ApplicationInformation::ApplicationInformation()
+{
+}
+
+ApplicationInformation::~ApplicationInformation()
+{
+}
+
+std::string ApplicationInformation::getName() const
+{
+       return m_name;
+}
+
+void ApplicationInformation::setName(const std::string &name)
+{
+       m_name = name;
+}
+
+std::string ApplicationInformation::getAppId() const
+{
+       return m_appId;
+}
+
+void ApplicationInformation::setAppId(const std::string &appId)
+{
+       m_appId = appId;
+}
+
+std::string ApplicationInformation::getIconPath() const
+{
+       return m_iconPath;
+}
+
+void ApplicationInformation::setIconPath(const std::string &iconPath)
+{
+       m_iconPath = iconPath;
+}
+
+std::string ApplicationInformation::getVersion() const
+{
+       return m_version;
+}
+
+void ApplicationInformation::setVersion(const std::string &version)
+{
+       m_version = version;
+}
+
+bool ApplicationInformation::getShow() const
+{
+       return m_show;
+}
+
+void ApplicationInformation::setShow(const bool &show)
+{
+       m_show = show;
+}
+
+std::vector<std::string> ApplicationInformation::getCategories() const
+{
+       return m_categories;
+}
+
+void ApplicationInformation::setCategories(const std::vector<std::string> &categories)
+{
+       m_categories = categories;
+}
+
+void ApplicationInformation::addCategories(const std::string &category)
+{
+       m_categories.push_back(category);
+}
+
+time_t ApplicationInformation::getInstallDate() const
+{
+       return m_installDate;
+}
+
+void ApplicationInformation::setInstallDate(const time_t &date)
+{
+       m_installDate = date;
+}
+
+long ApplicationInformation::getInstallSize() const
+{
+       return m_installSize;
+}
+
+void ApplicationInformation::setInstallSize(const long &size)
+{
+       m_installSize = size;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Application/ApplicationInformation.h b/src/platform/API/Application/ApplicationInformation.h
new file mode 100755 (executable)
index 0000000..33f53bd
--- /dev/null
@@ -0,0 +1,73 @@
+//
+// 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_INFORMATION_H_
+#define TIZENAPIS_API_APPLICATION_INFORMATION_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class ApplicationInformation;
+typedef DPL::SharedPtr<ApplicationInformation> ApplicationInformationPtr;
+
+typedef std::vector<ApplicationInformationPtr> ApplicationInformationArray;
+typedef DPL::SharedPtr<ApplicationInformationArray> ApplicationInformationArrayPtr;
+
+class ApplicationInformation
+{
+  public:
+    ApplicationInformation();
+    ~ApplicationInformation();
+
+       std::string getName() const;
+       void setName(const std::string &name);
+       std::string getAppId() const;
+       void setAppId(const std::string &appId);
+       std::string getIconPath() const;
+       void setIconPath(const std::string &iconPath);
+       std::string getVersion() const;
+       void setVersion(const std::string &version);
+       bool getShow() const;
+       void setShow(const bool &show);
+       std::vector<std::string> getCategories() const;
+       void setCategories(const std::vector<std::string> &categories);
+       void addCategories(const std::string &category);
+       time_t getInstallDate() const;
+       void setInstallDate(const time_t &date);
+       long getInstallSize() const;
+       void setInstallSize(const long &size);
+
+  private:
+    std::string        m_name;
+    std::string        m_appId;
+    std::string        m_iconPath;
+    std::string        m_version;
+       bool m_show;
+       time_t m_installDate;
+       long m_installSize;
+       std::vector<std::string> m_categories;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Application/ApplicationInstallInfo.cpp b/src/platform/API/Application/ApplicationInstallInfo.cpp
new file mode 100755 (executable)
index 0000000..863d6cf
--- /dev/null
@@ -0,0 +1,75 @@
+//
+// 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 "ApplicationInstallInfo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+ApplicationInstallInfo::ApplicationInstallInfo()
+{
+}
+
+ApplicationInstallInfo::~ApplicationInstallInfo()
+{
+}
+
+std::string ApplicationInstallInfo::getFilePath() const
+{
+       return m_filePath;
+}
+
+void ApplicationInstallInfo::setFilePath(const std::string &filePath)
+{
+       m_filePath = filePath;
+}
+
+std::string ApplicationInstallInfo::getAlgorithm() const
+{
+       return m_algorithm;
+}
+
+void ApplicationInstallInfo::setAlgorithm(const std::string &algorithm)
+{
+       m_algorithm = algorithm;
+}
+
+std::string ApplicationInstallInfo::getKey() const
+{
+       return m_key;
+}
+
+void ApplicationInstallInfo::setKey(const std::string &key)
+{
+       m_key = key;
+}
+
+std::string ApplicationInstallInfo::getPackageFormat() const
+{
+       return m_packageFormat;
+}
+
+void ApplicationInstallInfo::setPackageFormat(const std::string &packageFormat)
+{
+       m_packageFormat = packageFormat;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Application/ApplicationInstallInfo.h b/src/platform/API/Application/ApplicationInstallInfo.h
new file mode 100755 (executable)
index 0000000..c9c9dde
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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_INSTALL_INFO_H_
+#define TIZENAPIS_API_APPLICATION_INSTALL_INFO_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class ApplicationInstallInfo;
+typedef DPL::SharedPtr<ApplicationInstallInfo> ApplicationInstallInfoPtr;
+
+class ApplicationInstallInfo
+{
+  public:
+    ApplicationInstallInfo();
+    ~ApplicationInstallInfo();
+
+       std::string getFilePath() const;
+       void setFilePath(const std::string &filepath);
+       std::string getAlgorithm() const;
+       void setAlgorithm(const std::string &algorithm);
+       std::string getKey() const;
+       void setKey(const std::string &key);
+       std::string getPackageFormat() const;
+       void setPackageFormat(const std::string &packageFormat);
+
+  private:
+    std::string        m_filePath;
+    std::string        m_algorithm;
+    std::string        m_key;
+    std::string        m_packageFormat;
+};
+
+}
+}
+}
+#endif
diff --git a/src/platform/API/Application/EventApplicationAddAppInfoEventListener.h b/src/platform/API/Application/EventApplicationAddAppInfoEventListener.h
new file mode 100755 (executable)
index 0000000..1592355
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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_APPLICATION_ADD_APP_INFO_EVENT_LISTENER_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_ADD_APP_INFO_EVENT_LISTENER_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "EventApplicationAppInfoEventListener.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationAddAppInfoEventListener : public WrtDeviceApis::Commons::IEvent<EventApplicationAddAppInfoEventListener>
+{
+private:
+       /* parameter */
+       EventApplicationAppInfoEventListenerEmitterPtr m_emitter;
+
+       /* result */
+       long m_watchId;
+
+public:
+       void setEmitter(EventApplicationAppInfoEventListenerEmitterPtr &value)
+       {
+               m_emitter = value;
+       }
+
+       EventApplicationAppInfoEventListenerEmitterPtr getEmitter() const
+       {
+               return m_emitter;
+       }
+
+       void setWatchId(long watchId)
+       {
+               m_watchId = watchId;
+       }
+
+       long getWatchId() const
+       {
+               return m_watchId;
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationAddAppInfoEventListener> EventApplicationAddAppInfoEventListenerPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_ADD_APP_INFO_EVENT_LISTENER_H_
diff --git a/src/platform/API/Application/EventApplicationAppInfoEventListener.h b/src/platform/API/Application/EventApplicationAppInfoEventListener.h
new file mode 100755 (executable)
index 0000000..4354d32
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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_APPLICATION_APP_INFO_EVENT_LISTENER_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_APP_INFO_EVENT_LISTENER_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include <Commons/Emitters.h>
+#include "ApplicationInformation.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationAppInfoEventListener : public WrtDeviceApis::Commons::ListenerEvent<EventApplicationAppInfoEventListener>
+{
+public:
+       enum CallbackType
+       {
+               OnError,
+               OnInstalled,
+               OnUpdated,
+               OnUninstalled
+       };
+
+private:
+       CallbackType m_type;
+
+       std::string m_appId;
+       ApplicationInformationPtr m_appInfo;
+       
+public:
+       void setAppId(const std::string &appId)
+       {
+               m_appId = appId;
+       }
+
+       std::string getAppId() const
+       {
+               return m_appId;
+       }
+
+       void setAppInfo(const ApplicationInformationPtr &appInfo)
+       {
+               m_appInfo = appInfo;
+       }
+
+       ApplicationInformationPtr getAppInfo() const
+       {
+               return m_appInfo;
+       }
+
+       void setType(CallbackType type)
+       {
+               m_type = type;
+       }
+
+       int getType() const
+       {
+               return m_type;
+       }
+
+       EventApplicationAppInfoEventListener() :
+               m_type(OnError),
+               m_appInfo(NULL)
+       {
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationAppInfoEventListener> EventApplicationAppInfoEventListenerPtr;
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventApplicationAppInfoEventListener> EventApplicationAppInfoEventListenerEmitter;
+typedef DPL::SharedPtr<EventApplicationAppInfoEventListenerEmitter> EventApplicationAppInfoEventListenerEmitterPtr;
+typedef WrtDeviceApis::Commons::Emitters<EventApplicationAppInfoEventListenerEmitter> EventApplicationAppInfoEventListenerEmitters;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_APP_INFO_EVENT_LISTENER_H_
diff --git a/src/platform/API/Application/EventApplicationFindAppControl.h b/src/platform/API/Application/EventApplicationFindAppControl.h
new file mode 100755 (executable)
index 0000000..83ff3d2
--- /dev/null
@@ -0,0 +1,75 @@
+//
+// 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_FIND_APP_CONTROL_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_FIND_APP_CONTROL_H_
+
+
+#include <dpl/log/log.h>
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "ApplicationInformation.h"
+#include "ApplicationControl.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationFindAppControl : public WrtDeviceApis::Commons::IEvent<EventApplicationFindAppControl>
+{
+private:
+       /* parameter */
+       ApplicationControlPtr m_appControl;
+
+       /* result */
+       ApplicationInformationArrayPtr m_appInfoArray;
+
+public:
+       void setAppControl(ApplicationControlPtr &appControl)
+       {
+               m_appControl = appControl;
+       }
+
+       ApplicationControlPtr getAppControl() const
+       {
+               return m_appControl;
+       }
+
+       void setAppInfos(ApplicationInformationArrayPtr &appInfos)
+       {
+               m_appInfoArray = appInfos;
+       }
+
+       ApplicationInformationArrayPtr getAppInfos() const
+       {
+               return m_appInfoArray;
+       }
+       
+       EventApplicationFindAppControl() :
+               m_appControl(NULL),
+               m_appInfoArray(NULL)
+       {
+       }               
+};
+
+typedef DPL::SharedPtr<EventApplicationFindAppControl> EventApplicationFindAppControlPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_FIND_APP_CONTROL_H_
diff --git a/src/platform/API/Application/EventApplicationGetAppCerts.h b/src/platform/API/Application/EventApplicationGetAppCerts.h
new file mode 100644 (file)
index 0000000..bfcb88f
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// 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_CERTS_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_GET_APP_CERTS_H_
+
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "ApplicationCert.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationGetAppCerts : public WrtDeviceApis::Commons::IEvent<EventApplicationGetAppCerts>
+{
+private:
+       std::string m_appId;
+       ApplicationCertArrayPtr  m_certs;
+
+public:
+       void setAppId(std::string appId)
+       {
+               m_appId = appId;
+       }
+
+       std::string getAppId()
+       {
+               return m_appId;
+       }
+       
+       void setAppCerts(ApplicationCertArrayPtr &certs)
+       {
+               m_certs = certs;
+       }
+
+       ApplicationCertArrayPtr getAppCerts() const
+       {
+               return m_certs;
+       }
+
+       void addAppCert(ApplicationCertPtr cert)
+       {
+               m_certs->push_back(cert);
+       }
+
+       EventApplicationGetAppCerts() :
+               m_certs(new ApplicationCertArray())
+       {
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationGetAppCerts> EventApplicationGetAppCertsPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_GET_APP_CERTS_H_
\ No newline at end of file
diff --git a/src/platform/API/Application/EventApplicationGetAppContext.h b/src/platform/API/Application/EventApplicationGetAppContext.h
new file mode 100755 (executable)
index 0000000..005a837
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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_CONTEXT_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_GET_APP_CONTEXT_H_
+
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "ApplicationContext.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationGetAppContext : public WrtDeviceApis::Commons::IEvent<EventApplicationGetAppContext>
+{
+private:
+       /* parameter */
+       std::string  m_appContextId;
+
+       /* result */
+       ApplicationContextPtr m_appContext;
+
+public:
+       void setAppContextId(std::string appContextId)
+       {
+               m_appContextId = appContextId;
+       }
+
+       std::string getAppContextId() const
+       {
+               return m_appContextId;
+       }
+
+       void setAppContext(const ApplicationContextPtr appContext)
+       {
+               m_appContext = appContext;
+       }
+
+       ApplicationContextPtr getAppContext() const
+       {
+               return m_appContext;
+       }
+
+       EventApplicationGetAppContext() :
+               m_appContext(NULL)
+       {
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationGetAppContext> EventApplicationGetAppContextPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_GET_APP_CONTEXT_H_
diff --git a/src/platform/API/Application/EventApplicationGetAppInfo.h b/src/platform/API/Application/EventApplicationGetAppInfo.h
new file mode 100755 (executable)
index 0000000..baf5eda
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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_INFO_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_GET_APP_INFO_H_
+
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "ApplicationInformation.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationGetAppInfo : public WrtDeviceApis::Commons::IEvent<EventApplicationGetAppInfo>
+{
+private:
+       /* parameter */
+       std::string  m_appId;
+
+       /* result */
+       ApplicationInformationPtr m_appInfo;
+
+public:
+       void setAppId(std::string appId)
+       {
+               m_appId = appId;
+       }
+
+       std::string getAppId() const
+       {
+               return m_appId;
+       }
+
+       void setAppInfo(const ApplicationInformationPtr appInfo)
+       {
+               m_appInfo = appInfo;
+       }
+
+       ApplicationInformationPtr getAppInfo() const
+       {
+               return m_appInfo;
+       }
+
+       EventApplicationGetAppInfo() :
+               m_appInfo(NULL)
+       {
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationGetAppInfo> EventApplicationGetAppInfoPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_GET_APP_INFO_H_
diff --git a/src/platform/API/Application/EventApplicationGetAppsContext.h b/src/platform/API/Application/EventApplicationGetAppsContext.h
new file mode 100755 (executable)
index 0000000..6b1c87f
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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_APPS_CONTEXT_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_GET_APPS_CONTEXT_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "ApplicationContext.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationGetAppsContext : public WrtDeviceApis::Commons::IEvent<EventApplicationGetAppsContext>
+{
+private:
+       /* result */
+       ApplicationContextArrayPtr m_appContextArray;
+
+public:
+       void addAppContext(const ApplicationContextPtr appContext)
+       {
+               m_appContextArray->push_back(appContext);
+       }
+       
+       const ApplicationContextArrayPtr getAppContextArray() const
+       {
+               return m_appContextArray;
+       }
+
+       void setAppContextArray(ApplicationContextArrayPtr appContextArray)
+       {
+               m_appContextArray = appContextArray;
+       }       
+
+       EventApplicationGetAppsContext() :
+               m_appContextArray(new ApplicationContextArray())
+       {
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationGetAppsContext> EventApplicationGetAppsContextPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_GET_APPS_CONTEXT_H_
diff --git a/src/platform/API/Application/EventApplicationGetAppsInfo.h b/src/platform/API/Application/EventApplicationGetAppsInfo.h
new file mode 100755 (executable)
index 0000000..92e93d8
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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_APPS_INFO_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_GET_APPS_INFO_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "ApplicationInformation.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationGetAppsInfo : public WrtDeviceApis::Commons::IEvent<EventApplicationGetAppsInfo>
+{
+private:
+       /* result */
+       ApplicationInformationArrayPtr m_appInfoArray;
+
+public:
+       void addAppInfo(const ApplicationInformationPtr appInfo)
+       {
+               m_appInfoArray->push_back(appInfo);
+       }
+
+       const ApplicationInformationArrayPtr getAppInfoArray() const
+       {
+               return m_appInfoArray;
+       }
+
+       void setAppInfoArray(ApplicationInformationArrayPtr appInfoArray)
+       {
+               m_appInfoArray = appInfoArray;
+       }
+
+       EventApplicationGetAppsInfo() :
+               m_appInfoArray(new ApplicationInformationArray())
+       {
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationGetAppsInfo> EventApplicationGetAppsInfoPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_GET_APPS_INFO_H_
diff --git a/src/platform/API/Application/EventApplicationGetCurrApp.h b/src/platform/API/Application/EventApplicationGetCurrApp.h
new file mode 100644 (file)
index 0000000..0bb3c80
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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_CURR_APP_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_GET_CURR_APP_H_
+
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Tizen/Application/Application.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationGetCurrApp : public WrtDeviceApis::Commons::IEvent<EventApplicationGetCurrApp>
+{
+private:
+       /* result */
+       ApplicationPtr m_app;
+
+public:
+       void setApp(const ApplicationPtr app)
+       {
+               m_app = app;
+       }
+
+       ApplicationPtr getApp() const
+       {
+               return m_app;
+       }
+
+       EventApplicationGetCurrApp() :
+               m_app(NULL)
+       {
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationGetCurrApp> EventApplicationGetCurrAppPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_GET_CURR_APP_H_
\ No newline at end of file
diff --git a/src/platform/API/Application/EventApplicationGetRequestedAppControl.h b/src/platform/API/Application/EventApplicationGetRequestedAppControl.h
new file mode 100644 (file)
index 0000000..447a83c
--- /dev/null
@@ -0,0 +1,71 @@
+//
+// 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_APPLICATION_GET_REQUESTED_APP_CONTROL_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_GET_REQUESTED_APP_CONTROL_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "RequestedApplicationControl.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationGetRequestedAppControl : public WrtDeviceApis::Commons::IEvent<EventApplicationGetRequestedAppControl>
+{
+private:
+       /* result */
+       RequestedApplicationControlPtr   m_reqAppControl;
+
+       std::string             m_encodedBundle;
+
+public:
+       void setRequestedAppControl(RequestedApplicationControlPtr &reqAppControl)
+       {
+               m_reqAppControl = reqAppControl;
+       }
+
+       RequestedApplicationControlPtr getRequestedAppControl() const
+       {
+               return m_reqAppControl;
+       }
+
+       void setEncodedBundle(std::string encodedBundle)
+       {
+               m_encodedBundle = encodedBundle;
+       }
+
+       std::string getEncodedBundle() const
+       {
+               return m_encodedBundle;
+       }
+
+       EventApplicationGetRequestedAppControl() :
+               m_reqAppControl(NULL)
+       {
+       }               
+};
+
+typedef DPL::SharedPtr<EventApplicationGetRequestedAppControl> EventApplicationGetRequestedAppControlPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_GET_REQUESTED_APP_CONTROL_H_
\ No newline at end of file
diff --git a/src/platform/API/Application/EventApplicationInstall.h b/src/platform/API/Application/EventApplicationInstall.h
new file mode 100755 (executable)
index 0000000..c9b5e74
--- /dev/null
@@ -0,0 +1,110 @@
+//
+// 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_EVENT_APPLICATION_INSTALL_H_
+#define TIZENAPIS_API_EVENT_APPLICATION_INSTALL_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "ApplicationInstallInfo.h"
+#include <dpl/log/log.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationInstall: public WrtDeviceApis::Commons::IEvent<EventApplicationInstall> {
+
+private:
+       ApplicationInstallInfoPtr m_appInstallInfo;
+       ApplicationInformationPtr m_appinfo;
+       std::string  m_appId;
+       int m_callbackType;
+       int m_eventType;
+
+public:
+/* CALLBACK TYPE */
+       static const int APPLICATION_INSTALL_UNKNOWN = 0;
+       static const int APPLICATION_INSTALL_INSTALL_CALLBACK = 1;
+       static const int APPLICATION_INSTALL_UNINSTALL_CALLBACK = 2;
+       static const int APPLICATION_INSTALL_UPDATE_CALLBACK = 3;
+/* EVENT TYPE */       
+       static const int APPLICATION_INSTALL_INSTALL = 4;
+       static const int APPLICATION_INSTALL_UNINSTALL = 5;
+       static const int APPLICATION_INSTALL_UPDATE = 6;
+ public:       
+       void setAppInstallInfo(ApplicationInstallInfoPtr &appInstallInfo){
+               m_appInstallInfo = appInstallInfo;
+       }
+
+       ApplicationInstallInfoPtr getAppInstallInfo() const{
+               return m_appInstallInfo;
+       }
+       void setApplicationInformation(const ApplicationInformationPtr appinfo)
+       {
+               m_appinfo = appinfo;
+       }
+
+       ApplicationInformationPtr getApplicationInformation() const
+       {
+               return m_appinfo;
+       }
+
+       void setAppId(std::string appId)
+       {
+               m_appId = appId;
+       }
+
+       std::string getAppId() const
+       {
+               return m_appId;
+       }
+
+       void setCallbackType(int callbacktype){
+               m_callbackType = callbacktype;
+       }
+
+       int getCallbackType() const{
+               return m_callbackType;
+       }
+
+       void setEventType(int type){
+               m_eventType = type;
+       }
+
+       int getEventType(){
+               return m_eventType;
+       }       
+
+       EventApplicationInstall() :
+               m_appInstallInfo(NULL),
+               m_appinfo(NULL),
+               m_callbackType(APPLICATION_INSTALL_UNKNOWN),
+               m_eventType(APPLICATION_INSTALL_UNKNOWN)
+       {
+       }               
+};
+
+typedef DPL::SharedPtr<EventApplicationInstall> EventApplicationInstallPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif
diff --git a/src/platform/API/Application/EventApplicationKill.h b/src/platform/API/Application/EventApplicationKill.h
new file mode 100755 (executable)
index 0000000..53ee9ac
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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_APPLICATION_KILL_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_KILL_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationKill : public WrtDeviceApis::Commons::IEvent<EventApplicationKill>
+{
+private:
+       /* parameter */
+       std::string m_contextId;
+
+public:
+       void setContextId(std::string contextId)
+       {
+               m_contextId = contextId;
+       }
+
+       std::string getContextId() const
+       {
+               return m_contextId;
+       }
+
+       EventApplicationKill()
+       {
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationKill> EventApplicationKillPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_KILL_H_
diff --git a/src/platform/API/Application/EventApplicationLaunch.h b/src/platform/API/Application/EventApplicationLaunch.h
new file mode 100755 (executable)
index 0000000..1022d9f
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// 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_APPLICATION_LAUNCH_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_LAUNCH_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationLaunch : public WrtDeviceApis::Commons::IEvent<EventApplicationLaunch>
+{
+private:
+       /* parameter */
+       std::string m_appId;
+
+public:
+       void setAppId(std::string appId)
+       {
+               m_appId = appId;
+       }
+
+       std::string getAppId() const
+       {
+               return m_appId;
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationLaunch> EventApplicationLaunchPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_LAUNCH_H_
diff --git a/src/platform/API/Application/EventApplicationLaunchAppControl.h b/src/platform/API/Application/EventApplicationLaunchAppControl.h
new file mode 100755 (executable)
index 0000000..1ce53f8
--- /dev/null
@@ -0,0 +1,118 @@
+//
+// 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_APPLICATION_LAUNCH_APP_CONTROL_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_LAUNCH_APP_CONTROL_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "ApplicationControl.h"
+#include "ApplicationControlData.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationLaunchAppControlReply;
+typedef DPL::SharedPtr<EventApplicationLaunchAppControlReply> EventApplicationLaunchAppControlReplyPtr;
+
+class EventApplicationLaunchAppControl : public WrtDeviceApis::Commons::IEvent<EventApplicationLaunchAppControl>
+{
+private:
+       /* parameters */
+       ApplicationControlPtr   m_appControl;
+       std::string             m_appId;
+
+       EventApplicationLaunchAppControlReplyPtr   m_eventReply;
+
+public:
+       void setAppControl(ApplicationControlPtr &appControl)
+       {
+               m_appControl = appControl;
+       }
+
+       ApplicationControlPtr getAppControl() const
+       {
+               return m_appControl;
+       }
+
+       void setAppId(std::string appId)
+       {
+               m_appId = appId;
+       }
+
+       std::string getAppId()
+       {
+               return m_appId;
+       }
+
+       void setEventReply(EventApplicationLaunchAppControlReplyPtr &eventReply)
+       {
+               m_eventReply = eventReply;
+       }
+
+       EventApplicationLaunchAppControlReplyPtr getEventReply() const
+       {
+               return m_eventReply;
+       }
+
+       EventApplicationLaunchAppControl() :
+               m_appControl(NULL),
+               m_eventReply(NULL)
+       {
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationLaunchAppControl> EventApplicationLaunchAppControlPtr;
+
+class EventApplicationLaunchAppControlReply : public WrtDeviceApis::Commons::IEvent<EventApplicationLaunchAppControlReply>
+{
+private:
+       ApplicationControlDataArrayPtr m_appControlDataArray;
+
+public:
+       void addAppControlData(std::string &key, std::vector<std::string> &value)
+       {
+               ApplicationControlDataPtr appControlData(new ApplicationControlData());
+               appControlData->setKey(key);
+               appControlData->setValue(value);
+
+               m_appControlDataArray->push_back(appControlData);
+       }
+       void setAppControlDataArray(ApplicationControlDataArrayPtr &appControlDataArray)
+       {
+               m_appControlDataArray = appControlDataArray;
+       }
+
+       ApplicationControlDataArrayPtr getAppControlDataArray() const
+       {
+               return m_appControlDataArray;
+       }
+       
+       EventApplicationLaunchAppControlReply() :
+               m_appControlDataArray(new ApplicationControlDataArray())
+       {
+       }               
+};
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_LAUNCH_APP_CONTROL_H_
diff --git a/src/platform/API/Application/EventApplicationRemoveAppInfoEventListener.h b/src/platform/API/Application/EventApplicationRemoveAppInfoEventListener.h
new file mode 100755 (executable)
index 0000000..61c9902
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// 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_APPLICATION_REMOVE_APP_INFO_EVENT_LISTENER_H_
+#define TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_REMOVE_APP_INFO_EVENT_LISTENER_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class EventApplicationRemoveAppInfoEventListener : public WrtDeviceApis::Commons::IEvent<EventApplicationRemoveAppInfoEventListener>
+{
+private:
+       /* result */
+       long m_watchId;
+
+public:
+       void setWatchId(long watchId)
+       {
+               m_watchId = watchId;
+       }
+
+       long getWatchId() const
+       {
+               return m_watchId;
+       }
+};
+
+typedef DPL::SharedPtr<EventApplicationRemoveAppInfoEventListener> EventApplicationRemoveAppInfoEventListenerPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_EVENT_APPLICATION_ADD_APP_INFO_EVENT_LISTENER_H_
diff --git a/src/platform/API/Application/IApplicationManager.cpp b/src/platform/API/Application/IApplicationManager.cpp
new file mode 100644 (file)
index 0000000..a25b13f
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 "IApplicationManager.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application{
+
+using namespace WrtDeviceApis::Commons;
+
+IApplicationManager::IApplicationManager() :
+               EventRequestReceiver<EventApplicationGetCurrApp>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationLaunch>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationKill>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationLaunchAppControl>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationLaunchAppControlReply>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationFindAppControl>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationGetAppsContext>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationGetAppContext>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationGetAppsInfo>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationGetAppInfo>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationAddAppInfoEventListener>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationRemoveAppInfoEventListener>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationInstall>(ThreadEnum::APPLICATION_THREAD),
+               EventRequestReceiver<EventApplicationGetAppCerts>(ThreadEnum::APPLICATION_THREAD)
+{
+}
+
+IApplicationManager::~IApplicationManager()
+{
+}
+
+} // Application
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Application/IApplicationManager.h b/src/platform/API/Application/IApplicationManager.h
new file mode 100644 (file)
index 0000000..7c3b698
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// 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_IAPPLICATION_MANAGER_H_
+#define TIZENAPIS_API_APPLICATION_IAPPLICATION_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include "EventApplicationGetCurrApp.h"
+#include "EventApplicationLaunch.h"
+#include "EventApplicationKill.h"
+#include "EventApplicationLaunchAppControl.h"
+#include "EventApplicationFindAppControl.h"
+#include "EventApplicationGetAppsContext.h"
+#include "EventApplicationGetAppContext.h"
+#include "EventApplicationGetAppsInfo.h"
+#include "EventApplicationGetAppInfo.h"
+#include "EventApplicationAddAppInfoEventListener.h"
+#include "EventApplicationRemoveAppInfoEventListener.h"
+#include "EventApplicationInstall.h"
+#include "EventApplicationGetAppCerts.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class IApplicationManager :
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationGetCurrApp>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationLaunch>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationKill>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationLaunchAppControl>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationLaunchAppControlReply>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationFindAppControl>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationGetAppsContext>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationGetAppContext>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationGetAppsInfo>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationGetAppInfo>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationAddAppInfoEventListener>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationRemoveAppInfoEventListener>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationInstall>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventApplicationGetAppCerts>
+{
+public:
+       virtual ~IApplicationManager();
+       virtual void getCurrentApplication(const EventApplicationGetCurrAppPtr& event) = 0;
+       virtual void launch(const EventApplicationLaunchPtr& event) = 0;
+       virtual void kill(const EventApplicationKillPtr& event) = 0;
+       virtual void launchAppControl(const EventApplicationLaunchAppControlPtr& event) = 0;
+       virtual void findAppControl(const EventApplicationFindAppControlPtr& event) = 0;
+       virtual void getAppsContext(const EventApplicationGetAppsContextPtr& event) = 0;
+       virtual void getAppContext(const EventApplicationGetAppContextPtr& event) = 0;
+       virtual void getAppsInfo(const EventApplicationGetAppsInfoPtr& event) = 0;
+       virtual void getAppInfo(const EventApplicationGetAppInfoPtr& event) = 0;
+       virtual void addAppInfoEventListener(const EventApplicationAddAppInfoEventListenerPtr& event) = 0;
+       virtual void removeAppInfoEventListener(const EventApplicationRemoveAppInfoEventListenerPtr& event) = 0;
+       virtual void install(const EventApplicationInstallPtr& event) = 0;
+       virtual void uninstall(const EventApplicationInstallPtr& event) = 0;
+       virtual void update(const EventApplicationInstallPtr& event) = 0;
+       virtual void getAppCerts(const EventApplicationGetAppCertsPtr& event) = 0;
+
+protected:
+       IApplicationManager();
+
+       virtual void OnRequestReceived(const EventApplicationGetCurrAppPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationLaunchPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationKillPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationLaunchAppControlPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationLaunchAppControlReplyPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationFindAppControlPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationGetAppsContextPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationGetAppContextPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationGetAppsInfoPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationGetAppInfoPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationAddAppInfoEventListenerPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationRemoveAppInfoEventListenerPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationInstallPtr& event) = 0;
+       virtual void OnRequestReceived(const EventApplicationGetAppCertsPtr& event) = 0;
+ };
+
+typedef DPL::SharedPtr<IApplicationManager> IApplicationManagerPtr;
+
+} // Application
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_API_APPLICATION_IAPPLICATION_MANAGER_H_
\ No newline at end of file
diff --git a/src/platform/API/Application/RequestedApplicationControl.cpp b/src/platform/API/Application/RequestedApplicationControl.cpp
new file mode 100644 (file)
index 0000000..0f3d7a6
--- /dev/null
@@ -0,0 +1,98 @@
+//
+// 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 "RequestedApplicationControl.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+RequestedApplicationControl::RequestedApplicationControl() :
+       m_appControl(NULL),
+       m_appService(NULL)
+{
+    LogDebug("entered");
+}
+
+
+RequestedApplicationControl::~RequestedApplicationControl()
+{
+    LogDebug("entered");
+}
+
+ApplicationControlPtr RequestedApplicationControl::getAppControl() const
+{
+       return m_appControl;
+}
+
+
+// TODO: Should I add & or not?
+void RequestedApplicationControl::setAppControl(ApplicationControlPtr &appControl)
+{
+       m_appControl = appControl;
+}
+
+void RequestedApplicationControl::replyResult(std::vector<ApplicationControlDataPtr> &appControlDataArray)
+{
+       service_h reply;
+       service_create(&reply);
+
+       if (!appControlDataArray.empty())
+       {
+               const char** arr = NULL;
+
+               LogDebug("appControlDataArray.size() : "<<appControlDataArray.size());
+               for (size_t i = 0; i < appControlDataArray.size(); ++i) {
+                       std::vector<std::string> valueArray = appControlDataArray.at(i)->getValue();
+                       
+                       arr = (const char**) calloc (sizeof(char*), valueArray.size());
+
+                       if (arr != NULL) {
+                               for (size_t j = 0; j < valueArray.size(); j++) {
+                                       arr[j] = valueArray.at(j).c_str();
+                                       LogDebug("== value : " << arr[j]);
+                               }
+                       }
+                       service_add_extra_data_array(reply, appControlDataArray.at(i)->getKey().c_str(), arr, valueArray.size());
+                       if (arr) {
+                               free (arr);
+                       }
+               }
+       } else {
+               LogError("[replyResult] appControlDataArray is empty");
+       }
+
+       service_reply_to_launch_request(reply, m_appControl->getService_h(), SERVICE_RESULT_SUCCEEDED);
+
+       service_destroy(reply);
+}
+
+void RequestedApplicationControl::replyFailure()
+{
+       service_h reply;
+       service_create(&reply);
+
+       LogError("[replyFailure] enter RequestedApplicationControl::replyFailure");
+       service_reply_to_launch_request(reply, m_appControl->getService_h(), SERVICE_RESULT_FAILED);
+
+       service_destroy(reply);
+}
+
+}
+}
+}
diff --git a/src/platform/API/Application/RequestedApplicationControl.h b/src/platform/API/Application/RequestedApplicationControl.h
new file mode 100644 (file)
index 0000000..c927482
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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_REQUESTED_APPLICATION_CONTROL_H_
+#define TIZENAPIS_API_REQUESTED_APPLICATION_CONTROL_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <app_service.h>
+
+#include "ApplicationControl.h"
+#include "ApplicationControlData.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class RequestedApplicationControl;
+typedef DPL::SharedPtr<RequestedApplicationControl> RequestedApplicationControlPtr;
+
+/* This object represents a single extra data for service request and reply */
+class RequestedApplicationControl
+{
+  public:
+    RequestedApplicationControl();
+    ~RequestedApplicationControl();
+
+       ApplicationControlPtr getAppControl() const;
+       void setAppControl(ApplicationControlPtr &appControl);
+
+       void replyResult(std::vector<ApplicationControlDataPtr> &appControlDataArray);
+       void replyFailure();
+       
+  private:
+       ApplicationControlPtr m_appControl;
+       service_h m_appService;
+};
+}
+}
+}
+#endif
+
diff --git a/src/platform/API/Application/config.cmake b/src/platform/API/Application/config.cmake
new file mode 100755 (executable)
index 0000000..b88436c
--- /dev/null
@@ -0,0 +1,13 @@
+get_current_path()
+set(SRCS_PLATFORM_API_APPLICATION
+  ${CURRENT_PATH}/ApplicationContext.cpp
+  ${CURRENT_PATH}/ApplicationControl.cpp  
+  ${CURRENT_PATH}/ApplicationControlData.cpp
+  ${CURRENT_PATH}/RequestedApplicationControl.cpp
+  ${CURRENT_PATH}/ApplicationFactory.cpp
+  ${CURRENT_PATH}/ApplicationInformation.cpp
+  ${CURRENT_PATH}/ApplicationCert.cpp
+  ${CURRENT_PATH}/ApplicationInstallInfo.cpp
+  ${CURRENT_PATH}/IApplicationManager.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Bluetooth/BTDevice.h b/src/platform/API/Bluetooth/BTDevice.h
new file mode 100644 (file)
index 0000000..96121c4
--- /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_BT_DEVICE_H_
+#define TIZENAPIS_API_BT_DEVICE_H_
+
+#include <ctime>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/BluetoothFactory.cpp b/src/platform/API/Bluetooth/BluetoothFactory.cpp
new file mode 100644 (file)
index 0000000..a28debc
--- /dev/null
@@ -0,0 +1,71 @@
+//
+// 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/BluetoothAdapterManager.h>
+#include <Bluetooth/BluetoothDeviceManager.h>
+#include <Bluetooth/BluetoothSocketManager.h>
+#include <Bluetooth/BluetoothServiceHandlerManager.h>
+#include "BluetoothFactory.h"
+
+
+using namespace TizenApis::Platform::Bluetooth;
+
+namespace TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/BluetoothFactory.h b/src/platform/API/Bluetooth/BluetoothFactory.h
new file mode 100644 (file)
index 0000000..218882c
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/BluetoothProperty.h b/src/platform/API/Bluetooth/BluetoothProperty.h
new file mode 100644 (file)
index 0000000..ed5de3b
--- /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 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/platform/API/Bluetooth/EventBTConnectToServiceByUUID.h b/src/platform/API/Bluetooth/EventBTConnectToServiceByUUID.h
new file mode 100644 (file)
index 0000000..38a3033
--- /dev/null
@@ -0,0 +1,47 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTCreateDestroyBonding.cpp b/src/platform/API/Bluetooth/EventBTCreateDestroyBonding.cpp
new file mode 100644 (file)
index 0000000..6e453ce
--- /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.
+//
+#include "EventBTCreateDestroyBonding.h"
+#include "IBluetoothAdapterManager.h"
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Bluetooth/JSBluetoothAdapter.h>
+
+using namespace TizenApis::Api::Bluetooth;
+using namespace TizenApis::Tizen1_0;
+
+namespace TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTCreateDestroyBonding.h b/src/platform/API/Bluetooth/EventBTCreateDestroyBonding.h
new file mode 100644 (file)
index 0000000..85f5367
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTGetAdapter.h b/src/platform/API/Bluetooth/EventBTGetAdapter.h
new file mode 100644 (file)
index 0000000..dc103f7
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTGetDevice.cpp b/src/platform/API/Bluetooth/EventBTGetDevice.cpp
new file mode 100644 (file)
index 0000000..c9d758c
--- /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.
+//
+#include "EventBTGetDevice.h"
+
+namespace TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTGetDevice.h b/src/platform/API/Bluetooth/EventBTGetDevice.h
new file mode 100644 (file)
index 0000000..4c252cc
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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_DEVICE_H_
+#define TIZENAPIS_API_BLUETOOTH_GET_DEVICE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "BTDevice.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Bluetooth {
+
+
+class EventBTGetDevice : public WrtDeviceApis::Commons::IEvent<EventBTGetDevice>
+{
+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();
+
+
+};
+
+typedef DPL::SharedPtr<EventBTGetDevice> EventBTGetDevicePtr;
+} 
+}
+}
+#endif 
diff --git a/src/platform/API/Bluetooth/EventBTGetKnownDevices.cpp b/src/platform/API/Bluetooth/EventBTGetKnownDevices.cpp
new file mode 100644 (file)
index 0000000..4152ab1
--- /dev/null
@@ -0,0 +1,36 @@
+//
+// 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 TizenApis {
+namespace Api {
+namespace Bluetooth {  
+
+void EventBTGetKnownDevices::addDevice(BluetoothDeviceData device)
+{
+       m_Devices.push_back(device);
+}
+
+std::vector<BluetoothDeviceData> EventBTGetKnownDevices::getDevices()
+{
+       return m_Devices;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Bluetooth/EventBTGetKnownDevices.h b/src/platform/API/Bluetooth/EventBTGetKnownDevices.h
new file mode 100644 (file)
index 0000000..38acb8e
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTOnDiscoveryDevices.cpp b/src/platform/API/Bluetooth/EventBTOnDiscoveryDevices.cpp
new file mode 100644 (file)
index 0000000..51498f5
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTOnDiscoveryDevices.h b/src/platform/API/Bluetooth/EventBTOnDiscoveryDevices.h
new file mode 100644 (file)
index 0000000..040352a
--- /dev/null
@@ -0,0 +1,62 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTRegisterRFCOMM.h b/src/platform/API/Bluetooth/EventBTRegisterRFCOMM.h
new file mode 100644 (file)
index 0000000..03334de
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTServiceOnConnect.cpp b/src/platform/API/Bluetooth/EventBTServiceOnConnect.cpp
new file mode 100644 (file)
index 0000000..0a78ce3
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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 TizenApis {
+namespace Api {
+namespace Bluetooth {
+
+EventBTServiceOnConnect::EventBTServiceOnConnect()
+{
+       
+}
+
+EventBTServiceOnConnect::~EventBTServiceOnConnect()
+{
+}
+
+void EventBTServiceOnConnect::setSocketData(BluetoothSocketData socketData) 
+{ 
+       m_socketData = socketData;
+}
+
+BluetoothSocketData EventBTServiceOnConnect::getSocketData() 
+{ 
+       return m_socketData;
+}
+
+
+
+}
+}
+}
+
diff --git a/src/platform/API/Bluetooth/EventBTServiceOnConnect.h b/src/platform/API/Bluetooth/EventBTServiceOnConnect.h
new file mode 100644 (file)
index 0000000..c5a1bfb
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTSetName.h b/src/platform/API/Bluetooth/EventBTSetName.h
new file mode 100644 (file)
index 0000000..6cc1839
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// 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_NAME_H
+#define TIZENAPIS_API_BLUETOOTH_SET_NAME_H
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Bluetooth {
+       
+class EventBTSetName;
+
+typedef DPL::SharedPtr<EventBTSetName> EventBTSetNamePtr;
+
+class EventBTSetName :
+    public WrtDeviceApis::Commons::IEvent<EventBTSetName>
+{
+public:
+       EventBTSetName(){}
+       ~EventBTSetName(){}
+       void setName(std::string name) { m_name = name;}
+       std::string getName() { return m_name;}
+private:
+       std::string m_name;
+};
+}
+}
+}
+#endif
+
diff --git a/src/platform/API/Bluetooth/EventBTSetPowered.h b/src/platform/API/Bluetooth/EventBTSetPowered.h
new file mode 100644 (file)
index 0000000..8f58e16
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTSetVisible.h b/src/platform/API/Bluetooth/EventBTSetVisible.h
new file mode 100644 (file)
index 0000000..3a219ca
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTSocketNotification.cpp b/src/platform/API/Bluetooth/EventBTSocketNotification.cpp
new file mode 100644 (file)
index 0000000..6849266
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTSocketNotification.h b/src/platform/API/Bluetooth/EventBTSocketNotification.h
new file mode 100644 (file)
index 0000000..46e7de2
--- /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 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 TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/EventBTStopDiscovery.h b/src/platform/API/Bluetooth/EventBTStopDiscovery.h
new file mode 100644 (file)
index 0000000..5673541
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// 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 TizenApis {
+namespace Api {
+namespace Bluetooth {
+
+class EventBTStopDiscovery : public WrtDeviceApis::Commons::IEvent<EventBTStopDiscovery>
+{
+private:
+public:
+       EventBTStopDiscovery()
+       {
+       }
+
+       ~EventBTStopDiscovery() { }
+};
+
+typedef DPL::SharedPtr<EventBTStopDiscovery> EventBTStopDiscoveryPtr;
+}
+}
+}
+#endif 
+
diff --git a/src/platform/API/Bluetooth/EventBTUnregisterRFCOMM.h b/src/platform/API/Bluetooth/EventBTUnregisterRFCOMM.h
new file mode 100644 (file)
index 0000000..2ef7fb5
--- /dev/null
@@ -0,0 +1,42 @@
+//
+// 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 TizenApis {
+namespace Api {
+namespace Bluetooth {
+
+class EventBTUnregisterRFCOMMService : public WrtDeviceApis::Commons::IEvent<EventBTUnregisterRFCOMMService>
+{
+public:
+       EventBTUnregisterRFCOMMService() { }
+       ~EventBTUnregisterRFCOMMService() { }
+};
+
+typedef DPL::SharedPtr<EventBTUnregisterRFCOMMService> EventBTUnregisterRFCOMMServicePtr;
+}
+}
+}
+#endif 
+
diff --git a/src/platform/API/Bluetooth/IBluetoothAdapterManager.cpp b/src/platform/API/Bluetooth/IBluetoothAdapterManager.cpp
new file mode 100644 (file)
index 0000000..6094815
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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"
+
+using namespace TizenApis::Api;
+
+
+namespace TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/IBluetoothAdapterManager.h b/src/platform/API/Bluetooth/IBluetoothAdapterManager.h
new file mode 100644 (file)
index 0000000..6944caa
--- /dev/null
@@ -0,0 +1,89 @@
+//
+// 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 <API/Bluetooth/EventBTCreateDestroyBonding.h>
+#include <API/Bluetooth/EventBTGetKnownDevices.h>
+#include <API/Bluetooth/EventBTGetDevice.h>
+#include <API/Bluetooth/EventBTSetPowered.h>
+#include <API/Bluetooth/EventBTRegisterRFCOMM.h>
+#include <API/Bluetooth/EventBTSetVisible.h>
+#include <API/Bluetooth/EventBTOnDiscoveryDevices.h>
+#include <API/Bluetooth/EventBTSetName.h>
+#include <API/Bluetooth/EventBTStopDiscovery.h>
+
+using namespace TizenApis::Api;
+
+namespace TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/IBluetoothDeviceManager.cpp b/src/platform/API/Bluetooth/IBluetoothDeviceManager.cpp
new file mode 100644 (file)
index 0000000..dcc399b
--- /dev/null
@@ -0,0 +1,42 @@
+//
+// 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"
+
+using namespace TizenApis::Api;
+
+
+namespace TizenApis {
+namespace Api {
+namespace Bluetooth {
+
+using namespace WrtDeviceApis::Commons;
+
+IBluetoothDeviceManager::IBluetoothDeviceManager() :
+//     EventRequestReceiver<EventBTConnectToServiceByUUID>(ThreadEnum::BLUETOOTH_THREAD)
+       EventRequestReceiver<EventBTConnectToServiceByUUID>(ThreadEnum::NULL_THREAD)
+
+{
+}
+
+IBluetoothDeviceManager::~IBluetoothDeviceManager() {
+}
+}
+}
+}
+
diff --git a/src/platform/API/Bluetooth/IBluetoothDeviceManager.h b/src/platform/API/Bluetooth/IBluetoothDeviceManager.h
new file mode 100644 (file)
index 0000000..82daa98
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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 <API/Bluetooth/EventBTConnectToServiceByUUID.h>
+#include <API/Bluetooth/BTDevice.h>
+
+using namespace TizenApis::Api;
+
+
+namespace TizenApis {
+namespace Api {
+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/platform/API/Bluetooth/IBluetoothServiceHandlerManager.cpp b/src/platform/API/Bluetooth/IBluetoothServiceHandlerManager.cpp
new file mode 100644 (file)
index 0000000..659ad27
--- /dev/null
@@ -0,0 +1,40 @@
+//
+// 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 TizenApis {
+namespace Api {
+namespace Bluetooth {
+
+
+IBluetoothServiceHandlerManager::IBluetoothServiceHandlerManager() :
+//     EventRequestReceiver<EventBTUnregisterRFCOMMService>(ThreadEnum::BLUETOOTH_THREAD)
+       EventRequestReceiver<EventBTUnregisterRFCOMMService>(ThreadEnum::NULL_THREAD)
+{
+}
+
+IBluetoothServiceHandlerManager::~IBluetoothServiceHandlerManager() {
+}
+}
+
+}
+}
+
diff --git a/src/platform/API/Bluetooth/IBluetoothServiceHandlerManager.h b/src/platform/API/Bluetooth/IBluetoothServiceHandlerManager.h
new file mode 100644 (file)
index 0000000..9225d1e
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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 <API/Bluetooth/EventBTUnregisterRFCOMM.h>
+#include <API/Bluetooth/EventBTServiceOnConnect.h>
+
+using namespace TizenApis::Api;
+
+namespace TizenApis {
+namespace Api {
+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 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/platform/API/Bluetooth/IBluetoothSocketManager.cpp b/src/platform/API/Bluetooth/IBluetoothSocketManager.cpp
new file mode 100644 (file)
index 0000000..a541382
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// 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"
+
+using namespace TizenApis::Api;
+
+
+namespace TizenApis {
+namespace Api {
+namespace Bluetooth {
+
+
+IBluetoothSocketManager::IBluetoothSocketManager()
+{
+}
+
+IBluetoothSocketManager::~IBluetoothSocketManager() {
+}
+}
+
+}
+}
+
diff --git a/src/platform/API/Bluetooth/IBluetoothSocketManager.h b/src/platform/API/Bluetooth/IBluetoothSocketManager.h
new file mode 100644 (file)
index 0000000..a1f33fa
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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 <API/Bluetooth/BTDevice.h>
+#include <API/Bluetooth/EventBTSocketNotification.h>
+
+
+using namespace TizenApis::Api;
+
+
+namespace TizenApis {
+namespace Api {
+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
diff --git a/src/platform/API/Bluetooth/config.cmake b/src/platform/API/Bluetooth/config.cmake
new file mode 100644 (file)
index 0000000..8554799
--- /dev/null
@@ -0,0 +1,16 @@
+get_current_path()
+
+set(SRCS_PLATFORM_API_BLUETOOTH
+  ${CURRENT_PATH}/BluetoothFactory.cpp
+  ${CURRENT_PATH}/EventBTGetKnownDevices.cpp
+  ${CURRENT_PATH}/EventBTGetDevice.cpp
+  ${CURRENT_PATH}/EventBTOnDiscoveryDevices.cpp
+  ${CURRENT_PATH}/EventBTSocketNotification.cpp
+  ${CURRENT_PATH}/EventBTCreateDestroyBonding.cpp
+  ${CURRENT_PATH}/IBluetoothAdapterManager.cpp
+  ${CURRENT_PATH}/IBluetoothDeviceManager.cpp
+  ${CURRENT_PATH}/IBluetoothSocketManager.cpp
+  ${CURRENT_PATH}/IBluetoothServiceHandlerManager.cpp
+  ${CURRENT_PATH}/IBluetoothSocketManager.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Calendar/CalendarEvent.cpp b/src/platform/API/Calendar/CalendarEvent.cpp
new file mode 100755 (executable)
index 0000000..7ef9345
--- /dev/null
@@ -0,0 +1,505 @@
+//
+// 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 <Commons/Exception.h>
+#include "CalendarEvent.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+CalendarEvent::CalendarEvent():
+    m_id(UNDEFINED_ITEM_ID),
+    m_parentId(UNDEFINED_ITEM_ID),
+    m_calendarId(UNDEFINED_CALENDAR_ID),
+    m_startTime(UNDEFINED_TIME),
+    m_endTime(UNDEFINED_TIME),
+    m_recurrence(new EventRecurrenceRule()),
+    m_status(UNDEFINED_STATUS),
+    m_alarms(new EventAlarmList()),
+    m_categories(new StringArray()),
+    m_isAllDay(false),
+    m_lastModifiedDate(UNDEFINED_TIME),
+    m_visibility(PUBLIC_VISIBILITY),
+    m_availability(BUSY_FB),
+    m_uid(UNDEFINED_ID),
+    m_recurrenceId(UNDEFINED_TIME),
+    m_attendees(new EventAttendeeList()),
+    m_isDetached(false),
+    m_attributesOfInterest(new AttributeList()),
+    m_latitude(UNDEFINED_GEO),
+    m_longitude(UNDEFINED_GEO),
+    m_timeZone(DEFAULT_TIMEZONE),
+    m_priority(LOW_PRIORITY),
+    m_createdDate(UNDEFINED_TIME),
+    m_completedDate(UNDEFINED_TIME),
+    m_progress(0),
+    m_calendarType(EVENT_TYPE)
+{
+}
+
+CalendarEvent::CalendarEvent(const CalendarEvent &original)
+{
+    LogDebug("Copy constructor called.");
+
+    m_id = original.getId();
+    m_parentId = original.getParentId();
+    m_calendarId = original.getCalendarId();
+    m_description = original.getDescription();
+    m_subject = original.getSubject();
+    m_startTime = original.getStartTime();
+    m_endTime = original.getEndTime();
+    m_location = original.getLocation();
+
+    EventRecurrenceRulePtr recurrenceRulePtr( new EventRecurrenceRule() );
+    m_recurrence = recurrenceRulePtr;
+    m_recurrence->setFrequency(original.getRecurrenceRule()->getFrequency());
+    m_recurrence->setInterval(original.getRecurrenceRule()->getInterval());
+    m_recurrence->setEndDate(original.getRecurrenceRule()->getEndDate());
+    m_recurrence->setOccurrenceCount(original.getRecurrenceRule()->getOccurrenceCount());
+    m_recurrence->setDaysOfTheMonth(original.getRecurrenceRule()->getDaysOfTheMonth());
+    m_recurrence->setDaysOfTheWeek(original.getRecurrenceRule()->getDaysOfTheWeek());
+    m_recurrence->setDaysOfTheYear(original.getRecurrenceRule()->getDaysOfTheYear());
+    m_recurrence->setWeeksOfTheYear(original.getRecurrenceRule()->getWeeksOfTheYear());
+    m_recurrence->setSetPositions(original.getRecurrenceRule()->getSetPositions());
+    m_recurrence->setExceptions(original.getRecurrenceRule()->getExceptions());
+    m_recurrence->setTimeZone(original.getRecurrenceRule()->getTimeZone());
+
+    m_status = original.getStatus();
+
+    LogDebug("Copying alarms...");
+    EventAlarmListPtr alarmsPtr( new EventAlarmList() );
+    m_alarms = alarmsPtr;
+    for( unsigned int i=0; i<original.getAlarms()->size(); i++) {
+        EventAlarmPtr alarmPtr( new EventAlarm() );
+        alarmPtr->setAbsoluteDate(original.getAlarms()->at(i)->getAbsoluteDate());
+        alarmPtr->setDuration(original.getAlarms()->at(i)->getDuration());
+        alarmPtr->setMethods(original.getAlarms()->at(i)->getMethods());
+        alarmPtr->setTimeZone(original.getAlarms()->at(i)->getTimeZone());
+        alarmPtr->setDescription(original.getAlarms()->at(i)->getDescription());
+        m_alarms->push_back(alarmPtr);
+    }
+
+    StringArrayPtr categoriesPtr( new StringArray() );
+    m_categories = categoriesPtr;
+    *m_categories = *(original.getCategories());
+
+    m_isAllDay = original.getIsAllDay();
+    m_organizer = original.getOrganizer();
+    m_lastModifiedDate = original.getLastModifiedDate();
+    m_visibility = original.getVisibility();
+    m_availability = original.getAvailability();
+    m_uid = original.getUId();
+    m_recurrenceId = original.getRecurrenceId();
+
+    LogDebug("Copying attendees...");
+    EventAttendeeListPtr attendeesPtr( new EventAttendeeList() );
+    m_attendees = attendeesPtr;
+    for( unsigned int i=0; i<original.getAttendees()->size(); i++) {
+        EventAttendeePtr attendeePtr( new EventAttendee() );
+        attendeePtr->setName(original.getAttendees()->at(i)->getName());
+        attendeePtr->setURI(original.getAttendees()->at(i)->getURI());
+        attendeePtr->setRole(original.getAttendees()->at(i)->getRole());
+        attendeePtr->setStatus(original.getAttendees()->at(i)->getStatus());
+        attendeePtr->setRSVP(original.getAttendees()->at(i)->getRSVP());
+        attendeePtr->setType(original.getAttendees()->at(i)->getType());
+        attendeePtr->setGroup(original.getAttendees()->at(i)->getGroup());
+        attendeePtr->setDelegatorURI(original.getAttendees()->at(i)->getDelegatorURI());
+        attendeePtr->setDelegateURI(original.getAttendees()->at(i)->getDelegateURI());
+        attendeePtr->setAddressBookId(original.getAttendees()->at(i)->getAddressBookId());
+        attendeePtr->setContactId(original.getAttendees()->at(i)->getContactId());
+        m_attendees->push_back(attendeePtr);
+    }
+
+    m_isDetached = original.getIsDetached();
+
+    AttributeListPtr attributesPtr( new AttributeList() );
+    m_attributesOfInterest = attributesPtr;
+    *m_attributesOfInterest = *(original.getAttributesOfInterest());
+
+    m_latitude = original.getLatitude();
+    m_longitude = original.getLongitude();
+
+    m_timeZone = original.getTimeZone();
+    m_priority = original.getPriority();
+    m_createdDate = original.getCreatedDate();
+    m_completedDate = original.getCompletedDate();
+    m_progress = original.getProgress();
+    m_calendarType = original.getCalendarType();
+
+    LogDebug("Copying done.");
+}
+
+CalendarEvent::~CalendarEvent()
+{
+}
+
+int CalendarEvent::getId() const
+{
+    return m_id;
+}
+
+void CalendarEvent::setId(int value)
+{
+    m_id = value;
+
+    // Set the uid also.
+    std::stringstream ss;
+    ss<<value;
+    m_uid = ss.str();
+    LogDebug("m_id: "<<m_id<<", m_uid: "<<m_uid);
+}
+
+void CalendarEvent::resetId()
+{
+    m_id = UNDEFINED_ITEM_ID;
+    m_uid = UNDEFINED_ID;
+}
+
+bool CalendarEvent::getIdIsSet() const
+{
+    return !(m_id==UNDEFINED_ITEM_ID);
+}
+
+int CalendarEvent::getParentId() const
+{
+    return m_parentId;
+}
+
+void CalendarEvent::setParentId(int value)
+{
+    m_parentId = value;
+}
+
+int CalendarEvent::getCalendarId() const
+{
+    return m_calendarId;
+}
+
+void CalendarEvent::setCalendarId(int value)
+{
+    m_calendarId = value;
+}
+
+std::string CalendarEvent::getDescription() const
+{
+    return m_description;
+}
+
+void CalendarEvent::setDescription(const std::string &value)
+{
+    m_description = value;
+}
+
+std::string CalendarEvent::getSubject() const
+{
+    return m_subject;
+}
+
+void CalendarEvent::setSubject(const std::string &value)
+{
+    m_subject = value;
+}
+
+long long int CalendarEvent::getStartTime() const
+{
+    return m_startTime;
+}
+
+void CalendarEvent::setStartTime(long long int value)
+{
+    m_startTime = value;
+}
+
+long long int CalendarEvent::getEndTime() const
+{
+    return m_endTime;
+}
+
+void CalendarEvent::setEndTime(long long int value)
+{
+    m_endTime = value;
+}
+
+std::string CalendarEvent::getLocation() const
+{
+    return m_location;
+}
+
+void CalendarEvent::setLocation(const std::string &value)
+{
+    m_location = value;
+}
+
+EventRecurrenceRulePtr CalendarEvent::getRecurrenceRule() const
+{
+    return m_recurrence;
+}
+
+void CalendarEvent::setRecurrenceRule(EventRecurrenceRulePtr value)
+{
+    m_recurrence = value;
+}
+
+CalendarEvent::EventStatus CalendarEvent::getStatus() const
+{
+    return m_status == UNDEFINED_STATUS ? TENTATIVE_STATUS : m_status;
+}
+
+void CalendarEvent::setStatus(EventStatus value)
+{
+    m_status = value;
+}
+
+EventAlarmListPtr CalendarEvent::getAlarms() const
+{
+    return m_alarms;
+}
+void CalendarEvent::setAlarms(const EventAlarmListPtr value)
+{
+    m_alarms = value;
+}
+
+StringArrayPtr CalendarEvent::getCategories() const
+{
+    return m_categories;
+}
+void CalendarEvent::setCategories(const StringArrayPtr value)
+{
+    m_categories = value;
+}
+
+void CalendarEvent::display() const
+{
+    LogDebug("m_id " << m_id);
+    LogDebug("m_parentId " << m_parentId);
+    LogDebug("m_calendarId " << m_calendarId);
+    LogDebug("m_calendarType " << m_calendarType);
+    LogDebug("m_description " << m_description);
+    LogDebug("m_subject " << m_subject);
+
+    LogDebug("m_startTime " << m_startTime);
+
+    LogDebug("m_endTime " << m_endTime);
+    LogDebug("m_location " << m_location);
+    LogDebug("m_recurrence " << m_recurrence);
+    LogDebug("m_status " << m_status);
+    LogDebug("m_isAllDay " << m_isAllDay);
+    LogDebug("m_organizer " << m_organizer);
+    LogDebug("m_lastModifiedDate " << m_lastModifiedDate);
+    LogDebug("m_visibility " << m_visibility);
+    LogDebug("m_availability " << m_availability);
+
+    if(m_recurrence->getFrequency()!=EventRecurrenceRule::NO_RECURRENCE) {
+        LogDebug("recurrence frequency " << m_recurrence->getFrequency());
+        LogDebug("recurrence interval " << m_recurrence->getInterval());
+        LogDebug("recurrence recurrenceCount " << m_recurrence->getOccurrenceCount());
+        LogDebug("recurrence endDate " << m_recurrence->getEndDate());
+    }
+}
+
+bool CalendarEvent::validate() const
+{
+    LogInfo("Nothing to validate.");
+    return true;
+}
+
+bool CalendarEvent::getIsAllDay() const
+{
+    return m_isAllDay;
+}
+
+void CalendarEvent::setIsAllDay(bool value)
+{
+    m_isAllDay = value;
+}
+
+std::string CalendarEvent::getOrganizer() const
+{
+    return m_organizer;
+}
+
+void CalendarEvent::setOrganizer(const std::string &value)
+{
+    m_organizer = value;
+}
+
+long long int CalendarEvent::getLastModifiedDate() const
+{
+    return m_lastModifiedDate;
+}
+
+void CalendarEvent::setLastModifiedDate(long long int value)
+{
+    m_lastModifiedDate = value;
+}
+
+CalendarEvent::EventVisibility CalendarEvent::getVisibility() const
+{
+    return m_visibility == UNDEFINED_VISIBILITY ? PUBLIC_VISIBILITY : m_visibility;
+}
+
+void CalendarEvent::setVisibility(EventVisibility value)
+{
+    m_visibility = value;
+}
+
+CalendarEvent::EventAvailability CalendarEvent::getAvailability() const
+{
+    return m_availability == UNDEFINED_AVAILABILITY ? BUSY_FB : m_availability;
+}
+
+void CalendarEvent::setAvailability(EventAvailability value)
+{
+    m_availability = value;
+}
+
+std::string CalendarEvent::getUId() const
+{
+    return m_uid;
+}
+
+void CalendarEvent::setUId(const std::string &value)
+{
+    m_uid = value;
+}
+
+long long int CalendarEvent::getRecurrenceId() const
+{
+    return m_recurrenceId;
+}
+
+void CalendarEvent::setRecurrenceId(long long int value)
+{
+    m_recurrenceId = value;
+}
+
+EventAttendeeListPtr CalendarEvent::getAttendees() const
+{
+    return m_attendees;
+}
+
+void CalendarEvent::setAttendees(const EventAttendeeListPtr value)
+{
+    m_attendees = value;
+}
+
+bool CalendarEvent::getIsDetached() const
+{
+    return m_isDetached;
+}
+
+void CalendarEvent::setIsDetached(bool value)
+{
+    m_isDetached = value;
+}
+
+AttributeListPtr CalendarEvent::getAttributesOfInterest() const
+{
+    return m_attributesOfInterest;
+}
+
+void CalendarEvent::setAttributesOfInterest(AttributeListPtr value)
+{
+    m_attributesOfInterest = value;
+}
+
+double CalendarEvent::getLatitude() const
+{
+    return m_latitude;
+}
+
+void CalendarEvent::setLatitude(double value)
+{
+    m_latitude = value;
+}
+
+double CalendarEvent::getLongitude() const
+{
+    return m_longitude;
+}
+
+void CalendarEvent::setLongitude(double value)
+{
+    m_longitude = value;
+}
+
+std::string CalendarEvent::getTimeZone() const
+{
+    return m_timeZone;
+}
+
+void CalendarEvent::setTimeZone(std::string value)
+{
+    m_timeZone = value;
+}
+
+CalendarEvent::TaskPriority CalendarEvent::getPriority() const
+{
+    return m_priority;
+}
+
+void CalendarEvent::setPriority(TaskPriority value)
+{
+    m_priority = value;
+}
+
+long long int CalendarEvent::getCreatedDate() const
+{
+    return m_createdDate;
+}
+
+void CalendarEvent::setCreatedDate(long long int value)
+{
+    m_createdDate = value;
+}
+
+long long int CalendarEvent::getCompletedDate() const
+{
+    return m_completedDate;
+}
+
+void CalendarEvent::setCompletedDate(long long int value)
+{
+    m_completedDate = value;
+}
+
+int CalendarEvent::getProgress() const
+{
+    return m_progress;
+}
+
+void CalendarEvent::setProgress(int value)
+{
+    m_progress = value;
+}
+
+CalendarEvent::CalendarType CalendarEvent::getCalendarType() const
+{
+    return m_calendarType;
+}
+
+void CalendarEvent::setCalendarType(CalendarType type)
+{
+    m_calendarType = type;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Calendar/CalendarEvent.h b/src/platform/API/Calendar/CalendarEvent.h
new file mode 100755 (executable)
index 0000000..a2cba55
--- /dev/null
@@ -0,0 +1,239 @@
+//
+// 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 _ABSTRACT_LAYER_CALENDAR_EVENT_H_
+#define _ABSTRACT_LAYER_CALENDAR_EVENT_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+#include "EventAlarm.h"
+#include "EventAttendee.h"
+#include "EventRecurrenceRule.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+#define UNDEFINED_CALENDAR_ID -1
+#define UNDEFINED_ITEM_ID -1
+#define UNDEFINED_GEO -1
+#define UNDEFINED_ID "-1"
+
+typedef std::vector<std::string> AttributeList;
+typedef DPL::SharedPtr<AttributeList> AttributeListPtr;
+
+/* This object represents a single calendar event */
+class CalendarEvent
+{
+  public:
+    typedef enum
+    {
+        TENTATIVE_STATUS,
+        CONFIRMED_STATUS,
+        CANCELLED_STATUS,
+        NEEDS_ACTION_STATUS,
+        IN_PROCESS_STATUS,
+        COMPLETED_STATUS,
+        UNDEFINED_STATUS
+    } EventStatus;
+
+    typedef enum
+    {
+        PUBLIC_VISIBILITY,
+        PRIVATE_VISIBILITY,
+        CONFIDENTIAL_VISIBILITY,
+        UNDEFINED_VISIBILITY
+    } EventVisibility;
+
+    typedef enum
+    {
+        BUSY_FB,
+        BUSY_UNAVAILABLE_FB,
+        FREE_FB,
+        BUSY_TENTATIVE_FB,
+        UNDEFINED_AVAILABILITY
+    } EventAvailability;
+
+    typedef enum
+    {
+        LOW_PRIORITY,
+        MEDIUM_PRIORITY,
+        HIGH_PRIORITY,
+        UNDEFINED_PRIORITY
+    } TaskPriority;
+
+    typedef enum
+    {
+        ICALENDAR_20,
+        VCALENDAR_10,
+        UNDEFINED_FORMAT
+    } VObjectFormat;
+
+    typedef enum
+    {
+        EVENT_TYPE = 0,
+        TASK_TYPE,
+        UNDEFINED_TYPE
+    } CalendarType;
+
+
+    CalendarEvent();
+    CalendarEvent(const CalendarEvent &original); // copy constructor for clone operation
+    virtual ~CalendarEvent();
+
+    int getId() const;
+    void setId(int value);
+    void resetId();
+    bool getIdIsSet() const;
+
+    int getParentId() const;
+    void setParentId(int value);
+
+    int getCalendarId() const;
+    void setCalendarId(int value);
+
+    std::string getDescription() const;
+    void setDescription(const std::string &value);
+
+    std::string getSubject() const;
+    void setSubject(const std::string &value);
+
+    long long int getStartTime() const;
+    void setStartTime(long long int value);
+
+    long long int getEndTime() const;
+    void setEndTime(long long int value);
+
+    std::string getLocation() const;
+    void setLocation(const std::string &value);
+
+    EventRecurrenceRulePtr getRecurrenceRule() const;
+    void setRecurrenceRule(EventRecurrenceRulePtr value);
+
+    EventStatus getStatus() const;
+    void setStatus(EventStatus value);
+
+    EventAlarmListPtr getAlarms() const;
+    void setAlarms(const EventAlarmListPtr value);
+
+    StringArrayPtr getCategories() const;
+    void setCategories(const StringArrayPtr value);
+
+    void display() const;
+    bool validate() const;
+
+    bool getIsAllDay() const;
+    void setIsAllDay(bool value);
+
+    long long int getLastModifiedDate() const;
+    void setLastModifiedDate(long long int value);
+
+    std::string getOrganizer() const;
+    void setOrganizer(const std::string &value);
+
+    EventVisibility getVisibility() const;
+    void setVisibility(EventVisibility value);
+
+    EventAvailability getAvailability() const;
+    void setAvailability(EventAvailability value);
+
+    std::string getUId() const;
+    void setUId(const std::string &value);
+
+    long long int getRecurrenceId() const;
+    void setRecurrenceId(long long int value);
+
+    EventAttendeeListPtr getAttendees() const;
+    void setAttendees(const EventAttendeeListPtr value);
+
+    bool getIsDetached() const;
+    void setIsDetached(bool value);
+
+    void setAttributesOfInterest(AttributeListPtr value);
+    AttributeListPtr getAttributesOfInterest() const;
+
+    double getLatitude() const;
+    void setLatitude(double value);
+
+    double getLongitude() const;
+    void setLongitude(double value);
+
+    void setTimeZone(std::string value);
+    std::string getTimeZone() const;
+
+    TaskPriority getPriority() const;
+    void setPriority(TaskPriority value);
+
+    long long int getCreatedDate() const;
+    void setCreatedDate(long long int value);
+
+    long long int getCompletedDate() const;
+    void setCompletedDate(long long int value);
+
+    int getProgress() const;
+    void setProgress(int value);
+
+    CalendarType getCalendarType() const;
+    void setCalendarType(CalendarType type);
+
+  protected:
+    int m_id;
+    int m_parentId; // the parent id if it's detached.
+    int m_calendarId;
+    std::string m_description;
+    std::string m_subject;
+    long long int m_startTime;
+    long long int m_endTime;
+    std::string m_location;
+    EventRecurrenceRulePtr m_recurrence;
+    EventStatus m_status;
+    EventAlarmListPtr m_alarms;
+    StringArrayPtr m_categories;
+    bool m_isAllDay;
+    std::string m_organizer;
+    long long int m_lastModifiedDate;
+    EventVisibility m_visibility;
+    EventAvailability m_availability;
+    std::string m_uid; // uid is same with id.
+    long long int m_recurrenceId;
+    EventAttendeeListPtr m_attendees;
+    bool m_isDetached;
+    AttributeListPtr m_attributesOfInterest;
+    double m_latitude;
+    double m_longitude;
+    std::string m_timeZone;
+    TaskPriority m_priority;
+    long long int m_createdDate;
+    long long int m_completedDate;
+    int m_progress;
+    CalendarType m_calendarType;
+};
+
+typedef DPL::SharedPtr<CalendarEvent> CalendarEventPtr;
+typedef std::vector<CalendarEventPtr> CalendarEventList;
+typedef DPL::SharedPtr<CalendarEventList> CalendarEventListPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_CALENDAR_EVENT_H_ */
+
diff --git a/src/platform/API/Calendar/CalendarFactory.cpp b/src/platform/API/Calendar/CalendarFactory.cpp
new file mode 100755 (executable)
index 0000000..f49630d
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 "CalendarFactory.h"
+#include "ICalendarManager.h"
+#include "ICalendar.h"
+#include <Calendar/CalendarManager.h>
+
+using namespace TizenApis::Platform::Calendar;
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+ICalendarManagerPtr CalendarFactory::createCalendarManagerObject()
+{
+    ICalendarManagerPtr result(new CalendarManager());
+    return result;
+}
+
+ICalendarPtr CalendarFactory::createCalendarObject()
+{
+    ICalendarPtr result(new TizenApis::Platform::Calendar::Calendar());
+    return result;
+}
+
+CalendarFactory& CalendarFactory::getInstance()
+{
+    static CalendarFactory theInstance;
+    return theInstance;
+}
+
+}
+}
+}
\ No newline at end of file
diff --git a/src/platform/API/Calendar/CalendarFactory.h b/src/platform/API/Calendar/CalendarFactory.h
new file mode 100755 (executable)
index 0000000..4b7e57c
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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 _ABSTRACT_LAYER_CALENDAR_FACTORY_H_
+#define _ABSTRACT_LAYER_CALENDAR_FACTORY_H_
+
+#include "ICalendarManager.h"
+#include "ICalendar.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class CalendarFactory : private DPL::Noncopyable
+{
+  private:
+    CalendarFactory()
+    {
+    }
+  public:
+    static CalendarFactory& getInstance();
+    ICalendarManagerPtr    createCalendarManagerObject();
+    ICalendarPtr           createCalendarObject();
+};
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_CALENDAR_FACTORY_H_ */
diff --git a/src/platform/API/Calendar/EventAlarm.cpp b/src/platform/API/Calendar/EventAlarm.cpp
new file mode 100755 (executable)
index 0000000..c563f21
--- /dev/null
@@ -0,0 +1,83 @@
+//
+// 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 "EventAlarm.h"
+#include "EventRecurrenceRule.h"
+#include <dpl/log/log.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+EventAlarm::EventAlarm()
+{
+    m_absoluteDate = UNDEFINED_TIME;
+    m_timeZone = DEFAULT_TIMEZONE;
+}
+EventAlarm::~EventAlarm()
+{
+}
+
+long long int EventAlarm::getAbsoluteDate() const
+{
+    return m_absoluteDate;
+}
+void EventAlarm::setAbsoluteDate(const long long int &value)
+{
+    m_absoluteDate = value;
+}
+
+TizenApis::Api::TimeUtil::DurationProperties EventAlarm::getDuration() const
+{
+    return m_duration;
+}
+void EventAlarm::setDuration(TizenApis::Api::TimeUtil::DurationProperties value)
+{
+    m_duration = value;
+}
+
+std::vector<EventAlarm::EventAlarmType> EventAlarm::getMethods() const
+{
+    return m_methods;
+}
+void EventAlarm::setMethods(const std::vector<EventAlarm::EventAlarmType> &value)
+{
+    m_methods = value;
+}
+
+std::string EventAlarm::getTimeZone() const
+{
+    return m_timeZone;
+}
+void EventAlarm::setTimeZone(const std::string &value)
+{
+    m_timeZone = value;
+}
+
+std::string EventAlarm::getDescription() const
+{
+    return m_description;
+}
+void EventAlarm::setDescription(const std::string &value)
+{
+    m_description = value;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Calendar/EventAlarm.h b/src/platform/API/Calendar/EventAlarm.h
new file mode 100755 (executable)
index 0000000..ea8c747
--- /dev/null
@@ -0,0 +1,77 @@
+//
+// 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 _EVENT_ALARM_H_
+#define _EVENT_ALARM_H_
+
+#include <vector>
+#include <ctime>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "API/TimeUtil/DurationProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class EventAlarm
+{
+  public:
+    typedef enum
+    {
+        NO_ALARM,
+        SILENT_ALARM,
+        SOUND_ALARM,
+        UNDEFINED_ALARM_TYPE
+    } EventAlarmType;
+
+    EventAlarm();
+    virtual ~EventAlarm();
+
+    long long int getAbsoluteDate() const;
+    void setAbsoluteDate(const long long int &value);
+
+    TizenApis::Api::TimeUtil::DurationProperties getDuration() const;
+    void setDuration(TizenApis::Api::TimeUtil::DurationProperties value);
+
+    std::vector<EventAlarmType> getMethods() const;
+    void setMethods(const std::vector<EventAlarmType> &value);
+
+    std::string getTimeZone() const;
+    void setTimeZone(const std::string &value);
+
+    std::string getDescription() const;
+    void setDescription(const std::string &value);
+
+  protected:
+    long long int m_absoluteDate;
+    TizenApis::Api::TimeUtil::DurationProperties m_duration;
+    std::vector<EventAlarmType> m_methods;
+    std::string m_description;
+    std::string m_timeZone;
+};
+
+typedef DPL::SharedPtr<EventAlarm> EventAlarmPtr;
+typedef std::vector<EventAlarmPtr> EventAlarmList;
+typedef DPL::SharedPtr<EventAlarmList> EventAlarmListPtr;
+
+}
+}
+}
+
+#endif /* _EVENT_ALARM_H_ */
diff --git a/src/platform/API/Calendar/EventAttendee.cpp b/src/platform/API/Calendar/EventAttendee.cpp
new file mode 100755 (executable)
index 0000000..20d4cf9
--- /dev/null
@@ -0,0 +1,150 @@
+//
+// 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 "EventAttendee.h"
+#include <dpl/log/log.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+EventAttendee::EventAttendee()
+{
+    m_role = REQ_PARTICIPANT_ROLE;
+    m_status = PENDING_AT_STATUS;
+    m_RSVP = false;
+    m_type = INDIVIDUAL_TYPE;
+}
+
+EventAttendee::~EventAttendee()
+{
+}
+
+std::string EventAttendee::getName() const
+{
+    return m_name;
+}
+
+void EventAttendee::setName(const std::string &value)
+{
+    m_name = value;
+}
+
+std::string EventAttendee::getURI() const
+{
+    return m_uri;
+}
+
+void EventAttendee::setURI(const std::string &value)
+{
+    m_uri = value;
+}
+
+EventAttendee::EventAttendeeRole EventAttendee::getRole() const
+{
+    return m_role;
+}
+
+void EventAttendee::setRole(EventAttendeeRole value)
+{
+    m_role = value;
+}
+
+EventAttendee::EventAttendeeStatus EventAttendee::getStatus() const
+{
+    return m_status;
+}
+
+void EventAttendee::setStatus(EventAttendeeStatus value)
+{
+    m_status = value;
+}
+
+bool EventAttendee::getRSVP() const
+{
+    return m_RSVP;
+}
+
+void EventAttendee::setRSVP(bool value)
+{
+    m_RSVP = value;
+}
+
+EventAttendee::EventAttendeeType EventAttendee::getType() const
+{
+    return m_type;
+}
+
+void EventAttendee::setType(EventAttendeeType value)
+{
+    m_type = value;
+}
+
+std::string EventAttendee::getGroup() const
+{
+    return m_group;
+}
+
+void EventAttendee::setGroup(const std::string &value)
+{
+    m_group = value;
+}
+
+std::string EventAttendee::getDelegatorURI() const
+{
+    return m_delegatorURI;
+}
+
+void EventAttendee::setDelegatorURI(const std::string &value)
+{
+    m_delegatorURI = value;
+}
+
+std::string EventAttendee::getDelegateURI() const
+{
+    return m_delegateURI;
+}
+
+void EventAttendee::setDelegateURI(const std::string &value)
+{
+    m_delegateURI = value;
+}
+
+std::string EventAttendee::getAddressBookId() const
+{
+    return m_addressBookId;
+}
+
+void EventAttendee::setAddressBookId(const std::string &value)
+{
+    m_addressBookId = value;
+}
+
+std::string EventAttendee::getContactId() const
+{
+    return m_contactId;
+}
+
+void EventAttendee::setContactId(const std::string &value)
+{
+    m_contactId = value;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Calendar/EventAttendee.h b/src/platform/API/Calendar/EventAttendee.h
new file mode 100755 (executable)
index 0000000..463426d
--- /dev/null
@@ -0,0 +1,123 @@
+//
+// 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 _ABSTRACT_LAYER_EVENT_ATTENDEE_H_
+#define _ABSTRACT_LAYER_EVENT_ATTENDEE_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class EventAttendee
+{
+  public:
+
+    typedef enum
+    {
+        REQ_PARTICIPANT_ROLE,
+        OPT_PARTICIPANT_ROLE,
+        NON_PARTICIPANT_ROLE,
+        CHAIR_ROLE,
+        UNDEFINED_ATTENDEE_ROLE
+    } EventAttendeeRole;
+
+    typedef enum
+    {
+        PENDING_AT_STATUS,
+        ACCEPTED_AT_STATUS,
+        DECLINED_AT_STATUS,
+        TENTATIVE_AT_STATUS,
+        DELEGATED_AT_STATUS,
+        COMPLETED_AT_STATUS,
+        IN_PROCESS_AT_STATUS,
+        UNDEFINED_ATTENDEE_STATUS
+    } EventAttendeeStatus;
+
+    typedef enum
+    {
+        INDIVIDUAL_TYPE,
+        GROUP_TYPE,
+        RESOURCE_TYPE,
+        ROOM_TYPE,
+        UNKNOWN_TYPE,
+        UNDEFINED_ATTENDEE_TYPE
+    } EventAttendeeType;
+
+    EventAttendee();
+    virtual ~EventAttendee();
+
+    std::string getName() const;
+    void setName(const std::string &value);
+
+    std::string getURI() const;
+    void setURI(const std::string &value);
+
+    EventAttendeeRole getRole() const;
+    void setRole(EventAttendeeRole value);
+
+    EventAttendeeStatus getStatus() const;
+    void setStatus(EventAttendeeStatus value);
+
+    bool getRSVP() const;
+    void setRSVP(bool value);
+
+    EventAttendeeType getType() const;
+    void setType(EventAttendeeType value);
+
+    std::string getGroup() const;
+    void setGroup(const std::string &value);
+
+    std::string getDelegatorURI() const;
+    void setDelegatorURI(const std::string &value);
+
+    std::string getDelegateURI() const;
+    void setDelegateURI(const std::string &value);
+
+    std::string getAddressBookId() const;
+    void setAddressBookId(const std::string &value);
+
+    std::string getContactId() const;
+    void setContactId(const std::string &value);
+
+  protected:
+    std::string m_name;
+    std::string m_uri;
+    EventAttendeeRole m_role;
+    EventAttendeeStatus m_status;
+    bool m_RSVP;
+    EventAttendeeType m_type;
+    std::string m_group;
+    std::string m_delegatorURI;
+    std::string m_delegateURI;
+    std::string m_addressBookId;
+    std::string m_contactId;
+};
+
+typedef DPL::SharedPtr<EventAttendee> EventAttendeePtr;
+typedef std::vector<EventAttendeePtr> EventAttendeeList;
+typedef DPL::SharedPtr<EventAttendeeList> EventAttendeeListPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_EVENT_ATTENDEE_H_ */
diff --git a/src/platform/API/Calendar/EventId.cpp b/src/platform/API/Calendar/EventId.cpp
new file mode 100755 (executable)
index 0000000..ba0c3f7
--- /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.
+//
+
+
+#include "EventId.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+EventId::EventId()
+{
+    m_uid = "";
+    m_recurrenceId = "0";
+    m_calendarType = CalendarEvent::UNDEFINED_TYPE;
+}
+
+EventId::~EventId()
+{
+}
+
+std::string EventId::getUId() const
+{
+    return m_uid;
+}
+
+void EventId::setUId(const std::string &value)
+{
+    m_uid = value;
+}
+
+std::string EventId::getRecurrenceId() const
+{
+    return m_recurrenceId;
+}
+
+void EventId::setRecurrenceId(const std::string &value)
+{
+    m_recurrenceId = value;
+}
+
+CalendarEvent::CalendarType EventId::getCalendarType() const
+{
+    return m_calendarType;
+}
+
+void EventId::setCalendarType(CalendarEvent::CalendarType type)
+{
+    m_calendarType = type;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Calendar/EventId.h b/src/platform/API/Calendar/EventId.h
new file mode 100755 (executable)
index 0000000..081e949
--- /dev/null
@@ -0,0 +1,62 @@
+//
+// 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 _ABSTRACT_LAYER_EVENT_ID_H_
+#define _ABSTRACT_LAYER_EVENT_ID_H_
+
+#include <string>
+#include <ctime>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+#include "CalendarEvent.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class EventId
+{
+  public:
+    EventId();
+    virtual ~EventId();
+
+    std::string getUId() const;
+    void setUId(const std::string &value);
+
+    std::string getRecurrenceId() const;
+    void setRecurrenceId(const std::string &value);
+    
+    CalendarEvent::CalendarType getCalendarType() const;
+    void setCalendarType(CalendarEvent::CalendarType type);
+
+  protected:
+    std::string m_uid;
+    std::string m_recurrenceId;
+    CalendarEvent::CalendarType m_calendarType;
+};
+
+typedef DPL::SharedPtr<EventId> EventIdPtr;
+typedef std::vector<EventIdPtr> EventIdList;
+typedef DPL::SharedPtr<EventIdList> EventIdListPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_EVENT_ID_H_ */
diff --git a/src/platform/API/Calendar/EventRecurrenceRule.cpp b/src/platform/API/Calendar/EventRecurrenceRule.cpp
new file mode 100755 (executable)
index 0000000..db98727
--- /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 "EventRecurrenceRule.h"
+#include <Commons/Exception.h>
+#include <dpl/log/log.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+EventRecurrenceRule::EventRecurrenceRule()
+{
+    m_frequency = NO_RECURRENCE;
+    m_interval = DEFAULT_INTERVAL;
+    m_endDate = UNDEFINED_TIME;
+    m_occurrenceCount = -1;
+    StringArrayPtr stringArrayPtr(new StringArray());
+    m_daysOfTheWeek = stringArrayPtr;
+    NumberArrayPtr numberArraySetPositionsPtr(new NumberArray());
+    m_setPositions = numberArraySetPositionsPtr;
+    NumberArrayPtr numberArrayExceptionsPtr(new NumberArray());
+    m_exceptions = numberArrayExceptionsPtr;
+    m_timeZone = DEFAULT_TIMEZONE;
+}
+
+EventRecurrenceRule::~EventRecurrenceRule()
+{
+}
+
+EventRecurrenceRule::EventRecurrence EventRecurrenceRule::getFrequency() const
+{
+    return m_frequency;
+}
+
+void EventRecurrenceRule::setFrequency(const EventRecurrenceRule::EventRecurrence &value)
+{
+    m_frequency = value;
+}
+
+int EventRecurrenceRule::getInterval() const
+{
+    return m_interval;
+}
+
+void EventRecurrenceRule::setInterval(const int &value)
+{
+    m_interval = value;
+}
+
+long long int EventRecurrenceRule::getEndDate() const
+{
+    return m_endDate;
+}
+
+void EventRecurrenceRule::setEndDate(long long int value)
+{
+    m_endDate = value;
+}
+
+long EventRecurrenceRule::getOccurrenceCount() const
+{
+    return m_occurrenceCount;
+}
+void EventRecurrenceRule::setOccurrenceCount(long value)
+{
+    m_occurrenceCount = value;
+}
+
+std::vector<int> EventRecurrenceRule::getDaysOfTheMonth() const
+{
+    return m_daysOfTheMonth;
+}
+
+void EventRecurrenceRule::setDaysOfTheMonth(std::vector<int> value)
+{
+    m_daysOfTheMonth = value;
+}
+
+StringArrayPtr EventRecurrenceRule::getDaysOfTheWeek() const
+{
+    return m_daysOfTheWeek;
+}
+
+void EventRecurrenceRule::setDaysOfTheWeek(StringArrayPtr value)
+{
+    m_daysOfTheWeek = value;
+}
+
+std::vector<int> EventRecurrenceRule::getDaysOfTheYear() const
+{
+    return m_daysOfTheYear;
+}
+
+void EventRecurrenceRule::setDaysOfTheYear(std::vector<int> value)
+{
+    m_daysOfTheYear = value;
+}
+
+std::vector<int> EventRecurrenceRule::getWeeksOfTheYear() const
+{
+    return m_weeksOfTheYear;
+}
+
+void EventRecurrenceRule::setWeeksOfTheYear(std::vector<int> value)
+{
+    m_weeksOfTheYear = value;
+}
+
+NumberArrayPtr EventRecurrenceRule::getSetPositions() const
+{
+    return m_setPositions;
+}
+
+void EventRecurrenceRule::setSetPositions(NumberArrayPtr value)
+{
+    m_setPositions = value;
+}
+
+NumberArrayPtr EventRecurrenceRule::getExceptions() const
+{
+    return m_exceptions;
+}
+
+void EventRecurrenceRule::setExceptions(NumberArrayPtr value)
+{
+    m_exceptions = value;
+}
+
+std::string EventRecurrenceRule::getTimeZone() const
+{
+    return m_timeZone;
+}
+
+void EventRecurrenceRule::setTimeZone(std::string value)
+{
+    m_timeZone = value;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Calendar/EventRecurrenceRule.h b/src/platform/API/Calendar/EventRecurrenceRule.h
new file mode 100755 (executable)
index 0000000..7eaa80a
--- /dev/null
@@ -0,0 +1,111 @@
+//
+// 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 _EVENT_RECURRENCE_RULE_H_
+#define _EVENT_RECURRENCE_RULE_H_
+
+#include <string>
+#include <vector>
+#include <ctime>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+typedef std::vector<std::string> StringArray;
+typedef DPL::SharedPtr<StringArray> StringArrayPtr;
+
+typedef std::vector<long long int> NumberArray;
+typedef DPL::SharedPtr<NumberArray> NumberArrayPtr;
+
+#define UNDEFINED_TIME -1
+#define DEFAULT_TIMEZONE ""
+#define DEFAULT_INTERVAL 1
+
+class EventRecurrenceRule
+{
+  public:
+
+    typedef enum
+    {
+        NO_RECURRENCE,
+        DAILY_RECURRENCE,
+        WEEKLY_RECURRENCE,
+        MONTHLY_RECURRENCE,
+        YEARLY_RECURRENCE,
+        UNDEFINED_RECURRENCE
+    } EventRecurrence;
+
+    EventRecurrenceRule();
+    virtual ~EventRecurrenceRule();
+
+    EventRecurrence getFrequency() const;
+    void setFrequency(const EventRecurrence &value);
+
+    int getInterval() const;
+    void setInterval(const int &value);
+
+    long long int getEndDate() const;
+    void setEndDate(long long int value);
+
+    long getOccurrenceCount() const;
+    void setOccurrenceCount(long value);
+
+    std::vector<int> getDaysOfTheMonth() const;
+    void setDaysOfTheMonth(std::vector<int> value);
+
+    StringArrayPtr getDaysOfTheWeek() const;
+    void setDaysOfTheWeek(StringArrayPtr value);
+
+    std::vector<int> getDaysOfTheYear() const;
+    void setDaysOfTheYear(std::vector<int> value);
+
+    std::vector<int> getWeeksOfTheYear() const;
+    void setWeeksOfTheYear(std::vector<int> value);
+
+    NumberArrayPtr getSetPositions() const;
+    void setSetPositions(NumberArrayPtr value);
+
+    NumberArrayPtr getExceptions() const;
+    void setExceptions(NumberArrayPtr value);
+
+    std::string getTimeZone() const;
+    void setTimeZone(std::string value);
+
+  protected:
+    EventRecurrence m_frequency;
+    int m_interval;
+    long long int m_endDate;
+    long m_occurrenceCount;
+    std::vector<int> m_daysOfTheMonth;
+    StringArrayPtr m_daysOfTheWeek;
+    std::vector<int> m_daysOfTheYear;
+    std::vector<int> m_weeksOfTheYear;
+    NumberArrayPtr m_setPositions;
+    NumberArrayPtr m_exceptions;
+    std::string m_timeZone;
+};
+
+typedef DPL::SharedPtr<EventRecurrenceRule> EventRecurrenceRulePtr;
+
+}
+}
+}
+
+#endif /* _EVENT_RECURRENCE_RULE_H_ */
diff --git a/src/platform/API/Calendar/ICalendar.cpp b/src/platform/API/Calendar/ICalendar.cpp
new file mode 100755 (executable)
index 0000000..e406ec0
--- /dev/null
@@ -0,0 +1,119 @@
+//
+// 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 "ICalendar.h"
+#include <Commons/ThreadPool.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+ICalendar::ICalendar() :
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventAddEvent>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventAddEvents>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventDeleteEvent>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventDeleteEvents>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateEvent>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateEvents>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventFindEvents>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventCreateEventFromString>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventExportEventToString>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventWatchChanges>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventClearWatch>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventExpandEventRecurrence>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventGet>(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    m_id("-1"),
+    m_accountId(0),
+    m_name(""),
+    m_type(CalendarEvent::EVENT_TYPE),
+    m_lastChangedVersion(-1)
+{
+}
+
+ICalendar::~ICalendar()
+{
+}
+
+void ICalendar::addEvent(IEventAddEventPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventAddEvent>::PostRequest(event);
+}
+
+void ICalendar::addEvents(IEventAddEventsPtr &events)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventAddEvents>::PostRequest(events);
+}
+
+void ICalendar::updateEvent(IEventUpdateEventPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateEvent>::PostRequest(event);
+}
+
+void ICalendar::updateEvents(IEventUpdateEventsPtr &events)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateEvents>::PostRequest(events);
+}
+
+void ICalendar::deleteEvent(IEventDeleteEventPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventDeleteEvent>::PostRequest(event);
+}
+
+void ICalendar::deleteEvents(IEventDeleteEventsPtr &events)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventDeleteEvents>::PostRequest(events);
+}
+
+void ICalendar::findEvents(IEventFindEventsPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventFindEvents>::PostRequest(event);
+}
+
+void ICalendar::createEventFromString(IEventCreateEventFromStringPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventCreateEventFromString>::PostRequest(event);
+}
+
+void ICalendar::exportEventToString(IEventExportEventToStringPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventExportEventToString>::PostRequest(event);
+}
+
+void ICalendar::watchChanges(IEventWatchChangesPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventWatchChanges>::PostRequest(event);
+}
+
+void ICalendar::clearWatch(IEventClearWatchPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventClearWatch>::PostRequest(event);
+}
+
+void ICalendar::expandEventRecurrence(IEventExpandEventRecurrencePtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventExpandEventRecurrence>::PostRequest(event);
+}
+
+void ICalendar::get(IEventGetPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventGet>::PostRequest(event);
+}
+
+}
+}
+}
diff --git a/src/platform/API/Calendar/ICalendar.h b/src/platform/API/Calendar/ICalendar.h
new file mode 100755 (executable)
index 0000000..dbdede0
--- /dev/null
@@ -0,0 +1,154 @@
+//
+// 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 _ABSTRACT_LAYER_ICALENDAR_H_
+#define _ABSTRACT_LAYER_ICALENDAR_H_
+
+#include <string>
+#include <sstream>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include "CalendarEvent.h"
+#include "IEventAddEvent.h"
+#include "IEventAddEvents.h"
+#include "IEventDeleteEvent.h"
+#include "IEventDeleteEvents.h"
+#include "IEventFindEvents.h"
+#include "IEventUpdateEvent.h"
+#include "IEventUpdateEvents.h"
+#include "IEventCreateEventFromString.h"
+#include "IEventExportEventToString.h"
+#include "IEventWatchChanges.h"
+#include "IEventClearWatch.h"
+#include "IEventExpandEventRecurrence.h"
+#include "IEventGet.h"
+#include "OnEventsChanged.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class ICalendar : public WrtDeviceApis::Commons::EventRequestReceiver< IEventAddEvent >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventAddEvents >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventDeleteEvent >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventDeleteEvents >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventUpdateEvent >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventUpdateEvents >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventFindEvents >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventCreateEventFromString >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventExportEventToString >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventWatchChanges >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventClearWatch >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventExpandEventRecurrence >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventGet >
+{
+  public:
+    ICalendar();
+    virtual ~ICalendar();
+    virtual void                addEvent(IEventAddEventPtr &event);
+    virtual void                addEvents(IEventAddEventsPtr &events);
+    virtual void                updateEvent(IEventUpdateEventPtr &event);
+    virtual void                updateEvents(IEventUpdateEventsPtr &events);
+    virtual void                deleteEvent(IEventDeleteEventPtr &event);
+    virtual void                deleteEvents(IEventDeleteEventsPtr &events);
+    virtual void                findEvents(IEventFindEventsPtr &event);
+    virtual void                createEventFromString(IEventCreateEventFromStringPtr &event);
+    virtual void                exportEventToString(IEventExportEventToStringPtr &event);
+    virtual void                watchChanges(IEventWatchChangesPtr &event);
+    virtual void                clearWatch(IEventClearWatchPtr &event);
+       virtual void                            expandEventRecurrence(IEventExpandEventRecurrencePtr &event);
+       virtual void                            get(IEventGetPtr &event);
+
+    virtual std::string         getName() const
+    {
+        return m_name;
+    }
+    virtual void                setName(const std::string &value)
+    {
+        m_name = value;
+    }
+
+    virtual CalendarEvent::CalendarType        getType() const
+    {
+        return m_type;
+    }
+    virtual void                setType(const CalendarEvent::CalendarType value)
+    {
+        m_type = value;
+    }
+
+    virtual std::string                 getId() const
+    {
+        return m_id;
+    }
+    virtual void                setId(const int value)
+    {
+        std::stringstream ss;
+        ss<<value;
+        m_id = ss.str();
+    }
+
+    virtual int                 getAccountId() const
+    {
+        return m_accountId;
+    }
+    virtual void                setAccountId(const int value)
+    {
+        m_accountId = value;
+    }
+
+    virtual int getLastChangedVersion()
+    {
+        return m_lastChangedVersion;
+    }
+    virtual void setLastChangedVersion(int value)
+    {
+        m_lastChangedVersion = value;
+    }
+
+    OnEventsChangedEmitters m_changeEmitters;
+
+  protected:
+    std::string m_id;
+    int m_accountId;
+    std::string m_name;
+    CalendarEvent::CalendarType m_type;
+    int m_lastChangedVersion;
+
+    virtual void OnRequestReceived(const IEventAddEventPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventAddEventsPtr &events) = 0;
+    virtual void OnRequestReceived(const IEventDeleteEventPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventDeleteEventsPtr &events) = 0;
+    virtual void OnRequestReceived(const IEventUpdateEventPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventUpdateEventsPtr &events) = 0;
+    virtual void OnRequestReceived(const IEventFindEventsPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventCreateEventFromStringPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventExportEventToStringPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventWatchChangesPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventClearWatchPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventExpandEventRecurrencePtr &event) = 0;
+    virtual void OnRequestReceived(const IEventGetPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<ICalendar> ICalendarPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_ICALENDAR_H_ */
diff --git a/src/platform/API/Calendar/ICalendarManager.cpp b/src/platform/API/Calendar/ICalendarManager.cpp
new file mode 100755 (executable)
index 0000000..04fae1a
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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 "ICalendarManager.h"
+#include <Commons/ThreadPool.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+ICalendarManager::ICalendarManager() :
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventGetCalendars >(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventGetDefaultCalendar >(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventGetCalendar >(WrtDeviceApis::Commons::ThreadEnum::CALENDAR_THREAD)
+{
+}
+
+ICalendarManager::~ICalendarManager()
+{
+}
+
+void ICalendarManager::getCalendars(const IEventGetCalendarsPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventGetCalendars>::PostRequest(event);
+}
+
+void ICalendarManager::getDefaultCalendar(const IEventGetDefaultCalendarPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventGetDefaultCalendar>::PostRequest(event);
+}
+
+void ICalendarManager::getCalendar(const IEventGetCalendarPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventGetCalendar>::PostRequest(event);
+}
+
+}
+}
+}
diff --git a/src/platform/API/Calendar/ICalendarManager.h b/src/platform/API/Calendar/ICalendarManager.h
new file mode 100755 (executable)
index 0000000..1c47c3f
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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 _ABSTRACT_LAYER_ICALENDAR_MANAGER_H_
+#define _ABSTRACT_LAYER_ICALENDAR_MANAGER_H_
+
+#include "ICalendar.h"
+#include "IEventGetCalendars.h"
+#include "IEventGetDefaultCalendar.h"
+#include "IEventGetCalendar.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class ICalendarManager : public WrtDeviceApis::Commons::EventRequestReceiver< IEventGetCalendars >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventGetDefaultCalendar >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventGetCalendar >
+{
+  public:
+    ICalendarManager();
+    virtual ~ICalendarManager();
+    virtual void getCalendars(const IEventGetCalendarsPtr &event);
+    virtual void getDefaultCalendar(const IEventGetDefaultCalendarPtr &event);
+    virtual void getCalendar(const IEventGetCalendarPtr &event);
+  protected:
+    virtual void OnRequestReceived(const IEventGetCalendarsPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventGetDefaultCalendarPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventGetCalendarPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<ICalendarManager> ICalendarManagerPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_ICALENDAR_MANAGER_H_ */
diff --git a/src/platform/API/Calendar/IEventAddEvent.h b/src/platform/API/Calendar/IEventAddEvent.h
new file mode 100755 (executable)
index 0000000..daddf29
--- /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 _ABSTRACT_LAYER_IEVENT_ADD_EVENT_H_
+#define _ABSTRACT_LAYER_IEVENT_ADD_EVENT_H_
+
+#include <Commons/IEvent.h>
+#include "CalendarEvent.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventAddEvent : public WrtDeviceApis::Commons::IEvent<IEventAddEvent>
+{
+    CalendarEventPtr m_eventAdd;
+    bool m_result;
+  public:
+    void             setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool             getResult() const
+    {
+        return m_result;
+    }
+    void             setEvent(CalendarEventPtr value)
+    {
+        m_eventAdd = value;
+    }
+    CalendarEventPtr getEvent() const
+    {
+        return m_eventAdd;
+    }
+    IEventAddEvent() : m_eventAdd(NULL),
+        m_result(false)
+    {
+    }
+    ~IEventAddEvent()
+    {
+    }
+    virtual void    clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventAddEvent> IEventAddEventPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_ADD_EVENT_H_ */
diff --git a/src/platform/API/Calendar/IEventAddEvents.h b/src/platform/API/Calendar/IEventAddEvents.h
new file mode 100755 (executable)
index 0000000..80f8fc4
--- /dev/null
@@ -0,0 +1,80 @@
+//
+// 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 _IEVENT_ADD_EVENTS_H_
+#define _IEVENT_ADD_EVENTS_H_
+
+#include <Commons/IEvent.h>
+#include "CalendarEvent.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventAddEvents : public WrtDeviceApis::Commons::IEvent<IEventAddEvents>
+{
+    CalendarEventListPtr m_events;
+    bool m_result;
+    CalendarEvent::CalendarType m_calendarType;
+
+  public:
+    void             setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool             getResult() const
+    {
+        return m_result;
+    }
+
+    void setCalendarType(CalendarEvent::CalendarType value)
+    {
+        m_calendarType = value;
+    }
+    CalendarEvent::CalendarType getCalendarType() const
+    {
+        return m_calendarType;
+    }
+
+    void             setEvents(CalendarEventListPtr value)
+    {
+        m_events = value;
+    }
+    CalendarEventListPtr getEvents() const
+    {
+        return m_events;
+    }
+
+    IEventAddEvents() : m_result(false), m_calendarType(CalendarEvent::EVENT_TYPE)
+    {
+    }
+    ~IEventAddEvents()
+    {
+    }
+    virtual void    clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventAddEvents> IEventAddEventsPtr;
+
+}
+}
+}
+#endif /* _IEVENT_ADD_EVENTS_H_ */
diff --git a/src/platform/API/Calendar/IEventClearWatch.h b/src/platform/API/Calendar/IEventClearWatch.h
new file mode 100755 (executable)
index 0000000..c44c2ad
--- /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 _IEVENT_CLEAR_WATCH_H_
+#define _IEVENT_CLEAR_WATCH_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "CalendarEvent.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventClearWatch : public WrtDeviceApis::Commons::IEvent<IEventClearWatch>
+{
+    long m_watchId;
+    bool m_result;
+
+  public:
+    void             setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool             getResult() const
+    {
+        return m_result;
+    }
+
+    void             setWatchId(long value)
+    {
+        m_watchId = value;
+    }
+    long getWatchId() const
+    {
+        return m_watchId;
+    }
+
+    IEventClearWatch() : m_result(false)
+    {
+    }
+    ~IEventClearWatch()
+    {
+    }
+    virtual void clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventClearWatch> IEventClearWatchPtr;
+
+}
+}
+}
+#endif /* _IEVENT_CLEAR_WATCH_H_ */
diff --git a/src/platform/API/Calendar/IEventCreateEventFromString.h b/src/platform/API/Calendar/IEventCreateEventFromString.h
new file mode 100755 (executable)
index 0000000..6069d01
--- /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.
+//
+
+
+#ifndef _IEVENT_CREATE_EVENT_FROM_STRING_H_
+#define _IEVENT_CREATE_EVENT_FROM_STRING_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include "ICalendar.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventCreateEventFromString : public WrtDeviceApis::Commons::IEvent<
+        IEventCreateEventFromString>
+{
+    CalendarEventPtr    m_event;
+    std::string         m_eventString;
+    int                 m_format;
+    bool m_result;
+
+  public:
+    void    setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool    getResult() const
+    {
+        return m_result;
+    }
+
+    std::string getEventString() const
+    {
+        return m_eventString;
+    }
+    void setEventString(std::string value)
+    {
+        m_eventString = value;
+    }
+
+    void    setEvent(CalendarEventPtr value)
+    {
+        m_event = value;
+    }
+    CalendarEventPtr    getEvent() const
+    {
+        return m_event;
+    }
+
+    void    setFormat(int value)
+    {
+        m_format = value;
+    }
+    int    getFormat() const
+    {
+        return m_format;
+    }
+
+    IEventCreateEventFromString() : m_result(false)
+    {
+    }
+    ~IEventCreateEventFromString()
+    {
+    }
+    virtual void clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventCreateEventFromString> IEventCreateEventFromStringPtr;
+
+}
+}
+}
+#endif /* _IEVENT_CREATE_EVENT_FROM_STRING_H_ */
diff --git a/src/platform/API/Calendar/IEventDeleteEvent.h b/src/platform/API/Calendar/IEventDeleteEvent.h
new file mode 100755 (executable)
index 0000000..5d3f5c7
--- /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 _ABSTRACT_LAYER_IEVENT_DELETE_EVENT_H_
+#define _ABSTRACT_LAYER_IEVENT_DELETE_EVENT_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "EventId.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventDeleteEvent : public WrtDeviceApis::Commons::IEvent<IEventDeleteEvent>
+{
+    EventIdPtr m_eventId;
+    bool m_result;
+  public:
+    void             setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool             getResult() const
+    {
+        return m_result;
+    }
+
+    void             setEventId(EventIdPtr value)
+    {
+        m_eventId = value;
+    }
+    EventIdPtr getEventId() const
+    {
+        return m_eventId;
+    }
+
+    IEventDeleteEvent() : m_eventId(NULL),
+        m_result(false)
+    {
+    }
+    ~IEventDeleteEvent()
+    {
+    }
+    virtual void clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventDeleteEvent> IEventDeleteEventPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_DELETE_EVENT_H_ */
diff --git a/src/platform/API/Calendar/IEventDeleteEvents.h b/src/platform/API/Calendar/IEventDeleteEvents.h
new file mode 100755 (executable)
index 0000000..ed198cc
--- /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 _IEVENT_DELETE_EVENTS_H_
+#define _IEVENT_DELETE_EVENTS_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "EventId.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventDeleteEvents : public WrtDeviceApis::Commons::IEvent<IEventDeleteEvents>
+{
+    EventIdListPtr m_eventIds;
+    bool m_result;
+
+  public:
+    void             setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool             getResult() const
+    {
+        return m_result;
+    }
+
+    void             setEventIds(EventIdListPtr value)
+    {
+        m_eventIds = value;
+    }
+    EventIdListPtr getEventIds() const
+    {
+        return m_eventIds;
+    }
+
+    IEventDeleteEvents() : m_result(false)
+    {
+    }
+    ~IEventDeleteEvents()
+    {
+    }
+    virtual void clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventDeleteEvents> IEventDeleteEventsPtr;
+
+}
+}
+}
+#endif /* _IEVENT_DELETE_EVENTS_H_ */
diff --git a/src/platform/API/Calendar/IEventExpandEventRecurrence.h b/src/platform/API/Calendar/IEventExpandEventRecurrence.h
new file mode 100755 (executable)
index 0000000..b2db0a3
--- /dev/null
@@ -0,0 +1,104 @@
+//
+// 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 _IEVENT_EXPAND_EVENT_RECURRENCE_H_
+#define _IEVENT_EXPAND_EVENT_RECURRENCE_H_
+
+#include <Commons/IEvent.h>
+#include "CalendarEvent.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventExpandEventRecurrence : public WrtDeviceApis::Commons::IEvent<IEventExpandEventRecurrence>
+{
+    CalendarEventListPtr m_expandedEventList; //output
+    bool m_result; // ouput
+    CalendarEventPtr m_event; // input
+    long long int m_startDate; // input
+    long long int m_endDate; // input
+
+  public:
+    void             setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool             getResult() const
+    {
+        return m_result;
+    }
+
+    CalendarEventListPtr getExpandedEventList() const
+    {
+        return m_expandedEventList;
+    }
+
+    void             setEvent(CalendarEventPtr value)
+    {
+        m_event = value;
+    }
+    CalendarEventPtr getEvent() const
+    {
+        return m_event;
+    }
+
+    void             setStartDate(long long int value)
+    {
+        m_startDate = value;
+    }
+    long long int             getStartDate() const
+    {
+        return m_startDate;
+    }
+
+    void             setEndDate(long long int value)
+    {
+        m_endDate = value;
+    }
+    long long int             getEndDate() const
+    {
+        return m_endDate;
+    }
+
+    void                    addExpandedEvent(CalendarEventPtr value)
+    {
+        m_expandedEventList->push_back(value);
+    }
+
+    IEventExpandEventRecurrence() : m_result(false)
+    {
+        CalendarEventListPtr events(new CalendarEventList());
+        m_expandedEventList = events;
+    }
+    ~IEventExpandEventRecurrence()
+    {
+    }
+    virtual void    clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventExpandEventRecurrence> IEventExpandEventRecurrencePtr;
+
+}
+}
+}
+
+#endif /* _IEVENT_EXPAND_EVENT_RECURRENCE_H_ */
diff --git a/src/platform/API/Calendar/IEventExportEventToString.h b/src/platform/API/Calendar/IEventExportEventToString.h
new file mode 100755 (executable)
index 0000000..1bef09d
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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 _IEVENT_EXPORT_EVENT_TO_STRING_H_
+#define _IEVENT_EXPORT_EVENT_TO_STRING_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "CalendarEvent.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventExportEventToString : public WrtDeviceApis::Commons::IEvent<IEventExportEventToString>
+{
+    std::string m_eventString;
+    CalendarEventPtr m_event;
+    int              m_format;
+    bool m_result;
+
+  public:
+    void             setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool             getResult() const
+    {
+        return m_result;
+    }
+
+    void             setEvent(CalendarEventPtr value)
+    {
+        m_event = value;
+    }
+    CalendarEventPtr     getEvent() const
+    {
+        return m_event;
+    }
+
+    void             setEventString(std::string value)
+    {
+        m_eventString = value;
+    }
+    std::string getEventString() const
+    {
+        return m_eventString;
+    }
+
+    void    setFormat(int value)
+    {
+        m_format = value;
+    }
+    int    getFormat() const
+    {
+        return m_format;
+    }
+
+    IEventExportEventToString() : m_result(false)
+    {
+    }
+    ~IEventExportEventToString()
+    {
+    }
+    virtual void clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventExportEventToString> IEventExportEventToStringPtr;
+
+}
+}
+}
+#endif /* _IEVENT_EXPORT_EVENT_TO_STRING_H_ */
diff --git a/src/platform/API/Calendar/IEventFindEvents.h b/src/platform/API/Calendar/IEventFindEvents.h
new file mode 100755 (executable)
index 0000000..3feaac9
--- /dev/null
@@ -0,0 +1,145 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_FIND_EVENTS_H_
+#define _ABSTRACT_LAYER_IEVENT_FIND_EVENTS_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include "CalendarEvent.h"
+#include <API/Filter/IFilter.h>
+#include <API/Filter/SortMode.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventFindEvents : public WrtDeviceApis::Commons::IEvent<IEventFindEvents>
+{
+    /* user is responsible to free objects inside list */
+    CalendarEventListPtr m_events;
+    bool m_result;
+    CalendarEvent::CalendarType m_calendarType;
+       Tizen::FilterPtr                        m_genericFilter;
+       Tizen::SortModeArrayPtr m_sortModes;
+       std::vector<std::string>                m_attributesOfInterest;
+       bool    m_genericFilterIsSet;
+       bool    m_sortModesIsSet;
+       bool    m_attributesOfInterestIsSet;
+
+  public:
+    void                        setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool                        getResult() const
+    {
+        return m_result;
+    }
+
+    void setCalendarType(CalendarEvent::CalendarType value)
+    {
+        m_calendarType = value;
+    }
+    CalendarEvent::CalendarType getCalendarType() const
+    {
+        return m_calendarType;
+    }
+
+    void                        addEvent(CalendarEventPtr value)
+    {
+        m_events->push_back(value);
+    }
+
+    CalendarEventListPtr getEvents()
+    {
+        return m_events;
+    }
+
+       Tizen::FilterPtr getGenericFilter() const
+       {
+               return m_genericFilter;
+       }
+
+       void setGenericFilter(const Tizen::FilterPtr &value)
+       {
+               m_genericFilter = value;
+               m_genericFilterIsSet = true;
+       }
+
+       Tizen::SortModeArrayPtr getSortModes() const
+       {
+               return m_sortModes;
+       }
+
+       void setSortModes(const Tizen::SortModeArrayPtr &value)
+       {
+               m_sortModes = value;
+               m_sortModesIsSet = true;
+       }
+
+       std::vector<std::string> getAttributesOfInterest() const
+       {
+               return m_attributesOfInterest;
+       }
+
+       void setAttributesOfInterest(const std::vector<std::string> &value)
+       {
+               m_attributesOfInterest = value;
+               m_attributesOfInterestIsSet = true;
+       }
+
+       bool getGenericFilterIsSet() const
+       {
+               return m_genericFilterIsSet;
+       }
+
+       bool getSortModesIsSet() const
+       {
+               return m_sortModesIsSet;
+       }
+
+       bool getAttributesOfInterestIsSet() const
+       {
+               return m_attributesOfInterestIsSet;
+       }
+
+    IEventFindEvents() : m_result(false),
+           m_calendarType(CalendarEvent::EVENT_TYPE),
+        m_genericFilterIsSet(false),
+        m_sortModesIsSet(false),
+        m_attributesOfInterestIsSet(false)
+    {
+       CalendarEventListPtr events(new CalendarEventList());
+       m_events = events;
+    }
+    ~IEventFindEvents()
+    {
+    }
+    virtual void clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventFindEvents> IEventFindEventsPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_FIND_EVENTS_H_ */
diff --git a/src/platform/API/Calendar/IEventGet.h b/src/platform/API/Calendar/IEventGet.h
new file mode 100755 (executable)
index 0000000..437db7b
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_GET_H_
+#define _ABSTRACT_LAYER_IEVENT_GET_H_
+
+#include <vector>
+#include <string>
+#include <Commons/IEvent.h>
+#include "ICalendar.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventGet : public WrtDeviceApis::Commons::IEvent<IEventGet>
+{
+    CalendarEventPtr m_item; // output parameter
+    bool m_result;
+    EventIdPtr m_itemId; // input parameter
+
+  public:
+    bool getResult() const
+    {
+        return m_result;
+    }
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+
+    EventIdPtr getItemId() const
+    {
+        return m_itemId;
+    }
+    void setItemId(EventIdPtr value)
+    {
+        m_itemId = value;
+    }
+
+    CalendarEventPtr getItem() const
+    {
+        return m_item;
+    }
+    void setItem(CalendarEventPtr value)
+    {
+        m_item = value;
+    }
+
+    IEventGet() : m_result(false)
+    {
+    }
+    ~IEventGet()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventGet> IEventGetPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_GET_H_ */
diff --git a/src/platform/API/Calendar/IEventGetCalendar.h b/src/platform/API/Calendar/IEventGetCalendar.h
new file mode 100755 (executable)
index 0000000..3324e4b
--- /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.
+//
+
+#ifndef _ABSTRACT_LAYER_IEVENT_GET_CALENDAR_H_
+#define _ABSTRACT_LAYER_IEVENT_GET_CALENDAR_H_
+
+#include <vector>
+#include <string>
+#include <Commons/IEvent.h>
+#include "ICalendar.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventGetCalendar : public WrtDeviceApis::Commons::IEvent<IEventGetCalendar>
+{
+    ICalendarPtr m_calendar;
+    bool m_result;
+    std::string m_id;
+    CalendarEvent::CalendarType m_type;
+
+  public:
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    void setType(CalendarEvent::CalendarType value)
+    {
+        m_type = value;
+    }
+    CalendarEvent::CalendarType getType() const
+    {
+        return m_type;
+    }
+
+    void setId(std::string &value)
+    {
+        m_id = value;
+    }
+    std::string getId() const
+    {
+        return m_id;
+    }
+
+    void setCalendar(ICalendarPtr value)
+    {
+        m_calendar = value;
+    }
+    ICalendarPtr getCalendar() const
+    {
+        return m_calendar;
+    }
+
+    IEventGetCalendar() : m_calendar(NULL),
+        m_result(false),
+        m_id(""),
+        m_type(CalendarEvent::EVENT_TYPE)
+    {
+    }
+    ~IEventGetCalendar()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventGetCalendar> IEventGetCalendarPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_GET_CALENDAR_H_ */
diff --git a/src/platform/API/Calendar/IEventGetCalendars.h b/src/platform/API/Calendar/IEventGetCalendars.h
new file mode 100755 (executable)
index 0000000..b6b8962
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_GET_CALENDARS_H_
+#define _ABSTRACT_LAYER_IEVENT_GET_CALENDARS_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include "ICalendar.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventGetCalendars : public WrtDeviceApis::Commons::IEvent<IEventGetCalendars>
+{
+    std::vector<ICalendarPtr> m_calendars;
+    bool m_result;
+    CalendarEvent::CalendarType m_type;
+
+  public:
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    void setType(CalendarEvent::CalendarType value)
+    {
+        m_type = value;
+    }
+    CalendarEvent::CalendarType getType() const
+    {
+        return m_type;
+    }
+
+    void addCalendar(ICalendarPtr value)
+    {
+        m_calendars.push_back(value);
+    }
+    std::vector<ICalendarPtr> getCalendars() const
+    {
+        return m_calendars;
+    }
+    IEventGetCalendars() : m_result(false),
+        m_type(CalendarEvent::EVENT_TYPE)
+    {
+    }
+    ~IEventGetCalendars()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventGetCalendars> IEventGetCalendarsPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_GET_CALENDARS_H_ */
diff --git a/src/platform/API/Calendar/IEventGetDefaultCalendar.h b/src/platform/API/Calendar/IEventGetDefaultCalendar.h
new file mode 100755 (executable)
index 0000000..e4380d2
--- /dev/null
@@ -0,0 +1,80 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_GET_DEFAULT_CALENDAR_H_
+#define _ABSTRACT_LAYER_IEVENT_GET_DEFAULT_CALENDAR_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include "ICalendar.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventGetDefaultCalendar : public WrtDeviceApis::Commons::IEvent<IEventGetDefaultCalendar>
+{
+    ICalendarPtr m_calendar;
+    bool m_result;
+    CalendarEvent::CalendarType m_type;
+
+  public:
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    void setType(CalendarEvent::CalendarType value)
+    {
+        m_type = value;
+    }
+    CalendarEvent::CalendarType getType() const
+    {
+        return m_type;
+    }
+
+    void setCalendar(ICalendarPtr value)
+    {
+        m_calendar = value;
+    }
+    ICalendarPtr getCalendar() const
+    {
+        return m_calendar;
+    }
+
+    IEventGetDefaultCalendar() : m_calendar(NULL),
+        m_result(false),
+        m_type(CalendarEvent::EVENT_TYPE)
+    {
+    }
+    ~IEventGetDefaultCalendar()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventGetDefaultCalendar> IEventGetDefaultCalendarPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_GET_DEFAULT_CALENDAR_H_ */
diff --git a/src/platform/API/Calendar/IEventUpdateEvent.h b/src/platform/API/Calendar/IEventUpdateEvent.h
new file mode 100755 (executable)
index 0000000..01cf34d
--- /dev/null
@@ -0,0 +1,81 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_UPDATE_EVENT_H_
+#define _ABSTRACT_LAYER_IEVENT_UPDATE_EVENT_H_
+
+#include <Commons/IEvent.h>
+#include "CalendarEvent.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventUpdateEvent : public WrtDeviceApis::Commons::IEvent<IEventUpdateEvent>
+{
+    CalendarEventPtr m_event;
+    bool m_result;
+    bool m_updateAllInstances;
+
+  public:
+    void             setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool             getResult() const
+    {
+        return m_result;
+    }
+
+    void             setEvent(CalendarEventPtr value)
+    {
+        m_event = value;
+    }
+    CalendarEventPtr getEvent() const
+    {
+        return m_event;
+    }
+
+    void             setUpdateAllInstances(bool value)
+    {
+        m_updateAllInstances = value;
+    }
+    bool             getUpdateAllInstances() const
+    {
+        return m_updateAllInstances;
+    }
+
+    IEventUpdateEvent() : m_event(NULL),
+        m_result(false), m_updateAllInstances(true)
+    {
+    }
+    ~IEventUpdateEvent()
+    {
+    }
+    virtual void clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventUpdateEvent> IEventUpdateEventPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_UPDATE_EVENT_H_ */
diff --git a/src/platform/API/Calendar/IEventUpdateEvents.h b/src/platform/API/Calendar/IEventUpdateEvents.h
new file mode 100755 (executable)
index 0000000..58ec70f
--- /dev/null
@@ -0,0 +1,80 @@
+//
+// 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 _IEVENT_UPDATE_EVENTS_H_
+#define _IEVENT_UPDATE_EVENTS_H_
+
+#include <Commons/IEvent.h>
+#include "CalendarEvent.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventUpdateEvents : public WrtDeviceApis::Commons::IEvent<IEventUpdateEvents>
+{
+    CalendarEventListPtr m_events;
+    bool m_result;
+    bool m_updateAllInstances;
+
+  public:
+    void             setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool             getResult() const
+    {
+        return m_result;
+    }
+
+    void             setEvents(CalendarEventListPtr value)
+    {
+        m_events = value;
+    }
+    CalendarEventListPtr getEvents() const
+    {
+        return m_events;
+    }
+
+    void             setUpdateAllInstances(bool value)
+    {
+        m_updateAllInstances = value;
+    }
+    bool             getUpdateAllInstances() const
+    {
+        return m_updateAllInstances;
+    }
+
+    IEventUpdateEvents() : m_result(false), m_updateAllInstances(true)
+    {
+    }
+    ~IEventUpdateEvents()
+    {
+    }
+    virtual void clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventUpdateEvents> IEventUpdateEventsPtr;
+
+}
+}
+}
+#endif /* _IEVENT_UPDATE_EVENTS_H_ */
diff --git a/src/platform/API/Calendar/IEventWatchChanges.h b/src/platform/API/Calendar/IEventWatchChanges.h
new file mode 100755 (executable)
index 0000000..63194ba
--- /dev/null
@@ -0,0 +1,91 @@
+//
+// 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 _IEVENT_WATCH_CHANGES_H_
+#define _IEVENT_WATCH_CHANGES_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "CalendarEvent.h"
+#include "OnEventsChanged.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class IEventWatchChanges : public WrtDeviceApis::Commons::IEvent<IEventWatchChanges>
+{
+    AttributeListPtr m_attributesOfInterest;
+    bool m_result;
+    long m_watchId;
+    OnEventsChangedEmitterPtr m_emitter;
+
+  public:
+    void             setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool             getResult() const
+    {
+        return m_result;
+    }
+
+    void             setAttributes(AttributeListPtr value)
+    {
+        m_attributesOfInterest = value;
+    }
+    AttributeListPtr getAttributes() const
+    {
+        return m_attributesOfInterest;
+    }
+
+    void             setWatchId(long value)
+    {
+        m_watchId = value;
+    }
+    long            getWatchId() const
+    {
+        return m_watchId;
+    }
+
+    void             setEmitter(OnEventsChangedEmitterPtr value)
+    {
+        m_emitter = value;
+    }
+    OnEventsChangedEmitterPtr            getEmitter() const
+    {
+        return m_emitter;
+    }
+
+    IEventWatchChanges() : m_result(false)
+    {
+    }
+    ~IEventWatchChanges()
+    {
+    }
+    virtual void clearOnCancel()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventWatchChanges> IEventWatchChangesPtr;
+
+}
+}
+}
+#endif /* _IEVENT_WATCH_CHANGES_H_ */
diff --git a/src/platform/API/Calendar/OnEventsChanged.h b/src/platform/API/Calendar/OnEventsChanged.h
new file mode 100755 (executable)
index 0000000..c07fa1e
--- /dev/null
@@ -0,0 +1,98 @@
+//
+// 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 _ON_EVENTS_CHANGED_H_
+#define _ON_EVENTS_CHANGED_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/Emitters.h>
+#include "CalendarEvent.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Calendar {
+
+class OnEventsChanged : public WrtDeviceApis::Commons::ListenerEvent<OnEventsChanged>
+{
+    public:
+    typedef enum
+    {
+               ON_ADD,
+               ON_UPDATE,
+               ON_DELETE,
+               //ON_CALENDAR_RESET
+    } EventChangeStatus;
+
+    void setResult (bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    void setCalendarType(CalendarEvent::CalendarType value)
+    {
+        m_calendarType = value;
+    }
+    CalendarEvent::CalendarType getCalendarType() const
+    {
+        return m_calendarType;
+    }
+
+    CalendarEventListPtr getEventList() const {
+        return m_eventList;
+    }
+
+    void setStatus(EventChangeStatus value) {
+        m_status = value;
+    }
+    EventChangeStatus getStatus() const {
+        return m_status;
+    }
+
+    void addEvent(CalendarEventPtr value) {
+        m_eventList->push_back(value);
+    }
+
+    OnEventsChanged() : m_result(false) {
+       CalendarEventListPtr events(new CalendarEventList());
+       m_eventList = events;
+    }
+    ~OnEventsChanged() {
+    }
+
+    private:
+    CalendarEventListPtr m_eventList;
+    EventChangeStatus m_status;
+    bool m_result;
+    CalendarEvent::CalendarType m_calendarType;
+};
+
+typedef DPL::SharedPtr<OnEventsChanged> OnEventsChangedPtr;
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<OnEventsChanged> OnEventsChangedEmitter;
+typedef DPL::SharedPtr<OnEventsChangedEmitter> OnEventsChangedEmitterPtr;
+typedef WrtDeviceApis::Commons::Emitters<OnEventsChangedEmitter> OnEventsChangedEmitters;
+
+}
+}
+}
+
+#endif //_ON_EVENTS_CHANGED_H_
diff --git a/src/platform/API/Calendar/config.cmake b/src/platform/API/Calendar/config.cmake
new file mode 100755 (executable)
index 0000000..ec71ec2
--- /dev/null
@@ -0,0 +1,12 @@
+get_current_path()
+set(SRCS_PLATFORM_API_CALENDAR
+  ${CURRENT_PATH}/CalendarEvent.cpp
+  ${CURRENT_PATH}/CalendarFactory.cpp
+  ${CURRENT_PATH}/ICalendar.cpp
+  ${CURRENT_PATH}/ICalendarManager.cpp
+  ${CURRENT_PATH}/EventAttendee.cpp
+  ${CURRENT_PATH}/EventRecurrenceRule.cpp
+  ${CURRENT_PATH}/EventId.cpp
+  ${CURRENT_PATH}/EventAlarm.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Callhistory/CallHistoryDefine.h b/src/platform/API/Callhistory/CallHistoryDefine.h
new file mode 100755 (executable)
index 0000000..fc40d09
--- /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 TIZENAPIS_API_CALLHISTORY_DEFINE_H_
+#define TIZENAPIS_API_CALLHISTORY_DEFINE_H_
+
+namespace {
+
+#define STR_TIZEN_TEL                  "TEL"
+#define STR_TIZEN_XMPP                 "XMPP"
+#define STR_TIZEN_SIP                  "SIP"
+
+#define STR_CALL                               "CALL"
+#define STR_CALL_VOICE                 "VOICECALL"
+#define STR_CALL_VIDEO                 "VIDEOCALL"
+#define STR_CALL_EMERGENCY             "EMERGENCYCALL"
+
+#define STR_DIALED                     "DIALED"
+#define STR_RECEIVED                   "RECEIVED"
+#define STR_MISSED_NEW                 "MISSEDNEW"
+#define STR_MISSED                     "MISSED"
+#define STR_REJECTED                   "REJECTED"
+#define STR_BLOCKED                    "BLOCKED"
+
+#define STR_ENTRY_ID                   "uid"
+#define STR_SERVICE_ID                 "serviceId"
+#define STR_CALL_TYPE                  "type"
+#define STR_TAGS                       "features"
+#define STR_REMOTE_PARTIES             "remoteParties"
+#define STR_FORWARDEDFROM              "forwardedFrom"
+#define STR_START_TIME                 "startTime"
+#define STR_DURATION                   "duration"
+#define STR_END_REASON                 "endReason"
+#define STR_DIRECTION                  "direction"
+#define STR_RECORDING                  "recording"
+#define STR_COST                       "cost"
+#define STR_CURRENCY                   "currency"
+
+#define STR_REMOTE_PARTY               "remoteParty"
+#define STR_PERSIONID                  "personId"
+
+#define STR_RP_REMOTEPARTY             "remoteParties.remoteParty"
+#define STR_RP_PERSONID                "remoteParties.personId"
+
+#define STR_LOG_ID                     "id"
+#define STR_NUMBER                     "number"
+#define STR_LOG_TIME                   "log_time"
+#define STR_LOG_TYPE                   "log_type"
+#define STR_DATA1                      "data1"
+#define STR_PERSON_ID                  "person_id"
+
+}
+
+#endif
diff --git a/src/platform/API/Callhistory/CallHistoryEntryProperties.cpp b/src/platform/API/Callhistory/CallHistoryEntryProperties.cpp
new file mode 100755 (executable)
index 0000000..79cca14
--- /dev/null
@@ -0,0 +1,184 @@
+//
+// 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 "CallHistoryEntryProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+CallHistoryEntryProperties::CallHistoryEntryProperties() :
+               m_entryId(0),
+               m_serviceId(""),
+               m_callType(""),
+               m_startTime(0),
+               m_duration(0),
+               m_endReason(""),
+               m_direction(""),
+               m_cost(0),
+               m_currency(""),
+               m_filterMark(false)
+{
+       m_tags = StringArrayPtr(new StringArray());
+       m_remoteParties = RemotePartyListPtr(new RemotePartyList());
+       m_forwardedFrom = RemotePartyPtr(new RemoteParty());
+       m_recording = StringArrayPtr(new StringArray());
+}
+
+void CallHistoryEntryProperties::setEntryId(const unsigned long EntryId)
+{
+       m_entryId = EntryId;
+}
+
+void CallHistoryEntryProperties::setServiceId(const std::string ServiceId)
+{
+       m_serviceId = ServiceId;
+}
+
+void CallHistoryEntryProperties::setCallType(const std::string CallType)
+{
+       m_callType = CallType;
+}
+
+void CallHistoryEntryProperties::setTags(const StringArrayPtr &Tags)
+{
+       m_tags = Tags;
+}
+
+void CallHistoryEntryProperties::setRemoteParties(const RemotePartyListPtr &RemoteParties)
+{
+       m_remoteParties = RemoteParties;
+}
+
+void CallHistoryEntryProperties::setForwardedFrom(const RemotePartyPtr &ForwardedFrom)
+{
+       m_forwardedFrom = ForwardedFrom;
+}
+
+void CallHistoryEntryProperties::setStartTime(const time_t StartTime)
+{
+       m_startTime = StartTime;
+}
+
+void CallHistoryEntryProperties::setDuration(const unsigned long Duration)
+{
+       m_duration = Duration;
+}
+
+void CallHistoryEntryProperties::setEndReason(const std::string EndReason)
+{
+       m_endReason = EndReason;
+}
+
+void CallHistoryEntryProperties::setDirection(const std::string Direction)
+{
+       m_direction = Direction;
+}
+
+void CallHistoryEntryProperties::setRecording(const StringArrayPtr &Recording)
+{
+       m_recording = Recording;
+}
+
+void CallHistoryEntryProperties::setCost(const unsigned long Cost)
+{
+       m_cost = Cost;
+}
+
+void CallHistoryEntryProperties::setCurrency(const std::string Currency)
+{
+       m_currency = Currency;
+}
+
+
+void CallHistoryEntryProperties::setFilterMark(const bool Mark)
+{
+       m_filterMark = Mark;
+}
+
+unsigned long CallHistoryEntryProperties::getEntryId() const
+{
+       return m_entryId;
+}
+
+std::string CallHistoryEntryProperties::getServiceId() const
+{
+       return m_serviceId;
+}
+
+std::string CallHistoryEntryProperties::getCallType() const
+{
+       return m_callType;
+}
+
+StringArrayPtr CallHistoryEntryProperties::getTags() const
+{
+       return m_tags;
+}
+
+RemotePartyListPtr CallHistoryEntryProperties::getRemoteParties() const
+{
+       return m_remoteParties;
+}
+
+RemotePartyPtr CallHistoryEntryProperties::getForwardedFrom() const
+{
+       return m_forwardedFrom;
+}
+
+time_t CallHistoryEntryProperties::getStartTime() const
+{
+       return m_startTime;
+}
+
+unsigned long CallHistoryEntryProperties::getDuration() const
+{
+       return m_duration;
+}
+
+std::string CallHistoryEntryProperties::getEndReason() const
+{
+       return m_endReason;
+}
+
+std::string CallHistoryEntryProperties::getDirection() const
+{
+       return m_direction;
+}
+
+StringArrayPtr CallHistoryEntryProperties::getRecording() const
+{
+       return m_recording;
+}
+
+unsigned long CallHistoryEntryProperties::getCost() const
+{
+       return m_cost;
+}
+
+std::string CallHistoryEntryProperties::getCurrency() const
+{
+       return m_currency;
+}
+
+bool CallHistoryEntryProperties::getFilterMark() const
+{
+       return m_filterMark;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Callhistory/CallHistoryEntryProperties.h b/src/platform/API/Callhistory/CallHistoryEntryProperties.h
new file mode 100755 (executable)
index 0000000..c0a3cda
--- /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.
+//
+
+#ifndef TIZENAPIS_API_CALLHISTORY_ENTRY_PROPERTIES_H_
+#define TIZENAPIS_API_CALLHISTORY_ENTRY_PROPERTIES_H_
+
+#include <dpl/shared_ptr.h>
+#include <string>
+#include <vector>
+#include "RemoteParty.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+class CallHistoryEntryProperties;
+typedef DPL::SharedPtr<CallHistoryEntryProperties> CallHistoryEntryPropertiesPtr;
+typedef std::vector<CallHistoryEntryPropertiesPtr> CallHistoryEntryList;
+typedef DPL::SharedPtr<CallHistoryEntryList> CallHistoryEntryListPtr;
+typedef std::vector<std::string> StringArray;
+typedef DPL::SharedPtr<StringArray> StringArrayPtr;
+
+class CallHistoryEntryProperties
+{
+private:
+       unsigned long m_entryId;
+       std::string m_serviceId;
+       std::string m_callType;
+       StringArrayPtr m_tags;
+       RemotePartyListPtr m_remoteParties;
+       RemotePartyPtr m_forwardedFrom;
+       time_t m_startTime;
+       unsigned long m_duration;
+       std::string m_endReason;
+       std::string m_direction;
+       StringArrayPtr m_recording;
+       unsigned long m_cost;
+       std::string m_currency;
+
+       bool m_filterMark;
+
+public:
+       void setEntryId(const unsigned long EntryId);
+       void setServiceId(const std::string ServiceId);
+       void setCallType(const std::string CallType);
+       void setTags(const StringArrayPtr &Tags);
+       void setRemoteParties(const RemotePartyListPtr &RemoteParties);
+       void setForwardedFrom(const RemotePartyPtr &ForwardedFrom);
+       void setStartTime(const time_t StartTime);
+       void setDuration(const unsigned long Duration);
+       void setEndReason(const std::string EndReason);
+       void setDirection(const std::string Direction);
+       void setRecording(const StringArrayPtr &Recording);
+       void setCost(const unsigned long Cost);
+       void setCurrency(const std::string Currency);
+       void setFilterMark(const bool mark);
+
+       unsigned long getEntryId() const;
+       std::string getServiceId() const;
+       std::string getCallType() const;
+       StringArrayPtr getTags() const;
+       RemotePartyListPtr getRemoteParties() const;
+       RemotePartyPtr getForwardedFrom() const;
+       time_t getStartTime() const;
+       unsigned long getDuration() const;
+       std::string getEndReason() const;
+       std::string getDirection() const;
+       StringArrayPtr getRecording() const;
+       unsigned long getCost() const;
+       std::string getCurrency() const;
+       bool getFilterMark() const;
+       
+       CallHistoryEntryProperties();
+};
+}
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/platform/API/Callhistory/CallHistoryFactory.cpp b/src/platform/API/Callhistory/CallHistoryFactory.cpp
new file mode 100755 (executable)
index 0000000..a957957
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 <Callhistory/CallHistory.h>
+#include <Callhistory/CallHistoryEntry.h>
+#include "CallHistoryFactory.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+CallHistoryFactory& CallHistoryFactory::getInstance()
+{
+       static CallHistoryFactory theInstance;
+       return theInstance;
+}
+
+ICallHistoryPtr CallHistoryFactory::getCallHistoryObject()
+{
+       ICallHistoryPtr result(new Platform::Callhistory::CallHistory()); 
+       return result;
+}
+
+ICallHistoryEntryPtr CallHistoryFactory::getCallHistoryEntryObject()
+{
+       ICallHistoryEntryPtr result(new Platform::Callhistory::CallHistoryEntry()); 
+       return result;
+}
+
+CallHistoryFactory::CallHistoryFactory()
+{
+}
+
+}
+}
+}
+
diff --git a/src/platform/API/Callhistory/CallHistoryFactory.h b/src/platform/API/Callhistory/CallHistoryFactory.h
new file mode 100755 (executable)
index 0000000..d930a89
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// 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 _ABSTRACT_LAYER_CALLHISTORY_FACTORY_H_
+#define _ABSTRACT_LAYER_CALLHISTORY_FACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include "ICallHistory.h"
+#include "ICallHistoryEntry.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+
+class CallHistoryFactory : public DPL::Noncopyable
+{
+public:
+       static CallHistoryFactory& getInstance();
+       ICallHistoryPtr getCallHistoryObject();
+       ICallHistoryEntryPtr getCallHistoryEntryObject();
+
+protected:
+       CallHistoryFactory();
+};
+
+}
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/platform/API/Callhistory/EventCallHistory.h b/src/platform/API/Callhistory/EventCallHistory.h
new file mode 100755 (executable)
index 0000000..ad55671
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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_CALL_EVENT_CALLHISTORY_H_
+#define TIZENAPIS_API_CALL_EVENT_CALLHISTORY_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+class EventCallHistory : public WrtDeviceApis::Commons::IEvent<EventCallHistory>
+{
+public:
+       typedef enum {
+               NONE,
+               CONNECT,
+               DISCONNECT,
+       } CmdType;      
+private:
+       CmdType m_cmdType;
+
+public:
+       void setCmdType(const CmdType cmd) {m_cmdType = cmd;}
+       CmdType getCmdType() const {return m_cmdType;}
+
+       EventCallHistory() : m_cmdType(EventCallHistory::NONE) {}
+};
+
+typedef DPL::SharedPtr<EventCallHistory> EventCallHistoryPtr;
+} 
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/platform/API/Callhistory/EventCallHistoryListener.cpp b/src/platform/API/Callhistory/EventCallHistoryListener.cpp
new file mode 100755 (executable)
index 0000000..99900f2
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 "EventCallHistoryListener.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+EventCallHistoryListener::EventCallHistoryListener()
+{
+}
+
+void EventCallHistoryListener::setResultState(const ResultStates state)
+{
+       m_resultState = state;
+}
+
+void EventCallHistoryListener::setResult (const CallHistoryEntryListPtr &entryList) 
+{
+       m_entryList = entryList;
+}
+
+EventCallHistoryListener::ResultStates EventCallHistoryListener::getResultState() const
+{
+       return m_resultState;
+}
+
+CallHistoryEntryListPtr EventCallHistoryListener::getResult() const 
+{
+       return m_entryList;
+}
+
+}
+}
+}
+
diff --git a/src/platform/API/Callhistory/EventCallHistoryListener.h b/src/platform/API/Callhistory/EventCallHistoryListener.h
new file mode 100755 (executable)
index 0000000..dccc23f
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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_CALL_EVENT_CALLHISTORY_LISTENER_H_
+#define TIZENAPIS_API_CALL_EVENT_CALLHISTORY_LISTENER_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "CallHistoryEntryProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+
+class EventCallHistoryListener : public WrtDeviceApis::Commons::ListenerEvent<EventCallHistoryListener>
+{
+public:
+       typedef enum {
+               ADDED,
+               CHANGED
+       } ResultStates;
+
+private:
+       ResultStates m_resultState;
+       Api::Callhistory::CallHistoryEntryListPtr m_entryList;
+
+public:
+       void setResultState(const ResultStates state);
+       void setResult(const Api::Callhistory::CallHistoryEntryListPtr &entryList);
+       ResultStates getResultState() const;
+       Api::Callhistory::CallHistoryEntryListPtr getResult() const;
+
+       EventCallHistoryListener();
+};
+
+typedef DPL::SharedPtr<EventCallHistoryListener> EventCallHistoryListenerPtr;
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventCallHistoryListener> EventCallHistoryListenerEmitter;
+typedef DPL::SharedPtr<EventCallHistoryListenerEmitter> EventCallHistoryListenerEmitterPtr;
+
+}
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/platform/API/Callhistory/EventCallHistoryTemplate.h b/src/platform/API/Callhistory/EventCallHistoryTemplate.h
new file mode 100755 (executable)
index 0000000..bbd55b8
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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_EVENT_CALLHISTORY_TEMPLATE_H_
+#define TIZENAPIS_API_EVENT_CALLHISTORY_TEMPLATE_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+
+template <class templateClass>
+class EventCallHistoryTemplate : public WrtDeviceApis::Commons::IEvent<templateClass>
+{
+public:
+       EventCallHistoryTemplate() { }
+};
+
+template <class templateEventClass>
+class EventCallHistoryPtrs
+{
+private:
+       DPL::SharedPtr<templateEventClass> eventPtr;
+       void * thisPtr;
+public:
+       DPL::SharedPtr<templateEventClass> getEventPtrs() const {return eventPtr;}
+       void *getThisPtr() {return thisPtr;}
+       EventCallHistoryPtrs(const DPL::SharedPtr<templateEventClass> &event, void *myPtr) : eventPtr(event), thisPtr(myPtr) {}
+};
+
+}
+}
+}
+#endif //TIZENAPIS_API_EVENT_CALLHISTORY_TEMPLATE_H_
\ No newline at end of file
diff --git a/src/platform/API/Callhistory/EventFindCallHistory.cpp b/src/platform/API/Callhistory/EventFindCallHistory.cpp
new file mode 100755 (executable)
index 0000000..4d14fd0
--- /dev/null
@@ -0,0 +1,112 @@
+//
+// 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 "EventFindCallHistory.h"
+
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+EventFindCallHistory::EventFindCallHistory() : m_filterIsSet(false),
+                               m_sortModesIsSet(false),
+                               m_limitIsSet(false),
+                               m_offsetIsSet(false)
+{
+}
+
+void EventFindCallHistory::setFilter(const FilterPtr &filter)
+{
+       m_filter = filter;
+       m_filterIsSet = true;
+}
+
+void EventFindCallHistory::setSortMode(const SortModePtr &sortMode)
+{
+       m_sortModes = sortMode;
+       m_sortModesIsSet = true;
+}
+
+void EventFindCallHistory::setLimit(const unsigned long limit)
+{
+       if (limit > 0) {
+               m_limit = limit;
+               m_limitIsSet = true;
+       }
+}
+
+void EventFindCallHistory::setOffset(const unsigned long offset)
+{
+       if (offset > 0) {
+               m_offset = offset;
+               m_offsetIsSet = true;
+       }
+}
+
+void EventFindCallHistory::setResult(const CallHistoryEntryListPtr &callEntries)
+{
+       m_callEntries = callEntries; 
+}
+
+FilterPtr EventFindCallHistory::getFilter() const
+{
+       return m_filter;
+}
+
+SortModePtr EventFindCallHistory::getSortMode() const
+{
+       return m_sortModes;
+}
+
+unsigned long EventFindCallHistory::getLimit() const
+{
+       return m_limit;
+}
+
+unsigned long EventFindCallHistory::getOffset() const
+{
+       return m_offset;
+}
+
+bool EventFindCallHistory::getFilterIsSet() const
+{
+       return m_filterIsSet;
+}
+
+bool EventFindCallHistory::getSortModesIsSet() const
+{
+       return m_sortModesIsSet;
+}
+
+bool EventFindCallHistory::getLimitIsSet() const
+{
+       return m_limitIsSet;
+}
+
+bool EventFindCallHistory::getOffsetIsSet() const
+{
+       return m_offsetIsSet;
+}
+
+CallHistoryEntryListPtr EventFindCallHistory::getResult() const
+{
+       return m_callEntries;
+}
+
+}
+}
+}
\ No newline at end of file
diff --git a/src/platform/API/Callhistory/EventFindCallHistory.h b/src/platform/API/Callhistory/EventFindCallHistory.h
new file mode 100755 (executable)
index 0000000..48e54d9
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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_CALL_EVENT_FIND_CALLHISTORY_H_
+#define TIZENAPIS_API_CALL_EVENT_FIND_CALLHISTORY_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <vector>
+#include <API/Filter/IFilter.h>
+#include <API/Filter/SortMode.h>
+#include "CallHistoryEntryProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+class EventFindCallHistory : public WrtDeviceApis::Commons::IEvent<EventFindCallHistory>
+{
+  private:
+       CallHistoryEntryListPtr m_callEntries;
+       Tizen::FilterPtr m_filter;
+       Tizen::SortModePtr m_sortModes;
+       unsigned long m_limit;
+       unsigned long m_offset;
+       bool m_filterIsSet;
+       bool m_sortModesIsSet;
+       bool m_limitIsSet;
+       bool m_offsetIsSet;
+
+  public:
+       void setFilter(const Tizen::FilterPtr &filter);
+       void setSortMode(const Tizen::SortModePtr &sortMode);
+       void setLimit(const unsigned long limit);
+       void setOffset(const unsigned long offset);
+       void setResult(const CallHistoryEntryListPtr &callEntries);
+
+       Tizen::FilterPtr getFilter() const;
+       Tizen::SortModePtr getSortMode() const;
+       unsigned long getLimit() const;
+       unsigned long getOffset() const;
+       bool getFilterIsSet() const;
+       bool getSortModesIsSet() const;
+       bool getLimitIsSet() const;
+       bool getOffsetIsSet() const;
+       CallHistoryEntryListPtr getResult() const;
+
+       EventFindCallHistory();
+};
+
+typedef DPL::SharedPtr<EventFindCallHistory> EventFindCallHistoryPtr;
+} 
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/platform/API/Callhistory/EventRemoveAll.h b/src/platform/API/Callhistory/EventRemoveAll.h
new file mode 100755 (executable)
index 0000000..ded7b03
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// 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_CALL_EVENT_REMOVE_ALL_H_
+#define TIZENAPIS_API_CALL_EVENT_REMOVE_ALL_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "EventCallHistoryTemplate.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+class EventRemoveAll : public EventCallHistoryTemplate<EventRemoveAll>
+{
+public:
+       EventRemoveAll() {}
+};
+
+typedef DPL::SharedPtr<EventRemoveAll> EventRemoveAllPtr;
+}
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/platform/API/Callhistory/EventRemoveBatch.h b/src/platform/API/Callhistory/EventRemoveBatch.h
new file mode 100755 (executable)
index 0000000..f008a7a
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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_CALL_EVENT_REMOVE_BATCH_H_
+#define TIZENAPIS_API_CALL_EVENT_REMOVE_BATCH_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "EventCallHistoryTemplate.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+class EventRemoveBatch : public EventCallHistoryTemplate<EventRemoveBatch>
+{
+  private:
+       std::vector<unsigned long> m_entryIds;
+
+  public:
+       void setEntryIds(const std::vector<unsigned long> &entryIds) { m_entryIds = entryIds; }
+       std::vector<unsigned long> getEntryIds() const { return m_entryIds; }
+
+       EventRemoveBatch() {}
+};
+
+typedef DPL::SharedPtr<EventRemoveBatch> EventRemoveBatchPtr;
+}
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/platform/API/Callhistory/ICallHistory.cpp b/src/platform/API/Callhistory/ICallHistory.cpp
new file mode 100755 (executable)
index 0000000..271bc47
--- /dev/null
@@ -0,0 +1,40 @@
+//
+// 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 "ICallHistory.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+
+using namespace WrtDeviceApis::Commons;
+
+ICallHistory::ICallHistory()  :
+               EventRequestReceiver<EventFindCallHistory>(ThreadEnum::CALLHISTORY_THREAD),
+               EventRequestReceiver<EventRemoveBatch>(ThreadEnum::CALLHISTORY_THREAD),
+               EventRequestReceiver<EventRemoveAll>(ThreadEnum::CALLHISTORY_THREAD),
+               EventRequestReceiver<EventCallHistory>(ThreadEnum::CALLHISTORY_THREAD)
+{
+}
+
+ICallHistory::~ICallHistory()
+{
+}
+
+}
+}
+}
diff --git a/src/platform/API/Callhistory/ICallHistory.h b/src/platform/API/Callhistory/ICallHistory.h
new file mode 100755 (executable)
index 0000000..8ab8855
--- /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_ICALLHISTORY_H_
+#define TIZENAPIS_API_ICALLHISTORY_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include "EventCallHistory.h"
+#include "EventFindCallHistory.h"
+#include "EventRemoveBatch.h"
+#include "EventRemoveAll.h"
+#include "EventCallHistoryListener.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+
+class ICallHistory : public WrtDeviceApis::Commons::EventRequestReceiver<EventFindCallHistory>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventRemoveBatch>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventRemoveAll>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventCallHistory>
+{
+public:
+       virtual ~ICallHistory();
+
+       virtual void find(const EventFindCallHistoryPtr& event) = 0;
+
+       virtual bool remove(const unsigned long entryId) = 0;
+
+       virtual void removeBatch(const EventRemoveBatchPtr& event) = 0;
+
+       virtual void removeAll(const EventRemoveAllPtr& event) = 0;
+
+       virtual long addListener(const EventCallHistoryListenerEmitterPtr& emitter) = 0;
+
+       virtual void removeListener(const long id) = 0;
+
+protected:
+       ICallHistory();
+       virtual void OnRequestReceived(const EventCallHistoryPtr& event) = 0;
+       virtual void OnRequestReceived(const EventFindCallHistoryPtr& event) = 0;
+       virtual void OnRequestReceived(const EventRemoveBatchPtr& event) = 0;
+       virtual void OnRequestReceived(const EventRemoveAllPtr& event) = 0;
+};
+typedef DPL::SharedPtr<ICallHistory> ICallHistoryPtr;
+}
+}
+}
+
+#endif
diff --git a/src/platform/API/Callhistory/ICallHistoryEntry.cpp b/src/platform/API/Callhistory/ICallHistoryEntry.cpp
new file mode 100755 (executable)
index 0000000..4b760ab
--- /dev/null
@@ -0,0 +1,36 @@
+//
+// 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 "ICallHistoryEntry.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+
+using namespace WrtDeviceApis::Commons;
+
+ICallHistoryEntry::ICallHistoryEntry()
+{
+}
+
+ICallHistoryEntry::~ICallHistoryEntry()
+{
+}
+
+}
+}
+}
diff --git a/src/platform/API/Callhistory/ICallHistoryEntry.h b/src/platform/API/Callhistory/ICallHistoryEntry.h
new file mode 100755 (executable)
index 0000000..5d8b39c
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// 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_ICALLHISTORYENTRY_H_
+#define TIZENAPIS_API_ICALLHISTORYENTRY_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+
+class ICallHistoryEntry
+{
+public:
+       virtual ~ICallHistoryEntry();
+
+       virtual void setMarkSeen(const unsigned long entryId) = 0;
+
+protected:
+       ICallHistoryEntry();
+};
+typedef DPL::SharedPtr<ICallHistoryEntry> ICallHistoryEntryPtr;
+}
+}
+}
+
+#endif
diff --git a/src/platform/API/Callhistory/RemoteParty.h b/src/platform/API/Callhistory/RemoteParty.h
new file mode 100755 (executable)
index 0000000..d940637
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// 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_REMOTEPARTY_H_
+#define TIZENAPIS_API_REMOTEPARTY_H_
+
+#include <dpl/shared_ptr.h>
+#include <string>
+#include <vector>
+
+namespace TizenApis {
+namespace Api {
+namespace Callhistory {
+class RemoteParty;
+typedef DPL::SharedPtr<RemoteParty> RemotePartyPtr;
+typedef std::vector<RemotePartyPtr> RemotePartyList;
+typedef DPL::SharedPtr<RemotePartyList> RemotePartyListPtr;
+
+class RemoteParty
+{
+private:
+       std::string m_remoteParty;
+       std::string m_personId;
+
+public:
+       void setRemoteParty(const std::string remoteParty) { m_remoteParty = remoteParty; }
+       void setPersonId(const std::string personId) { m_personId = personId; }
+
+       std::string getRemoteParty() const { return m_remoteParty; }
+       std::string getPersonId() const { return m_personId; }
+
+       
+       RemoteParty() : m_remoteParty(""), m_personId("") {}
+};
+}
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/platform/API/Callhistory/config.cmake b/src/platform/API/Callhistory/config.cmake
new file mode 100755 (executable)
index 0000000..f3d91d4
--- /dev/null
@@ -0,0 +1,10 @@
+get_current_path()
+set(SRCS_PLATFORM_API_CALLHISTORY
+  ${CURRENT_PATH}/CallHistoryEntryProperties.cpp
+  ${CURRENT_PATH}/CallHistoryFactory.cpp
+  ${CURRENT_PATH}/EventCallHistoryListener.cpp
+  ${CURRENT_PATH}/EventFindCallHistory.cpp
+  ${CURRENT_PATH}/ICallHistory.cpp
+  ${CURRENT_PATH}/ICallHistoryEntry.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Contact/ContactAddress.cpp b/src/platform/API/Contact/ContactAddress.cpp
new file mode 100755 (executable)
index 0000000..2903be1
--- /dev/null
@@ -0,0 +1,342 @@
+//
+// 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        ContactAddress.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include "ContactAddress.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+ContactAddress::ContactAddress() :
+       m_countryIsSet(false),
+       m_regionIsSet(false),
+       m_cityIsSet(false),
+       m_streetAddressIsSet(false),
+       m_additionalInformationIsSet(false),
+       m_postalCodeIsSet(false),
+       m_isDefault(false)
+{
+       m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
+}
+
+ContactAddress::~ContactAddress()
+{
+       //nothing to do
+}
+std::string ContactAddress::getCountry() const
+{
+       return m_country;
+}
+
+void ContactAddress::setCountry(const std::string &value)
+{
+       m_country = value;
+       m_countryIsSet = true;
+}
+
+void ContactAddress::unsetCountry()
+{
+       m_country = "";
+       m_countryIsSet = false;
+}
+
+bool ContactAddress::getCountryIsSet() const
+{
+       return m_countryIsSet;
+}
+
+std::string ContactAddress::getRegion() const
+{
+       return m_region;
+}
+
+void ContactAddress::setRegion(const std::string &value)
+{
+       m_region = value;
+       m_regionIsSet = true;
+}
+
+void ContactAddress::unsetRegion()
+{
+       m_region = "";
+       m_regionIsSet = false;
+}
+
+bool ContactAddress::getRegionIsSet() const
+{
+       return m_regionIsSet;
+}
+
+std::string ContactAddress::getCity() const
+{
+       return m_city;
+}
+
+void ContactAddress::setCity(const std::string &value)
+{
+       m_city = value;
+       m_cityIsSet = true;
+}
+
+void ContactAddress::unsetCity()
+{
+       m_city = "";
+       m_cityIsSet = false;
+}
+
+bool ContactAddress::getCityIsSet() const
+{
+       return m_cityIsSet;
+}
+
+std::string ContactAddress::getStreetAddress() const
+{
+       return m_streetAddress;
+}
+
+void ContactAddress::setStreetAddress(const std::string &value)
+{
+       m_streetAddress = value;
+       m_streetAddressIsSet = true;
+}
+
+void ContactAddress::unsetStreetAddress()
+{
+       m_streetAddress = "";
+       m_streetAddressIsSet = false;
+}
+
+bool ContactAddress::getStreetAddressIsSet() const
+{
+       return m_streetAddressIsSet;
+}
+
+std::string ContactAddress::getAdditionalInformation() const
+{
+       return m_additionalInformation;
+}
+
+void ContactAddress::setAdditionalInformation(const std::string &value)
+{
+       m_additionalInformation = value;
+       m_additionalInformationIsSet = true;
+}
+
+void ContactAddress::unsetAdditionalInformation()
+{
+       m_additionalInformation = "";
+       m_additionalInformationIsSet = false;
+}
+
+bool ContactAddress::getAdditionalInformationIsSet() const
+{
+       return m_additionalInformationIsSet;
+}
+
+std::string ContactAddress::getPostalCode() const
+{
+       return m_postalCode;
+}
+
+void ContactAddress::setPostalCode(const std::string &value)
+{
+       m_postalCode = value;
+       m_postalCodeIsSet = true;
+}
+
+void ContactAddress::unsetPostalCode()
+{
+       m_postalCode = "";
+       m_postalCodeIsSet = false;
+}
+
+bool ContactAddress::getPostalCodeIsSet() const
+{
+       return m_postalCodeIsSet;
+}
+
+bool ContactAddress::getIsDefault() const
+{
+       return m_isDefault;
+}
+
+void ContactAddress::setIsDefault(const bool &value)
+{
+       m_isDefault = value;
+}
+
+ContactAddressTypeArrayPtr ContactAddress::getTypes() const
+{
+       return m_types;
+}
+
+void ContactAddress::setTypes(const ContactAddressTypeArrayPtr &value)
+{
+       m_types = value;
+}
+
+void ContactAddress::addType(const ContactAddressType &value)
+{
+       m_types->push_back(value);
+}
+
+bool ContactAddress::isTypeOf(const ContactAddressType &value) const
+{
+       return std::find(m_types->begin(), m_types->end(), value) != m_types->end();
+}
+
+int ContactAddress::getTypesNum() const
+{
+       return m_types->size();
+}
+
+
+bool ContactAddress::compareTo(const ContactAddressPtr &address,
+               bool includeId,
+               bool includeTypes) const
+{
+       //compare basic fields
+       if ((!includeId) &&
+               m_country == address->getCountry() &&
+               m_region == address->getRegion() &&
+               m_city == address->getCity() &&
+               m_streetAddress == address->getStreetAddress() &&
+               m_additionalInformation == address->getAdditionalInformation() &&
+               m_postalCode == address->getPostalCode()) {
+               //if not include fields then addresses are equal
+               if (!includeTypes) {
+                       return true;
+               }
+               //if types have different sizes then addresses are different
+               if (m_types->size() != address->getTypes()->size()) {
+                       return false;
+               }
+               //compare each type
+               for (size_t i = 0; i < address->getTypes()->size(); i++) {
+                       if (!isTypeOf(address->getTypes()->at(i))) {
+                               return false;
+                       }
+               }
+               return true;
+       }
+       return false;
+}
+
+std::string ContactAddress::getAsSingleString() const
+{
+       std::string fullAddress;
+       //add street and street number when not empty
+       if (!m_streetAddress.empty()) {
+               fullAddress = m_streetAddress;
+       }
+       //add city and postal code when not empty
+       if (!m_city.empty()) {
+               if (!fullAddress.empty()) {
+                       fullAddress += " ";
+               }
+               if (!m_postalCode.empty()) {
+                       fullAddress += m_postalCode + " " + m_city;
+               } else {
+                       fullAddress += m_city;
+               }
+       }
+       //add country when not empty
+       if (!m_country.empty()) {
+               if (!fullAddress.empty()) {
+                       fullAddress += " " + m_country;
+               } else {
+                       fullAddress = m_country;
+               }
+       }
+       if (!fullAddress.empty()) {
+               return fullAddress;
+       }
+       //when no data on detailed fields, then return free form field
+       return "";
+}
+
+void ContactAddress::clear()
+{
+       m_country = "";
+       m_countryIsSet = false;
+
+       m_region = "";
+       m_regionIsSet = false;
+
+       m_city = "";
+       m_cityIsSet = false;
+
+       m_streetAddress = "";
+       m_streetAddressIsSet = false;
+
+       m_additionalInformation = "";
+       m_additionalInformationIsSet = false;
+
+       m_postalCode = "";
+       m_postalCodeIsSet = false;
+
+       m_isDefault = false;
+
+       m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
+}
+
+ContactAddressPtr ContactAddress::clone() const
+{
+       ContactAddressPtr result(new ContactAddress());
+
+       result->m_country = m_country;
+       result->m_countryIsSet = m_countryIsSet;
+
+       result->m_region = m_region;
+       result->m_regionIsSet = m_regionIsSet;
+
+       result->m_city = m_city;
+       result->m_cityIsSet = m_cityIsSet;
+
+       result->m_streetAddress = m_streetAddress;
+       result->m_streetAddressIsSet = m_streetAddressIsSet;
+
+       result->m_additionalInformation = m_additionalInformation;
+       result->m_additionalInformationIsSet = m_additionalInformationIsSet;
+
+       result->m_postalCode = m_postalCode;
+       result->m_postalCodeIsSet = m_postalCodeIsSet;
+
+       result->m_isDefault = m_isDefault;
+
+       result->m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
+       ContactAddressTypeArray::iterator typeIter;
+       for(typeIter = m_types->begin(); typeIter != m_types->end(); typeIter++)
+       {
+               ContactAddressType addressType = *typeIter;
+               result->m_types->push_back(addressType);
+       }
+
+       return result;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/ContactAddress.h b/src/platform/API/Contact/ContactAddress.h
new file mode 100755 (executable)
index 0000000..764a9e5
--- /dev/null
@@ -0,0 +1,130 @@
+//
+// 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        ContactAddress.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_CONTACT_ADDRESS_H_
+#define _API_CONTACT_CONTACT_ADDRESS_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include "ContactTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class ContactAddress;
+typedef DPL::SharedPtr<ContactAddress> ContactAddressPtr;
+
+typedef std::vector<ContactAddressPtr> ContactAddressArray;
+typedef DPL::SharedPtr<ContactAddressArray> ContactAddressArrayPtr;
+
+typedef std::vector<ContactAddressType> ContactAddressTypeArray;
+typedef DPL::SharedPtr<ContactAddressTypeArray> ContactAddressTypeArrayPtr;
+
+/* This object represents an address data of a contact */
+class ContactAddress
+{
+public:
+       ContactAddress();
+       ~ContactAddress();
+
+       std::string getCountry() const;
+       void setCountry(const std::string &value);
+       void unsetCountry();
+       bool getCountryIsSet() const;
+
+       std::string getRegion() const;
+       void setRegion(const std::string &value);
+       void unsetRegion();
+       bool getRegionIsSet() const;
+
+       std::string getCity() const;
+       void setCity(const std::string &value);
+       void unsetCity();
+       bool getCityIsSet() const;
+
+       std::string getStreetAddress() const;
+       void setStreetAddress(const std::string &value);
+       void unsetStreetAddress();
+       bool getStreetAddressIsSet() const;
+
+       std::string getAdditionalInformation() const;
+       void setAdditionalInformation(const std::string &value);
+       void unsetAdditionalInformation();
+       bool getAdditionalInformationIsSet() const;
+
+       std::string getPostalCode() const;
+       void setPostalCode(const std::string &value);
+       void unsetPostalCode();
+       bool getPostalCodeIsSet() const;
+
+       bool getIsDefault() const;
+       void setIsDefault(const bool &value);
+
+       ContactAddressTypeArrayPtr getTypes() const;
+       void setTypes(const ContactAddressTypeArrayPtr &value);
+       void addType(const ContactAddressType &value);
+       bool isTypeOf(const ContactAddressType &value) const;
+       int getTypesNum() const;
+
+       //returns m_country, ..., m_postalCode
+       //fields concatenated into single string
+       std::string getAsSingleString() const;
+
+       bool compareTo(const ContactAddressPtr &address,
+                                       bool includeId = false,
+                                       bool includeTypes = false) const;
+       void clear();
+       ContactAddressPtr clone() const;
+
+private:
+       std::string     m_country;
+       bool            m_countryIsSet;
+
+       std::string     m_region;
+       bool            m_regionIsSet;
+
+       std::string     m_city;
+       bool            m_cityIsSet;
+
+       std::string     m_streetAddress;
+       bool            m_streetAddressIsSet;
+
+       std::string     m_additionalInformation;
+       bool            m_additionalInformationIsSet;
+
+       std::string     m_postalCode;
+       bool            m_postalCodeIsSet;
+
+       bool            m_isDefault;
+
+       ContactAddressTypeArrayPtr m_types;
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_ADDRESS_H_
diff --git a/src/platform/API/Contact/ContactAnniversary.cpp b/src/platform/API/Contact/ContactAnniversary.cpp
new file mode 100755 (executable)
index 0000000..8fbb3e3
--- /dev/null
@@ -0,0 +1,110 @@
+//
+// 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        ContactAnniversary.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactAnniversary.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+ContactAnniversary::ContactAnniversary() :
+               m_dateIsSet(false),
+               m_labelIsSet(false)
+{
+       m_date = {0, };
+}
+
+ContactAnniversary::~ContactAnniversary()
+{
+}
+
+std::tm ContactAnniversary::getDate() const
+{
+       return m_date;
+}
+
+void ContactAnniversary::setDate(const std::tm &value)
+{
+       m_date = value;
+       m_dateIsSet = true;
+}
+
+void ContactAnniversary::unsetDate()
+{
+       m_date = {0, };
+       m_dateIsSet = false;
+}
+
+bool ContactAnniversary::getDateIsSet() const
+{
+       return m_dateIsSet;
+}
+
+std::string ContactAnniversary::getLabel() const
+{
+       return m_label;
+}
+
+void ContactAnniversary::setLabel(const std::string &value)
+{
+       m_label = value;
+       m_labelIsSet = true;
+}
+
+void ContactAnniversary::unsetLabel()
+{
+       m_label = "";
+       m_labelIsSet = false;
+}
+
+bool ContactAnniversary::getLabelIsSet() const
+{
+       return m_labelIsSet;
+}
+
+void ContactAnniversary::clear()
+{
+       m_date = {0, };
+       m_dateIsSet = false;
+
+       m_label = "";
+       m_labelIsSet = false;
+}
+
+ContactAnniversaryPtr ContactAnniversary::clone() const
+{
+       ContactAnniversaryPtr result(new ContactAnniversary());
+
+       result->m_date = m_date;
+       result->m_dateIsSet = m_dateIsSet;
+
+       result->m_label = m_label;
+       result->m_labelIsSet = m_labelIsSet;
+
+       return result;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/ContactAnniversary.h b/src/platform/API/Contact/ContactAnniversary.h
new file mode 100755 (executable)
index 0000000..7c30b27
--- /dev/null
@@ -0,0 +1,75 @@
+//
+// 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        ContactAnniversary.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_CONTACT_ANNIVERSARY_H_
+#define _API_CONTACT_CONTACT_ANNIVERSARY_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class ContactAnniversary;
+typedef DPL::SharedPtr<ContactAnniversary> ContactAnniversaryPtr;
+
+typedef std::vector<ContactAnniversaryPtr> ContactAnniversaryArray;
+typedef DPL::SharedPtr<ContactAnniversaryArray> ContactAnniversaryArrayPtr;
+
+/* This object represents an anniversary data of a contact */
+class ContactAnniversary
+{
+public:
+       ContactAnniversary();
+       ~ContactAnniversary();
+
+       std::tm getDate() const;
+       void setDate(const std::tm &value);
+       void unsetDate();
+       bool getDateIsSet() const;
+
+       std::string getLabel() const;
+       void setLabel(const std::string &value);
+       void unsetLabel();
+       bool getLabelIsSet() const;
+
+       void clear();
+       ContactAnniversaryPtr clone() const;
+
+private:
+       std::tm         m_date;
+       bool            m_dateIsSet;
+
+       std::string     m_label;
+       bool            m_labelIsSet;
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_ANNIVERSARY_H_
diff --git a/src/platform/API/Contact/ContactEmailAddress.cpp b/src/platform/API/Contact/ContactEmailAddress.cpp
new file mode 100755 (executable)
index 0000000..85330ed
--- /dev/null
@@ -0,0 +1,128 @@
+//
+// 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        ContactEmailAddress.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactEmailAddress.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+ContactEmailAddress::ContactEmailAddress() :
+               m_emailIsSet(false),
+               m_isDefault(false)
+{
+       m_types = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
+}
+
+ContactEmailAddress::~ContactEmailAddress()
+{
+}
+
+std::string ContactEmailAddress::getEmail() const
+{
+       return m_email;
+}
+
+void ContactEmailAddress::setEmail(const std::string &value)
+{
+       m_email = value;
+       m_emailIsSet = true;
+}
+
+void ContactEmailAddress::unsetEmail()
+{
+       m_email = "";
+       m_emailIsSet = false;
+}
+
+bool ContactEmailAddress::getEmailIsSet() const
+{
+       return m_emailIsSet;
+}
+
+bool ContactEmailAddress::getIsDefault() const
+{
+       return m_isDefault;
+}
+
+void ContactEmailAddress::setIsDefault(const bool &value)
+{
+       m_isDefault = value;
+}
+
+ContactEmailAddressTypeArrayPtr ContactEmailAddress::getTypes() const
+{
+       return m_types;
+}
+
+void ContactEmailAddress::setTypes(const ContactEmailAddressTypeArrayPtr &value)
+{
+       m_types = value;
+}
+
+void ContactEmailAddress::addType(ContactEmailAddressType value)
+{
+       m_types->push_back(value);
+}
+
+bool ContactEmailAddress::isTypeOf(ContactEmailAddressType value) const
+{
+       return std::find(m_types->begin(), m_types->end(), value) != m_types->end();
+}
+
+int ContactEmailAddress::getTypesNum() const
+{
+       return m_types->size();
+}
+
+void ContactEmailAddress::clear()
+{
+       m_email = "";
+       m_emailIsSet = false;
+
+       m_isDefault = false;
+
+       m_types = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
+}
+
+ContactEmailAddressPtr ContactEmailAddress::clone() const
+{
+       ContactEmailAddressPtr result(new ContactEmailAddress());
+
+       result->m_email = m_email;
+       result->m_emailIsSet = m_emailIsSet;
+
+       result->m_isDefault = m_isDefault;
+
+       result->m_types = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
+       ContactEmailAddressTypeArray::iterator typeIter;
+       for(typeIter = m_types->begin(); typeIter != m_types->end(); typeIter++)
+               result->m_types->push_back(*typeIter);
+
+       return result;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/ContactEmailAddress.h b/src/platform/API/Contact/ContactEmailAddress.h
new file mode 100755 (executable)
index 0000000..87afbf7
--- /dev/null
@@ -0,0 +1,83 @@
+//
+// 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        ContactEmailAddress.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_CONTACT_EMAIL_ADDRESS_H_
+#define _API_CONTACT_CONTACT_EMAIL_ADDRESS_H_
+
+#include <algorithm>
+#include <vector>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "ContactTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class ContactEmailAddress;
+typedef DPL::SharedPtr<ContactEmailAddress> ContactEmailAddressPtr;
+
+typedef std::vector<ContactEmailAddressPtr> ContactEmailAddressArray;
+typedef DPL::SharedPtr<ContactEmailAddressArray> ContactEmailAddressArrayPtr;
+
+typedef std::vector<ContactEmailAddressType> ContactEmailAddressTypeArray;
+typedef DPL::SharedPtr<ContactEmailAddressTypeArray> ContactEmailAddressTypeArrayPtr;
+
+class ContactEmailAddress
+{
+public:
+       ContactEmailAddress();
+       ~ContactEmailAddress();
+
+       std::string getEmail() const;
+       void setEmail(const std::string &value);
+       void unsetEmail();
+       bool getEmailIsSet() const;
+
+       bool getIsDefault() const;
+       void setIsDefault(const bool &value);
+
+       ContactEmailAddressTypeArrayPtr getTypes() const;
+       void setTypes(const ContactEmailAddressTypeArrayPtr &value);
+       void addType(ContactEmailAddressType value);
+       bool isTypeOf(ContactEmailAddressType value) const;
+       int getTypesNum() const;
+
+       void clear();
+       ContactEmailAddressPtr clone() const;
+
+private:
+       std::string     m_email;
+       bool            m_emailIsSet;
+
+       bool            m_isDefault;
+
+       ContactEmailAddressTypeArrayPtr m_types;
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_EMAIL_ADDRESS_H_
diff --git a/src/platform/API/Contact/ContactFactory.cpp b/src/platform/API/Contact/ContactFactory.cpp
new file mode 100755 (executable)
index 0000000..4b5db05
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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        ContactFactory.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ * ##
+ */
+
+#include <map>
+#include "ContactFactory.h"
+#include <Contact/ContactImpl.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+ContactFactory& ContactFactory::getInstance() // static
+{
+       static ContactFactory theInstance;
+       return theInstance;
+}
+
+ContactManagerPtr ContactFactory::createContactManager()
+{
+       static ContactManagerPtr result(new TizenApis::Platform::Contact::ContactManager());
+//     static ContactManagerPtr result(NULL);
+       return result;
+}
+
+ContactPtr ContactFactory::createContact()
+{
+       ContactPtr result(new TizenApis::Platform::Contact::Contact());
+       return result;
+}
+
+PersonPtr ContactFactory::createPerson()
+{
+       PersonPtr result(new TizenApis::Platform::Contact::Person());
+       return result;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/ContactFactory.h b/src/platform/API/Contact/ContactFactory.h
new file mode 100755 (executable)
index 0000000..ad70463
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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        ContactFactory.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ * ##
+ */
+
+#ifndef _API_CONTACT_CONTACT_FACTORY_H_
+#define _API_CONTACT_CONTACT_FACTORY_H_
+
+#include <dpl/shared_ptr.h>
+#include "IContactManager.h"
+#include "IContact.h"
+#include "IPerson.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class ContactFactory : private DPL::Noncopyable
+{
+private:
+       ContactFactory()
+       {
+       }
+public:
+       static ContactFactory&  getInstance();
+       ContactManagerPtr      createContactManager();
+       ContactPtr              createContact();
+       PersonPtr               createPerson();
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_FACTORY_H_
diff --git a/src/platform/API/Contact/ContactGroup.cpp b/src/platform/API/Contact/ContactGroup.cpp
new file mode 100755 (executable)
index 0000000..e05c147
--- /dev/null
@@ -0,0 +1,247 @@
+//
+// 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        ContactGroup.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactGroup.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+ContactGroup::ContactGroup() :
+               m_idIsSet(false),
+               m_addressBookIdIsSet(false),
+               m_nameIsSet(false),
+               m_ringtoneURIIsSet(false),
+               m_photoURIIsSet(false),
+               m_readOnly(false)
+{
+}
+
+ContactGroup::~ContactGroup()
+{
+}
+
+std::string ContactGroup::getId() const
+{
+       return m_id;
+}
+
+void ContactGroup::setId(const std::string &value)
+{
+       m_id = value;
+       m_idIsSet = true;
+}
+
+void ContactGroup::setId(const int value)
+{
+       std::stringstream oss;
+       oss << value;
+       m_id = oss.str();
+       m_idIsSet = true;
+}
+
+void ContactGroup::unsetId()
+{
+       m_id = "";
+       m_idIsSet = false;
+}
+
+bool ContactGroup::getIdIsSet() const
+{
+       return m_idIsSet;
+}
+
+std::string ContactGroup::getAddressBookId() const
+{
+       return m_addressBookId;
+}
+
+void ContactGroup::setAddressBookId(const std::string &value)
+{
+       m_addressBookId = value;
+       m_addressBookIdIsSet = true;
+}
+
+void ContactGroup::setAddressBookId(const int value)
+{
+       std::stringstream oss;
+       oss << value;
+       m_addressBookId = oss.str();
+       m_addressBookIdIsSet = true;
+}
+
+void ContactGroup::unsetAddressBookId()
+{
+       m_addressBookId = "";
+       m_addressBookIdIsSet = false;
+}
+
+bool ContactGroup::getAddressBookIdIsSet() const
+{
+       return m_addressBookIdIsSet;
+}
+
+std::string ContactGroup::getName() const
+{
+       return m_name;
+}
+
+void ContactGroup::setName(const std::string &value)
+{
+       m_name = value;
+       m_nameIsSet = true;
+}
+
+void ContactGroup::unsetName()
+{
+       m_name = "";
+       m_nameIsSet = false;
+}
+
+bool ContactGroup::getNameIsSet() const
+{
+       return m_nameIsSet;
+}
+
+std::string ContactGroup::getRingtoneURI() const
+{
+       return m_ringtoneURI;
+}
+
+void ContactGroup::setRingtoneURI(const std::string &value)
+{
+       m_ringtoneURI = value;
+       m_ringtoneURIIsSet = true;
+}
+
+void ContactGroup::unsetRingtoneURI()
+{
+       m_ringtoneURI = "";
+       m_ringtoneURIIsSet = false;
+}
+
+bool ContactGroup::getRingtoneURIIsSet() const
+{
+       return m_ringtoneURIIsSet;
+}
+
+std::string ContactGroup::getRingtoneURIRealPath() const
+{
+       return m_ringtoneURIRealPath;
+}
+
+void ContactGroup::setRingtoneURIRealPath(const std::string &value)
+{
+       m_ringtoneURIRealPath = value;
+}
+
+std::string ContactGroup::getPhotoURI() const
+{
+       return m_photoURI;
+}
+
+void ContactGroup::setPhotoURI(const std::string &value)
+{
+       m_photoURI = value;
+       m_photoURIIsSet = true;
+}
+
+void ContactGroup::unsetPhotoURI()
+{
+       m_photoURI = "";
+       m_photoURIIsSet = false;
+}
+
+bool ContactGroup::getPhotoURIIsSet() const
+{
+       return m_photoURIIsSet;
+}
+
+std::string ContactGroup::getPhotoURIRealPath() const
+{
+       return m_photoURIRealPath;
+}
+
+void ContactGroup::setPhotoURIRealPath(const std::string &value)
+{
+       m_photoURIRealPath = value;
+}
+
+bool ContactGroup::getReadOnly() const
+{
+       return m_readOnly;
+}
+
+void ContactGroup::setReadOnly(const bool &value)
+{
+       m_readOnly = value;
+}
+
+void ContactGroup::clear()
+{
+       m_id = "";
+       m_idIsSet = false;
+
+       m_addressBookId = "";
+       m_addressBookIdIsSet = false;
+
+       m_name = "";
+       m_nameIsSet = false;
+
+       m_ringtoneURI = "";
+       m_ringtoneURIIsSet = false;
+
+       m_photoURI = "";
+       m_photoURIIsSet = false;
+
+       m_readOnly = false;
+}
+
+ContactGroupPtr ContactGroup::clone() const
+{
+       ContactGroupPtr result(new ContactGroup());
+
+       result->m_id = m_id;
+       result->m_idIsSet = m_idIsSet;
+
+       result->m_addressBookId = m_addressBookId;
+       result->m_addressBookIdIsSet = m_addressBookIdIsSet;
+
+       result->m_name = m_name;
+       result->m_nameIsSet = m_nameIsSet;
+
+       result->m_ringtoneURI = m_ringtoneURI;
+       result->m_ringtoneURIIsSet = m_ringtoneURIIsSet;
+
+       result->m_photoURI = m_photoURI;
+       result->m_photoURIIsSet = m_photoURIIsSet;
+
+       result->m_readOnly = m_readOnly;
+
+       return result;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/ContactGroup.h b/src/platform/API/Contact/ContactGroup.h
new file mode 100755 (executable)
index 0000000..9c18b95
--- /dev/null
@@ -0,0 +1,112 @@
+//
+// 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        ContactGroup.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_CONTACT_GROUP_H_
+#define _API_CONTACT_CONTACT_GROUP_H_
+
+#include <vector>
+#include <string>
+#include <sstream>
+#include <dpl/shared_ptr.h>
+#include "ContactTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class ContactGroup;
+typedef DPL::SharedPtr<ContactGroup> ContactGroupPtr;
+
+typedef std::vector<ContactGroupPtr> ContactGroupArray;
+typedef DPL::SharedPtr<ContactGroupArray> ContactGroupArrayPtr;
+
+class ContactGroup
+{
+public:
+       ContactGroup();
+       virtual ~ContactGroup();
+
+       std::string getId() const;
+       void setId(const std::string &value);
+       void setId(const int value);
+       void unsetId();
+       bool getIdIsSet() const;
+
+       std::string getAddressBookId() const;
+       void setAddressBookId(const std::string &value);
+       void setAddressBookId(const int value);
+       void unsetAddressBookId();
+       bool getAddressBookIdIsSet() const;
+
+       std::string getName() const;
+       void setName(const std::string &value);
+       void unsetName();
+       bool getNameIsSet() const;
+
+       std::string getRingtoneURI() const;
+       void setRingtoneURI(const std::string &value);
+       void unsetRingtoneURI();
+       bool getRingtoneURIIsSet() const;
+       std::string getRingtoneURIRealPath() const;
+       void setRingtoneURIRealPath(const std::string &value);
+
+       std::string getPhotoURI() const;
+       void setPhotoURI(const std::string &value);
+       void unsetPhotoURI();
+       bool getPhotoURIIsSet() const;
+       std::string getPhotoURIRealPath() const;
+       void setPhotoURIRealPath(const std::string &value);
+
+       bool getReadOnly() const;
+       void setReadOnly(const bool &value);
+
+       void clear();
+       ContactGroupPtr clone() const;
+
+private:
+       std::string     m_id;
+       bool            m_idIsSet;
+
+       std::string     m_addressBookId;
+       bool            m_addressBookIdIsSet;
+
+       std::string     m_name;
+       bool            m_nameIsSet;
+
+       std::string     m_ringtoneURI;
+       bool            m_ringtoneURIIsSet;
+       std::string     m_ringtoneURIRealPath;
+
+       std::string     m_photoURI;
+       bool            m_photoURIIsSet;
+       std::string     m_photoURIRealPath;
+
+       bool            m_readOnly;
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_GROUP_H_
diff --git a/src/platform/API/Contact/ContactName.cpp b/src/platform/API/Contact/ContactName.cpp
new file mode 100755 (executable)
index 0000000..fc5a466
--- /dev/null
@@ -0,0 +1,322 @@
+//
+// 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        ContactName.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactName.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+ContactName::ContactName() :
+               m_prefixIsSet(false),
+               m_suffixIsSet(false),
+               m_firstNameIsSet(false),
+               m_middleNameIsSet(false),
+               m_lastNameIsSet(false),
+               m_phoneticFirstNameIsSet(false),
+               m_phoneticLastNameIsSet(false),
+               m_displayNameIsSet(false)
+{
+       m_nicknames = StringArrayPtr(new StringArray());
+}
+
+ContactName::~ContactName()
+{
+}
+
+std::string ContactName::getPrefix() const
+{
+       return m_prefix;
+}
+
+void ContactName::setPrefix(const std::string &value)
+{
+       m_prefix = value;
+       m_prefixIsSet = true;
+}
+
+void ContactName::unsetPrefix()
+{
+       m_prefix = "";
+       m_prefixIsSet = false;
+}
+
+bool ContactName::getPrefixIsSet() const
+{
+       return m_prefixIsSet;
+}
+
+std::string ContactName::getSuffix() const
+{
+       return m_suffix;
+}
+
+void ContactName::setSuffix(const std::string &value)
+{
+       m_suffix = value;
+       m_suffixIsSet = true;
+}
+
+void ContactName::unsetSuffix()
+{
+       m_suffix = "";
+       m_suffixIsSet = false;
+}
+
+bool ContactName::getSuffixIsSet() const
+{
+       return m_suffixIsSet;
+}
+
+std::string ContactName::getFirstName() const
+{
+       return m_firstName;
+}
+
+void ContactName::setFirstName(const std::string &value)
+{
+       m_firstName = value;
+       m_firstNameIsSet = true;
+}
+
+void ContactName::unsetFirstName()
+{
+       m_firstName = "";
+       m_firstNameIsSet = false;
+}
+
+bool ContactName::getFirstNameIsSet() const
+{
+       return m_firstNameIsSet;
+}
+
+std::string ContactName::getMiddleName() const
+{
+       return m_middleName;
+}
+
+void ContactName::setMiddleName(const std::string &value)
+{
+       m_middleName = value;
+       m_middleNameIsSet = true;
+}
+
+void ContactName::unsetMiddleName()
+{
+       m_middleName = "";
+       m_middleNameIsSet = false;
+}
+
+bool ContactName::getMiddleNameIsSet() const
+{
+       return m_middleNameIsSet;
+}
+
+std::string ContactName::getLastName() const
+{
+       return m_lastName;
+}
+
+void ContactName::setLastName(const std::string &value)
+{
+       m_lastName = value;
+       m_lastNameIsSet = true;
+}
+
+void ContactName::unsetLastName()
+{
+       m_lastName = "";
+       m_lastNameIsSet = false;
+}
+
+bool ContactName::getLastNameIsSet() const
+{
+       return m_lastNameIsSet;
+}
+
+StringArrayPtr ContactName::getNicknames() const
+{
+       return m_nicknames;
+}
+
+void ContactName::setNicknames(const StringArrayPtr &value)
+{
+       if(value == NULL)
+               m_nicknames = StringArrayPtr(new StringArray());
+       else
+               m_nicknames = value;
+}
+
+void ContactName::addNickname(const std::string &value)
+{
+       m_nicknames->push_back(value);
+}
+
+void ContactName::clearNicknames()
+{
+       m_nicknames->clear();
+}
+
+int ContactName::getNicknamesNum() const
+{
+       return m_nicknames->size();
+}
+
+std::string ContactName::getPhoneticFirstName() const
+{
+       return m_phoneticFirstName;
+}
+
+void ContactName::setPhoneticFirstName(const std::string &value)
+{
+       m_phoneticFirstName = value;
+       m_phoneticFirstNameIsSet = true;
+}
+
+void ContactName::unsetPhoneticFirstName()
+{
+       m_phoneticFirstName = "";
+       m_phoneticFirstNameIsSet = false;
+}
+
+bool ContactName::getPhoneticFirstNameIsSet() const
+{
+       return m_phoneticFirstNameIsSet;
+}
+
+std::string ContactName::getPhoneticLastName() const
+{
+       return m_phoneticLastName;
+}
+
+void ContactName::setPhoneticLastName(const std::string &value)
+{
+       m_phoneticLastName = value;
+       m_phoneticLastNameIsSet = true;
+}
+
+void ContactName::unsetPhoneticLastName()
+{
+       m_phoneticLastName = "";
+       m_phoneticLastNameIsSet = false;
+}
+
+bool ContactName::getPhoneticLastNameIsSet() const
+{
+       return m_phoneticLastNameIsSet;
+}
+
+std::string ContactName::getDisplayName() const
+{
+       return m_displayName;
+}
+
+void ContactName::setDisplayName(const std::string &value)
+{
+       m_displayName = value;
+       m_displayNameIsSet = true;
+}
+
+void ContactName::unsetDisplayName()
+{
+       m_displayName = "";
+       m_displayNameIsSet = false;
+}
+
+bool ContactName::getDisplayNameIsSet() const
+{
+       return m_displayNameIsSet;
+}
+
+void ContactName::clear()
+{
+       m_prefix = "";
+       m_prefixIsSet = false;
+
+       m_suffix = "";
+       m_suffixIsSet = false;
+
+       m_firstName = "";
+       m_firstNameIsSet = false;
+
+       m_middleName = "";
+       m_middleNameIsSet = false;
+
+       m_lastName = "";
+       m_lastNameIsSet = false;
+
+       m_nicknames = StringArrayPtr(new StringArray());
+
+       m_phoneticFirstName = "";
+       m_phoneticFirstNameIsSet = false;
+
+       m_phoneticLastName = "";
+       m_phoneticLastNameIsSet = false;
+
+       m_displayName = "";
+       m_displayNameIsSet = false;
+}
+
+ContactNamePtr ContactName::clone() const
+{
+       ContactNamePtr result(new ContactName());
+
+       result->m_prefix = m_prefix;
+       result->m_prefixIsSet = m_prefixIsSet;
+
+       result->m_suffix = m_suffix;
+       result->m_suffixIsSet = m_suffixIsSet;
+
+       result->m_firstName = m_firstName;
+       result->m_firstNameIsSet = m_firstNameIsSet;
+
+       result->m_middleName = m_middleName;
+       result->m_middleNameIsSet = m_middleNameIsSet;
+
+       result->m_lastName = m_lastName;
+       result->m_lastNameIsSet = m_lastNameIsSet;
+
+       result->m_nicknames = StringArrayPtr(new StringArray());
+       StringArray::iterator nicknameIter;
+       for(nicknameIter = m_nicknames->begin(); nicknameIter != m_nicknames->end(); nicknameIter++)
+       {
+               std::string nickname = *nicknameIter;
+               result->m_nicknames->push_back(nickname);
+       }
+
+       result->m_phoneticFirstName = m_phoneticFirstName;
+       result->m_phoneticFirstNameIsSet = m_phoneticFirstNameIsSet;
+
+       result->m_phoneticLastName = m_phoneticLastName;
+       result->m_phoneticLastNameIsSet = m_phoneticLastNameIsSet;
+
+       result->m_displayName = m_displayName;
+       result->m_displayNameIsSet = m_displayNameIsSet;
+
+       return result;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/ContactName.h b/src/platform/API/Contact/ContactName.h
new file mode 100755 (executable)
index 0000000..52bb187
--- /dev/null
@@ -0,0 +1,130 @@
+//
+// 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        ContactName.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_CONTACT_NAME_H_
+#define _API_CONTACT_CONTACT_NAME_H_
+
+#include <vector>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "ContactTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class ContactName;
+typedef DPL::SharedPtr<ContactName> ContactNamePtr;
+
+typedef std::vector<ContactNamePtr> ContactNameArray;
+typedef DPL::SharedPtr<ContactNameArray> ContactNameArrayPtr;
+
+class ContactName
+{
+public:
+       ContactName();
+       virtual ~ContactName();
+
+       std::string getPrefix() const;
+       void setPrefix(const std::string &value);
+       void unsetPrefix();
+       bool getPrefixIsSet() const;
+
+       std::string getSuffix() const;
+       void setSuffix(const std::string &value);
+       void unsetSuffix();
+       bool getSuffixIsSet() const;
+
+       std::string getFirstName() const;
+       void setFirstName(const std::string &value);
+       void unsetFirstName();
+       bool getFirstNameIsSet() const;
+
+       std::string getMiddleName() const;
+       void setMiddleName(const std::string &value);
+       void unsetMiddleName();
+       bool getMiddleNameIsSet() const;
+
+       std::string getLastName() const;
+       void setLastName(const std::string &value);
+       void unsetLastName();
+       bool getLastNameIsSet() const;
+
+       StringArrayPtr getNicknames() const;
+       void setNicknames(const StringArrayPtr &value);
+       void addNickname(const std::string& value);
+       void clearNicknames();
+       int  getNicknamesNum() const;
+
+       std::string getPhoneticFirstName() const;
+       void setPhoneticFirstName(const std::string &value);
+       void unsetPhoneticFirstName();
+       bool getPhoneticFirstNameIsSet() const;
+
+       std::string getPhoneticLastName() const;
+       void setPhoneticLastName(const std::string &value);
+       void unsetPhoneticLastName();
+       bool getPhoneticLastNameIsSet() const;
+
+       std::string getDisplayName() const;
+       void setDisplayName(const std::string &value);
+       void unsetDisplayName();
+       bool getDisplayNameIsSet() const;
+
+       void clear();
+       ContactNamePtr clone() const;
+
+private:
+       std::string     m_prefix;
+       bool            m_prefixIsSet;
+
+       std::string     m_suffix;
+       bool            m_suffixIsSet;
+
+       std::string     m_firstName;
+       bool            m_firstNameIsSet;
+
+       std::string     m_middleName;
+       bool            m_middleNameIsSet;
+
+       std::string     m_lastName;
+       bool            m_lastNameIsSet;
+
+       StringArrayPtr  m_nicknames;
+
+       std::string     m_phoneticFirstName;
+       bool            m_phoneticFirstNameIsSet;
+
+       std::string     m_phoneticLastName;
+       bool            m_phoneticLastNameIsSet;
+
+       std::string     m_displayName;
+       bool            m_displayNameIsSet;
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_NAME_H_
diff --git a/src/platform/API/Contact/ContactOrganization.cpp b/src/platform/API/Contact/ContactOrganization.cpp
new file mode 100755 (executable)
index 0000000..7d2812f
--- /dev/null
@@ -0,0 +1,196 @@
+//
+// 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        ContactOrganization.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactOrganization.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+ContactOrganization::ContactOrganization() :
+               m_nameIsSet(false),
+               m_departmentIsSet(false),
+               m_titleIsSet(false),
+               m_roleIsSet(false),
+               m_logoURIIsSet(false)
+{
+}
+
+ContactOrganization::~ContactOrganization()
+{
+}
+
+std::string ContactOrganization::getName() const
+{
+       return m_name;
+}
+
+void ContactOrganization::setName(const std::string &value)
+{
+       m_name = value;
+       m_nameIsSet = true;
+}
+
+void ContactOrganization::unsetName()
+{
+       m_name = "";
+       m_nameIsSet = false;
+}
+
+bool ContactOrganization::getNameIsSet() const
+{
+       return m_nameIsSet;
+}
+
+std::string ContactOrganization::getDepartment() const
+{
+       return m_department;
+}
+
+void ContactOrganization::setDepartment(const std::string &value)
+{
+       m_department = value;
+       m_departmentIsSet = true;
+}
+
+void ContactOrganization::unsetDepartment()
+{
+       m_department = "";
+       m_departmentIsSet = false;
+}
+
+bool ContactOrganization::getDepartmentIsSet() const
+{
+       return m_departmentIsSet;
+}
+
+std::string ContactOrganization::getTitle() const
+{
+       return m_title;
+}
+
+void ContactOrganization::setTitle(const std::string &value)
+{
+       m_title = value;
+       m_titleIsSet = true;
+}
+
+void ContactOrganization::unsetTitle()
+{
+       m_title = "";
+       m_titleIsSet = false;
+}
+
+bool ContactOrganization::getTitleIsSet() const
+{
+       return m_titleIsSet;
+}
+
+std::string ContactOrganization::getRole() const
+{
+       return m_role;
+}
+
+void ContactOrganization::setRole(const std::string &value)
+{
+       m_role = value;
+       m_roleIsSet = true;
+}
+
+void ContactOrganization::unsetRole()
+{
+       m_role = "";
+       m_roleIsSet = false;
+}
+
+bool ContactOrganization::getRoleIsSet() const
+{
+       return m_roleIsSet;
+}
+
+std::string ContactOrganization::getLogoURI() const
+{
+       return m_logoURI;
+}
+
+void ContactOrganization::setLogoURI(const std::string &value)
+{
+       m_logoURI = value;
+       m_logoURIIsSet = true;
+}
+
+void ContactOrganization::unsetLogoURI()
+{
+       m_logoURI = "";
+       m_logoURIIsSet = false;
+}
+
+bool ContactOrganization::getLogoURIIsSet() const
+{
+       return m_logoURIIsSet;
+}
+
+void ContactOrganization::clear()
+{
+       m_name = "";
+       m_nameIsSet = false;
+
+       m_department = "";
+       m_departmentIsSet = false;
+
+       m_title = "";
+       m_titleIsSet = false;
+
+       m_role = "";
+       m_roleIsSet = false;
+
+       m_logoURI = "";
+       m_logoURIIsSet = false;
+}
+
+ContactOrganizationPtr ContactOrganization::clone() const
+{
+       ContactOrganizationPtr result(new ContactOrganization());
+
+       result->m_name = m_name;
+       result->m_nameIsSet = m_nameIsSet;
+
+       result->m_department = m_department;
+       result->m_departmentIsSet = m_departmentIsSet;
+
+       result->m_title = m_title;
+       result->m_titleIsSet = m_titleIsSet;
+
+       result->m_role = m_role;
+       result->m_roleIsSet = m_roleIsSet;
+
+       result->m_logoURI = m_logoURI;
+       result->m_logoURIIsSet = m_logoURIIsSet;
+
+       return result;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/ContactOrganization.h b/src/platform/API/Contact/ContactOrganization.h
new file mode 100755 (executable)
index 0000000..fea60ef
--- /dev/null
@@ -0,0 +1,97 @@
+//
+// 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        ContactOrganization.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_CONTACT_ORGANIZATION_H_
+#define _API_CONTACT_CONTACT_ORGANIZATION_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class ContactOrganization;
+typedef DPL::SharedPtr<ContactOrganization> ContactOrganizationPtr;
+
+typedef std::vector<ContactOrganizationPtr> ContactOrganizationArray;
+typedef DPL::SharedPtr<ContactOrganizationArray> ContactOrganizationArrayPtr;
+
+class ContactOrganization
+{
+public:
+       ContactOrganization();
+       ~ContactOrganization();
+
+       std::string getName() const;
+       void setName(const std::string &value);
+       void unsetName();
+       bool getNameIsSet() const;
+
+       std::string getDepartment() const;
+       void setDepartment(const std::string &value);
+       void unsetDepartment();
+       bool getDepartmentIsSet() const;
+
+       std::string getTitle() const;
+       void setTitle(const std::string &value);
+       void unsetTitle();
+       bool getTitleIsSet() const;
+
+       std::string getRole() const;
+       void setRole(const std::string &value);
+       void unsetRole();
+       bool getRoleIsSet() const;
+
+       std::string getLogoURI() const;
+       void setLogoURI(const std::string &value);
+       void unsetLogoURI();
+       bool getLogoURIIsSet() const;
+
+       void clear();
+       ContactOrganizationPtr clone() const;
+
+private:
+       std::string     m_name;
+       bool            m_nameIsSet;
+
+       std::string     m_department;
+       bool            m_departmentIsSet;
+
+       std::string     m_title;
+       bool            m_titleIsSet;
+
+       std::string     m_role;
+       bool            m_roleIsSet;
+
+       std::string     m_logoURI;
+       bool            m_logoURIIsSet;
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_ORGANIZATION_H_
diff --git a/src/platform/API/Contact/ContactPhoneNumber.cpp b/src/platform/API/Contact/ContactPhoneNumber.cpp
new file mode 100755 (executable)
index 0000000..645df7f
--- /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.
+//
+
+/**
+ * @file        ContactPhoneNumber.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactPhoneNumber.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+using namespace std;
+
+ContactPhoneNumber::ContactPhoneNumber() :
+               m_numberIsSet(false),
+               m_isDefault(false)
+{
+       m_types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
+}
+
+ContactPhoneNumber::~ContactPhoneNumber()
+{
+}
+
+std::string ContactPhoneNumber::getNumber() const
+{
+       return m_number;
+}
+
+void ContactPhoneNumber::setNumber(const std::string &value)
+{
+       m_number = value;
+       m_numberIsSet = true;
+}
+
+void ContactPhoneNumber::unsetNumber()
+{
+       m_number = "";
+       m_numberIsSet = false;
+}
+
+bool ContactPhoneNumber::getNumberIsSet() const
+{
+       return m_numberIsSet;
+}
+
+bool ContactPhoneNumber::getIsDefault() const
+{
+       return m_isDefault;
+}
+
+void ContactPhoneNumber::setIsDefault(const bool &value)
+{
+       m_isDefault = value;
+}
+
+ContactPhoneNumberTypeArrayPtr ContactPhoneNumber::getTypes() const
+{
+       return m_types;
+}
+
+void ContactPhoneNumber::setTypes(const ContactPhoneNumberTypeArrayPtr &value)
+{
+       m_types = value;
+}
+
+void ContactPhoneNumber::addType(const ContactPhoneNumberType value)
+{
+       m_types->push_back(value);
+}
+
+bool ContactPhoneNumber::isTypeOf(const ContactPhoneNumberType value) const
+{
+       return std::find(m_types->begin(), m_types->end(), value) != m_types->end();
+}
+
+int ContactPhoneNumber::getTypesNum() const
+{
+       return m_types->size();
+}
+
+void ContactPhoneNumber::clear()
+{
+       m_number = "";
+       m_numberIsSet = false;
+
+       m_isDefault = false;
+
+       m_types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
+}
+
+ContactPhoneNumberPtr ContactPhoneNumber::clone() const
+{
+       ContactPhoneNumberPtr result(new ContactPhoneNumber());
+
+       result->m_number = m_number;
+       result->m_numberIsSet = m_numberIsSet;
+
+       result->m_isDefault = m_isDefault;
+
+       result->m_types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
+       ContactPhoneNumberTypeArray::iterator typeIter;
+       for(typeIter = m_types->begin(); typeIter != m_types->end(); typeIter++)
+       {
+               ContactPhoneNumberType type = *typeIter;
+               result->m_types->push_back(type);
+       }
+
+       return result;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/ContactPhoneNumber.h b/src/platform/API/Contact/ContactPhoneNumber.h
new file mode 100755 (executable)
index 0000000..c5a3d6e
--- /dev/null
@@ -0,0 +1,84 @@
+//
+// 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        ContactPhoneNumber.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_CONTACT_PHONE_NUMBER_H_
+#define _API_CONTACT_CONTACT_PHONE_NUMBER_H_
+
+#include <algorithm>
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include "ContactTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class ContactPhoneNumber;
+typedef DPL::SharedPtr<ContactPhoneNumber> ContactPhoneNumberPtr;
+
+typedef std::vector<ContactPhoneNumberPtr> ContactPhoneNumberArray;
+typedef DPL::SharedPtr<ContactPhoneNumberArray> ContactPhoneNumberArrayPtr;
+
+typedef std::vector<ContactPhoneNumberType> ContactPhoneNumberTypeArray;
+typedef DPL::SharedPtr<ContactPhoneNumberTypeArray> ContactPhoneNumberTypeArrayPtr;
+
+/* This object represents a phone number data of a contact */
+class ContactPhoneNumber
+{
+public:
+       ContactPhoneNumber();
+       ~ContactPhoneNumber();
+
+       std::string getNumber() const;
+       void setNumber(const std::string &value);
+       void unsetNumber();
+       bool getNumberIsSet() const;
+
+       bool getIsDefault() const;
+       void setIsDefault(const bool &value);
+
+       ContactPhoneNumberTypeArrayPtr getTypes() const;
+       void setTypes(const ContactPhoneNumberTypeArrayPtr &value);
+       void addType(const ContactPhoneNumberType value);
+       bool isTypeOf(const ContactPhoneNumberType value) const;
+       int getTypesNum() const;
+
+       void clear();
+       ContactPhoneNumberPtr clone() const;
+
+private:
+       std::string     m_number;
+       bool            m_numberIsSet;
+
+       bool            m_isDefault;
+
+       ContactPhoneNumberTypeArrayPtr m_types;
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_PHONE_NUMBER_H_
diff --git a/src/platform/API/Contact/ContactRef.cpp b/src/platform/API/Contact/ContactRef.cpp
new file mode 100755 (executable)
index 0000000..a79d037
--- /dev/null
@@ -0,0 +1,113 @@
+//
+// 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        ContactRef.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactRef.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+ContactRef::ContactRef() :
+               m_addressBookIdIsSet(false),
+               m_contactIdIsSet(false)
+{
+}
+
+ContactRef::~ContactRef()
+{
+}
+
+std::string ContactRef::getAddressBookId() const
+{
+       return m_addressBookId;
+}
+
+void ContactRef::setAddressBookId(const std::string value)
+{
+       m_addressBookId = value;
+       m_addressBookIdIsSet = true;
+}
+
+bool ContactRef::getAddressBookIdIsSet() const
+{
+       return m_addressBookIdIsSet;
+}
+
+void ContactRef::setAddressBookId(const int value)
+{
+       std::stringstream oss;
+       oss << value;
+       m_addressBookId = oss.str();
+       m_addressBookIdIsSet = true;
+}
+
+std::string ContactRef::getContactId() const
+{
+       return m_contactId;
+}
+
+void ContactRef::setContactId(const std::string value)
+{
+       m_contactId = value;
+       m_contactIdIsSet = true;
+}
+
+bool ContactRef::getContactIdIsSet() const
+{
+       return m_contactIdIsSet;
+}
+
+void ContactRef::setContactId(const int value)
+{
+       std::stringstream oss;
+       oss << value;
+       m_contactId = oss.str();
+       m_contactIdIsSet = true;
+}
+
+void ContactRef::clear()
+{
+       m_addressBookId = "";
+       m_addressBookIdIsSet = false;
+
+       m_contactId = "";
+       m_contactIdIsSet = false;
+}
+
+ContactRefPtr ContactRef::clone()
+{
+       ContactRefPtr result(new ContactRef());
+
+       result->m_addressBookId = m_addressBookId;
+       result->m_addressBookIdIsSet = m_addressBookIdIsSet;
+
+       result->m_contactId = m_contactId;
+       result->m_contactIdIsSet = m_contactIdIsSet;
+
+       return result;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/ContactRef.h b/src/platform/API/Contact/ContactRef.h
new file mode 100755 (executable)
index 0000000..0702d3e
--- /dev/null
@@ -0,0 +1,75 @@
+//
+// 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        ContactRef.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_CONTACT_REF_H_
+#define _API_CONTACT_CONTACT_REF_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class ContactRef;
+typedef DPL::SharedPtr<ContactRef> ContactRefPtr;
+
+typedef std::vector<ContactRefPtr> ContactRefArray;
+typedef DPL::SharedPtr<ContactRefArray> ContactRefArrayPtr;
+
+class ContactRef
+{
+public:
+       ContactRef();
+       virtual ~ContactRef();
+
+       std::string getAddressBookId() const;
+       void setAddressBookId(const std::string value);
+       void setAddressBookId(const int value);
+       bool getAddressBookIdIsSet() const;
+
+       std::string getContactId() const;
+       void setContactId(const std::string value);
+       void setContactId(const int value);
+       bool getContactIdIsSet() const;
+
+       virtual void clear();
+       virtual ContactRefPtr clone();
+
+protected:
+       std::string     m_addressBookId;
+       bool            m_addressBookIdIsSet;
+
+       std::string     m_contactId;
+       bool            m_contactIdIsSet;
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_REF_H_
diff --git a/src/platform/API/Contact/ContactTypes.h b/src/platform/API/Contact/ContactTypes.h
new file mode 100755 (executable)
index 0000000..0be18c9
--- /dev/null
@@ -0,0 +1,93 @@
+//
+// 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       ContactTypes.h
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_CONTACT_TYPES_H_
+#define _API_CONTACT_CONTACT_TYPES_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+typedef std::vector<std::string> StringArray;
+typedef DPL::SharedPtr<StringArray> StringArrayPtr;
+
+//typedef std::vector<std::string> AttributesOfInterestArray;
+//typedef DPL::SharedPtr<AttributesOfInterestArray> AttributesOfInterestArrayPtr;
+
+enum ContactEmailAddressType
+{
+       CONTACT_EMAIL_TYPE_NULL ,
+       CONTACT_EMAIL_TYPE_WORK ,
+       CONTACT_EMAIL_TYPE_PREF ,
+       CONTACT_EMAIL_TYPE_HOME
+};
+
+enum ContactPhoneNumberType
+{
+       CONTACT_PHONE_NUMBER_TYPE_NULL,
+       CONTACT_PHONE_NUMBER_TYPE_WORK,
+       CONTACT_PHONE_NUMBER_TYPE_PREF,
+       CONTACT_PHONE_NUMBER_TYPE_HOME,
+       CONTACT_PHONE_NUMBER_TYPE_VOICE,
+       CONTACT_PHONE_NUMBER_TYPE_FAX,
+       CONTACT_PHONE_NUMBER_TYPE_MSG,
+       CONTACT_PHONE_NUMBER_TYPE_CELL,
+       CONTACT_PHONE_NUMBER_TYPE_PAGER,
+       CONTACT_PHONE_NUMBER_TYPE_BBS,
+       CONTACT_PHONE_NUMBER_TYPE_MODEM,
+       CONTACT_PHONE_NUMBER_TYPE_CAR,
+       CONTACT_PHONE_NUMBER_TYPE_ISDN,
+       CONTACT_PHONE_NUMBER_TYPE_VIDEO,
+       CONTACT_PHONE_NUMBER_TYPE_PCS
+};
+
+enum ContactAddressType
+{
+       CONTACT_ADDRESS_TYPE_NULL,
+       CONTACT_ADDRESS_TYPE_WORK,
+       CONTACT_ADDRESS_TYPE_PREF,
+       CONTACT_ADDRESS_TYPE_HOME
+};
+
+enum ContactWebSiteType
+{
+       WEBSITE_TYPE_NULL,
+       WEBSITE_TYPE_HOMEPAGE,
+       WEBSITE_TYPE_BLOG
+};
+
+enum ContactVCardFormat
+{
+       VCARD_30_FORMAT
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_TYPES_H_
+
diff --git a/src/platform/API/Contact/ContactWebSite.cpp b/src/platform/API/Contact/ContactWebSite.cpp
new file mode 100755 (executable)
index 0000000..59ff120
--- /dev/null
@@ -0,0 +1,109 @@
+//
+// 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        ContactWebSite.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactWebSite.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+ContactWebSite::ContactWebSite() :
+               m_urlIsSet(false),
+               m_typeIsSet(false)
+{
+}
+
+ContactWebSite::~ContactWebSite()
+{
+}
+
+std::string ContactWebSite::getUrl() const
+{
+       return m_url;
+}
+
+void ContactWebSite::setUrl(const std::string &value)
+{
+       m_url = value;
+       m_urlIsSet = true;
+}
+
+void ContactWebSite::unsetUrl()
+{
+       m_url = "";
+       m_urlIsSet = false;
+}
+
+bool ContactWebSite::getUrlIsSet() const
+{
+       return m_urlIsSet;
+}
+
+ContactWebSiteType ContactWebSite::getType() const
+{
+       return m_type;
+}
+
+void ContactWebSite::setType(const ContactWebSiteType value)
+{
+       m_type = value;
+       m_typeIsSet = true;
+}
+
+void ContactWebSite::unsetType()
+{
+       m_type = WEBSITE_TYPE_HOMEPAGE;
+       m_typeIsSet = false;
+}
+
+bool ContactWebSite::getTypeIsSet() const
+{
+       return m_typeIsSet;
+}
+
+void ContactWebSite::clear()
+{
+       m_url = "";
+       m_urlIsSet = false;
+
+       m_type = WEBSITE_TYPE_HOMEPAGE;
+       m_typeIsSet = false;
+}
+
+ContactWebSitePtr ContactWebSite::clone() const
+{
+       ContactWebSitePtr result(new ContactWebSite());
+
+       result->m_url = m_url;
+       result->m_urlIsSet = m_urlIsSet;
+
+       result->m_type = m_type;
+       result->m_typeIsSet = m_typeIsSet;
+
+       return result;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/ContactWebSite.h b/src/platform/API/Contact/ContactWebSite.h
new file mode 100755 (executable)
index 0000000..2bda48a
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// 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        ContactWebSite.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_CONTACT_WEB_SITE_H_
+#define _API_CONTACT_CONTACT_WEB_SITE_H_
+
+#include <vector>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "ContactTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class ContactWebSite;
+typedef DPL::SharedPtr<ContactWebSite> ContactWebSitePtr;
+
+typedef std::vector<ContactWebSitePtr> ContactWebSiteArray;
+typedef DPL::SharedPtr<ContactWebSiteArray> ContactWebSiteArrayPtr;
+
+class ContactWebSite
+{
+public:
+       ContactWebSite();
+       ~ContactWebSite();
+
+       std::string getUrl() const;
+       void setUrl(const std::string &value);
+       void unsetUrl();
+       bool getUrlIsSet() const;
+
+       ContactWebSiteType getType() const;
+       void setType(const ContactWebSiteType value);
+       void unsetType();
+       bool getTypeIsSet() const;
+
+       void clear();
+       ContactWebSitePtr clone() const;
+
+private:
+       std::string         m_url;
+       bool            m_urlIsSet;
+
+       ContactWebSiteType          m_type;
+       bool            m_typeIsSet;
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_WEB_SITE_H_
diff --git a/src/platform/API/Contact/EventAddressBookAdd.h b/src/platform/API/Contact/EventAddressBookAdd.h
new file mode 100755 (executable)
index 0000000..9ad3ec6
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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        EventAddressBookAdd.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookAdd : public WrtDeviceApis::Commons::IEvent<EventAddressBookAdd>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       ContactPtr      m_contact;
+
+       bool m_contactIsSet;
+
+public:
+       EventAddressBookAdd() :
+               m_result(false),
+               m_contactIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookAdd()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       ContactPtr getContact() const
+       {
+               return m_contact;
+       }
+
+       void setContact(const ContactPtr &value)
+       {
+               m_contact = value;
+               m_contactIsSet = true;
+       }
+
+       bool getContactIsSet() const
+       {
+               return m_contactIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookAdd> EventAddressBookAddPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_H_
+
diff --git a/src/platform/API/Contact/EventAddressBookAddBatch.h b/src/platform/API/Contact/EventAddressBookAddBatch.h
new file mode 100755 (executable)
index 0000000..d1043eb
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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        EventAddressBookAddBatch.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_BATCH_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_BATCH_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookAddBatch : public WrtDeviceApis::Commons::IEvent<EventAddressBookAddBatch>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       ContactArrayPtr m_contacts;
+
+       bool m_contactsIsSet;
+
+public:
+       EventAddressBookAddBatch() :
+               m_result(false),
+               m_contactsIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookAddBatch()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       ContactArrayPtr getContacts() const
+       {
+               return m_contacts;
+       }
+
+       void setContacts(const ContactArrayPtr &value)
+       {
+               m_contacts = value;
+               m_contactsIsSet = true;
+       }
+
+       bool getContactsIsSet() const
+       {
+               return m_contactsIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookAddBatch> EventAddressBookAddBatchPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_BATCH_H_
+
diff --git a/src/platform/API/Contact/EventAddressBookAddChangeListener.h b/src/platform/API/Contact/EventAddressBookAddChangeListener.h
new file mode 100755 (executable)
index 0000000..78d8c87
--- /dev/null
@@ -0,0 +1,119 @@
+//
+// 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        EventAddressBookAddChangeListener.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_CHANGE_LISTENER_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_CHANGE_LISTENER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "EventAddressBookChangeListener.h"
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookAddChangeListener : public WrtDeviceApis::Commons::IEvent<EventAddressBookAddChangeListener>
+{
+private:
+       bool m_result;
+
+       /* result */
+       long m_id;
+
+       bool m_idIsSet;
+
+       /* parameters */
+       EventAddressBookChangeListenerEmitterPtr m_emitter;
+
+       bool m_emitterIsSet;
+
+public:
+       EventAddressBookAddChangeListener() :
+               m_result(false),
+               m_id(0),
+               m_idIsSet(false),
+               m_emitterIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookAddChangeListener()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       void setEmitter(EventAddressBookChangeListenerEmitterPtr &value)
+       {
+               m_emitter = value;
+               m_emitterIsSet = true;
+       }
+
+       EventAddressBookChangeListenerEmitterPtr getEmitter() const
+       {
+               return m_emitter;
+       }
+
+       bool getEmitterIsSet() const
+       {
+               return m_emitterIsSet;
+       }
+
+       long getId() const
+       {
+               return m_id;
+       }
+
+       void setId(const long value)
+       {
+               m_id = value;
+               m_idIsSet = true;
+       }
+
+       bool getIdIsSet() const
+       {
+               return m_idIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookAddChangeListener> EventAddressBookAddChangeListenerPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_CHANGE_LISTENER_H_
diff --git a/src/platform/API/Contact/EventAddressBookAddGroup.h b/src/platform/API/Contact/EventAddressBookAddGroup.h
new file mode 100755 (executable)
index 0000000..3dcfe1d
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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        EventAddressBookAddGroup.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_GROUP_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_GROUP_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "ContactGroup.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookAddGroup : public WrtDeviceApis::Commons::IEvent<EventAddressBookAddGroup>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       ContactGroupPtr m_contactGroup;
+
+       bool m_contactGroupIsSet;
+
+public:
+       EventAddressBookAddGroup() :
+               m_result(false),
+               m_contactGroup(NULL),
+               m_contactGroupIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookAddGroup()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       ContactGroupPtr getContactGroup() const
+       {
+               return m_contactGroup;
+       }
+
+       void setContactGroup(const ContactGroupPtr &value)
+       {
+               m_contactGroup = value;
+               m_contactGroupIsSet = true;
+       }
+
+       bool getContactGroupIsSet() const
+       {
+               return m_contactGroupIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookAddGroup> EventAddressBookAddGroupPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_ADD_GROUP_H_
+
diff --git a/src/platform/API/Contact/EventAddressBookChangeListener.h b/src/platform/API/Contact/EventAddressBookChangeListener.h
new file mode 100755 (executable)
index 0000000..8af8fcf
--- /dev/null
@@ -0,0 +1,251 @@
+//
+// 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        EventAddressBookChangeListener.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ * ##
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_CHANGE_LISTENER_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_CHANGE_LISTENER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventInfoAddressBookChange;
+typedef DPL::SharedPtr<EventInfoAddressBookChange> EventInfoAddressBookChangePtr;
+
+class EventAddressBookChangeListener : public WrtDeviceApis::Commons::ListenerEvent<EventAddressBookChangeListener>
+{
+private:
+       EventInfoAddressBookChangePtr m_eventInfo;
+
+public:
+       EventAddressBookChangeListener(EventInfoAddressBookChangePtr &eventInfo) : m_eventInfo(eventInfo)
+       {
+       }
+
+       EventInfoAddressBookChangePtr getEventInfo() const { return m_eventInfo; }
+};
+typedef DPL::SharedPtr<EventAddressBookChangeListener> EventAddressBookChangeListenerPtr;
+
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventAddressBookChangeListener> EventAddressBookChangeListenerEmitter;
+typedef DPL::SharedPtr<EventAddressBookChangeListenerEmitter> EventAddressBookChangeListenerEmitterPtr;
+
+class EventInfoAddressBookChange
+{
+private:
+
+public:
+       EventInfoAddressBookChange()
+       {
+       }
+
+       virtual ~EventInfoAddressBookChange()
+       {
+       }
+
+       enum CallbackType
+       {
+               OnContactsAdded,
+               OnContactsUpdated,
+               OnContactsRemoved,
+               OnAddressBookReset,
+               OnError
+       };
+
+       virtual CallbackType getCallbackType() const = 0;
+};
+
+class EventInfoAddressBookChangeAdded : public EventInfoAddressBookChange
+{
+private:
+       /* results */
+       ContactArrayPtr         m_contacts;
+
+       bool            m_contactsIsSet;
+
+public:
+       EventInfoAddressBookChangeAdded() : m_contactsIsSet(false)
+       {
+       }
+
+       virtual ~EventInfoAddressBookChangeAdded()
+       {
+       }
+
+       virtual CallbackType getCallbackType() const
+       {
+               return OnContactsAdded;
+       }
+
+    ContactArrayPtr getContacts() const
+    {
+        return m_contacts;
+    }
+
+    void setContacts(ContactArrayPtr contacts)
+    {
+       m_contactsIsSet = true;
+        m_contacts = contacts;
+    }
+
+    bool getContactsIsSet() const
+    {
+       return m_contactsIsSet;
+    }
+};
+typedef DPL::SharedPtr<EventInfoAddressBookChangeAdded> EventInfoAddressBookChangeAddedPtr;
+
+class EventInfoAddressBookChangeUpdated : public EventInfoAddressBookChange
+{
+private:
+       /* results */
+       ContactArrayPtr         m_contacts;
+
+       bool            m_contactsIsSet;
+
+public:
+       EventInfoAddressBookChangeUpdated() : m_contactsIsSet(false)
+       {
+       }
+
+       virtual ~EventInfoAddressBookChangeUpdated()
+       {
+       }
+
+       virtual CallbackType getCallbackType() const
+       {
+               return OnContactsUpdated;
+       }
+
+    ContactArrayPtr getContacts() const
+    {
+        return m_contacts;
+    }
+
+    void setContacts(ContactArrayPtr contacts)
+    {
+       m_contactsIsSet = true;
+        m_contacts = contacts;
+    }
+
+    bool getContactsIsSet() const
+    {
+       return m_contactsIsSet;
+    }
+};
+typedef DPL::SharedPtr<EventInfoAddressBookChangeUpdated> EventInfoAddressBookChangeUpdatedPtr;
+
+class EventInfoAddressBookChangeRemoved : public EventInfoAddressBookChange
+{
+private:
+       /* results */
+       StringArrayPtr          m_contactIds;
+
+       bool    m_contactIdsIsSet;
+
+public:
+       EventInfoAddressBookChangeRemoved() : m_contactIdsIsSet(false)
+       {
+       }
+
+       virtual ~EventInfoAddressBookChangeRemoved()
+       {
+       }
+
+       virtual CallbackType getCallbackType() const
+       {
+               return OnContactsRemoved;
+       }
+
+       StringArrayPtr getContactIds() const
+    {
+        return m_contactIds;
+    }
+
+    void setContactIds(StringArrayPtr contactIds)
+    {
+       m_contactIdsIsSet = true;
+       m_contactIds = contactIds;
+    }
+
+    bool getContactIdsIsSet() const
+    {
+       return m_contactIdsIsSet;
+    }
+};
+typedef DPL::SharedPtr<EventInfoAddressBookChangeRemoved> EventInfoAddressBookChangeRemovedPtr;
+
+class EventInfoAddressBookChangeReset : public EventInfoAddressBookChange
+{
+private:
+       /* results */
+
+public:
+       EventInfoAddressBookChangeReset()
+       {
+       }
+
+       virtual ~EventInfoAddressBookChangeReset()
+       {
+       }
+
+       virtual CallbackType getCallbackType() const
+       {
+               return OnAddressBookReset;
+       }
+};
+typedef DPL::SharedPtr<EventInfoAddressBookChangeReset> EventInfoAddressBookChangeResetPtr;
+
+class EventInfoAddressBookChangeError : public EventInfoAddressBookChange
+{
+private:
+       /* results */
+
+public:
+       EventInfoAddressBookChangeError()
+       {
+       }
+
+       virtual ~EventInfoAddressBookChangeError()
+       {
+       }
+
+       virtual CallbackType getCallbackType() const
+       {
+               return OnError;
+       }
+};
+typedef DPL::SharedPtr<EventInfoAddressBookChangeError> EventInfoAddressBookChangeErrorPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_CHANGE_LISTENER_H_
diff --git a/src/platform/API/Contact/EventAddressBookFind.h b/src/platform/API/Contact/EventAddressBookFind.h
new file mode 100755 (executable)
index 0000000..331930b
--- /dev/null
@@ -0,0 +1,139 @@
+//
+// 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        EventAddressBookFind.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_FIND_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_FIND_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <API/Filter/IFilter.h>
+#include <API/Filter/SortMode.h>
+#include "ContactTypes.h"
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+/* Event sent while searching contacts */
+class EventAddressBookFind : public WrtDeviceApis::Commons::IEvent<EventAddressBookFind>
+{
+private:
+       bool    m_result;
+
+       /* parameters */
+       Tizen::FilterPtr        m_filter;
+       Tizen::SortModePtr      m_sortMode;
+
+       bool    m_filterIsSet;
+       bool    m_sortModeIsSet;
+
+       /* results */
+       ContactArrayPtr         m_contacts;
+
+       bool    m_contactsIsSet;
+
+public:
+       EventAddressBookFind() :
+               m_result(false),
+               m_filterIsSet(false),
+               m_sortModeIsSet(false),
+               m_contactsIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookFind()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       Tizen::FilterPtr getFilter() const
+       {
+               return m_filter;
+       }
+
+       void setFilter(const Tizen::FilterPtr &value)
+       {
+               m_filter = value;
+               m_filterIsSet = true;
+       }
+
+       bool getFilterIsSet() const
+       {
+               return m_filterIsSet;
+       }
+
+       Tizen::SortModePtr getSortMode() const
+       {
+               return m_sortMode;
+       }
+
+       void setSortMode(const Tizen::SortModePtr &value)
+       {
+               m_sortMode = value;
+               m_sortModeIsSet = true;
+       }
+
+       bool getSortModeIsSet() const
+       {
+               return m_sortModeIsSet;
+       }
+
+       ContactArrayPtr getContacts() const
+       {
+               return m_contacts;
+       }
+
+       void setContacts(const ContactArrayPtr &value)
+       {
+               m_contacts = value;
+               m_contactsIsSet = true;
+       }
+
+       bool getContactsIsSet() const
+       {
+               return m_contactsIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookFind> EventAddressBookFindPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_FIND_H_
diff --git a/src/platform/API/Contact/EventAddressBookGet.h b/src/platform/API/Contact/EventAddressBookGet.h
new file mode 100755 (executable)
index 0000000..51fbb87
--- /dev/null
@@ -0,0 +1,118 @@
+//
+// 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        EventAddressBookGet.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_GET_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_GET_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookGet : public WrtDeviceApis::Commons::IEvent<EventAddressBookGet>
+{
+private:
+       bool m_result;
+
+       /* result */
+       ContactPtr m_contact;
+
+       bool m_contactIsSet;
+
+       /* parameters */
+       std::string     m_id;
+
+       bool m_idIsSet;
+
+public:
+       EventAddressBookGet() :
+               m_result(false),
+               m_contact(NULL),
+               m_contactIsSet(false),
+               m_idIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookGet()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       std::string getId() const
+       {
+               return m_id;
+       }
+
+       void setId(const std::string value)
+       {
+               m_id = value;
+               m_idIsSet = true;
+       }
+
+       bool getIdIsSet() const
+       {
+               return m_idIsSet;
+       }
+
+       void setContact(ContactPtr &value)
+       {
+               m_contact = value;
+               m_contactIsSet = true;
+       }
+
+       ContactPtr getContact() const
+       {
+               return m_contact;
+       }
+
+       bool getContactIsSet() const
+       {
+               return m_contactIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookGet> EventAddressBookGetPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_GET_H_
diff --git a/src/platform/API/Contact/EventAddressBookGetGroup.h b/src/platform/API/Contact/EventAddressBookGetGroup.h
new file mode 100755 (executable)
index 0000000..08fd9b7
--- /dev/null
@@ -0,0 +1,118 @@
+//
+// 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        EventAddressBookGetGroup.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_GET_GROUP_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_GET_GROUP_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "ContactGroup.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookGetGroup : public WrtDeviceApis::Commons::IEvent<EventAddressBookGetGroup>
+{
+private:
+       bool m_result;
+
+       /* result */
+       ContactGroupPtr m_contactGroup;
+
+       bool m_contactGroupIsSet;
+
+       /* parameters */
+       std::string     m_id;
+
+       bool m_idIsSet;
+
+public:
+       EventAddressBookGetGroup() :
+               m_result(false),
+               m_contactGroup(NULL),
+               m_contactGroupIsSet(false),
+               m_idIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookGetGroup()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       std::string getId() const
+       {
+               return m_id;
+       }
+
+       void setId(const std::string value)
+       {
+               m_id = value;
+               m_idIsSet = true;
+       }
+
+       bool getIdIsSet() const
+       {
+               return m_idIsSet;
+       }
+
+       void setContactGroup(ContactGroupPtr &value)
+       {
+               m_contactGroup = value;
+               m_contactGroupIsSet = true;
+       }
+
+       ContactGroupPtr getContactGroup() const
+       {
+               return m_contactGroup;
+       }
+
+       bool getContactGroupIsSet() const
+       {
+               return m_contactGroupIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookGetGroup> EventAddressBookGetGroupPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_GET_GROUP_H_
diff --git a/src/platform/API/Contact/EventAddressBookGetGroups.h b/src/platform/API/Contact/EventAddressBookGetGroups.h
new file mode 100755 (executable)
index 0000000..abc03c8
--- /dev/null
@@ -0,0 +1,97 @@
+//
+// 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        EventAddressBookGetGroups.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_GET_GROUPS_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_GET_GROUPS_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "ContactGroup.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookGetGroups : public WrtDeviceApis::Commons::IEvent<EventAddressBookGetGroups>
+{
+private:
+       bool m_result;
+
+       /* result */
+       ContactGroupArrayPtr m_contactGroups;
+
+       bool m_contactGroupsIsSet;
+
+       /* parameters */
+
+public:
+       EventAddressBookGetGroups() :
+               m_result(false),
+               m_contactGroupsIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookGetGroups()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       void setContactGroups(ContactGroupArrayPtr &value)
+       {
+               m_contactGroups = value;
+               m_contactGroupsIsSet = true;
+       }
+
+       ContactGroupArrayPtr getContactGroups() const
+       {
+               return m_contactGroups;
+       }
+
+       bool getContactGroupsIsSet() const
+       {
+               return m_contactGroupsIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookGetGroups> EventAddressBookGetGroupsPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_GET_GROUPS_H_
diff --git a/src/platform/API/Contact/EventAddressBookRemove.h b/src/platform/API/Contact/EventAddressBookRemove.h
new file mode 100755 (executable)
index 0000000..4aa2af5
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// 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        EventAddressBookRemove.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookRemove : public WrtDeviceApis::Commons::IEvent<EventAddressBookRemove>
+{
+private:
+       bool    m_result;
+
+       /* parameters */
+       std::string     m_contactId;
+
+       bool    m_contactIdIsSet;
+
+public:
+       EventAddressBookRemove() :
+               m_result(false),
+               m_contactIdIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookRemove()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       std::string getContactId() const
+       {
+               return m_contactId;
+       }
+
+       void setContactId(const std::string value)
+       {
+               m_contactIdIsSet = true;
+               m_contactId = value;
+       }
+
+       bool getContactIdIsSet() const
+       {
+               return m_contactIdIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookRemove> EventAddressBookRemovePtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_H_
+
diff --git a/src/platform/API/Contact/EventAddressBookRemoveBatch.h b/src/platform/API/Contact/EventAddressBookRemoveBatch.h
new file mode 100755 (executable)
index 0000000..9036e04
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// 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        EventAddressBookRemoveBatch.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_BATCH_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_BATCH_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookRemoveBatch : public WrtDeviceApis::Commons::IEvent<EventAddressBookRemoveBatch>
+{
+private:
+       bool    m_result;
+
+       /* parameters */
+       StringArrayPtr  m_contactIds;
+
+       bool    m_contactIdsIsSet;
+
+public:
+       EventAddressBookRemoveBatch() :
+               m_result(false),
+               m_contactIdsIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookRemoveBatch()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       StringArrayPtr getContactIds() const
+       {
+               return m_contactIds;
+       }
+
+       void setContactIds(const StringArrayPtr &value)
+       {
+               m_contactIdsIsSet = true;
+               m_contactIds = value;
+       }
+
+       bool getContactIdsIsSet() const
+       {
+               return m_contactIdsIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookRemoveBatch> EventAddressBookRemoveBatchPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_BATCH_H_
+
diff --git a/src/platform/API/Contact/EventAddressBookRemoveChangeListener.h b/src/platform/API/Contact/EventAddressBookRemoveChangeListener.h
new file mode 100755 (executable)
index 0000000..9135be2
--- /dev/null
@@ -0,0 +1,98 @@
+//
+// 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        EventAddressBookRemoveChangeListener.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_CHANGE_LISTENER_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_CHANGE_LISTENER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookRemoveChangeListener : public WrtDeviceApis::Commons::IEvent<EventAddressBookRemoveChangeListener>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+
+       /* result */
+       long m_id;
+
+       bool m_idIsSet;
+
+public:
+       EventAddressBookRemoveChangeListener() :
+               m_result(false),
+               m_id(0),
+               m_idIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookRemoveChangeListener()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       long getId() const
+       {
+               return m_id;
+       }
+
+       void setId(const long value)
+       {
+               m_id = value;
+               m_idIsSet = true;
+       }
+
+       bool getIdIsSet() const
+       {
+               return m_idIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookRemoveChangeListener> EventAddressBookRemoveChangeListenerPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_CHANGE_LISTENER_H_
diff --git a/src/platform/API/Contact/EventAddressBookRemoveGroup.h b/src/platform/API/Contact/EventAddressBookRemoveGroup.h
new file mode 100755 (executable)
index 0000000..23d0875
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// 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        EventAddressBookRemoveGroup.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_GROUP_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_GROUP_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookRemoveGroup : public WrtDeviceApis::Commons::IEvent<EventAddressBookRemoveGroup>
+{
+private:
+       bool    m_result;
+
+       /* parameters */
+       std::string     m_contactGroupId;
+
+       bool    m_contactGroupIdIsSet;
+
+public:
+       EventAddressBookRemoveGroup() :
+               m_result(false),
+               m_contactGroupIdIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookRemoveGroup()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       std::string getContactGroupId() const
+       {
+               return m_contactGroupId;
+       }
+
+       void setContactGroupId(const std::string value)
+       {
+               m_contactGroupIdIsSet = true;
+               m_contactGroupId = value;
+       }
+
+       bool getContactGroupIdIsSet() const
+       {
+               return m_contactGroupIdIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookRemoveGroup> EventAddressBookRemoveGroupPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_REMOVE_GROUP_H_
+
diff --git a/src/platform/API/Contact/EventAddressBookUpdate.h b/src/platform/API/Contact/EventAddressBookUpdate.h
new file mode 100755 (executable)
index 0000000..0b72e1f
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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        EventAddressBookUpdate.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_UPDATE_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_UPDATE_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookUpdate : public WrtDeviceApis::Commons::IEvent<EventAddressBookUpdate>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       ContactPtr      m_contact;
+
+       bool m_contactIsSet;
+
+public:
+       EventAddressBookUpdate() :
+               m_result(false),
+               m_contactIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookUpdate()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       ContactPtr getContact() const
+       {
+               return m_contact;
+       }
+
+       void setContact(const ContactPtr &value)
+       {
+               m_contact = value;
+               m_contactIsSet = true;
+       }
+
+       bool getContactIsSet() const
+       {
+               return m_contactIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookUpdate> EventAddressBookUpdatePtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_UPDATE_H_
+
diff --git a/src/platform/API/Contact/EventAddressBookUpdateBatch.h b/src/platform/API/Contact/EventAddressBookUpdateBatch.h
new file mode 100755 (executable)
index 0000000..325a893
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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        EventAddressBookUpdateBatch.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_UPDATE_BATCH_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_UPDATE_BATCH_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookUpdateBatch : public WrtDeviceApis::Commons::IEvent<EventAddressBookUpdateBatch>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       ContactArrayPtr m_contacts;
+
+       bool m_contactsIsSet;
+
+public:
+       EventAddressBookUpdateBatch() :
+               m_result(false),
+               m_contactsIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookUpdateBatch()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       ContactArrayPtr getContacts() const
+       {
+               return m_contacts;
+       }
+
+       void setContacts(const ContactArrayPtr &value)
+       {
+               m_contacts = value;
+               m_contactsIsSet = true;
+       }
+
+       bool getContactsIsSet() const
+       {
+               return m_contactsIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookUpdateBatch> EventAddressBookUpdateBatchPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_UPDATE_BATCH_H_
+
diff --git a/src/platform/API/Contact/EventAddressBookUpdateGroup.h b/src/platform/API/Contact/EventAddressBookUpdateGroup.h
new file mode 100755 (executable)
index 0000000..2c843ce
--- /dev/null
@@ -0,0 +1,97 @@
+//
+// 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        EventAddressBookUpdateGroup.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_UPDATE_GROUP_H_
+#define _API_CONTACT_EVENT_ADDRESS_BOOK_UPDATE_GROUP_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "ContactGroup.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventAddressBookUpdateGroup : public WrtDeviceApis::Commons::IEvent<EventAddressBookUpdateGroup>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       ContactGroupPtr m_contactGroup;
+
+       bool m_contactGroupIsSet;
+
+public:
+       EventAddressBookUpdateGroup() :
+               m_result(false),
+               m_contactGroup(NULL),
+               m_contactGroupIsSet(false)
+       {
+       }
+
+       virtual ~EventAddressBookUpdateGroup()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       ContactGroupPtr getContactGroup() const
+       {
+               return m_contactGroup;
+       }
+
+       void setContactGroup(const ContactGroupPtr &value)
+       {
+               m_contactGroup = value;
+               m_contactGroupIsSet = true;
+       }
+
+       bool getContactGroupIsSet() const
+       {
+               return m_contactGroupIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventAddressBookUpdateGroup> EventAddressBookUpdateGroupPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_ADDRESS_BOOK_UPDATE_GROUP_H_
+
diff --git a/src/platform/API/Contact/EventContactManagerAddChangeListener.h b/src/platform/API/Contact/EventContactManagerAddChangeListener.h
new file mode 100755 (executable)
index 0000000..0d082f2
--- /dev/null
@@ -0,0 +1,119 @@
+//
+// 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        EventContactManagerAddChangeListener.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_ADD_CHANGE_LISTENER_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_ADD_CHANGE_LISTENER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "EventContactManagerChangeListener.h"
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventContactManagerAddChangeListener : public WrtDeviceApis::Commons::IEvent<EventContactManagerAddChangeListener>
+{
+private:
+       bool m_result;
+
+       /* result */
+       long m_id;
+
+       bool m_idIsSet;
+
+       /* parameters */
+       EventContactManagerChangeListenerEmitterPtr m_emitter;
+
+       bool m_emitterIsSet;
+
+public:
+       EventContactManagerAddChangeListener() :
+               m_result(false),
+               m_id(0),
+               m_idIsSet(false),
+               m_emitterIsSet(false)
+       {
+       }
+
+       virtual ~EventContactManagerAddChangeListener()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       void setEmitter(EventContactManagerChangeListenerEmitterPtr &value)
+       {
+               m_emitter = value;
+               m_emitterIsSet = true;
+       }
+
+       EventContactManagerChangeListenerEmitterPtr getEmitter() const
+       {
+               return m_emitter;
+       }
+
+       bool getEmitterIsSet() const
+       {
+               return m_emitterIsSet;
+       }
+
+       long getId() const
+       {
+               return m_id;
+       }
+
+       void setId(const long value)
+       {
+               m_id = value;
+               m_idIsSet = true;
+       }
+
+       bool getIdIsSet() const
+       {
+               return m_idIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventContactManagerAddChangeListener> EventContactManagerAddChangeListenerPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_ADD_CHANGE_LISTENER_H_
diff --git a/src/platform/API/Contact/EventContactManagerChangeListener.h b/src/platform/API/Contact/EventContactManagerChangeListener.h
new file mode 100755 (executable)
index 0000000..e713f03
--- /dev/null
@@ -0,0 +1,229 @@
+//
+// 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        EventContactManagerChangeListener.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ * ##
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_CHANGE_LISTENER_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_CHANGE_LISTENER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "IPerson.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventInfoContactManagerChange;
+typedef DPL::SharedPtr<EventInfoContactManagerChange> EventInfoContactManagerChangePtr;
+
+class EventContactManagerChangeListener : public WrtDeviceApis::Commons::ListenerEvent<EventContactManagerChangeListener>
+{
+private:
+       EventInfoContactManagerChangePtr m_eventInfo;
+
+public:
+       EventContactManagerChangeListener(EventInfoContactManagerChangePtr &eventInfo) : m_eventInfo(eventInfo)
+       {
+       }
+
+       EventInfoContactManagerChangePtr getEventInfo() const { return m_eventInfo; }
+};
+typedef DPL::SharedPtr<EventContactManagerChangeListener> EventContactManagerChangeListenerPtr;
+
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventContactManagerChangeListener> EventContactManagerChangeListenerEmitter;
+typedef DPL::SharedPtr<EventContactManagerChangeListenerEmitter> EventContactManagerChangeListenerEmitterPtr;
+
+class EventInfoContactManagerChange
+{
+private:
+
+public:
+       EventInfoContactManagerChange()
+       {
+       }
+
+       virtual ~EventInfoContactManagerChange()
+       {
+       }
+
+       enum CallbackType
+       {
+               OnPersonsAdded,
+               OnPersonsUpdated,
+               OnPersonsRemoved,
+               OnError
+       };
+
+       virtual CallbackType getCallbackType() const = 0;
+};
+
+class EventInfoContactManagerChangeAdded : public EventInfoContactManagerChange
+{
+private:
+       /* results */
+       PersonArrayPtr          m_persons;
+
+       bool            m_personsIsSet;
+
+public:
+       EventInfoContactManagerChangeAdded() : m_personsIsSet(false)
+       {
+       }
+
+       virtual ~EventInfoContactManagerChangeAdded()
+       {
+       }
+
+       virtual CallbackType getCallbackType() const
+       {
+               return OnPersonsAdded;
+       }
+
+    PersonArrayPtr getPersons() const
+    {
+        return m_persons;
+    }
+
+    void setPersons(PersonArrayPtr persons)
+    {
+       m_personsIsSet = true;
+        m_persons = persons;
+    }
+
+    bool getPersonsIsSet() const
+    {
+       return m_personsIsSet;
+    }
+};
+typedef DPL::SharedPtr<EventInfoContactManagerChangeAdded> EventInfoContactManagerChangeAddedPtr;
+
+class EventInfoContactManagerChangeUpdated : public EventInfoContactManagerChange
+{
+private:
+       /* results */
+       PersonArrayPtr          m_persons;
+
+       bool            m_personsIsSet;
+
+public:
+       EventInfoContactManagerChangeUpdated() : m_personsIsSet(false)
+       {
+       }
+
+       virtual ~EventInfoContactManagerChangeUpdated()
+       {
+       }
+
+       virtual CallbackType getCallbackType() const
+       {
+               return OnPersonsUpdated;
+       }
+
+    PersonArrayPtr getPersons() const
+    {
+        return m_persons;
+    }
+
+    void setPersons(PersonArrayPtr persons)
+    {
+       m_personsIsSet = true;
+        m_persons = persons;
+    }
+
+    bool getPersonsIsSet() const
+    {
+       return m_personsIsSet;
+    }
+};
+typedef DPL::SharedPtr<EventInfoContactManagerChangeUpdated> EventInfoContactManagerChangeUpdatedPtr;
+
+class EventInfoContactManagerChangeRemoved : public EventInfoContactManagerChange
+{
+private:
+       /* results */
+       StringArrayPtr          m_personIds;
+
+       bool    m_personIdsIsSet;
+
+public:
+       EventInfoContactManagerChangeRemoved() : m_personIdsIsSet(false)
+       {
+       }
+
+       virtual ~EventInfoContactManagerChangeRemoved()
+       {
+       }
+
+       virtual CallbackType getCallbackType() const
+       {
+               return OnPersonsRemoved;
+       }
+
+       StringArrayPtr getPersonIds() const
+    {
+        return m_personIds;
+    }
+
+    void setPersonIds(StringArrayPtr personIds)
+    {
+       m_personIdsIsSet = true;
+       m_personIds = personIds;
+    }
+
+    bool getPersonIdsIsSet() const
+    {
+       return m_personIdsIsSet;
+    }
+};
+typedef DPL::SharedPtr<EventInfoContactManagerChangeRemoved> EventInfoContactManagerChangeRemovedPtr;
+
+class EventInfoContactManagerChangeError : public EventInfoContactManagerChange
+{
+private:
+       /* results */
+
+public:
+       EventInfoContactManagerChangeError()
+       {
+       }
+
+       virtual ~EventInfoContactManagerChangeError()
+       {
+       }
+
+       virtual CallbackType getCallbackType() const
+       {
+               return OnError;
+       }
+};
+typedef DPL::SharedPtr<EventInfoContactManagerChangeError> EventInfoContactManagerChangeErrorPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_CHANGE_LISTENER_H_
diff --git a/src/platform/API/Contact/EventContactManagerFind.h b/src/platform/API/Contact/EventContactManagerFind.h
new file mode 100755 (executable)
index 0000000..cefb11c
--- /dev/null
@@ -0,0 +1,139 @@
+//
+// 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        EventContactManagerFind.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_FIND_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_FIND_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <API/Filter/IFilter.h>
+#include <API/Filter/SortMode.h>
+#include "ContactTypes.h"
+#include "IPerson.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+/* Event sent while searching persons */
+class EventContactManagerFind : public WrtDeviceApis::Commons::IEvent<EventContactManagerFind>
+{
+private:
+       bool    m_result;
+
+       /* parameters */
+       Tizen::FilterPtr        m_filter;
+       Tizen::SortModePtr      m_sortMode;
+
+       bool    m_filterIsSet;
+       bool    m_sortModeIsSet;
+
+       /* results */
+       PersonArrayPtr          m_persons;
+
+       bool    m_personsIsSet;
+
+public:
+       EventContactManagerFind() :
+               m_result(false),
+               m_filterIsSet(false),
+               m_sortModeIsSet(false),
+               m_personsIsSet(false)
+       {
+       }
+
+       virtual ~EventContactManagerFind()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       Tizen::FilterPtr getFilter() const
+       {
+               return m_filter;
+       }
+
+       void setFilter(const Tizen::FilterPtr &value)
+       {
+               m_filter = value;
+               m_filterIsSet = true;
+       }
+
+       bool getFilterIsSet() const
+       {
+               return m_filterIsSet;
+       }
+
+       Tizen::SortModePtr getSortMode() const
+       {
+               return m_sortMode;
+       }
+
+       void setSortMode(const Tizen::SortModePtr &value)
+       {
+               m_sortMode = value;
+               m_sortModeIsSet = true;
+       }
+
+       bool getSortModeIsSet() const
+       {
+               return m_sortModeIsSet;
+       }
+
+       PersonArrayPtr getPersons() const
+       {
+               return m_persons;
+       }
+
+       void setPersons(const PersonArrayPtr &value)
+       {
+               m_persons = value;
+               m_personsIsSet = true;
+       }
+
+       bool getPersonsIsSet() const
+       {
+               return m_personsIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventContactManagerFind> EventContactManagerFindPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_FIND_H_
diff --git a/src/platform/API/Contact/EventContactManagerGet.h b/src/platform/API/Contact/EventContactManagerGet.h
new file mode 100755 (executable)
index 0000000..b306873
--- /dev/null
@@ -0,0 +1,118 @@
+//
+// 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        EventContactManagerGet.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_GET_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_GET_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPerson.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventContactManagerGet : public WrtDeviceApis::Commons::IEvent<EventContactManagerGet>
+{
+private:
+       bool m_result;
+
+       /* result */
+       PersonPtr m_person;
+
+       bool m_personIsSet;
+
+       /* parameters */
+       std::string     m_id;
+
+       bool m_idIsSet;
+
+public:
+       EventContactManagerGet() :
+               m_result(false),
+               m_person(NULL),
+               m_personIsSet(false),
+               m_idIsSet(false)
+       {
+       }
+
+       virtual ~EventContactManagerGet()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       std::string getId() const
+       {
+               return m_id;
+       }
+
+       void setId(const std::string value)
+       {
+               m_id = value;
+               m_idIsSet = true;
+       }
+
+       bool getIdIsSet() const
+       {
+               return m_idIsSet;
+       }
+
+       void setPerson(PersonPtr &value)
+       {
+               m_person = value;
+               m_personIsSet = true;
+       }
+
+       PersonPtr getPerson() const
+       {
+               return m_person;
+       }
+
+       bool getPersonIsSet() const
+       {
+               return m_personIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventContactManagerGet> EventContactManagerGetPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_GET_H_
diff --git a/src/platform/API/Contact/EventContactManagerGetAddressBook.h b/src/platform/API/Contact/EventContactManagerGetAddressBook.h
new file mode 100755 (executable)
index 0000000..6769f53
--- /dev/null
@@ -0,0 +1,118 @@
+//
+// 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        EventContactManagerGetAddressBook.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_GET_ADDRESS_BOOK_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_GET_ADDRESS_BOOK_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IAddressBook.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventContactManagerGetAddressBook : public WrtDeviceApis::Commons::IEvent<EventContactManagerGetAddressBook>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       std::string m_addressBookId;
+
+       bool m_addressBookIdIsSet;
+
+       /* result */
+       AddressBookPtr  m_addressBook;
+
+       bool m_addressBookIsSet;
+
+public:
+       EventContactManagerGetAddressBook() :
+               m_result(false),
+               m_addressBookIdIsSet(false),
+               m_addressBookIsSet(false)
+       {
+       }
+
+       virtual ~EventContactManagerGetAddressBook()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       std::string getAddressBookId() const
+       {
+               return m_addressBookId;
+       }
+
+       void setAddressBookId(const std::string &value)
+       {
+               m_addressBookId = value;
+               m_addressBookIdIsSet = true;
+       }
+
+       bool getaddressBookIdIsSet() const
+       {
+               return m_addressBookIdIsSet;
+       }
+
+       AddressBookPtr getAddressBook() const
+       {
+               return m_addressBook;
+       }
+
+       void setAddressBook(const AddressBookPtr &value)
+       {
+               m_addressBook = value;
+               m_addressBookIsSet = true;
+       }
+
+       bool getAddressBookIsSet() const
+       {
+               return m_addressBookIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventContactManagerGetAddressBook> EventContactManagerGetAddressBookPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_GET_ADDRESS_BOOK_H_
+
diff --git a/src/platform/API/Contact/EventContactManagerGetAddressBooks.h b/src/platform/API/Contact/EventContactManagerGetAddressBooks.h
new file mode 100755 (executable)
index 0000000..fc1d350
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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        EventContactManagerGetAddressBooks.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_GET_ADDRESS_BOOKS_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_GET_ADDRESS_BOOKS_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IAddressBook.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventContactManagerGetAddressBooks : public WrtDeviceApis::Commons::IEvent<EventContactManagerGetAddressBooks>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       AddressBookArrayPtr     m_addressBooks;
+
+       bool m_addressBooksIsSet;
+
+public:
+       EventContactManagerGetAddressBooks() :
+               m_result(false),
+               m_addressBooksIsSet(false)
+       {
+       }
+
+       virtual ~EventContactManagerGetAddressBooks()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       AddressBookArrayPtr getAddressBooks() const
+       {
+               return m_addressBooks;
+       }
+
+       void setAddressBooks(const AddressBookArrayPtr &value)
+       {
+               m_addressBooks = value;
+               m_addressBooksIsSet = true;
+       }
+
+       bool setAddressBooksIsSet() const
+       {
+               return m_addressBooksIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventContactManagerGetAddressBooks> EventContactManagerGetAddressBooksPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_GET_ADDRESS_BOOKS_H_
+
diff --git a/src/platform/API/Contact/EventContactManagerGetDefaultAddressBook.h b/src/platform/API/Contact/EventContactManagerGetDefaultAddressBook.h
new file mode 100755 (executable)
index 0000000..c20f886
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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        EventContactManagerGetDefaultAddressBook.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_GET_DEFAULT_ADDRESS_BOOK_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_GET_DEFAULT_ADDRESS_BOOK_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IAddressBook.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventContactManagerGetDefaultAddressBook : public WrtDeviceApis::Commons::IEvent<EventContactManagerGetDefaultAddressBook>
+{
+private:
+       bool m_result;
+
+       /* result */
+       AddressBookPtr  m_defaultAddressBook;
+
+       bool m_defaultAddressBookIsSet;
+
+public:
+       EventContactManagerGetDefaultAddressBook() :
+               m_result(false),
+               m_defaultAddressBookIsSet(false)
+       {
+       }
+
+       virtual ~EventContactManagerGetDefaultAddressBook()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       AddressBookPtr getDefaultAddressBook() const
+       {
+               return m_defaultAddressBook;
+       }
+
+       void setDefaultAddressBook(const AddressBookPtr &value)
+       {
+               m_defaultAddressBook = value;
+               m_defaultAddressBookIsSet = true;
+       }
+
+       bool getDefaultAddressBookIsSet() const
+       {
+               return m_defaultAddressBookIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventContactManagerGetDefaultAddressBook> EventContactManagerGetDefaultAddressBookPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_GET_DEFAULT_ADDRESS_BOOK_H_
+
diff --git a/src/platform/API/Contact/EventContactManagerRemove.h b/src/platform/API/Contact/EventContactManagerRemove.h
new file mode 100755 (executable)
index 0000000..1563bfe
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// 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        EventContactManagerRemove.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_REMOVE_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_REMOVE_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventContactManagerRemove : public WrtDeviceApis::Commons::IEvent<EventContactManagerRemove>
+{
+private:
+       bool    m_result;
+
+       /* parameters */
+       std::string     m_personId;
+
+       bool    m_personIdIsSet;
+
+public:
+       EventContactManagerRemove() :
+               m_result(false),
+               m_personIdIsSet(false)
+       {
+       }
+
+       virtual ~EventContactManagerRemove()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       std::string getPersonId() const
+       {
+               return m_personId;
+       }
+
+       void setPersonId(const std::string value)
+       {
+               m_personIdIsSet = true;
+               m_personId = value;
+       }
+
+       bool getPersonIdIsSet() const
+       {
+               return m_personIdIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventContactManagerRemove> EventContactManagerRemovePtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_REMOVE_H_
+
diff --git a/src/platform/API/Contact/EventContactManagerRemoveBatch.h b/src/platform/API/Contact/EventContactManagerRemoveBatch.h
new file mode 100755 (executable)
index 0000000..52b80de
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// 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        EventContactManagerRemoveBatch.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_REMOVE_BATCH_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_REMOVE_BATCH_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventContactManagerRemoveBatch : public WrtDeviceApis::Commons::IEvent<EventContactManagerRemoveBatch>
+{
+private:
+       bool    m_result;
+
+       /* parameters */
+       StringArrayPtr  m_personIds;
+
+       bool    m_personIdsIsSet;
+
+public:
+       EventContactManagerRemoveBatch() :
+               m_result(false),
+               m_personIdsIsSet(false)
+       {
+       }
+
+       virtual ~EventContactManagerRemoveBatch()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       StringArrayPtr getPersonIds() const
+       {
+               return m_personIds;
+       }
+
+       void setPersonIds(const StringArrayPtr &value)
+       {
+               m_personIdsIsSet = true;
+               m_personIds = value;
+       }
+
+       bool getPersonIdsIsSet() const
+       {
+               return m_personIdsIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventContactManagerRemoveBatch> EventContactManagerRemoveBatchPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_REMOVE_BATCH_H_
+
diff --git a/src/platform/API/Contact/EventContactManagerRemoveChangeListener.h b/src/platform/API/Contact/EventContactManagerRemoveChangeListener.h
new file mode 100755 (executable)
index 0000000..1dda68d
--- /dev/null
@@ -0,0 +1,98 @@
+//
+// 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        EventContactManagerRemoveChangeListener.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_REMOVE_CHANGE_LISTENER_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_REMOVE_CHANGE_LISTENER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventContactManagerRemoveChangeListener : public WrtDeviceApis::Commons::IEvent<EventContactManagerRemoveChangeListener>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       long m_id;
+
+       bool m_idIsSet;
+
+       /* result */
+
+public:
+       EventContactManagerRemoveChangeListener() :
+               m_result(false),
+               m_id(0),
+               m_idIsSet(false)
+       {
+       }
+
+       virtual ~EventContactManagerRemoveChangeListener()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       long getId() const
+       {
+               return m_id;
+       }
+
+       void setId(const long value)
+       {
+               m_id = value;
+               m_idIsSet = true;
+       }
+
+       bool getIdIsSet() const
+       {
+               return m_idIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventContactManagerRemoveChangeListener> EventContactManagerRemoveChangeListenerPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_REMOVE_CHANGE_LISTENER_H_
diff --git a/src/platform/API/Contact/EventContactManagerUpdate.h b/src/platform/API/Contact/EventContactManagerUpdate.h
new file mode 100755 (executable)
index 0000000..3b64ea5
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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        EventContactManagerUpdate.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_UPDATE_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_UPDATE_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPerson.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventContactManagerUpdate : public WrtDeviceApis::Commons::IEvent<EventContactManagerUpdate>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       PersonPtr m_person;
+
+       bool m_personIsSet;
+
+public:
+       EventContactManagerUpdate() :
+               m_result(false),
+               m_personIsSet(false)
+       {
+       }
+
+       virtual ~EventContactManagerUpdate()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       PersonPtr getPerson() const
+       {
+               return m_person;
+       }
+
+       void setPerson(const PersonPtr &value)
+       {
+               m_person = value;
+               m_personIsSet = true;
+       }
+
+       bool getPersonIsSet() const
+       {
+               return m_personIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventContactManagerUpdate> EventContactManagerUpdatePtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_UPDATE_H_
+
diff --git a/src/platform/API/Contact/EventContactManagerUpdateBatch.h b/src/platform/API/Contact/EventContactManagerUpdateBatch.h
new file mode 100755 (executable)
index 0000000..fe90728
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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        EventContactManagerUpdateBatch.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_CONTACT_MANAGER_UPDATE_BATCH_H_
+#define _API_CONTACT_EVENT_CONTACT_MANAGER_UPDATE_BATCH_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPerson.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventContactManagerUpdateBatch : public WrtDeviceApis::Commons::IEvent<EventContactManagerUpdateBatch>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       PersonArrayPtr  m_persons;
+
+       bool m_personsIsSet;
+
+public:
+       EventContactManagerUpdateBatch() :
+               m_result(false),
+               m_personsIsSet(false)
+       {
+       }
+
+       virtual ~EventContactManagerUpdateBatch()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       PersonArrayPtr getPersons() const
+       {
+               return m_persons;
+       }
+
+       void setPersons(const PersonArrayPtr &value)
+       {
+               m_persons = value;
+               m_personsIsSet = true;
+       }
+
+       bool getPersonsIsSet() const
+       {
+               return m_personsIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventContactManagerUpdateBatch> EventContactManagerUpdateBatchPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_CONTACT_MANAGER_UPDATE_BATCH_H_
+
diff --git a/src/platform/API/Contact/EventPersonLink.h b/src/platform/API/Contact/EventPersonLink.h
new file mode 100755 (executable)
index 0000000..a4f182a
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// 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        EventPersonLink.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_PERSON_LINK_H_
+#define _API_CONTACT_EVENT_PERSON_LINK_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class EventPersonLink : public WrtDeviceApis::Commons::IEvent<EventPersonLink>
+{
+private:
+       bool    m_result;
+
+       /* parameters */
+       std::string     m_personId;
+
+       bool    m_personIdIsSet;
+
+public:
+       EventPersonLink() :
+               m_result(false),
+               m_personIdIsSet(false)
+       {
+       }
+
+       virtual ~EventPersonLink()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       std::string getPersonId() const
+       {
+               return m_personId;
+       }
+
+       void setPersonId(const std::string value)
+       {
+               m_personIdIsSet = true;
+               m_personId = value;
+       }
+
+       bool getPersonIdIsSet() const
+       {
+               return m_personIdIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventPersonLink> EventPersonLinkPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_PERSON_LINK_H_
+
diff --git a/src/platform/API/Contact/EventPersonUnlink.h b/src/platform/API/Contact/EventPersonUnlink.h
new file mode 100755 (executable)
index 0000000..6ff7c5c
--- /dev/null
@@ -0,0 +1,121 @@
+//
+// 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        EventPersonUnlink.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_EVENT_PERSON_UNLINK_H_
+#define _API_CONTACT_EVENT_PERSON_UNLINK_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPerson.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class IPerson;
+typedef DPL::SharedPtr<IPerson> PersonPtr;
+
+class EventPersonUnlink : public WrtDeviceApis::Commons::IEvent<EventPersonUnlink>
+{
+private:
+       bool m_result;
+
+       /* parameters */
+       std::string     m_contactId;
+
+       bool m_contactIdIsSet;
+
+       /* results */
+       PersonPtr m_person;
+
+       bool m_personIsSet;
+
+public:
+       EventPersonUnlink() :
+               m_result(false),
+               m_contactIdIsSet(false),
+               m_personIsSet(false)
+       {
+       }
+
+       virtual ~EventPersonUnlink()
+       {
+       }
+
+       virtual void clearOnCancel()
+       {
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getResult() const
+       {
+               return m_result;
+       }
+
+       std::string getContactId() const
+       {
+               return m_contactId;
+       }
+
+       void setContactId(const std::string value)
+       {
+               m_contactIdIsSet = true;
+               m_contactId = value;
+       }
+
+       bool getContactIdIsSet() const
+       {
+               return m_contactIdIsSet;
+       }
+
+       PersonPtr getPerson() const
+       {
+               return m_person;
+       }
+
+       void setPerson(const PersonPtr value)
+       {
+               m_personIsSet = true;
+               m_person = value;
+       }
+
+       bool getPersonIsSet() const
+       {
+               return m_personIsSet;
+       }
+};
+
+typedef DPL::SharedPtr<EventPersonUnlink> EventPersonUnlinkPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_EVENT_PERSON_UNLINK_H_
+
diff --git a/src/platform/API/Contact/IAddressBook.cpp b/src/platform/API/Contact/IAddressBook.cpp
new file mode 100755 (executable)
index 0000000..6fdb38b
--- /dev/null
@@ -0,0 +1,154 @@
+//
+// 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        IAddressBook.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <Commons/ThreadPool.h>
+#include "IAddressBook.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+using namespace WrtDeviceApis::Commons;
+
+IAddressBook::IAddressBook() :
+       //initialize all receivers to work on CONTACT_THREAD thread
+       EventRequestReceiver< EventAddressBookGet >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookAdd >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookAddBatch >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookUpdate >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookUpdateBatch >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookRemove >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookRemoveBatch >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookFind >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookAddChangeListener >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookRemoveChangeListener >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookGetGroup >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookAddGroup >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookUpdateGroup >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookRemoveGroup >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventAddressBookGetGroups >(ThreadEnum::NULL_THREAD)
+{
+       //Nothing to do
+       LogDebug("entered");
+}
+
+IAddressBook::~IAddressBook()
+{
+       //Nothing to do
+//     LogDebug("entered");
+}
+
+void IAddressBook::get(const EventAddressBookGetPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookGet >::PostRequest(event);
+}
+
+void IAddressBook::add(const EventAddressBookAddPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookAdd >::PostRequest(event);
+}
+
+void IAddressBook::addBatch(const EventAddressBookAddBatchPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookAddBatch >::PostRequest(event);
+}
+
+void IAddressBook::update(const EventAddressBookUpdatePtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookUpdate >::PostRequest(event);
+}
+
+void IAddressBook::updateBatch(const EventAddressBookUpdateBatchPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookUpdateBatch >::PostRequest(event);
+}
+
+void IAddressBook::remove(const EventAddressBookRemovePtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookRemove >::PostRequest(event);
+}
+
+void IAddressBook::removeBatch(const EventAddressBookRemoveBatchPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookRemoveBatch >::PostRequest(event);
+}
+
+void IAddressBook::find(const EventAddressBookFindPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookFind >::PostRequest(event);
+}
+
+void IAddressBook::addChangeListener(const EventAddressBookAddChangeListenerPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookAddChangeListener >::PostRequest(event);
+}
+
+void IAddressBook::removeChangeListener(const EventAddressBookRemoveChangeListenerPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookRemoveChangeListener >::PostRequest(event);
+}
+
+void IAddressBook::getGroup(const EventAddressBookGetGroupPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookGetGroup >::PostRequest(event);
+}
+
+void IAddressBook::addGroup(const EventAddressBookAddGroupPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookAddGroup >::PostRequest(event);
+}
+
+void IAddressBook::updateGroup(const EventAddressBookUpdateGroupPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookUpdateGroup >::PostRequest(event);
+}
+
+void IAddressBook::removeGroup(const EventAddressBookRemoveGroupPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookRemoveGroup >::PostRequest(event);
+}
+
+void IAddressBook::getGroups(const EventAddressBookGetGroupsPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventAddressBookGetGroups >::PostRequest(event);
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/IAddressBook.h b/src/platform/API/Contact/IAddressBook.h
new file mode 100755 (executable)
index 0000000..e7d611f
--- /dev/null
@@ -0,0 +1,129 @@
+//
+// 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        IAddressBook.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_IADDRESS_BOOK_H_
+#define _API_CONTACT_IADDRESS_BOOK_H_
+
+#include <vector>
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/EventReceiver.h>
+#include "EventAddressBookGet.h"
+#include "EventAddressBookAdd.h"
+#include "EventAddressBookAddBatch.h"
+#include "EventAddressBookUpdate.h"
+#include "EventAddressBookUpdateBatch.h"
+#include "EventAddressBookRemove.h"
+#include "EventAddressBookRemoveBatch.h"
+#include "EventAddressBookFind.h"
+#include "EventAddressBookAddChangeListener.h"
+#include "EventAddressBookRemoveChangeListener.h"
+#include "EventAddressBookGetGroup.h"
+#include "EventAddressBookAddGroup.h"
+#include "EventAddressBookUpdateGroup.h"
+#include "EventAddressBookRemoveGroup.h"
+#include "EventAddressBookGetGroups.h"
+#include "IContactEventPrivateData.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class IAddressBook;
+typedef DPL::SharedPtr<IAddressBook> AddressBookPtr;
+
+typedef std::vector<AddressBookPtr> AddressBookArray;
+typedef DPL::SharedPtr<AddressBookArray> AddressBookArrayPtr;
+
+class IAddressBook :
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookGet >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookAdd >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookAddBatch >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookUpdate >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookUpdateBatch >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookRemove >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookRemoveBatch >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookFind >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookAddChangeListener >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookRemoveChangeListener >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookGetGroup >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookAddGroup >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookUpdateGroup >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookRemoveGroup >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookGetGroups >,
+       public IContactEventPrivateData
+{
+public:
+       explicit IAddressBook();
+       virtual ~IAddressBook();
+
+       virtual void get(const EventAddressBookGetPtr &event);
+       virtual void add(const EventAddressBookAddPtr &event);
+       virtual void addBatch(const EventAddressBookAddBatchPtr &event);
+       virtual void update(const EventAddressBookUpdatePtr &event);
+       virtual void updateBatch(const EventAddressBookUpdateBatchPtr &event);
+       virtual void remove(const EventAddressBookRemovePtr &event);
+       virtual void removeBatch(const EventAddressBookRemoveBatchPtr &event);
+       virtual void find(const EventAddressBookFindPtr &event);
+       virtual void addChangeListener(const EventAddressBookAddChangeListenerPtr &event);
+       virtual void removeChangeListener(const EventAddressBookRemoveChangeListenerPtr &event);
+       virtual void getGroup(const EventAddressBookGetGroupPtr &event);
+       virtual void addGroup(const EventAddressBookAddGroupPtr &event);
+       virtual void updateGroup(const EventAddressBookUpdateGroupPtr &event);
+       virtual void removeGroup(const EventAddressBookRemoveGroupPtr &event);
+       virtual void getGroups(const EventAddressBookGetGroupsPtr &event);
+
+       virtual std::string getId() const = 0;
+       virtual void        setId(const std::string &value) = 0;
+       virtual std::string getName() const = 0;
+       virtual void        setName(const std::string &value) = 0;
+       virtual std::string getAccountId() const = 0;
+       virtual void        setAccountId(const std::string &value) = 0;
+       virtual bool        getReadOnly() const = 0;
+       virtual void        setReadOnly(const bool &value) = 0;
+
+protected:
+       virtual void    OnRequestReceived(const EventAddressBookGetPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookAddPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookAddBatchPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookUpdatePtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookUpdateBatchPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookRemovePtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookRemoveBatchPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookFindPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookAddChangeListenerPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookRemoveChangeListenerPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookGetGroupPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookAddGroupPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookUpdateGroupPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookRemoveGroupPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventAddressBookGetGroupsPtr &event) = 0;
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_IADDRESS_BOOK_H_
diff --git a/src/platform/API/Contact/IContact.cpp b/src/platform/API/Contact/IContact.cpp
new file mode 100755 (executable)
index 0000000..0bb63c5
--- /dev/null
@@ -0,0 +1,697 @@
+//
+// 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        IContact.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ * ## - Change name to IContact
+ */
+
+#include "ContactFactory.h"
+#include "IContact.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+IContact::IContact() :
+               m_idIsSet(false),
+               m_addressBookIdIsSet(false),
+               m_personIdIsSet(false),
+               m_lastUpdatedIsSet(false),
+               m_photoURIIsSet(false),
+               m_birthdayIsSet(false),
+               m_ringtoneURIIsSet(false)
+{
+       m_lastUpdated = {0, };
+       m_name = ContactNamePtr(NULL);
+       m_addresses = ContactAddressArrayPtr(new ContactAddressArray());
+       m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
+       m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
+       m_birthday = {0, };
+       m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
+       m_organizations = ContactOrganizationArrayPtr(new ContactOrganizationArray());
+       m_notes = StringArrayPtr(new StringArray());
+       m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray());
+       m_isFavorite = false;
+       m_groupIds = StringArrayPtr(new StringArray());
+}
+
+IContact::~IContact()
+{
+}
+
+std::string IContact::getId() const
+{
+       return m_id;
+}
+
+void IContact::setId(const std::string value)
+{
+       m_id = value;
+       m_idIsSet = true;
+}
+
+void IContact::setId(const int value)
+{
+       std::stringstream oss;
+       oss << value;
+       m_id = oss.str();
+       m_idIsSet = true;
+}
+
+void IContact::unsetId()
+{
+       m_id = "";
+       m_idIsSet = false;
+}
+
+bool IContact::getIdIsSet() const
+{
+       return m_idIsSet;
+}
+
+std::string IContact::getAddressBookId() const
+{
+       return m_addressBookId;
+}
+
+void IContact::setAddressBookId(const std::string value)
+{
+       m_addressBookId = value;
+       m_addressBookIdIsSet = true;
+}
+
+void IContact::setAddressBookId(const int value)
+{
+       std::stringstream oss;
+       oss << value;
+       m_addressBookId = oss.str();
+       m_addressBookIdIsSet = true;
+}
+
+void IContact::unsetAddressBookId()
+{
+       m_addressBookId = "";
+       m_addressBookIdIsSet = false;
+}
+
+bool IContact::getAddressBookIdIsSet() const
+{
+       return m_addressBookIdIsSet;
+}
+
+std::string IContact::getPersonId() const
+{
+       return m_personId;
+}
+
+void IContact::setPersonId(const std::string value)
+{
+       m_personId = value;
+       m_personIdIsSet = true;
+}
+
+void IContact::setPersonId(const int value)
+{
+       std::stringstream oss;
+       oss << value;
+       m_personId = oss.str();
+       m_personIdIsSet = true;
+}
+
+void IContact::unsetPersonId()
+{
+       m_personId = "";
+       m_personIdIsSet = false;
+}
+
+bool IContact::getPersonIdIsSet() const
+{
+       return m_personIdIsSet;
+}
+
+std::tm IContact::getLastUpdated() const
+{
+       return m_lastUpdated;
+}
+
+void IContact::setLastUpdated(const std::tm &value)
+{
+       m_lastUpdated = value;
+       m_lastUpdatedIsSet = true;
+}
+
+void IContact::unsetLastUpdated()
+{
+       m_lastUpdated = {0, };
+       m_lastUpdatedIsSet = false;
+}
+
+bool IContact::getLastUpdatedIsSet() const
+{
+       return m_lastUpdatedIsSet;
+}
+
+ContactNamePtr IContact::getName() const
+{
+       return m_name;
+}
+
+void IContact::setName(const ContactNamePtr &value)
+{
+       m_name = value;
+}
+
+void IContact::unsetName()
+{
+       m_name = ContactNamePtr(NULL);
+}
+
+ContactAddressArrayPtr IContact::getAddresses() const
+{
+       return m_addresses;
+}
+
+void IContact::setAddresses(const ContactAddressArrayPtr &value)
+{
+       if(value == NULL)
+               m_addresses = ContactAddressArrayPtr(new ContactAddressArray());
+       else
+               m_addresses = value;
+}
+
+void IContact::addAddress(const ContactAddressPtr &value)
+{
+       m_addresses->push_back(value);
+}
+
+void IContact::clearAddresses()
+{
+       m_addresses->clear();
+}
+
+int IContact::getAddressesNum() const
+{
+       return m_addresses->size();
+}
+
+std::string IContact::getPhotoURI() const
+{
+       return m_photoURI;
+}
+
+void IContact::setPhotoURI(const std::string &value)
+{
+       m_photoURI = value;
+       m_photoURIIsSet = true;
+}
+
+void IContact::unsetPhotoURI()
+{
+       m_photoURI = "";
+       m_photoURIIsSet = false;
+}
+
+bool IContact::getPhotoURIIsSet() const
+{
+       return m_photoURIIsSet;
+}
+
+std::string IContact::getPhotoURIRealPath() const
+{
+       return m_photoURIRealPath;
+}
+
+void IContact::setPhotoURIRealPath(const std::string &value)
+{
+       m_photoURIRealPath = value;
+}
+
+ContactPhoneNumberArrayPtr IContact::getPhoneNumbers() const
+{
+       return m_phoneNumbers;
+}
+
+void IContact::setPhoneNumbers(const ContactPhoneNumberArrayPtr &value)
+{
+       if(value == NULL)
+               m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
+       else
+               m_phoneNumbers = value;
+}
+
+void IContact::addPhoneNumber(const ContactPhoneNumberPtr &value)
+{
+       m_phoneNumbers->push_back(value);
+}
+
+void IContact::clearPhoneNumbers()
+{
+       m_phoneNumbers->clear();
+}
+
+int IContact::getPhoneNumbersNum() const
+{
+       return m_phoneNumbers->size();
+}
+
+ContactEmailAddressArrayPtr IContact::getEmails() const
+{
+       return m_emails;
+}
+
+void IContact::setEmails(const ContactEmailAddressArrayPtr &value)
+{
+       if(value == NULL)
+               m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
+       else
+               m_emails = value;
+}
+
+void IContact::addEmail(const ContactEmailAddressPtr& value)
+{
+       m_emails->push_back(value);
+}
+
+void IContact::clearEmails()
+{
+       m_emails->clear();
+}
+
+int IContact::getEmailsNum() const
+{
+       return m_emails->size();
+}
+
+std::tm IContact::getBirthday() const
+{
+       return m_birthday;
+}
+
+void IContact::setBirthday(const std::tm &value)
+{
+       m_birthday = value;
+       m_birthdayIsSet = true;
+}
+
+void IContact::unsetBirthday()
+{
+       m_birthday = {0, };
+       m_birthdayIsSet = false;
+}
+
+bool IContact::getBirthdayIsSet() const
+{
+       return m_birthdayIsSet;
+}
+
+ContactAnniversaryArrayPtr IContact::getAnniversaries() const
+{
+       return m_anniversaries;
+}
+
+void IContact::setAnniversaries(const ContactAnniversaryArrayPtr &value)
+{
+       if(value == NULL)
+               m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
+       else
+               m_anniversaries = value;
+}
+
+void IContact::addAnniversary(const ContactAnniversaryPtr &value)
+{
+       m_anniversaries->push_back(value);
+}
+
+void IContact::clearAnniversaries()
+{
+       m_anniversaries->clear();
+}
+
+int IContact::getAnniversariesNum() const
+{
+       return m_anniversaries->size();
+}
+
+ContactOrganizationArrayPtr IContact::getOrganizations() const
+{
+       return m_organizations;
+}
+
+void IContact::setOrganizations(const ContactOrganizationArrayPtr &value)
+{
+       if(value == NULL)
+               m_organizations = ContactOrganizationArrayPtr(new ContactOrganizationArray());
+       else
+               m_organizations = value;
+}
+
+void IContact::addOrganization(const ContactOrganizationPtr &value)
+{
+       m_organizations->push_back(value);
+}
+
+void IContact::clearOrganizations()
+{
+       m_organizations->clear();
+}
+
+int IContact::getOrganizationsNum() const
+{
+       return m_organizations->size();
+}
+
+StringArrayPtr IContact::getNotes() const
+{
+       return m_notes;
+}
+
+void IContact::setNotes(const StringArrayPtr &value)
+{
+       if(value == NULL)
+               m_notes = StringArrayPtr(new StringArray());
+       else
+               m_notes = value;
+}
+
+void IContact::addNote(const std::string &value)
+{
+       m_notes->push_back(value);
+}
+
+void IContact::clearNotes()
+{
+       m_notes->clear();
+}
+
+int IContact::getNotesNum() const
+{
+       return m_notes->size();
+}
+
+ContactWebSiteArrayPtr IContact::getUrls() const
+{
+       return m_urls;
+}
+
+void IContact::setUrls(const ContactWebSiteArrayPtr &value)
+{
+       if(value == NULL)
+               m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray());
+       else
+               m_urls = value;
+}
+
+void IContact::addUrl(const ContactWebSitePtr &value)
+{
+       m_urls->push_back(value);
+}
+
+void IContact::clearUrls()
+{
+       m_urls->clear();
+}
+
+int IContact::getUrlsNum() const
+{
+       return m_urls->size();
+}
+
+bool IContact::getIsFavorite() const
+{
+       return m_isFavorite;
+}
+
+void IContact::setIsFavorite(const bool &value)
+{
+       m_isFavorite = value;
+}
+
+std::string IContact::getRingtoneURI() const
+{
+       return m_ringtoneURI;
+}
+
+void IContact::setRingtoneURI(const std::string &value)
+{
+       m_ringtoneURI = value;
+       m_ringtoneURIIsSet = true;
+}
+
+void IContact::unsetRingtoneURI()
+{
+       m_ringtoneURI = "";
+       m_ringtoneURIIsSet = false;
+}
+
+bool IContact::getRingtoneURIIsSet() const
+{
+       return m_ringtoneURIIsSet;
+}
+
+std::string IContact::getRingtoneURIRealPath() const
+{
+       return m_ringtoneURIRealPath;
+}
+
+void IContact::setRingtoneURIRealPath(const std::string &value)
+{
+       m_ringtoneURIRealPath = value;
+}
+
+StringArrayPtr IContact::getGroupIds() const
+{
+       return m_groupIds;
+}
+
+void IContact::setGroupIds(const StringArrayPtr &value)
+{
+       if(value == NULL)
+               m_groupIds = StringArrayPtr(new StringArray());
+       else
+               m_groupIds = value;
+}
+
+void IContact::addGroupId(const std::string &value)
+{
+       m_groupIds->push_back(value);
+}
+
+void IContact::clearGroupIds()
+{
+       m_groupIds->clear();
+}
+
+int IContact::getGroupIdsNum() const
+{
+       return m_groupIds->size();
+}
+
+void IContact::copy(const ContactPtr &contact)
+{
+       m_id = contact->m_id;
+       m_idIsSet = contact->m_idIsSet;
+
+       m_addressBookId = contact->m_addressBookId;
+       m_addressBookIdIsSet = contact->m_addressBookIdIsSet;
+
+       m_personId = contact->m_personId;
+       m_personIdIsSet = contact->m_personIdIsSet;
+
+       m_lastUpdated = contact->m_lastUpdated;
+       m_lastUpdatedIsSet = contact->m_lastUpdatedIsSet;
+
+       if(contact->m_name == NULL)
+               m_name = ContactNamePtr(NULL);
+       else
+               m_name = contact->m_name->clone();
+
+       m_addresses = ContactAddressArrayPtr(new ContactAddressArray());
+       ContactAddressArray::iterator contactAddressIter;
+       for(contactAddressIter = contact->m_addresses->begin(); contactAddressIter != contact->m_addresses->end(); contactAddressIter++)
+               m_addresses->push_back((*contactAddressIter)->clone());
+
+       m_photoURI = contact->m_photoURI;
+       m_photoURIIsSet = contact->m_photoURIIsSet;
+
+       m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
+       ContactPhoneNumberArray::iterator contactPhoneNumberIter;
+       for(contactPhoneNumberIter = contact->m_phoneNumbers->begin(); contactPhoneNumberIter != contact->m_phoneNumbers->end(); contactPhoneNumberIter++)
+               m_phoneNumbers->push_back((*contactPhoneNumberIter)->clone());
+
+       m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
+       ContactEmailAddressArray::iterator contactEmailAddressIter;
+       for(contactEmailAddressIter = contact->m_emails->begin(); contactEmailAddressIter != contact->m_emails->end(); contactEmailAddressIter++)
+               m_emails->push_back((*contactEmailAddressIter)->clone());
+
+       m_birthday = contact->m_birthday;
+       m_birthdayIsSet = contact->m_birthdayIsSet;
+
+       m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
+       ContactAnniversaryArray::iterator contactAnniversaryIter;
+       for(contactAnniversaryIter = contact->m_anniversaries->begin(); contactAnniversaryIter != contact->m_anniversaries->end(); contactAnniversaryIter++)
+               m_anniversaries->push_back((*contactAnniversaryIter)->clone());
+
+       m_organizations = ContactOrganizationArrayPtr(new ContactOrganizationArray());
+       ContactOrganizationArray::iterator contactOrganizationIter;
+       for(contactOrganizationIter = contact->m_organizations->begin(); contactOrganizationIter != contact->m_organizations->end(); contactOrganizationIter++)
+               m_organizations->push_back((*contactOrganizationIter)->clone());
+
+       m_notes = StringArrayPtr(new StringArray());
+       StringArray::iterator noteIter;
+       for(noteIter = contact->m_notes->begin(); noteIter != contact->m_notes->end(); noteIter++)
+       {
+               std::string note = *noteIter;
+               m_notes->push_back(note);
+       }
+
+       m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray());
+       ContactWebSiteArray::iterator contactWebSiteIter;
+       for(contactWebSiteIter = contact->m_urls->begin(); contactWebSiteIter != contact->m_urls->end(); contactWebSiteIter++)
+               m_urls->push_back((*contactWebSiteIter)->clone());
+
+       m_isFavorite = contact->m_isFavorite;
+
+       m_ringtoneURI = contact->m_ringtoneURI;
+       m_ringtoneURIIsSet = contact->m_ringtoneURIIsSet;
+
+       m_groupIds = StringArrayPtr(new StringArray());
+       StringArray::iterator groupIdIter;
+       for(groupIdIter = contact->m_groupIds->begin(); groupIdIter != contact->m_groupIds->end(); groupIdIter++)
+       {
+               std::string groupId = *groupIdIter;
+               m_groupIds->push_back(groupId);
+       }
+}
+
+void IContact::clear()
+{
+       m_id = "";
+       m_idIsSet = false;
+
+       m_addressBookId = "";
+       m_addressBookIdIsSet = false;
+
+       m_personId = "";
+       m_personIdIsSet = false;
+
+       m_lastUpdated = {0, };
+       m_lastUpdatedIsSet = false;
+
+       m_name = ContactNamePtr(NULL);
+
+       m_addresses = ContactAddressArrayPtr(new ContactAddressArray());
+
+       m_photoURI = "";
+       m_photoURIIsSet = false;
+
+       m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
+
+       m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
+
+       m_birthday = {0, };
+       m_birthdayIsSet = false;
+
+       m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
+
+       m_organizations = ContactOrganizationArrayPtr(new ContactOrganizationArray());
+
+       m_notes = StringArrayPtr(new StringArray());
+
+       m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray());
+
+       m_isFavorite = false;
+
+       m_ringtoneURI = "";
+       m_ringtoneURIIsSet = false;
+
+       m_groupIds = StringArrayPtr(new StringArray());
+}
+
+ContactPtr IContact::clone() const
+{
+       ContactPtr result = ContactFactory::getInstance().createContact();
+
+       if(m_name != NULL)
+               result->m_name = m_name->clone();
+
+       result->m_addresses = ContactAddressArrayPtr(new ContactAddressArray());
+       ContactAddressArray::iterator contactAddressIter;
+       for(contactAddressIter = m_addresses->begin(); contactAddressIter != m_addresses->end(); contactAddressIter++)
+               result->m_addresses->push_back((*contactAddressIter)->clone());
+
+       result->m_photoURI = m_photoURI;
+       result->m_photoURIIsSet = m_photoURIIsSet;
+
+       result->m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
+       ContactPhoneNumberArray::iterator contactPhoneNumberIter;
+       for(contactPhoneNumberIter = m_phoneNumbers->begin(); contactPhoneNumberIter != m_phoneNumbers->end(); contactPhoneNumberIter++)
+               result->m_phoneNumbers->push_back((*contactPhoneNumberIter)->clone());
+
+       result->m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
+       ContactEmailAddressArray::iterator contactEmailAddressIter;
+       for(contactEmailAddressIter = m_emails->begin(); contactEmailAddressIter != m_emails->end(); contactEmailAddressIter++)
+               result->m_emails->push_back((*contactEmailAddressIter)->clone());
+
+       result->m_birthday = m_birthday;
+       result->m_birthdayIsSet = m_birthdayIsSet;
+
+       result->m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
+       ContactAnniversaryArray::iterator contactAnniversaryIter;
+       for(contactAnniversaryIter = m_anniversaries->begin(); contactAnniversaryIter != m_anniversaries->end(); contactAnniversaryIter++)
+               result->m_anniversaries->push_back((*contactAnniversaryIter)->clone());
+
+       result->m_organizations = ContactOrganizationArrayPtr(new ContactOrganizationArray());
+       ContactOrganizationArray::iterator contactOrganizationIter;
+       for(contactOrganizationIter = m_organizations->begin(); contactOrganizationIter != m_organizations->end(); contactOrganizationIter++)
+               result->m_organizations->push_back((*contactOrganizationIter)->clone());
+
+       result->m_notes = StringArrayPtr(new StringArray());
+       StringArray::iterator noteIter;
+       for(noteIter = m_notes->begin(); noteIter != m_notes->end(); noteIter++)
+       {
+               std::string note = *noteIter;
+               result->m_notes->push_back(note);
+       }
+
+       result->m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray());
+       ContactWebSiteArray::iterator contactWebSiteIter;
+       for(contactWebSiteIter = m_urls->begin(); contactWebSiteIter != m_urls->end(); contactWebSiteIter++)
+               result->m_urls->push_back((*contactWebSiteIter)->clone());
+
+       result->m_isFavorite = m_isFavorite;
+
+       result->m_ringtoneURI = m_ringtoneURI;
+       result->m_ringtoneURIIsSet = m_ringtoneURIIsSet;
+
+       result->m_groupIds = StringArrayPtr(new StringArray());
+       StringArray::iterator groupIdIter;
+       for(groupIdIter = m_groupIds->begin(); groupIdIter != m_groupIds->end(); groupIdIter++)
+       {
+               std::string groupId = *groupIdIter;
+               result->m_groupIds->push_back(groupId);
+       }
+
+       return result;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/IContact.h b/src/platform/API/Contact/IContact.h
new file mode 100755 (executable)
index 0000000..811efc4
--- /dev/null
@@ -0,0 +1,214 @@
+//
+// 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        IContact.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ * ##
+ */
+
+#ifndef _API_CONTACT_ICONTACT_H_
+#define _API_CONTACT_ICONTACT_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/enable_shared_from_this.h>
+#include "ContactTypes.h"
+#include "ContactName.h"
+#include "ContactAddress.h"
+#include "ContactPhoneNumber.h"
+#include "ContactEmailAddress.h"
+#include "ContactAnniversary.h"
+#include "ContactOrganization.h"
+#include "ContactWebSite.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class IContact;
+typedef DPL::SharedPtr<IContact> ContactPtr;
+
+typedef std::vector<ContactPtr> ContactArray;
+typedef DPL::SharedPtr<ContactArray> ContactArrayPtr;
+
+class IContact : public DPL::EnableSharedFromThis<IContact>
+{
+public:
+       IContact();
+       virtual ~IContact();
+
+       virtual std::string convertToString(const std::string &format) = 0;
+       virtual void setContactFromString(const std::string &vObjectStr) = 0;
+
+       std::string getId() const;
+       void setId(const std::string value);
+       void setId(const int value);
+       void unsetId();
+       bool getIdIsSet() const;
+
+       std::string getAddressBookId() const;
+       void setAddressBookId(const std::string value);
+       void setAddressBookId(const int value);
+       void unsetAddressBookId();
+       bool getAddressBookIdIsSet() const;
+
+       std::string getPersonId() const;
+       void setPersonId(const std::string value);
+       void setPersonId(const int value);
+       void unsetPersonId();
+       bool getPersonIdIsSet() const;
+
+       std::tm getLastUpdated() const;
+       void setLastUpdated(const std::tm &value);
+       void unsetLastUpdated();
+       bool getLastUpdatedIsSet() const;
+
+       ContactNamePtr getName() const;
+       void setName(const ContactNamePtr &value);
+       void unsetName();
+
+       ContactAddressArrayPtr getAddresses() const;
+       void setAddresses(const ContactAddressArrayPtr &value);
+       void addAddress(const ContactAddressPtr &value);
+       void clearAddresses();
+       int  getAddressesNum() const;
+
+       std::string getPhotoURI() const;
+       void setPhotoURI(const std::string &value);
+       void unsetPhotoURI();
+       bool getPhotoURIIsSet() const;
+       std::string getPhotoURIRealPath() const;
+       void setPhotoURIRealPath(const std::string &value);
+
+       ContactPhoneNumberArrayPtr getPhoneNumbers() const;
+       void setPhoneNumbers(const ContactPhoneNumberArrayPtr &value);
+       void addPhoneNumber(const ContactPhoneNumberPtr &value);
+       void clearPhoneNumbers();
+       int  getPhoneNumbersNum() const;
+
+       ContactEmailAddressArrayPtr getEmails() const;
+       void setEmails(const ContactEmailAddressArrayPtr &value);
+       void addEmail(const ContactEmailAddressPtr& value);
+       void clearEmails();
+       int  getEmailsNum() const;
+
+       std::tm getBirthday() const;
+       void setBirthday(const std::tm &value);
+       void unsetBirthday();
+       bool getBirthdayIsSet() const;
+
+       ContactAnniversaryArrayPtr getAnniversaries() const;
+       void setAnniversaries(const ContactAnniversaryArrayPtr &value);
+       void addAnniversary(const ContactAnniversaryPtr &value);
+       void clearAnniversaries();
+       int  getAnniversariesNum() const;
+
+       ContactOrganizationArrayPtr getOrganizations() const;
+       void setOrganizations(const ContactOrganizationArrayPtr &value);
+       void addOrganization(const ContactOrganizationPtr &value);
+       void clearOrganizations();
+       int  getOrganizationsNum() const;
+
+       StringArrayPtr getNotes() const;
+       void setNotes(const StringArrayPtr &value);
+       void addNote(const std::string &value);
+       void clearNotes();
+       int  getNotesNum() const;
+
+       ContactWebSiteArrayPtr getUrls() const;
+       void setUrls(const ContactWebSiteArrayPtr &value);
+       void addUrl(const ContactWebSitePtr &value);
+       void clearUrls();
+       int  getUrlsNum() const;
+
+       bool getIsFavorite() const;
+       void setIsFavorite(const bool &value);
+
+       std::string getRingtoneURI() const;
+       void setRingtoneURI(const std::string &value);
+       void unsetRingtoneURI();
+       bool getRingtoneURIIsSet() const;
+       std::string getRingtoneURIRealPath() const;
+       void setRingtoneURIRealPath(const std::string &value);
+
+       StringArrayPtr getGroupIds() const;
+       void setGroupIds(const StringArrayPtr &value);
+       void addGroupId(const std::string &value);
+       void clearGroupIds();
+       int  getGroupIdsNum() const;
+
+       virtual void copy(const ContactPtr &contact);
+       virtual void clear();
+       virtual ContactPtr clone() const;
+
+protected:
+       std::string                 m_id;
+       bool                        m_idIsSet;
+
+       std::string                 m_addressBookId;
+       bool                        m_addressBookIdIsSet;
+
+       std::string                 m_personId;
+       bool                        m_personIdIsSet;
+
+       std::tm                     m_lastUpdated;
+       bool                        m_lastUpdatedIsSet;
+
+       ContactNamePtr              m_name;
+
+       ContactAddressArrayPtr      m_addresses;
+
+       std::string                 m_photoURI;
+       bool                        m_photoURIIsSet;
+       std::string                 m_photoURIRealPath;
+
+       ContactPhoneNumberArrayPtr  m_phoneNumbers;
+
+       ContactEmailAddressArrayPtr m_emails;
+
+       std::tm                     m_birthday;
+       bool                        m_birthdayIsSet;
+
+       ContactAnniversaryArrayPtr  m_anniversaries;
+
+       ContactOrganizationArrayPtr m_organizations;
+
+       StringArrayPtr              m_notes;
+
+       ContactWebSiteArrayPtr      m_urls;
+
+       bool                        m_isFavorite;
+
+       std::string                 m_ringtoneURI;
+       bool                        m_ringtoneURIIsSet;
+       std::string                 m_ringtoneURIRealPath;
+
+       StringArrayPtr              m_groupIds;
+
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_CONTACT_H_
diff --git a/src/platform/API/Contact/IContactEventPrivateData.h b/src/platform/API/Contact/IContactEventPrivateData.h
new file mode 100755 (executable)
index 0000000..0d5254c
--- /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.
+//
+
+/**
+ * @file        ContactEventPrivateData.h
+ * @author      Lukasz Marek (l.marek@samsung.com)
+ * @version     0.1
+ * @brief
+ * ##
+ */
+
+#ifndef _API_CONTACT_ICONTACT_EVENT_PRIVATE_DATA_H_
+#define _API_CONTACT_ICONTACT_EVENT_PRIVATE_DATA_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+/* This is base class for objects stored as private data inside some contact events */
+class IContactEventPrivateData
+{
+};
+
+typedef DPL::SharedPtr<IContactEventPrivateData> IContactEventPrivateDataPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_ICONTACT_EVENT_PRIVATE_DATA_H_
diff --git a/src/platform/API/Contact/IContactManager.cpp b/src/platform/API/Contact/IContactManager.cpp
new file mode 100755 (executable)
index 0000000..3439579
--- /dev/null
@@ -0,0 +1,124 @@
+//
+// 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        IContactManager.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ * ##
+ */
+
+#include <Commons/ThreadPool.h>
+#include "IContactManager.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+using namespace WrtDeviceApis::Commons;
+
+IContactManager::IContactManager() :
+               EventRequestReceiver< EventContactManagerGetAddressBook >(ThreadEnum::NULL_THREAD),
+               EventRequestReceiver< EventContactManagerGetAddressBooks >(ThreadEnum::NULL_THREAD),
+               EventRequestReceiver< EventContactManagerGetDefaultAddressBook >(ThreadEnum::NULL_THREAD),
+               EventRequestReceiver< EventContactManagerGet >(ThreadEnum::NULL_THREAD),
+               EventRequestReceiver< EventContactManagerUpdate >(ThreadEnum::NULL_THREAD),
+               EventRequestReceiver< EventContactManagerUpdateBatch >(ThreadEnum::NULL_THREAD),
+               EventRequestReceiver< EventContactManagerRemove >(ThreadEnum::NULL_THREAD),
+               EventRequestReceiver< EventContactManagerRemoveBatch >(ThreadEnum::NULL_THREAD),
+               EventRequestReceiver< EventContactManagerFind >(ThreadEnum::NULL_THREAD),
+               EventRequestReceiver< EventContactManagerAddChangeListener >(ThreadEnum::NULL_THREAD),
+               EventRequestReceiver< EventContactManagerRemoveChangeListener >(ThreadEnum::NULL_THREAD)
+{
+       //Nothing to do
+}
+
+IContactManager::~IContactManager()
+{
+       //Nothing to do
+}
+
+void IContactManager::getAddressBook(const EventContactManagerGetAddressBookPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventContactManagerGetAddressBook >::PostRequest(event);
+}
+
+void IContactManager::getAddressBooks(const EventContactManagerGetAddressBooksPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventContactManagerGetAddressBooks >::PostRequest(event);
+}
+
+void IContactManager::getDefaultAddressBook(const EventContactManagerGetDefaultAddressBookPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventContactManagerGetDefaultAddressBook >::PostRequest(event);
+}
+
+void IContactManager::get(const EventContactManagerGetPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventContactManagerGet >::PostRequest(event);
+}
+
+void IContactManager::update(const EventContactManagerUpdatePtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventContactManagerUpdate >::PostRequest(event);
+}
+
+void IContactManager::updateBatch(const EventContactManagerUpdateBatchPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventContactManagerUpdateBatch >::PostRequest(event);
+}
+
+void IContactManager::remove(const EventContactManagerRemovePtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventContactManagerRemove >::PostRequest(event);
+}
+
+void IContactManager::removeBatch(const EventContactManagerRemoveBatchPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventContactManagerRemoveBatch >::PostRequest(event);
+}
+
+void IContactManager::find(const EventContactManagerFindPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventContactManagerFind >::PostRequest(event);
+}
+
+void IContactManager::addChangeListener(const EventContactManagerAddChangeListenerPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventContactManagerAddChangeListener >::PostRequest(event);
+}
+
+void IContactManager::removeChangeListener(const EventContactManagerRemoveChangeListenerPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventContactManagerRemoveChangeListener >::PostRequest(event);
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/IContactManager.h b/src/platform/API/Contact/IContactManager.h
new file mode 100755 (executable)
index 0000000..7be3387
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// 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        IContactManager.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_CONTACT_ICONTACT_MANAGER_H_
+#define _API_CONTACT_ICONTACT_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/EventReceiver.h>
+#include "IAddressBook.h"
+#include "EventContactManagerGetAddressBook.h"
+#include "EventContactManagerGetAddressBooks.h"
+#include "EventContactManagerGetDefaultAddressBook.h"
+#include "EventContactManagerGet.h"
+#include "EventContactManagerUpdate.h"
+#include "EventContactManagerUpdateBatch.h"
+#include "EventContactManagerRemove.h"
+#include "EventContactManagerRemoveBatch.h"
+#include "EventContactManagerFind.h"
+#include "EventContactManagerAddChangeListener.h"
+#include "EventContactManagerRemoveChangeListener.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class IContactManager :
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventContactManagerGetAddressBook >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventContactManagerGetAddressBooks >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventContactManagerGetDefaultAddressBook >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventContactManagerGet >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventContactManagerUpdate >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventContactManagerUpdateBatch >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventContactManagerRemove >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventContactManagerRemoveBatch >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventContactManagerFind >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventContactManagerAddChangeListener >,
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventContactManagerRemoveChangeListener >
+{
+public:
+       IContactManager();
+       virtual ~IContactManager();
+       virtual void getAddressBook(const EventContactManagerGetAddressBookPtr &event);
+       virtual void getAddressBooks(const EventContactManagerGetAddressBooksPtr &event);
+       virtual void getDefaultAddressBook(const EventContactManagerGetDefaultAddressBookPtr &event);
+       virtual void get(const EventContactManagerGetPtr &event);
+       virtual void update(const EventContactManagerUpdatePtr &event);
+       virtual void updateBatch(const EventContactManagerUpdateBatchPtr &event);
+       virtual void remove(const EventContactManagerRemovePtr &event);
+       virtual void removeBatch(const EventContactManagerRemoveBatchPtr &event);
+       virtual void find(const EventContactManagerFindPtr &event);
+       virtual void addChangeListener(const EventContactManagerAddChangeListenerPtr &event);
+       virtual void removeChangeListener(const EventContactManagerRemoveChangeListenerPtr &event);
+
+protected:
+       virtual void OnRequestReceived(const EventContactManagerGetAddressBookPtr &event) = 0;
+       virtual void OnRequestReceived(const EventContactManagerGetAddressBooksPtr &event) = 0;
+       virtual void OnRequestReceived(const EventContactManagerGetDefaultAddressBookPtr &event) = 0;
+       virtual void OnRequestReceived(const EventContactManagerGetPtr &event) = 0;
+       virtual void OnRequestReceived(const EventContactManagerUpdatePtr &event) = 0;
+       virtual void OnRequestReceived(const EventContactManagerUpdateBatchPtr &event) = 0;
+       virtual void OnRequestReceived(const EventContactManagerRemovePtr &event) = 0;
+       virtual void OnRequestReceived(const EventContactManagerRemoveBatchPtr &event) = 0;
+       virtual void OnRequestReceived(const EventContactManagerFindPtr &event) = 0;
+       virtual void OnRequestReceived(const EventContactManagerAddChangeListenerPtr &event) = 0;
+       virtual void OnRequestReceived(const EventContactManagerRemoveChangeListenerPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<IContactManager> ContactManagerPtr;
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_ICONTACT_MANAGER_H_
diff --git a/src/platform/API/Contact/IPerson.cpp b/src/platform/API/Contact/IPerson.cpp
new file mode 100755 (executable)
index 0000000..6612070
--- /dev/null
@@ -0,0 +1,326 @@
+//
+// 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        IPerson.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ * ## - Change name to IPerson
+ */
+
+#include "IPerson.h"
+
+#include <Commons/ThreadPool.h>
+#include "ContactFactory.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+using namespace WrtDeviceApis::Commons;
+
+IPerson::IPerson() :
+               EventRequestReceiver< EventPersonLink >(ThreadEnum::NULL_THREAD),
+               EventRequestReceiver< EventPersonUnlink >(ThreadEnum::NULL_THREAD),
+               m_idIsSet(false),
+               m_displayNameIsSet(false),
+               m_contactCount(0),
+               m_contactCountIsSet(false),
+               m_hasPhoneNumber(false),
+               m_hasEmail(false),
+               m_isFavorite(false),
+               m_photoURIIsSet(false),
+               m_ringtoneURIIsSet(false),
+               m_displayContactIdIsSet(false)
+{
+}
+
+IPerson::~IPerson()
+{
+}
+
+void IPerson::link(const EventPersonLinkPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventPersonLink >::PostRequest(event);
+}
+
+void IPerson::unlink(const EventPersonUnlinkPtr &event)
+{
+       //post event to PLATFORM implementation
+       EventRequestReceiver< EventPersonUnlink >::PostRequest(event);
+}
+
+std::string IPerson::getId() const
+{
+       return m_id;
+}
+
+void IPerson::setId(const std::string value)
+{
+       m_id = value;
+       m_idIsSet = true;
+}
+
+void IPerson::setId(const int value)
+{
+       std::stringstream oss;
+       oss << value;
+       m_id = oss.str();
+       m_idIsSet = true;
+}
+
+void IPerson::unsetId()
+{
+       m_id = "";
+       m_idIsSet = false;
+}
+
+bool IPerson::getIdIsSet() const
+{
+       return m_idIsSet;
+}
+
+std::string IPerson::getDisplayName() const
+{
+       return m_displayName;
+}
+
+void IPerson::setDisplayName(const std::string value)
+{
+       m_displayName = value;
+       m_displayNameIsSet = true;
+}
+
+void IPerson::unsetDisplayName()
+{
+       m_displayName = "";
+       m_displayNameIsSet = false;
+}
+
+bool IPerson::getDisplayNameIsSet() const
+{
+       return m_displayNameIsSet;
+}
+
+long IPerson::getContactCount() const
+{
+       return m_contactCount;
+}
+
+void IPerson::setContactCount(const long value)
+{
+       m_contactCount = value;
+       m_contactCountIsSet = true;
+}
+void IPerson::unsetContactCount()
+{
+       m_contactCount = 0;
+       m_contactCountIsSet = false;
+}
+
+bool IPerson::getContactCountIsSet() const
+{
+       return m_contactCountIsSet;
+}
+
+bool IPerson::getHasPhoneNumber() const
+{
+       return m_hasPhoneNumber;
+}
+
+void IPerson::setHasPhoneNumber(const bool &value)
+{
+       m_hasPhoneNumber = value;
+}
+
+bool IPerson::getHasEmail() const
+{
+       return m_hasEmail;
+}
+
+void IPerson::setHasEmail(const bool &value)
+{
+       m_hasEmail = value;
+}
+
+bool IPerson::getIsFavorite() const
+{
+       return m_isFavorite;
+}
+
+void IPerson::setIsFavorite(const bool &value)
+{
+       m_isFavorite = value;
+}
+
+std::string IPerson::getPhotoURI() const
+{
+       return m_photoURI;
+}
+
+void IPerson::setPhotoURI(const std::string &value)
+{
+       m_photoURI = value;
+       m_photoURIIsSet = true;
+}
+
+void IPerson::unsetPhotoURI()
+{
+       m_photoURI = "";
+       m_photoURIIsSet = false;
+}
+
+bool IPerson::getPhotoURIIsSet() const
+{
+       return m_photoURIIsSet;
+}
+
+std::string IPerson::getPhotoURIRealPath() const
+{
+       return m_photoURIRealPath;
+}
+
+void IPerson::setPhotoURIRealPath(const std::string &value)
+{
+       m_photoURIRealPath = value;
+}
+
+std::string IPerson::getRingtoneURI() const
+{
+       return m_ringtoneURI;
+}
+
+void IPerson::setRingtoneURI(const std::string &value)
+{
+       m_ringtoneURI = value;
+       m_ringtoneURIIsSet = true;
+}
+
+void IPerson::unsetRingtoneURI()
+{
+       m_ringtoneURI = "";
+       m_ringtoneURIIsSet = false;
+}
+
+bool IPerson::getRingtoneURIIsSet() const
+{
+       return m_ringtoneURIIsSet;
+}
+
+std::string IPerson::getRingtoneURIRealPath() const
+{
+       return m_ringtoneURIRealPath;
+}
+
+void IPerson::setRingtoneURIRealPath(const std::string &value)
+{
+       m_ringtoneURIRealPath = value;
+}
+
+std::string IPerson::getDisplayContactId() const
+{
+       return m_displayContactId;
+}
+
+void IPerson::setDisplayContactId(const std::string value)
+{
+       m_displayContactId = value;
+       m_displayContactIdIsSet = true;
+}
+
+void IPerson::setDisplayContactId(const int value)
+{
+       std::stringstream oss;
+       oss << value;
+       m_displayContactId = oss.str();
+       m_displayContactIdIsSet = true;
+}
+
+void IPerson::unsetDisplayContactId()
+{
+       m_displayContactId = "";
+       m_displayContactIdIsSet = false;
+}
+
+bool IPerson::getDisplayContactIdIsSet() const
+{
+       return m_displayContactIdIsSet;
+}
+
+void IPerson::copy(const PersonPtr &person)
+{
+       m_id = person->m_id;
+       m_idIsSet = person->m_idIsSet;
+
+       m_displayName = person->m_displayName;
+       m_displayNameIsSet = person->m_displayNameIsSet;
+
+       m_contactCount = person->m_contactCount;
+       m_contactCountIsSet = person->m_contactCountIsSet;
+
+       m_hasPhoneNumber = person->m_hasPhoneNumber;
+
+       m_hasEmail = person->m_hasEmail;
+
+       m_isFavorite = person->m_isFavorite;
+
+       m_photoURI = person->m_photoURI;
+       m_photoURIIsSet = person->m_photoURIIsSet;
+       m_photoURIRealPath = person->m_photoURIRealPath;
+
+       m_ringtoneURI = person->m_ringtoneURI;
+       m_ringtoneURIIsSet = person->m_ringtoneURIIsSet;
+       m_ringtoneURIRealPath = person->m_ringtoneURIRealPath;
+
+       m_displayContactId = person->m_displayContactId;
+       m_displayContactIdIsSet = person->m_displayContactIdIsSet;
+}
+
+void IPerson::clear()
+{
+       m_id = "";
+       m_idIsSet = false;
+
+       m_displayName = "";
+       m_displayNameIsSet = false;
+
+       m_contactCount = 0;
+       m_contactCountIsSet = false;
+
+       m_hasPhoneNumber = false;
+
+       m_hasEmail = false;
+
+       m_isFavorite = false;
+
+       m_photoURI = "";
+       m_photoURIIsSet = false;
+       m_photoURIRealPath = "";
+
+       m_ringtoneURI = "";
+       m_ringtoneURIIsSet = false;
+       m_ringtoneURIRealPath = "";
+
+       m_displayContactId = "";
+       m_displayContactIdIsSet = false;
+}
+
+} // Contact
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Contact/IPerson.h b/src/platform/API/Contact/IPerson.h
new file mode 100755 (executable)
index 0000000..ee9aee4
--- /dev/null
@@ -0,0 +1,142 @@
+//
+// 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        IPerson.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ * ##
+ */
+
+#ifndef _API_CONTACT_IPERSON_H_
+#define _API_CONTACT_IPERSON_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include "EventPersonLink.h"
+#include "EventPersonUnlink.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Contact {
+
+class IPerson;
+typedef DPL::SharedPtr<IPerson> PersonPtr;
+
+typedef std::vector<PersonPtr> PersonArray;
+typedef DPL::SharedPtr<PersonArray> PersonArrayPtr;
+
+class IPerson :
+               public WrtDeviceApis::Commons::EventRequestReceiver< EventPersonLink >,
+               public WrtDeviceApis::Commons::EventRequestReceiver< EventPersonUnlink >
+{
+public:
+       IPerson();
+       virtual ~IPerson();
+
+       virtual void link(const EventPersonLinkPtr &event);
+       virtual void unlink(const EventPersonUnlinkPtr &event);
+
+protected:
+       virtual void    OnRequestReceived(const EventPersonLinkPtr &event) = 0;
+       virtual void    OnRequestReceived(const EventPersonUnlinkPtr &event) = 0;
+
+public:
+       std::string getId() const;
+       void setId(const std::string value);
+       void setId(const int value);
+       void unsetId();
+       bool getIdIsSet() const;
+
+       std::string getDisplayName() const;
+       void setDisplayName(const std::string value);
+       void unsetDisplayName();
+       bool getDisplayNameIsSet() const;
+
+       long getContactCount() const;
+       void setContactCount(const long value);
+       void unsetContactCount();
+       bool getContactCountIsSet() const;
+
+       bool getIsFavorite() const;
+       void setIsFavorite(const bool &value);
+
+       bool getHasPhoneNumber() const;
+       void setHasPhoneNumber(const bool &value);
+
+       bool getHasEmail() const;
+       void setHasEmail(const bool &value);
+
+       std::string getPhotoURI() const;
+       void setPhotoURI(const std::string &value);
+       void unsetPhotoURI();
+       bool getPhotoURIIsSet() const;
+       std::string getPhotoURIRealPath() const;
+       void setPhotoURIRealPath(const std::string &value);
+
+       std::string getRingtoneURI() const;
+       void setRingtoneURI(const std::string &value);
+       void unsetRingtoneURI();
+       bool getRingtoneURIIsSet() const;
+       std::string getRingtoneURIRealPath() const;
+       void setRingtoneURIRealPath(const std::string &value);
+
+       std::string getDisplayContactId() const;
+       void setDisplayContactId(const std::string value);
+       void setDisplayContactId(const int value);
+       void unsetDisplayContactId();
+       bool getDisplayContactIdIsSet() const;
+
+       virtual void copy(const PersonPtr &person);
+       virtual void clear();
+
+protected:
+       std::string                 m_id;
+       bool                        m_idIsSet;
+
+       std::string                 m_displayName;
+       bool                        m_displayNameIsSet;
+
+       long                        m_contactCount;
+       bool                        m_contactCountIsSet;
+
+       bool                        m_hasPhoneNumber;
+
+       bool                        m_hasEmail;
+
+       bool                        m_isFavorite;
+
+       std::string                 m_photoURI;
+       bool                        m_photoURIIsSet;
+       std::string                 m_photoURIRealPath;
+
+       std::string                 m_ringtoneURI;
+       bool                        m_ringtoneURIIsSet;
+       std::string                 m_ringtoneURIRealPath;
+
+       std::string                 m_displayContactId;
+       bool                        m_displayContactIdIsSet;
+};
+
+} // Contact
+} // Api
+} // TizenApis
+
+#endif // _API_CONTACT_IPERSON_H_
diff --git a/src/platform/API/Contact/config.cmake b/src/platform/API/Contact/config.cmake
new file mode 100755 (executable)
index 0000000..4a129cf
--- /dev/null
@@ -0,0 +1,18 @@
+get_current_path()
+set(SRCS_PLATFORM_API_CONTACT
+  ${CURRENT_PATH}/IAddressBook.cpp
+  ${CURRENT_PATH}/IContactManager.cpp
+  ${CURRENT_PATH}/IContact.cpp
+  ${CURRENT_PATH}/IPerson.cpp
+  ${CURRENT_PATH}/ContactGroup.cpp
+  ${CURRENT_PATH}/ContactRef.cpp
+  ${CURRENT_PATH}/ContactName.cpp
+  ${CURRENT_PATH}/ContactAnniversary.cpp
+  ${CURRENT_PATH}/ContactAddress.cpp
+  ${CURRENT_PATH}/ContactFactory.cpp
+  ${CURRENT_PATH}/ContactPhoneNumber.cpp
+  ${CURRENT_PATH}/ContactEmailAddress.cpp
+  ${CURRENT_PATH}/ContactOrganization.cpp
+  ${CURRENT_PATH}/ContactWebSite.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Content/IEventBrowseFolder.h b/src/platform/API/Content/IEventBrowseFolder.h
new file mode 100755 (executable)
index 0000000..8277b1a
--- /dev/null
@@ -0,0 +1,194 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_BROWSE_FOLDER_H_
+#define _ABSTRACT_LAYER_IEVENT_BROWSE_FOLDER_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include <API/Filter/IFilter.h>
+#include <API/Filter/SortMode.h>
+
+#include <dpl/shared_ptr.h>
+#include "MediacontentMedia.h"
+
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+class IEventBrowseFolder : public WrtDeviceApis::Commons::IEvent<IEventBrowseFolder>
+{
+
+       public:
+               
+       IEventBrowseFolder()
+       {
+               m_result = false;
+               m_filterIsSet = false;
+               m_sortModesIsSet = false;
+               m_limitIsSet = false;
+               m_offsetIsSet = false;
+               m_folderIdIsSet = false;
+
+       }
+       
+               
+       virtual ~IEventBrowseFolder(){}
+
+       void addMedia(MediacontentMedia *value)
+       {
+               MediacontentMediaPtr mediaItem(value);
+               m_media.push_back(mediaItem);   
+       }
+
+       vector<MediacontentMediaPtr> getMedia()
+       {       
+               return m_media; 
+       }
+       
+
+       void setLimit(const unsigned long value)
+       {
+               m_limitIsSet = true;
+               m_limit = value;
+       }
+       void setOffset(const unsigned long value)
+       {
+               m_offsetIsSet = true;
+               m_offset = value;
+       }
+
+       void setFilter(const Tizen::FilterPtr &value)
+       {
+               m_filter = value;
+               m_filterIsSet = true;
+       }
+
+       void setSortModes(const Tizen::SortModeArrayPtr &value)
+       {
+               m_sortModes = value;
+               m_sortModesIsSet = true;
+       }
+
+       void setSortMode(const Tizen::SortModePtr &value)
+       {
+               m_sortMode = value;
+               m_sortModesIsSet = true;
+       }
+       
+       void setFolderID(const string &value)
+       {
+               m_folderId = value;
+               m_folderIdIsSet = true;
+       }
+
+       string getFolderID()
+       {
+               return m_folderId;
+       }
+
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getLimitIsSet() const
+       {
+               return m_limitIsSet;
+       }
+       
+       bool getOffsetIsSet() const
+       {
+               return m_offsetIsSet;
+       }
+
+       bool getResult()const
+       {
+               return m_result; 
+       }
+
+       bool getFilterIsSet()const
+       {
+               return m_filterIsSet; 
+       }
+
+       bool getFolderIdIsSet()const
+       {
+               return m_folderIdIsSet; 
+       }
+       
+       bool getSortModesIsSet()const
+       {
+               return m_sortModesIsSet; 
+       }
+
+       unsigned long getLimit() const
+       {
+               return m_limit;
+       }
+       
+       unsigned long getOffset() const
+       {
+               return m_offset;
+       }       
+
+       FilterPtr getFilter() const
+       {
+               return m_filter;
+       }
+       
+       SortModeArrayPtr getSortModes() const
+       {
+               return m_sortModes;
+       }
+
+       SortModePtr getSortMode() const
+       {
+               return m_sortMode;
+       }
+
+       private:
+       bool m_filterIsSet;
+       bool m_sortModesIsSet;
+
+       bool m_result;                                                                  //OUTPUT: operation result
+       bool m_limitIsSet;
+       bool m_offsetIsSet;
+       bool m_folderIdIsSet;
+
+       unsigned long m_limit;
+       unsigned long m_offset;
+       FilterPtr m_filter;
+       SortModeArrayPtr m_sortModes;
+       SortModePtr m_sortMode;
+
+       string m_folderId;
+       
+       vector<MediacontentMediaPtr> m_media;  
+
+};
+
+typedef DPL::SharedPtr<IEventBrowseFolder> IEventBrowseFolderPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_BROWSE_FOLDER_H_ */
diff --git a/src/platform/API/Content/IEventFindFolder.h b/src/platform/API/Content/IEventFindFolder.h
new file mode 100755 (executable)
index 0000000..31f3c3b
--- /dev/null
@@ -0,0 +1,162 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_FIND_FOLDER_H_
+#define _ABSTRACT_LAYER_IEVENT_FIND_FOLDER_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <API/Filter/IFilter.h>
+#include <API/Filter/SortMode.h>
+#include "MediacontentFolder.h"
+
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+class IEventFindFolder : public WrtDeviceApis::Commons::IEvent<IEventFindFolder>
+{
+       public:
+       IEventFindFolder()
+       {       
+               m_result = false;
+               m_filterIsSet = false;
+               m_sortModesIsSet = false;
+               m_limitIsSet = false;
+               m_offsetIsSet = false;
+               
+       }
+       ~IEventFindFolder(){}           
+       
+       void addFolder(MediacontentFolderPtr value)
+       { 
+               m_folder.push_back(value);
+       }
+       
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       vector<MediacontentFolderPtr> getFolder()
+       {
+               return m_folder; 
+       }
+
+       void setLimit(const unsigned long value)
+       {
+               m_limitIsSet = true;
+               m_limit = value;
+       }
+       void setOffset(const unsigned long value)
+       {
+               m_offsetIsSet = true;
+               m_offset = value;
+       }
+
+       void setFilter(const Tizen::FilterPtr &value)
+       {
+               m_filter = value;
+               m_filterIsSet = true;
+       }
+
+       void setSortModes(const Tizen::SortModeArrayPtr &value)
+       {
+               m_sortModes = value;
+               m_sortModesIsSet = true;
+       }
+
+       bool getLimitIsSet() const
+       {
+               return m_limitIsSet;
+       }
+       
+       bool getOffsetIsSet() const
+       {
+               return m_offsetIsSet;
+       }
+
+       bool getResult()const
+       {
+               return m_result; 
+       }
+
+       bool getFilterIsSet()const
+       {
+               return m_filterIsSet; 
+       }
+       
+       bool getSortModesIsSet()const
+       {
+               return m_sortModesIsSet; 
+       }
+
+       unsigned long getLimit() const
+       {
+               return m_limit;
+       }
+       
+       unsigned long getOffset() const
+       {
+               return m_offset;
+       }       
+
+       FilterPtr getFilter() const
+       {
+               return m_filter;
+       }
+       
+       SortModeArrayPtr getSortModes() const
+       {
+               return m_sortModes;
+       }
+
+
+
+       virtual void clearOnCancel(){;}
+
+
+       private:
+       bool m_filterIsSet;
+       bool m_sortModesIsSet;
+
+       bool m_result;                                  //OUTPUT: operation result
+       bool m_limitIsSet;
+       bool m_offsetIsSet;
+
+
+       unsigned long m_limit;
+       unsigned long m_offset;
+       FilterPtr m_filter;
+       SortModeArrayPtr m_sortModes;
+       vector<MediacontentFolderPtr> m_folder;           //OUTPUT: result list
+
+
+       
+};
+
+typedef DPL::SharedPtr<IEventFindFolder> IEventFindFolderPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_FIND_FOLDER_H_ */
diff --git a/src/platform/API/Content/IEventFindMedia.h b/src/platform/API/Content/IEventFindMedia.h
new file mode 100755 (executable)
index 0000000..7044edf
--- /dev/null
@@ -0,0 +1,163 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_FIND_MEDIA_H_
+#define _ABSTRACT_LAYER_IEVENT_FIND_MEDIA_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include <API/Filter/IFilter.h>
+#include <API/Filter/SortMode.h>
+
+#include <dpl/shared_ptr.h>
+#include "MediacontentMedia.h"
+
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+class IEventFindMedia : public WrtDeviceApis::Commons::IEvent<IEventFindMedia>
+{
+
+       public:
+               
+       IEventFindMedia()
+       {
+               m_result = false;
+               m_filterIsSet = false;
+               m_sortModesIsSet = false;
+               m_limitIsSet = false;
+               m_offsetIsSet = false;
+               
+
+       }
+       
+               
+       virtual ~IEventFindMedia(){}
+
+       void addMedia(MediacontentMedia *value)
+       {
+               MediacontentMediaPtr mediaItem(value);
+               m_media.push_back(mediaItem);   
+       }
+
+       vector<MediacontentMediaPtr> getMedia()
+       {       
+               return m_media; 
+       }
+       
+
+       void setLimit(const unsigned long value)
+       {
+               m_limitIsSet = true;
+               m_limit = value;
+       }
+       void setOffset(const unsigned long value)
+       {
+               m_offsetIsSet = true;
+               m_offset = value;
+       }
+
+       void setFilter(const Tizen::FilterPtr &value)
+       {
+               m_filter = value;
+               m_filterIsSet = true;
+       }
+
+       void setSortModes(const Tizen::SortModeArrayPtr &value)
+       {
+               m_sortModes = value;
+               m_sortModesIsSet = true;
+       }
+
+       void setResult(bool value)
+       {
+               m_result = value;
+       }
+
+       bool getLimitIsSet() const
+       {
+               return m_limitIsSet;
+       }
+       
+       bool getOffsetIsSet() const
+       {
+               return m_offsetIsSet;
+       }
+
+       bool getResult()const
+       {
+               return m_result; 
+       }
+
+       bool getFilterIsSet()const
+       {
+               return m_filterIsSet; 
+       }
+       
+       bool getSortModesIsSet()const
+       {
+               return m_sortModesIsSet; 
+       }
+
+       unsigned long getLimit() const
+       {
+               return m_limit;
+       }
+       
+       unsigned long getOffset() const
+       {
+               return m_offset;
+       }       
+
+       FilterPtr getFilter() const
+       {
+               return m_filter;
+       }
+       
+       SortModeArrayPtr getSortModes() const
+       {
+               return m_sortModes;
+       }
+
+
+       private:
+       bool m_filterIsSet;
+       bool m_sortModesIsSet;
+
+       bool m_result;                                                                  //OUTPUT: operation result
+       bool m_limitIsSet;
+       bool m_offsetIsSet;
+
+       unsigned long m_limit;
+       unsigned long m_offset;
+       FilterPtr m_filter;
+       SortModeArrayPtr m_sortModes;
+
+       vector<MediacontentMediaPtr> m_media;  
+
+};
+
+typedef DPL::SharedPtr<IEventFindMedia> IEventFindMediaPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_FIND_MEDIA_H_ */
diff --git a/src/platform/API/Content/IEventUpdateMedia.h b/src/platform/API/Content/IEventUpdateMedia.h
new file mode 100755 (executable)
index 0000000..4f7a9a8
--- /dev/null
@@ -0,0 +1,73 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_UPDATE_ITEM_H_
+#define _ABSTRACT_LAYER_IEVENT_UPDATE_ITEM_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "MediacontentMedia.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+class IEventUpdateMedia : public WrtDeviceApis::Commons::IEvent<IEventUpdateMedia>
+{
+
+       public:
+       IEventUpdateMedia():m_result(false), m_media(NULL)
+    {
+        LogDebug("entered");
+    }
+       ~IEventUpdateMedia(){}
+       
+
+    void setMediaItem(MediacontentMediaPtr value)
+    {
+       LogDebug("setMediaItem11");
+        m_media = value;
+    }
+
+       MediacontentMediaPtr getMediaItem()
+       {       
+               return m_media; 
+       }
+       
+
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+       private:
+       bool m_result;
+       MediacontentMediaPtr m_media;           //OUTPUT: result list
+};
+
+typedef DPL::SharedPtr<IEventUpdateMedia> IEventUpdateMediaPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_UPDATE_ITEM_H_ */
diff --git a/src/platform/API/Content/IEventUpdateMediaItems.h b/src/platform/API/Content/IEventUpdateMediaItems.h
new file mode 100755 (executable)
index 0000000..5026a53
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_UPDATE_ITEMS_H_
+#define _ABSTRACT_LAYER_IEVENT_UPDATE_ITEMS_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "MediacontentMedia.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+class IEventUpdateMediaItems : public WrtDeviceApis::Commons::IEvent<IEventUpdateMediaItems>
+{
+
+       public:
+       IEventUpdateMediaItems():m_result(false)
+    {
+        LogDebug("entered");
+    }
+       virtual ~IEventUpdateMediaItems(){}
+       
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    MediacontentMediaListPtr getMediaItems() const
+    {
+        return m_mediaList;
+    }
+
+    void setMediaItems(MediacontentMediaListPtr value)
+    {
+        m_mediaList = value;
+    }
+
+
+       private:
+       bool m_result;
+       MediacontentMediaListPtr m_mediaList;
+};
+
+typedef DPL::SharedPtr<IEventUpdateMediaItems> IEventUpdateMediaItemsPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_UPDATE_ITEMS_H_ */
diff --git a/src/platform/API/Content/IMediacontentManager.cpp b/src/platform/API/Content/IMediacontentManager.cpp
new file mode 100755 (executable)
index 0000000..3651a6f
--- /dev/null
@@ -0,0 +1,77 @@
+//
+// 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/ThreadPool.h>
+#include "IMediacontentManager.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+
+IMediacontentManager::IMediacontentManager() :
+//     WrtDeviceApis::Commons::EventRequestReceiver<IEventGetMediacontent>(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD),
+       WrtDeviceApis::Commons::EventRequestReceiver<IEventFindFolder>(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD),
+       WrtDeviceApis::Commons::EventRequestReceiver<IEventBrowseFolder>(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD),      
+       WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateMedia>(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD),
+       WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateMediaItems>(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD)
+
+{
+}
+
+IMediacontentManager::~IMediacontentManager()
+{
+}
+
+/*
+void IMediacontentManager::getMediacontent( const IEventGetMediacontentPtr &event )
+{
+    LogDebug("entered");
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventGetMediacontent>::PostRequest(event);
+}
+*/
+
+void IMediacontentManager::findFolder(IEventFindFolderPtr &ptr)
+{
+       LogDebug("IMediacontentManager::called findFolders");
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventFindFolder>::PostRequest(ptr);
+}
+
+void IMediacontentManager::updateMedia(IEventUpdateMediaPtr &ptr)
+{
+       LogDebug("IMediacontentManager::called updateMedia");
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateMedia>::PostRequest(ptr);
+}
+
+void IMediacontentManager::browseFolder(IEventBrowseFolderPtr &ptr)
+{
+       LogDebug("IMediacontentManager::called IEventBrowseFolder");
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventBrowseFolder>::PostRequest(ptr);
+}
+
+void IMediacontentManager::updateMediaItems(IEventUpdateMediaItemsPtr &ptr)
+{
+       LogDebug("IMediacontentManager::called IEventBrowseFolder");
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateMediaItems>::PostRequest(ptr);
+}
+
+
+}
+}
+}
diff --git a/src/platform/API/Content/IMediacontentManager.h b/src/platform/API/Content/IMediacontentManager.h
new file mode 100755 (executable)
index 0000000..d2e59eb
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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 _ABSTRACT_LAYER_ICONTENT_MANAGER_H_
+#define _ABSTRACT_LAYER_ICONTENT_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include "IEventFindMedia.h"
+#include "IEventFindFolder.h"
+#include "IEventUpdateMedia.h"
+#include "IEventUpdateMediaItems.h"
+#include "IEventBrowseFolder.h" 
+
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+class IMediacontentManager : 
+//             public WrtDeviceApis::Commons::EventRequestReceiver<IEventGetMediacontent>,
+        public WrtDeviceApis::Commons::EventRequestReceiver<IEventFindFolder>,
+        public WrtDeviceApis::Commons::EventRequestReceiver<IEventBrowseFolder>,        
+        public WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateMedia>,
+        public WrtDeviceApis::Commons::EventRequestReceiver<IEventUpdateMediaItems>                    
+{
+    public:
+       IMediacontentManager();
+       virtual ~IMediacontentManager();
+//     virtual void getMediacontent(const IEventGetMediacontentPtr &event );
+
+
+       typedef enum
+       {
+               CONTENT_IMAGE,
+               CONTENT_VIDEO,
+               CONTENT_AUDIO
+       } MediacontentType;
+
+       virtual void findFolder(IEventFindFolderPtr &ptr);      
+       virtual void updateMedia(IEventUpdateMediaPtr &ptr);
+       virtual void browseFolder(IEventBrowseFolderPtr &ptr);
+       virtual void updateMediaItems(IEventUpdateMediaItemsPtr &ptr);  
+
+       virtual void OnRequestReceived(const IEventFindFolderPtr &value) = 0;
+       virtual void OnRequestReceived(const IEventUpdateMediaPtr &value) = 0;
+       virtual void OnRequestReceived(const IEventBrowseFolderPtr &value) = 0; 
+       virtual void OnRequestReceived(const IEventUpdateMediaItemsPtr &value) = 0;     
+       
+       protected:
+//     virtual void OnRequestReceived(const IEventGetMediacontentPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<IMediacontentManager> IMediacontentManagerPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_ICONTENT_MANAGER_H_ */
diff --git a/src/platform/API/Content/MediacontentAudio.cpp b/src/platform/API/Content/MediacontentAudio.cpp
new file mode 100755 (executable)
index 0000000..7e04048
--- /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 <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "MediacontentAudio.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+
+MediacontentAudio::MediacontentAudio()
+{
+       m_lyricsState = CONTENT_LYRIC_UNKNOWN;
+
+       m_editableAttrList.push_back("rating");
+       m_editableAttrList.push_back("title");
+       m_editableAttrList.push_back("description");
+}
+
+MediacontentAudio::~MediacontentAudio()
+{
+}
+
+
+string MediacontentAudio::getAudioAlbum() const
+{
+       return m_audioAlbum;
+}
+vector<std::string> MediacontentAudio::getAudioArtist() const
+{
+       return m_audioArtist;
+}
+
+vector<std::string> MediacontentAudio::getAudioGenre() const
+{
+       return m_audioGenre;
+}
+vector<std::string> MediacontentAudio::getAudioComposer() const
+{
+       return m_audioAuthor;
+}
+
+string MediacontentAudio::getAudioCopyright() const
+{
+       return m_audioCopyright;
+}
+
+int MediacontentAudio::getAudioBitrate() const
+{
+       return m_audioBitrate;
+}
+
+
+int MediacontentAudio::getAudioTrackNum() const
+{
+       return m_audioTrackNum;
+}
+
+int MediacontentAudio::getAudioDuration() const
+{
+       return m_audioDuration;
+}
+
+unsigned long long MediacontentAudio::getAudioSize() const
+{      
+       return m_audioSize;
+}
+
+MediacontentLyricsPtr MediacontentAudio::getAudioLyrics() const
+{
+       return m_lyrics;
+}
+
+void MediacontentAudio::setAudioAlbum(const string &value, bool isChanged)
+{
+       m_audioAlbum = value;
+       m_isChangedAudioAlbum = isChanged;
+}
+
+void MediacontentAudio::setAudioArtist(const vector<std::string> &value, bool isChanged)
+{
+       m_audioArtist = value;
+       m_isChangedAudioArtist = isChanged;
+}
+
+void MediacontentAudio::setAudioGenre(const vector<std::string> &value, bool isChanged)
+{
+       m_audioGenre = value;
+       m_isChangedAudioGenre = isChanged;
+}
+
+void MediacontentAudio::setAudioComposer(const vector<std::string> &value, bool isChanged)
+{
+       m_audioAuthor = value;
+       m_isChangedAudioComposer = isChanged;
+}
+
+void MediacontentAudio::setAudioCopyright(const string &value)
+{
+       m_audioCopyright = value;
+}
+
+void MediacontentAudio::setAudioBitrate(const int &value) 
+{
+       m_audioBitrate = value;
+}
+
+void MediacontentAudio::setAudioTrackNum(const int &value, bool isChanged)
+{
+       m_audioTrackNum = value;
+       m_isChangedAudioTrackNumber = isChanged;
+}
+
+void MediacontentAudio::setAudioDuration(const int &value)     
+{
+       m_audioDuration = value;
+}
+
+void MediacontentAudio::setAudioSize(const unsigned long long &value)
+{
+       m_audioSize = value;
+}
+
+void MediacontentAudio::setAudioLyrics(MediacontentLyricsPtr value)
+{
+       m_lyrics = value;
+       m_lyricsState = CONTENT_LYRIC_EXISTENT;
+}
+
+
+bool MediacontentAudio::isChangedAudioAlbum()
+{
+       return  m_isChangedAudioAlbum;
+}
+
+bool MediacontentAudio::isChangedAudioArtist()
+{
+       return  m_isChangedAudioArtist;
+}
+bool MediacontentAudio::isChangedAudioGenre()
+{
+       return  m_isChangedAudioGenre;
+}
+
+bool MediacontentAudio::isChangedAudioComposer()
+{
+       return  m_isChangedAudioComposer;
+}
+
+bool MediacontentAudio::isChangedAudioTrackNumber()
+{
+       return  m_isChangedAudioTrackNumber;
+}
+
+mediacontent_lyric_state MediacontentAudio::getLyricsState()
+{
+       return m_lyricsState;
+}
+
+vector<std::string>    MediacontentAudio::getEditableAttr() const
+{
+    return m_editableAttrList;
+}
+
+void MediacontentAudio::display() const
+{
+
+       MediacontentMedia::display();
+}
+
+void MediacontentAudio::appendAudioArtist(const string &value)
+{
+       m_audioArtist.push_back(value);
+}
+
+void MediacontentAudio::appendAudioGenre(const string &value)
+{
+       m_audioGenre.push_back(value);
+}
+
+void MediacontentAudio::appendAudioComposer(const string &value)
+{
+       m_audioAuthor.push_back(value);
+}
+
+void MediacontentAudio::setAudioLyricNonExistent()
+{
+       m_lyricsState = CONTENT_LYRIC_NON_EXISTENT;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Content/MediacontentAudio.h b/src/platform/API/Content/MediacontentAudio.h
new file mode 100755 (executable)
index 0000000..03357d7
--- /dev/null
@@ -0,0 +1,122 @@
+//
+// 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 _ABSTRACT_LAYER_CONTENT_AUDIO_H_
+#define _ABSTRACT_LAYER_CONTENT_AUDIO_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/optional.h>
+#include <dpl/shared_ptr.h>
+#include "MediacontentMedia.h"
+#include "MediacontentLyrics.h"
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+typedef enum
+{
+       CONTENT_LYRIC_UNKNOWN = 0,
+       CONTENT_LYRIC_EXISTENT, 
+       CONTENT_LYRIC_NON_EXISTENT,
+}mediacontent_lyric_state;
+
+class MediacontentAudio : public MediacontentMedia
+{
+       public:
+
+       MediacontentAudio();
+       virtual ~MediacontentAudio();
+
+       string getAudioAlbum() const;
+       vector<std::string> getAudioArtist() const;
+       vector<std::string> getAudioGenre() const;
+       vector<std::string> getAudioComposer() const;
+       string getAudioCopyright() const;
+       int getAudioBitrate() const;    
+       int getAudioTrackNum() const;
+       int getAudioDuration() const;   
+       int getAudioRating() const;
+       unsigned long long getAudioSize() const;
+       
+       MediacontentLyricsPtr getAudioLyrics() const;
+
+       void setAudioAlbum(const string &value, bool isChanged=false);
+       void setAudioArtist(const vector<std::string> &value, bool isChanged=false);
+       void setAudioGenre(const vector<std::string> &value, bool isChanged=false);
+       void setAudioComposer(const vector<std::string> &value, bool isChanged=false);
+
+       void appendAudioArtist(const string &value);
+       void appendAudioGenre(const string &value);
+       void appendAudioComposer(const string &value);
+       
+       void setAudioCopyright(const string &value);
+       void setAudioBitrate(const int &value); 
+       void setAudioTrackNum(const int &value, bool isChanged=false);
+       void setAudioDuration(const int &value);        
+       void setAudioSize(const unsigned long long  &value);
+
+       void setAudioLyrics(MediacontentLyricsPtr value);
+       void setAudioLyricNonExistent();
+       //void setLyricsState(mediacontent_lyric_state value);
+       
+       bool isChangedAudioAlbum();
+       bool isChangedAudioArtist();
+       bool isChangedAudioGenre();
+       bool isChangedAudioComposer();
+       bool isChangedAudioTrackNumber();
+       mediacontent_lyric_state getLyricsState();
+
+       virtual vector<std::string>     getEditableAttr() const;
+               
+       void display() const;                   
+
+       protected:
+       string m_audioAlbum;
+       vector<std::string> m_audioArtist;
+       vector<std::string> m_audioGenre;
+       vector<std::string> m_audioAuthor;
+       string m_audioCopyright;
+       int m_audioTrackNum;
+       int m_audioDuration;
+       int m_audioBitrate;
+       unsigned long long m_audioSize;
+       bool m_isChangedAudioAlbum;
+       bool m_isChangedAudioArtist;
+       bool m_isChangedAudioGenre;
+       bool m_isChangedAudioComposer;
+       bool m_isChangedAudioTrackNumber;
+       mediacontent_lyric_state m_lyricsState;
+
+       MediacontentLyricsPtr m_lyrics;
+
+};
+
+typedef DPL::SharedPtr<MediacontentAudio> MediacontentAudioPtr;
+
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_CONTENT_AUDIO_H_ */
+
diff --git a/src/platform/API/Content/MediacontentFactory.cpp b/src/platform/API/Content/MediacontentFactory.cpp
new file mode 100755 (executable)
index 0000000..12d43e6
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// 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 "MediacontentFactory.h"
+#include <Content/MediacontentManager.h>
+
+using namespace TizenApis::Platform::Content;
+
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+IMediacontentManagerPtr MediacontentFactory::createMediacontentManagerObject()
+{
+    IMediacontentManagerPtr result(new MediacontentManager());
+    return result;
+}
+MediacontentFactory& MediacontentFactory::getInstance()
+{
+    static MediacontentFactory theInstance;
+    return theInstance;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Content/MediacontentFactory.h b/src/platform/API/Content/MediacontentFactory.h
new file mode 100755 (executable)
index 0000000..c0d8f1e
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// 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 _ABSTRACT_LAYER_CONTENT_FACTORY_H_
+#define _ABSTRACT_LAYER_CONTENT_FACTORY_H_
+
+#include "IMediacontentManager.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+       
+class MediacontentFactory : private DPL::Noncopyable
+{
+       private:
+       MediacontentFactory(){}
+
+       public:
+       static MediacontentFactory& getInstance();
+       IMediacontentManagerPtr    createMediacontentManagerObject();
+
+};
+
+}
+}
+}
+
+#endif /* WRTPLUGINSCAMERAFACTORY_H_ */
\ No newline at end of file
diff --git a/src/platform/API/Content/MediacontentFolder.cpp b/src/platform/API/Content/MediacontentFolder.cpp
new file mode 100755 (executable)
index 0000000..ce8dba8
--- /dev/null
@@ -0,0 +1,143 @@
+//
+// 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 <Commons/Exception.h>
+#include "MediacontentFolder.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+
+MediacontentFolder::MediacontentFolder()
+{
+
+}
+
+MediacontentFolder::~MediacontentFolder()
+{
+
+}
+
+
+string MediacontentFolder::getFolderUUID() const
+{
+    return m_folderUUID;
+}
+
+void MediacontentFolder::setFolderUUID(const string &value)
+{
+       m_folderUUID = value;
+}
+
+
+string MediacontentFolder::getFolderName() const
+{
+    return m_folderName;
+}
+
+void MediacontentFolder::setFolderName(const string &value)
+{
+       m_folderName = value;
+}
+
+string MediacontentFolder::getFolderPath() const
+{
+       return m_folderPath;
+
+}
+
+void MediacontentFolder::setFolderPath(const string &value)
+{
+       m_folderPath = value;
+
+}
+
+string MediacontentFolder::getFolderStorageType()
+{
+       return m_storageType;   
+}
+
+void MediacontentFolder::setFolderStorageType(const string &value)
+{
+       m_storageType = value;
+
+}
+tm MediacontentFolder::getFolderModifiedDate() const
+{
+       return m_modifiedDate;
+}
+
+MediaIdListPtr MediacontentFolder::getMediaIdList() const
+{
+       return m_mediaIdArrayPtr;
+}
+
+
+void MediacontentFolder::setFolderModifiedDate(const tm &value)
+{
+       m_modifiedDate = value;
+
+}
+
+void MediacontentFolder::setMediaIdList(const MediaIdListPtr &value)
+{
+       m_mediaIdArrayPtr = value;
+
+}
+
+
+void MediacontentFolder::insertValue(string attrName, string value)
+{
+       m_folderValue.insert(pair<string, string>(attrName,value));
+}
+
+string MediacontentFolder::findValue(string attrName)
+{
+
+       string value;
+       
+       map<string, string>::iterator pos;
+
+       pos = m_folderValue.find(attrName);
+
+       if(m_folderValue.end() != pos)
+       {
+               value = pos->second;
+       }
+       else
+       {
+               LogDebug("Attribute(" << attrName << ") There is no data.");
+       }
+       return value;
+}
+
+
+void MediacontentFolder::display() const
+{
+    LogDebug("m_folderUUID: " << m_folderUUID);
+    LogDebug("m_folderName: " << m_folderName);
+       LogDebug("m_folderPath: " << m_folderPath);
+       LogDebug("m_storageType: " << m_storageType);
+}
+
+
+}
+}
+}
diff --git a/src/platform/API/Content/MediacontentFolder.h b/src/platform/API/Content/MediacontentFolder.h
new file mode 100755 (executable)
index 0000000..910be85
--- /dev/null
@@ -0,0 +1,89 @@
+//
+// 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 _ABSTRACT_LAYER_CONTENT_FOLDER_H_
+#define _ABSTRACT_LAYER_CONTENT_FOLDER_H_
+
+#include <map>
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/optional.h>
+#include <dpl/shared_ptr.h>
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+
+typedef vector<std::string> MediaIdList;
+typedef DPL::SharedPtr<MediaIdList> MediaIdListPtr;
+
+class MediacontentFolder
+{
+       public:
+
+       MediacontentFolder();
+       virtual ~MediacontentFolder();
+
+
+       string  getFolderUUID() const;
+       string  getFolderPath() const;  
+       string  getFolderName() const;
+       string  getFolderStorageType();
+       tm      getFolderModifiedDate() const;
+       MediaIdListPtr  getMediaIdList() const; 
+
+       void setFolderUUID(const string &value);
+       void setFolderPath(const string &value);        
+       void setFolderName(const string &value);
+       void setFolderStorageType(const string &value);         
+       void setFolderModifiedDate(const tm &value);
+       void setMediaIdList(const MediaIdListPtr &value);
+
+       void insertValue(string attr, string value);
+       string findValue(string attr);
+
+       void display() const;
+
+       protected:
+
+       string  m_folderUUID;
+       string  m_folderPath;   
+       string  m_folderName;
+       string  m_storageType;          
+       tm      m_modifiedDate;
+       MediaIdListPtr m_mediaIdArrayPtr;
+
+       map<string,string> m_folderValue;
+
+};
+
+typedef DPL::SharedPtr<MediacontentFolder> MediacontentFolderPtr;
+typedef std::vector<MediacontentFolderPtr> MediacontentFolderList;
+typedef DPL::SharedPtr<MediacontentFolderList> MediacontentFolderListPtr;
+
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_CONTENT_FOLDER_H_ */
+
diff --git a/src/platform/API/Content/MediacontentImage.cpp b/src/platform/API/Content/MediacontentImage.cpp
new file mode 100755 (executable)
index 0000000..9e2b80e
--- /dev/null
@@ -0,0 +1,131 @@
+//
+// 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 <Commons/Exception.h>
+
+#include "MediacontentImage.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+MediacontentImage::MediacontentImage()
+{
+       LogDebug("enter");
+       m_editableAttrList.push_back("title");
+       m_editableAttrList.push_back("rating");
+       m_editableAttrList.push_back("description");
+       m_editableAttrList.push_back("geolocation");
+       m_editableAttrList.push_back("orientation");
+}
+
+MediacontentImage::~MediacontentImage()
+{
+       LogDebug("enter");
+}
+
+double MediacontentImage::getImageLatitude() const
+{
+       return m_imageLatitude;
+}
+
+double MediacontentImage::getImageLongitude() const
+{
+       return m_imageLongitude;        
+
+}
+
+void MediacontentImage::setImageLatitude(const double  &value, bool isChanged)
+{
+       m_imageLatitude = value;
+       m_isChangedLatitude = isChanged;
+}
+void MediacontentImage::setImageLongitude(const double  &value, bool isChanged)
+{
+       m_imageLongitude = value;
+       m_isChangedLongitude = isChanged;
+}
+
+int MediacontentImage::getImageWidth() const
+{
+       return m_imageWidth;
+
+}
+
+void MediacontentImage::setImageWidth(const int &value)
+{
+       m_imageWidth = value;
+
+}
+
+int MediacontentImage::getImageHeight() const
+{
+       return m_imageHeight;
+}
+void MediacontentImage::setImageHeight(const int &value)
+{
+       m_imageHeight = value;
+}
+
+string MediacontentImage::getImageOrientation() const
+{
+       return m_imageOrientation;
+}
+
+void MediacontentImage::setImageOrientation(const string &value, bool isChanged)
+{
+       m_imageOrientation = value;
+       m_isChangedOrientation=isChanged;
+}
+
+vector<std::string>    MediacontentImage::getEditableAttr() const
+{
+    return m_editableAttrList;
+}
+
+bool MediacontentImage::isChangedOrientaion () const
+{
+       return m_isChangedOrientation;
+}
+
+bool MediacontentImage::isChangedLatitude () const
+{
+       return m_isChangedLatitude;
+}
+
+bool MediacontentImage::isChangedLongitude() const
+{
+       return m_isChangedLongitude;
+}
+
+void MediacontentImage::display()
+{
+       MediacontentMedia::display();
+       LogDebug("m_imageWidth : " << m_imageWidth);
+       LogDebug("m_imageHeight : " << m_imageHeight);
+       LogDebug("m_imageOrientation : " << m_imageOrientation);
+       LogDebug("m_imageLongitude : " << m_imageLongitude);
+       LogDebug("m_imageLatitude : " << m_imageLatitude);      
+
+}
+
+
+}
+}
+}
diff --git a/src/platform/API/Content/MediacontentImage.h b/src/platform/API/Content/MediacontentImage.h
new file mode 100755 (executable)
index 0000000..009ff4c
--- /dev/null
@@ -0,0 +1,85 @@
+//
+// 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 _ABSTRACT_LAYER_CONTENT_IMAGE_H_
+#define _ABSTRACT_LAYER_CONTENT_IMAGE_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/optional.h>
+#include <dpl/shared_ptr.h>
+#include "MediacontentMedia.h"
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+class MediacontentImage : public MediacontentMedia
+{
+       public:
+
+       MediacontentImage();
+       virtual         ~MediacontentImage();
+
+       int getImageWidth() const;
+       int getImageHeight() const;
+       string getImageOrientation() const;
+       double getImageLatitude() const;
+       double getImageLongitude() const;
+
+
+       void setImageWidth(const int &value);   
+       void setImageHeight(const int &value);  
+       void setImageOrientation(const string &value, bool isChanged=false);
+       void setImageLatitude(const double &value, bool isChanged=false);
+       void setImageLongitude(const double &value, bool isChanged=false);      
+
+       bool isChangedOrientaion() const;
+       bool isChangedLatitude() const;
+       bool isChangedLongitude() const;
+
+       void display();
+       
+       virtual vector<std::string>     getEditableAttr() const;
+       
+
+       protected:
+       int m_imageWidth;
+       int m_imageHeight;
+       string m_imageOrientation;              
+       double m_imageLongitude;
+       double m_imageLatitude; 
+
+       bool m_isChangedOrientation;
+       bool m_isChangedLatitude;
+       bool m_isChangedLongitude;
+
+};
+
+typedef DPL::SharedPtr<MediacontentImage> MediacontentImagePtr;
+
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_CONTENT_MEDIA_H_ */
+
diff --git a/src/platform/API/Content/MediacontentLyrics.cpp b/src/platform/API/Content/MediacontentLyrics.cpp
new file mode 100755 (executable)
index 0000000..d5508aa
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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 <Commons/Exception.h>
+#include "MediacontentLyrics.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+MediacontentLyrics::MediacontentLyrics()
+{
+}
+
+MediacontentLyrics::~MediacontentLyrics()
+{
+}
+
+
+string MediacontentLyrics::getMediaLyricsType() const
+{
+       return m_lyricsType;
+}
+
+void MediacontentLyrics::setMediaLyricsType(string value)
+{
+       m_lyricsType = value;
+}
+
+vector<unsigned long> MediacontentLyrics::getMediaLyricsTimeStamps() const
+{
+       return m_timeStamps;
+}
+
+void MediacontentLyrics::addMediaLyricsTimeStamp(unsigned long value)
+{
+       m_timeStamps.push_back(value);
+}
+
+vector<string> MediacontentLyrics::getMediaLyricsTexts() const
+{
+       return m_texts;
+}
+
+void MediacontentLyrics::addMediaLyricsText(string value)
+{
+       m_texts.push_back(value);
+}
+
+
+}
+}
+}
diff --git a/src/platform/API/Content/MediacontentLyrics.h b/src/platform/API/Content/MediacontentLyrics.h
new file mode 100755 (executable)
index 0000000..b73bdad
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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 _ABSTRACT_LAYER_CONTENT_LYRICS_H_
+#define _ABSTRACT_LAYER_CONTENT_LYRICS_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/optional.h>
+#include <dpl/shared_ptr.h>
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+
+class MediacontentLyrics
+{
+       
+       public:
+
+       MediacontentLyrics();
+       virtual ~MediacontentLyrics();
+
+       string getMediaLyricsType() const;
+       vector<string> getMediaLyricsTexts() const;
+       vector<unsigned long> getMediaLyricsTimeStamps() const; 
+       
+       void setMediaLyricsType(string value);
+       void addMediaLyricsText(string value);
+       void addMediaLyricsTimeStamp(unsigned long value);      
+       
+       private:
+       string m_lyricsType;
+       vector<unsigned long> m_timeStamps;
+       vector<string> m_texts;
+       
+};
+
+
+typedef DPL::SharedPtr<MediacontentLyrics> MediacontentLyricsPtr;
+
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_CONTENT_LYRICS_H_ */
+
diff --git a/src/platform/API/Content/MediacontentMedia.cpp b/src/platform/API/Content/MediacontentMedia.cpp
new file mode 100755 (executable)
index 0000000..68991f7
--- /dev/null
@@ -0,0 +1,230 @@
+//
+// 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 <Commons/Exception.h>
+#include "MediacontentMedia.h"
+#include <aul/aul.h>
+
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+MediacontentMedia::MediacontentMedia()
+{
+       m_isChangedFavorite = false;
+       m_isChangedDisplayName = false;
+
+       m_size = 0;
+       m_rating = 0;
+       m_favorite = false;  //unused.
+}
+
+MediacontentMedia::~MediacontentMedia()
+{
+}
+
+string MediacontentMedia::getMediaUUID() const
+{
+       return m_mediaUUID;
+}
+
+void MediacontentMedia::setMediaUUID(const string &value)
+{
+       m_mediaUUID = value;
+}
+
+string MediacontentMedia::getMimeType()
+{
+       LogDebug("MediacontentMedia::getMimeType");             
+       return m_mimeType;
+}
+
+string MediacontentMedia::getDisplayName() const
+{
+    return m_displayName;
+}
+
+void MediacontentMedia::setMimeType(const string &value)
+{
+       m_mimeType = value;
+}
+
+void MediacontentMedia::setDisplayName(const string &value, bool isChanged)
+{
+       m_displayName = value;
+       if (isChanged)
+               m_isChangedDisplayName = true;
+}
+
+string MediacontentMedia::getFilePath() const
+{
+       return m_filePath;
+
+}
+
+void MediacontentMedia::setFilePath(const string &value)
+{
+       m_filePath = value;
+
+}
+
+string MediacontentMedia::getThumbnailPath() const
+{
+       return m_thumbnailPath;
+}
+
+
+tm MediacontentMedia::getCreatedDate() const
+{
+       return m_createdDate;
+}
+
+tm MediacontentMedia::getReleasedDate() const
+{
+       return m_releasedDate;
+}
+
+void MediacontentMedia::setThumbnailPath(const string &value)
+{
+       m_thumbnailPath = value;
+
+}
+tm MediacontentMedia::getModifiedDate() const
+{
+       return m_modifiedDate;
+}
+
+void MediacontentMedia::setCreatedDate(const tm &value)
+{
+       m_createdDate = value;
+
+}
+
+void MediacontentMedia::setReleasedDate(const tm &value)
+{
+       m_releasedDate = value;
+
+}
+
+void MediacontentMedia::setModifiedDate(const tm &value)
+{
+       m_modifiedDate = value;
+
+}
+bool MediacontentMedia::getFavorite() const
+{
+       return m_favorite;
+}
+void MediacontentMedia::setFavorite(bool value)
+{
+       m_favorite = value;
+       m_isChangedFavorite = true;
+
+}
+string MediacontentMedia::getMediaType() const
+{
+       return m_mediaType;
+}
+
+void MediacontentMedia::setMediaType(const string &value) 
+{
+       m_mediaType = value;
+}
+
+void MediacontentMedia::display() const
+{
+
+       LogDebug("m_mediaUUID : " << m_mediaUUID);
+       LogDebug("m_mediaType : " << m_mediaType);
+//     LogDebug("m_mimeType : " << m_mimeType);
+       LogDebug("m_displayName : " << m_displayName);
+       LogDebug("m_filePath : " << m_filePath);
+       LogDebug("m_thumbnailPath : " << m_thumbnailPath);
+       LogDebug("m_description : " << m_description);
+//     LogDebug("m_createdDate : " << m_createdDate);
+//     LogDebug("m_releasedDate : " << m_releasedDate);
+//     LogDebug("m_modifiedDate : " << m_modifiedDate);
+       LogDebug("m_favorite : " << m_favorite);
+       
+
+}
+string MediacontentMedia::getDescription() const
+{
+       return m_description;
+}
+
+void MediacontentMedia::setDescription(const string &value, bool isChanged)
+{
+       m_description = value;
+       if ( isChanged )
+               m_isChangedDescription = true;
+       
+}
+
+bool MediacontentMedia::getIsChangedFavorite() const
+{
+       return m_isChangedFavorite;
+}
+
+bool MediacontentMedia::isChangedRating() const
+{
+       return m_isChangedRating;
+}
+
+bool MediacontentMedia::isChangedDisplayName() const
+{
+       return m_isChangedDisplayName;
+}
+
+bool MediacontentMedia::isChangedDescription() const
+{
+       return m_isChangedDescription;
+}
+
+vector<std::string>    MediacontentMedia::getEditableAttr() const
+{
+    return m_editableAttrList;
+}
+
+void MediacontentMedia::setSize(unsigned long long value)
+{
+       m_size = value;
+}
+
+unsigned long long MediacontentMedia::getSize() const
+{
+       return m_size;
+}
+
+void MediacontentMedia::setRating(int value, bool isChanged)
+{
+       m_rating = value;
+       if ( isChanged )
+               m_isChangedRating = true;
+}
+
+int MediacontentMedia::getRating() const
+{
+       return m_rating;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Content/MediacontentMedia.h b/src/platform/API/Content/MediacontentMedia.h
new file mode 100755 (executable)
index 0000000..f2e95ae
--- /dev/null
@@ -0,0 +1,127 @@
+//
+// 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 _ABSTRACT_LAYER_CONTENT_MEDIA_H_
+#define _ABSTRACT_LAYER_CONTENT_MEDIA_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/optional.h>
+#include <dpl/shared_ptr.h>
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+typedef enum 
+{
+       MEDIA_TYPE_IMAGE        = 1,
+       MEDIA_TYPE_VIDEO        = 2,
+       MEDIA_TYPE_AUDIO        = 3,
+       MEDIA_TYPE_UNKOWN       = 4,
+}media_type;
+
+
+typedef vector<std::string> EditableAttributeList;
+typedef DPL::SharedPtr<EditableAttributeList> EditableAttributeListPtr;
+
+typedef vector<std::string> StringArray;
+typedef DPL::SharedPtr<StringArray> StringArrayPtr;
+
+class MediacontentMedia
+{
+       public:
+
+       MediacontentMedia();
+       virtual ~MediacontentMedia();
+
+       virtual string getMediaUUID() const;
+       virtual string getMediaType() const;
+       virtual string getMimeType();
+       virtual string getDisplayName() const;
+       virtual string getFilePath() const;
+       virtual string getThumbnailPath() const;
+       virtual tm getCreatedDate() const;
+       virtual tm getReleasedDate() const;
+       virtual tm getModifiedDate() const;
+       virtual string getDescription() const;  
+       virtual bool getFavorite() const;
+       virtual unsigned long long getSize() const;
+       virtual int getRating() const;
+
+       bool getIsChangedFavorite() const;
+       bool isChangedRating() const;
+       bool isChangedDisplayName() const;
+       bool isChangedDescription() const;
+
+       virtual void setMediaUUID(const string &value);
+       virtual void setMediaType(const string &value);
+       virtual void setMimeType(const string &value);
+       virtual void setDisplayName(const string &value, bool isChanged=false); //title
+       virtual void setFilePath(const string &value);  
+       virtual void setThumbnailPath(const string &value);     
+       virtual void setCreatedDate(const tm &value);
+       virtual void setReleasedDate(const tm &value);
+       virtual void setModifiedDate(const tm &value);  
+       virtual void setFavorite( bool value);
+       virtual void setDescription(const string &value, bool isChanged=false);
+       virtual void setSize(unsigned long long value);
+       virtual void setRating(int value, bool isChanged=false);
+
+       void display() const;
+       virtual vector<std::string>     getEditableAttr() const;
+
+       private:
+       string m_mediaUUID;
+       string m_mediaType;
+       string m_mimeType;
+       string m_displayName;
+       string m_filePath;
+       string m_thumbnailPath;
+       string m_description;
+       tm m_createdDate;
+       tm m_releasedDate;
+       tm m_modifiedDate;
+       unsigned long long m_size;
+       int m_rating;
+       bool m_favorite;  //unused.
+       bool m_isChangedFavorite;
+       bool m_isChangedRating;
+       bool m_isChangedDisplayName;
+       bool m_isChangedDescription;
+       
+       protected:
+       vector<std::string> m_editableAttrList;
+
+};
+
+
+typedef DPL::SharedPtr<MediacontentMedia> MediacontentMediaPtr;
+typedef std::vector<MediacontentMediaPtr> MediacontentMediaList;
+typedef DPL::SharedPtr<MediacontentMediaList> MediacontentMediaListPtr;
+
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_CONTENT_MEDIA_H_ */
+
diff --git a/src/platform/API/Content/MediacontentVideo.cpp b/src/platform/API/Content/MediacontentVideo.cpp
new file mode 100755 (executable)
index 0000000..750c05d
--- /dev/null
@@ -0,0 +1,167 @@
+//
+// 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 <Commons/Exception.h>
+#include "MediacontentVideo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+
+MediacontentVideo::MediacontentVideo()
+{
+       m_editableAttrList.push_back("title");
+       m_editableAttrList.push_back("rating");
+       m_editableAttrList.push_back("description");
+       m_editableAttrList.push_back("geolocation");
+
+}
+
+MediacontentVideo::~MediacontentVideo()
+{
+}
+
+int MediacontentVideo::getVideoDuration() const
+{
+       return m_videoDuration;
+
+}
+
+int MediacontentVideo::getVideoWidth() const
+{
+       return m_videoWidth;
+
+}
+
+int MediacontentVideo::getVideoHeight() const
+{
+       return m_videoHeight;
+}
+
+double MediacontentVideo::getVideoLatitude() const
+{
+       return m_videoLatitude;
+}
+
+double MediacontentVideo::getVideoLongitude() const
+{
+       return m_videoLongitude;        
+
+}
+
+string MediacontentVideo::getVideoAlbum() const
+{
+    return m_videoAlbum;
+}
+
+vector<std::string> MediacontentVideo::getVideoArtist() const
+{
+    return m_videoArtist;
+}
+
+
+void MediacontentVideo::setVideoDuration(const int &value)
+{
+       m_videoDuration = value;
+}
+
+void MediacontentVideo::setVideoWidth(const int &value)
+{
+       m_videoWidth = value;
+
+}
+
+void MediacontentVideo::setVideoHeight(const int &value)
+{
+       m_videoHeight = value;
+
+}
+
+void MediacontentVideo::setVideoLatitude(const double  &value, bool isChanged)
+{
+       m_videoLatitude = value;
+       m_isChangedLatitude =isChanged;
+}
+
+void MediacontentVideo::setVideoLongitude(const double  &value, bool isChanged)
+{
+       m_videoLongitude = value;
+       m_isChangedLongitude=isChanged;
+}
+
+void MediacontentVideo::setVideoAlbum(const string &value, bool isChanged)
+{
+       m_videoAlbum = value;
+       m_isChangedAlbum=isChanged;
+}
+
+void MediacontentVideo::setVideoArtist(const vector<std::string> &value, bool isChanged)
+{
+       m_videoArtist = value;
+       m_isChangedArtists=isChanged;
+}
+
+void MediacontentVideo::appendVideoArtist(const string value)
+{
+       m_videoArtist.push_back(value);
+}
+
+bool MediacontentVideo::isChangedArtists()
+{
+       return m_isChangedArtists;
+}
+
+bool MediacontentVideo::isChangedAlbum()
+{
+       return m_isChangedAlbum;
+}
+
+bool MediacontentVideo::isChangedLatitude()
+{
+       return m_isChangedLatitude;
+}
+
+bool MediacontentVideo::isChangedLongitude()
+{
+       return m_isChangedLongitude;
+}
+
+vector<std::string> MediacontentVideo::getEditableAttr() const
+{
+    return m_editableAttrList;
+}
+
+void MediacontentVideo::display() const
+{
+
+       LogDebug("m_videoLongitude: " << m_videoLongitude;);
+    LogDebug("m_videoLatitude:  " << m_videoLatitude); 
+    LogDebug("m_videoAlbum: " << m_videoAlbum;);
+       //LogDebug("m_videoArtist:       " << m_videoArtist);
+       //LogDebug("m_videoPlayedTime: " << m_videoPlayedTime);
+       LogDebug("m_videoDuration: " << m_videoDuration);
+       LogDebug("m_videoWidth: " << m_videoWidth);
+       LogDebug("m_videoHeight: " << m_videoHeight);   
+       MediacontentMedia::display();
+}
+
+}
+}
+}
diff --git a/src/platform/API/Content/MediacontentVideo.h b/src/platform/API/Content/MediacontentVideo.h
new file mode 100755 (executable)
index 0000000..ad1bfda
--- /dev/null
@@ -0,0 +1,89 @@
+//
+// 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 _ABSTRACT_LAYER_CONTENT_VIDEO_H_
+#define _ABSTRACT_LAYER_CONTENT_VIDEO_H_
+
+#include <ctime>
+#include <string>
+#include <vector>
+#include <dpl/optional.h>
+#include <dpl/shared_ptr.h>
+#include "MediacontentMedia.h"
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Content {
+
+class MediacontentVideo : public MediacontentMedia
+{
+       public:
+
+       MediacontentVideo();
+       virtual ~MediacontentVideo();
+
+       int getVideoDuration() const;
+       int getVideoWidth() const;
+       int getVideoHeight() const;
+       double getVideoLatitude() const;
+       double getVideoLongitude() const;
+       string getVideoAlbum() const;
+       vector<std::string> getVideoArtist() const;
+       void setVideoDuration(const int &value);                
+       void setVideoWidth(const int &value);   
+       void setVideoHeight(const int &value);  
+       void setVideoLatitude(const double &value, bool isChanged=false);
+       void setVideoLongitude(const double &value, bool isChanged=false);      
+       void setVideoAlbum(const string &value, bool isChanged=false);  
+       void setVideoArtist(const vector<std::string> &value, bool isChanged=false);
+       void appendVideoArtist(const string value);
+
+       bool isChangedArtists();
+       bool isChangedAlbum();
+       bool isChangedLatitude();
+       bool isChangedLongitude();
+
+       virtual vector<std::string> getEditableAttr() const;
+
+       void display() const;   
+
+       private:
+       double  m_videoLongitude;
+       double m_videoLatitude; 
+       string m_videoAlbum;
+       vector<std::string> m_videoArtist;
+       int m_videoDuration;
+       int m_videoWidth;
+       int m_videoHeight;
+       bool m_isChangedArtists;
+       bool m_isChangedAlbum;
+       bool m_isChangedLatitude;
+       bool m_isChangedLongitude;
+       
+};
+
+typedef DPL::SharedPtr<MediacontentVideo> MediacontentVideoPtr;
+
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_CONTENT_VIDEO_H_ */
+
diff --git a/src/platform/API/Content/config.cmake b/src/platform/API/Content/config.cmake
new file mode 100755 (executable)
index 0000000..0378f51
--- /dev/null
@@ -0,0 +1,28 @@
+get_current_path()
+
+pkg_search_module(mm-fileinfo REQUIRED mm-fileinfo)
+pkg_search_module(aul REQUIRED aul)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_CONTENT
+  ${mm-fileinfo_INCLUDE_DIRS}
+  ${aul_INCLUDE_DIRS}  
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_CONTENT
+  ${mm-fileinfo_LIBRARIES}  
+  ${aul_LIBRARIES}  
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_API_CONTENT
+  ${CURRENT_PATH}/MediacontentFactory.cpp
+  ${CURRENT_PATH}/MediacontentMedia.cpp
+  ${CURRENT_PATH}/MediacontentFolder.cpp  
+  ${CURRENT_PATH}/MediacontentImage.cpp  
+  ${CURRENT_PATH}/MediacontentVideo.cpp    
+  ${CURRENT_PATH}/MediacontentAudio.cpp   
+  ${CURRENT_PATH}/IMediacontentManager.cpp
+  ${CURRENT_PATH}/MediacontentLyrics.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Download/DownloadRequest.cpp b/src/platform/API/Download/DownloadRequest.cpp
new file mode 100644 (file)
index 0000000..cd28574
--- /dev/null
@@ -0,0 +1,86 @@
+//
+// 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 <Commons/Exception.h>
+#include "DownloadRequest.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+DownloadRequest::DownloadRequest():
+    m_url(""),
+    m_destination(""),
+    m_fileName("")
+{
+}
+
+DownloadRequest::DownloadRequest(std::string url, std::string destination, std::string fileName)
+{
+    m_url = url;
+    m_destination = destination;
+    m_fileName = fileName;
+}
+
+DownloadRequest::~DownloadRequest()
+{
+}
+
+std::string DownloadRequest::getUrl() const
+{
+    return m_url;
+}
+
+void DownloadRequest::setUrl(std::string url)
+{
+    m_url = url;
+}
+
+std::string DownloadRequest::getDestination() const
+{
+    return m_destination;
+}
+
+void DownloadRequest::setDestination(std::string destination)
+{
+    m_destination = destination;
+}
+
+std::string DownloadRequest::getDestinationFullPath() const
+{
+    return m_destination_fullpath;
+}
+
+void DownloadRequest::setDestinationFullPath(std::string destination_fullpath)
+{
+    m_destination_fullpath = destination_fullpath;
+}
+
+std::string DownloadRequest::getFileName() const
+{
+    return m_fileName;
+}
+
+void DownloadRequest::setFileName(std::string fileName)
+{
+    m_fileName = fileName;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Download/DownloadRequest.h b/src/platform/API/Download/DownloadRequest.h
new file mode 100644 (file)
index 0000000..d85259f
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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 _ABSTRACT_LAYER_DOWNLOAD_REQUEST_H_
+#define _ABSTRACT_LAYER_DOWNLOAD_REQUEST_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+class DownloadRequest
+{
+  public:
+
+    DownloadRequest();
+    DownloadRequest(std::string url, std::string destination, std::string fileName);
+    virtual ~DownloadRequest();
+
+    std::string getUrl() const;
+    void setUrl(std::string value);
+
+    std::string getDestination() const;
+    void setDestination(std::string value);
+
+    std::string getDestinationFullPath() const;
+    void setDestinationFullPath(std::string value);
+
+    std::string getFileName() const;
+    void setFileName(std::string value);
+
+  protected:
+    std::string m_url;
+    std::string m_destination;
+    std::string m_destination_fullpath;
+    std::string m_fileName;
+};
+
+typedef DPL::SharedPtr<DownloadRequest> DownloadRequestPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_DOWNLOAD_REQUEST_H_ */
+
diff --git a/src/platform/API/Download/IDownloadManager.cpp b/src/platform/API/Download/IDownloadManager.cpp
new file mode 100755 (executable)
index 0000000..8098d19
--- /dev/null
@@ -0,0 +1,84 @@
+//
+// 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 "IDownloadManager.h"
+#include <Commons/ThreadPool.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+IDownloadManager::IDownloadManager() :
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventStartDownload >(WrtDeviceApis::Commons::ThreadEnum::DOWNLOAD_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventCancelDownload >(WrtDeviceApis::Commons::ThreadEnum::DOWNLOAD_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventPauseDownload >(WrtDeviceApis::Commons::ThreadEnum::DOWNLOAD_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventResumeDownload >(WrtDeviceApis::Commons::ThreadEnum::DOWNLOAD_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventGetState >(WrtDeviceApis::Commons::ThreadEnum::DOWNLOAD_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventGetDownloadRequest >(WrtDeviceApis::Commons::ThreadEnum::DOWNLOAD_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventGetMIMEType >(WrtDeviceApis::Commons::ThreadEnum::DOWNLOAD_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventSetListener >(WrtDeviceApis::Commons::ThreadEnum::DOWNLOAD_THREAD)
+{
+}
+
+IDownloadManager::~IDownloadManager()
+{
+}
+
+void IDownloadManager::startDownload(const IEventStartDownloadPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventStartDownload>::PostRequest(event);
+}
+
+void IDownloadManager::cancelDownload(const IEventCancelDownloadPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventCancelDownload>::PostRequest(event);
+}
+
+void IDownloadManager::pauseDownload(const IEventPauseDownloadPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventPauseDownload>::PostRequest(event);
+}
+
+void IDownloadManager::resumeDownload(const IEventResumeDownloadPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventResumeDownload>::PostRequest(event);
+}
+
+void IDownloadManager::getState(const IEventGetStatePtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventGetState>::PostRequest(event);
+}
+
+void IDownloadManager::getDownloadRequest(const IEventGetDownloadRequestPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventGetDownloadRequest>::PostRequest(event);
+}
+
+void IDownloadManager::getMIMEType(const IEventGetMIMETypePtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventGetMIMEType>::PostRequest(event);
+}
+
+void IDownloadManager::setListener(const IEventSetListenerPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventSetListener>::PostRequest(event);
+}
+
+}
+}
+}
diff --git a/src/platform/API/Download/IDownloadManager.h b/src/platform/API/Download/IDownloadManager.h
new file mode 100755 (executable)
index 0000000..af5238d
--- /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.
+//
+
+
+#ifndef _ABSTRACT_LAYER_IDOWNLOAD_MANAGER_H_
+#define _ABSTRACT_LAYER_IDOWNLOAD_MANAGER_H_
+
+#include "IEventStartDownload.h"
+#include "IEventCancelDownload.h"
+#include "IEventPauseDownload.h"
+#include "IEventResumeDownload.h"
+#include "IEventGetState.h"
+#include "IEventGetDownloadRequest.h"
+#include "IEventGetMIMEType.h"
+#include "IEventSetListener.h"
+#include "OnDownloadStateChanged.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+#define TIZEN_ENUM_DOWNLOAD_STATE_QUEUED        "QUEUED"
+#define TIZEN_ENUM_DOWNLOAD_STATE_DOWNLOADING   "DOWNLOADING"
+#define TIZEN_ENUM_DOWNLOAD_STATE_PAUSED        "PAUSED"
+#define TIZEN_ENUM_DOWNLOAD_STATE_CANCELED      "CANCELED"
+#define TIZEN_ENUM_DOWNLOAD_STATE_COMPLETED     "COMPLETED"
+#define TIZEN_ENUM_DOWNLOAD_STATE_FAILED        "FAILED"
+
+class IDownloadManager : public WrtDeviceApis::Commons::EventRequestReceiver< IEventStartDownload >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventCancelDownload >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventPauseDownload >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventResumeDownload >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventGetState >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventGetDownloadRequest >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventGetMIMEType >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventSetListener >
+{
+  public:
+    IDownloadManager();
+    virtual ~IDownloadManager();
+    virtual void startDownload(const IEventStartDownloadPtr &event);
+    virtual void cancelDownload(const IEventCancelDownloadPtr &event);
+    virtual void pauseDownload(const IEventPauseDownloadPtr &event);
+    virtual void resumeDownload(const IEventResumeDownloadPtr &event);
+    virtual void getState(const IEventGetStatePtr &event);
+    virtual void getDownloadRequest(const IEventGetDownloadRequestPtr &event);
+    virtual void getMIMEType(const IEventGetMIMETypePtr &event);
+    virtual void setListener(const IEventSetListenerPtr &event);
+
+  protected:
+    virtual void OnRequestReceived(const IEventStartDownloadPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventCancelDownloadPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventPauseDownloadPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventResumeDownloadPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventGetStatePtr &event) = 0;
+    virtual void OnRequestReceived(const IEventGetDownloadRequestPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventGetMIMETypePtr &event) = 0;
+    virtual void OnRequestReceived(const IEventSetListenerPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<IDownloadManager> IDownloadManagerPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_IDOWNLOAD_MANAGER_H_ */
diff --git a/src/platform/API/Download/IEventCancelDownload.h b/src/platform/API/Download/IEventCancelDownload.h
new file mode 100644 (file)
index 0000000..b491b3e
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_CANCEL_DOWNLOAD_H_
+#define _ABSTRACT_LAYER_IEVENT_CANCEL_DOWNLOAD_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+class IEventCancelDownload : public WrtDeviceApis::Commons::IEvent<IEventCancelDownload>
+{
+    long m_downloadId;
+    bool m_result;
+
+    public:
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    void setDownloadId(long value)
+    {
+        m_downloadId = value;
+    }
+    long getDownloadId() const
+    {
+        return m_downloadId;
+    }
+
+    IEventCancelDownload() : m_downloadId(-1),
+        m_result(false)
+    {
+    }
+    ~IEventCancelDownload()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventCancelDownload> IEventCancelDownloadPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_CANCEL_DOWNLOAD_H_ */
diff --git a/src/platform/API/Download/IEventGetDownloadRequest.h b/src/platform/API/Download/IEventGetDownloadRequest.h
new file mode 100644 (file)
index 0000000..a3f73bc
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_GET_DOWNLOAD_REQUEST_H_
+#define _ABSTRACT_LAYER_IEVENT_GET_DOWNLOAD_REQUEST_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <string>
+#include "DownloadRequest.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+class IEventGetDownloadRequest : public WrtDeviceApis::Commons::IEvent<IEventGetDownloadRequest>
+{
+    long m_downloadId;
+    DownloadRequestPtr m_downloadRequest;
+    bool m_result;
+
+  public:
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    void setDownloadId(long value)
+    {
+        m_downloadId = value;
+    }
+    long getDownloadId() const
+    {
+        return m_downloadId;
+    }
+
+    void setDownloadRequest(DownloadRequestPtr value)
+    {
+        m_downloadRequest = value;
+    }
+    DownloadRequestPtr getDownloadRequest() const
+    {
+        return m_downloadRequest;
+    }
+
+    IEventGetDownloadRequest() : m_downloadId(-1),
+        m_downloadRequest(NULL),
+        m_result(false)
+    {
+    }
+    ~IEventGetDownloadRequest()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventGetDownloadRequest> IEventGetDownloadRequestPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_GET_DOWNLOAD_REQUEST_H_ */
diff --git a/src/platform/API/Download/IEventGetMIMEType.h b/src/platform/API/Download/IEventGetMIMEType.h
new file mode 100644 (file)
index 0000000..66430de
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_GET_MIME_TYPE_H_
+#define _ABSTRACT_LAYER_IEVENT_GET_MIME_TYPE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+class IEventGetMIMEType : public WrtDeviceApis::Commons::IEvent<IEventGetMIMEType>
+{
+    long m_downloadId;
+    std::string m_MIMEType;
+    bool m_result;
+
+  public:
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    void setDownloadId(long value)
+    {
+        m_downloadId = value;
+    }
+    long getDownloadId() const
+    {
+        return m_downloadId;
+    }
+
+    void setMIMEType(std::string value)
+    {
+        m_MIMEType = value;
+    }
+    std::string getMIMEType() const
+    {
+        return m_MIMEType;
+    }
+
+    IEventGetMIMEType() : m_downloadId(-1),
+        m_MIMEType(""),
+        m_result(false)
+    {
+    }
+    ~IEventGetMIMEType()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventGetMIMEType> IEventGetMIMETypePtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_GET_MIME_TYPE_H_ */
diff --git a/src/platform/API/Download/IEventGetState.h b/src/platform/API/Download/IEventGetState.h
new file mode 100755 (executable)
index 0000000..d8b1381
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_GET_STATE_H_
+#define _ABSTRACT_LAYER_IEVENT_GET_STATE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+class IEventGetState : public WrtDeviceApis::Commons::IEvent<IEventGetState>
+{
+    long m_downloadId;
+    std::string m_downloadState;
+    bool m_result;
+
+  public:
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    void setDownloadId(long value)
+    {
+        m_downloadId = value;
+    }
+    long getDownloadId() const
+    {
+        return m_downloadId;
+    }
+
+    void setDownloadState(std::string value)
+    {
+        m_downloadState = value;
+    }
+    std::string getDownloadState() const
+    {
+        return m_downloadState;
+    }
+
+    IEventGetState() : m_downloadId(-1),
+        m_downloadState(""),
+        m_result(false)
+    {
+    }
+    ~IEventGetState()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventGetState> IEventGetStatePtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_GET_STATE_H_ */
diff --git a/src/platform/API/Download/IEventPauseDownload.h b/src/platform/API/Download/IEventPauseDownload.h
new file mode 100755 (executable)
index 0000000..59052cd
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_PAUSE_DOWNLOAD_H_
+#define _ABSTRACT_LAYER_IEVENT_PAUSE_DOWNLOAD_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+class IEventPauseDownload : public WrtDeviceApis::Commons::IEvent<IEventPauseDownload>
+{
+    long m_downloadId;
+    bool m_result;
+
+    public:
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    void setDownloadId(long value)
+    {
+        m_downloadId = value;
+    }
+    long getDownloadId() const
+    {
+        return m_downloadId;
+    }
+
+    IEventPauseDownload() : m_downloadId(-1),
+        m_result(false)
+    {
+    }
+    ~IEventPauseDownload()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventPauseDownload> IEventPauseDownloadPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_PAUSE_DOWNLOAD_H_ */
diff --git a/src/platform/API/Download/IEventResumeDownload.h b/src/platform/API/Download/IEventResumeDownload.h
new file mode 100755 (executable)
index 0000000..4a4a127
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_RESUME_DOWNLOAD_H_
+#define _ABSTRACT_LAYER_IEVENT_RESUME_DOWNLOAD_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+class IEventResumeDownload : public WrtDeviceApis::Commons::IEvent<IEventResumeDownload>
+{
+    long m_downloadId;
+    bool m_result;
+
+    public:
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    void setDownloadId(long value)
+    {
+        m_downloadId = value;
+    }
+    long getDownloadId() const
+    {
+        return m_downloadId;
+    }
+
+    IEventResumeDownload() : m_downloadId(-1),
+        m_result(false)
+    {
+    }
+    ~IEventResumeDownload()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventResumeDownload> IEventResumeDownloadPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_RESUME_DOWNLOAD_H_ */
diff --git a/src/platform/API/Download/IEventSetListener.h b/src/platform/API/Download/IEventSetListener.h
new file mode 100755 (executable)
index 0000000..add87c6
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_SET_DOWNLOAD_LISTENER_H_
+#define _ABSTRACT_LAYER_IEVENT_SET_DOWNLOAD_LISTENER_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "OnDownloadStateChanged.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+class IEventSetListener : public WrtDeviceApis::Commons::IEvent<IEventSetListener>
+{
+    long m_downloadId;
+    bool m_result;
+    OnDownloadStateChangedEmitterPtr m_emitter;
+
+  public:
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    void setDownloadId(long value)
+    {
+        m_downloadId = value;
+    }
+    long getDownloadId() const
+    {
+        return m_downloadId;
+    }
+
+    void setEmitter(OnDownloadStateChangedEmitterPtr value)
+    {
+        m_emitter = value;
+    }
+    OnDownloadStateChangedEmitterPtr getEmitter() const
+    {
+        return m_emitter;
+    }
+
+    IEventSetListener() : m_downloadId(-1),
+        m_result(false),
+        m_emitter(NULL)
+    {
+    }
+    ~IEventSetListener()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventSetListener> IEventSetListenerPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_SET_DOWNLOAD_LISTENER_H_ */
diff --git a/src/platform/API/Download/IEventStartDownload.h b/src/platform/API/Download/IEventStartDownload.h
new file mode 100755 (executable)
index 0000000..830c273
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_START_DOWNLOAD_H_
+#define _ABSTRACT_LAYER_IEVENT_START_DOWNLOAD_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "DownloadRequest.h"
+#include "OnDownloadStateChanged.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+class IEventStartDownload : public WrtDeviceApis::Commons::IEvent<IEventStartDownload>
+{
+    DownloadRequestPtr m_downloadRequest;
+    long m_downloadId;
+    bool m_result;
+    OnDownloadStateChangedEmitterPtr m_emitter;
+
+  public:
+    void setResult(bool value)
+    {
+        m_result = value;
+    }
+    bool getResult() const
+    {
+        return m_result;
+    }
+
+    void setDownloadRequest(DownloadRequestPtr value)
+    {
+        m_downloadRequest = value;
+    }
+    DownloadRequestPtr getDownloadRequest() const
+    {
+        return m_downloadRequest;
+    }
+
+    void setDownloadId(long value)
+    {
+        m_downloadId = value;
+    }
+    long getDownloadId() const
+    {
+        return m_downloadId;
+    }
+
+    void setEmitter(OnDownloadStateChangedEmitterPtr value)
+    {
+        m_emitter = value;
+    }
+    OnDownloadStateChangedEmitterPtr getEmitter() const
+    {
+        return m_emitter;
+    }
+
+    IEventStartDownload() : m_downloadRequest(NULL),
+        m_downloadId(-1),
+        m_result(false),
+        m_emitter(NULL)
+    {
+    }
+    ~IEventStartDownload()
+    {
+    }
+};
+
+typedef DPL::SharedPtr<IEventStartDownload> IEventStartDownloadPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_START_DOWNLOAD_H_ */
diff --git a/src/platform/API/Download/OnDownloadStateChanged.h b/src/platform/API/Download/OnDownloadStateChanged.h
new file mode 100755 (executable)
index 0000000..748dea8
--- /dev/null
@@ -0,0 +1,126 @@
+//
+// 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 _ON_DOWNLOAD_STATE_CHANGED_H_
+#define _ON_DOWNLOAD_STATE_CHANGED_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/Emitters.h>
+#include "DownloadRequest.h"
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Download {
+
+class OnDownloadStateChanged : public WrtDeviceApis::Commons::ListenerEvent<OnDownloadStateChanged>
+{
+    public:
+
+    OnDownloadStateChanged(){
+        m_downloadId = -1;
+        m_downloadState = "";
+        m_fullPath = "";
+        m_receivedSize = 0;
+        m_totalSize = 0;
+        m_errorMessage = "";
+    }
+    ~OnDownloadStateChanged() {
+    }
+
+    void setResult (bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    void setDownloadId(long value)
+    {
+        m_downloadId = value;
+    }
+    long getDownloadId() const
+    {
+        return m_downloadId;
+    }
+
+    void setDownloadState(std::string value)
+    {
+        m_downloadState = value;
+    }
+    std::string getDownloadState() const
+    {
+        return m_downloadState;
+    }
+
+    void setFullPath(std::string value)
+    {
+        m_fullPath = value;
+    }
+    std::string getFullPath() const
+    {
+        return m_fullPath;
+    }
+
+    void setReceivedSize(unsigned long long value)
+    {
+        m_receivedSize = value;
+    }
+    unsigned long long getReceivedSize() const
+    {
+        return m_receivedSize;
+    }
+
+    void setTotalSize(unsigned long long value)
+    {
+        m_totalSize = value;
+    }
+    unsigned long long getTotalSize() const
+    {
+        return m_totalSize;
+    }
+
+    void setErrorMessage(std::string value)
+    {
+        m_errorMessage = value;
+    }
+    std::string getErrorMessage() const
+    {
+        return m_errorMessage;
+    }
+
+    private:
+    long m_downloadId;
+    std::string m_downloadState;
+    std::string m_fullPath;
+    unsigned long long m_receivedSize;
+    unsigned long long m_totalSize;
+    bool m_result;
+    std::string m_errorMessage;
+};
+
+typedef DPL::SharedPtr<OnDownloadStateChanged> OnDownloadStateChangedPtr;
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<OnDownloadStateChanged> OnDownloadStateChangedEmitter;
+typedef DPL::SharedPtr<OnDownloadStateChangedEmitter> OnDownloadStateChangedEmitterPtr;
+
+}
+}
+}
+
+#endif //_ON_DOWNLOAD_STATE_CHANGED_H_
diff --git a/src/platform/API/Download/config.cmake b/src/platform/API/Download/config.cmake
new file mode 100755 (executable)
index 0000000..d73a5f5
--- /dev/null
@@ -0,0 +1,6 @@
+get_current_path()
+set(SRCS_PLATFORM_API_DOWNLOAD
+  ${CURRENT_PATH}/IDownloadManager.cpp
+  ${CURRENT_PATH}/DownloadRequest.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Filesystem/Enums.h b/src/platform/API/Filesystem/Enums.h
new file mode 100755 (executable)
index 0000000..12af283
--- /dev/null
@@ -0,0 +1,111 @@
+//
+// 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_FILESYSTEM_ENUMS_H_
+#define TIZENAPIS_FILESYSTEM_ENUMS_H_
+
+#include <string>
+#include <map>
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+enum LocationType
+{
+    LT_APPS,
+    LT_DOCUMENTS,
+    LT_DOWNLOADS,
+    LT_GAMES,
+    LT_IMAGES,
+    LT_OTHERS,
+    LT_ROOT,
+    LT_SDCARD,
+    LT_USBHOST,
+    LT_SOUNDS,
+    LT_TEMP,
+    LT_VIDEOS,
+    LT_WGTPKG,
+    LT_WGTPRV,
+    LT_WGTPRVTMP
+};
+
+enum NodeType
+{
+    NT_DIRECTORY,
+    NT_FILE
+};
+
+enum AccessMode
+{
+    AM_READ     = 0x0001,
+    AM_WRITE    = 0x0002,
+    AM_APPEND   = 0x0004
+};
+
+/**
+ * Used in @see IManager::access().
+ */
+enum AccessType
+{
+    AT_EXISTS   = 0x0000, //!< AT_EXISTS - checks for existence
+    AT_READ     = 0x0001, //!< AT_READ   - checks for read access
+    AT_WRITE    = 0x0002, //!< AT_WRITE  - checks for write access
+    AT_EXEC     = 0x0004 //!< AT_EXEC   - checks for execution access
+};
+
+enum Permissions
+{
+    PERM_NONE   = 0x0000,
+    PERM_READ   = 0x0001,
+    PERM_WRITE  = 0x0002
+};
+
+enum PlatformMode
+{
+    PM_USER_READ    = 0x0100,
+    PM_USER_WRITE   = 0x0080,
+    PM_USER_EXEC    = 0x0040,
+    PM_GROUP_READ   = 0x0020,
+    PM_GROUP_WRITE  = 0x0010,
+    PM_GROUP_EXEC   = 0x0008,
+    PM_OTHER_READ   = 0x0004,
+    PM_OTHER_WRITE  = 0x0002,
+    PM_OTHER_EXEC   = 0x0001,
+    PM_NONE         = 0x0000
+};
+
+enum Options
+{
+    OPT_NONE        = 0x0000,
+    OPT_OVERWRITE   = 0x0001,
+    OPT_RECURSIVE   = 0x0002
+};
+
+enum FindFilter
+{
+    FF_NAME,
+    FF_CREATED,
+    FF_MODIFIED,
+    FF_SIZE
+};
+typedef std::map<FindFilter, std::string> FiltersMap;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif /* TIZENAPIS_FILESYSTEM_ENUMS_H_ */
diff --git a/src/platform/API/Filesystem/EventCopy.cpp b/src/platform/API/Filesystem/EventCopy.cpp
new file mode 100755 (executable)
index 0000000..dfaf5d9
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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 "EventCopy.h"
+#include <dpl/assert.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+EventCopy::EventCopy(const IPathPtr& src,
+        const IPathPtr& dest) :
+    m_src(src),
+    m_dest(dest),
+    m_options(OPT_NONE)
+{
+    Assert(src && "Source path not set.");
+    Assert(dest && "Destination path not set.");
+}
+
+IPathPtr EventCopy::getDestination() const
+{
+    return m_dest;
+}
+
+IPathPtr EventCopy::getSource() const
+{
+    return m_src;
+}
+
+INodePtr EventCopy::getResult() const
+{
+    return m_result;
+}
+
+void EventCopy::setResult(const INodePtr& node)
+{
+    m_result = node;
+}
+
+int EventCopy::getOptions() const
+{
+    return m_options;
+}
+
+void EventCopy::setOptions(int options)
+{
+    m_options = options;
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventCopy.h b/src/platform/API/Filesystem/EventCopy.h
new file mode 100755 (executable)
index 0000000..c28d0a9
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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_FILESYSTEM_EVENTCOPY_H_
+#define TIZENAPIS_FILESYSTEM_EVENTCOPY_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPath.h"
+#include "INode.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class EventCopy : public WrtDeviceApis::Commons::IEvent<EventCopy>
+{
+  public:
+    /**
+     * Creates new event object.
+     * @param src Path to source node.
+     * @param dest Path to destination node.
+     * @return New object.
+     */
+    EventCopy(const IPathPtr& src,
+            const IPathPtr& dest);
+
+    /**
+     * Gets destination path.
+     * @return Destination path.
+     */
+    IPathPtr getDestination() const;
+
+    /**
+     * Gets source path.
+     * @return Source path.
+     */
+    IPathPtr getSource() const;
+
+    /**
+     * Gets result node.
+     * @return Result node.
+     */
+    INodePtr getResult() const;
+
+    /**
+     * Sets result node.
+     * @param node Result node.
+     */
+    void setResult(const INodePtr& node);
+
+    /**
+     * Gets options.
+     * @return Options.
+     */
+    int getOptions() const;
+
+    /**
+     * Sets options.
+     * @param options Options.
+     */
+    void setOptions(int options);
+
+  private:
+    IPathPtr m_src;   ///< Source path.
+    IPathPtr m_dest;  ///< Destination path.
+    INodePtr m_result; ///< Result node.
+    int m_options;    ///< Options for copy action @see WrtPlugins::Api::Filesystem::Options.
+};
+
+typedef DPL::SharedPtr<EventCopy> EventCopyPtr;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_EVENTCOPY_H_
diff --git a/src/platform/API/Filesystem/EventCreate.cpp b/src/platform/API/Filesystem/EventCreate.cpp
new file mode 100755 (executable)
index 0000000..85d8e39
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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 "EventCreate.h"
+
+#include <dpl/assert.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+EventCreate::EventCreate(const IPathPtr& path,
+        NodeType type) :
+    m_path(path),
+    m_type(type),
+    m_options(OPT_NONE)
+{
+    Assert(path && "Path is not set.");
+}
+
+IPathPtr EventCreate::getPath() const
+{
+    return m_path;
+}
+
+NodeType EventCreate::getType() const
+{
+    return m_type;
+}
+
+int EventCreate::getOptions() const
+{
+    return m_options;
+}
+
+void EventCreate::setOptions(int options)
+{
+    m_options = options;
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventCreate.h b/src/platform/API/Filesystem/EventCreate.h
new file mode 100755 (executable)
index 0000000..aa8be93
--- /dev/null
@@ -0,0 +1,77 @@
+//
+// 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_FILESYSTEM_EVENTCREATE_H_
+#define TIZENAPIS_FILESYSTEM_EVENTCREATE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPath.h"
+#include "Enums.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class EventCreate : public WrtDeviceApis::Commons::IEvent<EventCreate>
+{
+  public:
+    /**
+     * Creates new event object.
+     * @param path Path to node to create.
+     * @param type Type of node to create.
+     * @return New object.
+     */
+    EventCreate(const IPathPtr& path,
+            NodeType type);
+
+    /**
+     * Gets path to the node.
+     * @return Path to node.
+     */
+    IPathPtr getPath() const;
+
+    /**
+     * Gets type of the node.
+     * @return Type of node.
+     */
+    NodeType getType() const;
+
+    /**
+     * Gets options.
+     * @return Options.
+     */
+    int getOptions() const;
+
+    /**
+     * Sets options.
+     * @param options Options.
+     */
+    void setOptions(int options);
+
+  private:
+    IPathPtr m_path;  ///< Path to node to create.
+    NodeType m_type;  ///< Type of the node.
+    int m_options;    ///< Options for create action @see WrtPlugins::Api::Filesystem::Options.
+};
+
+typedef DPL::SharedPtr<EventCreate> EventCreatePtr;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_EVENTCREATE_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventFind.cpp b/src/platform/API/Filesystem/EventFind.cpp
new file mode 100755 (executable)
index 0000000..86c81f1
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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 "EventFind.h"
+
+#include <Filesystem/Path.h>
+#include "INode.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+EventFind::EventFind(const IPathPtr& path) : m_path(path)
+{
+}
+
+IPathPtr EventFind::getPath() const
+{
+    return m_path;
+}
+
+NodeList EventFind::getResult() const
+{
+    return m_nodes;
+}
+
+void EventFind::addResult(const INodePtr& node)
+{
+    m_nodes.push_back(node);
+}
+
+void EventFind::setResult(const NodeList& nodes)
+{
+    m_nodes = nodes;
+}
+
+void EventFind::addFilter(FindFilter name,
+        const std::string& value)
+{
+    m_filters.insert(std::pair<FindFilter, std::string>(name, value));
+}
+
+FiltersMap EventFind::getFilters() const
+{
+    return m_filters;
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventFind.h b/src/platform/API/Filesystem/EventFind.h
new file mode 100755 (executable)
index 0000000..4039d3c
--- /dev/null
@@ -0,0 +1,91 @@
+//
+// 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_IEVENTFILESYSTEMFIND_H_
+#define TIZENAPIS_IEVENTFILESYSTEMFIND_H_
+
+#include <list>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPath.h"
+#include "INodeTypes.h"
+#include "Enums.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class EventFind : public WrtDeviceApis::Commons::IEvent<EventFind>
+{
+  public:
+    /**
+     * Creates new event object.
+     * @param path Start path.
+     * @return New object.
+     */
+    explicit EventFind(const IPathPtr& path);
+
+    /**
+     * Gets start path.
+     * @return Path to start searching from.
+     */
+    IPathPtr getPath() const;
+
+    /**
+     * Gets found nodes.
+     * @return Nodes.
+     */
+    NodeList getResult() const;
+
+    /**
+     * Adds found node.
+     * @param node Found node.
+     */
+    void addResult(const INodePtr& node);
+
+    /**
+     * Sets found nodes.
+     * @param nodes Nodes.
+     */
+    void setResult(const NodeList& nodes);
+
+    /**
+     * Adds find filter.
+     * @param name Filter name.
+     * @param value Filter value.
+     */
+    void addFilter(FindFilter name,
+            const std::string& value);
+
+    /**
+     * Gets all filters.
+     * @return Filters.
+     */
+    FiltersMap getFilters() const;
+
+  private:
+    IPathPtr m_path;    ///< Start path.
+    NodeList m_nodes;   ///< Resolved nodes.
+    FiltersMap m_filters; ///< Search filters.
+};
+
+typedef DPL::SharedPtr<EventFind> EventFindPtr;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif /* TIZENAPIS_IEVENTFILESYSTEMFIND_H_ */
diff --git a/src/platform/API/Filesystem/EventGetStorage.cpp b/src/platform/API/Filesystem/EventGetStorage.cpp
new file mode 100755 (executable)
index 0000000..7204518
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 "EventGetStorage.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+EventGetStorage::EventGetStorage()
+{
+}
+
+void EventGetStorage::setLabel(const std::string &Label)
+{
+       label = Label;
+}
+
+std::string EventGetStorage::getLabel() const
+{
+       return label;
+}
+
+void EventGetStorage::setResult (const StoragePropertiesPtr &Storages) 
+{ 
+       storages = Storages;
+}
+
+StoragePropertiesPtr EventGetStorage::getResult() const 
+{
+       return storages;
+}
+
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventGetStorage.h b/src/platform/API/Filesystem/EventGetStorage.h
new file mode 100755 (executable)
index 0000000..0ba7f57
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// 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_FILESYSTEM_EVENT_GET_STORAGE_H_
+#define TIZENAPIS_API_FILESYSTEM_EVENT_GET_STORAGE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <string>
+#include "StorageProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class EventGetStorage : public WrtDeviceApis::Commons::IEvent<
+        EventGetStorage>
+{
+  private:
+       std::string label;
+       StoragePropertiesPtr storages;
+  public:
+       void setLabel(const std::string &Label);
+       std::string getLabel() const;
+       void setResult (const StoragePropertiesPtr& Storages);
+       StoragePropertiesPtr getResult() const;
+       EventGetStorage();
+};
+
+typedef DPL::SharedPtr<EventGetStorage> EventGetStoragePtr;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif //TIZENAPIS_API_FILESYSTEM_EVENT_GET_STORAGE_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventListNodes.cpp b/src/platform/API/Filesystem/EventListNodes.cpp
new file mode 100755 (executable)
index 0000000..5e1fea3
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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 "EventListNodes.h"
+#include <dpl/assert.h>
+#include "INode.h"
+#include "Enums.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+EventListNodes::EventListNodes(const INodePtr& node) : m_node(node)
+{
+    Assert(m_node && "Node can't be NULL.");
+}
+
+INodePtr EventListNodes::getNode() const
+{
+    return m_node;
+}
+
+NodeFilterPtr EventListNodes::getFilter() const
+{
+    return m_filter;
+}
+
+void EventListNodes::setFilter(const NodeFilterPtr& filter)
+{
+    m_filter = filter;
+}
+
+NodeList EventListNodes::getResult() const
+{
+    return m_list;
+}
+
+void EventListNodes::setResult(const NodeList& list)
+{
+    m_list = list;
+}
+
+
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventListNodes.h b/src/platform/API/Filesystem/EventListNodes.h
new file mode 100755 (executable)
index 0000000..393ff8b
--- /dev/null
@@ -0,0 +1,81 @@
+//
+// 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_FILESYSTEM_EVENTLISTNODES_H_
+#define TIZENAPIS_FILESYSTEM_EVENTLISTNODES_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "INodeTypes.h"
+#include "NodeFilter.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class EventListNodes : public WrtDeviceApis::Commons::IEvent<EventListNodes>
+{
+  public:
+    /**
+     * Creates new event object.
+     * @param path Node to list children for.
+     * @return New object.
+     */
+    explicit EventListNodes(const INodePtr& node);
+
+    /**
+     * Gets parent node.
+     * @return Parent node.
+     */
+    INodePtr getNode() const;
+
+    /**
+     * Gets filter.
+     * @return Filter.
+     */
+    NodeFilterPtr getFilter() const;
+
+    /**
+     * Sets filter.
+     * @param filter Filter to list only specific nodes.
+     */
+    void setFilter(const NodeFilterPtr& filter);
+
+    /**
+     * Gets nodes.
+     * @return Nodes list.
+     */
+    NodeList getResult() const;
+
+    /**
+     * Sets nodes list.
+     * @param list Nodes list.
+     */
+    void setResult(const NodeList& list);
+
+  private:
+    NodeList m_list;      ///< List of child nodes.
+    INodePtr m_node;      ///< Node to list children for.
+    NodeFilterPtr m_filter; ///< Filter.
+};
+
+typedef DPL::SharedPtr<EventListNodes> EventListNodesPtr;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_EVENTLISTNODES_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventListStorages.cpp b/src/platform/API/Filesystem/EventListStorages.cpp
new file mode 100755 (executable)
index 0000000..249feb8
--- /dev/null
@@ -0,0 +1,40 @@
+//
+// 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 "EventListStorages.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+EventListStorages::EventListStorages()
+{
+}
+
+void EventListStorages::setResult (const std::vector<StoragePropertiesPtr>& Storages) 
+{ 
+       storages = Storages;
+}
+
+std::vector<StoragePropertiesPtr> EventListStorages::getResult() const 
+{
+       return storages;
+}
+
+} // Filesystem
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filesystem/EventListStorages.h b/src/platform/API/Filesystem/EventListStorages.h
new file mode 100755 (executable)
index 0000000..4950362
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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_FILESYSTEM_EVENT_LIST_STORAGES_H_
+#define TIZENAPIS_API_FILESYSTEM_EVENT_LIST_STORAGES_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <vector>
+#include "StorageProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class EventListStorages : public WrtDeviceApis::Commons::IEvent<
+        EventListStorages>
+{
+  private:
+       std::vector<StoragePropertiesPtr> storages;
+  public:
+       void setResult (const std::vector<StoragePropertiesPtr>& Storages);
+       std::vector<StoragePropertiesPtr> getResult() const;
+       EventListStorages();
+};
+
+typedef DPL::SharedPtr<EventListStorages> EventListStoragesPtr;
+}
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventMove.cpp b/src/platform/API/Filesystem/EventMove.cpp
new file mode 100755 (executable)
index 0000000..497c734
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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 "EventMove.h"
+#include <dpl/assert.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+EventMove::EventMove(const IPathPtr& src,
+        const IPathPtr& dest) :
+    m_src(src),
+    m_dest(dest),
+    m_options(OPT_NONE)
+{
+    Assert(src && "Source path not set.");
+    Assert(dest && "Destination path not set.");
+}
+
+IPathPtr EventMove::getDestination() const
+{
+    return m_dest;
+}
+
+IPathPtr EventMove::getSource() const
+{
+    return m_src;
+}
+
+INodePtr EventMove::getResult() const
+{
+    return m_result;
+}
+
+void EventMove::setResult(const INodePtr& node)
+{
+    m_result = node;
+}
+
+int EventMove::getOptions() const
+{
+    return m_options;
+}
+
+void EventMove::setOptions(int options)
+{
+    m_options = options;
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventMove.h b/src/platform/API/Filesystem/EventMove.h
new file mode 100755 (executable)
index 0000000..92379ba
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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_FILESYSTEM_EVENTMOVE_H_
+#define TIZENAPIS_FILESYSTEM_EVENTMOVE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPath.h"
+#include "INode.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class EventMove : public WrtDeviceApis::Commons::IEvent<EventMove>
+{
+  public:
+    /**
+     * Creates new event object.
+     * @param src Source path.
+     * @param dest Destination path.
+     * @return New object.
+     */
+    EventMove(const IPathPtr& src,
+            const IPathPtr& dest);
+
+    /**
+     * Gets destination path.
+     * @return Destination path.
+     */
+    IPathPtr getDestination() const;
+
+    /**
+     * Gets source path.
+     * @return Source path.
+     */
+    IPathPtr getSource() const;
+
+    /**
+     * Gets result node.
+     * @return Result node.
+     */
+    INodePtr getResult() const;
+
+    /**
+     * Sets result node.
+     * @param node Result node.
+     */
+    void setResult(const INodePtr& node);
+
+    /**
+     * Gets options.
+     * @return Options.
+     */
+    int getOptions() const;
+
+    /**
+     * Sets options.
+     * @param options Options.
+     */
+    void setOptions(int options);
+
+  private:
+    IPathPtr m_src;   ///< Source path.
+    IPathPtr m_dest;  ///< Destination path.
+    INodePtr m_result; ///< Result node.
+    int m_options;    ///< Options for copy action @see WrtPlugins::Api::Filesystem::Options.
+};
+
+typedef DPL::SharedPtr<EventMove> EventMovePtr;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_EVENTMOVE_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventOpen.cpp b/src/platform/API/Filesystem/EventOpen.cpp
new file mode 100755 (executable)
index 0000000..517394e
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// 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 "EventOpen.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+EventOpen::EventOpen(int mode) : m_mode(mode)
+{
+}
+
+int EventOpen::getMode() const
+{
+    return m_mode;
+}
+
+IStreamPtr EventOpen::getResult() const
+{
+    return m_stream;
+}
+
+void EventOpen::setResult(const IStreamPtr& stream)
+{
+    m_stream = stream;
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventOpen.h b/src/platform/API/Filesystem/EventOpen.h
new file mode 100755 (executable)
index 0000000..a757b8c
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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_FILESYSTEM_EVENTOPEN_H_
+#define TIZENAPIS_FILESYSTEM_EVENTOPEN_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IStream.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class EventOpen : public WrtDeviceApis::Commons::IEvent<EventOpen>
+{
+  public:
+    /**
+     * Creates new event object.
+     * @param mode Mode to open the node in.
+     * @return New object.
+     */
+    explicit EventOpen(int mode);
+
+    /**
+     * Gets mode.
+     * @return Mode.
+     */
+    int getMode() const;
+
+    /**
+     * Gets result stream.
+     * @return Result stream.
+     */
+    IStreamPtr getResult() const;
+
+    /**
+     * Sets result stream.
+     * @param stream Result stream.
+     */
+    void setResult(const IStreamPtr& stream);
+
+  private:
+    int m_mode;         ///< Mode.
+    IStreamPtr m_stream; ///< Opened stream.
+};
+
+typedef DPL::SharedPtr<EventOpen> EventOpenPtr;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_EVENTOPEN_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventReadText.cpp b/src/platform/API/Filesystem/EventReadText.cpp
new file mode 100755 (executable)
index 0000000..156b8d7
--- /dev/null
@@ -0,0 +1,35 @@
+//
+// 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 "EventReadText.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+std::string EventReadText::getResult() const
+{
+    return m_result;
+}
+
+void EventReadText::setResult(const std::string& result)
+{
+    m_result = result;
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventReadText.h b/src/platform/API/Filesystem/EventReadText.h
new file mode 100755 (executable)
index 0000000..6719d65
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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_FILESYSTEM_EVENTREADTEXT_H_
+#define TIZENAPIS_FILESYSTEM_EVENTREADTEXT_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPath.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class EventReadText : public WrtDeviceApis::Commons::IEvent<EventReadText>
+{
+  public:
+    /**
+     * Gets read text.
+     * @return Text.
+     */
+    std::string getResult() const;
+
+    /**
+     * Sets read text.
+     * @param result Text.
+     */
+    void setResult(const std::string& result);
+
+  private:
+    std::string m_result; ///< Read text.
+};
+
+typedef DPL::SharedPtr<EventReadText> EventReadTextPtr;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_EVENTREADTEXT_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventRemove.cpp b/src/platform/API/Filesystem/EventRemove.cpp
new file mode 100755 (executable)
index 0000000..1ec53dd
--- /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.
+//
+
+#include "EventRemove.h"
+#include <dpl/assert.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+EventRemove::EventRemove(const IPathPtr& path) :
+    m_path(path),
+    m_options(OPT_NONE)
+{
+    Assert(m_path && "Path is not set.");
+}
+
+IPathPtr EventRemove::getPath() const
+{
+    return m_path;
+}
+
+int EventRemove::getOptions() const
+{
+    return m_options;
+}
+
+void EventRemove::setOptions(int options)
+{
+    m_options = options;
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventRemove.h b/src/platform/API/Filesystem/EventRemove.h
new file mode 100755 (executable)
index 0000000..ae6d69c
--- /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 TIZENAPIS_FILESYSTEM_EVENTREMOVE_H_
+#define TIZENAPIS_FILESYSTEM_EVENTREMOVE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "INode.h"
+#include "Enums.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class EventRemove : public WrtDeviceApis::Commons::IEvent<EventRemove>
+{
+  public:
+    /**
+     * Creates new event object.
+     * @param path Path to the node to remove.
+     * @return New object.
+     */
+    explicit EventRemove(const IPathPtr& path);
+
+    /**
+     * Gets path to the node to remove.
+     * @return Path.
+     */
+    IPathPtr getPath() const;
+
+    /**
+     * Gets options.
+     * @return Options.
+     */
+    int getOptions() const;
+
+    /**
+     * Sets options.
+     * @param options Options.
+     */
+    void setOptions(int options);
+
+  private:
+    IPathPtr m_path; ///< Source path.
+    int m_options;  ///< Options for remove action @see WrtPlugins::Api::Filesystem::Options.
+};
+
+typedef DPL::SharedPtr<EventRemove> EventRemovePtr;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_EVENTREMOVE_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventResolve.cpp b/src/platform/API/Filesystem/EventResolve.cpp
new file mode 100755 (executable)
index 0000000..c6b72b7
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// 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 "EventResolve.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+EventResolve::EventResolve(const IPathPtr& path) : m_path(path)
+{
+}
+
+IPathPtr EventResolve::getPath() const
+{
+    return m_path;
+}
+
+INodePtr EventResolve::getResult() const
+{
+    return m_node;
+}
+
+void EventResolve::setResult(const INodePtr& node)
+{
+    m_node = node;
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventResolve.h b/src/platform/API/Filesystem/EventResolve.h
new file mode 100755 (executable)
index 0000000..3fbd7c7
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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_FILESYSTEM_EVENTRESOLVE_H_
+#define TIZENAPIS_FILESYSTEM_EVENTRESOLVE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IPath.h"
+#include "INode.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class EventResolve : public WrtDeviceApis::Commons::IEvent<EventResolve>
+{
+  public:
+    /**
+     * Creates new event object.
+     * @param path Path to the node to resolve.
+     * @return New object.
+     */
+    explicit EventResolve(const IPathPtr& path);
+
+    /**
+     * Gets path of the node to resolve.
+     * @return Path to resolve.
+     */
+    IPathPtr getPath() const;
+
+    /**
+     * Gets resolved node.
+     * NULL if none found. Check exception code.
+     * @return Resolved node or NULL.
+     */
+    INodePtr getResult() const;
+
+    /**
+     * Sets resolved node.
+     * @param node Resolved node.
+     */
+    void setResult(const INodePtr& node);
+
+  private:
+    IPathPtr m_path; ///< Path to the requested node.
+    INodePtr m_node; ///< Resolved node.
+};
+
+typedef DPL::SharedPtr<EventResolve> EventResolvePtr;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // WRTPLUGINS_FILESYSTEM_EVENTRESOLVE_H_
diff --git a/src/platform/API/Filesystem/EventStorageStateChanged.h b/src/platform/API/Filesystem/EventStorageStateChanged.h
new file mode 100755 (executable)
index 0000000..d156474
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// 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_FILESYSTEM_EVENT_STORAGESTATE_CHANGED_H_
+#define TIZENAPIS_API_FILESYSTEM_EVENT_STORAGESTATE_CHANGED_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "StorageProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+
+class EventStorageStateChanged : public WrtDeviceApis::Commons::ListenerEvent<EventStorageStateChanged>
+{
+private:
+       StoragePropertiesPtr storages;
+
+public:
+       void setResult (const StoragePropertiesPtr& Storages);
+       StoragePropertiesPtr getResult() const;
+
+       EventStorageStateChanged();
+};
+
+typedef DPL::SharedPtr<EventStorageStateChanged> EventStorageStateChangedPtr;
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventStorageStateChanged> EventStorageStateChangedEmitter;
+typedef DPL::SharedPtr<EventStorageStateChangedEmitter> EventStorageStateChangedEmitterPtr;
+
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif //TIZENAPIS_API_FILESYSTEM_EVENT_STORAGESTATE_CHANGED_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/EventStoragestateChanged.cpp b/src/platform/API/Filesystem/EventStoragestateChanged.cpp
new file mode 100755 (executable)
index 0000000..dc58b14
--- /dev/null
@@ -0,0 +1,40 @@
+//
+// 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 "EventStorageStateChanged.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+EventStorageStateChanged::EventStorageStateChanged()
+{
+}
+
+void EventStorageStateChanged::setResult (const StoragePropertiesPtr &Storages) 
+{ 
+       storages = Storages;
+}
+
+StoragePropertiesPtr EventStorageStateChanged::getResult() const 
+{
+       return storages;
+}
+
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/IManager.cpp b/src/platform/API/Filesystem/IManager.cpp
new file mode 100755 (executable)
index 0000000..468dd6b
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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 <Filesystem/Manager.h>
+#include <Commons/ThreadPool.h>
+#include "IManager.h"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+IManager& IManager::getInstance()
+{
+    static Platform::Filesystem::Manager instance;
+    return instance;
+}
+
+IManager::IManager() :
+    EventRequestReceiver<EventResolve>(ThreadEnum::FILESYSTEM_THREAD),
+    EventRequestReceiver<EventGetStorage>(ThreadEnum::FILESYSTEM_THREAD),
+    EventRequestReceiver<EventListStorages>(ThreadEnum::FILESYSTEM_THREAD),
+    EventRequestReceiver<EventCopy>(ThreadEnum::FILESYSTEM_THREAD),
+    EventRequestReceiver<EventMove>(ThreadEnum::FILESYSTEM_THREAD),
+    EventRequestReceiver<EventCreate>(ThreadEnum::FILESYSTEM_THREAD),
+    EventRequestReceiver<EventRemove>(ThreadEnum::FILESYSTEM_THREAD),
+    EventRequestReceiver<EventFind>(ThreadEnum::FILESYSTEM_THREAD)
+{
+}
+
+IManager::~IManager()
+{
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/IManager.h b/src/platform/API/Filesystem/IManager.h
new file mode 100755 (executable)
index 0000000..ff81074
--- /dev/null
@@ -0,0 +1,176 @@
+//
+// 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_FILESYSTEM_IMANAGER_H_
+#define TIZENAPIS_FILESYSTEM_IMANAGER_H_
+
+#include <map>
+#include <vector>
+#include <string>
+#include <cstddef>
+#include <dpl/noncopyable.h>
+#include <Commons/EventReceiver.h>
+#include "EventResolve.h"
+#include "EventGetStorage.h"
+#include "EventListStorages.h"
+#include "EventStorageStateChanged.h"
+#include "EventCopy.h"
+#include "EventMove.h"
+#include "EventRemove.h"
+#include "EventCreate.h"
+#include "EventFind.h"
+#include "Enums.h"
+#include "INode.h"
+#include "IPath.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+typedef std::vector<IPathPtr> LocationPaths;
+
+typedef std::vector<LocationType> LocationTypes;
+
+typedef std::map<std::string, Api::Filesystem::IPathPtr> StorageList;
+
+class IManager : public WrtDeviceApis::Commons::EventRequestReceiver<EventResolve>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventGetStorage>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventListStorages>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventCopy>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventMove>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventCreate>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventRemove>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventFind>
+{
+  public:
+    static IManager& getInstance();
+
+    virtual ~IManager() = 0;
+
+    /**
+     * Gets base path.
+     * @return Valid path or empty shared pointer.
+     */
+    virtual IPathPtr getBasePath() const = 0;
+
+    virtual StorageList getStorageList() const = 0;
+
+    /**
+     * Gets path for specified location type.
+     * @param type Location type @see WrtPlugins::Api::Filesystem::LocationType.
+     * @return Valid path or empty shared pointer.
+     */
+    virtual IPathPtr getLocationPath(LocationType type) const = 0;
+
+    /**
+     * Gets paths to default locations.
+     * @return Paths to predefined virtual locations.
+     */
+    virtual LocationPaths getLocationPaths() const = 0;
+
+    /**
+     * Gets locations supported by platform.
+     * @return Supported locations.
+     */
+    virtual LocationTypes getLocations() const = 0;
+
+    /**
+     * Gets filesystem node.
+     * @param event Get node event @see Api::Filesystem::EventGetNode.
+     * @remarks Asynchronous.
+     */
+    virtual void getNode(const EventResolvePtr& event) = 0;
+
+    /**
+     * Gets maximum length of filesystem path.
+     * @return Maximum path length.
+     */
+    virtual std::size_t getMaxPathLength() const = 0;
+
+    /**
+     * Copies node to specified destination.
+     * @param event Copy node event @see Api::Filesystem::EventCopy.
+     * @remarks Asynchronous.
+     */
+    virtual void copy(const EventCopyPtr& event) = 0;
+
+    /**
+     * Moves node to specified destination.
+     * @param event Move node event @see Api::Filesystem::EventMove.
+     * @remarks Asynchronous.
+     */
+    virtual void move(const EventMovePtr& event) = 0;
+
+    /**
+     * Creates a node.
+     * @param event Create node event @see Api::Filesystem::EventCreate.
+     * @remarks Asynchronous.
+     */
+    virtual void create(const EventCreatePtr& event) = 0;
+
+    /**
+     * Removes node.
+     * @param event Remove node event @see Api::Filesystem::EventRemove.
+     * @remarks Asynchronous.
+     */
+    virtual void remove(const EventRemovePtr& event) = 0;
+
+    /**
+     * Finds nodes.
+     * @param event Find nodes event @see Api::Filesystem::EventFind.
+     * @remarks Asynchronous.
+     */
+    virtual void find(const EventFindPtr& event) = 0;
+
+    /**
+     * Checks if node at specified path has supplied access rights.
+     * @param path Path to the node.
+     * @param accessType Access right(s) to check @see AccessType. Multiple values
+     *                   can be passed using OR operator.
+     * @return True if specified node has supplied access rights, false otherwise.
+     */
+//    virtual bool access(const IPathPtr& path,
+//            int accessType) const = 0;
+
+    virtual void addOpenedNode(const Api::Filesystem::INodePtr& node) = 0;
+    virtual void removeOpenedNode(const Api::Filesystem::INodePtr& node) = 0;
+    virtual bool checkIfOpened(const Api::Filesystem::IPathPtr& path) const = 0;
+
+    virtual void getStorage(const EventGetStoragePtr& event) = 0;
+    virtual void listStorages(const EventListStoragesPtr& event) = 0;
+
+    virtual long addStorageStateChangeListener(const EventStorageStateChangedEmitterPtr& emitter) = 0;
+    virtual void removeStorageStateChangeListener(EventStorageStateChangedEmitter::IdType id) = 0;
+       virtual void addWidgetStorage(const std::string &key, const std::string &value) = 0;
+
+  protected:
+    IManager();
+
+    virtual void OnRequestReceived(const EventResolvePtr& event) = 0;
+    virtual void OnRequestReceived(const EventGetStoragePtr& event) = 0;
+    virtual void OnRequestReceived(const EventListStoragesPtr& event) = 0;
+    virtual void OnRequestReceived(const EventCopyPtr& event) = 0;
+    virtual void OnRequestReceived(const EventMovePtr& event) = 0;
+    virtual void OnRequestReceived(const EventCreatePtr& event) = 0;
+    virtual void OnRequestReceived(const EventRemovePtr& event) = 0;
+    virtual void OnRequestReceived(const EventFindPtr& event) = 0;
+}; // IManager
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_IMANAGER_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/INode.cpp b/src/platform/API/Filesystem/INode.cpp
new file mode 100755 (executable)
index 0000000..38ec24c
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// 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 "INode.h"
+#include <Commons/ThreadPool.h>
+
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+INode::INode() :
+    EventRequestReceiver<EventListNodes>(ThreadEnum::FILESYSTEM_THREAD),
+    EventRequestReceiver<EventOpen>(ThreadEnum::FILESYSTEM_THREAD),
+    EventRequestReceiver<EventReadText>(ThreadEnum::FILESYSTEM_THREAD)
+{
+}
+
+INode::~INode()
+{
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/INode.h b/src/platform/API/Filesystem/INode.h
new file mode 100755 (executable)
index 0000000..84e5b1c
--- /dev/null
@@ -0,0 +1,188 @@
+//
+// 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_FILESYSTEM_INODE_H_
+#define TIZENAPIS_FILESYSTEM_INODE_H_
+
+#include <string>
+#include <vector>
+#include <ctime>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/Deprecated.h>
+#include <Commons/EventReceiver.h>
+#include "EventListNodes.h"
+#include "EventOpen.h"
+#include "EventReadText.h"
+#include "Enums.h"
+#include "IPath.h"
+#include "IStream.h"
+#include "INodeTypes.h"
+#include "NodeFilter.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class INode : public WrtDeviceApis::Commons::EventRequestReceiver<EventListNodes>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventOpen>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventReadText>
+{
+  public:
+    typedef std::vector<std::string> NameList;
+    typedef NameList::iterator NodeListIterator;
+
+  public:
+    virtual ~INode() = 0;
+
+    /**
+     * Gets direct child of this node.
+     * @param path Path to the child node.
+     * @return Ptr to the child node.
+     * @remarks Ownership passed to the caller.
+     */
+    virtual INodePtr getChild(const IPathPtr& path) = 0;
+
+    /**
+     * Gets path of current node.
+     * @return Node's path.
+     */
+    virtual IPathPtr getPath() const = 0;
+
+    /**
+     * Gets type of current node.
+     * @return Node's type.
+     */
+    virtual NodeType getType() const = 0;
+
+    /**
+     * Gets permissions of the virtual node (not real filesystem node).
+     * @return Node's permissions.
+     */
+    virtual int getPermissions() const = 0;
+
+    /**
+     * Sets permissions on the virtual node (not real filesystem node).
+     * @param perms Node's permissions @see Api::Filesystem::Permissions.
+     */
+    virtual void setPermissions(int perms) = 0;
+
+    /**
+     * Gets list of names of direct child nodes.
+     * @return Names of child nodes.
+     */
+    virtual NameList getChildNames() const = 0;
+
+    /**
+     * Gets list of direct child nodes.
+     * @return Child nodes.
+     * @remarks Ownership passed to the caller.
+     * @deprecated
+     */
+    virtual NodeList getChildNodes(const NodeFilterPtr& filter =
+                NodeFilterPtr()) const /* WRT_PLUGINS_DEPRECATED */ = 0;
+
+    /**
+     * Gets list of direct descendant nodes.
+     * @param event Get child nodes event.
+     */
+    virtual void getChildNodes(const EventListNodesPtr& event) = 0;
+
+    /**
+     * Gets stream for this node.
+     * @param mode @see Api::Filesystem::AccessMode.
+     * @return Stream connected with current node.
+     * @deprecated Use async version of thi method instead.
+     */
+    virtual IStreamPtr open(int mode) = 0;
+
+    /**
+     * Gets stream for this node.
+     * @param mode @see Api::Filesystem::AccessMode.
+     * @return Stream connected with current node.
+     */
+    virtual void open(const EventOpenPtr& event) = 0;
+
+    /**
+     * Removes underlying filesystem node.
+     * @param options Removal options (by default removal is recursive).
+     * @remarks Synchronous.
+     * Valid options:
+     * - OPT_RECURSIVE - remove node recursively.
+     */
+    virtual void remove(int options = OPT_RECURSIVE) = 0;
+
+    /**
+     * Creates child of current node.
+     * @param path Path to the node to create.
+     * @param type Type of the node @see Api::Filesystem::NodeType.
+     * @param options Additional options see remarks (no options by default).
+     * @return Ptr to newly created node.
+     * @remarks
+     * Valid options:
+     * - OPT_RECURSIVE - attempt to create all necessary sub-directories
+     */
+    virtual INodePtr createChild(const IPathPtr& path,
+            NodeType type,
+            int options = OPT_NONE) = 0;
+
+    /**
+     * Gets size of this node.
+     * @return Size.
+     */
+    virtual std::size_t getSize() const = 0;
+
+    /**
+     * Gets creation date of this node.
+     * @return Date.
+     */
+    virtual std::time_t getCreated() const = 0;
+
+    /**
+     * Gets last modification date of this node.
+     * @return Date.
+     */
+    virtual std::time_t getModified() const = 0;
+
+    /**
+     * Gets parent of this node.
+     * @return Parent node or NULL if no parent (e.g. in case of a root node).
+     */
+    virtual INodePtr getParent() const = 0;
+
+    /**
+     * Gets platform permissions.
+     * @return Platform permissions (set of flags from @see Permissions enum).
+     */
+    virtual int getMode() const = 0;
+
+    /**
+     * Reads whole file as text.
+     * @param event Read file event.
+     */
+    virtual void read(const EventReadTextPtr& event) = 0;
+
+    virtual std::string toUri(int widgetId) const = 0;
+
+  protected:
+    INode();
+};
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif /* TIZENAPIS_FILESYSTEM_INODE_H_ */
diff --git a/src/platform/API/Filesystem/INodeTypes.h b/src/platform/API/Filesystem/INodeTypes.h
new file mode 100755 (executable)
index 0000000..244ddcd
--- /dev/null
@@ -0,0 +1,38 @@
+//
+// 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_FILESYSTEM_INODETYPES_H_
+#define TIZENAPIS_FILESYSTEM_INODETYPES_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class INode;
+
+typedef DPL::SharedPtr<INode> INodePtr;
+
+typedef std::vector<INodePtr> NodeList;
+typedef NodeList::iterator NodeListIterator;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_INODETYPES_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/IPath.cpp b/src/platform/API/Filesystem/IPath.cpp
new file mode 100755 (executable)
index 0000000..df6f459
--- /dev/null
@@ -0,0 +1,40 @@
+//
+// 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 <Filesystem/Path.h>
+#include "IPath.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+IPathPtr IPath::create(const std::string& str)
+{
+    return Platform::Filesystem::Path::create(str);
+}
+
+IPath::SeparatorType IPath::getSeparator()
+{
+    return Platform::Filesystem::Path::getSeparator();
+}
+
+IPath::~IPath()
+{
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/IPath.h b/src/platform/API/Filesystem/IPath.h
new file mode 100755 (executable)
index 0000000..10b7ce7
--- /dev/null
@@ -0,0 +1,159 @@
+//
+// 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_FILESYSTEM_IPATH_H_
+#define TIZENAPIS_FILESYSTEM_IPATH_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class IPath;
+typedef DPL::SharedPtr<IPath> IPathPtr;
+
+class IPath
+{
+  public:
+    typedef char SeparatorType;
+
+  public:
+    /**
+     * Creates path object from specified string.
+     * @param str Path string.
+     * @return Path.
+     * @throw InvalidArgumentException If supplied string is not a valid path.
+     * @throw PlatformException If error in platform occurs.
+     * @remarks Ownership passed to the caller.
+     */
+    static IPathPtr create(const std::string& str);
+
+    /**
+     * Gets separator used by current platform.
+     * @return Path separator.
+     */
+    static SeparatorType getSeparator();
+
+  public:
+    virtual ~IPath() = 0;
+
+    /**
+     * Gets full path.
+     * @return Full path.
+     */
+    virtual std::string getFullPath() const = 0;
+
+    /**
+     * Gets base path (full path w/o name).
+     * @return Base path
+     */
+    virtual std::string getPath() const = 0;
+
+    /**
+     * Gets the last part of path.
+     * @return Path's name.
+     * @return Last part is typically name of a directory or file.
+     */
+    virtual std::string getName() const = 0;
+
+    /**
+     * Appends path specified as string to current path.
+     * @param path Path to append.
+     * @return Current path object.
+     */
+    virtual IPathPtr append(const std::string& path) = 0;
+
+    /**
+     * Appends path specified as path object to current path.
+     * @param path Path to append.
+     * @return Current path object.
+     */
+    virtual IPathPtr append(const IPathPtr& path) = 0;
+
+    /**
+     * Checks if path is abolute.
+     * @return True if absolute, false if relative.
+     */
+    virtual bool isAbsolute() const = 0;
+
+    /**
+     * Clones this object.
+     * @return Independent copy.
+     */
+    virtual IPathPtr clone() const = 0;
+};
+
+inline const IPathPtr operator+(const IPath& lhs,
+        const IPath& rhs)
+{
+    return IPath::create(lhs.getFullPath())->append(rhs.getFullPath());
+}
+
+inline const IPathPtr operator+(const IPath& lhs,
+        const std::string& rhs)
+{
+    return IPath::create(lhs.getFullPath())->append(rhs);
+}
+
+inline const IPathPtr operator+(const std::string& lhs,
+        const IPath& rhs)
+{
+    return IPath::create(lhs)->append(rhs.getFullPath());
+}
+
+inline const bool operator==(const IPath& lhs,
+        const IPath& rhs)
+{
+    return (lhs.getFullPath() == rhs.getFullPath());
+}
+
+inline const bool operator==(const IPath& lhs,
+        const std::string& rhs)
+{
+    return (lhs.getFullPath() == rhs);
+}
+
+inline const bool operator==(const std::string& lhs,
+        const IPath& rhs)
+{
+    return (lhs == rhs.getFullPath());
+}
+
+inline const bool operator!=(const IPath& lhs,
+        const IPath& rhs)
+{
+    return (lhs.getFullPath() != rhs.getFullPath());
+}
+
+inline const bool operator!=(const IPath& lhs,
+        const std::string& rhs)
+{
+    return (lhs.getFullPath() != rhs);
+}
+
+inline const bool operator!=(const std::string& lhs,
+        const IPath& rhs)
+{
+    return (lhs != rhs.getFullPath());
+}
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_IPATH_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/IStream.cpp b/src/platform/API/Filesystem/IStream.cpp
new file mode 100755 (executable)
index 0000000..17c730d
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// 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 "IStream.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+IStream::~IStream()
+{
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/IStream.h b/src/platform/API/Filesystem/IStream.h
new file mode 100755 (executable)
index 0000000..ca4d781
--- /dev/null
@@ -0,0 +1,128 @@
+//
+// 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_FILESYSTEM_ISTREAM_H_
+#define TIZENAPIS_FILESYSTEM_ISTREAM_H_
+
+#include <cstddef>
+#include <string>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class IStream;
+typedef DPL::SharedPtr<IStream> IStreamPtr;
+
+class IStream : private DPL::Noncopyable
+{
+  public:
+    virtual ~IStream() = 0;
+
+    virtual IStreamPtr write(bool arg) = 0;
+    virtual IStreamPtr write(unsigned char arg) = 0;
+    virtual IStreamPtr write(char arg) = 0;
+    virtual IStreamPtr write(int arg) = 0;
+    virtual IStreamPtr write(double arg) = 0;
+    virtual IStreamPtr write(const std::string& arg) = 0;
+
+    virtual IStreamPtr read(bool& arg) = 0;
+    virtual IStreamPtr read(unsigned char& arg) = 0;
+    virtual IStreamPtr read(char& arg) = 0;
+    virtual IStreamPtr read(int& arg) = 0;
+    virtual IStreamPtr read(double& arg) = 0;
+    virtual IStreamPtr read(std::string& arg) = 0;
+
+    /**
+     * Gets characters from stream.
+     * @param num Number of characters to read.
+     * @return Pointer to read buffer.
+     * @throw PlatformException if stream is closed, EOF is set or write-only.
+     * @remarks Passes ownership to the caller.
+     */
+    virtual char* getChars(std::size_t num) = 0;
+
+    /**
+     * Gets bytes from stream.
+     * @param num Number of bytes to read.
+     * @return Pointer to read buffer.
+     * @remarks Passes ownership to the caller.
+     * @throw PlatformException if stream is closed, EOF is set or write-only.
+     */
+    virtual unsigned char* getBytes(std::size_t num) = 0;
+
+    /**
+     * Gets number of bytes read by last getBytes() or getChars() operation.
+     * @return Number of read bytes.
+     * @throw PlatformException if stream is closed or write-only.
+     */
+    virtual std::size_t getCount() const = 0;
+
+    /**
+     * Reads line of characters from stream (till '\n' character).
+     * @return Read line.
+     */
+    virtual std::string getLine() = 0;
+
+    /**
+     * Checks whether stream is open.
+     * @return True if stream is open, false otherwsie.
+     */
+    virtual bool isOpen() const = 0;
+
+    /**
+     * Checks whether End-Of-Line character occured.
+     * @return True if EOF flag was set, false otherwise.
+     */
+    virtual bool isEof() const = 0;
+
+    /**
+     * Closes stream.
+     */
+    virtual void close() = 0;
+
+    /**
+     * Gets current position in stream.
+     * @return Position or -1 if fails.
+     */
+    virtual long getPosition() const = 0;
+
+    /**
+     * Sets current position in stream.
+     * @param position Position to set.
+     */
+    virtual void setPosition(long position) = 0;
+
+    /**
+     * Gets mode stream was opened in.
+     * @return Mode @see Api::Filesystem::AccessMode.
+     */
+    virtual int getMode() const = 0;
+
+    /**
+     * Gets stream's size.
+     * @return Size or -1 if unavailable (e.g. stream is write-only).
+     */
+    virtual long getSize() const = 0;
+};
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif /* TIZENAPIS_FILESYSTEM_ISTREAM_H_ */
diff --git a/src/platform/API/Filesystem/NodeFilter.cpp b/src/platform/API/Filesystem/NodeFilter.cpp
new file mode 100755 (executable)
index 0000000..f981519
--- /dev/null
@@ -0,0 +1,110 @@
+//
+// 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 "NodeFilter.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+OptionalString NodeFilter::getName() const
+{
+    return m_name;
+}
+
+void NodeFilter::setName(const OptionalString& name)
+{
+    m_name = name;
+}
+
+OptionalDate NodeFilter::getMinCreated() const
+{
+    return m_created.min;
+}
+
+void NodeFilter::setMinCreated(const OptionalDate& date)
+{
+    m_created.min = date;
+}
+
+OptionalDate NodeFilter::getMaxCreated() const
+{
+    return m_created.max;
+}
+
+void NodeFilter::setMaxCreated(const OptionalDate& date)
+{
+    m_created.max = date;
+}
+
+void NodeFilter::setCreated(const OptionalDate& date)
+{
+    m_created.min = m_created.max = date;
+}
+
+OptionalDate NodeFilter::getMinModified() const
+{
+    return m_modified.min;
+}
+
+void NodeFilter::setMinModified(const OptionalDate& date)
+{
+    m_modified.min = date;
+}
+
+OptionalDate NodeFilter::getMaxModified() const
+{
+    return m_modified.max;
+}
+
+void NodeFilter::setMaxModified(const OptionalDate& date)
+{
+    m_modified.max = date;
+}
+
+void NodeFilter::setModified(const OptionalDate& date)
+{
+    m_modified.min = m_modified.max = date;
+}
+
+OptionalSize NodeFilter::getMinSize() const
+{
+    return m_size.min;
+}
+
+void NodeFilter::setMinSize(const OptionalSize& size)
+{
+    m_size.min = size;
+}
+
+OptionalSize NodeFilter::getMaxSize() const
+{
+    return m_size.max;
+}
+
+void NodeFilter::setMaxSize(const OptionalSize& size)
+{
+    m_size.max = size;
+}
+
+void NodeFilter::setSize(const OptionalSize& size)
+{
+    m_size.min = m_size.max = size;
+}
+} // Filesystem
+} // Api
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/NodeFilter.h b/src/platform/API/Filesystem/NodeFilter.h
new file mode 100755 (executable)
index 0000000..cab7813
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// 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_FILESYSTEM_NODEFILTER_H_
+#define TIZENAPIS_FILESYSTEM_NODEFILTER_H_
+
+#include <ctime>
+#include <cstddef>
+#include <string>
+#include <dpl/optional.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/Range.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+typedef DPL::Optional<std::string> OptionalString;
+typedef DPL::Optional<std::time_t> OptionalDate;
+typedef DPL::Optional<std::size_t> OptionalSize;
+
+class NodeFilter
+{
+  public:
+    OptionalString getName() const;
+    void setName(const OptionalString& name);
+
+    OptionalDate getMinCreated() const;
+    void setMinCreated(const OptionalDate& date);
+
+    OptionalDate getMaxCreated() const;
+    void setMaxCreated(const OptionalDate& date);
+
+    void setCreated(const OptionalDate& date);
+
+    OptionalDate getMinModified() const;
+    void setMinModified(const OptionalDate& date);
+
+    OptionalDate getMaxModified() const;
+    void setMaxModified(const OptionalDate& date);
+
+    void setModified(const OptionalDate& date);
+
+    OptionalSize getMinSize() const;
+    void setMinSize(const OptionalSize& size);
+
+    OptionalSize getMaxSize() const;
+    void setMaxSize(const OptionalSize& size);
+
+    void setSize(const OptionalSize& size);
+
+  private:
+    OptionalString m_name;
+    WrtDeviceApis::Commons::Range<OptionalDate> m_created;
+    WrtDeviceApis::Commons::Range<OptionalDate> m_modified;
+    WrtDeviceApis::Commons::Range<OptionalSize> m_size;
+};
+
+typedef DPL::SharedPtr<NodeFilter> NodeFilterPtr;
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_NODEFILTER_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/PathUtils.cpp b/src/platform/API/Filesystem/PathUtils.cpp
new file mode 100755 (executable)
index 0000000..2e565b0
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// 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 "PathUtils.h"
+#include <dpl/log/log.h>
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+namespace PathUtils {
+PathList getParts(const IPathPtr& path)
+{
+    PathList result;
+    IPath::SeparatorType separator = path->getSeparator();
+    std::string fullPath = path->getFullPath();
+    std::string::size_type pos = 0;
+    while ((pos = fullPath.find(separator, pos + 1)) != std::string::npos) {
+        result.push_back(IPath::create(fullPath.substr(0, pos)));
+    }
+    return result;
+}
+} // PathUtils
+} // Filesystem
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filesystem/PathUtils.h b/src/platform/API/Filesystem/PathUtils.h
new file mode 100755 (executable)
index 0000000..23aaf8e
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// 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_FILESYSTEM_PATHUTILS_H_
+#define TIZENAPIS_FILESYSTEM_PATHUTILS_H_
+
+#include <vector>
+#include "IPath.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+namespace PathUtils {
+typedef std::vector<IPathPtr> PathList;
+typedef PathList::iterator PathListIterator;
+
+/**
+ * Gets sub-paths of supplied path.
+ * The supplied path is not included.
+ * @param path
+ * @return List of paths.
+ */
+PathList getParts(const IPathPtr& path);
+} // PathUtils
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_PATHUTILS_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/StorageProperties.cpp b/src/platform/API/Filesystem/StorageProperties.cpp
new file mode 100755 (executable)
index 0000000..d207ee3
--- /dev/null
@@ -0,0 +1,84 @@
+//
+// 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 "StorageProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+StorageProperties::StorageProperties() :
+               id(0),
+               label(""),
+               type(0),
+               state(0),
+               fullpath("")
+{
+}
+
+void StorageProperties::setId (const int Id)
+{
+       id = Id;
+}
+
+void StorageProperties::setLabel (const std::string &Label)
+{
+       label = Label;
+}
+
+void StorageProperties::setType (const short Type)
+{
+       type = Type;
+}
+
+void StorageProperties::setState (const short State)
+{
+       state = State;
+}
+
+void StorageProperties::setFullPath (const std::string &FullPath)
+{
+       fullpath = FullPath;
+}
+
+int StorageProperties::getId() const
+{
+       return id;
+}
+
+std::string StorageProperties::getLabel() const
+{
+       return label;
+}
+
+short StorageProperties::getType() const
+{
+       return type;
+}
+
+short StorageProperties::getState() const
+{
+       return state;
+}
+
+std::string StorageProperties::getFullPath() const
+{
+       return fullpath;
+}
+} // Filesystem
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filesystem/StorageProperties.h b/src/platform/API/Filesystem/StorageProperties.h
new file mode 100755 (executable)
index 0000000..12ac84b
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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_FILESYSTEM_STORAGE_PROPERTIES_H_
+#define TIZENAPIS_API_FILESYSTEM_STORAGE_PROPERTIES_H_
+
+#include <dpl/shared_ptr.h>
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Filesystem {
+class StorageProperties;
+typedef DPL::SharedPtr<StorageProperties> StoragePropertiesPtr;
+
+class StorageProperties
+{
+private:
+       int id;
+       std::string label;
+       short type;
+       short state;
+       std::string fullpath;
+public:
+       enum StorageType
+       {
+               TYPE_INTERNAL = 0,
+               TYPE_EXTERNAL,
+       };
+
+       enum StorageState
+       {
+               STATE_UNMOUNTABLE = -2,
+               STATE_REMOVED = -1,
+               STATE_MOUNTED = 0,
+               STATE_MOUNTED_READONLY = 1,
+       };
+
+       void setId (const int Id);
+       void setLabel (const std::string &Label);
+       void setType (const short Type);
+       void setState (const short State);
+       void setFullPath (const std::string &FullPath);
+
+       int getId() const;
+       std::string getLabel() const;
+       short getType() const;
+       short getState() const;
+       std::string getFullPath() const;
+       
+       StorageProperties();
+};
+} // Filesystem
+} // Api
+} // TizenApis
+
+#endif //TIZENAPIS_API_FILESYSTEM_STORAGE_PROPERTIES_H_
\ No newline at end of file
diff --git a/src/platform/API/Filesystem/config.cmake b/src/platform/API/Filesystem/config.cmake
new file mode 100755 (executable)
index 0000000..8993a7b
--- /dev/null
@@ -0,0 +1,23 @@
+get_current_path()
+
+set(SRCS_PLATFORM_API_FILESYSTEM
+  ${CURRENT_PATH}/IManager.cpp
+  ${CURRENT_PATH}/IPath.cpp
+  ${CURRENT_PATH}/IStream.cpp
+  ${CURRENT_PATH}/EventResolve.cpp
+  ${CURRENT_PATH}/EventGetStorage.cpp
+  ${CURRENT_PATH}/EventListStorages.cpp  
+  ${CURRENT_PATH}/EventCopy.cpp
+  ${CURRENT_PATH}/EventMove.cpp
+  ${CURRENT_PATH}/EventRemove.cpp
+  ${CURRENT_PATH}/EventFind.cpp
+  ${CURRENT_PATH}/EventListNodes.cpp
+  ${CURRENT_PATH}/EventOpen.cpp
+  ${CURRENT_PATH}/EventReadText.cpp
+  ${CURRENT_PATH}/INode.cpp
+  ${CURRENT_PATH}/NodeFilter.cpp
+  ${CURRENT_PATH}/PathUtils.cpp
+  ${CURRENT_PATH}/StorageProperties.cpp
+  ${CURRENT_PATH}/EventStoragestateChanged.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Filter/AnyType.cpp b/src/platform/API/Filter/AnyType.cpp
new file mode 100755 (executable)
index 0000000..369be1d
--- /dev/null
@@ -0,0 +1,399 @@
+//
+// 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        AnyType.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSFilter class
+ */
+
+#include <limits>
+#include <sstream>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include "AnyType.h"
+#include <Tizen/TimeUtil/TimeUtilConverter.h>
+#include <Tizen/TimeUtil/JSTZDate.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+Any::Any()
+{
+       m_type = PrimitiveType_Null;
+       m_value.i = 0;
+       m_json = "null";
+       m_priv = NULL;
+}
+
+Any::Any(bool value)
+{
+       m_type = PrimitiveType_Boolean;
+       m_value.b = value;
+       m_json = value?"true":"false";
+       m_priv = NULL;
+}
+
+Any::Any(double value, std::string json)
+{
+       m_type = PrimitiveType_Double;
+       m_value.d = value;
+       m_json = json;
+       m_priv = NULL;
+
+       if(value == (double)((char)value))
+               m_type |= PrimitiveType_Char;
+       if(value == (double)((unsigned char)value))
+               m_type |= PrimitiveType_UChar;
+       if(value == (double)((int)value))
+               m_type |= PrimitiveType_Int;
+       if(value == (double)((unsigned int)value))
+               m_type |= PrimitiveType_UInt;
+       if(value == (double)((long)value))
+               m_type |= PrimitiveType_Long;
+       if(value == (double)((unsigned long)value))
+               m_type |= PrimitiveType_ULong;
+}
+
+Any::Any(std::string value)
+{
+       m_type = PrimitiveType_String;
+       m_value.s = new std::string(value);
+       m_json = "\"" + value + "\"";
+       m_priv = NULL;
+}
+
+Any::Any(std::tm value, std::string json)
+{
+       m_type = PrimitiveType_Time;
+       m_value.t = value;
+       m_json = json;
+       m_priv = NULL;
+}
+
+Any::Any(void * priv, std::string json)
+{
+       m_type = PrimitiveType_Object;
+       m_value.i = 0;
+       m_json = json;
+       m_priv = priv;
+}
+
+Any::~Any()
+{
+       if(m_type == PrimitiveType_String)
+               delete m_value.s;
+}
+
+std::string Any::toString() const
+{
+       std::stringstream oss;
+
+       if(m_type == PrimitiveType_Undefined || m_type == PrimitiveType_Null)
+               return "";
+       else if(m_type == PrimitiveType_Boolean)
+               return m_json;
+       else if(m_type == PrimitiveType_String)
+               return *m_value.s;
+       else if(m_type == PrimitiveType_Object)
+               return m_json;
+       else if(m_type & PrimitiveType_Number)
+       {
+               if(m_type & PrimitiveType_ULong)
+                       oss << (unsigned long)m_value.d;
+               else if(m_type & PrimitiveType_Long)
+                       oss << (long)m_value.d;
+               else
+               {
+                       oss << std::setprecision(std::numeric_limits<double>::digits10);
+                       oss << std::setiosflags(std::ios::fixed);
+                       oss << m_value.d;
+               }
+
+               return oss.str();
+       }
+       else if(m_type == PrimitiveType_Time)
+       {
+               oss << std::setfill('0') << std::setiosflags(std::ios::right) << std::setw(4) << (m_value.t.tm_year + 1900);
+               oss << std::setfill('0') << std::setiosflags(std::ios::right) << std::setw(2) << (m_value.t.tm_mon + 1);
+               oss << std::setfill('0') << std::setiosflags(std::ios::right) << std::setw(2) << m_value.t.tm_mday;
+               oss << std::setfill('0') << std::setiosflags(std::ios::right) << std::setw(2) << m_value.t.tm_hour;
+               oss << std::setfill('0') << std::setiosflags(std::ios::right) << std::setw(2) << m_value.t.tm_min;
+               oss << std::setfill('0') << std::setiosflags(std::ios::right) << std::setw(2) << m_value.t.tm_sec;
+
+               return oss.str();
+       }
+       else
+               return m_json;
+}
+
+std::string Any::toJSON() const
+{
+       return m_json;
+}
+
+unsigned int Any::getType() const
+{
+       return m_type;
+}
+
+bool Any::isType(PrimitiveType type) const
+{
+       return (bool)(m_type & type);
+}
+
+bool Any::isNullOrUndefined() const
+{
+       return (bool)((m_type & PrimitiveType_Undefined) | (m_type & PrimitiveType_Null));
+}
+
+bool Any::getBool() const
+{
+       if(m_type != PrimitiveType_Boolean)
+               ThrowMsg(InvalidArgumentException, "Type mismatch.");
+
+       return m_value.b;
+}
+
+char Any::getChar() const
+{
+       if(!(m_type & PrimitiveType_Char))
+               ThrowMsg(InvalidArgumentException, "Type mismatch.");
+
+       return (char)m_value.d;
+}
+
+unsigned char Any::getUChar() const
+{
+       if(!(m_type & PrimitiveType_UChar))
+               ThrowMsg(InvalidArgumentException, "Type mismatch.");
+
+       return (unsigned char)m_value.d;
+}
+
+int Any::getInt() const
+{
+       if(!(m_type & PrimitiveType_Int))
+               ThrowMsg(InvalidArgumentException, "Type mismatch.");
+
+       return (int)m_value.d;
+}
+
+unsigned int Any::getUInt() const
+{
+       if(!(m_type & PrimitiveType_UInt))
+               ThrowMsg(InvalidArgumentException, "Type mismatch.");
+
+       return (unsigned int)m_value.d;
+}
+
+long Any::getLong() const
+{
+       if(!(m_type & PrimitiveType_Long))
+               ThrowMsg(InvalidArgumentException, "Type mismatch.");
+
+       return (long)m_value.d;
+}
+
+unsigned long Any::getULong() const
+{
+       if(!(m_type & PrimitiveType_ULong))
+               ThrowMsg(InvalidArgumentException, "Type mismatch.");
+
+       return (unsigned long)m_value.d;
+}
+
+double Any::getDouble() const
+{
+       if(!(m_type & PrimitiveType_Double))
+               ThrowMsg(InvalidArgumentException, "Type mismatch.");
+
+       return m_value.d;
+}
+
+std::string Any::getString() const
+{
+       if(m_type != PrimitiveType_String)
+               ThrowMsg(InvalidArgumentException, "Type mismatch.");
+
+       return *m_value.s;
+}
+
+std::tm Any::getDateTm() const
+{
+       if(m_type != PrimitiveType_Time)
+               ThrowMsg(InvalidArgumentException, "Type mismatch.");
+
+       return m_value.t;
+}
+
+std::time_t Any::getTimeT() const
+{
+       if(m_type != PrimitiveType_Time)
+               ThrowMsg(InvalidArgumentException, "Type mismatch.");
+
+       std::tm *time = const_cast<std::tm*>(&(m_value.t));
+       return timegm(time);
+}
+
+AnyTypeConverter::AnyTypeConverter(JSContextRef context) :
+               Converter(context)
+{
+}
+
+AnyTypeConverter::~AnyTypeConverter()
+{
+}
+
+JSValueRef AnyTypeConverter::toJSValueRef(const AnyPtr& arg)
+{
+       if(arg->isType(PrimitiveType_Undefined))
+               return JSValueMakeUndefined(m_context);
+       else if(arg->isType(PrimitiveType_Null))
+               return JSValueMakeNull(m_context);
+       else if(arg->isType(PrimitiveType_Boolean))
+               return toJSValueRef(arg->getBool());
+       else if(arg->isType(PrimitiveType_Number))
+               return toJSValueRef(arg->getDouble());
+       else if(arg->isType(PrimitiveType_String))
+               return toJSValueRef(arg->getString());
+       else if(arg->isType(PrimitiveType_Time))
+               return toJSValueRef(arg->getDateTm());
+       else if(arg->isType(PrimitiveType_Object))
+       {
+               ScopedJSStringRef json(JSStringCreateWithUTF8CString(arg->toJSON().c_str()));
+               return JSValueMakeFromJSONString(m_context, json.get());
+       }
+
+       return JSValueMakeUndefined(m_context);
+}
+
+AnyPtr AnyTypeConverter::toAny(const JSValueRef &value)
+{
+       JSType jstype = JSValueGetType(m_context, value);
+       ScopedJSStringRef json(JSValueCreateJSONString(m_context, value, 0, NULL));
+
+       if(jstype == kJSTypeBoolean)
+               return AnyPtr(new Any(Converter::toBool(value)));
+       else if(jstype == kJSTypeNumber)
+               return AnyPtr(new Any(Converter::toDouble(value), toString(json.get())));
+       else if(jstype == kJSTypeString)
+               return AnyPtr(new Any(Converter::toString(value)));
+       else if(jstype == kJSTypeObject)
+       {
+               if(isDate(value))
+                       return AnyPtr(new Any(Converter::toDateTm(value), toString(json.get())));
+               else if(JSValueIsObjectOfClass(m_context, value, TizenApis::Tizen1_0::JSTZDate::getClassRef()))
+               {
+                       TizenApis::Tizen1_0::TimeUtilConverter timeConverter(m_context);
+                       std::tm tmValue = timeConverter.toTZDateTime(value);
+                       std::stringstream ss;
+                       ss<<timegm(&tmValue);
+                       return AnyPtr(new Any(tmValue, ss.str()));
+               }
+               else
+               {
+                       void *priv = NULL;
+                       JSObjectRef object = JSValueToObject(m_context, value, NULL);
+                       if (object)
+                               priv = JSObjectGetPrivate(object);
+
+                       return AnyPtr(new Any(priv, toString(json.get())));
+               }
+       }
+       else
+               return AnyPtr(new Any());
+}
+
+bool AnyTypeConverter::toBool(const AnyPtr& arg)
+{
+       return arg->getBool();
+}
+
+char AnyTypeConverter::toChar(const AnyPtr& arg)
+{
+       return arg->getChar();
+}
+
+unsigned char AnyTypeConverter::toUChar(const AnyPtr& arg)
+{
+       return arg->getUChar();
+}
+
+int AnyTypeConverter::toInt(const AnyPtr& arg)
+{
+       return arg->getInt();
+}
+
+unsigned int AnyTypeConverter::toUInt(const AnyPtr& arg)
+{
+       return arg->getUInt();
+}
+
+long AnyTypeConverter::toLong(const AnyPtr& arg)
+{
+       return arg->getLong();
+}
+
+unsigned long AnyTypeConverter::toULong(const AnyPtr& arg)
+{
+       return arg->getULong();
+}
+
+double AnyTypeConverter::toDouble(const AnyPtr& arg)
+{
+       return arg->getDouble();
+}
+
+std::string AnyTypeConverter::toString(const AnyPtr& arg)
+{
+       return arg->getString();
+}
+
+tm AnyTypeConverter::toDateTm(const AnyPtr& arg)
+{
+       return arg->getDateTm();
+}
+
+time_t AnyTypeConverter::toTimeT(const AnyPtr& arg)
+{
+       return arg->getTimeT();
+}
+
+bool AnyTypeConverter::isDate(const JSValueRef& arg)
+{
+       // this method originated from TizenApis::Commons::Validator::isDate()
+       if ( JSValueIsNull( m_context, arg ) || JSValueIsUndefined( m_context, arg ) || !JSValueIsObject( m_context, arg ) )
+               return false;
+
+       Try {
+               toDateTm( arg );
+       } Catch(Exception) {
+               return false;
+       }
+       return true;
+}
+
+} // Tizen
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filter/AnyType.h b/src/platform/API/Filter/AnyType.h
new file mode 100755 (executable)
index 0000000..c7a24e5
--- /dev/null
@@ -0,0 +1,165 @@
+//
+// 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        AnyType.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSFilter class
+ */
+
+#ifndef _API_ANYTYPE_H_
+#define _API_ANYTYPE_H_
+
+#include <ctime>
+#include <iomanip>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Converter.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+
+#define _PT_UNDEFINED  (0)
+#define _PT_NULL               (1 << 0)
+#define _PT_BOOLEAN            (1 << 1)
+#define _PT_CHAR               (1 << 2)
+#define _PT_UCHAR              (1 << 3)
+#define _PT_INT                        (1 << 4)
+#define _PT_UINT               (1 << 5)
+#define _PT_LONG               (1 << 6)
+#define _PT_ULONG              (1 << 7)
+#define _PT_DOUBLE             (1 << 8)
+#define _PT_STRING             (1 << 9)
+#define _PT_TIME               (1 << 10)
+#define _PT_OBJECT             (1 << 11)
+
+enum PrimitiveType {
+       PrimitiveType_NoType    = 0,
+       PrimitiveType_Undefined = _PT_UNDEFINED,
+       PrimitiveType_Null              = _PT_NULL,
+       PrimitiveType_Boolean   = _PT_BOOLEAN,
+       PrimitiveType_Char              = _PT_CHAR,
+       PrimitiveType_UChar             = _PT_UCHAR,
+       PrimitiveType_Int               = _PT_INT,
+       PrimitiveType_UInt              = _PT_UINT,
+       PrimitiveType_Long              = _PT_LONG,
+       PrimitiveType_ULong             = _PT_ULONG,
+       PrimitiveType_Double    = _PT_DOUBLE,
+       PrimitiveType_String    = _PT_STRING,
+       PrimitiveType_Time              = _PT_TIME,
+       PrimitiveType_Object    = _PT_OBJECT,
+       PrimitiveType_Number    = (_PT_CHAR | _PT_UCHAR | _PT_INT | _PT_UINT |
+                                                               _PT_LONG | _PT_ULONG | _PT_DOUBLE),
+       PrimitiveType_Integer   = (_PT_CHAR | _PT_UCHAR | _PT_INT | _PT_UINT |
+                                                               _PT_LONG | _PT_ULONG),
+       PrimitiveType_Any               = (_PT_BOOLEAN | _PT_CHAR | _PT_UCHAR | _PT_INT |
+                                                               _PT_UINT | _PT_LONG | _PT_ULONG | _PT_DOUBLE |
+                                                               _PT_STRING | _PT_TIME | _PT_OBJECT)
+};
+
+class Any
+{
+private:
+       union AnyTypeUnion
+       {
+               bool b;
+               double d;
+               std::tm t;
+               std::string* s;
+               int i;
+       };
+
+       unsigned int m_type;
+
+       AnyTypeUnion m_value;
+
+       std::string m_json;
+
+       void * m_priv;
+
+public:
+       Any();
+       Any(bool value);
+       Any(double value, std::string json);
+       Any(std::string value);
+       Any(std::tm value, std::string json);
+       Any(void * priv, std::string json);
+       virtual ~Any();
+
+       virtual std::string toString() const;
+       std::string toJSON() const;
+
+       unsigned int getType() const;
+       bool isType(PrimitiveType type) const;
+       bool isNullOrUndefined() const;
+
+       bool getBool() const;
+       char getChar() const;
+       unsigned char getUChar() const;
+       int getInt() const;
+       unsigned int getUInt() const;
+       long getLong() const;
+       unsigned long getULong() const;
+       double getDouble() const;
+       std::string getString() const;
+       std::tm getDateTm() const;
+       std::time_t getTimeT() const;
+};
+typedef DPL::SharedPtr<Any> AnyPtr;
+
+typedef std::vector<AnyPtr> AnyArray;
+typedef DPL::SharedPtr<AnyArray> AnyArrayPtr;
+
+class AnyTypeConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+public:
+       explicit AnyTypeConverter(JSContextRef context);
+       virtual ~AnyTypeConverter();
+
+       JSValueRef toJSValueRef(const AnyPtr& arg);
+       AnyPtr toAny(const JSValueRef &value);
+
+       bool toBool(const AnyPtr& arg);
+       char toChar(const AnyPtr& arg);
+       unsigned char toUChar(const AnyPtr& arg);
+       int toInt(const AnyPtr& arg);
+       unsigned int toUInt(const AnyPtr& arg);
+       long toLong(const AnyPtr& arg);
+       unsigned long toULong(const AnyPtr& arg);
+       double toDouble(const AnyPtr& arg);
+       std::string toString(const AnyPtr& arg);
+       tm toDateTm(const AnyPtr& arg);
+       time_t toTimeT(const AnyPtr& arg);
+
+       using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
+       using WrtDeviceApis::CommonsJavaScript::Converter::toString;
+       using WrtDeviceApis::CommonsJavaScript::Converter::toDateTm;
+
+protected:
+       bool isDate(const JSValueRef& arg);
+};
+
+typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<AnyTypeConverter> AnyTypeConverterFactory;
+
+} // Tizen
+} // Api
+} // TizenApis
+
+#endif // _API_ANYTYPE_H_
diff --git a/src/platform/API/Filter/AttributeFilter.cpp b/src/platform/API/Filter/AttributeFilter.cpp
new file mode 100644 (file)
index 0000000..a4fb230
--- /dev/null
@@ -0,0 +1,88 @@
+//
+// 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       AttributeFilter.cpp
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#include "AttributeFilter.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+using namespace std;
+
+AttributeFilter::AttributeFilter(const string attributeName,
+        const MatchFlag& matchFlag,
+               const AnyPtr& matchValue) :
+       m_attributeName(attributeName),
+       m_matchFlag(matchFlag),
+       m_matchValue(matchValue)
+{
+}
+
+AttributeFilter::~AttributeFilter()
+{
+}
+
+string AttributeFilter::getAttributeName() const
+{
+       return m_attributeName;
+}
+
+void AttributeFilter::setAttributeName(const string &value)
+{
+       m_attributeName = value;
+}
+
+bool AttributeFilter::validate(FilterValidatorPtr& validator, int depth)
+{
+       return validator->validateAttribute(m_attributeName, m_matchFlag, m_matchValue, depth);
+}
+
+void AttributeFilter::travel(IFilterVisitorPtr& visitor, int depth)
+{
+       visitor->visitAttribute(m_attributeName, m_matchFlag, m_matchValue, depth);
+}
+
+AnyPtr AttributeFilter::getMatchValue() const
+{
+       return m_matchValue;
+}
+
+void AttributeFilter::setMatchValue(const AnyPtr &value)
+{
+       m_matchValue = value;
+}
+
+MatchFlag AttributeFilter::getMatchFlag() const
+{
+       return m_matchFlag;
+}
+
+void AttributeFilter::setMatchFlag(const MatchFlag& value)
+{
+       m_matchFlag = value;
+}
+
+} // Tizen
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filter/AttributeFilter.h b/src/platform/API/Filter/AttributeFilter.h
new file mode 100644 (file)
index 0000000..db8fa3e
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// 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       AttributeFilter.h
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _API_ATTRIBUTE_FILTER_H_
+#define _API_ATTRIBUTE_FILTER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "AnyType.h"
+#include "IFilter.h"
+#include "FilterTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+class AttributeFilter : public IFilter
+{
+private: // fields
+
+       /**
+        * attribute name object
+        */
+       std::string  m_attributeName;
+
+       /**
+        * match value object.
+        */
+       MatchFlag  m_matchFlag;
+
+       /**
+        * match value object.
+        */
+       AnyPtr  m_matchValue;
+
+protected:
+
+public: // methods
+
+       /**
+        * constructor of abstraction filter
+        */
+       explicit AttributeFilter(const std::string attributeName,
+               const MatchFlag& matchFlag,
+                       const AnyPtr& matchValue);
+
+       virtual ~AttributeFilter();
+
+       /**
+        * method used to identify filter type
+        */
+       virtual FilterType getFilterType() const
+       {
+               return ATTRIBUTE_FILTER;
+       }
+
+       virtual bool setFilterType(const FilterType& filterType) { return false; };
+
+       virtual bool validate(FilterValidatorPtr& validator, int depth = 0);
+
+       virtual void travel(IFilterVisitorPtr& traversal, int depth = 0);
+
+       std::string getAttributeName() const;
+       void setAttributeName(const std::string &value);
+
+       AnyPtr getMatchValue() const;
+       void setMatchValue(const AnyPtr &value);
+
+       MatchFlag getMatchFlag() const;
+       void setMatchFlag(const MatchFlag& value);
+};
+
+typedef DPL::SharedPtr<AttributeFilter> AttributeFilterPtr;
+
+} // Tizen
+} // Api
+} // TizenApis
+
+#endif // _API_ATTRIBUTE_FILTER_H_
diff --git a/src/platform/API/Filter/AttributeRangeFilter.cpp b/src/platform/API/Filter/AttributeRangeFilter.cpp
new file mode 100644 (file)
index 0000000..f11b8b8
--- /dev/null
@@ -0,0 +1,88 @@
+//
+// 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       AttributeRangeFilter.cpp
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#include "AttributeRangeFilter.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+using namespace std;
+
+AttributeRangeFilter::AttributeRangeFilter(const string& attributeName,
+               const AnyPtr& initialValue,
+               const AnyPtr& endValue) :
+       m_attributeName(attributeName),
+       m_initialValue(initialValue),
+       m_endValue(endValue)
+{
+}
+
+AttributeRangeFilter::~AttributeRangeFilter()
+{
+}
+
+bool AttributeRangeFilter::validate(FilterValidatorPtr& validator, int depth)
+{
+       return validator->validateAttributeRange(m_attributeName, m_initialValue, m_endValue, depth);
+}
+
+void AttributeRangeFilter::travel(IFilterVisitorPtr& visitor, int depth)
+{
+       visitor->visitAttributeRange(m_attributeName, m_initialValue, m_endValue, depth);
+}
+
+string AttributeRangeFilter::getAttributeName() const
+{
+       return m_attributeName;
+}
+
+AnyPtr AttributeRangeFilter::getInitialValue() const
+{
+       return m_initialValue;
+}
+
+AnyPtr AttributeRangeFilter::getEndValue() const
+{
+       return m_endValue;
+}
+
+void AttributeRangeFilter::setAttributeName(const string& attributeName)
+{
+       m_attributeName = attributeName;
+}
+
+void AttributeRangeFilter::setInitialValue(const AnyPtr& initialValue)
+{
+       m_initialValue = initialValue;
+}
+
+void AttributeRangeFilter::setEndValue(const AnyPtr& endValue)
+{
+       m_endValue = endValue;
+}
+
+} // Tizen
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filter/AttributeRangeFilter.h b/src/platform/API/Filter/AttributeRangeFilter.h
new file mode 100644 (file)
index 0000000..585040c
--- /dev/null
@@ -0,0 +1,118 @@
+//
+// 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       AttributeRangeFilter.h
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _API_ATTRIBUTE_RANGE_FILTER_H_
+#define _API_ATTRIBUTE_RANGE_FILTER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "AnyType.h"
+#include "IFilter.h"
+#include "FilterTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+class AttributeRangeFilter : public IFilter
+{
+private: // fields
+       /**
+        * attribute name
+        */
+       std::string  m_attributeName;
+
+       /**
+        * initial value
+        */
+       AnyPtr  m_initialValue;
+
+       /**
+        * end value
+        */
+       AnyPtr  m_endValue;
+
+protected:
+
+public: // methods
+       /**
+        * constructor of abstraction filter
+        */
+       explicit AttributeRangeFilter(const std::string& attributeName,
+                       const AnyPtr& initialValue,
+                       const AnyPtr& endValue);
+
+       virtual ~AttributeRangeFilter();
+
+       /**
+        * method used to identify filter type
+        */
+       virtual FilterType getFilterType() const
+       {
+               return ATTRIBUTE_RANGE_FILTER;
+       }
+       virtual bool setFilterType(const FilterType& filterType) { return false; };
+
+       virtual bool validate(FilterValidatorPtr& validator, int depth = 0);
+
+       virtual void travel(IFilterVisitorPtr& visitor, int depth = 0);
+
+       /**
+        * method used to get attribute name
+        */
+       std::string getAttributeName() const;
+
+       /**
+        * method used to get initial value
+        */
+       AnyPtr getInitialValue() const;
+
+       /**
+        * method used to get end value
+        */
+       AnyPtr getEndValue() const;
+
+       /**
+        * method used to set attribute name
+        */
+       void setAttributeName(const std::string& attributeName);
+
+       /**
+        * method used to set initial value
+        */
+       void setInitialValue(const AnyPtr& initialValue);
+
+       /**
+        * method used to set end value
+        */
+       void setEndValue(const AnyPtr& endValue);
+};
+
+typedef DPL::SharedPtr<AttributeRangeFilter> AttributeRangeFilterPtr;
+
+} // Tizen
+} // Api
+} // TizenApis
+
+#endif // _API_ATTRIBUTE_RANGE_FILTER_H_
diff --git a/src/platform/API/Filter/CompositeFilter.cpp b/src/platform/API/Filter/CompositeFilter.cpp
new file mode 100644 (file)
index 0000000..fa5467a
--- /dev/null
@@ -0,0 +1,104 @@
+//
+// 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       CompositeFilter.cpp
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#include "CompositeFilter.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+CompositeFilter::CompositeFilter(const FilterType& type, const FilterArrayPtr& filters) :
+               m_filters(filters)
+{
+       if(type != UNION_FILTER && type != INTERSECTION_FILTER)
+               m_type = UNION_FILTER;
+       else
+               m_type = type;
+}
+
+CompositeFilter::~CompositeFilter()
+{
+}
+
+FilterType CompositeFilter::getFilterType() const
+{
+       return m_type;
+}
+
+bool CompositeFilter::setFilterType(const FilterType& filterType)
+{
+       if(filterType != UNION_FILTER && filterType != INTERSECTION_FILTER)
+               return false;
+
+       m_type = filterType;
+       return true;
+}
+
+bool CompositeFilter::validate(FilterValidatorPtr& validator, int depth)
+{
+       FilterArray::iterator it;
+
+       for(it=m_filters->begin(); it != m_filters->end(); it++)
+       {
+               if(!(*it)->validate(validator, depth+1))
+                       return false;
+       }
+
+       return validator->validateComposite(depth);
+}
+
+void CompositeFilter::travel(IFilterVisitorPtr& visitor, int depth)
+{
+       visitor->visitPreComposite(m_type, depth);
+
+       FilterArray::iterator it = m_filters->begin();
+       if(it != m_filters->end())
+       {
+               while(1)
+               {
+                       (*it)->travel(visitor, depth+1);
+
+                       if(++it == m_filters->end())
+                               break;
+
+                       visitor->visitInComposite(m_type, depth);
+               }
+       }
+
+       visitor->visitPostComposite(m_type, depth);
+}
+
+FilterArrayPtr CompositeFilter::getFilters() const
+{
+       return m_filters;
+}
+
+void CompositeFilter::setFilters(const FilterArrayPtr& value)
+{
+       m_filters = value;
+}
+
+} // Tizen
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filter/CompositeFilter.h b/src/platform/API/Filter/CompositeFilter.h
new file mode 100644 (file)
index 0000000..8b147d8
--- /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.
+//
+
+/**
+ * @file       CompositeFilter.h
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _API_COMPOSITE_FILTER_H_
+#define _API_COMPOSITE_FILTER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "IFilter.h"
+#include "FilterTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+class CompositeFilter : public IFilter
+{
+private: // fields
+       /**
+        * filter type. UNION_FILTER(OR) or INTERSECTION_FILTER(AND)
+        */
+       FilterType              m_type;
+
+       /**
+        * filter array.
+        */
+       FilterArrayPtr  m_filters;
+
+protected:
+
+public: // methods
+       /**
+        * constructor of abstraction filter
+        * @param[in] filterType - type of filter according to FilterType
+        */
+       explicit CompositeFilter(const FilterType& type, const FilterArrayPtr& filters);
+
+       virtual ~CompositeFilter();
+
+       /**
+        * method used to identify filter type
+        */
+       virtual FilterType getFilterType() const;
+
+       virtual bool setFilterType(const FilterType& filterType);
+
+       virtual bool validate(FilterValidatorPtr& validator, int depth = 0);
+
+       virtual void travel(IFilterVisitorPtr& visitor, int depth = 0);
+
+       FilterArrayPtr getFilters() const;
+       void setFilters(const FilterArrayPtr& value);
+};
+
+typedef DPL::SharedPtr<CompositeFilter> CompositeFilterPtr;
+
+} // Tizen
+} // Api
+} // TizenApis
+
+#endif // _API_COMPOSITE_FILTER_H_
diff --git a/src/platform/API/Filter/FilterFactory.cpp b/src/platform/API/Filter/FilterFactory.cpp
new file mode 100644 (file)
index 0000000..27f3fb6
--- /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.
+//
+
+/**
+ * @file        FilterFactory.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "FilterFactory.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+using namespace std;
+
+CompositeFilterPtr FilterFactory::createCompositeFilterObject(const FilterType& type,
+               const FilterArrayPtr& filters)
+{
+       CompositeFilterPtr result(new CompositeFilter(type, filters));
+    return result;
+}
+
+AttributeFilterPtr FilterFactory::createAttributeFilterObject(const string& attributeName,
+               const MatchFlag& matchFlag,
+               const AnyPtr& matchValue)
+{
+       AttributeFilterPtr result(new AttributeFilter(attributeName, matchFlag, matchValue));
+    return result;
+}
+
+AttributeRangeFilterPtr FilterFactory::createAttributeRangeFilterObject(const string& attributeName,
+               const AnyPtr& initialValue,
+        const AnyPtr& endValue)
+{
+       AttributeRangeFilterPtr result(new AttributeRangeFilter(attributeName, initialValue, endValue));
+    return result;
+}
+
+SortModePtr FilterFactory::createSortModeObject(const string& attributeName, const SortOrder& type)
+{
+       SortModePtr result(new SortMode(attributeName, type));
+    return result;
+}
+
+FilterFactory& FilterFactory::getInstance()
+{
+    static FilterFactory theInstance;
+    return theInstance;
+}
+
+} // Tizen
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filter/FilterFactory.h b/src/platform/API/Filter/FilterFactory.h
new file mode 100644 (file)
index 0000000..b495f45
--- /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.
+//
+
+/**
+ * @file        FilterFactory.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_FILTER_FACTORY_H_
+#define _API_FILTER_FACTORY_H_
+
+#include <string>
+#include "CompositeFilter.h"
+#include "AttributeFilter.h"
+#include "AttributeRangeFilter.h"
+#include "SortMode.h"
+#include "AnyType.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+class FilterFactory : private DPL::Noncopyable
+{
+private:
+       FilterFactory()
+       {
+       }
+
+public:
+       static FilterFactory& getInstance();
+
+       CompositeFilterPtr createCompositeFilterObject(const FilterType& type,
+                       const FilterArrayPtr& filters);
+
+       AttributeFilterPtr createAttributeFilterObject(const std::string& attributeName,
+                       const MatchFlag& matchFlag,
+                       const AnyPtr& matchValue);
+
+       AttributeRangeFilterPtr createAttributeRangeFilterObject(const std::string& attributeName,
+                       const AnyPtr& initialValue,
+                       const AnyPtr& endValue);
+
+       SortModePtr     createSortModeObject(const std::string& attributeName,
+                       const SortOrder& type = ASCENDING_SORT_ORDER);
+};
+
+} // Tizen
+} // Api
+} // TizenApis
+
+#endif // _API_FILTER_FACTORY_H_
diff --git a/src/platform/API/Filter/FilterTypes.h b/src/platform/API/Filter/FilterTypes.h
new file mode 100644 (file)
index 0000000..e4bf94d
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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       FilterTypes.h
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _API_FILTER_TYPES_H_
+#define _API_FILTER_TYPES_H_
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+enum FilterType
+{
+       UNION_FILTER,
+       INTERSECTION_FILTER,
+       ATTRIBUTE_FILTER,
+       ATTRIBUTE_RANGE_FILTER,
+    FILTERTYPE_COUNT
+};
+
+enum MatchFlag
+{
+       MATCH_NONE,
+       MATCH_EXACTLY,
+       MATCH_FULLSTRING,
+       MATCH_CONTAINS,
+       MATCH_STARTSWITH,
+       MATCH_ENDSWITH,
+       MATCH_EXISTS
+};
+
+enum SortOrder
+{
+       ASCENDING_SORT_ORDER = 1,
+       DESCENDING_SORT_ORDER = 2
+};
+
+} // TizenApis
+} // Api
+} // TizenApis
+
+#endif // _API_FILTER_TYPES_H_
+
diff --git a/src/platform/API/Filter/FilterValidator.cpp b/src/platform/API/Filter/FilterValidator.cpp
new file mode 100644 (file)
index 0000000..9643f7d
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// 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       IFilterTracer.cpp
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include "FilterValidator.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+using namespace std;
+
+FilterValidator::FilterValidator(PropertyStructArray properties)
+{
+       int i;
+       for(i=0; properties[i].attributeName != 0 ; i++)
+               m_properties[properties[i].attributeName] =
+                               PropertyPtr(new Property(properties[i].type));
+}
+
+FilterValidator::~FilterValidator()
+{
+}
+
+bool FilterValidator::validateAttribute(std::string& attrName,
+               MatchFlag& matchFlag, AnyPtr& matchValue, int depth)
+{
+       if(m_properties.find(attrName) == m_properties.end())
+               return false;
+
+       if(matchValue == NULL)
+               return false;
+
+       PropertyPtr prop = m_properties[attrName];
+
+       if(matchFlag == MATCH_EXISTS)
+               return true;
+
+       if(!matchValue->isType(prop->type))
+               return false;
+
+       return true;
+}
+
+bool FilterValidator::validateAttributeRange(std::string& attrName,
+               AnyPtr& initialValue, AnyPtr& endValue, int depth)
+{
+       if(initialValue == NULL || endValue == NULL)
+               return false;
+
+       if(m_properties.find(attrName) == m_properties.end())
+               return false;
+
+       PropertyPtr prop = m_properties[attrName];
+
+       bool initialValueIsNull = initialValue->isNullOrUndefined();
+       bool endValueIsNull = endValue->isNullOrUndefined();
+
+       // Invalid if both values are null
+       if(initialValueIsNull && endValueIsNull)
+               return false;
+
+       if(!initialValueIsNull && !initialValue->isType(prop->type))
+               return false;
+
+       if(!endValueIsNull && !endValue->isType(prop->type))
+               return false;
+
+       return true;
+}
+
+bool FilterValidator::validateComposite(int depth)
+{
+       return true;
+}
+
+} // Tizen
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filter/FilterValidator.h b/src/platform/API/Filter/FilterValidator.h
new file mode 100644 (file)
index 0000000..8e0d982
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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       FilterValidator.h
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _API_FILTER_VALIDATOR_H_
+#define _API_FILTER_VALIDATOR_H_
+
+#include <map>
+#include <vector>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <API/Filter/FilterTypes.h>
+#include "AnyType.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+class IFilter;
+typedef DPL::SharedPtr<IFilter> FilterPtr;
+typedef std::vector<std::string> MatchFlagArray;
+typedef DPL::SharedPtr<MatchFlagArray> MatchFlagArrayPtr;
+
+struct PropertyStruct
+{
+       const char * attributeName;
+    const PrimitiveType type;
+};
+typedef PropertyStruct PropertyStructArray[];
+
+// GoF Visitor Pattern
+class FilterValidator
+{
+private:
+       class Property
+       {
+       public:
+               Property(PrimitiveType pType) :
+                       type(pType) {}
+               PrimitiveType type;
+       };
+       typedef DPL::SharedPtr<Property> PropertyPtr;
+       typedef std::map<std::string, PropertyPtr> PropertyMap;
+
+       PropertyMap                             m_properties;
+
+public:
+       FilterValidator(PropertyStructArray properties);
+
+       virtual ~FilterValidator();
+
+       // validate AttributeFilter
+       virtual bool validateAttribute(std::string& attrName,
+                       MatchFlag& matchFlag, AnyPtr& matchValue, int depth=0);
+
+       // validate AttributeRangeFilter
+       virtual bool validateAttributeRange(std::string& attrName,
+                       AnyPtr& initialValue, AnyPtr& endValue, int depth=0);
+
+       // validate CompositeFilter
+       virtual bool validateComposite(int depth=0);
+};
+
+typedef DPL::SharedPtr<FilterValidator> FilterValidatorPtr;
+
+} // Tizen
+} // Api
+} // TizenApis
+
+#endif // _API_FILTER_VALIDATOR_H_
diff --git a/src/platform/API/Filter/IFilter.cpp b/src/platform/API/Filter/IFilter.cpp
new file mode 100644 (file)
index 0000000..090a38e
--- /dev/null
@@ -0,0 +1,41 @@
+//
+// 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       IFilter.cpp
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#include "IFilter.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+IFilter::IFilter()
+{
+}
+
+IFilter::~IFilter()
+{
+}
+
+} // Tizen
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filter/IFilter.h b/src/platform/API/Filter/IFilter.h
new file mode 100644 (file)
index 0000000..ac1f7e7
--- /dev/null
@@ -0,0 +1,77 @@
+//
+// 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       IFilter.h
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief      Represents tizen AbstractFilter
+ */
+
+#ifndef _API_IFILTER_H_
+#define _API_IFILTER_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include "FilterTypes.h"
+#include "IFilterVisitor.h"
+#include "FilterValidator.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+class IFilter;
+typedef DPL::SharedPtr<IFilter> FilterPtr;
+
+typedef std::vector<FilterPtr> FilterArray;
+typedef DPL::SharedPtr<FilterArray> FilterArrayPtr;
+
+class IFilter
+{
+private: // fields
+
+protected:
+
+public: // methods
+
+       /**
+        * constructor of abstraction filter
+        */
+       explicit IFilter();
+
+       virtual ~IFilter();
+
+       /**
+        * method used to identify filter type
+        */
+       virtual FilterType getFilterType() const = 0;
+
+       virtual bool setFilterType(const FilterType& filterType) = 0;
+
+       // validator uses GoF visitor patter.
+       virtual bool validate(FilterValidatorPtr& validator, int depth = 0) = 0;
+
+       // GoF visitor patter.
+       virtual void travel(IFilterVisitorPtr& visitor, int depth = 0) = 0;
+};
+
+} // Tizen
+} // Api
+} // TizenApis
+
+#endif // _API_IFILTER_H_
diff --git a/src/platform/API/Filter/IFilterVisitor.cpp b/src/platform/API/Filter/IFilterVisitor.cpp
new file mode 100644 (file)
index 0000000..2081b73
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// 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       IFilterVisitor.cpp
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "IFilterVisitor.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+IFilterVisitor::IFilterVisitor()
+{
+}
+
+IFilterVisitor::~IFilterVisitor()
+{
+}
+
+} // Tizen
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filter/IFilterVisitor.h b/src/platform/API/Filter/IFilterVisitor.h
new file mode 100644 (file)
index 0000000..be0f2e2
--- /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.
+//
+
+/**
+ * @file       IFilterVisitor.h
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _API_IFILTER_VISITOR_H_
+#define _API_IFILTER_VISITOR_H_
+
+#include <vector>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "AnyType.h"
+#include "FilterTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+class IFilter;
+typedef DPL::SharedPtr<IFilter> FilterPtr;
+typedef std::vector<std::string> MatchFlagArray;
+typedef DPL::SharedPtr<MatchFlagArray> MatchFlagArrayPtr;
+
+// GoF Visitor Pattern
+class IFilterVisitor
+{
+public:
+       IFilterVisitor();
+       virtual ~IFilterVisitor();
+
+       virtual void visitPreComposite(FilterType& type, int depth) = 0;
+       virtual void visitInComposite(FilterType& type, int depth) = 0;
+       virtual void visitPostComposite(FilterType& type, int depth) = 0;
+       virtual void visitAttribute(std::string& attrName,
+                       MatchFlag& matchFlag, AnyPtr& matchValue, int depth) = 0;
+       virtual void visitAttributeRange(std::string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth) = 0;
+};
+
+typedef DPL::SharedPtr<IFilterVisitor> IFilterVisitorPtr;
+
+} // Tizen
+} // Api
+} // TizenApis
+
+#endif // _API_IFILTER_VISITOR_H_
diff --git a/src/platform/API/Filter/SimpleCoordinates.cpp b/src/platform/API/Filter/SimpleCoordinates.cpp
new file mode 100644 (file)
index 0000000..45b6be0
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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       SimpleCoordinates.cpp
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#include "SimpleCoordinates.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+using namespace std;
+
+SimpleCoordinates::SimpleCoordinates(const double latitude,
+        const double longitude) :
+       m_latitude(latitude),
+       m_longitude(longitude)
+{
+}
+
+SimpleCoordinates::~SimpleCoordinates()
+{
+}
+
+double SimpleCoordinates::getLatitude() const
+{
+       return m_latitude;
+}
+
+void SimpleCoordinates::setLatitude(const double value)
+{
+       m_latitude = value;
+}
+
+double SimpleCoordinates::getLongitude() const
+{
+       return m_longitude;
+}
+
+void SimpleCoordinates::setLongitude(const double value)
+{
+       m_longitude = value;
+}
+
+} // Tizen
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filter/SimpleCoordinates.h b/src/platform/API/Filter/SimpleCoordinates.h
new file mode 100644 (file)
index 0000000..2a80319
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// 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       SimpleCoordinates.h
+ * @author     Kisub Song (kisubs.song@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+
+#ifndef _API_SIMPLE_CORDINATES_H_
+#define _API_SIMPLE_CORDINATES_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+class SimpleCoordinates
+{
+private: // fields
+
+       /**
+        * attribute latitude object
+        */
+       double  m_latitude;
+
+       /**
+        * match value object.
+        */
+       double  m_longitude;
+
+protected:
+
+public: // methods
+
+       /**
+        * constructor of SimpleCoorindates
+        */
+       explicit SimpleCoordinates(const double latitude,
+                       const double longitude);
+
+       virtual ~SimpleCoordinates();
+
+       double getLatitude() const;
+       void setLatitude(const double value);
+
+       double getLongitude() const;
+       void setLongitude(const double value);
+};
+
+typedef DPL::SharedPtr<SimpleCoordinates> SimpleCoordinatesPtr;
+
+} // Tizen
+} // Api
+} // TizenApis
+
+#endif // _API_SIMPLE_CORDINATES_H_
diff --git a/src/platform/API/Filter/SortMode.cpp b/src/platform/API/Filter/SortMode.cpp
new file mode 100644 (file)
index 0000000..8baef6c
--- /dev/null
@@ -0,0 +1,62 @@
+//
+// 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        SortMode.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "SortMode.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+SortMode::SortMode(const std::string& attributeName, const SortOrder& order) :
+               m_attributeName(attributeName),
+               m_order(order)
+{
+}
+
+SortMode::~SortMode()
+{
+}
+
+SortOrder SortMode::getOrder() const
+{
+       return m_order;
+}
+
+void SortMode::setOrder(SortOrder value)
+{
+       m_order = value;
+}
+
+std::string SortMode::getAttributeName() const
+{
+       return m_attributeName;
+}
+
+void SortMode::setAttributeName(const std::string &value)
+{
+       m_attributeName = value;
+}
+
+} // Tizen
+} // Api
+} // TizenApis
diff --git a/src/platform/API/Filter/SortMode.h b/src/platform/API/Filter/SortMode.h
new file mode 100644 (file)
index 0000000..0e6882e
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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        SortMode.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _API_SORT_MODE_H_
+#define _API_SORT_MODE_H_
+
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+#include "FilterTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Tizen {
+
+class SortMode;
+typedef DPL::SharedPtr<SortMode> SortModePtr;
+
+typedef std::vector<SortModePtr> SortModeArray;
+typedef DPL::SharedPtr<SortModeArray> SortModeArrayPtr;
+
+class SortMode
+{
+public:
+       SortMode(const std::string& attributeName, const SortOrder& order = ASCENDING_SORT_ORDER);
+       virtual ~SortMode();
+
+       SortOrder getOrder() const;
+       void setOrder(SortOrder value);
+
+       std::string getAttributeName() const;
+       void setAttributeName(const std::string &value);
+
+protected:
+       std::string m_attributeName;
+       SortOrder m_order;
+};
+
+typedef DPL::SharedPtr<SortMode> SortModePtr;
+
+} // Tizen
+} // Api
+} // TizenApis
+
+#endif // _API_SORT_MODE_H_
diff --git a/src/platform/API/Filter/config.cmake b/src/platform/API/Filter/config.cmake
new file mode 100755 (executable)
index 0000000..67ac58d
--- /dev/null
@@ -0,0 +1,14 @@
+get_current_path()
+set(SRCS_PLATFORM_API_FILTER
+  ${CURRENT_PATH}/AnyType.cpp
+  ${CURRENT_PATH}/FilterFactory.cpp
+  ${CURRENT_PATH}/IFilter.cpp
+  ${CURRENT_PATH}/CompositeFilter.cpp
+  ${CURRENT_PATH}/AttributeFilter.cpp
+  ${CURRENT_PATH}/AttributeRangeFilter.cpp
+  ${CURRENT_PATH}/SortMode.cpp
+  ${CURRENT_PATH}/IFilterVisitor.cpp
+  ${CURRENT_PATH}/FilterValidator.cpp
+  ${CURRENT_PATH}/SimpleCoordinates.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Messaging/AttachmentFactory.cpp b/src/platform/API/Messaging/AttachmentFactory.cpp
new file mode 100755 (executable)
index 0000000..bf2b3c4
--- /dev/null
@@ -0,0 +1,473 @@
+//
+// 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 <Commons/Exception.h>
+#include "AttachmentFactory.h"
+#include "Attachments.h"
+#include <Messaging/Attachment.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <WidgetDB/WidgetDBMgr.h>
+
+using namespace std;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Platform::Messaging;
+
+namespace {
+const char* PATH_DOWNLOADS = "/opt/usr/media/Downloads";
+const char* PATH_DOCUMENTS = "/opt/usr/media/Documents";
+const char* PATH_SOUNDS = "/opt/usr/media/Music";
+const char* PATH_IMAGES = "/opt/usr/media/Images";
+const char* PATH_VIDEOS = "/opt/usr/media/Videos";
+
+const char* VPATH_DOWNLOADS = "download";
+const char* VPATH_DOCUMENTS = "documents";
+const char* VPATH_SOUNDS = "music";
+const char* VPATH_IMAGES = "images";
+const char* VPATH_VIDEOS = "videos";
+const char* VPATH_WGT_PACKAGE = "wgt-package";
+const char* VPATH_WGT_PRIVATE = "wgt-private";
+const char* VPATH_WGT_PRIVATE_TEMP = "wgt-package-tmp";
+
+const char* COMMAND_NAME = "/bin/cp";
+const char* COMMAND_SWITCH_RECURSIVE = "-r";
+const char* MKDIR_COMMAND_NAME = "/bin/mkdir";
+const char* MKDIR_COMMAND_SWITCH_RECURSIVE = "-p";
+
+}
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+const char AttachmentFactory::m_pathSeparator = '/';
+
+IAttachmentPtr AttachmentFactory::createAttachment(const std::string& fullPath,
+        bool isVirtualPath)
+{
+    LogDebug("enter");
+    IAttachmentPtr attachment(new Attachment(fullPath, isVirtualPath));
+    if (!attachment->getIsCreatedProperly()) {
+        ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,
+                 "Attachment couldn't be created");
+    }
+    return attachment;
+}
+
+IAttachmentPtr AttachmentFactory::createAttachment(const std::string& path,
+        const std::string& mimeType)
+{
+    LogDebug("enter");
+
+    //check virtualPath
+    bool isVirtualPath = true;
+    IAttachmentPtr attachment(new Attachment(path, isVirtualPath));
+    if (!attachment->getIsCreatedProperly()) {
+        ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,
+                 "Attachment couldn't be created");
+    }
+
+    if ( attachment )
+       attachment->setMimeType(mimeType);
+               
+    return attachment;
+}
+
+std::string AttachmentFactory::getVirtualPathFromRealPath(JSContextRef context, 
+       const std::string& real_path)
+{
+       LogDebug("path = " << real_path);       
+
+       //find virtual root
+       std::string root;
+       std::string tail;
+
+       std::string::size_type virtualrootpathposition;
+       //download
+       virtualrootpathposition = real_path.find(PATH_DOWNLOADS);
+       if (virtualrootpathposition != std::string::npos)
+       {
+               std::string vroot(PATH_DOWNLOADS);
+               tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
+               LogDebug("tail = " << tail);
+               vroot=VPATH_DOWNLOADS;
+               std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
+
+               return virtualpath;
+       }
+
+       //document
+       virtualrootpathposition = real_path.find(PATH_DOCUMENTS);
+       if (virtualrootpathposition != std::string::npos)
+       {
+               std::string vroot(PATH_DOCUMENTS);
+               tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
+               LogDebug("tail = " << tail);
+               vroot=VPATH_DOCUMENTS;
+               std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
+
+               return virtualpath;
+       }
+
+       //sound
+       virtualrootpathposition = real_path.find(PATH_SOUNDS);
+       if (virtualrootpathposition != std::string::npos)
+       {
+               std::string vroot(PATH_SOUNDS);
+               tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
+               LogDebug("tail = " << tail);
+               vroot=VPATH_SOUNDS;
+               std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
+
+               return virtualpath;
+       }
+
+       //image
+       virtualrootpathposition = real_path.find(PATH_IMAGES);
+       if (virtualrootpathposition != std::string::npos)
+       {
+               std::string vroot(PATH_IMAGES);
+               tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
+               LogDebug("tail = " << tail);
+               vroot=VPATH_IMAGES;
+               std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
+               LogDebug("virtualpath = " << virtualpath);
+               return virtualpath;
+       }
+
+       //video
+       virtualrootpathposition = real_path.find(PATH_VIDEOS);
+       if (virtualrootpathposition != std::string::npos)
+       {
+               std::string vroot(PATH_VIDEOS);
+               tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
+               LogDebug("tail = " << tail);
+               vroot=VPATH_VIDEOS;
+               std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
+               LogDebug("virtualpath = " << virtualpath);
+               return virtualpath;
+       }
+
+    int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+       WidgetDB::Api::IWidgetDBPtr widgetDB =
+        WidgetDB::Api::getWidgetDB(widgetId);
+
+       //wgt-package
+       virtualrootpathposition = real_path.find(widgetDB->getWidgetInstallationPath());
+       if (virtualrootpathposition != std::string::npos)
+       {
+               std::string vroot(widgetDB->getWidgetInstallationPath());
+               tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
+               LogDebug("tail = " << tail);
+               vroot=VPATH_WGT_PACKAGE;
+               std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
+               LogDebug("virtualpath = " << virtualpath);
+               return virtualpath;
+       }       
+       
+       //wgt-private
+       virtualrootpathposition = real_path.find(widgetDB->getWidgetPersistentStoragePath());
+       if (virtualrootpathposition != std::string::npos)
+       {
+               std::string vroot(widgetDB->getWidgetPersistentStoragePath());
+               tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
+               LogDebug("tail = " << tail);
+               vroot=VPATH_WGT_PRIVATE;
+               std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
+               LogDebug("virtualpath = " << virtualpath);
+               return virtualpath;
+       }
+
+       //wgt-package-tmp
+       virtualrootpathposition = real_path.find(widgetDB->getWidgetTemporaryStoragePath());
+       if (virtualrootpathposition != std::string::npos)
+       {
+               std::string vroot(widgetDB->getWidgetTemporaryStoragePath());
+               tail = real_path.substr(virtualrootpathposition + vroot.size() + 1, real_path.size() - 1);
+               LogDebug("tail = " << tail);
+               vroot=VPATH_WGT_PRIVATE_TEMP;
+               std::string virtualpath = vroot +  AttachmentFactory::m_pathSeparator + tail ;
+               LogDebug("virtualpath = " << virtualpath);
+               return virtualpath;
+       }
+
+       return "";
+       
+}
+
+std::string AttachmentFactory::getVirtualPathFromEmailServiceFolder(JSContextRef context, 
+               const std::string& real_path)
+{
+
+       //another folder
+       //copy
+       LogDebug("path = " << real_path);       
+
+       int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+       int error = 0;
+
+      WidgetDB::Api::IWidgetDBPtr widgetDB =
+               WidgetDB::Api::getWidgetDB(widgetId);
+                       
+#if 0
+       IWrtWrapperPtr wrt = WrtWrappersMgr::getInstance().getWrtWrapper(context);
+       Assert(wrt && "WrtWrapper not found, not a GLOBAL context supplied?");
+
+       WidgetDB::Api::IWidgetDBPtr widgetDB =
+        WidgetDB::Api::getWidgetDB(wrt->getWidgetId());
+#endif
+
+       size_t pos = real_path.find_last_of("/");
+       if ((pos + 1) >= real_path.size()) {
+           LogError("Problem with short name creation");
+           Throw(InvalidArgumentException);
+       }
+       std::string attachShortName = real_path.substr(pos + 1);
+       std::string privat_dir = widgetDB->getWidgetPersistentStoragePath();
+       if ( privat_dir.empty())
+       {
+               LogError("Problem with short name creation");
+               Throw(InvalidArgumentException);
+       }
+
+       char buf[] = "/email/XXXXXX";
+       mode_t mask = umask(S_IWGRP | S_IWOTH);
+       error = mkstemp(buf);
+       umask(mask);
+       LogDebug("mkstemp =" << error);
+       
+       LogDebug("temp file=" << buf << AttachmentFactory::m_pathSeparator << attachShortName);
+       
+       std::stringstream mkdir_cmd;
+       mkdir_cmd << MKDIR_COMMAND_NAME;
+       mkdir_cmd << " " << MKDIR_COMMAND_SWITCH_RECURSIVE;
+        mkdir_cmd << " \"" << privat_dir << buf  << AttachmentFactory::m_pathSeparator << "\"";
+
+       LogDebug("mkdir path=" << mkdir_cmd.str());
+
+       int result = system(mkdir_cmd.str().c_str());
+       if (-1 != result) {
+       std::stringstream cp_cmd;
+       cp_cmd << COMMAND_NAME;
+       cp_cmd << " " << COMMAND_SWITCH_RECURSIVE;
+       cp_cmd << " \"" << real_path << "\"";
+       cp_cmd << " \"" << privat_dir << buf  << AttachmentFactory::m_pathSeparator << attachShortName << "\"";
+       
+       LogDebug("cp path=" << cp_cmd.str());
+
+               result = system(cp_cmd.str().c_str());
+       if (-1 != result) {
+               if (0 != WIFEXITED(result)) {
+                       if (0 != WEXITSTATUS(result)) {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Command failed.");
+                       }
+               } else {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                       "Command terminated abnormally.");
+               }
+       } else {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't launch command.");
+       }
+       }
+       else 
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't launch command.");
+       }
+       
+       std::string vrootpath(VPATH_WGT_PRIVATE);
+       return vrootpath+ buf + AttachmentFactory::m_pathSeparator + attachShortName ;
+       
+}
+
+
+std::string AttachmentFactory::getDummyFileFromRealPath(JSContextRef context, 
+               const std::string& real_path)
+{
+       //This file is not in list of root locations
+       LogDebug("path = " << real_path);       
+
+       int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+       int error = 0;
+
+       WidgetDB::Api::IWidgetDBPtr widgetDB =
+               WidgetDB::Api::getWidgetDB(widgetId);
+
+       size_t pos = real_path.find_last_of("/");
+       if ((pos + 1) >= real_path.size()) {
+           LogError("Problem with short name creation");
+           Throw(InvalidArgumentException);
+       }
+       std::string attachShortName = real_path.substr(pos + 1);
+       std::string privat_dir = widgetDB->getWidgetPersistentStoragePath();
+       if ( privat_dir.empty())
+       {
+               LogError("Problem with short name creation");
+               Throw(InvalidArgumentException);
+       }
+
+       char buf[] = "/email/XXXXXX";
+       mode_t mask = umask(S_IWGRP | S_IWOTH);
+       error = mkstemp(buf);
+       umask(mask);
+       LogDebug("mkstemp =" << error);
+               
+       LogDebug("temp file=" << buf << AttachmentFactory::m_pathSeparator << attachShortName);
+
+       std::stringstream mkdir_cmd;
+       mkdir_cmd << MKDIR_COMMAND_NAME;
+       mkdir_cmd << " " << MKDIR_COMMAND_SWITCH_RECURSIVE;
+       mkdir_cmd << " \"" << privat_dir << buf  << AttachmentFactory::m_pathSeparator << "\"";
+
+       LogDebug("mkdir path=" << mkdir_cmd.str());
+
+       int result = system(mkdir_cmd.str().c_str());   //make folder in the wgt-private.
+       if (-1 != result) {
+               std::stringstream cp_cmd;
+               cp_cmd << COMMAND_NAME;
+               cp_cmd << " " << COMMAND_SWITCH_RECURSIVE;
+               cp_cmd << " \"" << real_path << "\"";
+               cp_cmd << " \"" << privat_dir << buf  << AttachmentFactory::m_pathSeparator << attachShortName << "\"";
+               
+               LogDebug("cp path=" << cp_cmd.str());
+
+               result = system(cp_cmd.str().c_str());  //copy
+               if (-1 != result) {
+                       if (0 != WIFEXITED(result)) {
+                               if (0 != WEXITSTATUS(result)) {
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Command failed.");
+                               }
+                       } else {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                               "Command terminated abnormally.");
+                       }
+               } else {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't launch command.");
+               }
+       }
+       else 
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't launch command.");
+       }
+       
+       return privat_dir + buf + AttachmentFactory::m_pathSeparator + attachShortName ;
+       
+}
+
+
+
+std::string AttachmentFactory::getRealPathFromVirtualPath(JSContextRef context, 
+       const std::string& path)
+{
+       LogDebug("path = " << path);    
+
+       std::string root;
+       std::string tail;
+       std::string::size_type separatorPosition = path.find(AttachmentFactory::m_pathSeparator);
+       if (separatorPosition != std::string::npos) {
+               root = path.substr(0, separatorPosition);
+               tail = path.substr(separatorPosition + 1, path.size() - 1);
+       } else {
+               root = path;
+       }
+       LogDebug("root = " << root);
+       LogDebug("tail = " << tail);
+
+    int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+       WidgetDB::Api::IWidgetDBPtr widgetDB =
+        WidgetDB::Api::getWidgetDB(widgetId);
+
+       std::string realroot;
+
+       if ( root == VPATH_DOWNLOADS )
+       {
+               realroot = PATH_DOWNLOADS;
+       }
+       else if ( root == VPATH_DOCUMENTS )
+       {
+               realroot = PATH_DOCUMENTS;
+       }
+       else if ( root == VPATH_SOUNDS )
+       {
+               realroot = PATH_SOUNDS;
+       }
+       else if ( root == VPATH_IMAGES )
+       {
+               realroot = PATH_IMAGES;
+       }
+       else if ( root == VPATH_VIDEOS )
+       {
+               realroot = PATH_VIDEOS;
+       }
+       else if ( root == VPATH_WGT_PACKAGE )
+       {
+               realroot = widgetDB->getWidgetInstallationPath();
+       }
+       else if ( root == VPATH_WGT_PRIVATE )
+       {
+               realroot = widgetDB->getWidgetPersistentStoragePath();
+       }
+       else if ( root == VPATH_WGT_PRIVATE_TEMP )
+       {
+               realroot = widgetDB->getWidgetTemporaryStoragePath();
+       }
+       else
+       {       //exception
+               LogDebug("Can't find root path");
+               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,
+                 "Attachment couldn't be created");
+       }
+
+       std::string ret = realroot + AttachmentFactory::m_pathSeparator + tail;
+                                       
+       return ret;
+}
+
+bool AttachmentFactory::removeDummyFile(const std::string& dummyFilePath)
+{
+       //remove dummy filePath.
+
+       if (dummyFilePath.length()>0)
+       {
+               //remove file
+               if ( 0 == unlink(dummyFilePath.c_str()))
+               {
+                       //remove folder
+                       size_t pos = dummyFilePath.find_last_of("/");
+                       if ((pos + 1) >= dummyFilePath.size()) {
+                           LogError("Problem with short name creation");
+                       }
+                       std::string folder = dummyFilePath.substr(0, pos);
+                       LogDebug("remove folder : " << folder);
+                       if ( 0 != remove(folder.c_str()))
+                       {
+                               LogError("Remove Error");
+                       }
+               }
+               else 
+               {
+                       LogDebug("remove file error : " << dummyFilePath);
+               }
+       }
+                               
+       return true;
+}
+
+
+}
+}
+}
diff --git a/src/platform/API/Messaging/AttachmentFactory.h b/src/platform/API/Messaging/AttachmentFactory.h
new file mode 100755 (executable)
index 0000000..626a633
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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 ATTACHMENTFACTORY_H
+#define ATTACHMENTFACTORY_H
+
+#include <string>
+#include <JavaScriptCore/JavaScript.h>
+
+#include "IAttachment.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class AttachmentFactory
+{
+  public:
+
+    /**
+     * Generate attachment object
+     * @param[in] fullPath path to file
+     * @param[in] isVirtualPath false when path is real file system path, true when it's path on file system exposed to user
+     */
+    static IAttachmentPtr createAttachment(const std::string& fullPath,
+            bool isVirtualPath);
+
+    static IAttachmentPtr createAttachment(const std::string& path,
+            const std::string& mimeType = "");
+       
+    static std::string getRealPathFromVirtualPath(JSContextRef context, 
+               const std::string& path);
+
+    static std::string getVirtualPathFromRealPath(JSContextRef context, 
+               const std::string& real_path);
+
+    static std::string getVirtualPathFromEmailServiceFolder(JSContextRef context, 
+               const std::string& real_path);
+
+    static std::string getDummyFileFromRealPath(JSContextRef context, 
+                       const std::string& real_path);
+
+    static bool removeDummyFile(const std::string& dummyFilePath);
+
+private:       
+    static const char m_pathSeparator;
+
+};
+
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/Attachments.cpp b/src/platform/API/Messaging/Attachments.cpp
new file mode 100755 (executable)
index 0000000..15ad203
--- /dev/null
@@ -0,0 +1,290 @@
+//
+// 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 <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "Attachments.h"
+#include "AttachmentFactory.h"
+
+extern "C" {
+#include <sys/stat.h>
+#include <stdlib.h>
+}
+
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+//--------------------------------------------------------------------------
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+Attachments::Attachments() :
+    m_validAttachments(false)
+{
+    LogDebug("enter");
+}
+
+Attachments::~Attachments()
+{
+    LogDebug("enter");
+}
+
+IAttachmentPtr Attachments::appendAttachment(const std::string& fullPath,
+        bool isVirtualPath)
+{
+    LogDebug("enter, fullPath=" << fullPath);
+    IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
+            fullPath,
+            isVirtualPath);
+    m_validAttachments = false;
+    m_attachments.push_back(tmpAttach);
+    return tmpAttach;
+}
+
+void Attachments::appendAttachment(const IAttachmentPtr& attachment)
+{
+    LogDebug("enter");
+    m_validAttachments = false;
+    m_attachments.push_back(attachment);
+}
+
+void Attachments::appendInlineAttachment(const IAttachmentPtr& attachment)
+{
+    LogDebug("enter");
+    m_validInineAttachments = false;
+    m_inlineAttachments.push_back(attachment);
+}
+
+IAttachmentPtr Attachments::appendAttachment(const IMessagePtr& message, const std::string& fullPath,
+                 bool isVirtualPath)
+{
+       LogDebug("enter");
+       IAttachmentPtr iAttachment = appendAttachment(fullPath, isVirtualPath);
+
+       if (message && iAttachment)
+       {
+               iAttachment->setMessage(message);
+       }
+
+       return iAttachment;
+}
+
+void Attachments::appendAttachment(const IMessagePtr& message, const IAttachmentPtr& attachment)
+{
+       LogDebug("enter");
+
+    m_validAttachments = false;
+
+    if (attachment && message)
+               attachment->setMessage(message);
+       
+    m_attachments.push_back(attachment);
+}
+
+void Attachments::appendAttachments(const vector<IAttachmentPtr>& attachments)
+{
+    LogDebug("enter");
+    back_insert_iterator< vector<IAttachmentPtr> >biit(m_attachments);
+    copy(attachments.begin(), attachments.end(), biit);
+}
+
+size_t Attachments::getAttachmentsCount() const
+{
+    LogDebug("enter");
+    return m_attachments.size();
+}
+
+size_t Attachments::getInlineAttachmentsCount() const
+{
+    LogDebug("enter");
+    return m_inlineAttachments.size();
+}
+
+IAttachmentPtr Attachments::getAttachment(const size_t index) const
+{
+    LogDebug("enter");
+    if (index >= m_attachments.size()) {
+        ThrowMsg(OutOfRangeException, "Trying to get attachment out of range");
+    }
+    return m_attachments[index];
+}
+
+IAttachmentPtr Attachments::getInlineAttachment(const size_t index) const
+{
+    LogDebug("enter");
+    if (index >= m_inlineAttachments.size()) {
+        ThrowMsg(OutOfRangeException, "Trying to get attachment out of range");
+    }
+    return m_inlineAttachments[index];
+}
+
+void Attachments::removeAttachment(const size_t index)
+{
+    LogDebug("enter");
+    if (index >= m_attachments.size()) {
+        ThrowMsg(OutOfRangeException, "Trying to get attachment out of range");
+    }
+    m_validAttachments = false;
+    m_attachments.erase(m_attachments.begin() + index);
+}
+
+void Attachments::removeAttachment(const IAttachmentPtr& attachment)
+{
+    m_attachments.erase(
+        remove(m_attachments.begin(), m_attachments.end(), attachment),
+        m_attachments.end());
+}
+
+vector<IAttachmentPtr> Attachments::getAttachments() const
+{
+    LogDebug("enter");
+    return m_attachments;
+}
+
+vector<IAttachmentPtr> Attachments::getInlineAttachments() const
+{
+    LogDebug("enter");
+    return m_inlineAttachments;
+}
+
+vector<string> Attachments::getAttachmentsFullPaths() const
+{
+    vector<string> retVal;
+
+    for (size_t i = 0; i < m_attachments.size(); i++) {
+        retVal.push_back(m_attachments[i]->getFullPath());
+    }
+    return retVal;
+}
+
+vector<string> Attachments::getAttachmentsShortNames() const
+{
+    vector<string> retVal;
+
+    for (size_t i = 0; i < m_attachments.size(); i++) {
+        retVal.push_back(m_attachments[i]->getShortName());
+    }
+    return retVal;
+}
+
+void Attachments::setAttachments(const vector<string>& attachments,
+        bool isVirtualPath)
+{
+    vector<string>::const_iterator it = attachments.begin();
+
+    m_attachments.clear();
+    while (it != attachments.end()) {
+        appendAttachment(*it, isVirtualPath);
+        ++it;
+    }
+}
+
+void Attachments::setAttachments(const vector<IAttachmentPtr>& attachments)
+{
+    m_attachments = attachments;
+    m_validAttachments = false;
+}
+
+void Attachments::setInlineAttachments(const vector<IAttachmentPtr>& attachments)
+{
+    m_inlineAttachments = attachments;
+    m_validInineAttachments = false;
+}
+
+bool Attachments::isAttachmentsValid() const
+{
+    return m_validAttachments;
+}
+
+void Attachments::setAttachmentsValidity(bool state)
+{
+    m_validAttachments = state;
+}
+
+bool Attachments::isInlineAttachmentsValid() const
+{
+    return m_validInineAttachments;
+}
+
+void Attachments::setInlineAttachmentsValidity(bool state)
+{
+    m_validInineAttachments = state;
+}
+
+const vector<IAttachmentPtr>& Attachments::getAttachmentsRef() const
+{
+    return m_attachments;
+}
+
+void Attachments::saveAttachment(const string& destFileName,
+        const IAttachmentPtr& attachment)
+{
+    //  possible move it as a virtual function - to be clarified
+    LogError("N/A");
+    //TODO
+}
+
+void Attachments::setAttachmentWithExpand(const size_t index,
+        const std::string& fullPath,
+        bool isVirtualPath)
+{
+    // expand if needed
+    if (index >= m_attachments.size()) {
+        m_attachments.resize(index + 1);    // resize with empty ptr
+    }
+    IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
+            fullPath,
+            isVirtualPath);
+    m_attachments[index] = tmpAttach;
+    m_validAttachments = false;
+}
+
+void Attachments::reverse()
+{
+    std::reverse(m_attachments.begin(), m_attachments.end());
+}
+
+void Attachments::insertAttachment(const size_t index,
+        const std::string& fullPath,
+        bool isVirtualPath)
+{
+    IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
+            fullPath,
+            isVirtualPath);
+    m_attachments.insert(m_attachments.begin() + index, tmpAttach);
+    m_validAttachments = false;
+}
+
+void Attachments::insertAttachmentWithExpand(const size_t index,
+        const std::string& fullPath,
+        bool isVirtualPath)
+{
+    // expand if needed
+    if (index >= m_attachments.size()) {
+        m_attachments.resize(index);    // resize with empty ptr
+    }
+    IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
+            fullPath,
+            isVirtualPath);
+    m_attachments.insert(m_attachments.begin() + index, tmpAttach);
+    m_validAttachments = false;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/Attachments.h b/src/platform/API/Messaging/Attachments.h
new file mode 100755 (executable)
index 0000000..66bca96
--- /dev/null
@@ -0,0 +1,236 @@
+//
+// 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 ATTACHMENTS_H
+#define ATTACHMENTS_H
+
+#include <vector>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "IMessagingTypes.h"
+#include "IAttachment.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class Attachments
+{
+    std::vector<IAttachmentPtr> m_attachments;
+    std::vector<IAttachmentPtr> m_inlineAttachments;
+
+  public: // fields
+
+  private:
+
+    bool m_validAttachments;
+    bool m_validInineAttachments;
+
+  public: // methods
+
+    Attachments();
+
+    virtual ~Attachments();
+
+    /**
+     * method for append attachment into list
+     * @param[in] fullPath - path for attachment
+     * @return AttachmentPtr - if file exist create attachment object
+     *                         it is possible to modify name, etc.
+     * @throw InvalidArgumentException - if file not exist
+     */
+    IAttachmentPtr appendAttachment(const std::string& fullPath,
+            bool isVirtualPath);
+
+    /**
+     * method for append attachment into list
+     * @param[in] attachment - attachment to be added
+     */
+    void appendAttachment(const IAttachmentPtr& attachment);
+
+    void appendInlineAttachment(const IAttachmentPtr& attachment);
+
+    /**
+     * method for append attachment into list
+     * @param[in] message - message interface
+     * @param[in] fullPath - path for attachment
+     * @return AttachmentPtr - if file exist create attachment object
+     *                         it is possible to modify name, etc.
+     * @throw InvalidArgumentException - if file not exist
+     */
+    IAttachmentPtr appendAttachment(const IMessagePtr& message, const std::string& fullPath,
+            bool isVirtualPath);
+
+    /**
+     * method for append attachment into list
+     * @param[in] message - message interface
+     * @param[in] attachment - attachment to be added
+     */
+    void appendAttachment(const IMessagePtr& message, const IAttachmentPtr& attachment);
+
+    /**
+     * method for append attachments list
+     * @param[in] attachments - attachment list
+     */
+    void appendAttachments(const std::vector<IAttachmentPtr>& attachments);
+
+    /**
+     * get attachment count
+     * @return attachment count
+     */
+    size_t getAttachmentsCount() const;
+
+    size_t getInlineAttachmentsCount() const;
+
+    /**
+     * get attachment object at index
+     * @param[in] index - index of attachment to get
+     * @return attachment object
+     * @throw OutOfRangeException if index is out of range
+     */
+    IAttachmentPtr getAttachment(const size_t index) const;
+
+    IAttachmentPtr getInlineAttachment(const size_t index) const;
+
+    /**
+     * remove attachment at the index
+     * @param[in] index - index of attachment to get
+     * @return void
+     * @throw OutOfRangeException if index is out of range
+     */
+    void removeAttachment(const size_t index);
+
+    /**
+     * remove attachment at the index
+     * @param[in] attachment - AttachmentPtr object
+     * @return void
+     * @throw OutOfRangeException if index is out of range
+     */
+    void removeAttachment(const IAttachmentPtr& attachment);
+
+    /**
+     * get all attachments vector
+     * @return attachment vector
+     */
+    std::vector<IAttachmentPtr> getAttachments() const;
+
+    std::vector<IAttachmentPtr> getInlineAttachments() const;
+
+    /**
+     * get all attachments full path vector
+     * @return attachment path vector
+     */
+    std::vector<std::string> getAttachmentsFullPaths() const;
+
+    /**
+     * get all attachments names vector
+     * @return attachment names vector
+     */
+    std::vector<std::string> getAttachmentsShortNames() const;
+
+    /**
+     * get all attachments vector reference
+     * @return attachment vector
+     */
+    const std::vector<IAttachmentPtr>& getAttachmentsRef() const;
+
+    /**
+     * set attachments
+     * @param[in] attachments - vector of and attachments full path
+     * @throw InvalidArgumentException - if file not exist
+     */
+    void setAttachments(const std::vector<std::string>& attachments,
+            bool isVirtualPath);
+
+    /**
+     * set attachmentsPtr
+     * @param[in] attachments - vector of AttachmentPtr
+     */
+    void setAttachments(const std::vector<IAttachmentPtr>& attachments);
+
+    void setInlineAttachments(const std::vector<IAttachmentPtr>& attachments);
+
+    /**
+     * check if attachments are modified and need update in platform
+     * @return bool
+     */
+    bool isAttachmentsValid() const;
+
+    /**
+     * setting validity after update
+     * @param[in] state - state for validity to set
+     */
+    void setAttachmentsValidity(bool state);
+
+    bool isInlineAttachmentsValid() const;
+
+    void setInlineAttachmentsValidity(bool state);
+
+    /**
+     * saving attachment file to selected destination file
+     * @param[in] destFileName - destination file to save attachment
+     * @param[in] attachment - attachment to be saved
+     */
+    void saveAttachment(const std::string& destFileName,
+            const IAttachmentPtr& attachment);
+
+    /**
+     * sets attachment at given position and expands array if needed
+     * @param[in] index - position
+     * @param[in] fullPath - path for attachment
+     * @throw InvalidArgumentException - if file not exist
+     */
+    void setAttachmentWithExpand(const size_t index,
+            const std::string& fullPath,
+            bool isVirtualPath);
+
+    /**
+     * The reverse() method reverses the order of the elements in an array
+     * (makes the last element first, and the first element last).
+     */
+    void reverse();
+
+    /**
+     * Creates new attachment and inserts it at given position
+     * @param[in] index position
+     * @param[in] fullPath - path for attachment
+     * @param[in] isVirtualPath - true if path is virtual
+     * @throw InvalidArgumentException - if file not exist
+     */
+    void insertAttachment(const size_t index,
+            const std::string& fullPath,
+            bool isVirtualPath);
+
+    /**
+     * Creates new attachment and inserts it at given position and expands array if needed
+     * @param[in] index position
+     * @param[in] fullPath - path for attachment
+     * @param[in] isVirtualPath - true if path is virtual
+     * @throw InvalidArgumentException - if file not exist
+     */
+    void insertAttachmentWithExpand(const size_t index,
+            const std::string& fullPath,
+            bool isVirtualPath);
+};
+
+typedef DPL::SharedPtr<Attachments> AttachmentsPtr;
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/BccRecipient.cpp b/src/platform/API/Messaging/BccRecipient.cpp
new file mode 100755 (executable)
index 0000000..ac899dc
--- /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.
+//
+
+#include "BccRecipient.h"
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+BccRecipient::BccRecipient() :
+    m_bccRecipients(new Recipients())
+{
+}
+
+BccRecipient::~BccRecipient()
+{
+}
+
+void BccRecipient::setBccValidity(bool state)
+{
+    m_bccRecipients->setValid(state);
+}
+
+bool BccRecipient::getBccValidity() const
+{
+    return m_bccRecipients->isValid();
+}
+
+Recipients BccRecipient::getBccRecipients() const
+{
+    return *m_bccRecipients;
+}
+
+void BccRecipient::setBccRecipients(const Recipients& value)
+{
+    *m_bccRecipients = value;
+}
+
+void BccRecipient::appendBccRecipients(const std::string & value)
+{
+    m_bccRecipients->appendRecipient(value);
+}
+
+void BccRecipient::appendBccRecipients(const Recipients& value)
+{
+    *m_bccRecipients += value;
+}
+
+void BccRecipient::removeBccRecipients(const Recipients& value)
+{
+    *m_bccRecipients -= value;
+}
+
+RecipientsPtr BccRecipient::getBccRecipientsPtr() const
+{
+    return m_bccRecipients;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/BccRecipient.h b/src/platform/API/Messaging/BccRecipient.h
new file mode 100755 (executable)
index 0000000..db86c3b
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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 BCCRECIPIENT_H
+#define BCCRECIPIENT_H
+
+#include <string>
+#include "Recipient.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class BccRecipient
+{
+  private: // fields
+
+    RecipientsPtr m_bccRecipients;
+
+  public:
+
+    BccRecipient();
+
+    virtual ~BccRecipient();
+
+    void setBccValidity(bool state);
+
+    bool getBccValidity() const;
+
+    Recipients getBccRecipients() const;
+
+    RecipientsPtr getBccRecipientsPtr() const;
+
+    void appendBccRecipients(const std::string & value);
+
+    void appendBccRecipients(const Recipients& value);
+
+    void removeBccRecipients(const Recipients& value);
+
+    void setBccRecipients(const Recipients& value);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/Body.cpp b/src/platform/API/Messaging/Body.cpp
new file mode 100755 (executable)
index 0000000..c2a2ee8
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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 "Body.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+Body::Body() :
+    m_body(""),
+    m_validBody(false)
+{
+}
+
+Body::~Body()
+{
+}
+
+void Body::setBody(const std::string& value)
+{
+    m_body = value;
+    m_validBody = false;
+}
+
+std::string Body::getBody() const
+{
+    return m_body;
+}
+
+const std::string& Body::getBodyRef() const
+{
+    return m_body;
+}
+
+bool Body::isBodyValid() const
+{
+    return m_validBody;
+}
+
+void Body::setBodyValidity(bool state)
+{
+    m_validBody = state;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/Body.h b/src/platform/API/Messaging/Body.h
new file mode 100755 (executable)
index 0000000..9c8887d
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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 BODY_H
+#define BODY_H
+
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class Body
+{
+  private:   // fields
+
+    /**
+     * body value
+     */
+    std::string m_body;                //plainBody on SMS, MMS, ...
+
+    /**
+     * information if abstract message body has been changed and need update
+     * in low level
+     */
+    bool m_validBody;
+
+  public:   // methods
+
+    Body();
+
+    virtual ~Body();
+
+    /**
+     * setter of body value
+     */
+    void setBody(const std::string& value);
+
+    /**
+     * getter of body value
+     */
+    std::string getBody() const;
+
+    /**
+     * getter of body value
+     */
+    const std::string& getBodyRef() const;
+
+    /**
+     * check body validity
+     * */
+    bool isBodyValid() const;
+
+    /**
+     * set body validity
+     * */
+    void setBodyValidity(bool state);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/CallbackNumber.cpp b/src/platform/API/Messaging/CallbackNumber.cpp
new file mode 100755 (executable)
index 0000000..e748216
--- /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.
+//
+
+#include <dpl/log/log.h>
+#include "CallbackNumber.h"
+#include "CallbackNumber.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+CallbackNumber::CallbackNumber() :
+    m_callbackNumber(""),
+    m_validCallbackNumber(false)
+{
+}
+
+CallbackNumber::~CallbackNumber()
+{
+}
+
+void CallbackNumber::setCallbackNumber(const std::string& value)
+{
+    LogDebug("set callbackNumber=" << value);
+    m_callbackNumber = value;
+    m_validCallbackNumber = false;
+}
+
+std::string CallbackNumber::getCallbackNumber() const
+{
+    return m_callbackNumber;
+}
+
+const std::string& CallbackNumber::getCallbackNumberRef() const
+{
+    return m_callbackNumber;
+}
+
+bool CallbackNumber::isCallbackNumberValid() const
+{
+    return m_validCallbackNumber;
+}
+
+void CallbackNumber::setCallbackNumberValidity(bool state)
+{
+    m_validCallbackNumber = state;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/CallbackNumber.h b/src/platform/API/Messaging/CallbackNumber.h
new file mode 100755 (executable)
index 0000000..c66a3e5
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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 CALLBACKNUMBER_H
+#define CALLBACKNUMBER_H
+
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class CallbackNumber
+{
+  private:   // fields
+
+    /**
+     * CallbackNumber value
+     */
+    std::string m_callbackNumber;
+
+    /**
+     * information if abstract message body has been changed and need update
+     * in low level
+     */
+    bool m_validCallbackNumber;
+
+  public:   // methods
+
+    CallbackNumber();
+
+    virtual ~CallbackNumber();
+
+    /**
+     * setter of CallbackNumber value
+     */
+    void setCallbackNumber(const std::string& value);
+
+    /**
+     * getter of CallbackNumber value
+     */
+    std::string getCallbackNumber() const;
+
+    /**
+     * getter of CallbackNumber value
+     */
+    const std::string& getCallbackNumberRef() const;
+
+    /**
+     * check CallbackNumber validity
+     * */
+    bool isCallbackNumberValid() const;
+
+    /**
+     * set CallbackNumber validity
+     * */
+    void setCallbackNumberValidity(bool state);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/CcRecipient.cpp b/src/platform/API/Messaging/CcRecipient.cpp
new file mode 100755 (executable)
index 0000000..cec105a
--- /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.
+//
+
+#include "CcRecipient.h"
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+CcRecipient::CcRecipient() :
+    m_ccRecipients(new Recipients())
+{
+}
+
+CcRecipient::~CcRecipient()
+{
+}
+
+void CcRecipient::setCcValidity(bool state)
+{
+    m_ccRecipients->setValid(state);
+}
+
+bool CcRecipient::getCcValidity(void) const
+{
+    return m_ccRecipients->isValid();
+}
+
+Recipients CcRecipient::getCcRecipients() const
+{
+    return *m_ccRecipients;
+}
+
+RecipientsPtr CcRecipient::getCcRecipientsPtr() const
+{
+    return m_ccRecipients;
+}
+
+void CcRecipient::appendCcRecipients(const std::string & value)
+{
+    m_ccRecipients->appendRecipient(value);
+}
+
+void CcRecipient::appendCcRecipients(const Recipients& value)
+{
+    *m_ccRecipients += value;
+}
+
+void CcRecipient::removeCcRecipients(const Recipients& value)
+{
+    *m_ccRecipients -= value;
+}
+
+void CcRecipient::setCcRecipients(const Recipients& value)
+{
+    *m_ccRecipients = value;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/CcRecipient.h b/src/platform/API/Messaging/CcRecipient.h
new file mode 100755 (executable)
index 0000000..043dfbe
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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 CCRECIPIENT_H
+#define CCRECIPIENT_H
+
+#include <string>
+#include "Recipient.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class CcRecipient
+{
+  private: // fields
+
+    RecipientsPtr m_ccRecipients;
+
+  public:
+
+    CcRecipient();
+
+    virtual ~CcRecipient();
+
+    void setCcValidity(bool state);
+
+    bool getCcValidity(void) const;
+
+    Recipients getCcRecipients() const;
+
+    RecipientsPtr getCcRecipientsPtr() const;
+
+    void appendCcRecipients(const std::string & value);
+
+    void appendCcRecipients(const Recipients& value);
+
+    void removeCcRecipients(const Recipients& value);
+
+    void setCcRecipients(const Recipients& value);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/ConversationFilterValidator.cpp b/src/platform/API/Messaging/ConversationFilterValidator.cpp
new file mode 100755 (executable)
index 0000000..89bcf97
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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 "ConversationFilterValidator.h"
+#include "ConversationFilterValidatorFactory.h"
+
+#include <API/Messaging/log.h>
+
+#include <dpl/log/log.h>
+
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               ConversationFilterValidator::ConversationFilterValidator(PropertyStructArray properties):FilterValidator(properties){
+                       m_isTypeSetted = false;
+               }
+
+               ConversationFilterValidator::~ConversationFilterValidator() {
+                       m_isTypeSetted = false;
+               }
+
+
+               bool ConversationFilterValidator::validateAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth){
+                       if(initialValue == NULL || endValue == NULL)
+                               return false;
+
+                       bool retVal = false;
+
+                       if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP)!=0){
+                               LogError(">>> [ERROR] Not Supported attribute :[" << attrName << "]");
+                               return false;
+                       }
+
+                       retVal = FilterValidator::validateAttributeRange(attrName, initialValue, endValue, depth);
+                       return retVal;
+               }
+
+               bool ConversationFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                               Api::Tizen::AnyPtr& matchValue, int depth){
+
+                               if(matchValue == NULL)
+                                       return false;
+
+                               bool retBool = false;
+
+                               if(validateAttributeEach(attrName, matchFlag, matchValue, depth) == false){
+                                       MsgLogWanning(">>>[Warning] attrName:[" << attrName << "] is invalid value:[" << matchValue->toString() << "]");
+                                       return false;
+                               }
+
+                               retBool = FilterValidator::validateAttribute(attrName, matchFlag, matchValue,depth);
+                               LogDebug(">>> retBool:" << retBool);
+                               return retBool;
+               }
+
+               bool ConversationFilterValidator::validateAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
+
+                       if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_TYPE)==0){
+                               if(m_isTypeSetted == true){
+                                       MsgLogError(">>> [ERROR] duplicated type :[" << attrName << "], value:[" << value->toString()<< "]");
+                                       return false;
+                               }else{
+                                       m_isTypeSetted = true;
+                               }
+                       }
+
+                       return true;
+               }
+
+       }
+       }
+}
diff --git a/src/platform/API/Messaging/ConversationFilterValidator.h b/src/platform/API/Messaging/ConversationFilterValidator.h
new file mode 100755 (executable)
index 0000000..9f6c7dd
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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 CONVERSATIONFILTERVALIDATOR_H_
+#define CONVERSATIONFILTERVALIDATOR_H_
+
+#include <API/Filter/FilterValidator.h>
+
+namespace TizenApis {
+
+       namespace Platform {
+               namespace Messaging {
+
+               class ConversationFilterValidator : public Api::Tizen::FilterValidator {
+                       private:
+                               bool m_isTypeSetted;
+
+                       public:
+                               ConversationFilterValidator(Api::Tizen::PropertyStructArray properties);
+                               virtual ~ConversationFilterValidator();
+
+                               // validate AttributeRangeFilter
+                               virtual bool validateAttributeRange(std::string& attrName,
+                                                                                       Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0);
+
+                               virtual bool validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                                                Api::Tizen::AnyPtr& matchValue, int depth=0);
+
+                       protected:
+                               bool validateAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth);
+
+               };
+
+               typedef DPL::SharedPtr<ConversationFilterValidator> ConversationFilterValidatorPtr;
+
+               }
+       }
+}
+
+#endif /* CONVERSATIONFILTERVALIDATOR_H_ */
diff --git a/src/platform/API/Messaging/ConversationFilterValidatorFactory.cpp b/src/platform/API/Messaging/ConversationFilterValidatorFactory.cpp
new file mode 100755 (executable)
index 0000000..d37ed1e
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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 "ConversationFilterValidatorFactory.h"
+
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               const std::string ConversationFilterValidatorFactory::ATTRIBUTE_ID               = "id";
+               const std::string ConversationFilterValidatorFactory::ATTRIBUTE_TYPE             = "type";
+               const std::string ConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP        = "timestamp";
+               const std::string ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT    = "messageCount";
+               const std::string ConversationFilterValidatorFactory::ATTRIBUTE_UNREAD_MESSAGES  = "unreadMessages";
+               const std::string ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW          = "preview";
+               const std::string ConversationFilterValidatorFactory::ATTRIBUTE_FROM             = "from";
+               const std::string ConversationFilterValidatorFactory::ATTRIBUTE_TO               = "to";
+
+               static PropertyStructArray properties =
+               {
+                               {ConversationFilterValidatorFactory::ATTRIBUTE_ID.c_str(),              Api::Tizen::PrimitiveType_String},
+                               {ConversationFilterValidatorFactory::ATTRIBUTE_TYPE.c_str(),            Api::Tizen::PrimitiveType_String},
+                               {ConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP.c_str(),       Api::Tizen::PrimitiveType_Time},
+                               {ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT.c_str(),   Api::Tizen::PrimitiveType_Number},
+                               {ConversationFilterValidatorFactory::ATTRIBUTE_UNREAD_MESSAGES.c_str(), Api::Tizen::PrimitiveType_Number},
+                               {ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW.c_str(),         Api::Tizen::PrimitiveType_String},
+                               {ConversationFilterValidatorFactory::ATTRIBUTE_FROM.c_str(),            Api::Tizen::PrimitiveType_String},
+                               {ConversationFilterValidatorFactory::ATTRIBUTE_TO.c_str(),              Api::Tizen::PrimitiveType_String},
+                               {0,                  Api::Tizen::PrimitiveType_NoType}
+               };
+
+               ConversationFilterValidatorPtr ConversationFilterValidatorFactory::getConversationFilterValidator()
+               {
+                   ConversationFilterValidatorPtr theInstance =
+                               ConversationFilterValidatorPtr(new ConversationFilterValidator(properties));
+
+                   return theInstance;
+               }
+
+               }
+       }
+}
diff --git a/src/platform/API/Messaging/ConversationFilterValidatorFactory.h b/src/platform/API/Messaging/ConversationFilterValidatorFactory.h
new file mode 100755 (executable)
index 0000000..0d3a153
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// 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 CONVERSATIONFILTERVALIDATORFACTORY_H_
+#define CONVERSATIONFILTERVALIDATORFACTORY_H_
+
+#include <API/Filter/FilterValidator.h>
+#include "ConversationFilterValidator.h"
+
+namespace TizenApis {
+
+       namespace Platform {
+               namespace Messaging {
+
+               class ConversationFilterValidatorFactory {
+                       public:
+                               ConversationFilterValidatorFactory(){};
+
+                       public:
+                               static const std::string ATTRIBUTE_ID;
+                               static const std::string ATTRIBUTE_TYPE;
+                               static const std::string ATTRIBUTE_TIMESTAMP;
+                               static const std::string ATTRIBUTE_MESSAGE_COUNT;
+                               static const std::string ATTRIBUTE_UNREAD_MESSAGES;
+                               static const std::string ATTRIBUTE_PREVIEW;
+                               static const std::string ATTRIBUTE_FROM;
+                               static const std::string ATTRIBUTE_TO;
+
+                       public:
+                               static ConversationFilterValidatorPtr getConversationFilterValidator();
+               };
+               
+               }
+       }
+
+}
+
+#endif /* CONVERSATIONFILTERVALIDATORFACTORY_H_ */
diff --git a/src/platform/API/Messaging/EmailAccountInfo.cpp b/src/platform/API/Messaging/EmailAccountInfo.cpp
new file mode 100755 (executable)
index 0000000..baa8ccf
--- /dev/null
@@ -0,0 +1,85 @@
+//
+// 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 <sstream>
+#include <Commons/Exception.h>
+#include "EmailAccountInfo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+EmailAccountInfo::EmailAccountInfo(int id,
+        const std::string& name,
+        const std::string& address) :
+    m_name(name),
+    m_address(address)
+{
+    std::stringstream stream;
+    stream << id;
+    if (stream.fail()) {
+        ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+                 "Couldn't convert e-mail account id");
+    }
+    m_id = stream.str();
+}
+
+EmailAccountInfo::EmailAccountInfo(const std::string& id,
+        const std::string& name,
+        const std::string& address) :
+    m_id(id),
+    m_name(name),
+    m_address(address)
+{
+}
+
+int EmailAccountInfo::getIntId() const
+{
+    int result = 0;
+    std::stringstream stream(m_id);
+    stream >> result;
+    if (stream.fail()) {
+        ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+                 "Couldn't convert e-mail account id");
+    }
+    return result;
+}
+
+std::string EmailAccountInfo::getId() const
+{
+    return m_id;
+}
+
+std::string EmailAccountInfo::getName() const
+{
+    return m_name;
+}
+
+std::string EmailAccountInfo::getAddress() const
+{
+    return m_address;
+}
+
+const bool EmailAccountInfo::operator==(const EmailAccountInfo& account) const
+{
+    return (m_id == account.m_id &&
+            m_name == account.m_name &&
+            m_address == account.m_address);
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/EmailAccountInfo.h b/src/platform/API/Messaging/EmailAccountInfo.h
new file mode 100755 (executable)
index 0000000..96e0b6f
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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_MESSAGING_EMAILACCOUNTINFO_H_
+#define WRTPLUGINS_MESSAGING_EMAILACCOUNTINFO_H_
+
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EmailAccountInfo
+{
+  public:
+    EmailAccountInfo(int id,
+            const std::string& name,
+            const std::string& address);
+
+    EmailAccountInfo(const std::string& id = "",
+            const std::string& name = "",
+            const std::string& address = "");
+
+    int getIntId() const;
+
+    std::string getId() const;
+
+    std::string getName() const;
+
+    std::string getAddress() const;
+
+    //void setAccountData(int id, const char* name, const char* address);
+
+    const bool operator==(const EmailAccountInfo& account) const;
+
+  private:
+    std::string m_id;
+    std::string m_name;
+    std::string m_address;
+};
+
+//typedef DPL::SharedPtr<EmailAccountInfo> EmailAccountInfoPtr;
+
+}
+}
+}
+#endif // WRTPLUGINS_MESSAGING_EMAILACCOUNTINFO_H_
diff --git a/src/platform/API/Messaging/EmitterConversationReceived.cpp b/src/platform/API/Messaging/EmitterConversationReceived.cpp
new file mode 100755 (executable)
index 0000000..24e3241
--- /dev/null
@@ -0,0 +1,26 @@
+//
+// 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 "EmitterConversationReceived.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+}
+} // Api
+} // WrtPlugins
diff --git a/src/platform/API/Messaging/EmitterConversationReceived.h b/src/platform/API/Messaging/EmitterConversationReceived.h
new file mode 100755 (executable)
index 0000000..9d8ba04
--- /dev/null
@@ -0,0 +1,38 @@
+//
+// 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_MESSAGING_EMITTERCONVERSATIONRECEIVED_H_
+#define WRTPLUGINS_MESSAGING_EMITTERCONVERSATIONRECEIVED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "EventMessageReceived.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EmitterConversationReceived : public WrtDeviceApis::Commons::ListenerEventEmitter<EventMessageReceived>
+{
+
+};
+
+typedef DPL::SharedPtr<EmitterConversationReceived> EmitterConversationReceivedPtr;
+} // Api
+} // WrtPlugins
+}
+#endif // WRTPLUGINS_MESSAGING_EMITTERCONVERSATIONRECEIVED_H_
diff --git a/src/platform/API/Messaging/EmitterFolderReceived.cpp b/src/platform/API/Messaging/EmitterFolderReceived.cpp
new file mode 100755 (executable)
index 0000000..57c8d25
--- /dev/null
@@ -0,0 +1,26 @@
+//
+// 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 "EmitterFolderReceived.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+}
+} // Api
+} // WrtPlugins
diff --git a/src/platform/API/Messaging/EmitterFolderReceived.h b/src/platform/API/Messaging/EmitterFolderReceived.h
new file mode 100755 (executable)
index 0000000..be9677c
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// 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_MESSAGING_EMITTERFOLDERRECEIVED_H_
+#define WRTPLUGINS_MESSAGING_EMITTERFOLDERRECEIVED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "EventMessageReceived.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EmitterFolderReceived : public WrtDeviceApis::Commons::ListenerEventEmitter<
+        EventMessageReceived>
+{
+
+};
+
+typedef DPL::SharedPtr<EmitterFolderReceived> EmitterFolderReceivedPtr;
+} // Api
+} // WrtPlugins
+}
+#endif // WRTPLUGINS_MESSAGING_EMITTERMESSAGERECEIVED_H_
diff --git a/src/platform/API/Messaging/EmitterMessageReceived.cpp b/src/platform/API/Messaging/EmitterMessageReceived.cpp
new file mode 100755 (executable)
index 0000000..22ce8f4
--- /dev/null
@@ -0,0 +1,25 @@
+//
+// 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 "EmitterMessageReceived.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+}
+} // Api
+} // WrtPlugins
diff --git a/src/platform/API/Messaging/EmitterMessageReceived.h b/src/platform/API/Messaging/EmitterMessageReceived.h
new file mode 100755 (executable)
index 0000000..0a82a0c
--- /dev/null
@@ -0,0 +1,38 @@
+//
+// 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_MESSAGING_EMITTERMESSAGERECEIVED_H_
+#define WRTPLUGINS_MESSAGING_EMITTERMESSAGERECEIVED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "EventMessageReceived.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EmitterMessageReceived : public WrtDeviceApis::Commons::ListenerEventEmitter<EventMessageReceived>
+{
+
+};
+
+typedef DPL::SharedPtr<EmitterMessageReceived> EmitterMessageReceivedPtr;
+} // Api
+} // WrtPlugins
+}
+#endif // WRTPLUGINS_MESSAGING_EMITTERMESSAGERECEIVED_H_
diff --git a/src/platform/API/Messaging/EventAddDraftMessage.h b/src/platform/API/Messaging/EventAddDraftMessage.h
new file mode 100755 (executable)
index 0000000..4b4af2c
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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 EVENTADDDRAFTMESSAGE_H
+#define EVENTADDDRAFTMESSAGE_H
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IMessage.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventAddDraftMessage;
+
+typedef DPL::SharedPtr<EventAddDraftMessage> EventAddDraftMessagePtr;
+
+class EventAddDraftMessage :
+    public WrtDeviceApis::Commons::IEvent<EventAddDraftMessage>
+{
+  private:
+    long m_index;
+    int m_type;
+
+  public:
+  EventAddDraftMessage() : m_index(-1), m_type(-1){
+  }
+
+    IMessagePtr msg;
+
+    void setIndex(long index){
+        m_index = index;
+    }
+
+    long getIndex(){
+        return m_index;
+    }
+
+    void setType(int type){
+        m_type = type;
+    }
+
+    int getType(){
+        return m_type;
+    }  
+
+    virtual void clearOnCancel()
+    {
+    }
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/EventDeleteConversations.h b/src/platform/API/Messaging/EventDeleteConversations.h
new file mode 100755 (executable)
index 0000000..7929297
--- /dev/null
@@ -0,0 +1,77 @@
+//
+// 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 EVENT_DELETE_CONVERSATIONS_H
+#define EVENT_DELETE_CONVERSATIONS_H
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IMessage.h"
+#include <API/Filter/IFilter.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventDeleteConversations;
+
+typedef DPL::SharedPtr<EventDeleteConversations> EventDeleteConversationsPtr;
+
+class EventDeleteConversations :
+    public WrtDeviceApis::Commons::IEvent<EventDeleteConversations>
+{
+private:
+       std::vector<Api::Messaging::IConversationPtr> m_conversations;
+       bool m_FilterUse;
+       Api::Tizen::SortModePtr m_sortMode;
+       Api::Tizen::FilterPtr m_filter;
+       unsigned long m_limit;
+       unsigned long m_offset;
+       long m_index;
+       int m_type;
+       
+  public:
+       void setSortMode(Api::Tizen::SortModePtr sortMode) { m_sortMode = sortMode;}
+       void setFilter(Api::Tizen::FilterPtr filter) { m_filter = filter;}
+       void setLimit(unsigned long limit) { m_limit = limit;}
+       void setOffset(unsigned long offset) { m_offset = offset;}
+
+       Api::Tizen::SortModePtr getSortMode() { return m_sortMode;}
+       Api::Tizen::FilterPtr getFilter() { return m_filter;}
+       unsigned long getLimit() { return m_limit;}
+       unsigned long getOffset() { return m_offset;}
+       void setConversations(const std::vector<Api::Messaging::IConversationPtr>& conversations) { m_conversations = conversations; }
+       std::vector<Api::Messaging::IConversationPtr> getConversations() { return m_conversations; }
+       void setFilterUsing(bool filter) { m_FilterUse = filter;}
+       bool isFilterUsing() { return m_FilterUse;}
+       void setIndex(long index){m_index = index;}
+       long getIndex(){return m_index;}
+       void setType(int type){m_type = type;}
+       int getType(){return m_type;}   
+
+
+    virtual void clearOnCancel()
+    {
+    }
+};
+}
+}
+}
+#endif
+
diff --git a/src/platform/API/Messaging/EventDeleteMessage.h b/src/platform/API/Messaging/EventDeleteMessage.h
new file mode 100755 (executable)
index 0000000..7913c72
--- /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 EVENTDELETEMESSAGE_H
+#define EVENTDELETEMESSAGE_H
+
+#include <dpl/shared_ptr.h>
+
+#include <Commons/IEvent.h>
+#include "IMessaging.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventDeleteMessage;
+
+typedef DPL::SharedPtr<EventDeleteMessage> EventDeleteMessagePtr;
+
+class EventDeleteMessage :
+    public WrtDeviceApis::Commons::IEvent<EventDeleteMessage>
+{
+  public:
+
+    IMessagePtr msg;
+
+    virtual void clearOnCancel()
+    {
+    }
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/EventDeleteMessages.h b/src/platform/API/Messaging/EventDeleteMessages.h
new file mode 100755 (executable)
index 0000000..346dd3d
--- /dev/null
@@ -0,0 +1,77 @@
+//
+// 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 EVENTDELETEMESSAGES_H
+#define EVENTDELETEMESSAGES_H
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IMessage.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventDeleteMessages;
+
+typedef DPL::SharedPtr<EventDeleteMessages> EventDeleteMessagesPtr;
+
+class EventDeleteMessages :
+    public WrtDeviceApis::Commons::IEvent<EventDeleteMessages>
+{
+       private:
+               Api::Tizen::FilterPtr m_filter;
+               long m_index;
+               int m_type;
+  public:
+
+    IMessagePtr msg;
+    std::vector<Api::Messaging::IMessagePtr> msgArray;   
+
+       public:
+               void setFilter(const Api::Tizen::FilterPtr& filter) {
+                       m_filter = filter;
+               }
+
+               Api::Tizen::FilterPtr getFilter() {
+                       return m_filter;
+               }
+               void setIndex(long index){
+                       m_index = index;
+               }
+
+               long getIndex(){
+                       return m_index;
+               }
+
+               void setType(int type){
+                       m_type = type;
+               }
+
+               int getType(){
+                       return m_type;
+               }       
+
+    virtual void clearOnCancel()
+    {
+    }
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/EventGetConversationId.h b/src/platform/API/Messaging/EventGetConversationId.h
new file mode 100755 (executable)
index 0000000..1bbf818
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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 EVENT_GET_CONVERSATION_ID_H
+#define EVENT_GET_CONVERSATION_ID_H
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventGetConversationId;
+
+typedef DPL::SharedPtr<EventGetConversationId> EventGetConversationIdPtr;
+
+class EventGetConversationId :
+    public WrtDeviceApis::Commons::IEvent<EventGetConversationId>
+{
+public:
+               void setConversationMsgPtr(const IMessagePtr msgPtr) { m_msgPtr = msgPtr;}
+               void setConversationId(int conversationId) { m_conversationId = conversationId;}
+               IMessagePtr getConversationMsgPtr() const { return m_msgPtr;}
+               int getConversationId() { return m_conversationId;}     
+               EventGetConversationId() { }
+               ~EventGetConversationId(){}
+private:
+               int m_conversationId;
+               IMessagePtr m_msgPtr;
+};
+}
+}
+}
+#endif
+
diff --git a/src/platform/API/Messaging/EventGetMessagingService.h b/src/platform/API/Messaging/EventGetMessagingService.h
new file mode 100755 (executable)
index 0000000..50b9705
--- /dev/null
@@ -0,0 +1,110 @@
+//
+// 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_API_GET_MESSAGING_SERVICE_EVENT_MESSAGING_H_
+#define WRTPLUGINS_API_GET_MESSAGING_SERVICE_EVENT_MESSAGING_H_
+
+#include <vector>
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/Exception.h>
+
+#include "IMessagingService.h"
+#include "IMessagingTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+class EventGetMessagingService: public WrtDeviceApis::Commons::IEvent<EventGetMessagingService> 
+{
+       
+public:
+       static const int MESSAGING_SERVICE_MANAGER_EVENT_TYPE_ALL = 1;
+       static const int MESSAGING_SERVICE_MANAGER_EVENT_TYPE_ACCOUNT = 2;
+
+private:
+       
+     long m_accountID;
+       int m_messagingServiceType;
+     int m_eventType;
+               
+     std::vector< IMessagingServicePtr > m_messagingServices;
+       
+public:
+       void setAccountID(long value) {
+               //ToDo : check vailded Account, now temporary
+               m_accountID = value;
+               m_eventType = MESSAGING_SERVICE_MANAGER_EVENT_TYPE_ACCOUNT; //if set account, type will be changed as account type
+       }
+
+       long getAccountID() const {
+               return m_accountID;
+       }
+
+       void setEventType(int type) {
+               m_eventType = type;
+       }
+       
+       int getEventType() const{
+               return m_eventType;
+       }       
+
+       void setMessagingServiceType(int type) {
+               m_messagingServiceType = type;
+       }
+
+       int getMessagingServiceType() const {
+               return m_messagingServiceType;
+       }
+               
+       void setMessagingServicesRef(const std::vector< IMessagingServicePtr > &msgServices)
+       {
+               m_messagingServices = msgServices;
+       }
+
+       std::size_t getNumberOfMessagingService()
+       {
+               return m_messagingServices.size();
+       }
+               
+       IMessagingServicePtr getMessagingService(std::size_t index)
+       {
+               if (index >= m_messagingServices.size() || m_messagingServices.size() == 0) {
+                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               }
+               
+               return m_messagingServices[index];
+       }
+       
+       std::vector<IMessagingServicePtr> getMessagingServices()
+       {
+               return m_messagingServices;
+       }
+       
+       EventGetMessagingService() 
+       {
+               m_accountID = -1, 
+               m_eventType = MESSAGING_SERVICE_MANAGER_EVENT_TYPE_ALL;
+       }
+};
+
+typedef DPL::SharedPtr<EventGetMessagingService> EventGetMessagingServicePtr;
+
+} // Api
+} // WrtPlugins
+}
+#endif //WRTPLUGINS_API_GET_MESSAGING_SERVICE_EVENT_MESSAGING_H_
\ No newline at end of file
diff --git a/src/platform/API/Messaging/EventMessageReceived.cpp b/src/platform/API/Messaging/EventMessageReceived.cpp
new file mode 100755 (executable)
index 0000000..8ca3699
--- /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.
+//
+
+#include "EventMessageReceived.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+EventMessageReceived::~EventMessageReceived()
+{
+}
+
+IMessagePtr EventMessageReceived::getMessage() const
+{
+    return m_message;
+}
+
+void EventMessageReceived::setMessage(const IMessagePtr& message)
+{
+    m_message = message;
+}
+
+IConversationPtr EventMessageReceived::getConversation() const
+{
+    return m_conversation;
+}
+
+void EventMessageReceived::setConversation(const IConversationPtr& converation)
+{
+    m_conversation = converation;
+}
+
+IMessageFolderPtr EventMessageReceived::getMessageFolder() const
+{
+    return m_messagefolder;
+}
+
+void EventMessageReceived::setMessageFolder(const IMessageFolderPtr& messagefolder)
+{
+    m_messagefolder = messagefolder;
+}
+
+void EventMessageReceived::setMsg_Event_Type(Msg_EventType state)
+{
+       m_msg_event_type = state;
+}
+
+}
+} // Api
+} // WrtPlugins
diff --git a/src/platform/API/Messaging/EventMessageReceived.h b/src/platform/API/Messaging/EventMessageReceived.h
new file mode 100755 (executable)
index 0000000..dba8661
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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_MESSAGING_EVENTMESSAGERECEIVED_H_
+#define WRTPLUGINS_MESSAGING_EVENTMESSAGERECEIVED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include "IMessage.h"
+#include "IConversation.h"
+#include "IMessageFolder.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventMessageReceived : public WrtDeviceApis::Commons::ListenerEvent<
+        EventMessageReceived>
+{
+  public:
+    typedef enum
+    {
+         MSG_ADDED = 0,
+         MSG_UPDATED = 1,
+         MSG_DELETED = 2,
+         MSG_MULTIPLE = 3,
+    } Msg_EventType;
+
+    virtual ~EventMessageReceived();
+
+    IMessagePtr getMessage() const;
+    IConversationPtr getConversation() const;
+    IMessageFolderPtr getMessageFolder() const;
+       
+    void setMessage(const IMessagePtr& message);
+    void setConversation(const IConversationPtr &conversation);
+    void setMessageFolder(const IMessageFolderPtr &messagefolder);
+
+    void setMsg_Event_Type(Msg_EventType state);
+    Msg_EventType getMsg_Event_Type() {   return m_msg_event_type;}
+
+
+  private:
+    IConversationPtr m_conversation;
+    IMessagePtr m_message;
+    IMessageFolderPtr m_messagefolder; 
+    Msg_EventType m_msg_event_type;
+       
+};
+
+typedef DPL::SharedPtr<EventMessageReceived> EventMessageReceivedPtr;
+} // Api
+} // WrtPlugins
+}
+#endif // WRTPLUGINS_MESSAGING_EVENTMESSAGERECEIVED_H_
diff --git a/src/platform/API/Messaging/EventMessagingService.h b/src/platform/API/Messaging/EventMessagingService.h
new file mode 100755 (executable)
index 0000000..34bae9e
--- /dev/null
@@ -0,0 +1,123 @@
+//
+// 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_API_MESSAGING_SERVICE_EVENT_H_
+#define WRTPLUGINS_API_MESSAGING_SERVICE_EVENT_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "MessageProperties.h"
+
+#include "IMessage.h"
+#include "IAttachment.h"
+#include "IMessagingService.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventMessagingService;
+
+enum MessagingServiceEventType
+{
+       MESSAGING_SERVICE_EVENT_TYPE_SEND_MESSAGE = 1,
+       MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY,
+       MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT,
+       MESSAGING_SERVICE_EVENT_TYPE_SYNC,
+       MESSAGING_SERVICE_EVENT_TYPE_SYNC_FOLDER,
+       MESSAGING_SERVICE_EVENT_COUNT,
+};
+
+
+
+class EventMessagingService: public WrtDeviceApis::Commons::IEvent<EventMessagingService> {
+       
+public:
+#if 0  
+       static const int MESSAGING_SERVICE_EVENT_TYPE_SEND_MESSAGE                      = 1;
+       static const int MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY         = 2;
+       static const int MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT = 3;
+       static const int MESSAGING_SERVICE_EVENT_TYPE_SYNC                                      = 4;   //now, I have no idea about sync.                                
+       static const int MESSAGING_SERVICE_EVENT_TYPE_SYNC_FOLDER                       = 5;
+#endif
+private:
+       
+       MessagingPropertiesPtr m_messagingPropsPtr;
+       int m_eventType;
+       
+                
+       //now temporary
+       //IMessagePtr m_message;
+public:        
+       int getEventType() const{
+               return m_eventType;
+       }       
+
+       void setEventType(int type) {
+               m_eventType = type;
+       }
+       
+       void setMessageProperties(MessagingPropertiesPtr msgProps)
+       {
+               m_messagingPropsPtr = msgProps;
+       }
+
+       MessagingPropertiesPtr getMessageProperties()
+       {
+               return m_messagingPropsPtr;
+       }
+
+       int getHandle() const {
+               return m_handle;
+       }
+
+       void setHandle(int handle)
+       {
+               m_handle = handle;
+       }
+
+       std::vector<std::string> m_successRecipients;   //sucess
+       std::vector<std::string> m_failRecipients;              //fail
+       bool store;
+
+       IMessagePtr m_message;
+       IAttachmentPtr m_attachment;
+       IMessagingServicePtr m_messagingService;
+
+       int opId;
+       int m_handle;
+
+       std::string m_folder_name;
+
+       int m_sync_account_id;  //account ID
+       int m_sync_folder_id;   // folder ID
+       int m_sync_limit;       //limit
+       
+       EventMessagingService()
+       {
+               m_eventType = MESSAGING_SERVICE_EVENT_TYPE_SEND_MESSAGE;        //default value.
+       }
+               
+};
+
+typedef DPL::SharedPtr<EventMessagingService> EventMessagingServicePtr;
+
+} // Api
+} // WrtPlugins
+}
+#endif //WRTPLUGINS_API_MESSAGING_SERVICE_EVENT_H_
+
diff --git a/src/platform/API/Messaging/EventMessagingStorage.h b/src/platform/API/Messaging/EventMessagingStorage.h
new file mode 100755 (executable)
index 0000000..6427ec6
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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_API_ADD_DRAFT_MESSAGE_EVENT_MESSAGINGSTORAGE_H_
+#define WRTPLUGINS_API_ADD_DRAFT_MESSAGE_EVENT_MESSAGINGSTORAGE_H_
+
+//#include "PluginTempleteProperties.h"
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <API/Messaging/IMessagingTypes.h>     // later MAY be changed to IMessagingStorage.h 
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+       
+class EventMessagingStorage: public WrtDeviceApis::Commons::IEvent<EventMessagingStorage> {
+       
+public:
+
+       static const int MESSAGING_STORAGE_EVENT_UNKNOWN                                = -1;
+       static const int MESSAGING_STORAGE_EVENT_ADD_DRAFT_MESSAGE                              = 1;    
+       static const int MESSAGING_STORAGE_EVENT_QUERY_MESSAGES                                 = 2;
+       static const int MESSAGING_STORAGE_EVENT_DELETE_MESSAGES                                = 3;
+       static const int MESSAGING_STORAGE_EVENT_UPDATE_MESSAGES                                = 4;
+       static const int MESSAGING_STORAGE_EVENT_QUERY_CONVERSATIONS                    = 5;
+       static const int MESSAGING_STORAGE_EVENT_DELETE_CONVERSATIONS                   = 6;
+       static const int MESSAGING_STORAGE_EVENT_QUERYFOLDERS                                   = 7;    
+//     static const int MESSAGING_STORAGE_EVENT_ON_MESSAGING_STORAGE_CHANGES   = 8;
+
+
+// input parameters
+//MessageFilterPtr messageFilter;
+std::vector<Api::Messaging::MessageType> messageTypes;
+std::vector<Api::Messaging::FolderType> folderTypes;
+// AccountID to be added for email 
+// Message to be added for addDraftMessage
+// tempolary    IMessagePtr msg;
+
+private:
+
+/*     
+     long m_accountID;
+*/     
+     int m_eventType;
+
+               
+public:
+/*
+       void setAccountID(long value) {
+               //ToDo : check vailded Account, now temporary
+               m_accountID = value;
+               m_eventType = MESSAGING_SERVICE_MANAGER_EVENT_TYPE_ACCOUNT; //if set account, type will be changed as account type
+       }
+
+       long getAccountID() const {
+               return m_accountID;
+       }
+
+*/
+void setEventType(int type){
+       m_eventType = type;
+}
+
+int getEventType(){
+               return m_eventType;
+       }       
+
+
+       EventMessagingStorage() 
+       {
+//             m_accountID = -1, 
+               m_eventType = MESSAGING_STORAGE_EVENT_UNKNOWN;
+       }
+};
+
+typedef DPL::SharedPtr<EventMessagingStorage> EventMessagingStoragePtr;
+
+} // Api
+} // WrtPlugins
+}
+#endif //WRTPLUGINS_API_GET_MESSAGING_SERVICE_EVENT_MESSAGING_H_
\ No newline at end of file
diff --git a/src/platform/API/Messaging/EventOnSendingFailed.h b/src/platform/API/Messaging/EventOnSendingFailed.h
new file mode 100755 (executable)
index 0000000..238ed2d
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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 EVENTONSENDINGFAILED_H_
+#define EVENTONSENDINGFAILED_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/EventListener.h>
+#include <Commons/ListenerEventEmitter.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+/*
+ *
+ */
+class EventOnSendingFailed : public WrtDeviceApis::Commons::ListenerEvent<EventOnSendingFailed>
+{
+  public:
+    typedef enum
+    {
+        NO_NETWORKING,
+        NO_CONNECTION,
+        BAD_PAYLOAD,
+        UNKNOWN
+    } ErrorCode;
+
+    EventOnSendingFailed()
+    {
+    }
+
+    void setError(ErrorCode error)
+    {
+        m_error = error;
+    }
+
+    ErrorCode getError() const
+    {
+        return m_error;
+    }
+
+  private:
+    ErrorCode m_error;
+};
+
+typedef DPL::SharedPtr<EventOnSendingFailed> EventOnSendingFailedPtr;
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventOnSendingFailed>
+EventOnSendingFailedEmitter;
+typedef DPL::SharedPtr<EventOnSendingFailedEmitter>
+EventOnSendingFailedEmitterPtr;
+} // Api
+} // WrtPlugins
+}
+#endif /* EVENTONSENDINGFAILED_H_ */
diff --git a/src/platform/API/Messaging/EventQueryConversations.h b/src/platform/API/Messaging/EventQueryConversations.h
new file mode 100755 (executable)
index 0000000..47b2a5d
--- /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.
+//
+
+#ifndef EVENT_QUERY_CONVERSATIONS_H
+#define EVENT_QUERY_CONVERSATIONS_H
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <API/Filter/SortMode.h>
+
+#include "IMessage.h"
+#include "IConversation.h"
+#include <API/Filter/IFilter.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventQueryConversations;
+
+typedef DPL::SharedPtr<EventQueryConversations> EventQueryConversationsPtr;
+
+class EventQueryConversations :
+    public WrtDeviceApis::Commons::IEvent<EventQueryConversations>
+{
+  public:
+         EventQueryConversations() : m_limit(0), m_offset(0), m_index(-1), m_type(-1){
+         }     
+       void setSortMode(Api::Tizen::SortModePtr sortMode) { m_sortMode = sortMode;}
+       void setFilter(Api::Tizen::FilterPtr filter) { m_filter = filter;}
+       void setLimit(unsigned long limit) { m_limit = limit;}
+       void setOffset(unsigned long offset) { m_offset = offset;}
+       void addConversations(std::vector<IConversationPtr> conv) 
+               { m_conversations.insert(m_conversations.end(), conv.begin(), conv.end());}
+       Api::Tizen::SortModePtr getSortMode() { return m_sortMode;}
+       Api::Tizen::FilterPtr getFilter() { return m_filter;}
+       unsigned long getLimit() { return m_limit;}
+       unsigned long getOffset() { return m_offset;}
+       std::vector<IConversationPtr> getConversatioins() { return m_conversations;}
+       void setIndex(long index){
+               m_index = index;
+       }
+       
+       long getIndex(){
+               return m_index;
+       }
+       
+       void setType(int type){
+               m_type = type;
+       }
+       
+       int getType(){
+               return m_type;
+       }       
+
+    virtual void clearOnCancel()
+    {
+    }
+
+private:
+    // input parameters
+       Api::Tizen::SortModePtr m_sortMode;
+       Api::Tizen::FilterPtr m_filter;
+       unsigned long m_limit;
+       unsigned long m_offset;
+       long m_index;
+       int m_type;             
+    //output parameter
+       std::vector<IConversationPtr> m_conversations;
+
+};
+}
+}
+}
+#endif
+
diff --git a/src/platform/API/Messaging/EventQueryFolders.h b/src/platform/API/Messaging/EventQueryFolders.h
new file mode 100755 (executable)
index 0000000..d3019c4
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// 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 EVENTQUERYFOLDERS_H
+#define EVENTQUERYFOLDERS_H
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IMessage.h"
+#include "IMessageFolder.h"
+#include <API/Filter/IFilter.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventQueryFolders;
+
+typedef DPL::SharedPtr<EventQueryFolders> EventQueryFoldersPtr;
+
+class EventQueryFolders :
+    public WrtDeviceApis::Commons::IEvent<EventQueryFolders>
+{
+       private:
+               // input parameters
+               Api::Tizen::FilterPtr m_filter;
+               int m_accountId;        
+               long m_index;
+               int m_type;             
+               //output parameter
+               std::vector<IMessageFolderPtr> m_folders;
+
+  public:
+    EventQueryFolders() : m_accountId(-1), m_index(-1), m_type(-1){
+       }
+       
+       void setFilter(Api::Tizen::FilterPtr filter) { m_filter = filter;}
+       void addFolders(std::vector<IMessageFolderPtr> folder) 
+               { m_folders.insert(m_folders.end(), folder.begin(), folder.end());}
+       Api::Tizen::FilterPtr getFilter() { return m_filter;}
+       std::vector<IMessageFolderPtr> getFolders() { return m_folders;}
+
+       void setAccountId(int accountId){
+               m_accountId = accountId;
+       }
+       int getAccountId(){
+               return m_accountId;
+       }
+
+       void setIndex(long index){
+               m_index = index;
+       }
+       
+       long getIndex(){
+               return m_index;
+       }
+       
+       void setType(int type){
+               m_type = type;
+       }
+       
+       int getType(){
+               return m_type;
+       }       
+       
+
+    virtual void clearOnCancel()
+    {
+    }
+
+
+
+};
+}
+}
+}
+#endif
+
diff --git a/src/platform/API/Messaging/EventQueryMessages.h b/src/platform/API/Messaging/EventQueryMessages.h
new file mode 100755 (executable)
index 0000000..350b99f
--- /dev/null
@@ -0,0 +1,113 @@
+//
+// 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 EVENTQUERYMESSAGES_H
+#define EVENTQUERYMESSAGES_H
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <API/Filter/SortMode.h>
+
+#include "IMessage.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventQueryMessages;
+
+typedef DPL::SharedPtr<EventQueryMessages> EventQueryMessagesPtr;
+
+class EventQueryMessages :
+    public WrtDeviceApis::Commons::IEvent<EventQueryMessages>
+{
+       private:
+       Api::Tizen::FilterPtr m_filter;
+       Api::Tizen::SortModePtr m_sortMode;
+       long m_limit;
+       long m_offset;
+       long m_index;
+       int m_type;
+
+  public:
+       EventQueryMessages() : m_limit(0), m_offset(0), m_index(-1), m_type(-1){
+       }
+    // input parameters
+    std::vector<MessageType> messageTypes;
+    std::vector<FolderType> folderTypes;
+
+    //output parameter
+    std::vector<Api::Messaging::IMessagePtr> msgs;
+
+       public:
+               void setFilter(const Api::Tizen::FilterPtr& filter) {
+                       m_filter = filter;
+               }
+
+               Api::Tizen::FilterPtr getFilter() {
+                       return m_filter;
+               }
+
+               void setSortMode(const Api::Tizen::SortModePtr& sortMode) {
+                       m_sortMode = sortMode;
+               }
+
+               Api::Tizen::SortModePtr getSortMode() {
+                       return m_sortMode;
+               }
+
+               void setLimit(long limit){
+                       m_limit = limit;
+               }
+
+               long getLimit(){
+                       return m_limit;
+               }
+
+               void setOffset(long offset){
+                       m_offset = offset;
+               }
+
+               long getOffset(){
+                       return m_offset;
+               }
+
+               void setIndex(long index){
+                       m_index = index;
+               }
+
+               long getIndex(){
+                       return m_index;
+               }
+
+               void setType(int type){
+                       m_type = type;
+               }
+
+               int getType(){
+                       return m_type;
+               }       
+
+    virtual void clearOnCancel()
+    {
+    }
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/EventSendMessage.h b/src/platform/API/Messaging/EventSendMessage.h
new file mode 100755 (executable)
index 0000000..b687c6f
--- /dev/null
@@ -0,0 +1,80 @@
+//
+// 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 EVENTSENDMESSAGE_H
+#define EVENTSENDMESSAGE_H
+
+#include <dpl/shared_ptr.h>
+
+#include <Commons/IEvent.h>
+#include "IMessagingService.h"
+#include "IMessaging.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventSendMessage;
+
+typedef DPL::SharedPtr<EventSendMessage> EventSendMessagePtr;
+
+class EventSendMessage :
+    public WrtDeviceApis::Commons::IEvent<EventSendMessage>
+{
+  public:
+
+    IMessagePtr msg;
+    IMessagingServicePtr m_messagingService;   //messaging service.
+    
+    std::vector<std::string> m_successRecipients;      //sucess
+    std::vector<std::string> m_failRecipients;         //fail
+    bool store;
+    int opId;
+
+    void setRecipient(const std::string &recipient)
+    {
+        m_recipient = recipient;
+    }
+
+    std::string getRecipient() const
+    {
+        return m_recipient;
+    }
+
+    virtual void clearOnCancel()
+    {
+    }
+
+    void setSendCallbackPerRecipient(bool sendCallbackPerRecipient)
+    {
+        m_sendCallbackPerRecipient = sendCallbackPerRecipient;
+    }
+
+    bool getSendCallbackPerRecipient() const
+    {
+        return m_sendCallbackPerRecipient;
+    }
+
+  private:
+    std::string m_recipient;
+    bool m_sendCallbackPerRecipient;
+       
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/EventUpdateMessage.h b/src/platform/API/Messaging/EventUpdateMessage.h
new file mode 100755 (executable)
index 0000000..ed497f2
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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 EVENTUPDATEMESSAGE_H
+#define EVENTUPDATEMESSAGE_H
+
+#include <dpl/shared_ptr.h>
+
+#include <Commons/IEvent.h>
+#include "IMessaging.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventUpdateMessage;
+
+typedef DPL::SharedPtr<EventUpdateMessage> EventUpdateMessagePtr;
+
+class EventUpdateMessage :
+    public WrtDeviceApis::Commons::IEvent<EventUpdateMessage>
+{
+  public:
+
+    IMessagePtr msg;
+
+    virtual void clearOnCancel()
+    {
+    }
+};
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<EventUpdateMessage >
+EventUpdateMessageAnswerReceiver;
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/EventUpdateMessages.h b/src/platform/API/Messaging/EventUpdateMessages.h
new file mode 100755 (executable)
index 0000000..de05f4a
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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 EVENTUPDATEMESSAGES_H
+#define EVENTUPDATEMESSAGES_H
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include "IMessage.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventUpdateMessages;
+
+typedef DPL::SharedPtr<EventUpdateMessages> EventUpdateMessagesPtr;
+
+class EventUpdateMessages :
+    public WrtDeviceApis::Commons::IEvent<EventUpdateMessages>
+{
+  private:
+    long m_index;
+    int m_type;
+
+  public:
+
+    IMessagePtr msg;
+    std::vector<Api::Messaging::IMessagePtr> msgArray; 
+
+    void setIndex(long index){
+        m_index = index;
+    }
+       
+    long getIndex(){
+        return m_index;
+    }
+       
+    void setType(int type){
+        m_type = type;
+    }
+       
+    int getType(){
+        return m_type;
+    }  
+
+    virtual void clearOnCancel()
+    {
+    }
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/FolderFilterValidator.cpp b/src/platform/API/Messaging/FolderFilterValidator.cpp
new file mode 100755 (executable)
index 0000000..bf48fc9
--- /dev/null
@@ -0,0 +1,144 @@
+//
+// 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 "FolderFilterValidator.h"
+#include "FolderFilterValidatorFactory.h"
+
+#include <dpl/log/log.h>
+#include "log.h"
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               FolderFilterValidator::FolderFilterValidator(PropertyStructArray properties):FilterValidator(properties){
+                       m_isAccountIdSetted = false;
+
+                       initMatchFlagVectors();
+                       initAttributeAndMatchFlagsMap();
+               }
+
+               FolderFilterValidator::~FolderFilterValidator(){
+               }
+
+               void FolderFilterValidator::initMatchFlagVectors(){
+                       m_accountIdMatchFlagVec.push_back(FolderFilterValidatorFactory::MATCH_EXACTLY);
+                       m_folderPathMatchFlagVec.push_back(FolderFilterValidatorFactory::MATCH_EXACTLY);
+               }
+
+               void FolderFilterValidator::initAttributeAndMatchFlagsMap(){
+                       m_attributeAndMatchFlagsMap[FolderFilterValidatorFactory::ATTRIBUTE_ACCOUNTID]      = m_accountIdMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[FolderFilterValidatorFactory::ATTRIBUTE_FOLDERPATH]        = m_folderPathMatchFlagVec;
+               }
+
+               bool FolderFilterValidator::validateAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth){
+                       bool retVal = false;
+                       return retVal;
+               }
+
+               bool FolderFilterValidator::vectorContains(std::vector<std::string>& vec, Api::Tizen::MatchFlag& value){
+                       std::string matchStr;
+                       switch(value)
+                       {
+                       case Api::Tizen::MATCH_EXACTLY:
+                               matchStr = "EXACTLY";
+                               break;
+                       case Api::Tizen::MATCH_FULLSTRING:
+                               matchStr = "FULLSTRING";
+                               break;
+                       case Api::Tizen::MATCH_CONTAINS:
+                               matchStr = "CONTAINS";
+                               break;
+                       case Api::Tizen::MATCH_STARTSWITH:
+                               matchStr = "STARTSWITH";
+                               break;
+                       case Api::Tizen::MATCH_ENDSWITH:
+                               matchStr = "ENDSWITH";
+                               break;
+                       case Api::Tizen::MATCH_EXISTS:
+                               matchStr = "EXISTS";
+                               break;
+                       default:
+                               matchStr = "";
+                               break;
+                       }
+
+                       std::vector<std::string>::iterator it;
+                       for(it=vec.begin(); it<vec.end(); it++){
+                               if((*it).compare(matchStr) == 0){
+                                       return true;
+                               }
+                       }
+
+                       return false;
+               }
+
+               bool FolderFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                               Api::Tizen::AnyPtr& matchValue, int depth){
+                       bool retBool = false;
+
+                       if(matchValue == NULL)
+                               return false;
+
+                       if(validateAttributeEach(attrName, matchFlag, matchValue, depth) == false){
+                               MsgLogWanning(">>>[Warning] attrName:[" << attrName << "] is invalid value:[" << matchValue->toString() << "]");
+                               return false;
+                       }
+                       LogDebug("## 001 ##");
+                       retBool = FilterValidator::validateAttribute(attrName, matchFlag, matchValue, depth);
+                       LogDebug("## 002 ##");                  
+                       LogDebug(">>> retBool:" << retBool);
+                       return retBool;
+               }
+
+               bool FolderFilterValidator::validateAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
+
+                       if(attrName.compare(FolderFilterValidatorFactory::ATTRIBUTE_ACCOUNTID)==0){
+                               LogDebug("<<< m_isAccountIdSetted :[" << m_isAccountIdSetted << "]");
+                               if(m_isAccountIdSetted == true){
+                                       LogError(">>> [ERROR] duplicated account :[" << attrName << "], value:[" <<
+                                                       value->toString()<< "]");
+                                       return false;
+                               }else{
+                                       m_isAccountIdSetted = true;
+                               }
+                       }
+
+                       if(m_attributeAndMatchFlagsMap.count(attrName) == 0)
+                       {
+                               MsgLogWanning(">>>[Waning] attrName is not supported:[" << attrName << "]");
+                               return false;                   
+                       }
+
+                       std::vector<std::string> vec = m_attributeAndMatchFlagsMap.find(attrName)->second;
+
+                       if(vectorContains(vec, matchFlag)==false){
+                               MsgLogWanning(">>>[Waning]MatchFlag check fail unsupported flag:[" << matchFlag << "] for Attribute:[" << attrName << "]");
+                               return false;
+                       }
+                       return true;
+               }
+
+       }
+       }
+
+}
diff --git a/src/platform/API/Messaging/FolderFilterValidator.h b/src/platform/API/Messaging/FolderFilterValidator.h
new file mode 100755 (executable)
index 0000000..9771aeb
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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 FOLDERFILTERVALIDATOR_H_
+#define FOLDERFILTERVALIDATOR_H_
+
+#include <API/Filter/FilterValidator.h>
+#include <vector>
+
+namespace TizenApis {
+
+       namespace Platform {
+
+               namespace Messaging {
+
+               class FolderFilterValidator: public Api::Tizen::FilterValidator {
+                       private:
+                               bool m_isAccountIdSetted;
+
+                               std::vector<std::string>  m_accountIdMatchFlagVec;
+                               std::vector<std::string>  m_folderPathMatchFlagVec;
+
+                               std::map<std::string, std::vector<std::string> > m_attributeAndMatchFlagsMap;
+
+                       public:
+                       FolderFilterValidator(Api::Tizen::PropertyStructArray properties);
+
+                               virtual ~FolderFilterValidator();
+
+                               // validate AttributeRangeFilter
+                                       virtual bool validateAttributeRange(std::string& attrName,
+                                                       Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0);
+
+                                       virtual bool validateAttribute(std::string& attrName,
+                                                       Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& matchValue, int depth=0);
+
+                               protected:
+                                               bool validateAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth);
+
+                               private :
+                                       void initMatchFlagVectors();
+                                       void initAttributeAndMatchFlagsMap();
+
+                                       bool vectorContains(std::vector<std::string>& vec, Api::Tizen::MatchFlag& value);
+
+               };
+
+               typedef DPL::SharedPtr<FolderFilterValidator> FolderFilterValidatorPtr;
+       }
+ }
+}
+#endif /* MESSAGEFILTERVALIDATOR_H_ */
diff --git a/src/platform/API/Messaging/FolderFilterValidatorFactory.cpp b/src/platform/API/Messaging/FolderFilterValidatorFactory.cpp
new file mode 100755 (executable)
index 0000000..79199e7
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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 "FolderFilterValidatorFactory.h"
+
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               const std::string FolderFilterValidatorFactory::ATTRIBUTE_ACCOUNTID               = "serviceId";
+               const std::string FolderFilterValidatorFactory::ATTRIBUTE_FOLDERPATH             = "path";
+
+                std::string FolderFilterValidatorFactory::MATCH_EXACTLY              = "EXACTLY";
+                std::string FolderFilterValidatorFactory::MATCH_CONTAINS             = "CONTAINS";
+                std::string FolderFilterValidatorFactory::MATCH_STARTSWITH           = "STARTSWITH";
+                std::string FolderFilterValidatorFactory::MATCH_ENDSWITH             = "ENDSWITH";
+               //TODO change to constant
+               static PropertyStructArray properties =
+               {
+                               {"serviceId",        Api::Tizen::PrimitiveType_String},
+                               {"path",             Api::Tizen::PrimitiveType_String},
+                               {0,                  Api::Tizen::PrimitiveType_NoType}
+               };
+
+               FolderFilterValidatorPtr FolderFilterValidatorFactory::getFolderFilterValidator()
+               {
+                   FolderFilterValidatorPtr theInstance =
+                               FolderFilterValidatorPtr(new FolderFilterValidator(properties));
+
+                   return theInstance;
+               }
+
+               }
+       }       //naspace Platform
+} //naspace WrtPlugins
diff --git a/src/platform/API/Messaging/FolderFilterValidatorFactory.h b/src/platform/API/Messaging/FolderFilterValidatorFactory.h
new file mode 100755 (executable)
index 0000000..c04b6c9
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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 FOLDERFILTERVALIDATORFACTORY_H_
+#define FOLDERFILTERVALIDATORFACTORY_H_
+
+#include <API/Filter/FilterValidator.h>
+#include "FolderFilterValidator.h"
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               class FolderFilterValidatorFactory {
+                       private:
+                               FolderFilterValidatorFactory()
+                               {
+                               }
+
+                       public:
+                               static FolderFilterValidatorPtr getFolderFilterValidator();
+
+                       public:
+                               static const std::string ATTRIBUTE_ACCOUNTID;
+                               static const std::string ATTRIBUTE_FOLDERPATH;
+
+                               static  std::string MATCH_EXACTLY;
+                               static  std::string MATCH_CONTAINS;
+                               static  std::string MATCH_STARTSWITH;
+                               static  std::string MATCH_ENDSWITH;
+                               static  std::string MATCH_CASESENSITIVE;
+               };
+
+               }
+       }               //Platform
+}
+
+#endif 
diff --git a/src/platform/API/Messaging/From.cpp b/src/platform/API/Messaging/From.cpp
new file mode 100755 (executable)
index 0000000..59b2e80
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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 "From.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+From::From() :
+    m_from(""),
+    m_validFrom(false)
+{
+}
+
+From::~From()
+{
+}
+
+void From::setFrom(const std::string& value)
+{
+    m_from = value;
+    m_validFrom = false;
+}
+
+std::string From::getFrom() const
+{
+    return m_from;
+}
+
+const std::string& From::getFromRef() const
+{
+    return m_from;
+}
+
+void From::setFromValidity(bool val)
+{
+    m_validFrom = val;
+}
+
+bool From::getFromValidity() const
+{
+    return m_validFrom;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/From.h b/src/platform/API/Messaging/From.h
new file mode 100755 (executable)
index 0000000..fc89826
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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 FROM_H
+#define FROM_H
+
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class From
+{
+  private: // fields
+
+    /**
+     * from value
+     */
+    std::string m_from;
+
+    /**
+     * information if abstract message from has been changed and need update
+     * in low level
+     */
+    bool m_validFrom;
+
+  public: // methods
+
+    From();
+
+    virtual ~From();
+
+    /**
+     * setter of from value
+     */
+    void setFrom(const std::string& value);
+
+    /**
+     * getter of from value
+     */
+    std::string getFrom() const;
+
+    const std::string& getFromRef() const;
+
+    void setFromValidity(bool val);
+
+    bool getFromValidity() const;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/IAttachment.cpp b/src/platform/API/Messaging/IAttachment.cpp
new file mode 100755 (executable)
index 0000000..9f71f0a
--- /dev/null
@@ -0,0 +1,240 @@
+//
+// 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 <dpl/log/log.h>
+#include <dpl/errno_string.h>
+#include <Commons/Exception.h>
+#include "IAttachment.h"
+
+extern "C" {
+#include <sys/stat.h>
+#include <stdlib.h>
+}
+
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+//--------------------------------------------------------------------------
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+IAttachment::IAttachment() :
+    m_validAttachment(false),
+    m_hasDummyFile(false),
+    m_attachmentID(-1)
+{
+}
+
+void IAttachment::init(const string& fullPath,
+        bool isVirtualPath)
+{
+       Try
+       {
+               struct stat buffer;
+               std::string l_fullPath;
+               LogDebug("FULL Path : " << fullPath);
+
+               if (isVirtualPath) {
+                       LogDebug("translating path");
+                       l_fullPath = getRealPath(fullPath);
+               } else {
+                       l_fullPath = fullPath;
+               }
+               LogDebug("real path " << l_fullPath);
+
+               char buff[PATH_MAX + 1];
+               if ((NULL == realpath(l_fullPath.c_str(), buff)) || (l_fullPath.size() > PATH_MAX + 1)) {
+                       std::string errnoString = DPL::GetErrnoString();
+                       LogError("get full path problem " << errnoString);
+                       m_fileSize = 0;
+                       m_attachFullPath = "";
+                       m_attachShortName = "";
+                       m_isCreatedProperly = true;
+                       m_validAttachment = false;
+               }
+               else
+               {
+                       if (-1 == lstat(buff, &buffer)) {
+                               LogError("Attachment file not exist");
+                               m_validAttachment = false;
+                       }
+
+                       if (!S_ISREG(buffer.st_mode)) {
+                               LogError("Attachment file not exist");
+                               m_validAttachment = false;
+                       }
+                       m_fileSize = buffer.st_size;
+                       m_attachFullPath = l_fullPath;
+                       makeShortName();
+                       m_isCreatedProperly = true;
+                       m_validAttachment = true;                       
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception) {
+               LogError("attachment not created properly");
+               m_isCreatedProperly = false;
+       }
+}
+
+IAttachment::~IAttachment()
+{
+    LogDebug("enter");
+}
+
+string IAttachment::getShortName() const
+{
+    return m_attachShortName;
+}
+
+string IAttachment::getFullPath() const
+{
+    return m_attachFullPath;
+}
+
+unsigned int IAttachment::getFileSize() const
+{
+    return m_fileSize;
+}
+
+std::string IAttachment::getMimeType() const
+{
+    return m_mimeType;
+}
+
+void IAttachment::setMimeType(const std::string &mimeType)
+{
+    m_mimeType = mimeType;
+}
+
+void IAttachment::setDummyFilePath(const std::string& dummyFilePath)
+{
+   m_dummyFilePath = dummyFilePath;
+
+   char buff[PATH_MAX + 1];
+   if ( NULL != realpath(m_dummyFilePath.c_str(), buff))
+   {
+       LogDebug("dummy File is valided " << m_dummyFilePath);
+       m_hasDummyFile = true;
+   }
+   else
+   {
+        std::string errnoString = DPL::GetErrnoString();
+        LogError("get full path problem " << errnoString);
+       m_hasDummyFile = false;
+   }
+   
+}
+
+std::string IAttachment::getDummyFilePath() const
+{
+       return m_dummyFilePath;
+}
+
+bool IAttachment::hasDummyFile() const
+{
+       return m_hasDummyFile;
+}
+
+
+#if 0
+//for security
+void IAttachment::setVirtualPath(const std::string& virtualPath)
+{
+       m_virtualPath = m_virtualPath;
+}
+
+std::string IAttachment::getVirtualPath()
+{
+       return m_virtualPath;
+}
+#endif
+
+Api::Messaging::IMessagePtr IAttachment::getMessage() const
+{
+       return m_message;
+}
+
+void IAttachment::setMessage(const Api::Messaging::IMessagePtr& message)
+{
+       m_message = message;
+}
+
+int IAttachment::getAttachmentID() const
+{
+       return m_attachmentID;
+}
+
+void IAttachment::setAttachmentID(int id)
+{
+       m_attachmentID = id;
+}
+
+bool IAttachment::getDownloaded() const
+{
+       return m_isDownloaded;
+}
+
+void IAttachment::setDownloaded(bool downloaded)
+{
+       m_isDownloaded = downloaded;
+}
+
+bool IAttachment::getIsInlineAttachment() const
+{
+       return m_isInlineAttachment;
+}
+
+void IAttachment::setIsInlineAttachment(bool isInlineAttachment)
+{
+       m_isInlineAttachment = isInlineAttachment;
+}
+
+
+bool IAttachment::getIsCreatedProperly() const
+{
+    return m_isCreatedProperly;
+}
+
+bool IAttachment::getIsValidAttachment() const
+{
+       LogError("m_validAttachment : " << m_validAttachment);
+       return m_validAttachment;
+}
+
+void IAttachment::rename(const string& newName)
+{
+    // path for attachment is still not changed
+    m_attachShortName = newName;
+    m_validAttachment = false;
+}
+
+void IAttachment::makeShortName()
+{
+    size_t pos;
+    // find position of last occurence of / sign (get only file name from all path
+    pos = m_attachFullPath.find_last_of("/");
+    if ((pos + 1) >= m_attachFullPath.size()) {
+        LogError("Problem with short name creation");
+        Throw(InvalidArgumentException);
+    }
+    m_attachShortName = m_attachFullPath.substr(pos + 1);
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/IAttachment.h b/src/platform/API/Messaging/IAttachment.h
new file mode 100755 (executable)
index 0000000..cee7d72
--- /dev/null
@@ -0,0 +1,176 @@
+//
+// 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 IATTACHMENT_H
+#define IATTACHMENT_H
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "IMessage.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class IAttachment;
+typedef DPL::SharedPtr<IAttachment> IAttachmentPtr;
+
+//--------------------------------------------------------------------------
+
+class IAttachment
+{
+  protected: // fields
+
+    /**
+     * value of attachment full path name
+     */
+    std::string m_attachFullPath;
+
+    /**
+     * value of attachment short name used to display in message
+     */
+    std::string m_attachShortName;
+
+    /**
+     * value of attachment file size
+     */
+    unsigned int m_fileSize;
+
+    /**
+     * value of attachment mime type
+     */
+    std::string m_mimeType;
+
+    /**
+    * The downloaded email file copy to a temporary folder (for security), the file in the temp Folder  is dummy File.
+    */
+    std::string m_dummyFilePath;
+
+    //std::string m_virtualPath;
+
+    /**
+     * information if abstract message attachment has been changed and need
+     * update in low level
+     * only name may be changed, not path
+     */
+    bool m_validAttachment;
+
+    bool m_isCreatedProperly;
+
+    bool m_isDownloaded;
+
+    bool m_hasDummyFile;       // If object have a dummy file, is deleted when it destroy;
+   
+    int m_attachmentID;                // attachment ID from email service.
+
+    bool m_isInlineAttachment;         // is inline attachment from email service.
+
+    int m_nth;                                 // attachment order index, 1 base.
+
+    IMessagePtr m_message;     //message ptr
+
+  public: // methods
+
+    explicit IAttachment();
+
+    void init(const std::string& fullPath,
+            bool isVirtualPath);
+
+    virtual ~IAttachment();
+
+    /**
+     * getter of attachment name (only name without path) value
+     */
+    std::string getShortName() const;
+
+    /**
+     * getter of attachment name (full path) value
+     */
+    std::string getFullPath() const;
+
+    /**
+     * getter of attachment size
+     */
+    unsigned int getFileSize() const;
+
+    /**
+     * getter of attachment mime type
+     */
+    std::string getMimeType() const;
+
+    /**
+     * setter of attachment mime type
+     */
+    void setMimeType(const std::string &mimeType);
+
+    Api::Messaging::IMessagePtr getMessage() const;
+       
+    void setMessage(const Api::Messaging::IMessagePtr& message);
+
+    /**
+     * getter of attachment valid
+     */
+    bool getIsCreatedProperly() const;
+
+    bool getIsValidAttachment() const;
+    /**
+     * rename short name value of attachment
+     */
+    void rename(const std::string& newName);
+
+    //void setVirtualPath(const std::string& virtualPath);
+               
+   // std::string getVirtualPath();
+       
+    void setAttachmentID(int id);
+       
+    int getAttachmentID() const;
+
+    void setDownloaded(bool downloaded);
+       
+    bool getDownloaded() const;
+
+    void setIsInlineAttachment(bool isInlineAttachment);
+       
+    bool getIsInlineAttachment() const;
+
+    void setDummyFilePath(const std::string& dummyFilePath);
+
+    std::string getDummyFilePath() const;      
+
+    bool hasDummyFile() const; 
+
+
+    int getNth()
+    {
+               return m_nth;
+    }
+       
+    void setNth(int nth)
+    {
+        m_nth = nth;
+    }
+  private:
+
+    void makeShortName();
+
+    virtual std::string getRealPath(const std::string &path) const = 0;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/IBinarySms.cpp b/src/platform/API/Messaging/IBinarySms.cpp
new file mode 100755 (executable)
index 0000000..2626d37
--- /dev/null
@@ -0,0 +1,37 @@
+//
+// 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 "IBinarySms.h"
+#include <dpl/log/log.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+IBinarySms::IBinarySms(const std::string& id) :
+    IMessage(BINARYSMS, id)
+{
+    LogDebug("enter");
+}
+
+IBinarySms::~IBinarySms()
+{
+    LogDebug("enter");
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/IBinarySms.h b/src/platform/API/Messaging/IBinarySms.h
new file mode 100755 (executable)
index 0000000..3b571a6
--- /dev/null
@@ -0,0 +1,47 @@
+//
+// 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 IBINARYSMS_H
+#define IBINARYSMS_H
+
+#include "IMessage.h"
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class IBinarySms;
+typedef DPL::SharedPtr<IBinarySms> IBinarySmsPtr;
+
+class IBinarySms :
+    virtual public IMessage
+{
+  public:     // fields
+
+  public:     // methods
+
+    explicit IBinarySms(const std::string& id = "");
+
+    virtual ~IBinarySms();
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/IConversation.h b/src/platform/API/Messaging/IConversation.h
new file mode 100755 (executable)
index 0000000..8880112
--- /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.
+//
+
+#ifndef ICONVERSATION_H
+#define ICONVERSATION_H
+
+#include <dpl/shared_ptr.h>
+#include <map>
+#include <string>
+#include <vector>
+#include <API/Messaging/IMessagingTypes.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class IConversation;
+typedef DPL::SharedPtr<IConversation> IConversationPtr;
+
+
+class IConversation
+{
+public:        
+       IConversation() {}
+    virtual ~IConversation() {};
+       // getter
+       virtual unsigned int getId() = 0;
+       virtual unsigned short getType() = 0;
+       virtual time_t getTime() = 0;
+       virtual unsigned long getMessageCount() = 0;
+       virtual unsigned long getUnreadMessages() = 0;
+       virtual std::string  getPreview() = 0;
+       virtual std::string getSubject() = 0;
+       virtual bool getRead() = 0;
+       virtual std::string getFrom() = 0;
+       virtual std::vector<std::string> getTo() = 0;
+       virtual std::vector<std::string> getCC() = 0;
+       virtual std::vector<std::string> getBCC() = 0;
+       virtual unsigned int getLastMessageId() = 0;
+       virtual bool getResult() = 0;
+
+       virtual void setId(const unsigned int id) = 0;
+
+#if 0
+private:
+       
+       // setter
+       virtual void setId(unsigned int id) = 0;
+       virtual void setType(unsigned short type) = 0;
+       virtual void setTime(time_t time) = 0;
+       virtual void setMessageCount(unsigned long messageCount) = 0;
+       virtual void setUnreadMessages(unsigned long unreadMessages) = 0;
+       virtual void setPreview(unsigned long unreadMessages) = 0;
+       virtual void setRead(bool read) = 0;
+       virtual void setFrom(std::string from) = 0;
+       virtual void setTo(std::vector<std::string> to) = 0;
+       virtual void setCC(std::vector<std::string> cc) = 0;
+       virtual void setBCC(std::vector<std::string> bcc) = 0;
+       virtual void setLastMessageId(unsigned int id) = 0;
+#endif 
+};
+}
+}
+}
+
+#endif
+
diff --git a/src/platform/API/Messaging/IEmail.cpp b/src/platform/API/Messaging/IEmail.cpp
new file mode 100755 (executable)
index 0000000..a934863
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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 "IEmail.h"
+#include <dpl/log/log.h>
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+IEmail::IEmail(const string& id) : IMessage(EMAIL, id)
+{
+    LogInfo("enter");
+}
+
+IEmail::~IEmail()
+{
+    LogInfo("enter");
+}
+
+IEmail & IEmail::operator <<(const VirtualMessage& msg)
+{
+    setBody(msg.getBodyRef());
+    setFolderType(msg.getCurrentFolder());
+    setCurrentUserFolder(msg.getCurrentUserFolder());
+    setFrom(msg.getFromRef());
+    setDateTime(msg.getDateTime());
+    setSourceAddress(msg.getSourceAddress());
+    setToRecipients(msg.getToRecipients());
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+    setAttachments(msg.getAttachments());
+#endif
+    setBccRecipients(msg.getBccRecipients());
+    setCcRecipients(msg.getCcRecipients());
+    setSubject(msg.getSubjectRef());
+
+    return *this;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/IEmail.h b/src/platform/API/Messaging/IEmail.h
new file mode 100755 (executable)
index 0000000..6fc7fc2
--- /dev/null
@@ -0,0 +1,94 @@
+//
+// 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 IEMAIL_H
+#define IEMAIL_H
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "VirtualMessage.h"
+#include "IMessage.h"
+#include "Subject.h"
+#include "ToRecipient.h"
+#include "CcRecipient.h"
+#include "BccRecipient.h"
+#include "Attachments.h"
+#include <API/Messaging/EmailAccountInfo.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class IEmail : virtual public IMessage,
+    public CcRecipient,
+    public BccRecipient,
+    public Attachments
+{
+  public:
+    explicit IEmail(const std::string& id = "");
+
+    virtual ~IEmail();
+
+    IEmail & operator <<(const VirtualMessage& msg);
+
+    void setHtmlBody(const std::string& htmlBody = "") 
+    {
+               m_htmlBody = htmlBody;
+    }
+
+    std::string getHtmlBody() const 
+    {
+               return m_htmlBody;
+    }
+       
+    void setEmailAccount(const EmailAccountInfo& account)
+    {
+               m_emailAccount = account;
+    }
+
+    EmailAccountInfo getEmailAccount()
+    {
+               return m_emailAccount;
+    }
+       
+    virtual int getAccountID() = 0;
+    virtual int getUID() = 0;
+    virtual int isBodyDownloaded() = 0;
+    
+    virtual int downloadBody() = 0;
+    virtual void downloadBodyCancel(int handle ) = 0;
+
+    virtual int downloadAttachment(const Api::Messaging::IAttachmentPtr& attachment) = 0;
+    virtual void downloadAttachmentCancel(int handle ) = 0;
+       
+    virtual bool hasAttachment() = 0;
+
+#if 0  
+    virtual void sync(int account_id);  
+    virtual void sync_folder(int account_id, int folder_id);
+#endif    
+  private:
+    std::string m_htmlBody;            //html body for Email.
+    EmailAccountInfo m_emailAccount;   
+};
+
+typedef DPL::SharedPtr<IEmail> IEmailPtr;
+}
+}
+}
+#endif // IEMAIL_H
+
diff --git a/src/platform/API/Messaging/IEmailAccount.cpp b/src/platform/API/Messaging/IEmailAccount.cpp
new file mode 100755 (executable)
index 0000000..097d9f6
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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 <Commons/Exception.h>
+#include "IEmailAccount.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+IEmailAccount::IEmailAccount() :
+    m_validAccount(false)
+{
+}
+
+IEmailAccount::~IEmailAccount()
+{
+}
+
+void IEmailAccount::setCurrentEmailAccount(const EmailAccountInfo& account)
+{
+       m_currentAccount = account;
+}
+
+EmailAccountInfo IEmailAccount::getCurrentEmailAccount() const
+{
+    return m_currentAccount;
+}
+
+bool IEmailAccount::isCurrentAccountValid() const
+{
+    return m_validAccount;
+}
+
+void IEmailAccount::setCurrentAccountValid(bool state)
+{
+    m_validAccount = state;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/IEmailAccount.h b/src/platform/API/Messaging/IEmailAccount.h
new file mode 100755 (executable)
index 0000000..d18714c
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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 IEMAILACCOUNT_H
+#define IEMAILACCOUNT_H
+
+#include <vector>
+#include "EmailAccountInfo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+       
+class IEmailAccount
+{
+  public:
+    IEmailAccount();
+
+    virtual ~IEmailAccount();
+
+    /**
+     * setter of current email account value
+     */
+    void setCurrentEmailAccount(const EmailAccountInfo& value);
+
+    /**
+     * getter of current email account value
+     */
+    EmailAccountInfo getCurrentEmailAccount() const;
+
+    /**
+     * check validity state
+     */
+    bool isCurrentAccountValid() const;
+
+    /**
+     * setter for validity state
+     */
+    void setCurrentAccountValid(bool state);
+
+  private:
+
+    /**
+     * abstract value of current email account
+     */
+     EmailAccountInfo m_currentAccount;
+       
+
+    /**
+     * information if abstract message current account has been changed
+     * and need update in low level
+     */
+    bool m_validAccount;
+};
+}
+}
+}
+#endif // IEMAILACCOUNT_H
diff --git a/src/platform/API/Messaging/IEmptyMessage.cpp b/src/platform/API/Messaging/IEmptyMessage.cpp
new file mode 100755 (executable)
index 0000000..f247d74
--- /dev/null
@@ -0,0 +1,40 @@
+//
+// 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 "IEmptyMessage.h"
+#include <dpl/log/log.h>
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+IEmptyMessage::IEmptyMessage(const string& id) :
+    IMessage(SMS, id)
+{
+    LogInfo("enter");
+}
+
+IEmptyMessage::~IEmptyMessage()
+{
+    LogInfo("enter");
+}
+
+}
+}
+}
diff --git a/src/platform/API/Messaging/IEmptyMessage.h b/src/platform/API/Messaging/IEmptyMessage.h
new file mode 100755 (executable)
index 0000000..beb9672
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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 IEMPTYMESSAGE_H
+#define IEMPTYMESSAGE_H
+
+#include "IMessage.h"
+//#include "CallbackNumber.h"
+#include "VirtualMessage.h"
+//#include "ValidityPeriodHours.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class IEmptyMessage;
+typedef DPL::SharedPtr<IEmptyMessage> IEmptyMessagePtr;
+
+class IEmptyMessage :
+    virtual public IMessage
+{
+  public: // fields
+
+  public: // methods
+
+    explicit IEmptyMessage(const std::string& id = "");
+
+    virtual ~IEmptyMessage();
+
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/IMessage.cpp b/src/platform/API/Messaging/IMessage.cpp
new file mode 100755 (executable)
index 0000000..53f9a24
--- /dev/null
@@ -0,0 +1,289 @@
+//
+// 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 <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "IMessage.h"
+#include "EventSendMessage.h"
+#include "EventMessagingService.h"
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+IMessage::IMessage(const MessageType msgType,
+        const string& id) :
+    m_id(id),
+    m_msgType(msgType),
+    m_readStatus(false),
+    m_validReadStatus(false),
+    m_isReadChangeStatus(false),
+    m_validisReadChangeStatus(true),    
+    m_folder(DRAFTBOX),
+    m_requestReceiver(NULL),
+    m_sendMessageEvent(NULL)
+{
+    LogDebug("message creation, msgId=" << m_id << ", msgType=" << m_msgType);
+
+    //initialize dateTime of message
+    time_t rawtime;
+    time(&rawtime);
+    tm* local = localtime(&rawtime);
+    if (local) {
+        m_dateTime = *local;
+    } else {
+        LogError("Failed to initialize message dateTime");
+    }
+}
+
+IMessage::~IMessage()
+{
+    LogDebug("destroying message, msgId=" << m_id << ", msgType=" << m_msgType);
+}
+
+string IMessage::getId() const
+{
+    return m_id;
+}
+
+const string& IMessage::getIdRef() const
+{
+    return m_id;
+}
+
+MessageType IMessage::getMessageType() const
+{
+    return m_msgType;
+}
+
+struct tm IMessage::getDateTime() const
+{
+    return m_dateTime;
+}
+
+string IMessage::convertId(int arg) const
+{
+    ostringstream stream;
+    stream << arg;
+    return stream.str();
+}
+
+int IMessage::convertId(const string& arg) const
+{
+    int retVal = 0;
+    istringstream(arg) >> retVal;
+    return retVal;
+}
+
+void IMessage::setId(const string& value)
+{
+    m_id = value;
+}
+
+void IMessage::setDateTime(const tm dateTime)
+{
+    m_dateTime = dateTime;
+}
+
+void IMessage::setReadStatus(bool state)
+{
+    m_validReadStatus = false;
+    m_readStatus = state;
+}
+
+void IMessage::setSize(int size)
+{
+    m_size = size;
+}
+
+int IMessage::getSize() const
+{
+    return m_size;
+}
+
+bool IMessage::isRead() const
+{
+    return m_readStatus;
+}
+
+bool IMessage::isReadStatusValid() const
+{
+    return m_validReadStatus;
+}
+
+void IMessage::setReadStatusValidity(bool valid)
+{
+    m_validReadStatus = valid;
+}
+
+bool IMessage::isReadChangeStatus() const
+{
+    return m_isReadChangeStatus;
+}
+
+void IMessage::setisReadChangeStatus(bool state)
+{
+    m_validisReadChangeStatus = false;
+    m_isReadChangeStatus = state;
+}
+
+bool IMessage::isReadChangeStatusValid() const
+{
+    return m_validisReadChangeStatus;
+}
+
+void IMessage::setisReadChangeStatusValidity(bool valid)
+{
+    m_validisReadChangeStatus = valid;
+}
+
+FolderType IMessage::getCurrentFolder() const
+{
+    return m_folder;
+}
+
+void IMessage::setFolderType(FolderType folder)
+{
+    m_folder = folder;
+}
+
+string IMessage::getCurrentUserFolder() const
+{
+    if (m_folder != USERDEFINED_FOLDER) {
+        LogError("folder is not user folder type");
+        Throw(WrtDeviceApis::Commons::UnknownException);
+    }
+    return m_userFolderName;
+}
+
+void IMessage::setCurrentUserFolder(const std::string& arg)
+{
+    m_userFolderName = arg;
+}
+
+bool IMessage::validatePhoneNumber(std::string& number)
+{
+    LogDebug("testing number=" << number);
+    return true;
+
+    pcrecpp::RE re("[^0-9#\\+\\*]?");
+    re.GlobalReplace("", &number);     //remove invailde phone number. phone Number were composed only number.
+    
+    if (number.empty()) {
+        LogError("wrong phoneNumber=" << number);
+        return false;
+    }
+    LogDebug("phoneNumber=" << number);
+
+    pcrecpp::RE re2("^[+#]?[0-9]{1,22}$");
+    if (re2.FullMatch(number)) {
+        LogDebug("vaildate Number=" << number);
+        return true;
+    }
+    else
+    {
+        LogDebug("invaildate Number=" << number);
+         return false;
+    }
+}
+
+bool IMessage::validateEmailAddr(const Recipients& addr)
+{
+    for (size_t i = 0; i < addr.getRecipientSize(); i++) {
+        if (false == validateEmailAddr(addr.getRecipient(i))) {
+            LogError("wrong email address");
+            return false;
+        }
+    }
+    return true;
+}
+
+bool IMessage::validateEmailAddr(const std::string& email)
+{
+    if (email.empty()) {
+        return false;
+    }
+    pcrecpp::RE re(
+        "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}"
+        "\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\"
+        ".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"
+        );
+    if (re.FullMatch(email)) {
+        LogDebug("emailAddress=" << email);
+        return true;
+    }
+    LogError("wrong emailAddress=" << email);
+    return false;
+}
+
+void IMessage::setEmitter(const EventOnSendingFailedEmitterPtr& emitter)
+{
+    m_emitter = emitter;
+}
+
+EventOnSendingFailedEmitterPtr IMessage::getEmitter() const
+{
+    return m_emitter;
+}
+
+void IMessage::setSendMessageEvent(const EventSendMessagePtr &event)
+{
+    m_sendMessageEvent = event;
+}
+
+EventSendMessagePtr IMessage::getSendMessageEvent() const
+{
+    return m_sendMessageEvent;
+}
+
+void IMessage::setMessagingServiceEvent(const EventMessagingServicePtr & event)
+{
+       m_messagingServiceEvent = event;
+}
+
+EventMessagingServicePtr IMessage::getMessagingServiceEvent() const
+{
+       return m_messagingServiceEvent;
+}
+
+void IMessage::setRequestReceiver(ReqReceiverMessage* reqReceiver)
+{
+    m_requestReceiver = reqReceiver;
+}
+
+ReqReceiverMessage* IMessage::getRequestReceiver() const
+{
+    return m_requestReceiver;
+}
+
+void IMessage::setMessageStatus( MessageStatus status)
+{
+       LogDebug("setMessageStatus : " << status);
+       m_msgStatus = status;
+}
+
+MessageStatus IMessage::getMessageStatus() const
+{
+       return m_msgStatus;
+}
+
+}
+}
+}
diff --git a/src/platform/API/Messaging/IMessage.h b/src/platform/API/Messaging/IMessage.h
new file mode 100755 (executable)
index 0000000..3b27aee
--- /dev/null
@@ -0,0 +1,388 @@
+//
+// 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 IMESSAGE_H
+#define IMESSAGE_H
+
+#include <string>
+#include <ctime>
+#include <dpl/shared_ptr.h>
+#include <dpl/enable_shared_from_this.h>
+#include "IMessagingTypes.h"
+#include "ToRecipient.h"
+#include "Body.h"
+#include "From.h"
+#include "SourceAddress.h"
+#include "MessagePriority.h"
+#include "CallbackNumber.h"
+#include "ValidityPeriodHours.h"
+#include "Subject.h"
+#include "EventOnSendingFailed.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class EventSendMessage;
+class EventMessagingService;
+typedef DPL::SharedPtr<EventSendMessage> EventSendMessagePtr;
+typedef DPL::SharedPtr<EventMessagingService> EventMessagingServicePtr;
+
+//--------------------------------------------------------------------------
+
+class IMessage;
+typedef DPL::SharedPtr<IMessage> IMessagePtr;
+
+//--------------------------------------------------------------------------
+
+class ReqReceiverMessage;
+
+//--------------------------------------------------------------------------
+
+class IMessage :
+    public DPL::EnableSharedFromThis<IMessage>,
+    public ToRecipient,
+    public Body,
+    public From,
+    public SourceAddress,
+    public MessagePriority,
+    public CallbackNumber,
+    public ValidityPeriodHours,
+    public Subject
+{
+  private: // fields
+
+    /**
+     * id of message
+     */
+    std::string m_id;
+
+    /**
+     * message type value
+     */
+    const MessageType m_msgType;
+
+    /**
+     * message status value
+     */
+    MessageStatus m_msgStatus;
+
+    /**
+     * Message creation date time
+     */
+    struct tm m_dateTime;
+
+    /**
+     * Message read status
+     */
+    bool m_readStatus;
+
+    /**
+     * Read status validity.
+     */
+    bool m_validReadStatus;
+
+    /**
+     * Message IsRead Change status
+     */
+    bool m_isReadChangeStatus;
+
+    /**
+     * Change IsRead Change status validity.
+     */
+    bool m_validisReadChangeStatus;
+
+    /**
+     * Message size in bytes
+     */
+    int m_size;
+
+    /**
+     * Message current folder
+     */
+    FolderType m_folder;
+
+    /**
+     * User folder name
+     */
+    std::string m_userFolderName;
+
+    /*
+     * Event emitter. Used when there is one global callback function
+     */
+    EventOnSendingFailedEmitterPtr m_emitter;
+
+    /*
+     * Request receiver. Used when there are callback funtions assigned at function executing scope
+     */
+    ReqReceiverMessage *m_requestReceiver;
+
+    /*
+     * SendMessage event. Used when there are callback funtions assigned at function executing scope
+     */
+    EventSendMessagePtr m_sendMessageEvent;
+
+     /*
+     * Messaging Service event. Used when there are callback funtions assigned at function executing scope
+     */
+   EventMessagingServicePtr m_messagingServiceEvent;
+
+  protected:
+    void setSize(int size);
+
+  public: // methods
+
+    /**
+     * constructor of abstraction message
+     * @param[in] msgType - type of message according to MessageType
+     * @param[in] id - id of message, if id is empty, new message will be
+     *                created, othercase message will be read from low
+     *                level message
+     */
+    explicit IMessage(const MessageType msgType,
+            const std::string& id = "");
+
+    virtual ~IMessage();
+
+    /**
+     * method is used to send message specyfied type
+     * @throw PlatformException Thrown when sending fail
+     */
+    virtual int send() = 0;
+
+    /**
+     * method is used to cancel sending message
+     * @throw PlatformException Thrown when sending fail
+     */
+    virtual void sendCancel(int handle) = 0;
+
+    /**
+     * method used to update all fields in lower level
+     * @param[in] draftsOnly - if true only draft messages can be
+     * fully updated. Other messages can only have read flag changed
+     * @throw PlatformException Thrown when update fail
+     */
+    virtual void update(bool draftsOnly = false) = 0;
+
+
+    /**
+     * method used to updateIsRead
+     * @throw PlatformException Thrown when updateIsRead fail
+     */
+    virtual void updateIsRead() = 0;
+
+
+    /**
+     * method used to updateMessage
+     * @throw PlatformException Thrown when updateMessage fail
+     */
+    virtual void updateMessage() = 0;
+
+
+    /**
+     * method used to addMessageToDraft
+     * @throw PlatformException Thrown when addMessageToDraft fail
+     */
+    virtual void addMessageToDraft() = 0;
+
+    /**
+     * method used to createSendMessage
+     * @throw PlatformException Thrown when createSendMessage fail
+     */
+    virtual void createSendMessage() = 0;      
+       
+
+    /**
+     * method used to read all data from low level message
+     * @throw PlatformException Thrown when reading message fail
+     */
+    virtual void readAllData() = 0;
+
+    /**
+     *  method used to get current storage folder
+     */
+    virtual FolderType getCurrentFolder() const;
+
+    /**
+     *  method used to get current user folder name
+     */
+    virtual std::string getCurrentUserFolder() const;
+
+    /**
+     *  method used to set current user folder name
+     */
+    void setCurrentUserFolder(const std::string& arg);
+
+    /**
+     * method used to move message to new folder
+     * @param[in] newFolder - destination folder
+     * @throw PlatformException Thrown when move message to folder fail
+     */
+    virtual void moveToFolder(const FolderType newFolder) = 0;
+
+    /**
+     * method used to move message to user defined new folder
+     * @param[in] newFolder - users destination folder
+     * @throw PlatformException Thrown when move message to folder fail
+     */
+    virtual void moveToFolder(const std::string& newFolder) = 0;
+
+    /**
+     * method used to copy message to new folder (create new message with
+     * new message id)
+     * @param[in] newFolder - destination folder
+     * @throw PlatformException Thrown when copy message to folder fail
+     */
+    virtual void copyToFolder(const FolderType newFolder) = 0;
+
+    /**
+     * method used to copy message to user defined new folder
+     * @param[in] newFolder - users destination folder
+     * @throw PlatformException Thrown when move message to folder fail
+     */
+    virtual void copyToFolder(const std::string& newFolder) = 0;
+
+    /**
+     * method used to identify message type
+     */
+    MessageType getMessageType() const;
+
+    /**
+     * method used to get message id
+     */
+    std::string getId() const;
+
+    /**
+     * method used to get message size
+     */
+    int getSize() const;
+
+    /**
+     * method used to get message id
+     */
+    virtual const std::string& getIdRef() const;
+
+    /**
+     * used for get tm struct
+     */
+    struct tm getDateTime() const;
+
+    /**
+     * Is message already been read
+     */
+    virtual bool isRead() const;
+
+    /**
+     * Is message already been read
+     */
+    virtual void setReadStatus(bool state);
+
+    /**
+     * Returns true if read status is valid
+     */
+    bool isReadStatusValid() const;
+
+    /**
+     * Sets read status validity
+     */
+    void setReadStatusValidity(bool valid);
+
+    bool isReadChangeStatus() const;
+       
+    void setisReadChangeStatus(bool state);
+       
+    bool isReadChangeStatusValid() const;
+       
+    void setisReadChangeStatusValidity(bool valid);
+       
+    void setMessageStatus( MessageStatus status);
+
+    MessageStatus getMessageStatus() const;
+
+    /**
+     *  Remove message
+     * @throw PlatformException Thrown when remove message fail
+     */
+    virtual void remove() = 0;
+
+    /**
+     * convert id from int to string
+     */
+    virtual std::string convertId(int arg) const;
+
+    /**
+     * convert id from string to int
+     */
+    virtual int convertId(const std::string& arg) const;
+
+    /**
+     * set message id
+     */
+    void setId(const std::string& id);
+
+    /**
+     * set date time
+     */
+    void setDateTime(const tm dateTime);
+
+    /**
+     * set current folder
+     */
+    virtual void setFolderType(FolderType folder);
+
+    /**
+     * validate phone number, if fail return false
+     * if number contains wrong characters, then cut them
+     */
+    bool validatePhoneNumber(std::string& number);
+
+    /**
+     * validate email address, if fail return false
+     */
+    bool validateEmailAddr(const Recipients& addr);
+
+    /**
+     * validate email address, if fail return false
+     */
+    bool validateEmailAddr(const std::string& email);
+
+    /*
+     * Sets event emitter
+     */
+    void setEmitter(const EventOnSendingFailedEmitterPtr& emitter);
+
+    /*
+     * Gets event emitter
+     */
+    EventOnSendingFailedEmitterPtr getEmitter() const;
+
+    void setSendMessageEvent(const EventSendMessagePtr &event);
+
+    EventSendMessagePtr getSendMessageEvent() const;
+
+    void setMessagingServiceEvent(const EventMessagingServicePtr &event);
+
+    EventMessagingServicePtr getMessagingServiceEvent() const;
+
+    void setRequestReceiver(ReqReceiverMessage* reqReceiver);
+
+    ReqReceiverMessage* getRequestReceiver() const;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/IMessageFolder.h b/src/platform/API/Messaging/IMessageFolder.h
new file mode 100755 (executable)
index 0000000..c035e38
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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 IMESSAGEFOLDER_H
+#define IMESSAGEFOLDER_H
+
+#include <dpl/shared_ptr.h>
+#include <map>
+#include <string>
+#include <vector>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class IMessageFolder;
+typedef DPL::SharedPtr<IMessageFolder> IMessageFolderPtr;
+
+class IMessageFolder
+{
+public:        
+       
+       IMessageFolder() {}
+    virtual ~IMessageFolder() {};
+
+       virtual void setName(std::string name)=0;
+       virtual void setSynchronizable(bool synchronizable)=0;
+       
+       virtual unsigned long getId()=0;
+       virtual unsigned long getParentId()=0;
+       virtual unsigned long getAccountId()=0;
+       virtual unsigned short getContentType()=0;
+       virtual std::string getName()=0;
+       virtual std::string getPath()=0;
+       virtual unsigned short getType()=0;
+       virtual bool getSynchronizable()=0;
+};
+}
+}
+}
+
+#endif
+
diff --git a/src/platform/API/Messaging/IMessaging.cpp b/src/platform/API/Messaging/IMessaging.cpp
new file mode 100755 (executable)
index 0000000..3194012
--- /dev/null
@@ -0,0 +1,37 @@
+//
+// 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 "IMessaging.h"
+#include <Messaging/Messaging.h>
+
+using namespace TizenApis::Platform::Messaging;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+IMessaging& IMessaging::getInstance()
+{
+    return TizenApis::Platform::Messaging::Messaging::getInstance();
+}
+
+IMessaging::~IMessaging()
+{
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/IMessaging.h b/src/platform/API/Messaging/IMessaging.h
new file mode 100755 (executable)
index 0000000..c876d9b
--- /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 IMESSAGING_H
+#define IMESSAGING_H
+
+#include <dpl/shared_ptr.h>
+#include "IMessagingTypes.h"
+#include "ISms.h"
+#include "IBinarySms.h"
+#include "IMms.h"
+#include "IEmail.h"
+#include "VirtualMessage.h"
+#include "MessageFactory.h"
+#include "IEmailAccount.h"
+#include "EmitterMessageReceived.h"
+#include "EmitterConversationReceived.h"
+#include "EmitterFolderReceived.h"
+#include "IConversation.h"
+#include "IMessageFolder.h"
+#include <API/Filter/IFilter.h>
+#include <API/Filter/SortMode.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class IMessaging : private DPL::Noncopyable,
+    public IEmailAccount
+{
+  public:
+    static IMessaging& getInstance();
+
+  public:
+    virtual ~IMessaging() = 0;
+
+/*
+    virtual void getNumberOfMessages(MessageType msgType,
+            FolderType folder,
+            int* readed,
+            int* unReaded) = 0;
+
+    virtual std::vector<IMessagePtr> findMessages(
+            const std::vector<MessageType>& msgTypes,
+            FolderType folder,
+//            const Api::Messaging::MessageFilterPtr& filter) = 0;
+            const Api::Tizen::FilterPtr& filter) = 0;
+
+    virtual std::vector<IMessagePtr> findMessages(
+            const std::vector<MessageType>& msgTypes,
+            const std::string &folder,
+//            const Api::Messaging::MessageFilterPtr& filter) = 0;
+            const Api::Tizen::FilterPtr& filter) = 0;
+
+       virtual std::vector<IMessagePtr> findMessages(const Api::Tizen::FilterPtr& filter,
+               const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset) = 0;
+*/
+       virtual std::vector<IMessagePtr> findMessages(const Api::Tizen::FilterPtr& filter,
+               const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset, const int type) = 0;      
+       
+//     virtual std::vector<IMessagePtr> findMessages(const Api::Tizen::FilterPtr& filter) = 0;
+
+//    virtual std::vector<std::string> getMessageIds(MessageType msgType,
+//            FolderType folder) = 0;
+
+    virtual void createFolder(MessageType msgType,
+            const std::string& userFolder) = 0;
+
+    virtual void deleteFolder(MessageType msgType,
+            const std::string& userFolder) = 0;
+
+    virtual std::vector<std::string> getFolderNames(MessageType msgType) = 0;
+
+    virtual void addOnMessageReceived(const EmitterMessageReceivedPtr& emitter, const Api::Tizen::FilterPtr& filter, const int funtionIndex)
+        = 0;
+    virtual void addOnMessageReceived(const EmitterConversationReceivedPtr& emitter, const Api::Tizen::FilterPtr& filter, const int funtionIndex)
+        = 0;
+    virtual void addOnMessageReceived(const EmitterFolderReceivedPtr& emitter, const Api::Tizen::FilterPtr& filter, const int funtionIndex)
+        = 0;
+
+    virtual void removeOnMessageMsgReceived(EmitterMessageReceived::IdType id) = 0;
+
+    virtual void removeOnMessageConvReceived(EmitterConversationReceived::IdType id) = 0;
+
+    virtual void removeOnMessageFolderReceived(EmitterFolderReceived::IdType id) = 0;
+
+       virtual int getConversationId(const int& msgId, const MessageType &msgtype) = 0;
+
+//     virtual std::vector<IConversationPtr> queryConversations(const Api::Tizen::SortModePtr& sortMode, const Api::Tizen::FilterPtr& filter, long limit=0, long offset=0) = 0;
+       virtual std::vector<IConversationPtr> queryConversations(const Api::Tizen::FilterPtr& filter, const Api::Tizen::SortModePtr& sortMode, int type, long limit=0, long offset=0)= 0;
+//     virtual bool deleteConversations(const Api::Tizen::SortModePtr& sortMode, const Api::Tizen::FilterPtr& filter) = 0;
+       virtual bool deleteConversations(const std::vector<IConversationPtr>& conversations) = 0;
+       virtual std::vector<IMessageFolderPtr> queryFolders(const Api::Tizen::FilterPtr& filter) = 0;
+       
+
+    virtual void fetchEmailHeaders() = 0;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/IMessagingService.cpp b/src/platform/API/Messaging/IMessagingService.cpp
new file mode 100755 (executable)
index 0000000..bc28a78
--- /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.
+//\r
+\r
+#include "IMessagingService.h"
+#include "EventGetMessagingService.h"
+#include "EventMessagingService.h"\r
+\r
+using namespace TizenApis::Api::Messaging;\r
+using namespace WrtDeviceApis::Commons;\r
+\r
+namespace TizenApis {\r
+namespace Api {\r
+namespace Messaging{\r
+\r
+IMessagingService::IMessagingService() :\r
+         m_messagingServiceType(-1)\r
+{\r
+       LogDebug("create  IMessagingService");\r
+}\r
+\r
+IMessagingService::~IMessagingService()\r
+{\r
+       LogDebug("destory  IMessagingService");\r
+}\r
+
+void IMessagingService::setMessagingServiceEvent(const EventMessagingServicePtr &event)
+{
+               m_messagingServiceEvent = event;
+}
+
+EventMessagingServicePtr IMessagingService::getMessagingServiceEvent() const
+{
+       return m_messagingServiceEvent;
+}
+
+void IMessagingService::OnCancelEvent(const EventMessagingServicePtr &event)\r
+{\r
+       LogDebug("<<<<<<<<<<<<<<<<< OnCancelEvent >>>>>>>>>>>>>>>>>>>>>> " );\r
+       LogDebug(" OpID " << event->opId);\r
+       LogDebug(" Handle " << event->getHandle());\r
+       LogDebug(" event Type " << event->getEventType());\r
+       cancelOperation(event->opId, event->getHandle(), event->getEventType(), event->m_message);\r
+       return;\r
+}\r
+\r
+}\r
+}\r
+}\r
+\r
+\r
+\r
diff --git a/src/platform/API/Messaging/IMessagingService.h b/src/platform/API/Messaging/IMessagingService.h
new file mode 100755 (executable)
index 0000000..546fb87
--- /dev/null
@@ -0,0 +1,174 @@
+//
+// 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_API_IMESSAGING_SERVICE_H_
+#define WRTPLUGINS_API_IMESSAGING_SERVICE_H_
+
+#include <dpl/log/log.h>
+#include "IMessagingTypes.h"
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include <API/Messaging/IEmailAccount.h>
+#include <API/Messaging/IMessageFolder.h>
+#include <API/Messaging/IMessage.h>
+#include <Commons/EventReceiver.h>
+#include <Commons/IExternEventCanceler.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+enum MessagingServiceOpType
+{
+       MESSAGING_SERVICE_OP_SEND_MESSAGE = 0,
+       MESSAGING_SERVICE_OP_DOWNLOAD_BODY,
+       MESSAGING_SERVICE_OP_DOWNLOAD_ATTACHMENT,
+       MESSAGING_SERVICE_OP_SYNC,
+       MESSAGING_SERVICE_OP_SYNC_FOLDER,
+       MESSAGING_SERVICE_OP_COUNT,
+};
+
+class ReqReceiverMessage;
+class IMessagingService;
+
+typedef DPL::SharedPtr<IMessagingService> IMessagingServicePtr;
+
+class IMessagingService:
+       public WrtDeviceApis::Commons::IExternEventCanceler< EventMessagingService >,
+       public IEmailAccount
+{
+public:
+       virtual  ~IMessagingService();
+
+//     /**
+//      * Gets a service of messaging
+//      * @param event @see TizenApis::Api::PluginTemplete::EventGetMessagingService
+//      * @exception WrtDeviceApis::Commons::PlatformException when platform error occurs
+//      */
+
+       int getAccountID() const
+       {       
+               if ( m_messagingServiceType == Api::Messaging::EMAIL)
+               {
+                       return getCurrentEmailAccount().getIntId();
+               }
+               else if(m_messagingServiceType == Api::Messaging::SMS)
+               {
+                       return m_messagingServiceId;
+               }
+               else if(m_messagingServiceType == Api::Messaging::MMS)
+               {
+                       return m_messagingServiceId;
+               }
+               else 
+               {
+                       return -1;              //default is -1
+               }
+       }
+       
+       int getType() const
+       {
+               return m_messagingServiceType;
+       }
+       
+       std::string getName() const
+       {       
+               if ( m_messagingServiceType == Api::Messaging::EMAIL)
+               {
+                       return getCurrentEmailAccount().getName();
+               }
+               else
+               {
+                       return m_messagingServiceName;
+               }
+       }
+               
+       virtual int createOpId(int type) = 0;
+       virtual int getHandleFromOpId(int opId) = 0;
+       virtual int getOpTypeFromOpId(int opId) = 0;
+       virtual Api::Messaging::IMessagePtr getMessageFromOpId(int opId) = 0;
+       virtual Api::Messaging::EventMessagingServicePtr getEventFromOpId(int opId) = 0;
+       virtual void setHandleToOpId(int opId, int handle) = 0;
+       virtual void setMessageToOpId(int opId, Api::Messaging::IMessagePtr& message) = 0;
+       virtual void setEventToOpId(int opId, EventMessagingServicePtr &event) = 0;
+       virtual int deleteOpId(int opId)=0;
+                                       
+       virtual int sync(const Api::Messaging::IMessagingServicePtr& messagingService, const int limit) = 0;
+       virtual void syncCancel(int handle) = 0;
+       virtual int syncFolder(const Api::Messaging::IMessagingServicePtr& messagingService, const int folder_id, const int limit) = 0;
+       virtual void syncFolderCancel(int handle) = 0;
+
+       virtual void cancelOperation(int opId, int handle, int eventType, Api::Messaging::IMessagePtr& message) = 0;
+       
+    void OnCancelEvent(const EventMessagingServicePtr &event);
+    void setMessagingServiceEvent(const EventMessagingServicePtr &event);
+    EventMessagingServicePtr getMessagingServiceEvent() const;
+
+    void setRequestReceiver(ReqReceiverMessage* reqReceiver)
+    {
+               m_requestReceiver = reqReceiver;
+    }
+
+    ReqReceiverMessage* getRequestReceiver() const
+    {
+               return m_requestReceiver;
+    }
+
+private: 
+        short m_messagingServiceType;          //type
+        std::string m_messagingServiceName;
+        int m_messagingServiceId;
+        /*
+         * Request receiver. Used when there are callback funtions assigned at function executing scope
+         */
+        ReqReceiverMessage *m_requestReceiver;
+        
+        /*
+         * Messaging Service event. Used when there are callback funtions assigned at function executing scope
+        */
+        EventMessagingServicePtr m_messagingServiceEvent;
+         
+protected:
+       IMessagingService();
+       
+       void setType(int type)
+       {
+               m_messagingServiceType = type;
+       }
+
+       void setName(const std::string& name = "" )
+       {
+               m_messagingServiceName = name;
+       }
+
+       void setId(int serviceId)
+       {
+               m_messagingServiceId = serviceId;
+       }
+
+};
+
+}
+}
+}
+
+#endif //WRTPLUGINS_API_IMESSAGING_SERVICE_H_
+
+
+
diff --git a/src/platform/API/Messaging/IMessagingServiceManager.cpp b/src/platform/API/Messaging/IMessagingServiceManager.cpp
new file mode 100755 (executable)
index 0000000..bc0739d
--- /dev/null
@@ -0,0 +1,38 @@
+//
+// 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 "IMessagingServiceManager.h"
+
+using namespace TizenApis::Api::Messaging;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging{
+
+IMessagingServiceManager::IMessagingServiceManager() :
+        EventRequestReceiver<EventGetMessagingService>(ThreadEnum::MESSAGING_THREAD)
+{
+}
+
+IMessagingServiceManager::~IMessagingServiceManager()
+{
+}
+
+}
+}
+}
diff --git a/src/platform/API/Messaging/IMessagingServiceManager.h b/src/platform/API/Messaging/IMessagingServiceManager.h
new file mode 100755 (executable)
index 0000000..2469633
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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_API_IMESSAGING_SERVICE_MANAGER_H_
+#define WRTPLUGINS_API_IMESSAGING_SERVICE_MANAGER_H_
+
+#include <vector>
+#include <dpl/log/log.h>
+
+#include "IMessagingTypes.h"
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+
+#include <API/Messaging/EventGetMessagingService.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//class EventGetMessagingService;
+//typedef DPL::SharedPtr<EventGetMessagingService> EventGetMessagingServicePtr;
+
+class IMessagingServiceManager: 
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventGetMessagingService> 
+{
+public:
+       virtual  ~IMessagingServiceManager();
+
+//     /**
+//      * Gets a service of messaging
+//      * @param event @see TizenApis::Api::PluginTemplete::EventGetMessagingService
+//      * @exception WrtDeviceApis::Commons::PlatformException when platform error occurs
+//      */
+       virtual void getMessagingServiceManager (const EventGetMessagingServicePtr& event) = 0;
+
+protected:
+       std::vector< IMessagingServicePtr > m_messagingServices;                //service list vector.
+       IMessagingServiceManager();
+
+       virtual void OnRequestReceived(const EventGetMessagingServicePtr& event) = 0;
+};
+
+typedef DPL::SharedPtr<IMessagingServiceManager> IMessagingServiceManagerPtr;
+
+}
+}
+}
+
+#endif /* WRTPLUGINS_API_IMESSAGING_SERVICE_MANAGER_H_ */
diff --git a/src/platform/API/Messaging/IMessagingTypes.h b/src/platform/API/Messaging/IMessagingTypes.h
new file mode 100755 (executable)
index 0000000..5470b81
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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 IMESSAGINGTYPES_H
+#define IMESSAGINGTYPES_H
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+#define NAME_SMS_TYPE          "SMS"
+#define NAME_MMS_TYPE  "MMS"
+#define NAME_EMAIL_TYPE        "EMAIL"
+#define NAME_CHAT_TYPE         "CHAT"
+
+enum MessageType
+{
+       UNKNOWN = 0,
+       SMS = 1,
+       MMS,
+       EMAIL,
+       CHAT,
+       BINARYSMS,
+       VIRTUAL_MESSAGE,
+       EMPTY_MESSAGE,
+       MESSAGETYPE_COUNT
+};
+
+enum MessageStatus
+{
+       MESSAGE_STATUS_CREATED = 0,
+       MESSAGE_STATUS_DRAFT,
+       MESSAGE_STATUS_SENDING ,
+       MESSAGE_STATUS_SENT,
+       MESSAGE_STATUS_LOADED,
+       MESSAGE_STATUS_FAILED
+};
+
+//--------------------------------------------------------------------------
+
+enum FolderType
+{
+    TEMP_FOLDER =0,
+    INBOX = 1,
+    OUTBOX = 2,
+    DRAFTBOX = 3,
+    SENTBOX =4,
+    TRASHBOX,
+    SPAMBOX,
+    SEARCHED,
+    ALL_FOLDERS,
+    FLAGED,
+    USERDEFINED_FOLDER,
+    FOLDERTYPE_COUNT
+};
+
+//--------------------------------------------------------------------------
+
+enum AddressType
+{
+    TO_ADDRESS,
+    CC_ADDRESS,
+    BCC_ADDRESS,
+    ADDRESS_COUNT
+};
+
+enum MessageServiceAccountId
+{
+       UNKNOWN_ACCOUNT_ID = 0,
+       SMS_ACCOUNT_ID = 101,
+       MMS_ACCOUNT_ID = 102,
+       MESSAGE_ACCOUNT_COUNT
+};
+
+
+}
+}
+}
+#endif
+
diff --git a/src/platform/API/Messaging/IMms.cpp b/src/platform/API/Messaging/IMms.cpp
new file mode 100755 (executable)
index 0000000..8e5d16e
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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 "IMms.h"
+#include "ValidityPeriodHours.h"
+#include <dpl/log/log.h>
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+IMms::IMms(const string& id) :
+    IMessage(MMS, id),
+    m_mmsType(MULTIPART_MIXED)
+{
+    LogInfo("enter");
+}
+
+IMms::~IMms()
+{
+    LogInfo("enter");
+}
+
+IMms::MMSType IMms::getMmsType() const
+{
+    return m_mmsType;
+}
+
+void IMms::setMmsType(MMSType type)
+{
+    m_mmsType = type;
+}
+
+IMms & IMms::operator <<(const VirtualMessage& msg)
+{
+    setBody(msg.getBodyRef());
+    setFolderType(msg.getCurrentFolder());
+    setCurrentUserFolder(msg.getCurrentUserFolder());
+    setFrom(msg.getFromRef());
+    setDateTime(msg.getDateTime());
+    setSourceAddress(msg.getSourceAddress());
+    setToRecipients(msg.getToRecipients());
+    setValidityPeriodHours(msg.getValidityPeriodHours());
+
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+    setAttachments(msg.getAttachments());
+#endif
+    setBccRecipients(msg.getBccRecipients());
+    setCcRecipients(msg.getCcRecipients());
+    setSubject(msg.getSubjectRef());
+
+    return *this;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/IMms.h b/src/platform/API/Messaging/IMms.h
new file mode 100755 (executable)
index 0000000..e47d7de
--- /dev/null
@@ -0,0 +1,80 @@
+//
+// 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 IMMS_H
+#define IMMS_H
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "VirtualMessage.h"
+#include "IMessage.h"
+#include "Subject.h"
+#include "ToRecipient.h"
+#include "CcRecipient.h"
+#include "BccRecipient.h"
+#include "Attachments.h"
+#include "IMmsSlides.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class IMms;
+typedef DPL::SharedPtr<IMms> IMmsPtr;
+
+class IMms :
+    virtual public IMessage,
+    virtual public IMmsSlides,
+    public CcRecipient,
+    public BccRecipient,
+    public Attachments
+{
+  public:   // fields
+
+    enum MMSType
+    {
+        MULTIPART_MIXED   = 0,
+        MULTIPART_RELATED = 1
+    };
+
+  public:   // methods
+
+    explicit IMms(const std::string& id = "");
+
+    virtual ~IMms();
+
+    /**
+     *  geter for mms type
+     * */
+    virtual MMSType getMmsType() const;
+
+    /**
+     *  seter for mms type
+     * */
+    virtual void setMmsType(MMSType type);
+
+    IMms & operator <<(const VirtualMessage& msg);
+
+    virtual bool hasAttachment()=0;
+
+  private:
+    MMSType m_mmsType;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/IMmsSlide.h b/src/platform/API/Messaging/IMmsSlide.h
new file mode 100755 (executable)
index 0000000..936c22b
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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 IMMSSLIDE_H
+#define IMMSSLIDE_H
+
+#include <dpl/shared_ptr.h>
+
+#include "IMmsSlideProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class IMmsSlide;
+typedef DPL::SharedPtr<IMmsSlide> IMmsSlidePtr;
+
+class IMmsSlide :
+    public IMmsSlidePropertyImage,
+    public IMmsSlidePropertyAudio,
+    public IMmsSlidePropertyText,
+    public IMmsSlidePropertyVideo
+{
+  public:
+    typedef unsigned long Ulong;
+
+  public:   // methods
+
+    virtual ~IMmsSlide()
+    {
+    }
+
+    /**
+     * Get duration
+     */
+    virtual Ulong getDuration() const = 0;
+
+    /**
+     * Set duration
+     * @param[in] - value in miliseconds
+     */
+    virtual void setDuration(Ulong duration) = 0;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/IMmsSlideProperties.h b/src/platform/API/Messaging/IMmsSlideProperties.h
new file mode 100755 (executable)
index 0000000..6de63b0
--- /dev/null
@@ -0,0 +1,239 @@
+//
+// 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 IMMS_SLIDE_PROPERTIES_H
+#define IMMS_SLIDE_PROPERTIES_H
+
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class IMmsSlidePropertyImage
+{
+  public:
+    typedef unsigned long Ulong;
+
+  public:
+
+    virtual ~IMmsSlidePropertyImage()
+    {
+    }
+
+    /**
+     * get image filename
+     * */
+    virtual const std::string& getImageFilename() const = 0;
+
+    /**
+     * get image filename
+     * @param[in] picture filename
+     * @throw MMS_MESSAGE_SIZE_EXCEEDED_ERROR
+     * @throw MMS_VIDEO_SLIDE_ERROR
+     * */
+    virtual void setImageFilename(const std::string& filename) = 0;
+
+    /**
+     * get imageBegin
+     * begining of image presentation within a slide in milisecond
+     * */
+    virtual Ulong getImageBegin() const = 0;
+
+    /**
+     * set imageBegin;
+     * begining of image presentation within a slide in milisecond
+     * @param[in] - value in miliseconds
+     * */
+    virtual void setImageBegin(Ulong value) = 0;
+
+    /**
+     * get imageEnd
+     * end of image presentation within a slide in milisecond
+     * */
+    virtual Ulong getImageEnd() const = 0;
+
+    /**
+     * set imageBegin;
+     * end of image presentation within a slide in milisecond
+     * @param[in] - value in miliseconds
+     * */
+    virtual void setImageEnd(Ulong value) = 0;
+};
+
+//--------------------------------------------------------------------------
+
+class IMmsSlidePropertyAudio
+{
+  public:
+    typedef unsigned long Ulong;
+
+  public:
+
+    virtual ~IMmsSlidePropertyAudio()
+    {
+    }
+
+    /**
+     * get audio filename
+     * */
+    virtual const std::string& getAudioFilename() const = 0;
+
+    /**
+     * get audio filename
+     * @param[in] audio filename
+     * @throw MMS_MESSAGE_SIZE_EXCEEDED_ERROR
+     * @throw MMS_VIDEO_SLIDE_ERROR
+     * */
+    virtual void setAudioFilename(const std::string& filename) = 0;
+
+    /**
+     * get audio begin
+     * begining of image presentation within a slide in milisecond
+     * */
+    virtual Ulong getAudioBegin() const = 0;
+
+    /**
+     * set audio begin;
+     * begining of audio presentation within a slide in milisecond
+     * @param[in] - value in miliseconds
+     * */
+    virtual void setAudioBegin(Ulong value) = 0;
+
+    /**
+     * get audioEnd
+     * end of audio presentation within a slide in milisecond
+     * */
+    virtual Ulong getAudioEnd() const = 0;
+
+    /**
+     * set audioEnd;
+     * end of audio presentation within a slide in milisecond
+     * @param[in] - value in miliseconds
+     * */
+    virtual void setAudioEnd(Ulong value) = 0;
+};
+
+//--------------------------------------------------------------------------
+
+class IMmsSlidePropertyText
+{
+  public:
+    typedef unsigned long Ulong;
+
+  public:
+
+    virtual ~IMmsSlidePropertyText()
+    {
+    }
+
+    /**
+     * get text filename
+     * */
+    virtual const std::string& getTextFilename() const = 0;
+
+    /**
+     * get text filename
+     * @param[in] text filename
+     * @throw MMS_MESSAGE_SIZE_EXCEEDED_ERROR
+     * @throw MMS_VIDEO_SLIDE_ERROR
+     * */
+    virtual void setTextFilename(const std::string& filename) = 0;
+
+    /**
+     * get text begin
+     * begining of text presentation within a slide in milisecond
+     * */
+    virtual Ulong getTextBegin() const = 0;
+
+    /**
+     * set text begin;
+     * begining of text presentation within a slide in milisecond
+     * @param[in] - value in miliseconds
+     * */
+    virtual void setTextBegin(Ulong value) = 0;
+
+    /**
+     * get textEnd
+     * end of text presentation within a slide in milisecond
+     * */
+    virtual Ulong getTextEnd() const = 0;
+
+    /**
+     * set textEnd;
+     * end of text presentation within a slide in milisecond
+     * @param[in] - value in miliseconds
+     * */
+    virtual void setTextEnd(Ulong value) = 0;
+};
+
+//--------------------------------------------------------------------------
+
+class IMmsSlidePropertyVideo
+{
+  public:
+    typedef unsigned long Ulong;
+
+  public:
+
+    virtual ~IMmsSlidePropertyVideo()
+    {
+    }
+
+    /**
+     * get video filename
+     * */
+    virtual const std::string& getVideoFilename() const = 0;
+
+    /**
+     * get video filename
+     * @param[in] vdeo filename
+     * @throw MMS_MESSAGE_SIZE_EXCEEDED_ERROR
+     * @throw MMS_VIDEO_SLIDE_ERROR
+     * */
+    virtual void setVideoFilename(const std::string& filename) = 0;
+
+    /**
+     * get video begin
+     * begining of video presentation within a slide in milisecond
+     * */
+    virtual Ulong getVideoBegin() const = 0;
+
+    /**
+     * set video begin;
+     * begining of video presentation within a slide in milisecond
+     * @param[in] - value in miliseconds
+     * */
+    virtual void setVideoBegin(Ulong value) = 0;
+
+    /**
+     * get videoEnd
+     * end of video presentation within a slide in milisecond
+     * */
+    virtual Ulong getVideoEnd() const = 0;
+
+    /**
+     * set videoEnd;
+     * end of video presentation within a slide in milisecond
+     * @param[in] - value in miliseconds
+     * */
+    virtual void setVideoEnd(Ulong value) = 0;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/IMmsSlides.h b/src/platform/API/Messaging/IMmsSlides.h
new file mode 100755 (executable)
index 0000000..d7a7ee7
--- /dev/null
@@ -0,0 +1,103 @@
+//
+// 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 IMMS_SLIDES_H
+#define IMMS_SLIDES_H
+
+#include <vector>
+
+#include "IMmsSlide.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class IMmsSlides
+{
+  public:
+
+    virtual ~IMmsSlides()
+    {
+    }
+
+    /**
+     * create empty slide
+     * @return shared pointer to created IMmsSlide
+     * */
+    virtual IMmsSlidePtr createEmptySlide() const = 0;
+
+    /**
+     * check data validity
+     * @return true if slides are valid
+     *      or false if one or more slide need update
+     * */
+    virtual bool checkSlidesValidity() const = 0;
+
+    /**
+     * set data validity
+     * */
+    virtual void setSlidesValidity(bool state) = 0;
+
+    /**
+     * set slides
+     * */
+    virtual void setSlides(const std::vector<IMmsSlidePtr>& slides) = 0;
+
+    /**
+     * add slide to mms object
+     * */
+    virtual void addSlide(const IMmsSlidePtr& slide) = 0;
+
+    /**
+     * get slide count
+     * @return number of slides in mms
+     * */
+    virtual size_t getSlideCount() const = 0;
+
+    /**
+     * get slide by number
+     * @return shared pointer to IMmsSlide
+     * @throw INVALID_ARGUMENT_EXCEPTION
+     * if argument is wrong
+     * */
+    virtual IMmsSlidePtr getSlide(size_t nb) const = 0;
+
+    /**
+     * get slides
+     * @return vector of slides from Mms
+     * */
+    virtual std::vector<IMmsSlidePtr> getSlides() const = 0;
+
+    /**
+     * replace slide
+     * @throw INVALID_ARGUMENT_EXCEPTION
+     * if argument is wrong
+     * */
+    virtual void replaceSlide(size_t pos,
+            const IMmsSlidePtr& slide) = 0;
+
+    /**
+     * remove slide
+     * @throw INVALID_ARGUMENT_EXCEPTION
+     * if argument is wrong
+     * */
+    virtual void removeSlide(size_t pos) = 0;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/ISms.cpp b/src/platform/API/Messaging/ISms.cpp
new file mode 100755 (executable)
index 0000000..4ceecc9
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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 "ISms.h"
+#include <dpl/log/log.h>
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+ISms::ISms(const string& id) :
+    IMessage(SMS, id)
+{
+    LogInfo("enter");
+}
+
+ISms::~ISms()
+{
+    LogInfo("enter");
+}
+
+ISms & ISms::operator <<(const VirtualMessage& msg)
+{
+    setBody(msg.getBodyRef());
+    setFolderType(msg.getCurrentFolder());
+    setCurrentUserFolder(msg.getCurrentUserFolder());
+    setFrom(msg.getFromRef());
+    setDateTime(msg.getDateTime());
+    setSourceAddress(msg.getSourceAddress());
+    setToRecipients(msg.getToRecipients());
+    setCallbackNumber(getCallbackNumberRef());
+    setValidityPeriodHours(msg.getValidityPeriodHours());
+
+    return *this;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/ISms.h b/src/platform/API/Messaging/ISms.h
new file mode 100755 (executable)
index 0000000..f791a0d
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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 ISMS_H
+#define ISMS_H
+
+#include "IMessage.h"
+#include "CallbackNumber.h"
+#include "VirtualMessage.h"
+#include "ValidityPeriodHours.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class ISms;
+typedef DPL::SharedPtr<ISms> ISmsPtr;
+
+class ISms :
+    virtual public IMessage
+{
+  public: // fields
+
+  public: // methods
+
+    explicit ISms(const std::string& id = "");
+
+    virtual ~ISms();
+
+    ISms & operator <<(const VirtualMessage& msg);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/MessageEventPrivateData.h b/src/platform/API/Messaging/MessageEventPrivateData.h
new file mode 100755 (executable)
index 0000000..1bcb993
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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 MESSAGEEVENTPRIVATEDATA_H_
+#define MESSAGEEVENTPRIVATEDATA_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "IMessage.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+/*
+ * I cannot put IMessagePtr directly in EventOnSendingFailed because the IMessage contains an emitter based on this event
+ * and I get recurring include dependency and I don't want to mix standard pointers with shared pointers.
+ */
+class MessageEventPrivateData : public WrtDeviceApis::Commons::IEventPrivateData
+{
+  public:
+    explicit MessageEventPrivateData(const IMessagePtr& message) : m_message(
+            message)
+    {
+    }
+
+    IMessagePtr GetMessage() const
+    {
+        return m_message;
+    }
+
+  private:
+    IMessagePtr m_message;
+};
+
+typedef DPL::SharedPtr<MessageEventPrivateData> MessageEventPrivateDataPtr;
+} // Api
+} // WrtPlugins
+}
+#endif /* MESSAGEEVENTPRIVATEDATA_H_ */
diff --git a/src/platform/API/Messaging/MessageFactory.cpp b/src/platform/API/Messaging/MessageFactory.cpp
new file mode 100755 (executable)
index 0000000..bbbc797
--- /dev/null
@@ -0,0 +1,293 @@
+//
+// 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 <Commons/Exception.h>
+#include <Messaging/Sms.h>
+#include <Messaging/BinarySms.h>
+#include <Messaging/Mms.h>
+#include <Messaging/Email.h>
+#include <Messaging/EmptyMessage.h>
+#include "MessageFactory.h"
+#include <API/Messaging/IAttachment.h>
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Platform::Messaging;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+IMessagePtr MessageFactory::createMessage(const MessageType msgType,
+        const std::string& id)
+{
+
+       LogInfo("enter");
+
+       ISms* retSms = NULL;
+       IMms* retMms =NULL;
+       IEmail* retEmail = NULL;
+       IBinarySms* retBinarySms = NULL;
+       IEmptyMessage* retEmptyMessage = NULL;
+
+       IMessagePtr imsg(NULL);
+
+       switch (msgType) {
+               case SMS:
+               {
+                       LogDebug("creation sms message with id");
+                       retSms = new Sms(id);
+                       imsg = (IMessagePtr) retSms;
+                       break;
+               }
+
+               case BINARYSMS:
+               {
+                       LogDebug("creation binary sms message with id");
+                       retBinarySms = new BinarySms(id);
+                       imsg = (IMessagePtr) retBinarySms;
+               break;
+               }
+
+               case MMS:
+               {
+                       LogDebug("creation mms message with id");
+                       retMms =        new Mms(id);
+                       imsg = (IMessagePtr) retMms;
+
+                       std::vector<IAttachmentPtr> attachments = retMms->getAttachments();
+
+                       unsigned int idx = 0;
+                       for (; idx < attachments.size() ; idx++ )
+                       {
+                       LogDebug("set Messsage ID = " << attachments[idx]->getAttachmentID());
+                       attachments[idx]->setMessage(imsg);
+                       }
+                       break;
+               }
+               case EMAIL:
+               {
+                       LogDebug("creation email message with id");
+                       retEmail= new Email(id);
+                       imsg = (IMessagePtr) retEmail;
+                       break;
+               }
+               case EMPTY_MESSAGE:
+               {
+                       LogDebug("creation empty message with id");
+                       retEmptyMessage = new EmptyMessage(id);
+                       imsg = (IMessagePtr) retEmptyMessage;
+                       break;
+               }
+               default:
+                       LogError("creation error, unknown message type");
+                       break;
+       }
+       LogInfo("end");
+       return imsg;
+
+}
+
+IMessagePtr MessageFactory::createMessage(const MessageType msgType,
+        const int id)
+{
+    std::ostringstream stream;
+    stream << id;
+    std::string idStr = stream.str();
+    return createMessage(msgType, idStr);
+}
+
+IMessagePtr MessageFactory::createMessage(const MessageType msgType,
+        const int id, const msg_struct_t msg_data)
+{
+    LogInfo("enter");
+    IMessage* retVal = NULL;
+    std::ostringstream stream;
+    stream << id;
+    std::string idStr = stream.str();
+       
+    switch (msgType) {
+    case SMS:
+        LogDebug("creation sms message with data");
+        retVal = new Sms(idStr, msg_data);
+        break;
+
+    case MMS:
+        LogDebug("creation mms message with data");
+        retVal = new Mms(idStr, msg_data);
+        break;
+
+    case EMPTY_MESSAGE:
+        LogDebug("creation empty message with data");
+        retVal = new EmptyMessage(idStr);
+        break;
+               
+    default:
+        LogError("creation error, unknown message type");
+        break;
+    }
+    LogInfo("end");
+    return IMessagePtr(retVal);
+}
+
+IMessagePtr MessageFactory::createMessage(const MessageType msgType,
+           Api::Messaging::EmailAccountInfo& account, const std::string& id )
+{
+       LogInfo("enter, CreateMessage with account");
+               
+       std::ostringstream stream;
+       stream << id;
+       std::string idStr = stream.str();
+       
+       LogInfo("createMessage with , idstr =" << idStr);
+       
+       if (msgType == EMAIL)
+       {       
+               LogDebug("Account Address:" << &account);
+               IMessage* retVal = NULL;
+               LogDebug("creation email message with account");
+               retVal = new Email(account);
+               return IMessagePtr(retVal);
+       }
+       
+       return createMessage(msgType, idStr);
+       
+}
+
+IMessagePtr MessageFactory::createEmailMessage(const int accountId, const int mailId)
+{
+       LogInfo("enter, Create Email Message with account ID");
+       IEmail* email = NULL;
+       LogDebug("creation email message with account ID");
+       std::stringstream stream;
+       unsigned int idx;
+       
+       stream << mailId;
+       if (stream.fail()) {
+               ThrowMsg(UnknownException,  "Couldn't convert e-mail account id");
+       }
+       
+       email = new Email(stream.str(), accountId);
+
+       IMessagePtr imsg(email);
+
+       std::vector<IAttachmentPtr> attachments = email->getAttachments();
+       std::vector<IAttachmentPtr> inlineAttachments = email->getInlineAttachments();
+       
+       for (idx = 0; idx < attachments.size() ; idx++ )
+       {
+               LogDebug("set Attachment ID = " << attachments[idx]->getAttachmentID());
+               attachments[idx]->setMessage(imsg);
+       }
+
+       for (idx = 0; idx < inlineAttachments.size() ; idx++ )
+       {
+               LogDebug("set inline Attachment ID = " << inlineAttachments[idx]->getAttachmentID());
+               inlineAttachments[idx]->setMessage(imsg);
+       }
+
+       return imsg;
+       
+       
+#if 0
+       IMessage* retVal = NULL;
+       LogDebug("creation email message with account ID");
+
+       
+       std::stringstream stream;
+       stream << mailId;
+       if (stream.fail()) {
+               ThrowMsg(UnknownException,  "Couldn't convert e-mail account id");
+       }
+       
+       retVal = new Email(stream.str(), accountId);
+
+       
+       
+       
+               
+       return IMessagePtr(retVal);
+#endif
+}
+
+IMessagePtr MessageFactory::createEmailMessage()
+{
+       LogInfo("enter, Create Temporary Email Message without account");
+
+       IEmail* email = NULL;
+
+       email = new Email(Api::Messaging::TEMP_FOLDER); //create dumy email.
+
+       IMessagePtr imsg(email);
+       
+       return imsg;
+}
+
+IMessagePtr MessageFactory::createVirtualMessage()
+{
+    return IMessagePtr(new VirtualMessage());
+}
+
+VirtualMessagePtr MessageFactory::convertToVirtualMessage(IMessagePtr msg)
+{
+    VirtualMessagePtr tmp = DPL::DynamicPointerCast<VirtualMessage >(msg);
+    if (!tmp) {
+        ThrowMsg(ConversionException,
+                 "Conversion IMessage to VirtualMessagePtr error");
+    }
+    return tmp;
+}
+
+ISmsPtr MessageFactory::convertToSms(IMessagePtr msg)
+{
+    ISmsPtr tmp = DPL::DynamicPointerCast<ISms >(msg);
+    if (!tmp) {
+        ThrowMsg(ConversionException, "Conversion IMessage to ISms error");
+    }
+    return tmp;
+}
+
+IBinarySmsPtr MessageFactory::convertToBinarySms(IMessagePtr msg)
+{
+    IBinarySmsPtr tmp = DPL::DynamicPointerCast<IBinarySms >(msg);
+    if (!tmp) {
+        ThrowMsg(ConversionException, "Conversion IMessage to IBinarySms error");
+    }
+    return tmp;
+}
+
+IMmsPtr MessageFactory::convertToMms(IMessagePtr msg)
+{
+    IMmsPtr tmp = DPL::DynamicPointerCast<IMms >(msg);
+    if (!tmp) {
+        ThrowMsg(ConversionException, "Conversion IMessage to IMms error");
+    }
+    return tmp;
+}
+
+IEmailPtr MessageFactory::convertToEmail(IMessagePtr msg)
+{
+    IEmailPtr tmp = DPL::DynamicPointerCast<IEmail >(msg);
+    if (!tmp) {
+        ThrowMsg(ConversionException, "Conversion IMessage to IEmail error");
+    }
+    return tmp;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/MessageFactory.h b/src/platform/API/Messaging/MessageFactory.h
new file mode 100755 (executable)
index 0000000..395ceef
--- /dev/null
@@ -0,0 +1,114 @@
+//
+// 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 MESSAGEFACTORY_H
+#define MESSAGEFACTORY_H
+
+#include <string>
+#include "IMessaging.h"
+#include "IMessage.h"
+#include "EmailAccountInfo.h"
+#include "msg_types.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class MessageFactory
+{
+  public:
+
+    /**
+     * Generate message specyfied type
+     * @param[in] msgType type of message to create
+     * @param[in] id if id is set, then is trying to read existing message
+     * from storage by specyfid if
+     */
+    static IMessagePtr createMessage(const MessageType msgType,
+            const std::string& id = "");
+
+    /**
+     * Generate message specyfied type
+     * @param[in] msgType type of message to create
+     * @param[in] int id
+     * from storage by specyfid if
+     */
+    static IMessagePtr createMessage(const MessageType msgType,
+            const int id);
+
+    static IMessagePtr createMessage(const MessageType msgType,
+            const int id, const msg_struct_t msg_data);
+
+    /**
+     * Generate message specyfied type
+     * @param[in] msgType type of message to create
+     * @param[in] account of mail.
+     */
+    static IMessagePtr createMessage(const MessageType msgType,
+           Api::Messaging::EmailAccountInfo& account, const std::string& id = "" );
+
+    static IMessagePtr createEmailMessage ( const int accountId, const int id = 0 );
+
+    static IMessagePtr createEmailMessage();
+
+    /**
+     * Generate virtual message specyfied type, without platform projection
+     * @param[in] msgType type of message to create
+     */
+    static IMessagePtr createVirtualMessage();
+
+    /**
+     * Convert abstract message (IMessage) to virtual message
+     * @param[in] msg - pointer to message to convert
+     * @throw ConversionException if conversion fail
+     */
+    static VirtualMessagePtr convertToVirtualMessage(IMessagePtr msg);
+
+    /**
+     * Convert abstract message (IMessage) to abstract sms (ISms)
+     * @param[in] msg - pointer to message to convert
+     * @throw ConversionException if conversion fail
+     */
+    static ISmsPtr convertToSms(IMessagePtr msg);
+
+    /**
+     * Convert abstract message (IMessage) to abstract binary sms (IBinarySms)
+     * @param[in] msg - pointer to message to convert
+     * @throw ConversionException if conversion fail
+     */
+    static IBinarySmsPtr convertToBinarySms(IMessagePtr msg);
+
+    /**
+     * Convert abstract message (IMessage) to abstract Mms (IMms)
+     * @param[in] msg - pointer to message to convert
+     * @throw ConversionException if conversion fail
+     */
+    static IMmsPtr convertToMms(IMessagePtr msg);
+
+    /**
+     * Convert abstract message (IMessage) to abstract email (IEmail)
+     * @param[in] msg - pointer to message to convert
+     * @throw ConversionException if conversion fail
+     */
+    static IEmailPtr convertToEmail(IMessagePtr msg);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/MessageFilterValidator.cpp b/src/platform/API/Messaging/MessageFilterValidator.cpp
new file mode 100755 (executable)
index 0000000..9fc1858
--- /dev/null
@@ -0,0 +1,206 @@
+//
+// 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 "MessageFilterValidator.h"
+#include "MessageFilterValidatorFactory.h"
+
+#include <dpl/log/log.h>
+#include "log.h"
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               MessageFilterValidator::MessageFilterValidator(PropertyStructArray properties)
+                               :FilterValidator(properties){
+                       m_isTypeSetted = false;
+
+                       initMatchFlagVectors();
+                       initAttributeAndMatchFlagsMap();
+               }
+
+               MessageFilterValidator::~MessageFilterValidator(){
+               }
+
+               void MessageFilterValidator::initMatchFlagVectors(){
+                       m_typeMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+
+                       m_idMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+
+                       m_serviceIdMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+
+                       m_folderIdMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+
+                       m_timestampMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+
+                       m_fromMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+                       m_fromMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
+                       m_fromMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_STARTSWITH);
+                       m_fromMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_ENDSWITH);
+
+                       m_toMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+                       m_toMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
+                       m_toMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_STARTSWITH);
+                       m_toMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_ENDSWITH);
+
+                       m_ccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+                       m_ccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
+                       m_ccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_STARTSWITH);
+                       m_ccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_ENDSWITH);
+
+                       m_bccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+                       m_bccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
+                       m_bccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_STARTSWITH);
+                       m_bccMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_ENDSWITH);
+
+                       m_bodyMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
+
+                       m_isReadMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+
+                       m_priorityMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+
+                       m_attachmentMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+                       
+                       m_subjectMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_EXACTLY);
+                       m_subjectMatchFlagVec.push_back(MessageFilterValidatorFactory::MATCH_CONTAINS);
+               }
+
+               void MessageFilterValidator::initAttributeAndMatchFlagsMap(){
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_TYPE]      = m_typeMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_ID]        = m_idMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_SERVICE_ID]= m_serviceIdMatchFlagVec;                      
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_FOLDER]    = m_folderIdMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP] = m_timestampMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_FROM]      = m_fromMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_CC]        = m_ccMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_BCC]       = m_bccMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_BODY]      = m_bodyMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_IS_READ]   = m_isReadMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_PRIORITY]  = m_priorityMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_SUBJECT]   = m_subjectMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_ATTACHMENT] = m_attachmentMatchFlagVec;
+                       m_attributeAndMatchFlagsMap[MessageFilterValidatorFactory::ATTRIBUTE_TO]        = m_toMatchFlagVec;
+               }
+
+               bool MessageFilterValidator::validateAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth){
+                       if(initialValue == NULL || endValue == NULL)
+                               return false;
+
+                       bool retVal = false;
+
+                       if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP)!=0){
+                               MsgLogError(">>> [ERROR] Not Supported attribute :[" << attrName << "]");
+                               return false;
+                       }
+
+                       retVal = FilterValidator::validateAttributeRange(attrName, initialValue, endValue, depth);
+                       return retVal;
+               }
+
+
+               bool MessageFilterValidator::vectorContains(std::vector<std::string>& vec, Api::Tizen::MatchFlag& value){
+                       std::string matchStr;
+                       switch(value)
+                       {
+                       case Api::Tizen::MATCH_EXACTLY:
+                               matchStr = "EXACTLY";
+                               break;
+                       case Api::Tizen::MATCH_FULLSTRING:
+                               matchStr = "FULLSTRING";
+                               break;
+                       case Api::Tizen::MATCH_CONTAINS:
+                               matchStr = "CONTAINS";
+                               break;
+                       case Api::Tizen::MATCH_STARTSWITH:
+                               matchStr = "STARTSWITH";
+                               break;
+                       case Api::Tizen::MATCH_ENDSWITH:
+                               matchStr = "ENDSWITH";
+                               break;
+                       case Api::Tizen::MATCH_EXISTS:
+                               matchStr = "EXISTS";
+                               break;
+                       default:
+                               matchStr = "";
+                               break;
+                       }
+
+                       std::vector<std::string>::iterator it;
+                       for(it=vec.begin(); it<vec.end(); it++){
+                               if((*it).compare(matchStr) == 0){
+                                       return true;
+                               }
+                       }
+
+                       return false;
+               }
+
+               bool MessageFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                               Api::Tizen::AnyPtr& matchValue, int depth){
+                       bool retBool = false;
+
+                       if(matchValue == NULL)
+                               return false;
+
+                       if(validateAttributeEach(attrName, matchFlag, matchValue, depth) == false){
+                               MsgLogWanning(">>>[Warning] attrName:[" << attrName << "] is invalid value:[" << matchValue->toString() << "]");
+                               return false;
+                       }
+
+                       retBool = FilterValidator::validateAttribute(attrName, matchFlag, matchValue, depth);
+                       LogDebug(">>> retBool:" << retBool);
+                       return retBool;
+               }
+
+               bool MessageFilterValidator::validateAttributeEach(std::string& attrName,MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
+
+                       if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TYPE)==0){
+                               if(m_isTypeSetted == true){
+                                       MsgLogError(">>> [ERROR] duplicated type :[" << attrName << "], value:[" <<
+                                                       value->toString()<< "]");
+                                       return false;
+                               }else{
+                                       m_isTypeSetted = true;
+                               }
+                       }
+
+                       if(m_attributeAndMatchFlagsMap.count(attrName) == 0)
+                       {
+                               MsgLogWanning(">>>[Waning] attrName is not supported:[" << attrName << "]");
+                               return false;
+                       }
+
+                       std::vector<std::string> vec = m_attributeAndMatchFlagsMap.find(attrName)->second;
+
+                       if(vectorContains(vec, matchFlag)==false){
+                               MsgLogWanning(">>>[Waning]MatchFlag check fail unsupported flag:[" << matchFlag << "] for Attribute:[" << attrName << "]");
+                               return false;
+                       }
+
+                       LogDebug(">>> return true");
+                       return true;
+               }
+
+                       }       //namespace Messaging
+       }
+
+}
diff --git a/src/platform/API/Messaging/MessageFilterValidator.h b/src/platform/API/Messaging/MessageFilterValidator.h
new file mode 100755 (executable)
index 0000000..ba88ea0
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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 MESSAGEFILTERVALIDATOR_H_
+#define MESSAGEFILTERVALIDATOR_H_
+
+#include <API/Filter/FilterValidator.h>
+#include <vector>
+
+namespace TizenApis {
+
+       namespace Platform {
+
+               namespace Messaging {
+
+               class MessageFilterValidator: public Api::Tizen::FilterValidator {
+                       private:
+                               bool m_isTypeSetted;
+
+                               std::vector<std::string>  m_typeMatchFlagVec;
+                               std::vector<std::string>  m_idMatchFlagVec;
+                               std::vector<std::string>  m_serviceIdMatchFlagVec;                              
+                               std::vector<std::string>  m_folderIdMatchFlagVec;
+                               std::vector<std::string>  m_timestampMatchFlagVec;
+                               std::vector<std::string>  m_fromMatchFlagVec;
+                               std::vector<std::string>  m_toMatchFlagVec;
+                               std::vector<std::string>  m_ccMatchFlagVec;
+                               std::vector<std::string>  m_bccMatchFlagVec;
+                               std::vector<std::string>  m_bodyMatchFlagVec;
+                               std::vector<std::string>  m_isReadMatchFlagVec;
+                               std::vector<std::string>  m_priorityMatchFlagVec;
+                               std::vector<std::string>  m_subjectMatchFlagVec;
+                               std::vector<std::string>  m_attachmentMatchFlagVec;
+
+                               std::map<std::string, std::vector<std::string> > m_attributeAndMatchFlagsMap;
+
+                       public:
+                       MessageFilterValidator(Api::Tizen::PropertyStructArray properties);
+
+                               virtual ~MessageFilterValidator();
+
+                               // validate AttributeRangeFilter
+                                       virtual bool validateAttributeRange(std::string& attrName,
+                                                       Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0);
+
+                                       virtual bool validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                                                       Api::Tizen::AnyPtr& matchValue, int depth=0);
+
+                       protected:
+                                       bool validateAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth);
+
+                               private :
+                                       void initMatchFlagVectors();
+                                       void initAttributeAndMatchFlagsMap();
+
+                                       bool vectorContains(std::vector<std::string>& vec, Api::Tizen::MatchFlag& value);
+
+               };
+
+               typedef DPL::SharedPtr<MessageFilterValidator> MessageFilterValidatorPtr;
+       }
+ }
+}
+#endif /* MESSAGEFILTERVALIDATOR_H_ */
diff --git a/src/platform/API/Messaging/MessageFilterValidatorFactory.cpp b/src/platform/API/Messaging/MessageFilterValidatorFactory.cpp
new file mode 100755 (executable)
index 0000000..49b70a8
--- /dev/null
@@ -0,0 +1,75 @@
+//
+// 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 "MessageFilterValidatorFactory.h"
+
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_ID               = "id";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_SERVICE_ID       = "serviceId";              
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_TYPE             = "type";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_FOLDER           = "folderId";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP        = "timestamp";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_FROM             = "from";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_TO               = "to";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_CC               = "cc";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_BCC              = "bcc";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_BODY             = "body";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_IS_READ          = "isRead";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_PRIORITY         = "isHighPriority";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_SUBJECT          = "subject";
+               const std::string MessageFilterValidatorFactory::ATTRIBUTE_ATTACHMENT   = "hasAttachment";
+
+                std::string MessageFilterValidatorFactory::MATCH_EXACTLY              = "EXACTLY";
+                std::string MessageFilterValidatorFactory::MATCH_CONTAINS             = "CONTAINS";
+                std::string MessageFilterValidatorFactory::MATCH_STARTSWITH           = "STARTSWITH";
+                std::string MessageFilterValidatorFactory::MATCH_ENDSWITH             = "ENDSWITH";
+
+               static PropertyStructArray properties =
+               {
+                               {MessageFilterValidatorFactory::ATTRIBUTE_ID.c_str(),        Api::Tizen::PrimitiveType_String},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_SERVICE_ID.c_str(),Api::Tizen::PrimitiveType_String},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_TYPE.c_str(),      Api::Tizen::PrimitiveType_String},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_FOLDER.c_str(),    Api::Tizen::PrimitiveType_String},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP.c_str(), Api::Tizen::PrimitiveType_Time},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_FROM.c_str(),      Api::Tizen::PrimitiveType_String},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_TO.c_str(),        Api::Tizen::PrimitiveType_String},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_CC.c_str(),        Api::Tizen::PrimitiveType_String},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_BCC.c_str(),       Api::Tizen::PrimitiveType_String},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_BODY.c_str(),      Api::Tizen::PrimitiveType_String},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_IS_READ.c_str(),   Api::Tizen::PrimitiveType_Boolean},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_PRIORITY.c_str(),  Api::Tizen::PrimitiveType_Boolean},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_SUBJECT.c_str(),   Api::Tizen::PrimitiveType_String},
+                               {MessageFilterValidatorFactory::ATTRIBUTE_ATTACHMENT.c_str(),   Api::Tizen::PrimitiveType_Boolean},
+                               {0,                  Api::Tizen::PrimitiveType_NoType}
+               };
+
+               MessageFilterValidatorPtr MessageFilterValidatorFactory::getMessageFilterValidator()
+               {
+                   MessageFilterValidatorPtr theInstance =
+                               MessageFilterValidatorPtr(new MessageFilterValidator(properties));
+
+                   return theInstance;
+               }
+
+               }
+       }       //naspace Platform
+} //naspace WrtPlugins
diff --git a/src/platform/API/Messaging/MessageFilterValidatorFactory.h b/src/platform/API/Messaging/MessageFilterValidatorFactory.h
new file mode 100755 (executable)
index 0000000..7478017
--- /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 MESSAGINGFILTERVALIDATORFACTORY_H_
+#define MESSAGINGFILTERVALIDATORFACTORY_H_
+
+#include <API/Filter/FilterValidator.h>
+#include "MessageFilterValidator.h"
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               class MessageFilterValidatorFactory {
+                       private:
+                               MessageFilterValidatorFactory()
+                               {
+                               }
+
+                       public:
+                               static MessageFilterValidatorPtr getMessageFilterValidator();
+
+                       public:
+                               static const std::string ATTRIBUTE_ID;
+                               static const std::string ATTRIBUTE_SERVICE_ID;                          
+                               static const std::string ATTRIBUTE_TYPE;
+                               static const std::string ATTRIBUTE_FOLDER;
+                               static const std::string ATTRIBUTE_TIMESTAMP;
+                               static const std::string ATTRIBUTE_FROM;
+                               static const std::string ATTRIBUTE_TO;
+                               static const std::string ATTRIBUTE_CC;
+                               static const std::string ATTRIBUTE_BCC;
+                               static const std::string ATTRIBUTE_BODY;
+                               static const std::string ATTRIBUTE_IS_READ;
+                               static const std::string ATTRIBUTE_PRIORITY;
+                               static const std::string ATTRIBUTE_SUBJECT;
+                               static const std::string ATTRIBUTE_ATTACHMENT;
+
+                               static  std::string MATCH_EXACTLY;
+                               static  std::string MATCH_CONTAINS;
+                               static  std::string MATCH_STARTSWITH;
+                               static  std::string MATCH_ENDSWITH;
+                               static  std::string MATCH_CASESENSITIVE;
+               };
+
+               }
+       }               //Platform
+}
+
+#endif /* MESSAGINGFILTERVALIDATORFACTORY_H_ */
diff --git a/src/platform/API/Messaging/MessagePriority.cpp b/src/platform/API/Messaging/MessagePriority.cpp
new file mode 100755 (executable)
index 0000000..76ee083
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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 "MessagePriority.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+MessagePriority::MessagePriority() :
+    m_priority(NORMAL),
+    m_validPriority(false)
+{
+}
+
+void MessagePriority::setPriority(MessagePriority::Priority value)
+{
+    m_priority = value;
+    m_validPriority = false;
+}
+
+MessagePriority::Priority MessagePriority::getPriority() const
+{
+    return m_priority;
+}
+
+bool MessagePriority::isPriorityValid() const
+{
+    return m_validPriority;
+}
+
+void MessagePriority::setPriorityValid(bool state)
+{
+    m_validPriority = state;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/MessagePriority.h b/src/platform/API/Messaging/MessagePriority.h
new file mode 100755 (executable)
index 0000000..900624c
--- /dev/null
@@ -0,0 +1,73 @@
+//
+// 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 MESSAGEPRIORITY_H
+#define MESSAGEPRIORITY_H
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class MessagePriority
+{
+  public:
+    enum Priority
+    {
+        LOW,
+        NORMAL,
+        HIGH
+    };
+
+  public:
+    MessagePriority();
+
+    /**
+     * setter of MessagePriority value
+     */
+    void setPriority(Priority value);
+
+    /**
+     * getter of MessagePriority value
+     */
+    Priority getPriority() const;
+
+    /**
+     * check MessagePriority validity
+     * */
+    bool isPriorityValid() const;
+
+    /**
+     * set MessagePriority validity
+     * */
+    void setPriorityValid(bool state);
+
+  private:
+    /**
+     * MessagePriority value
+     */
+    Priority m_priority;
+
+    /**
+     * information if abstract message MessagePriority has been changed and need update
+     * in low level
+     */
+    bool m_validPriority;
+};
+}
+}
+}
+#endif // MESSAGEPRIORITY_H
diff --git a/src/platform/API/Messaging/MessageProperties.h b/src/platform/API/Messaging/MessageProperties.h
new file mode 100755 (executable)
index 0000000..b46b389
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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_API_MESSAGING_PROPERTIES_H_
+#define WRTPLUGINS_API_MESSAGING_PROPERTIES_H_
+
+#include <dpl/shared_ptr.h>
+#include <string>
+#include <vector>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+struct MessagingProperties {
+       std::string subject;
+       std::vector< std::string > to;
+       std::vector< std::string > cc;
+       std::vector< std::string > bcc;
+       std::string plainBody;
+       std::string htmlBody;
+       bool priority;
+
+       MessagingProperties() :
+               priority(false)
+       {
+       
+       }
+};
+
+typedef DPL::SharedPtr<MessagingProperties> MessagingPropertiesPtr;
+
+}//Messaging
+} // Api
+} 
+
+#endif //WRTPLUGINS_API_MESSAGING_PROPERTIES_H_
\ No newline at end of file
diff --git a/src/platform/API/Messaging/MessageStorageFactory.cpp b/src/platform/API/Messaging/MessageStorageFactory.cpp
new file mode 100755 (executable)
index 0000000..0de9afd
--- /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.
+//
+
+#include "MessageStorageFactory.h"
+//#include <Messaging/MessagingServiceManager.h>
+#include <Messaging/JSMessagingListener.h>
+
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+using namespace TizenApis::Platform::Messaging;
+
+
+JSMessagingListenerPtr MessageStorageFactory::getMessagingListener(context) {
+       return JSMessagingListenerPtr( new JSMessagingListener::JSMessagingListener(context) );
+}
+
+MessageStorageFactory& MessageStorageFactory::getInstance() {
+       static MessageStorageFactory theInstance;
+       return theInstance;
+}
+
+MessageStorageFactory::MessageStorageFactory() {
+}
+
+MessageStorageFactory::~MessageStorageFactory(){
+}
+
+}
+}
+}
+
diff --git a/src/platform/API/Messaging/MessageStorageFactory.h b/src/platform/API/Messaging/MessageStorageFactory.h
new file mode 100755 (executable)
index 0000000..b919ce7
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// 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_API_MESSAGING_STORAGE_FACTORY_H_
+#define WRTPLUGINS_API_MESSAGING_STORAGE_FACTORY_H_
+
+#include <dpl/noncopyable.h>
+//#include "IMessagingServiceManager.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+       
+class MessageStorageFactory : DPL::Noncopyable
+{
+public:
+       IMessagingServiceManagerPtr getMessagingListener();
+       static MessageStorageFactory& getInstance();
+
+protected:
+       MessageStorageFactory();
+       ~MessageStorageFactory();
+};
+
+
+}
+}
+}
+
+#endif //WRTPLUGINS_API_MESSAGING_FACTORY_H_
+
diff --git a/src/platform/API/Messaging/MessagingFactory.cpp b/src/platform/API/Messaging/MessagingFactory.cpp
new file mode 100755 (executable)
index 0000000..4c6462b
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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.
+//
+\r
+#include "MessagingFactory.h"\r
+#include <Messaging/MessagingServiceManager.h>\r
+\r
+namespace TizenApis {\r
+namespace Api {\r
+namespace Messaging {\r
+\r
+using namespace TizenApis::Platform::Messaging;\r
+\r
+\r
+IMessagingServiceManagerPtr MessagingFactory::getMessagingServiceManager() {\r
+       return IMessagingServiceManagerPtr( new MessagingServiceManager() );\r
+}\r
+\r
+MessagingFactory& MessagingFactory::getInstance() {\r
+       static MessagingFactory theInstance;\r
+       return theInstance;\r
+}\r
+\r
+MessagingFactory::MessagingFactory() {\r
+}\r
+\r
+MessagingFactory::~MessagingFactory(){\r
+}\r
+\r
+}\r
+}\r
+}\r
+\r
diff --git a/src/platform/API/Messaging/MessagingFactory.h b/src/platform/API/Messaging/MessagingFactory.h
new file mode 100755 (executable)
index 0000000..c25cbb4
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// 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.
+//\r
+
+#ifndef WRTPLUGINS_API_MESSAGING_FACTORY_H_\r
+#define WRTPLUGINS_API_MESSAGING_FACTORY_H_\r
+\r
+#include <dpl/noncopyable.h>\r
+#include "IMessagingServiceManager.h"\r
+\r
+namespace TizenApis {\r
+namespace Api {\r
+namespace Messaging {\r
+       \r
+class MessagingFactory : DPL::Noncopyable\r
+{\r
+public:\r
+       IMessagingServiceManagerPtr getMessagingServiceManager();\r
+       static MessagingFactory& getInstance();\r
+\r
+protected:\r
+       MessagingFactory();\r
+       ~MessagingFactory();\r
+};\r
+\r
+\r
+}\r
+}\r
+}\r
+\r
+#endif //WRTPLUGINS_API_MESSAGING_FACTORY_H_\r
+\r
diff --git a/src/platform/API/Messaging/MmsSlide.cpp b/src/platform/API/Messaging/MmsSlide.cpp
new file mode 100755 (executable)
index 0000000..9873f9e
--- /dev/null
@@ -0,0 +1,164 @@
+//
+// 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 "MmsSlide.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+MmsSlide::MmsSlide() : m_duration(0)
+{
+}
+
+MmsSlide::~MmsSlide()
+{
+}
+
+unsigned long MmsSlide::getDuration() const
+{
+    return m_duration;
+}
+
+void MmsSlide::setDuration(Ulong duration)
+{
+    m_duration = duration;
+}
+
+const std::string& MmsSlide::getImageFilename() const
+{
+    return m_image.getFilename();
+}
+
+void MmsSlide::setImageFilename(const std::string& filename)
+{
+    m_image.setFilename(filename);
+}
+
+unsigned long MmsSlide::getImageBegin() const
+{
+    return m_image.getStartTime();
+}
+
+void MmsSlide::setImageBegin(Ulong value)
+{
+    m_image.setStartTime(value);
+}
+
+unsigned long MmsSlide::getImageEnd() const
+{
+    return m_image.getEndTime();
+}
+
+void MmsSlide::setImageEnd(Ulong value)
+{
+    m_image.setEndTime(value);
+}
+
+const std::string& MmsSlide::getAudioFilename() const
+{
+    return m_audio.getFilename();
+}
+
+void MmsSlide::setAudioFilename(const std::string& filename)
+{
+    m_audio.setFilename(filename);
+}
+
+unsigned long MmsSlide::getAudioBegin() const
+{
+    return m_audio.getStartTime();
+}
+
+void MmsSlide::setAudioBegin(Ulong value)
+{
+    m_audio.setStartTime(value);
+}
+
+unsigned long MmsSlide::getAudioEnd() const
+{
+    return m_audio.getEndTime();
+}
+
+void MmsSlide::setAudioEnd(Ulong value)
+{
+    m_audio.setEndTime(value);
+}
+
+const std::string& MmsSlide::getTextFilename() const
+{
+    return m_text.getFilename();
+}
+
+void MmsSlide::setTextFilename(const std::string& filename)
+{
+    m_text.setFilename(filename);
+}
+
+unsigned long MmsSlide::getTextBegin() const
+{
+    return m_text.getStartTime();
+}
+
+void MmsSlide::setTextBegin(Ulong value)
+{
+    m_text.setStartTime(value);
+}
+
+unsigned long MmsSlide::getTextEnd() const
+{
+    return m_text.getEndTime();
+}
+
+void MmsSlide::setTextEnd(Ulong value)
+{
+    m_text.setEndTime(value);
+}
+
+const std::string& MmsSlide::getVideoFilename() const
+{
+    return m_video.getFilename();
+}
+
+void MmsSlide::setVideoFilename(const std::string& filename)
+{
+    m_video.setFilename(filename);
+}
+
+unsigned long MmsSlide::getVideoBegin() const
+{
+    return m_video.getStartTime();
+}
+
+void MmsSlide::setVideoBegin(Ulong value)
+{
+    m_video.setStartTime(value);
+}
+
+unsigned long MmsSlide::getVideoEnd() const
+{
+    return m_video.getEndTime();
+}
+
+void MmsSlide::setVideoEnd(Ulong value)
+{
+    m_video.setEndTime(value);
+}
+}
+}
+}
+
diff --git a/src/platform/API/Messaging/MmsSlide.h b/src/platform/API/Messaging/MmsSlide.h
new file mode 100755 (executable)
index 0000000..2228112
--- /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.
+//
+
+#ifndef MMS_SLIDE_H
+#define MMS_SLIDE_H
+
+#include "IMmsSlide.h"
+#include "MmsSlideProperty.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class MmsSlide : public virtual IMmsSlide
+{
+  public:
+    MmsSlide();
+
+    virtual ~MmsSlide();
+
+    //duration
+    virtual Ulong getDuration() const;
+    virtual void setDuration(Ulong duration);
+
+    //image
+    virtual const std::string& getImageFilename() const;
+    virtual void setImageFilename(const std::string& filename);
+    virtual Ulong getImageBegin() const;
+    virtual void setImageBegin(Ulong value);
+    virtual Ulong getImageEnd() const;
+    virtual void setImageEnd(Ulong value);
+
+    //audio
+    virtual const std::string& getAudioFilename() const;
+    virtual void setAudioFilename(const std::string& filename);
+    virtual Ulong getAudioBegin() const;
+    virtual void setAudioBegin(Ulong value);
+    virtual Ulong getAudioEnd() const;
+    virtual void setAudioEnd(Ulong value);
+
+    //text
+    virtual const std::string& getTextFilename() const;
+    virtual void setTextFilename(const std::string& filename);
+    virtual Ulong getTextBegin() const;
+    virtual void setTextBegin(Ulong value);
+    virtual Ulong getTextEnd() const;
+    virtual void setTextEnd(Ulong value);
+
+    //video
+    virtual const std::string& getVideoFilename() const;
+    virtual void setVideoFilename(const std::string& filename);
+    virtual Ulong getVideoBegin() const;
+    virtual void setVideoBegin(Ulong value);
+    virtual Ulong getVideoEnd() const;
+    virtual void setVideoEnd(Ulong value);
+
+  private:
+    Ulong m_duration;
+
+    MmsSlideProperty m_image;
+    MmsSlideProperty m_audio;
+    MmsSlideProperty m_text;
+    MmsSlideProperty m_video;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/MmsSlideProperty.cpp b/src/platform/API/Messaging/MmsSlideProperty.cpp
new file mode 100755 (executable)
index 0000000..59258ab
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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 "MmsSlideProperty.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+MmsSlideProperty::MmsSlideProperty() :
+    m_filename(""),
+    m_startTime(0),
+    m_endTime(0)
+{
+}
+
+MmsSlideProperty::~MmsSlideProperty()
+{
+}
+
+const std::string& MmsSlideProperty::getFilename() const
+{
+    return m_filename;
+}
+
+unsigned long MmsSlideProperty::getStartTime() const
+{
+    return m_startTime;
+}
+
+unsigned long MmsSlideProperty::getEndTime() const
+{
+    return m_endTime;
+}
+
+void MmsSlideProperty::setFilename(const std::string& value)
+{
+    m_filename = value;
+}
+
+void MmsSlideProperty::setStartTime(Ulong value)
+{
+    m_startTime = value;
+}
+
+void MmsSlideProperty::setEndTime(Ulong value)
+{
+    m_endTime = value;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/MmsSlideProperty.h b/src/platform/API/Messaging/MmsSlideProperty.h
new file mode 100755 (executable)
index 0000000..c0404c6
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// 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 MMS_SLIDE_PROPERTY_H
+#define MMS_SLIDE_PROPERTY_H
+
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class MmsSlideProperty
+{
+  private:
+    typedef unsigned long Ulong;
+
+  private:
+
+    std::string m_filename;
+
+    Ulong m_startTime;
+
+    Ulong m_endTime;
+
+  public:
+
+    MmsSlideProperty();
+
+    virtual ~MmsSlideProperty();
+
+    /**
+     * getters for filename
+     * */
+    virtual const std::string& getFilename() const;
+
+    /**
+     * getters for startTime
+     * */
+    virtual Ulong getStartTime() const;
+
+    /**
+     * getters for endTime
+     * */
+    virtual Ulong getEndTime() const;
+
+    /**
+     * setters for filename
+     * */
+    virtual void setFilename(const std::string& value);
+
+    /**
+     * setters for start time
+     * */
+    virtual void setStartTime(Ulong value);
+
+    /**
+     * setters for end time
+     * */
+    virtual void setEndTime(Ulong value);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/MmsSlides.cpp b/src/platform/API/Messaging/MmsSlides.cpp
new file mode 100755 (executable)
index 0000000..e5af28f
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// 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 "MmsSlides.h"
+#include "MmsSlide.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+MmsSlides::MmsSlides() : m_valid(false)
+{
+}
+
+MmsSlides::~MmsSlides()
+{
+}
+
+bool MmsSlides::checkSlidesValidity() const
+{
+    return m_valid;
+}
+
+void MmsSlides::setSlidesValidity(bool state)
+{
+    m_valid = state;
+}
+
+void MmsSlides::setSlides(const std::vector<IMmsSlidePtr>& slides)
+{
+    m_slides = slides;
+}
+
+IMmsSlidePtr MmsSlides::createEmptySlide() const
+{
+    IMmsSlide* slide = NULL;
+    slide = new MmsSlide;
+
+    return IMmsSlidePtr(slide);
+}
+
+void MmsSlides::addSlide(const IMmsSlidePtr& slide)
+{
+    m_slides.push_back(slide);
+}
+
+size_t MmsSlides::getSlideCount() const
+{
+    return m_slides.size();
+}
+
+IMmsSlidePtr MmsSlides::getSlide(size_t nb) const
+{
+    if (nb >= m_slides.size()) {
+        //TODO -exception?
+    }
+    return m_slides[nb];
+}
+
+std::vector<IMmsSlidePtr> MmsSlides::getSlides() const
+{
+    return m_slides;
+}
+
+void MmsSlides::replaceSlide(size_t pos,
+        const IMmsSlidePtr& slide)
+{
+    if (pos >= m_slides.size()) {
+        //TODO
+    } else {
+        //m_slides.erase(m_slides.begin()+pos);
+        m_slides[pos] = slide;
+    }
+}
+
+void MmsSlides::removeSlide(size_t pos)
+{
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/MmsSlides.h b/src/platform/API/Messaging/MmsSlides.h
new file mode 100755 (executable)
index 0000000..d28529e
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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 MMS_SLIDES_H
+#define MMS_SLIDES_H
+
+#include "IMmsSlides.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class MmsSlides :
+    virtual public IMmsSlides
+{
+  public:
+
+    MmsSlides();
+
+    virtual ~MmsSlides();
+
+    virtual IMmsSlidePtr createEmptySlide() const;
+
+    virtual bool checkSlidesValidity() const;
+
+    virtual void setSlidesValidity(bool state);
+
+    virtual void setSlides(const std::vector<IMmsSlidePtr>& slides);
+
+    virtual void addSlide(const IMmsSlidePtr& slide);
+
+    virtual size_t getSlideCount() const;
+
+    virtual IMmsSlidePtr getSlide(size_t nb) const;
+
+    virtual std::vector<IMmsSlidePtr> getSlides() const;
+
+    virtual void replaceSlide(size_t pos,
+            const IMmsSlidePtr& slide);
+
+    virtual void removeSlide(size_t pos);
+
+  private:
+
+    bool m_valid;
+
+    std::vector<IMmsSlidePtr> m_slides;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/Recipient.cpp b/src/platform/API/Messaging/Recipient.cpp
new file mode 100755 (executable)
index 0000000..25ffe52
--- /dev/null
@@ -0,0 +1,205 @@
+//
+// 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 <sstream>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "Recipient.h"
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+
+namespace {
+const static string emptyString;
+}
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+Recipients::Recipients() :
+    m_validRecipients(false)
+{
+}
+
+Recipients::Recipients(const vector<string>& value) :
+    m_validRecipients(false)
+{
+    m_recipients = value;
+}
+
+Recipients::~Recipients()
+{
+}
+
+bool Recipients::isValid() const
+{
+    return m_validRecipients;
+}
+
+void Recipients::setValid(bool state)
+{
+    m_validRecipients = state;
+}
+
+void Recipients::setRecipients(const vector<string>& value)
+{
+    m_recipients = value;
+    m_validRecipients = false;
+}
+
+void Recipients::setRecipients(const std::string& value)
+{
+    vector<string> tmp = split(value, ';');
+    setRecipients(tmp);
+}
+
+void Recipients::setRecipient(const size_t index,
+        const string& value)
+{
+    if (index >= m_recipients.size()) {
+        Throw(OutOfRangeException);
+        return;
+    }
+    m_recipients[index] = value;
+    m_validRecipients = false;
+}
+
+void Recipients::setRecipientWithExpand(const size_t index,
+        const std::string& value)
+{
+    if (index >= m_recipients.size()) {
+        m_recipients.resize(index + 1, emptyString);
+    }
+    m_recipients[index] = value;
+    m_validRecipients = false;
+}
+
+vector<string> Recipients::getRecipients() const
+{
+    return m_recipients;
+}
+
+const vector<string>& Recipients::getRecipientsRef() const
+{
+    return m_recipients;
+}
+
+string Recipients::getRecipient(const size_t index) const
+{
+    if (index >= m_recipients.size()) {
+        Throw(WrtDeviceApis::Commons::OutOfRangeException);
+//        return "";
+    }
+    return m_recipients[index];
+}
+
+void Recipients::appendRecipient(const string & value)
+{
+    vector<string> tmp = split(value, ';');
+    m_recipients.insert(m_recipients.end(), tmp.begin(), tmp.end());
+    m_validRecipients = false;
+}
+
+void Recipients::removeRecipient(const size_t position)
+{
+    if (position >= m_recipients.size()) {
+        Throw(WrtDeviceApis::Commons::OutOfRangeException);
+    } else {
+        m_recipients.erase(m_recipients.begin() + position);
+        m_validRecipients = false;
+    }
+}
+
+void Recipients::removeRecipient(const string & value)
+{
+    m_recipients.erase(
+        remove(m_recipients.begin(), m_recipients.end(), value),
+        m_recipients.end());
+    m_validRecipients = false;
+}
+
+string Recipients::join(char delimiter) const
+{
+    string retVal;
+    for (size_t i = 0; i < m_recipients.size(); i++) {
+        retVal += m_recipients[i] + delimiter;
+    }
+    return retVal;
+}
+
+vector<string> Recipients::split(const string& input,
+        char delimiter)
+{
+    vector<string> ret;
+    stringstream stream(input);
+    string item;
+    while (getline(stream, item, delimiter)) {
+        ret.push_back(item);
+    }
+    return ret;
+}
+
+size_t Recipients::getRecipientSize() const
+{
+    return m_recipients.size();
+}
+
+bool Recipients::operator !=(const Recipients& arg) const
+{
+    if (m_recipients == arg.m_recipients) {
+        return true;
+    }
+    return false;
+}
+
+Recipients & Recipients::operator +=(const Recipients& val)
+{
+    const vector<string>& tmp = val.getRecipientsRef();
+    m_recipients.insert(m_recipients.end(), tmp.begin(), tmp.end());
+    m_validRecipients = false;
+    return *this;
+}
+
+Recipients & Recipients::operator -=(const Recipients& val)
+{
+    //check if recipients are inside list
+    vector<string> l_recipients = m_recipients;
+    vector<string> l_toDelete = val.getRecipients();
+    sort(l_recipients.begin(), l_recipients.end());
+    sort(l_toDelete.begin(), l_toDelete.end());
+    if (!includes(l_recipients.begin(), l_recipients.end(), l_toDelete.begin(),
+                  l_toDelete.end())) {
+        LogError("lack of recipient to delete from main variable");
+        Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+    }
+    //delete recipients
+    vector<string>::const_iterator it = l_toDelete.begin();
+    const vector<string>::const_iterator endIt = l_toDelete.end();
+    while (it != endIt) {
+        m_recipients.erase(
+            remove(m_recipients.begin(),
+                   m_recipients.end(), *it), m_recipients.end());
+        ++it;
+    }
+    m_validRecipients = false;
+    return *this;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/Recipient.h b/src/platform/API/Messaging/Recipient.h
new file mode 100755 (executable)
index 0000000..f1a94c7
--- /dev/null
@@ -0,0 +1,107 @@
+//
+// 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 RECIPIENT_H
+#define RECIPIENT_H
+
+#include "IMessagingTypes.h"
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class Recipients
+{
+  private: // fields
+
+    /**
+     * recipient value
+     */
+    std::vector<std::string> m_recipients;
+
+    bool m_validRecipients;
+
+  public: // methods
+
+    Recipients();
+
+    explicit Recipients(const std::vector<std::string>& value);
+
+    virtual ~Recipients();
+
+    /**
+     * information if abstract message to recipient has been changed and
+     * need update in low level
+     */
+    bool isValid() const;
+
+    void setValid(bool state);
+
+    /**
+     * setter of recipient value
+     */
+    void setRecipients(const std::vector<std::string>& value);
+
+    void setRecipients(const std::string& value);
+
+    void setRecipient(const size_t index,
+            const std::string& value);
+
+    void setRecipientWithExpand(const size_t index,
+            const std::string& value);
+
+    /**
+     * getter of recipient value
+     */
+    std::vector<std::string> getRecipients() const;
+
+    const std::vector<std::string>& getRecipientsRef() const;
+
+    std::string getRecipient(const size_t index) const;
+
+    void appendRecipient(const std::string & value);
+
+    void removeRecipient(const size_t position);
+
+    void removeRecipient(const std::string & value);
+
+    size_t getRecipientSize() const;
+
+    bool operator !=(const Recipients& arg) const;
+
+    Recipients & operator +=(const Recipients& val);
+
+    Recipients & operator -=(const Recipients& val);
+
+    std::string join(char delimiter = ';') const;
+
+  private:
+
+    std::vector<std::string> split(const std::string& input,
+            char delimiter);
+};
+
+typedef DPL::SharedPtr<Recipients> RecipientsPtr;
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/ReqReceiverMessage.cpp b/src/platform/API/Messaging/ReqReceiverMessage.cpp
new file mode 100755 (executable)
index 0000000..e148a8e
--- /dev/null
@@ -0,0 +1,856 @@
+//
+// 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 <vector>
+#include <Commons/Exception.h>
+#include "ReqReceiverMessage.h"
+#include "IMessaging.h"
+#include "IMessage.h"
+
+#include "MessageFilterValidatorFactory.h"
+#include "ConversationFilterValidatorFactory.h"
+#include "FolderFilterValidatorFactory.h"
+
+//for email service
+#include <email-types.h>
+#include <email-api.h>
+#include <dpl/singleton_safe_impl.h>
+
+IMPLEMENT_SAFE_SINGLETON(TizenApis::Api::Messaging::ReqReceiverMessage)
+
+using namespace std;
+using namespace TizenApis::Api::Tizen;
+using namespace TizenApis::Platform::Messaging;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+
+ReqReceiverMessage::ReqReceiverMessage() :
+    EventAddDraftMessageReqReceiver(ThreadEnum::MESSAGING_THREAD),     
+//    EventSendMessageReqReceiver(ThreadEnum::MESSAGING_THREAD),
+    EventUpdateMessageReqReceiver(ThreadEnum::MESSAGING_THREAD),
+//    EventDeleteMessageReqReceiver(ThreadEnum::MESSAGING_THREAD),
+    EventDeleteMessagesReqReceiver(ThreadEnum::MESSAGING_THREAD),
+    EventUpdateMessagesReqReceiver(ThreadEnum::MESSAGING_THREAD),
+    EventQueryMessagesReqReceiver(ThreadEnum::MESSAGING_THREAD),
+    EventGetConversationIdReqReceiver(ThreadEnum::MESSAGING_THREAD),
+    EventQueryConversationsReqReceiver(ThreadEnum::MESSAGING_THREAD),
+    EventDeleteConversationsReqReceiver(ThreadEnum::MESSAGING_THREAD),
+    EventQueryFoldersReqReceiver(ThreadEnum::MESSAGING_THREAD),
+    EventMessagingServiceReqReceiver(ThreadEnum::MESSAGING_THREAD)
+{
+    LogDebug("create receiver for messaging");
+}
+
+ReqReceiverMessage::~ReqReceiverMessage()
+{
+}
+
+void ReqReceiverMessage::addDraftMessage(const EventAddDraftMessagePtr& event)
+{
+    LogDebug("enter");
+    EventAddDraftMessageReqReceiver::PostRequest(event);
+}
+/*
+void ReqReceiverMessage::sendMessage(const EventSendMessagePtr& event)
+{
+    LogDebug("enter");
+    EventSendMessageReqReceiver::PostRequest(event);
+}
+*/
+void ReqReceiverMessage::sendMessage(const EventMessagingServicePtr& event)
+{
+    LogDebug("enter");
+    EventMessagingServiceReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::updateMessage(const EventUpdateMessagePtr& event)
+{
+    LogDebug("enter");
+    EventUpdateMessageReqReceiver::PostRequest(event);
+}
+
+/*
+void ReqReceiverMessage::deleteMessage(const EventDeleteMessagePtr& event)
+{
+    LogDebug("enter");
+    EventDeleteMessageReqReceiver::PostRequest(event);
+}
+*/
+
+void ReqReceiverMessage::deleteMessages(const EventDeleteMessagesPtr& event)
+{
+    LogDebug("enter");
+    EventDeleteMessagesReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::updateMessages(const EventUpdateMessagesPtr& event)
+{
+    LogDebug("enter");
+    EventUpdateMessagesReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::queryMessages(const EventQueryMessagesPtr& event)
+{
+    LogDebug("enter");
+    EventQueryMessagesReqReceiver::PostRequest(event);
+}
+
+
+void ReqReceiverMessage::getConversationId(const EventGetConversationIdPtr& event)
+{
+       LogDebug("enter");
+       EventGetConversationIdReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::queryConversations(const EventQueryConversationsPtr& event)
+{
+       LogDebug("enter");
+       EventQueryConversationsReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::deleteConversations(const EventDeleteConversationsPtr& event)
+{
+       LogDebug("enter");
+       EventDeleteConversationsReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::queryFolders(const EventQueryFoldersPtr& event)
+{
+       LogDebug("enter");
+       EventQueryFoldersReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::loadMessageBody(const EventMessagingServicePtr& event)
+{
+       LogDebug("enter");
+       EventMessagingServiceReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::loadMessageAttachment(const EventMessagingServicePtr& event)
+{
+       LogDebug("enter");
+       EventMessagingServiceReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::sync(const EventMessagingServicePtr& event)
+{
+       LogDebug("enter");
+       EventMessagingServiceReqReceiver::PostRequest(event);
+}
+
+void ReqReceiverMessage::syncFolder(const EventMessagingServicePtr& event)
+{
+       LogDebug("enter");
+
+       if (event && event->m_messagingService && event->m_messagingService->getAccountID() > 0)
+       {
+               //check pop3 folder
+               email_account_t* accounts = NULL;
+               if (email_get_account( event->m_messagingService->getAccountID(), GET_FULL_DATA, &accounts)) 
+               {       
+               
+                       if (accounts == NULL) {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't get accounts");
+                       }
+                       
+                       LogDebug("accounts[0].incoming_server_type = " << accounts[0].incoming_server_type);
+                       LogDebug("m_folder_name = " << event->m_folder_name);
+                       if ( accounts[0].incoming_server_type == EMAIL_SERVER_TYPE_POP3 && event->m_folder_name != "INBOX" )
+                       {
+                               LogDebug("Can't Sync Folder because POP3 spec.");
+                               ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Operation Type is mismatched");
+                       }
+               }
+               if (accounts != NULL) 
+               {
+                       email_free_account(&accounts, 1);
+               }               
+       }
+       
+       EventMessagingServiceReqReceiver::PostRequest(event);
+}
+
+
+bool ReqReceiverMessage::validateFilter(const Tizen::FilterPtr& filter){
+       LogDebug("<<<");
+
+       bool retBool = false;
+
+       if(filter != NULL){
+               MessageFilterValidatorPtr validator =
+                               MessageFilterValidatorFactory::getMessageFilterValidator();
+
+               FilterValidatorPtr filterValidator = DPL::StaticPointerCast<FilterValidator>(validator);
+               retBool = filter->validate(filterValidator);
+               LogDebug("retBool:" << retBool);
+               if(retBool == false){
+                       MsgLogError(">>> Validate FAIL InvalidArgumentException");
+                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               }
+       }else{
+               LogDebug("filter is NULL");
+               retBool = false;
+       }
+
+       LogDebug(">>> retBool:" << retBool);
+       return retBool;
+
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventAddDraftMessagePtr& event)
+{
+    LogDebug("enter");
+
+    Try {
+        IMessagePtr msg = event->msg;
+        if (!event->checkCancelled()) {
+            event->setCancelAllowed(false);
+               email_account_t* accounts = NULL;
+               int count = 0;
+               if (msg->getMessageType() == Api::Messaging::EMAIL )
+               {       
+                       Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                       Try {
+                                                               
+                               if (email_get_account_list(&accounts, &count)) {
+                                       if (0 < count)
+                                       {
+                                               int index = (int)event->getIndex();
+                                               Api::Messaging::EmailAccountInfo account(accounts[index-1].account_id,
+                                                                                                           accounts[index-1].incoming_server_user_name,
+                                                                                                           accounts[index-1].user_email_address );                                             
+                                               email->setEmailAccount(account);
+                                       }
+                                       if (accounts != NULL) {
+                                               email_free_account(&accounts, count);
+                                       }
+                               }               
+                       }
+                       Catch(WrtDeviceApis::Commons::PlatformException) {
+                               if (accounts != NULL) {
+                                       email_free_account(&accounts, count);
+                               }
+                               MsgLogError("platform exception");
+                               Throw(WrtDeviceApis::Commons::PlatformException);
+               }
+                                               
+                               
+               }
+
+                  msg->addMessageToDraft();
+        } else {
+            event->setCancelAllowed(true);
+        }
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        MsgLogError("platform exception");
+        event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+    }
+
+}
+/*
+void ReqReceiverMessage::OnRequestReceived(const EventSendMessagePtr& event)
+{
+    LogDebug("enter");
+
+    Try {
+               IMessagePtr msg = event->msg;
+               //this prevents calling BONDI, Tizen callback immidiately after leaving this function
+               //callback will be called after receving platform callback.
+               msg->setRequestReceiver(this);
+               msg->setSendMessageEvent(event);
+               if (!event->checkCancelled()) {
+                       event->setCancelAllowed(false);
+                       event->switchToManualAnswer();
+                       if (msg->getMessageStatus() == Api::Messaging::MESSAGE_STATUS_CREATED ) //create message.
+                       {
+                               //add draft Message
+                               if (msg->getMessageType() == Api::Messaging::EMAIL )
+                               {
+                                       Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                                       email->setEmailAccount(event->m_messagingService->getCurrentEmailAccount());
+                               }
+                               
+                               msg->addMessageToDraft();       //save 
+                               
+                               LogDebug("Message Status = " << msg->getMessageStatus());
+                               LogDebug("Message ID = " << msg->getId());
+                       }
+                       
+                       int handle = msg->send();
+                       LogDebug("handle : " << handle);
+                       if (event->opId && event->m_messagingService)
+                       {
+                               event->m_messagingService->setHandleToOpId(event->opId, handle);
+                       }
+               } else {
+                       event->setCancelAllowed(true);
+               }
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+        WrtDeviceApis::Commons::EventRequestReceiver<EventSendMessage>::ManualAnswer(event);
+    }
+}
+*/
+void ReqReceiverMessage::OnRequestReceived(const EventUpdateMessagePtr& event)
+{
+    LogDebug("enter");
+
+    Try {
+        IMessagePtr msg = event->msg;
+        if (!event->checkCancelled()) {
+            event->setCancelAllowed(false);
+            msg->update(true);
+        } else {
+            event->setCancelAllowed(true);
+        }
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        MsgLogError("platform exception");
+        event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+    }
+}
+/*
+void ReqReceiverMessage::OnRequestReceived(const EventDeleteMessagePtr& event)
+{
+    LogDebug("enter");
+
+    Try {
+        IMessagePtr msg = event->msg;
+        msg->remove();
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        MsgLogError("platform exception");
+        event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+    }
+}
+*/
+
+
+void ReqReceiverMessage::OnRequestReceived(const EventDeleteMessagesPtr& event)
+{
+       LogDebug("enter");
+
+       Try {
+/*
+               Tizen::FilterPtr filter = event->getFilter();
+               if(filter != NULL){
+                       bool isValidFilter = validateFilter(filter);
+                       if(isValidFilter == false){
+                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                       }
+
+                       event->msgArray = IMessaging::getInstance().findMessages(event->getFilter());
+               }
+*/
+               std::vector<Api::Messaging::IMessagePtr> msg = event->msgArray;
+               LogDebug("msg.size()" << msg.size());
+
+               int vecSize = msg.size();
+               for(int i=0; i < vecSize; i++){
+                       int type = msg[i]->getMessageType();
+                       std::string id = msg[i]->getId();
+                       MsgLogError("type :"<<type);
+                       MsgLogError("id :"<<id);
+                       MsgLogError("body" << msg[i]->getBody());
+                       msg[i]->remove();
+               }//for
+       }Catch(WrtDeviceApis::Commons::PlatformException) {
+               MsgLogError("platform exception");
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+       }
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventUpdateMessagesPtr& event)
+{
+    LogDebug("enter");
+
+    Try {
+        std::vector<Api::Messaging::IMessagePtr> msg = event->msgArray;
+        LogDebug("msg.size()" << msg.size());
+        int vecSize = msg.size();
+        for(int i=0; i < vecSize; i++)
+        {
+//            int type = msg[i]->getMessageType();
+            std::string id = msg[i]->getId();
+            msg[i]->updateMessage();                   
+//            msg[i]->updateIsRead();                  
+        }
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        MsgLogError("platform exception");
+        event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+    }
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventQueryMessagesPtr& event)
+{
+    LogDebug("<<<");
+
+       Try {
+
+               vector<IMessagePtr> msgs;
+               vector<IMessagePtr> tmp;
+
+               //check filter validation
+               Tizen::FilterPtr filter = event->getFilter();
+               bool isValidFilter = validateFilter(filter);
+               if(isValidFilter == false){
+                       MsgLogError("[ERROR]this filter is invalid");
+                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               }
+
+               // using filter
+               LogDebug("event->getType() = " << event->getType());
+               if(event->getType() > Api::Messaging::UNKNOWN)
+               {
+                       tmp = IMessaging::getInstance().findMessages(event->getFilter(), event->getSortMode(), event->getLimit(), event->getOffset(), event->getType());
+               }
+               else
+               {
+                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               }
+
+               msgs.insert(msgs.end(), tmp.begin(), tmp.end());
+               event->msgs = msgs;
+
+       }Catch(WrtDeviceApis::Commons::PlatformException) {
+               MsgLogError("platform exception");
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+       }Catch(WrtDeviceApis::Commons::InvalidArgumentException){
+               MsgLogError("InvalidArgumentException");
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException);
+       }
+       Catch (exception) {
+               MsgLogError("platform exception");
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+       }
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventGetConversationIdPtr& event)
+{
+       LogDebug("enter");
+
+       Try {
+               Api::Messaging::IMessagePtr msg = event->getConversationMsgPtr();
+               Api::Messaging::MessageType msgType = msg->getMessageType();
+               unsigned int msgId = 0;
+
+               if (msgType == EMAIL)
+               {
+                       Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                       msgId = email->getUID();
+
+               }
+               else
+               {
+                       msgId = msg->convertId(msg->getId());
+               }
+
+               int conversationId = IMessaging::getInstance().getConversationId(msgId, msgType);
+               LogDebug("Cond Id:" << conversationId);
+               event->setConversationId(conversationId);
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               MsgLogError("platform exception");
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+       }
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventQueryConversationsPtr& event)
+{
+       LogDebug("<<<");
+
+       Try
+       {
+               //check filter validation
+               Tizen::FilterPtr filter = event->getFilter();
+               vector<IConversationPtr> tmp;
+               if(filter != NULL){
+                       ConversationFilterValidatorPtr validator =
+                                       ConversationFilterValidatorFactory::getConversationFilterValidator();
+
+                       FilterValidatorPtr filterValidator = DPL::StaticPointerCast<FilterValidator>(validator);
+                       bool isValidFilter = filter->validate(filterValidator);
+                       if(isValidFilter == false){
+                               MsgLogError("[ERROR]Filter is Invalid");
+                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                       }
+               }
+               LogDebug("event->getType() = "<<event->getType());
+               if(event->getType() > Api::Messaging::UNKNOWN)
+               {
+                       tmp = IMessaging::getInstance().queryConversations(event->getFilter(), event->getSortMode(), event->getType(), event->getLimit(), event->getOffset());
+               }
+               else
+               {
+//                     LogDebug("enter");              
+//                     tmp = IMessaging::getInstance().queryConversations(event->getSortMode(), event->getFilter(), event->getLimit(), event->getOffset());
+                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               }               
+               
+               event->addConversations(tmp);
+
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException)
+       {
+               MsgLogError("platform exception");
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+       }
+       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+       {
+               MsgLogError("InvalidArgumentException");
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException);
+       }
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventMessagingServicePtr& event)
+{
+    LogDebug("enter : EventMessagingServicePtr");
+
+    Try {
+               LogDebug("event type :" << event->getEventType() );
+               int MessagingServiceEventType = event->getEventType();
+
+               if (MessagingServiceEventType == MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY)
+               {
+                       if (!event->checkCancelled()) {
+                               IMessagePtr msg = event->m_message;
+                               if(msg)
+                               {
+       
+                                       msg->setRequestReceiver(this);
+                                       msg->setMessagingServiceEvent(event);
+
+                                       int type = msg->getMessageType();
+                                       LogDebug("message type :" << type);
+                                       if ( msg->getMessageType() == Api::Messaging::EMAIL )
+                                       {
+                                               IEmailPtr email = MessageFactory::convertToEmail(msg);
+                                               event->switchToManualAnswer();          //switch to manual answer;
+                                               int handle = email->downloadBody();
+                                               LogDebug("Load Message Body handle : " << handle);
+                                               if (event->opId && event->m_messagingService)
+                                               {
+                                                       event->m_messagingService->setHandleToOpId(event->opId, handle);
+                                               }
+                                               if (handle > 0)
+                                               {
+                                                       event->setHandle(handle);       //set handle
+                                               }                                               
+                                       }
+                               }
+                               else {
+                               LogDebug(" invaild message. ");
+                                       event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException);
+                               }
+
+                       }
+                       else
+                       {
+                               LogDebug(" Cancel ");
+                               event->setCancelAllowed(true);
+                       }
+               }
+
+               else if (MessagingServiceEventType == MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT)
+               {
+                       if (!event->checkCancelled()) {
+                               IMessagePtr msg = event->m_message;
+                               if(msg)
+                               {
+                                       msg->setRequestReceiver(this);
+                                       msg->setMessagingServiceEvent(event);
+
+                                       int type = msg->getMessageType();
+                                       LogDebug("message type :" << type);
+                                       if ( msg->getMessageType() == Api::Messaging::EMAIL )
+                                       {
+                                               IEmailPtr email = MessageFactory::convertToEmail(msg);
+                                               event->switchToManualAnswer();          //switch to manual answer;
+                                               int handle = email->downloadAttachment(event->m_attachment);
+                                               LogDebug("Load Message Attachment handle : " << handle);
+                                               if (event->opId && event->m_messagingService)
+                                               {
+                                                       event->m_messagingService->setHandleToOpId(event->opId, handle);
+                                               }
+                                               if (handle > 0)
+                                               {
+                                                       event->setHandle(handle);       //set handle
+                                               }                                               
+                                       }
+                                       else
+                                       {
+                                               LogDebug(" invaild message. ");
+                                               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException);
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               LogDebug(" cancel. ");
+                               event->setCancelAllowed(true);
+                       }
+
+               }
+
+               else if (MessagingServiceEventType == MESSAGING_SERVICE_EVENT_TYPE_SYNC)
+               {
+                       if (event->m_messagingService)
+                       {
+                               if (!event->checkCancelled()) {
+                                       int type = event->m_messagingService->getType();
+                                       LogDebug("messaging service type :" << type);
+
+                                       event->m_messagingService->setRequestReceiver(this);
+                                       event->m_messagingService->setMessagingServiceEvent(event);     //
+
+                                       if (type == Api::Messaging::EMAIL)
+                                       {
+                                               event->switchToManualAnswer(); //switch to manual answer;
+                                               LogDebug("privateData->getAccountId() :" << event->m_messagingService->getAccountID());
+
+                                               if ( event->m_messagingService->getAccountID() > 0)
+                                               {
+                                                       int handle = event->m_messagingService->sync( event->m_messagingService, event->m_sync_limit );
+                                                       LogDebug("Sync handle : " << handle);
+                                                       if (event->opId && event->m_messagingService)
+                                                       {
+                                                               event->m_messagingService->setHandleToOpId(event->opId, handle);
+                                                       }
+                                                       if (handle > 0)
+                                                       {
+                                                               event->setHandle(handle);       //set handle
+                                                       }
+
+                                               }
+                                               else
+                                                       event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException);
+                                       }
+                                       else
+                                       {
+                                               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException);
+                                       }
+                               }
+                               else
+                               {
+                                       LogDebug(" cancel. ");
+                                       event->setCancelAllowed(true);
+                               }
+                       }
+
+               }
+               else if (MessagingServiceEventType == MESSAGING_SERVICE_EVENT_TYPE_SYNC_FOLDER)
+               {
+                       if (event->m_messagingService)
+                       {
+                               if (!event->checkCancelled()) {
+                                       int type = event->m_messagingService->getType();
+                                       LogDebug("messaging service type :" << type);
+
+                                       event->m_messagingService->setRequestReceiver(this);
+                                       event->m_messagingService->setMessagingServiceEvent(event);                                             
+                                       if (type == Api::Messaging::EMAIL)
+                                       {
+                                               event->switchToManualAnswer(); //switch to manual answer;
+                                               LogDebug("privateData->getAccountId() :" << event->m_messagingService->getAccountID());
+
+                                               if ( event->m_messagingService->getAccountID() > 0)
+                                               {
+                                                       int handle = event->m_messagingService->syncFolder( event->m_messagingService, event->m_sync_folder_id, event->m_sync_limit);
+                                                       LogDebug("Sync Folder handle : " << handle);
+                                                       if (event->opId && event->m_messagingService)
+                                                       {
+                                                               event->m_messagingService->setHandleToOpId(event->opId, handle);
+                                                       }
+                                                       if (handle > 0)
+                                                       {
+                                                               event->setHandle(handle);       //set handle
+                                                       }
+                                               }
+                                               else
+                                                       event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException);
+                                       }
+                                       else
+                                       {
+                                               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException);
+                                       }
+                               }
+                               else
+                               {
+                                       LogDebug(" cancel. ");
+                                       event->setCancelAllowed(true);
+                               }
+                       }
+               }
+               else if (MessagingServiceEventType == MESSAGING_SERVICE_EVENT_TYPE_SEND_MESSAGE)
+               {
+                       IMessagePtr msg = event->m_message;
+                       msg->setRequestReceiver(this);
+                       msg->setMessagingServiceEvent(event);
+                       if (!event->checkCancelled()) 
+                       {
+
+                               if (msg->getMessageStatus() == Api::Messaging::MESSAGE_STATUS_CREATED ) //create message.
+                               {
+                                       //if draft Message.
+                                       if (msg->getMessageType() == Api::Messaging::EMAIL )
+                                       {
+                                               Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                                               email->setEmailAccount(event->m_messagingService->getCurrentEmailAccount());
+                                       }
+                                       
+                                       msg->createSendMessage();
+                                       LogDebug("Message Status = " << msg->getMessageStatus());
+                                       LogDebug("Message ID = " << msg->getId());
+                               }
+                               event->switchToManualAnswer();
+
+                               int handle = msg->send();
+                               LogDebug("handle : " << handle);
+                               if (event->opId && event->m_messagingService)
+                               {
+                                       event->m_messagingService->setHandleToOpId(event->opId, handle);
+                               }
+
+                               if (handle > 0)
+                               {
+                                       event->setHandle(handle);       //set handle
+                               }
+                               
+                       }       
+
+               }
+               else
+               {
+                       LogDebug(" Cancel ");
+                       event->setCancelAllowed(true);
+               }
+
+    }
+    Catch (WrtDeviceApis::Commons::PlatformException) {
+         MsgLogError("platform exception");
+        event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+    }
+    Catch (WrtDeviceApis::Commons::ConversionException) {
+         MsgLogError("conversion exception");
+        event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::ConversionException);
+    }
+
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventDeleteConversationsPtr& event)
+{
+       LogDebug("enter");
+
+       Try
+       {/*
+                       if (event->isFilterUsing())
+                       {
+                               LogDebug("filter use");
+
+                               //check filter validation
+                               FilterPtr filter = event->getFilter();
+                               if(filter != NULL)
+                               {
+                                       ConversationFilterValidatorPtr validator =
+                                               ConversationFilterValidatorFactory::getConversationFilterValidator();
+
+
+                                       FilterValidatorPtr filterValidator = DPL::StaticPointerCast<FilterValidator>(validator);
+                                       bool isValidFilter = filter->validate(filterValidator);
+
+                                       if(isValidFilter == false)
+                                       {
+                                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                                       }
+                               }
+
+                               if (IMessaging::getInstance().deleteConversations(event->getSortMode(), event->getFilter()) == false)
+                               {
+                                       Throw(WrtDeviceApis::Commons::PlatformException);
+                               }
+                                       //.queryConversations(event->getSortMode(), event->getFilter());
+                       }
+                       else*/
+                       {
+                               LogDebug("no filter");
+
+                               if (IMessaging::getInstance().deleteConversations(event->getConversations()) == false)
+                               {
+                                       Throw(WrtDeviceApis::Commons::PlatformException);
+                               }
+                       }
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException)
+       {
+               MsgLogError("platform exception");
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+       }
+       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+       {
+               MsgLogError("InvalidArgumentException");
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException);
+       }
+}
+
+void ReqReceiverMessage::OnRequestReceived(const EventQueryFoldersPtr& event)
+{
+       LogDebug("enter");
+
+       Try
+       {
+
+               //check filter validation
+               Tizen::FilterPtr filter = event->getFilter();
+               if(filter != NULL){
+                       FolderFilterValidatorPtr validator =
+                                       FolderFilterValidatorFactory::getFolderFilterValidator();
+
+                       FilterValidatorPtr filterValidator = DPL::StaticPointerCast<FilterValidator>(validator);
+
+                       bool isValidFilter = filter->validate(filterValidator);
+                       if(isValidFilter == false){
+                               MsgLogError("[ERROR]Filter is Invalid");
+                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                       }
+                       
+               }
+
+               vector<IMessageFolderPtr> tmp = IMessaging::getInstance().queryFolders(event->getFilter());
+               event->addFolders(tmp);
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException)
+       {
+               MsgLogError("platform exception");
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+       }
+       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+       {
+               MsgLogError("InvalidArgumentException");
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException);
+       }
+}
+
+}
+}
+}
diff --git a/src/platform/API/Messaging/ReqReceiverMessage.h b/src/platform/API/Messaging/ReqReceiverMessage.h
new file mode 100755 (executable)
index 0000000..000a00b
--- /dev/null
@@ -0,0 +1,151 @@
+//
+// 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 REQRECEIVERMESSAGE_H
+#define REQRECEIVERMESSAGE_H
+
+#include <dpl/singleton.h>
+
+#include "EventAddDraftMessage.h"
+#include "EventSendMessage.h"
+#include "EventUpdateMessage.h"
+//#include "EventDeleteMessage.h"
+#include "EventDeleteMessages.h"
+#include "EventUpdateMessages.h"
+#include "EventQueryMessages.h"
+#include "EventGetConversationId.h"
+#include "EventQueryConversations.h"
+#include "EventQueryFolders.h"
+#include "EventDeleteConversations.h"
+#include "EventMessagingService.h"
+
+#include "log.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+typedef WrtDeviceApis::Commons::EventRequestReceiver<EventAddDraftMessage>
+EventAddDraftMessageReqReceiver;
+//typedef WrtDeviceApis::Commons::EventRequestReceiver<EventSendMessage>
+//EventSendMessageReqReceiver;
+typedef WrtDeviceApis::Commons::EventRequestReceiver<EventUpdateMessage>
+EventUpdateMessageReqReceiver;
+//typedef WrtDeviceApis::Commons::EventRequestReceiver<EventDeleteMessage>
+//EventDeleteMessageReqReceiver;
+typedef WrtDeviceApis::Commons::EventRequestReceiver<EventDeleteMessages>
+EventDeleteMessagesReqReceiver;
+typedef WrtDeviceApis::Commons::EventRequestReceiver<EventUpdateMessages>
+EventUpdateMessagesReqReceiver;
+typedef WrtDeviceApis::Commons::EventRequestReceiver<EventQueryMessages>
+EventQueryMessagesReqReceiver;
+typedef WrtDeviceApis::Commons::EventRequestReceiver<EventGetConversationId>
+EventGetConversationIdReqReceiver;
+typedef WrtDeviceApis::Commons::EventRequestReceiver<EventQueryConversations>
+EventQueryConversationsReqReceiver;    
+typedef WrtDeviceApis::Commons::EventRequestReceiver<EventDeleteConversations>
+EventDeleteConversationsReqReceiver;
+typedef WrtDeviceApis::Commons::EventRequestReceiver<EventQueryFolders>
+EventQueryFoldersReqReceiver;  
+typedef WrtDeviceApis::Commons::EventRequestReceiver<EventMessagingService>
+EventMessagingServiceReqReceiver;      
+class ReqReceiverMessage : public EventAddDraftMessageReqReceiver,
+//  public EventSendMessageReqReceiver,        
+    public EventUpdateMessageReqReceiver,
+//    public EventDeleteMessageReqReceiver,
+    public EventDeleteMessagesReqReceiver,
+    public EventUpdateMessagesReqReceiver, 
+    public EventQueryMessagesReqReceiver,
+    public EventGetConversationIdReqReceiver,
+    public EventQueryConversationsReqReceiver,
+    public EventDeleteConversationsReqReceiver,
+    public EventQueryFoldersReqReceiver,    
+    public EventMessagingServiceReqReceiver
+{
+       private:
+               bool validateFilter(const Tizen::FilterPtr& filter);
+
+  public:
+    ReqReceiverMessage();
+
+    virtual ~ReqReceiverMessage();
+
+    void addDraftMessage(const EventAddDraftMessagePtr& event);
+
+//    void sendMessage(const EventSendMessagePtr& event);
+
+    void sendMessage(const EventMessagingServicePtr& event);
+
+    void updateMessage(const EventUpdateMessagePtr& event);
+
+//    void deleteMessage(const EventDeleteMessagePtr& event);
+
+    void deleteMessages(const EventDeleteMessagesPtr& event);  
+
+    void updateMessages(const EventUpdateMessagesPtr& event);
+
+    void queryMessages(const EventQueryMessagesPtr& event);
+
+    void getConversationId(const EventGetConversationIdPtr& event);
+
+    void queryConversations(const EventQueryConversationsPtr& event);
+
+    void deleteConversations(const EventDeleteConversationsPtr& event);
+
+    void queryFolders(const EventQueryFoldersPtr& event);
+
+    void loadMessageBody(const EventMessagingServicePtr& event);
+
+    void loadMessageAttachment(const EventMessagingServicePtr& event);
+       
+    void sync(const EventMessagingServicePtr& event);
+
+    void syncFolder(const EventMessagingServicePtr& event);
+
+               
+  protected:
+
+    void OnRequestReceived(const EventAddDraftMessagePtr& event);
+
+//    void OnRequestReceived(const EventSendMessagePtr& event);
+
+    void OnRequestReceived(const EventUpdateMessagePtr& event);
+
+//    void OnRequestReceived(const EventDeleteMessagePtr& event);
+
+    void OnRequestReceived(const EventDeleteMessagesPtr& event);
+
+    void OnRequestReceived(const EventUpdateMessagesPtr& event);
+
+    void OnRequestReceived(const EventQueryMessagesPtr& event);
+
+    void OnRequestReceived(const EventGetConversationIdPtr& event);    
+
+    void OnRequestReceived(const EventQueryConversationsPtr& event);
+
+    void OnRequestReceived(const EventDeleteConversationsPtr& event);
+
+    void OnRequestReceived(const EventQueryFoldersPtr& event);
+
+    void OnRequestReceived(const EventMessagingServicePtr& event);     
+};
+
+typedef DPL::Singleton<ReqReceiverMessage> ReqReceiverMessageSingleton;
+}
+}
+}
+#endif // REQRECEIVERMESSAGE_H
diff --git a/src/platform/API/Messaging/SourceAddress.cpp b/src/platform/API/Messaging/SourceAddress.cpp
new file mode 100755 (executable)
index 0000000..4c78134
--- /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.
+//
+
+#include <dpl/log/log.h>
+#include "Commons/Exception.h"
+#include "SourceAddress.h"
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+SourceAddress::SourceAddress() :
+    m_validSourceAddress(false)
+{
+}
+
+SourceAddress::~SourceAddress()
+{
+}
+
+void SourceAddress::setSourceAddressValidity(bool state)
+{
+    m_validSourceAddress = state;
+}
+
+bool SourceAddress::getSourceAddressValidity() const
+{
+    return m_validSourceAddress;
+}
+
+std::string SourceAddress::getSourceAddress() const
+{
+    return m_sourceAddress;
+}
+
+void SourceAddress::setSourceAddress(const Recipients& value)
+{
+    if (value.getRecipientSize() != 1) {
+        LogError("wrong source address value");
+        Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+    }
+    m_sourceAddress = value.getRecipient(0);
+    m_validSourceAddress = false;
+}
+
+void SourceAddress::setSourceAddress(const std::string& value)
+{
+    m_sourceAddress = value;
+    m_validSourceAddress = false;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/SourceAddress.h b/src/platform/API/Messaging/SourceAddress.h
new file mode 100755 (executable)
index 0000000..8df5d33
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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 SOURCEADDRESS_H
+#define SOURCEADDRESS_H
+
+#include "Recipient.h"
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class SourceAddress
+{
+  private: // fields
+
+    std::string m_sourceAddress;
+
+    bool m_validSourceAddress;
+
+  public:
+
+    SourceAddress();
+
+    virtual ~SourceAddress();
+
+    void setSourceAddressValidity(bool state);
+
+    bool getSourceAddressValidity() const;
+
+    std::string getSourceAddress() const;
+
+    void setSourceAddress(const Recipients& value);
+
+    void setSourceAddress(const std::string& value);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/StorageChangesConversationFilterValidator.cpp b/src/platform/API/Messaging/StorageChangesConversationFilterValidator.cpp
new file mode 100755 (executable)
index 0000000..f8ca417
--- /dev/null
@@ -0,0 +1,71 @@
+//
+// 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 "StorageChangesConversationFilterValidator.h"
+#include "StorageChangesConversationFilterValidatorFactory.h"
+
+#include <dpl/log/log.h>
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               StorageChangesConversationFilterValidator::StorageChangesConversationFilterValidator(PropertyStructArray properties)
+                               :FilterValidator(properties){
+                       m_isTypeSetted = false;
+               }
+
+               StorageChangesConversationFilterValidator::~StorageChangesConversationFilterValidator(){
+               }
+
+               bool StorageChangesConversationFilterValidator::validateAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue,
+                               Api::Tizen::AnyPtr& endValue, int depth){
+
+                       if(initialValue == NULL || endValue == NULL)
+                               return false;
+
+                       bool retVal = false;
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP)!=0){
+                               LogError(">>> [ERROR] Not Supported attribute :[" << attrName << "]");
+                               return false;
+                       }
+
+                       retVal = FilterValidator::validateAttributeRange(attrName, initialValue, endValue);
+                       return retVal;
+               }
+
+               bool StorageChangesConversationFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                               Api::Tizen::AnyPtr& matchValue, int depth){
+
+                       if(matchValue == NULL)
+                               return false;
+
+                       bool retBool = false;
+
+                       retBool = FilterValidator::validateAttribute(attrName, matchFlag, matchValue, depth);
+                       LogDebug(">>> retBool:" << retBool);
+                       return retBool;
+               }
+
+       }
+       }
+
+}
diff --git a/src/platform/API/Messaging/StorageChangesConversationFilterValidator.h b/src/platform/API/Messaging/StorageChangesConversationFilterValidator.h
new file mode 100755 (executable)
index 0000000..4370721
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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 STORAGECHANGESCONVERSATIONATOR_H_
+#define STORAGECHANGESCONVERSATIONATOR_H_
+
+#include <API/Filter/FilterValidator.h>
+
+
+namespace TizenApis {
+
+       namespace Platform {
+
+               namespace Messaging {
+
+               class StorageChangesConversationFilterValidator: public Api::Tizen::FilterValidator {
+                       private:
+                               bool m_isTypeSetted;
+
+                       public:
+                       StorageChangesConversationFilterValidator(Api::Tizen::PropertyStructArray properties);
+
+                               virtual ~StorageChangesConversationFilterValidator();
+
+                               // validate AttributeRangeFilter
+                                       virtual bool validateAttributeRange(std::string& attrName,
+                                                       Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0);
+
+                                       virtual bool validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                                                       Api::Tizen::AnyPtr& matchValue, int depth=0);
+
+
+
+               };
+
+               typedef DPL::SharedPtr<StorageChangesConversationFilterValidator> StorageChangesConversationFilterValidatorPtr;
+       }
+}
+       }
+
+#endif 
diff --git a/src/platform/API/Messaging/StorageChangesConversationFilterValidatorFactory.cpp b/src/platform/API/Messaging/StorageChangesConversationFilterValidatorFactory.cpp
new file mode 100755 (executable)
index 0000000..44b8834
--- /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.
+//
+
+#include "StorageChangesConversationFilterValidatorFactory.h"
+
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_ID             = "id";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_TYPE             = "type";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP        = "timestamp";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT    = "messageCount";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_UNREAD_MESSAGES  = "unreadMessages";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW          = "preview";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_SUBJECT          = "subject";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_IS_READ          = "isRead";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_FROM             = "from";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_TO               = "to";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_CC               = "cc";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_BCC              = "bcc";
+               const std::string StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_LAST_MESSAGE_ID  = "lastMessageId";
+
+               static PropertyStructArray properties =
+               {
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_ID.c_str(),                           Api::Tizen::PrimitiveType_String},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_TYPE.c_str(),             Api::Tizen::PrimitiveType_String},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP.c_str(), Api::Tizen::PrimitiveType_Time},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT.c_str(),    Api::Tizen::PrimitiveType_Number},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_UNREAD_MESSAGES.c_str(),  Api::Tizen::PrimitiveType_Number},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW.c_str(),          Api::Tizen::PrimitiveType_String},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_SUBJECT.c_str(),          Api::Tizen::PrimitiveType_String},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_IS_READ.c_str(),          Api::Tizen::PrimitiveType_Number},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_FROM.c_str(),             Api::Tizen::PrimitiveType_String},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_TO.c_str(),               Api::Tizen::PrimitiveType_String},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_CC.c_str(),               Api::Tizen::PrimitiveType_String},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_BCC.c_str(),              Api::Tizen::PrimitiveType_String},
+                               {StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_LAST_MESSAGE_ID.c_str(),  Api::Tizen::PrimitiveType_String},                               
+                               {0,                  Api::Tizen::PrimitiveType_NoType}
+               };
+
+               StorageChangesConversationFilterValidatorPtr StorageChangesConversationFilterValidatorFactory::getStorageChangesConversationFilterValidator()
+               {
+                   static StorageChangesConversationFilterValidatorPtr theInstance =
+                               StorageChangesConversationFilterValidatorPtr(new StorageChangesConversationFilterValidator(properties));
+
+                   return theInstance;
+               }
+
+               }
+       }       //naspace Platform
+} //naspace WrtPlugins
diff --git a/src/platform/API/Messaging/StorageChangesConversationFilterValidatorFactory.h b/src/platform/API/Messaging/StorageChangesConversationFilterValidatorFactory.h
new file mode 100755 (executable)
index 0000000..351127d
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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 STORAGECHANGESCONVERSATIONFILTERVALIDATORFACTORY_H_
+#define STORAGECHANGESCONVERSATIONFILTERVALIDATORFACTORY_H_
+
+#include <API/Filter/FilterValidator.h>
+#include "StorageChangesConversationFilterValidator.h"
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               class StorageChangesConversationFilterValidatorFactory {
+                       private:
+                               StorageChangesConversationFilterValidatorFactory()
+                               {
+                               }
+
+                       public:
+                               static StorageChangesConversationFilterValidatorPtr getStorageChangesConversationFilterValidator();
+
+                       public:
+                               static const std::string ATTRIBUTE_ID;
+                               static const std::string ATTRIBUTE_TYPE;
+                               static const std::string ATTRIBUTE_TIMESTAMP;
+                               static const std::string ATTRIBUTE_MESSAGE_COUNT;
+                               static const std::string ATTRIBUTE_UNREAD_MESSAGES;
+                               static const std::string ATTRIBUTE_PREVIEW;                             
+                               static const std::string ATTRIBUTE_SUBJECT;
+                               static const std::string ATTRIBUTE_IS_READ;
+                               static const std::string ATTRIBUTE_FROM;
+                               static const std::string ATTRIBUTE_TO;
+                               static const std::string ATTRIBUTE_CC;
+                               static const std::string ATTRIBUTE_BCC;
+                               static const std::string ATTRIBUTE_LAST_MESSAGE_ID;
+               };
+
+               }
+       }               //Platform
+}
+
+#endif /* MESSAGINGFILTERVALIDATORFACTORY_H_ */
diff --git a/src/platform/API/Messaging/StorageChangesConversationGenerator.cpp b/src/platform/API/Messaging/StorageChangesConversationGenerator.cpp
new file mode 100755 (executable)
index 0000000..593d76f
--- /dev/null
@@ -0,0 +1,690 @@
+//
+// 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 "StorageChangesConversationGenerator.h"
+#include "StorageChangesConversationFilterValidatorFactory.h"
+#include "API/Messaging/ConversationFilterValidatorFactory.h"
+
+#include "IMessagingTypes.h"
+
+#include <email-types.h>
+
+#include <dpl/log/log.h>
+#include <algorithm>
+
+using namespace std;
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+
+               const int StorageChangesConversationGenerator::MESSAGE_TYPE_NOT_INITIALIZED = -1;
+
+               StorageChangesConversationGenerator::StorageChangesConversationGenerator(Api::Messaging::IConversationPtr conv):m_messageType(MESSAGE_TYPE_NOT_INITIALIZED) {
+
+                       m_id = conv->getId();
+                       m_type = conv->getType();
+                       m_time = conv->getTime();
+                       m_messageCount = conv->getMessageCount();
+                       m_unreadMessages = conv->getUnreadMessages();
+                       m_preview = conv->getPreview();
+                       m_subject = conv->getSubject();
+                       m_read = conv->getRead();
+                       m_from = conv->getFrom();
+                       m_to = conv->getTo();
+                       m_cc = conv->getCC();
+                       m_bcc = conv->getBCC();
+                       m_lastMessageId = conv->getLastMessageId();
+
+//                     struct tm * timeinfo;
+//                     timeinfo = localtime( &m_time );
+                       
+               }
+
+               StorageChangesConversationGenerator::~StorageChangesConversationGenerator() {
+               }
+
+
+               void StorageChangesConversationGenerator::visitPreComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+                       m_operand.push_back(leftblank);
+                       LogDebug("Left_blank");                 
+                       LogDebug(">>>");
+               }
+
+               void StorageChangesConversationGenerator::visitInComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+                       if(type ==  UNION_FILTER ){
+                               LogDebug("UNION_FILTER");
+                               m_operand.push_back(operandUnion);
+                       }else if(type == INTERSECTION_FILTER){
+                               LogDebug("INTERSECTION_FILTER");
+                               m_operand.push_back(operandIntersection);                               
+                       }else{
+                               LogError("[ERROR] invalid Filter type:" << type);
+                       }
+
+                       LogDebug(">>>");
+               }
+
+               void StorageChangesConversationGenerator::visitPostComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+                       bool data1, data2;
+                       do
+                       {
+                               LogDebug("m_result size =" << m_result.size());
+                               data1 = m_result.back();
+                               m_result.pop_back();
+                               data2 = m_result.back();
+                               m_result.pop_back();
+                               LogDebug("m_result size =" << m_result.size());                         
+                               LogDebug("m_operand.back() =" << m_operand.back());     
+                               LogDebug("m_operand size =" << m_operand.size());                                                               
+                               if(m_operand.back() == operandUnion)
+                               {
+                                       LogDebug("Union");                              
+                                       LogDebug("data1 = " << data1);
+                                       LogDebug("data2 = " << data2);
+                                       LogDebug("data1 || data2 = " << (data1 || data2));                                      
+                                       m_operand.pop_back();
+                                       m_result.push_back(data1 || data2);
+                                       LogDebug("result" << m_result.back());
+                                       LogDebug("m_result size =" << m_result.size());
+                               }
+                               else if(m_operand.back() == operandIntersection)
+                               {
+                                       LogDebug("Intersection");                               
+                                       LogDebug("data1 = " << data1);
+                                       LogDebug("data2 = " << data2);
+                                       LogDebug("data1 && data2 = " << (data1 && data2));                                      
+                                       m_operand.pop_back();                           
+                                       m_result.push_back(data1 && data2);
+                                       LogDebug("result " << m_result.back());
+                                       LogDebug("m_result size =" << m_result.size());                                 
+                                       
+                               }
+                       }while(m_operand.back() != leftblank);
+                       m_operand.pop_back();
+                       LogDebug("elase leftblank from m_operand");
+                       LogDebug("m_operand size =" << m_operand.size());                                                                                       
+                       LogDebug(">>>");
+               }
+
+               struct tm StorageChangesConversationGenerator::convertToTimeFormat(const std::string& timeString){
+                       LogDebug("<<< timeString:[" << timeString << "]");
+
+                       struct tm tm_Time;
+                       memset(&tm_Time, 0, sizeof(tm_Time));
+
+                       int nextStart = 0;
+
+                       int yearLength = 4;
+                       tm_Time.tm_year = atoi(timeString.substr(0, yearLength).c_str())-1900;
+                       nextStart = nextStart + yearLength;
+                       LogDebug("<<< tm_Time.tm_year:[" << tm_Time.tm_year << "]");
+
+                       int monthLength = 2;
+                       tm_Time.tm_mon = atoi(timeString.substr(nextStart, monthLength).c_str());
+                       nextStart = nextStart + monthLength;
+                       LogDebug("<<< initTime.tm_mon:[" << tm_Time.tm_mon << "]");
+
+                       int dateLength = 2;
+                       tm_Time.tm_mday = atoi(timeString.substr(nextStart, dateLength).c_str());
+                       nextStart = nextStart + dateLength;
+                       LogDebug("<<< initTime.tm_mday:[" << tm_Time.tm_mday << "]");
+
+                       int hourLength = 2;
+                       tm_Time.tm_hour = atoi(timeString.substr(nextStart, hourLength).c_str());
+                       nextStart = nextStart + hourLength;
+                       LogDebug("<<< initTime.tm_hour:[" << tm_Time.tm_hour << "]");
+
+                       int minuteLength = 2;
+                       tm_Time.tm_min = atoi(timeString.substr(nextStart, minuteLength).c_str());
+                       nextStart = nextStart + minuteLength;
+                       LogDebug("<<< initTime.tm_min:[" << tm_Time.tm_min << "]");
+
+                       int secondLength = 2;
+                       tm_Time.tm_sec = atoi(timeString.substr(nextStart, secondLength).c_str());
+                       LogDebug("<<< initTime.tm_sec:[" << tm_Time.tm_sec << "]");
+
+                       return tm_Time;
+                       }
+
+
+               bool StorageChangesConversationGenerator::getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+                       LogDebug("<<< attrName.compare(valueString) : " << attrName.compare(valueString));
+
+                       if(attrName.compare(valueString) == 0)
+                       {
+                               LogDebug("<<< getMatchExactlyClause SAME >>>");
+                               return TRUE;                            
+                       }
+                       else{
+                               LogDebug("<<< getMatchExactlyClause DIFF >>>");
+                               return FALSE;                                                           
+                       }
+               }
+
+               bool StorageChangesConversationGenerator::getMatchFullstringClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string tempString1;
+                       std::string tempString2;
+                       
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+                       
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+
+                       LogDebug("<<< attrName : " << tempString1);
+                       LogDebug("<<< valueString : " << tempString2);
+                       
+                       if(tempString1.compare(tempString2) == 0)
+                       {
+                               LogDebug("<<< getMatchFullstringClause SAME >>>");
+                               return TRUE;                            
+                       }
+                       else{
+                               LogDebug("<<< getMatchFullstringClause DIFF >>>");
+                               return FALSE;                                                           
+                       }
+               }
+
+               bool StorageChangesConversationGenerator::getMatchContainsClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string tempString1;
+                       std::string tempString2;
+               
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+                       
+                       LogDebug("<<< attrName.find(valueString) : " << tempString1.find(tempString2));
+
+                       if(tempString1.find(tempString2) != std::string::npos)
+                       {
+                               LogDebug("<<< getMatchContainsClause CONTAINS >>>");
+                               return TRUE;                            
+                       }else{
+                               LogDebug("<<< getMatchContainsClause NOT CONTAINS >>>");
+                               return FALSE;                                                           
+                       }
+                       }
+
+               bool StorageChangesConversationGenerator::getMatchStartwithClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string tempString1;
+                       std::string tempString2;
+               
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+                       
+                       if(tempString1.size() < tempString2.size())
+                               return FALSE;
+
+                       if(tempString1.compare(0,tempString2.size(), tempString2) == 0)
+                       {
+                               LogDebug("<<< getMatchStartwithClause START WITH >>>");
+                       return TRUE;
+               }
+                       else{
+                               LogDebug("<<< getMatchStartwithClause NOT START WITH >>>");
+                               return FALSE;                                                           
+                       }
+               }
+
+               bool StorageChangesConversationGenerator::getMatchEndwithClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string tempString1;
+                       std::string tempString2;
+               
+                       std::string valueString = value->toString();
+
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+                       
+                       LogDebug("<<< attrName.compare(attrName.size()-valueString.size(),valueString.size(), valueString) : " << attrName.compare(attrName.size()-valueString.size(),valueString.size(), valueString));
+
+
+                       if(tempString1.size() < tempString2.size())
+                               return FALSE;
+
+                       if(tempString1.compare(tempString1.size()-tempString2.size(),tempString2.size(), tempString2) == 0 )
+                       {
+                               LogDebug("<<< getMatchEndwithClause END WITH >>>");
+                               return TRUE;                            
+                       }
+                       else{
+                               LogDebug("<<< getMatchEndwithClause NOT END WITH >>>");
+                               return FALSE;                                                           
+                       }
+               }
+
+               bool StorageChangesConversationGenerator::getMatchExistClause(std::string& attrName)
+               {
+                       LogDebug("<<< attrName : " << attrName);
+                       if(attrName.size()> 0)
+                               return TRUE;
+                       else
+                               return FALSE;
+               }
+
+
+               void StorageChangesConversationGenerator::visitAttribute(std::string& attrName,
+                                                MatchFlag& matchFlag, AnyPtr& matchValue, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]");
+                       if(matchFlag != Api::Tizen::MATCH_EXISTS){
+                               if(matchValue == NULL)  {
+                               return;
+                               }
+                       }
+
+                       LogDebug("matchValue:" << matchValue->toString());
+
+                       visitAttributeEach(attrName, matchFlag, matchValue, depth);
+                       LogDebug(">>>");
+               }
+
+               void StorageChangesConversationGenerator::visitAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
+                       std::string valueString;
+
+//  Check msg_type and filter_type
+
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_ID)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               int nType = atoi(value->toString().c_str());
+                               if((int)m_id == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< id is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< id is different");
+                               }
+                               return;
+                       }
+
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_TYPE)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               std::string convertType = value->toString();
+                               int nType = convertMessageType(convertType);
+                               if((int)m_type == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< type is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< type is different");
+                               }
+                               return;
+                       }
+                       
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               int nType = atoi(value->toString().c_str());
+                               if((int)m_messageCount == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< messageCount is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< messageCount is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_UNREAD_MESSAGES)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               int nType = atoi(value->toString().c_str());
+                               if((int)m_unreadMessages == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< unreadMessages is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< unreadMessages is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_IS_READ)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               std::string lowerString;
+                               lowerString.assign(value->toString());
+                               StrLowChange(lowerString);                              
+                               int nType = lowerString.compare("true");
+
+                               if((int)m_read != nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< read is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< read is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_LAST_MESSAGE_ID)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               int nType = atoi(value->toString().c_str());
+                               if((int)m_lastMessageId == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< lastMessageId is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< lastMessageId is different");
+                               }
+                               return;
+                       }
+  
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_body:[" << m_preview << "]");
+  
+                               valueString = m_preview;
+                               if(getMatchFlagResult(value, valueString, matchFlag))
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< preview is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< preview is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_FROM)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_from:[" << m_from << "]");
+   
+                               valueString = m_from;
+                               if(getMatchFlagResult(value, valueString, matchFlag))
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< from is same");
+                               }
+                               else
+                       {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< from is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_SUBJECT)==0){
+                       LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_subject:[" << m_subject << "]");
+  
+                               valueString = m_subject;
+                               if(getMatchFlagResult(value, valueString, matchFlag))
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< subject is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< subject is different");
+                               }
+                               return;
+                       }
+  
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_TO)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_to.size :[" << m_to.size() << "]");
+  
+                               bool result = FALSE;
+                               for(unsigned int i=0; i < m_to.size(); i++)
+                               {
+                                       valueString = m_to[i];
+                                       result = result || getMatchFlagResult(value, valueString, matchFlag);
+                               }
+                               LogDebug("<<< to compare result is :" << result);
+                               m_result.push_back(result);
+                               return;
+                       }
+  
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_CC)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_cc.size :[" << m_cc.size() << "]");
+  
+                               bool result = FALSE;
+                               for(unsigned int i=0; i < m_cc.size(); i++)
+                               {
+                                       valueString = m_cc[i];
+                                       result = result || getMatchFlagResult(value, valueString, matchFlag);
+                               }
+                               LogDebug("<<< cc compare result is : " << result);
+                               m_result.push_back(result);
+                               return;
+                       }
+  
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_BCC)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_cc.size :[" << m_bcc.size() << "]");
+  
+                               bool result = FALSE;
+                               for(unsigned int i=0; i < m_bcc.size(); i++)
+                               {
+                                       valueString = m_bcc[i];
+                                       result = result || getMatchFlagResult(value, valueString, matchFlag);
+                               }
+                               LogDebug("<<< bcc compare result is : " << result);
+                               m_result.push_back(result);
+                               return;
+                       }
+  
+                       LogDebug(">>>");
+                       }
+
+               int StorageChangesConversationGenerator::convertMessageType(std::string& stringType){
+                       LogDebug("<<< stringType:[" << stringType << "]");
+
+                       int retMessageType = -1;
+
+                       if(stringType.compare("messaging.sms") ==0){
+                               retMessageType = Api::Messaging::SMS;
+                       }else if(stringType.compare("messaging.mms") ==0){
+                               retMessageType = Api::Messaging::MMS;
+                       }else if(stringType.compare("messaging.email") ==0){
+                               retMessageType = Api::Messaging::EMAIL;
+                       }else{
+                               LogError("invalid type:[" << stringType << "]");
+                               return -1;
+                       }
+
+                       LogDebug(">>> retMessageType:" << retMessageType);
+                       return retMessageType;
+               }
+
+               std::string StorageChangesConversationGenerator::convertBooleanStringToIntegerString(std::string& booleanString){
+                       std::string retString;
+
+                       if(booleanString.compare("true") == 0){
+                               retString = "1";
+                       }else if(booleanString.compare("false") == 0){
+                               retString = "0";
+                       }else{
+                               LogError("invalid booleanString:[" << booleanString << "]");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid booleanString :[" + booleanString + "]");
+                       }
+                       return retString;
+               }
+
+               void StorageChangesConversationGenerator::visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth) {
+                       time_t init_time, mid_time, end_time;
+                       struct tm startTime;
+                       struct tm endTime;                      
+//                     struct tm retValue;
+                       string initialValueStr;
+                       string endValueStr;
+
+                       memset(&startTime, 0, sizeof(startTime));
+                       memset(&endTime, 0, sizeof(endTime));
+
+
+                       if(initialValue == NULL || endValue == NULL)
+                               return;
+
+                       if(attrName.compare(StorageChangesConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP)==0){
+
+                               if (!initialValue->isNullOrUndefined()) {
+                                       if( TizenApis::Api::Tizen::PrimitiveType_Time==initialValue->getType() ) {
+                                               LogDebug("<<<initialValue->getType()[" << initialValue->getType() <<"]");                                       
+                                               startTime = initialValue->getDateTm();
+                                               LogDebug("<<<valueStr[" << initialValueStr <<"]");
+                                       }
+                                       else {
+                                               LogError("initialValue->getType() : [" << initialValue->getType() << "]");                                      
+                                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid initialValue Type");
+                                       }
+                               }
+                               
+                               if (!endValue->isNullOrUndefined()) {
+                                       if( TizenApis::Api::Tizen::PrimitiveType_Time==endValue->getType() ) {
+                                               LogDebug("<<<endValue->getType()[" << endValue->getType() <<"]");                                       
+                                               endTime= endValue->getDateTm();
+                                               LogDebug("<<<valueStr[" << endValueStr <<"]");                                  
+                                       } else {
+                                               LogError("endValue->getType() : [" << endValue->getType() << "]");                                      
+                                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid endValue Type");
+                                       }
+                               }
+
+                               
+//                             retValue = convertToTimeFormat(initialValueStr);
+                               init_time = mktime(&startTime);
+
+                               mid_time = m_time;
+
+//                             retValue = convertToTimeFormat(endValueStr);            
+                               end_time = mktime(&endTime);
+
+                               LogDebug("<<< mktime(initialValue):[" << init_time << "]");
+                               LogDebug("<<< mktime(m_dateTime):[" << mid_time << "]");
+                               LogDebug("<<< mktime(endValue):[" << end_time << "]");
+                               LogDebug("<<< mid_time - init_time:[" << mid_time - init_time << "]");
+                               LogDebug("<<< end_time - mid_time:[" << end_time - mid_time << "]");
+
+                               if(((mid_time - init_time) >= 0 ) && ((end_time - mid_time) >= 0 ))
+                               {
+                                       LogDebug("<<< timestamp is in range");
+                                       m_result.push_back(TRUE);
+                               }
+                               else
+                               {
+                                       LogDebug("<<< timestamp is out of range");
+                                       m_result.push_back(FALSE);
+                               }
+                       }
+                       }
+                       
+               bool StorageChangesConversationGenerator::getMatchFlagResult(Api::Tizen::AnyPtr& value, std::string& valueString, Api::Tizen::MatchFlag& matchFlag)
+               {
+                       std::vector<std::string>::iterator iter;
+                       bool result = FALSE;
+                       if(matchFlag == Api::Tizen::MATCH_EXACTLY){
+                               LogDebug("STRING_MATCH_EXACTLY");
+                               result = result || getMatchExactlyClause(valueString, value);
+                       }else if(matchFlag == Api::Tizen::MATCH_FULLSTRING){
+                               LogDebug("STRING_MATCH_FULLSTRING");
+                               result = result || getMatchFullstringClause(valueString, value);                                                
+                       }else if(matchFlag == Api::Tizen::MATCH_CONTAINS){
+                               LogDebug("STRING_MATCH_CONTAINS");
+                               result = result || getMatchContainsClause(valueString, value);                                          
+                       }else if(matchFlag == Api::Tizen::MATCH_STARTSWITH){
+                               LogDebug("STRING_MATCH_STARTSWITH");
+                               result = result || getMatchStartwithClause(valueString, value);
+                       }else if(matchFlag == Api::Tizen::MATCH_ENDSWITH){
+                               LogDebug("STRING_MATCH_ENDSWITH");
+                               result = result || getMatchEndwithClause(valueString, value);                           
+                       }else if(matchFlag == Api::Tizen::MATCH_EXISTS){
+                               LogDebug("STRING_MATCH_EXIST");
+                               result = result || getMatchExistClause(valueString);
+                       }else{
+                               LogDebug("[ERROR]invalid match flag : iter:" << *iter);
+                       }
+                       return result;
+               }
+
+               bool StorageChangesConversationGenerator::getCompareResult()
+               {       
+                       bool result;
+                       LogDebug("m_result.size() " << m_result.size());
+                       result = m_result.back();
+                       m_result.pop_back();                    
+                       LogDebug("result = " << result);        
+                       return result;
+               }
+
+               void StorageChangesConversationGenerator::StrLowChange(std::string& tempString)
+               {       
+                       std::transform(tempString.begin(), tempString.end(), tempString.begin(), ::tolower);
+                       return;
+               }
+
+
+}
+       }               //namespace Platform
+}              //namespace WrtPlugins
diff --git a/src/platform/API/Messaging/StorageChangesConversationGenerator.h b/src/platform/API/Messaging/StorageChangesConversationGenerator.h
new file mode 100755 (executable)
index 0000000..83580fd
--- /dev/null
@@ -0,0 +1,114 @@
+//
+// 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 STORAGECHANGESCONVERSATIONGENERATOR_H_
+#define STORAGECHANGESCONVERSATIONGENERATOR_H_
+
+#include <API/Filter/IFilterVisitor.h>
+#include <API/Filter/SortMode.h>
+#include <API/Messaging/IMessaging.h>
+
+#include <map>
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+
+//             using namespace std;
+
+               class StorageChangesConversationGenerator: public TizenApis::Api::Tizen::IFilterVisitor{
+                       public:
+
+                               enum operandType
+                               {
+                                       leftblank = 1,
+                                       rightblank = 2,
+                                       operandUnion = 3,
+                                       operandIntersection = 4
+                               };
+                               
+                               StorageChangesConversationGenerator(Api::Messaging::IConversationPtr conv);
+                               virtual ~StorageChangesConversationGenerator();
+
+                               void visitPreComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitInComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitPostComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitAttribute(std::string& attrName,
+                                               Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& matchValue, int depth);
+
+                               void visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth);
+
+                               bool getMatchFlagResult(Api::Tizen::AnyPtr& value, std::string& valueString, Api::Tizen::MatchFlag& matchFlag);
+                               bool getCompareResult();                                                        
+
+                       private:
+                               bool getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchFullstringClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchContainsClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchStartwithClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchEndwithClause(std::string& attrName, Api::Tizen::AnyPtr& value);                           
+                               bool getMatchExistClause(std::string& attrName);                                
+                               bool getBetweenRangeClause(struct tm initialValue, struct tm endValue);                         
+
+                               void visitAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth);
+                               int convertMessageType(std::string& stringType);
+                               std::string convertBooleanStringToIntegerString(std::string& booleanString);
+
+                               struct tm convertToTimeFormat(const std::string& timeString);                   
+                               std::string createTimeString(std::string& timeString);
+                               std::string createFolderType(std::string& value);
+                               std::string createPriorityType(std::string& value);
+                               std::string createDateTimeType(Api::Tizen::AnyPtr& value);
+
+                               void StrLowChange(std::string& tempString);
+
+                       private:
+                               int m_messageType;
+
+                               std::vector<std::string> typeVector;
+                               std::map<std::string, std::string> attributeMap;
+
+                               std::vector<bool> m_result;
+                               std::vector<int> m_operand;                             
+
+                               unsigned int m_id;
+                               unsigned short int m_type;
+                               time_t m_time;
+                               unsigned long m_messageCount;
+                               unsigned long m_unreadMessages;
+                               std::string m_preview;
+                               std::string m_subject;
+                               bool m_read;
+                               std::string m_from;
+                               std::vector<std::string> m_to;
+                               std::vector<std::string> m_cc;
+                               std::vector<std::string> m_bcc;
+                               unsigned int m_lastMessageId;
+
+                               Api::Messaging::RecipientsPtr Recipents;
+                               std::string m_currentType;
+
+                               static const int MESSAGE_TYPE_NOT_INITIALIZED;
+
+               };
+
+               typedef DPL::SharedPtr<StorageChangesConversationGenerator> StorageChangesConversationGeneratorPtr;
+       }               // namespace Platform
+} // namespace WrtPlugins
+}
+#endif /* MESSAGEQUERYGENERATOR_H_ */
diff --git a/src/platform/API/Messaging/StorageChangesFolderFilterValidator.cpp b/src/platform/API/Messaging/StorageChangesFolderFilterValidator.cpp
new file mode 100755 (executable)
index 0000000..b0cb95c
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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 "StorageChangesFolderFilterValidator.h"
+#include "StorageChangesFolderFilterValidatorFactory.h"
+
+#include <dpl/log/log.h>
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               StorageChangesFolderFilterValidator::StorageChangesFolderFilterValidator(PropertyStructArray properties):FilterValidator(properties){
+                       m_isTypeSetted = false;
+               }
+
+               StorageChangesFolderFilterValidator::~StorageChangesFolderFilterValidator(){
+               }
+
+               bool StorageChangesFolderFilterValidator::validateAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth){
+                       bool retVal = false;
+                               LogError(">>> [ERROR] Not Supported attribute :[" << attrName << "]");
+                       return retVal;
+               }
+
+               bool StorageChangesFolderFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                               Api::Tizen::AnyPtr& matchValue, int depth){
+
+                       bool retBool = false;
+
+                       if(matchValue == NULL)
+                               return false;
+
+                       retBool = FilterValidator::validateAttribute(attrName, matchFlag, matchValue, depth);
+                       LogDebug(">>> retBool:" << retBool);
+                       return retBool;
+
+               }
+       }
+       }
+
+}
diff --git a/src/platform/API/Messaging/StorageChangesFolderFilterValidator.h b/src/platform/API/Messaging/StorageChangesFolderFilterValidator.h
new file mode 100755 (executable)
index 0000000..6445642
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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 STORAGECHANGESFOLDERATOR_H_
+#define STORAGECHANGESFOLDERATOR_H_
+
+#include <API/Filter/FilterValidator.h>
+
+
+namespace TizenApis {
+
+       namespace Platform {
+
+               namespace Messaging {
+
+               class StorageChangesFolderFilterValidator: public Api::Tizen::FilterValidator {
+                       private:
+                               bool m_isTypeSetted;
+
+                       public:
+                       StorageChangesFolderFilterValidator(Api::Tizen::PropertyStructArray properties);
+
+                               virtual ~StorageChangesFolderFilterValidator();
+
+                               // validate AttributeRangeFilter
+                                       virtual bool validateAttributeRange(std::string& attrName,
+                                                       Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0);
+
+                                       virtual bool validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                                                               Api::Tizen::AnyPtr& matchValue, int depth=0);
+
+
+
+               };
+
+               typedef DPL::SharedPtr<StorageChangesFolderFilterValidator> StorageChangesFolderFilterValidatorPtr;
+       }
+}
+       }
+
+#endif 
diff --git a/src/platform/API/Messaging/StorageChangesFolderFilterValidatorFactory.cpp b/src/platform/API/Messaging/StorageChangesFolderFilterValidatorFactory.cpp
new file mode 100755 (executable)
index 0000000..7064465
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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 "StorageChangesFolderFilterValidatorFactory.h"
+
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               const std::string StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_ID              = "id";
+               const std::string StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_PARENT_ID       = "parentId";
+               const std::string StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_ACCOUNT_ID      = "serviceId";
+               const std::string StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_CONTENT_TYPE    = "contentType";
+               const std::string StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_NAME            = "name";
+               const std::string StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_PATH            = "path";
+               const std::string StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_TYPE            = "type";
+               const std::string StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_SYNCHRONIZABLE  = "synchronizable";
+
+               static PropertyStructArray properties =
+               {
+                               {StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_ID.c_str(),                                      Api::Tizen::PrimitiveType_String},
+                               {StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_PARENT_ID.c_str(),                       Api::Tizen::PrimitiveType_String},
+                               {StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_ACCOUNT_ID.c_str(),                      Api::Tizen::PrimitiveType_String},
+                               {StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_CONTENT_TYPE.c_str(),            Api::Tizen::PrimitiveType_String},
+                               {StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_NAME.c_str(),                            Api::Tizen::PrimitiveType_String},
+                               {StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_PATH.c_str(),                                    Api::Tizen::PrimitiveType_String},
+                               {StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_TYPE.c_str(),                                    Api::Tizen::PrimitiveType_String},
+                               {StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_SYNCHRONIZABLE.c_str(),          Api::Tizen::PrimitiveType_Number},
+                               {0,                  Api::Tizen::PrimitiveType_NoType}
+               };
+
+               StorageChangesFolderFilterValidatorPtr StorageChangesFolderFilterValidatorFactory::getStorageChangesFolderFilterValidator()
+               {
+                   static StorageChangesFolderFilterValidatorPtr theInstance =
+                               StorageChangesFolderFilterValidatorPtr(new StorageChangesFolderFilterValidator(properties));
+
+                   return theInstance;
+               }
+
+               }
+       }       //naspace Platform
+} //naspace WrtPlugins
diff --git a/src/platform/API/Messaging/StorageChangesFolderFilterValidatorFactory.h b/src/platform/API/Messaging/StorageChangesFolderFilterValidatorFactory.h
new file mode 100755 (executable)
index 0000000..4dd9207
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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 STORAGECHANGESFOLDERFILTERVALIDATORFACTORY_H_
+#define STORAGECHANGESFOLDERFILTERVALIDATORFACTORY_H_
+
+#include <API/Filter/FilterValidator.h>
+#include "StorageChangesFolderFilterValidator.h"
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               class StorageChangesFolderFilterValidatorFactory {
+                       private:
+                               StorageChangesFolderFilterValidatorFactory()
+                               {
+                               }
+
+                       public:
+                               static StorageChangesFolderFilterValidatorPtr getStorageChangesFolderFilterValidator();
+
+                       public:
+                               static const std::string ATTRIBUTE_ID;
+                               static const std::string ATTRIBUTE_PARENT_ID;
+                               static const std::string ATTRIBUTE_ACCOUNT_ID;
+                               static const std::string ATTRIBUTE_CONTENT_TYPE;
+                               static const std::string ATTRIBUTE_NAME;                                
+                               static const std::string ATTRIBUTE_PATH;
+                               static const std::string ATTRIBUTE_TYPE;
+                               static const std::string ATTRIBUTE_SYNCHRONIZABLE;
+               };
+
+               }
+       }               //Platform
+}
+
+#endif /* MESSAGINGFILTERVALIDATORFACTORY_H_ */
diff --git a/src/platform/API/Messaging/StorageChangesFolderGenerator.cpp b/src/platform/API/Messaging/StorageChangesFolderGenerator.cpp
new file mode 100755 (executable)
index 0000000..243eb57
--- /dev/null
@@ -0,0 +1,493 @@
+//
+// 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 "StorageChangesFolderGenerator.h"
+#include "StorageChangesFolderFilterValidatorFactory.h"
+
+#include "IMessagingTypes.h"
+
+#include <email-types.h>
+
+#include <dpl/log/log.h>
+
+using namespace std;
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+
+               const int StorageChangesFolderGenerator::MESSAGE_TYPE_NOT_INITIALIZED = -1;
+
+               StorageChangesFolderGenerator::StorageChangesFolderGenerator(Api::Messaging::IMessageFolderPtr folder):m_messageType(MESSAGE_TYPE_NOT_INITIALIZED) {
+
+                       m_id = folder->getId();
+                       m_parentid = folder->getParentId();
+                       m_accountid = folder->getAccountId();
+                       m_contestType = (unsigned short)folder->getContentType();
+                       m_name = folder->getName();
+                       m_path = folder->getPath();
+                       m_type = (unsigned short)folder->getType();                     
+                       m_synchronizable = folder->getSynchronizable();
+
+                       LogDebug("m_type:" << m_type );
+               
+               }
+
+               StorageChangesFolderGenerator::~StorageChangesFolderGenerator() {
+               }
+
+
+               void StorageChangesFolderGenerator::visitPreComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+                       m_operand.push_back(leftblank);
+                       LogDebug("Left_blank");                 
+                       LogDebug(">>>");
+               }
+
+               void StorageChangesFolderGenerator::visitInComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+                       if(type ==  UNION_FILTER ){
+                               LogDebug("UNION_FILTER");
+                               m_operand.push_back(operandUnion);
+                       }else if(type == INTERSECTION_FILTER){
+                               LogDebug("INTERSECTION_FILTER");
+                               m_operand.push_back(operandIntersection);                               
+                       }else{
+                               LogError("[ERROR] invalid Filter type:" << type);
+                       }
+
+                       LogDebug(">>>");
+               }
+
+               void StorageChangesFolderGenerator::visitPostComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+                       bool data1, data2;
+                       do
+                       {
+                               LogDebug("m_result size =" << m_result.size());
+                               data1 = m_result.back();
+                               m_result.pop_back();
+                               data2 = m_result.back();
+                               m_result.pop_back();
+                               LogDebug("m_result size =" << m_result.size());                         
+                               LogDebug("m_operand.back() =" << m_operand.back());     
+                               LogDebug("m_operand size =" << m_operand.size());                                                               
+                               if(m_operand.back() == operandUnion)
+                               {
+                                       LogDebug("Union");                              
+                                       LogDebug("data1 = " << data1);
+                                       LogDebug("data2 = " << data2);
+                                       LogDebug("data1 || data2 = " << (data1 || data2));                                      
+                                       m_operand.pop_back();
+                                       m_result.push_back(data1 || data2);
+                                       LogDebug("result" << m_result.back());
+                                       LogDebug("m_result size =" << m_result.size());
+                               }
+                               else if(m_operand.back() == operandIntersection)
+                               {
+                                       LogDebug("Intersection");                               
+                                       LogDebug("data1 = " << data1);
+                                       LogDebug("data2 = " << data2);
+                                       LogDebug("data1 && data2 = " << (data1 && data2));                                      
+                                       m_operand.pop_back();                           
+                                       m_result.push_back(data1 && data2);
+                                       LogDebug("result " << m_result.back());
+                                       LogDebug("m_result size =" << m_result.size());                                 
+                                       
+                               }
+                       }while(m_operand.back() != leftblank);
+                       m_operand.pop_back();
+                       LogDebug("elase leftblank from m_operand");
+                       LogDebug("m_operand size =" << m_operand.size());                                                                                       
+                       LogDebug(">>>");
+               }
+
+               bool StorageChangesFolderGenerator::getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+                       LogDebug("<<< attrName.compare(valueString) : " << attrName.compare(valueString));
+                       
+                       if(attrName.compare(valueString) == 0)
+                       {
+                               LogDebug("<<< getMatchExactlyClause SAME >>>");
+                               return TRUE;                            
+                       }
+                       else{
+                               LogDebug("<<< getMatchExactlyClause DIFF >>>");
+                               return FALSE;                                                           
+                       }
+               }
+
+               bool StorageChangesFolderGenerator::getMatchFullstringClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string tempString1;
+                       std::string tempString2;
+                       
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+                       
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+
+                       LogDebug("<<< attrName : " << tempString1);
+                       LogDebug("<<< valueString : " << tempString2);
+                       
+                       if(tempString1.compare(tempString2) == 0)
+                       {
+                               LogDebug("<<< getMatchFullstringClause SAME >>>");
+                               return TRUE;                            
+                       }
+                       else{
+                               LogDebug("<<< getMatchFullstringClause DIFF >>>");
+                               return FALSE;                                                           
+                       }
+               }               
+
+               bool StorageChangesFolderGenerator::getMatchContainsClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string tempString1;
+                       std::string tempString2;
+                       
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+                       
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+
+                       LogDebug("<<< attrName : " << tempString1);
+                       LogDebug("<<< valueString : " << tempString2);
+
+                       if(tempString1.find(tempString2) != std::string::npos)
+                       {
+                               LogDebug("<<< getMatchContainsClause CONTAINS >>>");
+                               return TRUE;                            
+                       }else{
+                               LogDebug("<<< getMatchContainsClause NOT CONTAINS >>>");
+                               return FALSE;                                                           
+                       }
+               }
+
+               bool StorageChangesFolderGenerator::getMatchStartwithClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string tempString1;
+                       std::string tempString2;
+                       
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+                       
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+
+                       LogDebug("<<< attrName : " << tempString1);
+                       LogDebug("<<< valueString : " << tempString2);
+
+                       if(tempString1.size() < tempString2.size())
+                               return FALSE;
+
+                       if(tempString1.compare(0,tempString2.size(), tempString2) == 0)
+               {
+                               LogDebug("<<< getMatchStartwithClause START WITH >>>");
+                               return TRUE;
+                       }
+                       else{
+                               LogDebug("<<< getMatchStartwithClause NOT START WITH >>>");
+                               return FALSE;                                                           
+                       }
+               }
+
+               bool StorageChangesFolderGenerator::getMatchEndwithClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string tempString1;
+                       std::string tempString2;
+                       
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+                       
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+
+                       LogDebug("<<< attrName : " << tempString1);
+                       LogDebug("<<< valueString : " << tempString2);
+
+                       if(tempString1.size() < tempString2.size())
+                               return FALSE;
+
+                       if(tempString1.compare(tempString1.size()-tempString2.size(),tempString2.size(), tempString2) == 0 )
+                       {
+                               LogDebug("<<< getMatchEndwithClause END WITH >>>");
+                               return TRUE;                            
+                       }
+                       else{
+                               LogDebug("<<< getMatchEndwithClause NOT END WITH >>>");
+                               return FALSE;                                                           
+                       }
+                       }
+
+
+               bool StorageChangesFolderGenerator::getMatchExistClause(std::string& attrName)
+               {
+                       LogDebug("<<< attrName : " << attrName);
+                       if(attrName.size()> 0)
+                               return TRUE;
+                       else
+                               return FALSE;
+               }
+
+               void StorageChangesFolderGenerator::visitAttribute(std::string& attrName,
+                               Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& matchValue, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]");
+
+                       if(matchFlag != Api::Tizen::MATCH_EXISTS){
+                               if(matchValue == NULL)  {
+                               return;
+                               }
+                       }
+
+                       LogDebug("matchValue:" << matchValue->toString());
+
+                       visitAttributeEach(attrName, matchFlag, matchValue, depth);
+               }
+
+               void StorageChangesFolderGenerator::visitAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
+                       std::string valueString;
+
+//  Check Folder_type and filter_type
+                       if(attrName.compare( StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_ACCOUNT_ID)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               int nType = atoi(value->toString().c_str());
+                               if((int)m_accountid == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< accountid is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< accountid is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_CONTENT_TYPE)==0){
+                       LogDebug("<<< value:[" << value << "]");
+                               std::string convertType = value->toString();
+                               int nType = convertMessageType(convertType);
+                               if((int)m_contestType == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< contestType is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< contestType is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_TYPE )==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               std::string convertType = value->toString();
+                               int nType = convertFolderType(convertType);
+                               if((int)m_type == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< type is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< type is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_SYNCHRONIZABLE)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               std::string lowerString;
+                               lowerString.assign(value->toString());
+                               StrLowChange(lowerString);                              
+                               int nType = lowerString.compare("true");
+                               if((int)m_synchronizable != nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< synchronizable is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< synchronizable is different");
+                               }
+                               return;
+                       }
+
+                       if(attrName.compare(StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_NAME)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_name:[" << m_name << "]");
+
+                               valueString = m_name;
+                               if(getMatchFlagResult(value, valueString, matchFlag))
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< name is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< name is different");
+                               }
+                               return;
+                       }
+
+                       if(attrName.compare(StorageChangesFolderFilterValidatorFactory::ATTRIBUTE_PATH)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_path:[" << m_path << "]");
+
+                               valueString = m_path;
+                               if(getMatchFlagResult(value, valueString, matchFlag))
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< path is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< path is different");
+                               }
+                               return;
+                       }
+
+                       LogDebug(">>>");
+               }
+
+               int StorageChangesFolderGenerator::convertMessageType(std::string& stringType){
+                       LogDebug("<<< stringType:[" << stringType << "]");
+
+                       int retMessageType = -1;
+
+                       if(stringType.compare("messaging.sms") ==0){
+                               retMessageType = Api::Messaging::SMS;
+                       }else if(stringType.compare("messaging.mms") ==0){
+                               retMessageType = Api::Messaging::MMS;
+                       }else if(stringType.compare("messaging.email") ==0){
+                               retMessageType = Api::Messaging::EMAIL;
+                       }else{
+                               LogError("invalid type:[" << stringType << "]");
+                               return -1;
+                       }
+
+                       LogDebug(">>> retMessageType:" << retMessageType);
+                       return retMessageType;
+               }
+
+               int StorageChangesFolderGenerator::convertFolderType(std::string& stringType){
+                       LogDebug("<<< stringType:[" << stringType << "]");
+
+                       int retMessageType = -1;
+
+                       if(stringType.compare("INBOX") ==0){
+                               retMessageType = Api::Messaging::INBOX;
+                       }else if(stringType.compare("OUTBOX") ==0){
+                               retMessageType = Api::Messaging::OUTBOX;
+                       }else if(stringType.compare("DRAFTBOX") ==0){
+                               retMessageType = Api::Messaging::DRAFTBOX;
+                       }else if(stringType.compare("SENTBOX") ==0){
+                               retMessageType = Api::Messaging::SENTBOX;
+                       }else{
+                               LogError("invalid type:[" << stringType << "]");
+                               return -1;
+                       }
+
+                       LogDebug(">>> retMessageType:" << retMessageType);
+                       return retMessageType;
+               }
+
+
+               void StorageChangesFolderGenerator::visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth) {
+                       LogDebug("<<< NOT SUPPROTED");
+                       LogDebug(">>>");
+                       m_result.push_back(FALSE);                                              
+               }
+
+               bool StorageChangesFolderGenerator::getMatchFlagResult(Api::Tizen::AnyPtr& value, std::string& valueString, Api::Tizen::MatchFlag& matchFlag)
+               {
+                       std::vector<std::string>::iterator iter;
+                       bool result = FALSE;
+                       if(matchFlag == Api::Tizen::MATCH_EXACTLY){
+                               LogDebug("STRING_MATCH_EXACTLY");
+                               result = result || getMatchExactlyClause(valueString, value);
+                       }else if(matchFlag == Api::Tizen::MATCH_FULLSTRING){
+                               LogDebug("STRING_MATCH_FULLSTRING");
+                               result = result || getMatchFullstringClause(valueString, value);                                                
+                       }else if(matchFlag == Api::Tizen::MATCH_CONTAINS){
+                               LogDebug("STRING_MATCH_CONTAINS");
+                               result = result || getMatchContainsClause(valueString, value);                                          
+                       }else if(matchFlag == Api::Tizen::MATCH_STARTSWITH){
+                               LogDebug("STRING_MATCH_STARTSWITH");
+                               result = result || getMatchStartwithClause(valueString, value);
+                       }else if(matchFlag == Api::Tizen::MATCH_ENDSWITH){
+                               LogDebug("STRING_MATCH_ENDSWITH");
+                               result = result || getMatchEndwithClause(valueString, value);                           
+                       }else if(matchFlag == Api::Tizen::MATCH_EXISTS){
+                               LogDebug("STRING_MATCH_EXIST");
+                               result = result || getMatchExistClause(valueString);
+                       }else{
+                               LogDebug("[ERROR]invalid match flag : iter:" << *iter);
+                       }
+                       return result;
+               }
+
+               bool StorageChangesFolderGenerator::getCompareResult()
+               {       
+                       bool result;
+                       LogDebug("m_result.size() " << m_result.size());
+                       result = m_result.back();
+                       m_result.pop_back();                    
+                       LogDebug("result = " << result);        
+                       return result;
+               }
+
+
+               void StorageChangesFolderGenerator::StrLowChange(std::string& tempString)
+               {       
+                       std::transform(tempString.begin(), tempString.end(), tempString.begin(), ::tolower);
+                       return;
+               }
+               
+}
+       }               //namespace Platform
+}              //namespace WrtPlugins
diff --git a/src/platform/API/Messaging/StorageChangesFolderGenerator.h b/src/platform/API/Messaging/StorageChangesFolderGenerator.h
new file mode 100755 (executable)
index 0000000..928f011
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// 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 STORAGECHANGESFOLDERGENERATOR_H_
+#define STORAGECHANGESFOLDERGENERATOR_H_
+
+#include <API/Filter/IFilterVisitor.h>
+#include <API/Filter/SortMode.h>
+#include <API/Messaging/IMessaging.h>
+
+
+#include <map>
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+
+//             using namespace std;
+
+               class StorageChangesFolderGenerator: public TizenApis::Api::Tizen::IFilterVisitor{
+                       public:
+
+                               enum operandType
+                               {
+                                       leftblank = 1,
+                                       rightblank = 2,
+                                       operandUnion = 3,
+                                       operandIntersection = 4
+                               };
+                               
+                               StorageChangesFolderGenerator(Api::Messaging::IMessageFolderPtr conv);
+                               virtual ~StorageChangesFolderGenerator();
+
+                               void visitPreComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitInComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitPostComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                                               Api::Tizen::AnyPtr& matchValue, int depth);
+                               void visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth);
+                               bool getMatchFlagResult(Api::Tizen::AnyPtr& value, std::string& valueString, Api::Tizen::MatchFlag& matchFlag);
+                               bool getCompareResult();                                                        
+
+                       private:
+                               bool getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchFullstringClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchContainsClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchStartwithClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchEndwithClause(std::string& attrName, Api::Tizen::AnyPtr& value);                           
+                               bool getMatchExistClause(std::string& attrName);                                
+
+                               void visitAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth);
+                               int convertMessageType(std::string& stringType);
+                               int convertFolderType(std::string& stringType);                         
+
+                               void StrLowChange(std::string& tempString);
+
+                       private:
+                               int m_messageType;
+
+                               std::vector<std::string> typeVector;
+                               std::map<std::string, std::string> attributeMap;
+
+                               std::vector<bool> m_result;
+                               std::vector<int> m_operand;                             
+
+                               unsigned long m_id;
+                               unsigned long m_parentid;
+                               unsigned long m_accountid;
+//                             Api::Messaging::MessageType m_contestType;
+                               unsigned short m_contestType;                           
+                               std::string m_name;
+                               std::string m_path;
+//                             Api::Messaging::FolderType m_type;                              
+                               unsigned short m_type;                          
+                               bool m_synchronizable;
+
+                               static const int MESSAGE_TYPE_NOT_INITIALIZED;
+
+               };
+
+               typedef DPL::SharedPtr<StorageChangesFolderGenerator> StorageChangesFolderGeneratorPtr;
+       }               // namespace Platform
+} // namespace WrtPlugins
+}
+#endif /* MESSAGEQUERYGENERATOR_H_ */
diff --git a/src/platform/API/Messaging/StorageChangesMessageFilterValidator.cpp b/src/platform/API/Messaging/StorageChangesMessageFilterValidator.cpp
new file mode 100755 (executable)
index 0000000..f787d0c
--- /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.
+//
+
+#include "StorageChangesMessageFilterValidator.h"
+#include "StorageChangesMessageFilterValidatorFactory.h"
+
+#include <dpl/log/log.h>
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               StorageChangesMessageFilterValidator::StorageChangesMessageFilterValidator(PropertyStructArray properties):FilterValidator(properties){
+                       m_isTypeSetted = false;
+               }
+
+               StorageChangesMessageFilterValidator::~StorageChangesMessageFilterValidator(){
+               }
+
+               bool StorageChangesMessageFilterValidator::validateAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth){
+                       bool retVal = false;
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP)!=0){
+                               LogError(">>> [ERROR] Not Supported attribute :[" << attrName << "]");
+                               return false;
+                       }
+
+                       retVal = FilterValidator::validateAttributeRange(attrName, initialValue, endValue);
+                       return retVal;
+               }
+
+               //TODO Implement
+               bool StorageChangesMessageFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                               Api::Tizen::AnyPtr& matchValue, int depth){
+                       if(matchValue == NULL)
+                               return false;
+
+                       bool retBool = false;
+                       
+                       retBool = FilterValidator::validateAttribute(attrName, matchFlag, matchValue, depth);
+                       LogDebug(">>> retBool:" << retBool);
+                       return retBool;
+               }
+       }
+       }
+
+}
diff --git a/src/platform/API/Messaging/StorageChangesMessageFilterValidator.h b/src/platform/API/Messaging/StorageChangesMessageFilterValidator.h
new file mode 100755 (executable)
index 0000000..fc9ff87
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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 STORAGECHANGESMESSAGEFILTERVALIDATOR_H_
+#define STORAGECHANGESMESSAGEFILTERVALIDATOR_H_
+
+#include <API/Filter/FilterValidator.h>
+
+
+namespace TizenApis {
+
+       namespace Platform {
+
+               namespace Messaging {
+
+               class StorageChangesMessageFilterValidator: public Api::Tizen::FilterValidator {
+                       private:
+                               bool m_isTypeSetted;
+
+                       public:
+                       StorageChangesMessageFilterValidator(Api::Tizen::PropertyStructArray properties);
+
+                               virtual ~StorageChangesMessageFilterValidator();
+
+                               // validate AttributeRangeFilter
+                                       virtual bool validateAttributeRange(std::string& attrName,
+                                                       Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0);
+
+                                       virtual bool validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                                                               Api::Tizen::AnyPtr& matchValue, int depth=0);
+
+
+
+               };
+
+               typedef DPL::SharedPtr<StorageChangesMessageFilterValidator> StorageChangesMessageFilterValidatorPtr;
+       }
+}
+}
+
+#endif 
diff --git a/src/platform/API/Messaging/StorageChangesMessageFilterValidatorFactory.cpp b/src/platform/API/Messaging/StorageChangesMessageFilterValidatorFactory.cpp
new file mode 100755 (executable)
index 0000000..0258893
--- /dev/null
@@ -0,0 +1,75 @@
+//
+// 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 "StorageChangesMessageFilterValidatorFactory.h"
+
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_SERVICE_ID       = "serviceId";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_CONVERSATION_ID  = "conversationId";           
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_FOLDER_ID        = "folderId";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_TYPE             = "type";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP        = "timestamp";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_FROM             = "from";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_TO               = "to";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_CC               = "cc";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_BCC              = "bcc";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_BODY             = "body";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_IS_READ          = "isRead";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_HAS_ATTACHMENT   = "hasAttachment";            
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_PRIORITY         = "isHighPriority";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_SUBJECT          = "subject";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_IS_RESPONSE_TO   = "isResponseTo";
+               const std::string StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_MESSAGE_STATUS   = "messageStatus";
+
+
+               static PropertyStructArray properties =
+               {
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_SERVICE_ID.c_str(),            Api::Tizen::PrimitiveType_String},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_CONVERSATION_ID.c_str(),       Api::Tizen::PrimitiveType_String},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_FOLDER_ID.c_str(),             Api::Tizen::PrimitiveType_String},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_TYPE.c_str(),                  Api::Tizen::PrimitiveType_String},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP.c_str(), Api::Tizen::PrimitiveType_Time},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_FROM.c_str(),                  Api::Tizen::PrimitiveType_String},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_TO.c_str(),                    Api::Tizen::PrimitiveType_String},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_CC.c_str(),                    Api::Tizen::PrimitiveType_String},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_BCC.c_str(),                   Api::Tizen::PrimitiveType_String},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_BODY.c_str(),                  Api::Tizen::PrimitiveType_String},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_IS_READ.c_str(),               Api::Tizen::PrimitiveType_Number},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_HAS_ATTACHMENT.c_str(),        Api::Tizen::PrimitiveType_Number},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_PRIORITY.c_str(),  Api::Tizen::PrimitiveType_Number},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_SUBJECT.c_str(),               Api::Tizen::PrimitiveType_String},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_IS_RESPONSE_TO.c_str(),        Api::Tizen::PrimitiveType_String},
+                               {StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_MESSAGE_STATUS.c_str(),        Api::Tizen::PrimitiveType_String},
+                               {0,                  Api::Tizen::PrimitiveType_NoType}
+               };
+
+               StorageChangesMessageFilterValidatorPtr StorageChangesMessageFilterValidatorFactory::getStorageChangesMessageFilterValidator()
+               {
+                   static StorageChangesMessageFilterValidatorPtr theInstance =
+                               StorageChangesMessageFilterValidatorPtr(new StorageChangesMessageFilterValidator(properties));
+
+                   return theInstance;
+               }
+
+               }
+       }       //naspace Platform
+} //naspace WrtPlugins
diff --git a/src/platform/API/Messaging/StorageChangesMessageFilterValidatorFactory.h b/src/platform/API/Messaging/StorageChangesMessageFilterValidatorFactory.h
new file mode 100755 (executable)
index 0000000..5b09b93
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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 STORAGECHANGESMESSAGINGFILTERVALIDATORFACTORY_H_
+#define STORAGECHANGESMESSAGINGFILTERVALIDATORFACTORY_H_
+
+#include <API/Filter/FilterValidator.h>
+#include "StorageChangesMessageFilterValidator.h"
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               class StorageChangesMessageFilterValidatorFactory {
+                       private:
+                               StorageChangesMessageFilterValidatorFactory()
+                               {
+                               }
+
+                       public:
+                               static StorageChangesMessageFilterValidatorPtr getStorageChangesMessageFilterValidator();
+
+                       public:
+                               static const std::string ATTRIBUTE_SERVICE_ID;
+                               static const std::string ATTRIBUTE_CONVERSATION_ID;
+                               static const std::string ATTRIBUTE_FOLDER_ID;                           
+                               static const std::string ATTRIBUTE_TYPE;
+                               static const std::string ATTRIBUTE_TIMESTAMP;
+                               static const std::string ATTRIBUTE_FROM;
+                               static const std::string ATTRIBUTE_TO;
+                               static const std::string ATTRIBUTE_CC;
+                               static const std::string ATTRIBUTE_BCC;
+                               static const std::string ATTRIBUTE_BODY;
+                               static const std::string ATTRIBUTE_IS_READ;
+                               static const std::string ATTRIBUTE_HAS_ATTACHMENT;
+                               static const std::string ATTRIBUTE_PRIORITY;
+                               static const std::string ATTRIBUTE_SUBJECT;
+                               static const std::string ATTRIBUTE_IS_RESPONSE_TO;
+                               static const std::string ATTRIBUTE_MESSAGE_STATUS;
+               };
+
+               }
+       }               //Platform
+}
+
+#endif /* MESSAGINGFILTERVALIDATORFACTORY_H_ */
diff --git a/src/platform/API/Messaging/StorageChangesMessageGenerator.cpp b/src/platform/API/Messaging/StorageChangesMessageGenerator.cpp
new file mode 100644 (file)
index 0000000..8dacffc
--- /dev/null
@@ -0,0 +1,884 @@
+//
+// 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 "StorageChangesMessageGenerator.h"
+#include "StorageChangesMessageFilterValidatorFactory.h"
+#include "API/Messaging/ConversationFilterValidatorFactory.h"
+
+#include "IMessagingTypes.h"
+
+#include <email-types.h>
+
+#include <dpl/log/log.h>
+#include <algorithm>
+
+using namespace std;
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               const int StorageChangesMessageGenerator::MESSAGE_TYPE_NOT_INITIALIZED = -1;
+
+               StorageChangesMessageGenerator::StorageChangesMessageGenerator(Api::Messaging::IMessagePtr msg, Api::Messaging::IConversationPtr conv) : 
+                       m_messageType(MESSAGE_TYPE_NOT_INITIALIZED) , m_serviceId(-1)
+                       {
+
+                       m_type = msg->getMessageType();
+                       m_folder = msg->getCurrentFolder();
+                       m_dateTime = msg->getDateTime();
+                       m_from = msg->getFrom();
+                       m_conversationId = conv->getId();                       
+
+                       Recipents = msg->getToRecipientsPtr();
+
+                       if(m_type == Api::Messaging::SMS)
+                       {
+                               LogDebug("size :" << Recipents->getRecipientSize());
+                       
+                               if(Recipents->getRecipientSize()>0)
+                               {
+                               m_to = Recipents->getRecipientsRef();
+                                       LogDebug("m_to :" << m_to[0]);                                          
+                               }
+                       }
+                       else if(m_type == Api::Messaging::MMS)
+                       {
+                               LogDebug("to size :" << Recipents->getRecipientSize());
+                       
+                               Api::Messaging::IMmsPtr mms = DPL::DynamicPointerCast<Api::Messaging::IMms >(msg);
+                               if(Recipents->getRecipientSize() > 0)
+                               {
+                                       m_to = Recipents->getRecipientsRef();
+                                       LogDebug("m_to :" << m_to[0]);          
+                               }
+
+                               Recipents = mms->getCcRecipientsPtr();
+                               LogDebug("cc size :" << Recipents->getRecipientSize());
+                               
+                               if(Recipents->getRecipientSize() > 0)
+                               {
+                                       m_cc = Recipents->getRecipientsRef();
+                               }
+
+                               Recipents = mms->getBccRecipientsPtr();
+                               LogDebug("bcc size :" << Recipents->getRecipientSize());
+                               
+                               if(Recipents->getRecipientSize() > 0)
+                               {
+                                       m_bcc = Recipents->getRecipientsRef();
+                               }
+                               m_hasAttachment = mms->hasAttachment();
+
+
+                       }
+                       else if(m_type == Api::Messaging::EMAIL)
+                       {
+                               LogDebug("to size :" << Recipents->getRecipientSize());
+                       
+                               Api::Messaging::IEmailPtr email = DPL::DynamicPointerCast<Api::Messaging::IEmail >(msg);                        
+                               if(Recipents->getRecipientSize() > 0)
+                               {
+                                       m_to = Recipents->getRecipientsRef();
+                                       LogDebug("m_to :" << m_to[0]);          
+                               }
+
+                               Recipents = email->getCcRecipientsPtr();
+                               LogDebug("cc size :" << Recipents->getRecipientSize());
+                               
+                               if(Recipents->getRecipientSize() > 0)
+                               {
+                                       m_cc = Recipents->getRecipientsRef();
+                               }
+
+                               Recipents = email->getBccRecipientsPtr();
+                               LogDebug("bcc size :" << Recipents->getRecipientSize());
+                               
+                               if(Recipents->getRecipientSize() > 0)
+                               {
+                                       m_bcc = Recipents->getRecipientsRef();
+                               }
+                               
+                               m_serviceId =  email->getAccountID();
+                               if (m_serviceId ==  -1) {
+                                       ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+                                       "Couldn't convert e-mail account id");
+                               }
+
+                               m_hasAttachment = email->hasAttachment();
+
+//                             if (m_conversationId == email->getUID())
+//                                     m_isResponseTo = -1;
+                               m_isResponseTo = m_conversationId;
+                               
+                       }
+
+
+                       
+                       m_body = msg->getBody();
+                       m_isRead = msg->isRead();
+                       m_priority = msg->getPriority();
+                       m_subject = msg->getSubject();
+                       m_messageStatus = msg->getMessageStatus();
+               
+                       
+                       LogDebug("m_type:" << m_type );
+                       LogDebug("m_folder:" << m_folder );
+                       LogDebug("m_dateTime year:" << m_dateTime.tm_year + 1900 );
+                       LogDebug("m_dateTime mon:" << m_dateTime.tm_mon );
+                       LogDebug("m_dateTime day:" << m_dateTime.tm_mday );
+                       LogDebug("m_dateTime hour:" << m_dateTime.tm_hour );
+                       LogDebug("m_dateTime min:" << m_dateTime.tm_min );
+                       LogDebug("m_dateTime sec:" << m_dateTime.tm_sec );                      
+                       LogDebug("m_from:" << m_from );
+                       LogDebug("m_body:" << m_body );
+                       LogDebug("m_isRead:" << m_isRead );
+                       LogDebug("m_priority:" << m_priority );
+                       LogDebug("m_subject:" << m_subject );
+                       
+               }
+
+               StorageChangesMessageGenerator::~StorageChangesMessageGenerator() {
+               }
+
+               void StorageChangesMessageGenerator::visitPreComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+                       m_operand.push_back(leftblank);                                         
+                       LogDebug("Left_blank");                 
+                       LogDebug(">>>");
+               }
+
+               void StorageChangesMessageGenerator::visitInComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+                       if(type ==  UNION_FILTER ){
+                               LogDebug("UNION_FILTER");
+                               m_operand.push_back(operandUnion);                              
+                       }else if(type == INTERSECTION_FILTER){
+                               LogDebug("INTERSECTION_FILTER");
+                               m_operand.push_back(operandIntersection);                               
+                       }else{
+                               LogError("[ERROR] invalid Filter type:" << type);
+                       }
+
+                       LogDebug(">>>");
+               }
+
+               void StorageChangesMessageGenerator::visitPostComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+                       bool data1, data2;
+                       do
+                       {
+                               LogDebug("m_result size =" << m_result.size());
+                               data1 = m_result.back();
+                               m_result.pop_back();
+                               data2 = m_result.back();
+                               m_result.pop_back();
+                               LogDebug("m_result size =" << m_result.size());                         
+                               LogDebug("m_operand.back() =" << m_operand.back());     
+                               LogDebug("m_operand size =" << m_operand.size());                                                               
+                               if(m_operand.back() == operandUnion)
+                               {
+                                       LogDebug("Union");                              
+                                       LogDebug("data1 = " << data1);
+                                       LogDebug("data2 = " << data2);
+                                       LogDebug("data1 || data2 = " << (data1 || data2));                                      
+                                       m_operand.pop_back();
+                                       m_result.push_back(data1 || data2);
+                                       LogDebug("result" << m_result.back());
+                                       LogDebug("m_result size =" << m_result.size());
+                               }
+                               else if(m_operand.back() == operandIntersection)
+                               {
+                                       LogDebug("Intersection");                               
+                                       LogDebug("data1 = " << data1);
+                                       LogDebug("data2 = " << data2);
+                                       LogDebug("data1 && data2 = " << (data1 && data2));                                      
+                                       m_operand.pop_back();                           
+                                       m_result.push_back(data1 && data2);
+                                       LogDebug("result" << m_result.back());
+                                       LogDebug("m_result size =" << m_result.size());                                 
+                       
+                       }
+                       }while(m_operand.back() != leftblank);
+                       m_operand.pop_back();
+                       LogDebug("elase leftblank from m_operand");                     
+                       LogDebug("m_operand size =" << m_operand.size());                                                                                       
+                       LogDebug(">>>");
+               }
+
+               struct tm StorageChangesMessageGenerator::convertToTimeFormat(const std::string& timeString){
+                       LogDebug("<<< timeString:[" << timeString << "]");
+
+                       struct tm tm_Time;
+                       memset(&tm_Time, 0, sizeof(tm_Time));
+
+                       int nextStart = 0;
+
+                       int yearLength = 4;
+                       tm_Time.tm_year = atoi(timeString.substr(0, yearLength).c_str())-1900;
+                       nextStart = nextStart + yearLength;
+                       LogDebug("<<< tm_Time.tm_year:[" << tm_Time.tm_year << "]");
+
+                       int monthLength = 2;
+                       tm_Time.tm_mon = atoi(timeString.substr(nextStart, monthLength).c_str());
+                       nextStart = nextStart + monthLength;
+                       LogDebug("<<< initTime.tm_mon:[" << tm_Time.tm_mon << "]");
+
+                       int dateLength = 2;
+                       tm_Time.tm_mday = atoi(timeString.substr(nextStart, dateLength).c_str());
+                       nextStart = nextStart + dateLength;
+                       LogDebug("<<< initTime.tm_mday:[" << tm_Time.tm_mday << "]");
+
+                       int hourLength = 2;
+                       tm_Time.tm_hour = atoi(timeString.substr(nextStart, hourLength).c_str());
+                       nextStart = nextStart + hourLength;
+                       LogDebug("<<< initTime.tm_hour:[" << tm_Time.tm_hour << "]");
+
+                       int minuteLength = 2;
+                       tm_Time.tm_min = atoi(timeString.substr(nextStart, minuteLength).c_str());
+                       nextStart = nextStart + minuteLength;
+                       LogDebug("<<< initTime.tm_min:[" << tm_Time.tm_min << "]");
+
+                       int secondLength = 2;
+                       tm_Time.tm_sec = atoi(timeString.substr(nextStart, secondLength).c_str());
+                       LogDebug("<<< initTime.tm_sec:[" << tm_Time.tm_sec << "]");
+
+                       return tm_Time;
+               }
+
+               bool StorageChangesMessageGenerator::getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+                       LogDebug("<<< attrName.compare(valueString) : " << attrName.compare(valueString));
+                       
+                       if(attrName.compare(valueString) == 0)
+                       {
+                               LogDebug("<<< getMatchExactlyClause SAME >>>");
+                               return TRUE;                            
+                       }
+                       else{
+                               LogDebug("<<< getMatchExactlyClause DIFF >>>");
+                               return FALSE;                                                           
+                       }
+                       }
+
+               bool StorageChangesMessageGenerator::getMatchFullstringClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string tempString1;
+                       std::string tempString2;
+                       
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+                       
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+
+                       LogDebug("<<< attrName : " << tempString1);
+                       LogDebug("<<< valueString : " << tempString2);
+                       
+                       if(tempString1.compare(tempString2) == 0)
+                       {
+                               LogDebug("<<< getMatchFullstringClause SAME >>>");
+                               return TRUE;                            
+                       }
+                       else{
+                               LogDebug("<<< getMatchFullstringClause DIFF >>>");
+                               return FALSE;                                                           
+                       }
+               }
+
+               bool StorageChangesMessageGenerator::getMatchContainsClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+
+                       std::string tempString1;
+                       std::string tempString2;
+               
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+
+                       LogDebug("<<< attrName : " << tempString1);
+                       LogDebug("<<< valueString : " << tempString2);
+                       
+                       if(tempString1.find(tempString2) != std::string::npos)
+                       {
+                               LogDebug("<<< getMatchContainsClause CONTAINS >>>");
+                               return TRUE;                            
+                       }else{
+                               LogDebug("<<< getMatchContainsClause NOT CONTAINS >>>");
+                               return FALSE;                                                           
+                       }
+               }
+
+               bool StorageChangesMessageGenerator::getMatchStartwithClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string tempString1;
+                       std::string tempString2;
+               
+                       std::string valueString = value->toString();
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+
+                       LogDebug("<<< attrName : " << tempString1);
+                       LogDebug("<<< valueString : " << tempString2);
+
+                       
+                       if(tempString1.size() < tempString2.size())
+                               return FALSE;
+                               
+                       if(tempString1.compare(0,tempString2.size(), tempString2) == 0)
+                       {
+                               LogDebug("<<< getMatchStartwithClause START WITH >>>");
+                       return TRUE;
+               }
+                       else{
+                               LogDebug("<<< getMatchStartwithClause NOT START WITH >>>");
+                               return FALSE;                                                           
+                       }
+               }
+
+               bool StorageChangesMessageGenerator::getMatchEndwithClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string tempString1;
+                       std::string tempString2;
+               
+                       std::string valueString = value->toString();
+
+                       LogDebug("<<< attrName : " << attrName);
+                       LogDebug("<<< valueString : " << valueString);
+
+                       tempString1.assign(attrName);
+                       tempString2.assign(valueString);
+
+                       StrLowChange(tempString1);
+                       StrLowChange(tempString2);
+                       
+                       LogDebug("<<< attrName.compare(attrName.size()-valueString.size(),valueString.size(), valueString) : " << attrName.compare(attrName.size()-valueString.size(),valueString.size(), valueString));
+
+
+                       if(tempString1.size() < tempString2.size())
+                               return FALSE;
+                       
+                       if(tempString1.compare(tempString1.size()-tempString2.size(),tempString2.size(), tempString2) == 0 )
+                       {
+                               LogDebug("<<< getMatchEndwithClause END WITH >>>");
+                               return TRUE;                            
+                       }
+                       else{
+                               LogDebug("<<< getMatchEndwithClause NOT END WITH >>>");
+                               return FALSE;                                                           
+                       }
+               }
+               
+               bool StorageChangesMessageGenerator::getBetweenRangeClause(struct tm initialValue, struct tm endValue)
+               {
+                       time_t init_time, mid_time, end_time;
+                       init_time = mktime(&initialValue);
+                       mid_time = mktime(&m_dateTime);
+                       end_time = mktime(&endValue);
+                       LogDebug("<<< mktime(initialValue):[" << init_time << "]");
+                       LogDebug("<<< mktime(m_dateTime):[" << mid_time << "]");
+                       LogDebug("<<< mktime(endValue):[" << end_time << "]");
+                       LogDebug("<<< mid_time - init_time:[" << mid_time - init_time << "]");
+                       LogDebug("<<< end_time - mid_time:[" << end_time - mid_time << "]");
+                       
+                       if(((mid_time - init_time) >= 0 ) && ((end_time - mid_time) >= 0 ))
+                               return TRUE;
+                       else
+                               return FALSE;
+                               
+               }
+
+               bool StorageChangesMessageGenerator::getMatchExistClause(std::string& attrName)
+               {
+                       LogDebug("<<< attrName : " << attrName);
+                       if(attrName.size()> 0)
+                               return TRUE;
+                       else
+                               return FALSE;
+               }
+
+               void StorageChangesMessageGenerator::visitAttribute(std::string& attrName,
+                               MatchFlag& matchFlag, Api::Tizen::AnyPtr& matchValue, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]");
+                       if(matchFlag != Api::Tizen::MATCH_EXISTS){
+                               if(matchValue == NULL)  {
+                               return;
+                               }
+                       }
+
+                       LogDebug("matchValue:" << matchValue->toString());
+
+                       visitAttributeEach(attrName, matchFlag, matchValue, depth);
+
+                       LogDebug(">>>");
+               }
+               
+               void StorageChangesMessageGenerator::visitAttributeEach(std::string& attrName, MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
+                       std::string valueString;
+
+//  Check msg_type and filter_type
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_SERVICE_ID)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               int nType = atoi(value->toString().c_str());                            
+                               if(m_serviceId == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< Type is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< Type is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_CONVERSATION_ID)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               int nType = atoi(value->toString().c_str());                            
+                               if(m_conversationId == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< conversationID is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< conversationID is different");
+                               }
+                               return;
+                       }                       
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_TYPE)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               m_currentType = value->toString();
+                               m_messageType = convertMessageType(m_currentType);
+                               if((int)m_type == m_messageType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< Type is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< Type is different");
+                               }
+                               return;
+                               }
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_FOLDER_ID)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               int nType = atoi(value->toString().c_str());
+                               if((int)m_folder == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< folder is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< folder is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_IS_READ)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               std::string lowerString;
+                               lowerString.assign(value->toString());
+                               StrLowChange(lowerString);                              
+                               int nType = lowerString.compare("true");
+                               if((int)m_isRead != nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< isRead is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< isRead is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_HAS_ATTACHMENT)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               std::string lowerString;
+                               lowerString.assign(value->toString());
+                               StrLowChange(lowerString);                              
+                               int nType = lowerString.compare("true");
+                               if((int)m_hasAttachment != nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< isRead is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< isRead is different");
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_MESSAGE_STATUS)==0){
+                               LogDebug("<<< value:[" << value->toString() << "]");
+                               std::string convertStatus = value->toString();
+                               int nStatus = convertMessageStatus(convertStatus);
+                               if((int)m_messageStatus == nStatus)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< folder is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< folder is different");
+                               }
+                               return;
+                       }                       
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_PRIORITY)==0){
+                               LogDebug("<<< value:[" << value->toString() << "]");
+                               std::string lowerString;
+                               lowerString.assign(value->toString());
+                               StrLowChange(lowerString);      
+                               if(lowerString.compare("true"))
+                               {
+                                       if((int)m_priority == Api::Messaging::MessagePriority::Priority::HIGH)
+                                       {
+                                               m_result.push_back(TRUE);
+                                               LogDebug("<<< priority is HIGH");
+                                       }
+                                       else
+                                       {
+                                               m_result.push_back(FALSE);
+                                               LogDebug("<<< priority is LOW OR NORMAL");
+                                       }
+                               }
+                               else if(lowerString.compare("false") == 0)
+                               {
+                                       if((int)m_priority == Api::Messaging::MessagePriority::Priority::NORMAL)
+                                       {
+                                               m_result.push_back(FALSE);
+                                               LogDebug("<<< priority is HIGH");
+                                       }
+                                       else
+                                       {
+                                               m_result.push_back(TRUE);
+                                               LogDebug("<<< priority is LOW OR NORMAL");
+                                       }
+                               }
+                               return;
+                       }
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_BODY)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_body:[" << m_body << "]");
+
+                               valueString = m_body;
+                               if(getMatchFlagResult(value, valueString, matchFlag))
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< body is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< body is different");
+                               }
+                               return;
+                       }
+
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_SUBJECT)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_subject:[" << m_subject << "]");
+
+                               valueString = m_subject;
+                               if(getMatchFlagResult(value, valueString, matchFlag))
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< subject is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< subject is different");
+                               }
+                               return;
+                       }
+
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_FROM)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_from:[" << m_from << "]");
+
+                               valueString = m_from;
+                               if(getMatchFlagResult(value, valueString, matchFlag))
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< from is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< from is different");
+                               }
+                               return;
+                       }
+
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_TO)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_to.size :[" << m_to.size() << "]");
+
+                               bool result = FALSE;
+                               for(unsigned int i=0; i < m_to.size(); i++)
+                               {
+                                       valueString = m_to[i];
+                                       result = result || getMatchFlagResult(value, valueString, matchFlag);
+                               }
+                               LogDebug("<<< to compare result is :" << result);
+                               m_result.push_back(result);
+                               return;
+                       }
+
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_CC)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_cc.size :[" << m_cc.size() << "]");
+
+                               bool result = FALSE;
+                               for(unsigned int i=0; i < m_cc.size(); i++)
+                               {
+                                       valueString = m_cc[i];
+                                       result = result || getMatchFlagResult(value, valueString, matchFlag);
+                               }
+                               LogDebug("<<< cc compare result is : " << result);
+                               m_result.push_back(result);
+                               return;
+                       }
+
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_BCC)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               LogDebug("<<< value->toString():[" << value->toString() << "]");
+                               LogDebug("<<< m_cc.size :[" << m_bcc.size() << "]");
+
+                               bool result = FALSE;
+                               for(unsigned int i=0; i < m_bcc.size(); i++)
+                               {
+                                       valueString = m_bcc[i];
+                                       result = result || getMatchFlagResult(value, valueString, matchFlag);
+                               }
+                               LogDebug("<<< bcc compare result is : " << result);
+                               m_result.push_back(result);
+                               return;
+                       }
+
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_IS_RESPONSE_TO)==0){
+                               LogDebug("<<< value:[" << value << "]");
+                               int nType = atoi(value->toString().c_str());                            
+                               if(m_isResponseTo == nType)
+                               {
+                                       m_result.push_back(TRUE);
+                                       LogDebug("<<< conversationID is same");
+                               }
+                               else
+                               {
+                                       m_result.push_back(FALSE);
+                                       LogDebug("<<< conversationID is different");
+                               }
+                               return;
+                       }
+                       LogDebug(">>>");
+               }
+
+               int StorageChangesMessageGenerator::convertMessageType(std::string& stringType){
+                       LogDebug("<<< stringType:[" << stringType << "]");
+
+                       int retMessageType = -1;
+
+                       if(stringType.compare("messaging.sms") ==0){
+                               retMessageType = Api::Messaging::SMS;
+                       }else if(stringType.compare("messaging.mms") ==0){
+                               retMessageType = Api::Messaging::MMS;
+                       }else if(stringType.compare("messaging.email") ==0){
+                               retMessageType = Api::Messaging::EMAIL;
+                       }else{
+                               LogError("invalid type:[" << stringType << "]");
+                               return -1;
+                       }
+
+                       LogDebug(">>> retMessageType:" << retMessageType);
+                       return retMessageType;
+               }
+
+               int StorageChangesMessageGenerator::convertFolderType(std::string& stringType){
+                       LogDebug("<<< stringType:[" << stringType << "]");
+
+                       int retMessageType = -1;
+
+                       if(stringType.compare("INBOX") ==0){
+                               retMessageType = Api::Messaging::INBOX;
+                       }else if(stringType.compare("OUTBOX") ==0){
+                               retMessageType = Api::Messaging::OUTBOX;
+                       }else if(stringType.compare("DRAFTBOX") ==0){
+                               retMessageType = Api::Messaging::DRAFTBOX;
+                       }else if(stringType.compare("SENTBOX") ==0){
+                               retMessageType = Api::Messaging::SENTBOX;
+                       }else{
+                               LogError("invalid type:[" << stringType << "]");
+                               return -1;
+                       }
+
+                       LogDebug(">>> retMessageType:" << retMessageType);
+                       return retMessageType;
+               }
+
+               int StorageChangesMessageGenerator::convertMessageStatus(std::string& stringStatus){
+                       LogDebug("<<< stringType:[" << stringStatus << "]");
+
+                       int retMessageStatus = -1;
+
+                       if(stringStatus.compare("SENT") ==0){
+                               retMessageStatus = Api::Messaging::MESSAGE_STATUS_SENT;
+                       }else if(stringStatus.compare("SENDING") ==0){
+                               retMessageStatus = Api::Messaging::MESSAGE_STATUS_SENDING;
+                       }else if(stringStatus.compare("FAILED") ==0){
+                               retMessageStatus = Api::Messaging::MESSAGE_STATUS_FAILED;
+                       }else if(stringStatus.compare("DRAFT") ==0){
+                               retMessageStatus = Api::Messaging::MESSAGE_STATUS_DRAFT;
+                       }else{
+                               LogError("invalid type:[" << stringStatus << "]");
+                               return -1;
+                       }
+
+                       LogDebug(">>> retMessageType:" << retMessageStatus);
+                       return retMessageStatus;
+               }
+
+               void StorageChangesMessageGenerator::visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth) {
+                       struct tm startTime;
+                       struct tm endTime;
+                       bool result = FALSE;
+
+                       string initialValueStr;
+                       string endValueStr;
+
+                       if(initialValue == NULL || endValue == NULL)
+                               return;
+
+                       if(attrName.compare(StorageChangesMessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP)==0){
+//                             startTime = convertToTimeFormat(initialValueStr);
+//                             endTime = convertToTimeFormat(endValueStr);
+
+                               if (!initialValue->isNullOrUndefined()) {
+                                       if( TizenApis::Api::Tizen::PrimitiveType_Time==initialValue->getType() ) {
+                                               LogDebug("<<<initialValue->getType()[" << initialValue->getType() <<"]");                                       
+                                               startTime = initialValue->getDateTm();
+                                       }
+                                       else {
+                                               LogError("initialValue->getType() : [" << initialValue->getType() << "]");                                      
+                                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid initialValue Type");
+                                       }
+                               }
+                               
+                               if (!endValue->isNullOrUndefined()) {
+                                       if( TizenApis::Api::Tizen::PrimitiveType_Time==endValue->getType() ) {
+                                               LogDebug("<<<initialValue->getType()[" << endValue->getType() <<"]");                                   
+                                               endTime = endValue->getDateTm();
+                                               LogDebug("<<<valueStr[" << endValueStr <<"]");                                  
+                                       } else {
+                                               LogError("endValue->getType() : [" << endValue->getType() << "]");                                      
+                                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid endValue Type");
+                                       }
+                               }
+
+                               result = getBetweenRangeClause(startTime, endTime);
+                               if(result == TRUE)
+                               {
+                                       LogDebug("<<< timestamp is in range");
+                                       m_result.push_back(TRUE);
+                               }else{
+                                       LogDebug("<<< timestamp is out of range");
+                                       m_result.push_back(FALSE);
+                               }
+                       }
+               }
+
+               bool StorageChangesMessageGenerator::getMatchFlagResult(Api::Tizen::AnyPtr& value, std::string& valueString, MatchFlag& matchFlag)
+               {
+                               std::vector<std::string>::iterator iter;
+                       bool result = FALSE;
+                       if(matchFlag == Api::Tizen::MATCH_EXACTLY){
+                               LogDebug("STRING_MATCH_EXACTLY");
+                               result = result || getMatchExactlyClause(valueString, value);
+                       }else if(matchFlag == Api::Tizen::MATCH_FULLSTRING){
+                               LogDebug("STRING_MATCH_FULLSTRING");
+                               result = result || getMatchFullstringClause(valueString, value);                                                
+                       }else if(matchFlag == Api::Tizen::MATCH_CONTAINS){
+                               LogDebug("STRING_MATCH_CONTAINS");
+                               result = result || getMatchContainsClause(valueString, value);                                          
+                       }else if(matchFlag == Api::Tizen::MATCH_STARTSWITH){
+                               LogDebug("STRING_MATCH_STARTSWITH");
+                               result = result || getMatchStartwithClause(valueString, value);
+                       }else if(matchFlag == Api::Tizen::MATCH_ENDSWITH){
+                               LogDebug("STRING_MATCH_ENDSWITH");
+                               result = result || getMatchEndwithClause(valueString, value);                           
+                       }else if(matchFlag == Api::Tizen::MATCH_EXISTS){
+                               LogDebug("STRING_MATCH_EXIST");
+                               result = result || getMatchExistClause(valueString);
+                       }else{
+                               LogDebug("[ERROR]invalid match flag : iter:" << *iter);
+                       }
+                       return result;
+               }
+
+               bool StorageChangesMessageGenerator::getCompareResult()
+               {
+                       bool result;
+                       LogDebug("m_result.size() " << m_result.size());                                
+                       result = m_result.back();
+                       m_result.pop_back();
+                       LogDebug("result = " << result);        
+                       return result;
+               }
+
+               void StorageChangesMessageGenerator::StrLowChange(std::string& tempString)
+               {       
+                       std::transform(tempString.begin(), tempString.end(), tempString.begin(), ::tolower);
+                       return;
+               }
+
+
+       }
+       }               //namespace Platform
+}              //namespace WrtPlugins
diff --git a/src/platform/API/Messaging/StorageChangesMessageGenerator.h b/src/platform/API/Messaging/StorageChangesMessageGenerator.h
new file mode 100755 (executable)
index 0000000..b58bb8c
--- /dev/null
@@ -0,0 +1,124 @@
+//
+// 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 STORAGECHANGESMESSAGEGENERATOR_H_
+#define STORAGECHANGESMESSAGEGENERATOR_H_
+
+#include <API/Filter/IFilterVisitor.h>
+#include <API/Filter/SortMode.h>
+#include <API/Messaging/IMessaging.h>
+
+#include <map>
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+
+//             using namespace std;
+
+               class StorageChangesMessageGenerator: public TizenApis::Api::Tizen::IFilterVisitor{
+                       public:
+
+                               enum operandType
+                               {
+                                       leftblank = 1,
+                                       rightblank = 2,
+                                       operandUnion = 3,
+                                       operandIntersection = 4
+                               };
+                               
+                               StorageChangesMessageGenerator(Api::Messaging::IMessagePtr msg, Api::Messaging::IConversationPtr convconv);
+                               virtual ~StorageChangesMessageGenerator();
+
+                               void visitPreComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitInComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitPostComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitAttribute(std::string& attrName,
+                                               Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& matchValue, int depth);
+                               void visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth);
+                               bool getMatchFlagResult(Api::Tizen::AnyPtr& value, std::string& valueString, Api::Tizen::MatchFlag& matchFlag);
+                               bool getCompareResult();                                                        
+                               int getMessageType(){
+                                       return m_messageType;
+                               };
+
+                       private:
+                               std::string convertToEmfAttrName(std::string attrName);
+                               bool getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchFullstringClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchContainsClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchStartwithClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               bool getMatchEndwithClause(std::string& attrName, Api::Tizen::AnyPtr& value);                           
+                               bool getMatchExistClause(std::string& attrName);                                
+                               bool getBetweenRangeClause(struct tm initialValue, struct tm endValue);                         
+
+                               void visitAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth);
+                               int convertMessageType(std::string& stringType);
+                               int convertMessageStatus(std::string& stringStatus);                            
+                               int convertFolderType(std::string& stringType);                         
+
+                               struct tm convertToTimeFormat(const std::string& timeString);                   
+                               std::string createTimeString(std::string& timeString);
+                               std::string createFolderType(std::string& value);
+                               std::string createPriorityType(std::string& value);
+                               std::string createDateTimeType(Api::Tizen::AnyPtr& value);
+                               void initAttributeMap();
+
+                               void StrLowChange(std::string& tempString);
+
+                       private:
+                               int m_messageType;
+
+                               std::vector<std::string> typeVector;
+                               std::map<std::string, std::string> attributeMap;
+
+                               std::vector<bool> m_result;
+                               std::vector<int> m_operand;                             
+
+//                             std::string m_id;
+                               Api::Messaging::MessageType m_type;
+                               Api::Messaging::FolderType m_folder;
+                               struct tm m_dateTime;
+                               std::string m_from;
+                               std::vector<std::string> m_to;
+                               std::vector<std::string> m_cc;
+                               std::vector<std::string> m_bcc;
+                               std::string m_body;
+                               bool m_isRead;
+                               Api::Messaging::MessagePriority::Priority m_priority;
+                               std::string m_subject;
+
+//new attribute
+                               int m_serviceId;
+                               int m_conversationId;
+                               int m_isResponseTo;
+                               Api::Messaging::MessageStatus  m_messageStatus;
+                               bool m_hasAttachment;
+
+                               Api::Messaging::RecipientsPtr Recipents;
+                               std::string m_currentType;
+
+                               static const int MESSAGE_TYPE_NOT_INITIALIZED;
+
+               };
+
+               typedef DPL::SharedPtr<StorageChangesMessageGenerator> StorageChangesMessageGeneratorPtr;
+       }               // namespace Platform
+} // namespace WrtPlugins
+}
+#endif /* MESSAGEQUERYGENERATOR_H_ */
diff --git a/src/platform/API/Messaging/Subject.cpp b/src/platform/API/Messaging/Subject.cpp
new file mode 100755 (executable)
index 0000000..694efae
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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 "Subject.h"
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+Subject::Subject() :
+    m_subject(""),
+    m_validSubject(false)
+{
+}
+
+Subject::~Subject()
+{
+}
+
+void Subject::setSubject(const string& value)
+{
+    m_validSubject = false;
+    m_subject = value;
+}
+
+string Subject::getSubject() const
+{
+    return m_subject;
+}
+
+const std::string& Subject::getSubjectRef() const
+{
+    return m_subject;
+}
+
+bool Subject::isSubjectValid() const
+{
+    return m_validSubject;
+}
+
+void Subject::setSubjectValidity(bool state)
+{
+    m_validSubject = state;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/Subject.h b/src/platform/API/Messaging/Subject.h
new file mode 100755 (executable)
index 0000000..b309f23
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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 SUBJECT_H
+#define SUBJECT_H
+
+#include <string>
+#include "IMessagingTypes.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class Subject
+{
+  private:   // fields
+    /**
+     * abstract subject value of message
+     */
+    std::string m_subject;
+
+    /**
+     * information if abstract message body has been changed and need update
+     * in low level
+     */
+    bool m_validSubject;
+
+  public:   // methods
+
+    Subject();
+
+    virtual ~Subject();
+
+    /**
+     * setter of subject value
+     */
+    void setSubject(const std::string& value);
+
+    /**
+     * getter of subject value
+     */
+    std::string getSubject() const;
+
+    /**
+     * getter of subject value
+     */
+    const std::string& getSubjectRef() const;
+
+    /**
+     * check validity state
+     */
+    bool isSubjectValid() const;
+
+    /**
+     * setter for validity state
+     */
+    void setSubjectValidity(bool state);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/ToRecipient.cpp b/src/platform/API/Messaging/ToRecipient.cpp
new file mode 100644 (file)
index 0000000..b093e01
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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 "ToRecipient.h"
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+ToRecipient::ToRecipient() :
+    m_toRecipients(new Recipients())
+{
+}
+
+ToRecipient::~ToRecipient()
+{
+}
+
+void ToRecipient::setToValidity(bool state)
+{
+    m_toRecipients->setValid(state);
+}
+
+bool ToRecipient::getToValidity() const
+{
+    return m_toRecipients->isValid();
+}
+
+Recipients ToRecipient::getToRecipients() const
+{
+    return *m_toRecipients;
+}
+
+RecipientsPtr ToRecipient::getToRecipientsPtr() const
+{
+    return m_toRecipients;
+}
+
+void ToRecipient::appendToRecipients(const string & value)
+{
+    m_toRecipients->appendRecipient(value);
+}
+
+void ToRecipient::appendToRecipients(const Recipients& value)
+{
+    LogDebug("enter, recipientCount=" << value.getRecipientSize());
+    *m_toRecipients += value;
+}
+
+void ToRecipient::removeToRecipients(const Recipients& value)
+{
+    *m_toRecipients -= value;
+}
+
+void ToRecipient::setToRecipients(const Recipients& value)
+{
+    *m_toRecipients = value;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/ToRecipient.h b/src/platform/API/Messaging/ToRecipient.h
new file mode 100644 (file)
index 0000000..25ef4b5
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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 TORECIPIENT_H
+#define TORECIPIENT_H
+
+#include "Recipient.h"
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+class ToRecipient
+{
+  private: // fields
+
+    RecipientsPtr m_toRecipients;
+
+  public:
+
+    ToRecipient();
+
+    virtual ~ToRecipient();
+
+    void setToValidity(bool state);
+
+    bool getToValidity() const;
+
+    Recipients getToRecipients() const;
+
+    RecipientsPtr getToRecipientsPtr() const;
+
+    void appendToRecipients(const std::string & value);
+
+    void appendToRecipients(const Recipients& value);
+
+    void removeToRecipients(const Recipients& value);
+
+    void setToRecipients(const Recipients& value);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/ValidityPeriodHours.cpp b/src/platform/API/Messaging/ValidityPeriodHours.cpp
new file mode 100755 (executable)
index 0000000..4c64c5e
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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 "ValidityPeriodHours.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+ValidityPeriodHours::ValidityPeriodHours() :
+    m_validityPeriodHours(0),
+    m_validValidityPeriodHours(false)
+{
+}
+
+ValidityPeriodHours::~ValidityPeriodHours()
+{
+}
+
+void ValidityPeriodHours::setValidityPeriodHours(int value)
+{
+    m_validityPeriodHours = value;
+    m_validValidityPeriodHours = false;
+}
+
+int ValidityPeriodHours::getValidityPeriodHours() const
+{
+    return m_validityPeriodHours;
+}
+
+bool ValidityPeriodHours::isValidityPeriodHoursValid() const
+{
+    return m_validValidityPeriodHours;
+}
+
+void ValidityPeriodHours::setValidityPeriodHoursValidity(bool state)
+{
+    m_validValidityPeriodHours = state;
+}
+}
+}
+}
diff --git a/src/platform/API/Messaging/ValidityPeriodHours.h b/src/platform/API/Messaging/ValidityPeriodHours.h
new file mode 100755 (executable)
index 0000000..f6f4fb2
--- /dev/null
@@ -0,0 +1,71 @@
+//
+// 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 VALIDITYPERIODHOURS_H
+#define VALIDITYPERIODHOURS_H
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class ValidityPeriodHours
+{
+  private:   // fields
+
+    /**
+     * ValidityPeriodHours value
+     */
+    int m_validityPeriodHours;
+
+    /**
+     * information if abstract message ValidityPeriodHours has been changed and need update
+     * in low level
+     */
+    bool m_validValidityPeriodHours;
+
+  public:   // methods
+
+    ValidityPeriodHours();
+
+    virtual ~ValidityPeriodHours();
+
+    /**
+     * setter of ValidityPeriodHours value
+     */
+    void setValidityPeriodHours(int value);
+
+    /**
+     * getter of ValidityPeriodHours value
+     */
+    int getValidityPeriodHours() const;
+
+    /**
+     * check ValidityPeriodHours validity
+     * */
+    bool isValidityPeriodHoursValid() const;
+
+    /**
+     * set ValidityPeriodHours validity
+     * */
+    void setValidityPeriodHoursValidity(bool state);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/VirtualMessage.cpp b/src/platform/API/Messaging/VirtualMessage.cpp
new file mode 100755 (executable)
index 0000000..ee537a4
--- /dev/null
@@ -0,0 +1,102 @@
+//
+// 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       VirtualMessage.cpp
+ * @author     Pawel Misiak (p.misiak@samsung.com)
+ * @version    0.1
+ * @brief
+ */
+#include <dpl/log/log.h>
+#include "Commons/Exception.h"
+#include "IMessage.h"
+#include "VirtualMessage.h"
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+VirtualMessage::VirtualMessage() :
+    IMessage(VIRTUAL_MESSAGE, "")
+{
+}
+
+VirtualMessage::~VirtualMessage()
+{
+}
+
+int VirtualMessage::send()
+{
+ return -1;
+}
+
+void VirtualMessage::sendCancel(int handle)
+{
+}
+
+void VirtualMessage::update(bool /*draftsOnly*/)
+{
+}
+
+void VirtualMessage::readAllData()
+{
+}
+
+void VirtualMessage::moveToFolder(const FolderType newFolder)
+{
+}
+
+void VirtualMessage::moveToFolder(const std::string& newFolder)
+{
+}
+
+void VirtualMessage::copyToFolder(const FolderType newFolder)
+{
+}
+
+void VirtualMessage::copyToFolder(const std::string& newFolder)
+{
+}
+
+void VirtualMessage::remove()
+{
+}
+
+void VirtualMessage::updateIsRead()
+{
+}
+
+void VirtualMessage::updateMessage()
+{
+}
+
+void VirtualMessage::addMessageToDraft()
+{
+}
+
+void VirtualMessage::createSendMessage(){
+}
+
+
+
+}
+}
+}
diff --git a/src/platform/API/Messaging/VirtualMessage.h b/src/platform/API/Messaging/VirtualMessage.h
new file mode 100755 (executable)
index 0000000..ae61c08
--- /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.
+//
+
+#ifndef IVIRTUALMESSAGE_H
+#define IVIRTUALMESSAGE_H
+
+#include <string>
+#include <ctime>
+#include <dpl/shared_ptr.h>
+#include "IMessage.h"
+#include "Subject.h"
+#include "CcRecipient.h"
+#include "BccRecipient.h"
+#include "Attachments.h"
+#include "CallbackNumber.h"
+#include "ValidityPeriodHours.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Messaging {
+
+//--------------------------------------------------------------------------
+
+class VirtualMessage;
+typedef DPL::SharedPtr<VirtualMessage> VirtualMessagePtr;
+
+class VirtualMessage :
+    public IMessage,
+    public CcRecipient,
+    public BccRecipient,
+    public Attachments
+{
+  public:
+    VirtualMessage();
+
+    virtual ~VirtualMessage();
+
+    int send();
+
+    void sendCancel(int handle);
+
+    void update(bool draftsOnly = false);
+
+    void readAllData();
+
+    void moveToFolder(const FolderType newFolder);
+
+    void moveToFolder(const std::string& newFolder);
+
+    void copyToFolder(const FolderType newFolder);
+
+    void copyToFolder(const std::string& newFolder);
+
+    void remove();
+
+    void updateIsRead();       
+
+    void updateMessage();      
+
+    void addMessageToDraft();
+       
+    void createSendMessage();  
+       
+};
+}
+}
+}
+#endif
diff --git a/src/platform/API/Messaging/config.cmake b/src/platform/API/Messaging/config.cmake
new file mode 100755 (executable)
index 0000000..a90fb9b
--- /dev/null
@@ -0,0 +1,57 @@
+get_current_path()
+set(SRCS_PLATFORM_API_MESSAGING
+  ${CURRENT_PATH}/IMessagingServiceManager.cpp
+  ${CURRENT_PATH}/IMessagingService.cpp
+  ${CURRENT_PATH}/MessagingFactory.cpp
+
+    ${CURRENT_PATH}/Attachments.cpp
+    ${CURRENT_PATH}/IAttachment.cpp
+    ${CURRENT_PATH}/AttachmentFactory.cpp
+    ${CURRENT_PATH}/BccRecipient.cpp
+    ${CURRENT_PATH}/Body.cpp
+    ${CURRENT_PATH}/CcRecipient.cpp
+    ${CURRENT_PATH}/From.cpp
+    ${CURRENT_PATH}/IBinarySms.cpp
+    ${CURRENT_PATH}/IEmptyMessage.cpp   
+    ${CURRENT_PATH}/IEmail.cpp
+    ${CURRENT_PATH}/IMessage.cpp
+    ${CURRENT_PATH}/IMessaging.cpp
+    ${CURRENT_PATH}/IMms.cpp
+    ${CURRENT_PATH}/MmsSlide.cpp
+    ${CURRENT_PATH}/MmsSlides.cpp
+    ${CURRENT_PATH}/MmsSlideProperty.cpp
+    ${CURRENT_PATH}/ISms.cpp
+    ${CURRENT_PATH}/MessageFactory.cpp
+    ${CURRENT_PATH}/Recipient.cpp
+    ${CURRENT_PATH}/Subject.cpp
+    ${CURRENT_PATH}/ToRecipient.cpp
+    ${CURRENT_PATH}/ReqReceiverMessage.cpp
+    ${CURRENT_PATH}/EmailAccountInfo.cpp
+    ${CURRENT_PATH}/IEmailAccount.cpp
+    ${CURRENT_PATH}/SourceAddress.cpp
+    ${CURRENT_PATH}/CallbackNumber.cpp
+    ${CURRENT_PATH}/ValidityPeriodHours.cpp
+    ${CURRENT_PATH}/MessagePriority.cpp
+    ${CURRENT_PATH}/VirtualMessage.cpp
+    ${CURRENT_PATH}/EventMessageReceived.cpp
+    ${CURRENT_PATH}/EmitterMessageReceived.cpp
+    ${CURRENT_PATH}/EmitterConversationReceived.cpp
+    ${CURRENT_PATH}/EmitterFolderReceived.cpp    
+    ${CURRENT_PATH}/MessageFilterValidatorFactory.cpp
+    ${CURRENT_PATH}/MessageFilterValidator.cpp
+    ${CURRENT_PATH}/ConversationFilterValidatorFactory.cpp
+    ${CURRENT_PATH}/ConversationFilterValidator.cpp
+    ${CURRENT_PATH}/FolderFilterValidatorFactory.cpp
+    ${CURRENT_PATH}/FolderFilterValidator.cpp    
+    ${CURRENT_PATH}/StorageChangesMessageFilterValidatorFactory.cpp
+    ${CURRENT_PATH}/StorageChangesMessageFilterValidator.cpp
+    ${CURRENT_PATH}/StorageChangesMessageGenerator.cpp    
+    ${CURRENT_PATH}/StorageChangesConversationFilterValidatorFactory.cpp
+    ${CURRENT_PATH}/StorageChangesConversationFilterValidator.cpp    
+    ${CURRENT_PATH}/StorageChangesConversationGenerator.cpp    
+    ${CURRENT_PATH}/StorageChangesFolderFilterValidatorFactory.cpp
+    ${CURRENT_PATH}/StorageChangesFolderFilterValidator.cpp    
+    ${CURRENT_PATH}/StorageChangesFolderGenerator.cpp        
+
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Messaging/log.h b/src/platform/API/Messaging/log.h
new file mode 100755 (executable)
index 0000000..b46c4a6
--- /dev/null
@@ -0,0 +1,24 @@
+//
+// 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 LOG_H_
+#define LOG_H_
+
+#define MsgLogError(ARG) LogError("\u001B[0;31m" << ARG << "\u001B[0;39m")
+#define MsgLogWanning(ARG) LogError("\u001B[1;33m" << ARG << "\u001B[0;39m")
+
+#endif /* LOG_H_ */
diff --git a/src/platform/API/NFC/EventNFC.h b/src/platform/API/NFC/EventNFC.h
new file mode 100755 (executable)
index 0000000..715b965
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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_API_NFC_EVENT_NFC_H_
+#define WRTPLUGINS_API_NFC_EVENT_NFC_H_
+
+#include <Commons/IEvent.h>
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+template <class templateClass>
+class EventNFCTemplate : public WrtDeviceApis::Commons::IEvent<templateClass>
+{
+protected:
+       bool result;
+       std::string errorName;
+       std::string errorMessage;
+public:
+       void setResult(const bool value) {result = value;}
+       bool getResult() const {return result;}
+       void setError(const std::string &error) { errorName= error;}
+       void setErrorMessage(const std::string &message) { errorMessage= message;}
+       std::string getError() {return errorName;}
+       std::string getErrorMessage() {return errorMessage;}
+       EventNFCTemplate() :result(true), errorName(""), errorMessage("") { }
+};
+
+template <class templateEventClass>
+class EventNFCPtrs
+{
+private:
+       DPL::SharedPtr<templateEventClass> eventPtr;
+       void * thisPtr;
+public:
+       DPL::SharedPtr<templateEventClass> getEventPtrs() const {return eventPtr;}
+       void *getThisPtr() {return thisPtr;}
+       EventNFCPtrs(const DPL::SharedPtr<templateEventClass> &event, void *myPtr) : eventPtr(event), thisPtr(myPtr) {}
+};
+
+} // NFC
+} // Api
+} // TizenApis
+
+#endif //WRTPLUGINS_API_NFC_EVENT_NFC_H_
\ No newline at end of file
diff --git a/src/platform/API/NFC/EventNFCChanged.h b/src/platform/API/NFC/EventNFCChanged.h
new file mode 100755 (executable)
index 0000000..b0fd850
--- /dev/null
@@ -0,0 +1,101 @@
+//
+// 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_API_NFC_EVENT_NFC_CHANGED_H_
+#define WRTPLUGINS_API_NFC_EVENT_NFC_CHANGED_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "EventNFC.h"
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+enum EventNFCType {
+       NFC_TAG_TYPE,
+       NFC_TARGET_TYPE
+};
+enum EventNFCStatus {
+       NFC_ATTATCHED,
+       NFC_DETATCHED
+};
+
+enum EventNFCSEType {
+       NFC_SE_NONE,
+       NFC_SE_ESE,
+       NFC_SE_UICC,
+       NFC_SE_INVALID
+};
+
+class EventNFCChanged : public WrtDeviceApis::Commons::ListenerEvent<EventNFCChanged>
+{
+private:
+       void  *m_props;
+       EventNFCType m_type;
+       EventNFCStatus m_status;
+public:
+       void *getNFCProperties() { return m_props; }
+       void setNFCProperties(void *props) { m_props = props; }
+        EventNFCType getNFCType() const {return m_type;}
+        void setNFCType(const EventNFCType type) {m_type = type;}
+        EventNFCStatus getNFCStatus() const {return m_status;}
+        void setNFCStatus(const EventNFCStatus type) {m_status = type;}         
+       EventNFCChanged() {}
+};
+class EventNFCChangedSetPowered : public EventNFCTemplate<EventNFCChangedSetPowered>
+{
+private:
+       bool powerState;
+public:
+       bool getState()  {return powerState;}
+       EventNFCChangedSetPowered(bool state): powerState(state) { }
+};
+
+class EventNFCSetCardEmulation : public EventNFCTemplate<EventNFCSetCardEmulation>
+{
+private:
+       EventNFCSEType seType;
+public:
+       EventNFCSEType getSEType()  {return seType;}
+       EventNFCSetCardEmulation(EventNFCSEType type): seType(type) { }
+};
+
+class EventNFCChangedCardEmulation : public WrtDeviceApis::Commons::ListenerEvent<EventNFCChangedCardEmulation>
+{
+private:
+       EventNFCSEType seType;
+public:
+       EventNFCSEType getSEType()  {return seType;}
+       void setSEType(EventNFCSEType type) {seType = type;}
+       EventNFCChangedCardEmulation():seType(NFC_SE_NONE) { }
+};
+
+typedef DPL::SharedPtr<EventNFCChanged> EventNFCChangedPtr;
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventNFCChanged> EventNFCChangedEmitter;
+typedef DPL::SharedPtr<EventNFCChangedEmitter> EventNFCChangedEmitterPtr;
+typedef DPL::SharedPtr<EventNFCChangedSetPowered> EventNFCChangedSetPoweredPtr;
+typedef DPL::SharedPtr<EventNFCSetCardEmulation> EventNFCSetCardEmulationPtr;
+typedef DPL::SharedPtr<EventNFCChangedCardEmulation> EventNFCChangedCardEmulationPtr;
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventNFCChangedCardEmulation> EventNFCChangedCardEmulationEmitter;
+typedef DPL::SharedPtr<EventNFCChangedCardEmulationEmitter> EventNFCChangedCardEmulationEmitterPtr;
+} // NFC
+} // Api
+} // TizenApis
+
+#endif //WRTPLUGINS_API_NFC_EVENT_NFC_CHANGED_H_
\ No newline at end of file
diff --git a/src/platform/API/NFC/EventTagAction.h b/src/platform/API/NFC/EventTagAction.h
new file mode 100755 (executable)
index 0000000..5710f7c
--- /dev/null
@@ -0,0 +1,93 @@
+//
+// 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_API_NFC_EVENT_TAG_ACTION_H_
+#define WRTPLUGINS_API_NFC_EVENT_TAG_ACTION_H_
+
+#include <vector>
+#include "EventNFC.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+template <class templateClass>
+class EventTagAction : public EventNFCTemplate<templateClass>
+{
+protected:
+       void *messageHandle;
+       void setNdefMessageHandle(void *handle) { messageHandle = handle; }
+       void *getNdefMessageHandle()  { return messageHandle; }
+public:
+       EventTagAction() { }
+};
+
+class EventTagActionRead : public EventNFCTemplate<EventTagActionRead>
+{
+public:
+       void setReadNdefResult(std::vector<unsigned char> &result) {rawData = result;}
+       std::vector<unsigned char> getReadNdefResult()  {return rawData;}
+       EventTagActionRead(){ }
+private:
+       std::vector<unsigned char> rawData;
+       
+};
+
+class EventTagActionWrite : public EventTagAction<EventTagActionWrite>
+{
+public:
+       void writeNdef(void *handle) {setNdefMessageHandle(handle);}
+       void *getNdefForWriting()  {return getNdefMessageHandle();}
+       void setNdefForWriting(void *handle) {setNdefMessageHandle(handle);}
+       EventTagActionWrite(){ }
+};
+
+class EventTagActionTransceive : public EventNFCTemplate<EventTagActionTransceive>
+{
+private:
+       std::vector<unsigned char> transceiveBuffer;
+public:
+       void setTransceiveBuffer(const std::vector<unsigned char> &data) {transceiveBuffer = data;}
+       std::vector<unsigned char> getTransceiveBuffer() const {return transceiveBuffer;}
+       int getTransceiveBufferSize() const {return transceiveBuffer.size();}
+       void transceive(const std::vector<unsigned char> &data) {setTransceiveBuffer(data);}
+       EventTagActionTransceive()  { }
+};
+
+class EventTagActionFormat : public EventNFCTemplate<EventTagActionFormat>
+{
+private:
+       std::vector<unsigned char> m_key;
+
+public:
+       void format(const std::vector<unsigned char> &key) {m_key = key;}
+       std::vector<unsigned char> getKey() {return m_key;}
+       int getKeySize() const {return m_key.size();}
+       EventTagActionFormat()  { }
+};
+
+typedef DPL::SharedPtr<EventTagActionRead> EventTagActionReadPtr;
+typedef DPL::SharedPtr<EventTagActionWrite> EventTagActionWritePtr;
+typedef DPL::SharedPtr<EventTagActionTransceive> EventTagActionTransceivePtr;
+typedef DPL::SharedPtr<EventTagActionFormat> EventTagActionFormatPtr;
+} // NFC
+} // Api
+} // TizenApis
+
+#endif //WRTPLUGINS_API_NFC_EVENT_TAG_ACTION_H_
diff --git a/src/platform/API/NFC/EventTargetAction.h b/src/platform/API/NFC/EventTargetAction.h
new file mode 100755 (executable)
index 0000000..eac5342
--- /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 WRTPLUGINS_API_NFC_EVENT_TARGET_ACTION_H_
+#define WRTPLUGINS_API_NFC_EVENT_TARGET_ACTION_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/ListenerEventEmitter.h>
+#include "EventNFC.h"
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+class EventTargetActionReceive  : public WrtDeviceApis::Commons::ListenerEvent<EventTargetActionReceive>
+{
+
+public:
+       void setReadNdefResult(std::vector<unsigned char> &ndefResult) {rawData = ndefResult;}
+       std::vector<unsigned char> getReadNdefResult()  {return rawData;}
+       EventTargetActionReceive(){ }
+private:
+       std::vector<unsigned char> rawData;
+       
+};
+
+class EventTargetActionSend : public EventNFCTemplate<EventTargetActionSend>
+{
+public:
+       void *getMessageForSending()  {return message;}
+       void setMessageForSending(void* handle)  {message = handle;}
+       EventTargetActionSend(void *handle) :message(handle){ }
+private:
+       void *message;
+};
+
+typedef DPL::SharedPtr<EventTargetActionReceive> EventTargetActionReceivePtr;
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<EventTargetActionReceive> EventTargetActionReceiveEmitter;
+typedef DPL::SharedPtr<EventTargetActionReceiveEmitter> EventTargetActionReceiveEmitterPtr;
+
+typedef DPL::SharedPtr<EventTargetActionSend> EventTargetActionSendPtr;
+
+} // NFC
+} // Api
+} // TizenApis
+
+#endif //WRTPLUGINS_API_NFC_EVENT_TARGET_ACTION_H_
diff --git a/src/platform/API/NFC/INFCAdapter.cpp b/src/platform/API/NFC/INFCAdapter.cpp
new file mode 100755 (executable)
index 0000000..00e4997
--- /dev/null
@@ -0,0 +1,37 @@
+//
+// 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.
+//\r
+\r
+\r
+#include "INFCAdapter.h"\r
+\r
+namespace TizenApis {\r
+namespace Api {\r
+namespace NFC {\r
+\r
+using namespace WrtDeviceApis::Commons;\r
+\r
+INFCAdapter::INFCAdapter() :\r
+       EventNFCSetPoweredRequestReceiver(ThreadEnum::NFC_THREAD),\r
+       EventNFCSetCardEmulationRequestReceiver(ThreadEnum::NFC_THREAD) {\r
+}\r
+\r
+INFCAdapter::~INFCAdapter() {\r
+}\r
+\r
+}\r
+}\r
+}\r
diff --git a/src/platform/API/NFC/INFCAdapter.h b/src/platform/API/NFC/INFCAdapter.h
new file mode 100755 (executable)
index 0000000..a1a10f5
--- /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 _ABSTRACT_LAYER_INFCADAPTER_H_
+#define _ABSTRACT_LAYER_INFCADAPTER_H_
+
+#include <dpl/shared_ptr.h>
+#include <vector>
+#include <Commons/ThreadPool.h>
+#include "EventNFCChanged.h"
+#include "TagFilter.h"
+
+typedef WrtDeviceApis::Commons::EventRequestReceiver<TizenApis::Api::NFC::EventNFCChangedSetPowered> EventNFCSetPoweredRequestReceiver;
+typedef WrtDeviceApis::Commons::EventRequestReceiver<TizenApis::Api::NFC::EventNFCSetCardEmulation> EventNFCSetCardEmulationRequestReceiver;
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+class INFCAdapter :
+               public EventNFCSetPoweredRequestReceiver,
+               public EventNFCSetCardEmulationRequestReceiver
+{
+    public:
+
+    virtual                     ~INFCAdapter();
+       virtual int setTagListener(const EventNFCChangedEmitterPtr& emitter, const TagFilterPtr& filter) = 0;
+       virtual void unsetTagListener() = 0;
+       virtual int setPeerListener(const EventNFCChangedEmitterPtr& emitter) = 0;
+       virtual void unsetPeerListener() = 0;
+       virtual void *getCachedMessage() = 0;
+       virtual bool getPowerState() = 0;
+       virtual void setPowered(const EventNFCChangedSetPoweredPtr& event) = 0;
+       virtual EventNFCSEType getSEType() = 0;
+       virtual void setCardEmulation(const EventNFCSetCardEmulationPtr& event) = 0;
+       virtual void setCardEmulationChangeListener(const EventNFCChangedCardEmulationEmitterPtr& event) = 0;
+       virtual void unsetCardEmulationChangeListener() = 0;
+protected:
+        INFCAdapter();
+       virtual void OnRequestReceived(const EventNFCChangedSetPoweredPtr& event) = 0;
+       virtual void OnRequestReceived(const EventNFCSetCardEmulationPtr& event) = 0;
+};
+
+typedef DPL::SharedPtr<INFCAdapter> INFCAdapterPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_INFCADAPTER_H_ */
diff --git a/src/platform/API/NFC/INFCTag.cpp b/src/platform/API/NFC/INFCTag.cpp
new file mode 100755 (executable)
index 0000000..9e9e721
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// 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.
+//\r
+\r
+\r
+#include "INFCTag.h"\r
+\r
+namespace TizenApis {\r
+namespace Api {\r
+namespace NFC {\r
+\r
+using namespace WrtDeviceApis::Commons;\r
+\r
+INFCTag::INFCTag() :\r
+               EventRequestReceiver<EventTagActionRead>(ThreadEnum::NFC_THREAD),\r
+               EventRequestReceiver<EventTagActionWrite>(ThreadEnum::NFC_THREAD),\r
+               EventRequestReceiver<EventTagActionTransceive>(ThreadEnum::NFC_THREAD),\r
+               EventRequestReceiver<EventTagActionFormat>(ThreadEnum::NFC_THREAD){\r
+}\r
+\r
+INFCTag::~INFCTag() {\r
+}\r
+\r
+}\r
+}\r
+}\r
diff --git a/src/platform/API/NFC/INFCTag.h b/src/platform/API/NFC/INFCTag.h
new file mode 100755 (executable)
index 0000000..acf3730
--- /dev/null
@@ -0,0 +1,88 @@
+//
+// 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 _ABSTRACT_LAYER_NFCTAG_H_
+#define _ABSTRACT_LAYER_NFCTAG_H_
+
+#include <dpl/shared_ptr.h>
+#include <vector>
+#include <Commons/ThreadPool.h>
+#include "EventTagAction.h"
+#include "NFCTagProperties.h"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+       enum nfcTagType {
+               NFC_TAGTYPE_GENERIC_PICC = 0x00,
+               NFC_TAGTYPE_ISO14443_A_PICC = 0x01,
+               NFC_TAGTYPE_ISO14443_4A_PICC = 0x02,
+               NFC_TAGTYPE_ISO14443_3A_PICC = 0x03,
+               NFC_TAGTYPE_MIFARE_MINI_PICC = 0x04,
+               NFC_TAGTYPE_MIFARE_1K_PICC = 0x05,
+               NFC_TAGTYPE_MIFARE_4K_PICC = 0x06,
+               NFC_TAGTYPE_MIFARE_ULTRA_PICC = 0x07,
+               NFC_TAGTYPE_MIFARE_DESFIRE_PICC = 0x08,
+               NFC_TAGTYPE_ISO14443_B_PICC = 0x09,
+               NFC_TAGTYPE_ISO14443_4B_PICC = 0x0a,
+               NFC_TAGTYPE_ISO14443_BPRIME_PICC = 0x0b,
+               NFC_TAGTYPE_FELICA_PICC = 0x0c,
+               NFC_TAGTYPE_JEWEL_PICC = 0x0d,
+               NFC_TAGTYPE_ISO15693_PICC = 0x0e,
+               NFC_TAGTYPE_UNKNOWN_TARGET = 0xff
+       };
+       
+class INFCTag :
+               public EventRequestReceiver<EventTagActionRead>,
+               public EventRequestReceiver<EventTagActionWrite>,
+               public EventRequestReceiver<EventTagActionTransceive>,
+               public EventRequestReceiver<EventTagActionFormat>
+{
+    public:
+
+       
+       virtual                     ~INFCTag();
+       virtual bool isConnected() = 0;
+       virtual nfcTagType getTagType() = 0;
+       virtual bool isNDEFSupport() = 0;
+       virtual long getNdefSize() = 0;
+       virtual std::vector<NFCTagProperties> getProperties() = 0;
+       virtual void readNdef(const EventTagActionReadPtr& event) = 0;
+       virtual void writeNdef(const EventTagActionWritePtr& event) = 0;
+       virtual void transceive(const EventTagActionTransceivePtr& event) = 0;
+       virtual void format(const EventTagActionFormatPtr& event) = 0;
+    protected:
+               INFCTag();
+               virtual void OnRequestReceived(const EventTagActionReadPtr& event) = 0;
+               virtual void OnRequestReceived(const EventTagActionWritePtr& event) = 0;
+               virtual void OnRequestReceived(const EventTagActionTransceivePtr& event) = 0;
+               virtual void OnRequestReceived(const EventTagActionFormatPtr& event) = 0;
+
+};
+
+typedef DPL::SharedPtr<INFCTag> INFCTagPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_NFCTAG_H_ */
diff --git a/src/platform/API/NFC/INFCTarget.cpp b/src/platform/API/NFC/INFCTarget.cpp
new file mode 100755 (executable)
index 0000000..9ec935f
--- /dev/null
@@ -0,0 +1,35 @@
+//
+// 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.
+//\r
+\r
+\r
+#include "INFCTarget.h"\r
+\r
+namespace TizenApis {\r
+namespace Api {\r
+namespace NFC {\r
+\r
+using namespace WrtDeviceApis::Commons;\r
+\r
+INFCTarget::INFCTarget() : EventRequestReceiver<EventTargetActionSend>(ThreadEnum::NFC_THREAD) {\r
+}\r
+\r
+INFCTarget::~INFCTarget() {\r
+}\r
+\r
+}\r
+}\r
+}\r
diff --git a/src/platform/API/NFC/INFCTarget.h b/src/platform/API/NFC/INFCTarget.h
new file mode 100755 (executable)
index 0000000..e41313a
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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 _ABSTRACT_LAYER_NFCTARGET_H_
+#define _ABSTRACT_LAYER_NFCTARGET_H_
+
+#include <dpl/shared_ptr.h>
+#include <vector>
+#include "EventTargetAction.h"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+
+class INFCTarget : public EventRequestReceiver<EventTargetActionSend>
+{
+    public:
+
+
+       virtual                     ~INFCTarget();
+       virtual bool isConnected() = 0;
+       virtual void setReceiveNDEFListener(const EventTargetActionReceiveEmitterPtr& event) = 0;
+       virtual void unsetReceiveNDEFListener() = 0;
+       virtual void sendNDEF(const EventTargetActionSendPtr& event) = 0;
+    protected:
+               INFCTarget();
+               virtual void OnRequestReceived(const EventTargetActionSendPtr& event) = 0;
+};
+
+typedef DPL::SharedPtr<INFCTarget> INFCTargetPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_NFCTARGET_H_ */
diff --git a/src/platform/API/NFC/INdefMessage.h b/src/platform/API/NFC/INdefMessage.h
new file mode 100755 (executable)
index 0000000..3df51d2
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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 _ABSTRACT_LAYER_INDEFMESSAGE_H_
+#define _ABSTRACT_LAYER_INDEFMESSAGE_H_
+
+#include <dpl/shared_ptr.h>
+#include <vector>
+#include "NdefRecordProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+class INdefMessage
+{
+    public:
+
+                                      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;
+};
+
+typedef DPL::SharedPtr<INdefMessage> INdefMessagePtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_INDEFMESSAGE_H_ */
diff --git a/src/platform/API/NFC/INdefRecord.h b/src/platform/API/NFC/INdefRecord.h
new file mode 100755 (executable)
index 0000000..04eb729
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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 _ABSTRACT_LAYER_INDEFRECORD_H_
+#define _ABSTRACT_LAYER_INDEFRECORD_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include "NdefRecordProperties.h"
+
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+class INdefRecord
+{
+    public:
+                                      INdefRecord() {}
+       virtual                     ~INdefRecord() {}
+       virtual void *getHandle() = 0;
+       virtual NdefRecordProperties getNDEFRecordProperties() = 0;
+       virtual nfcTNF getTNF() = 0;
+       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;
+       virtual bool getUri(char **uri) = 0;
+       virtual bool getMimeType(char **mimeType) = 0;
+    protected:
+
+};
+
+typedef DPL::SharedPtr<INdefRecord> INdefRecordPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_INDEFRECORD_H_ */
diff --git a/src/platform/API/NFC/NFCFactory.cpp b/src/platform/API/NFC/NFCFactory.cpp
new file mode 100755 (executable)
index 0000000..96756ef
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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 "NFCFactory.h"
+
+#include <NFC/NFCAdapter.h>
+#include <NFC/NdefMessage.h>
+#include <NFC/NdefRecord.h>
+#include <NFC/NFCTag.h>
+#include <NFC/NFCTarget.h>
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+INFCAdapterPtr NFCFactory::createNFCAdapterObject() {
+       return INFCAdapterPtr( new Platform::NFC::NFCAdapter() );
+}
+
+INdefMessagePtr NFCFactory::createNDEFMessageObject() {
+       return INdefMessagePtr( new Platform::NFC::NdefMessage() );
+}
+
+INdefMessagePtr NFCFactory::createNDEFMessageObject(void *messageHandle) {
+       return INdefMessagePtr( new Platform::NFC::NdefMessage(messageHandle) );
+}
+
+INdefMessagePtr NFCFactory::createNDEFMessageObject(std::vector<void *> ndefRcords) {
+       return INdefMessagePtr( new Platform::NFC::NdefMessage(ndefRcords) );
+}
+
+INdefMessagePtr NFCFactory::createNDEFMessageObject(std::vector<unsigned char> rawdata) {
+       return INdefMessagePtr( new Platform::NFC::NdefMessage(rawdata) );
+}
+
+INdefRecordPtr NFCFactory::createNDEFRecordObject() {
+       return INdefRecordPtr( new Platform::NFC::NdefRecord() );
+}
+
+INdefRecordPtr NFCFactory::createNDEFRecordObject(std::vector<unsigned char> data) {
+       return INdefRecordPtr( new Platform::NFC::NdefRecord(data) );
+}
+
+INdefRecordPtr NFCFactory::createNDEFRecordObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload) {
+       return INdefRecordPtr( new Platform::NFC::NdefRecord(ndefRecordProperties, payload) );
+}
+
+INdefRecordPtr NFCFactory::createNDEFRecordObject(const std::string &text, const std::string &langCode, const short encodeType) {
+       return INdefRecordPtr( new Platform::NFC::NdefRecord(text, langCode, encodeType) );
+}
+
+INdefRecordPtr NFCFactory::createNDEFRecordObject(const std::string &uri) {
+       return INdefRecordPtr( new Platform::NFC::NdefRecord(uri) );
+}
+
+INdefRecordPtr NFCFactory::createNDEFRecordObject(const std::string &mimeType, const std::vector<unsigned char> data) {
+       return INdefRecordPtr( new Platform::NFC::NdefRecord(mimeType, data) );
+}
+
+INFCTagPtr NFCFactory::createNFCTagObject(void *tagHandle) {
+       return INFCTagPtr( new Platform::NFC::NFCTag(tagHandle));
+}
+
+INFCTargetPtr NFCFactory::createNFCTargetObject(void *targetHandle) {
+       return INFCTargetPtr( new Platform::NFC::NFCTarget(targetHandle));
+}
+
+NFCFactory& NFCFactory::getInstance() {
+       static NFCFactory theInstance;
+       return theInstance;
+}
+
+}
+}
+}
diff --git a/src/platform/API/NFC/NFCFactory.h b/src/platform/API/NFC/NFCFactory.h
new file mode 100755 (executable)
index 0000000..5a5c58a
--- /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 WRTPLUGINS_API_NFCFACTORY_H_
+#define WRTPLUGINS_API_NFCFACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include "INFCAdapter.h"
+#include "INdefMessage.h"
+#include "INdefRecord.h"
+#include "INFCTag.h"
+#include "INFCTarget.h"
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+class NFCFactory : DPL::Noncopyable
+{
+private:
+    /**
+     * Private constructor to provide singleton
+     */
+    NFCFactory(){;}
+public:
+       INFCAdapterPtr createNFCAdapterObject();
+       INdefMessagePtr createNDEFMessageObject();
+       INdefMessagePtr createNDEFMessageObject(void *messageHandle);
+       INdefMessagePtr createNDEFMessageObject(std::vector<void *> ndefRcords);
+       INdefMessagePtr createNDEFMessageObject(std::vector<unsigned char> rawdata);
+       INdefRecordPtr createNDEFRecordObject();
+       INdefRecordPtr createNDEFRecordObject(std::vector<unsigned char> data);
+       INdefRecordPtr createNDEFRecordObject(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+       INdefRecordPtr createNDEFRecordObject(const std::string &text, const std::string &langCode, const short encodeType);
+       INdefRecordPtr createNDEFRecordObject(const std::string &uri);
+       INdefRecordPtr createNDEFRecordObject(const std::string &mimeType, const std::vector<unsigned char> data);
+       INFCTagPtr createNFCTagObject(void *tagHandle);
+       INFCTargetPtr createNFCTargetObject(void *targetHandle);
+
+       static NFCFactory& getInstance();
+
+};
+
+}
+}
+}
+
+#endif //WRTPLUGINS_API_NFCFACTORY_H_
+
diff --git a/src/platform/API/NFC/NFCTagProperties.h b/src/platform/API/NFC/NFCTagProperties.h
new file mode 100755 (executable)
index 0000000..63a8ddb
--- /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 WRTPLUGINS_API_NFC_NFCTAG_PROPERTIES_H_
+#define WRTPLUGINS_API_NFC_NFCTAG_PROPERTIES_H_
+
+#include <dpl/shared_ptr.h>
+#include <vector>
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+       
+struct NFCTagProperties
+{
+       std::string key ;
+       std::vector<unsigned char> value ;
+       NFCTagProperties()
+               : key("")
+       {
+       }
+};
+
+
+typedef DPL::SharedPtr<NFCTagProperties> NFCTagPropertiesPtr;
+
+} // NFC 
+} // Api
+} // TizenApis
+
+#endif //WRTPLUGINS_API_NFC_NFCTAG_PROPERTIES_H_
\ No newline at end of file
diff --git a/src/platform/API/NFC/NdefRecordProperties.h b/src/platform/API/NFC/NdefRecordProperties.h
new file mode 100755 (executable)
index 0000000..0c11ba6
--- /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 WRTPLUGINS_API_NFC_NDEFRECORD_PROPERTIES_H_
+#define WRTPLUGINS_API_NFC_NDEFRECORD_PROPERTIES_H_
+
+#include <dpl/shared_ptr.h>
+#include <vector>
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+       
+enum nfcTNF {
+       NFC_TNF_EMPTY = 0,
+       NFC_TNF_WELL_KNOWN = 1,
+       NFC_TNF_MIME_MEDIA = 2,
+       NFC_TNF_URI = 3,
+       NFC_TNF_EXTERNAL_RTD = 4,
+       NFC_TNF_UNKNOWN = 5,
+       NFC_TNF_UNCHANGED = 6
+};
+
+enum nfcTextEncodeUTF {
+       NFC_TEXT_ENCODE_UTF_8 = 0,
+       NFC_TEXT_ENCODE_UTF_16 = 1
+};
+struct NdefRecordProperties
+{
+       nfcTNF  tnf;
+       std::vector<unsigned char> typeName ;
+       std::vector<unsigned char> id ;
+       NdefRecordProperties()
+               : tnf(NFC_TNF_EMPTY)
+       {
+       }
+};
+
+struct NdefRecordData
+{
+       NdefRecordProperties properties;
+       std::vector<unsigned char> payload;
+       NdefRecordData() {}
+};
+
+typedef DPL::SharedPtr<NdefRecordProperties> NdefRecordPropertiesPtr;
+
+} // NFC
+} // Api
+} // TizenApis
+
+#endif //WRTPLUGINS_API_NFC_NDEFRECORD_PROPERTIES_H_
\ No newline at end of file
diff --git a/src/platform/API/NFC/TagFilter.cpp b/src/platform/API/NFC/TagFilter.cpp
new file mode 100755 (executable)
index 0000000..49e7c42
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 "TagFilter.h"
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+TagFilter::TagFilter()
+{
+}
+
+TagFilter::~TagFilter()
+{
+}
+
+void TagFilter::addTagTypeValue(nfcTagType type){
+       m_tagList.push_back(type);
+}
+
+nfcTagType TagFilter::getFilterValue(int index){
+       if (index >=0 && index < (int)m_tagList.size())
+               return m_tagList.at(index);
+       else
+               return NFC_TAGTYPE_UNKNOWN_TARGET;
+}
+
+int TagFilter::getFilterSize(){
+               return m_tagList.size();
+}
+
+}
+}
+}
diff --git a/src/platform/API/NFC/TagFilter.h b/src/platform/API/NFC/TagFilter.h
new file mode 100755 (executable)
index 0000000..8233a9d
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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 _TIZEN10_NFC_TAG_FILTER_H_
+#define _TIZEN10_NFC_TAG_FILTER_H_
+
+#include <map>
+#include <string>
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <JavaScriptCore/JavaScript.h>
+
+#include "INFCTag.h"
+
+namespace TizenApis {
+namespace Api {
+namespace NFC {
+
+class TagFilter
+{
+  public:
+
+    typedef std::vector<nfcTagType> TagList;
+
+    explicit TagFilter();
+    virtual ~TagFilter();
+
+    void addTagTypeValue(nfcTagType type);
+    int getFilterSize();
+    nfcTagType getFilterValue(int index);
+  private:
+    TagList m_tagList;
+};
+
+typedef DPL::SharedPtr<TagFilter> TagFilterPtr;
+
+}
+}
+}
+#endif  //_TIZEN10_NFC_TAG_FILTER_H_
\ No newline at end of file
diff --git a/src/platform/API/NFC/config.cmake b/src/platform/API/NFC/config.cmake
new file mode 100755 (executable)
index 0000000..32d5bfe
--- /dev/null
@@ -0,0 +1,10 @@
+get_current_path()
+
+set(SRCS_PLATFORM_API_NFC
+  ${CURRENT_PATH}/NFCFactory.cpp
+  ${CURRENT_PATH}/INFCAdapter.cpp
+  ${CURRENT_PATH}/INFCTag.cpp
+  ${CURRENT_PATH}/TagFilter.cpp  
+  ${CURRENT_PATH}/INFCTarget.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/NetworkBearerSelection/EventNetworkBearerRelease.h b/src/platform/API/NetworkBearerSelection/EventNetworkBearerRelease.h
new file mode 100755 (executable)
index 0000000..50d9c6a
--- /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 WRTPLUGINS_API_NETWORK_BEAR_RELEASE_EVENT_H_
+#define WRTPLUGINS_API_NETWORK_BEAR_RELEASE_EVENT_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace NetworkBearerSelection {
+
+class EventNetworkBearerRelease : public WrtDeviceApis::Commons::IEvent<EventNetworkBearerRelease>
+{
+  public:
+    void setNetworkType(const std::string &value)
+    {
+        m_networkType = value;    
+    }
+
+    std::string getNetworkType() const
+    {
+        return m_networkType;
+    }
+
+    void setDomainName(const std::string &value)
+    {
+        m_domainName = value;    
+    }
+
+    std::string getDomainName() const
+    {
+        return m_domainName;
+    }
+    
+    EventNetworkBearerRelease()
+    {
+    }
+
+    ~EventNetworkBearerRelease()
+    {
+    }
+  private:
+    std::string m_networkType;
+    std::string m_domainName;    
+};
+
+typedef DPL::SharedPtr<EventNetworkBearerRelease> EventNetworkBearerReleasePtr;
+
+}
+}
+}
+#endif
diff --git a/src/platform/API/NetworkBearerSelection/EventNetworkBearerSelection.h b/src/platform/API/NetworkBearerSelection/EventNetworkBearerSelection.h
new file mode 100755 (executable)
index 0000000..3038ce1
--- /dev/null
@@ -0,0 +1,80 @@
+//
+// 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_API_NETWORK_BEAR_SELECTION_EVENT_H_
+#define WRTPLUGINS_API_NETWORK_BEAR_SELECTION_EVENT_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "OnNetworkBearerSelectionStateChanged.h"
+
+namespace TizenApis {
+namespace Api {
+namespace NetworkBearerSelection {
+
+class EventNetworkBearerSelection : public WrtDeviceApis::Commons::IEvent<EventNetworkBearerSelection>
+{
+  public:
+    void setNetworkType(const std::string &value)
+    {
+        m_networkType = value;    
+    }
+
+    std::string getNetworkType() const
+    {
+        return m_networkType;
+    }
+
+    void setDomainName(const std::string &value)
+    {
+        m_domainName = value;    
+    }
+
+    std::string getDomainName() const
+    {
+        return m_domainName;
+    }
+    
+    void setEmitter(OnNetworkBearerSelectionStateChangedEmitterPtr value)
+    {
+        m_emitter = value;
+    }
+
+    OnNetworkBearerSelectionStateChangedEmitterPtr getEmitter() const
+    {
+        return m_emitter;
+    }
+
+    EventNetworkBearerSelection() : m_emitter(NULL)
+    {
+    }
+
+    ~EventNetworkBearerSelection()
+    {
+    }
+  private:
+    std::string m_networkType;
+    std::string m_domainName;    
+    OnNetworkBearerSelectionStateChangedEmitterPtr m_emitter;
+};
+
+typedef DPL::SharedPtr<EventNetworkBearerSelection> EventNetworkBearerSelectionPtr;
+
+}
+}
+}
+#endif
diff --git a/src/platform/API/NetworkBearerSelection/INetworkBearerSelection.cpp b/src/platform/API/NetworkBearerSelection/INetworkBearerSelection.cpp
new file mode 100755 (executable)
index 0000000..deaaf6a
--- /dev/null
@@ -0,0 +1,38 @@
+//
+// 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 "INetworkBearerSelection.h"
+#include "EventNetworkBearerSelection.h"
+#include "EventNetworkBearerRelease.h"
+
+namespace TizenApis {
+namespace Api {
+namespace NetworkBearerSelection {
+using namespace WrtDeviceApis::Commons;
+
+INetworkBearerSelection::INetworkBearerSelection() : EventRequestReceiver< EventNetworkBearerSelection >(ThreadEnum::NULL_THREAD),
+    EventRequestReceiver< EventNetworkBearerRelease >(ThreadEnum::NULL_THREAD)
+{
+}
+
+INetworkBearerSelection::~INetworkBearerSelection()
+{
+}
+
+}
+}
+}
diff --git a/src/platform/API/NetworkBearerSelection/INetworkBearerSelection.h b/src/platform/API/NetworkBearerSelection/INetworkBearerSelection.h
new file mode 100755 (executable)
index 0000000..0953705
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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_API_INETWORKBEARERSELECTION_H_
+#define WRTPLUGINS_API_INETWORKBEARERSELECTION_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include "EventNetworkBearerSelection.h"
+#include "EventNetworkBearerRelease.h"
+
+namespace TizenApis {
+namespace Api {
+namespace NetworkBearerSelection {
+
+class EventNetworkBearerSelection;
+class EventNetworkBearerRelease;
+
+typedef DPL::SharedPtr<EventNetworkBearerSelection> EventNetworkBearerSelectionPtr;
+typedef DPL::SharedPtr<EventNetworkBearerRelease> EventNetworkBearerReleasePtr;
+
+
+class INetworkBearerSelection :
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventNetworkBearerSelection>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventNetworkBearerRelease>
+{
+  public:
+    virtual ~INetworkBearerSelection();
+    INetworkBearerSelection();
+
+    virtual void requestRouteToHost(const EventNetworkBearerSelectionPtr &event) = 0;
+    virtual void releaseRouteToHost(const EventNetworkBearerReleasePtr &event) = 0;
+
+  protected:
+       virtual void OnRequestReceived(const EventNetworkBearerSelectionPtr &event) = 0;
+       virtual void OnRequestReceived(const EventNetworkBearerReleasePtr &event) = 0;    
+};
+
+typedef DPL::SharedPtr<INetworkBearerSelection> INetworkBearerSelectionPtr;
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/API/NetworkBearerSelection/NetworkBearerSelectionFactory.cpp b/src/platform/API/NetworkBearerSelection/NetworkBearerSelectionFactory.cpp
new file mode 100755 (executable)
index 0000000..d9c548c
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// 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 <NetworkBearerSelection/NetworkBearerSelection.h>
+#include "NetworkBearerSelectionFactory.h"
+
+namespace TizenApis {
+namespace Api {
+namespace NetworkBearerSelection {
+
+INetworkBearerSelectionPtr NetworkBearerSelectionFactory::getNetworkBearerSelections()
+{
+    INetworkBearerSelectionPtr result(new TizenApis::Platform::NetworkBearerSelection::NetworkBearerSelection());
+    return result;
+}
+
+NetworkBearerSelectionFactory& NetworkBearerSelectionFactory::getInstance()
+{
+    static NetworkBearerSelectionFactory theInstance;
+    return theInstance;
+}
+
+NetworkBearerSelectionFactory::NetworkBearerSelectionFactory()
+{
+}
+
+}
+}
+}
diff --git a/src/platform/API/NetworkBearerSelection/NetworkBearerSelectionFactory.h b/src/platform/API/NetworkBearerSelection/NetworkBearerSelectionFactory.h
new file mode 100755 (executable)
index 0000000..e8a5f81
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// 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_API_NETWORKBEARERSELECTION_FACTORY_H_
+#define WRTPLUGINS_API_NETWORKBEARERSELECTION_FACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include "INetworkBearerSelection.h"
+
+namespace TizenApis {
+namespace Api {
+namespace NetworkBearerSelection {
+
+class NetworkBearerSelectionFactory : DPL::Noncopyable
+{
+  public:
+    INetworkBearerSelectionPtr getNetworkBearerSelections();
+
+    static NetworkBearerSelectionFactory& getInstance();
+
+  protected:
+    NetworkBearerSelectionFactory();
+};
+
+}
+}
+}
+
+#endif
+
diff --git a/src/platform/API/NetworkBearerSelection/OnNetworkBearerSelectionStateChanged.h b/src/platform/API/NetworkBearerSelection/OnNetworkBearerSelectionStateChanged.h
new file mode 100755 (executable)
index 0000000..8a6c964
--- /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 _ON_NETWORK_BEARER_SELECTION_STATE_CHANGED_H_
+#define _ON_NETWORK_BEARER_SELECTION_STATE_CHANGED_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/Emitters.h>
+
+namespace TizenApis {
+namespace Api {
+namespace NetworkBearerSelection {
+
+enum connectionStateType {
+    CONNECTION_STATE_DISCONNECTED = 0,
+    CONNECTION_STATE_CONNECTED = 1,
+    CONNECTION_STATE_ERROR = 2
+};
+
+class OnNetworkBearerSelectionStateChanged : public WrtDeviceApis::Commons::ListenerEvent<OnNetworkBearerSelectionStateChanged>
+{
+  public:
+
+    OnNetworkBearerSelectionStateChanged(){
+    }
+    ~OnNetworkBearerSelectionStateChanged() {
+    }
+
+    void setConnectionStateType(connectionStateType state) {
+        m_callbackType = state;
+    }
+
+    connectionStateType getConnectionStateType() {
+        return m_callbackType;
+    }
+
+  private:
+    connectionStateType m_callbackType;
+};
+
+typedef DPL::SharedPtr<OnNetworkBearerSelectionStateChanged> OnNetworkBearerSelectionStateChangedPtr;
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<OnNetworkBearerSelectionStateChanged> OnNetworkBearerSelectionStateChangedEmitter;
+typedef DPL::SharedPtr<OnNetworkBearerSelectionStateChangedEmitter> OnNetworkBearerSelectionStateChangedEmitterPtr;
+
+}
+}
+}
+
+#endif //_ON_POWER_STATE_CHANGED_H_
diff --git a/src/platform/API/NetworkBearerSelection/config.cmake b/src/platform/API/NetworkBearerSelection/config.cmake
new file mode 100755 (executable)
index 0000000..efe16fd
--- /dev/null
@@ -0,0 +1,7 @@
+get_current_path()
+
+set(SRCS_PLATFORM_API_NETWORKBEARERSELECTION
+  ${CURRENT_PATH}/INetworkBearerSelection.cpp
+  ${CURRENT_PATH}/NetworkBearerSelectionFactory.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Notification/INotification.cpp b/src/platform/API/Notification/INotification.cpp
new file mode 100644 (file)
index 0000000..8037024
--- /dev/null
@@ -0,0 +1,37 @@
+//
+// 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 TizenApis {
+namespace Api {
+namespace Notification {
+
+INotification::INotification()
+{
+}
+INotification::INotification(bool progress)
+{
+}
+
+INotification::~INotification() {
+}
+
+}
+}
+}
diff --git a/src/platform/API/Notification/INotification.h b/src/platform/API/Notification/INotification.h
new file mode 100644 (file)
index 0000000..06f46be
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// 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 <API/Application/ApplicationControl.h>
+
+
+namespace TizenApis {
+namespace Api {
+namespace Notification {
+
+
+class INotification 
+{
+public:
+       virtual ~INotification();
+       // notification
+       virtual std::string getId() = 0;
+       virtual std::string getType() = 0;
+       virtual time_t getPostedTime() = 0;
+       virtual std::string getTitle() = 0;
+       virtual void setTitle(const std::string& title) = 0;
+       virtual std::string getContent() = 0;   
+       virtual void setContent(const std::string& content) = 0;
+
+       // status notification
+       virtual std::string getStatusType() = 0;
+       virtual void setStatusType(const std::string& progressType) = 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& iconPath) = 0;
+       virtual bool getVibration() = 0;
+       virtual void setVibration(const bool& vibration) = 0;
+       virtual TizenApis::Api::Application::ApplicationControlPtr getApplicationControl() = 0;
+       virtual void setApplicationControl(TizenApis::Api::Application::ApplicationControlPtr control) = 0;
+       virtual void setApplicationId(const std::string& appId) = 0;
+       virtual std::string getApplicationId() = 0;
+       virtual double getProgressValue() = 0;  
+       virtual void setProgressValue(const unsigned short& progressValue) = 0; 
+       virtual void* getNotificationHandle() = 0;
+       virtual void setNotificationHandle(void *handle) = 0;           
+protected:
+       INotification();
+       INotification(bool progress);
+};
+
+typedef DPL::SharedPtr<INotification> INotificationPtr;
+
+}
+}
+}
+
+#endif 
diff --git a/src/platform/API/Notification/INotificationManager.cpp b/src/platform/API/Notification/INotificationManager.cpp
new file mode 100644 (file)
index 0000000..12297f1
--- /dev/null
@@ -0,0 +1,38 @@
+//
+// 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 TizenApis {
+namespace Api {
+namespace Notification {
+
+INotificationManager::INotificationManager()
+       
+{
+}
+
+INotificationManager::~INotificationManager()
+       
+{
+}
+
+
+}
+}
+}
diff --git a/src/platform/API/Notification/INotificationManager.h b/src/platform/API/Notification/INotificationManager.h
new file mode 100644 (file)
index 0000000..03a435a
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// 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 TizenApis {
+namespace Api {
+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/platform/API/Notification/NotificationFactory.cpp b/src/platform/API/Notification/NotificationFactory.cpp
new file mode 100644 (file)
index 0000000..e70d57c
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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 <Notification/NotificationManager.h>
+#include <Notification/StatusNotification.h>
+
+
+namespace TizenApis {
+namespace Api {
+namespace Notification {
+
+INotificationManagerPtr NotificationFactory::getNotificationManager() 
+{
+       return INotificationManagerPtr(new TizenApis::Platform::Notification::NotificationManager());
+}              
+
+INotificationPtr NotificationFactory::getNotification(bool ongoing) 
+{
+       return INotificationPtr(new TizenApis::Platform::Notification::StatusNotification(ongoing));
+}              
+
+INotificationPtr NotificationFactory::getNotification() 
+{
+       return INotificationPtr(new TizenApis::Platform::Notification::StatusNotification());
+}
+
+NotificationFactory& NotificationFactory::getInstance() 
+{
+       static NotificationFactory theInstance;
+       return theInstance;
+}
+
+NotificationFactory::NotificationFactory() 
+{
+}
+
+NotificationFactory::~NotificationFactory()
+{
+}
+}
+}
+}
diff --git a/src/platform/API/Notification/NotificationFactory.h b/src/platform/API/Notification/NotificationFactory.h
new file mode 100644 (file)
index 0000000..0d6d4bf
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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 <API/Notification/INotificationManager.h>
+#include <API/Notification/INotification.h>
+
+
+
+namespace TizenApis {
+namespace Api {
+namespace Notification {
+       
+class NotificationFactory : DPL::Noncopyable
+{
+public:
+       INotificationManagerPtr getNotificationManager();
+       INotificationPtr getNotification(bool ongoing);
+       INotificationPtr getNotification();
+       static NotificationFactory& getInstance();
+
+protected:
+       NotificationFactory();
+       ~NotificationFactory();
+};
+
+}
+}
+}
+
+#endif 
+
diff --git a/src/platform/API/Notification/config.cmake b/src/platform/API/Notification/config.cmake
new file mode 100644 (file)
index 0000000..99352f4
--- /dev/null
@@ -0,0 +1,8 @@
+get_current_path()
+
+set(SRCS_PLATFORM_API_NOTIFICATION
+  ${CURRENT_PATH}/NotificationFactory.cpp
+  ${CURRENT_PATH}/INotificationManager.cpp
+  ${CURRENT_PATH}/INotification.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Power/IEventGetScreenBrightness.h b/src/platform/API/Power/IEventGetScreenBrightness.h
new file mode 100755 (executable)
index 0000000..7d15269
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_GET_SCREEN_BRIGHTNESS_H_
+#define _ABSTRACT_LAYER_IEVENT_GET_SCREEN_BRIGHTNESS_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class IEventGetScreenBrightness : public WrtDeviceApis::Commons::IEvent<IEventGetScreenBrightness>
+{
+    bool m_result;
+    double m_brightness;
+
+  public:
+    void setResult(bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    void setBrightness(double value) {
+        m_brightness = value;
+    }
+    double getBrightenss() const {
+        return m_brightness;
+    }
+
+    IEventGetScreenBrightness() :  m_result(false),
+        m_brightness(0) {
+    }
+    ~IEventGetScreenBrightness() {
+    }
+};
+
+typedef DPL::SharedPtr<IEventGetScreenBrightness> IEventGetScreenBrightnessPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_GET_SCREEN_BRIGHTNESS_H_ */
diff --git a/src/platform/API/Power/IEventIsScreenOn.h b/src/platform/API/Power/IEventIsScreenOn.h
new file mode 100644 (file)
index 0000000..577c9d4
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_IS_SCREEN_ON_H_
+#define _ABSTRACT_LAYER_IEVENT_IS_SCREEN_ON_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class IEventIsScreenOn : public WrtDeviceApis::Commons::IEvent<IEventIsScreenOn>
+{
+    bool m_result;
+    bool m_isScreenOn;
+
+  public:
+    void setResult(bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    void setIsScreenOn(bool value) {
+        m_isScreenOn = value;
+    }
+    bool getIsScreenOn() const {
+        return m_isScreenOn;
+    }
+
+    IEventIsScreenOn() :  m_result(false),
+        m_isScreenOn(true) {
+    }
+    ~IEventIsScreenOn() {
+    }
+};
+
+typedef DPL::SharedPtr<IEventIsScreenOn> IEventIsScreenOnPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_IS_SCREEN_ON_H_ */
diff --git a/src/platform/API/Power/IEventRelease.h b/src/platform/API/Power/IEventRelease.h
new file mode 100755 (executable)
index 0000000..7844c6c
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_RELEASE_H_
+#define _ABSTRACT_LAYER_IEVENT_RELEASE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class IEventRelease : public WrtDeviceApis::Commons::IEvent<IEventRelease>
+{
+    PowerResource m_resource;
+    bool m_result;
+
+  public:
+    void setResult(bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    void setResource(PowerResource value) {
+        m_resource = value;
+    }
+    PowerResource getResource() const {
+        return m_resource;
+    }
+
+    IEventRelease() : m_resource(UNDEFINED_RESOURCE),
+        m_result(false) {
+    }
+    ~IEventRelease() {
+    }
+};
+
+typedef DPL::SharedPtr<IEventRelease> IEventReleasePtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_RELEASE_H_ */
diff --git a/src/platform/API/Power/IEventRequest.h b/src/platform/API/Power/IEventRequest.h
new file mode 100755 (executable)
index 0000000..e689ac7
--- /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 _ABSTRACT_LAYER_IEVENT_REQUEST_H_
+#define _ABSTRACT_LAYER_IEVENT_REQUEST_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "IPowerManager.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class IEventRequest : public WrtDeviceApis::Commons::IEvent<IEventRequest>
+{
+    PowerResource m_powerResource;
+    PowerState m_powerState;
+    bool m_result;
+
+  public:
+    void setResult(bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    void setResource(PowerResource value) {
+        m_powerResource = value;
+    }
+    PowerResource getResource() const {
+        return m_powerResource;
+    }
+
+    void setState(PowerState value) {
+        m_powerState = value;
+    }
+    PowerState getState() const {
+        return m_powerState;
+    }
+
+    IEventRequest() : m_powerResource(UNDEFINED_RESOURCE),
+        m_powerState(UNDEFINED_STATE),
+        m_result(false) {
+    }
+    ~IEventRequest() {
+    }
+};
+
+typedef DPL::SharedPtr<IEventRequest> IEventRequestPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_REQUEST_H_ */
diff --git a/src/platform/API/Power/IEventRestoreScreenBrightness.h b/src/platform/API/Power/IEventRestoreScreenBrightness.h
new file mode 100755 (executable)
index 0000000..585ea2b
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_RESTORE_SCREEN_BRIGHTNESS_H_
+#define _ABSTRACT_LAYER_IEVENT_RESTORE_SCREEN_BRIGHTNESS_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class IEventRestoreScreenBrightness : public WrtDeviceApis::Commons::IEvent<IEventRestoreScreenBrightness>
+{
+    bool m_result;
+
+  public:
+    void setResult(bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    IEventRestoreScreenBrightness() : m_result(false) {
+    }
+    ~IEventRestoreScreenBrightness() {
+    }
+};
+
+typedef DPL::SharedPtr<IEventRestoreScreenBrightness> IEventRestoreScreenBrightnessPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_RESTORE_SCREEN_BRIGHTNESS_H_ */
\ No newline at end of file
diff --git a/src/platform/API/Power/IEventSetScreenBrightness.h b/src/platform/API/Power/IEventSetScreenBrightness.h
new file mode 100755 (executable)
index 0000000..f10fa3d
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_SET_SCREEN_BRIGHTNESS_H_
+#define _ABSTRACT_LAYER_IEVENT_SET_SCREEN_BRIGHTNESS_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class IEventSetScreenBrightness : public WrtDeviceApis::Commons::IEvent<IEventSetScreenBrightness>
+{
+    bool m_result;
+    double m_brightness;
+
+  public:
+    void setResult(bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    void setBrightness(double value) {
+        m_brightness = value;
+    }
+    double getBrightness() const {
+        return m_brightness;
+    }
+
+    IEventSetScreenBrightness() :  m_result(false),
+        m_brightness(0) {
+    }
+    ~IEventSetScreenBrightness() {
+    }
+};
+
+typedef DPL::SharedPtr<IEventSetScreenBrightness> IEventSetScreenBrightnessPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_SET_SCREEN_BRIGHTNESS_H_ */
+
diff --git a/src/platform/API/Power/IEventSetScreenStateChangeListener.h b/src/platform/API/Power/IEventSetScreenStateChangeListener.h
new file mode 100755 (executable)
index 0000000..e2e2a63
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_SET_SCREEN_STATE_CHANGE_LISTENER_H_
+#define _ABSTRACT_LAYER_IEVENT_SET_SCREEN_STATE_CHANGE_LISTENER_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "OnPowerStateChanged.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class IEventSetScreenStateChangeListener : public WrtDeviceApis::Commons::IEvent<IEventSetScreenStateChangeListener>
+{
+    bool m_result;
+    OnPowerStateChangedEmitterPtr m_emitter;
+
+  public:
+    void setResult(bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    void setEmitter(OnPowerStateChangedEmitterPtr value) {
+        m_emitter = value;
+    }
+    OnPowerStateChangedEmitterPtr getEmitter() const {
+        return m_emitter;
+    }
+
+    IEventSetScreenStateChangeListener() : m_result(false),
+        m_emitter(NULL) {
+    }
+    ~IEventSetScreenStateChangeListener() {
+    }
+};
+
+typedef DPL::SharedPtr<IEventSetScreenStateChangeListener> IEventSetScreenStateChangeListenerPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_SET_SCREEN_STATE_CHANGE_LISTENER_H_ */
diff --git a/src/platform/API/Power/IEventTurnScreenOff.h b/src/platform/API/Power/IEventTurnScreenOff.h
new file mode 100755 (executable)
index 0000000..bf70796
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_TURN_SCREEN_OFF_H_
+#define _ABSTRACT_LAYER_IEVENT_TURN_SCREEN_OFF_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class IEventTurnScreenOff : public WrtDeviceApis::Commons::IEvent<IEventTurnScreenOff>
+{
+    bool m_result;
+
+  public:
+    void setResult(bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    IEventTurnScreenOff() :  m_result(false) {
+    }
+    ~IEventTurnScreenOff() {
+    }
+};
+
+typedef DPL::SharedPtr<IEventTurnScreenOff> IEventTurnScreenOffPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_TURN_SCREEN_OFF_H_ */
\ No newline at end of file
diff --git a/src/platform/API/Power/IEventTurnScreenOn.h b/src/platform/API/Power/IEventTurnScreenOn.h
new file mode 100755 (executable)
index 0000000..281f6e3
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_TURN_SCREEN_ON_H_
+#define _ABSTRACT_LAYER_IEVENT_TURN_SCREEN_ON_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class IEventTurnScreenOn : public WrtDeviceApis::Commons::IEvent<IEventTurnScreenOn>
+{
+    bool m_result;
+
+  public:
+    void setResult(bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    IEventTurnScreenOn() : m_result(false) {
+    }
+    ~IEventTurnScreenOn() {
+    }
+};
+
+typedef DPL::SharedPtr<IEventTurnScreenOn> IEventTurnScreenOnPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_TURN_SCREEN_ON_H_ */
\ No newline at end of file
diff --git a/src/platform/API/Power/IEventUnsetScreenStateChangeListener.h b/src/platform/API/Power/IEventUnsetScreenStateChangeListener.h
new file mode 100755 (executable)
index 0000000..d023861
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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 _ABSTRACT_LAYER_IEVENT_UNSET_SCREEN_STATE_CHANGE_LISTENER_H_
+#define _ABSTRACT_LAYER_IEVENT_UNSET_SCREEN_STATE_CHANGE_LISTENER_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class IEventUnsetScreenStateChangeListener : public WrtDeviceApis::Commons::IEvent<IEventUnsetScreenStateChangeListener>
+{
+    bool m_result;
+
+  public:
+    void setResult(bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    IEventUnsetScreenStateChangeListener() : m_result(false) {
+    }
+    ~IEventUnsetScreenStateChangeListener() {
+    }
+};
+
+typedef DPL::SharedPtr<IEventUnsetScreenStateChangeListener> IEventUnsetScreenStateChangeListenerPtr;
+
+}
+}
+}
+#endif /* _ABSTRACT_LAYER_IEVENT_UNSET_SCREEN_STATE_CHANGE_LISTENER_H_ */
+
diff --git a/src/platform/API/Power/IPowerManager.cpp b/src/platform/API/Power/IPowerManager.cpp
new file mode 100755 (executable)
index 0000000..b38b398
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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 "IPowerManager.h"
+#include <Commons/ThreadPool.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+IPowerManager::IPowerManager() :
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventRequest >(WrtDeviceApis::Commons::ThreadEnum::POWER_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventRelease >(WrtDeviceApis::Commons::ThreadEnum::POWER_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventSetScreenStateChangeListener >(WrtDeviceApis::Commons::ThreadEnum::POWER_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventUnsetScreenStateChangeListener >(WrtDeviceApis::Commons::ThreadEnum::POWER_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventGetScreenBrightness >(WrtDeviceApis::Commons::ThreadEnum::POWER_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventSetScreenBrightness >(WrtDeviceApis::Commons::ThreadEnum::POWER_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventIsScreenOn >(WrtDeviceApis::Commons::ThreadEnum::POWER_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventRestoreScreenBrightness >(WrtDeviceApis::Commons::ThreadEnum::POWER_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventTurnScreenOn >(WrtDeviceApis::Commons::ThreadEnum::POWER_THREAD),
+    WrtDeviceApis::Commons::EventRequestReceiver< IEventTurnScreenOff >(WrtDeviceApis::Commons::ThreadEnum::POWER_THREAD)
+{
+}
+
+IPowerManager::~IPowerManager()
+{
+}
+
+void IPowerManager::request(const IEventRequestPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventRequest>::PostRequest(event);
+}
+
+void IPowerManager::release(const IEventReleasePtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventRelease>::PostRequest(event);
+}
+
+void IPowerManager::setScreenStateChangeListener(const IEventSetScreenStateChangeListenerPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventSetScreenStateChangeListener>::PostRequest(event);
+}
+
+void IPowerManager::unsetScreenStateChangeListener(const IEventUnsetScreenStateChangeListenerPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventUnsetScreenStateChangeListener>::PostRequest(event);
+}
+
+void IPowerManager::getScreenBrightness(const IEventGetScreenBrightnessPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventGetScreenBrightness>::PostRequest(event);
+}
+
+void IPowerManager::setScreenBrightness(const IEventSetScreenBrightnessPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventSetScreenBrightness>::PostRequest(event);
+}
+
+void IPowerManager::isScreenOn(const IEventIsScreenOnPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventIsScreenOn>::PostRequest(event);
+}
+
+void IPowerManager::restoreScreenBrightness(const IEventRestoreScreenBrightnessPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventRestoreScreenBrightness>::PostRequest(event);
+}
+
+void IPowerManager::turnScreenOn(const IEventTurnScreenOnPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventTurnScreenOn>::PostRequest(event);
+}
+
+void IPowerManager::turnScreenOff(const IEventTurnScreenOffPtr &event)
+{
+    WrtDeviceApis::Commons::EventRequestReceiver<IEventTurnScreenOff>::PostRequest(event);
+}
+
+}
+}
+}
diff --git a/src/platform/API/Power/IPowerManager.h b/src/platform/API/Power/IPowerManager.h
new file mode 100755 (executable)
index 0000000..d508a97
--- /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.
+//
+
+#ifndef _ABSTRACT_LAYER_IPOWER_MANAGER_H_
+#define _ABSTRACT_LAYER_IPOWER_MANAGER_H_
+
+#include "PowerCommon.h"
+#include "IEventRequest.h"
+#include "IEventRelease.h"
+#include "IEventSetScreenStateChangeListener.h"
+#include "IEventUnsetScreenStateChangeListener.h"
+#include "IEventGetScreenBrightness.h"
+#include "IEventSetScreenBrightness.h"
+#include "IEventIsScreenOn.h"
+#include "IEventRestoreScreenBrightness.h"
+#include "IEventTurnScreenOn.h"
+#include "IEventTurnScreenOff.h"
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class IPowerManager : public WrtDeviceApis::Commons::EventRequestReceiver< IEventRequest >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventRelease >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventSetScreenStateChangeListener >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventUnsetScreenStateChangeListener >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventGetScreenBrightness >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventSetScreenBrightness >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventIsScreenOn >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventRestoreScreenBrightness >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventTurnScreenOn >,
+    public WrtDeviceApis::Commons::EventRequestReceiver< IEventTurnScreenOff >
+{
+  public:
+    IPowerManager();
+    virtual ~IPowerManager();
+    virtual void request(const IEventRequestPtr &event);
+    virtual void release(const IEventReleasePtr &event);
+    virtual void setScreenStateChangeListener(const IEventSetScreenStateChangeListenerPtr &event);
+    virtual void unsetScreenStateChangeListener(const IEventUnsetScreenStateChangeListenerPtr &event);
+    virtual void getScreenBrightness(const IEventGetScreenBrightnessPtr &event);
+    virtual void setScreenBrightness(const IEventSetScreenBrightnessPtr &event);
+    virtual void isScreenOn(const IEventIsScreenOnPtr &event);
+    virtual void restoreScreenBrightness(const IEventRestoreScreenBrightnessPtr &event);
+    virtual void turnScreenOn(const IEventTurnScreenOnPtr &event);
+    virtual void turnScreenOff(const IEventTurnScreenOffPtr &event);
+
+  protected:
+    virtual void OnRequestReceived(const IEventRequestPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventReleasePtr &event) = 0;
+    virtual void OnRequestReceived(const IEventSetScreenStateChangeListenerPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventUnsetScreenStateChangeListenerPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventGetScreenBrightnessPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventSetScreenBrightnessPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventIsScreenOnPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventRestoreScreenBrightnessPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventTurnScreenOnPtr &event) = 0;
+    virtual void OnRequestReceived(const IEventTurnScreenOffPtr &event) = 0;
+};
+
+typedef DPL::SharedPtr<IPowerManager> IPowerManagerPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_IPOWER_MANAGER_H_ */
diff --git a/src/platform/API/Power/OnPowerStateChanged.h b/src/platform/API/Power/OnPowerStateChanged.h
new file mode 100755 (executable)
index 0000000..9bc4502
--- /dev/null
@@ -0,0 +1,88 @@
+//
+// 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 _ON_POWER_STATE_CHANGED_H_
+#define _ON_POWER_STATE_CHANGED_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/ListenerEvent.h>
+#include <Commons/Emitters.h>
+#include "PowerCommon.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+class OnPowerStateChanged : public WrtDeviceApis::Commons::ListenerEvent<OnPowerStateChanged>
+{
+    public:
+
+    OnPowerStateChanged(){
+       m_resource = UNDEFINED_RESOURCE;
+       m_previousState = UNDEFINED_STATE;
+       m_changedState = UNDEFINED_STATE;
+       m_result = false;
+    }
+    ~OnPowerStateChanged() {
+    }
+
+    void setResult (bool value) {
+        m_result = value;
+    }
+    bool getResult() const {
+        return m_result;
+    }
+
+    void setResource(PowerResource value) {
+        m_resource = value;
+    }
+    PowerResource getResource() const {
+        return m_resource;
+    }
+
+    void setPreviousState(PowerState value) {
+        m_previousState = value;
+    }
+    PowerState getPreviousState() const {
+        return m_previousState;
+    }
+
+    void setChangedState(PowerState value) {
+        m_changedState = value;
+    }
+    PowerState getChangedState() const {
+        return m_changedState;
+    }
+
+    private:
+    PowerResource m_resource;
+    PowerState m_previousState;
+    PowerState m_changedState;
+    bool m_result;
+};
+
+typedef DPL::SharedPtr<OnPowerStateChanged> OnPowerStateChangedPtr;
+typedef WrtDeviceApis::Commons::ListenerEventEmitter<OnPowerStateChanged> OnPowerStateChangedEmitter;
+typedef DPL::SharedPtr<OnPowerStateChangedEmitter> OnPowerStateChangedEmitterPtr;
+
+}
+}
+}
+
+#endif //_ON_POWER_STATE_CHANGED_H_
diff --git a/src/platform/API/Power/PowerCommon.h b/src/platform/API/Power/PowerCommon.h
new file mode 100755 (executable)
index 0000000..e65a428
--- /dev/null
@@ -0,0 +1,47 @@
+//
+// 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 _ABSTRACT_LAYER_POWER_COMMON_H_
+#define _ABSTRACT_LAYER_POWER_COMMON_H_
+
+namespace TizenApis {
+namespace Api {
+namespace Power {
+
+typedef enum
+{
+    SCREEN_RESOURCE,
+    CPU_RESOURCE,
+    UNDEFINED_RESOURCE
+} PowerResource;
+
+typedef enum
+{
+    SCREEN_OFF_STATE,
+    SCREEN_DIM_STATE,
+    SCREEN_NORMAL_STATE,
+    SCREEN_BRIGHT_STATE,
+    CPU_AWAKE_STATE,
+    UNDEFINED_STATE
+} PowerState;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_POWER_COMMON_H_ */
+
diff --git a/src/platform/API/Power/config.cmake b/src/platform/API/Power/config.cmake
new file mode 100755 (executable)
index 0000000..b5ecc4b
--- /dev/null
@@ -0,0 +1,5 @@
+get_current_path()
+set(SRCS_PLATFORM_API_POWER
+  ${CURRENT_PATH}/IPowerManager.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/SystemSetting/EventGetSetting.h b/src/platform/API/SystemSetting/EventGetSetting.h
new file mode 100755 (executable)
index 0000000..52d4197
--- /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 WRTPLUGINS_API_SYSTEMSETTING_GET_SETTING_EVENT_H_
+#define WRTPLUGINS_API_SYSTEMSETTING_GET_SETTING_EVENT_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+#include "ISystemSettingType.h"
+
+namespace TizenApis {
+namespace Api {
+namespace SystemSetting {
+
+class EventGetSetting : public WrtDeviceApis::Commons::IEvent<EventGetSetting>
+{
+       public:
+               void setSettingValue(const std::string &value)
+               {
+                       m_settingValue = value;
+               }
+
+               std::string getSettingValue() const
+               {
+                       return m_settingValue;
+               }
+
+//             void setSettingType(const std::string &value)
+               void setSettingType(Api::SystemSetting::SettingType value)
+               {
+                       m_settingType = value;
+               }
+
+//             std::string getSettingType() const
+               Api::SystemSetting::SettingType getSettingType() const
+               {
+                       return m_settingType;
+               }
+
+               EventGetSetting()
+               {
+               }
+
+               ~EventGetSetting()
+               {
+               }
+       private:
+               std::string m_settingValue;
+//             std::string m_settingType;
+// USE TO CONVERTER
+               Api::SystemSetting::SettingType m_settingType;
+//             int m_settingType;
+
+};
+
+typedef DPL::SharedPtr<EventGetSetting> EventGetSettingPtr;
+
+}
+}
+}
+#endif
diff --git a/src/platform/API/SystemSetting/EventSetRingtone.h b/src/platform/API/SystemSetting/EventSetRingtone.h
new file mode 100755 (executable)
index 0000000..1bbb42d
--- /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 WRTPLUGINS_API_SYSTEMSETTING_SET_RINGTONE_EVENT_H_
+#define WRTPLUGINS_API_SYSTEMSETTING_SET_RINGTONE_EVENT_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace SystemSetting {
+
+class EventSetRingtone : public WrtDeviceApis::Commons::IEvent<EventSetRingtone>
+{
+       public:
+               void setRingtoneURI(const std::string &value)
+               {
+                       m_ringtoneUri = value;
+               }
+
+               std::string getRingtoneURI() const
+               {
+                       return m_ringtoneUri;
+               }
+
+               void setRingtoneType(const std::string &value)
+               {
+                       m_ringtoneType = value;
+               }
+
+               std::string getRingtoneType() const
+               {
+                       return m_ringtoneType;
+               }
+
+               EventSetRingtone()
+               {
+               }
+
+               ~EventSetRingtone()
+               {
+               }
+               private:
+                       std::string m_ringtoneUri;
+                       std::string m_ringtoneType;
+};
+
+typedef DPL::SharedPtr<EventSetRingtone> EventSetRingtonePtr;
+
+}
+}
+}
+#endif
diff --git a/src/platform/API/SystemSetting/EventSetSetting.h b/src/platform/API/SystemSetting/EventSetSetting.h
new file mode 100755 (executable)
index 0000000..095fbc7
--- /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 WRTPLUGINS_API_SYSTEMSETTING_SET_SETTING_EVENT_H_
+#define WRTPLUGINS_API_SYSTEMSETTING_SET_SETTING_EVENT_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+#include "ISystemSettingType.h"
+
+namespace TizenApis {
+namespace Api {
+namespace SystemSetting {
+
+class EventSetSetting : public WrtDeviceApis::Commons::IEvent<EventSetSetting>
+{
+       public:
+               void setSettingValue(const std::string &value)
+               {
+                       m_settingValue = value;
+               }
+
+               std::string getSettingValue() const
+               {
+                       return m_settingValue;
+               }
+
+               void setSettingType(Api::SystemSetting::SettingType value)
+               {
+                       m_settingType = value;
+               }
+
+               Api::SystemSetting::SettingType getSettingType() const
+               {
+                       return m_settingType;
+               }
+
+               EventSetSetting()
+               {
+               }
+
+               ~EventSetSetting()
+               {
+               }
+       private:
+               std::string m_settingValue;
+               Api::SystemSetting::SettingType m_settingType;
+};
+
+typedef DPL::SharedPtr<EventSetSetting> EventSetSettingPtr;
+
+}
+}
+}
+#endif
diff --git a/src/platform/API/SystemSetting/EventSetWallpaper.h b/src/platform/API/SystemSetting/EventSetWallpaper.h
new file mode 100755 (executable)
index 0000000..53ca752
--- /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 WRTPLUGINS_API_SYSTEMSETTING_SET_WALLPAPER_EVENT_H_
+#define WRTPLUGINS_API_SYSTEMSETTING_SET_WALLPAPER_EVENT_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace SystemSetting {
+
+class EventSetWallpaper : public WrtDeviceApis::Commons::IEvent<EventSetWallpaper>
+{
+       public:
+               void setWallpaperURI(const std::string &value)
+               {
+                       m_wallpaperUri = value;
+               }
+
+               std::string getWallpaperURI() const
+               {
+                       return m_wallpaperUri;
+               }
+
+               void setWallpaperType(const std::string &value)
+               {
+                       m_wallpaperType = value;
+               }
+
+               std::string getWallpaperType() const
+               {
+                       return m_wallpaperType;
+               }
+
+               EventSetWallpaper()
+               {
+               }
+
+               ~EventSetWallpaper()
+               {
+               }
+       private:
+               std::string m_wallpaperUri;
+               std::string m_wallpaperType;
+};
+
+typedef DPL::SharedPtr<EventSetWallpaper> EventSetWallpaperPtr;
+
+}
+}
+}
+#endif
diff --git a/src/platform/API/SystemSetting/ISystemSetting.cpp b/src/platform/API/SystemSetting/ISystemSetting.cpp
new file mode 100755 (executable)
index 0000000..fb4b699
--- /dev/null
@@ -0,0 +1,41 @@
+//
+// 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 "ISystemSetting.h"
+#include "EventSetWallpaper.h"
+#include "EventSetRingtone.h"
+
+namespace TizenApis {
+namespace Api {
+namespace SystemSetting {
+using namespace WrtDeviceApis::Commons;
+
+ISystemSetting::ISystemSetting() :
+       EventRequestReceiver< EventSetWallpaper >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventSetRingtone >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventSetSetting >(ThreadEnum::NULL_THREAD),
+       EventRequestReceiver< EventGetSetting >(ThreadEnum::NULL_THREAD)
+{
+}
+
+ISystemSetting::~ISystemSetting()
+{
+}
+
+}
+}
+}
diff --git a/src/platform/API/SystemSetting/ISystemSetting.h b/src/platform/API/SystemSetting/ISystemSetting.h
new file mode 100755 (executable)
index 0000000..4a8c847
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// 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_API_ISYSTEMSETTING_H_
+#define WRTPLUGINS_API_ISYSTEMSETTING_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include "EventSetWallpaper.h"
+#include "EventSetRingtone.h"
+#include "EventSetSetting.h"
+#include "EventGetSetting.h"
+
+namespace TizenApis {
+namespace Api {
+namespace SystemSetting {
+
+class EventSetWallpaper;
+class EventSetRingtone;
+class EventSetSetting;
+class EventGetSetting;
+
+
+typedef DPL::SharedPtr<EventSetWallpaper> EventSetWallpaperPtr;
+typedef DPL::SharedPtr<EventSetRingtone> EventSetRingtonePtr;
+typedef DPL::SharedPtr<EventSetSetting> EventSetSettingPtr;
+typedef DPL::SharedPtr<EventGetSetting> EventGetSettingPtr;
+
+
+class ISystemSetting :
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventSetWallpaper>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventSetRingtone>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventSetSetting>,
+    public WrtDeviceApis::Commons::EventRequestReceiver<EventGetSetting>
+{
+  public:
+    virtual ~ISystemSetting();
+    ISystemSetting();
+
+    virtual void setWallpaper(const EventSetWallpaperPtr &event) = 0;
+    virtual void setRingtone(const EventSetRingtonePtr &event) = 0;
+    virtual void setProperty(const EventSetSettingPtr &event) = 0;
+    virtual void getProperty(const EventGetSettingPtr &event) = 0;
+    virtual std::string getProperty(const Api::SystemSetting::SettingType settingType) = 0;
+
+  protected:
+       virtual void OnRequestReceived(const EventSetWallpaperPtr &event) = 0;
+       virtual void OnRequestReceived(const EventSetRingtonePtr &event) = 0;
+       virtual void OnRequestReceived(const EventSetSettingPtr &event) = 0;
+       virtual void OnRequestReceived(const EventGetSettingPtr &event) = 0;
+
+};
+
+typedef DPL::SharedPtr<ISystemSetting> ISystemSettingPtr;
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/API/SystemSetting/ISystemSettingType.h b/src/platform/API/SystemSetting/ISystemSettingType.h
new file mode 100755 (executable)
index 0000000..0d9e4cd
--- /dev/null
@@ -0,0 +1,48 @@
+//\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
+#ifndef ISYSTEMSETTINGTYPES_H\r
+#define ISYSTEMSETTINGTYPES_H\r
+\r
+namespace TizenApis {\r
+namespace Api {\r
+namespace SystemSetting {\r
+\r
+//--------------------------------------------------------------------------\r
+\r
+//#define NAME_SMS_TYPE                "SMS"\r
+\r
+#define NAME_HOME_SCREEN_TYPE          "HOME_SCREEN"\r
+#define NAME_LOCK_SCREEN_TYPE                  "LOCK_SCREEN"\r
+#define NAME_INCOMMING_CALL_TYPE               "INCOMING_CALL"\r
+#define NAME_INCOMMING_EMAIL_TYPE              "NOTIFICATION_EMAIL"\r
+\r
+enum SettingType\r
+{\r
+    HOME_SCREEN =0,\r
+    LOCK_SCREEN,\r
+    INCOMMING_CALL,\r
+    NOTIFICATION_EMAIL\r
+};\r
+\r
+\r
+}\r
+}\r
+}\r
+#endif\r
+\r
+\r
diff --git a/src/platform/API/SystemSetting/SystemSettingFactory.cpp b/src/platform/API/SystemSetting/SystemSettingFactory.cpp
new file mode 100755 (executable)
index 0000000..a6ca6ce
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// 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 <SystemSetting/SystemSetting.h>
+#include "SystemSettingFactory.h"
+
+namespace TizenApis {
+namespace Api {
+namespace SystemSetting {
+
+ISystemSettingPtr SystemSettingFactory::getSystemSetting()
+{
+    ISystemSettingPtr result(new TizenApis::Platform::SystemSetting::SystemSetting());
+    return result;
+}
+
+SystemSettingFactory& SystemSettingFactory::getInstance()
+{
+    static SystemSettingFactory theInstance;
+    return theInstance;
+}
+
+SystemSettingFactory::SystemSettingFactory()
+{
+}
+
+}
+}
+}
diff --git a/src/platform/API/SystemSetting/SystemSettingFactory.h b/src/platform/API/SystemSetting/SystemSettingFactory.h
new file mode 100755 (executable)
index 0000000..84fc859
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// 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_API_SYSTEMSETTING_FACTORY_H_
+#define WRTPLUGINS_API_SYSTEMSETTING_FACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include "ISystemSetting.h"
+
+namespace TizenApis {
+namespace Api {
+namespace SystemSetting {
+
+class SystemSettingFactory : DPL::Noncopyable
+{
+  public:
+    ISystemSettingPtr getSystemSetting();
+
+    static SystemSettingFactory& getInstance();
+
+  protected:
+    SystemSettingFactory();
+};
+
+}
+}
+}
+
+#endif
+
diff --git a/src/platform/API/SystemSetting/config.cmake b/src/platform/API/SystemSetting/config.cmake
new file mode 100644 (file)
index 0000000..21c80ec
--- /dev/null
@@ -0,0 +1,7 @@
+get_current_path()
+
+set(SRCS_PLATFORM_API_SYSTEMSETTING
+  ${CURRENT_PATH}/ISystemSetting.cpp
+  ${CURRENT_PATH}/SystemSettingFactory.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/Systeminfo/BaseProperties.h b/src/platform/API/Systeminfo/BaseProperties.h
new file mode 100755 (executable)
index 0000000..c64a4f7
--- /dev/null
@@ -0,0 +1,83 @@
+//
+// 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_API_BASE_PROPERTIES_H_
+#define WRTPLUGINS_API_BASE_PROPERTIES_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include "standards/Tizen/Systeminfo/JSNetworkInfo.h"
+#include "standards/Tizen/Systeminfo/JSWifiNetworkInfo.h"
+#include "standards/Tizen/Systeminfo/JSCellularNetworkInfo.h"
+#include "standards/Tizen/Systeminfo/JSSIMInfo.h"
+#include "standards/Tizen/Systeminfo/JSStorageInfo.h"
+#include "standards/Tizen/Systeminfo/JSBatteryInfo.h"
+#include "standards/Tizen/Systeminfo/JSDisplayInfo.h"
+#include "standards/Tizen/Systeminfo/JSCpuInfo.h"
+#include "standards/Tizen/Systeminfo/JSDeviceCapabilitiesInfo.h"
+#include "standards/Tizen/Systeminfo/JSDeviceOrientationInfo.h"
+#include "standards/Tizen/Systeminfo/JSBuildInfo.h"
+
+#include "SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Systeminfo {
+
+struct WatchOption
+{
+       unsigned long timeout;
+       double        highThreshold;
+       double        lowThreshold;
+    std::string   id;
+
+    WatchOption () :
+       timeout(0),
+       highThreshold(0.0),
+       lowThreshold(0.0),
+       id("")
+       {
+       }
+};
+
+class BaseProperty
+{
+  public:
+
+    explicit BaseProperty()
+    {
+    }
+
+    virtual ~BaseProperty()
+    {
+    }
+
+    virtual JSValueRef getValue(JSContextRef context, void* handle) const = 0;
+    virtual const char* getProperty() const = 0;
+    virtual const int getWatchType() const = 0;    
+};
+
+typedef DPL::SharedPtr<BaseProperty> BasePropertyPtr;
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/API/Systeminfo/EventGetSysteminfo.cpp b/src/platform/API/Systeminfo/EventGetSysteminfo.cpp
new file mode 100755 (executable)
index 0000000..6b52973
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+#include "EventGetSysteminfo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Systeminfo {
+
+EventGetSysteminfo::EventGetSysteminfo()
+{
+}
+
+EventGetSysteminfo::~EventGetSysteminfo()
+{
+}
+
+void EventGetSysteminfo::setBasePropertyPtr(const BasePropertyPtr& baseProperty)
+{
+    m_BaseProperty = baseProperty;
+}
+
+JSValueRef EventGetSysteminfo::getValue() const
+{
+    return m_value;
+}
+
+const char * EventGetSysteminfo::getProperty() const
+{
+    return m_BaseProperty->getProperty();
+}
+
+void EventGetSysteminfo::processGetValue(void* handle)
+{
+    LogDebug("enter");
+    if (!m_BaseProperty) {
+        LogError("property is not set");
+        setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::ConversionException);
+    } else {
+        WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_callbackManager = DPL::StaticPointerCast<WrtDeviceApis::CommonsJavaScript::JSCallbackManager >(getPrivateData());
+        if (!m_callbackManager) {
+            LogError("property is not set");
+            setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::NullPointerException);
+        } else {
+            JSContextRef context = m_callbackManager->getContext();
+            m_value = m_BaseProperty->getValue(context, handle);
+        }
+    }
+}
+
+}
+}
+}
\ No newline at end of file
diff --git a/src/platform/API/Systeminfo/EventGetSysteminfo.h b/src/platform/API/Systeminfo/EventGetSysteminfo.h
new file mode 100755 (executable)
index 0000000..4036759
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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_API_SYSTEMINFO_EVENT_GET_SYSTEMINFO_H_
+#define WRTPLUGINS_API_SYSTEMINFO_EVENT_GET_SYSTEMINFO_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include "ISysteminfo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Systeminfo {
+class EventGetSysteminfo;
+
+class EventGetSysteminfo : public WrtDeviceApis::Commons::IEvent<EventGetSysteminfo>
+{
+  private :
+    Api::Systeminfo::BasePropertyPtr m_BaseProperty;
+    JSValueRef m_value;
+
+  public :
+    EventGetSysteminfo();
+    ~EventGetSysteminfo();
+
+    void setBasePropertyPtr(const BasePropertyPtr& baseProperty);
+    JSValueRef getValue() const;
+    const char * getProperty() const;
+    void processGetValue(void* handle);
+};
+
+typedef DPL::SharedPtr<EventGetSysteminfo> EventGetSysteminfoPtr;
+
+}
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/platform/API/Systeminfo/EventWatchSysteminfo.cpp b/src/platform/API/Systeminfo/EventWatchSysteminfo.cpp
new file mode 100755 (executable)
index 0000000..3db463d
--- /dev/null
@@ -0,0 +1,416 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <Commons/Exception.h>
+#include "EventWatchSysteminfo.h"
+#include "Systeminfo/Systeminfo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Systeminfo {
+
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+
+namespace {
+
+static Eina_Bool timeout_timer_cb(void* data)
+{
+    LogDebug("enter");
+    EventWatchSysteminfo *event = static_cast<EventWatchSysteminfo *> (data);
+    event->timeoutWatch();
+    return ECORE_CALLBACK_RENEW;
+}
+
+}
+
+#define MAX_STORAGE_CNT 3
+DPL::Atomic EventWatchSysteminfo::m_uniqId = 1;
+
+EventWatchSysteminfo::EventWatchSysteminfo() :
+    m_initTimer(NULL),
+    m_id(m_uniqId),
+    m_canceled(false),
+    m_lastValue(NULL),
+    m_storageCnt(0),
+    m_tmpStorageCnt(0),
+    m_Systeminfo(NULL)
+{
+    ++m_uniqId;
+}
+
+EventWatchSysteminfo::~EventWatchSysteminfo()
+{
+    LogDebug("destroy event data, id=" << m_id);
+    removeTimer();
+}
+
+void EventWatchSysteminfo::setWatchOption(const WatchOption& watchoption) {
+    m_WatchOption = watchoption;
+}
+
+WatchOption EventWatchSysteminfo::getWatchOption() {
+    return m_WatchOption;
+}
+
+JSCallbackManagerPtr EventWatchSysteminfo::getCallbackManager() {
+    return DPL::StaticPointerCast< JSCallbackManager >(getPrivateData());
+}
+
+BasePropertyPtr EventWatchSysteminfo::getBasePropertyPtr() {
+    return m_BaseProperty;
+}
+
+void EventWatchSysteminfo::setSysteminfoPtr(void* SysteminfoPtr) {
+    m_Systeminfo = SysteminfoPtr;
+}
+
+void EventWatchSysteminfo::setBasePropertyPtr(const BasePropertyPtr& baseProperty) {
+    m_BaseProperty = baseProperty;
+}
+
+const char * EventWatchSysteminfo::getProperty() const {
+    return m_BaseProperty->getProperty();
+}
+
+const int EventWatchSysteminfo::getWatchType() const {
+    return m_BaseProperty->getWatchType();
+}
+
+void EventWatchSysteminfo::getWatchValue(int cnt)
+{
+    LogDebug("enter");
+    m_tmpStorageCnt = cnt;
+    processGetValue();
+}
+
+int EventWatchSysteminfo::getId() const
+{
+    return m_id;
+}
+
+void EventWatchSysteminfo::setId(int id)
+{
+    m_id = id;
+}
+
+JSValueRef EventWatchSysteminfo::getPropertyValue(JSContextRef context, JSValueRef value, std::string key)
+{
+    JSObjectRef object = NULL;
+    JSValueRef* exception = NULL;
+    JSStringRef propertyName = NULL;
+
+    object = JSValueToObject(context, value, exception);
+    propertyName = JSStringCreateWithUTF8CString(key.c_str());
+
+    return JSObjectGetProperty(context, object, propertyName, exception);
+}
+
+void EventWatchSysteminfo::processGetValue()
+{
+    LogDebug("thread=" << DPL::Thread::GetCurrentThread());
+    if(m_canceled) {
+               LogDebug("Watch event is cancelled aleardy.");
+        return;
+    }
+    if (m_Systeminfo == NULL) {
+        LogError("systeminfo pointer is not set");
+        return;
+    }
+
+    JSCallbackManagerPtr m_cbm = DPL::StaticPointerCast< JSCallbackManager >(getPrivateData());
+    JSContextRef context = m_cbm->getContext();
+    JSValueRef tmpValue = NULL;
+
+    if(!m_lastValue) {
+        m_lastValue = m_BaseProperty->getValue(context, (void*)((TizenApis::Platform::Systeminfo::Systeminfo*)m_Systeminfo)->getConnectionHandle());
+        return;
+    }
+
+    JSValueRef* exception = NULL;
+    if (m_BaseProperty->getWatchType() == Platform::Systeminfo::WATCH_TYPE_CPU) {
+        tmpValue = ((TizenApis::Platform::Systeminfo::Systeminfo*)m_Systeminfo)->getCpuValue(context);
+    } else {
+        tmpValue = m_BaseProperty->getValue(context, (void*)((TizenApis::Platform::Systeminfo::Systeminfo*)m_Systeminfo)->getConnectionHandle());
+    }
+    Converter converter(context);
+
+    if (!tmpValue) {
+        return;
+    }
+    LogDebug("watchType : " << m_BaseProperty->getWatchType());
+
+    if (m_BaseProperty->getWatchType() == Platform::Systeminfo::WATCH_TYPE_BATTERY) {
+        std::string key = "level";
+        JSValueRef propertyLevel = getPropertyValue(context, tmpValue, key);
+        double level = JSValueToNumber(context, propertyLevel, exception);
+        propertyLevel = getPropertyValue(context, m_lastValue, key);
+        double prevLevel = JSValueToNumber(context, propertyLevel, exception);
+
+        key = "isCharging";
+        JSValueRef propertyCharging = getPropertyValue(context, tmpValue, key);
+        bool isCharging = JSValueToBoolean(context, propertyCharging);
+        propertyCharging = getPropertyValue(context, m_lastValue, key);
+        bool prevIsCharging = JSValueToBoolean(context, propertyCharging);
+
+        if(level != prevLevel || isCharging != prevIsCharging) {
+            if (((m_WatchOption.highThreshold > 0) && (level > m_WatchOption.highThreshold))
+            || ((m_WatchOption.lowThreshold > 0) && (level < m_WatchOption.lowThreshold))
+            || ((m_WatchOption.highThreshold == 0) && (m_WatchOption.lowThreshold == 0))) {
+               m_cbm->callOnSuccess(tmpValue);
+                setTimer();
+            }
+        }
+        m_lastValue = tmpValue;
+    } else if (m_BaseProperty->getWatchType() == Platform::Systeminfo::WATCH_TYPE_DISPLAY) {
+        std::string key = "brightness";
+        JSValueRef propertyBrightness = getPropertyValue(context, tmpValue, key);
+        double brightness = JSValueToNumber(context, propertyBrightness, exception);
+        propertyBrightness = getPropertyValue(context, m_lastValue, key);
+        double prevBrightness = JSValueToNumber(context, propertyBrightness, exception);
+
+        if(brightness != prevBrightness) {
+            if (((m_WatchOption.highThreshold > 0) && (brightness > m_WatchOption.highThreshold))
+                || ((m_WatchOption.lowThreshold > 0) && (brightness < m_WatchOption.lowThreshold))
+                || ((m_WatchOption.highThreshold == 0) && (m_WatchOption.lowThreshold == 0))) {
+                m_cbm->callOnSuccess(tmpValue);
+                setTimer();
+            }
+        }
+        m_lastValue = tmpValue;
+    } else if (m_BaseProperty->getWatchType() == Platform::Systeminfo::WATCH_TYPE_WIFINETWORK) {
+        std::string key = "status";
+        JSValueRef propertyStatus = getPropertyValue(context, tmpValue, key);
+        JSStringRef status = JSValueToStringCopy(context, propertyStatus, exception);
+        propertyStatus = getPropertyValue(context, m_lastValue, key);
+        JSStringRef prevStatus = JSValueToStringCopy(context, propertyStatus, exception);
+
+        key = "ssid";
+        JSValueRef propertySsid = getPropertyValue(context, tmpValue, key);
+        JSStringRef ssid = JSValueToStringCopy(context, propertySsid, exception);
+        propertySsid = getPropertyValue(context, m_lastValue, key);
+        JSStringRef prevSsid = JSValueToStringCopy(context, propertySsid, exception);
+
+        key = "signalStrength";
+        JSValueRef propertySignalStrength = getPropertyValue(context, tmpValue, key);
+        double signalStrength = JSValueToNumber(context, propertySignalStrength, exception);
+        propertySignalStrength = getPropertyValue(context, m_lastValue, key);
+        double prevSignalStrength = JSValueToNumber(context, propertySignalStrength, exception);
+
+        if(!JSStringIsEqual(status,prevStatus) || !JSStringIsEqual(ssid,prevSsid) || signalStrength != prevSignalStrength) {
+            if (((m_WatchOption.highThreshold > 0) && (signalStrength > m_WatchOption.highThreshold))
+                || ((m_WatchOption.lowThreshold > 0) && (signalStrength < m_WatchOption.lowThreshold))
+                || ((m_WatchOption.highThreshold == 0) && (m_WatchOption.lowThreshold == 0))) {
+                m_cbm->callOnSuccess(tmpValue);
+                setTimer();
+            }
+        }
+        m_lastValue = tmpValue;
+    } else if (m_BaseProperty->getWatchType() == Platform::Systeminfo::WATCH_TYPE_CELLULARNETWORK) {
+        std::string key = "status";
+        JSValueRef propertyStatus = getPropertyValue(context, tmpValue, key);
+        JSStringRef status = JSValueToStringCopy(context, propertyStatus, exception);
+        propertyStatus = getPropertyValue(context, m_lastValue, key);
+        JSStringRef prevStatus = JSValueToStringCopy(context, propertyStatus, exception);
+
+        key = "apn";
+        JSValueRef propertyApn = getPropertyValue(context, tmpValue, key);
+        JSStringRef apn = JSValueToStringCopy(context, propertyApn, exception);
+        propertyApn = getPropertyValue(context, m_lastValue, key);
+        JSStringRef prevApn = JSValueToStringCopy(context, propertyApn, exception);
+
+        key = "mcc";
+        JSValueRef propertyMcc = getPropertyValue(context, tmpValue, key);
+        double mcc = JSValueToNumber(context, propertyMcc, exception);
+        propertyMcc = getPropertyValue(context, m_lastValue, key);
+        double prevMcc = JSValueToNumber(context, propertyMcc, exception);
+
+        key = "mnc";
+        JSValueRef propertyMnc = getPropertyValue(context, tmpValue, key);
+        double mnc = JSValueToNumber(context, propertyMnc, exception);
+        propertyMnc = getPropertyValue(context, m_lastValue, key);
+        double prevMnc = JSValueToNumber(context, propertyMnc, exception);
+
+        key = "lac";
+        JSValueRef propertyLac = getPropertyValue(context, tmpValue, key);
+        JSStringRef lac = JSValueToStringCopy(context, propertyLac, exception);
+        propertyLac = getPropertyValue(context, m_lastValue, key);
+        JSStringRef prevLac = JSValueToStringCopy(context, propertyLac, exception);
+
+        key = "cellId";
+        JSValueRef propertyCellId = getPropertyValue(context, tmpValue, key);
+        JSStringRef cellId = JSValueToStringCopy(context, propertyCellId, exception);
+        propertyCellId = getPropertyValue(context, m_lastValue, key);
+        JSStringRef prevCellId = JSValueToStringCopy(context, propertyCellId, exception);
+
+        key = "isRoaming";
+        JSValueRef propertyRoam = getPropertyValue(context, tmpValue, key);
+        bool roam = JSValueToBoolean(context, propertyRoam);
+        propertyRoam = getPropertyValue(context, m_lastValue, key);
+        bool prevRoam = JSValueToBoolean(context, propertyRoam);
+
+        if ( !JSStringIsEqual(status, prevStatus) || !JSStringIsEqual(apn, prevApn) || mcc != prevMcc || mnc != prevMnc
+            || roam != prevRoam || !JSStringIsEqual(lac, prevLac) || !JSStringIsEqual(cellId, prevCellId)) {
+            m_cbm->callOnSuccess(tmpValue);
+            setTimer();
+        }
+        m_lastValue = tmpValue;
+    } else if (m_BaseProperty->getWatchType() == Platform::Systeminfo::WATCH_TYPE_CPU) {
+        std::string key = "load";
+        JSValueRef propertyLoad = getPropertyValue(context, tmpValue, key);
+        double load = JSValueToNumber(context, propertyLoad, exception);
+        propertyLoad = getPropertyValue(context, m_lastValue, key);
+        double prevLoad = JSValueToNumber(context, propertyLoad, exception);
+
+        if(load != prevLoad) {
+            if (((m_WatchOption.highThreshold > 0) && (load > m_WatchOption.highThreshold))
+                || ((m_WatchOption.lowThreshold > 0) && (load < m_WatchOption.lowThreshold))
+                || ((m_WatchOption.highThreshold == 0) && (m_WatchOption.lowThreshold == 0))) {
+                m_cbm->callOnSuccess(tmpValue);
+                setTimer();
+            }
+        }
+        m_lastValue = tmpValue;
+    } else if (m_BaseProperty->getWatchType() == Platform::Systeminfo::WATCH_TYPE_STORAGE) {
+        JSValueRef tmpValueList[MAX_STORAGE_CNT];
+        JSValueRef lastValueList[MAX_STORAGE_CNT];
+        if (m_tmpStorageCnt > MAX_STORAGE_CNT) {
+            Throw(Exception);
+        }
+
+        for (int i=0; i<m_tmpStorageCnt; i++) {
+            tmpValueList[i] = JSGetArrayElement(context, JSValueToObject(context, tmpValue, NULL), i);
+        }
+
+        for (int j=0; j<m_storageCnt; j++) {
+            lastValueList[j] = JSGetArrayElement(context, JSValueToObject(context, m_lastValue, NULL), j);
+        }
+
+        if (m_tmpStorageCnt == m_storageCnt) {
+            LogDebug("enter");
+            for (int i=0; i<m_tmpStorageCnt; i++) {
+               LogDebug("enter");
+               std::string key = "type";
+               JSValueRef propertyType = getPropertyValue(context, tmpValueList[i], key);
+               JSStringRef type = JSValueToStringCopy(context, propertyType, exception);
+               propertyType = getPropertyValue(context, lastValueList[i], key);
+               JSStringRef prevType = JSValueToStringCopy(context, propertyType, exception);
+
+               key = "capacity";
+               JSValueRef propertyCapacity = getPropertyValue(context, tmpValueList[i], key);
+               double capacity = JSValueToNumber(context, propertyCapacity, exception);
+               propertyCapacity = getPropertyValue(context, lastValueList[i], key);
+               double prevCapacity = JSValueToNumber(context, propertyCapacity, exception);
+               LogDebug("capacity : " << capacity << "prevCapacity : " << prevCapacity);
+
+               key = "availableCapacity";
+               JSValueRef propertyAvailableCapacity = getPropertyValue(context, tmpValueList[i], key);
+               double availableCapacity = JSValueToNumber(context, propertyAvailableCapacity, exception);
+               propertyAvailableCapacity = getPropertyValue(context, lastValueList[i], key);
+               double prevAvailableCapacity = JSValueToNumber(context, propertyAvailableCapacity, exception);
+               LogDebug("availableCapacity : " << availableCapacity << "prevAvailableCapacity : " << prevAvailableCapacity);
+
+               key = "isRemoveable";
+               JSValueRef propertyIsRemoveable = getPropertyValue(context, tmpValueList[i], key);
+               bool isRemoveable = JSValueToBoolean(context, propertyIsRemoveable);
+               propertyIsRemoveable = getPropertyValue(context, lastValueList[i], key);
+               double prevIsRemoveable = JSValueToBoolean(context, propertyIsRemoveable);
+               LogDebug("isRemoveable : " << propertyIsRemoveable << "prevIsRemoveable : " << prevIsRemoveable);
+
+               if (!JSStringIsEqual(type, prevType) || capacity != prevCapacity || availableCapacity != prevAvailableCapacity
+                    || isRemoveable != prevIsRemoveable) {
+                    LogDebug("make callback");
+                    m_cbm->callOnSuccess(tmpValue);
+                    setTimer();
+               }
+               m_lastValue = tmpValue;
+            }
+        } else {
+            LogDebug("enter");
+            m_cbm->callOnSuccess(tmpValue);
+            m_storageCnt = m_tmpStorageCnt;
+            m_lastValue = tmpValue;
+            setTimer();
+        }
+    } else if (m_BaseProperty->getWatchType() == Platform::Systeminfo::WATCH_TYPE_DEVICE_ORIENTATION) {
+        std::string key = "status";
+        JSValueRef propertyStatus = getPropertyValue(context, tmpValue, key);
+        double status = JSValueToNumber(context, propertyStatus, exception);
+        propertyStatus = getPropertyValue(context, m_lastValue, key);
+        double prevStatus = JSValueToNumber(context, propertyStatus, exception);
+        LogDebug("status : " << status << "prevStatus : " << prevStatus);
+       if (status != prevStatus) {
+            LogDebug("make callback");
+            m_cbm->callOnSuccess(tmpValue);
+            setTimer();
+       }
+       m_lastValue = tmpValue;
+    } else if (m_BaseProperty->getWatchType() == Platform::Systeminfo::WATCH_TYPE_NETWORK) {
+        std::string key = "networkType";
+        JSValueRef propertyNetworkType = getPropertyValue(context, tmpValue, key);
+        JSStringRef networkType = JSValueToStringCopy(context, propertyNetworkType, exception);
+        propertyNetworkType = getPropertyValue(context, m_lastValue, key);
+        JSStringRef prevNetworkType = JSValueToStringCopy(context, propertyNetworkType, exception);
+        LogDebug("networkType : " << networkType << "prevNetworkType : " << prevNetworkType);
+       if (networkType != prevNetworkType) {
+            LogDebug("make callback");
+            m_cbm->callOnSuccess(tmpValue);
+            setTimer();
+       }
+       m_lastValue = tmpValue;
+    }
+}
+
+void EventWatchSysteminfo::setTimer()
+{
+    if (m_WatchOption.timeout > 0) {
+        if (m_initTimer) {
+            ecore_timer_freeze(m_initTimer);
+            ecore_timer_del(m_initTimer);
+            m_initTimer = NULL;
+        }
+        double value = m_WatchOption.timeout/(double)1000;
+        m_initTimer = ecore_timer_add(value, timeout_timer_cb, this);
+        ecore_timer_thaw(m_initTimer);
+    }
+}
+
+void EventWatchSysteminfo::removeTimer()
+{
+    if (m_initTimer) {
+        ecore_timer_freeze(m_initTimer);
+        ecore_timer_del(m_initTimer);
+    }
+    m_initTimer = NULL;        
+}
+
+void EventWatchSysteminfo::clearWatch()
+{
+    m_canceled = true;
+    removeTimer();
+    ((TizenApis::Platform::Systeminfo::Systeminfo*)m_Systeminfo)->clearWatch(m_id);
+}
+
+void EventWatchSysteminfo::timeoutWatch()
+{
+    clearWatch();
+}
+
+}
+}
+}
diff --git a/src/platform/API/Systeminfo/EventWatchSysteminfo.h b/src/platform/API/Systeminfo/EventWatchSysteminfo.h
new file mode 100755 (executable)
index 0000000..3408a99
--- /dev/null
@@ -0,0 +1,81 @@
+//
+// 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_API_SYSTEMINFO_EVENT_WATCH_SYSTEMINFO_H_
+#define WRTPLUGINS_API_SYSTEMINFO_EVENT_WATCH_SYSTEMINFO_H_
+
+#include <ctime>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <Commons/IEvent.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include "ISysteminfo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Systeminfo {
+class EventWatchSysteminfo;
+
+class EventWatchSysteminfo : public WrtDeviceApis::Commons::IEvent<EventWatchSysteminfo>
+{
+  private :
+       static DPL::Atomic m_uniqId;
+
+       Api::Systeminfo::BasePropertyPtr m_BaseProperty;
+       Api::Systeminfo::WatchOption     m_WatchOption;
+       void*            m_Systeminfo;
+
+       Ecore_Timer *m_initTimer;
+       long m_id;
+       int m_watchType;
+       bool m_canceled;
+       JSValueRef m_lastValue;
+       DPL::Mutex m_mutex;
+       int m_storageCnt;
+       int m_tmpStorageCnt;
+
+  public :
+        EventWatchSysteminfo();
+       ~EventWatchSysteminfo();
+
+       void setWatchOption(const WatchOption& watchoption);
+       WatchOption getWatchOption();
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getCallbackManager();
+       BasePropertyPtr getBasePropertyPtr();
+       void setSysteminfoPtr(void* SysteminfoPtr);
+       void setBasePropertyPtr(const BasePropertyPtr& baseProperty);
+       const char * getProperty() const;
+       const int getWatchType() const;
+       void getWatchValue(int cnt = 1);
+       int getId() const;
+       void setId(int id);
+       JSValueRef getPropertyValue(JSContextRef context, JSValueRef value, std::string key);
+       void processGetValue();
+       void setTimer();
+       void removeTimer();
+       void clearWatch();
+       void timeoutWatch();
+};
+
+typedef DPL::SharedPtr<EventWatchSysteminfo> EventWatchSysteminfoPtr;
+}
+}
+}
+
+#endif
diff --git a/src/platform/API/Systeminfo/ISysteminfo.cpp b/src/platform/API/Systeminfo/ISysteminfo.cpp
new file mode 100755 (executable)
index 0000000..71907a0
--- /dev/null
@@ -0,0 +1,38 @@
+//
+// 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 "ISysteminfo.h"
+#include "EventGetSysteminfo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Systeminfo {
+using namespace WrtDeviceApis::Commons;
+
+ISysteminfo::ISysteminfo() : 
+    EventRequestReceiver<EventGetSysteminfo>(ThreadEnum::NULL_THREAD),
+    EventRequestReceiver<EventWatchSysteminfo>(ThreadEnum::NULL_THREAD)        
+{
+}
+
+ISysteminfo::~ISysteminfo()
+{
+}
+
+}
+}
+}
diff --git a/src/platform/API/Systeminfo/ISysteminfo.h b/src/platform/API/Systeminfo/ISysteminfo.h
new file mode 100755 (executable)
index 0000000..c1a669f
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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_API_ISYSTEMINFO_H_
+#define WRTPLUGINS_API_ISYSTEMINFO_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+
+#include "BaseProperties.h"
+#include "EventGetSysteminfo.h"
+#include "EventWatchSysteminfo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Systeminfo {
+
+class EventGetSysteminfo;
+class EventWatchSysteminfo;
+typedef DPL::SharedPtr<EventGetSysteminfo> EventGetSysteminfoPtr;
+typedef DPL::SharedPtr<EventWatchSysteminfo> EventWatchSysteminfoPtr;
+
+class ISysteminfo : 
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventGetSysteminfo>,
+       public WrtDeviceApis::Commons::EventRequestReceiver<EventWatchSysteminfo>       
+{
+  public:
+    virtual ~ISysteminfo();
+
+    virtual Api::Systeminfo::DeviceCapabilitiesPropertiesPtr getCapabilities() = 0;
+    virtual void get(const EventGetSysteminfoPtr& event) = 0;
+    virtual void watch(const EventWatchSysteminfoPtr& event) = 0;    
+       virtual BasePropertyPtr getBasePropertyPtr(JSContextRef context, JSValueRef property) = 0;
+       virtual void clearWatch(const long id) = 0;
+
+  protected:
+    ISysteminfo();
+
+    virtual void OnRequestReceived(const EventGetSysteminfoPtr& event) = 0;
+    virtual void OnRequestReceived(const EventWatchSysteminfoPtr& event) = 0;    
+};
+
+typedef DPL::SharedPtr<ISysteminfo> ISysteminfoPtr;
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/API/Systeminfo/SysteminfoFactory.cpp b/src/platform/API/Systeminfo/SysteminfoFactory.cpp
new file mode 100755 (executable)
index 0000000..7237b9b
--- /dev/null
@@ -0,0 +1,42 @@
+//
+// 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 <Systeminfo/Systeminfo.h>
+#include "SysteminfoFactory.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Systeminfo {
+
+ISysteminfoPtr SysteminfoFactory::getSysteminfos()
+{
+    return ISysteminfoPtr(new Platform::Systeminfo::Systeminfo());
+}
+
+SysteminfoFactory& SysteminfoFactory::getInstance()
+{
+    static SysteminfoFactory theInstance;
+    return theInstance;
+}
+
+SysteminfoFactory::SysteminfoFactory()
+{
+}
+
+}
+}
+}
diff --git a/src/platform/API/Systeminfo/SysteminfoFactory.h b/src/platform/API/Systeminfo/SysteminfoFactory.h
new file mode 100755 (executable)
index 0000000..e8929eb
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// 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_API_SYSTMEINFOFACTORY_H_
+#define WRTPLUGINS_API_SYSTMEINFOFACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include "ISysteminfo.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Systeminfo {
+
+class SysteminfoFactory : DPL::Noncopyable
+{
+  public:
+    ISysteminfoPtr getSysteminfos();
+
+    static SysteminfoFactory& getInstance();
+
+  protected:
+    SysteminfoFactory();
+};
+
+}
+}
+}
+
+#endif
+
diff --git a/src/platform/API/Systeminfo/SysteminfoPropertyInfo.h b/src/platform/API/Systeminfo/SysteminfoPropertyInfo.h
new file mode 100755 (executable)
index 0000000..9dff448
--- /dev/null
@@ -0,0 +1,285 @@
+//
+// 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_API_PROPERTY_INFO_H_
+#define WRTPLUGINS_API_PROPERTY_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Systeminfo {
+
+enum SystemInfosDeviceOrientationStatus {
+    PORTRAIT_PRIMARY = 0,
+    PORTRAIT_SECONDARY = 1,
+    LANDSCAPE_PRIMARY = 2,
+    LANDSCAPE_SECONDARY = 3
+};
+
+struct DeviceCapabilitiesProperties
+{
+    bool            bluetooth;
+    bool            nfc;
+    unsigned short  multiTouchCount;
+    std::string     inputKeyboard;
+    bool            wifi;
+    bool            wifiDirect;
+    bool            openglesVersion1_1;
+    bool            openglesVersion2_0;
+    bool            fmRadio;
+    std::string     platformVersion;
+    std::string     platformName;
+    bool            cameraFront;
+    bool            cameraFrontFlash;
+    bool            cameraBack;
+    bool            cameraBackFlash;
+    bool            location;
+    bool            locationGps;    
+    bool            locationWps;
+    bool            microphone;
+    bool            usbHost;
+    bool            usbAccessory;
+    bool            screenOutputRca;
+    bool            screenOutputHdmi;
+    std::string     platformCoreCpuArch;
+    std::string     platformCoreFpuArch;
+    bool            sipVoip;
+    std::string     duid;
+    bool            speechRecognition;
+    bool            accelerometer;    
+    bool            barometer;
+    bool            gyroscope;
+    bool            magnetometer;
+    bool            proximity;
+
+    DeviceCapabilitiesProperties() :
+        bluetooth(false),
+        nfc(false),
+        multiTouchCount(0),
+        inputKeyboard(""),
+        wifi(false),
+        wifiDirect(false),
+        openglesVersion1_1(false),
+        openglesVersion2_0(false),
+        fmRadio(false),
+        platformVersion(""),
+        platformName(""),
+        cameraFront(false),
+        cameraFrontFlash(false),
+        cameraBack(false),
+        cameraBackFlash(false),
+        location(false),
+        locationGps(false),
+        locationWps(false),
+        microphone(false),
+        usbHost(false),
+        usbAccessory(false),
+        screenOutputRca(false),
+        screenOutputHdmi(false),
+        platformCoreCpuArch(""),
+        platformCoreFpuArch(""),
+        sipVoip(false),
+        duid(""),
+        speechRecognition(false),
+        accelerometer(false),
+        barometer(false),
+        gyroscope(false),
+        magnetometer(false),
+        proximity(false)
+        {
+        }
+};
+
+struct BatteryProperties
+{
+    double level;
+    bool isCharging;
+
+    BatteryProperties() :
+        level(0.0),
+        isCharging(false)
+    {
+    }
+};
+
+struct CpuProperties
+{
+    double load;
+
+    CpuProperties() :
+        load(0.0)
+    {
+    }
+};
+
+struct StorageProperties
+{
+       std::string             type;
+       unsigned long long      capacity;
+       unsigned long long      availableCapacity;
+       bool                    isRemoveable;
+
+       StorageProperties():
+               type("UNKNOWN"),
+               capacity(0),
+               availableCapacity(0),
+               isRemoveable(false)
+       {
+       }
+};
+
+struct DisplayProperties
+{
+       unsigned long  resolutionWidth;
+       unsigned long  resolutionHeight;
+       unsigned long  dotsPerInchWidth;
+       unsigned long  dotsPerInchHeight;
+       double         physicalWidth;
+       double         physicalHeight;
+       double         brightness;
+
+       DisplayProperties() :
+               resolutionWidth(0),
+               resolutionHeight(0),
+               dotsPerInchWidth(0),
+               dotsPerInchHeight(0),
+               physicalWidth(0.0),
+               physicalHeight(0.0),
+               brightness(0.0)
+       {
+       }
+};
+
+struct WifiNetworkProperties
+{
+       std::string             status;
+       std::string             ssid;
+       std::string             ipAddress;
+       std::string             ipv6Address;    
+       double                  signalStrength;
+
+       WifiNetworkProperties() :
+               status(""),
+               ssid(""),
+               ipAddress(""),
+               ipv6Address(""),
+               signalStrength(0.0)
+       {
+       }
+};
+
+struct NetworkProperties
+{
+       std::string             networkType;
+
+       NetworkProperties() :
+               networkType("UNKNOWN")
+       {
+       }
+};
+
+struct CellularNetworkProperties
+{
+       std::string             status;
+       std::string             apn;
+       std::string             ipAddress;
+       std::string             ipv6Address;    
+       unsigned short  mcc;
+       unsigned short  mnc;
+       unsigned short  cellId;
+       unsigned short  lac;
+       bool                    isRoaming;
+
+       CellularNetworkProperties() :
+               status(""),
+               apn(""),
+               ipAddress(""),
+               ipv6Address(""),
+               mcc(0),
+               mnc(0),
+               cellId(0),
+               lac(0),
+               isRoaming(false)
+       {
+       }
+};
+
+struct SIMProperties
+{
+       std::string             operatorName;
+       std::string             msisdn;
+       std::string             iccid;
+       unsigned short  mcc;
+       unsigned short  mnc;
+       std::string             msin;
+       std::string             spn;
+
+       SIMProperties() :
+               operatorName(""),
+               msisdn(""),
+               iccid(""),
+               mcc(0),
+               mnc(0),
+               msin(""),
+               spn("")
+       {
+       }
+};
+
+struct DeviceOrientationProperties
+{
+    std::string  status;
+
+    DeviceOrientationProperties() :
+        status("")
+    {\r
+    }
+};
+
+struct BuildProperties
+{
+    std::string  model;
+
+    BuildProperties() :
+        model("")
+    {\r
+    }
+};
+
+typedef DPL::SharedPtr<DeviceCapabilitiesProperties> DeviceCapabilitiesPropertiesPtr;
+typedef DPL::SharedPtr<BatteryProperties> BatteryPropertiesPtr;
+typedef DPL::SharedPtr<CpuProperties> CpuPropertiesPtr;
+typedef DPL::SharedPtr<StorageProperties> StoragePropertiesPtr;
+typedef DPL::SharedPtr<DisplayProperties> DisplayPropertiesPtr;
+typedef DPL::SharedPtr<WifiNetworkProperties> WifiNetworkPropertiesPtr;
+typedef DPL::SharedPtr<NetworkProperties> NetworkPropertiesPtr;
+typedef DPL::SharedPtr<CellularNetworkProperties> CellularNetworkPropertiesPtr;
+typedef DPL::SharedPtr<SIMProperties> SIMPropertiesPtr;
+typedef DPL::SharedPtr<DeviceOrientationProperties> DeviceOrientationPropertiesPtr;
+typedef DPL::SharedPtr<BuildProperties> BuildPropertiesPtr;
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/API/Systeminfo/config.cmake b/src/platform/API/Systeminfo/config.cmake
new file mode 100755 (executable)
index 0000000..90e0333
--- /dev/null
@@ -0,0 +1,9 @@
+get_current_path()
+
+set(SRCS_PLATFORM_API_SYSTEMINFO
+  ${CURRENT_PATH}/SysteminfoFactory.cpp
+  ${CURRENT_PATH}/EventGetSysteminfo.cpp  
+  ${CURRENT_PATH}/EventWatchSysteminfo.cpp
+  ${CURRENT_PATH}/ISysteminfo.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/TimeUtil/DurationProperties.h b/src/platform/API/TimeUtil/DurationProperties.h
new file mode 100755 (executable)
index 0000000..b7dd32f
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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_API_TIMEUTIL_DURATION_PROPERTIES_H_
+#define WRTPLUGINS_API_TIMEUTIL_DURATION_PROPERTIES_H_
+
+#include <dpl/shared_ptr.h>
+#include <string>
+
+using namespace std;
+
+namespace TizenApis {
+namespace Api {
+namespace TimeUtil {
+
+namespace {
+       const short MSECS_UNIT= 0;
+       const short SECONDS_UNIT = 1;
+       const short MINUTES_UNIT = 2;
+       const short HOURS_UNIT = 3;
+       const short DAYS_UNIT = 4;
+
+}
+
+struct DurationProperties
+{
+       long long length;
+       short unit;
+       DurationProperties()
+               : length(0),
+               unit(MSECS_UNIT)
+       {
+       }
+};
+
+typedef DPL::SharedPtr<DurationProperties> DurationPropertiesPtr;
+
+} //TimeUtil
+} // Api
+} // TizenApis
+
+#endif //WRTPLUGINS_API_TIMEUTIL_DURATION_PROPERTIES_H_
\ No newline at end of file
diff --git a/src/platform/API/TimeUtil/EventSetCurrentTZDate.h b/src/platform/API/TimeUtil/EventSetCurrentTZDate.h
new file mode 100755 (executable)
index 0000000..0aef815
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// 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_API_TIMEUTIL_EVENT_SET_CURRENT_TZDATE_H_
+#define WRTPLUGINS_API_TIMEUTIL_EVENT_SET_CURRENT_TZDATE_H_
+
+#include <Commons/IEvent.h>
+#include <dpl/shared_ptr.h>
+#include "TZDateProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace TimeUtil {
+
+class EventSetCurrentTZDate : public WrtDeviceApis::Commons::IEvent<EventSetCurrentTZDate>
+{
+    bool             m_result;
+    TZDateProperties m_properties;
+public:
+       
+    EventSetCurrentTZDate() : m_result(false) { LogDebug("entered"); }
+    ~EventSetCurrentTZDate() { }
+    void             setResult(bool value) { m_result = value; }
+    bool             getResult() const { return m_result; }
+    TZDateProperties                getTZDateProperties() const { return  m_properties;}
+    void                setTZDateProperties(const TZDateProperties &value) {m_properties = value;}
+    virtual void    clearOnCancel(){;}
+};
+
+typedef DPL::SharedPtr<EventSetCurrentTZDate> EventSetCurrentTZDatePtr;
+
+} //TimeUtil
+} // Api
+} // TizenApis
+
+#endif //WRTPLUGINS_API_TIMEUTIL_EVENT_SET_CURRENT_DATETIME_H_
\ No newline at end of file
diff --git a/src/platform/API/TimeUtil/ITZDate.h b/src/platform/API/TimeUtil/ITZDate.h
new file mode 100755 (executable)
index 0000000..94ba71f
--- /dev/null
@@ -0,0 +1,98 @@
+//
+// 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 _ABSTRACT_LAYER_ITZDATE_H_
+#define _ABSTRACT_LAYER_ITZDATE_H_
+
+#include <ctime>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include "DurationProperties.h"
+#include "TZDateProperties.h"
+
+namespace TizenApis {
+namespace Api {
+namespace TimeUtil {
+
+class ITZDate {
+public:
+       enum TZDateFields {
+               TZDATE_ERA,
+               TZDATE_YEAR,
+               TZDATE_MONTH,
+               TZDATE_WEEK_OF_YEAR,
+               TZDATE_WEEK_OF_MONTH,
+               TZDATE_DATE,
+               TZDATE_DAY_OF_YEAR,
+               TZDATE_DAY_OF_WEEK,
+               TZDATE_DAY_OF_WEEK_IN_MONTH,
+               TZDATE_AM_PM,
+               TZDATE_HOUR,
+               TZDATE_HOUR_OF_DAY,
+               TZDATE_MINUTE,
+               TZDATE_SECOND,
+               TZDATE_MILLISECOND,
+               TZDATE_ZONE_OFFSET,
+               TZDATE_DST_OFFSET,
+
+               TZDATE_FIELDS_COUNT,
+       };
+       
+       enum DSTTransition {
+               PREV_TRANSITION,
+               NEXT_TRANSITION
+       };
+       
+       ITZDate() {
+               ;
+       }
+       virtual ~ITZDate() {
+               ;
+       }
+
+       virtual bool  isNull() =0;
+       virtual long get(const TZDateFields field) =0;
+       virtual std::string getTimezone() =0;
+       virtual TZDateProperties toTimezone(const std::string timezone) =0;
+       virtual void set(const TZDateFields field, const long value) = 0;
+               
+       virtual long getUTC(const TZDateFields field) = 0;
+       virtual void setUTC(const TZDateFields field, const long value) = 0;
+
+       virtual long long difference(const TZDateProperties &prop) =0;
+       virtual TZDateProperties addDuration(const DurationProperties &duration) =0;
+       virtual TZDateProperties toUTC() =0;
+       virtual TZDateProperties toLocalTimezone() =0;
+       virtual double getTime() =0;
+       virtual bool setTime(const double time) =0;
+       virtual std::string toDateString(bool bLocale = false) =0;
+       virtual std::string toTimeString(bool bLocale = false)=0;       
+       virtual std::string toString(bool bLocale = false) =0;
+
+       virtual std::string getTimezoneAbbreviation() =0;
+       virtual long secondsFromUTC() =0;               
+       virtual bool isDST() =0;
+       virtual TZDateProperties getDSTTransition(DSTTransition trans) =0;
+};
+
+typedef DPL::SharedPtr<ITZDate> ITZDatePtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_IDATETIME_H_ */
diff --git a/src/platform/API/TimeUtil/ITimeUtil.h b/src/platform/API/TimeUtil/ITimeUtil.h
new file mode 100755 (executable)
index 0000000..a2bde21
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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 _ABSTRACT_LAYER_ITIMEUTIL_H_
+#define _ABSTRACT_LAYER_ITIMEUTIL_H_
+
+#include <string>
+#include <vector>
+
+#include <dpl/shared_ptr.h>
+#include <Commons/ThreadPool.h>
+#include <Commons/EventReceiver.h>
+#include "EventSetCurrentTZDate.h"
+
+namespace TizenApis {
+namespace Api {
+namespace TimeUtil{
+
+using namespace WrtDeviceApis::Commons;
+
+class ITimeUtil
+{
+    public:
+
+
+       ITimeUtil() {}
+       
+        virtual                     ~ITimeUtil() {}
+
+       virtual void setCurrentTZDate(const TZDateProperties &tzdate) =0;
+       virtual std::string getLocalTimezone( )=0;
+       virtual std::string getUTCTimezone() =0;
+       virtual std::vector<std::string> getAvailableTimezones() =0;
+       virtual std::string getDateFormat(const bool b_shortFormat)=0;
+       virtual std::string getTimeFormat() =0;
+};
+
+typedef DPL::SharedPtr<ITimeUtil> ITimeUtilPtr;
+
+}
+}
+}
+
+#endif /* _ABSTRACT_LAYER_ITIMEUTIL_H_ */
diff --git a/src/platform/API/TimeUtil/TZDateProperties.h b/src/platform/API/TimeUtil/TZDateProperties.h
new file mode 100755 (executable)
index 0000000..e9b4b58
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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_API_TIMEUTIL_TZDATE_PROPERTIES_H_
+#define WRTPLUGINS_API_TIMEUTIL_TZDATE_PROPERTIES_H_
+
+#include <ctime>
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Api {
+namespace TimeUtil {
+       
+struct TZDateProperties
+{
+       long year;
+       long month;
+       long day;
+       long hours;
+       long minutes;
+       long seconds;
+       long milliseconds;
+       std::string timezone;
+       TZDateProperties()
+               : year(0), month(0), day(0), hours(0), minutes(0), seconds(0), milliseconds(0),
+               timezone("")
+       {
+       }
+};
+
+
+typedef DPL::SharedPtr<TZDateProperties> TZDatePropertiesPtr;
+
+} //TimeUtil
+} // Api
+} // TizenApis
+
+#endif //WRTPLUGINS_API_TIMEUTIL_TZDATE_PROPERTIES_H_
\ No newline at end of file
diff --git a/src/platform/API/TimeUtil/TimeUtilFactory.cpp b/src/platform/API/TimeUtil/TimeUtilFactory.cpp
new file mode 100755 (executable)
index 0000000..4354c28
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 "TimeUtilFactory.h"
+#include <TimeUtil/TimeUtil.h>
+#include <TimeUtil/TZDate.h>
+
+namespace TizenApis {
+namespace Api {
+namespace TimeUtil {
+       
+ITimeUtilPtr TimeUtilFactory::createTimeUtilObject() {
+       return ITimeUtilPtr( new Platform::TimeUtil::TimeUtil() );
+}
+
+ITZDatePtr TimeUtilFactory::createTZDateObject(const std::string &timezone) {
+       return ITZDatePtr( new Platform::TimeUtil::TZDate(timezone) );
+}
+
+ITZDatePtr TimeUtilFactory::createTZDateObject(const bool isNotNull) {
+       return ITZDatePtr( new Platform::TimeUtil::TZDate(isNotNull) );
+}
+
+ITZDatePtr TimeUtilFactory::createTZDateObject(const TZDateProperties &properties) {
+       return ITZDatePtr( new Platform::TimeUtil::TZDate(properties) );
+}
+
+TimeUtilFactory& TimeUtilFactory::getInstance() {
+       static TimeUtilFactory theInstance;
+       return theInstance;
+}
+
+}
+}
+}
diff --git a/src/platform/API/TimeUtil/TimeUtilFactory.h b/src/platform/API/TimeUtil/TimeUtilFactory.h
new file mode 100755 (executable)
index 0000000..c467595
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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_API_TIMEUTILFACTORY_H_
+#define WRTPLUGINS_API_TIMEUTILFACTORY_H_
+
+#include <dpl/noncopyable.h>
+#include <string>
+
+#include "ITimeUtil.h"
+#include "ITZDate.h"
+
+namespace TizenApis {
+namespace Api {
+namespace TimeUtil {
+
+class TimeUtilFactory : DPL::Noncopyable
+{
+private:
+    /**
+     * Private constructor to provide singleton
+     */
+    TimeUtilFactory(){;}
+public:
+       ITimeUtilPtr createTimeUtilObject();
+       ITZDatePtr createTZDateObject(const std::string &timezone);
+       ITZDatePtr createTZDateObject(const bool isNotNull = TRUE);
+       ITZDatePtr createTZDateObject(const TZDateProperties &properties);
+               
+       static TimeUtilFactory& getInstance();
+
+};
+
+}
+}
+}
+
+#endif //WRTPLUGINS_API_TIMEUTILFACTORY_H_
+
diff --git a/src/platform/API/TimeUtil/TimezoneProperties.h b/src/platform/API/TimeUtil/TimezoneProperties.h
new file mode 100755 (executable)
index 0000000..7b9aa85
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// 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 _ABSTRACT_LAYER_TIMEZONEPROPERTIES_H_
+#define _ABSTRACT_LAYER_TIMEZONEPROPERTIES_H_
+
+#include <dpl/shared_ptr.h>
+#include <string>
+
+namespace TizenApis {
+namespace Api {
+namespace TimeUtil {
+
+struct TimezoneProperties
+{
+    std::string name;
+    TimezoneProperties() :
+        name("")
+    {
+    }
+};
+
+typedef DPL::SharedPtr<TimezoneProperties> TimezonePropertiesPtr;
+} // TimeUtil
+} // Api
+} // TizenApis
+
+#endif // _ABSTRACT_LAYER_TIMEZONEPROPERTIES_H_
\ No newline at end of file
diff --git a/src/platform/API/TimeUtil/config.cmake b/src/platform/API/TimeUtil/config.cmake
new file mode 100755 (executable)
index 0000000..d452c42
--- /dev/null
@@ -0,0 +1,6 @@
+get_current_path()
+
+set(SRCS_PLATFORM_API_TIMEUTIL
+  ${CURRENT_PATH}/TimeUtilFactory.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/API/config.cmake b/src/platform/API/config.cmake
new file mode 100755 (executable)
index 0000000..a778961
--- /dev/null
@@ -0,0 +1,18 @@
+include_config_file(Filter)
+include_config_file(Calendar)
+include_config_file(Contact)
+include_config_file(Bluetooth)
+include_config_file(Application)
+include_config_file(Messaging)
+include_config_file(Callhistory)
+include_config_file(TimeUtil)
+include_config_file(Systeminfo)
+include_config_file(NFC)
+include_config_file(Filesystem)
+include_config_file(Account)
+include_config_file(Content)
+include_config_file(Power)
+include_config_file(Notification)
+include_config_file(Download)
+include_config_file(NetworkBearerSelection)
+include_config_file(SystemSetting)
diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9ab7b00
--- /dev/null
@@ -0,0 +1,3 @@
+include_config_file(API)
+include_config_file(commons)
+include_config_file(${PLATFORM})
diff --git a/src/platform/Tizen/Application/AppManagerWrapper.cpp b/src/platform/Tizen/Application/AppManagerWrapper.cpp
new file mode 100644 (file)
index 0000000..b833d85
--- /dev/null
@@ -0,0 +1,634 @@
+//
+// 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 "AppManagerWrapper.h"
+
+#include <dpl/log/log.h>
+#include <dpl/singleton_impl.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+
+IMPLEMENT_SINGLETON(TizenApis::Platform::Application::AppManagerWrapper)
+
+namespace TizenApis {
+namespace Platform {
+namespace Application {
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+
+AppManagerPackageInfo::AppManagerPackageInfo(const char *str, AppManagerPackageInfoNameType type) :
+               m_show(false),
+               m_appIdIsSet(false),
+               m_initialized(false)
+{
+       if(str == NULL)
+       {
+               LogDebug("str is NULL");
+               return;
+       }
+
+       if(str[0] == '\0')
+       {
+               LogDebug("str is empty string");
+               return;
+       }
+
+       // PackageName is not used no more.. this function should be modified..
+       if(type == PackageName)
+       {
+               //initializeWithPackageName(str);
+               initializeWithAppId(str);
+       }
+       else if(type == ApplicationId)
+       {
+               initializeWithAppId(str);
+       }
+       else
+       {
+               LogWarning("type is wrong : " << type);
+       }
+}
+
+AppManagerPackageInfo::~AppManagerPackageInfo()
+{
+}
+
+int AppManagerPackageInfo::app_list_cb(const pkgmgr_appinfo_h handle, void *user_data)
+{
+       int ret = 0;
+       char* appid = NULL;
+
+       AppManagerPackageInfo *pkgInfo = (AppManagerPackageInfo *)user_data;
+       
+       ret = pkgmgr_appinfo_get_appid(handle, &appid);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get appid by");
+       }
+       else if (appid != NULL)
+       {
+               pkgInfo->m_appId = appid;
+               pkgInfo->m_appIdIsSet = true;
+       }
+
+       return false;
+}
+
+
+void AppManagerPackageInfo::initializeWithPackageName(const char *packageName)
+{
+       if (m_initialized)
+               return;
+
+       //get AID & No Display value by using package name
+       pkgmgr_pkginfo_h handle;
+       int ret = 0;
+
+       ret = pkgmgr_pkginfo_get_pkginfo(packageName, &handle);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get pkginfo by " << packageName);
+               return;
+       }
+
+       ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, app_list_cb, this);
+
+       ret = pkgmgr_pkginfo_destroy_pkginfo(handle);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get destory pkginfo " << packageName);
+               return;
+       }       
+
+       initializeWithAppId(m_appId.c_str());
+
+}
+
+int AppManagerPackageInfo::category_cb(const char *category, void *user_data)
+{
+       vector<string> *tmp = (vector<string>*)user_data;
+       
+       if (category == NULL)
+               return true;
+       
+       tmp->push_back(category);
+
+       return true;
+}
+
+void AppManagerPackageInfo::initializeWithAppId(const char *appId)
+{
+       if (m_initialized)
+               return;
+       
+       // get package Name, nodisplay by appId
+       pkgmgr_appinfo_h handle;
+       char* pkgName = NULL;
+       bool noDisplay = false;
+       int ret = 0;
+
+       ret = pkgmgr_appinfo_get_appinfo(appId, &handle);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get appinfo by " << appId);
+               return;
+       }
+
+       ret = pkgmgr_appinfo_get_pkgname(handle, &pkgName);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get appinfo by " << appId);
+               return;
+       }
+
+       ret = pkgmgr_appinfo_is_nodisplay(handle, &noDisplay);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get nodisplay " << appId);
+               return;
+       }
+
+       ret = pkgmgr_appinfo_foreach_category(handle, category_cb, &m_categories);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get categories " << m_appId);
+       }
+
+       m_packageName = pkgName;
+       m_appId = appId;
+       m_appIdIsSet = true;
+       m_show = !noDisplay;
+
+       ret = pkgmgr_appinfo_destroy_appinfo(handle);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get destroy appinfo " << appId);
+               return;
+       }       
+
+       char* iconPath = NULL;
+       char* name = NULL;
+       app_info_h app_handle;
+
+       ret = app_manager_get_app_info(appId, &app_handle);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get appinfo by " << appId);
+               return;
+       }
+
+       ret = app_info_get_name(app_handle, &name);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get name by " << appId);
+               return;
+       }
+
+       ret = app_info_get_icon(app_handle, &iconPath);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get icon path by " << appId);
+               return;
+       }
+
+       m_name = name;
+       m_iconPath = iconPath;
+
+       ret = app_info_destroy(app_handle);
+       if (ret < 0)
+       {
+               LogDebug("Fail to destory appinfo");
+               return;
+       }
+
+       char *version = NULL;
+       pkgmgr_pkginfo_h pkg_handle;
+
+       ret = pkgmgr_pkginfo_get_pkginfo(m_packageName.c_str(), &pkg_handle);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get pkginfo");
+               return;
+       }
+
+       ret = pkgmgr_pkginfo_get_version(pkg_handle, &version);
+       if (ret < 0)
+       {
+               LogDebug("Fail to get version");
+               return;
+       }
+
+       m_version = version;
+
+       ret = pkgmgr_pkginfo_destroy_pkginfo(pkg_handle);
+       if (ret < 0)
+       {
+               LogDebug("Fail to destory pkginfo");
+               return;
+       }
+
+       m_initialized = true;
+
+}
+
+bool AppManagerPackageInfo::isValid() const
+{
+       return m_initialized;
+}
+
+string AppManagerPackageInfo::getPackageName()
+{
+       return m_packageName;
+}
+
+string AppManagerPackageInfo::getAppId()
+{
+       return m_appId;
+}
+
+void AppManagerPackageInfo::setAppId(std::string &appId)
+{
+       m_appId = appId;
+       m_appIdIsSet = true;
+}
+
+bool AppManagerPackageInfo::getAppIdIsSet()
+{
+       return m_appIdIsSet;
+}
+
+string AppManagerPackageInfo::getName()
+{
+       return m_name;
+}
+
+string AppManagerPackageInfo::getIconPath()
+{
+       return m_iconPath;
+}
+
+string AppManagerPackageInfo::getVersion()
+{
+       return m_version;
+}
+
+bool AppManagerPackageInfo::getShow()
+{
+       return m_show;
+}
+
+vector<string> AppManagerPackageInfo::getCategories()
+{
+       return m_categories;    
+}
+
+InstalledApplicationMap::InstalledApplicationMap()
+{
+       int result = app_manager_foreach_app_info(foreachAppInstalledCallback, &m_map);
+       if(result != APP_MANAGER_ERROR_NONE)
+       {
+               ThrowMsg(PlatformException, "Error while app_manager_foreach_app_installed");
+       }
+}
+
+InstalledApplicationMap::~InstalledApplicationMap()
+{
+}
+
+string InstalledApplicationMap::getAppId(string &packageName)
+{
+       AppManagerPackageInfoMap::iterator iter = m_map.find(packageName);
+       if(iter == m_map.end())
+       {
+               LogDebug("No package name : " << packageName);
+               return "";
+       }
+
+       return iter->second->getAppId();
+}
+
+void InstalledApplicationMap::remove(string &appId)
+{
+       AppManagerPackageInfoMap::iterator iter = m_map.find(appId);
+       if(iter == m_map.end())
+       {
+               LogDebug("No package name : " << appId);
+               return;
+       }
+
+       m_map.erase(iter);
+}
+
+void InstalledApplicationMap::add(string &packageName, string &appId)
+{
+       AppManagerPackageInfoPtr packageInfo =
+                       AppManagerPackageInfoPtr(new AppManagerPackageInfo(packageName.c_str(), AppManagerPackageInfo::PackageName));
+
+       if(!packageInfo->getAppIdIsSet())
+       {
+               packageInfo->setAppId(appId);
+       }
+       else if(packageInfo->getAppId() != packageName)
+       {
+               LogWarning("app id from ail (" << packageInfo->getAppId() << ") is not match with given app id (" << appId << ")");
+               packageInfo->setAppId(appId);
+       }
+
+       m_map.insert(AppManagerPackageInfoPair(appId, packageInfo));
+}
+
+AppManagerPackageInfoPtr InstalledApplicationMap::getPackageInfo(string &packageName)
+{
+       return m_map.at(packageName);
+}
+
+
+AppManagerPackageInfoArrayPtr InstalledApplicationMap::getPackageInfoList()
+{
+       AppManagerPackageInfoArrayPtr packageInfos =
+                       AppManagerPackageInfoArrayPtr(new AppManagerPackageInfoArray());
+
+       AppManagerPackageInfoMap::iterator iter = m_map.begin();
+       for(; iter != m_map.end(); iter++)
+       {
+               packageInfos->push_back(iter->second);
+       }
+
+       return packageInfos;
+}
+
+bool InstalledApplicationMap::foreachAppInstalledCallback(app_info_h app_info, void *user_data)
+{
+       AppManagerPackageInfoMap *map = (AppManagerPackageInfoMap *)user_data;
+
+       if (app_info == NULL)
+               return true;
+
+       char *appid = NULL;
+       int result = app_info_get_app_id(app_info, &appid);
+       if ((result != APP_MANAGER_ERROR_NONE) || (appid == NULL)) {
+               return true;
+       }
+
+       AppManagerPackageInfoPtr packageInfo =
+                       AppManagerPackageInfoPtr(new AppManagerPackageInfo(appid, AppManagerPackageInfo::ApplicationId));
+
+       if(!packageInfo->isValid())
+               return true;
+
+       map->insert(AppManagerPackageInfoPair(packageInfo->getAppId(), packageInfo));
+
+       return true;
+}
+
+
+AppManagerWrapper::AppManagerWrapper() :
+               m_registeredCallback(false),
+               m_applicationMap(NULL),
+               m_watchIdAcc(0)
+{
+}
+
+AppManagerWrapper::~AppManagerWrapper()
+{
+       if(m_registeredCallback)
+       {
+               unregisterAppListChangedCallbacks();
+       }
+}
+
+void AppManagerWrapper::registerAppListChangedCallbacks(IAppManagerAppListChangedCallbacks *callbacks)
+{
+       if(callbacks == NULL)
+       {
+               LogWarning("Parameter is NULL.");
+               return;
+       }
+
+       if(!m_registeredCallback)
+       {
+               registerAppListChangedCallbacks();
+       }
+
+       m_callbacks.insert(callbacks);
+}
+
+void AppManagerWrapper::unregisterAppListChangedCallbacks(IAppManagerAppListChangedCallbacks *callbacks)
+{
+       if(callbacks == NULL)
+       {
+               LogWarning("Parameter is NULL.");
+               return;
+       }
+
+       if(m_callbacks.size() == 0)
+       {
+               LogWarning("No callbacks are registered.");
+               return;
+       }
+
+       AppListChangedCallbacksSet::iterator iter = m_callbacks.find(callbacks);
+       if(iter == m_callbacks.end())
+       {
+               LogWarning("Callbacks " << callbacks << " are not registered.");
+               return;
+       }
+
+       m_callbacks.erase(iter);
+
+       if(m_callbacks.size() == 0)
+       {
+               unregisterAppListChangedCallbacks();
+       }
+}
+
+AppManagerPackageInfoArrayPtr AppManagerWrapper::getInstalledAppList()
+{
+       LogDebug("called");
+
+       InstalledApplicationMapPtr applicationMap = InstalledApplicationMapPtr(NULL);
+
+       if(m_applicationMap != NULL)
+               applicationMap = m_applicationMap;
+       else
+               applicationMap = InstalledApplicationMapPtr(new InstalledApplicationMap());
+
+       return applicationMap->getPackageInfoList();
+}
+
+long AppManagerWrapper::getWatchIdAndInc()
+{
+       return ++m_watchIdAcc;
+}
+
+void AppManagerWrapper::appListChangedCallback(app_manger_event_type_e event_type,
+                                               const char *package,
+                                               void *user_data)
+{
+       if(user_data == NULL)
+       {
+               LogWarning("app_manager listener passed NULL user_data");
+               return;
+       }
+
+       AppManagerWrapper *appManager = (AppManagerWrapper *)user_data;
+
+       appManager->appListChangedCallback(event_type, package);
+}
+
+void AppManagerWrapper::appListChangedCallback(app_manger_event_type_e event_type,
+                                               const char *package)
+{
+       if(package == NULL)
+       {
+               LogWarning("app_manager listener gave a NULL package name.");
+               return;
+       }
+
+       if(m_applicationMap == NULL)
+       {
+               LogError("application map did not set");
+               return;
+       }
+
+       AppManagerPackageInfoPtr packageInfo;
+
+       if (event_type != APP_MANAGER_EVENT_UNINSTALLED) {
+               packageInfo = AppManagerPackageInfoPtr(new AppManagerPackageInfo(package, AppManagerPackageInfo::PackageName));
+       } else {
+               std::string tmpStr = std::string(package);
+               packageInfo = m_applicationMap->getPackageInfo(tmpStr);
+       }
+
+       if(!packageInfo->isValid())
+       {
+               LogWarning("package " << package << " is not exists.");
+               return;
+       }
+
+       string packageName = packageInfo->getPackageName();
+       string appId;
+
+       if(!packageInfo->getAppIdIsSet())
+       {
+               appId = m_applicationMap->getAppId(packageName);
+
+               if(appId.empty())
+               {
+                       LogWarning("No app id for package name : " << packageName);
+                       return;
+               }
+
+               packageInfo->setAppId(appId);
+       }
+       else
+       {
+               appId = packageInfo->getAppId();
+       }
+
+       switch(event_type)
+       {
+       case APP_MANAGER_EVENT_INSTALLED:
+               appListAppInstalled(packageInfo);
+               m_applicationMap->add(packageName, appId);
+               break;
+       case APP_MANAGER_EVENT_UNINSTALLED:
+               appListAppUninstalled(packageInfo);
+               m_applicationMap->remove(appId);
+               break;
+       case APP_MANAGER_EVENT_UPDATED:
+               appListAppUpdated(packageInfo);
+               break;
+       default:
+               LogWarning("app_manager listener gave wrong event_type : " << event_type);
+               break;
+       }
+}
+
+void AppManagerWrapper::appListAppInstalled(AppManagerPackageInfoPtr &packageInfo)
+{
+       LogDebug("app installed : " << packageInfo->getPackageName());
+
+       AppListChangedCallbacksSet::iterator iter = m_callbacks.begin();
+       for(; iter != m_callbacks.end(); iter++)
+       {
+               (*iter)->onAppManagerEventInstalled(packageInfo);
+       }
+}
+
+void AppManagerWrapper::appListAppUninstalled(AppManagerPackageInfoPtr &packageInfo)
+{
+       LogDebug("app uninstalled : " << packageInfo->getPackageName());
+
+       AppListChangedCallbacksSet::iterator iter = m_callbacks.begin();
+       for(; iter != m_callbacks.end(); iter++)
+       {
+               (*iter)->onAppManagerEventUninstalled(packageInfo);
+       }
+}
+
+void AppManagerWrapper::appListAppUpdated(AppManagerPackageInfoPtr &packageInfo)
+{
+       LogDebug("app updated : " << packageInfo->getPackageName());
+
+       AppListChangedCallbacksSet::iterator iter = m_callbacks.begin();
+       for(; iter != m_callbacks.end(); iter++)
+       {
+               (*iter)->onAppManagerEventUpdated(packageInfo);
+       }
+}
+
+void AppManagerWrapper::registerAppListChangedCallbacks()
+{
+       if(m_registeredCallback)
+       {
+               LogWarning("Callback already registered.");
+               return;
+       }
+
+       // AppManagerWrapper will be used as a singleton object,
+       // so this pointer of it can be passed as a parameter of a async function.
+       int result = app_manager_set_app_list_changed_cb(appListChangedCallback, this);
+       if (result != APP_MANAGER_ERROR_NONE)
+       {
+               LogWarning("app_manager_set_app_list_changed_cb() returns APP_MANAGER_ERROR_INVALID_PARAMETER");
+
+               ThrowMsg(InvalidArgumentException, "Error while registering listener to app_manager");
+       }
+
+       m_registeredCallback = true;
+       m_applicationMap = InstalledApplicationMapPtr(new InstalledApplicationMap());
+}
+
+void AppManagerWrapper::unregisterAppListChangedCallbacks()
+{
+       if(!m_registeredCallback)
+       {
+               LogWarning("Callback already unregistered.");
+               return;
+       }
+
+       app_manager_unset_app_list_changed_cb();
+
+       m_registeredCallback = false;
+       m_applicationMap = InstalledApplicationMapPtr(NULL);
+}
+
+} // Application
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Application/AppManagerWrapper.h b/src/platform/Tizen/Application/AppManagerWrapper.h
new file mode 100644 (file)
index 0000000..f49fea7
--- /dev/null
@@ -0,0 +1,175 @@
+//
+// 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_APPLICATION_APP_MANAGER_WRAPPER_H_
+#define TIZENAPIS_PLATFORM_APPLICATION_APP_MANAGER_WRAPPER_H_
+
+#include <string>
+#include <map>
+#include <set>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+
+#include <app_manager.h>
+#include <package-manager.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Application {
+
+class AppManagerPackageInfo
+{
+public:
+       enum AppManagerPackageInfoNameType
+       {
+               PackageName,
+               ApplicationId
+       };
+
+       AppManagerPackageInfo(const char *str, AppManagerPackageInfoNameType type);
+       virtual ~AppManagerPackageInfo();
+
+       bool isValid() const;
+       std::string getPackageName();
+
+       std::string getAppId();
+       void setAppId(std::string &appId);
+       bool getAppIdIsSet();
+
+       std::string getName();
+       std::string getIconPath();
+       std::string getVersion();
+       bool getShow();
+
+       std::vector<std::string> getCategories();
+
+private:
+       void initializeWithPackageName(const char *packageName);
+       void initializeWithAppId(const char *appId);
+
+       static int app_list_cb(const pkgmgr_appinfo_h handle, void *user_data);
+
+       std::string m_packageName;
+
+       std::string m_appId;
+       std::string m_name;
+       std::string m_iconPath;
+       std::string m_version;
+       bool m_show;
+       std::vector<std::string> m_categories;
+
+       bool m_appIdIsSet;
+       bool m_initialized;
+
+       // callback for pkgmgrinfo_appinfo_get_category_list_foreach
+       static int category_cb(const char *category, void *user_data);
+       
+};
+typedef DPL::SharedPtr<AppManagerPackageInfo> AppManagerPackageInfoPtr;
+typedef std::vector<AppManagerPackageInfoPtr> AppManagerPackageInfoArray;
+typedef DPL::SharedPtr<AppManagerPackageInfoArray> AppManagerPackageInfoArrayPtr;
+
+class InstalledApplicationMap
+{
+public:
+       InstalledApplicationMap();
+       virtual ~InstalledApplicationMap();
+
+       std::string getAppId(std::string &packageName);
+       void remove(std::string &packageName);
+       void add(std::string &packageName, std::string &appId);
+       AppManagerPackageInfoPtr getPackageInfo(std::string &packageName);      
+
+       AppManagerPackageInfoArrayPtr getPackageInfoList();
+
+private:
+       // first is package name
+       typedef std::map<std::string, AppManagerPackageInfoPtr> AppManagerPackageInfoMap;
+       typedef std::pair<std::string, AppManagerPackageInfoPtr> AppManagerPackageInfoPair;
+       AppManagerPackageInfoMap m_map;
+
+       // callback for app_manager_foreach_app_installed
+       static bool foreachAppInstalledCallback(app_info_h app_info, void *user_data);
+};
+typedef DPL::SharedPtr<InstalledApplicationMap> InstalledApplicationMapPtr;
+
+class IAppManagerAppListChangedCallbacks
+{
+public:
+    friend class AppManagerWrapper;
+
+       IAppManagerAppListChangedCallbacks() {}
+       ~IAppManagerAppListChangedCallbacks() {}
+
+protected:
+       virtual void onAppManagerEventInstalled(AppManagerPackageInfoPtr &pkgInfo) = 0;
+       virtual void onAppManagerEventUninstalled(AppManagerPackageInfoPtr &pkgInfo) = 0;
+       virtual void onAppManagerEventUpdated(AppManagerPackageInfoPtr &pkgInfo) = 0;
+};
+
+class AppManagerWrapper
+{
+public:
+       AppManagerWrapper();
+       virtual ~AppManagerWrapper();
+
+       // Can throw InvalidArgumentException or PlatformException
+       void registerAppListChangedCallbacks(IAppManagerAppListChangedCallbacks *callbacks);
+
+       // No throws
+       void unregisterAppListChangedCallbacks(IAppManagerAppListChangedCallbacks *callbacks);
+
+       // Can throw PlatformException
+       AppManagerPackageInfoArrayPtr getInstalledAppList();
+
+       long getWatchIdAndInc();
+
+private:
+       // callback for app_manager_set_app_list_changed_cb
+       static void appListChangedCallback(app_manger_event_type_e event_type,
+                                          const char *package,
+                                          void *user_data);
+
+       void appListChangedCallback(app_manger_event_type_e event_type,
+                                   const char *package);
+
+       void appListAppInstalled(AppManagerPackageInfoPtr &packageInfo);
+       void appListAppUninstalled(AppManagerPackageInfoPtr &packageInfo);
+       void appListAppUpdated(AppManagerPackageInfoPtr &packageInfo);
+
+       void registerAppListChangedCallbacks();
+       void unregisterAppListChangedCallbacks();
+
+       typedef std::set<IAppManagerAppListChangedCallbacks *> AppListChangedCallbacksSet;
+       AppListChangedCallbacksSet m_callbacks;
+       bool m_registeredCallback;
+
+       InstalledApplicationMapPtr m_applicationMap;
+
+       long m_watchIdAcc;
+
+public:
+       friend class DPL::Singleton<AppManagerWrapper>;
+};
+
+typedef DPL::Singleton<AppManagerWrapper> AppManagerWrapperSingleton;
+
+} // Application
+} // Platform
+} // TizenApis
+
+#endif // TIZENAPIS_PLATFORM_APPLICATION_APP_MANAGER_WRAPPER_H_
diff --git a/src/platform/Tizen/Application/Application.cpp b/src/platform/Tizen/Application/Application.cpp
new file mode 100755 (executable)
index 0000000..e59ad46
--- /dev/null
@@ -0,0 +1,159 @@
+//
+// 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 "Application.h"
+
+#include <bundle.h>
+#include <app.h>
+#include <app_service.h>
+
+#include <API/Application/ApplicationControlData.h>
+#include <API/Application/ApplicationControl.h>
+
+#include "ApplicationManager.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Application {        
+
+using namespace Api::Application;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+extern "C" int service_create_event(bundle *data, struct service_s **service);
+       
+Application::Application()
+{
+}
+
+Application::~Application()
+{
+}
+
+std::string Application::getContextId() const
+{
+       return m_contextId;
+}
+
+void Application::setContextId(const std::string &id)
+{
+       m_contextId = id;
+}
+
+ApplicationInformationPtr Application::getAppInfo() const
+{
+       return m_appInfo;
+}
+
+void Application::setAppInfo(ApplicationInformationPtr& appInfo)
+{
+       m_appInfo = appInfo;
+}
+
+void Application::getRequestedAppControl(const EventApplicationGetRequestedAppControlPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               int ret = 0;
+
+               std::string bundle_str = event->getEncodedBundle();
+               LogDebug("bundle str : " << bundle_str);
+
+               service_h service = NULL;
+               char* tmpStr = NULL;
+
+               bundle *request_bundle = bundle_decode((bundle_raw*)bundle_str.c_str(), bundle_str.length());
+               ret = service_create_event(request_bundle, &service);
+               if(ret != SERVICE_ERROR_NONE)
+               {
+                       LogError("Fail to create event");
+                       event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+                       bundle_free(request_bundle);
+                       return;
+               }
+               bundle_free(request_bundle);
+
+               ApplicationControlPtr appControl(new ApplicationControl());
+               appControl->setService_h(service);
+
+               ret = service_get_operation(service, &tmpStr);
+               if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
+               {
+                       LogDebug(" operation : " << tmpStr);
+                       appControl->setOperation(tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+
+               ret = service_get_uri(service, &tmpStr);
+               if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
+               {
+                       LogDebug(" uri       : " << tmpStr);
+                       appControl->setUri(tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+
+               ret = service_get_mime(service, &tmpStr);
+               if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
+               {
+                       LogDebug(" mime      : " << tmpStr);
+                       appControl->setMime(tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+
+               ret = service_get_category(service, &tmpStr);
+               if(ret == SERVICE_ERROR_NONE && tmpStr != NULL)
+               {
+                       LogDebug(" category      : " << tmpStr);
+                       appControl->setCategory(tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+
+               std::vector<ApplicationControlDataPtr> appControlDataArray;
+               ret = service_foreach_extra_data(service, TizenApis::Platform::Application::ApplicationManager::service_extra_data_callback, &appControlDataArray);
+               if (ret != SERVICE_ERROR_NONE)
+               {
+                       LogError("service_foreach_extra_data fail");
+                       event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+               }
+               else
+               {
+                       appControl->setAppControlDataArray(appControlDataArray);
+               }
+               
+               RequestedApplicationControlPtr appCtrMgr(new RequestedApplicationControl());
+               appCtrMgr->setAppControl(appControl);
+
+               event->setRequestedAppControl(appCtrMgr);               
+               
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on getAppControl : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+
+}
+}
+}
diff --git a/src/platform/Tizen/Application/Application.h b/src/platform/Tizen/Application/Application.h
new file mode 100644 (file)
index 0000000..6cce857
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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_H_
+#define TIZENAPIS_API_APPLICATION_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <API/Application/ApplicationInformation.h>
+#include <API/Application/EventApplicationGetRequestedAppControl.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Application {
+
+class Application;
+typedef DPL::SharedPtr<Application> ApplicationPtr;
+
+class Application
+{
+  public:
+    Application();
+    ~Application();
+
+       std::string getContextId() const;
+       void setContextId(const std::string &id);
+       ApplicationInformationPtr getAppInfo() const;
+       void setAppInfo(ApplicationInformationPtr &appInfo);
+
+       void getRequestedAppControl(const EventApplicationGetRequestedAppControlPtr& event);
+
+  private:
+       ApplicationInformationPtr m_appInfo;
+    std::string        m_contextId;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Application/ApplicationManager.cpp b/src/platform/Tizen/Application/ApplicationManager.cpp
new file mode 100644 (file)
index 0000000..a8f1441
--- /dev/null
@@ -0,0 +1,1924 @@
+//
+// 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 "ApplicationManager.h"
+
+#include <cassert>
+#include <sstream>
+#include <Commons/Exception.h>
+#include <Commons/EventReceiver.h>
+#include <Commons/Regex.h>
+
+#include <API/Application/ApplicationInformation.h>
+#include <API/Application/ApplicationContext.h>
+#include <API/Application/ApplicationControlData.h>
+#include <API/Application/ApplicationControl.h>
+#include <API/Application/ApplicationCert.h>
+#include "Application.h"
+
+#include <app.h>
+
+#include <dpl/log/log.h>
+
+// to get package name by appid
+#include <app_info.h>
+#include <app_manager.h>
+
+// To get cert information from package
+#include <package_manager.h>
+#include <package_info.h>
+
+// To get app size and installed time
+#include <pkgmgr-info.h>
+
+// To get ppid
+#include <unistd.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Application {
+
+using namespace Api::Application;
+using namespace DPL;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace Platform;
+
+namespace {
+
+       typedef KeyMultiMap<ApplicationManager*, LaunchAppControlPendingEvent> LaunchAppControlPendingEventMap;
+       static LaunchAppControlPendingEventMap gLaunchAppControlPendingEventMap;
+
+       // Callback from 'app_manager_set_app_context_event_cb'
+       // Used by 'kill'
+       static void app_manager_app_context_event_callback(app_context_h app_context,
+                       app_context_event_e event, void *user_data)
+       {
+               LogDebug("called");
+               int ret = 0;
+
+               if(event != APP_CONTEXT_EVENT_TERMINATED)
+                       return;
+
+               int pid = 0;
+
+               ret = app_context_get_pid(app_context, &pid);
+               if(ret != APP_MANAGER_ERROR_NONE)
+               {
+                       LogDebug("Fail to get pid of terminated app (" << ret << ")");
+                       return;
+               }
+
+               ApplicationManager* appManager = (ApplicationManager*)(user_data);
+               appManager->invokeManualAnswerKill(pid);
+       }
+
+       // get package name by id
+       static char* getPackageById(const char* appId)
+       {
+               app_info_h handle;
+               char* pkgName;
+               int ret = 0;
+               
+               ret = app_manager_get_app_info(appId, &handle);
+               if (ret < 0)
+               {
+                       LogDebug("Fail to get appinfo by " << appId);
+                       return NULL;
+               }
+
+               ret = app_info_get_package(handle, &pkgName);
+               if (ret < 0)
+               {
+                       LogDebug("Fail to get pkgName by " << appId);
+                       return NULL;
+               }
+
+               ret = app_info_destroy(handle);
+               if (ret < 0)
+               {
+                       LogDebug("Fail to get destory appinfo");
+                       return NULL;
+               }
+
+               return pkgName;
+       }
+
+       static void addPackageData(const char* package, ApplicationInformationPtr appinfo)
+       {
+               int result = 0;
+               int total_size = 0;
+               int installed_time = 0;
+               pkgmgrinfo_pkginfo_h handle;
+
+               result = pkgmgrinfo_pkginfo_get_pkginfo(package, &handle);
+               if (result != PMINFO_R_OK) {
+                       LogDebug("Fail to create pkginfo handle");
+               }
+
+               result = pkgmgrinfo_pkginfo_get_total_size(handle, &total_size);
+               if (result == PMINFO_R_OK) {
+                       appinfo->setInstallSize(total_size);
+               }
+
+               result = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time);
+               if (result == PMINFO_R_OK) {
+                       appinfo->setInstallDate(installed_time);
+               }
+
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       }
+
+       // Callback of 'app_manager_foreach_app_context'
+       // Used by 'getAppsContext'
+       static bool app_manager_app_context_callback(app_context_h app_context, void *user_data)
+       {
+               int ret = 0;
+
+               char *app_id = NULL;
+               int pid;
+
+               std::string contextId;
+
+               if (user_data == NULL)
+               {
+                       return false;
+               }
+
+               ret = app_context_get_app_id(app_context, &app_id);
+               if((ret != APP_MANAGER_ERROR_NONE) || (app_id == NULL))
+               {
+                       LogDebug("app_context_get_app_id error (" << ret << ")");
+                       return false;
+               }
+
+               ret = app_context_get_pid(app_context, &pid);
+               if(ret != APP_MANAGER_ERROR_NONE)
+               {
+                       LogDebug("app_context_get_app_id error (" << ret << ")");
+                       if (app_id)
+                               free(app_id);
+                       return false;
+               }
+
+               std::stringstream sstream;
+               sstream << pid;
+               contextId = sstream.str();
+
+               ApplicationContextPtr appContext(new ApplicationContext());
+               appContext->setAppId(app_id);
+               appContext->setContextId(contextId);
+
+               ApplicationContextArray* appContextArray = (ApplicationContextArray*)user_data;
+
+               appContextArray->push_back(appContext);
+
+               if (app_id)
+                       free(app_id);
+
+               return true;
+       }
+
+       // Callback of 'service_send_launch_request'
+       // Used by 'launchAppControl'
+       static void service_reply_callback(service_h request, service_h reply,
+                       service_result_e result, void *user_data)
+       {
+               LogDebug("appControlResultCallback called");
+               LaunchAppControlPendingEventMap::DataKeyType key =
+                               (LaunchAppControlPendingEventMap::DataKeyType)user_data;
+
+               LaunchAppControlPendingEvent *pendingEvent = gLaunchAppControlPendingEventMap.getData(key);
+               if(pendingEvent != NULL)
+               {
+                       ApplicationManager *application = (ApplicationManager *)pendingEvent->getThisObject();
+                       EventApplicationLaunchAppControlReplyPtr event = pendingEvent->getEvent();
+                       application->invokeManualAnswerLaunchAppControl(request, reply, result, event);
+
+                       delete pendingEvent;
+                       pendingEvent = NULL;
+                       user_data = NULL;
+
+                       gLaunchAppControlPendingEventMap.eraseData(key);
+               }
+       }
+
+       // Callback from 'service_foreach_extra_data'
+       // Used by 'getAppControl' && 'launchAppControl Reply'
+
+       static int installAppResultCallback(int req_id, const char *pkg_type,
+                       const char *pkg_name, const char *key, const char *val,
+                       const void *pmsg, void *priv_data)
+       {
+
+
+               LogDebug("installAppResultCallback called with req_id: [" << req_id
+                                 << "] pkg_type: [" << pkg_type  << "] pkg_name: [" << pkg_name << "] key: [" << key << "] val: [" << val << "]");
+
+               if (key && strncmp(key, "end", strlen("end")) == 0) {
+                       int result = EXIT_SUCCESS;
+                       if (strncasecmp(val, "ok", strlen("ok")) != 0) {
+                               result = EXIT_FAILURE;  //error_code
+                       }
+
+                       if(priv_data != NULL) {
+                               ApplicationInstallPendingEvent *pendingEvent = (ApplicationInstallPendingEvent *)priv_data;
+                               ApplicationManager *application = (ApplicationManager *)pendingEvent->getThisObject();
+                               Api::Application::EventApplicationInstallPtr event = pendingEvent->getEvent();
+                               application->installAppAnswer(req_id,pkg_type,pkg_name,key,val,pmsg,result,event);
+
+                               delete pendingEvent;
+                               pendingEvent = NULL;
+                               priv_data = NULL;
+                       }
+               }
+
+               return 0;
+       }
+
+       static int isAppInstalled(char *pkgname)
+       {
+               int ret;
+               char *appName;
+
+               ret = app_manager_get_app_name(pkgname, &appName);
+
+               free(appName);
+
+               if(ret != APP_MANAGER_ERROR_NONE)
+                       return 0;
+
+               return 1;
+       }
+
+       // Callback from 'service_foreach_app_matched'
+       // Used by 'findAppControl'
+       static bool service_app_matched_callback(service_h service, const char *appid, void *user_data)
+       {
+               if(appid == NULL)
+               {
+                       LogWarning("appid is NULL");
+                       return false;
+               }
+
+               AppManagerPackageInfoPtr packageInfo =
+                               AppManagerPackageInfoPtr(new AppManagerPackageInfo(appid, AppManagerPackageInfo::ApplicationId));
+
+               ApplicationInformationPtr appInfo(new ApplicationInformation());
+
+               appInfo->setAppId(packageInfo->getAppId());
+               appInfo->setName(packageInfo->getName());
+               appInfo->setIconPath(packageInfo->getIconPath());
+               appInfo->setVersion(packageInfo->getVersion());
+               appInfo->setShow(packageInfo->getShow());
+               appInfo->setCategories(packageInfo->getCategories());
+
+               addPackageData(packageInfo->getPackageName().c_str(), appInfo);
+
+               ApplicationInformationArray *appInfos = (ApplicationInformationArray *)user_data;
+               appInfos->push_back(appInfo);
+
+               return true;
+       }
+
+
+       static bool package_cert_cb(package_info_h handle, package_cert_type_e cert_type, const char *cert_value, void *user_data)
+       {
+               ApplicationCertPtr cert(new ApplicationCert());
+               const char* certName = NULL;
+               
+               switch(cert_type) {
+               case PACKAGE_INFO_AUTHOR_ROOT_CERT:
+                       certName = "AUTHOR_ROOT";
+                       break;
+               case PACKAGE_INFO_AUTHOR_INTERMEDIATE_CERT:
+                       certName = "AUTHOR_INTERMEDIATE";
+                       break;
+               case PACKAGE_INFO_AUTHOR_SIGNER_CERT:
+                       certName = "AUTHOR_SIGNER";
+                       break;
+               case PACKAGE_INFO_DISTRIBUTOR_ROOT_CERT:
+                       certName = "DISTRIBUTOR_ROOT";
+                       break;
+               case PACKAGE_INFO_DISTRIBUTOR_INTERMEDIATE_CERT:
+                       certName = "DISTRIBUTOR_INTERMEDIATE";
+                       break;
+               case PACKAGE_INFO_DISTRIBUTOR_SIGNER_CERT:
+                       certName = "DISTRIBUTOR_SIGNER";
+                       break;
+               case PACKAGE_INFO_DISTRIBUTOR2_ROOT_CERT:
+                       certName = "DISTRIBUTOR2_ROOT";
+                       break;
+               case PACKAGE_INFO_DISTRIBUTOR2_INTERMEDIATE_CERT:
+                       certName = "DISTRIBUTOR2_INTERMEDIATE";
+                       break;
+               case PACKAGE_INFO_DISTRIBUTOR2_SIGNER_CERT:
+                       certName = "DISTRIBUTOR2_SIGNER";
+                       break;
+               default:
+                       LogDebug("Unknow Cert type!!!");
+                       break;
+               }
+               
+               cert->setType(certName);
+               cert->setValue(cert_value);
+
+               ApplicationCertArray *certs = (ApplicationCertArray *)user_data;
+               certs->push_back(cert);
+
+               return true;
+       }
+
+       
+       static int get_current_app_id(char** app_id)
+       {
+               LogDebug("get_current_app_id enter");
+               int parent_pid = getppid();
+               LogDebug("parent pid : " << parent_pid);
+       
+               int ret = app_manager_get_app_id(parent_pid, app_id);
+       
+               if ((ret != APP_MANAGER_ERROR_NONE) || (app_id == NULL))
+               {
+                       LogDebug("Cannot get app id from pid : " << parent_pid);
+               }
+               else
+               {
+                       LogDebug("appid : " << *app_id);
+               }
+       
+               return ret; 
+       }
+
+       
+}
+
+ApplicationManager::ApplicationManager() :
+       m_initialized(false)
+{
+       
+}
+
+ApplicationManager::~ApplicationManager() 
+{
+       if(m_installedApplicationsEmitters.size() != 0)
+       {
+               AppManagerWrapperSingleton::Instance().unregisterAppListChangedCallbacks(this);
+               WatchIdMap::iterator iter = m_watchIdMap.begin();
+               for(; iter != m_watchIdMap.end(); iter++)
+               {
+                       m_installedApplicationsEmitters.detach(iter->second);
+               }
+       }
+
+       LaunchAppControlPendingEventMap::DataPtrListType dataPtrList =
+                       gLaunchAppControlPendingEventMap.getDataPtrList(this);
+
+       LaunchAppControlPendingEventMap::DataPtrListType::iterator iter = dataPtrList.begin();
+       for(; iter != dataPtrList.end(); iter++)
+       {
+               delete *iter;
+       }
+
+       gLaunchAppControlPendingEventMap.eraseKey(this);
+}
+
+void ApplicationManager::getCurrentApplication(const EventApplicationGetCurrAppPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationGetCurrApp>::PostRequest(event);
+}
+
+void ApplicationManager::launch(const EventApplicationLaunchPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationLaunch>::PostRequest(event);
+}
+
+void ApplicationManager::kill(const EventApplicationKillPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationKill>::PostRequest(event);
+}
+
+void ApplicationManager::launchAppControl(const EventApplicationLaunchAppControlPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventApplicationLaunchAppControlReplyPtr eventReply = event->getEventReply();
+       if(eventReply != NULL)
+               EventRequestReceiver<EventApplicationLaunchAppControlReply>::PostRequest(eventReply);
+
+       EventRequestReceiver<EventApplicationLaunchAppControl>::PostRequest(event);
+}
+
+void ApplicationManager::findAppControl(const EventApplicationFindAppControlPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationFindAppControl>::PostRequest(event);
+}
+
+void ApplicationManager::getAppsContext(const EventApplicationGetAppsContextPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationGetAppsContext>::PostRequest(event);
+}
+
+void ApplicationManager::getAppContext(const EventApplicationGetAppContextPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationGetAppContext>::PostRequest(event);
+}
+
+void ApplicationManager::getAppsInfo(const EventApplicationGetAppsInfoPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationGetAppsInfo>::PostRequest(event);
+}
+
+void ApplicationManager::getAppInfo(const EventApplicationGetAppInfoPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationGetAppInfo>::PostRequest(event);
+}
+
+void ApplicationManager::addAppInfoEventListener(const EventApplicationAddAppInfoEventListenerPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationAddAppInfoEventListener>::PostRequest(event);
+}
+
+void ApplicationManager::removeAppInfoEventListener(const EventApplicationRemoveAppInfoEventListenerPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationRemoveAppInfoEventListener>::PostRequest(event);
+}
+
+void ApplicationManager::install(const EventApplicationInstallPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationInstall>::PostRequest(event);
+}
+
+void ApplicationManager::uninstall(const EventApplicationInstallPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationInstall>::PostRequest(event);
+}
+
+void ApplicationManager::update(const EventApplicationInstallPtr& event)
+{
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationInstall>::PostRequest(event);
+}
+
+void ApplicationManager::getAppCerts(const EventApplicationGetAppCertsPtr& event)
+{
+       LogError("ApplicationManager::getAppCerts");
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventApplicationGetAppCerts>::PostRequest(event);
+}
+
+
+void ApplicationManager::invokeManualAnswerLaunchAppControl(service_h request, service_h reply,
+               service_result_e result,
+               Api::Application::EventApplicationLaunchAppControlReplyPtr &event)
+{
+       if (event == NULL) {
+               return;
+       }
+
+       if(result == SERVICE_RESULT_SUCCEEDED)
+       {
+               LogDebug("SERVICE_RESULT_SUCCEEDED in serviceResultCallback");
+
+               // create new service object to store result.
+               ApplicationControlDataArrayPtr appControlDataArray(new ApplicationControlDataArray());
+
+               int result = service_foreach_extra_data(reply, service_extra_data_callback, appControlDataArray.Get());
+               if( result == SERVICE_ERROR_NONE)
+               {
+                       event->setAppControlDataArray(appControlDataArray);
+                       LogDebug("service_foreach_extra_data() success");
+               }
+               else
+               {
+                       LogDebug("service_foreach_extra_data() failed");
+                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+               }
+       }
+       else if(result == SERVICE_RESULT_FAILED || result == SERVICE_RESULT_CANCELED)
+       {
+               LogDebug("SERVICE_RESULT_FAILED in serviceResultCallback : " <<result);
+               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+       }
+
+       EventRequestReceiver<EventApplicationLaunchAppControlReply>::ManualAnswer(event);
+}
+
+void ApplicationManager::invokeManualAnswerKill(int pid)
+{
+       DPL::Mutex::ScopedLock lock(&m_killMapLock);
+
+       std::map<int, EventApplicationKillPtr>::iterator it = m_killEventMap.find(pid);
+       if (it == m_killEventMap.end())
+               return;
+
+       EventApplicationKillPtr event = it->second;
+       m_killEventMap.erase(it);
+
+       LogDebug("Calling kill success callback for pid : " << pid);
+
+       EventRequestReceiver<EventApplicationKill>::ManualAnswer(event);
+}
+
+void ApplicationManager::installAppAnswer(int req_id,
+                                                                  const char* pkg_type,
+                                                                  const char* pkg_name,
+                                                                  const char* key,
+                                                                  const char* val,
+                                                                  const void* pmsg,
+                                                                  int result,
+                                                                  Api::Application::EventApplicationInstallPtr &event)
+{
+       if (event == NULL) {
+               return;
+       }
+
+       switch(event->getEventType()) {
+               case EventApplicationInstall::APPLICATION_INSTALL_INSTALL:
+               case EventApplicationInstall::APPLICATION_INSTALL_UPDATE: {
+                       /* TODO: this needs to be either done in package manager or here
+                        * 1- delete the store file if decryption is done
+                        * 2- retrieve the installed date and size from package manager for the given package
+                        * 3- retrieve the rest of the info (e.g. name, version, iconPath) from app-manager (if not already in there,
+                        *    need to store the info there)
+                        * 4- construct the result to be passed onto the user
+                        * */
+                       if (result == EXIT_SUCCESS) {
+                               ApplicationInstallInfoPtr appInstallInfo = event->getAppInstallInfo();
+                               if(appInstallInfo == NULL)
+                               {
+                                       LogError("appInstallInfo is not exists.");
+                                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                                       EventRequestReceiver<EventApplicationInstall>::ManualAnswer(event);
+                               }
+
+                               AppManagerPackageInfoPtr packageInfo =
+                                               AppManagerPackageInfoPtr(new AppManagerPackageInfo(pkg_name, AppManagerPackageInfo::PackageName));
+
+                               std::string appId = packageInfo->getAppId();
+                               if(appId.empty())
+                               {
+                                       LogError("can not get the information of " << pkg_name);
+                                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               }
+
+                               std::string name = packageInfo->getName();
+                               std::string iconPath = packageInfo->getIconPath();
+                               std::string version = packageInfo->getVersion();
+                               bool show = packageInfo->getShow();
+                               std::string packageName = packageInfo->getPackageName();
+
+                               ApplicationInformationPtr appinfo(new ApplicationInformation());
+                               if( name.empty() || iconPath.empty() )
+                               {
+                                       LogError("can not get the information of " << appId << " package");
+                                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               }
+                               else
+                               {
+                                       if(version.empty())
+                                       {
+                                               LogWarning("can not get the version information of " << appId << " package");
+                                       }
+                                       appinfo->setName(name);
+                                       appinfo->setAppId(appId);
+                                       appinfo->setIconPath(iconPath);
+                                       appinfo->setVersion(version);
+                                       appinfo->setShow(show);
+                                       appinfo->setCategories(packageInfo->getCategories());
+
+                                       addPackageData(packageName.c_str(), appinfo);
+
+                                       event->setApplicationInformation(appinfo);
+                               }
+
+                       } else {
+                               LogError("Application installation failed for pkgname :"<<pkg_name<<" package");
+                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                       }
+                       LogDebug("Send Response for APPLICATION_INSTALL_INSTALL/UPDATE request");
+                       EventRequestReceiver<EventApplicationInstall>::ManualAnswer(event);
+                       break;
+               }
+               case EventApplicationInstall::APPLICATION_INSTALL_UNINSTALL: {
+                       if (result == EXIT_FAILURE) {
+                               LogError("Application uninstallation failed for pkgname :"<<pkg_name<<" package");
+                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                       }
+                       LogDebug("Send Response for APPLICATION_INSTALL_UNINSTALL request");
+                       EventRequestReceiver<EventApplicationInstall>::ManualAnswer(event);
+                       break;
+               }
+               default:
+                       LogError("[ERROR] UNKNOWN EVENT TYPE");
+                       event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+                       EventRequestReceiver<EventApplicationInstall>::ManualAnswer(event);
+                       break;
+       }
+
+}
+
+
+bool ApplicationManager::service_extra_data_callback(service_h service, const char *key, void* user_data)
+{
+       int ret = 0;
+
+       ApplicationControlDataArray* appControlDataArray = (ApplicationControlDataArray*)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;
+               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");
+                       std::vector<std::string> valArray;
+                       LogDebug("value length : " << length);
+                       for (int i = 0; i < length; i++)
+                       {
+                               LogDebug("value            : " << value[i]);
+                               if(value[i])
+                               {
+                                       valArray.push_back(value[i]);
+                               }
+                       }
+
+                       ApplicationControlDataPtr appControlData(new ApplicationControlData());
+                       appControlData->setKey(keyStr);
+                       appControlData->setValue(valArray);
+                       appControlDataArray->push_back(appControlData);
+
+                       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;
+                       }
+                       LogDebug("service_get_extra_data success");
+                       LogDebug("key = "<<key<<" value = "<<value);
+                       std::vector<std::string> valArray;
+                       valArray.push_back(value);
+
+                       ApplicationControlDataPtr appControlData(new ApplicationControlData());
+                       appControlData->setKey(keyStr);
+                       appControlData->setValue(valArray);
+                       appControlDataArray->push_back(appControlData);
+
+                       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;
+}
+
+
+
+
+void ApplicationManager::OnRequestReceived(const EventApplicationGetCurrAppPtr& event)
+{
+       LogDebug("entered");
+
+       // TODO: @20121130-wscho: if Application object already created, then just return that.
+       /*
+       if (m_app != NULL) {
+               event->setApp(m_app);
+               return;
+       }
+       */
+
+       Try
+       {
+               std::string appId;
+
+               AppManagerPackageInfoPtr packageInfo(NULL);
+
+               // get package info of current app
+               {
+                       char *app_id = NULL;
+
+                       //int ret = app_get_id(&app_id);
+                       int 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;
+                       }
+
+                       packageInfo = AppManagerPackageInfoPtr(
+                                       new AppManagerPackageInfo(app_id, AppManagerPackageInfo::ApplicationId));
+
+                       appId = app_id;
+
+                       free(app_id);
+               }
+
+               if(!packageInfo->isValid())
+               {
+                       LogError("Can not set package info");
+                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                       return;
+               }
+
+               std::string name = packageInfo->getName();
+               std::string iconPath = packageInfo->getIconPath();
+               std::string version = packageInfo->getVersion();
+               bool show = packageInfo->getShow();
+               std::string packageName = packageInfo->getPackageName();
+
+               LogDebug("name : " << name);
+               LogDebug("iconPath : " << iconPath);
+               LogDebug("version : " << version);
+               LogDebug("show : " << show);
+               LogDebug("packageName : " << packageName);
+
+               ApplicationInformationPtr appinfo(new ApplicationInformation());
+               if( name.empty() || iconPath.empty())
+               {
+                       LogError("can not get the information of " << appId << " package");
+                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                       return;
+               }
+               if(version.empty())
+               {
+                       LogWarning("can not get the version information of " << appId << " package");
+               }
+
+               appinfo->setName(name);
+               appinfo->setAppId(appId);
+               appinfo->setIconPath(iconPath);
+               appinfo->setVersion(version);
+               appinfo->setShow(show);
+               appinfo->setCategories(packageInfo->getCategories());
+
+               addPackageData(packageName.c_str(), appinfo);
+
+               LogError("get package data successfully");
+
+
+               ApplicationPtr app(new TizenApis::Api::Application::Application());
+               app->setAppInfo(appinfo);
+
+               LogDebug("set appinfo to application");
+
+               {
+                       //int pid = getpid();
+                       int pid = getppid();
+                       std::stringstream sstr;
+                       sstr << pid;
+                       app->setContextId(sstr.str());
+
+                       LogError("set pid : " << pid);
+               }
+
+               event->setApp(app);
+               LogDebug("set application to event ");
+               m_app = app;
+               
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on getAppInfo : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+
+}
+
+
+void ApplicationManager::OnRequestReceived(const EventApplicationLaunchPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               int ret;
+               int retry = 0;
+
+               std::string appId = event->getAppId();
+               if(appId.empty())
+               {
+                       LogError("App id is empty");
+                       event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                       return;
+               }
+
+               LogDebug("Launching app id : " << appId);
+
+               service_h service;
+               service_create(&service);
+
+               service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+
+               service_set_app_id(service, appId.c_str());
+
+               // give a second chance to launch application to avoid platform issue.
+               // this retry code will be removed after platform code change.
+               while (retry < 3) {
+                       ret = service_send_launch_request(service, NULL, this);
+                       if (ret != SERVICE_ERROR_LAUNCH_REJECTED) {
+                               break;
+                       }
+                       // delay 300ms for each retry
+                       usleep(300 * 1000);
+                       retry++;
+                       LogDebug("retry launch request : " << retry);
+               }
+
+               service_destroy(service);
+               
+               if(ret != SERVICE_ERROR_NONE)
+               {
+                       switch (ret)
+                       {
+                       case SERVICE_ERROR_INVALID_PARAMETER:
+                               LogDebug("service_send_launch_request returns SERVICE_ERROR_INVALID_PARAMETER");
+                               event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                               break;
+                       case SERVICE_ERROR_OUT_OF_MEMORY:
+                               LogDebug("service_send_launch_request returns SERVICE_ERROR_OUT_OF_MEMORY");
+                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                               break;
+                       case SERVICE_ERROR_LAUNCH_REJECTED:
+                       case SERVICE_ERROR_APP_NOT_FOUND:
+                               LogDebug("service_send_launch_request returns SERVICE_ERROR_APP_NOT_FOUND");
+                               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               break;                          
+                       default:
+                               LogDebug("service_send_launch_request returns UNKNOWN ERROR!!! (" << ret << ")");
+                               event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+                               break;
+                       }
+               }
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on launch : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+void ApplicationManager::OnRequestReceived(const EventApplicationKillPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               int ret;
+               std::string contextId = event->getContextId();
+
+               if(contextId.empty())
+               {
+                       LogError("Context id is empty");
+                       event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                       return;
+               }
+
+               LogDebug("Killing context id : " << contextId);
+
+               int pid;
+               std::stringstream(contextId) >> pid;
+               if(pid <= 0)
+               {
+                       LogError("Context id is wrong : " << pid);
+                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                       return;
+               }
+
+               char *appIdCStr = NULL;
+               ret = app_manager_get_app_id(pid, &appIdCStr);
+               if (ret != APP_MANAGER_ERROR_NONE)
+               {
+                       LogError("Error while getting app id (" << ret << ")");
+                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                       return;
+               }
+
+               std::string appId = appIdCStr;
+               free(appIdCStr);
+
+               app_context_h appContext;
+               ret = app_manager_get_app_context (appId.c_str(), &appContext);
+               if (ret != APP_MANAGER_ERROR_NONE)
+               {
+                       LogError("Error while getting app context (" << ret << ")");
+                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                       return;
+               }
+
+               // TODO thread
+               ret = app_manager_set_app_context_event_cb(app_manager_app_context_event_callback, this);
+               if (ret != APP_MANAGER_ERROR_NONE)
+               {
+                       LogError("Error while registering app context event (" << ret << ")");
+                       event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+                       return;
+               }
+
+               ret = app_manager_terminate_app(appContext);
+               if (ret != APP_MANAGER_ERROR_NONE)
+               {
+                       LogError("Error while terminating app (" << ret << ")");
+                       event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+                       return;
+               }
+
+               DPL::Mutex::ScopedLock lock(&m_killMapLock);
+               m_killEventMap[pid] = event;
+               event->switchToManualAnswer();
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on kill : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+void ApplicationManager::OnRequestReceived(const EventApplicationLaunchAppControlPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               int ret = 0;
+               int retry = 0;
+
+               ApplicationControlPtr appControl = event->getAppControl();
+               if(appControl == NULL)
+               {
+                       LogError("appControl is NULL");
+                       event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                       return;
+               }
+
+               std::string operation = appControl->getOperation();
+               if(operation.empty())
+               {
+                       LogDebug("operation being madatory is empty");
+                       event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                       return;
+               }
+
+               std::string appId = event->getAppId();
+
+               service_h service;
+               service_create(&service);
+
+               if (!appId.empty())
+               {
+                       LogDebug(" app id    : " << appId);
+
+                       service_set_app_id(service, appId.c_str());
+               }
+
+               service_set_operation(service, operation.c_str() );
+               LogDebug(" operation : " << operation);
+
+               std::string uri = appControl->getUri();
+               if (!uri.empty())
+               {
+                       LogDebug(" uri       : " << uri);
+                       service_set_uri(service, uri.c_str() );
+               }
+
+               std::string mime = appControl->getMime();
+               if (!mime.empty())
+               {
+                       LogDebug(" mime      : " << mime);
+                       service_set_mime(service, mime.c_str() );
+               }
+
+               std::string category = appControl->getCategory();
+               if (!category.empty())
+               {
+                       LogDebug(" category  : " << category);
+                       service_set_category(service, category.c_str() );
+               }
+
+               std::vector<ApplicationControlDataPtr> appControlDataArray = appControl->getAppControlDataArray();
+
+               if(!appControlDataArray.empty())
+               {
+                       LogDebug(" datas     : " << appControlDataArray.size());
+
+                       ApplicationControlDataArray::iterator iter;
+                       for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
+                       {
+                               ApplicationControlDataPtr appControlData = *iter;
+
+                               std::string key = appControlData->getKey();
+                               LogDebug("  key      : " << key);
+
+                               if(key.empty())
+                               {
+                                       event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                                       continue;
+                               }
+
+                               std::vector<std::string> valueArray = appControlData->getValue();
+                               size_t size = valueArray.size();
+
+                               const char **arr = (const char**)calloc(sizeof(char*), size);
+
+                               for (size_t j = 0; j < size; j++)
+                               {
+                                       arr[j] = valueArray.at(j).c_str();
+                                       LogDebug("  value    : " << arr[j]);
+                               }
+
+                               // @20121207-wscho: roll-back to return extra-data instead of extra-data array when the value size is one.
+                               const char *keyCStr = key.c_str();
+                               if (size == 1) {
+                                       service_add_extra_data(service, keyCStr, arr[0]);
+                               } else {
+                                       service_add_extra_data_array(service, keyCStr, arr, size);
+                               }
+
+                               if (arr)
+                                       free(arr);
+                       }
+               }
+
+               LaunchAppControlPendingEvent *pendingEvent = NULL;
+               LaunchAppControlPendingEventMap::DataKeyType key = 0;
+
+               EventApplicationLaunchAppControlReplyPtr eventReply = event->getEventReply();
+               if(eventReply)
+               {
+                       pendingEvent = new LaunchAppControlPendingEvent((void*)this, eventReply);
+                       key = gLaunchAppControlPendingEventMap.insert(this, pendingEvent);
+               }
+
+               // give a second chance to launch application to avoid platform issue.
+               // this retry code will be removed after platform code change.
+               while (retry < 3) {
+                       ret = service_send_launch_request(service, service_reply_callback, (void *)key);
+                       if (ret != SERVICE_ERROR_LAUNCH_REJECTED) {
+                               break;
+                       }
+                       // delay 300ms for each retry
+                       usleep(300 * 1000);
+                       retry++;
+                       LogDebug("retry launch request : " << retry);
+               }
+
+               service_destroy(service);
+
+               if(ret != SERVICE_ERROR_NONE)
+               {
+                       switch (ret)
+                       {
+                       case SERVICE_ERROR_INVALID_PARAMETER:
+                               LogDebug("service_send_launch_request returns SERVICE_ERROR_INVALID_PARAMETER");
+                               event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                               break;
+                       case SERVICE_ERROR_OUT_OF_MEMORY:
+                               LogDebug("service_send_launch_request returns SERVICE_ERROR_OUT_OF_MEMORY");
+                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                               break;
+                       case SERVICE_ERROR_LAUNCH_REJECTED:
+                       case SERVICE_ERROR_APP_NOT_FOUND:
+                               LogDebug("service_send_launch_request returns SERVICE_ERROR_APP_NOT_FOUND");
+                               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               break;
+                       default:
+                               LogDebug("service_send_launch_request returns UNKNOWN ERROR!!!");
+                               event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+                               break;
+                       }
+
+                       if(pendingEvent)
+                       {
+                               gLaunchAppControlPendingEventMap.eraseData(key);
+
+                               delete pendingEvent;
+                               pendingEvent = NULL;
+
+                               eventReply->cancelRequest();
+                               EventRequestReceiver<EventApplicationLaunchAppControlReply>::ManualAnswer(eventReply);
+                       }
+               }
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on launchAppControl : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+void ApplicationManager::OnRequestReceived(const EventApplicationLaunchAppControlReplyPtr& event)
+{
+       LogDebug("entered");
+       event->switchToManualAnswer();
+}
+
+void ApplicationManager::OnRequestReceived(const EventApplicationFindAppControlPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               ApplicationControlPtr appControl = event->getAppControl();
+               if(appControl == NULL)
+               {
+                       LogError("appControl is NULL");
+                       event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                       return;
+               }
+
+               std::string operation = appControl->getOperation();
+               if(operation.empty())
+               {
+                       LogDebug("operation being madatory is empty");
+                       event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                       return;
+               }
+
+               service_h service;
+               service_create(&service);
+
+               service_set_operation(service, operation.c_str() );
+               LogDebug(" operation : " << operation);
+
+               std::string uri = appControl->getUri();
+               if (!uri.empty())
+               {
+                       LogDebug(" uri       : " << uri);
+                       service_set_uri(service, uri.c_str() );
+               }
+
+               std::string mime = appControl->getMime();
+               if (!mime.empty())
+               {
+                       LogDebug(" mime      : " << mime);
+                       service_set_mime(service, mime.c_str() );
+               }
+
+               std::string category = appControl->getCategory();
+               if (!category.empty())
+               {
+                       LogDebug(" category  : " << category);
+                       service_set_category(service, category.c_str() );
+               }
+
+               std::vector<ApplicationControlDataPtr> appControlDataArray = appControl->getAppControlDataArray();
+
+               if(!appControlDataArray.empty())
+               {
+                       LogDebug(" datas     : " << appControlDataArray.size());
+
+                       ApplicationControlDataArray::iterator iter;
+                       for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
+                       {
+                               ApplicationControlDataPtr appControlData = *iter;
+
+                               std::string key = appControlData->getKey();
+                               LogDebug("  key      : " << key);
+
+                               if(key.empty())
+                               {
+                                       event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                                       continue;
+                               }
+
+                               std::vector<std::string> valueArray = appControlData->getValue();
+                               size_t size = valueArray.size();
+
+                               const char **arr = (const char**)calloc(sizeof(char*), size);
+
+                               for (size_t j = 0; j < size; j++)
+                               {
+                                       arr[j] = valueArray.at(j).c_str();
+                                       LogDebug("  value    : " << arr[j]);
+                               }
+
+                               // @20121207-wscho: roll-back to return extra-data instead of extra-data array when the value size is one.
+                               const char *keyCStr = key.c_str();
+                               if (size == 1) {
+                                       service_add_extra_data(service, keyCStr, arr[0]);
+                               } else {
+                                       service_add_extra_data_array(service, keyCStr, arr, size);
+                               }
+
+                               if (arr)
+                                       free(arr);
+                       }
+               }
+
+               ApplicationInformationArrayPtr appInfos(new ApplicationInformationArray());
+
+               int result = service_foreach_app_matched(service, service_app_matched_callback, (void *)appInfos.Get());
+               if (result != SERVICE_ERROR_NONE)
+               {
+                       LogError("service_foreach_app_matched error (" << result << ")");
+                       event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                       service_destroy(service);
+                       return;
+               }
+
+               service_destroy(service);
+
+               event->setAppInfos(appInfos);
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on findAppControl : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+
+void ApplicationManager::OnRequestReceived(const EventApplicationGetAppsContextPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               int ret = 0;
+
+               ApplicationContextArrayPtr appContextArray = event->getAppContextArray();
+               ret = app_manager_foreach_app_context(app_manager_app_context_callback, appContextArray.Get());
+               if(ret != APP_MANAGER_ERROR_NONE)
+               {
+                       LogError("app_manager_foreach_app_context error (" << ret << ")");
+                       event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+               }
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on  : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+void ApplicationManager::OnRequestReceived(const EventApplicationGetAppContextPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               int ret = 0;
+
+               std::string contextId = event->getAppContextId();
+               int pid;
+
+               if (contextId.empty())
+               {
+                       //pid = getpid();
+                       pid = getppid();
+
+                       std::stringstream sstr;
+                       sstr << pid;
+                       contextId = sstr.str();
+               }
+               else
+               {
+                       std::stringstream(contextId) >> pid;
+                       if (pid <= 0)
+                       {
+                               LogError("contextId is wrong : " << contextId);
+                               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               return;
+                       }
+               }
+
+               char *app_id = NULL;
+
+               ret = app_manager_get_app_id(pid, &app_id);
+               if(ret != APP_MANAGER_ERROR_NONE)
+               {
+                       switch(ret)
+                       {
+                       case APP_MANAGER_ERROR_NO_SUCH_APP:
+                               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);
+                               break;
+                       }
+
+                       if(app_id)
+                               free(app_id);
+
+                       return;
+               }
+
+               ApplicationContextPtr appContext(new ApplicationContext());
+               appContext->setAppId(app_id);
+               appContext->setContextId(contextId);
+
+               event->setAppContext(appContext);
+
+               if(app_id)
+                       free(app_id);
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on getAppContext : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+void ApplicationManager::OnRequestReceived(const EventApplicationGetAppsInfoPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               AppManagerPackageInfoArrayPtr pkgInfos =
+                               AppManagerWrapperSingleton::Instance().getInstalledAppList();
+
+               AppManagerPackageInfoArray::iterator iter = pkgInfos->begin();
+               for(; iter != pkgInfos->end(); iter++)
+               {
+                       AppManagerPackageInfoPtr packageInfo = *iter;
+                       if(!packageInfo->getAppIdIsSet())
+                               continue;
+
+                       std::string appId = packageInfo->getAppId();
+
+                       ApplicationInformationPtr appinfo(new ApplicationInformation());
+                       appinfo->setName(packageInfo->getName());
+                       appinfo->setIconPath(packageInfo->getIconPath());
+                       appinfo->setVersion(packageInfo->getVersion());
+                       appinfo->setAppId(packageInfo->getAppId());
+                       appinfo->setShow(packageInfo->getShow());
+                       appinfo->setCategories(packageInfo->getCategories());
+
+                       addPackageData(packageInfo->getPackageName().c_str(), appinfo);
+
+                       event->addAppInfo(appinfo);
+               }
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on getAppsInfo : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+void ApplicationManager::OnRequestReceived(const EventApplicationGetAppInfoPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               AppManagerPackageInfoPtr packageInfo(NULL);
+
+               std::string appId = event->getAppId();
+
+               // in case of no argument, get application information of current.
+               if (appId.empty())
+               {
+                       char *app_id = NULL;
+
+                       //int ret = app_get_id(&app_id);
+                       int 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;
+                       }
+
+                       packageInfo = AppManagerPackageInfoPtr(
+                                       new AppManagerPackageInfo(app_id, AppManagerPackageInfo::ApplicationId));
+
+                       appId = app_id;
+
+                       free(app_id);
+               }
+               else
+               {
+                       packageInfo = AppManagerPackageInfoPtr(
+                                       new AppManagerPackageInfo(appId.c_str(), AppManagerPackageInfo::ApplicationId));
+               }
+
+               if(!packageInfo->isValid())
+               {
+                       LogError("Can not set package info");
+                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                       return;
+               }
+
+               std::string name = packageInfo->getName();
+               std::string iconPath = packageInfo->getIconPath();
+               std::string version = packageInfo->getVersion();
+               bool show = packageInfo->getShow();
+               std::string packageName = packageInfo->getPackageName();
+
+               ApplicationInformationPtr appinfo(new ApplicationInformation());
+               if( name.empty() || iconPath.empty())
+               {
+                       LogError("can not get the information of " << appId << " package");
+                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                       return;
+               }
+               else
+               {
+                       if(version.empty())
+                       {
+                               LogWarning("can not get the version information of " << appId << " package");
+                       }
+
+                       appinfo->setName(name);
+                       appinfo->setAppId(appId);
+                       appinfo->setIconPath(iconPath);
+                       appinfo->setVersion(version);
+                       appinfo->setShow(show);
+                       appinfo->setCategories(packageInfo->getCategories());
+
+                       addPackageData(packageName.c_str(), appinfo);
+
+                       event->setAppInfo(appinfo);
+               }
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on getAppInfo : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+void ApplicationManager::OnRequestReceived(const EventApplicationAddAppInfoEventListenerPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               EventApplicationAppInfoEventListenerEmitterPtr emitter = event->getEmitter();
+
+               if(m_installedApplicationsEmitters.size() == 0)
+               {
+                       LogDebug("First time registering event listener to this application object.");
+
+                       // Below can throw Exception
+                       AppManagerWrapperSingleton::Instance().registerAppListChangedCallbacks(this);
+               }
+
+               m_installedApplicationsEmitters.attach(emitter);
+
+               long watchId = AppManagerWrapperSingleton::Instance().getWatchIdAndInc();
+
+               m_watchIdMap[watchId] = emitter->getId();
+
+               event->setWatchId(watchId);
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on addAppInfoEventListener : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+void ApplicationManager::OnRequestReceived(const EventApplicationRemoveAppInfoEventListenerPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               long watchId = event->getWatchId();
+
+               if(m_watchIdMap.find(watchId) == m_watchIdMap.end())
+                       ThrowMsg(NotFoundException, "No watchId : " << watchId);
+
+               EventApplicationAppInfoEventListenerEmitter::IdType emitterId = m_watchIdMap[watchId];
+
+               bool success = m_installedApplicationsEmitters.detach(emitterId);
+               if(!success)
+                       ThrowMsg(NotFoundException, "No watchId : " << watchId);
+
+               if(m_installedApplicationsEmitters.size() == 0)
+               {
+                       LogDebug("No more event listener on this application object.");
+
+                       AppManagerWrapperSingleton::Instance().unregisterAppListChangedCallbacks(this);
+               }
+       }
+       Catch (WrtDeviceApis::Commons::NotFoundException)
+       {
+               LogError("Not found : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on removeAppInfoEventListener : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+void ApplicationManager::OnRequestReceived(const EventApplicationInstallPtr& event)
+{
+       switch(event->getEventType()) {
+               case EventApplicationInstall::APPLICATION_INSTALL_INSTALL:
+               case EventApplicationInstall::APPLICATION_INSTALL_UPDATE: {
+
+                       LogDebug("APPLICATION_INSTALL_INSTALL/APPLICATION_INSTALL_UPDATE request received");
+                       ApplicationInstallInfoPtr appInstallInfo = event->getAppInstallInfo();
+                       if(appInstallInfo == NULL)
+                       {
+                               LogError("appInstallInfo is not exists.");
+                               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               break;
+                       }
+                       std::string filePath = appInstallInfo->getFilePath();
+                       std::string algo = appInstallInfo->getAlgorithm();
+                       std::string key = appInstallInfo->getKey();
+                       if (!algo.empty() && !key.empty()) {
+
+                               std::string decFilePath = filePath.substr(0,filePath.rfind(".wgt")) + "-dec.wgt";
+                               LogDebug("App key: " << key << " algo: " << algo << " decpath: " <<decFilePath);
+                               filePath = decFilePath;
+                       }
+
+                       pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST);
+                       if(pc == NULL){
+                               LogError("[ERROR] pkgmgr_client_install - unable to create client object");
+                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                               break;
+                       }
+
+                       ApplicationInstallPendingEvent *pendingEvent =
+                                       new ApplicationInstallPendingEvent((void *)this, event);
+                       int ret = pkgmgr_client_install(pc,
+                                       appInstallInfo->getPackageFormat().c_str(),
+                                       NULL,                                  //not used for wgt
+                                       filePath.c_str(),                      //(decrypted) wgt file location
+                                       NULL,                                  //not used for wgt
+                                       PM_QUIET,                              //use PM_QUIET. If set to PM_DEFAULT, pkgmgr show system pop up window
+                                       installAppResultCallback,
+                                       pendingEvent);
+                       if(ret < PKGMGR_R_OK){
+                               LogError("[ERROR] pkgmgr_client_install FAIL :" << ret);
+                               event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                               if(pendingEvent) {
+                                       delete pendingEvent;
+                                       pendingEvent = NULL;
+                               }
+                               break;
+                       }
+                       event->switchToManualAnswer();
+                       LogDebug("Waiting for response for APPLICATION_INSTALL_INSTALL/APPLICATION_INSTALL_UPDATE request");
+                       break;
+               }
+               case EventApplicationInstall::APPLICATION_INSTALL_UNINSTALL: {
+                       LogDebug("APPLICATION_INSTALL_UNINSTALL request received");
+                       ApplicationInstallInfoPtr appInstallInfo = event->getAppInstallInfo();
+                       if(appInstallInfo == NULL)
+                       {
+                               LogError("appInstallInfo is not exists.");
+                               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               break;
+                       }
+                       std::string strId = event->getAppId();
+                       const char* appId = strId.c_str();
+                       char *package = getPackageById(appId);
+                       if(package == NULL) {
+                               LogError("package not found for appid :"<<appId);
+                               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               break;
+                       }
+
+                       pkgmgr_info *pkg_info = pkgmgr_info_new("wgt", package);
+                       if(pkg_info == NULL) {
+                               LogError("package info cannnot be retrieved for appid :"<<appId);
+                               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               free(package); package = NULL;
+                               break;
+                       }
+                       char *name = pkgmgr_info_get_string(pkg_info, "pkg_name");
+                       free(package); package = NULL;
+                       pkgmgr_info_free(pkg_info); pkg_info = NULL;
+                       if(name == NULL || isAppInstalled(name) != 0) {
+                               LogError("can not get name of "<<appId<<" package");
+                               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               if (name) {
+                                       free(name); name = NULL;
+                               }
+                               break;
+                       }
+
+                       LogDebug("APPLICATION_INSTALL_UNINSTALL package_name: " << name);
+                       pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST);
+                       if(pc == NULL){
+                               LogError("[ERROR] pkgmgr_client_uninstall - unable to create client object");
+                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                               free(name); name = NULL;
+                               break;
+                       }
+
+                       ApplicationInstallPendingEvent *pendingEvent =
+                                       new ApplicationInstallPendingEvent((void *)this, event);
+                       int ret = pkgmgr_client_uninstall(pc,
+                                       "wgt",                              //package type it can be deb and wgt. We should set to "wgt".
+                                       name,                               //name of the package
+                                       PM_QUIET,                           //use PM_QUIET. If set to PM_DEFAULT, pkgmgr show system pop up window
+                                       installAppResultCallback,
+                                       pendingEvent);
+                       free(name); name = NULL;
+                       if(ret < PKGMGR_R_OK){
+                               LogError("[ERROR] pkgmgr_client_uninstall FAIL :" << ret);
+                               event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException);
+                               if(pendingEvent) {
+                                       delete pendingEvent;
+                                       pendingEvent = NULL;
+                               }
+                               break;
+                       }
+                       event->switchToManualAnswer();
+                       LogDebug("Waiting for response for APPLICATION_INSTALL_UNINSTALL request");
+                       break;
+               }
+               default:
+                       LogError("[ERROR] UNKNOWN EVENT TYPE");
+                       event->setExceptionCode(Commons::ExceptionCodes::UnknownException);
+                       break;
+       }
+}
+
+
+void ApplicationManager::OnRequestReceived(const EventApplicationGetAppCertsPtr& event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               std::string appId = event->getAppId();
+
+               // in case of no argument, get application information of current.
+               if (appId.empty())
+               {
+                       char *tmp = NULL;
+
+                       //int ret = app_get_id(&tmp);
+                       int ret = get_current_app_id(&tmp);
+                       if((ret != APP_ERROR_NONE) || (tmp == NULL))
+                       {
+                               LogError("Can not get app id from current pid (" << ret << ")");
+                               event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                               return;
+                       }
+
+                       appId = tmp;
+                       if (tmp)
+                               free(tmp);
+               }
+
+               const char* app_id = appId.c_str();
+               
+               char* package = getPackageById(app_id);
+
+               if (package == NULL)
+               {
+                       LogError("Can not get package from pid (" << app_id << ")");
+                       event->setExceptionCode(Commons::ExceptionCodes::NotFoundException);
+                       return;
+               }
+               
+               LogDebug("package : " << package);
+               package_info_h pkg_info;
+               int result = 0;
+               
+               result = package_manager_get_package_info(package, &pkg_info);
+               if (result != PACKAGE_MANAGER_ERROR_NONE)
+               {
+                       event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                       return;
+               }       
+
+               ApplicationCertArrayPtr certArray(new ApplicationCertArray());
+
+               result = package_info_foreach_cert_info(pkg_info, package_cert_cb, (void*)certArray.Get());
+               if (result != PACKAGE_MANAGER_ERROR_NONE)
+               {
+                       event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                       return;
+               }
+
+               event->setAppCerts(certArray);
+
+               LogDebug("Finish to getting package cert info");
+       }
+       Catch (WrtDeviceApis::Commons::Exception)
+       {
+               LogError("Error on getAppInfo : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+
+void ApplicationManager::onAppManagerEventInstalled(AppManagerPackageInfoPtr &pkgInfo)
+{
+       std::string packageName = pkgInfo->getPackageName();
+
+       EventApplicationAppInfoEventListenerPtr event(new EventApplicationAppInfoEventListener());
+       ApplicationInformationPtr appinfo(new ApplicationInformation());
+
+       appinfo->setAppId(pkgInfo->getAppId());
+       appinfo->setName(pkgInfo->getName());
+       appinfo->setIconPath(pkgInfo->getIconPath());
+       appinfo->setVersion(pkgInfo->getVersion());
+       appinfo->setShow(pkgInfo->getShow());
+       appinfo->setCategories(pkgInfo->getCategories());       
+
+       addPackageData(packageName.c_str(), appinfo);
+
+       event->setType(EventApplicationAppInfoEventListener::OnInstalled);
+       LogDebug("APP_MANAGER_EVENT_INSTALLED, package name : "<< packageName);
+
+       event->setAppInfo(appinfo);
+
+       m_installedApplicationsEmitters.emit(event);
+}
+
+void ApplicationManager::onAppManagerEventUninstalled(AppManagerPackageInfoPtr &pkgInfo)
+{
+       std::string packageName = pkgInfo->getPackageName();
+
+       EventApplicationAppInfoEventListenerPtr event(new EventApplicationAppInfoEventListener());
+       ApplicationInformationPtr appinfo(new ApplicationInformation());
+
+       appinfo->setAppId(pkgInfo->getAppId());
+
+       event->setType(EventApplicationAppInfoEventListener::OnUninstalled);
+       LogDebug("APP_MANAGER_EVENT_UNINSTALLED, package name : " << packageName);
+
+       event->setAppInfo(appinfo);
+
+       m_installedApplicationsEmitters.emit(event);
+}
+
+void ApplicationManager::onAppManagerEventUpdated(AppManagerPackageInfoPtr &pkgInfo)
+{
+       std::string packageName = pkgInfo->getPackageName();
+
+       EventApplicationAppInfoEventListenerPtr event(new EventApplicationAppInfoEventListener());
+       ApplicationInformationPtr appinfo(new ApplicationInformation());
+
+       appinfo->setAppId(pkgInfo->getAppId());
+       appinfo->setName(pkgInfo->getName());
+       appinfo->setIconPath(pkgInfo->getIconPath());
+       appinfo->setVersion(pkgInfo->getVersion());
+       appinfo->setShow(pkgInfo->getShow());
+       appinfo->setCategories(pkgInfo->getCategories());       
+
+       addPackageData(packageName.c_str(), appinfo);
+
+       event->setType(EventApplicationAppInfoEventListener::OnUpdated);
+       LogDebug("APP_MANAGER_EVENT_UPDATED, package name : " << packageName);
+
+       event->setAppInfo(appinfo);
+
+       m_installedApplicationsEmitters.emit(event);
+}
+
+void ApplicationManager::initialize() 
+{
+       if (!m_initialized) {
+               DPL::Mutex::ScopedLock lock(&m_initializationMutex);
+               if (!m_initialized) {
+                       
+               }
+       }
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Application/ApplicationManager.h b/src/platform/Tizen/Application/ApplicationManager.h
new file mode 100644 (file)
index 0000000..391a9ad
--- /dev/null
@@ -0,0 +1,301 @@
+//
+// 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_APPLICATION_H_
+#define TIZENAPIS_PLATFORM_APPLICATION_H_
+
+#include <map>
+#include <set>
+#include <list>
+#include <Commons/Emitters.h>
+#include <API/Application/IApplicationManager.h>
+#include <API/Application/ApplicationFactory.h>
+
+//#include <app_manager.h>
+#include <app_service.h>
+
+#include "AppManagerWrapper.h"
+
+using namespace TizenApis::Api::Application;
+
+namespace TizenApis {
+namespace Platform {
+namespace Application {
+
+class ApplicationManager: public IApplicationManager, public IAppManagerAppListChangedCallbacks {
+    friend class ApplicationFactory;
+
+public:
+       ApplicationManager();
+       virtual ~ApplicationManager();
+       virtual void getCurrentApplication(const EventApplicationGetCurrAppPtr& event);
+       virtual void launch(const EventApplicationLaunchPtr& event);
+       virtual void kill(const EventApplicationKillPtr& event);
+       virtual void launchAppControl(const EventApplicationLaunchAppControlPtr& event);
+       virtual void findAppControl(const EventApplicationFindAppControlPtr& event);
+       virtual void getAppsContext(const EventApplicationGetAppsContextPtr& event);
+       virtual void getAppContext(const EventApplicationGetAppContextPtr& event);
+       virtual void getAppsInfo(const EventApplicationGetAppsInfoPtr& event);
+       virtual void getAppInfo(const EventApplicationGetAppInfoPtr& event);
+       virtual void addAppInfoEventListener(const EventApplicationAddAppInfoEventListenerPtr& event);
+       virtual void removeAppInfoEventListener(const EventApplicationRemoveAppInfoEventListenerPtr& event);
+       virtual void install(const EventApplicationInstallPtr& event);
+       virtual void uninstall(const EventApplicationInstallPtr& event);
+       virtual void update(const EventApplicationInstallPtr& event);
+       virtual void getAppCerts(const EventApplicationGetAppCertsPtr& event);
+
+       void invokeManualAnswerLaunchAppControl(service_h request, service_h reply, service_result_e result,
+                       Api::Application::EventApplicationLaunchAppControlReplyPtr &event);
+       //void InstalledApplicationChanged(app_manger_event_type_e event_type,const char *package);
+       void invokeManualAnswerKill(int pid);
+       void installAppAnswer(int req_id,
+                                                 const char* pkg_type,
+                                                 const char* pkg_name,
+                                                 const char* key,
+                                                 const char* val,
+                                                 const void* pmsg,
+                                                 int result,
+                                                 Api::Application::EventApplicationInstallPtr &event);
+
+       static bool service_extra_data_callback(service_h service, const char *key, void* user_data);
+
+protected:
+       virtual void OnRequestReceived(const EventApplicationGetCurrAppPtr& event);
+       virtual void OnRequestReceived(const EventApplicationLaunchPtr& event);
+       virtual void OnRequestReceived(const EventApplicationKillPtr& event);
+       virtual void OnRequestReceived(const EventApplicationLaunchAppControlPtr& event);
+       virtual void OnRequestReceived(const EventApplicationLaunchAppControlReplyPtr& event);
+       virtual void OnRequestReceived(const EventApplicationFindAppControlPtr& event);
+       virtual void OnRequestReceived(const EventApplicationGetAppsContextPtr& event);
+       virtual void OnRequestReceived(const EventApplicationGetAppContextPtr& event);
+       virtual void OnRequestReceived(const EventApplicationGetAppsInfoPtr& event);
+       virtual void OnRequestReceived(const EventApplicationGetAppInfoPtr& event);
+       virtual void OnRequestReceived(const EventApplicationAddAppInfoEventListenerPtr& event);
+       virtual void OnRequestReceived(const EventApplicationRemoveAppInfoEventListenerPtr& event);
+       virtual void OnRequestReceived(const EventApplicationInstallPtr& event);
+       virtual void OnRequestReceived(const EventApplicationGetAppCertsPtr& event);
+
+       // inherited from IAppManagerAppListChangedCallbacks
+       virtual void onAppManagerEventInstalled(AppManagerPackageInfoPtr &pkgInfo);
+       virtual void onAppManagerEventUninstalled(AppManagerPackageInfoPtr &pkgInfo);
+       virtual void onAppManagerEventUpdated(AppManagerPackageInfoPtr &pkgInfo);
+
+private:
+       void initialize();
+
+       DPL::Mutex m_initializationMutex;
+       bool m_initialized;
+
+       std::map<int, EventApplicationKillPtr> m_killEventMap;
+       mutable DPL::Mutex m_killMapLock;
+
+       typedef WrtDeviceApis::Commons::Emitters<TizenApis::Api::Application::EventApplicationAppInfoEventListenerEmitter> EventApplicationAppInfoEventListenerEmitters;
+       typedef std::map<long, TizenApis::Api::Application::EventApplicationAppInfoEventListenerEmitter::IdType> WatchIdMap;
+
+       EventApplicationAppInfoEventListenerEmitters m_installedApplicationsEmitters;
+       WatchIdMap      m_watchIdMap;
+
+       ApplicationPtr m_app;
+};
+
+class LaunchAppControlPendingEvent
+{
+public:
+       LaunchAppControlPendingEvent(void *thisObject, const Api::Application::EventApplicationLaunchAppControlReplyPtr &event) :
+               m_thisObject(thisObject),
+               m_event(event)
+       {
+       }
+
+       virtual ~LaunchAppControlPendingEvent()
+       {
+       }
+
+       void* getThisObject() const { return m_thisObject; }
+       Api::Application::EventApplicationLaunchAppControlReplyPtr getEvent() const { return m_event; }
+
+private:
+       void *m_thisObject;
+       Api::Application::EventApplicationLaunchAppControlReplyPtr m_event;
+};
+
+class ApplicationInstallPendingEvent
+{
+public:
+       ApplicationInstallPendingEvent(void *thisObject, const Api::Application::EventApplicationInstallPtr &event) :
+               m_thisObject(thisObject),
+               m_event(event)
+       {
+       }
+
+       virtual ~ApplicationInstallPendingEvent()
+       {
+       }
+
+       void* getThisObject() const { return m_thisObject; }
+       Api::Application::EventApplicationInstallPtr getEvent() const { return m_event; }
+
+private:
+       void *m_thisObject;
+       Api::Application::EventApplicationInstallPtr m_event;
+};
+
+template <class KeyType, class DataType>
+class KeyMultiMap
+{
+public:
+       typedef unsigned int                                DataKeyType;
+       typedef DataType *                                  DataPtrType;
+       typedef std::pair<KeyType, DataPtrType>             KeyDataPairType;
+       typedef std::map<DataKeyType, KeyDataPairType>      DataMapType;
+       typedef std::set<DataKeyType>                       DataKeySetType;
+       typedef std::map<KeyType, DataKeySetType>           KeyMapType;
+       typedef std::list<DataPtrType>                      DataPtrListType;
+
+       KeyMultiMap() :
+               m_keyAcc(0)
+       {
+       }
+
+       DataKeyType insert(const KeyType &key, const DataPtrType &dataPtr)
+       {
+               DataKeyType dataKey = ++m_keyAcc;
+
+               KeyDataPairType pair(key, dataPtr);
+               m_dataMap.insert(std::pair<DataKeyType, KeyDataPairType>(dataKey, pair));
+
+               typename KeyMapType::iterator keyMapIter = m_keyMap.find(key);
+               if(keyMapIter == m_keyMap.end())
+               {
+                       DataKeySetType newKeySet;
+                       m_keyMap.insert(std::pair<KeyType, DataKeySetType>(key, newKeySet));
+                       keyMapIter = m_keyMap.find(key);
+               }
+
+               DataKeySetType &dataKeySet = keyMapIter->second;
+
+               dataKeySet.insert(dataKey);
+
+               return dataKey;
+       }
+
+       DataPtrType getData(const DataKeyType &dataKey) const
+       {
+               typename DataMapType::const_iterator dataMapIter = m_dataMap.find(dataKey);
+
+               if(dataMapIter == m_dataMap.end())
+                       return static_cast<DataPtrType>(NULL);
+
+               return dataMapIter->second.second;
+       }
+
+       DataPtrListType getDataPtrList(const KeyType &key)
+       {
+               DataPtrListType dataPtrList;
+
+               typename KeyMapType::const_iterator keyMapIter = m_keyMap.find(key);
+               if(keyMapIter == m_keyMap.end())
+                       return dataPtrList;
+
+               DataKeySetType keySet = keyMapIter->second;
+               DataKeySetType::iterator keySetIter = keySet.begin();
+               for(; keySetIter != keySet.end(); keySetIter++)
+               {
+                       DataPtrType dataPtr = getData(*keySetIter);
+                       if(dataPtr == NULL)
+                       {
+                               LogWarning("No data for " << *keySetIter);
+                               break;
+                       }
+
+                       dataPtrList.push_back(dataPtr);
+               }
+
+               return dataPtrList;
+       }
+
+       void eraseData(const DataKeyType &dataKey)
+       {
+               typename DataMapType::iterator dataKeyIter = m_dataMap.find(dataKey);
+
+               if(dataKeyIter == m_dataMap.end())
+               {
+                       LogDebug("No data for " << dataKey);
+                       return;
+               }
+
+               KeyType key = dataKeyIter->second.first;
+
+               m_dataMap.erase(dataKeyIter);
+
+               typename KeyMapType::iterator keyMapIter = m_keyMap.find(key);
+               if(keyMapIter == m_keyMap.end())
+               {
+                       LogWarning("No data for Key");
+                       return;
+               }
+
+               DataKeySetType &keySet = keyMapIter->second;
+               DataKeySetType::iterator keySetIter = keySet.find(dataKey);
+               if(keySetIter == keySet.end())
+               {
+                       LogWarning("No data for " << dataKey);
+                       return;
+               }
+
+               keySet.erase(keySetIter);
+       }
+
+       void eraseKey(const KeyType &key)
+       {
+               typename KeyMapType::iterator keyMapIter = m_keyMap.find(key);
+               if(keyMapIter == m_keyMap.end())
+               {
+                       LogDebug("No data to erase.");
+                       return;
+               }
+
+               DataKeySetType &keySet = keyMapIter->second;
+               DataKeySetType::iterator keySetIter = keySet.begin();
+               for(; keySetIter != keySet.end(); keySetIter++)
+               {
+                       typename DataMapType::iterator dataKeyIter = m_dataMap.find(*keySetIter);
+                       if(dataKeyIter == m_dataMap.end())
+                       {
+                               LogWarning("No data to erase.");
+                               break;
+                       }
+
+                       m_dataMap.erase(dataKeyIter);
+               }
+
+               m_keyMap.erase(keyMapIter);
+       }
+
+private:
+       DataKeyType m_keyAcc;
+
+       DataMapType m_dataMap;
+       KeyMapType m_keyMap;
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/Tizen/Application/config.cmake b/src/platform/Tizen/Application/config.cmake
new file mode 100755 (executable)
index 0000000..c606d3d
--- /dev/null
@@ -0,0 +1,38 @@
+get_current_path()
+
+pkg_search_module(capi-appfw-app-manager REQUIRED capi-appfw-app-manager)
+pkg_search_module(capi-appfw-application REQUIRED capi-appfw-application)
+pkg_search_module(wrt-deviceapis-commons REQUIRED wrt-deviceapis-commons)
+pkg_search_module(wrt-deviceapis-commons-javascript REQUIRED wrt-deviceapis-commons-javascript)
+pkg_search_module(pkgmgr REQUIRED pkgmgr)
+pkg_search_module(pkgmgr-info REQUIRED pkgmgr-info)
+pkg_search_module(capi-appfw-package-manager REQUIRED capi-appfw-package-manager)
+set(INCLUDES_PLATFORM_IMPLEMENTATION_APPLICATION
+  ${capi-appfw-app-manager_INCLUDE_DIRS}
+  ${capi-appfw-application_INCLUDE_DIRS}  
+  ${wrt-deviceapis-commons_INCLUDE_DIRS}
+  ${wrt-deviceapis-commons-javascript_INCLUDE_DIRS}  
+  ${pkgmgr_INCLUDE_DIRS}
+  ${pkgmgr-info_INCLUDE_DIRS}
+  ${capi-appfw-package-manager_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_APPLICATION
+  ${capi-appfw-app-manager_LIBRARIES}
+  ${capi-appfw-application_LIBRARIES}  
+  ${wrt-deviceapis-commons_LIBRARIES}
+  ${wrt-deviceapis-commons-javascript_LIBRARIES}  
+  ${pkgmgr_LIBRARIES}
+  ${pkgmgr-info_LIBRARIES}
+  ${capi-appfw-package-manager_LIBRARIES}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_APPLICATION
+  ${CURRENT_PATH}/ApplicationManager.cpp
+  ${CURRENT_PATH}/AppManagerWrapper.cpp
+  ${CURRENT_PATH}/Application.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/Bluetooth/BluetoothAdapterManager.cpp b/src/platform/Tizen/Bluetooth/BluetoothAdapterManager.cpp
new file mode 100755 (executable)
index 0000000..1d6baba
--- /dev/null
@@ -0,0 +1,1074 @@
+//
+// 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 <API/Bluetooth/BluetoothProperty.h>
+
+
+
+
+using namespace TizenApis::Api;
+using namespace WrtDeviceApis;
+using namespace DPL;
+
+
+namespace TizenApis {
+namespace Platform {
+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->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);
+}
+
+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 (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);
+}
+
+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 (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);
+}
+
+
+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 (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);
+}
+
+
+
+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");
+               }
+
+               if (getVisibility() == false)
+               {
+                       ThrowMsg(Commons::UnknownException, "please set visivility");
+               }
+               
+               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/platform/Tizen/Bluetooth/BluetoothAdapterManager.h b/src/platform/Tizen/Bluetooth/BluetoothAdapterManager.h
new file mode 100644 (file)
index 0000000..442aa92
--- /dev/null
@@ -0,0 +1,110 @@
+//
+// 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 <API/Bluetooth/IBluetoothAdapterManager.h>
+#include <API/Bluetooth/BluetoothFactory.h>
+#include <glib.h>
+#include <bluetooth.h>
+#include <API/Bluetooth/BluetoothProperty.h>
+
+using namespace TizenApis::Api;
+using namespace TizenApis::Api::Bluetooth;
+
+namespace TizenApis {
+namespace Platform {
+namespace Bluetooth {
+
+class BluetoothAdapterManager : public Api::Bluetooth::IBluetoothAdapterManager
+{
+       friend class TizenApis::Api::Bluetooth::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/platform/Tizen/Bluetooth/BluetoothCBManager.cpp b/src/platform/Tizen/Bluetooth/BluetoothCBManager.cpp
new file mode 100644 (file)
index 0000000..9da4088
--- /dev/null
@@ -0,0 +1,593 @@
+//
+// 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(TizenApis::Platform::Bluetooth::BluetoothCBManager);
+
+namespace TizenApis {
+namespace Platform {
+namespace Bluetooth {
+
+using namespace Platform;
+
+
+
+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 (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/platform/Tizen/Bluetooth/BluetoothCBManager.h b/src/platform/Tizen/Bluetooth/BluetoothCBManager.h
new file mode 100644 (file)
index 0000000..612ee04
--- /dev/null
@@ -0,0 +1,97 @@
+//
+// 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 TizenApis {
+namespace Platform {
+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/platform/Tizen/Bluetooth/BluetoothDeviceManager.cpp b/src/platform/Tizen/Bluetooth/BluetoothDeviceManager.cpp
new file mode 100644 (file)
index 0000000..fc77364
--- /dev/null
@@ -0,0 +1,342 @@
+//
+// 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 TizenApis::Api;
+using namespace WrtDeviceApis;
+
+
+namespace TizenApis {
+namespace Platform {
+namespace Bluetooth {
+
+using namespace Platform;
+
+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/platform/Tizen/Bluetooth/BluetoothDeviceManager.h b/src/platform/Tizen/Bluetooth/BluetoothDeviceManager.h
new file mode 100644 (file)
index 0000000..9880464
--- /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.
+//
+
+#ifndef TIZENAPIS_TIZEN_BLUETOOTH_DEVICE_MANAGER_H_
+#define TIZENAPIS_TIZEN_BLUETOOTH_DEVICE_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <API/Bluetooth/IBluetoothDeviceManager.h>
+#include <API/Bluetooth/BluetoothFactory.h>
+#include <bluetooth.h>
+#include <API/Bluetooth/BluetoothProperty.h>
+
+using namespace TizenApis::Api;
+using namespace TizenApis::Api::Bluetooth;
+
+namespace TizenApis {
+namespace Platform {
+namespace Bluetooth {
+
+class BluetoothDeviceManager : public Api::Bluetooth::IBluetoothDeviceManager
+{
+       friend class TizenApis::Api::Bluetooth::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/platform/Tizen/Bluetooth/BluetoothServiceHandlerManager.cpp b/src/platform/Tizen/Bluetooth/BluetoothServiceHandlerManager.cpp
new file mode 100644 (file)
index 0000000..45ff768
--- /dev/null
@@ -0,0 +1,171 @@
+//
+// 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 <API/Bluetooth/BluetoothProperty.h>
+#include <API/Bluetooth/BTDevice.h>
+
+
+namespace TizenApis {
+namespace Platform {
+namespace Bluetooth {
+
+using namespace Platform;
+
+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);
+
+       Api::Bluetooth::EventBTServiceOnConnectPtr event(new Api::Bluetooth::EventBTServiceOnConnect());
+
+       if (result == BT_ERROR_NONE)
+       {
+               if (connection_state == BT_SOCKET_CONNECTED)
+               {
+       
+                       Api::Bluetooth::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 Api::Bluetooth::EventBTServiceOnConnectEmitterPtr& emitter)
+{
+       // pass uuid for server socket
+       BluetoothCBManagerSingleton::Instance().addConnectionStateCallback(m_Uuid, 
+                               (void*)this, BluetoothCBManager::FROM_SERVICE);
+
+       LogDebug("setServiceHandlerListener - OK");
+       m_emitter = emitter;
+}
+
+
+std::string BluetoothServiceHandlerManager::getUUID()
+{
+       return m_Uuid;
+}
+
+void BluetoothServiceHandlerManager::setUUID(std::string uuid)
+{
+       m_Uuid = uuid;
+}
+
+void BluetoothServiceHandlerManager::unRegister(const Api::Bluetooth::EventBTUnregisterRFCOMMServicePtr &event)
+{
+       LogDebug("Enter");
+       WrtDeviceApis::Commons::EventRequestReceiver<Api::Bluetooth::EventBTUnregisterRFCOMMService>::PostRequest(event);
+}
+
+void BluetoothServiceHandlerManager::OnRequestReceived(const Api::Bluetooth::EventBTUnregisterRFCOMMServicePtr& event) 
+{
+       LogDebug("Enter");
+       
+       try 
+       {
+               std::map<std::string, Api::Bluetooth::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/platform/Tizen/Bluetooth/BluetoothServiceHandlerManager.h b/src/platform/Tizen/Bluetooth/BluetoothServiceHandlerManager.h
new file mode 100644 (file)
index 0000000..c2ff976
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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 <API/Bluetooth/IBluetoothServiceHandlerManager.h>
+#include <API/Bluetooth/BluetoothFactory.h>
+#include <bluetooth.h>
+#include <dpl/mutex.h>
+#include <vector>
+#include <bluetooth.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Bluetooth {
+
+class BluetoothServiceHandlerManager : public Api::Bluetooth::IBluetoothServiceHandlerManager
+{
+       friend class TizenApis::Api::Bluetooth::BluetoothFactory;
+public:
+       virtual ~BluetoothServiceHandlerManager();
+       virtual void unRegister(const Api::Bluetooth::EventBTUnregisterRFCOMMServicePtr &event);
+       virtual void setServiceHandlerListener(const Api::Bluetooth::EventBTServiceOnConnectEmitterPtr& emitter);
+       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;
+       Api::Bluetooth::EventBTServiceOnConnectEmitterPtr m_emitter;
+protected:
+       BluetoothServiceHandlerManager();
+       virtual void OnRequestReceived(const Api::Bluetooth::EventBTUnregisterRFCOMMServicePtr& event) ;
+};
+
+}
+}
+}
+
+#endif
+
diff --git a/src/platform/Tizen/Bluetooth/BluetoothSocketManager.cpp b/src/platform/Tizen/Bluetooth/BluetoothSocketManager.cpp
new file mode 100644 (file)
index 0000000..887144b
--- /dev/null
@@ -0,0 +1,187 @@
+//
+// 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>
+
+using namespace TizenApis::Api;
+
+
+namespace TizenApis {
+namespace Platform {
+namespace Bluetooth {
+
+using namespace Platform;
+
+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/platform/Tizen/Bluetooth/BluetoothSocketManager.h b/src/platform/Tizen/Bluetooth/BluetoothSocketManager.h
new file mode 100644 (file)
index 0000000..f567da2
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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 <API/Bluetooth/IBluetoothSocketManager.h>
+#include <API/Bluetooth/BluetoothFactory.h>
+#include <bluetooth.h>
+#include <dpl/mutex.h>
+#include <vector>
+
+using namespace TizenApis::Api;
+using namespace TizenApis::Api::Bluetooth;
+
+namespace TizenApis {
+namespace Platform {
+namespace Bluetooth {
+
+
+class BluetoothSocketManager : public Api::Bluetooth::IBluetoothSocketManager
+{
+       friend class TizenApis::Api::Bluetooth::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_ */
+
diff --git a/src/platform/Tizen/Bluetooth/config.cmake b/src/platform/Tizen/Bluetooth/config.cmake
new file mode 100644 (file)
index 0000000..ead810c
--- /dev/null
@@ -0,0 +1,22 @@
+get_current_path()
+
+pkg_search_module(capi-network-bluetooth REQUIRED capi-network-bluetooth)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_BLUETOOTH
+       ${capi-network-bluetooth_INCLUDE_DIRS}
+       PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_BLUETOOTH
+       ${capi-network-bluetooth_LIBRARIES}
+       PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_BLUETOOTH
+  ${CURRENT_PATH}/BluetoothAdapterManager.cpp
+  ${CURRENT_PATH}/BluetoothDeviceManager.cpp
+  ${CURRENT_PATH}/BluetoothSocketManager.cpp
+  ${CURRENT_PATH}/BluetoothServiceHandlerManager.cpp
+  ${CURRENT_PATH}/BluetoothCBManager.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/Calendar/Calendar.cpp b/src/platform/Tizen/Calendar/Calendar.cpp
new file mode 100755 (executable)
index 0000000..e534c96
--- /dev/null
@@ -0,0 +1,1313 @@
+//
+// 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 <calendar2.h>
+#include <dpl/log/log.h>
+#include <dpl/scoped_ptr.h>
+#include "Calendar.h"
+#include "CalendarManager.h"
+#include "CalendarFilter.h"
+#include "CalendarFilterValidator.h"
+#include "API/Calendar/OnEventsChanged.h"
+#include "API/Calendar/IEventWatchChanges.h"
+#include "API/Calendar/IEventClearWatch.h"
+#include "API/Calendar/EventId.h"
+#include <API/Filter/IFilter.h>
+#include <API/Filter/IFilterVisitor.h>
+#include <sstream>
+#include <algorithm>
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Platform {
+namespace Calendar {
+
+Calendar::Calendar()
+{
+}
+
+Calendar::~Calendar()
+{
+}
+
+void Calendar::OnRequestReceived(const IEventAddEventPtr &event)
+{
+    Try
+    {
+        if (!event->getEvent()) {
+            ThrowMsg(NullPointerException, "event parameter is NULL");
+        }
+        if (event->getEvent()->getIdIsSet()) {
+            LogWarning("adding event that is already added");
+            event->getEvent()->resetId();
+        }
+        DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(event->getEvent(), getType()));
+        event->getEvent()->setCalendarType(getType());
+        eventWrapper->convertAbstractEventToPlatformEvent();
+
+        eventWrapper->setCalendarId(getId());
+        eventWrapper->setCalendarAccountId(getAccountId());
+        eventWrapper->saveEvent();
+        event->setResult(true);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventAddEventsPtr &event)
+{
+    calendar_list_h listForAdd = NULL;
+
+    Try
+    {
+        if (event->getEvents()->empty()) {
+            ThrowMsg(NullPointerException, "Items array is empty.");
+        }
+
+        int ret, count = 0;
+        calendar_record_h record = NULL;
+        int* ids = NULL;
+
+        ret = calendar_list_create(&listForAdd);
+        if (CALENDAR_ERROR_NONE != ret) {
+            ThrowMsg(PlatformException, "Can't create a list: "<<ret);
+        }
+
+        for(unsigned int i=0; i<event->getEvents()->size(); i++) {
+            if (event->getEvents()->at(i)->getIdIsSet()) {
+                LogWarning("Item has index: " << i << ". Resetting it.");
+                event->getEvents()->at(i)->resetId();
+            }
+            DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(event->getEvents()->at(i), getType()));
+            event->getEvents()->at(i)->setCalendarType(getType());
+            eventWrapper->convertAbstractEventToPlatformEvent();
+
+            eventWrapper->setCalendarId(getId());
+            eventWrapper->setCalendarAccountId(getAccountId());
+
+            // Clone the record because the platform event will be freed by destructor.
+            record = NULL;
+            ret = calendar_record_clone(eventWrapper->getPlatformEvent(), &record);
+            if(CALENDAR_ERROR_NONE!=ret) {
+                ThrowMsg(PlatformException, "Clonning failed: "<<ret);
+            }
+
+            ret = calendar_list_add(listForAdd, record);
+            if (CALENDAR_ERROR_NONE != ret) {
+                ThrowMsg(PlatformException, "Can't add the item to the list: "<<ret);
+            }
+        }
+
+        ret = calendar_db_insert_records(listForAdd, &ids, &count);
+        if (CALENDAR_ERROR_NONE != ret) {
+            ThrowMsg(PlatformException, "Can't insert the item list: "<<ret);
+        } else {
+            LogDebug("Add records requst done with count: "<<count);
+        }
+
+        for(int i=0; i<count; i++) {
+            event->getEvents()->at(i)->setId(ids[i]);
+        }
+
+               if(ids) {
+                       free(ids);
+               }
+
+        event->setResult(true);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+
+    if(listForAdd) {
+        calendar_list_destroy(listForAdd, true);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventUpdateEventPtr &event)
+{
+    calendar_query_h query = NULL;
+    calendar_filter_h filter = NULL;
+
+    Try
+    {
+        if (!event->getEvent()) {
+            ThrowMsg(NullPointerException, "Item object is NULL.");
+        }
+
+        CalendarEventPtr theItem = event->getEvent();
+        if (!theItem->getIdIsSet()) {
+            ThrowMsg(InvalidArgumentException, "Item id is not set.");
+        }
+
+        int ret;
+
+        const char *dataType;
+        if(getType() == CalendarEvent::TASK_TYPE) {
+            dataType = _calendar_todo._uri;
+        } else {
+            dataType = _calendar_event._uri;
+        }
+
+        DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(theItem, getType()));
+        eventWrapper->convertAbstractEventToPlatformEvent(true);
+
+        if ( event->getUpdateAllInstances() || 0>=theItem->getRecurrenceRule()->getFrequency()) {
+            // Platform detects the detached events and uptates all instances.
+            eventWrapper->saveEvent();
+        } else {
+            LogDebug("Update the exdate for a recurring parent event and add a new child event.");
+
+            // First update the parent event.
+            EventRecurrenceRulePtr rrule = theItem->getRecurrenceRule();
+            (*rrule->getExceptions()).push_back(theItem->getRecurrenceId());
+
+            std::string exdate = "";
+            for( unsigned int i=0; i<rrule->getExceptions()->size(); i++ ) {
+                std::stringstream ss;
+                ss<<rrule->getExceptions()->at(i);
+                exdate.append(ss.str());
+                if(i!=rrule->getExceptions()->size()-1) {
+                    exdate.append(",");
+                }
+            }
+            ret = calendar_record_set_str(eventWrapper->getPlatformEvent(), _calendar_event.exdate, exdate.c_str());
+            if(ret!=CALENDAR_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Can't update the exdate: "<<ret);
+            } else {
+                LogDebug("Set the exdate for the parent event: "<<exdate);
+            }
+
+            // Don't set the recurrence id for the parent event.
+            ret = calendar_record_set_str(eventWrapper->getPlatformEvent(), _calendar_event.recurrence_id, NULL);
+            if (CALENDAR_ERROR_NONE != ret) {
+                ThrowMsg(PlatformException, "Can't set recurrence id.");
+            }
+
+            eventWrapper->saveEvent();
+
+            // Now add the detached child event.
+            EventRecurrenceRulePtr emptyRRule( new EventRecurrenceRule() );
+            // Detached event should not have rrule set.
+            theItem->setRecurrenceRule(emptyRRule);
+
+            theItem->setParentId(theItem->getId());
+
+            // Convert the modified child event.
+            eventWrapper->convertAbstractEventToPlatformEvent();
+
+            // Reset id for record insertion.
+            theItem->resetId();
+            eventWrapper->saveEvent();
+
+            theItem->setIsDetached(true);
+        }
+
+        event->setResult(true);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+
+    if(query) {
+        calendar_query_destroy(query);
+    }
+    if(filter) {
+        calendar_filter_destroy(filter);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventUpdateEventsPtr &event)
+{
+    calendar_list_h listForUpdate = NULL;
+    calendar_list_h listForAdd = NULL;
+    calendar_query_h query =   NULL;
+    calendar_filter_h filter = NULL;
+
+    Try
+    {
+        if (event->getEvents()->empty()) {
+            ThrowMsg(NullPointerException, "Item array is empty.");
+        }
+
+        int ret, count = -1;
+        calendar_record_h record = NULL;
+
+        const char *dataType;
+        if(getType() == CalendarEvent::TASK_TYPE) {
+            dataType = _calendar_todo._uri;
+        } else {
+            dataType = _calendar_event._uri;
+        }
+
+        ret = calendar_list_create(&listForUpdate);
+        if (CALENDAR_ERROR_NONE != ret) {
+            ThrowMsg(PlatformException, "Can't create a list for update: "<<ret);
+        }
+        ret = calendar_list_create(&listForAdd);
+        if (CALENDAR_ERROR_NONE != ret) {
+            ThrowMsg(PlatformException, "Can't create a list for add: "<<ret);
+        }
+
+        for(unsigned int i=0; i<event->getEvents()->size(); i++) {
+            CalendarEventPtr thisEvent = event->getEvents()->at(i);
+            if (!thisEvent->getIdIsSet()) {
+                ThrowMsg(InvalidArgumentException, "Item id is not set.");
+            }
+
+            DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(thisEvent, getType()));
+            eventWrapper->convertAbstractEventToPlatformEvent(true);
+
+            if( true==thisEvent->getIsDetached() ) {
+                // Treat the detached event same as the parent event.
+                record = NULL;
+                ret = calendar_record_clone(eventWrapper->getPlatformEvent(), &record);
+                if(CALENDAR_ERROR_NONE!=ret) {
+                    ThrowMsg(PlatformException, "Clonning failed: "<<ret);
+                }
+
+                ret = calendar_list_add(listForUpdate, record);
+                if (CALENDAR_ERROR_NONE != ret) {
+                    ThrowMsg(PlatformException, "Can't add the detached item to the list: "<<ret);
+                } else {
+                    LogDebug("Added the detached event to the update list: "<<thisEvent->getId());
+                }
+            } else if (event->getUpdateAllInstances() || 0>=thisEvent->getRecurrenceRule()->getFrequency()) {
+                // Platform detects the detached events and uptates all instances.
+                record = NULL;
+                ret = calendar_record_clone(eventWrapper->getPlatformEvent(), &record);
+                if(CALENDAR_ERROR_NONE!=ret) {
+                    ThrowMsg(PlatformException, "Clonning failed: "<<ret);
+                }
+
+                ret = calendar_list_add(listForUpdate, record);
+                if (CALENDAR_ERROR_NONE != ret) {
+                    ThrowMsg(PlatformException, "Can't add the item to the list: "<<ret);
+                }
+            } else {
+                LogDebug("Update the exdate for a recurring parent event and add a new child event.");
+                DPL::ScopedPtr<EventWrapper> eventWrapperChild(new EventWrapper(thisEvent, getType()));
+                eventWrapperChild->convertAbstractEventToPlatformEvent(true);
+
+                std::stringstream ss;
+                ss<<thisEvent->getRecurrenceId();
+                ret = calendar_record_set_str(eventWrapperChild->getPlatformEvent(), _calendar_event.recurrence_id, ss.str().c_str());
+                if (CALENDAR_ERROR_NONE != ret) {
+                    ThrowMsg(PlatformException, "Cannot set event recurrence id: "<<ret);
+                } else {
+                    LogDebug("Saved the rid for the child: "<<thisEvent->getRecurrenceId());
+                }
+
+                ret = calendar_record_set_int(eventWrapperChild->getPlatformEvent(), _calendar_event.original_event_id, thisEvent->getId());
+                if (CALENDAR_ERROR_NONE != ret) {
+                    ThrowMsg(PlatformException, "Cannot set the parent id: "<<ret);
+                }
+
+                ret = calendar_record_set_int(eventWrapperChild->getPlatformEvent(), _calendar_event.freq, CALENDAR_RECURRENCE_NONE);
+                if (CALENDAR_ERROR_NONE != ret) {
+                    ThrowMsg(PlatformException, "Cannot set the frequency: "<<ret);
+                }
+
+                record = NULL;
+                ret = calendar_record_clone(eventWrapperChild->getPlatformEvent(), &record);
+                if(CALENDAR_ERROR_NONE!=ret) {
+                    ThrowMsg(PlatformException, "Clonning the child event failed: "<<ret);
+                }
+
+                ret = calendar_list_add(listForAdd, record);
+                if (CALENDAR_ERROR_NONE != ret) {
+                    ThrowMsg(PlatformException, "Can't add the item to the add list: "<<ret);
+                }
+
+                thisEvent->setIsDetached(true);
+
+                // Now update the parent event.
+                EventRecurrenceRulePtr rrule = thisEvent->getRecurrenceRule();
+                (*rrule->getExceptions()).push_back(thisEvent->getRecurrenceId());
+
+                std::string exdate = "";
+                for( unsigned int j=0; j<rrule->getExceptions()->size(); j++ ) {
+                    std::stringstream ss;
+                    ss<<rrule->getExceptions()->at(j);
+                    exdate.append(ss.str());
+                    if(j!=rrule->getExceptions()->size()-1) {
+                        exdate.append(",");
+                    }
+                }
+                ret = calendar_record_set_str(eventWrapper->getPlatformEvent(), _calendar_event.exdate, exdate.c_str());
+                if(ret!=CALENDAR_ERROR_NONE) {
+                    ThrowMsg(PlatformException, "Can't update the exdate: "<<ret);
+                } else {
+                    LogDebug("Set the exdate for the parent event: "<<exdate);
+                }
+
+                record = NULL;
+                ret = calendar_record_clone(eventWrapper->getPlatformEvent(), &record);
+                if(CALENDAR_ERROR_NONE!=ret) {
+                    ThrowMsg(PlatformException, "Clonning the child event failed: "<<ret);
+                }
+
+                ret = calendar_list_add(listForUpdate, record);
+                if (CALENDAR_ERROR_NONE != ret) {
+                    ThrowMsg(PlatformException, "Can't add the item to the update list: "<<ret);
+                }
+            }
+        }
+
+        // Perform the platform operations.
+        count = -1;
+        ret = calendar_list_get_count(listForAdd, &count);
+        if(CALENDAR_ERROR_NONE!=ret){
+            ThrowMsg(PlatformException, "Getting list count failed: "<<ret);
+        } else {
+            LogDebug("Final list count for add: "<<count);
+        }
+        if(count>0) {
+            ret = calendar_db_insert_records(listForAdd, NULL, NULL);
+            if (CALENDAR_ERROR_NONE != ret) {
+                ThrowMsg(PlatformException, "Can't insert the item list: "<<ret);
+            } else {
+                LogDebug("Add records requst done for update batch operation.");
+            }
+        }
+
+        count = -1;
+        ret = calendar_list_get_count(listForUpdate, &count);
+        if(CALENDAR_ERROR_NONE!=ret){
+            ThrowMsg(PlatformException, "Getting list count failed: "<<ret);
+        } else {
+            LogDebug("Final list count for update: "<<count);
+        }
+        if(count>0) {
+            ret = calendar_db_update_records(listForUpdate);
+            if (CALENDAR_ERROR_NONE != ret) {
+                ThrowMsg(PlatformException, "Can't update the item list: "<<ret);
+            } else {
+                LogDebug("Update records requst done for update batch operation.");
+            }
+        }
+
+        event->setResult(true);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+
+    if(listForAdd) {
+        calendar_list_destroy(listForAdd, true);
+    }
+    if(listForUpdate) {
+        calendar_list_destroy(listForUpdate, true);
+    }
+    if(query) {
+        calendar_query_destroy(query);
+    }
+    if(filter) {
+        calendar_filter_destroy(filter);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventDeleteEventPtr &event)
+{
+    Try
+    {
+        if (!event->getEventId()) {
+            ThrowMsg(NullPointerException, "Item id is not set.");
+        }
+
+        DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(getType()));
+        event->getEventId()->setCalendarType(getType());
+        std::istringstream stream(event->getEventId()->getUId());
+        int id = -1;
+        stream>>id;
+        eventWrapper->getAbstractEvent()->setId(id);
+
+        std::stringstream ss(event->getEventId()->getRecurrenceId());
+        long long int rid;
+        ss>>rid;
+
+        LogDebug("id: " << id << ", rid: " << rid);
+
+        eventWrapper->loadEvent(id);
+
+        eventWrapper->setCalendarId(getId());
+        eventWrapper->setCalendarAccountId(getAccountId());
+
+        // recurrence id is reset while loading the platform event.
+        eventWrapper->getAbstractEvent()->setRecurrenceId(rid);
+
+        eventWrapper->deleteEvent();
+        event->setResult(true);
+    }
+    Catch (NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::NotFoundException);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventGetPtr &event)
+{
+    Try
+    {
+        if (!event->getItemId()) {
+            ThrowMsg(NullPointerException, "Id parameter is NULL");
+        }
+
+        DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(getType()));
+        std::stringstream ss(event->getItemId()->getUId());
+        int id = -1;
+        ss>>id;
+
+        eventWrapper->loadEvent(id);
+
+        event->setItem(eventWrapper->getAbstractEvent());
+        event->setResult(true);
+    }
+    Catch (NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::NotFoundException);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventDeleteEventsPtr &event)
+{
+    calendar_list_h listForUpdate = NULL;
+    calendar_query_h query = NULL;
+    calendar_filter_h filter = NULL;
+
+    Try
+    {
+        if (event->getEventIds()->empty()) {
+            ThrowMsg(NullPointerException, "Item id array is empty.");
+        }
+
+        std::vector<int> listForDelete;
+        std::vector<int> listForDetached;
+        std::vector<int> listForDetachedParent;
+
+        int ret, id, count;
+        long long int rid;
+        calendar_record_h item, record;
+        const char *dataType = NULL;
+
+        ret = calendar_list_create(&listForUpdate);
+        if (CALENDAR_ERROR_NONE != ret) {
+            ThrowMsg(PlatformException, "Can't create a list for update: "<<ret);
+        }
+
+        for(unsigned int i=0; i<event->getEventIds()->size(); i++) {
+            DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(getType()));
+            event->getEventIds()->at(i)->setCalendarType(getType());
+
+            std::istringstream stream(event->getEventIds()->at(i)->getUId());
+            stream>>id;
+            eventWrapper->getAbstractEvent()->setId(id);
+
+            eventWrapper->loadEvent(id);
+            item = eventWrapper->getPlatformEvent();
+
+            std::stringstream ss(event->getEventIds()->at(i)->getRecurrenceId());
+            ss>>rid;
+            eventWrapper->getAbstractEvent()->setRecurrenceId(rid);
+
+            // If the recurrenceId is set, delete the instance of recurring event only.
+            LogDebug("id to delete: "<<id<<", rid: "<<rid<<", type: "<< getType());
+
+            dataType = NULL;
+            if(getType() == CalendarEvent::TASK_TYPE) {
+                dataType = _calendar_todo._uri;
+            } else {
+                dataType = _calendar_event._uri;
+            }
+
+            /* Platform detects the detached events and deletes them automatically.
+            But if both parent and detached ids are added to the list, platform error is returned. */
+            if ( 0>=rid ) {
+                listForDelete.push_back(id);
+            } else if (true==eventWrapper->getAbstractEvent()->getIsDetached() ) {
+                listForDetached.push_back(id);
+
+                int parentId;
+                ret = calendar_record_get_int(eventWrapper->getPlatformEvent(), _calendar_event.original_event_id, &parentId);
+                if (CALENDAR_ERROR_NONE != ret) {
+                    ThrowMsg(PlatformException, "Can't get the parent id: "<<ret);
+                }
+                listForDetachedParent.push_back(parentId);
+                LogDebug("Added the detached event id: "<<id<<", parent id: "<<parentId);
+            } else {
+                EventRecurrenceRulePtr rrule = eventWrapper->getAbstractEvent()->getRecurrenceRule();
+                (*rrule->getExceptions()).push_back(rid);
+
+                std::string exdate = "";
+                for( unsigned int i=0; i<rrule->getExceptions()->size(); i++ ) {
+                    std::stringstream ss;
+                    ss<<rrule->getExceptions()->at(i);
+                    exdate.append(ss.str());
+                    if(i!=rrule->getExceptions()->size()-1) {
+                        exdate.append(",");
+                    }
+                }
+                ret = calendar_record_set_str(item, _calendar_event.exdate, exdate.c_str());
+                if(ret!=CALENDAR_ERROR_NONE) {
+                    ThrowMsg(PlatformException, "Can't delete the instance: "<<ret);
+                } else {
+                    LogDebug("Set the exdate: "<<exdate);
+                }
+
+                record = NULL;
+                ret = calendar_record_clone(item, &record);
+                if(CALENDAR_ERROR_NONE!=ret) {
+                    ThrowMsg(PlatformException, "Clonning failed: "<<ret);
+                }
+
+                ret = calendar_list_add(listForUpdate, record);
+                if (CALENDAR_ERROR_NONE != ret) {
+                    ThrowMsg(PlatformException, "Can't add the item to the list: "<<ret);
+                }
+                LogDebug("Calendar item instance added for update.");
+            }
+        }
+
+        // Perform the platform operations.
+        // Uptate operatoin should be done first not to update records after deletion.
+        count = -1;
+        ret = calendar_list_get_count(listForUpdate, &count);
+        if(CALENDAR_ERROR_NONE!=ret){
+            LogWarning("Getting list count for update failed: "<<ret);
+        } else {
+            LogDebug("Final list count for update: "<<count);
+        }
+        if(count>0) {
+            ret = calendar_db_update_records(listForUpdate);
+            if (CALENDAR_ERROR_NONE != ret) {
+                ThrowMsg(PlatformException, "Can't update the item list: "<<ret);
+            } else {
+                LogDebug("Update records requst done for update batch operation.");
+            }
+        }
+
+        // Merge the detached event id list if the parent is not included in the delete list.
+        count = listForDetached.size();
+        LogDebug("Number of detached events: "<<count);
+        while(count--) {
+            std::vector<int>::iterator it;
+            it = std::find(listForDelete.begin(), listForDelete.end(), listForDetachedParent.at(count));
+            if(listForDelete.end()==it) {
+                listForDelete.push_back(listForDetached.at(count));
+                LogDebug("Add the detached event id to the delete list: "<<listForDetached.at(count));
+            } else {
+                LogDebug("The parent id is already included to the delete list: "<<listForDetachedParent.at(count));
+            }
+        }
+        count = listForDelete.size();
+
+        LogDebug("Final list count for deletion: "<<count);
+        if(count>0) {
+            ret = calendar_db_delete_records(dataType, &listForDelete[0], count);
+            if (CALENDAR_ERROR_NONE != ret) {
+                ThrowMsg(PlatformException, "Can't delete the records: "<<ret);
+            } else {
+                LogDebug("Delete records requst done for delete batch operation.");
+            }
+        }
+
+        event->setResult(true);
+    }
+    Catch (NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::NotFoundException);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+
+    if(query) {
+        calendar_query_destroy(query);
+    }
+    if(filter) {
+        calendar_filter_destroy(filter);
+    }
+    if(listForUpdate) {
+        calendar_list_destroy(listForUpdate, true);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventFindEventsPtr &event)
+{
+    Try
+    {
+        CalendarFilterPtr calendarFilter( new CalendarFilter() );
+
+        calendarFilter->setType(getType());
+        LogDebug("Default filter created with type "<<getType());
+
+               TizenApis::Api::Tizen::IFilterVisitorPtr filterTraversal = DPL::StaticPointerCast<TizenApis::Api::Tizen::IFilterVisitor>(calendarFilter);
+
+        int calendarId;
+        std::stringstream ss(getId());
+        ss>>calendarId;
+               if (event->getGenericFilterIsSet()) {
+            TizenApis::Api::Tizen::FilterPtr genericFilter = event->getGenericFilter();
+
+            TizenApis::Api::Tizen::FilterValidatorPtr validator = CalendarFilterValidatorFactory::getCalendarFilterValidator();
+            bool success = genericFilter->validate(validator);
+            if(!success) {
+                ThrowMsg(InvalidArgumentException, "Invalid filter arguments.");
+            } else {
+                LogDebug("Filter validation has passed.");
+            }
+
+                       genericFilter->travel(filterTraversal, 0);
+
+            LogDebug("Set additional calendar id: "<<calendarId);
+            calendarFilter->setCalendarId(calendarId, true);
+               } else {
+            LogDebug("Set calendar id: "<<calendarId);
+            calendarFilter->setCalendarId(calendarId, false);
+               }
+
+               if (event->getSortModesIsSet()) {
+                       calendarFilter->setSortMode(event->getSortModes());
+               }
+
+               calendarFilter->executeQuery();
+
+               LogDebug("Return the query result after conversion.");
+
+        calendar_list_h resultList = calendarFilter->getResultRecordList();
+        int ret;
+        int count = calendarFilter->getResultRecordCount();
+        calendar_record_h currentRecord = NULL;
+
+        calendar_list_first(resultList);
+
+        while(count--) {
+            currentRecord = NULL;
+            ret = calendar_list_get_current_record_p(resultList, &currentRecord);
+            if ( CALENDAR_ERROR_NONE != ret ) {
+                ThrowMsg(PlatformException, "Can't get current record: "<<ret);
+            }
+
+            DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(currentRecord, getType()));
+            event->addEvent(eventWrapper->convertPlatformEventToAbstractEvent());
+
+            calendar_list_next(resultList);
+        }
+        LogDebug("Length of found events: "<<event->getEvents()->size());
+
+        event->setResult(true);
+    }
+    Catch (InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+    Catch (NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::NotFoundException);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventCreateEventFromStringPtr &event)
+{
+    Try
+    {
+        DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(getType()));
+        eventWrapper->createEventFromString(event->getEventString());
+        event->setEvent(eventWrapper->convertPlatformEventToAbstractEvent());
+        event->getEvent()->setCalendarType(getType());
+        event->setResult(true);
+    }
+    Catch(PlatformException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogDebug("eventString: " + event->getEventString());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        LogDebug("eventString: " + event->getEventString());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventExportEventToStringPtr &event)
+{
+    Try
+    {
+        if (!event->getEvent()) {
+            ThrowMsg(NullPointerException, "event parameter is NULL");
+        }
+
+        DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(event->getEvent(), getType()));
+        event->getEvent()->setCalendarType(getType());
+        eventWrapper->convertAbstractEventToPlatformEvent();
+        event->setEventString(eventWrapper->exportEventToString());
+        event->setResult(true);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+static void eventChangedCb(const char *view_uri, void *user_data)
+{
+    LogDebug("Items change cb with view_uri: "<<view_uri);
+
+    OnEventsChangedPtr eventPtr(new OnEventsChanged());
+    calendar_list_h list = NULL;
+
+    Try
+    {
+       if (user_data == NULL) {
+            LogDebug("user_data is NULL.");
+               return;
+       }
+
+        Calendar *thisCalendar = (Calendar*) user_data;
+
+        int ret, id, type, updatedVersion, calendarId, count = 0;
+
+
+        std::stringstream ss(thisCalendar->getId());
+        ss>>calendarId;
+
+        LogDebug("Getting items with calendar id: "<<calendarId<<", version: "<<thisCalendar->getLastChangedVersion()<<", type: "<<thisCalendar->getType());
+        if (CalendarEvent::TASK_TYPE==thisCalendar->getType()) {
+            ret = calendar_db_get_changes_by_version(_calendar_todo._uri, calendarId, thisCalendar->getLastChangedVersion(), &list, &updatedVersion);
+        } else {
+            ret = calendar_db_get_changes_by_version(_calendar_event._uri, calendarId, thisCalendar->getLastChangedVersion(), &list, &updatedVersion);
+        }
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Can't get the updated item list: "<<ret);
+        }
+
+        ret = calendar_list_get_count(list, &count);
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Can't get the item count: "<<ret);
+        } else {
+            LogDebug("Item count: "<<count);
+        }
+
+        calendar_list_first(list);
+
+        calendar_record_h currentRecord = NULL;
+        while(count--)
+        {
+            currentRecord = NULL;
+            ret = calendar_list_get_current_record_p(list, &currentRecord);
+            if ( CALENDAR_ERROR_NONE != ret ) {
+                ThrowMsg(PlatformException, "Can't get current record: "<<ret);
+            }
+
+            ret = calendar_record_get_int(currentRecord, _calendar_updated_info.id ,&id);
+            if ( CALENDAR_ERROR_NONE != ret ) {
+                ThrowMsg(PlatformException, "Can't get updated info id: "<<ret);
+            }
+
+            ret = calendar_record_get_int(currentRecord, _calendar_updated_info.modified_status ,&type);
+            if ( CALENDAR_ERROR_NONE != ret ) {
+                ThrowMsg(PlatformException, "Can't get updated info modified status: "<<ret);
+            }
+
+            LogDebug("id "<<id<<", type "<<type);
+            if ( CALENDAR_EVENT_MODIFIED_STATUS_INSERTED==type ) {
+                eventPtr->setStatus(OnEventsChanged::ON_ADD);
+            } else if ( CALENDAR_EVENT_MODIFIED_STATUS_UPDATED==type ) {
+                eventPtr->setStatus(OnEventsChanged::ON_UPDATE);
+            } else if ( CALENDAR_EVENT_MODIFIED_STATUS_DELETED==type ) {
+                eventPtr->setStatus(OnEventsChanged::ON_DELETE);
+            } else {
+                LogWarning("Wrong change type.");
+                calendar_list_next(list);
+                continue;
+            }
+
+            DPL::ScopedPtr<EventWrapper> eventWrapper(new EventWrapper(thisCalendar->getType()));
+            Try {
+                eventWrapper->loadEvent(id);
+            } Catch (NotFoundException){
+                LogDebug("Handling deleted event with index: "<<id);
+            }
+            eventPtr->addEvent(eventWrapper->getAbstractEvent());
+
+            calendar_list_next(list);
+        }
+
+        ret = calendar_db_get_current_version(&updatedVersion);
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Can't get new version: "<<ret);
+        }
+
+        thisCalendar->setLastChangedVersion(updatedVersion);
+        LogDebug("Last change fetch version: "<<thisCalendar->getLastChangedVersion());
+
+        eventPtr->setResult(true);
+        eventPtr->setCalendarType(thisCalendar->getType());
+
+        if( eventPtr->getEventList()->size() > 0 ) {
+            thisCalendar->m_changeEmitters.emit(eventPtr);
+        } else {
+            LogDebug("No actual changes. Skip signal emission.");
+        }
+    }
+    Catch (Exception)
+    {   
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+
+    if( list ) {
+        calendar_list_destroy(list, true);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventWatchChangesPtr &event)
+{
+    Try
+    {
+        // Subscribe the watch to the platform just once.
+        int ret;
+        if( m_changeEmitters.size()==0 )
+        {
+            const char *dataType;
+            if(getType() == CalendarEvent::TASK_TYPE) {
+                dataType = _calendar_todo._uri;
+            } else {
+                dataType = _calendar_event._uri;
+            }
+
+            ret = calendar_db_add_changed_cb(dataType, eventChangedCb, this);
+            if( CALENDAR_ERROR_NONE!=ret ) {
+                ThrowMsg(PlatformException, "Can't add db changed cb: "<<ret);
+            } else {
+                // Save the last change fetch version to start watching.
+                int version;
+                ret = calendar_db_get_current_version(&version);
+                if( CALENDAR_ERROR_NONE!=ret ) {
+                    ThrowMsg(PlatformException, "Can't get version: "<<ret);
+                } else {
+                    setLastChangedVersion(version);
+                    LogDebug("Last change fetch version: "<<getLastChangedVersion());
+                }
+            }
+        }
+
+        m_changeEmitters.attach(event->getEmitter());
+        event->setWatchId(event->getEmitter()->getId());
+        event->setResult(true);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventClearWatchPtr &event)
+{
+    Try
+    {
+        if( m_changeEmitters.detach(event->getWatchId()) ) {
+            if( m_changeEmitters.size()==0 ) {
+                const char *dataType;
+                if(getType() == CalendarEvent::TASK_TYPE) {
+                    dataType = _calendar_todo._uri;
+                } else {
+                    dataType = _calendar_event._uri;
+                }
+
+                if( CALENDAR_ERROR_NONE!=calendar_db_remove_changed_cb(dataType, eventChangedCb, this) ) {
+                    ThrowMsg(PlatformException, "Can't remove change cb.");
+                } else {
+                    LogDebug("Platform watch cleared successfully.");
+                }
+            }
+            event->setResult(true);
+        } else {
+            LogDebug("Wrong watch Id.");
+            event->setResult(false);
+        }
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void Calendar::OnRequestReceived(const IEventExpandEventRecurrencePtr &event)
+{
+    const CalendarEventPtr calEvent = event->getEvent();
+    const long long int startDate = event->getStartDate();
+    const long long int endDate = event->getEndDate();
+    bool isAllDay = calEvent->getIsAllDay();
+
+    calendar_query_h query =   NULL;
+    calendar_filter_h filter = NULL;
+    calendar_list_h list = NULL;
+
+    Try {
+        if ( 0 >= calEvent->getRecurrenceRule()->getFrequency()) {
+            ThrowMsg(InvalidArgumentException, "This is not a recurring event.");
+        }
+
+        calendar_record_h currentRecord = NULL;
+        int ret, currentRecordIndex, count=0;
+        int calendarId;
+        std::stringstream ss(getId());
+        ss>>calendarId;
+
+        calendar_time_s st, et;
+               if( true==isAllDay ) {
+                       st.type = CALENDAR_TIME_LOCALTIME;
+                       struct tm* localTime = localtime((time_t*)&startDate);
+                       st.time.date = {localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday};
+
+                       et.type = CALENDAR_TIME_LOCALTIME;
+                       localTime = localtime((time_t*)&endDate);
+                       et.time.date = {localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday};
+               } else {
+               st.type = CALENDAR_TIME_UTIME;
+               st.time.utime = startDate;
+
+               et.type = CALENDAR_TIME_UTIME;
+               et.time.utime = endDate;
+               }
+
+        if( true==isAllDay ) {
+            ret = calendar_query_create(_calendar_instance_allday_calendar_book._uri, &query);
+        } else {
+            ret = calendar_query_create(_calendar_instance_normal_calendar_book._uri, &query);
+        }
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Creating a query failed: "<<ret);
+        }
+
+        if( true==isAllDay ) {
+            ret = calendar_filter_create(_calendar_instance_allday_calendar_book._uri, &filter);
+        } else {
+            ret = calendar_filter_create(_calendar_instance_normal_calendar_book._uri, &filter);
+        }
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Creating a filter failed: "<<ret);
+        }
+
+        if( true==isAllDay ) {
+            ret = calendar_filter_add_caltime(filter, _calendar_instance_allday_calendar_book.start_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, st);
+        } else {
+            ret = calendar_filter_add_caltime(filter, _calendar_instance_normal_calendar_book.start_time, CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, st);
+        }
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Adding a caltime filter failed: "<<ret);
+        }
+
+        ret = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Adding a filter operator failed: "<<ret);
+        }
+
+        if( true==isAllDay ) {
+            ret = calendar_filter_add_caltime(filter, _calendar_instance_allday_calendar_book.end_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, et);
+        } else {
+            ret = calendar_filter_add_caltime(filter, _calendar_instance_normal_calendar_book.end_time, CALENDAR_MATCH_LESS_THAN_OR_EQUAL, et);
+        }
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Adding a caltime filter failed: "<<ret);
+        }
+
+        ret = calendar_query_set_filter(query, filter);
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Setting a filter: "<<ret);
+        }
+
+        ret = calendar_db_get_records_with_query(query, 0, 0, &list);
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Getting event instances failed: "<<ret);
+        }
+
+        ret = calendar_list_get_count(list, &count);
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Can't get the item count: "<<ret);
+        } else {
+            LogDebug("Item count: "<<count<<", isAllDay: "<<isAllDay);
+        }
+
+        calendar_list_first(list);
+
+               struct tm tmTime = {0};
+
+        while(count--)
+        {
+            currentRecord = NULL;
+            ret = calendar_list_get_current_record_p(list, &currentRecord);
+            if ( CALENDAR_ERROR_NONE != ret ) {
+                ThrowMsg(PlatformException, "Can't get current record: "<<ret);
+            }
+
+            if( true==isAllDay ) {
+                ret = calendar_record_get_int(currentRecord, _calendar_instance_allday_calendar_book.event_id, &currentRecordIndex);
+            } else {
+                ret = calendar_record_get_int(currentRecord, _calendar_instance_normal_calendar_book.event_id, &currentRecordIndex);
+            }
+            if ( CALENDAR_ERROR_NONE != ret ) {
+                ThrowMsg(PlatformException, "Can't get current record id: "<<ret);
+            }
+
+            if(currentRecordIndex==calEvent->getId()) {
+                DPL::ScopedPtr<EventWrapper> recurringEventWrapper(new EventWrapper(getType()));
+                recurringEventWrapper->loadEvent(calEvent->getId());
+
+                // Set distintive attributes of each instance.
+                if( true==isAllDay ) {
+                    ret = calendar_record_get_caltime(currentRecord, _calendar_instance_allday_calendar_book.start_time, &st);
+
+                                       tmTime = {0};
+                                       tmTime.tm_year = st.time.date.year - 1900;
+                                       tmTime.tm_mon = st.time.date.month - 1;
+                                       tmTime.tm_mday = st.time.date.mday;
+
+                                       recurringEventWrapper->getAbstractEvent()->setRecurrenceId(mktime(&tmTime));
+                                       recurringEventWrapper->getAbstractEvent()->setStartTime(mktime(&tmTime));
+                } else {
+                    ret = calendar_record_get_caltime(currentRecord, _calendar_instance_normal_calendar_book.start_time, &st);
+
+                       recurringEventWrapper->getAbstractEvent()->setRecurrenceId(st.time.utime);
+                       recurringEventWrapper->getAbstractEvent()->setStartTime(st.time.utime);
+                }
+                if ( CALENDAR_ERROR_NONE != ret ) {
+                    ThrowMsg(PlatformException, "Can't get current record start time: "<<ret);
+                }
+
+                if( true==isAllDay ) {
+                    ret = calendar_record_get_caltime(currentRecord, _calendar_instance_allday_calendar_book.end_time, &et);
+
+                                       tmTime = {0};
+                                       tmTime.tm_year = et.time.date.year- 1900;
+                                       tmTime.tm_mon = et.time.date.month - 1;
+                                       tmTime.tm_mday = et.time.date.mday;
+
+                                       recurringEventWrapper->getAbstractEvent()->setEndTime(mktime(&tmTime));
+                } else {
+                    ret = calendar_record_get_caltime(currentRecord, _calendar_instance_normal_calendar_book.end_time, &et);
+
+                                       recurringEventWrapper->getAbstractEvent()->setEndTime(et.time.utime);
+                }
+                if ( CALENDAR_ERROR_NONE != ret ) {
+                    ThrowMsg(PlatformException, "Can't get current record end time: "<<ret);
+                }
+
+                LogDebug("Found a valid event instance with rid: "<<recurringEventWrapper->getAbstractEvent()->getRecurrenceId());
+
+                event->addExpandedEvent(recurringEventWrapper->getAbstractEvent());
+            }
+
+            calendar_list_next(list);
+        }
+        LogDebug("Length of expanded events from parent: "<<event->getExpandedEventList()->size());
+
+        if(query) {
+            calendar_query_destroy(query);
+            query = NULL;
+        }
+        if(filter) {
+            calendar_filter_destroy(filter);
+            filter = NULL;
+        }
+        if( list ) {
+            calendar_list_destroy(list, true);
+            list = NULL;
+        }
+
+        // Consider the detached events also.
+        currentRecord = NULL;
+        int parentId = event->getEvent()->getId();
+
+        ret = calendar_query_create(_calendar_event._uri, &query);
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Creating a query failed: "<<ret);
+        }
+
+        ret = calendar_filter_create(_calendar_event._uri, &filter);
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Creating a filter failed: "<<ret);
+        }
+
+        ret = calendar_filter_add_int(filter, _calendar_event.original_event_id, CALENDAR_MATCH_EQUAL, parentId);
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Adding an int filter failed: "<<ret);
+        }
+
+        ret = calendar_query_set_filter(query, filter);
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Setting a filter: "<<ret);
+        }
+
+        ret = calendar_db_get_records_with_query(query, 0, 0, &list);
+        if(CALENDAR_ERROR_NONE!=ret) {
+            ThrowMsg(PlatformException, "Finding detached instances failed: "<<ret);
+        }
+
+        ret = calendar_list_get_count(list, &count);
+        if( CALENDAR_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Can't get the item count: "<<ret);
+        } else {
+            LogDebug("Item count: "<<count);
+        }
+
+        calendar_list_first(list);
+
+        while(count--)
+        {
+            currentRecord = NULL;
+            ret = calendar_list_get_current_record_p(list, &currentRecord);
+            if ( CALENDAR_ERROR_NONE != ret ) {
+                ThrowMsg(PlatformException, "Can't get current record: "<<ret);
+            }
+
+            ret = calendar_record_get_int(currentRecord, _calendar_event.id, &currentRecordIndex);
+            if ( CALENDAR_ERROR_NONE != ret ) {
+                ThrowMsg(PlatformException, "Can't get current record id: "<<ret);
+            }
+
+            st = {CALENDAR_TIME_UTIME, {0}};
+            ret = calendar_record_get_caltime(currentRecord, _calendar_event.start_time, &st);
+            if ( CALENDAR_ERROR_NONE != ret ) {
+                ThrowMsg(PlatformException, "Can't get current record start time: "<<ret);
+            }
+
+            et = {CALENDAR_TIME_UTIME, {0}};
+            ret = calendar_record_get_caltime(currentRecord, _calendar_event.end_time, &et);
+            if ( CALENDAR_ERROR_NONE != ret ) {
+                ThrowMsg(PlatformException, "Can't get current record end time: "<<ret);
+            }
+
+            if (st.time.utime>=startDate && et.time.utime<=endDate) {
+                LogDebug("Found a valid detached event: "<<st.time.utime);
+                DPL::ScopedPtr<EventWrapper> detachedEventWrapper(new EventWrapper(getType()));
+                detachedEventWrapper->loadEvent(currentRecordIndex);
+
+                // Set the same parent uid to each instances
+                detachedEventWrapper->getAbstractEvent()->setId(parentId);
+                // Set distintive attributes of each instance.
+                detachedEventWrapper->getAbstractEvent()->setRecurrenceId(st.time.utime);
+                detachedEventWrapper->getAbstractEvent()->setStartTime(st.time.utime);
+                detachedEventWrapper->getAbstractEvent()->setEndTime(et.time.utime);
+
+                event->addExpandedEvent(detachedEventWrapper->getAbstractEvent());
+            }
+
+            calendar_list_next(list);
+        }
+
+        LogDebug("Length of total expanded events: "<<event->getExpandedEventList()->size());
+
+        event->setResult(true);
+
+        if(query) {
+            calendar_query_destroy(query);
+            query = NULL;
+        }
+        if(filter) {
+            calendar_filter_destroy(filter);
+            filter = NULL;
+        }
+        if( list ) {
+            calendar_list_destroy(list, true);
+            list = NULL;
+        }
+    }
+    Catch (InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+
+    if(query) {
+        calendar_query_destroy(query);
+    }
+    if(filter) {
+        calendar_filter_destroy(filter);
+    }
+    if( list ) {
+        calendar_list_destroy(list, true);
+    }
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Calendar/Calendar.h b/src/platform/Tizen/Calendar/Calendar.h
new file mode 100755 (executable)
index 0000000..3452387
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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 _CALENDAR_H_
+#define _CALENDAR_H_
+
+#include "API/Calendar/ICalendar.h"
+#include "EventWrapper.h"
+
+using namespace TizenApis::Api::Calendar;
+
+namespace TizenApis {
+namespace Platform {
+namespace Calendar {
+
+class Calendar : public ICalendar
+{
+  public:
+    Calendar();
+    virtual ~Calendar();
+
+  protected:
+    virtual void OnRequestReceived(const IEventAddEventPtr &event);
+    virtual void OnRequestReceived(const IEventAddEventsPtr &events);
+    virtual void OnRequestReceived(const IEventDeleteEventPtr &event);
+    virtual void OnRequestReceived(const IEventDeleteEventsPtr &events);
+    virtual void OnRequestReceived(const IEventUpdateEventPtr &event);
+    virtual void OnRequestReceived(const IEventUpdateEventsPtr &events);
+    virtual void OnRequestReceived(const IEventFindEventsPtr &event);
+    virtual void OnRequestReceived(const IEventCreateEventFromStringPtr &event);
+    virtual void OnRequestReceived(const IEventExportEventToStringPtr &event);
+    virtual void OnRequestReceived(const IEventWatchChangesPtr &event);
+    virtual void OnRequestReceived(const IEventClearWatchPtr &event);
+    virtual void OnRequestReceived(const IEventExpandEventRecurrencePtr &event);
+    virtual void OnRequestReceived(const IEventGetPtr &event);
+};
+
+}
+}
+}
+
+#endif /* _CALENDAR_H_ */
diff --git a/src/platform/Tizen/Calendar/CalendarFilter.cpp b/src/platform/Tizen/Calendar/CalendarFilter.cpp
new file mode 100755 (executable)
index 0000000..a68a9ed
--- /dev/null
@@ -0,0 +1,562 @@
+//
+// 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 "CalendarFilter.h"
+#include <calendar2.h>
+#include <map>
+#include <sstream>
+#include <time.h>
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Platform {
+namespace Calendar {
+
+std::map<std::string, unsigned int> CalendarFilter::m_eventAttributeMap = {
+    {CALENDAR_FILTER_ATTRIBUTE_ID_UID,                          _calendar_event.id},
+    {CALENDAR_FILTER_ATTRIBUTE_LAST_MODIFIED_DATE,              _calendar_event.last_modified_time},
+    {CALENDAR_FILTER_ATTRIBUTE_DESCRIPTION,                     _calendar_event.description},
+    {CALENDAR_FILTER_ATTRIBUTE_SUMMARY,                         _calendar_event.summary},
+    {CALENDAR_FILTER_ATTRIBUTE_START_DATE,                      _calendar_event.start_time},
+    {CALENDAR_FILTER_ATTRIBUTE_LOCATION,                        _calendar_event.location},
+    {CALENDAR_FILTER_ATTRIBUTE_LATITUDE,                        _calendar_event.latitude},
+    {CALENDAR_FILTER_ATTRIBUTE_LONGITUDE,                       _calendar_event.longitude},
+    {CALENDAR_FILTER_ATTRIBUTE_ORGANIZER,                       _calendar_event.organizer_name},
+    {CALENDAR_FILTER_ATTRIBUTE_VISIBILITY,                      _calendar_event.sensitivity},
+    {CALENDAR_FILTER_ATTRIBUTE_STATUS,                          _calendar_event.event_status},
+    {CALENDAR_FILTER_ATTRIBUTE_ALARMS,                          _calendar_event.has_alarm},
+    {CALENDAR_FILTER_ATTRIBUTE_CATEGORIES,                      _calendar_event.categories},
+    {CALENDAR_FILTER_ATTRIBUTE_PRIORITY,                        _calendar_event.priority},
+    {CALENDAR_FILTER_ATTRIBUTE_IS_DETACHED,                     _calendar_event.original_event_id},
+    {CALENDAR_FILTER_ATTRIBUTE_IS_ALL_DAY,                      _calendar_event.is_allday},
+    {CALENDAR_FILTER_ATTRIBUTE_ATTENDEES,                       _calendar_event.has_attendee},
+    {CALENDAR_FILTER_ATTRIBUTE_END_DATE,                        _calendar_event.end_time},
+    {CALENDAR_FILTER_ATTRIBUTE_AVAILABILITY,                    _calendar_event.busy_status},
+    {CALENDAR_FILTER_ATTRIBUTE_RECURRENCE_RULE,                 _calendar_event.freq}
+};
+
+std::map<std::string, unsigned int> CalendarFilter::m_taskAttributeMap = {
+    {CALENDAR_FILTER_ATTRIBUTE_ID,                              _calendar_todo.id},
+    {CALENDAR_FILTER_ATTRIBUTE_LAST_MODIFIED_DATE,              _calendar_todo.last_modified_time},
+    {CALENDAR_FILTER_ATTRIBUTE_DESCRIPTION,                     _calendar_todo.description},
+    {CALENDAR_FILTER_ATTRIBUTE_SUMMARY,                         _calendar_todo.summary},
+    {CALENDAR_FILTER_ATTRIBUTE_START_DATE,                      _calendar_todo.start_time},
+    {CALENDAR_FILTER_ATTRIBUTE_LOCATION,                        _calendar_todo.location},
+    {CALENDAR_FILTER_ATTRIBUTE_LATITUDE,                        _calendar_todo.latitude},
+    {CALENDAR_FILTER_ATTRIBUTE_LONGITUDE,                       _calendar_todo.longitude},
+    {CALENDAR_FILTER_ATTRIBUTE_ORGANIZER,                       _calendar_todo.organizer_name},
+    {CALENDAR_FILTER_ATTRIBUTE_VISIBILITY,                      _calendar_todo.sensitivity},
+    {CALENDAR_FILTER_ATTRIBUTE_STATUS,                          _calendar_todo.todo_status},
+    {CALENDAR_FILTER_ATTRIBUTE_ALARMS,                          _calendar_todo.has_alarm},
+    {CALENDAR_FILTER_ATTRIBUTE_CATEGORIES,                      _calendar_todo.categories},
+    {CALENDAR_FILTER_ATTRIBUTE_PRIORITY,                        _calendar_todo.priority},
+    {CALENDAR_FILTER_ATTRIBUTE_DUE_DATE,                        _calendar_todo.due_time},
+    {CALENDAR_FILTER_ATTRIBUTE_COMPLETED_DATE,                  _calendar_todo.completed_time},
+    {CALENDAR_FILTER_ATTRIBUTE_PROGRESS,                        _calendar_todo.progress},
+    {CALENDAR_FILTER_ATTRIBUTE_IS_ALL_DAY,                      _calendar_todo.is_allday},
+    {CALENDAR_FILTER_ATTRIBUTE_ATTENDEES,                       _calendar_todo.has_attendee}
+};
+
+CalendarFilter::CalendarFilter()
+{
+    m_type = CalendarEvent::UNDEFINED_TYPE;
+    m_query = NULL;
+    m_filter = NULL;
+    m_recordList = NULL;
+    m_recordCount = 0;
+}
+
+CalendarFilter::~CalendarFilter()
+{
+    LogDebug("Clear internal structs for filter.");
+    if(m_query) {
+        calendar_query_destroy(m_query);
+    }
+    if(m_filter) {
+        calendar_filter_destroy(m_filter);
+    }
+
+    // Child record will be freed in the caller function.
+    if(m_recordList) {
+        calendar_list_destroy(m_recordList, false);
+    }
+}
+
+void CalendarFilter::visitPreComposite(TizenApis::Api::Tizen::FilterType& type, int depth)
+{
+}
+
+void CalendarFilter::visitInComposite(TizenApis::Api::Tizen::FilterType& type, int depth)
+{
+       LogDebug("Composite type: "<<type);
+       if(type == TizenApis::Api::Tizen::UNION_FILTER) {
+               calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_OR);
+       } else if(type == TizenApis::Api::Tizen::INTERSECTION_FILTER) {
+               calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_AND);
+       }
+}
+
+void CalendarFilter::visitPostComposite(TizenApis::Api::Tizen::FilterType& type, int depth)
+{
+}
+
+void CalendarFilter::visitAttribute(std::string& attrName, TizenApis::Api::Tizen::MatchFlag& matchFlag, TizenApis::Api::Tizen::AnyPtr& matchValue, int depth)
+{
+       if(NULL==matchValue) {
+        LogWarning("Empty match value.");
+               return;
+       }
+
+       LogDebug("attrName: "<<attrName<<", value string: "<<matchValue->toString()<<", matchFlag: "<<matchFlag<<", depth:"<<depth);
+
+    calendar_match_str_flag_e strMatchFlag = CALENDAR_MATCH_EXACTLY;
+    calendar_match_int_flag_e intMatchFlag = CALENDAR_MATCH_EQUAL;
+
+       if( TizenApis::Api::Tizen::MATCH_EXACTLY==matchFlag ) {
+               strMatchFlag = CALENDAR_MATCH_EXACTLY;
+        intMatchFlag = CALENDAR_MATCH_EQUAL;
+       } else if( TizenApis::Api::Tizen::MATCH_FULLSTRING==matchFlag ) {
+        strMatchFlag = CALENDAR_MATCH_FULLSTRING;
+       } else if( TizenApis::Api::Tizen::MATCH_CONTAINS==matchFlag) {
+        strMatchFlag = CALENDAR_MATCH_CONTAINS;
+       } else if( TizenApis::Api::Tizen::MATCH_STARTSWITH==matchFlag) {
+        strMatchFlag = CALENDAR_MATCH_STARTSWITH;
+       } else if( TizenApis::Api::Tizen::MATCH_ENDSWITH==matchFlag) {
+        strMatchFlag = CALENDAR_MATCH_ENDSWITH;
+       }else if( TizenApis::Api::Tizen::MATCH_EXISTS==matchFlag) {
+        strMatchFlag = CALENDAR_MATCH_EXISTS;
+       } else {
+               LogWarning("Invalid matchFlag!");
+       }
+
+    if(CALENDAR_FILTER_ATTRIBUTE_VISIBILITY==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_STATUS==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_PRIORITY==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_PROGRESS==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_AVAILABILITY==attrName) {
+        int value;
+        if(CALENDAR_FILTER_ATTRIBUTE_VISIBILITY==attrName
+            || CALENDAR_FILTER_ATTRIBUTE_STATUS==attrName
+            || CALENDAR_FILTER_ATTRIBUTE_PRIORITY==attrName
+            || CALENDAR_FILTER_ATTRIBUTE_AVAILABILITY==attrName) {
+            value = convertStringToIntValue(attrName, matchValue->getString());
+        } else {
+            value = matchValue->getInt();
+        }
+
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            calendar_filter_add_int(m_filter, m_taskAttributeMap[attrName], intMatchFlag, value);
+        } else {
+            calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], intMatchFlag, value);
+        }
+        LogDebug("Added int filter with value: "<<value);
+    } else if(CALENDAR_FILTER_ATTRIBUTE_ID_UID==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_ID==attrName) {
+        int id;
+        std::stringstream ss(matchValue->getString());
+        ss>>id;
+
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            calendar_filter_add_int(m_filter, m_taskAttributeMap[attrName], intMatchFlag, id);
+        } else {
+            calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], intMatchFlag, id);
+
+            // Include the detached events.
+            calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_OR);
+            calendar_filter_add_int(m_filter, _calendar_event.original_event_id, CALENDAR_MATCH_EQUAL, id);
+        }
+        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 = matchValue->getTimeT();
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            calendar_filter_add_lli(m_filter, m_taskAttributeMap[attrName], intMatchFlag, (long long int) time);
+        } else {
+            calendar_filter_add_lli(m_filter, m_eventAttributeMap[attrName], intMatchFlag, (long long int) time);
+        }
+        LogDebug("Added lli filter with value: "<<time);
+    } else if(CALENDAR_FILTER_ATTRIBUTE_DESCRIPTION==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_SUMMARY==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_LOCATION==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_ORGANIZER==attrName) {
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            calendar_filter_add_str(m_filter, m_taskAttributeMap[attrName], strMatchFlag, matchValue->getString().c_str());
+        } else {
+            calendar_filter_add_str(m_filter, m_eventAttributeMap[attrName], strMatchFlag, matchValue->getString().c_str());
+        }
+        LogDebug("Added str filter with value: "<<matchValue->getString());
+    } else if(CALENDAR_FILTER_ATTRIBUTE_IS_ALL_DAY==attrName) {
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            calendar_filter_add_int(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_EQUAL, matchValue->getBool() ? 1 : 0);
+        } else {
+            calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_EQUAL, matchValue->getBool() ? 1 : 0);
+        }
+        LogDebug("Added int filter with value: "<<matchValue->getBool());
+    } else if(CALENDAR_FILTER_ATTRIBUTE_START_DATE==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_DUE_DATE==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_END_DATE==attrName) {
+        calendar_time_s calTime = {CALENDAR_TIME_UTIME, {0}};
+        std::time_t time = matchValue->getTimeT();
+        calTime.time.utime = (long long int) time;
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            calendar_filter_add_caltime(m_filter, m_taskAttributeMap[attrName], intMatchFlag, calTime);
+        } else {
+            calendar_filter_add_caltime(m_filter, m_eventAttributeMap[attrName], intMatchFlag, calTime);
+        }
+        LogDebug("Added caltime filter with value: "<<time);
+    } else if(CALENDAR_FILTER_ATTRIBUTE_LATITUDE==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_LONGITUDE==attrName) {
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            calendar_filter_add_double(m_filter, m_taskAttributeMap[attrName], intMatchFlag, matchValue->getDouble());
+        } else {
+            calendar_filter_add_double(m_filter, m_eventAttributeMap[attrName], intMatchFlag, matchValue->getDouble());
+        }
+        LogDebug("Added double filter with value: "<<matchValue->getDouble());
+    } else if(CALENDAR_FILTER_ATTRIBUTE_ALARMS==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_ATTENDEES==attrName) {
+        if(CalendarEvent::TASK_TYPE==m_type) {
+                       if( TizenApis::Api::Tizen::MATCH_EXACTLY==matchFlag ) {
+                               if( matchValue->isNullOrUndefined() ) {
+                           calendar_filter_add_int(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_EQUAL, 0);
+                               } else {
+                           calendar_filter_add_int(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_EQUAL, 1);
+                               }
+                       } else {
+                   calendar_filter_add_int(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_EQUAL, 1);
+                       }
+        } else {
+                       if( TizenApis::Api::Tizen::MATCH_EXACTLY==matchFlag ) {
+                               if( matchValue->isNullOrUndefined() ) {
+                           calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_EQUAL, 0);
+                               } else {
+                                   calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_EQUAL, 1);
+                               }
+                       } else {
+                   calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_EQUAL, 1);
+                       }
+        }
+        LogDebug("Added int filter.");
+    } else if(CALENDAR_FILTER_ATTRIBUTE_CATEGORIES==attrName) {
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            calendar_filter_add_str(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_CONTAINS, matchValue->getString().c_str());
+        } else {
+            calendar_filter_add_str(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_CONTAINS, matchValue->getString().c_str());
+        }
+        LogDebug("Added str filter for categories with value: "<<matchValue->getString());
+    } else if(CALENDAR_FILTER_ATTRIBUTE_IS_DETACHED==attrName) {
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            LogWarning("isDetached not supported for a task.");
+        } else {
+            calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN, 0);
+        }
+        LogDebug("Added int filter for isDetached with value 0.");
+    } else if(CALENDAR_FILTER_ATTRIBUTE_RECURRENCE_RULE==attrName) {
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            LogWarning("rrule not supported for a task.");
+        } else {
+                       if( TizenApis::Api::Tizen::MATCH_EXACTLY==matchFlag ) {
+                               if( matchValue->isNullOrUndefined() ) {
+                           calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_EQUAL, 0);
+                               } else {
+                           calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN, 0);
+                               }
+                       LogDebug("Added int filter for rrule EXACTLY flag.");
+                       } else {
+                   calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN, 0);
+                       LogDebug("Added int filter for rrule.");
+                       }
+        }
+    } else {
+        LogWarning("Not supported filter attribute: "<<attrName);
+    }
+
+       LogDebug("Attribute visit done.");
+}
+
+void CalendarFilter::visitAttributeRange(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& initialValue, TizenApis::Api::Tizen::AnyPtr& endValue, int depth)
+{
+       if(initialValue == NULL && endValue == NULL) {
+        LogWarning("Both initial/end values are empty.");
+               return;
+       }
+
+    LogDebug("attrName: " <<attrName<<", initialValue: "<<initialValue->toString()<<", endValue: " <<endValue->toString()<<", depth: "<<depth);
+
+    if(CALENDAR_FILTER_ATTRIBUTE_START_DATE==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_DUE_DATE==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_END_DATE==attrName) {
+        calendar_time_s startTime = {CALENDAR_TIME_UTIME, {0}};
+        calendar_time_s endTime = {CALENDAR_TIME_UTIME, {0}};
+        if (!initialValue->isNullOrUndefined()) {
+            startTime.time.utime = (long long int) (initialValue->getTimeT());
+        }
+        if (!endValue->isNullOrUndefined()) {
+            endTime.time.utime = (long long int) (endValue->getTimeT());
+        }
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            if (!initialValue->isNullOrUndefined()) {
+                calendar_filter_add_caltime(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, startTime);
+            }
+            if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
+                calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_AND);
+            }
+            if (!endValue->isNullOrUndefined()) {
+                calendar_filter_add_caltime(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_LESS_THAN_OR_EQUAL, endTime);
+            }
+        } else {
+            if (!initialValue->isNullOrUndefined()) {
+                calendar_filter_add_caltime(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, startTime);
+            }
+            if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
+                calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_AND);
+            }
+            if (!endValue->isNullOrUndefined()) {
+                calendar_filter_add_caltime(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_LESS_THAN_OR_EQUAL, endTime);
+            }
+        }
+        LogDebug("Added caltime range filter with initial value: "<<startTime.time.utime<<", end value: "<<endTime.time.utime);
+    } else if(CALENDAR_FILTER_ATTRIBUTE_LATITUDE==attrName ||
+        CALENDAR_FILTER_ATTRIBUTE_LONGITUDE==attrName) {
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            if (!initialValue->isNullOrUndefined()) {
+                calendar_filter_add_double(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, initialValue->getDouble());
+            }
+            if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
+                calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_AND);
+            }
+            if (!endValue->isNullOrUndefined()) {
+                calendar_filter_add_double(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_LESS_THAN_OR_EQUAL, endValue->getDouble());
+            }
+        } else {
+            if (!initialValue->isNullOrUndefined()) {
+                calendar_filter_add_double(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, initialValue->getDouble());
+            }
+            if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
+                calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_AND);
+            }
+            if (!endValue->isNullOrUndefined()) {
+                calendar_filter_add_double(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_LESS_THAN_OR_EQUAL, endValue->getDouble());
+            }
+        }
+        LogDebug("Added double range filter with initial value: "<<initialValue->getDouble()<<", end value: "<<endValue->getDouble());
+    } else if(CALENDAR_FILTER_ATTRIBUTE_COMPLETED_DATE==attrName ||
+        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)(initialValue->getTimeT()));
+            }
+            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)(endValue->getTimeT()));
+            }
+        } else {
+            if (!initialValue->isNullOrUndefined()) {
+                calendar_filter_add_lli(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, (long long int)(initialValue->getTimeT()));
+            }
+            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)(endValue->getTimeT()));
+            }
+        }
+        LogDebug("Added lli range filter with initial value: "<<initialValue->getTimeT()<<", end value: "<<endValue->getTimeT());
+    } else if(CALENDAR_FILTER_ATTRIBUTE_PROGRESS==attrName) {
+        if(CalendarEvent::TASK_TYPE==m_type) {
+            if (!initialValue->isNullOrUndefined()) {
+                calendar_filter_add_int(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, initialValue->getInt());
+            }
+            if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
+                calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_AND);
+            }
+            if (!endValue->isNullOrUndefined()) {
+                calendar_filter_add_int(m_filter, m_taskAttributeMap[attrName], CALENDAR_MATCH_LESS_THAN_OR_EQUAL, endValue->getInt());
+            }
+        } else {
+            if (!initialValue->isNullOrUndefined()) {
+                calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_GREATER_THAN_OR_EQUAL, initialValue->getInt());
+            }
+            if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
+                calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_AND);
+            }
+            if (!endValue->isNullOrUndefined()) {
+                calendar_filter_add_int(m_filter, m_eventAttributeMap[attrName], CALENDAR_MATCH_LESS_THAN_OR_EQUAL, endValue->getInt());
+            }
+        }
+        LogDebug("Added double range filter with initial value: "<<initialValue->getInt()<<", end value: "<<endValue->getInt());
+    } else {
+        LogWarning("Not supported filter attribute: "<<attrName);
+    }
+
+    LogDebug("Attribute range visit done.");
+}
+
+void CalendarFilter::setType(CalendarEvent::CalendarType type)
+{
+    if(CalendarEvent::TASK_TYPE==type) {
+        m_type = CalendarEvent::TASK_TYPE;
+        calendar_query_create(_calendar_todo._uri, &m_query);
+        calendar_filter_create(_calendar_todo._uri, &m_filter);
+    } else {
+        m_type = CalendarEvent::EVENT_TYPE;
+        calendar_query_create(_calendar_event._uri, &m_query);
+        calendar_filter_create(_calendar_event._uri, &m_filter);
+    }
+}
+
+void CalendarFilter::setCalendarId(int calendarId, bool isFilterSet)
+{
+    if( isFilterSet ) {
+        calendar_filter_add_operator(m_filter, CALENDAR_FILTER_OPERATOR_AND);
+    }
+
+    if(CalendarEvent::TASK_TYPE==m_type) {
+        calendar_filter_add_int(m_filter, _calendar_todo.calendar_book_id, CALENDAR_MATCH_EQUAL, calendarId);
+    } else {
+        calendar_filter_add_int(m_filter, _calendar_event.calendar_book_id, CALENDAR_MATCH_EQUAL, calendarId);
+    }
+}
+
+void CalendarFilter::setSortMode(TizenApis::Api::Tizen::SortModeArrayPtr attr)
+{
+       std::string attrName;
+       TizenApis::Api::Tizen::SortModeArray::iterator it = attr->begin();
+
+    // The first sort mode only.
+       attrName = (*it)->getAttributeName();
+       if (attrName.compare("") != 0) {
+        LogDebug("Setting the sort mode with attrName: "<<attrName);
+               if ((*it)->getOrder()==TizenApis::Api::Tizen::ASCENDING_SORT_ORDER) {
+            if(CalendarEvent::TASK_TYPE==m_type) {
+                       calendar_query_set_sort(m_query, m_taskAttributeMap[attrName], true);
+            } else {
+                       calendar_query_set_sort(m_query, m_eventAttributeMap[attrName], true);
+            }
+               } else {
+            if(CalendarEvent::TASK_TYPE==m_type) {
+                       calendar_query_set_sort(m_query, m_taskAttributeMap[attrName], false);
+            } else {
+                       calendar_query_set_sort(m_query, m_eventAttributeMap[attrName], false);
+            }
+               }
+       } else {
+           LogWarning("Empty attribute name.");
+       }
+}
+
+void CalendarFilter::executeQuery()
+{
+    int ret;
+    ret = calendar_query_set_filter(m_query, m_filter);
+    if( CALENDAR_ERROR_NONE!=ret ) {
+        ThrowMsg(PlatformException, "Setting filter failed: "<<ret);
+    }
+
+       ret = calendar_db_get_records_with_query(m_query, 0, 0, &m_recordList);
+    if( CALENDAR_ERROR_NONE!=ret ) {
+        ThrowMsg(PlatformException, "Getting record list failed: "<<ret);
+    }
+
+    ret = calendar_list_get_count(m_recordList, &m_recordCount);
+    if( CALENDAR_ERROR_NONE!=ret ) {
+        ThrowMsg(PlatformException, "Can't get the item count: "<<ret);
+    } else {
+        LogDebug("Item count: "<<m_recordCount);
+    }
+}
+
+int CalendarFilter::getResultRecordCount() const
+{
+       return m_recordCount;
+}
+
+calendar_list_h CalendarFilter::getResultRecordList() const
+{
+       return m_recordList;
+}
+
+int CalendarFilter::convertStringToIntValue(const std::string attrName, const std::string valueString)
+{
+       LogDebug("attrName: "<<attrName<<", valueString: "<<valueString);
+
+    if(attrName==CALENDAR_FILTER_ATTRIBUTE_VISIBILITY)
+    {
+        if(valueString=="PUBLIC") {
+            return CALENDAR_SENSITIVITY_PUBLIC;
+        } else if(valueString=="PRIVATE") {
+            return CALENDAR_SENSITIVITY_PRIVATE;
+        } else if(valueString=="CONFIDENTIAL") {
+            return CALENDAR_SENSITIVITY_CONFIDENTIAL;
+        } else {
+            LogWarning("Wrong visibility value.");
+        }
+    }
+    else if(attrName==CALENDAR_FILTER_ATTRIBUTE_STATUS)
+    {
+        if(valueString=="TENTATIVE") {
+            return CALENDAR_EVENT_STATUS_TENTATIVE;
+        } else if(valueString=="CONFIRMED") {
+            return CALENDAR_EVENT_STATUS_CONFIRMED;
+        } else if(valueString=="CANCELLED") {
+            return CALENDAR_EVENT_STATUS_CANCELLED;
+        } else if(valueString=="NEEDS_ACTION") {
+            return CALENDAR_TODO_STATUS_NEEDS_ACTION;
+        } else if(valueString=="IN_PROCESS") {
+            return CALENDAR_TODO_STATUS_IN_PROCESS;
+        } else if(valueString=="COMPLETED") {
+            return CALENDAR_TODO_STATUS_COMPLETED;
+        } else {
+            LogWarning("Wrong status value.");
+        }
+    }
+    else if(attrName==CALENDAR_FILTER_ATTRIBUTE_PRIORITY)
+    {
+        if(valueString=="HIGH") {
+            return CALENDAR_EVENT_PRIORITY_HIGH;
+        } else if(valueString=="MEDIUM") {
+            return CALENDAR_EVENT_PRIORITY_NORMAL;
+        } else if(valueString=="LOW") {
+            return CALENDAR_EVENT_PRIORITY_LOW;
+        } else {
+            LogWarning("Wrong priority value.");
+        }
+    }
+    else if(attrName==CALENDAR_FILTER_ATTRIBUTE_AVAILABILITY)
+    {
+        if(valueString=="BUSY") {
+            return CALENDAR_EVENT_BUSY_STATUS_BUSY;
+        } else if(valueString=="FREE") {
+            return CALENDAR_EVENT_BUSY_STATUS_FREE;
+        } else {
+            LogWarning("Wrong availability value.");
+        }
+    } else {
+        LogWarning("Invalid attrName");
+    }
+
+    return -1;
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Calendar/CalendarFilter.h b/src/platform/Tizen/Calendar/CalendarFilter.h
new file mode 100755 (executable)
index 0000000..4ecb992
--- /dev/null
@@ -0,0 +1,114 @@
+//
+// 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 _CALENDAR_FILTER_H_
+#define _CALENDAR_FILTER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <API/Filter/IFilterVisitor.h>
+#include <API/Filter/SortMode.h>
+#include "API/Calendar/CalendarEvent.h"
+#include <calendar2.h>
+
+using namespace TizenApis::Api::Calendar;
+
+namespace TizenApis {
+namespace Platform {
+namespace Calendar {
+
+// List of attributes that can be used as the filter argument.
+#define CALENDAR_FILTER_ATTRIBUTE_ID_UID "id.uid" // for event
+#define CALENDAR_FILTER_ATTRIBUTE_ID "id" // for task
+#define CALENDAR_FILTER_ATTRIBUTE_LAST_MODIFIED_DATE "lastModificationDate"
+#define CALENDAR_FILTER_ATTRIBUTE_DESCRIPTION "description"
+#define CALENDAR_FILTER_ATTRIBUTE_SUMMARY "summary"
+#define CALENDAR_FILTER_ATTRIBUTE_IS_ALL_DAY "isAllDay"
+#define CALENDAR_FILTER_ATTRIBUTE_START_DATE "startDate"
+#define CALENDAR_FILTER_ATTRIBUTE_LOCATION "location"
+#define CALENDAR_FILTER_ATTRIBUTE_LATITUDE "geolocation.latitude"
+#define CALENDAR_FILTER_ATTRIBUTE_LONGITUDE "geolocation.longitude"
+#define CALENDAR_FILTER_ATTRIBUTE_ORGANIZER "organizer"
+#define CALENDAR_FILTER_ATTRIBUTE_VISIBILITY "visibility"
+#define CALENDAR_FILTER_ATTRIBUTE_STATUS "status"
+#define CALENDAR_FILTER_ATTRIBUTE_PRIORITY "priority"
+#define CALENDAR_FILTER_ATTRIBUTE_ALARMS "alarms"
+#define CALENDAR_FILTER_ATTRIBUTE_CATEGORIES "categories"
+#define CALENDAR_FILTER_ATTRIBUTE_ATTENDEES "attendees"
+#define CALENDAR_FILTER_ATTRIBUTE_DUE_DATE "dueDate"
+#define CALENDAR_FILTER_ATTRIBUTE_COMPLETED_DATE "completedDate"
+#define CALENDAR_FILTER_ATTRIBUTE_PROGRESS "progress"
+#define CALENDAR_FILTER_ATTRIBUTE_IS_DETACHED "isDetached"
+#define CALENDAR_FILTER_ATTRIBUTE_END_DATE "endDate"
+#define CALENDAR_FILTER_ATTRIBUTE_AVAILABILITY "availability"
+#define CALENDAR_FILTER_ATTRIBUTE_RECURRENCE_RULE "recurrenceRule"
+
+class CalendarFilter: public TizenApis::Api::Tizen::IFilterVisitor
+{
+private:
+    CalendarEvent::CalendarType m_type;
+       calendar_query_h m_query;
+       calendar_filter_h m_filter;
+    calendar_list_h m_recordList;
+    int m_recordCount;
+       static std::map<std::string, unsigned int> m_eventAttributeMap;
+       static std::map<std::string, unsigned int> m_taskAttributeMap;
+
+public:
+       CalendarFilter();
+       virtual ~CalendarFilter();
+
+       virtual void visitPreComposite(TizenApis::Api::Tizen::FilterType& type, int depth);
+
+       virtual void visitInComposite(TizenApis::Api::Tizen::FilterType& type, int depth);
+
+       virtual void visitPostComposite(TizenApis::Api::Tizen::FilterType& type, int depth);
+
+       virtual void visitAttribute(std::string& attrName,
+                       TizenApis::Api::Tizen::MatchFlag& matchFlag,
+                       TizenApis::Api::Tizen::AnyPtr& matchValue,
+                       int depth);
+
+       virtual void visitAttributeRange(std::string& attrName,
+                       TizenApis::Api::Tizen::AnyPtr& initialValue,
+                       TizenApis::Api::Tizen::AnyPtr& endValue,
+                       int depth);
+
+    void setType(CalendarEvent::CalendarType type);
+
+    void setCalendarId(int calendarId, bool isFilterSet);
+
+       void setSortMode(TizenApis::Api::Tizen::SortModeArrayPtr attr);
+
+       void executeQuery();
+
+    int getResultRecordCount() const;
+
+       calendar_list_h getResultRecordList() const;
+
+private:
+       int convertStringToIntValue(const std::string attrName, const std::string valueString);
+};
+
+typedef DPL::SharedPtr<CalendarFilter> CalendarFilterPtr;
+
+}
+}
+}
+
+#endif /* _CALENDAR_FILTER_H_ */
diff --git a/src/platform/Tizen/Calendar/CalendarFilterValidator.cpp b/src/platform/Tizen/Calendar/CalendarFilterValidator.cpp
new file mode 100755 (executable)
index 0000000..edaffdb
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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 "CalendarFilterValidator.h"
+#include "CalendarFilter.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Calendar {
+
+using namespace TizenApis::Api::Tizen;
+
+static PropertyStructArray properties =
+{
+    {CALENDAR_FILTER_ATTRIBUTE_ID_UID,              PrimitiveType_String},
+    {CALENDAR_FILTER_ATTRIBUTE_ID,                     PrimitiveType_String},
+    {CALENDAR_FILTER_ATTRIBUTE_LAST_MODIFIED_DATE,  PrimitiveType_Time},
+    {CALENDAR_FILTER_ATTRIBUTE_DESCRIPTION,         PrimitiveType_String},
+    {CALENDAR_FILTER_ATTRIBUTE_SUMMARY,             PrimitiveType_String},
+    {CALENDAR_FILTER_ATTRIBUTE_START_DATE,          PrimitiveType_Time},
+    {CALENDAR_FILTER_ATTRIBUTE_LOCATION,            PrimitiveType_String},
+    {CALENDAR_FILTER_ATTRIBUTE_LATITUDE,            PrimitiveType_Double},
+    {CALENDAR_FILTER_ATTRIBUTE_LONGITUDE,           PrimitiveType_Double},
+    {CALENDAR_FILTER_ATTRIBUTE_ORGANIZER,           PrimitiveType_String},
+    {CALENDAR_FILTER_ATTRIBUTE_VISIBILITY,          PrimitiveType_String},
+    {CALENDAR_FILTER_ATTRIBUTE_STATUS,              PrimitiveType_String},
+    {CALENDAR_FILTER_ATTRIBUTE_CATEGORIES,          PrimitiveType_String},
+    {CALENDAR_FILTER_ATTRIBUTE_PRIORITY,            PrimitiveType_String},
+    {CALENDAR_FILTER_ATTRIBUTE_DUE_DATE,            PrimitiveType_Time},
+       {CALENDAR_FILTER_ATTRIBUTE_IS_DETACHED,                 PrimitiveType_Boolean},
+    {CALENDAR_FILTER_ATTRIBUTE_IS_ALL_DAY,          PrimitiveType_Boolean},
+    {CALENDAR_FILTER_ATTRIBUTE_END_DATE,            PrimitiveType_Time},
+    {CALENDAR_FILTER_ATTRIBUTE_COMPLETED_DATE,      PrimitiveType_Time},
+    {CALENDAR_FILTER_ATTRIBUTE_PROGRESS,               PrimitiveType_Integer},
+    {CALENDAR_FILTER_ATTRIBUTE_AVAILABILITY,        PrimitiveType_String},
+    {CALENDAR_FILTER_ATTRIBUTE_RECURRENCE_RULE,     PrimitiveType_Null},
+    {CALENDAR_FILTER_ATTRIBUTE_ALARMS,                         PrimitiveType_Null},
+       {CALENDAR_FILTER_ATTRIBUTE_ATTENDEES,                   PrimitiveType_Null},
+    {0,        PrimitiveType_NoType}
+};
+
+FilterValidatorPtr CalendarFilterValidatorFactory::getCalendarFilterValidator()
+{
+    static FilterValidatorPtr theInstance =
+               FilterValidatorPtr(new FilterValidator(properties));
+    return theInstance;
+}
+
+} // Calendar
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Calendar/CalendarFilterValidator.h b/src/platform/Tizen/Calendar/CalendarFilterValidator.h
new file mode 100755 (executable)
index 0000000..9e7b93c
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// 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 _PLATFORM_CALENDAR_FILTER_VALIDATOR_H_
+#define _PLATFORM_CALENDAR_FILTER_VALIDATOR_H_
+
+#include <API/Filter/FilterValidator.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Calendar {
+
+class CalendarFilterValidatorFactory : private DPL::Noncopyable
+{
+private:
+       CalendarFilterValidatorFactory()
+       {
+       }
+
+public:
+       static TizenApis::Api::Tizen::FilterValidatorPtr        getCalendarFilterValidator();
+};
+
+} // Calendar
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CALENDAR_FILTER_VALIDATOR_H_
\ No newline at end of file
diff --git a/src/platform/Tizen/Calendar/CalendarManager.cpp b/src/platform/Tizen/Calendar/CalendarManager.cpp
new file mode 100755 (executable)
index 0000000..29d6c57
--- /dev/null
@@ -0,0 +1,326 @@
+//
+// 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 "CalendarManager.h"
+#include <vector>
+#include <sstream>
+#include <dpl/log/log.h>
+#include <calendar2.h>
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Platform {
+namespace Calendar {
+
+int CalendarManager::m_instanceCount = 0;
+
+CalendarManager::CalendarManager()
+{
+    DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+    if (m_instanceCount == 0) {
+        LogDebug("Connect to the calendar DB.");
+        if (CALENDAR_ERROR_NONE != calendar_connect()) {
+            LogError("Calendar DB connection failed.");
+        }
+    }
+    m_instanceCount++;
+}
+
+CalendarManager::~CalendarManager()
+{
+    DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+    m_instanceCount--;
+    if (m_instanceCount == 0) {
+        LogDebug("Disconnect calendar DB.");
+        if (CALENDAR_ERROR_NONE != calendar_disconnect()) {
+            LogError("Calendar DB disconnect failed.");
+        }
+    }
+}
+
+void CalendarManager::OnRequestReceived(const IEventGetCalendarsPtr &event)
+{
+    Try
+    {
+        int ret, count;
+        calendar_list_h list = NULL;
+        ret = calendar_db_get_all_records(_calendar_book._uri, 0, 0, &list);
+        if (CALENDAR_ERROR_NONE != ret) {
+            ThrowMsg(PlatformException, "Getting calendar list failed: "<<ret);
+        }
+
+        ret = calendar_list_get_count(list, &count);
+        if(CALENDAR_ERROR_NONE!=ret){
+            ThrowMsg(PlatformException, "Getting calendar list count failed: "<<ret);
+        } else {
+            LogDebug("Calendar list count: "<<count);
+        }
+
+        calendar_record_h calendar = NULL;
+        calendar_list_first(list);
+
+        char* name = NULL;
+        int id, accountId, storeType;
+
+        while(count--)
+        {
+            if(CALENDAR_ERROR_NONE!=calendar_list_get_current_record_p(list, &calendar)) {
+                LogWarning("Getting current record failed.");
+                break;
+            }
+
+            ret = calendar_record_get_str(calendar, _calendar_book.name, &name);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar name: "<<ret);
+            }
+            ret = calendar_record_get_int(calendar, _calendar_book.id, &id);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar id: "<<ret);
+            }
+            ret = calendar_record_get_int(calendar, _calendar_book.account_id, &accountId);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar account id: "<<ret);
+            }
+            ret = calendar_record_get_int(calendar, _calendar_book.store_type, &storeType);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar store type: "<<ret);
+            }
+
+            if (name != NULL) {
+                LogDebug("Got calendar, id: "<<id<<", name: "<<name<<", account id: "<<accountId<<", storeType: "<<storeType);
+
+                if( (CALENDAR_BOOK_TYPE_EVENT==storeType && CalendarEvent::EVENT_TYPE==event->getType()) ||
+                    (CALENDAR_BOOK_TYPE_TODO==storeType && CalendarEvent::TASK_TYPE==event->getType()) ) {
+                    ICalendarPtr newCalendar(new Calendar());
+                    newCalendar->setName(name);
+                    newCalendar->setId(id);
+                    newCalendar->setAccountId(accountId);
+                    newCalendar->setType(event->getType());
+                    event->addCalendar(newCalendar);
+                } else {
+                    LogDebug("Different calendar type.");
+                }
+                free(name);
+            } else {
+                LogError("Calendar contains invalid parameters");
+            }
+            calendar = NULL;
+
+            calendar_list_next(list);
+        }
+
+        if(list) {
+            calendar_list_destroy(list, true);
+        }
+
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void CalendarManager::OnRequestReceived(const IEventGetDefaultCalendarPtr &event)
+{
+    ICalendarPtr newCalendar(new Calendar());
+    Try
+    {
+        int ret, count;
+        calendar_list_h list = NULL;
+        ret = calendar_db_get_all_records(_calendar_book._uri, 0, 0, &list);
+        if (CALENDAR_ERROR_NONE != ret) {
+            ThrowMsg(PlatformException, "Getting calendar list failed: "<<ret);
+        }
+
+        ret = calendar_list_get_count(list, &count);
+        if(CALENDAR_ERROR_NONE!=ret){
+            ThrowMsg(PlatformException, "Getting calendar list count failed: "<<ret);
+        } else {
+            LogDebug("Calendar list count: "<<count);
+        }
+
+        calendar_record_h calendar = NULL;
+        calendar_list_first(list);
+
+        char* name = NULL;
+        int id, accountId, storeType;
+        while(count--)
+        {
+            if(CALENDAR_ERROR_NONE!=calendar_list_get_current_record_p(list, &calendar)) {
+                LogWarning("Getting current record failed.");
+                break;
+            }
+
+            ret = calendar_record_get_str(calendar, _calendar_book.name, &name);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar name: "<<ret);
+            }
+            ret = calendar_record_get_int(calendar, _calendar_book.id, &id);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar id: "<<ret);
+            }
+            ret = calendar_record_get_int(calendar, _calendar_book.account_id, &accountId);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar account id: "<<ret);
+            }
+            ret = calendar_record_get_int(calendar, _calendar_book.store_type, &storeType);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar store type: "<<ret);
+            }
+
+            if (name != NULL) {
+                LogDebug("Got default calendar, id: "<<id<<", name: "<<name<<", account id: "<<accountId<<", storeType: "<<storeType);
+
+                if( (CALENDAR_BOOK_TYPE_EVENT==storeType && CalendarEvent::EVENT_TYPE==event->getType()) ||
+                    (CALENDAR_BOOK_TYPE_TODO==storeType && CalendarEvent::TASK_TYPE==event->getType()) ) {
+                    newCalendar->setName(name);
+                    newCalendar->setId(id);
+                    newCalendar->setAccountId(accountId);
+                    newCalendar->setType(event->getType());
+                    event->setCalendar(newCalendar);
+                    break;
+                } else {
+                    LogDebug("Different calendar type.");
+                }
+                free(name);
+            } else {
+                LogError("Calendar contains invalid parameters");
+            }
+
+            calendar = NULL;
+
+            calendar_list_next(list);
+        }
+
+        if(list) {
+            calendar_list_destroy(list, true);
+        }
+
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void CalendarManager::OnRequestReceived(const IEventGetCalendarPtr &event)
+{
+    Try
+    {
+        std::stringstream ss(event->getId());
+        int calendarId = -1;
+        ss>>calendarId;
+
+        LogInfo("Given id: "<<event->getId()<<", converted id: "<<calendarId);
+
+        ICalendarPtr newCalendar(new Calendar());
+
+        int ret, count;
+        calendar_list_h list = NULL;
+        ret = calendar_db_get_all_records(_calendar_book._uri, 0, 0, &list);
+        if (CALENDAR_ERROR_NONE != ret) {
+            ThrowMsg(PlatformException, "Getting calendar list failed: "<<ret);
+        }
+
+        ret = calendar_list_get_count(list, &count);
+        if(CALENDAR_ERROR_NONE!=ret){
+            LogWarning("Getting calendar list count failed: "<<ret);
+        } else {
+            LogDebug("Calendar list count: "<<count);
+        }
+
+        calendar_record_h calendar = NULL;
+        calendar_list_first(list);
+
+        char* name = NULL;
+        int id, accountId, storeType;
+        while(count--)
+        {
+            if(CALENDAR_ERROR_NONE!=calendar_list_get_current_record_p(list, &calendar)) {
+                LogWarning("Getting current record failed.");
+                break;
+            }
+
+            ret = calendar_record_get_str(calendar, _calendar_book.name, &name);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar name: "<<ret);
+            }
+            ret = calendar_record_get_int(calendar, _calendar_book.id, &id);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar id: "<<ret);
+            }
+            ret = calendar_record_get_int(calendar, _calendar_book.account_id, &accountId);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar account id: "<<ret);
+            }
+            ret = calendar_record_get_int(calendar, _calendar_book.store_type, &storeType);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get calendar store type: "<<ret);
+            }
+
+            if (name != NULL) {
+                LogDebug("Got a calendar, id: "<<id<<", name: "<<name<<", account id: "<<accountId<<", storeType: "<<storeType);
+
+                if( (CALENDAR_BOOK_TYPE_EVENT==storeType && CalendarEvent::EVENT_TYPE==event->getType()) ||
+                    (CALENDAR_BOOK_TYPE_TODO==storeType && CalendarEvent::TASK_TYPE==event->getType()) ) {
+                    if(id==calendarId) {
+                        newCalendar->setName(name);
+                        newCalendar->setId(id);
+                        newCalendar->setAccountId(accountId);
+                        newCalendar->setType(event->getType());
+                        event->setCalendar(newCalendar);
+                        break;
+                    }
+                } else {
+                    LogDebug("Different calendar type.");
+                }
+                free(name);
+            } else {
+                LogError("Calendar contains invalid parameters");
+            }
+
+            calendar = NULL;
+
+            calendar_list_next(list);
+        }
+        
+        if(list) {
+            calendar_list_destroy(list, true);
+        }
+
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Calendar/CalendarManager.h b/src/platform/Tizen/Calendar/CalendarManager.h
new file mode 100755 (executable)
index 0000000..066925e
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 _CALENDARMANAGER_H_
+#define _CALENDARMANAGER_H_
+
+#include <API/Calendar/ICalendarManager.h>
+#include "Calendar.h"
+#include <dpl/mutex.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Calendar {
+
+class CalendarManager : public Api::Calendar::ICalendarManager
+{
+  public:
+    CalendarManager();
+    virtual ~CalendarManager();
+
+  protected:
+    virtual void OnRequestReceived(const IEventGetCalendarsPtr &event);
+    virtual void OnRequestReceived(const IEventGetDefaultCalendarPtr &event);
+    virtual void OnRequestReceived(const IEventGetCalendarPtr &event);
+
+  private:
+    static int m_instanceCount;
+    DPL::Mutex m_constructorMutex;
+};
+
+}
+}
+}
+
+#endif /* _CALENDARMANAGER_H_ */
diff --git a/src/platform/Tizen/Calendar/EventWrapper.cpp b/src/platform/Tizen/Calendar/EventWrapper.cpp
new file mode 100755 (executable)
index 0000000..2ec28ae
--- /dev/null
@@ -0,0 +1,2319 @@
+//
+// 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 <sstream>
+#include <algorithm>
+#include <time.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "EventWrapper.h"
+#include "Calendar.h"
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Platform {
+namespace Calendar {
+
+EventWrapper::EventWrapper(CalendarEvent::CalendarType type) :
+    m_platformEvent(NULL),
+    m_abstractEvent(NULL),
+    m_calendarType(type)
+{
+    m_abstractEvent = CalendarEventPtr(new CalendarEvent());
+    if (!m_abstractEvent) {
+        ThrowMsg(UnknownException, "Abstract object is not created.");
+    }
+}
+
+EventWrapper::EventWrapper(const CalendarEventPtr &event, CalendarEvent::CalendarType type) :
+    m_platformEvent(NULL),
+    m_abstractEvent(event),
+    m_calendarType(type)
+{
+}
+
+EventWrapper::EventWrapper(calendar_record_h event, CalendarEvent::CalendarType type) :
+    m_platformEvent(event),
+    m_abstractEvent(NULL),
+    m_calendarType(type)
+{
+    m_abstractEvent = CalendarEventPtr(new CalendarEvent());
+    if (!m_abstractEvent) {
+        ThrowMsg(UnknownException, "Abstract object is not created.");
+    }
+}
+
+EventWrapper::~EventWrapper()
+{
+    freePlatformEvent();
+}
+
+int EventWrapper::getIdFromPlatformEvent()
+{
+    if (m_platformEvent == NULL) {
+        ThrowMsg(NullPointerException, "m_platformEvent is not set");
+    }
+
+    int ret, id;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_todo.id, &id);
+    } else {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_event.id, &id);
+    }
+    if (CALENDAR_ERROR_NONE!=ret) {
+        ThrowMsg(PlatformException, "Can't get id: "<<ret);
+    } else {
+        return id;
+    }
+}
+
+void EventWrapper::setCalendarId(const std::string &value)
+{
+    LogDebug("calendar id "<<value);
+    m_calendarId = value;
+}
+
+void EventWrapper::setCalendarAccountId(const int value)
+{
+    LogDebug("account id "<<value);
+    m_calendarAccountId = value;
+}
+
+void EventWrapper::saveEvent()
+{
+    if (m_platformEvent == NULL) {
+        ThrowMsg(NullPointerException, "m_platformEvent is not set");
+    }
+
+    int itemId = m_abstractEvent->getId();
+    LogDebug("Before saving/update eventId: " << itemId);
+
+    //displayPlatformEvent();
+
+    int ret;
+    if (itemId <= UNDEFINED_ITEM_ID) {
+        ret = calendar_db_insert_record(m_platformEvent, &itemId);
+        if (CALENDAR_ERROR_NONE!=ret) {
+            ThrowMsg(PlatformException, "Can't insert new item: "<<ret);
+        }
+        m_abstractEvent->setId(itemId);
+        LogDebug("New calendar item inserted with id: "<<itemId);
+    } else {
+        ret = calendar_db_update_record(m_platformEvent);
+        if (CALENDAR_ERROR_NONE != ret) {
+            ThrowMsg(PlatformException, "Can't update new item: "<<ret);
+        }
+        LogDebug("Calendar item updated.");
+    }
+}
+
+void EventWrapper::loadEvent(int id)
+{
+    LogDebug("Item id to load: " << id);
+    freePlatformEvent();
+
+    const char *dataType;
+    if(getType() == CalendarEvent::TASK_TYPE) {
+        dataType = _calendar_todo._uri;
+    } else {
+        dataType = _calendar_event._uri;
+    }
+
+    int ret = calendar_db_get_record(dataType, id, &m_platformEvent);
+    if (CALENDAR_ERROR_NONE!=ret) {
+        m_platformEvent = NULL;
+        ThrowMsg(NotFoundException, "Can't get item with id: "<<id<<", error code: "<<ret);
+    }
+
+    int isDeleted;
+    if(getType() == CalendarEvent::TASK_TYPE) {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_todo.is_deleted, &isDeleted);
+    } else {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_event.is_deleted, &isDeleted);
+    }
+    if (CALENDAR_ERROR_NONE!=ret) {
+        ThrowMsg(NotFoundException, "Item already deleted.");
+    }
+
+    convertPlatformEventToAbstractEvent();
+
+    m_abstractEvent->setCalendarType(getType());
+    //displayAbstractEvent();
+}
+
+void EventWrapper::deleteEvent()
+{
+    if (m_platformEvent == NULL) {
+        ThrowMsg(NullPointerException, "Platform event is null.");
+    }
+
+    // If the recurrenceId is set, delete the instance of recurring event only.
+    int itemId = m_abstractEvent->getId();
+    long long int recurrenceId = m_abstractEvent->getRecurrenceId();
+    LogDebug("itemId to delete: " << itemId << ", recurrenceId: " << recurrenceId << ", type: " << getType());
+
+    calendar_record_h item = NULL;
+    const char *dataType;
+    if(getType() == CalendarEvent::TASK_TYPE) {
+        dataType = _calendar_todo._uri;
+    } else {
+        dataType = _calendar_event._uri;
+    }
+
+    int ret = calendar_db_get_record(dataType, itemId, &item);
+    if (CALENDAR_ERROR_NONE != ret) {
+        ThrowMsg(NotFoundException, "Can't get calendar item: "<<ret);
+    }
+
+    int isDeleted;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_todo.is_deleted, &isDeleted);
+    } else {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_event.is_deleted, &isDeleted);
+    }
+    if (CALENDAR_ERROR_NONE!=ret) {
+        if (item) {
+            calendar_record_destroy(item, true);
+        }
+        ThrowMsg(NotFoundException, "Item already deleted.");
+    }
+
+    if (item) {
+        calendar_record_destroy(item, true);
+    }
+
+    if ( 0>=recurrenceId || true==getAbstractEvent()->getIsDetached()) {
+        // Platform detects the detached events and uptates all instances.
+        ret = calendar_db_delete_record(dataType, itemId);
+        if (CALENDAR_ERROR_NONE != ret) {
+            if(CALENDAR_ERROR_DB_RECORD_NOT_FOUND==ret) {
+                ThrowMsg(NotFoundException, "Item not found.");
+            } else {
+                ThrowMsg(PlatformException, "Can't delete calendar item: "<<ret);
+            }
+        }
+        m_abstractEvent->resetId();
+    } else {
+        EventRecurrenceRulePtr rrule = m_abstractEvent->getRecurrenceRule();
+        (*rrule->getExceptions()).push_back(recurrenceId);
+
+        std::string exdate = "";
+        for( unsigned int i=0; i<rrule->getExceptions()->size(); i++ ) {
+            std::stringstream ss;
+            ss<<rrule->getExceptions()->at(i);
+            exdate.append(ss.str());
+            if(i!=rrule->getExceptions()->size()-1) {
+                exdate.append(",");
+            }
+        }
+        ret = calendar_record_set_str(m_platformEvent, _calendar_event.exdate, exdate.c_str());
+        if(ret!=CALENDAR_ERROR_NONE) {
+            ThrowMsg(PlatformException, "Can't delete the instance: "<<ret);
+        } else {
+            LogDebug("Set the exdate: "<<exdate);
+        }
+
+        ret = calendar_db_update_record(m_platformEvent);
+        if (CALENDAR_ERROR_NONE != ret) {
+            ThrowMsg(PlatformException, "Can't update the exdate "<<ret);
+        }
+        LogDebug("Calendar item instance deleted.");
+    }
+}
+
+void EventWrapper::createEventFromString(std::string value)
+{
+    if (value.empty()) {
+        ThrowMsg(NullPointerException, "Failed to create an item from string.");
+    } else {
+        LogDebug("string to convert: "<<value);
+    }
+
+    calendar_list_h list = NULL;
+    int ret;
+
+    ret = calendar_vcalendar_parse_to_calendar(value.c_str(), &list);
+    if (CALENDAR_ERROR_NONE != ret) {
+        ThrowMsg(PlatformException, "Can't convert string: "<<ret);
+    }
+    if (NULL==list) {
+        ThrowMsg(PlatformException, "No items converted.");
+    }
+
+    int count = -1;
+    if(CALENDAR_ERROR_NONE!=calendar_list_get_count(list, &count)){
+        LogWarning("Getting list count failed.");
+    } else {
+        LogDebug("List count: "<<count);
+    }
+
+    if(count>0) {
+        calendar_list_first(list);
+
+        // We cover only one item per string.
+        calendar_record_h currentItem = NULL;
+        ret = calendar_list_get_current_record_p(list, &currentItem);
+        if(CALENDAR_ERROR_NONE!=ret) {
+            LogWarning("Getting current record failed: "<<ret);
+        }
+
+        ret = calendar_record_clone(currentItem, &m_platformEvent);
+        if(CALENDAR_ERROR_NONE!=ret) {
+            LogWarning("Clonning failed: "<<ret);
+        }
+    }
+
+    if(list) {
+        calendar_list_destroy(list, true);
+    }
+
+    //displayPlatformEvent();
+}
+
+std::string EventWrapper::exportEventToString()
+{
+    char *vStrings = NULL;
+    calendar_list_h list = NULL;
+    int ret;
+    std::string returnString;
+
+    ret = calendar_list_create(&list);
+    if (CALENDAR_ERROR_NONE != ret) {
+        ThrowMsg(PlatformException, "Can't create a list: "<<ret);
+    }
+
+    ret = calendar_list_add(list, m_platformEvent);
+    if (CALENDAR_ERROR_NONE != ret) {
+        ThrowMsg(PlatformException, "Can't add list item: "<<ret);
+    }
+
+    ret = calendar_vcalendar_make_from_records(list, &vStrings);
+    if (CALENDAR_ERROR_NONE != ret) {
+        ThrowMsg(PlatformException, "Can't convert item to string: "<<ret);
+    }
+    if (NULL==vStrings) {
+        ThrowMsg(PlatformException, "No items converted.");
+    }
+
+    returnString = std::string(vStrings);
+
+    if(vStrings) {
+        free(vStrings);
+    }
+    if(list) {
+        // Don't destroy the record itself.
+        calendar_list_destroy(list, false);
+    }
+
+    return returnString;
+}
+
+calendar_record_h EventWrapper::getPlatformEvent() const
+{
+    return m_platformEvent;
+}
+
+CalendarEventPtr EventWrapper::getAbstractEvent() const
+{
+    return m_abstractEvent;
+}
+
+void EventWrapper::freePlatformEvent()
+{
+    if (m_platformEvent != NULL) {
+        if (CALENDAR_ERROR_NONE != calendar_record_destroy(m_platformEvent, true)) {
+            LogWarning("Can't destroy calendar record.");
+        }
+        m_platformEvent = NULL;
+    } else {
+        LogDebug("Null platform event.");
+    }
+}
+
+calendar_record_h EventWrapper::convertAbstractEventToPlatformEvent(bool loadBeforeConvert)
+{
+    freePlatformEvent();
+    const char *dataType;
+    int ret;
+
+    if(getType() == CalendarEvent::TASK_TYPE) {
+        dataType = _calendar_todo._uri;
+    } else {
+        dataType = _calendar_event._uri;
+    }
+
+    if(loadBeforeConvert) {
+        // Load the item for update operation to include the id.
+        ret = calendar_db_get_record(dataType, m_abstractEvent->getId(), &m_platformEvent);
+        if (CALENDAR_ERROR_NONE!=ret) {
+            ThrowMsg(NotFoundException, "Can't load the item with id: "<<m_abstractEvent->getId()<<", error code: "<<ret);
+        } else {
+            LogDebug("Item loaded with id: "<<m_abstractEvent->getId());
+        }
+    } else {
+        ret = calendar_record_create(dataType, &m_platformEvent);
+        if (CALENDAR_ERROR_NONE != ret) {
+            ThrowMsg(PlatformException, "Can't create platform record: "<<ret);
+        } else {
+            LogDebug("Platform item created with dataType: "<<dataType);
+        }
+    }
+
+    setDescriptionToPlatformEvent();
+    setSummaryToPlatformEvent();
+    setStartTimeToPlatformEvent();
+    setEndTimeToPlatformEvent(); // replacement for duration
+    setLocationToPlatformEvent();
+    setCategoriesToPlatformEvent();
+    setStatusToPlatformEvent();
+    setAlarmsToPlatformEvent();
+    setIsAllDayToPlatformEvent();
+    setOrganizerToPlatformEvent();
+    setAttendeesToPlatformEvent();
+    setPositionToPlatformEvent();
+    setVisibilityToPlatformEvent();
+    setAvailabilityToPlatformEvent();
+    setRecurrenceRuleToPlatformEvent();
+    //setUIdToPlatformEvent(); // We don't set uid but use id field instead.
+    setRecurrenceIdToPlatformEvent();
+    setParentIdToPlatformEvent();
+    setPriorityToPlatformEvent();
+    setCreatedDateToPlatformEvent();
+    setCompletedDateToPlatformEvent();
+    setProgressToPlatformEvent();
+
+    return getPlatformEvent();
+}
+
+void EventWrapper::setDescriptionToPlatformEvent()
+{
+    int ret;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_todo.description, m_abstractEvent->getDescription().c_str());
+    } else {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_event.description, m_abstractEvent->getDescription().c_str());
+    }
+    if (CALENDAR_ERROR_NONE!=ret) {
+        LogWarning("Can't set item description.");
+    }
+}
+
+void EventWrapper::setSummaryToPlatformEvent()
+{
+    int ret;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_todo.summary, m_abstractEvent->getSubject().c_str());
+    } else {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_event.summary, m_abstractEvent->getSubject().c_str());
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set item subject.");
+    }
+}
+
+void EventWrapper::setStartTimeToPlatformEvent()
+{
+    int ret;
+    long long int time = m_abstractEvent->getStartTime();
+    if (time == UNDEFINED_TIME) {
+        time = m_abstractEvent->getEndTime();
+    }
+
+    calendar_time_s cal;
+    if(m_abstractEvent->getIsAllDay()) {
+        cal.type = CALENDAR_TIME_LOCALTIME;
+               struct tm* localTime = localtime((time_t*)&time);
+               cal.time.date = {localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday};
+    } else {
+        cal.type = CALENDAR_TIME_UTIME;
+           cal.time.utime = time;
+    }
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_caltime(m_platformEvent, _calendar_todo.start_time, cal);
+    } else {
+        ret = calendar_record_set_caltime(m_platformEvent, _calendar_event.start_time, cal);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        ThrowMsg(PlatformException, "Can't set start time: "<<ret);
+    } else {
+        LogDebug("Set start time.");
+    }
+
+    const char* timeZone = m_abstractEvent->getTimeZone().c_str();
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_todo.start_tzid, timeZone);
+    } else {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_event.start_tzid, timeZone);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        ThrowMsg(PlatformException, "Can't set start time zone: "<<ret);
+    } else {
+        LogDebug("Set time zone: "<<timeZone);
+    }
+}
+
+void EventWrapper::setEndTimeToPlatformEvent()
+{
+    int ret;
+    long long int time = m_abstractEvent->getEndTime();
+    if (time == UNDEFINED_TIME) {
+        time = m_abstractEvent->getStartTime();
+    }
+
+    calendar_time_s cal;
+    if(m_abstractEvent->getIsAllDay()) {
+        cal.type = CALENDAR_TIME_LOCALTIME;
+               struct tm* localTime = localtime((time_t*)&time);
+               cal.time.date = {localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday};
+    } else {
+        cal.type = CALENDAR_TIME_UTIME;
+           cal.time.utime = time;
+    }
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_caltime(m_platformEvent, _calendar_todo.due_time, cal);
+    } else {
+        ret = calendar_record_set_caltime(m_platformEvent, _calendar_event.end_time, cal);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set end/due time: "<<ret);
+    }
+}
+
+void EventWrapper::setLocationToPlatformEvent()
+{
+    int ret;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_todo.location, m_abstractEvent->getLocation().c_str());
+    } else {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_event.location, m_abstractEvent->getLocation().c_str());
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set location.");
+    }
+}
+
+void EventWrapper::setRecurrenceRuleToPlatformEvent()
+{
+    if (CalendarEvent::TASK_TYPE==getType()) {
+        LogDebug("No need to set rrule for a task.");
+        return;
+    }
+
+    EventRecurrenceRulePtr rrule  = m_abstractEvent->getRecurrenceRule();
+    if (NULL==rrule) {
+        LogDebug("rrule is not set.");
+        return;
+    } else if(EventRecurrenceRule::NO_RECURRENCE==rrule->getFrequency()) {
+        LogDebug("No recurrence frequency.");
+        return;
+    } else if(EventRecurrenceRule::UNDEFINED_RECURRENCE==rrule->getFrequency()) {
+        LogDebug("Undefined recurrence frequency.");
+        return;
+    } else {
+        LogDebug("frequency "<<rrule->getFrequency());
+    }
+
+    // set frequency
+    switch (rrule->getFrequency()) {
+    case EventRecurrenceRule::NO_RECURRENCE:
+        if(CALENDAR_ERROR_NONE!=calendar_record_set_int(m_platformEvent, _calendar_event.freq, CALENDAR_RECURRENCE_NONE)) {
+            LogWarning("Failed setting frequency.");
+        }
+        break;
+    case EventRecurrenceRule::DAILY_RECURRENCE:
+        if(CALENDAR_ERROR_NONE!=calendar_record_set_int(m_platformEvent, _calendar_event.freq, CALENDAR_RECURRENCE_DAILY)) {
+            LogWarning("Failed setting frequency.");
+        }
+        break;
+    case EventRecurrenceRule::WEEKLY_RECURRENCE:
+    {
+        if(CALENDAR_ERROR_NONE!=calendar_record_set_int(m_platformEvent, _calendar_event.freq, CALENDAR_RECURRENCE_WEEKLY)) {
+            LogWarning("Failed setting frequency.");
+        }
+        break;
+    }
+    case EventRecurrenceRule::MONTHLY_RECURRENCE:
+    {
+        if(CALENDAR_ERROR_NONE!=calendar_record_set_int(m_platformEvent, _calendar_event.freq, CALENDAR_RECURRENCE_MONTHLY)) {
+            LogWarning("Failed setting frequency.");
+        }
+        break;
+    }
+    case EventRecurrenceRule::YEARLY_RECURRENCE:
+    {
+        if(CALENDAR_ERROR_NONE!=calendar_record_set_int(m_platformEvent, _calendar_event.freq, CALENDAR_RECURRENCE_YEARLY)) {
+            LogWarning("Failed setting frequency.");
+        }
+        break;
+    }
+    case EventRecurrenceRule::UNDEFINED_RECURRENCE:
+    default:
+        LogWarning("Invalid reccurence rule frequency "<<rrule->getFrequency());
+        break;
+    }
+
+    // set byday
+    StringArrayPtr daysOfTheWeek = rrule->getDaysOfTheWeek();
+    if( 0 != daysOfTheWeek->size() ) {
+        std::string byday = "";
+        for(unsigned int i=0; i<daysOfTheWeek->size(); i++) {
+            byday.append(daysOfTheWeek->at(i));
+            if(i!=daysOfTheWeek->size()-1) {
+                byday.append(",");
+            }
+        }
+
+        LogDebug("byday: "<<byday);
+        if (CALENDAR_ERROR_NONE!=calendar_record_set_str(m_platformEvent, _calendar_event.byday, byday.c_str())) {
+            LogWarning("Can't set byday.");
+        }
+    }
+
+    // set the ocurrence count
+    if (-1 != rrule->getOccurrenceCount()) {
+        LogDebug("Set the occurrence count: "<<rrule->getOccurrenceCount());
+
+        if (CALENDAR_ERROR_NONE != calendar_record_set_int(m_platformEvent, _calendar_event.range_type, CALENDAR_RANGE_COUNT)) {
+            LogWarning("Can't set rrule range type.");
+        }
+
+        if (CALENDAR_ERROR_NONE != calendar_record_set_int(m_platformEvent, _calendar_event.count, rrule->getOccurrenceCount())) {
+            LogWarning("Can't set occurrence count.");
+        }
+    }
+
+    // set the exceptions
+    if ( !rrule->getExceptions()->empty() )
+    {
+        LogDebug("Set the exceptions of length: "<<rrule->getExceptions()->size());
+
+        std::string exdate = "";
+        for( unsigned int i=0; i<rrule->getExceptions()->size(); i++ )
+        {
+            std::stringstream ss;
+            ss<<rrule->getExceptions()->at(i);
+            exdate.append(ss.str());
+            if(i!=rrule->getExceptions()->size()-1) {
+                exdate.append(",");
+            }
+        }
+        LogDebug("exdate: "<<exdate);
+        if (CALENDAR_ERROR_NONE!=calendar_record_set_str(m_platformEvent, _calendar_event.exdate, exdate.c_str())) {
+            LogWarning("Can't save exceptions.");
+        }
+    }
+
+    // set the setPositions
+    if ( !rrule->getSetPositions()->empty() )
+    {
+        LogDebug("Set the setPositions of length: "<<rrule->getSetPositions()->size());
+
+        std::string bysetpos = "";
+        for( unsigned int i=0; i<rrule->getSetPositions()->size(); i++ )
+        {
+            std::stringstream ss;
+            ss<<rrule->getSetPositions()->at(i);
+            bysetpos.append(ss.str());
+            if(i!=rrule->getSetPositions()->size()-1) {
+                bysetpos.append(",");
+            }
+        }
+        LogDebug("bysetpos: "<<bysetpos);
+        if (CALENDAR_ERROR_NONE!=calendar_record_set_str(m_platformEvent, _calendar_event.bysetpos, bysetpos.c_str())) {
+            LogWarning("Can't save setPositions.");
+        }
+    }
+
+    // set the recurrence interval
+    if (CALENDAR_ERROR_NONE != calendar_record_set_int(m_platformEvent,
+                                                   _calendar_event.interval,
+                                                   rrule->getInterval()))
+    {
+        LogWarning("Can't set interval.");
+    }
+
+    // set the recurrence end date. This is automatically calculated by platform if empty.
+    if (UNDEFINED_TIME!=rrule->getEndDate()) {
+        LogDebug("Setting the end date: "<<rrule->getEndDate());
+
+        if (CALENDAR_ERROR_NONE != calendar_record_set_int(m_platformEvent, _calendar_event.range_type, CALENDAR_RANGE_UNTIL)) {
+            LogWarning("Can't set rrule range type.");
+        }
+
+        int ret;
+        calendar_time_s cal = {CALENDAR_TIME_UTIME, {0}};
+        cal.type = CALENDAR_TIME_UTIME;
+        cal.time.utime = m_abstractEvent->getRecurrenceRule()->getEndDate();
+        ret = calendar_record_set_caltime(m_platformEvent, _calendar_event.until_time, cal);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't set rrule until time: "<<ret);
+        }
+    }
+}
+
+void EventWrapper::setAlarmsToPlatformEvent()
+{
+    if( 0 != m_abstractEvent->getAlarms()->size() ) {
+        int ret;
+        calendar_record_h alarm = NULL;
+
+        for( unsigned int i=0; i<m_abstractEvent->getAlarms()->size(); i++ )
+        {
+            LogDebug("Set the alarms #"<<i);
+
+            alarm = NULL;
+            ret = calendar_record_create(_calendar_alarm._uri, &alarm);
+            if(CALENDAR_ERROR_NONE!=ret) {
+                LogWarning("Alarm creation failed: "<<ret);
+                continue;
+            }
+
+            EventAlarmPtr theAlarm = m_abstractEvent->getAlarms()->at(i);
+
+            calendar_alarm_time_unit_type_e tickUnit = CALENDAR_ALARM_NONE;
+            int tick = 0;
+            if( UNDEFINED_TIME!=theAlarm->getAbsoluteDate() ) {
+                tickUnit = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
+            } else {
+                if( TizenApis::Api::TimeUtil::MSECS_UNIT==theAlarm->getDuration().unit ) {
+                    tickUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE; // minimum calendar time unit.
+                    tick = theAlarm->getDuration().length / 60000;
+                } else if( TizenApis::Api::TimeUtil::SECONDS_UNIT==theAlarm->getDuration().unit ) {
+                    tickUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
+                    tick = theAlarm->getDuration().length / 1000;
+                } else if( TizenApis::Api::TimeUtil::MINUTES_UNIT==theAlarm->getDuration().unit ) {
+                    tickUnit = CALENDAR_ALARM_TIME_UNIT_MINUTE;
+                    tick = theAlarm->getDuration().length;
+                } else if( TizenApis::Api::TimeUtil::HOURS_UNIT==theAlarm->getDuration().unit ) {
+                    tickUnit = CALENDAR_ALARM_TIME_UNIT_HOUR;
+                    tick = theAlarm->getDuration().length;
+                } else if( TizenApis::Api::TimeUtil::DAYS_UNIT==theAlarm->getDuration().unit ) {
+                    tickUnit = CALENDAR_ALARM_TIME_UNIT_DAY;
+                    tick = theAlarm->getDuration().length;
+                } else {
+                    LogWarning("Wrong alarm time unit: "<<theAlarm->getDuration().unit);
+                }
+            }
+
+            if( CALENDAR_ALARM_TIME_UNIT_SPECIFIC==tickUnit ) {
+                long long int time = theAlarm->getAbsoluteDate();
+                LogDebug("Save absolute date: "<<time);
+                ret = calendar_record_set_lli(alarm, _calendar_alarm.time, time);
+                if (CALENDAR_ERROR_NONE != ret) {
+                    LogWarning("Can't set alarm time: "<<ret);
+                }
+            } else {
+                ret = calendar_record_set_int(alarm, _calendar_alarm.tick, tick);
+                if (CALENDAR_ERROR_NONE != ret) {
+                    LogWarning("Can't set alarm tick: "<<ret);
+                }
+            }
+
+            ret = calendar_record_set_int(alarm, _calendar_alarm.tick_unit, tickUnit);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't set alarm tick unit: "<<ret);
+            }
+
+            // Set the alarm type.
+            ret = calendar_record_set_int(alarm, _calendar_alarm.type, theAlarm->getMethods().at(0));
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't set alarm type: "<<ret);
+            }
+
+            // Set the display text
+            ret = calendar_record_set_str(alarm, _calendar_alarm.description, theAlarm->getDescription().c_str());
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't set alarm description: "<<ret);
+            }
+
+            if(CalendarEvent::TASK_TYPE==getType()) {
+                ret = calendar_record_add_child_record(m_platformEvent, _calendar_todo.calendar_alarm, alarm);
+            } else {
+                ret = calendar_record_add_child_record(m_platformEvent, _calendar_event.calendar_alarm, alarm);
+            }
+            if(CALENDAR_ERROR_NONE!=ret) {
+                LogWarning("Cannot add alarm child record: "<<ret);
+                if(alarm) {
+                    calendar_record_destroy(alarm, true);
+                }
+            }
+        }
+    } else {
+        LogDebug("No alarms to save.");
+    }
+}
+
+void EventWrapper::setStatusToPlatformEvent()
+{
+    int ret;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        calendar_todo_status_e taskStatus = CALENDAR_TODO_STATUS_NONE;
+
+        switch (m_abstractEvent->getStatus()) {
+        case CalendarEvent::NEEDS_ACTION_STATUS:
+            taskStatus = CALENDAR_TODO_STATUS_NEEDS_ACTION;
+            break;
+        case CalendarEvent::COMPLETED_STATUS:
+            taskStatus = CALENDAR_TODO_STATUS_COMPLETED;
+            break;
+        case CalendarEvent::IN_PROCESS_STATUS:
+            taskStatus = CALENDAR_TODO_STATUS_IN_PROCESS;
+            break;
+        case CalendarEvent::CANCELLED_STATUS:
+            taskStatus = CALENDAR_TODO_STATUS_CANCELED;
+            break;
+        default:
+            break;
+        }
+
+        ret = calendar_record_set_int(m_platformEvent, _calendar_todo.todo_status, taskStatus);
+    } else {
+        calendar_event_status_e eventStatus = CALENDAR_EVENT_STATUS_NONE;
+
+        switch (m_abstractEvent->getStatus()) {
+        case CalendarEvent::TENTATIVE_STATUS:
+            eventStatus = CALENDAR_EVENT_STATUS_TENTATIVE;
+            break;
+        case CalendarEvent::CONFIRMED_STATUS:
+            eventStatus = CALENDAR_EVENT_STATUS_CONFIRMED;
+            break;
+        case CalendarEvent::CANCELLED_STATUS:
+            eventStatus = CALENDAR_EVENT_STATUS_CANCELLED;
+            break;
+        default:
+            break;
+        }
+
+        ret = calendar_record_set_int(m_platformEvent, _calendar_event.event_status, eventStatus);
+    }
+
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set item status.");
+    }
+}
+
+void EventWrapper::setCategoriesToPlatformEvent()
+{
+    int ret;
+    std::string categories = "";
+
+    // Need to concatenate all categories into one string separated by a comma.
+    for (size_t i = 0; i < m_abstractEvent->getCategories()->size(); ++i) {
+        if(0==i) {
+            categories.append(m_abstractEvent->getCategories()->at(i));
+        } else {
+            categories.append("," + m_abstractEvent->getCategories()->at(i));
+        }
+    }
+
+    LogDebug("Saving categories: "<<categories);
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_todo.categories, categories.c_str());
+    } else {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_event.categories, categories.c_str());
+    }
+    if (CALENDAR_ERROR_NONE !=ret) {
+        LogWarning("Cannot save categories.");
+    }
+}
+
+void EventWrapper::setRecurrenceIdToPlatformEvent()
+{
+    int ret;
+    if (CalendarEvent::TASK_TYPE==getType()) {
+        LogDebug("No need to set recurrence id for a task.");
+        return;
+    }
+
+    if(UNDEFINED_TIME!=m_abstractEvent->getRecurrenceId()) {
+        std::stringstream ss;
+        ss<<m_abstractEvent->getRecurrenceId();
+        ret = calendar_record_set_str(m_platformEvent, _calendar_event.recurrence_id, ss.str().c_str());
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't set recurrence id.");
+        } else {
+            LogDebug("Set the recurrence id: "<<ss.str());
+        }
+    } else {
+        LogDebug("Recurrence id not defined.");
+    }
+}
+
+void EventWrapper::setParentIdToPlatformEvent()
+{
+    int ret;
+    if (CalendarEvent::TASK_TYPE==getType()) {
+        LogDebug("No need to set parent id for a task.");
+        return;
+    }
+
+    if(UNDEFINED_ITEM_ID!=m_abstractEvent->getParentId()) {
+        ret = calendar_record_set_int(m_platformEvent, _calendar_event.original_event_id, m_abstractEvent->getParentId());
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't set parent Id.");
+        } else {
+            LogDebug("Set the parent id: "<<m_abstractEvent->getParentId());
+        }
+    } else {
+        LogDebug("Parent id not defined.");
+    }
+}
+
+void EventWrapper::setIsAllDayToPlatformEvent()
+{
+    LogDebug("All day flag is set in the start time struct: "<<m_abstractEvent->getIsAllDay());
+}
+
+void EventWrapper::setOrganizerToPlatformEvent()
+{
+    int ret;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_todo.organizer_name, m_abstractEvent->getOrganizer().c_str());
+    } else {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_event.organizer_name, m_abstractEvent->getOrganizer().c_str());
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set item organizer.");
+    }
+}
+
+void EventWrapper::setVisibilityToPlatformEvent()
+{
+    int ret;
+    calendar_sensitivity_e visibility = CALENDAR_SENSITIVITY_PUBLIC;
+
+    switch (m_abstractEvent->getVisibility()) {
+    case CalendarEvent::PUBLIC_VISIBILITY:
+        visibility = CALENDAR_SENSITIVITY_PUBLIC;
+        break;
+    case CalendarEvent::PRIVATE_VISIBILITY:
+        visibility = CALENDAR_SENSITIVITY_PRIVATE;
+        break;
+    case CalendarEvent::CONFIDENTIAL_VISIBILITY:
+        visibility = CALENDAR_SENSITIVITY_CONFIDENTIAL;
+        break;
+    default:
+        LogDebug("Use the default visibility");
+        break;
+    }
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_int(m_platformEvent, _calendar_todo.sensitivity, visibility);
+    } else {
+        ret = calendar_record_set_int(m_platformEvent, _calendar_event.sensitivity, visibility);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set visibility.");
+    }
+}
+
+void EventWrapper::setAvailabilityToPlatformEvent()
+{
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        LogDebug("No need to set availability for a task.");
+        return;
+    }
+
+    calendar_event_busy_status_e availability = CALENDAR_EVENT_BUSY_STATUS_FREE;
+    switch (m_abstractEvent->getAvailability()) {
+    case CalendarEvent::BUSY_FB:
+        availability = CALENDAR_EVENT_BUSY_STATUS_BUSY;
+        break;
+    case CalendarEvent::BUSY_UNAVAILABLE_FB:
+        availability = CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE;
+        break;
+    case CalendarEvent::FREE_FB:
+        availability = CALENDAR_EVENT_BUSY_STATUS_FREE;
+        break;
+    case CalendarEvent::BUSY_TENTATIVE_FB:
+        availability = CALENDAR_EVENT_BUSY_STATUS_TENTATIVE;
+        break;
+    default:
+        LogDebug("Use the default availability");
+        break;
+    }
+
+    int ret = calendar_record_set_int(m_platformEvent, _calendar_event.busy_status, availability);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set availability.");
+    }
+}
+
+void EventWrapper::setUIdToPlatformEvent()
+{
+    int ret;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_todo.uid, m_abstractEvent->getUId().c_str());
+    } else {
+        ret = calendar_record_set_str(m_platformEvent, _calendar_event.uid, m_abstractEvent->getUId().c_str());
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set item uid.");
+    }
+}
+
+void EventWrapper::setAttendeesToPlatformEvent()
+{
+    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) {
+            LogDebug("Adding attendee "<<i+1<<" over "<<attendeeList->size());
+
+            attendee = NULL;
+            ret = calendar_record_create(_calendar_attendee._uri, &attendee);
+            if(CALENDAR_ERROR_NONE!=ret) {
+                LogWarning("Attendee creation failed: "<<ret);
+                continue;
+            }
+
+            EventAttendeePtr theAttendee = attendeeList->at(i);
+
+            // save name
+            ret = calendar_record_set_str(attendee, _calendar_attendee.name, theAttendee->getName().c_str());
+            if (CALENDAR_ERROR_NONE!=ret) {
+                LogWarning("Cannot set attendee name: "<<ret);
+            }
+
+            // save uri
+            ret = calendar_record_set_str(attendee, _calendar_attendee.email, theAttendee->getURI().c_str());
+            if (CALENDAR_ERROR_NONE!=ret) {
+                LogWarning("Cannot set attendee URI: "<<ret);
+            }
+
+            // save role
+            calendar_attendee_role_e role = CALENDAR_ATTENDEE_ROLE_CHAIR;
+            switch (theAttendee->getRole()) {
+            case EventAttendee::REQ_PARTICIPANT_ROLE:
+                role = CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT;
+                break;
+            case EventAttendee::OPT_PARTICIPANT_ROLE:
+                role = CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT;
+                break;
+            case EventAttendee::NON_PARTICIPANT_ROLE:
+                role = CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT;
+                break;
+            case EventAttendee::CHAIR_ROLE:
+                role = CALENDAR_ATTENDEE_ROLE_CHAIR;
+                break;
+            default:
+                LogDebug("Use the default role");
+                break;
+            }
+            ret = calendar_record_set_int(attendee, _calendar_attendee.role, role);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Cannot set attendee role: "<<ret);
+            }
+
+            // save status
+            calendar_attendee_status_e status = CALENDAR_ATTENDEE_STATUS_PENDING;
+            switch (theAttendee->getStatus()) {
+            case EventAttendee::PENDING_AT_STATUS:
+                status = CALENDAR_ATTENDEE_STATUS_PENDING;
+                break;
+            case EventAttendee::ACCEPTED_AT_STATUS:
+                status = CALENDAR_ATTENDEE_STATUS_ACCEPTED;
+                break;
+            case EventAttendee::DECLINED_AT_STATUS:
+                status = CALENDAR_ATTENDEE_STATUS_DECLINED;
+                break;
+            case EventAttendee::TENTATIVE_AT_STATUS:
+                status = CALENDAR_ATTENDEE_STATUS_TENTATIVE;
+                break;
+            case EventAttendee::DELEGATED_AT_STATUS:
+                status = CALENDAR_ATTENDEE_STATUS_DELEGATED;
+                break;
+            case EventAttendee::COMPLETED_AT_STATUS:
+                status = CALENDAR_ATTENDEE_STATUS_COMPLETED;
+                break;
+            case EventAttendee::IN_PROCESS_AT_STATUS:
+                status = CALENDAR_ATTENDEE_STATUS_IN_PROCESS;
+                break;
+            default:
+                LogDebug("Use the default status");
+                break;
+            }
+            ret = calendar_record_set_int(attendee, _calendar_attendee.status, status);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Cannot set attendee status: "<<ret);
+            }
+
+            // save RSVP
+            ret = calendar_record_set_int(attendee, _calendar_attendee.rsvp, theAttendee->getRSVP());
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Cannot set attendee RSVP: "<<ret);
+            }
+
+            // save type
+            ret = calendar_record_set_int(attendee, _calendar_attendee.type, theAttendee->getType());
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Cannot set attendee type: "<<ret);
+            }
+
+            // save group
+            ret = calendar_record_set_str(attendee, _calendar_attendee.group, theAttendee->getGroup().c_str());
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Cannot set attendee group: "<<ret);
+            }
+
+            // save delegatorURI
+            ret = calendar_record_set_str(attendee, _calendar_attendee.delegator_uri, theAttendee->getDelegatorURI().c_str());
+            if (CALENDAR_ERROR_NONE != ret ) {
+                LogWarning("Cannot set attendee delegator uri "<<ret);
+            }
+
+            // save delegateURI
+            ret = calendar_record_set_str(attendee, _calendar_attendee.delegate_uri, theAttendee->getDelegateURI().c_str());
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Cannot set attendee delegate uri: "<<ret);
+            }
+
+            // save contactId
+            ret = calendar_record_set_str(attendee, _calendar_attendee.uid, theAttendee->getContactId().c_str());
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Cannot set attendee uid: "<<ret);
+            }
+
+            // save addressBookId
+            std::stringstream ss(attendeeList->at(i)->getAddressBookId());
+            int addressBookId;
+            ss>>addressBookId;
+            LogDebug("addressBookId: "<<addressBookId);
+            ret = calendar_record_set_int(attendee, _calendar_attendee.person_id, addressBookId);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Cannot set attendee address book id "<<ret);
+            }
+
+            if(CalendarEvent::TASK_TYPE==getType()) {
+                ret = calendar_record_add_child_record(m_platformEvent, _calendar_todo.calendar_attendee, attendee);
+                return;
+            } else {
+                ret = calendar_record_add_child_record(m_platformEvent, _calendar_event.calendar_attendee, attendee);
+            }
+            if(CALENDAR_ERROR_NONE!=ret) {
+                LogWarning("Cannot add attendee child record: "<<ret);
+                if(attendee) {
+                    calendar_record_destroy(attendee, true);
+                }
+            }
+        }
+    } else {
+       LogDebug("No attendee to save.");
+   }
+}
+
+void EventWrapper::setPositionToPlatformEvent()
+{
+    int ret;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_double(m_platformEvent, _calendar_todo.latitude, m_abstractEvent->getLatitude());
+    } else {
+        ret = calendar_record_set_double(m_platformEvent, _calendar_event.latitude, m_abstractEvent->getLatitude());
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set latitude: "<<ret);
+    }
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_double(m_platformEvent, _calendar_todo.longitude, m_abstractEvent->getLongitude());
+    } else {
+        ret = calendar_record_set_double(m_platformEvent, _calendar_event.longitude, m_abstractEvent->getLongitude());
+    }
+
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set longitude: "<<ret);
+    }
+}
+
+void EventWrapper::setPriorityToPlatformEvent()
+{
+    int ret;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        calendar_todo_priority_e todoPriority = CALENDAR_TODO_PRIORITY_NORMAL;
+
+        switch (m_abstractEvent->getPriority()) {
+        case CalendarEvent::HIGH_PRIORITY:
+            todoPriority = CALENDAR_TODO_PRIORITY_HIGH;
+            break;
+        case CalendarEvent::MEDIUM_PRIORITY:
+            todoPriority = CALENDAR_TODO_PRIORITY_NORMAL;
+            break;
+        case CalendarEvent::LOW_PRIORITY:
+            todoPriority = CALENDAR_TODO_PRIORITY_LOW;
+            break;
+        default:
+            break;
+        }
+
+        ret = calendar_record_set_int(m_platformEvent, _calendar_todo.priority, todoPriority);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't set task priority: "<<ret);
+        }
+    } else {
+        calendar_event_priority_e eventPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
+
+        switch (m_abstractEvent->getPriority()) {
+        case CalendarEvent::HIGH_PRIORITY:
+            eventPriority = CALENDAR_EVENT_PRIORITY_HIGH;
+            break;
+        case CalendarEvent::MEDIUM_PRIORITY:
+            eventPriority = CALENDAR_EVENT_PRIORITY_NORMAL;
+            break;
+        case CalendarEvent::LOW_PRIORITY:
+            eventPriority = CALENDAR_EVENT_PRIORITY_LOW;
+            break;
+        default:
+            break;
+        }
+
+        ret = calendar_record_set_int(m_platformEvent, _calendar_event.priority, eventPriority);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't set event priority: "<<ret);
+        }
+    }
+}
+
+void EventWrapper::setCreatedDateToPlatformEvent()
+{
+    int ret;
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_set_lli(m_platformEvent, _calendar_todo.created_time, m_abstractEvent->getCreatedDate());
+    } else {
+        ret = calendar_record_set_lli(m_platformEvent, _calendar_event.created_time, m_abstractEvent->getCreatedDate());
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set createde time: "<<ret);
+    }
+}
+
+void EventWrapper::setCompletedDateToPlatformEvent()
+{   
+    if(CalendarEvent::EVENT_TYPE==getType()) {
+        LogDebug("No need to set the completed date for an event.");
+        return;
+    }
+
+    int ret = calendar_record_set_lli(m_platformEvent, _calendar_todo.completed_time, m_abstractEvent->getCompletedDate());
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning( "Can't set createde time: "<<ret);
+    }
+}
+
+void EventWrapper::setProgressToPlatformEvent()
+{   
+    if(CalendarEvent::EVENT_TYPE==getType()) {
+        LogDebug("No need to set the progress for an event.");
+        return;
+    }
+
+    int ret = calendar_record_set_int(m_platformEvent, _calendar_todo.progress, m_abstractEvent->getProgress());
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't set progress: "<<ret);
+    }
+}
+
+CalendarEventPtr EventWrapper::convertPlatformEventToAbstractEvent()
+{
+    LogDebug("Convert to abstract event.");
+    setDescriptionFromPlatformEvent();
+    setSummaryFromPlatformEvent();
+    setStartTimeFromPlatformEvent();
+    setEndTimeFromPlatformEvent(); // replace for duration
+    setLocationFromPlatformEvent();
+    setCategoriesFromPlatformEvent();
+    setStatusFromPlatformEvent();
+    setAlarmsFromPlatformEvent();
+    setIsAllDayFromPlatformEvent();
+    setOrganizerFromPlatformEvent();
+    setAttendeesFromPlatformEvent();
+    setPositionFromPlatformEvent();
+    setVisibilityFromPlatformEvent();
+    setLastModifiedDateFromPlatformEvent();
+    setAvailabilityFromPlatformEvent();
+    setRecurrenceRuleFromPlatformEvent();
+    setIdFromPlatformEvent();
+    setRecurrenceIdFromPlatformEvent();
+    setParentIdFromPlatformEvent();
+    //setUIdFromPlatformEvent(); // We set the uid value as the same with id.
+    setPriorityFromPlatformEvent();
+    setCreatedDateFromPlatformEvent();
+    setCompletedDateFromPlatformEvent();
+    setProgressFromPlatformEvent();
+    setIsDetachedFromPlatformEvent();
+
+    return getAbstractEvent();
+}
+
+void EventWrapper::setDescriptionFromPlatformEvent()
+{
+    int ret;
+    char *description = NULL;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_todo.description, &description);
+    } else {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_event.description, &description);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get description: "<<ret);
+    }
+
+    if (description) {
+        m_abstractEvent->setDescription(description);
+        free(description);
+    }
+}
+
+void EventWrapper::setSummaryFromPlatformEvent()
+{
+    int ret;
+    char *summary = NULL;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_todo.summary, &summary);
+    } else {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_event.summary, &summary);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get summary: "<<ret);
+    }
+
+    if (summary) {
+        m_abstractEvent->setSubject(summary);
+        free(summary);
+    }
+}
+
+void EventWrapper::setStartTimeFromPlatformEvent()
+{
+    int ret;
+    calendar_time_s cal;
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_caltime(m_platformEvent, _calendar_todo.start_time, &cal);
+    } else {
+        ret = calendar_record_get_caltime(m_platformEvent, _calendar_event.start_time, &cal);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        ThrowMsg(PlatformException, "Can't get start time: "<<ret);
+    }
+
+    // Set the isAllDay flag also.
+    if(CALENDAR_TIME_LOCALTIME==cal.type) {
+               struct tm tmTime = {0};
+               tmTime.tm_year = cal.time.date.year - 1900;
+               tmTime.tm_mon = cal.time.date.month - 1;
+               tmTime.tm_mday = cal.time.date.mday;
+        m_abstractEvent->setStartTime(mktime(&tmTime));
+        m_abstractEvent->setIsAllDay(true);
+    } else {
+        m_abstractEvent->setStartTime(cal.time.utime);
+        m_abstractEvent->setIsAllDay(false);
+    }
+
+    // Retrive the time zone info only when the start time is loaded.
+    char *timeZone = NULL;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_todo.start_tzid, &timeZone);
+    } else {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_event.start_tzid, &timeZone);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get time zone: "<<ret);
+    }
+
+    if( timeZone ) {
+        LogDebug("timeZone: "<<timeZone);
+        m_abstractEvent->setTimeZone(std::string(timeZone));
+        free(timeZone);
+    }
+}
+
+void EventWrapper::setEndTimeFromPlatformEvent()
+{
+    int ret;
+    calendar_time_s cal;
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_caltime(m_platformEvent, _calendar_todo.due_time, &cal);
+    } else {
+        ret = calendar_record_get_caltime(m_platformEvent, _calendar_event.end_time, &cal);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get due/end time: "<<ret);
+        return;
+    }
+
+    // Set the isAllDay flag also.
+    if(CALENDAR_TIME_LOCALTIME==cal.type) {
+               struct tm tmTime = {0};
+               tmTime.tm_year = cal.time.date.year - 1900;
+               tmTime.tm_mon = cal.time.date.month - 1;
+               tmTime.tm_mday = cal.time.date.mday;
+        m_abstractEvent->setEndTime(mktime(&tmTime));
+    } else {
+        m_abstractEvent->setEndTime(cal.time.utime);
+    }
+}
+
+void EventWrapper::setLocationFromPlatformEvent()
+{
+    int ret;
+    char *location = NULL;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_todo.location, &location);
+    } else {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_event.location, &location);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get location: "<<ret);
+    }
+
+    if (location) {
+        m_abstractEvent->setLocation(location);
+        free(location);
+    }
+}
+
+void EventWrapper::setRecurrenceRuleFromPlatformEvent()
+{
+    if (CalendarEvent::TASK_TYPE==getType()) {
+        LogDebug("No need to set rrule for a task.");
+        return;
+    }
+
+    int ret;
+    EventRecurrenceRulePtr rrule(new EventRecurrenceRule());
+
+    // load the recurrence frequency
+    int frequency;    
+    ret = calendar_record_get_int(m_platformEvent, _calendar_event.freq, &frequency);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get frequency: "<<ret);
+        return;
+    }
+    LogDebug("frequency "<<frequency);
+    switch (frequency) {
+    case CALENDAR_RECURRENCE_NONE:
+        rrule->setFrequency(EventRecurrenceRule::NO_RECURRENCE);
+        return;
+        break;
+    case CALENDAR_RECURRENCE_DAILY:
+        rrule->setFrequency(EventRecurrenceRule::DAILY_RECURRENCE);
+        break;
+    case CALENDAR_RECURRENCE_WEEKLY:
+        rrule->setFrequency(EventRecurrenceRule::WEEKLY_RECURRENCE);
+        break;
+    case CALENDAR_RECURRENCE_MONTHLY:
+        rrule->setFrequency(EventRecurrenceRule::MONTHLY_RECURRENCE);
+        break;
+    case CALENDAR_RECURRENCE_YEARLY:
+        rrule->setFrequency(EventRecurrenceRule::YEARLY_RECURRENCE);
+        break;
+    default:
+        LogWarning("Unknown recurrence frequency.");
+        rrule->setFrequency(EventRecurrenceRule::NO_RECURRENCE);
+        return;
+        break;
+    }
+
+    // load the byday
+    StringArrayPtr daysOfTheWeek(new StringArray());
+    char* byday = NULL;
+    ret = calendar_record_get_str(m_platformEvent, _calendar_event.byday, &byday);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get byday: "<<ret);
+    }
+    LogDebug("Loaded byday: "<<byday);
+    if (byday) {
+        char *saveptr = NULL;
+        char* pch = strtok_r(byday, ",", &saveptr);
+        while (NULL != pch) {
+            (*daysOfTheWeek).push_back(pch);
+            pch = strtok_r(NULL, ",", &saveptr);
+        }
+        free(byday);
+    }
+    rrule->setDaysOfTheWeek(daysOfTheWeek);
+    LogDebug("Number of daysOfTheWeek: "<<rrule->getDaysOfTheWeek()->size());
+
+    // load the recurrence interval
+    int interval;
+    ret = calendar_record_get_int(m_platformEvent, _calendar_event.interval, &interval);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get interval: "<<ret);
+    }
+    rrule->setInterval(interval);
+
+    // load the ocurrence count
+    int occurrrenceCount;
+    ret = calendar_record_get_int(m_platformEvent, _calendar_event.count, &occurrrenceCount);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get occurrrence count: "<<ret);
+    }
+    rrule->setOccurrenceCount(occurrrenceCount);
+
+    // load the recurrence end date
+    calendar_time_s cal = {CALENDAR_TIME_UTIME, {0}};
+    ret = calendar_record_get_caltime(m_platformEvent, _calendar_event.until_time, &cal);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get recurrence end date: "<<ret);
+    }
+
+    rrule->setEndDate(cal.time.utime);
+    LogDebug("endDate from platform = "<<rrule->getEndDate());
+
+    // load the exceptions
+    NumberArrayPtr exceptions(new NumberArray());
+    char* exdate = NULL;
+    ret = calendar_record_get_str(m_platformEvent, _calendar_event.exdate, &exdate);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get exdate: "<<ret);
+    }
+    LogDebug("Loaded exdate: "<<exdate);
+    if (exdate) {
+        char *saveptr = NULL;
+        char *pch = strtok_r(exdate, ",", &saveptr);
+        while (NULL != pch) {
+            std::stringstream ss(pch);
+            long long int oneException;
+            ss>>oneException;
+            (*exceptions).push_back(oneException);
+            pch = strtok_r(NULL, ",", &saveptr);
+        }
+        free(exdate);
+    }
+    rrule->setExceptions(exceptions);
+    LogDebug("Number of exceptions: "<<rrule->getExceptions()->size());
+
+    // load the setPositions
+    NumberArrayPtr setPositions(new NumberArray());
+    char* bysetpos = NULL;
+    ret = calendar_record_get_str(m_platformEvent, _calendar_event.bysetpos, &bysetpos);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get bysetpos: "<<ret);
+    }
+    LogDebug("Loaded bysetpos: "<<bysetpos);
+    if (bysetpos) {
+        char *saveptr = NULL;
+        char *pch = strtok_r(bysetpos, ",", &saveptr);
+        while (NULL != pch) {
+            std::stringstream ss(pch);
+            int setPos;
+            ss>>setPos;
+            (*setPositions).push_back(setPos);
+            pch = strtok_r(NULL, ",", &saveptr);
+        }
+        free(bysetpos);
+    }
+    rrule->setSetPositions(setPositions);
+    LogDebug("Number of setPositions: "<<rrule->getSetPositions()->size());
+
+    // set the loaded recurrence rule
+    m_abstractEvent->setRecurrenceRule(rrule);
+}
+
+void EventWrapper::setAlarmsFromPlatformEvent()
+{
+    int ret;
+    unsigned int count = 0, i;
+    calendar_list_h list = NULL;
+
+    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);
+    }
+
+    if(0==count) {
+        LogDebug("No alarms to set.");
+        return;
+    } else {
+        LogDebug("Number of alarms: "<<count);
+    }
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_clone_child_record_list(m_platformEvent, _calendar_todo.calendar_alarm, &list);
+    } else {
+        ret = calendar_record_clone_child_record_list(m_platformEvent, _calendar_event.calendar_alarm, &list);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get alarms list: "<<ret);
+        return;
+    }
+
+    int tick, tickUnit;
+    calendar_record_h alarm = NULL;
+    for(i=0; i<count; i++)
+    {
+        LogDebug("Processing the alarm #"<<i);
+
+        if(CalendarEvent::TASK_TYPE==getType()) {
+            ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_todo.calendar_alarm, i, &alarm);
+        } else {
+            ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_event.calendar_alarm, i, &alarm);
+        }
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't get the alarm: "<<ret);
+            continue;
+        }
+
+        EventAlarmPtr theAlarm( new EventAlarm() );
+
+        ret = calendar_record_get_int(alarm, _calendar_alarm.tick_unit, &tickUnit);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read alarm tick unit: "<<ret);
+            continue;
+        }
+
+        if( CALENDAR_ALARM_TIME_UNIT_SPECIFIC==tickUnit ) {
+            long long int time;
+            ret = calendar_record_get_lli(alarm, _calendar_alarm.time, &time);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Can't get alarm tick: "<<ret);
+                continue;
+            }
+            theAlarm->setAbsoluteDate(time);
+            LogDebug("Loaded absolute date: "<<theAlarm->getAbsoluteDate());
+        } else {
+            ret = calendar_record_get_int(alarm, _calendar_alarm.tick, &tick);
+            if (CALENDAR_ERROR_NONE != ret) {
+                LogWarning("Cannot read alarm tick. Stop processing alarms.");
+                continue;
+            }
+
+            TizenApis::Api::TimeUtil::DurationProperties duration;
+            if( CALENDAR_ALARM_TIME_UNIT_MINUTE==tickUnit ) {
+                duration.unit = TizenApis::Api::TimeUtil::MINUTES_UNIT;
+                duration.length = tick;
+            } else if( CALENDAR_ALARM_TIME_UNIT_HOUR==tickUnit ) {
+                duration.unit = TizenApis::Api::TimeUtil::HOURS_UNIT;
+                duration.length = tick;
+            } else if( CALENDAR_ALARM_TIME_UNIT_DAY==tickUnit ) {
+                duration.unit = TizenApis::Api::TimeUtil::DAYS_UNIT;
+                duration.length = tick;
+            } else if( CALENDAR_ALARM_TIME_UNIT_WEEK==tickUnit) {
+                duration.unit = TizenApis::Api::TimeUtil::DAYS_UNIT;
+                duration.length = tick*7;
+            } else if( CALENDAR_ALARM_TIME_UNIT_MONTH==tickUnit) {
+                // Not supportd correctly.
+                duration.unit = TizenApis::Api::TimeUtil::DAYS_UNIT;
+                duration.length = tick*30;
+            } else {
+                LogWarning("Wrong tick unit: "<<tickUnit);
+            }
+
+            theAlarm->setDuration(duration);
+        }
+
+        std::vector<EventAlarm::EventAlarmType> methods;
+        int type;
+        ret = calendar_record_get_int(alarm, _calendar_alarm.type, &type);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read alarm type: "<<ret);
+            continue;
+        }
+        methods.push_back((EventAlarm::EventAlarmType)type);
+        theAlarm->setMethods(methods);
+
+        char* description = NULL;
+        ret = calendar_record_get_str(alarm, _calendar_alarm.description, &description);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read alarm description: "<<ret);
+            theAlarm->setDescription("");
+            free(description);
+        } else {
+            LogDebug("Alarm description: "<<description);
+            if(description) {
+                theAlarm->setDescription(description);
+            }
+        }
+
+        // Save the alarm.
+        m_abstractEvent->getAlarms()->push_back(theAlarm);
+    }
+
+    if(list) {
+        calendar_list_destroy(list, true);
+    }
+    LogDebug("Number of alarms: "<<m_abstractEvent->getAlarms()->size());
+}
+
+void EventWrapper::setStatusFromPlatformEvent()
+{
+    int ret;
+    int status;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_todo.todo_status, &status);
+    } else {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_event.event_status, &status);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get status: "<<ret);
+        return;
+    }
+
+    switch (status) {
+    case CALENDAR_EVENT_STATUS_TENTATIVE:
+        m_abstractEvent->setStatus(CalendarEvent::TENTATIVE_STATUS);
+        break;
+    case CALENDAR_EVENT_STATUS_CONFIRMED:
+        m_abstractEvent->setStatus(CalendarEvent::CONFIRMED_STATUS);
+        break;
+    case CALENDAR_EVENT_STATUS_CANCELLED:
+    case CALENDAR_TODO_STATUS_CANCELED:
+        m_abstractEvent->setStatus(CalendarEvent::CANCELLED_STATUS);
+        break;
+    case CALENDAR_TODO_STATUS_NEEDS_ACTION:
+        m_abstractEvent->setStatus(CalendarEvent::NEEDS_ACTION_STATUS);
+        break;
+    case CALENDAR_TODO_STATUS_COMPLETED:
+        m_abstractEvent->setStatus(CalendarEvent::COMPLETED_STATUS);
+        break;
+    case CALENDAR_TODO_STATUS_IN_PROCESS:
+        m_abstractEvent->setStatus(CalendarEvent::IN_PROCESS_STATUS);
+        break;
+    default:
+        m_abstractEvent->setStatus(CalendarEvent::UNDEFINED_STATUS);
+        break;
+    }
+}
+
+void EventWrapper::setCategoriesFromPlatformEvent()
+{
+    m_abstractEvent->getCategories()->clear();
+
+    int ret;
+    char *categories = NULL;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_todo.categories, &categories);
+    } else {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_event.categories, &categories);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get categories: "<<ret);
+    }
+
+    if( categories ) {
+        LogDebug("Loaded categories: "<<categories);
+
+        char *saveptr = NULL;
+        char* pch = strtok_r(categories, ",", &saveptr);
+        while (NULL != pch) {
+            m_abstractEvent->getCategories()->push_back(pch);
+            pch = strtok_r(NULL, ",", &saveptr);
+        }
+        free(categories);
+    }
+
+    LogDebug("Number of categories: "<<m_abstractEvent->getCategories()->size());
+}
+
+void EventWrapper::setIdFromPlatformEvent()
+{
+    m_abstractEvent->setId(getIdFromPlatformEvent());
+
+    // Set the uid also.
+    std::stringstream ss;
+    ss<<getIdFromPlatformEvent();
+    m_abstractEvent->setUId(ss.str());
+}
+
+void EventWrapper::setRecurrenceIdFromPlatformEvent()
+{
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        LogDebug("No need to set the recurrence id for a task.");
+        return;
+    }
+
+    int ret;
+    char* recurrenceId = NULL;
+    ret = calendar_record_get_str(m_platformEvent, _calendar_event.recurrence_id, &recurrenceId);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get recurrence id: "<<ret);
+        return;
+    }
+
+    if( recurrenceId ) {
+        long long int rid;
+        std::stringstream ss(recurrenceId);
+        ss>>rid;
+        m_abstractEvent->setRecurrenceId(rid);
+        LogDebug("Set the recurrence id: "<<rid);
+    } else {
+        m_abstractEvent->setRecurrenceId(UNDEFINED_TIME);
+    }
+}
+
+void EventWrapper::setParentIdFromPlatformEvent()
+{
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        LogDebug("No need to set the parent id for a task.");
+        return;
+    }
+
+    int ret, parentId;
+    ret = calendar_record_get_int(m_platformEvent, _calendar_event.original_event_id, &parentId);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get parent id: "<<ret);
+        return;
+    }
+
+    if( parentId>0 ) {
+        m_abstractEvent->setParentId(parentId);
+    } else {
+        m_abstractEvent->setParentId(UNDEFINED_ITEM_ID);
+    }
+}
+
+void EventWrapper::setIsAllDayFromPlatformEvent()
+{
+    LogDebug("All day flag is set when getting the start time: "<<m_abstractEvent->getIsAllDay());
+}
+
+void EventWrapper::setOrganizerFromPlatformEvent()
+{
+    int ret;
+    char* organizer = NULL;
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_todo.organizer_name, &organizer);
+    } else {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_event.organizer_name, &organizer);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get organizer: "<<ret);
+    }
+
+    if (organizer) {
+        m_abstractEvent->setOrganizer(organizer);
+        free(organizer);
+    }
+}
+
+void EventWrapper::setLastModifiedDateFromPlatformEvent()
+{
+    int ret;
+    long long int lastModifiedDate;
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_lli(m_platformEvent, _calendar_todo.last_modified_time, &lastModifiedDate);
+    } else {
+        ret = calendar_record_get_lli(m_platformEvent, _calendar_event.last_modified_time, &lastModifiedDate);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get last modification time: "<<ret);
+        return;
+    }
+
+    m_abstractEvent->setLastModifiedDate(lastModifiedDate);
+}
+
+void EventWrapper::setVisibilityFromPlatformEvent()
+{
+    int ret, visibility;
+    
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_todo.sensitivity, &visibility);
+    } else {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_event.sensitivity, &visibility);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get visibility: "<<ret);
+        return;
+    }
+
+    switch (visibility) {
+    case CALENDAR_SENSITIVITY_PUBLIC:
+        m_abstractEvent->setVisibility(CalendarEvent::PUBLIC_VISIBILITY);
+        break;
+    case CALENDAR_SENSITIVITY_PRIVATE:
+        m_abstractEvent->setVisibility(CalendarEvent::PRIVATE_VISIBILITY);
+        break;
+    case CALENDAR_SENSITIVITY_CONFIDENTIAL:
+        m_abstractEvent->setVisibility(CalendarEvent::CONFIDENTIAL_VISIBILITY);
+        break;
+    default:
+        m_abstractEvent->setVisibility(CalendarEvent::PUBLIC_VISIBILITY);
+        break;
+    }
+}
+
+void EventWrapper::setAvailabilityFromPlatformEvent()
+{   
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        LogDebug("No need to set availability for a task.");
+        return;
+    }
+
+    int ret, availability;
+    ret = calendar_record_get_int(m_platformEvent, _calendar_event.busy_status, &availability);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get visibility: "<<ret);
+        return;
+    }
+
+    switch (availability) {
+    case CALENDAR_EVENT_BUSY_STATUS_BUSY:
+        m_abstractEvent->setAvailability(CalendarEvent::BUSY_FB);
+        break;
+    case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
+        m_abstractEvent->setAvailability(CalendarEvent::BUSY_UNAVAILABLE_FB);
+        break;
+    case CALENDAR_EVENT_BUSY_STATUS_FREE:
+        m_abstractEvent->setAvailability(CalendarEvent::FREE_FB);
+        break;
+    case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
+        m_abstractEvent->setAvailability(CalendarEvent::BUSY_TENTATIVE_FB);
+        break;
+    default:
+        m_abstractEvent->setAvailability(CalendarEvent::FREE_FB);
+        break;
+    }
+}
+
+void EventWrapper::setUIdFromPlatformEvent()
+{
+    int ret;
+    char* uid = NULL;
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_todo.uid, &uid);
+    } else {
+        ret = calendar_record_get_str(m_platformEvent, _calendar_event.uid, &uid);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get uid: "<<ret);
+    }
+
+    if (uid) {
+        m_abstractEvent->setUId(uid);
+        free(uid);
+    }
+}
+
+void EventWrapper::setAttendeesFromPlatformEvent()
+{
+    if ( NULL != m_abstractEvent->getAttendees() ) {
+        m_abstractEvent->getAttendees()->clear();
+    }
+
+    int ret;
+    unsigned int count = 0, i;
+    calendar_record_h attendee = NULL;
+    calendar_list_h list = NULL;
+
+    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 attendee count: "<<ret);
+        return;
+    }
+
+    if(0==count) {
+        LogDebug("No attendees to set.");
+        return;
+    }
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_clone_child_record_list(m_platformEvent, _calendar_todo.calendar_attendee, &list);
+    } else {
+        ret = calendar_record_clone_child_record_list(m_platformEvent, _calendar_event.calendar_attendee, &list);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get attendee list: "<<ret);
+        return;
+    }
+
+    for (i=0; i<count; i++)
+    {
+        LogDebug("Processing the attendee #"<<i);
+
+        if(CalendarEvent::TASK_TYPE==getType()) {
+            ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_todo.calendar_attendee, i, &attendee);
+        } else {
+            ret = calendar_record_get_child_record_at_p(m_platformEvent, _calendar_event.calendar_attendee, i, &attendee);
+        }
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't get attendee record: "<<ret);
+            continue;
+        }
+
+        EventAttendeePtr attendeePtr(new EventAttendee());
+
+        // load name
+        char* attendeeName = NULL;
+        ret = calendar_record_get_str(attendee, _calendar_attendee.name, &attendeeName);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read attendee name. Setting an empty string.");
+            attendeePtr->setName("");
+        } else {
+            if(attendeeName) {
+                attendeePtr->setName(attendeeName);
+                free(attendeeName);
+            }   
+        }
+
+        // load URI
+        char* attendeeURI = NULL;
+        ret = calendar_record_get_str(attendee, _calendar_attendee.email, &attendeeURI);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read attendee URI. Setting an empty string.");
+            attendeePtr->setURI("");
+        } else {
+            if(attendeeURI) {
+                attendeePtr->setURI(attendeeURI);
+                free(attendeeURI);
+            }
+        }
+
+        // load role
+        int attendeeRole;
+        ret = calendar_record_get_int(attendee, _calendar_attendee.role, &attendeeRole);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read attendee role. Setting the default value.");
+        }
+        switch (attendeeRole) {
+        case CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT:
+            attendeePtr->setRole(EventAttendee::REQ_PARTICIPANT_ROLE);
+            break;
+        case CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT:
+            attendeePtr->setRole(EventAttendee::OPT_PARTICIPANT_ROLE);
+            break;
+        case CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT:
+            attendeePtr->setRole(EventAttendee::NON_PARTICIPANT_ROLE);
+            break;
+        case CALENDAR_ATTENDEE_ROLE_CHAIR:
+            attendeePtr->setRole(EventAttendee::CHAIR_ROLE);
+            break;
+        default:
+            attendeePtr->setRole(EventAttendee::REQ_PARTICIPANT_ROLE);
+            break;
+        }
+
+        // load status
+        int attendeeStatus;
+        ret = calendar_record_get_int(attendee, _calendar_attendee.status, &attendeeStatus);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read attendee status. Setting the default value.");
+        }
+        switch (attendeeStatus) {
+        case CALENDAR_ATTENDEE_STATUS_PENDING:
+            attendeePtr->setStatus(EventAttendee::PENDING_AT_STATUS);
+            break;
+        case CALENDAR_ATTENDEE_STATUS_ACCEPTED:
+            attendeePtr->setStatus(EventAttendee::ACCEPTED_AT_STATUS);
+            break;
+        case CALENDAR_ATTENDEE_STATUS_DECLINED:
+            attendeePtr->setStatus(EventAttendee::DECLINED_AT_STATUS);
+            break;
+        case CALENDAR_ATTENDEE_STATUS_TENTATIVE:
+            attendeePtr->setStatus(EventAttendee::TENTATIVE_AT_STATUS);
+            break;
+        case CALENDAR_ATTENDEE_STATUS_DELEGATED:
+            attendeePtr->setStatus(EventAttendee::DELEGATED_AT_STATUS);
+            break;
+        case CALENDAR_ATTENDEE_STATUS_COMPLETED:
+            attendeePtr->setStatus(EventAttendee::COMPLETED_AT_STATUS);
+            break;
+        case CALENDAR_ATTENDEE_STATUS_IN_PROCESS:
+            attendeePtr->setStatus(EventAttendee::IN_PROCESS_AT_STATUS);
+            break;
+        default:
+            attendeePtr->setStatus(EventAttendee::PENDING_AT_STATUS);
+            break;
+        }
+
+        // load RSVP
+        int attendeeRSVP;
+        ret = calendar_record_get_int(attendee, _calendar_attendee.rsvp, &attendeeRSVP);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read attendee RSVP. Setting the default value.");
+        }
+        attendeePtr->setRSVP(attendeeRSVP>0 ? true : false);
+
+        // load type
+        int attendeeType;
+        ret = calendar_record_get_int(attendee, _calendar_attendee.type, &attendeeType);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read attendee type. Setting the default value.");
+        }
+        attendeePtr->setType((EventAttendee::EventAttendeeType)attendeeType);
+
+        // load group
+        char* attendeeGroup = NULL;
+        ret = calendar_record_get_str(attendee, _calendar_attendee.group, &attendeeGroup);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read attendee group. Setting an empty string.");
+            attendeePtr->setGroup("");
+        } else {
+            if(attendeeGroup) {
+                attendeePtr->setGroup(attendeeGroup);
+                free(attendeeGroup);
+            }
+        }
+
+        // load delegatorURI
+        char* attendeeDelegatorURI = NULL;
+        ret = calendar_record_get_str(attendee, _calendar_attendee.delegator_uri, &attendeeDelegatorURI);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read attendee delegatorURI. Setting an empty string.");
+            attendeePtr->setDelegatorURI("");
+        } else {
+            if(attendeeDelegatorURI) {
+                attendeePtr->setDelegatorURI(attendeeDelegatorURI);
+                free(attendeeDelegatorURI);
+            }
+        }
+
+        // load delegateURI
+        char* attendeeDelegateURI = NULL;
+        ret = calendar_record_get_str(attendee, _calendar_attendee.delegate_uri, &attendeeDelegateURI);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read attendee delegateURI. Setting an empty string.");
+            attendeePtr->setDelegateURI("");
+        } else {
+            if(attendeeDelegateURI) {
+                attendeePtr->setDelegateURI(attendeeDelegateURI);
+                free(attendeeDelegateURI);
+            }
+        }
+
+        // load contactId
+        char* attendeeContactId = NULL;
+        ret = calendar_record_get_str(attendee, _calendar_attendee.uid, &attendeeContactId);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read attendee UId. Setting an empty string.");
+            attendeePtr->setContactId("");
+        } else {
+            if(attendeeContactId) {
+                attendeePtr->setContactId(attendeeContactId);
+                free(attendeeContactId);
+            }
+        }
+
+        // load addressBookId
+        int attendeeAddressBookId;
+        ret = calendar_record_get_int(attendee, _calendar_attendee.person_id, &attendeeAddressBookId);
+        LogDebug("attendeeAddressBookId: "<<attendeeAddressBookId);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Cannot read attendee address book id. Setting an empty string.");
+            attendeeAddressBookId = -1;
+        }
+        std::stringstream ss;
+        if (attendeeAddressBookId>=0) {
+            ss<<attendeeAddressBookId;
+        } else {
+            ss<<"";
+        }
+        attendeePtr->setAddressBookId(ss.str());
+
+        m_abstractEvent->getAttendees()->push_back(attendeePtr);
+    }
+
+    if(list) {
+        calendar_list_destroy(list, true);
+    }
+}
+
+void EventWrapper::setPositionFromPlatformEvent()
+{
+    int ret;
+    double value;
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_double(m_platformEvent, _calendar_todo.latitude, &value);
+    } else {
+        ret = calendar_record_get_double(m_platformEvent, _calendar_event.latitude, &value);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get item latitude.");
+        return;
+    }
+    m_abstractEvent->setLatitude(value);
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_double(m_platformEvent, _calendar_todo.longitude, &value);
+    } else {
+        ret = calendar_record_get_double(m_platformEvent, _calendar_event.longitude, &value);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get item longitude.");
+        return;
+    }
+    m_abstractEvent->setLongitude(value);
+}
+
+void EventWrapper::setPriorityFromPlatformEvent()
+{
+    int ret;
+    int priority;
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_todo.priority, &priority);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't get task priority: "<<ret);
+            return;
+        }
+
+        switch (priority) {
+        case CALENDAR_TODO_PRIORITY_LOW:
+            m_abstractEvent->setPriority(CalendarEvent::LOW_PRIORITY);
+            break;
+        case CALENDAR_TODO_PRIORITY_NORMAL:
+            m_abstractEvent->setPriority(CalendarEvent::MEDIUM_PRIORITY);
+            break;
+        case CALENDAR_TODO_PRIORITY_HIGH:
+            m_abstractEvent->setPriority(CalendarEvent::HIGH_PRIORITY);
+            break;
+        default:
+            m_abstractEvent->setPriority(CalendarEvent::MEDIUM_PRIORITY);
+            break;
+        }
+    } else {
+        ret = calendar_record_get_int(m_platformEvent, _calendar_event.priority, &priority);
+        if (CALENDAR_ERROR_NONE != ret) {
+            LogWarning("Can't get event priority: "<<ret);
+            return;
+        }
+
+        switch (priority) {
+        case CALENDAR_EVENT_PRIORITY_LOW:
+            m_abstractEvent->setPriority(CalendarEvent::LOW_PRIORITY);
+            break;
+        case CALENDAR_EVENT_PRIORITY_NORMAL:
+            m_abstractEvent->setPriority(CalendarEvent::MEDIUM_PRIORITY);
+            break;
+        case CALENDAR_EVENT_PRIORITY_HIGH:
+            m_abstractEvent->setPriority(CalendarEvent::HIGH_PRIORITY);
+            break;
+        default:
+            m_abstractEvent->setPriority(CalendarEvent::MEDIUM_PRIORITY);
+            break;
+        }
+    }
+}
+
+void EventWrapper::setCreatedDateFromPlatformEvent()
+{
+    int ret;
+    long long int createdDate;
+
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        ret = calendar_record_get_lli(m_platformEvent, _calendar_todo.created_time, &createdDate);
+    } else {
+        ret = calendar_record_get_lli(m_platformEvent, _calendar_event.created_time, &createdDate);
+    }
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get created date: "<<ret);
+        return;
+    }
+
+    m_abstractEvent->setCreatedDate(createdDate);
+}
+
+void EventWrapper::setCompletedDateFromPlatformEvent()
+{
+    if(CalendarEvent::EVENT_TYPE==getType()) {
+        LogDebug("No need to set completedDate for an event.");
+        return;
+    }
+
+    int ret;
+    long long int completedDate;
+
+    ret = calendar_record_get_lli(m_platformEvent, _calendar_todo.completed_time, &completedDate);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get completed date: "<<ret);
+        return;
+    }
+
+    m_abstractEvent->setCompletedDate(completedDate);
+}
+
+void EventWrapper::setProgressFromPlatformEvent()
+{
+    if(CalendarEvent::EVENT_TYPE==getType()) {
+        LogDebug("No need to set progress for an event.");
+        return;
+    }
+
+    int ret;
+    int progress = 0;
+    ret = calendar_record_get_int(m_platformEvent, _calendar_todo.progress, &progress);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get progress: "<<ret);
+        return;
+    }
+
+    m_abstractEvent->setProgress(progress);
+}
+
+void EventWrapper::setIsDetachedFromPlatformEvent()
+{
+    if(CalendarEvent::TASK_TYPE==getType()) {
+        LogDebug("No need to set isDetached flag for a task.");
+        return;
+    }
+
+    int ret;
+    int isDetached;
+    ret = calendar_record_get_int(m_platformEvent, _calendar_event.original_event_id, &isDetached);
+    if (CALENDAR_ERROR_NONE != ret) {
+        LogWarning("Can't get isDetached: "<<ret);
+        return;
+    }
+
+    if (isDetached>0) {
+        m_abstractEvent->setIsDetached(true);
+        LogDebug("This is a detached event.");
+    } else {
+        m_abstractEvent->setIsDetached(false);
+    }
+}
+
+void EventWrapper::displayAbstractEvent()
+{
+    m_abstractEvent->display();
+}
+
+void EventWrapper::displayPlatformEvent()
+{
+     LogDebug("Displaying platform itemt disabled.");
+}
+
+CalendarEvent::CalendarType EventWrapper::getType()
+{
+    return m_calendarType;
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Calendar/EventWrapper.h b/src/platform/Tizen/Calendar/EventWrapper.h
new file mode 100755 (executable)
index 0000000..9524379
--- /dev/null
@@ -0,0 +1,127 @@
+//
+// 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 _CALENDAR_EVENT_WRAPPER_H_
+#define _CALENDAR_EVENT_WRAPPER_H_
+
+#include <string>
+#include <calendar2.h>
+#include <dpl/shared_ptr.h>
+#include <API/Calendar/CalendarEvent.h>
+#include <API/Calendar/EventAlarm.h>
+#include <API/Calendar/EventAttendee.h>
+#include <API/Calendar/EventRecurrenceRule.h>
+
+using namespace TizenApis::Api::Calendar;
+
+namespace TizenApis {
+namespace Platform {
+namespace Calendar {
+
+class EventWrapper
+{
+  public:
+    EventWrapper(CalendarEvent::CalendarType type = CalendarEvent::EVENT_TYPE);
+    explicit EventWrapper(const CalendarEventPtr &event, CalendarEvent::CalendarType type = CalendarEvent::EVENT_TYPE);
+    explicit EventWrapper(calendar_record_h event, CalendarEvent::CalendarType type = CalendarEvent::EVENT_TYPE);
+    virtual ~EventWrapper();
+    calendar_record_h convertAbstractEventToPlatformEvent(bool loadBeforeConvert = false);
+    CalendarEventPtr convertPlatformEventToAbstractEvent();
+    calendar_record_h getPlatformEvent() const;
+    CalendarEventPtr getAbstractEvent() const;
+    void        freePlatformEvent();
+    void        saveEvent();
+    void        loadEvent(int id);
+    void        deleteEvent();
+    void        createEventFromString(std::string value);
+    std::string exportEventToString();    
+
+       void setCalendarId(const std::string &value);
+       void setCalendarAccountId(const int value);
+
+    void displayAbstractEvent();     //only for debugging
+    void displayPlatformEvent();     //only for debugging
+
+  protected:
+    int  getIdFromPlatformEvent();
+
+    void setDescriptionToPlatformEvent();
+    void setSummaryToPlatformEvent();
+    void setStartTimeToPlatformEvent();
+    void setEndTimeToPlatformEvent();
+    void setLocationToPlatformEvent();
+    void setRecurrenceRuleToPlatformEvent();
+    void setAlarmsToPlatformEvent();
+    void setStatusToPlatformEvent();
+    void setCategoriesToPlatformEvent();
+    void setRecurrenceIdToPlatformEvent();
+    void setParentIdToPlatformEvent();
+    void setIsAllDayToPlatformEvent();
+    void setOrganizerToPlatformEvent();
+    void setVisibilityToPlatformEvent();
+    void setAvailabilityToPlatformEvent();
+    void setUIdToPlatformEvent();
+    void setAttendeesToPlatformEvent();
+    void setPositionToPlatformEvent();
+       void setPriorityToPlatformEvent();
+       void setCreatedDateToPlatformEvent();
+       void setCompletedDateToPlatformEvent();
+       void setProgressToPlatformEvent();
+
+    void setDescriptionFromPlatformEvent();
+    void setSummaryFromPlatformEvent();
+    void setStartTimeFromPlatformEvent();
+    void setEndTimeFromPlatformEvent();
+    void setLocationFromPlatformEvent();
+    void setRecurrenceRuleFromPlatformEvent();
+    void setAlarmsFromPlatformEvent();
+    void setStatusFromPlatformEvent();
+    void setCategoriesFromPlatformEvent();
+    void setIdFromPlatformEvent();
+    void setRecurrenceIdFromPlatformEvent();
+    void setParentIdFromPlatformEvent();
+    void setIsAllDayFromPlatformEvent();
+    void setOrganizerFromPlatformEvent();
+    void setLastModifiedDateFromPlatformEvent();
+    void setVisibilityFromPlatformEvent();
+    void setAvailabilityFromPlatformEvent();
+    void setUIdFromPlatformEvent();
+    void setAttendeesFromPlatformEvent();
+    void setPositionFromPlatformEvent();
+       void setPriorityFromPlatformEvent();
+       void setCreatedDateFromPlatformEvent();
+       void setCompletedDateFromPlatformEvent();
+       void setProgressFromPlatformEvent();
+       void setIsDetachedFromPlatformEvent();
+
+  private:
+    CalendarEvent::CalendarType getType();
+
+    calendar_record_h m_platformEvent;
+    CalendarEventPtr m_abstractEvent;
+    CalendarEvent::CalendarType    m_calendarType;
+    std::string m_calendarId;
+    int m_calendarAccountId;
+};
+
+typedef DPL::SharedPtr<EventWrapper> EventWrapperPtr;
+
+}
+}
+}
+#endif /* _CALENDAR_EVENT_WRAPPER_H_ */
diff --git a/src/platform/Tizen/Calendar/config.cmake b/src/platform/Tizen/Calendar/config.cmake
new file mode 100755 (executable)
index 0000000..2403cde
--- /dev/null
@@ -0,0 +1,25 @@
+get_current_path()
+
+pkg_search_module(calendar REQUIRED calendar-service2)
+pkg_search_module(glib REQUIRED glib-2.0)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_CALENDAR
+  ${calendar_INCLUDE_DIRS}
+  ${glib_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_CALENDAR
+  ${calendar_LIBRARIES}
+  ${glib_LIBRARIES}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_CALENDAR
+  ${CURRENT_PATH}/Calendar.cpp
+  ${CURRENT_PATH}/CalendarManager.cpp
+  ${CURRENT_PATH}/EventWrapper.cpp
+  ${CURRENT_PATH}/CalendarFilter.cpp
+  ${CURRENT_PATH}/CalendarFilterValidator.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/Callhistory/CallHistory.cpp b/src/platform/Tizen/Callhistory/CallHistory.cpp
new file mode 100755 (executable)
index 0000000..1007b3e
--- /dev/null
@@ -0,0 +1,874 @@
+//
+// 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 "CallHistory.h"
+
+#include <vector>
+#include <string>
+#include <sstream>
+#include <cassert>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/log/log.h>
+#include <API/Filter/IFilter.h>
+#include <API/Filter/IFilterVisitor.h>
+#include <API/Callhistory/CallHistoryDefine.h>
+
+#include "CallHistoryFilter.h"
+
+using namespace TizenApis::Api::Tizen;
+using namespace TizenApis::Api::Callhistory;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace DPL;
+
+namespace TizenApis {
+namespace Platform {
+namespace Callhistory {
+
+std::vector<CallHistory::WatcherPtr> CallHistory::m_watchers;
+
+CallHistory::CallHistory()
+{
+       LogDebug("Enter ");
+       if (contacts_connect2() == CONTACTS_ERROR_NONE) {
+               LogDebug("Successful to connect Call history DB ");
+       } else {
+               LogDebug("Failed to connect Call history DB ");
+       }
+
+       EventCallHistoryPtr event(new EventCallHistory());
+       event->setCmdType(EventCallHistory::CONNECT);
+       event->setForSynchronousCall();
+       EventRequestReceiver<EventCallHistory>::PostRequest(event);
+}
+
+CallHistory::~CallHistory()
+{
+       LogDebug("Enter ");
+
+       if (contacts_disconnect2()  == CONTACTS_ERROR_NONE) {
+               LogDebug("Successful to disconnect Call history DB ");
+       } else {
+               LogDebug("Failed to disconnect Call history DB ");
+       }
+
+       int ret = CONTACTS_ERROR_NONE;
+       std::vector<CallHistory::WatcherPtr>::iterator it = CallHistory::m_watchers.begin();
+
+       if (m_watchers.size() > 0) {
+               for (;it < CallHistory::m_watchers.end();) {
+                       ret = contacts_db_remove_changed_cb(_contacts_phone_log._uri, callhistoryListenerCB, it->Get());
+
+                       if (ret != CONTACTS_ERROR_NONE) {
+                               LogDebug("callhistory remove listener error [" << ret << "]");
+                       }
+
+                       it = CallHistory::m_watchers.erase(it);
+               }
+               LogDebug("CallHistory Watcher is removed. (" << CallHistory::m_watchers.size() << ")");
+       }
+
+       EventCallHistoryPtr event(new EventCallHistory());
+       event->setCmdType(EventCallHistory::DISCONNECT);
+       event->setForSynchronousCall();
+       EventRequestReceiver<EventCallHistory>::PostRequest(event);
+}
+
+void CallHistory::callhistoryListenerCB(const char* view_uri, void* user_data)
+{
+       LogDebug("enter");
+       if (user_data != NULL) {
+               ((CallHistory::Watcher*)user_data)->addedListenerCB();
+               ((CallHistory::Watcher*)user_data)->changedListenerCB();
+       }
+}
+
+void CallHistory::removeBatchCB(int error, void *user_data)
+{
+       LogDebug("enter");
+       if (user_data != NULL) {
+               CallHistory* chManager = (CallHistory *)((EventCallHistoryPtrs<EventRemoveBatch> *)user_data)->getThisPtr();
+
+               if (chManager) {
+                       EventRemoveBatchPtr event = ((EventCallHistoryPtrs<EventRemoveBatch> *)user_data)->getEventPtrs();
+                       chManager->callRemoveBatchEvent(error, event);
+               }
+       }
+       return;
+}
+
+void CallHistory::removeAllCB(int error, void *user_data)
+{
+       LogDebug("enter");
+       if (user_data != NULL) {
+               CallHistory* chManager = (CallHistory *)((EventCallHistoryPtrs<EventRemoveAll> *)user_data)->getThisPtr();
+
+               if (chManager) {
+                       EventRemoveAllPtr event = ((EventCallHistoryPtrs<EventRemoveAll> *)user_data)->getEventPtrs();
+                       chManager->callRemoveAllEvent(error, event);
+               }
+       }
+       return;
+}
+
+bool CallHistory::convertCallHistory(callhistory_query_s *query_log, CallHistoryEntryListPtr &callEntries)
+{
+       if (query_log == NULL || callEntries == NULL)
+               return false;
+
+       CallHistoryEntryPropertiesPtr callHistoryItem(new CallHistoryEntryProperties());
+       StringArrayPtr stringArray(new StringArray());
+       RemotePartyPtr remoteParty(new RemoteParty());
+       RemotePartyListPtr remotePartyList(new RemotePartyList());
+
+       std::string callType("");
+       std::string tags("");
+       std::string direction("");
+       std::string number("");
+       
+       if (query_log->phone_number != NULL) {
+               number.append(query_log->phone_number);
+       }
+
+       switch(query_log->calllog_type) {
+       case CONTACTS_PLOG_TYPE_VOICE_INCOMMING:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VOICE);
+               direction.append(STR_RECEIVED);
+               break;
+       case CONTACTS_PLOG_TYPE_VOICE_OUTGOING:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VOICE);
+               direction.append(STR_DIALED);
+               break;
+       case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VOICE);
+               direction.append(STR_MISSED);
+               break;
+       case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VOICE);
+               direction.append(STR_MISSED_NEW);
+               break;
+       case CONTACTS_PLOG_TYPE_VOICE_REJECT:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VOICE);
+               direction.append(STR_REJECTED);
+               break;
+       case CONTACTS_PLOG_TYPE_VOICE_BLOCKED:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VOICE);
+               direction.append(STR_BLOCKED);
+               break;
+       case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VIDEO);
+               direction.append(STR_RECEIVED);
+               break;
+       case CONTACTS_PLOG_TYPE_VIDEO_OUTGOING:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VIDEO);
+               direction.append(STR_DIALED);
+               break;
+       case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VIDEO);
+               direction.append(STR_MISSED);
+               break;
+       case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VIDEO);
+               direction.append(STR_MISSED_NEW);
+               break;
+       case CONTACTS_PLOG_TYPE_VIDEO_REJECT:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VIDEO);
+               direction.append(STR_REJECTED);
+               break;
+       case CONTACTS_PLOG_TYPE_VIDEO_BLOCKED:
+               callType.append(STR_TIZEN_TEL);
+               tags.append(STR_CALL_VIDEO);
+               direction.append(STR_BLOCKED);
+               break;
+       default:
+               return false;
+       }
+
+       callHistoryItem->setEntryId(query_log->calllog_db_id);
+       callHistoryItem->setCallType(callType);
+       stringArray->push_back(tags);
+       callHistoryItem->setTags(stringArray);
+
+       remoteParty->setRemoteParty(number);
+       std::stringstream personIdStream;
+       personIdStream << query_log->person_db_id;
+       remoteParty->setPersonId(personIdStream.str());
+
+       remotePartyList->push_back(remoteParty);
+       callHistoryItem->setRemoteParties(remotePartyList);
+
+       callHistoryItem->setStartTime(query_log->timestamp);
+       callHistoryItem->setDuration((unsigned long)(query_log->duration_sec));
+       callHistoryItem->setDirection(direction);
+
+       callEntries->insert(callEntries->end(), callHistoryItem);
+
+       return true;
+}
+
+void CallHistory::find(const EventFindCallHistoryPtr& event)
+{
+       EventRequestReceiver<EventFindCallHistory>::PostRequest(event);
+}
+
+bool CallHistory::remove(const unsigned long entryId)
+{
+       try {
+               int ret = contacts_db_delete_record(_contacts_phone_log._uri, (int)entryId);
+
+               if (ret == CONTACTS_ERROR_NONE) {
+                       return true;
+               } else {
+                       return false;
+               }
+       } catch (const Commons::PlatformException& ex) {
+               ThrowMsg(Commons::PlatformException, ex.GetMessage());
+       }
+}
+
+void CallHistory::removeBatch(const EventRemoveBatchPtr& event)
+{
+       EventRequestReceiver<EventRemoveBatch>::PostRequest(event);
+}
+
+void CallHistory::removeAll(const EventRemoveAllPtr& event)
+{
+       EventRequestReceiver<EventRemoveAll>::PostRequest(event);
+}
+
+long CallHistory::addListener(const EventCallHistoryListenerEmitterPtr& emitter)
+{
+       int ret =0;
+       if (CallHistory::m_watchers.size() == 0) {
+               WatcherPtr watcher(new Watcher(0, emitter));
+               ret = contacts_db_add_changed_cb(_contacts_phone_log._uri, callhistoryListenerCB, watcher.Get());
+
+               if (ret == CONTACTS_ERROR_NONE) {
+                       CallHistoryEntryListPtr callHistoryListPtr(new CallHistoryEntryList());
+
+                       contacts_query_h query = NULL;
+                       contacts_filter_h filter = NULL;
+                       contacts_list_h recordList = NULL;
+
+                       contacts_query_create(_contacts_phone_log._uri, &query);
+                       contacts_filter_create(_contacts_phone_log._uri, &filter);
+                       contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
+
+                       contacts_query_set_filter(query, filter);
+                       contacts_query_set_sort(query, _contacts_phone_log.id, false);
+                       ret = contacts_db_get_records_with_query(query, 0, 1, &recordList);
+
+                       if (ret != CONTACTS_ERROR_NONE) {
+                               LogDebug("callhistory query error [" << ret << "]");
+                       }
+                       
+                       if (parseRecord(&recordList, callHistoryListPtr)) {
+                               if (callHistoryListPtr->size() > 0) {
+                                       watcher->setCurrentLogId((*callHistoryListPtr)[0]->getEntryId());
+                               }
+                       }
+                       contacts_list_destroy(recordList, true);
+                       contacts_query_destroy(query);
+                       contacts_filter_destroy(filter);
+
+                       MissedCallListPtr missedCallList(updateCurrentMissedCall());
+                       watcher->setMissedCallList(missedCallList);
+               }
+
+               watcher->setHandle(static_cast<long>(emitter->getId()));
+               CallHistory::m_watchers.push_back(watcher);
+               return watcher->getHandle();
+       } else {
+               return 0;
+       }
+}
+
+void CallHistory::removeListener(const long id)
+{
+       std::vector<CallHistory::WatcherPtr>::iterator it = CallHistory::m_watchers.begin();
+       bool flag = false;
+       int ret = CONTACTS_ERROR_NONE;
+       
+       for (;it < CallHistory::m_watchers.end();) {
+               if (id == (*it)->getHandle()) {
+                       flag = true;
+                       ret = contacts_db_remove_changed_cb(_contacts_phone_log._uri, callhistoryListenerCB, it->Get());
+
+                       if (ret != CONTACTS_ERROR_NONE) {
+                               LogDebug("callhistory remove listener error [" << ret << "]");
+                       }
+
+                       it = CallHistory::m_watchers.erase(it);
+                       continue;
+               }
+               ++it;
+       }
+
+       LogDebug("CallHistory Watcher is removed. (" << CallHistory::m_watchers.size() << ")");
+
+       if (!flag) {
+               ThrowMsg(Commons::InvalidArgumentException, "Invalid values error : handle");
+       }
+}
+
+bool CallHistory::parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &callEntries)
+{
+       int ret = CONTACTS_ERROR_NONE;
+       unsigned int total = 0;
+       contacts_record_h record = NULL;
+       callhistory_query_s query_data;
+       int logType = 0;
+       int time = 0;
+
+       contacts_list_get_count(*recordList, &total);
+
+       LogDebug("total [" << total << "]");
+
+       for (int i = 0; i < total; i++) {
+               ret = contacts_list_get_current_record_p(*recordList, &record);
+
+               if (record == NULL) {
+                       ret = contacts_list_next(*recordList);
+                       if (ret != CONTACTS_ERROR_NONE && ret != CONTACTS_ERROR_NO_DATA) {
+                               LogDebug("callhistory parse error [" << ret << "]");
+                               return false;
+                       } else {
+                               continue;
+                       }
+               }
+
+               memset(&query_data, 0x00, sizeof(callhistory_query_s));
+
+               if (ret == CONTACTS_ERROR_NONE) {
+                       contacts_record_get_int(record, _contacts_phone_log.id, &(query_data.calllog_db_id));
+                       contacts_record_get_int(record, _contacts_phone_log.log_type , &logType);
+                       contacts_record_get_int(record, _contacts_phone_log.person_id, &(query_data.person_db_id));
+                       contacts_record_get_str_p(record, _contacts_phone_log.address, &(query_data.phone_number));
+                       contacts_record_get_int(record, _contacts_phone_log.log_time, &time);
+                       contacts_record_get_int(record, _contacts_phone_log.extra_data1, &(query_data.duration_sec));
+                       query_data.calllog_type = static_cast<contacts_phone_log_type_e>(logType);
+                       query_data.timestamp = static_cast<time_t>(time);
+                       convertCallHistory(&query_data, callEntries);
+               }
+
+               ret = contacts_list_next(*recordList);
+               if (ret != CONTACTS_ERROR_NONE && ret != CONTACTS_ERROR_NO_DATA) {
+                       LogDebug("callhistory parse error [" << ret << "]");
+                       return false;
+               }
+       }
+
+       return true;
+
+}
+
+unsigned int CallHistory::convertAttrName(std::string &name)
+{
+       std::string attrName("");
+       if (name.compare(STR_RP_REMOTEPARTY) == 0) {
+               return _contacts_phone_log.address;
+       } else if (name.compare(STR_START_TIME) == 0) {
+               return _contacts_phone_log.log_time;
+       } else if (name.compare(STR_DURATION) == 0) {
+               return _contacts_phone_log.extra_data1;
+       } else if (name.compare(STR_DIRECTION) == 0) {
+               return _contacts_phone_log.log_type;
+       } else if (name.compare(STR_ENTRY_ID) == 0) {
+               return _contacts_phone_log.id;
+       } else {
+               return 0;
+       }
+}
+
+MissedCallListPtr CallHistory::updateCurrentMissedCall()
+{
+       CallHistoryEntryListPtr callHistoryListPtr(new CallHistoryEntryList());
+       MissedCallListPtr missedCallList(new MissedCallList());
+       int ret = CONTACTS_ERROR_NONE;
+
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h recordList = NULL;
+
+       contacts_query_create(_contacts_phone_log._uri, &query);
+       contacts_filter_create(_contacts_phone_log._uri, &filter);
+       contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN);
+       contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
+       contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN);
+
+       contacts_query_set_filter(query, filter);
+       contacts_query_set_sort(query, _contacts_phone_log.log_time, false);
+       ret = contacts_db_get_records_with_query(query, 0, 0, &recordList);
+
+       if (ret != CONTACTS_ERROR_NONE) {
+               LogDebug("callhistory query error [" << ret << "]");
+       }
+
+       if (parseRecord(&recordList, callHistoryListPtr)) {
+               LogDebug("result counter [" << callHistoryListPtr->size() << "]");
+               CallHistoryEntryList::iterator it = callHistoryListPtr->begin();
+
+               for (;it != callHistoryListPtr->end(); ++it) {
+                       missedCallList->push_back((*it)->getEntryId());
+               }
+               LogDebug("missed Call size (" << missedCallList->size() << ")");
+       }
+
+       contacts_list_destroy(recordList, true);
+       contacts_query_destroy(query);
+       contacts_filter_destroy(filter);
+
+       return missedCallList;
+}
+
+void CallHistory::OnRequestReceived(const EventCallHistoryPtr& event)
+{
+       try {
+               if (event->getCmdType() == EventCallHistory::CONNECT) {
+                       if (contacts_connect2() == CONTACTS_ERROR_NONE) {
+                               LogDebug("Successful to connect Call history DB by sub thread");
+                       } else {
+                               LogDebug("Failed to connect Call history DB by sub thread");
+                       }
+               } else if (event->getCmdType() == EventCallHistory::DISCONNECT) {
+                       if (contacts_disconnect2()  == CONTACTS_ERROR_NONE) {
+                               LogDebug("Successful to disconnect Call history DB by sub thread");
+                       } else {
+                               LogDebug("Failed to disconnect Call history DB by sub thread");
+                       }
+               }
+       } catch (const Commons::PlatformException& ex) {
+               LogError("Exception: " << ex.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+void CallHistory::OnRequestReceived(const EventFindCallHistoryPtr& event)
+{
+       try {
+               LogDebug("enter");
+               CallHistoryEntryListPtr callHistoryListPtr(new CallHistoryEntryList());
+               int ret = CONTACTS_ERROR_NONE;
+
+               contacts_query_h query = NULL;
+               contacts_filter_h filter = NULL;
+               contacts_list_h recordList = NULL;
+               bool isAscending = false;
+               int limit = 0;
+               int offset = 0;
+
+               contacts_query_create(_contacts_phone_log._uri, &query);
+               contacts_filter_create(_contacts_phone_log._uri, &filter);
+
+               CallHistoryFilterPtr filtering(new CallHistoryFilter(filter));
+               IFilterVisitorPtr filterTraversal = DPL::StaticPointerCast<IFilterVisitor>(filtering);
+
+               if (event->getFilterIsSet()) {
+                       FilterPtr filterPtr = event->getFilter();
+                       filterPtr->travel(filterTraversal, 0);
+
+                       contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
+                       contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
+               } else {
+                       contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
+               }
+               contacts_query_set_filter(query, filter);
+
+               if (event->getSortModesIsSet()) {
+                       if (event->getSortMode()->getOrder() == Api::Tizen::ASCENDING_SORT_ORDER) {
+                               isAscending = true;
+                       } else {
+                               isAscending = false;
+                       }
+                       std::string attriName(event->getSortMode()->getAttributeName());
+                       contacts_query_set_sort(query, convertAttrName(attriName), isAscending);
+               } else {
+                       contacts_query_set_sort(query, _contacts_phone_log.id, isAscending);
+               }
+
+               if (event->getLimitIsSet()) {
+                       limit = static_cast<int>(event->getLimit());
+               }
+
+               if (event->getOffsetIsSet()) {
+                       offset = static_cast<int>(event->getOffset());
+               }
+
+               ret = contacts_db_get_records_with_query(query, offset, limit, &recordList);
+
+               if (ret != CONTACTS_ERROR_NONE) {
+                       LogDebug("callhistory query error [" << ret << "]");
+               }
+
+               if (parseRecord(&recordList, callHistoryListPtr)) {
+                       event->setResult(callHistoryListPtr);
+               }
+
+               contacts_list_destroy(recordList, true);
+               contacts_query_destroy(query);
+               contacts_filter_destroy(filter);
+       } catch (const Commons::PlatformException& ex) {
+               LogError("Exception: " << ex.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+}
+
+void CallHistory::OnRequestReceived(const EventRemoveBatchPtr& event)
+{
+       int* list = NULL;
+
+       try {
+               std::vector<unsigned long> entryIds = event->getEntryIds();
+               unsigned int cnt = 0;
+               int ret = CONTACTS_ERROR_NONE;
+               list = new int[entryIds.size()];
+
+               for (cnt = 0; cnt < entryIds.size(); cnt++) {
+                       list[cnt] = static_cast<int>(entryIds[cnt]);
+               }
+
+               if (entryIds.size() > 0) {
+                       EventRemoveBatchDataPtr eventData( new EventCallHistoryPtrs<EventRemoveBatch>(event, this));
+
+                       JSCallbackManagerPtr data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+                       if (data != NULL) {
+                               if (data->getOnSuccess() != NULL) {
+                                       ret = contacts_db_delete_records_async(_contacts_phone_log._uri, list, entryIds.size(), removeBatchCB, eventData.Get());
+                                       if (ret == CONTACTS_ERROR_NONE) {
+                                               m_removeBatchEvent.push_back(eventData);
+                                               event->switchToManualAnswer();
+                                       } else {
+                                               LogDebug("callhistory remove Batch error [" << ret << "]");
+                                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                                       }
+                               } else {
+                                       ret = contacts_db_delete_records(_contacts_phone_log._uri, list, entryIds.size());
+                                       if (ret != CONTACTS_ERROR_NONE) {
+                                               LogDebug("callhistory remove Batch error [" << ret << "]");
+                                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                                       }
+                               }
+                       } else {
+                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                       }
+               }
+
+       } catch (const Commons::PlatformException& ex) {
+               LogError("Exception: " << ex.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+
+       if (list != NULL) {
+               delete[] list;
+               list = NULL;
+       }
+}
+
+void CallHistory::OnRequestReceived(const EventRemoveAllPtr& event)
+{
+       int* list = NULL;
+
+       try {
+               int ret = CONTACTS_ERROR_NONE;
+               contacts_list_h record_list = NULL;
+               contacts_record_h record = NULL;
+               unsigned int total = 0;
+               unsigned int cnt = 0;
+               int value = 0;
+
+               ret = contacts_db_get_all_records(_contacts_phone_log._uri, 0, 0, &record_list);
+
+               if (record_list == NULL) {
+                       event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                       return;
+               }
+
+               contacts_list_get_count(record_list, &total);
+
+               list = new int[total];
+               LogDebug("total [" << total << "]");
+               for (unsigned int i = 0; i < total; i++) {
+                       ret = contacts_list_get_current_record_p(record_list, &record);
+
+                       if (record == NULL) {
+                               contacts_list_next(record_list);
+                               continue;
+                       }
+
+                       if (ret == CONTACTS_ERROR_NONE) {
+                               ret = contacts_record_get_int(record, _contacts_phone_log.id , &value);
+                               if (ret == CONTACTS_ERROR_NONE) {
+                                       list[cnt] = value;
+                                       cnt++;
+                               }
+                       }
+                       value = 0;
+                       contacts_list_next(record_list);
+               }
+
+               LogDebug("cnt [" << cnt << "]");
+
+               if (cnt > 0) {
+                       EventRemoveAllDataPtr eventData( new EventCallHistoryPtrs<EventRemoveAll>(event, this));
+
+                       JSCallbackManagerPtr data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+                       if (data != NULL) {
+                               if (data->getOnSuccess() != NULL) {
+                                       ret = contacts_db_delete_records_async(_contacts_phone_log._uri, list, cnt, removeAllCB, eventData.Get());
+                                       if (ret == CONTACTS_ERROR_NONE) {
+                                               m_removeAllEvent.push_back(eventData);
+                                               event->switchToManualAnswer();
+                                       } else {
+                                               LogDebug("callhistory remove All error [" << ret << "]");
+                                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                                       }
+                               } else {
+                                       ret = contacts_db_delete_records(_contacts_phone_log._uri, list, cnt);
+                                       if (ret != CONTACTS_ERROR_NONE) {
+                                               LogDebug("callhistory remove All error [" << ret << "]");
+                                               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+                                       }
+                               }
+                       }
+               }
+
+               contacts_list_destroy(record_list, true);
+       } catch (const Commons::PlatformException& ex) {
+               LogError("Exception: " << ex.GetMessage());
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+
+       if (list != NULL) {
+               delete[] list;
+               list = NULL;
+       }
+}
+
+void CallHistory::callRemoveBatchEvent(int error, const EventRemoveBatchPtr &event)
+{
+       if (error != CONTACTS_ERROR_NONE) {
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+       
+       EventRequestReceiver<EventRemoveBatch>::ManualAnswer(event);
+
+       std::vector<EventRemoveBatchDataPtr>::iterator it;
+       for (it = m_removeBatchEvent.begin(); it != m_removeBatchEvent.end(); ++it) {
+               if ((*it)->getEventPtrs() == event) {
+                       m_removeBatchEvent.erase(it);
+                       LogDebug("event is removed. (" << m_removeBatchEvent.size() << ")");
+                       break;
+               }
+       }
+}
+
+void CallHistory::callRemoveAllEvent(int error, const EventRemoveAllPtr &event)
+{
+       if (error != CONTACTS_ERROR_NONE) {
+               event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+       }
+       
+       EventRequestReceiver<EventRemoveAll>::ManualAnswer(event);
+
+       std::vector<EventRemoveAllDataPtr>::iterator it;
+       for (it = m_removeAllEvent.begin(); it != m_removeAllEvent.end(); ++it) {
+               if ((*it)->getEventPtrs() == event) {
+                       m_removeAllEvent.erase(it);
+                       LogDebug("event is removed. (" << m_removeAllEvent.size() << ")");
+                       break;
+               }
+       }
+}
+
+CallHistory::Watcher::Watcher(long handle, const Api::Callhistory::EventCallHistoryListenerEmitterPtr& emitter) :
+                       m_handle(handle),
+                       m_emitter(emitter),
+                       m_currentLogId(0)
+{
+       m_missedCallList = MissedCallListPtr(new MissedCallList());
+       if (contacts_connect2() == CONTACTS_ERROR_NONE) {
+               LogDebug("Successful to connect Call history DB ");
+       } else {
+               LogDebug("Failed to connect Call history DB ");
+       }
+}
+
+CallHistory::Watcher::~Watcher()
+{
+       if (contacts_disconnect2()  == CONTACTS_ERROR_NONE) {
+               LogDebug("Successful to disconnect Call history DB ");
+       } else {
+               LogDebug("Failed to disconnect Call history DB ");
+       }
+}
+
+void CallHistory::Watcher::stateHasChanged(CallHistoryEntryListPtr &entryList, EventCallHistoryListener::ResultStates state)
+{
+       if (entryList == NULL)
+               return;
+
+       EventCallHistoryListenerPtr event(new EventCallHistoryListener());
+       event->setResultState(state);
+       event->setResult(entryList);
+       m_emitter->emit(event);
+}
+
+bool CallHistory::Watcher::parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &entryList)
+{
+       CallHistory* callHistory = (CallHistory *) this;
+       if (callHistory != NULL) {
+               return callHistory->parseRecord(recordList, entryList);
+       }
+       return false;
+}
+
+bool CallHistory::Watcher::addMissedCall(CallHistoryEntryListPtr &entryList)
+{
+       if (entryList != NULL) {
+               CallHistoryEntryList::iterator it = entryList->begin();
+               for (; it != entryList->end(); it++) {
+                       if ((*it)->getDirection().compare(STR_MISSED_NEW) == 0) {
+                               m_missedCallList->push_back((*it)->getEntryId());
+                       }
+               }
+               return true;
+       }
+       return false;
+}
+
+bool CallHistory::Watcher::updateCurrentMissedCall()
+{
+       CallHistory* callHistory = (CallHistory *) this;
+       if (callHistory != NULL) {
+               setMissedCallList(callHistory->updateCurrentMissedCall());
+               return true;
+       }
+       return false;
+}
+
+void CallHistory::Watcher::addedListenerCB()
+{
+       CallHistoryEntryListPtr callHistoryListPtr(new CallHistoryEntryList());
+       int ret = CONTACTS_ERROR_NONE;
+
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h recordList = NULL;
+
+       contacts_query_create(_contacts_phone_log._uri, &query);
+       contacts_filter_create(_contacts_phone_log._uri, &filter);
+       contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
+       contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
+       contacts_filter_add_int(filter, _contacts_phone_log.id, CONTACTS_MATCH_GREATER_THAN,  static_cast<int>(getCurrentLogId()));
+
+       contacts_query_set_filter(query, filter);
+       contacts_query_set_sort(query, _contacts_phone_log.id, false);
+       ret = contacts_db_get_records_with_query(query, 0, 0, &recordList);
+
+       if (ret != CONTACTS_ERROR_NONE) {
+               LogDebug("callhistory query error [" << ret << "]");
+       }
+
+       if (parseRecord(&recordList, callHistoryListPtr)) {
+               if (callHistoryListPtr->size() > 0) {
+                       setCurrentLogId((*callHistoryListPtr)[0]->getEntryId());
+                       stateHasChanged(callHistoryListPtr, EventCallHistoryListener::ADDED);
+                       addMissedCall(callHistoryListPtr);
+               }
+       }
+
+       contacts_list_destroy(recordList, true);
+       contacts_query_destroy(query);
+       contacts_filter_destroy(filter);
+}
+
+void CallHistory::Watcher::changedListenerCB()
+{
+       MissedCallListPtr missedCallListPtr(getMissedCallList());
+       CallHistoryEntryListPtr callHistoryListPtr(new CallHistoryEntryList());
+       int ret = CONTACTS_ERROR_NONE;
+
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h recordList = NULL;
+       
+       if (missedCallListPtr->size() > 0) {
+               contacts_query_create(_contacts_phone_log._uri, &query);
+               contacts_filter_create(_contacts_phone_log._uri, &filter);
+               contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
+               contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
+
+               MissedCallList::iterator itM = missedCallListPtr->begin();
+
+               do {
+                       if (itM != missedCallListPtr->begin()) {
+                               contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
+                       }
+                       contacts_filter_add_int(filter, _contacts_phone_log.id, CONTACTS_MATCH_EQUAL,  static_cast<int>(*itM));
+                       itM++;
+               } while(itM < missedCallListPtr->end());
+
+               contacts_query_set_filter(query, filter);
+               contacts_query_set_sort(query, _contacts_phone_log.id, false);
+               ret = contacts_db_get_records_with_query(query, 0, 0, &recordList);
+
+               if (ret != CONTACTS_ERROR_NONE) {
+                       LogDebug("callhistory query error [" << ret << "]");
+               }
+
+               if (parseRecord(&recordList, callHistoryListPtr)) {
+                       CallHistoryEntryList::iterator itC = callHistoryListPtr->begin();
+
+                       for (;itC != callHistoryListPtr->end();) {
+                               if ((*itC)->getDirection().compare(STR_MISSED) != 0) {
+                                       itC = callHistoryListPtr->erase(itC);
+                                       continue;
+                               }
+                               ++itC;
+                       }
+
+                       if (callHistoryListPtr->size() > 0) {
+                               updateCurrentMissedCall();
+                               stateHasChanged(callHistoryListPtr, EventCallHistoryListener::CHANGED);
+                       }
+               }
+
+               contacts_list_destroy(recordList, true);
+               contacts_query_destroy(query);
+               contacts_filter_destroy(filter);
+       }
+
+}
+
+}
+}
+}
+
diff --git a/src/platform/Tizen/Callhistory/CallHistory.h b/src/platform/Tizen/Callhistory/CallHistory.h
new file mode 100755 (executable)
index 0000000..aeaa086
--- /dev/null
@@ -0,0 +1,162 @@
+//
+// 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_CALLHISTORY_H_
+#define TIZENAPIS_PLATFORM_CALLHISTORY_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+
+#include <API/Callhistory/ICallHistory.h>
+#include <API/Callhistory/CallHistoryFactory.h>
+#include <API/Callhistory/EventCallHistoryTemplate.h>
+#include <API/Callhistory/EventCallHistory.h>
+#include <API/Callhistory/EventFindCallHistory.h>
+#include <API/Callhistory/EventRemoveBatch.h>
+#include <API/Callhistory/EventRemoveAll.h>
+#include <API/Callhistory/EventCallHistoryListener.h>
+#include <API/Callhistory/CallHistoryEntryProperties.h>
+#include <API/Callhistory/RemoteParty.h>
+#include <contacts.h>
+
+using namespace TizenApis::Api::Callhistory;
+typedef DPL::SharedPtr<EventCallHistoryPtrs<EventRemoveBatch>> EventRemoveBatchDataPtr;
+typedef DPL::SharedPtr<EventCallHistoryPtrs<EventRemoveAll>> EventRemoveAllDataPtr;
+
+namespace TizenApis {
+namespace Platform {
+namespace Callhistory {
+
+typedef std::vector<unsigned long> MissedCallList;
+typedef DPL::SharedPtr<MissedCallList> MissedCallListPtr;
+
+typedef struct
+{
+       int             calllog_db_id;
+       contacts_phone_log_type_e       calllog_type;
+       int             person_db_id;
+       char*           phone_number;
+       time_t          timestamp;
+       int             duration_sec;
+} callhistory_query_s;
+
+class CallHistory : public Api::Callhistory::ICallHistory
+{
+public:
+       CallHistory();
+       ~CallHistory();
+
+       static void callhistoryListenerCB(const char* view_uri, void* user_data);
+       static void removeBatchCB(int error, void *user_data);
+       static void removeAllCB(int error, void *user_data);
+
+       void find(const EventFindCallHistoryPtr& event);
+       bool remove(const unsigned long entryId);
+       void removeBatch(const EventRemoveBatchPtr& event);
+       void removeAll(const EventRemoveAllPtr& event);
+       long addListener(const EventCallHistoryListenerEmitterPtr& emitter);
+       void removeListener(const long id);
+
+       class Watcher
+       {
+       private:
+               long m_handle;
+               EventCallHistoryListenerEmitterPtr m_emitter;
+               unsigned int m_currentLogId;
+               Platform::Callhistory::MissedCallListPtr m_missedCallList;
+
+       public:
+               Watcher(long handle, const EventCallHistoryListenerEmitterPtr& emitter);
+               ~Watcher();
+
+               void setHandle(long handle)
+               {
+                       m_handle = handle;
+               }
+
+               long getHandle()
+               {
+                       return m_handle;
+               }
+
+               void setCurrentLogId(unsigned int logId)
+               {
+                       m_currentLogId = logId;
+               }
+
+               unsigned int getCurrentLogId()
+               {
+                       return m_currentLogId;
+               }
+
+               void setMissedCallList(const Platform::Callhistory::MissedCallListPtr &missedCallList)
+               {
+                       m_missedCallList = missedCallList;
+               }
+
+               Platform::Callhistory::MissedCallListPtr getMissedCallList()
+               {
+                       return m_missedCallList;
+               }
+
+               EventCallHistoryListenerEmitterPtr getEmitter()
+               {
+                       return m_emitter;
+               }
+
+               void emit(const EventCallHistoryListenerPtr& event)
+               {
+                       m_emitter->emit(event);
+               }
+
+               void stateHasChanged(CallHistoryEntryListPtr &entryList, EventCallHistoryListener::ResultStates state);
+               bool parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &entryList);
+               bool addMissedCall(CallHistoryEntryListPtr &entryList);
+               bool updateCurrentMissedCall();
+               void addedListenerCB();
+               void changedListenerCB();
+       };
+       typedef DPL::SharedPtr<Watcher> WatcherPtr;
+
+private:
+       bool convertCallHistory(callhistory_query_s *query_log, CallHistoryEntryListPtr &callEntries);
+       bool parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &callEntries);
+       unsigned int  convertAttrName(std::string &name);
+       Platform::Callhistory::MissedCallListPtr updateCurrentMissedCall();
+
+       std::vector<EventRemoveBatchDataPtr> m_removeBatchEvent;
+       std::vector<EventRemoveAllDataPtr> m_removeAllEvent;
+
+       void callRemoveBatchEvent(int error, const EventRemoveBatchPtr &event);
+       void callRemoveAllEvent(int error, const EventRemoveAllPtr &event);
+
+protected:
+       void OnRequestReceived(const EventCallHistoryPtr& event);
+       void OnRequestReceived(const EventFindCallHistoryPtr& event);
+       void OnRequestReceived(const EventRemoveBatchPtr& event);
+       void OnRequestReceived(const EventRemoveAllPtr& event);
+
+private:
+       static std::vector<WatcherPtr> m_watchers;
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/Tizen/Callhistory/CallHistoryEntry.cpp b/src/platform/Tizen/Callhistory/CallHistoryEntry.cpp
new file mode 100755 (executable)
index 0000000..f68c33e
--- /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 "CallHistoryEntry.h"
+
+#include <Commons/Exception.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/log/log.h>
+#include <contacts.h>
+
+using namespace TizenApis::Api::Tizen;
+using namespace TizenApis::Api::Callhistory;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace DPL;
+
+namespace TizenApis {
+namespace Platform {
+namespace Callhistory {
+
+CallHistoryEntry::CallHistoryEntry()
+{
+       if (contacts_connect2() == CONTACTS_ERROR_NONE) {
+               LogDebug("Successful to connect Call history DB ");
+       } else {
+               LogDebug("Failed to connect Call history DB ");
+       }
+}
+
+CallHistoryEntry::~CallHistoryEntry()
+{
+       if (contacts_disconnect2()  == CONTACTS_ERROR_NONE) {
+               LogDebug("Successful to disconnect Call history DB ");
+       } else {
+               LogDebug("Failed to disconnect Call history DB ");
+       }
+}
+
+void CallHistoryEntry::setMarkSeen(const unsigned long entryId)
+{
+       contacts_record_h record = NULL;
+       int ret = -1;
+       int logType = 0;
+
+       ret = contacts_db_get_record (_contacts_phone_log._uri, (int)entryId, &record);
+
+       if (ret != CONTACTS_ERROR_NONE) {
+               ThrowMsg(Commons::ConversionException, "Type missmatch error");
+               return;
+       }
+
+       contacts_record_get_int (record, _contacts_phone_log.log_type, &logType);
+
+       if (logType == 5) {
+               contacts_record_set_int (record, _contacts_phone_log.log_type, 6);
+       } else if (logType == 7) {
+               contacts_record_set_int (record, _contacts_phone_log.log_type, 8);
+       } else {
+               contacts_record_destroy(record, true);
+               ThrowMsg(Commons::ConversionException, "Type missmatch error");
+               return;
+       }
+
+       ret = contacts_db_update_record (record);
+
+       if (ret != CONTACTS_ERROR_NONE) {
+               contacts_record_destroy(record, true);
+               ThrowMsg(Commons::ConversionException, "Type missmatch error");
+               return;
+       }
+
+       contacts_record_destroy(record, true);
+}
+
+}
+}
+}
+
diff --git a/src/platform/Tizen/Callhistory/CallHistoryEntry.h b/src/platform/Tizen/Callhistory/CallHistoryEntry.h
new file mode 100755 (executable)
index 0000000..567ee50
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// 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_CALLHISTORYENTRY_H_
+#define TIZENAPIS_PLATFORM_CALLHISTORYENTRY_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+
+#include <API/Callhistory/ICallHistoryEntry.h>
+#include <API/Callhistory/CallHistoryFactory.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Callhistory {
+
+class CallHistoryEntry : public Api::Callhistory::ICallHistoryEntry
+{
+public:
+       CallHistoryEntry();
+       ~CallHistoryEntry();
+
+       void setMarkSeen(const unsigned long entryId);
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/Tizen/Callhistory/CallHistoryFilter.cpp b/src/platform/Tizen/Callhistory/CallHistoryFilter.cpp
new file mode 100755 (executable)
index 0000000..b4b9d99
--- /dev/null
@@ -0,0 +1,303 @@
+//
+// 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 <iomanip>
+
+#include <API/Callhistory/CallHistoryDefine.h>
+#include "CallHistoryFilter.h"
+
+using namespace std;
+using namespace TizenApis::Api::Tizen;
+using namespace TizenApis::Api::Callhistory;
+
+namespace TizenApis {
+namespace Platform {
+namespace Callhistory {
+
+CallHistoryFilter::CallHistoryFilter(contacts_filter_h filter)
+{
+       m_filterStack.push(filter);
+}
+
+CallHistoryFilter::~CallHistoryFilter()
+{
+       contacts_filter_h filter = NULL;
+       while (m_filterStack.size() > 1) {
+               filter = m_filterStack.top();
+               contacts_filter_destroy(filter);
+               m_filterStack.pop();
+       }
+}
+
+void CallHistoryFilter::visitPreComposite(FilterType& type, int depth)
+{
+       LogDebug(" type [" << type << "] depth[" << depth << "]");
+       contacts_filter_h filter = NULL;
+       contacts_filter_create(_contacts_phone_log._uri, &filter);
+       if (filter != NULL) {
+               m_filterStack.push(filter);
+       }
+       LogDebug("filter stack size [" << m_filterStack.size() << "]");
+}
+
+void CallHistoryFilter::visitInComposite(FilterType& type, int depth)
+{
+       LogDebug("type [" << type << "] depth[" << depth << "]");
+       contacts_filter_h filter = m_filterStack.top();
+       if(type == Api::Tizen::UNION_FILTER)
+               contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
+       else if(type == Api::Tizen::INTERSECTION_FILTER)
+               contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
+
+       LogDebug("filter stack size [" << m_filterStack.size() << "]");
+}
+
+void CallHistoryFilter::visitPostComposite(FilterType& type, int depth)
+{
+       LogDebug(" type [" << type << "] depth[" << depth << "]");
+       contacts_filter_h filter = m_filterStack.top();
+       if (m_filterStack.size() > 1) {
+               m_filterStack.pop();
+               contacts_filter_h filterParent = m_filterStack.top();
+               contacts_filter_add_filter(filterParent, filter);
+               contacts_filter_destroy(filter);
+       }
+       LogDebug("filter stack size [" << m_filterStack.size() << "]");
+}
+
+void CallHistoryFilter::visitAttribute(std::string& attrName, MatchFlag& matchFlag, Api::Tizen::AnyPtr& matchValue, int depth)
+{
+       std::string str ("");
+       contacts_match_str_flag_e mFlag;
+
+       if (matchValue == NULL) {
+               return;
+       }
+
+       LogDebug("attrName [" << attrName << "] matchValue[" << matchValue->toString() << "] depth[" << depth << "]");
+       contacts_filter_h filter = m_filterStack.top();
+       contacts_filter_h subFilter = NULL;
+       contacts_filter_create(_contacts_phone_log._uri, &subFilter);
+
+       switch (matchFlag) {
+       case MATCH_EXACTLY:
+               mFlag = CONTACTS_MATCH_EXACTLY;
+               break;
+       case MATCH_FULLSTRING:
+               mFlag = CONTACTS_MATCH_FULLSTRING;
+               break;
+       case MATCH_CONTAINS:
+               mFlag = CONTACTS_MATCH_CONTAINS;
+               break;
+       case MATCH_STARTSWITH:
+               mFlag = CONTACTS_MATCH_STARTSWITH;
+               break;
+       case MATCH_ENDSWITH:
+               mFlag = CONTACTS_MATCH_ENDSWITH;
+               break;
+       case MATCH_EXISTS:
+               mFlag = CONTACTS_MATCH_EXISTS;
+               break;
+       default:
+               mFlag = CONTACTS_MATCH_EXACTLY;
+       }
+
+       if (attrName.compare(STR_DIRECTION) == 0) {
+               if (matchValue->toString().compare(STR_RECEIVED) == 0) {
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING);
+                       contacts_filter_add_filter(filter, subFilter);
+               } else if (matchValue->toString().compare(STR_DIALED) == 0) {
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_OUTGOING);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_OUTGOING);
+                       contacts_filter_add_filter(filter, subFilter);
+               } else if (matchValue->toString().compare(STR_MISSED) == 0) {
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN);
+                       contacts_filter_add_filter(filter, subFilter);
+               } else if (matchValue->toString().compare(STR_MISSED_NEW) == 0) {
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN);
+                       contacts_filter_add_filter(filter, subFilter);
+               } else if (matchValue->toString().compare(STR_REJECTED) == 0) {
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_REJECT);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_REJECT);
+                       contacts_filter_add_filter(filter, subFilter);
+               } else if (matchValue->toString().compare(STR_BLOCKED) == 0) {
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_BLOCKED);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
+                       contacts_filter_add_filter(filter, subFilter);
+               } else {
+                       contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
+               }
+       } else if (attrName.compare(STR_TAGS) == 0) {
+               if (matchValue->toString().compare(STR_CALL) == 0) {
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
+                       contacts_filter_add_filter(filter, subFilter);
+               } else if (matchValue->toString().compare(STR_CALL_VOICE) == 0) {
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_OUTGOING);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_REJECT);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VOICE_BLOCKED);
+                       contacts_filter_add_filter(filter, subFilter);
+               } else if (matchValue->toString().compare(STR_CALL_VIDEO) == 0) {
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_OUTGOING);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_REJECT);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_OR);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
+                       contacts_filter_add_filter(filter, subFilter);
+               } else {
+                       contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
+               }
+       } else if (attrName.compare(STR_RP_REMOTEPARTY) == 0) {
+               contacts_filter_add_str(filter, _contacts_phone_log.address, mFlag, matchValue->toString().c_str());
+       } else if (attrName.compare(STR_RP_PERSONID) == 0) {
+               contacts_filter_add_str(filter, _contacts_phone_log.person_id, mFlag, matchValue->toString().c_str());
+       } else if (attrName.compare(STR_START_TIME) == 0) {
+               if(matchValue->getType() == PrimitiveType_Time) {
+                       contacts_filter_add_int(filter, _contacts_phone_log.log_time, CONTACTS_MATCH_EQUAL, static_cast<int>(matchValue->getTimeT()));
+               }
+       } else if (attrName.compare(STR_DURATION) == 0) {
+               contacts_filter_add_str(filter, _contacts_phone_log.extra_data1, mFlag, matchValue->toString().c_str());
+       } else if (attrName.compare(STR_CALL_TYPE) == 0) {
+               if (matchValue->toString().compare(STR_TIZEN_TEL) == 0) {
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMMING);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
+                       contacts_filter_add_int(subFilter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
+                       contacts_filter_add_filter(filter, subFilter);
+               } else {
+                       contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
+               }
+       } else if (attrName.compare(STR_ENTRY_ID) == 0) {
+               contacts_filter_add_str(filter, _contacts_phone_log.id, mFlag, matchValue->toString().c_str());
+       } else {
+               contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_EQUAL, CONTACTS_PLOG_TYPE_NONE);
+       }
+
+       contacts_filter_destroy(subFilter);
+}
+
+void CallHistoryFilter::visitAttributeRange(std::string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth)
+{
+       if(initialValue == NULL || endValue == NULL)
+               return;
+
+       LogDebug("attrName [" << attrName << "] initialValue[" << initialValue->toString() << "] endValue[" << endValue->toString() << "] depth[" << depth <<"]");
+       contacts_filter_h filter = m_filterStack.top();
+       
+       unsigned int propertyId = 0;
+       int iValue = 0;
+       int eValue = 0;
+
+       if (attrName.compare(STR_RP_REMOTEPARTY) == 0) {
+               propertyId = _contacts_phone_log.address;
+       } else if (attrName.compare(STR_RP_PERSONID) == 0) {
+               propertyId = _contacts_phone_log.person_id;
+       } else if (attrName.compare(STR_START_TIME) == 0) {
+               propertyId = _contacts_phone_log.log_time;      
+       } else if (attrName.compare(STR_DURATION) == 0) {
+               propertyId = _contacts_phone_log.extra_data1;
+       } else if (attrName.compare(STR_ENTRY_ID) == 0) {
+               propertyId = _contacts_phone_log.id;
+       } else {
+               return;
+       }
+
+       if (!initialValue->isNullOrUndefined()) {
+               if (propertyId != _contacts_phone_log.address) {
+                       if(initialValue->getType() == PrimitiveType_Time) {
+                               iValue = static_cast<int>(initialValue->getTimeT());
+                       } else {
+                               iValue = atoi(initialValue->toString().c_str());
+                       }
+               }
+               LogDebug("attrName [" << attrName << "] initialValue[" << initialValue->toString() << "] iValue[" << iValue << "]");
+       }
+
+       if (!endValue->isNullOrUndefined()) {
+               if (propertyId != _contacts_phone_log.address) {
+                       if(endValue->getType() == PrimitiveType_Time) {
+                               eValue = static_cast<int>(endValue->getTimeT());
+                       } else {
+                               eValue = atoi(endValue->toString().c_str());
+                       }
+               }
+               LogDebug("attrName [" << attrName << "] endValue[" << endValue->toString() << "] eValue[" << eValue << "]");
+       }
+
+       contacts_filter_h subFilter = NULL;
+       contacts_filter_create(_contacts_phone_log._uri, &subFilter);
+
+       if (propertyId == _contacts_phone_log.address) {
+               if (!initialValue->isNullOrUndefined() && endValue->isNullOrUndefined()) {
+                       contacts_filter_add_str(filter, propertyId, CONTACTS_MATCH_STARTSWITH, initialValue->toString().c_str());
+               } else if (initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
+                       contacts_filter_add_str(filter, propertyId, CONTACTS_MATCH_ENDSWITH, endValue->toString().c_str());
+               } else if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
+                       contacts_filter_add_str(subFilter, propertyId, CONTACTS_MATCH_STARTSWITH, initialValue->toString().c_str());
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
+                       contacts_filter_add_str(subFilter, propertyId, CONTACTS_MATCH_ENDSWITH, endValue->toString().c_str());
+                       contacts_filter_add_filter(filter, subFilter);
+               }
+       } else {
+               if (!initialValue->isNullOrUndefined() && endValue->isNullOrUndefined()) {
+                       contacts_filter_add_int(filter, propertyId, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, iValue);
+               } else if (initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
+                       contacts_filter_add_int(filter, propertyId, CONTACTS_MATCH_LESS_THAN, eValue);
+               } else if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) {
+                       contacts_filter_add_int(subFilter, propertyId, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, iValue);
+                       contacts_filter_add_operator(subFilter, CONTACTS_FILTER_OPERATOR_AND);
+                       contacts_filter_add_int(subFilter, propertyId, CONTACTS_MATCH_LESS_THAN, eValue);
+                       contacts_filter_add_filter(filter, subFilter);
+               }
+       }
+       contacts_filter_destroy(subFilter);
+}
+
+contacts_filter_h CallHistoryFilter::getResult() const
+{
+       LogDebug("filter stack size [" << m_filterStack.size() << "]");
+       contacts_filter_h filter = m_filterStack.top();
+       return filter;
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Callhistory/CallHistoryFilter.h b/src/platform/Tizen/Callhistory/CallHistoryFilter.h
new file mode 100755 (executable)
index 0000000..0db43de
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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_CALLHISTORY_FILTER_H_
+#define TIZENAPIS_PLATFORM_CALLHISTORY_FILTER_H_
+
+#include <string>
+#include <stack>
+#include <dpl/shared_ptr.h>
+#include "time.h"
+
+#include <API/Filter/IFilterVisitor.h>
+#include <API/Callhistory/CallHistoryEntryProperties.h>
+#include <API/Callhistory/CallHistoryDefine.h>
+#include <contacts.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Callhistory {
+
+
+class CallHistoryFilter: public Api::Tizen::IFilterVisitor
+{
+private:
+       std::stack<contacts_filter_h> m_filterStack;
+
+public:
+       CallHistoryFilter(contacts_filter_h filter);
+       ~CallHistoryFilter();
+
+       void visitPreComposite(Api::Tizen::FilterType& type, int depth);
+
+       void visitInComposite(Api::Tizen::FilterType& type, int depth);
+
+       void visitPostComposite(Api::Tizen::FilterType& type, int depth);
+
+       void visitAttribute(std::string& attrName,
+                       Api::Tizen::MatchFlag& matchFlag,
+                       Api::Tizen::AnyPtr& matchValue,
+                       int depth);
+
+       void visitAttributeRange(std::string& attrName,
+                       Api::Tizen::AnyPtr& initialValue,
+                       Api::Tizen::AnyPtr& endValue,
+                       int depth);
+
+       contacts_filter_h getResult() const;
+};
+
+typedef DPL::SharedPtr<CallHistoryFilter> CallHistoryFilterPtr;
+
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Callhistory/config.cmake b/src/platform/Tizen/Callhistory/config.cmake
new file mode 100755 (executable)
index 0000000..d507527
--- /dev/null
@@ -0,0 +1,27 @@
+get_current_path()
+pkg_search_module(contacts-service REQUIRED contacts-service2)
+pkg_search_module(glib REQUIRED glib-2.0)
+pkg_search_module(libpcrecpp REQUIRED libpcrecpp)
+
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_CALLHISTORY
+  ${contacts-service_INCLUDE_DIRS}
+  ${glib_INCLUDE_DIRS}
+  ${libpcrecpp_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_CALLHISTORY
+  ${contacts-service_LIBRARIES}
+  ${capicall_LIBRARIES}
+  ${glib_LIBRARIES}
+  ${libpcrecpp_LIBRARIES}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_CALLHISTORY
+  ${CURRENT_PATH}/CallHistory.cpp
+  ${CURRENT_PATH}/CallHistoryEntry.cpp
+  ${CURRENT_PATH}/CallHistoryFilter.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/Contact/AddressBook.cpp b/src/platform/Tizen/Contact/AddressBook.cpp
new file mode 100755 (executable)
index 0000000..798e6ef
--- /dev/null
@@ -0,0 +1,1776 @@
+//
+// 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        AddressBook.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "AddressBook.h"
+
+#include <contacts.h>
+
+#include <ctime>
+#include <cstdlib>
+#include <cstddef>
+#include <dpl/log/log.h>
+#include <dpl/exception.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+#include <API/Contact/IAddressBook.h>
+#include <API/Contact/IContact.h>
+#include "Contact.h"
+#include "ContactObjectA2PConverter.h"
+#include "ContactObjectP2AConverter.h"
+#include "ContactsSvcObjectConverter.h"
+#include "ContactSearchEngine.h"
+#include "ContactFilterValidator.h"
+#include "ContactUtility.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+AddressBook::AddressBook(bool isDefault) :
+               IAddressBook(),
+               m_id(0),
+               m_name("TEST_ADDRESS_BOOK"),
+               m_readOnly(false),
+               m_accountId(0),
+               m_isDefaultAddressBook(isDefault),
+               m_eventMapAcc(100)
+{
+    LogDebug("entered");
+}
+
+AddressBook::~AddressBook()
+{
+       if(m_addressBookEmitters.size() != 0)
+       {
+               ContactsSvcChangeListenerManagerSingleton::Instance().unregisterContactsChangeListener(this);
+       }
+}
+
+std::string AddressBook::getId() const
+{
+       if(m_isDefaultAddressBook)
+               return string("");
+
+       return ContactUtility::intToStr(m_id);
+}
+
+void AddressBook::setId(const std::string &value)
+{
+       m_id = ContactUtility::strToInt(value);
+}
+
+std::string AddressBook::getAccountId() const
+{
+       if(m_isDefaultAddressBook)
+               return string("");
+
+       return ContactUtility::intToStr(m_accountId);
+}
+
+void AddressBook::setAccountId(const std::string &value)
+{
+       m_accountId = ContactUtility::strToInt(value);
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookGetPtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+       contacts_record_h contacts_record = NULL;
+
+       Try
+       {
+               if(!event->getIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "Invalid contact id");
+
+               string contactId = event->getId();
+
+               int contactIdInt = ContactUtility::strToInt(contactId);
+
+               errorCode = contacts_db_get_record(_contacts_contact._uri, contactIdInt, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
+                       ThrowMsg(NotFoundException, "No contact (id:" << contactIdInt << ")");
+
+               if(!m_isDefaultAddressBook)
+               {
+                       int addressBookId = 0;
+                       contacts_record_get_int(contacts_record, _contacts_contact.address_book_id, &addressBookId);
+                       if(addressBookId != m_id)
+                               ThrowMsg(NotFoundException, "No contact (id:" << contactIdInt << ") in this address book.");
+               }
+
+               ContactObjectP2AConverterPtr contactObjConverter(
+                               new ContactObjectP2AConverter(contacts_record, false));
+               ContactPtr contact = contactObjConverter->getAbstractContact();
+
+               event->setContact(contact);
+               event->setResult(true);
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               event->setResult(false);
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during getting contact : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               event->setResult(false);
+       }
+       Catch(Exception)
+       {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::UnknownException);
+               event->setResult(false);
+       }
+
+       if(contacts_record != NULL)
+               contacts_record_destroy(contacts_record, true);
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookAddPtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+       int id = 0;
+       contacts_record_h contacts_record = NULL;
+       ContactPtr contact(NULL);
+
+       Try
+       {
+               if(!event->getContactIsSet())
+                       ThrowMsg(InvalidArgumentException, "Contacts were not set.");
+
+               contact = event->getContact();
+               if(!contact)
+                       ThrowMsg(InvalidArgumentException, "No contacts.");
+               id = ContactUtility::strToInt(contact->getId());
+               if(id != 0)
+                       ThrowMsg(InvalidArgumentException, "invalid contact object : Id is already set");
+
+       }
+       Catch(InvalidArgumentException)
+       {
+               LogError("Invalid arguments for adding contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+
+       Try
+       {
+               DPL::SharedPtr<TizenApis::Platform::Contact::Contact> contactT =
+                               DPL::StaticPointerCast<TizenApis::Platform::Contact::Contact>(contact);
+
+               ContactObjectA2PConverterPtr contactObjConverter(NULL);
+
+               contacts_record = contactT->getPlatformContactObject();
+               if(contacts_record == NULL)
+               {
+                       contactObjConverter = ContactObjectA2PConverterPtr(
+                                       new ContactObjectA2PConverter(contact, false) );
+                       contacts_record = contactObjConverter->getPlatformContact();
+               }
+               else
+               {
+                       contactObjConverter = ContactObjectA2PConverterPtr(
+                                       new ContactObjectA2PConverter(contact, false, contacts_record) );
+                       contacts_record = contactObjConverter->getPlatformContact();
+               }
+
+               int contactId = 0;
+               if (!contacts_record)
+               {
+                       LogError("Error during converting contact object");
+                       ThrowMsg(PlatformException, "Error during converting contact object");
+               }
+
+               if(m_isDefaultAddressBook)
+                       errorCode = contacts_record_set_int(contacts_record, _contacts_contact.address_book_id, 0);
+               else
+                       errorCode = contacts_record_set_int(contacts_record, _contacts_contact.address_book_id, m_id);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogError("error code : " << errorCode);
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_insert_record()");
+               }
+
+               errorCode = contacts_db_insert_record(contacts_record, &contactId);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogError("error code : " << errorCode);
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_insert_record()");
+               }
+
+               contacts_record = NULL;
+               errorCode = contacts_db_get_record(_contacts_contact._uri, contactId, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
+                       ThrowMsg(PlatformException, "No contact just inserted  (id:" << contactId << ")");
+
+               ContactObjectP2AConverterPtr contactObjConverterForInserted(
+                               new ContactObjectP2AConverter(contacts_record, false));
+               ContactPtr insertedContact = contactObjConverterForInserted->getAbstractContact();
+               contact->copy(insertedContact);
+
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+       Catch (Exception)
+       {
+               LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::UnknownException);
+       }
+
+       if(contacts_record != NULL)
+               contacts_record_destroy(contacts_record, true);
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookAddBatchPtr &event)
+{
+       LogDebug("entered");
+       int errorCode = 0;
+       contacts_list_h contacts_list = NULL;
+       ContactArrayPtr contacts(NULL);
+
+       Try
+       {
+               if(!event->getContactsIsSet())
+                       ThrowMsg(InvalidArgumentException, "Contacts were not set.");
+
+               contacts = event->getContacts();
+               if(!contacts)
+                       ThrowMsg(InvalidArgumentException, "No contacts.");
+
+       }
+       Catch(InvalidArgumentException)
+       {
+               LogError("Invalid arguments for adding contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+
+       Try
+       {
+               errorCode = contacts_list_create(&contacts_list);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(PlatformException, "Fail to create contacts_list_h");
+               }
+
+               for(ContactArray::iterator i = contacts->begin(); i != contacts->end(); i++)
+               {
+                       contacts_record_h contacts_record = NULL;
+                       ContactPtr contact = *i;
+                       ContactObjectA2PConverterPtr contactObjConverter(NULL);
+
+                       Try
+                       {
+                               DPL::SharedPtr<TizenApis::Platform::Contact::Contact> newContactT =
+                                               DPL::StaticPointerCast<TizenApis::Platform::Contact::Contact>(contact);
+                               contacts_record = newContactT->getPlatformContactObject();
+                               if(contacts_record == NULL)
+                               {
+                                       errorCode = contacts_record_create(_contacts_contact._uri, &contacts_record);
+                                       if(errorCode != CONTACTS_ERROR_NONE)
+                                       {
+                                               ThrowMsg(PlatformException, "Error during creating contact record : " << errorCode);
+                                       }
+                               }
+
+                               contactObjConverter = ContactObjectA2PConverterPtr(
+                                               new ContactObjectA2PConverter(contact, false, contacts_record) );
+                               contacts_record = contactObjConverter->getPlatformContact();
+
+                               if(contacts_record == NULL)
+                               {
+                                       ThrowMsg(PlatformException, "Error during converting contact object");
+                               }
+
+                               if(m_isDefaultAddressBook)
+                                       errorCode = contacts_record_set_int(contacts_record, _contacts_contact.address_book_id, 0);
+                               else
+                                       errorCode = contacts_record_set_int(contacts_record, _contacts_contact.address_book_id, m_id);
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       ThrowMsg(PlatformException, "Error during add address book id : " << errorCode);
+                               }
+
+                               errorCode = contacts_list_add(contacts_list, contacts_record);
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       ThrowMsg(PlatformException, "Error during add to list : " << errorCode);
+                               }
+                       }
+                       Catch(Exception)
+                       {
+                               ThrowMsg(NotFoundException, "Error during converting contact object");
+//                             LogError("Error during converting contact object : " << _rethrown_exception.GetMessage());
+//                             continue;
+                       }
+               }
+
+               KeySharePtrPair *keyPair = new KeySharePtrPair();
+               keyPair->key = m_eventMapAcc;
+               keyPair->addressBook = this;
+               errorCode = contacts_db_insert_records_async(contacts_list, contactsAddBatchResultCallback, (void*)keyPair);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       delete keyPair;
+                       ThrowMsg(PlatformException, "Error during contacts_db_insert_records_async");
+               }
+
+               errorCode = contacts_list_destroy(contacts_list, true);
+               contacts_list = NULL;
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       delete keyPair;
+                       ThrowMsg(PlatformException, "Error during contacts_list_destroy");
+               }
+
+               pair<long, EventAddressBookAddBatchPtr> keyEventPair(m_eventMapAcc, event);
+               m_addBatchEventMap.insert(keyEventPair);
+
+               m_eventMapAcc++;
+
+               event->switchToManualAnswer();
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during adding contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+       Catch (Exception)
+       {
+               LogError("Error during adding contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+
+       if(contacts_list != NULL)
+               contacts_list_destroy(contacts_list, true);
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookUpdatePtr &event)
+{
+       LogDebug("entered");
+       ContactPtr contact(NULL);
+
+       Try
+       {
+               if(!event->getContactIsSet())
+                       ThrowMsg(InvalidArgumentException, "Contacts were not set.");
+
+               contact = event->getContact();
+               if(!contact)
+                       ThrowMsg(InvalidArgumentException, "No contact.");
+
+               if(!contact->getIdIsSet() || !contact->getAddressBookIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "Contact has no ID");
+
+               if(!m_isDefaultAddressBook && contact->getAddressBookId() != getId())
+                       ThrowMsg(InvalidArgumentException, "Wrong address book ID");
+       }
+       Catch(InvalidArgumentException)
+       {
+               LogError("Invalid arguments for adding contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+
+       Try
+       {
+               int errorCode = 0;
+
+               DPL::SharedPtr<TizenApis::Platform::Contact::Contact> contactT =
+                               DPL::StaticPointerCast<TizenApis::Platform::Contact::Contact>(contact);
+
+               ContactObjectA2PConverterPtr contactObjConverter(NULL);
+
+               contacts_record_h contacts_record = contactT->getPlatformContactObject();
+               if(contacts_record == NULL)
+               {
+                       contactObjConverter = ContactObjectA2PConverterPtr(
+                                       new ContactObjectA2PConverter(contact, false) );
+                       contacts_record = contactObjConverter->getPlatformContact();
+               }
+               else
+               {
+                       contactObjConverter = ContactObjectA2PConverterPtr(
+                                       new ContactObjectA2PConverter(contact, false, contacts_record) );
+                       contacts_record = contactObjConverter->getPlatformContact();
+               }
+
+               if (!contacts_record)
+               {
+                       LogError("Error during converting contact object");
+                       ThrowMsg(PlatformException, "Error during converting contact object");
+               }
+
+               errorCode = contacts_db_update_record(contacts_record);
+               if (errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
+                       ThrowMsg(NotFoundException, "Error during executing contacts_db_update_record()");
+               else if (errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogError("error code : " << errorCode);
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_update_record()");
+               }
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               return;
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       Catch (Exception)
+       {
+               LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       //m_latestVersion = get_contact_version();
+
+       event->setResult(true);
+       event->setExceptionCode(ExceptionCodes::None);
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookUpdateBatchPtr &event)
+{
+       LogDebug("entered");
+       int errorCode = 0;
+       contacts_list_h contacts_list = NULL;
+       ContactArrayPtr contacts(NULL);
+
+       Try
+       {
+               if(!event->getContactsIsSet())
+                       ThrowMsg(InvalidArgumentException, "Contacts were not set.");
+
+               contacts = event->getContacts();
+               if(!contacts)
+                       ThrowMsg(InvalidArgumentException, "No contacts.");
+
+       }
+       Catch(InvalidArgumentException)
+       {
+               LogError("Invalid arguments for updating contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+
+       Try
+       {
+               errorCode = contacts_list_create(&contacts_list);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(PlatformException, "Fail to create contacts_list_h");
+               }
+
+               for(ContactArray::iterator i = contacts->begin(); i != contacts->end(); i++)
+               {
+                       contacts_record_h contacts_record = NULL;
+                       ContactPtr contact = *i;
+                       ContactObjectA2PConverterPtr contactObjConverter(NULL);
+
+                       Try
+                       {
+                               if(!contact)
+                                       ThrowMsg(InvalidArgumentException, "No contact.");
+
+                               if(contact->getIdIsSet() == false)
+                                       ThrowMsg(InvalidArgumentException, "Contact has no ID");
+
+                               if(!m_isDefaultAddressBook && ( !contact->getAddressBookIdIsSet() || contact->getAddressBookId() != getId()))
+                                       ThrowMsg(InvalidArgumentException, "Wrong address book ID");
+
+                               DPL::SharedPtr<TizenApis::Platform::Contact::Contact> newContactT =
+                                               DPL::StaticPointerCast<TizenApis::Platform::Contact::Contact>(contact);
+                               contacts_record = newContactT->getPlatformContactObject();
+                               if(contacts_record == NULL)
+                               {
+                                       LogDebug("id : " << contact->getId());
+                                       int contactIdInt = ContactUtility::strToInt(contact->getId());
+                                       errorCode = contacts_db_get_record(_contacts_contact._uri, contactIdInt, &contacts_record);
+                                       if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
+                                               ThrowMsg(NotFoundException, "No contact (id:" << contactIdInt << ")");
+                               }
+                               contactObjConverter = ContactObjectA2PConverterPtr(
+                                               new ContactObjectA2PConverter(contact, false, contacts_record) );
+                               contacts_record = contactObjConverter->getPlatformContact();
+
+                               if(contacts_record == NULL)
+                               {
+                                       ThrowMsg(PlatformException, "Error during converting contact object");
+                               }
+
+                               errorCode = contacts_list_add(contacts_list, contacts_record);
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       ThrowMsg(PlatformException, "Error during add to list");
+                               }
+                       }
+                       Catch(Exception)
+                       {
+                               ThrowMsg(NotFoundException, "Error during converting contact object");
+//                             LogError("Error during converting contact object : " << _rethrown_exception.GetMessage());
+//                             continue;
+                       }
+               }
+
+               KeySharePtrPair *keyPair = new KeySharePtrPair();
+               keyPair->key = m_eventMapAcc;
+               keyPair->addressBook = this;
+               errorCode = contacts_db_update_records_async(contacts_list, contactsUpdateBatchResultCallback, (void*)keyPair);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       delete keyPair;
+                       ThrowMsg(PlatformException, "Error during contacts_db_update_records_async");
+               }
+
+               errorCode = contacts_list_destroy(contacts_list, true);
+               contacts_list = NULL;
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       delete keyPair;
+                       ThrowMsg(PlatformException, "Error during contacts_list_destroy");
+               }
+
+               pair<long, EventAddressBookUpdateBatchPtr> keyEventPair(m_eventMapAcc, event);
+               m_updateBatchEventMap.insert(keyEventPair);
+
+               m_eventMapAcc++;
+
+               event->switchToManualAnswer();
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during adding contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+       Catch (Exception)
+       {
+               LogError("Error during adding contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+
+       if(contacts_list != NULL)
+               contacts_list_destroy(contacts_list, false);
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookRemovePtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+       Try
+       {
+               if(!event->getContactIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "Contact id was not set.");
+
+               string contactIdStr = event->getContactId();
+
+               if(!ContactUtility::checkStrIsUInt(contactIdStr))
+                       ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
+
+               int contactId = ContactUtility::strToInt(contactIdStr);
+
+               if(!m_isDefaultAddressBook)
+               {
+                       contacts_record_h contacts_record = NULL;
+                       errorCode = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &contacts_record);
+                       if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
+                               ThrowMsg(PlatformException, "No contact id (id:" << contactId << ")");
+
+                       int addressBookId = 0;
+                       errorCode = contacts_record_get_int(contacts_record, _contacts_simple_contact.address_book_id, &addressBookId);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "Error while getting address book id");
+
+                       if(addressBookId != m_id)
+                               ThrowMsg(PlatformException, "Contact id (" << contactId << ") is not a member of this address book.");
+               }
+
+               errorCode = contacts_db_delete_record(_contacts_contact._uri, contactId);
+               if(errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
+                       ThrowMsg(NotFoundException, "Error during executing contacts_db_delete_record()");
+               else if (errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_delete_record()");
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid contact id : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               return;
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during updating contact : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       Catch (Exception)
+       {
+               LogError("Error during updating contact : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+
+       event->setResult(true);
+       event->setExceptionCode(ExceptionCodes::None);
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookRemoveBatchPtr &event)
+{
+       LogDebug("entered");
+       int errorCode = 0;
+       StringArrayPtr contactIds(NULL);
+
+       Try
+       {
+               if(!event->getContactIdsIsSet())
+                       ThrowMsg(InvalidArgumentException, "Contact IDs were not set.");
+
+               contactIds = event->getContactIds();
+               if(!contactIds)
+                       ThrowMsg(InvalidArgumentException, "No contact IDs.");
+
+       }
+       Catch(InvalidArgumentException)
+       {
+               LogError("Invalid arguments for removing contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+
+       Try
+       {
+               int *ids = new int[contactIds->size()];
+               int *tmpIds = new int[contactIds->size()];
+               int count = 0;
+
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(PlatformException, "Fail to create contacts_list_h");
+               }
+
+               for(StringArray::iterator i = contactIds->begin(); i != contactIds->end(); i++)
+               {
+                       string contactIdStr = *i;
+
+                       Try
+                       {
+                               int contactId;
+
+                               if(!ContactUtility::checkStrIsUInt(contactIdStr))
+                                       ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
+
+                               contactId = ContactUtility::strToInt(contactIdStr);
+
+                               if(!m_isDefaultAddressBook)
+                               {
+                                       contacts_record_h contacts_record = NULL;
+                                       errorCode = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &contacts_record);
+                                       if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
+                                               ThrowMsg(PlatformException, "No contact id (id:" << contactId << ")");
+
+                                       int addressBookId = 0;
+                                       errorCode = contacts_record_get_int(contacts_record, _contacts_simple_contact.address_book_id, &addressBookId);
+                                       if(errorCode != CONTACTS_ERROR_NONE)
+                                               ThrowMsg(PlatformException, "Error while getting address book id");
+
+                                       if(addressBookId != m_id)
+                                               ThrowMsg(PlatformException, "Contact id (" << contactId << ") is not a member of this address book.");
+                               }
+
+                               ids[count] = contactId;
+                               tmpIds[count] = contactId;
+                               count++;
+                       }
+                       Catch(Exception)
+                       {
+                               ThrowMsg(NotFoundException, "Error during converting contact object");
+//                             LogError("Error during converting contact object : " << _rethrown_exception.GetMessage());
+//                             continue;
+                       }
+               }
+
+               contacts_filter_h filter = NULL;
+               contacts_query_h query = NULL;
+
+               errorCode = contacts_query_create(_contacts_simple_contact._uri, &query);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_query_create error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+               errorCode = contacts_filter_create( _contacts_simple_contact._uri, &filter );
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_query_create error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+               for(int i = 0; i < contactIds->size(); i++)
+               {
+                       errorCode = contacts_filter_add_int(filter, _contacts_simple_contact.id, CONTACTS_MATCH_EQUAL, tmpIds[i]);
+                       if(i == (contactIds->size() - 1))
+                               break;
+
+                       errorCode = contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "contacts_filter_add_operator error : " << errorCode << " (" << __FUNCTION__ << ")");
+               }
+
+               errorCode = contacts_query_set_filter(query, filter);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_query_set_filter error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+               int record_count = 0;
+               errorCode = contacts_db_get_count_with_query(query, &record_count);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_db_get_count_with_query error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+               if(filter != NULL)
+                       contacts_filter_destroy(filter);
+               if(query != NULL)
+                       contacts_query_destroy(query);
+
+               if(contactIds->size() != (unsigned int)record_count)
+                       ThrowMsg(InvalidArgumentException, "Ids' db count  : " << record_count << " (" << __FUNCTION__ << ")");
+
+               KeySharePtrPair *keyPair = new KeySharePtrPair();
+               keyPair->key = m_eventMapAcc;
+               keyPair->addressBook = this;
+               errorCode = contacts_db_delete_records_async(_contacts_contact._uri, ids, count, contactsRemoveBatchResultCallback, (void*)keyPair);
+               if(ids != NULL)
+               {
+                       delete [] ids;
+               }
+               if(tmpIds != NULL)
+               {
+                       delete [] tmpIds;
+               }
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       delete keyPair;
+                       ThrowMsg(PlatformException, "Error during add to list");
+               }
+
+               pair<long, EventAddressBookRemoveBatchPtr> keyEventPair(m_eventMapAcc, event);
+               m_removeBatchEventMap.insert(keyEventPair);
+
+               m_eventMapAcc++;
+
+               event->switchToManualAnswer();
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid contact id : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               return;
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during deleting contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       Catch (Exception)
+       {
+               LogError("Error during deleting contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookFindPtr &event)
+{
+       LogDebug("entered");
+
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h contacts_list = NULL;
+
+       ContactArrayPtr contacts = ContactArrayPtr(new ContactArray());
+
+       Try
+       {
+               ContactSearchEnginePtr searchEngine(new ContactSearchEngine());
+
+               if(!m_isDefaultAddressBook)
+                       searchEngine->setAddressBookId(m_id);
+
+               if(event->getFilterIsSet())
+               {
+                       FilterPtr filter = event->getFilter();
+
+                       FilterValidatorPtr validator = ContactFilterValidatorFactory::getContactFilterValidator();
+                       bool success = filter->validate(validator);
+
+                       if(!success)
+                               ThrowMsg(InvalidArgumentException, "Invalid filter arguments.");
+
+                       searchEngine->setCondition(filter);
+               }
+
+               if (event->getSortModeIsSet())
+               {
+                       searchEngine->setSortMode(event->getSortMode());
+               }
+               else
+                       searchEngine->setSortMode();
+
+               event->setContacts(searchEngine->getContactSearchResult());
+               event->setResult(true);
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               event->setResult(false);
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during finding contact : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               event->setResult(false);
+       }
+       Catch (Exception)
+       {
+               LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+       }
+
+       if(filter != NULL)
+               contacts_filter_destroy(filter);
+
+       if(query != NULL)
+               contacts_query_destroy(query);
+
+       if(contacts_list != NULL)
+               contacts_list_destroy(contacts_list, true);
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookAddChangeListenerPtr &event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               if(!event->getEmitterIsSet())
+                       ThrowMsg(InvalidArgumentException, "Invalid arguments.");
+
+               EventAddressBookChangeListenerEmitterPtr emitter = event->getEmitter();
+               if(emitter == NULL)
+                       ThrowMsg(InvalidArgumentException, "Invalid arguments.");
+
+               if(m_addressBookEmitters.size() == 0)
+               {
+                       LogDebug("Watch registered initially");
+
+                       if(m_isDefaultAddressBook)
+                               ContactsSvcChangeListenerManagerSingleton::Instance().registerContactsChangeListener(this, -1);
+                       else
+                               ContactsSvcChangeListenerManagerSingleton::Instance().registerContactsChangeListener(this, m_id);
+               }
+
+               m_addressBookEmitters.attach(emitter);
+
+               long id = ContactsSvcChangeListenerManagerSingleton::Instance().getWatchIdAndInc();
+               m_watchIdMap[id] = emitter->getId();
+
+           event->setId(id);
+               event->setResult(true);
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               event->setResult(false);
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               event->setResult(false);
+       }
+       Catch (Exception)
+       {
+               LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+       }
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookRemoveChangeListenerPtr &event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               if(!event->getIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "Invalid arguments.");
+
+               long id = event->getId();
+               if(m_watchIdMap.find(id) == m_watchIdMap.end())
+                       ThrowMsg(NotFoundException, "No watchId : " << id);
+
+               bool success = m_addressBookEmitters.detach(m_watchIdMap[id]);
+               if(!success)
+                       ThrowMsg(NotFoundException, "No watchId : " << id);
+
+               m_watchIdMap.erase(id);
+
+               if(m_addressBookEmitters.size() == 0)
+               {
+                       LogDebug("No watcher is registered. unsubscribing from contact service.");
+
+                       ContactsSvcChangeListenerManagerSingleton::Instance().unregisterContactsChangeListener(this);
+               }
+
+               event->setResult(true);
+
+       }
+       Catch (NotFoundException)
+       {
+               LogError("WatchId doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               event->setResult(false);
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               event->setResult(false);
+       }
+       Catch (Exception)
+       {
+               LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+       }
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookGetGroupPtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+       contacts_record_h contacts_record = NULL;
+
+       Try
+       {
+               if(!event->getIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "Invalid group id");
+
+               string groupId = event->getId();
+
+               int groupIdInt = ContactUtility::strToInt(groupId);
+
+               errorCode = contacts_db_get_record(_contacts_group._uri, groupIdInt, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
+                       ThrowMsg(NotFoundException, "No group (id:" << groupIdInt << ")");
+
+               if(!m_isDefaultAddressBook)
+               {
+                       int addressBookId = 0;
+                       contacts_record_get_int(contacts_record, _contacts_group.address_book_id, &addressBookId);
+                       if(addressBookId != m_id)
+                               ThrowMsg(NotFoundException, "No group (id:" << groupIdInt << ") in this address book.");
+               }
+
+               ContactGroupPtr group = ContactGroupPtr(new ContactGroup());
+
+               ContactsSvcObjectConverter::convertToAbstract(contacts_record, group);
+
+               event->setContactGroup(group);
+               event->setResult(true);
+
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               event->setResult(false);
+
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during getting contact : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               event->setResult(false);
+
+       }
+       Catch(Exception)
+       {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::UnknownException);
+               event->setResult(false);
+       }
+
+       if(contacts_record != NULL)
+               contacts_record_destroy(contacts_record, true);
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookAddGroupPtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+
+       contacts_record_h contacts_record = NULL;
+       ContactGroupPtr group(NULL);
+
+       Try
+       {
+               if(!event->getContactGroupIsSet())
+                       ThrowMsg(InvalidArgumentException, "group were not set.");
+
+               group = event->getContactGroup();
+               if(!group)
+                       ThrowMsg(InvalidArgumentException, "No group.");
+
+               if(group->getIdIsSet() || group->getAddressBookIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "ContactGroup object is wrong");
+       }
+       Catch(InvalidArgumentException)
+       {
+               LogError("Invalid arguments for adding contacts : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+
+       Try
+       {
+               errorCode = contacts_record_create(_contacts_group._uri, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogError("error code : " << errorCode);
+                       ThrowMsg(PlatformException, "Error during executing contacts_record_create()");
+               }
+
+               if(m_isDefaultAddressBook)
+                       errorCode = contacts_record_set_int(contacts_record, _contacts_group.address_book_id, 0);
+               else
+                       errorCode = contacts_record_set_int(contacts_record, _contacts_group.address_book_id, m_id);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogError("error code : " << errorCode);
+                       ThrowMsg(PlatformException, "Error during executing contacts_record_set_int()");
+               }
+
+               ContactsSvcObjectConverter::convertToPlatform(group, contacts_record);
+
+               int groupId = 0;
+               errorCode = contacts_db_insert_record(contacts_record, &groupId);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogError("error code : " << errorCode);
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_insert_record()");
+               }
+               group->setId(groupId);
+               group->setAddressBookId(m_id);
+
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+       Catch (Exception)
+       {
+               LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::UnknownException);
+       }
+
+       if(contacts_record != NULL)
+               contacts_record_destroy(contacts_record, true);
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookUpdateGroupPtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+
+       contacts_record_h contacts_record = NULL;
+       ContactGroupPtr group(NULL);
+
+       Try
+       {
+               if(!event->getContactGroupIsSet())
+                       ThrowMsg(InvalidArgumentException, "group were not set.");
+
+               group = event->getContactGroup();
+               if(!group)
+                       ThrowMsg(InvalidArgumentException, "No group.");
+
+               if(!group->getIdIsSet() || !group->getAddressBookIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "Contact Group is wrong");
+
+               if(!m_isDefaultAddressBook && group->getAddressBookId() != getId())
+                       ThrowMsg(InvalidArgumentException, "Wrong address book ID");
+       }
+       Catch(InvalidArgumentException)
+       {
+               LogError("Invalid arguments for updating group : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+
+       if(group->getReadOnly())
+       {
+               LogWarning("Canceling updating readonly data.");
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+
+       Try
+       {
+               int id = ContactUtility::strToInt(group->getId());
+               LogDebug("Load platform object id : " << id);
+               errorCode = contacts_db_get_record(_contacts_group._uri, id, &contacts_record);
+               if (errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
+                       ThrowMsg(NotFoundException, "Error during executing contacts_db_get_record()");
+               else if (errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogError("error code : " << errorCode);
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_get_record()");
+               }
+
+               LogDebug("Update group : " << id);
+               ContactsSvcObjectConverter::convertToPlatform(group, contacts_record);
+
+               errorCode = contacts_db_update_record(contacts_record);
+               if (errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
+                       ThrowMsg(NotFoundException, "Error during executing contacts_db_update_record()");
+               else if (errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogError("error code : " << errorCode);
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_update_record()");
+               }
+
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+       Catch (Exception)
+       {
+               LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+
+       if(contacts_record != NULL)
+               contacts_record_destroy(contacts_record, true);
+
+       return;
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookRemoveGroupPtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+       Try
+       {
+               if(!event->getContactGroupIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "group were not set.");
+
+               string groupIdStr = event->getContactGroupId();
+
+               if(!ContactUtility::checkStrIsUInt(groupIdStr))
+                       ThrowMsg(InvalidArgumentException, "Id is wrong (" << groupIdStr << ")" );
+
+               int groupId = ContactUtility::strToInt(groupIdStr);
+
+               if(!m_isDefaultAddressBook)
+               {
+                       contacts_record_h contacts_record = NULL;
+                       errorCode = contacts_db_get_record(_contacts_group._uri, groupId, &contacts_record);
+                       if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
+                               ThrowMsg(PlatformException, "No group id (id:" << groupId << ")");
+
+                       int addressBookId = 0;
+                       errorCode = contacts_record_get_int(contacts_record, _contacts_group.address_book_id, &addressBookId);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "Error while getting address book id");
+
+                       if(addressBookId != m_id)
+                               ThrowMsg(PlatformException, "Contact id (" << groupId << ") is not a member of this address book.");
+               }
+
+               errorCode = contacts_db_delete_record(_contacts_group._uri, groupId);
+               if(errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
+                       ThrowMsg(NotFoundException, "Error during executing contacts_db_delete_record()");
+               else if (errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_delete_record()");
+
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid group id : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Group doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during removing group : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+       Catch (Exception)
+       {
+               LogError("Error during removing group : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+}
+
+void AddressBook::OnRequestReceived(const EventAddressBookGetGroupsPtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+
+       ContactGroupArrayPtr groups(new ContactGroupArray());
+       contacts_list_h groups_list = NULL;
+
+       Try
+       {
+
+               if(m_isDefaultAddressBook)
+               {
+                       errorCode = contacts_db_get_all_records(_contacts_group._uri, 0, 0, &groups_list);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "Fail to get group list (ret:" << errorCode << ")");
+               }
+               else
+               {
+                       contacts_query_h query = NULL;
+                       contacts_filter_h filter = NULL;
+
+                       errorCode = contacts_query_create(_contacts_group._uri, &query);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "Fail to get contacts_query_create (ret:" << errorCode << ")");
+
+                       errorCode = contacts_filter_create(_contacts_group._uri, &filter);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "Fail to get contacts_filter_create (ret:" << errorCode << ")");
+
+                       errorCode = contacts_filter_add_int(filter, _contacts_group.address_book_id, CONTACTS_MATCH_EQUAL, m_id);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "Fail to get contacts_filter_add_int (ret:" << errorCode << ")");
+
+                       errorCode = contacts_query_set_filter(query, filter);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "Fail to get contacts_query_set_filter (ret:" << errorCode << ")");
+
+                       errorCode = contacts_db_get_records_with_query(query, 0, 0, &groups_list);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "Fail to get contacts_db_get_records_with_query (ret:" << errorCode << ")");
+
+                       errorCode = contacts_filter_destroy(filter);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "Fail to get contacts_filter_destroy (ret:" << errorCode << ")");
+
+                       errorCode = contacts_query_destroy(query);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "Fail to get contacts_query_destroy (ret:" << errorCode << ")");
+               }
+
+               unsigned int record_count = 0;
+               errorCode = contacts_list_get_count(groups_list, &record_count);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Fail to get contacts_list_get_count (ret:" << errorCode << ")");
+
+               contacts_list_first(groups_list);
+               for(unsigned int i=0; i<record_count; i++)
+               {
+                       contacts_record_h contacts_record;
+                       errorCode = contacts_list_get_current_record_p(groups_list, &contacts_record);
+                       if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
+                       {
+                               LogWarning("Fail to get group record (ret:" << errorCode << ")");
+                               continue;
+                       }
+
+                       int id = 0;
+                       int addressBookId = 0;
+                       char *name = NULL;
+                       char *ringtoneURI = NULL;
+                       char *photoURI = NULL;
+                       bool isReadOnly = false;
+
+                       errorCode = contacts_record_get_int(contacts_record, _contacts_group.id, &id);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to get id from address book (ret:" << errorCode << ")");
+                               continue;
+                       }
+
+                       errorCode = contacts_record_get_int(contacts_record, _contacts_group.address_book_id, &addressBookId);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to get address book id from address book (ret:" << errorCode << ")");
+                               continue;
+                       }
+
+                       errorCode = contacts_record_get_str_p(contacts_record, _contacts_group.name, &name);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to get name from address book (ret:" << errorCode << ")");
+                               continue;
+                       }
+
+                       errorCode = contacts_record_get_str_p(contacts_record, _contacts_group.image_path, &photoURI);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to get image_path from address book (ret:" << errorCode << ")");
+                               continue;
+                       }
+
+                       errorCode = contacts_record_get_str_p(contacts_record, _contacts_group.ringtone_path, &ringtoneURI);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to get ringtone_path from address book (ret:" << errorCode << ")");
+                               continue;
+                       }
+
+                       errorCode = contacts_record_get_bool(contacts_record, _contacts_group.is_read_only, &isReadOnly);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to get is_read_only from address book (ret:" << errorCode << ")");
+                               continue;
+                       }
+
+                       ContactGroupPtr group = ContactGroupPtr(new ContactGroup());
+                       group->setId(id);
+                       group->setAddressBookId(addressBookId);
+
+                       if(name != NULL)
+                               group->setName(name);
+                       else
+                               group->setName("");
+
+                       if(photoURI != NULL)
+                               group->setPhotoURI(ContactUtility::convertPathToUri(photoURI));
+
+                       if(ringtoneURI != NULL)
+                               group->setRingtoneURI(ContactUtility::convertPathToUri(ringtoneURI));
+
+                       group->setReadOnly(isReadOnly);
+
+                       groups->push_back(group);
+
+                       errorCode = contacts_list_next(groups_list);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to get next address book (ret:" << errorCode << ")");
+                               break;
+                       }
+               }
+
+               event->setContactGroups(groups);
+               event->setResult(true);
+
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               event->setResult(false);
+
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during getting contact : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               event->setResult(false);
+
+       }
+       Catch(Exception)
+       {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::UnknownException);
+               event->setResult(false);
+       }
+
+       if(groups_list != NULL)
+               contacts_list_destroy(groups_list, true);
+}
+
+void AddressBook::onContactsSvcContactsAdded(TizenApis::Api::Contact::ContactArrayPtr &contacts)
+{
+       EventInfoAddressBookChangeAddedPtr contactsAdded(new EventInfoAddressBookChangeAdded());
+       contactsAdded->setContacts(contacts);
+       EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsAdded);
+       EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
+       m_addressBookEmitters.emit(listener);
+}
+
+void AddressBook::onContactsSvcContactsUpdated(TizenApis::Api::Contact::ContactArrayPtr &contacts)
+{
+       EventInfoAddressBookChangeUpdatedPtr contactsUpdated(new EventInfoAddressBookChangeUpdated());
+       contactsUpdated->setContacts(contacts);
+       EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsUpdated);
+       EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
+       m_addressBookEmitters.emit(listener);
+}
+
+void AddressBook::onContactsSvcContactsRemoved(TizenApis::Api::Contact::StringArrayPtr &contactIds)
+{
+       EventInfoAddressBookChangeRemovedPtr contactsRemoved(new EventInfoAddressBookChangeRemoved());
+       contactsRemoved->setContactIds(contactIds);
+       EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsRemoved);
+       EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
+       m_addressBookEmitters.emit(listener);
+}
+
+void AddressBook::contactsAddBatchResultCallback(int error, int *ids, unsigned int count, void *user_data)
+{
+       LogDebug("entered");
+
+       if(user_data == NULL)
+       {
+               LogError("user_data is NULL");
+               return;
+       }
+
+       KeySharePtrPair *keyPair = (KeySharePtrPair*)user_data;
+
+       long key = keyPair->key;
+       AddressBook *addressBook = keyPair->addressBook;
+
+       delete keyPair;
+
+       addressBook->contactsAddBatchResultCallback(error, ids, count, key);
+}
+
+void AddressBook::contactsAddBatchResultCallback(int error, int *ids, unsigned int count, long key)
+{
+       EventAddressBookAddBatchPtr event;
+
+       EventAddressBookAddBatchMap::iterator iter;
+       iter = m_addBatchEventMap.find(key);
+       if(iter == m_addBatchEventMap.end())
+       {
+               LogError("No event for key : " << key);
+               return;
+       }
+
+       event = iter->second;
+       m_addBatchEventMap.erase(iter);
+
+       if(error != CONTACTS_ERROR_NONE)
+       {
+               LogError("contacts_db_insert_result_cb gives error : " << error);
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               EventRequestReceiver<EventAddressBookAddBatch>::ManualAnswer(event);
+               return;
+       }
+
+#if 0
+       ContactArrayPtr contacts(new ContactArray());
+#else
+       ContactArrayPtr contacts = event->getContacts();
+#endif
+
+       for(unsigned int i=0; i<count; i++)
+       {
+               int errorCode = 0;
+               int contactId = ids[i];
+               LogDebug("contact id : " << contactId);
+
+               contacts_record_h contacts_record = NULL;
+
+               errorCode = contacts_db_get_record(_contacts_contact._uri, contactId, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogDebug("Fail contacts_db_get_record error _contacts_contact._uri : " << errorCode);
+                       continue;
+               }
+
+#if 0
+               ContactPtr absContact(NULL);
+#else
+               ContactPtr absContact = contacts->at(i);
+#endif
+
+               Try
+               {
+#if 0
+                       ContactObjectP2AConverterPtr contactObjConverter(
+                                       new ContactObjectP2AConverter(contacts_record, false) );
+#else
+                       ContactObjectP2AConverterPtr contactObjConverter(
+                                       new ContactObjectP2AConverter(contacts_record, false, absContact) );
+#endif
+                       absContact = contactObjConverter->getAbstractContact();
+               }
+               Catch(Exception)
+               {
+                       LogError("Fail error on converting contact to abs contact : " << _rethrown_exception.GetMessage());
+                       continue;
+               }
+
+#if 0
+               if(absContact != NULL)
+                       contacts->push_back(absContact);
+#endif
+
+               if(contacts_record != NULL)
+                       contacts_record_destroy(contacts_record, true);
+       }
+
+       event->setContacts(contacts);
+       event->setResult(true);
+       event->setExceptionCode(ExceptionCodes::None);
+       EventRequestReceiver<EventAddressBookAddBatch>::ManualAnswer(event);
+}
+
+void AddressBook::contactsUpdateBatchResultCallback(int error, void *user_data)
+{
+       LogDebug("entered");
+
+       if(user_data == NULL)
+       {
+               LogError("user_data is NULL");
+               return;
+       }
+
+       KeySharePtrPair *keyPair = (KeySharePtrPair*)user_data;
+
+       long key = keyPair->key;
+       AddressBook *addressBook = keyPair->addressBook;
+
+       delete keyPair;
+
+       addressBook->contactsUpdateBatchResultCallback(error, key);
+}
+
+void AddressBook::contactsUpdateBatchResultCallback(int error, long key)
+{
+       EventAddressBookUpdateBatchPtr event;
+
+       EventAddressBookUpdateBatchMap::iterator iter;
+       iter = m_updateBatchEventMap.find(key);
+       if(iter == m_updateBatchEventMap.end())
+       {
+               LogError("No event for key : " << key);
+               return;
+       }
+
+       event = iter->second;
+       m_updateBatchEventMap.erase(iter);
+
+       if(error != CONTACTS_ERROR_NONE)
+       {
+               LogError("contacts_db_result_cb gives error : " << error);
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               EventRequestReceiver<EventAddressBookUpdateBatch>::ManualAnswer(event);
+               return;
+       }
+
+       event->setResult(true);
+       event->setExceptionCode(ExceptionCodes::None);
+       EventRequestReceiver<EventAddressBookUpdateBatch>::ManualAnswer(event);
+}
+
+void AddressBook::contactsRemoveBatchResultCallback(int error, void *user_data)
+{
+       LogDebug("entered");
+
+       if(user_data == NULL)
+       {
+               LogError("user_data is NULL");
+               return;
+       }
+
+       KeySharePtrPair *keyPair = (KeySharePtrPair*)user_data;
+
+       long key = keyPair->key;
+       AddressBook *addressBook = keyPair->addressBook;
+
+       delete keyPair;
+
+       addressBook->contactsRemoveBatchResultCallback(error, key);
+}
+
+void AddressBook::contactsRemoveBatchResultCallback(int error, long key)
+{
+       EventAddressBookRemoveBatchPtr event;
+
+       EventAddressBookRemoveBatchMap::iterator iter;
+       iter = m_removeBatchEventMap.find(key);
+       if(iter == m_removeBatchEventMap.end())
+       {
+               LogError("No event for key : " << key);
+               return;
+       }
+
+       event = iter->second;
+       m_removeBatchEventMap.erase(iter);
+
+       if(error != CONTACTS_ERROR_NONE)
+       {
+               LogError("contacts_db_result_cb gives error : " << error);
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               EventRequestReceiver<EventAddressBookRemoveBatch>::ManualAnswer(event);
+               return;
+       }
+
+       event->setResult(true);
+       event->setExceptionCode(ExceptionCodes::None);
+       EventRequestReceiver<EventAddressBookRemoveBatch>::ManualAnswer(event);
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/AddressBook.h b/src/platform/Tizen/Contact/AddressBook.h
new file mode 100755 (executable)
index 0000000..bfd0cca
--- /dev/null
@@ -0,0 +1,170 @@
+//
+// 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        AddressBook.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _PLATFORM_CONTACT_ADDRESS_BOOK_H_
+#define _PLATFORM_CONTACT_ADDRESS_BOOK_H_
+
+#include <string>
+#include <vector>
+#include <Commons/Emitters.h>
+#include <API/Contact/IAddressBook.h>
+#include <API/Contact/IContact.h>
+
+#include "ContactsSvcChangeListenerManager.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class AddressBook : public TizenApis::Api::Contact::IAddressBook, public IContactsSvcContactsChangeListener
+{
+private:
+       int             m_id;
+       std::string     m_name;
+       bool            m_readOnly;
+       int             m_accountId;
+
+       bool            m_isDefaultAddressBook;
+
+public:
+       explicit AddressBook(bool isDefault);
+       virtual ~AddressBook();
+
+       virtual std::string getId() const;
+       virtual void        setId(const std::string &value);
+       void                setId(const int &value) { m_id = value; }
+       virtual std::string getName() const { return m_name; }
+       virtual void            setName(const std::string &value) { m_name = value; }
+       virtual bool        getReadOnly() const { return m_readOnly; }
+       virtual void        setReadOnly(const bool &value) { m_readOnly = value; }
+       virtual std::string getAccountId() const;
+       virtual void        setAccountId(const std::string &value);
+       void                setAccountId(const int &value) { m_accountId = value; }
+
+       virtual void get(const TizenApis::Api::Contact::EventAddressBookGetPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+       virtual void add(const TizenApis::Api::Contact::EventAddressBookAddPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+       virtual void update(const TizenApis::Api::Contact::EventAddressBookUpdatePtr &event)
+       {
+               OnRequestReceived(event);
+       }
+       virtual void remove(const TizenApis::Api::Contact::EventAddressBookRemovePtr &event)
+       {
+               OnRequestReceived(event);
+       }
+       virtual void addChangeListener(const TizenApis::Api::Contact::EventAddressBookAddChangeListenerPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+       virtual void removeChangeListener(const TizenApis::Api::Contact::EventAddressBookRemoveChangeListenerPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+       virtual void getGroup(const TizenApis::Api::Contact::EventAddressBookGetGroupPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+       virtual void addGroup(const TizenApis::Api::Contact::EventAddressBookAddGroupPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+       virtual void updateGroup(const TizenApis::Api::Contact::EventAddressBookUpdateGroupPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+       virtual void removeGroup(const TizenApis::Api::Contact::EventAddressBookRemoveGroupPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+       virtual void getGroups(const TizenApis::Api::Contact::EventAddressBookGetGroupsPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+
+
+protected:
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookGetPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookAddPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookAddBatchPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookUpdatePtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookUpdateBatchPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookRemovePtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookRemoveBatchPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookFindPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookAddChangeListenerPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookRemoveChangeListenerPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookGetGroupPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookAddGroupPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookUpdateGroupPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookRemoveGroupPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookGetGroupsPtr &event);
+
+       virtual void onContactsSvcContactsAdded(TizenApis::Api::Contact::ContactArrayPtr &contacts);
+       virtual void onContactsSvcContactsUpdated(TizenApis::Api::Contact::ContactArrayPtr &contacts);
+       virtual void onContactsSvcContactsRemoved(TizenApis::Api::Contact::StringArrayPtr &contactIds);
+
+private:
+       typedef WrtDeviceApis::Commons::Emitters<TizenApis::Api::Contact::EventAddressBookChangeListenerEmitter> AddressBookChangedEmitter;
+       AddressBookChangedEmitter       m_addressBookEmitters;
+
+       typedef std::map<long, TizenApis::Api::Contact::EventAddressBookChangeListenerEmitter::IdType> WatchIdMap;
+       WatchIdMap m_watchIdMap;
+
+       static void contactsAddBatchResultCallback(int error, int *ids, unsigned int count, void *user_data);
+       void contactsAddBatchResultCallback(int error, int *ids, unsigned int count, long key);
+
+       static void contactsUpdateBatchResultCallback(int error, void *user_data);
+       void contactsUpdateBatchResultCallback(int error, long key);
+
+       static void contactsRemoveBatchResultCallback(int error, void *user_data);
+       void contactsRemoveBatchResultCallback(int error, long key);
+
+       struct KeySharePtrPair
+       {
+               long key;
+               AddressBook *addressBook;
+       };
+
+       typedef std::map<long, TizenApis::Api::Contact::EventAddressBookAddBatchPtr> EventAddressBookAddBatchMap;
+       EventAddressBookAddBatchMap m_addBatchEventMap;
+
+       typedef std::map<long, TizenApis::Api::Contact::EventAddressBookUpdateBatchPtr> EventAddressBookUpdateBatchMap;
+       EventAddressBookUpdateBatchMap m_updateBatchEventMap;
+
+       typedef std::map<long, TizenApis::Api::Contact::EventAddressBookRemoveBatchPtr> EventAddressBookRemoveBatchMap;
+       EventAddressBookRemoveBatchMap m_removeBatchEventMap;
+
+       long m_eventMapAcc;
+};
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_ADDRESS_BOOK_H_
diff --git a/src/platform/Tizen/Contact/Contact.cpp b/src/platform/Tizen/Contact/Contact.cpp
new file mode 100755 (executable)
index 0000000..9dfabe6
--- /dev/null
@@ -0,0 +1,131 @@
+//
+// 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        Contact.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "Contact.h"
+
+#include <dpl/log/log.h>
+#include <dpl/exception.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+#include "ContactObjectA2PConverter.h"
+#include "ContactObjectP2AConverter.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+Contact::Contact()
+       : IContact()
+       , m_platformContactObject(NULL)
+       , m_platformContactObjectList(NULL)
+{
+//     LogDebug("entered");
+}
+
+Contact::~Contact()
+{
+       if (m_platformContactObjectList != NULL)
+               contacts_list_destroy(m_platformContactObjectList, true);
+}
+
+string Contact::convertToString(const string &format)
+{
+       LogDebug("entered");
+       int errorCode = 0;
+       char *vcard_stream = NULL;
+
+       if(!format.empty() && format != "VCARD_30")
+               ThrowMsg(ConversionException, "format must be 'VCARD_30'");
+
+       ContactPtr thisObj = SharedFromThis();
+       ContactObjectA2PConverterPtr contactObjConverter(NULL);
+
+       contacts_record_h contacts_record = NULL;
+       Try {
+               contactObjConverter = ContactObjectA2PConverterPtr(new ContactObjectA2PConverter(thisObj, true) );
+               contacts_record = contactObjConverter->getPlatformContact();
+       } Catch (Exception) {
+               ThrowMsg(PlatformException, "Fail to extract contact to platform object.");
+       }
+       errorCode = contacts_vcard_make_from_contact(contacts_record, &vcard_stream);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "Fail to convert to vCard.");
+
+       string result((char *)vcard_stream);
+
+       free(vcard_stream);
+
+       return result;
+}
+
+void Contact::setContactFromString(const std::string &vObjectStr)
+{
+       LogDebug("entered");
+       int errorCode = 0;
+       const char *vcard_stream = vObjectStr.c_str();
+
+       contacts_list_h contacts_list = NULL;
+       errorCode = contacts_vcard_parse_to_contacts(vcard_stream, &contacts_list);
+       if(errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
+               ThrowMsg(InvalidArgumentException, "Invalid vCard string.");
+       else if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "Fail to convert contact from vCard.");
+
+       unsigned int record_count = 0;
+       errorCode = contacts_list_get_count(contacts_list, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE || record_count == 0)
+       {
+               contacts_list_destroy(contacts_list, true);
+               ThrowMsg(InvalidArgumentException, "Invalid vCard string. (2)");
+       }
+
+       contacts_record_h contacts_record;
+       contacts_list_first(contacts_list);
+       errorCode = contacts_list_get_current_record_p(contacts_list, &contacts_record);
+       if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
+       {
+               contacts_list_destroy(contacts_list, true);
+               ThrowMsg(InvalidArgumentException, "Invalid vCard string. (3)");
+       }
+
+       ContactObjectP2AConverterPtr contactObjConverter(NULL);
+       Try {
+               ContactPtr thisObj = SharedFromThis();
+               contactObjConverter = ContactObjectP2AConverterPtr(new ContactObjectP2AConverter(contacts_record, true, thisObj) );
+               contactObjConverter->getAbstractContact();
+       } Catch (Exception) {
+               ThrowMsg(PlatformException, "Fail to extract contact from platform object.");
+       }
+
+       m_platformContactObject = contacts_record;
+       m_platformContactObjectList = contacts_list;
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/Contact.h b/src/platform/Tizen/Contact/Contact.h
new file mode 100755 (executable)
index 0000000..a19cefc
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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        Contact.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _PLATFORM_CONTACT_CONTACT_H_
+#define _PLATFORM_CONTACT_CONTACT_H_
+
+#include <string>
+#include <vector>
+#include <contacts.h>
+#include <API/Contact/IContact.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class Contact : public TizenApis::Api::Contact::IContact
+{
+public:
+       Contact();
+       virtual ~Contact();
+
+       virtual std::string convertToString(const std::string &format);
+
+       virtual void setContactFromString(const std::string &vObjectStr);
+
+       contacts_record_h getPlatformContactObject() const { return m_platformContactObject; };
+
+private:
+       contacts_record_h m_platformContactObject;
+       contacts_list_h m_platformContactObjectList;
+};
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_CONTACT_H_
diff --git a/src/platform/Tizen/Contact/ContactFilterValidator.cpp b/src/platform/Tizen/Contact/ContactFilterValidator.cpp
new file mode 100755 (executable)
index 0000000..3b41ac5
--- /dev/null
@@ -0,0 +1,89 @@
+//
+// 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        ContactFilterValidator.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactFilterValidator.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Tizen;
+
+static PropertyStructArray properties =
+{
+               {"id",                      PrimitiveType_String},
+               {"personId",                PrimitiveType_String},
+               {"addressBookId",           PrimitiveType_String},
+               {"lastUpdated",             PrimitiveType_Time},
+               {"isFavorite",              PrimitiveType_Boolean},
+               {"name.prefix",             PrimitiveType_String},
+               {"name.suffix",             PrimitiveType_String},
+               {"name.firstName",          PrimitiveType_String},
+               {"name.middleName",         PrimitiveType_String},
+               {"name.lastName",           PrimitiveType_String},
+               {"name.nicknames",          PrimitiveType_String},
+               {"name.phoneticFirstName",  PrimitiveType_String},
+               {"name.phoneticLastName",   PrimitiveType_String},
+               {"name.displayName",        PrimitiveType_String},
+               {"addresses.country",       PrimitiveType_String},
+               {"addresses.region",        PrimitiveType_String},
+               {"addresses.city",          PrimitiveType_String},
+               {"addresses.streetAddress", PrimitiveType_String},
+               {"addresses.additionalInformation",     PrimitiveType_String},
+               {"addresses.postalCode",    PrimitiveType_String},
+               {"addresses.isDefault",     PrimitiveType_Boolean},
+               {"addresses.types",         PrimitiveType_String},
+               {"photoURI",                PrimitiveType_String},
+               {"phoneNumbers.number",     PrimitiveType_String},
+               {"phoneNumbers.isDefault",  PrimitiveType_Boolean},
+               {"phoneNumbers.types",      PrimitiveType_String},
+               {"emails.email",            PrimitiveType_String},
+               {"emails.isDefault",        PrimitiveType_Boolean},
+               {"emails.types",            PrimitiveType_String},
+               {"birthday",                PrimitiveType_Time},
+               {"anniversaries.date",      PrimitiveType_Time},
+               {"anniversaries.label",     PrimitiveType_String},
+               {"organizations.name",      PrimitiveType_String},
+               {"organizations.department",PrimitiveType_String},
+               {"organizations.title",     PrimitiveType_String},
+               {"organizations.role",      PrimitiveType_String},
+               {"organizations.logoURI",   PrimitiveType_String},
+               {"notes",                   PrimitiveType_String},
+               {"urls.url",                            PrimitiveType_String},
+               {"urls.type",                           PrimitiveType_String},
+               {"ringtoneURI",                         PrimitiveType_String},
+               {"groupIds",                            PrimitiveType_String},
+               {0,     PrimitiveType_NoType}
+};
+
+FilterValidatorPtr ContactFilterValidatorFactory::getContactFilterValidator()
+{
+    static FilterValidatorPtr theInstance =
+               FilterValidatorPtr(new FilterValidator(properties));
+    return theInstance;
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactFilterValidator.h b/src/platform/Tizen/Contact/ContactFilterValidator.h
new file mode 100755 (executable)
index 0000000..ef8028f
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// 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        ContactFilterValidator.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _PLATFORM_CONTACT_CONTACT_FILTER_VALIDATOR_H_
+#define _PLATFORM_CONTACT_CONTACT_FILTER_VALIDATOR_H_
+
+#include <API/Filter/FilterValidator.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class ContactFilterValidatorFactory : private DPL::Noncopyable
+{
+private:
+       ContactFilterValidatorFactory()
+       {
+       }
+
+public:
+       static TizenApis::Api::Tizen::FilterValidatorPtr        getContactFilterValidator();
+};
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_CONTACT_FILTER_VALIDATOR_H_
diff --git a/src/platform/Tizen/Contact/ContactImpl.h b/src/platform/Tizen/Contact/ContactImpl.h
new file mode 100755 (executable)
index 0000000..85d32d1
--- /dev/null
@@ -0,0 +1,33 @@
+//
+// 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        ContactImpl.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _PLATFORM_CONTACT_CONTACT_IMPL_H_
+#define _PLATFORM_CONTACT_CONTACT_IMPL_H_
+
+#include "ContactManager.h"
+#include "AddressBook.h"
+#include "Contact.h"
+#include "Person.h"
+
+#endif // _PLATFORM_CONTACT_CONTACT_IMPL_H_
diff --git a/src/platform/Tizen/Contact/ContactManager.cpp b/src/platform/Tizen/Contact/ContactManager.cpp
new file mode 100755 (executable)
index 0000000..c93ea4c
--- /dev/null
@@ -0,0 +1,860 @@
+//
+// 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        ContactManager.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactManager.h"
+
+#include <contacts.h>
+#include <string>
+#include <dpl/log/log.h>
+#include <Commons/Regex.h>
+#include <API/Contact/ContactFactory.h>
+#include <API/Contact/IAddressBook.h>
+#include "ContactsSvcWrapper.h"
+#include "ContactsSvcObjectConverter.h"
+#include "ContactUtility.h"
+#include "PersonFilterValidator.h"
+#include "PersonSearchEngine.h"
+#include "Person.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace TizenApis::Api::Tizen;
+
+ContactManager::ContactManager() : m_eventMapAcc(0)
+{
+       ContactsSvcWrapperSingleton::Instance();
+}
+
+ContactManager::~ContactManager()
+{
+       if(m_contactManagerEmitters.size() != 0)
+       {
+               ContactsSvcChangeListenerManagerSingleton::Instance().unregisterPersonsChangeListener(this);
+       }
+}
+
+void ContactManager::OnRequestReceived(const EventContactManagerGetAddressBookPtr &event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               std::string addressBookId = event->getAddressBookId();
+               if(addressBookId.empty())
+               {
+                       //when database is not opened then set result as failed
+                       ThrowMsg(NotFoundException, "Address book id is empty");
+               }
+
+               AddressBookPtr addressBook =
+                               ContactsSvcWrapperSingleton::Instance().getAddressBook(addressBookId);
+
+               event->setAddressBook(addressBook);
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       Catch(PlatformException)
+       {
+               //when database is not opened then set result as failed
+               LogError("Contact DB not opened : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       Catch(NotFoundException)
+       {
+               //when database is not opened then set result as failed
+               LogError("Not found : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+       }
+       Catch(Exception)
+       {
+               LogError("Unknown exception : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::UnknownException);
+               return;
+       }
+}
+
+void ContactManager::OnRequestReceived(const EventContactManagerGetAddressBooksPtr &event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               AddressBookArrayPtr addressBookArray =
+                               ContactsSvcWrapperSingleton::Instance().getAddressBooks();
+
+               event->setAddressBooks(addressBookArray);
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       Catch (PlatformException)
+       {
+               //when database is not opened then set result as failed
+               LogError("Contact DB is not opened.");
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       Catch (Exception)
+       {
+               LogError("Unknown exception : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::UnknownException);
+               return;
+       }
+}
+
+void ContactManager::OnRequestReceived(const EventContactManagerGetDefaultAddressBookPtr &event)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               AddressBookPtr defaultAddressBook =
+                               ContactsSvcWrapperSingleton::Instance().getDefaultAddressBook();
+
+               event->setDefaultAddressBook(defaultAddressBook);
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       Catch (PlatformException)
+       {
+               //when database is not opened then set result as failed
+               LogError("Contact DB is not opened.");
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       Catch (Exception)
+       {
+               LogError("Unknown exception : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::UnknownException);
+               return;
+       }
+}
+
+void ContactManager::OnRequestReceived(const EventContactManagerGetPtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+       contacts_record_h contacts_record = NULL;
+
+       Try     {
+               if(!event->getIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "Invalid person id");
+
+               string personId = event->getId();
+
+               int personIdInt = ContactUtility::strToInt(personId);
+
+               errorCode = contacts_db_get_record(_contacts_person._uri, personIdInt, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(NotFoundException, "No person (id:" << personIdInt << ") : " << errorCode);
+               }
+               PersonPtr person = PersonPtr(new Person());
+
+               ContactsSvcObjectConverter::convertToAbstract(contacts_record, person);
+
+               event->setPerson(person);
+               event->setResult(true);
+
+       } Catch (NotFoundException) {
+               LogError("Person doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               event->setResult(false);
+
+       } Catch (PlatformException) {
+               LogError("Error during getting person : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+
+       } Catch (InvalidArgumentException) {
+               LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               event->setResult(false);
+
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::UnknownException);
+               event->setResult(false);
+       }
+
+       if(contacts_record != NULL)
+               contacts_record_destroy(contacts_record, true);
+}
+
+void ContactManager::OnRequestReceived(const EventContactManagerUpdatePtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+
+       contacts_record_h contacts_record = NULL;
+       PersonPtr person(NULL);
+
+       Try {
+               if(!event->getPersonIsSet())
+                       ThrowMsg(InvalidArgumentException, "Persons were not set.");
+
+               person = event->getPerson();
+               if(!person)
+                       ThrowMsg(InvalidArgumentException, "No persons.");
+
+               if(!person->getIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "Person object is wrong");
+
+       } Catch(InvalidArgumentException) {
+               LogError("Invalid arguments for updating persons : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+
+       Try
+       {
+               int id = ContactUtility::strToInt(person->getId());
+               LogDebug("Load platform object id : " << id);
+               errorCode = contacts_db_get_record(_contacts_person._uri, id, &contacts_record);
+               if (errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
+                       ThrowMsg(NotFoundException, "Error during executing contacts_db_get_record()");
+               else if (errorCode != CONTACTS_ERROR_NONE) {
+                       LogError("error code : " << errorCode);
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_get_record()");
+               }
+
+               ContactsSvcObjectConverter::convertToPlatform(person, contacts_record);
+
+               errorCode = contacts_db_update_record(contacts_record);
+               if (errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
+                       ThrowMsg(NotFoundException, "Error during executing contacts_db_update_record()");
+               else if (errorCode != CONTACTS_ERROR_NONE) {
+                       LogError("error code : " << errorCode);
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_update_record()");
+               }
+
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Person doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+       }
+       Catch (PlatformException) {
+               LogError("Error during updating person : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+       Catch (Exception) {
+               LogError("Error during display_contact_id person : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+
+       if(contacts_record != NULL)
+               contacts_record_destroy(contacts_record, true);
+
+       return;
+}
+
+void ContactManager::OnRequestReceived(const EventContactManagerUpdateBatchPtr &event)
+{
+       LogDebug("entered");
+       int errorCode = 0;
+       contacts_list_h contacts_list = NULL;
+       PersonArrayPtr persons(NULL);
+
+       Try
+       {
+               if(!event->getPersonsIsSet())
+                       ThrowMsg(InvalidArgumentException, "Persons were not set.");
+
+               persons = event->getPersons();
+               if(!persons)
+                       ThrowMsg(InvalidArgumentException, "No persons.");
+
+       }
+       Catch(InvalidArgumentException)
+       {
+               LogError("Invalid arguments for updating persons : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+
+       Try
+       {
+               errorCode = contacts_list_create(&contacts_list);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(PlatformException, "Fail to create contacts_list_h");
+               }
+
+               for(PersonArray::iterator i = persons->begin(); i != persons->end(); i++)
+               {
+                       contacts_record_h contacts_record = NULL;
+                       PersonPtr person = *i;
+
+                       Try
+                       {
+                               LogDebug("id : " << person->getId());
+                               int personIdInt = ContactUtility::strToInt(person->getId());
+                               errorCode = contacts_db_get_record(_contacts_person._uri, personIdInt, &contacts_record);
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       ThrowMsg(NotFoundException, "No person (id:" << personIdInt << ")");
+                               }
+
+                               ContactsSvcObjectConverter::convertToPlatform(person, contacts_record);
+
+                               errorCode = contacts_list_add(contacts_list, contacts_record);
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       ThrowMsg(PlatformException, "Error during add to list");
+                               }
+                       }
+                       Catch(Exception)
+                       {
+                               ThrowMsg(NotFoundException, "Error during converting contact object");
+//                             LogError("Error during converting person object : " << _rethrown_exception.GetMessage());
+//                             continue;
+                       }
+               }
+
+               KeySharePtrPair *keyPair = new KeySharePtrPair();
+               keyPair->key = m_eventMapAcc;
+               keyPair->contactManager = this;
+               errorCode = contacts_db_update_records_async(contacts_list, personsUpdateBatchResultCallback, (void*)keyPair);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       delete keyPair;
+                       ThrowMsg(PlatformException, "Error during contacts_db_update_records_async");
+               }
+
+               errorCode = contacts_list_destroy(contacts_list, true);
+               contacts_list = NULL;
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       delete keyPair;
+                       ThrowMsg(PlatformException, "Error during contacts_list_destroy");
+               }
+
+               pair<long, EventContactManagerUpdateBatchPtr> keyEventPair(m_eventMapAcc, event);
+               m_updateBatchEventMap.insert(keyEventPair);
+
+               m_eventMapAcc++;
+
+               event->switchToManualAnswer();
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Person doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during adding persons : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+       Catch (Exception)
+       {
+               LogError("Error during adding persons : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+
+       if(contacts_list != NULL)
+               contacts_list_destroy(contacts_list, false);
+}
+
+void ContactManager::OnRequestReceived(const EventContactManagerRemovePtr &event)
+{
+       LogDebug("entered");
+       int personId;
+
+       Try
+       {
+               if(!event->getPersonIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "Persons were not set.");
+
+               string personIdStr = event->getPersonId();
+
+               if(!validate("^[0-9]+$", personIdStr, VALIDATE_MATCH_CASELESS))
+                       ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+
+               try {
+                       istringstream iss(personIdStr);
+                       iss >> personId;
+               } catch (...) {
+                       ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+               }
+
+               int errorCode = contacts_db_delete_record(_contacts_person._uri, personId);
+               if(errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
+                       ThrowMsg(NotFoundException, "Error during executing contacts_db_delete_record()");
+               else if (errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_delete_record()");
+
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid person id : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Person doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               return;
+       }
+       Catch (PlatformException) {
+               LogError("Error during updating person : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       Catch (Exception) {
+               LogError("Error during updating person : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+}
+
+void ContactManager::OnRequestReceived(const EventContactManagerRemoveBatchPtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+       StringArrayPtr personIds(NULL);
+
+       Try
+       {
+               if(!event->getPersonIdsIsSet())
+                       ThrowMsg(InvalidArgumentException, "Person IDs were not set.");
+
+               personIds = event->getPersonIds();
+               if(!personIds)
+                       ThrowMsg(InvalidArgumentException, "No person IDs.");
+
+       }
+       Catch(InvalidArgumentException)
+       {
+               LogError("Invalid arguments for removing persons : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+
+       Try
+       {
+               int *ids = new int[personIds->size()];
+               int count = 0;
+
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(PlatformException, "Fail to create contacts_list_h");
+               }
+
+               for(StringArray::iterator i = personIds->begin(); i != personIds->end(); i++)
+               {
+                       string personIdStr = *i;
+
+                       Try
+                       {
+                               int personId;
+
+                               if(!validate("^[0-9]+$", personIdStr, VALIDATE_MATCH_CASELESS))
+                                       ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+
+                               try
+                               {
+                                       istringstream iss(personIdStr);
+                                       iss >> personId;
+                               }
+                               catch (...)
+                               {
+                                       ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+                               }
+
+                               ids[count] = personId;
+                               count++;
+                       }
+                       Catch(Exception)
+                       {
+                               ThrowMsg(NotFoundException, "Error during converting contact object");
+//                             LogError("Error during converting person object : " << _rethrown_exception.GetMessage());
+//                             continue;
+                       }
+               }
+
+               KeySharePtrPair *keyPair = new KeySharePtrPair();
+               keyPair->key = m_eventMapAcc;
+               keyPair->contactManager = this;
+               errorCode = contacts_db_delete_records_async(_contacts_person._uri, ids, count, personsRemoveBatchResultCallback, (void*)keyPair);
+
+               if(ids != NULL)
+               {
+                       delete [] ids;
+               }
+
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       delete keyPair;
+                       ThrowMsg(PlatformException, "Error during add to list");
+               }
+
+               pair<long, EventContactManagerRemoveBatchPtr> keyEventPair(m_eventMapAcc, event);
+               m_removeBatchEventMap.insert(keyEventPair);
+
+               m_eventMapAcc++;
+
+               event->switchToManualAnswer();
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid person id : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Person doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               return;
+       }
+       Catch (PlatformException)
+       {
+               LogError("Error during removing person : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       Catch (Exception)
+       {
+               LogError("Error during removing person : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+}
+
+void ContactManager::OnRequestReceived(const EventContactManagerFindPtr &event)
+{
+       LogDebug("entered");
+
+       Try     {
+               PersonSearchEnginePtr searchEngine(new PersonSearchEngine());
+
+               if(event->getFilterIsSet())
+               {
+                       FilterPtr filter = event->getFilter();
+
+                       FilterValidatorPtr validator = PersonFilterValidatorFactory::getPersonFilterValidator();
+                       bool success = filter->validate(validator);
+
+                       if(!success)
+                               ThrowMsg(InvalidArgumentException, "Invalid filter arguments.");
+
+                       searchEngine->setCondition(filter);
+               }
+
+               if (event->getSortModeIsSet())
+                       searchEngine->setSortMode(event->getSortMode());
+               else
+                       searchEngine->setSortMode();
+
+               event->setPersons(searchEngine->getResult());
+               event->setResult(true);
+
+       } Catch (NotFoundException) {
+               LogError("Person doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               event->setResult(false);
+
+       } Catch (PlatformException) {
+               LogError("Error during finding person : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+
+       } Catch (InvalidArgumentException) {
+               LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               event->setResult(false);
+
+       } Catch (Exception) {
+               LogError("Error during finding person : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+       }
+}
+
+void ContactManager::OnRequestReceived(const EventContactManagerAddChangeListenerPtr &event)
+{
+       LogDebug("entered");
+
+       Try     {
+               if(!event->getEmitterIsSet())
+                       ThrowMsg(InvalidArgumentException, "Invalid arguments.");
+
+               EventContactManagerChangeListenerEmitterPtr emitter = event->getEmitter();
+               if(emitter == NULL)
+                       ThrowMsg(InvalidArgumentException, "Invalid arguments.");
+
+               if(m_contactManagerEmitters.size() == 0)
+               {
+                       LogDebug("Watch registered initially");
+
+                       ContactsSvcChangeListenerManagerSingleton::Instance().registerPersonsChangeListener(this);
+               }
+
+               m_contactManagerEmitters.attach(emitter);
+
+               long id = ContactsSvcChangeListenerManagerSingleton::Instance().getWatchIdAndInc();
+               m_watchIdMap[id] = emitter->getId();
+
+           event->setId(id);
+               event->setResult(true);
+
+       } Catch (NotFoundException) {
+               LogError("Person doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               event->setResult(false);
+
+       } Catch (PlatformException) {
+               LogError("Error during addListner person : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+
+       } Catch (InvalidArgumentException) {
+               LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               event->setResult(false);
+
+       } Catch (Exception) {
+               LogError("Error during addListner person : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+       }
+}
+
+void ContactManager::OnRequestReceived(const EventContactManagerRemoveChangeListenerPtr &event)
+{
+       LogDebug("entered");
+
+       Try     {
+               if(!event->getIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "Invalid arguments.");
+
+               long id = event->getId();
+               if(m_watchIdMap.find(id) == m_watchIdMap.end())
+                       ThrowMsg(NotFoundException, "No watchId : " << id);
+
+               //DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
+               bool success = m_contactManagerEmitters.detach(m_watchIdMap[id]);
+               if(!success)
+                       ThrowMsg(NotFoundException, "No watchId : " << id);
+
+               m_watchIdMap.erase(id);
+
+               if(m_contactManagerEmitters.size() == 0)
+               {
+                       LogDebug("No watcher is registered. unsubscribing from person service.");
+
+                       ContactsSvcChangeListenerManagerSingleton::Instance().unregisterPersonsChangeListener(this);
+               }
+
+               event->setResult(true);
+
+       } Catch (NotFoundException) {
+               LogError("WatchId doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               event->setResult(false);
+
+       } Catch (PlatformException) {
+               LogError("Error during removeListner person : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+
+       } Catch (InvalidArgumentException) {
+               LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               event->setResult(false);
+
+       } Catch (Exception) {
+               LogError("Error during removeListner person : " << _rethrown_exception.GetMessage());
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               event->setResult(false);
+       }
+}
+
+void ContactManager::onContactsSvcPersonsAdded(TizenApis::Api::Contact::PersonArrayPtr &persons)
+{
+       EventInfoContactManagerChangeAddedPtr personsAdded(new EventInfoContactManagerChangeAdded());
+       personsAdded->setPersons(persons);
+       EventInfoContactManagerChangePtr event = DPL::StaticPointerCast<EventInfoContactManagerChange>(personsAdded);
+       EventContactManagerChangeListenerPtr listener(new EventContactManagerChangeListener(event));
+       m_contactManagerEmitters.emit(listener);
+}
+
+void ContactManager::onContactsSvcPersonsUpdated(TizenApis::Api::Contact::PersonArrayPtr &persons)
+{
+       EventInfoContactManagerChangeUpdatedPtr personsUpdated(new EventInfoContactManagerChangeUpdated());
+       personsUpdated->setPersons(persons);
+       EventInfoContactManagerChangePtr event = DPL::StaticPointerCast<EventInfoContactManagerChange>(personsUpdated);
+       EventContactManagerChangeListenerPtr listener(new EventContactManagerChangeListener(event));
+       m_contactManagerEmitters.emit(listener);
+}
+
+void ContactManager::onContactsSvcPersonsRemoved(TizenApis::Api::Contact::StringArrayPtr &personIds)
+{
+       EventInfoContactManagerChangeRemovedPtr personsRemoved(new EventInfoContactManagerChangeRemoved());
+       personsRemoved->setPersonIds(personIds);
+       EventInfoContactManagerChangePtr event = DPL::StaticPointerCast<EventInfoContactManagerChange>(personsRemoved);
+       EventContactManagerChangeListenerPtr listener(new EventContactManagerChangeListener(event));
+       m_contactManagerEmitters.emit(listener);
+}
+
+void ContactManager::personsUpdateBatchResultCallback(int error, void *user_data)
+{
+       LogDebug("entered");
+
+       if(user_data == NULL)
+       {
+               LogError("user_data is NULL");
+               return;
+       }
+
+       KeySharePtrPair *keyPair = (KeySharePtrPair*)user_data;
+
+       long key = keyPair->key;
+       ContactManager *contactManager = keyPair->contactManager;
+
+       delete keyPair;
+
+       contactManager->personsUpdateBatchResultCallback(error, key);
+}
+
+void ContactManager::personsUpdateBatchResultCallback(int error, long key)
+{
+       EventContactManagerUpdateBatchPtr event;
+
+       EventContactManagerUpdateBatchMap::iterator iter;
+       iter = m_updateBatchEventMap.find(key);
+       if(iter == m_updateBatchEventMap.end())
+       {
+               LogError("No event for key : " << key);
+               return;
+       }
+
+       event = iter->second;
+       m_updateBatchEventMap.erase(iter);
+
+       if(error != CONTACTS_ERROR_NONE)
+       {
+               LogError("persons_db_result_cb gives error : " << error);
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               EventRequestReceiver<EventContactManagerUpdateBatch>::ManualAnswer(event);
+               return;
+       }
+
+       event->setResult(true);
+       event->setExceptionCode(ExceptionCodes::None);
+       EventRequestReceiver<EventContactManagerUpdateBatch>::ManualAnswer(event);
+}
+
+void ContactManager::personsRemoveBatchResultCallback(int error, void *user_data)
+{
+       LogDebug("entered");
+
+       if(user_data == NULL)
+       {
+               LogError("user_data is NULL");
+               return;
+       }
+
+       KeySharePtrPair *keyPair = (KeySharePtrPair*)user_data;
+
+       long key = keyPair->key;
+       ContactManager *contactManager = keyPair->contactManager;
+
+       delete keyPair;
+
+       contactManager->personsRemoveBatchResultCallback(error, key);
+}
+
+void ContactManager::personsRemoveBatchResultCallback(int error, long key)
+{
+       EventContactManagerRemoveBatchPtr event;
+
+       EventContactManagerRemoveBatchMap::iterator iter;
+       iter = m_removeBatchEventMap.find(key);
+       if(iter == m_removeBatchEventMap.end())
+       {
+               LogError("No event for key : " << key);
+               return;
+       }
+
+       event = iter->second;
+       m_removeBatchEventMap.erase(iter);
+
+       if(error != CONTACTS_ERROR_NONE)
+       {
+               LogError("persons_db_result_cb gives error : " << error);
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               EventRequestReceiver<EventContactManagerRemoveBatch>::ManualAnswer(event);
+               return;
+       }
+
+       event->setResult(true);
+       event->setExceptionCode(ExceptionCodes::None);
+       EventRequestReceiver<EventContactManagerRemoveBatch>::ManualAnswer(event);
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactManager.h b/src/platform/Tizen/Contact/ContactManager.h
new file mode 100755 (executable)
index 0000000..78238b9
--- /dev/null
@@ -0,0 +1,128 @@
+//
+// 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        ContactManager.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _PLATFORM_CONTACT_CONTACT_MANAGER_H_
+#define _PLATFORM_CONTACT_CONTACT_MANAGER_H_
+
+#include <dpl/mutex.h>
+#include <API/Contact/IContactManager.h>
+#include "AddressBook.h"
+#include "ContactsSvcWrapper.h"
+#include "ContactsSvcChangeListenerManager.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class ContactManager: public TizenApis::Api::Contact::IContactManager, public IContactsSvcPersonsChangeListener
+{
+public:
+       ContactManager();
+       virtual ~ContactManager();
+
+       virtual void getAddressBook(const TizenApis::Api::Contact::EventContactManagerGetAddressBookPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+
+       virtual void getDefaultAddressBook(const TizenApis::Api::Contact::EventContactManagerGetDefaultAddressBookPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+
+       virtual void get(const TizenApis::Api::Contact::EventContactManagerGetPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+
+       virtual void update(const TizenApis::Api::Contact::EventContactManagerUpdatePtr &event)
+       {
+               OnRequestReceived(event);
+       }
+
+       virtual void remove(const TizenApis::Api::Contact::EventContactManagerRemovePtr &event)
+       {
+               OnRequestReceived(event);
+       }
+
+       virtual void addChangeListener(const TizenApis::Api::Contact::EventContactManagerAddChangeListenerPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+
+       virtual void removeChangeListener(const TizenApis::Api::Contact::EventContactManagerRemoveChangeListenerPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+
+protected:
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerGetAddressBookPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerGetAddressBooksPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerGetDefaultAddressBookPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerGetPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerUpdatePtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerUpdateBatchPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerRemovePtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerRemoveBatchPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerFindPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerAddChangeListenerPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerRemoveChangeListenerPtr &event);
+
+       virtual void onContactsSvcPersonsAdded(TizenApis::Api::Contact::PersonArrayPtr &persons);
+       virtual void onContactsSvcPersonsUpdated(TizenApis::Api::Contact::PersonArrayPtr &persons);
+       virtual void onContactsSvcPersonsRemoved(TizenApis::Api::Contact::StringArrayPtr &personIds);
+
+private:
+       static void personsUpdateBatchResultCallback(int error, void *user_data);
+       void personsUpdateBatchResultCallback(int error, long key);
+
+       static void personsRemoveBatchResultCallback(int error, void *user_data);
+       void personsRemoveBatchResultCallback(int error, long key);
+
+       typedef WrtDeviceApis::Commons::Emitters<TizenApis::Api::Contact::EventContactManagerChangeListenerEmitter> ContactManagerChangedEmitter;
+       ContactManagerChangedEmitter    m_contactManagerEmitters;
+
+       typedef std::map<long, TizenApis::Api::Contact::EventContactManagerChangeListenerEmitter::IdType> WatchIdMap;
+       WatchIdMap m_watchIdMap;
+
+       struct KeySharePtrPair
+       {
+               long key;
+               ContactManager *contactManager;
+       };
+
+       typedef std::map<long, TizenApis::Api::Contact::EventContactManagerUpdateBatchPtr> EventContactManagerUpdateBatchMap;
+       EventContactManagerUpdateBatchMap m_updateBatchEventMap;
+
+       typedef std::map<long, TizenApis::Api::Contact::EventContactManagerRemoveBatchPtr> EventContactManagerRemoveBatchMap;
+       EventContactManagerRemoveBatchMap m_removeBatchEventMap;
+
+       long m_eventMapAcc;
+};
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_CONTACT_MANAGER_H_
diff --git a/src/platform/Tizen/Contact/ContactObjectA2PConverter.cpp b/src/platform/Tizen/Contact/ContactObjectA2PConverter.cpp
new file mode 100755 (executable)
index 0000000..387145e
--- /dev/null
@@ -0,0 +1,1614 @@
+//
+// 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        ContactObjectA2PConverter.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Converter (TizenApis::Api::Contact::ContactPtr -> contacts_record_h)
+ */
+
+#include "ContactObjectA2PConverter.h"
+
+#include <Commons/Exception.h>
+#include "ContactUtility.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+static const char *EMPTY_STRING = "";
+
+ContactObjectA2PConverter::ContactObjectA2PConverter(const ContactPtr &abstractContact,
+               bool forScratch) :
+               m_abstractContact(abstractContact),
+               m_platformContact(NULL),
+               m_forScratch(forScratch),
+               m_convertFinished(false),
+               m_platformContactOwnership(false)
+{
+}
+
+ContactObjectA2PConverter::ContactObjectA2PConverter(const ContactPtr &abstractContact,
+               bool forScratch,
+               contacts_record_h platformContact) :
+               m_abstractContact(abstractContact),
+               m_platformContact(platformContact),
+               m_forScratch(forScratch),
+               m_convertFinished(false),
+               m_platformContactOwnership(false)
+{
+}
+
+ContactObjectA2PConverter::~ContactObjectA2PConverter()
+{
+       if(m_platformContactOwnership && m_platformContact != NULL)
+       {
+               contacts_record_destroy(m_platformContact, true);
+               m_platformContact = NULL;
+               m_platformContactOwnership = false;
+       }
+}
+
+contacts_record_h ContactObjectA2PConverter::getPlatformContact()
+{
+       LogDebug("enter");
+
+       int errorCode = 0;
+
+       if(m_abstractContact == NULL)
+       {
+               LogError("Abstract contact object did not set");
+               ThrowMsg(InvalidArgumentException, "Abstract contact object did not set");
+       }
+
+       if(m_platformContact == NULL)
+       {
+               if(m_abstractContact->getIdIsSet() && (m_forScratch == false))
+               {
+                       int id = ContactUtility::strToInt(m_abstractContact->getId());
+                       LogDebug("Load platform object id : " << id);
+                       errorCode = contacts_db_get_record(_contacts_contact._uri, id, &m_platformContact);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(UnknownException, "error on contacts_db_get_record (errorCode:" << errorCode << ")");
+               }
+               else
+               {
+                       LogDebug("New platform object has been created");
+                       errorCode = contacts_record_create(_contacts_contact._uri, &m_platformContact);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(UnknownException, "error on contacts_record_create (errorCode:" << errorCode << ")");
+               }
+
+               m_platformContactOwnership = true;
+       }
+
+       LogDebug("for scratch : " << m_forScratch);
+
+       Try
+       {
+               if(m_convertFinished == false)
+                       convertToPlatformObject();
+       }
+       Catch(Exception)
+       {
+               LogError("Error while converting - " << _rethrown_exception.GetMessage());
+               ThrowMsg(PlatformException, "Fail to convert abstract object to platform object.");
+       }
+
+       return m_platformContact;
+}
+
+void ContactObjectA2PConverter::convertToPlatformObject()
+{
+       importBaseInfoValue();
+       importNameValue();
+       importCompanyList();
+       importNoteList();
+       importNumberList();
+       importEmailList();
+       importGrouprelList();
+       importEventList();
+       importPostalList();
+       importWebAddrList();
+       importNicknameList();
+
+       m_convertFinished = true;
+}
+
+void ContactObjectA2PConverter::importBaseInfoValue()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+
+       const char *newValueStr = NULL;
+       char *oldValueStr = NULL;
+       string abstractValueStr;
+       string realPath;
+
+       // Contact.photoURI
+       if(!m_abstractContact->getPhotoURIIsSet() || m_abstractContact->getPhotoURI().empty())
+       {
+               errorCode = contacts_record_create(_contacts_image._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "creating image value A (errorCode:" << errorCode << ")");
+               contacts_record_add_child_record(m_platformContact, _contacts_contact.image, child_record);
+       }
+       else
+       {
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.image, 0, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE || child_record == NULL)
+               {
+                       LogDebug("Fail to get contacts_record_get_child_record_at_p : " << errorCode);
+                       errorCode = contacts_record_create(_contacts_image._uri, &child_record);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(UnknownException, "creating name value B (errorCode:" << errorCode << ")");
+               }
+
+               contacts_record_get_str_p(child_record, _contacts_image.path, &oldValueStr);
+               realPath = ContactUtility::convertUriToPath(m_abstractContact->getPhotoURI());
+               m_abstractContact->setPhotoURIRealPath(realPath);
+               abstractValueStr = m_abstractContact->getPhotoURIRealPath();
+               if(oldValueStr != NULL &&
+                               (!m_abstractContact->getPhotoURIIsSet() || m_abstractContact->getPhotoURI().empty()))
+               {
+                       newValueStr = EMPTY_STRING;
+               }
+               else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+               {
+                       newValueStr = abstractValueStr.c_str();
+               }
+
+               if(newValueStr != NULL)
+               {
+                       LogDebug("image : " << newValueStr);
+                       errorCode = contacts_record_set_str(child_record, _contacts_image.path, newValueStr);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               ThrowMsg(PlatformException, "importing photoURI E (err:" <<
+                                               errorCode << ", str:" << abstractValueStr << ")");
+                       }
+               }
+               contacts_record_add_child_record(m_platformContact, _contacts_contact.image, child_record);
+       }
+
+       // Contact.ringtoneURI
+       newValueStr = NULL;
+       oldValueStr = NULL;
+       contacts_record_get_str_p(m_platformContact, _contacts_contact.ringtone_path, &oldValueStr);
+       realPath = ContactUtility::convertUriToPath(m_abstractContact->getRingtoneURI());
+       m_abstractContact->setRingtoneURIRealPath(realPath);
+       abstractValueStr = m_abstractContact->getRingtoneURIRealPath();
+       if(oldValueStr != NULL &&
+                       (!m_abstractContact->getRingtoneURIIsSet() || m_abstractContact->getRingtoneURI().empty()))
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(m_platformContact, _contacts_contact.ringtone_path, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(PlatformException, "importing ringtoneURI E (err:" <<
+                                       errorCode << ", str:" << abstractValueStr << ")");
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importNameValue()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+
+       ContactNamePtr contactName = m_abstractContact->getName();
+       if(contactName == NULL ||
+                       (( !contactName->getFirstNameIsSet() || contactName->getFirstName().empty() )
+                       && ( !contactName->getLastNameIsSet() || contactName->getLastName().empty() )
+                       && ( !contactName->getMiddleNameIsSet() || contactName->getMiddleName().empty() )
+                       && ( !contactName->getPhoneticFirstNameIsSet() || contactName->getPhoneticFirstName().empty() )
+                       && ( !contactName->getPhoneticLastNameIsSet() || contactName->getPhoneticLastName().empty() )
+                       && ( !contactName->getSuffixIsSet() || contactName->getSuffix().empty() )
+                       && ( !contactName->getPrefixIsSet() || contactName->getPrefix().empty() ) ) )
+       {
+               errorCode = contacts_record_create(_contacts_name._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "creating name value A (errorCode:" << errorCode << ")");
+               contacts_record_add_child_record(m_platformContact, _contacts_contact.name, child_record);
+               return;
+       }
+
+       errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.name, 0, &child_record);
+       if(errorCode != CONTACTS_ERROR_NONE || child_record == NULL)
+       {
+               LogDebug("Fail to get contacts_record_get_child_record_at_p : " << errorCode);
+               errorCode = contacts_record_create(_contacts_name._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "creating name value B (errorCode:" << errorCode << ")");
+
+               importNameValueToNewValue(child_record, contactName);
+       }
+       else
+       {
+               importNameValueToExistingValue(child_record, contactName);
+       }
+
+       contacts_record_add_child_record(m_platformContact, _contacts_contact.name, child_record);
+}
+
+void ContactObjectA2PConverter::importNameValueToExistingValue(contacts_record_h child_record, ContactNamePtr &contactName)
+{
+       int errorCode = 0;
+
+       const char *newValueStr = NULL;
+       char *oldValueStr = NULL;
+       string abstractValueStr;
+
+       // ContactName.firstName
+       contacts_record_get_str_p(child_record, _contacts_name.first, &oldValueStr);
+       abstractValueStr = contactName->getFirstName();
+       if(oldValueStr != NULL && (!contactName->getFirstNameIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(child_record, _contacts_name.first, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(child_record, true);
+                       ThrowMsg(PlatformException, "importing firstName E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactName.lastName
+       newValueStr = NULL;
+       oldValueStr = NULL;
+       contacts_record_get_str_p(child_record, _contacts_name.last, &oldValueStr);
+       abstractValueStr = contactName->getLastName();
+       if(oldValueStr != NULL && (!contactName->getLastNameIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(child_record, _contacts_name.last, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(child_record, true);
+                       ThrowMsg(PlatformException, "importing lastName E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactName.middleName
+       newValueStr = NULL;
+       oldValueStr = NULL;
+       contacts_record_get_str_p(child_record, _contacts_name.addition, &oldValueStr);
+       abstractValueStr = contactName->getMiddleName();
+       if(oldValueStr != NULL && (!contactName->getMiddleNameIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(child_record, _contacts_name.addition, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(child_record, true);
+                       ThrowMsg(PlatformException, "importing middleName E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactName.prefix
+       newValueStr = NULL;
+       oldValueStr = NULL;
+       contacts_record_get_str_p(child_record, _contacts_name.prefix, &oldValueStr);
+       abstractValueStr = contactName->getPrefix();
+       if(oldValueStr != NULL && (!contactName->getPrefixIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(child_record, _contacts_name.prefix, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(child_record, true);
+                       ThrowMsg(PlatformException, "importing prefix E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactName.suffix
+       newValueStr = NULL;
+       oldValueStr = NULL;
+       contacts_record_get_str_p(child_record, _contacts_name.suffix, &oldValueStr);
+       abstractValueStr = contactName->getSuffix();
+       if(oldValueStr != NULL && (!contactName->getSuffixIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(child_record, _contacts_name.suffix, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(child_record, true);
+                       ThrowMsg(PlatformException, "importing suffix E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactName.phoneticFirstName
+       newValueStr = NULL;
+       oldValueStr = NULL;
+       contacts_record_get_str_p(child_record, _contacts_name.phonetic_first, &oldValueStr);
+       abstractValueStr = contactName->getPhoneticFirstName();
+       if(oldValueStr != NULL && (!contactName->getPhoneticFirstNameIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_first, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(child_record, true);
+                       ThrowMsg(PlatformException, "importing phoneticFirstName E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+
+       // ContactName.phoneticLastName
+       newValueStr = NULL;
+       oldValueStr = NULL;
+       contacts_record_get_str_p(child_record, _contacts_name.phonetic_last, &oldValueStr);
+       abstractValueStr = contactName->getPhoneticLastName();
+       if(oldValueStr != NULL && (!contactName->getPhoneticLastNameIsSet() || abstractValueStr.empty()) )
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_last, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(child_record, true);
+                       ThrowMsg(PlatformException, "importing phoneticLastName E (err:" <<
+                                       errorCode << ", str:" << newValueStr << ")");
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importNameValueToNewValue(contacts_record_h child_record, ContactNamePtr &contactName)
+{
+       int errorCode = 0;
+
+       // ContactName.firstName
+       if(contactName->getFirstNameIsSet())
+       {
+               string firstName = contactName->getFirstName();
+               if(firstName != EMPTY_STRING)
+               {
+                       errorCode = contacts_record_set_str(child_record, _contacts_name.first, firstName.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               contacts_record_destroy(child_record, true);
+                               ThrowMsg(PlatformException, "importing firstName N (err:" <<
+                                               errorCode << ", str:" << firstName << ")");
+                       }
+               }
+       }
+
+       // ContactName.lastName
+       if(contactName->getLastNameIsSet())
+       {
+               string lastName = contactName->getLastName();
+               if(lastName != EMPTY_STRING)
+               {
+                       errorCode = contacts_record_set_str(child_record, _contacts_name.last, lastName.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               contacts_record_destroy(child_record, true);
+                               ThrowMsg(PlatformException, "importing lastName N (err:" <<
+                                               errorCode << ", str:" << lastName << ")");
+                       }
+               }
+       }
+
+       // ContactName.middleName
+       if(contactName->getMiddleNameIsSet())
+       {
+               string middleName = contactName->getMiddleName();
+               if(middleName != EMPTY_STRING)
+               {
+                       errorCode = contacts_record_set_str(child_record, _contacts_name.addition, middleName.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               contacts_record_destroy(child_record, true);
+                               ThrowMsg(PlatformException, "importing middleName N (err:" <<
+                                               errorCode << ", str:" << middleName << ")");
+                       }
+               }
+       }
+
+       // ContactName.prefix
+       if(contactName->getPrefixIsSet())
+       {
+               string prefix = contactName->getPrefix();
+               if(prefix != EMPTY_STRING)
+               {
+                       errorCode = contacts_record_set_str(child_record, _contacts_name.prefix, prefix.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               contacts_record_destroy(child_record, true);
+                               ThrowMsg(PlatformException, "importing prefix N (err:" <<
+                                               errorCode << ", str:" << prefix << ")");
+                       }
+               }
+       }
+
+       // ContactName.suffix
+       if(contactName->getSuffixIsSet())
+       {
+               string suffix = contactName->getSuffix();
+               if(suffix != EMPTY_STRING)
+               {
+                       errorCode = contacts_record_set_str(child_record, _contacts_name.suffix, suffix.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               contacts_record_destroy(child_record, true);
+                               ThrowMsg(PlatformException, "importing suffix N (err:" <<
+                                               errorCode << ", str:" << suffix << ")");
+                       }
+               }
+       }
+
+       // ContactName.phoneticFirstName
+       if(contactName->getPhoneticFirstNameIsSet())
+       {
+               string phoneticFirstName = contactName->getPhoneticFirstName();
+               if(phoneticFirstName != EMPTY_STRING)
+               {
+                       errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_first, phoneticFirstName.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               contacts_record_destroy(child_record, true);
+                               ThrowMsg(PlatformException, "importing phoneticFirstName N (err:" <<
+                                               errorCode << ", str:" << phoneticFirstName << ")");
+                       }
+               }
+       }
+
+       // ContactName.phoneticLastName
+       if(contactName->getPhoneticLastNameIsSet())
+       {
+               string phoneticLastName = contactName->getPhoneticLastName();
+               if(phoneticLastName != EMPTY_STRING)
+               {
+                       errorCode = contacts_record_set_str(child_record, _contacts_name.phonetic_last, phoneticLastName.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               contacts_record_destroy(child_record, true);
+                               ThrowMsg(PlatformException, "importing phoneticLastName N (err:" <<
+                                               errorCode << ", str:" << phoneticLastName << ")");
+                       }
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importCompanyList()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+       unsigned int record_count = 0;
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.company, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting company count (err:" << errorCode << ")");
+       }
+
+       for(int i=record_count-1; i>=0; i--)
+       {
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.company, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "getting company value A (errorCode:" << errorCode << ")");
+
+               errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.company, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "removing company value A (errorCode:" << errorCode << ")");
+
+               child_record = NULL;
+       }
+
+       ContactOrganizationArrayPtr organizations = m_abstractContact->getOrganizations();
+       if(organizations->size() == 0)
+               return;
+
+       ContactOrganizationArray::iterator organizationsIter = organizations->begin();
+       for(; organizationsIter != organizations->end(); organizationsIter++)
+       {
+               ContactOrganizationPtr organization = *organizationsIter;
+
+               child_record = NULL;
+
+               errorCode = contacts_record_create(_contacts_company._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to create child_record with contacts_record_create(_contacts_company._uri)");
+                       continue;
+               }
+
+               // ContactOrganization.name
+               if(organization->getNameIsSet())
+               {
+                       string name = organization->getName();
+                       if(!name.empty())
+                       {
+                               errorCode = contacts_record_set_str(child_record, _contacts_company.name, name.c_str());
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       LogWarning("importing company name N (err:" << errorCode << ", str:" << name << ")");
+                                       contacts_record_destroy(child_record, true);
+                                       continue;
+                               }
+                       }
+               }
+
+               // ContactOrganization.department
+               if(organization->getDepartmentIsSet())
+               {
+                       string department = organization->getDepartment();
+                       if(!department.empty())
+                       {
+                               errorCode = contacts_record_set_str(child_record, _contacts_company.department, department.c_str());
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       LogWarning("importing department N (err:" << errorCode << ", str:" << department << ")");
+                                       contacts_record_destroy(child_record, true);
+                                       continue;
+                               }
+                       }
+               }
+
+               // ContactOrganization.title
+               if(organization->getTitleIsSet())
+               {
+                       string title = organization->getTitle();
+                       if(!title.empty())
+                       {
+                               errorCode = contacts_record_set_str(child_record, _contacts_company.job_title, title.c_str());
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       LogWarning("importing title N (err:" << errorCode << ", str:" << title << ")");
+                                       contacts_record_destroy(child_record, true);
+                                       continue;
+                               }
+                       }
+               }
+
+               // ContactOrganization.role
+               if(organization->getRoleIsSet())
+               {
+                       string role = organization->getRole();
+                       if(!role.empty())
+                       {
+                               errorCode = contacts_record_set_str(child_record, _contacts_company.role, role.c_str());
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       LogWarning("importing role N (err:" << errorCode << ", str:" << role << ")");
+                                       contacts_record_destroy(child_record, true);
+                                       continue;
+                               }
+                       }
+               }
+
+               // ContactOrganization.logoURI
+               if(organization->getLogoURIIsSet())
+               {
+                       string logoURI = organization->getLogoURI();
+                       if(!logoURI.empty())
+                       {
+                               logoURI = ContactUtility::convertUriToPath(logoURI);
+
+                               errorCode = contacts_record_set_str(child_record, _contacts_company.logo, logoURI.c_str());
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       LogWarning("importing logoURI N (err:" << errorCode << ", str:" << logoURI << ")");
+                                       contacts_record_destroy(child_record, true);
+                                       continue;
+                               }
+                       }
+               }
+
+               errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.company, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set company value to child_record");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importNoteList()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+       unsigned int record_count = 0;
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.note, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting note count (err:" << errorCode << ")");
+       }
+
+       for(int i=record_count-1; i>=0; i--)
+       {
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.note, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "getting note value A (errorCode:" << errorCode << ")");
+
+               errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.note, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "removing note value A (errorCode:" << errorCode << ")");
+
+               child_record = NULL;
+       }
+
+       StringArrayPtr notes = m_abstractContact->getNotes();
+       if(notes->size() == 0)
+               return;
+
+       StringArray::iterator notesIter = notes->begin();
+       for(; notesIter != notes->end(); notesIter++)
+       {
+               string note = *notesIter;
+
+               child_record = NULL;
+
+               if(note.empty())
+               {
+                       continue;
+               }
+
+               errorCode = contacts_record_create(_contacts_note._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to create child_record with contacts_record_create(_contacts_note._uri)");
+                       continue;
+               }
+
+               errorCode = contacts_record_set_str(child_record, _contacts_note.note, note.c_str());
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("importing note N (err:" << errorCode << ", str:" << note << ")");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.note, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set note value to child_record");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importNumberList()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+       unsigned int record_count = 0;
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.number, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting number count (err:" << errorCode << ")");
+       }
+
+       for(int i=record_count-1; i>=0; i--)
+       {
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.number, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "getting number value A (errorCode:" << errorCode << ")");
+
+               errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.number, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "removing number value A (errorCode:" << errorCode << ")");
+
+               child_record = NULL;
+       }
+
+       ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
+       if(phoneNumbers->size() == 0)
+               return;
+
+       ContactPhoneNumberArray::iterator phoneNumbersIter = phoneNumbers->begin();
+       for(; phoneNumbersIter != phoneNumbers->end(); phoneNumbersIter++)
+       {
+               ContactPhoneNumberPtr phoneNumber = *phoneNumbersIter;
+               ContactPhoneNumberTypeArrayPtr types = phoneNumber->getTypes();
+
+               if(!phoneNumber->getNumberIsSet() || phoneNumber->getNumber().empty())
+               {
+                       LogDebug("Number was not set.");
+                       continue;
+               }
+
+               string number = phoneNumber->getNumber();
+
+               bool ctsBoolDefault = phoneNumber->getIsDefault();
+
+               int ctsIntType = 0;
+               //char *ctsStrCustomType = NULL;
+
+               ContactPhoneNumberTypeArray::iterator typesIter = types->begin();
+               for(; typesIter != types->end(); typesIter++)
+               {
+                       ContactPhoneNumberType type = *typesIter;
+                       if(type == CONTACT_PHONE_NUMBER_TYPE_HOME)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_HOME;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_WORK)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_WORK;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_VOICE)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VOICE;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_FAX)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_FAX;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_MSG)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_MSG;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_CELL)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CELL;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_PAGER)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_PAGER;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_BBS)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_BBS;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_MODEM)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_MODEM;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_CAR)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CAR;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_ISDN)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_ISDN;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_VIDEO)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_VIDEO;
+                       else if(type == CONTACT_PHONE_NUMBER_TYPE_PCS)
+                               ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_PCS;
+                       else
+                       {
+                               // TODO Will be added after type changed to string
+                               // ctsIntType = ctsIntType | CONTACTS_NUMBER_TYPE_CUSTOM;
+                               // ctsStrCustomType = ...;
+                       }
+               }
+
+               child_record = NULL;
+
+               errorCode = contacts_record_create(_contacts_number._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to create child_record with contacts_record_create(_contacts_number._uri)");
+                       continue;
+               }
+
+               errorCode = contacts_record_set_str(child_record, _contacts_number.number, number.c_str());
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set number value to child_record number : " << number);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               errorCode = contacts_record_set_bool(child_record, _contacts_number.is_default, ctsBoolDefault);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set number value to child_record default : " << ctsBoolDefault);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               errorCode = contacts_record_set_int(child_record, _contacts_number.type, ctsIntType);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set number value to child_record type : " << ctsIntType);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               //if(ctsStrCustomType != NULL)
+               //{
+               //      errorCode = contacts_record_set_str(child_record, _contacts_number.label, ctsStrCustomType);
+               //      if(errorCode != CONTACTS_ERROR_NONE)
+               //      {
+               //              LogWarning("Fail to set number value to child_record custom type : " << ctsStrCustomType);
+               //              contacts_record_destroy(child_record, true);
+               //              continue;
+               //      }
+               //}
+
+               errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.number, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set number value to child_record");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importEmailList()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+       unsigned int record_count = 0;
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.email, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting email count (err:" << errorCode << ")");
+       }
+
+       for(int i=record_count-1; i>=0; i--)
+       {
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.email, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "getting email value A (errorCode:" << errorCode << ")");
+
+               errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.email, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "removing email value A (errorCode:" << errorCode << ")");
+
+               child_record = NULL;
+       }
+
+       ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
+       if(emails->size() == 0)
+               return;
+
+       ContactEmailAddressArray::iterator emailsIter = emails->begin();
+       for(; emailsIter != emails->end(); emailsIter++)
+       {
+               ContactEmailAddressPtr email = *emailsIter;
+               ContactEmailAddressTypeArrayPtr types = email->getTypes();
+
+               if(!email->getEmailIsSet() || email->getEmail().empty())
+               {
+                       LogDebug("email address was not set.");
+                       continue;
+               }
+
+               string emailAddress = email->getEmail();
+
+               bool ctsBoolDefault = email->getIsDefault();
+
+               int ctsIntType = 0;
+               //char *ctsStrCustomType = NULL;
+
+               ContactEmailAddressTypeArray::iterator typesIter = types->begin();
+               for(; typesIter != types->end(); typesIter++)
+               {
+                       ContactEmailAddressType type = *typesIter;
+                       if(type == CONTACT_EMAIL_TYPE_HOME)
+                               ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_HOME;
+                       else if(type == CONTACT_EMAIL_TYPE_WORK)
+                               ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_WORK;
+                       //else
+                       //{
+                       //      //TODO Will be added after type changed to string
+                       //      //ctsIntType = ctsIntType | CONTACTS_EMAIL_TYPE_CUSTOM;
+                       //      // ctsStrCustomType = ...;
+                       //}
+               }
+
+               child_record = NULL;
+
+               errorCode = contacts_record_create(_contacts_email._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to create child_record with contacts_record_create(_contacts_email._uri)");
+                       continue;
+               }
+
+               errorCode = contacts_record_set_str(child_record, _contacts_email.email, emailAddress.c_str());
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set email value to child_record email : " << emailAddress);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               errorCode = contacts_record_set_bool(child_record, _contacts_email.is_default, ctsBoolDefault);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set email value to child_record default : " << ctsBoolDefault);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               errorCode = contacts_record_set_int(child_record, _contacts_email.type, ctsIntType);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set email value to child_record type : " << ctsIntType);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               //if(ctsStrCustomType != NULL)
+               //{
+               //      errorCode = contacts_record_set_str(child_record, _contacts_email.label, ctsStrCustomType);
+               //      if(errorCode != CONTACTS_ERROR_NONE)
+               //      {
+               //              LogWarning("Fail to set email value to child_record custom type : " << ctsStrCustomType);
+               //              contacts_record_destroy(child_record, true);
+               //              continue;
+               //      }
+               //}
+
+               errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.email, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set email value to child_record");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importGrouprelList()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+       unsigned int record_count = 0;
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.group_relation, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting note count (err:" << errorCode << ")");
+       }
+
+       for(int i=record_count-1; i>=0; i--)
+       {
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.group_relation, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "getting note value A (errorCode:" << errorCode << ")");
+
+               errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.group_relation, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "removing note value A (errorCode:" << errorCode << ")");
+
+               child_record = NULL;
+       }
+
+       StringArrayPtr groupIds = m_abstractContact->getGroupIds();
+       if(groupIds->size() == 0)
+               return;
+
+       StringArray::iterator groupIdsIter = groupIds->begin();
+       for(; groupIdsIter != groupIds->end(); groupIdsIter++)
+       {
+               string groupId = *groupIdsIter;
+
+               child_record = NULL;
+
+               if(ContactUtility::checkStrIsUInt(groupId))
+               {
+                       LogWarning("groupId (" << groupId << ") is wrong.");
+                       continue;
+               }
+
+               int groupIdInt = ContactUtility::strToInt(groupId);
+
+               errorCode = contacts_record_create(_contacts_group_relation._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to create child_record with contacts_record_create(_contacts_group_relation._uri)");
+                       continue;
+               }
+
+               errorCode = contacts_record_set_int(child_record, _contacts_group_relation.group_id, groupIdInt);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("importing group id N (err:" << errorCode << ", str:" << groupIdInt << ")");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               int contactId = ContactUtility::strToInt(m_abstractContact->getId());
+               errorCode = contacts_record_set_int(child_record, _contacts_group_relation.contact_id, contactId);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("importing group contact_id N (err:" << errorCode << ", str:" << contactId << ")");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.group_relation, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set group value to child_record");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importEventList()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+       unsigned int record_count = 0;
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.event, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting event count (err:" << errorCode << ")");
+       }
+
+       for(int i=record_count-1; i>=0; i--)
+       {
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.event, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "getting event value A (errorCode:" << errorCode << ")");
+
+               errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.event, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "removing event value A (errorCode:" << errorCode << ")");
+
+               child_record = NULL;
+       }
+
+       if(!m_abstractContact->getBirthdayIsSet() && m_abstractContact->getAnniversariesNum() == 0)
+               return;
+
+       importEventListBirthday();
+
+       importEventListAnniversary();
+}
+
+void ContactObjectA2PConverter::importEventListBirthday()
+{
+       int errorCode = 0;
+
+       if(!m_abstractContact->getBirthdayIsSet())
+               return;
+
+       tm birthdayTm = m_abstractContact->getBirthday();
+
+       if (birthdayTm.tm_year == 0 && birthdayTm.tm_mon == 0 && birthdayTm.tm_mday == 0)
+               return;
+
+       int birthday = ContactUtility::toDateDbInt(birthdayTm);
+
+       contacts_record_h child_record = NULL;
+
+       errorCode = contacts_record_create(_contacts_event._uri, &child_record);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogWarning("Fail to create child_record with contacts_record_create(_contacts_event._uri)");
+               return;
+       }
+
+       errorCode = contacts_record_set_int(child_record, _contacts_event.type, CONTACTS_EVENT_TYPE_BIRTH);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogWarning("Fail to set event value to child_record type : " << CONTACTS_EVENT_TYPE_BIRTH);
+               contacts_record_destroy(child_record, true);
+               return;
+       }
+
+       errorCode = contacts_record_set_int(child_record, _contacts_event.date, birthday);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogWarning("Fail to set event value to child_record date : " << birthday);
+               contacts_record_destroy(child_record, true);
+               return;
+       }
+
+       errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.event, child_record);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogWarning("Fail to set event value to child_record");
+               contacts_record_destroy(child_record, true);
+               return;
+       }
+}
+
+void ContactObjectA2PConverter::importEventListAnniversary()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+
+       if(m_abstractContact->getAnniversariesNum() == 0)
+               return;
+
+       ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
+
+       ContactAnniversaryArray::iterator anniversariesIter = anniversaries->begin();
+       for(; anniversariesIter != anniversaries->end(); anniversariesIter++)
+       {
+               ContactAnniversaryPtr anniversary = *anniversariesIter;
+
+               if(!anniversary->getDateIsSet())
+                       continue;
+
+               tm dateTm = anniversary->getDate();
+
+               if (dateTm.tm_year == 0 && dateTm.tm_mon == 0 && dateTm.tm_mday == 0)
+                       continue;
+
+               int date = ContactUtility::toDateDbInt(dateTm);
+
+               child_record = NULL;
+
+               errorCode = contacts_record_create(_contacts_event._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to create child_record with contacts_record_create(_contacts_event._uri)");
+                       continue;
+               }
+
+               errorCode = contacts_record_set_int(child_record, _contacts_event.type, CONTACTS_EVENT_TYPE_ANNIVERSARY);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set event value to child_record type : CONTACTS_EVENT_TYPE_ANNIVERSARY");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               errorCode = contacts_record_set_int(child_record, _contacts_event.date, date);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set event value to child_record date : " << date);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               if(anniversary->getLabelIsSet())
+               {
+                       string label = anniversary->getLabel();
+                       errorCode = contacts_record_set_str(child_record, _contacts_event.label, label.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to set label value to child_record label : " << label);
+                               contacts_record_destroy(child_record, true);
+                               continue;
+                       }
+
+               }
+
+               errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.event, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set event value to child_record");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importPostalList()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+       unsigned int record_count = 0;
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.address, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting address count (err:" << errorCode << ")");
+       }
+
+       for(int i=record_count-1; i>=0; i--)
+       {
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.address, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "getting address value A (errorCode:" << errorCode << ")");
+
+               errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.address, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "removing address value A (errorCode:" << errorCode << ")");
+
+               child_record = NULL;
+       }
+
+       if(m_abstractContact->getAddressesNum() == 0)
+               return;
+
+       ContactAddressArrayPtr addresses = m_abstractContact->getAddresses();
+
+       ContactAddressArray::iterator addressesIter = addresses->begin();
+       for(; addressesIter != addresses->end(); addressesIter++)
+       {
+               ContactAddressPtr address = *addressesIter;
+               ContactAddressTypeArrayPtr types = address->getTypes();
+
+               if(( !address->getCountryIsSet() || address->getCountry().empty() ) &&
+                               ( !address->getRegionIsSet() || address->getRegion().empty() ) &&
+                               ( !address->getCityIsSet() || address->getCity().empty() ) &&
+                               ( !address->getStreetAddressIsSet() || address->getStreetAddress().empty() ) &&
+                               ( !address->getAdditionalInformationIsSet() || address->getAdditionalInformation().empty() ) &&
+                               ( !address->getPostalCodeIsSet() || address->getPostalCode().empty() ) )
+               {
+                       LogDebug("No information for address was not set.");
+                       continue;
+               }
+
+               bool ctsBoolDefault = address->getIsDefault();
+
+               int ctsIntType = 0;
+               //char *ctsStrCustomType = NULL;
+
+               ContactAddressTypeArray::iterator typesIter = types->begin();
+               for(; typesIter != types->end(); typesIter++)
+               {
+                       ContactAddressType type = *typesIter;
+                       if(type == CONTACT_ADDRESS_TYPE_HOME)
+                               ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_HOME;
+                       else if(type == CONTACT_ADDRESS_TYPE_WORK)
+                               ctsIntType = ctsIntType | CONTACTS_ADDRESS_TYPE_WORK;
+                       //else
+                       //{
+                       //      // TODO Will be added after type changed to string
+                       //      // ctsIntType = ctsIntType | CTS_POSTAL_TYPE_CUSTOM;
+                       //      // ctsStrCustomType = ...;
+                       //}
+               }
+
+               child_record = NULL;
+
+               errorCode = contacts_record_create(_contacts_address._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to create child_record with contacts_record_create(_contacts_address._uri)");
+                       continue;
+               }
+
+               if(address->getCountryIsSet())
+               {
+                       string country = address->getCountry();
+                       errorCode = contacts_record_set_str(child_record, _contacts_address.country, country.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to set country value to child_record str : " << country);
+                               contacts_record_destroy(child_record, true);
+                               continue;
+                       }
+               }
+
+               if(address->getRegionIsSet())
+               {
+                       string region = address->getRegion();
+                       errorCode = contacts_record_set_str(child_record, _contacts_address.region, region.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to set region value to child_record str : " << region);
+                               contacts_record_destroy(child_record, true);
+                               continue;
+                       }
+               }
+
+               if(address->getCityIsSet())
+               {
+                       string city = address->getCity();
+                       errorCode = contacts_record_set_str(child_record, _contacts_address.locality, city.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to set locality value to child_record str : " << city);
+                               contacts_record_destroy(child_record, true);
+                               continue;
+                       }
+               }
+
+               if(address->getStreetAddressIsSet())
+               {
+                       string streetAddress = address->getStreetAddress();
+                       errorCode = contacts_record_set_str(child_record, _contacts_address.street, streetAddress.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to set street value to child_record str : " << streetAddress);
+                               contacts_record_destroy(child_record, true);
+                               continue;
+                       }
+               }
+
+               if(address->getAdditionalInformationIsSet())
+               {
+                       string additionalInformation = address->getAdditionalInformation();
+                       errorCode = contacts_record_set_str(child_record, _contacts_address.extended, additionalInformation.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to set extended value to child_record str : " << additionalInformation);
+                               contacts_record_destroy(child_record, true);
+                               continue;
+                       }
+               }
+
+               if(address->getPostalCodeIsSet())
+               {
+                       string postalCode = address->getPostalCode();
+                       errorCode = contacts_record_set_str(child_record, _contacts_address.postal_code, postalCode.c_str());
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to set postal_code value to child_record str : " << postalCode);
+                               contacts_record_destroy(child_record, true);
+                               continue;
+                       }
+               }
+
+               errorCode = contacts_record_set_bool(child_record, _contacts_address.is_default, ctsBoolDefault);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set favorite value to child_record default : " << ctsBoolDefault);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               errorCode = contacts_record_set_int(child_record, _contacts_address.type, ctsIntType);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set default value to child_record type : " << ctsIntType);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               //if(ctsStrCustomType != NULL)
+               //{
+               //      errorCode = contacts_record_set_str(child_record, _contacts_address.label, ctsStrCustomType);
+               //      if(errorCode != CONTACTS_ERROR_NONE)
+               //      {
+               //              LogWarning("Fail to set custom value to child_record type : " << ctsStrCustomType);
+               //              contacts_record_destroy(child_record, true);
+               //              continue;
+               //      }
+               //}
+
+               errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.address, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set address value to child_record");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importWebAddrList()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+       unsigned int record_count = 0;
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.url, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting url count (err:" << errorCode << ")");
+       }
+
+       for(int i=record_count-1; i>=0; i--)
+       {
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.url, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "getting url value A (errorCode:" << errorCode << ")");
+
+               errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.url, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "removing url value A (errorCode:" << errorCode << ")");
+
+               child_record = NULL;
+       }
+
+       ContactWebSiteArrayPtr webSites = m_abstractContact->getUrls();
+       if(webSites->size() == 0)
+               return;
+
+       ContactWebSiteArray::iterator webSiteIter = webSites->begin();
+       for(; webSiteIter != webSites->end(); webSiteIter++)
+       {
+               ContactWebSitePtr webSite = *webSiteIter;
+               ContactWebSiteType type = webSite->getType();
+
+               if(!webSite->getUrlIsSet() || webSite->getUrl().empty())
+               {
+                       LogDebug("url was not set.");
+                       continue;
+               }
+
+               string url = webSite->getUrl();
+
+               int ctsIntType = 0;
+//             char *ctsStrCustomType = NULL;
+
+               if(type == WEBSITE_TYPE_HOMEPAGE)
+                       ctsIntType = CONTACTS_URL_TYPE_HOME;
+               else if(type == WEBSITE_TYPE_BLOG)
+                       ctsIntType = CONTACTS_URL_TYPE_WORK;
+               else
+               {
+                       // TODO Will be added after type changed to string
+                       // ctsIntType = CONTACTS_URL_TYPE_CUSTOM;
+                       // ctsStrCustomType = ...;
+               }
+
+               child_record = NULL;
+
+               errorCode = contacts_record_create(_contacts_url._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to create child_record with contacts_record_create(_contacts_url._uri)");
+                       continue;
+               }
+
+               errorCode = contacts_record_set_str(child_record, _contacts_url.url, url.c_str());
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set url value to child_record str : " << url);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               errorCode = contacts_record_set_int(child_record, _contacts_url.type, ctsIntType);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set default value to child_record type : " << ctsIntType);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+/*
+               if(ctsStrCustomType != NULL)
+               {
+                       errorCode = contacts_record_set_str(child_record, _contacts_url.label, ctsStrCustomType);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogWarning("Fail to set custom value to child_record type : " << ctsStrCustomType);
+                               contacts_record_destroy(child_record, true);
+                               continue;
+                       }
+               }
+*/
+               errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.url, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set url value to child_record");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+       }
+}
+
+void ContactObjectA2PConverter::importNicknameList()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+       unsigned int record_count = 0;
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.nickname, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+       {
+               ThrowMsg(PlatformException, "getting nickname count (err:" << errorCode << ")");
+       }
+
+       for(int i=record_count-1; i>=0; i--)
+       {
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.nickname, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "getting nickname value A (errorCode:" << errorCode << ")");
+
+               errorCode = contacts_record_remove_child_record(m_platformContact, _contacts_contact.nickname, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(UnknownException, "removing nickname value A (errorCode:" << errorCode << ")");
+
+               child_record = NULL;
+       }
+
+       ContactNamePtr contactName = m_abstractContact->getName();
+       if(contactName == NULL)
+               return;
+
+       if(contactName->getNicknamesNum() == 0)
+               return;
+
+       StringArrayPtr nicknames = contactName->getNicknames();
+
+       StringArray::iterator nicknamesIter = nicknames->begin();
+       for(; nicknamesIter != nicknames->end(); nicknamesIter++)
+       {
+               string nickname = *nicknamesIter;
+
+               if(nickname.empty())
+               {
+                       LogDebug("nickname was not set.");
+                       continue;
+               }
+
+               child_record = NULL;
+
+               errorCode = contacts_record_create(_contacts_nickname._uri, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to create child_record with contacts_record_create(_contacts_nickname._uri)");
+                       continue;
+               }
+
+               errorCode = contacts_record_set_str(child_record, _contacts_nickname.name, nickname.c_str());
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set nickname value to ctsValue str : " << nickname);
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+
+               errorCode = contacts_record_add_child_record(m_platformContact, _contacts_contact.nickname, child_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to set nickname value to child_record");
+                       contacts_record_destroy(child_record, true);
+                       continue;
+               }
+       }
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactObjectA2PConverter.h b/src/platform/Tizen/Contact/ContactObjectA2PConverter.h
new file mode 100755 (executable)
index 0000000..b58d452
--- /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.
+//
+
+/*
+ * @file        ContactObjectA2PConverter.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Converter (TizenApis::Api::Contact::ContactPtr -> contacts_record_h)
+ */
+
+#ifndef _PLATFORM_CONTACT_CONTACT_OBJECT_A2P_CONVERTER_H_
+#define _PLATFORM_CONTACT_CONTACT_OBJECT_A2P_CONVERTER_H_
+
+#include <string>
+#include <contacts.h>
+#include <dpl/shared_ptr.h>
+#include <API/Contact/IContact.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class ContactObjectA2PConverter
+{
+public:
+       ContactObjectA2PConverter(const TizenApis::Api::Contact::ContactPtr &abstractContact,
+                              bool forScratch);
+       ContactObjectA2PConverter(const TizenApis::Api::Contact::ContactPtr &abstractContact,
+                                 bool forScratch,
+                                 contacts_record_h platformContact);
+       virtual ~ContactObjectA2PConverter();
+
+       contacts_record_h getPlatformContact();
+
+protected:
+       void convertToPlatformObject();
+
+       void importBaseInfoValue();
+
+       void importNameValue();
+       void importNameValueToExistingValue(contacts_record_h ctsValue,
+                                                   TizenApis::Api::Contact::ContactNamePtr &contactName);
+       void importNameValueToNewValue(contacts_record_h ctsValue,
+                                      TizenApis::Api::Contact::ContactNamePtr &contactName);
+
+       void importCompanyList();
+
+       void importNoteList();
+
+       void importNumberList();
+
+       void importEmailList();
+
+       void importGrouprelList();
+
+       void importEventList();
+       void importEventListBirthday();
+       void importEventListAnniversary();
+
+       void importPostalList();
+
+       void importWebAddrList();
+
+       void importNicknameList();
+
+       TizenApis::Api::Contact::ContactPtr m_abstractContact;
+       contacts_record_h                   m_platformContact;
+       bool                                m_forScratch;
+       bool                                m_convertFinished;
+       bool                                m_platformContactOwnership;
+};
+typedef DPL::SharedPtr<ContactObjectA2PConverter> ContactObjectA2PConverterPtr;
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_CONTACT_ABSTRACT_OBJECT_WRAPPER_H_
diff --git a/src/platform/Tizen/Contact/ContactObjectP2AConverter.cpp b/src/platform/Tizen/Contact/ContactObjectP2AConverter.cpp
new file mode 100755 (executable)
index 0000000..c1f8672
--- /dev/null
@@ -0,0 +1,845 @@
+//
+// 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        ContactObjectP2AConverter.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Converter (contacts_record_h -> TizenApis::Api::Contact::ContactPtr)
+ */
+
+#include "ContactObjectP2AConverter.h"
+
+#include <vector>
+#include <pcrecpp.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+#include "AddressBook.h"
+#include "Contact.h"
+#include "ContactUtility.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+ContactObjectP2AConverter::ContactObjectP2AConverter(contacts_record_h platformContact,
+               bool forScratch) :
+               m_platformContact(platformContact),
+               m_abstractContact(ContactPtr(NULL)),
+               m_forScratch(forScratch),
+               m_convertFinished(false)
+{
+}
+
+ContactObjectP2AConverter::ContactObjectP2AConverter(contacts_record_h platformContact,
+               bool forScratch,
+               ContactPtr &abstractContact) :
+               m_platformContact(platformContact),
+               m_abstractContact(abstractContact),
+               m_forScratch(forScratch),
+               m_convertFinished(false)
+{
+}
+
+ContactObjectP2AConverter::~ContactObjectP2AConverter()
+{
+}
+
+ContactPtr ContactObjectP2AConverter::getAbstractContact()
+{
+       //LogDebug("enter");
+
+       if(m_platformContact == NULL)
+       {
+               LogError("Platform contact object did not set");
+               ThrowMsg(InvalidArgumentException, "Platform contact object did not set");
+       }
+
+       if(m_abstractContact == NULL)
+       {
+               //LogDebug("Abstract contact object did not set, so a new object has been created");
+               m_abstractContact = ContactPtr(new Contact());
+       }
+
+       //LogDebug("for scratch : " << m_forScratch);
+
+       Try
+       {
+               if(m_convertFinished == false)
+                       convertToAbstractObject();
+       }
+       Catch(Exception)
+       {
+               LogError("Error while converting - " << _rethrown_exception.GetMessage());
+               ThrowMsg(PlatformException, "Fail to convert platform object to abstract object.");
+       }
+
+       return m_abstractContact;
+}
+
+void ContactObjectP2AConverter::convertToAbstractObject()
+{
+       exportBaseInfoValue();
+       exportNameValue();
+       exportCompanyList();
+       exportNoteList();
+       exportNumberList();
+       exportEmailList();
+       exportGrouprelList();
+       exportEventList();
+       exportPostalList();
+       exportWebAddrList();
+       exportNicknameList();
+
+       m_convertFinished = true;
+}
+
+void ContactObjectP2AConverter::exportBaseInfoValue()
+{
+       int errorCode = 0;
+
+       if(!m_forScratch)
+       {
+               int id = 0;
+               contacts_record_get_int(m_platformContact, _contacts_contact.id, &id);
+               m_abstractContact->setId(id);
+
+               int addressBookId = 0;
+               contacts_record_get_int(m_platformContact, _contacts_contact.address_book_id, &addressBookId);
+               m_abstractContact->setAddressBookId(addressBookId);
+
+               int personId = 0;
+               contacts_record_get_int(m_platformContact, _contacts_contact.person_id, &personId);
+               m_abstractContact->setPersonId(personId);
+
+               int changedTime = 0;
+               contacts_record_get_int(m_platformContact, _contacts_contact.changed_time, &changedTime);
+               time_t changedTimeT = static_cast<time_t>(changedTime);
+               struct tm *changedTimeTm = gmtime(&changedTimeT);
+               m_abstractContact->setLastUpdated(*changedTimeTm);
+
+               bool isFavorite = false;
+               errorCode = contacts_record_get_bool(m_platformContact, _contacts_contact.is_favorite, &isFavorite);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       LogError("contacts_record_get_bool returned " << errorCode);
+               m_abstractContact->setIsFavorite(isFavorite);
+       }
+
+       char *charValue = NULL;
+
+       contacts_record_get_str_p(m_platformContact, _contacts_contact.image_thumbnail_path, &charValue);
+       if (charValue)
+               m_abstractContact->setPhotoURI(ContactUtility::convertPathToUri(charValue));
+       else
+       {
+               if(m_abstractContact->getPhotoURIIsSet())
+                       m_abstractContact->unsetPhotoURI();
+       }
+
+       contacts_record_get_str_p(m_platformContact, _contacts_contact.ringtone_path, &charValue);
+       if (charValue)
+               m_abstractContact->setRingtoneURI(ContactUtility::convertPathToUri(charValue));
+       else
+       {
+               if(m_abstractContact->getRingtoneURIIsSet())
+                       m_abstractContact->unsetRingtoneURI();
+       }
+
+       if(!m_forScratch)
+       {
+               contacts_record_get_str_p(m_platformContact, _contacts_contact.display_name, &charValue);
+               if (charValue)
+               {
+                       ContactNamePtr contactName = m_abstractContact->getName();
+                       if(contactName == NULL)
+                       {
+                               contactName = ContactNamePtr(new ContactName());
+                               m_abstractContact->setName(contactName);
+                       }
+                       contactName->setDisplayName(charValue);
+               }
+//             else
+//                     ThrowMsg(UnknownException, "converting base data (no display name)");
+       }
+}
+
+void ContactObjectP2AConverter::exportNameValue()
+{
+       int errorCode = 0;
+       contacts_record_h child_record = NULL;
+
+       errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.name, 0, &child_record);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+               ThrowMsg(UnknownException, "getting name value (err:" << errorCode << ")");
+
+       if(child_record == NULL || errorCode == CONTACTS_ERROR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have name value");
+               ContactNamePtr contactName = m_abstractContact->getName();
+               if(contactName != NULL)
+               {
+                       if(contactName->getFirstNameIsSet())
+                               contactName->unsetFirstName();
+
+                       if(contactName->getMiddleNameIsSet())
+                               contactName->unsetMiddleName();
+
+                       if(contactName->getLastNameIsSet())
+                               contactName->unsetLastName();
+
+                       if(contactName->getPrefixIsSet())
+                               contactName->unsetPrefix();
+
+                       if(contactName->getSuffixIsSet())
+                               contactName->unsetSuffix();
+
+                       if(contactName->getPhoneticFirstNameIsSet())
+                               contactName->unsetPhoneticFirstName();
+
+                       if(contactName->getPhoneticLastNameIsSet())
+                               contactName->unsetPhoneticLastName();
+               }
+               return;
+       }
+
+       ContactNamePtr contactName = m_abstractContact->getName();
+       if(contactName == NULL)
+       {
+               contactName = ContactNamePtr(new ContactName());
+               m_abstractContact->setName(contactName);
+       }
+
+       char *charValue = NULL;
+
+       contacts_record_get_str_p(child_record, _contacts_name.first, &charValue);
+       if (charValue)
+               contactName->setFirstName(charValue);
+       else
+       {
+               if(contactName->getFirstNameIsSet())
+                       contactName->unsetFirstName();
+       }
+
+       contacts_record_get_str_p(child_record, _contacts_name.addition, &charValue);
+       if (charValue)
+               contactName->setMiddleName(charValue);
+       else
+       {
+               if(contactName->getMiddleNameIsSet())
+                       contactName->unsetMiddleName();
+       }
+
+       contacts_record_get_str_p(child_record, _contacts_name.last, &charValue);
+       if (charValue)
+               contactName->setLastName(charValue);
+       else
+       {
+               if(contactName->getLastNameIsSet())
+                       contactName->unsetLastName();
+       }
+
+       contacts_record_get_str_p(child_record, _contacts_name.prefix, &charValue);
+       if (charValue)
+               contactName->setPrefix(charValue);
+       else
+       {
+               if(contactName->getPrefixIsSet())
+                       contactName->unsetPrefix();
+       }
+
+       contacts_record_get_str_p(child_record, _contacts_name.suffix, &charValue);
+       if (charValue)
+               contactName->setSuffix(charValue);
+       else
+       {
+               if(contactName->getSuffixIsSet())
+                       contactName->unsetSuffix();
+       }
+
+       contacts_record_get_str_p(child_record, _contacts_name.phonetic_first, &charValue);
+       if (charValue)
+               contactName->setPhoneticFirstName(charValue);
+       else
+       {
+               if(contactName->getPhoneticFirstNameIsSet())
+                       contactName->unsetPhoneticFirstName();
+       }
+
+       contacts_record_get_str_p(child_record, _contacts_name.phonetic_last, &charValue);
+       if (charValue)
+               contactName->setPhoneticLastName(charValue);
+       else
+       {
+               if(contactName->getPhoneticLastNameIsSet())
+                       contactName->unsetPhoneticLastName();
+       }
+}
+
+void ContactObjectP2AConverter::exportCompanyList()
+{
+       int errorCode = 0;
+       unsigned int child_count = 0;
+
+       if(m_abstractContact->getOrganizationsNum() > 0)
+               m_abstractContact->clearOrganizations();
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.company, &child_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+               ThrowMsg(UnknownException, "getting company list (err:" << errorCode << ")");
+
+       if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have company list");
+               return;
+       }
+
+       ContactOrganizationArrayPtr organizations = m_abstractContact->getOrganizations();
+
+       for(unsigned int i=0; i<child_count; i++)
+       {
+               contacts_record_h child_record = NULL;
+
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.company, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+                       continue;
+
+               ContactOrganizationPtr organization(new ContactOrganization());
+
+               organizations->push_back(organization);
+
+               char *charValue = NULL;
+
+               contacts_record_get_str_p(child_record, _contacts_company.name, &charValue);
+               if (charValue)
+                       organization->setName(charValue);
+               else
+               {
+                       if(organization->getNameIsSet())
+                               organization->unsetName();
+               }
+
+               contacts_record_get_str_p(child_record, _contacts_company.department, &charValue);
+               if (charValue)
+                       organization->setDepartment(charValue);
+               else
+               {
+                       if(organization->getDepartmentIsSet())
+                               organization->unsetDepartment();
+               }
+
+               contacts_record_get_str_p(child_record, _contacts_company.job_title, &charValue);
+               if (charValue)
+                       organization->setTitle(charValue);
+               else
+               {
+                       if(organization->getTitleIsSet())
+                               organization->unsetTitle();
+               }
+
+               contacts_record_get_str_p(child_record, _contacts_company.role, &charValue);
+               if (charValue)
+                       organization->setRole(charValue);
+               else
+               {
+                       if(organization->getRoleIsSet())
+                               organization->unsetRole();
+               }
+
+               contacts_record_get_str_p(child_record, _contacts_company.logo, &charValue);
+               if (charValue)
+                       organization->setLogoURI(ContactUtility::convertPathToUri(charValue));
+               else
+               {
+                       if(organization->getLogoURIIsSet())
+                               organization->unsetLogoURI();
+               }
+       }
+}
+
+void ContactObjectP2AConverter::exportNoteList()
+{
+       int errorCode = 0;
+       unsigned int child_count = 0;
+
+       if(m_abstractContact->getNotesNum() > 0)
+               m_abstractContact->clearNotes();
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.note, &child_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+               ThrowMsg(UnknownException, "getting note list (err:" << errorCode << ")");
+
+       if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have note list");
+               return;
+       }
+
+       StringArrayPtr notes = m_abstractContact->getNotes();
+
+       for(unsigned int i=0; i<child_count; i++)
+       {
+               contacts_record_h child_record = NULL;
+
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.note, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+                       continue;
+
+               char *charValue = NULL;
+
+               contacts_record_get_str_p(child_record, _contacts_note.note, &charValue);
+               if (charValue)
+                       notes->push_back(charValue);
+       }
+}
+
+void ContactObjectP2AConverter::exportNumberList()
+{
+       int errorCode = 0;
+       unsigned int child_count = 0;
+
+       if(m_abstractContact->getPhoneNumbersNum() > 0)
+               m_abstractContact->clearPhoneNumbers();
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.number, &child_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+               ThrowMsg(UnknownException, "getting number list (err:" << errorCode << ")");
+
+       if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have number list");
+               return;
+       }
+
+       ContactPhoneNumberArrayPtr phoneNumbers = m_abstractContact->getPhoneNumbers();
+
+       for(unsigned int i=0; i<child_count; i++)
+       {
+               contacts_record_h child_record = NULL;
+
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.number, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+                       continue;
+
+               ContactPhoneNumberPtr phoneNumber(new ContactPhoneNumber());
+
+               char *charValue = NULL;
+               bool boolValue = false;
+               int intValue = 0;
+
+               contacts_record_get_str_p(child_record, _contacts_number.number, &charValue);
+               if (charValue)
+               {
+                       phoneNumber->setNumber(charValue);
+                       phoneNumbers->push_back(phoneNumber);
+               }
+               else
+               {
+                       //LogDebug("Platform contact have a empty phone number");
+                       continue;
+               }
+
+               contacts_record_get_bool(child_record, _contacts_number.is_default, &boolValue);
+               phoneNumber->setIsDefault(boolValue);
+
+               contacts_record_get_int(child_record, _contacts_number.type, &intValue);
+               if(intValue & CONTACTS_NUMBER_TYPE_HOME)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_HOME);
+               if(intValue & CONTACTS_NUMBER_TYPE_WORK)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_WORK);
+               if(intValue & CONTACTS_NUMBER_TYPE_VOICE)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VOICE);
+               if(intValue & CONTACTS_NUMBER_TYPE_FAX)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_FAX);
+               if(intValue & CONTACTS_NUMBER_TYPE_MSG)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_MSG);
+               if(intValue & CONTACTS_NUMBER_TYPE_CELL)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CELL);
+               if(intValue & CONTACTS_NUMBER_TYPE_PAGER)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PAGER);
+               if(intValue & CONTACTS_NUMBER_TYPE_BBS)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_BBS);
+               if(intValue & CONTACTS_NUMBER_TYPE_MODEM)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_MODEM);
+               if(intValue & CONTACTS_NUMBER_TYPE_CAR)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CAR);
+               if(intValue & CONTACTS_NUMBER_TYPE_ISDN)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_ISDN);
+               if(intValue & CONTACTS_NUMBER_TYPE_VIDEO)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VIDEO);
+               if(intValue & CONTACTS_NUMBER_TYPE_PCS)
+                       phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PCS);
+
+               // TODO Will be added after type changed to string
+//             if(intValue & CONTACTS_NUMBER_TYPE_CUSTOM)
+//             {
+//                     contacts_record_get_str_p(child_record, _contacts_number.label, &charValue);
+//                     if (charValue)
+//                             phoneNumber->addType(CUSTOM);
+//             }
+       }
+}
+
+void ContactObjectP2AConverter::exportEmailList()
+{
+       int errorCode = 0;
+       unsigned int child_count = 0;
+
+       if(m_abstractContact->getEmailsNum() > 0)
+               m_abstractContact->clearEmails();
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.email, &child_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+               ThrowMsg(UnknownException, "getting email list (err:" << errorCode << ")");
+
+       if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have email list");
+               return;
+       }
+
+       ContactEmailAddressArrayPtr emails = m_abstractContact->getEmails();
+
+       for(unsigned int i=0; i<child_count; i++)
+       {
+               contacts_record_h child_record = NULL;
+
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.email, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+                       continue;
+
+               ContactEmailAddressPtr email(new ContactEmailAddress());
+
+               char *charValue = NULL;
+               bool boolValue = false;
+               int intValue = 0;
+
+               contacts_record_get_str_p(child_record, _contacts_email.email, &charValue);
+               if (charValue)
+               {
+                       email->setEmail(charValue);
+                       emails->push_back(email);
+               }
+               else
+               {
+                       //LogDebug("Platform contact have a empty email address");
+                       continue;
+               }
+
+               contacts_record_get_bool(child_record, _contacts_email.is_default, &boolValue);
+               email->setIsDefault(boolValue);
+
+               contacts_record_get_int(child_record, _contacts_email.type, &intValue);
+               if(intValue & CONTACTS_EMAIL_TYPE_HOME)
+                       email->addType(CONTACT_EMAIL_TYPE_HOME);
+               if(intValue & CONTACTS_EMAIL_TYPE_WORK)
+                       email->addType(CONTACT_EMAIL_TYPE_WORK);
+
+               // TODO Will be added after type changed to string
+//             if(intValue & CONTACTS_EMAIL_TYPE_CUSTOM)
+//             {
+//                     contacts_record_get_str_p(child_record, _contacts_email.label, &charValue);
+//                     if (charValue)
+//                             email->addType(CUSTOM);
+//             }
+       }
+}
+
+void ContactObjectP2AConverter::exportGrouprelList()
+{
+       int errorCode = 0;
+       unsigned int child_count = 0;
+
+       if(m_abstractContact->getGroupIdsNum() > 0)
+               m_abstractContact->clearGroupIds();
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.group_relation, &child_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+               ThrowMsg(UnknownException, "getting group list (err:" << errorCode << ")");
+
+       if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have group list");
+               return;
+       }
+
+       StringArrayPtr groupIds = m_abstractContact->getGroupIds();
+
+       for(unsigned int i=0; i<child_count; i++)
+       {
+               contacts_record_h child_record = NULL;
+
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.group_relation, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+                       continue;
+
+               int groupId;
+
+               contacts_record_get_int(child_record, _contacts_group_relation.group_id, &groupId);
+
+               groupIds->push_back(ContactUtility::intToStr(groupId));
+       }
+}
+
+void ContactObjectP2AConverter::exportEventList()
+{
+       int errorCode = 0;
+       unsigned int child_count = 0;
+
+       if(m_abstractContact->getAnniversariesNum() > 0)
+               m_abstractContact->clearAnniversaries();
+
+       if(m_abstractContact->getBirthdayIsSet())
+               m_abstractContact->unsetBirthday();
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.event, &child_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+               ThrowMsg(UnknownException, "getting event list (err:" << errorCode << ")");
+
+       if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have group list");
+               return;
+       }
+
+       ContactAnniversaryArrayPtr anniversaries = m_abstractContact->getAnniversaries();
+
+       for(unsigned int i=0; i<child_count; i++)
+       {
+               contacts_record_h child_record = NULL;
+
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.event, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+                       continue;
+
+               char *charValue = NULL;
+               int intValueType = 0;
+               int intValueDate = 0;
+
+               contacts_record_get_int(child_record, _contacts_event.date, &intValueDate);
+
+               tm tmDate = {0, };
+
+               Try {
+                       tmDate = ContactUtility::toDateTmFromDateDbInt(intValueDate);
+               } Catch(Exception) {
+                       LogError("date has wrong value");
+               }
+
+               contacts_record_get_int(child_record, _contacts_event.type, &intValueType);
+               if (intValueType == CONTACTS_EVENT_TYPE_BIRTH)
+               {
+                       m_abstractContact->setBirthday(tmDate);
+               }
+               else if(intValueType == CONTACTS_EVENT_TYPE_ANNIVERSARY)
+               {
+                       ContactAnniversaryPtr anniversary = ContactAnniversaryPtr(new ContactAnniversary());
+
+                       anniversary->setDate(tmDate);
+                       contacts_record_get_str_p(child_record, _contacts_event.label, &charValue);
+                       if(charValue)
+                               anniversary->setLabel(charValue);
+
+                       anniversaries->push_back(anniversary);
+               }
+       }
+}
+
+void ContactObjectP2AConverter::exportPostalList()
+{
+       int errorCode = 0;
+       unsigned int child_count = 0;
+
+       if(m_abstractContact->getAddressesNum() > 0)
+               m_abstractContact->clearAddresses();
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.address, &child_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+               ThrowMsg(UnknownException, "getting address list (err:" << errorCode << ")");
+
+       if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have address list");
+               return;
+       }
+
+       ContactAddressArrayPtr addresss = m_abstractContact->getAddresses();
+
+       for(unsigned int i=0; i<child_count; i++)
+       {
+               contacts_record_h child_record = NULL;
+
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.address, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+                       continue;
+
+               ContactAddressPtr address(new ContactAddress());
+
+               char *charValue = NULL;
+               bool boolValue = false;
+               int intValue = 0;
+
+               addresss->push_back(address);
+
+               contacts_record_get_str_p(child_record, _contacts_address.postal_code, &charValue);
+               if (charValue)
+                       address->setPostalCode(charValue);
+
+               contacts_record_get_str_p(child_record, _contacts_address.region, &charValue);
+               if (charValue)
+                       address->setRegion(charValue);
+
+               contacts_record_get_str_p(child_record, _contacts_address.locality, &charValue);
+               if (charValue)
+                       address->setCity(charValue);
+
+               contacts_record_get_str_p(child_record, _contacts_address.street, &charValue);
+               if (charValue)
+                       address->setStreetAddress(charValue);
+
+               contacts_record_get_str_p(child_record, _contacts_address.extended, &charValue);
+               if (charValue)
+                       address->setAdditionalInformation(charValue);
+
+               contacts_record_get_str_p(child_record, _contacts_address.country, &charValue);
+               if (charValue)
+                       address->setCountry(charValue);
+
+               contacts_record_get_bool(child_record, _contacts_address.is_default, &boolValue);
+               address->setIsDefault(boolValue);
+
+               contacts_record_get_int(child_record, _contacts_address.type, &intValue);
+               if(intValue & CONTACTS_ADDRESS_TYPE_HOME)
+                       address->addType(CONTACT_ADDRESS_TYPE_HOME);
+               if(intValue & CONTACTS_ADDRESS_TYPE_WORK)
+                       address->addType(CONTACT_ADDRESS_TYPE_WORK);
+
+               // TODO Will be added after type changed to string
+//             if(intValue & CONTACTS_ADDRESS_TYPE_CUSTOM)
+//             {
+//                     contacts_record_get_str_p(child_record, _contacts_address.label, &charValue);
+//                     if (charValue)
+//                             address->addType(CUSTOM);
+//             }
+       }
+}
+
+void ContactObjectP2AConverter::exportWebAddrList()
+{
+       int errorCode = 0;
+       unsigned int child_count = 0;
+
+       if(m_abstractContact->getUrlsNum() > 0)
+               m_abstractContact->clearUrls();
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.url, &child_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+               ThrowMsg(UnknownException, "getting address list (err:" << errorCode << ")");
+
+       if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have address list");
+               return;
+       }
+
+       ContactWebSiteArrayPtr urls = m_abstractContact->getUrls();
+
+       for(unsigned int i=0; i<child_count; i++)
+       {
+               contacts_record_h child_record = NULL;
+
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.url, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+                       continue;
+
+               ContactWebSitePtr url(new ContactWebSite());
+
+               char *charValue = NULL;
+               int intValue = 0;
+
+               urls->push_back(url);
+
+               contacts_record_get_str_p(child_record, _contacts_url.url, &charValue);
+               if (charValue)
+                       url->setUrl(charValue);
+
+               contacts_record_get_int(child_record, _contacts_url.type, &intValue);
+               if(intValue == CONTACTS_URL_TYPE_HOME)
+                       url->setType(WEBSITE_TYPE_HOMEPAGE);
+               else if(intValue == CONTACTS_URL_TYPE_WORK)
+                       url->setType(WEBSITE_TYPE_BLOG);
+
+               // TODO Will be added after type changed to string
+//             if(intValue & CONTACTS_URL_TYPE_CUSTOM)
+//             {
+//                     contacts_record_get_int(child_record, _contacts_url.label, &intValue);
+//                     if (charValue)
+//                             url->setType(CUSTOM);
+//             }
+       }
+}
+
+void ContactObjectP2AConverter::exportNicknameList()
+{
+       int errorCode = 0;
+       unsigned int child_count = 0;
+
+       ContactNamePtr contactName = m_abstractContact->getName();
+       if(contactName == NULL)
+       {
+               contactName = ContactNamePtr(new ContactName());
+               m_abstractContact->setName(contactName);
+       }
+
+       if(contactName->getNicknamesNum() > 0)
+               contactName->clearNicknames();
+
+       errorCode = contacts_record_get_child_record_count(m_platformContact, _contacts_contact.nickname, &child_count);
+       if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+               ThrowMsg(UnknownException, "getting nickname list (err:" << errorCode << ")");
+
+       if(child_count == 0 || errorCode == CONTACTS_ERROR_NO_DATA)
+       {
+               //LogDebug("Platform contact don't have nickname list");
+               return;
+       }
+
+       StringArrayPtr nicknames = contactName->getNicknames();
+
+       for(unsigned int i=0; i<child_count; i++)
+       {
+               contacts_record_h child_record = NULL;
+
+               errorCode = contacts_record_get_child_record_at_p(m_platformContact, _contacts_contact.nickname, i, &child_record);
+               if(errorCode != CONTACTS_ERROR_NONE && errorCode != CONTACTS_ERROR_NO_DATA)
+                       continue;
+
+               char *charValue = NULL;
+
+               contacts_record_get_str_p(child_record, _contacts_nickname.name, &charValue);
+               if (charValue)
+                       nicknames->push_back(charValue);
+       }
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactObjectP2AConverter.h b/src/platform/Tizen/Contact/ContactObjectP2AConverter.h
new file mode 100755 (executable)
index 0000000..5f9fac7
--- /dev/null
@@ -0,0 +1,75 @@
+//
+// 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        ContactObjectP2AConverter.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Converter (contacts_record_h -> TizenApis::Api::Contact::ContactPtr)
+ */
+
+#ifndef _PLATFORM_CONTACT_CONTACT_OBJECT_P2A_CONVERTER_H_
+#define _PLATFORM_CONTACT_CONTACT_OBJECT_P2A_CONVERTER_H_
+
+#include <string>
+#include <contacts.h>
+#include <dpl/shared_ptr.h>
+#include <API/Contact/IContact.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class ContactObjectP2AConverter
+{
+public:
+       ContactObjectP2AConverter(contacts_record_h platformContact,
+                                 bool forScratch);
+       ContactObjectP2AConverter(contacts_record_h platformContact,
+                                 bool forScratch,
+                                 TizenApis::Api::Contact::ContactPtr &abstractContact);
+       virtual ~ContactObjectP2AConverter();
+
+       TizenApis::Api::Contact::ContactPtr getAbstractContact();
+
+protected:
+       void convertToAbstractObject();
+
+       void exportBaseInfoValue();
+       void exportNameValue();
+       void exportCompanyList();
+       void exportNoteList();
+       void exportNumberList();
+       void exportEmailList();
+       void exportGrouprelList();
+       void exportEventList();
+       void exportPostalList();
+       void exportWebAddrList();
+       void exportNicknameList();
+
+       contacts_record_h                   m_platformContact;
+       TizenApis::Api::Contact::ContactPtr m_abstractContact;
+       bool                                m_forScratch;
+       bool                                m_convertFinished;
+};
+typedef DPL::SharedPtr<ContactObjectP2AConverter> ContactObjectP2AConverterPtr;
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_CONTACT_OBJECT_P2A_CONVERTER_H_
diff --git a/src/platform/Tizen/Contact/ContactSearchEngine.cpp b/src/platform/Tizen/Contact/ContactSearchEngine.cpp
new file mode 100755 (executable)
index 0000000..2bdd073
--- /dev/null
@@ -0,0 +1,1117 @@
+//
+// 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        ContactSearchEngine.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactSearchEngine.h"
+
+#include <contacts.h>
+#include <ctime>
+#include <algorithm>
+#include <limits>
+#include <iomanip>
+#include <Commons/Exception.h>
+#include "Contact.h"
+#include "ContactObjectP2AConverter.h"
+#include "ContactUtility.h"
+
+#define _CONTACTS_SVC_QUERY_FUNC_PREFIX(view_uri, query, filter) \
+       do { \
+               if((errorCode = contacts_query_create(view_uri, &query)) != CONTACTS_ERROR_NONE) \
+                       ThrowMsg(PlatformException, "contacts_query_create error : " << errorCode << " (" << __FUNCTION__ << ")"); \
+               if((errorCode = contacts_filter_create(view_uri, &filter)) != CONTACTS_ERROR_NONE) \
+                       ThrowMsg(PlatformException, "contacts_filter_create error : " << errorCode << " (" << __FUNCTION__ << ")"); \
+       } while(0)
+
+#define _CONTACTS_SVC_QUERY_FUNC_SUFFIX(query, filter, list, property_contact_id, result) \
+       do { \
+               if((errorCode = contacts_query_set_filter(query, filter)) != CONTACTS_ERROR_NONE) \
+                       ThrowMsg(PlatformException, "contacts_query_set_filter error : " << errorCode << " (" << __FUNCTION__ << ")"); \
+               if((errorCode = contacts_db_get_records_with_query(query, 0, 0, &list)) != CONTACTS_ERROR_NONE) \
+                       ThrowMsg(PlatformException, "contacts_db_get_records_with_query error : " << errorCode << " (" << __FUNCTION__ << ")"); \
+               unsigned int record_count = 0; \
+               if((errorCode = contacts_list_get_count(list, &record_count)) != CONTACTS_ERROR_NONE) \
+                       ThrowMsg(PlatformException, "contacts_list_get_count error : " << errorCode << " (" << __FUNCTION__ << ")"); \
+               contacts_list_first(list); \
+               for(unsigned int i=0; i<record_count; i++) { \
+                       contacts_record_h record; \
+                       if((errorCode = contacts_list_get_current_record_p(list, &record)) != CONTACTS_ERROR_NONE) \
+                               ThrowMsg(PlatformException, "contacts_list_get_current_record_p error : " << errorCode << " (" << __FUNCTION__ << ")"); \
+                       int value = 0; \
+                       if((errorCode = contacts_record_get_int(record, property_contact_id, &value)) != CONTACTS_ERROR_NONE) \
+                               ThrowMsg(PlatformException, "contacts_record_get_int error : " << errorCode << " (" << __FUNCTION__ << ")"); \
+                       result->insert(value); \
+                       contacts_list_next(list); \
+               } \
+               if(list != NULL) \
+                       contacts_list_destroy(list, true); \
+               if(filter != NULL) \
+                       contacts_filter_destroy(filter); \
+               if(query != NULL) \
+                       contacts_query_destroy(query); \
+       } while(0)
+
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+ContactSearchEngine::AttributePropertiesMap ContactSearchEngine::attributePropertiesMap = {
+               {"id",                      { _contacts_simple_contact._uri, _contacts_simple_contact.id, _contacts_simple_contact.id, ContactSearchEngine::ContactSvcPrimitiveType_Int, PrimitiveType_String } },
+               {"personId",                { _contacts_simple_contact._uri, _contacts_simple_contact.id, _contacts_simple_contact.person_id, ContactSearchEngine::ContactSvcPrimitiveType_Int, PrimitiveType_String } },
+               {"addressBookId",           { _contacts_simple_contact._uri, _contacts_simple_contact.id, _contacts_simple_contact.address_book_id, ContactSearchEngine::ContactSvcPrimitiveType_Int, PrimitiveType_String } },
+               {"lastUpdated",             { _contacts_simple_contact._uri, _contacts_simple_contact.id, _contacts_simple_contact.changed_time, ContactSearchEngine::ContactSvcPrimitiveType_Int, PrimitiveType_Time } },
+               {"isFavorite",              { _contacts_simple_contact._uri, _contacts_simple_contact.id, _contacts_simple_contact.is_favorite, ContactSearchEngine::ContactSvcPrimitiveType_Boolean, PrimitiveType_Boolean } },
+               {"name.prefix",             { _contacts_name._uri, _contacts_name.contact_id, _contacts_name.prefix, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"name.suffix",             { _contacts_name._uri, _contacts_name.contact_id, _contacts_name.suffix, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"name.firstName",          { _contacts_name._uri, _contacts_name.contact_id, _contacts_name.first, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"name.middleName",         { _contacts_name._uri, _contacts_name.contact_id, _contacts_name.addition, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"name.lastName",           { _contacts_name._uri, _contacts_name.contact_id, _contacts_name.last, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"name.nicknames",          { _contacts_nickname._uri, _contacts_nickname.contact_id, _contacts_nickname.name, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"name.phoneticFirstName",  { _contacts_name._uri, _contacts_name.contact_id, _contacts_name.phonetic_first, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"name.phoneticLastName",   { _contacts_name._uri, _contacts_name.contact_id, _contacts_name.phonetic_last, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"name.displayName",        { _contacts_simple_contact._uri, _contacts_simple_contact.id, _contacts_simple_contact.display_name, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"addresses.country",       { _contacts_address._uri, _contacts_address.contact_id, _contacts_address.country, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"addresses.region",        { _contacts_address._uri, _contacts_address.contact_id, _contacts_address.region, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"addresses.city",          { _contacts_address._uri, _contacts_address.contact_id, _contacts_address.locality, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"addresses.streetAddress", { _contacts_address._uri, _contacts_address.contact_id, _contacts_address.street, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"addresses.additionalInformation", { _contacts_address._uri, _contacts_address.contact_id, _contacts_address.extended, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"addresses.postalCode",    { _contacts_address._uri, _contacts_address.contact_id, _contacts_address.postal_code, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"addresses.isDefault",     { _contacts_address._uri, _contacts_address.contact_id, _contacts_address.is_default, ContactSearchEngine::ContactSvcPrimitiveType_Boolean, PrimitiveType_Boolean } },
+               {"addresses.types",         { _contacts_address._uri, _contacts_address.contact_id, _contacts_address.type, ContactSearchEngine::ContactSvcPrimitiveType_Int, PrimitiveType_Long } },
+               {"photoURI",                { _contacts_simple_contact._uri, _contacts_simple_contact.id, _contacts_simple_contact.image_thumbnail_path, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"phoneNumbers.number",     { _contacts_number._uri, _contacts_number.contact_id, _contacts_number.number, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"phoneNumbers.isDefault",  { _contacts_number._uri, _contacts_number.contact_id, _contacts_number.is_default, ContactSearchEngine::ContactSvcPrimitiveType_Boolean, PrimitiveType_Boolean } },
+               {"phoneNumbers.types",      { _contacts_number._uri, _contacts_number.contact_id, _contacts_number.type, ContactSearchEngine::ContactSvcPrimitiveType_Int, PrimitiveType_Long } },
+               {"emails.email",            { _contacts_email._uri, _contacts_email.contact_id, _contacts_email.email, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"emails.isDefault",        { _contacts_email._uri, _contacts_email.contact_id, _contacts_email.is_default, ContactSearchEngine::ContactSvcPrimitiveType_Boolean, PrimitiveType_Boolean } },
+               {"emails.types",            { _contacts_email._uri, _contacts_email.contact_id, _contacts_email.type, ContactSearchEngine::ContactSvcPrimitiveType_Int, PrimitiveType_Long } },
+               {"birthday",                { _contacts_event._uri, _contacts_event.contact_id, _contacts_event.date, ContactSearchEngine::ContactSvcPrimitiveType_Int, PrimitiveType_Long } },
+               {"anniversaries.date",      { _contacts_event._uri, _contacts_event.contact_id, _contacts_event.date, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"anniversaries.label",     { _contacts_event._uri, _contacts_event.contact_id, _contacts_event.label, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"organizations.name",      { _contacts_company._uri, _contacts_company.contact_id, _contacts_company.name, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"organizations.department",{ _contacts_company._uri, _contacts_company.contact_id, _contacts_company.department, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"organizations.title",     { _contacts_company._uri, _contacts_company.contact_id, _contacts_company.job_title, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"organizations.role",      { _contacts_company._uri, _contacts_company.contact_id, _contacts_company.role, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"organizations.logoURI",   { _contacts_company._uri, _contacts_company.contact_id, _contacts_company.logo, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"notes",                   { _contacts_note._uri, _contacts_note.contact_id, _contacts_note.note, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"urls.url",                { _contacts_url._uri, _contacts_url.contact_id, _contacts_url.url, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"urls.type",               { _contacts_url._uri, _contacts_url.contact_id, _contacts_url.type, ContactSearchEngine::ContactSvcPrimitiveType_Int, PrimitiveType_Long } },
+               {"ringtoneURI",             { _contacts_simple_contact._uri, _contacts_simple_contact.id, _contacts_simple_contact.ringtone_path, ContactSearchEngine::ContactSvcPrimitiveType_String, PrimitiveType_String } },
+               {"groupIds",                { _contacts_group_relation._uri, _contacts_group_relation.contact_id, _contacts_group_relation.group_id, ContactSearchEngine::ContactSvcPrimitiveType_Int, PrimitiveType_Long } }
+};
+
+ContactSearchEngine::ContactSearchEngine() :
+               m_addressBookId(0),
+               m_isAddressBookIdSet(false),
+               m_isFilterSet(false),
+               m_isSortModeSet(false),
+               m_sortOrder(ASCENDING_SORT_ORDER)
+{
+}
+
+ContactSearchEngine::~ContactSearchEngine()
+{
+}
+
+void ContactSearchEngine::setAddressBookId(int id)
+{
+       m_addressBookId = id;
+       m_isAddressBookIdSet = true;
+}
+
+void ContactSearchEngine::setCondition(FilterPtr filter)
+{
+       if(!filter)
+               return;
+
+       IFilterVisitorPtr filterQuery = DPL::StaticPointerCast<IFilterVisitor>(SharedFromThis());
+       filter->travel(filterQuery);
+
+       if(m_filteredContactIds != NULL)
+               m_isFilterSet = true;
+}
+
+void ContactSearchEngine::setSortMode(SortModePtr attr)
+{
+       if(!attr)
+               return;
+
+       m_sortOrder = attr->getOrder();
+       m_attributeNameForSort = attr->getAttributeName();
+
+       AttributePropertiesMap::iterator iter =
+                       attributePropertiesMap.find(m_attributeNameForSort);
+       if(iter == attributePropertiesMap.end())
+               ThrowMsg(NotFoundException, "There is no attribute name for sorting : " << m_attributeNameForSort);
+
+       m_isSortModeSet = true;
+}
+
+ContactArrayPtr ContactSearchEngine::getContactSearchResult()
+{
+       ContactArrayPtr result(NULL);
+
+       LogDebug("entered");
+       if(m_isFilterSet)
+       {
+               if(m_isSortModeSet)
+               {
+                       ContactIdArrayPtr ids = ContactIdArrayPtr(new ContactIdArray());
+
+                       AttributePropertiesMap::iterator iter =
+                                       attributePropertiesMap.find(m_attributeNameForSort);
+                       AttributeProperties &property = iter->second;
+
+                       sortContacts(property, ids, m_sortOrder, m_filteredContactIds);
+                       result = getContacts(ids);
+               }
+               else
+               {
+                       result = getContacts(m_filteredContactIds);
+               }
+       }
+       else
+       {
+               if(m_isSortModeSet)
+               {
+                       AttributePropertiesMap::iterator iter =
+                                       attributePropertiesMap.find(m_attributeNameForSort);
+                       AttributeProperties &property = iter->second;
+
+                       result = getAllContactsSorted(property, m_sortOrder);
+               }
+               else
+               {
+                       result = getAllContacts();
+               }
+       }
+       LogDebug("End");
+
+       return result;
+}
+
+void ContactSearchEngine::visitPreComposite(FilterType& type, int depth)
+{
+       ContactIdSetArrayPtr idSets = ContactIdSetArrayPtr(new ContactIdSetArray());
+
+       m_contactIdSetArrayStack.push(idSets);
+}
+
+void ContactSearchEngine::visitInComposite(FilterType& type, int depth)
+{
+       // Nothing to do
+}
+
+void ContactSearchEngine::visitPostComposite(FilterType& type, int depth)
+{
+       ContactIdSetArrayPtr idSets = m_contactIdSetArrayStack.top();
+       m_contactIdSetArrayStack.pop();
+
+       ContactIdSetPtr idSet = ContactIdSetPtr(new ContactIdSet());
+
+       if(type == UNION_FILTER)
+               getUnion(idSets, idSet);
+       else if(type == INTERSECTION_FILTER)
+               getIntersection(idSets, idSet);
+
+       if(depth == 0)
+       {
+               m_filteredContactIds = idSet;
+       }
+       else
+       {
+               if(idSet != NULL)
+               {
+                       ContactIdSetArrayPtr parentIdSets = m_contactIdSetArrayStack.top();
+                       parentIdSets->push_back(idSet);
+               }
+       }
+}
+
+void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag, AnyPtr& matchValue, int depth)
+{
+       ContactIdSetPtr idSet = ContactIdSetPtr(new ContactIdSet());
+
+       if(attrName == "id")
+       {
+               string value = matchValue->getString();
+               idSet->insert(ContactUtility::strToInt(value));
+
+               if(depth == 0)
+                       m_filteredContactIds = idSet;
+               else
+               {
+                       ContactIdSetArrayPtr parentIdSets = m_contactIdSetArrayStack.top();
+                       parentIdSets->push_back(idSet);
+               }
+
+               return;
+       }
+       else if(attrName == "addresses.types" ||
+                       attrName == "emails.types" ||
+                       attrName == "phoneNumbers.types" ||
+                       attrName == "urls.type")
+       {
+               if(depth == 0)
+                       m_filteredContactIds = ContactIdSetPtr(NULL);
+
+               return;
+       }
+
+       AttributePropertiesMap::iterator iter =
+                       attributePropertiesMap.find(attrName);
+       if(iter == attributePropertiesMap.end())
+               ThrowMsg(NotFoundException, "There is no attribute name for filter : " << attrName);
+       AttributeProperties &properties = iter->second;
+
+       if(properties.type == ContactSvcPrimitiveType_Boolean)
+       {
+               bool value = matchValue->getBool();
+
+               queryAttributeBool(properties, idSet, value);
+       }
+       else if(properties.type == ContactSvcPrimitiveType_String)
+       {
+               string value = matchValue->getString();
+               contacts_match_str_flag_e flag = CONTACTS_MATCH_EXISTS;
+
+               if(matchFlag == MATCH_EXACTLY)
+                       flag = CONTACTS_MATCH_EXACTLY;
+               else if(matchFlag == MATCH_FULLSTRING)
+                       flag = CONTACTS_MATCH_FULLSTRING;
+               else if(matchFlag == MATCH_CONTAINS)
+                       flag = CONTACTS_MATCH_CONTAINS;
+               else if(matchFlag == MATCH_STARTSWITH)
+                       flag = CONTACTS_MATCH_STARTSWITH;
+               else if(matchFlag == MATCH_ENDSWITH)
+                       flag = CONTACTS_MATCH_ENDSWITH;
+               else if(matchFlag == MATCH_EXISTS)
+                       flag = CONTACTS_MATCH_EXISTS;
+
+               queryAttributeString(properties, idSet, flag, value.c_str());
+       }
+       else if(properties.type == ContactSvcPrimitiveType_Int)
+       {
+               int value;
+
+               if(attrName == "id")
+                       value = ContactUtility::strToInt(matchValue->getString());
+               else
+                       value = matchValue->getInt();
+
+               contacts_match_int_flag_e flag;
+               if(matchFlag == MATCH_EXISTS)
+               {
+                       flag = CONTACTS_MATCH_GREATER_THAN_OR_EQUAL;
+                       value = 0;
+               }else{
+                       flag = CONTACTS_MATCH_EQUAL;
+               }
+
+               queryAttributeInt(properties, idSet, flag, value);
+       }
+
+       if(depth == 0)
+       {
+               m_filteredContactIds = idSet;
+       }
+       else
+       {
+               if(idSet != NULL)
+               {
+                       ContactIdSetArrayPtr parentIdSets = m_contactIdSetArrayStack.top();
+                       parentIdSets->push_back(idSet);
+               }
+       }
+}
+
+void ContactSearchEngine::visitAttributeRange(string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth)
+{
+       ContactIdSetPtr idSet = ContactIdSetPtr(new ContactIdSet());
+
+       bool initialValueIsSet = false;
+       bool endValueIsSet = false;
+
+       if(initialValue != NULL || initialValue->isNullOrUndefined())
+               initialValueIsSet = false;
+
+       if(endValue != NULL || endValue->isNullOrUndefined())
+               endValueIsSet = false;
+
+       if(!initialValueIsSet && !endValueIsSet)
+       {
+               if(depth == 0)
+                       m_filteredContactIds = ContactIdSetPtr(NULL);
+
+               return;
+       }
+
+       if(attrName == "id")
+       {
+               if(depth == 0)
+                       m_filteredContactIds = idSet;
+               else
+               {
+                       ContactIdSetArrayPtr parentIdSets = m_contactIdSetArrayStack.top();
+                       parentIdSets->push_back(idSet);
+               }
+
+               return;
+       }
+       else if(attrName == "addresses.types" ||
+                       attrName == "emails.types" ||
+                       attrName == "phoneNumbers.types" ||
+                       attrName == "urls.type")
+       {
+               if(depth == 0)
+                       m_filteredContactIds = ContactIdSetPtr(NULL);
+
+               return;
+       }
+
+       AttributePropertiesMap::iterator iter =
+                       attributePropertiesMap.find(attrName);
+       if(iter == attributePropertiesMap.end())
+               ThrowMsg(NotFoundException, "There is no attribute name for filter : " << attrName);
+       AttributeProperties &properties = iter->second;
+
+       if(properties.type == ContactSvcPrimitiveType_Boolean)
+       {
+               bool initialValueBool = false;
+               bool endValueBool = false;
+
+               if(initialValueIsSet)
+                       initialValueBool = initialValue->getBool();
+               if(endValueIsSet)
+                       endValueBool = endValue->getBool();
+
+               queryAttributeRangeBool(properties, idSet, initialValueIsSet, initialValueBool, endValueIsSet, endValueBool);
+       }
+       else if(properties.type == ContactSvcPrimitiveType_String)
+       {
+               const char *initialValueCStr = NULL;
+               const char *endValueCStr = NULL;
+
+               string initialValueStr;
+               string endValueStr;
+
+               if(initialValueIsSet)
+               {
+                       initialValueStr = initialValue->getString();
+                       initialValueCStr = initialValueStr.c_str();
+               }
+               if(endValueIsSet)
+               {
+                       endValueStr = endValue->getString();
+                       endValueCStr = endValueStr.c_str();
+               }
+
+               queryAttributeRangeString(properties, idSet, initialValueCStr, endValueCStr);
+       }
+       else if(properties.type == ContactSvcPrimitiveType_Int)
+       {
+               int initialValueInt = 0;
+               int endValueInt = 0;
+
+               if(attrName == "id")
+               {
+                       if(initialValueIsSet)
+                               initialValueInt = ContactUtility::strToInt(initialValue->getString());
+                       if(endValueIsSet)
+                               endValueInt = ContactUtility::strToInt(endValue->getString());
+               }
+               else
+               {
+                       if(initialValueIsSet)
+                               initialValueInt = initialValue->getInt();
+                       if(endValueIsSet)
+                               endValueInt = endValue->getInt();
+               }
+
+               queryAttributeRangeInt(properties, idSet, initialValueIsSet, initialValueInt, endValueIsSet, endValueInt);
+       }
+
+       if(depth == 0)
+       {
+               m_filteredContactIds = idSet;
+       }
+       else
+       {
+               ContactIdSetArrayPtr parentIdSets = m_contactIdSetArrayStack.top();
+               parentIdSets->push_back(idSet);
+       }
+}
+
+ContactArrayPtr ContactSearchEngine::getAllContactsSorted(AttributeProperties& attributeProperties, bool is_ascending)
+{
+       ContactArrayPtr contacts = ContactArrayPtr(new ContactArray());
+
+       ContactArrayPtr allContacts = getAllContacts();
+       ContactIdArrayPtr sortedIds = ContactIdArrayPtr(new ContactIdArray());
+
+       sortContacts(attributeProperties, sortedIds, is_ascending);
+
+       map<int,ContactPtr> contactMap;
+
+       ContactArray::iterator citer;
+       for(citer=allContacts->begin(); citer!=allContacts->end(); citer++)
+       {
+               ContactPtr contact = *citer;
+               int id = ContactUtility::strToInt(contact->getId());
+               contactMap.insert(pair<int,ContactPtr>(id, contact));
+       }
+
+       ContactIdArray::iterator iter;
+       for(iter=sortedIds->begin(); iter!=sortedIds->end(); iter++)
+       {
+               int id = *iter;
+
+               map<int,ContactPtr>::iterator idPair = contactMap.find(id);
+               if(idPair == contactMap.end())
+               {
+                       LogWarning("no contact id : " << id);
+                       continue;
+               }
+               contacts->push_back(idPair->second);
+       }
+
+       return contacts;
+}
+
+ContactArrayPtr ContactSearchEngine::getAllContacts()
+{
+       int errorCode = 0;
+
+       ContactArrayPtr contacts(new ContactArray());
+       contacts_list_h list = NULL;
+
+       LogDebug("start : " << m_isAddressBookIdSet);
+
+       if(!m_isAddressBookIdSet)
+       {
+               errorCode = contacts_db_get_all_records(_contacts_contact._uri, 0, 0, &list);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_db_get_all_records error : " << errorCode << " (" << __FUNCTION__ << ")");
+       }
+       else
+       {
+               contacts_query_h query = NULL;
+               contacts_filter_h filter = NULL;
+
+               errorCode = contacts_query_create(_contacts_contact._uri, &query);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Fail to get contacts_query_create (ret:" << errorCode << ")");
+
+               errorCode = contacts_filter_create(_contacts_contact._uri, &filter);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Fail to get contacts_filter_create (ret:" << errorCode << ")");
+
+               errorCode = contacts_filter_add_int(filter, _contacts_contact.address_book_id, CONTACTS_MATCH_EQUAL, m_addressBookId);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Fail to get contacts_filter_add_int (ret:" << errorCode << ")");
+
+               errorCode = contacts_query_set_filter(query, filter);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Fail to get contacts_query_set_filter (ret:" << errorCode << ")");
+
+               errorCode = contacts_db_get_records_with_query(query, 0, 0, &list);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Fail to get contacts_db_get_records_with_query (ret:" << errorCode << ")");
+
+               errorCode = contacts_filter_destroy(filter);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Fail to get contacts_filter_destroy (ret:" << errorCode << ")");
+
+               errorCode = contacts_query_destroy(query);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Fail to get contacts_query_destroy (ret:" << errorCode << ")");
+       }
+
+       unsigned int record_count = 0;
+       errorCode = contacts_list_get_count(list, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "Fail to get contacts_list_get_count : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       contacts_list_first(list);
+       for(unsigned int i=0; i<record_count; i++)
+       {
+               contacts_record_h record;
+               errorCode = contacts_list_get_current_record_p(list, &record);
+               if(errorCode != CONTACTS_ERROR_NONE || record == NULL)
+               {
+                       LogWarning("contacts_list_get_current_record_p error : " << errorCode << " (" << __FUNCTION__ << ")");
+                       continue;
+               }
+
+               ContactPtr contact(NULL);
+               Try
+               {
+                       ContactObjectP2AConverterPtr contactObjConverter(
+                                       new ContactObjectP2AConverter(record, false));
+
+                       contact = contactObjConverter->getAbstractContact();
+               }
+               Catch(Exception)
+               {
+                       LogWarning("fail to convert contact");
+                       continue;
+               }
+
+               contacts->push_back(contact);
+
+               contacts_list_next(list);
+       }
+
+       if(list != NULL)
+               contacts_list_destroy(list, true);
+
+       LogDebug("end");
+
+       return contacts;
+}
+
+ContactArrayPtr ContactSearchEngine::getContacts(ContactIdArrayPtr& ids)
+{
+       ContactArrayPtr contacts(new ContactArray());
+
+       ContactIdArray::iterator iter;
+       for(iter=ids->begin(); iter!=ids->end(); iter++)
+       {
+               Try
+               {
+                       ContactPtr contact = getContact(*iter);
+                       if(contact != NULL)
+                               contacts->push_back(contact);
+               }
+               Catch(Exception)
+               {
+                       LogWarning(_rethrown_exception.GetMessage());
+                       continue;
+               }
+       }
+
+       return contacts;
+}
+
+ContactArrayPtr ContactSearchEngine::getContacts(ContactIdSetPtr& ids)
+{
+       ContactArrayPtr contacts(new ContactArray());
+
+       ContactIdSet::iterator iter;
+       for(iter=ids->begin(); iter!=ids->end(); iter++)
+       {
+               Try
+               {
+                       ContactPtr contact = getContact(*iter);
+                       if(contact != NULL)
+                               contacts->push_back(contact);
+               }
+               Catch(Exception)
+               {
+                       LogWarning(_rethrown_exception.GetMessage());
+                       continue;
+               }
+       }
+       return contacts;
+}
+
+ContactPtr ContactSearchEngine::getContact(int id)
+{
+       int errorCode = 0;
+       contacts_record_h record = NULL;
+
+       errorCode = contacts_db_get_record(_contacts_contact._uri, id, &record);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogError("No contact (id:" << id << ") : " << errorCode << " (" << __FUNCTION__ << ")");
+               return ContactPtr(NULL);
+       }
+
+       if(m_isAddressBookIdSet)
+       {
+               int addressBookId = 0;
+
+               errorCode = contacts_record_get_int(record, _contacts_contact.address_book_id, &addressBookId);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogError("No contact (id:" << id << ") 2 : " << errorCode << " (" << __FUNCTION__ << ")");
+                       return ContactPtr(NULL);
+               }
+
+               if(addressBookId != m_addressBookId)
+                       return ContactPtr(NULL);
+       }
+
+       ContactObjectP2AConverterPtr contactObjConverter(
+                       new ContactObjectP2AConverter(record, false));
+       ContactPtr contact = contactObjConverter->getAbstractContact();
+
+       return contact;
+}
+
+void ContactSearchEngine::queryAttributeBool(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+               bool match_value)
+{
+       const char* view_uri = attributeProperties.viewUri;
+       unsigned int property_contact_id = attributeProperties.propertyContactId;
+       unsigned int property_id = attributeProperties.propertyId;
+
+       int errorCode = 0;
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h list = NULL;
+
+       _CONTACTS_SVC_QUERY_FUNC_PREFIX(view_uri, query, filter);
+
+       errorCode = contacts_filter_add_bool(filter, property_id, match_value);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               ThrowMsg(PlatformException, "contacts_filter_add_bool error : " << errorCode << " (" << __FUNCTION__ << ")");
+       }
+
+       _CONTACTS_SVC_QUERY_FUNC_SUFFIX(query, filter, list, property_contact_id, result);
+}
+
+void ContactSearchEngine::queryAttributeInt(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+               contacts_match_int_flag_e match, int match_value)
+{
+       const char* view_uri = attributeProperties.viewUri;
+       unsigned int property_contact_id = attributeProperties.propertyContactId;
+       unsigned int property_id = attributeProperties.propertyId;
+
+       int errorCode = 0;
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h list = NULL;
+
+       _CONTACTS_SVC_QUERY_FUNC_PREFIX(view_uri, query, filter);
+
+       errorCode = contacts_filter_add_int(filter, property_id, match, match_value);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               ThrowMsg(PlatformException, "contacts_filter_add_int error : " << errorCode << " (" << __FUNCTION__ << ")");
+       }
+
+       _CONTACTS_SVC_QUERY_FUNC_SUFFIX(query, filter, list, property_contact_id, result);
+}
+
+void ContactSearchEngine::queryAttributeString(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+               contacts_match_str_flag_e match, const char* match_value)
+{
+       const char* view_uri = attributeProperties.viewUri;
+       unsigned int property_contact_id = attributeProperties.propertyContactId;
+       unsigned int property_id = attributeProperties.propertyId;
+
+       int errorCode = 0;
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h list = NULL;
+
+       _CONTACTS_SVC_QUERY_FUNC_PREFIX(view_uri, query, filter);
+
+       errorCode = contacts_filter_add_str(filter, property_id, match, match_value);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               ThrowMsg(PlatformException, "contacts_filter_add_int error : " << errorCode << " (" << __FUNCTION__ << ")");
+       }
+
+       _CONTACTS_SVC_QUERY_FUNC_SUFFIX(query, filter, list, property_contact_id, result);
+}
+
+void ContactSearchEngine::queryAttributeRangeBool(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+               bool initial_value_is_set, bool initial_value, bool end_value_is_set, bool end_value)
+{
+       const char* view_uri = attributeProperties.viewUri;
+       unsigned int property_contact_id = attributeProperties.propertyContactId;
+       unsigned int property_id = attributeProperties.propertyId;
+
+       int errorCode = 0;
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h list = NULL;
+
+       _CONTACTS_SVC_QUERY_FUNC_PREFIX(view_uri, query, filter);
+
+       if(initial_value_is_set && end_value_is_set)
+       {
+               if(initial_value == end_value)
+               {
+                       if(initial_value == true)
+                               errorCode = contacts_filter_add_bool(filter, property_id, true);
+                       else if(end_value == false)
+                               errorCode = contacts_filter_add_bool(filter, property_id, false);
+               }
+       }
+       else if(initial_value_is_set)
+       {
+               if(initial_value == true)
+                       errorCode = contacts_filter_add_bool(filter, property_id, true);
+       }
+       else if(end_value_is_set)
+       {
+               if(end_value == false)
+                       errorCode = contacts_filter_add_bool(filter, property_id, false);
+       }
+
+       _CONTACTS_SVC_QUERY_FUNC_SUFFIX(query, filter, list, property_contact_id, result);
+}
+
+void ContactSearchEngine::queryAttributeRangeInt(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+               bool initial_value_is_set, int initial_value, bool end_value_is_set, int end_value)
+{
+       const char* view_uri = attributeProperties.viewUri;
+       unsigned int property_contact_id = attributeProperties.propertyContactId;
+       unsigned int property_id = attributeProperties.propertyId;
+
+       int errorCode = 0;
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h list = NULL;
+
+       _CONTACTS_SVC_QUERY_FUNC_PREFIX(view_uri, query, filter);
+
+       if(initial_value_is_set && end_value_is_set)
+       {
+               contacts_filter_h sub_filter = NULL;
+
+               errorCode = contacts_filter_create(_contacts_person._uri, &sub_filter);
+
+               errorCode = contacts_filter_add_int(sub_filter, property_id,
+                               CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, initial_value);
+
+               contacts_filter_add_operator(sub_filter, CONTACTS_FILTER_OPERATOR_AND);
+
+               errorCode = contacts_filter_add_int(sub_filter, property_id,
+                               CONTACTS_MATCH_LESS_THAN_OR_EQUAL, end_value);
+
+               errorCode = contacts_filter_add_filter(filter, sub_filter);
+       }
+       else if(initial_value_is_set)
+       {
+               errorCode = contacts_filter_add_int(filter, property_id,
+                               CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, initial_value);
+       }
+       else if(end_value_is_set)
+       {
+               errorCode = contacts_filter_add_int(filter, property_id,
+                               CONTACTS_MATCH_LESS_THAN_OR_EQUAL, end_value);
+       }
+
+       _CONTACTS_SVC_QUERY_FUNC_SUFFIX(query, filter, list, property_contact_id, result);
+}
+
+void ContactSearchEngine::queryAttributeRangeString(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+               const char* initial_value, const char* end_value)
+
+{
+       const char* view_uri = attributeProperties.viewUri;
+       unsigned int property_contact_id = attributeProperties.propertyContactId;
+       unsigned int property_id = attributeProperties.propertyId;
+       LogDebug("entered");
+
+       int errorCode = 0;
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h list = NULL;
+
+       _CONTACTS_SVC_QUERY_FUNC_PREFIX(view_uri, query, filter);
+
+       if(initial_value != NULL && end_value != NULL)
+       {
+               contacts_filter_h sub_filter = NULL;
+
+               errorCode = contacts_filter_create(view_uri, &sub_filter);
+
+               // TODO To be supported start
+               errorCode = contacts_filter_add_str(sub_filter, property_id,
+                               CONTACTS_MATCH_STARTSWITH, initial_value);
+
+               contacts_filter_add_operator(sub_filter, CONTACTS_FILTER_OPERATOR_AND);
+
+               errorCode = contacts_filter_add_str(sub_filter, property_id,
+                               CONTACTS_MATCH_ENDSWITH, end_value);
+
+               errorCode = contacts_filter_add_filter(filter, sub_filter);
+       }
+       else if(initial_value != NULL)
+       {
+               errorCode = contacts_filter_add_str(filter, property_id,
+                               CONTACTS_MATCH_STARTSWITH, initial_value);
+       }
+       else if(end_value != NULL)
+       {
+               errorCode = contacts_filter_add_str(filter, property_id,
+                               CONTACTS_MATCH_ENDSWITH, end_value);
+       }
+
+       _CONTACTS_SVC_QUERY_FUNC_SUFFIX(query, filter, list, property_contact_id, result);
+       LogDebug("end");
+}
+
+void ContactSearchEngine::sortContacts(AttributeProperties& attributeProperties, ContactIdArrayPtr& result,
+               bool is_ascending, ContactIdSetPtr& idSet)
+{
+       const char* view_uri = attributeProperties.viewUri;
+       unsigned int property_contact_id = attributeProperties.propertyContactId;
+       unsigned int property_id = attributeProperties.propertyId;
+
+       LogDebug("entered");
+
+       int errorCode = 0;
+       contacts_query_h query = NULL;
+       contacts_filter_h filter = NULL;
+       contacts_list_h list = NULL;
+
+       errorCode = contacts_query_create(view_uri, &query);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "contacts_query_create error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       errorCode = contacts_filter_create(view_uri, &filter);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "contacts_filter_create error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       ContactIdSet::iterator iter = idSet->begin();
+       if(iter != idSet->end())
+       {
+               errorCode = contacts_filter_add_int(filter, property_contact_id, CONTACTS_MATCH_EQUAL, *iter);
+               for(; iter!=idSet->end(); iter++)
+               {
+                       errorCode = contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_OR);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "contacts_filter_add_operator error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+                       errorCode = contacts_filter_add_int(filter, property_contact_id, CONTACTS_MATCH_EQUAL, *iter);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                               ThrowMsg(PlatformException, "contacts_query_create error : " << errorCode << " (" << __FUNCTION__ << ")");
+               }
+       }
+
+       errorCode = contacts_query_set_sort(query, property_id, is_ascending);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "contacts_query_set_sort error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       errorCode = contacts_query_set_filter(query, filter);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "contacts_query_set_filter error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       errorCode = contacts_db_get_records_with_query(query, 0, 0, &list);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "contacts_db_get_records_with_query error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       unsigned int record_count = 0;
+       errorCode = contacts_list_get_count(list, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "contacts_list_get_count error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       ContactIdSet overlappingIds;
+
+       contacts_list_first(list);
+       for(unsigned int i=0; i<record_count; i++)
+       {
+               contacts_record_h record;
+               errorCode = contacts_list_get_current_record_p(list, &record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_list_get_current_record_p error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+               int value = 0;
+               errorCode = contacts_record_get_int(record, property_contact_id, &value);
+               if(errorCode  != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_record_get_int error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+               if(overlappingIds.find(value) == overlappingIds.end())
+               {
+                       result->push_back(value);
+                       overlappingIds.insert(value);
+               }
+
+               contacts_list_next(list);
+       }
+
+       if(list != NULL)
+               contacts_list_destroy(list, true);
+
+       if(filter != NULL)
+               contacts_filter_destroy(filter);
+
+       if(query != NULL)
+               contacts_query_destroy(query);
+
+       LogDebug("end");
+}
+
+void ContactSearchEngine::sortContacts(AttributeProperties& attributeProperties, ContactIdArrayPtr& result,
+               bool is_ascending)
+{
+       const char* view_uri = attributeProperties.viewUri;
+       unsigned int property_contact_id = attributeProperties.propertyContactId;
+       unsigned int property_id = attributeProperties.propertyId;
+
+       int errorCode = 0;
+       contacts_query_h query = NULL;
+       contacts_list_h list = NULL;
+
+       errorCode = contacts_query_create(view_uri, &query);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "contacts_query_create error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       errorCode = contacts_query_set_sort(query, property_id, is_ascending);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "contacts_query_set_sort error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       errorCode = contacts_db_get_records_with_query(query, 0, 0, &list);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "contacts_db_get_records_with_query error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       unsigned int record_count = 0;
+       errorCode = contacts_list_get_count(list, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "contacts_list_get_count error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+       ContactIdSet overlappingIds;
+
+       contacts_list_first(list);
+       for(unsigned int i=0; i<record_count; i++)
+       {
+               contacts_record_h record;
+               errorCode = contacts_list_get_current_record_p(list, &record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_list_get_current_record_p error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+               int value = 0;
+               errorCode = contacts_record_get_int(record, property_contact_id, &value);
+               if(errorCode  != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "contacts_record_get_int error : " << errorCode << " (" << __FUNCTION__ << ")");
+
+               if(overlappingIds.find(value) == overlappingIds.end())
+               {
+                       result->push_back(value);
+                       overlappingIds.insert(value);
+               }
+
+               contacts_list_next(list);
+       }
+
+       if(list != NULL)
+               contacts_list_destroy(list, true);
+
+       if(query != NULL)
+               contacts_query_destroy(query);
+}
+
+void ContactSearchEngine::getIntersection(ContactIdSetArrayPtr& idSets, ContactIdSetPtr& result)
+{
+       ContactIdSetArray::iterator i;
+
+       if(idSets->size() == 0)
+       {
+               result = ContactIdSetPtr(NULL);
+               return;
+       }
+       else if(idSets->size() == 1)
+       {
+               *result = **idSets->begin();
+               return;
+       }
+
+       ContactIdSetArray::iterator minIter;
+       ContactIdSetArray::size_type minSize =
+                       numeric_limits<ContactIdSetArray::size_type>::max();
+
+       for(i=idSets->begin(); i!=idSets->end(); i++)
+       {
+               ContactIdSetPtr idSet = *i;
+               ContactIdSetArray::size_type size = idSet->size();
+               if(minSize > size)
+               {
+                       minSize = size;
+                       minIter = i;
+               }
+       }
+
+       ContactIdSetPtr p = *minIter;
+       ContactIdSetArrayPtr sa = ContactIdSetArrayPtr(new ContactIdSetArray());
+       for(i=idSets->begin(); i!=idSets->end(); i++)
+       {
+               if(minIter != i)
+               {
+                       sa->push_back(*i);
+               }
+       }
+
+       ContactIdSet::iterator iter;
+       for(iter=p->begin(); iter!=p->end(); iter++)
+       {
+               bool excluded = false;
+               int value = *iter;
+
+               for(i=sa->begin(); i!=sa->end(); i++)
+               {
+                       ContactIdSetPtr idSet = *i;
+                       if(idSet->find(value) == idSet->end())
+                       {
+                               excluded = true;
+                               break;
+                       }
+               }
+
+               if(excluded == false)
+               {
+                       result->insert(value);
+               }
+       }
+}
+
+void ContactSearchEngine::getUnion(ContactIdSetArrayPtr& idSets, ContactIdSetPtr& result)
+{
+       ContactIdSetArray::iterator i;
+
+       if(idSets->size() == 0)
+       {
+               result = ContactIdSetPtr(NULL);
+               return;
+       }
+       else if(idSets->size() == 1)
+       {
+               *result = **idSets->begin();
+               return;
+       }
+
+       for(i=idSets->begin(); i!=idSets->end(); i++)
+       {
+               ContactIdSetPtr ids = *i;
+               ContactIdSet::iterator j;
+               for(j=ids->begin(); j!=ids->end(); j++)
+               {
+                       result->insert(*j);
+               }
+       }
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactSearchEngine.h b/src/platform/Tizen/Contact/ContactSearchEngine.h
new file mode 100755 (executable)
index 0000000..44667dd
--- /dev/null
@@ -0,0 +1,152 @@
+//
+// 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        ContactSearchEngine.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _PLATFORM_CONTACT_CONTACT_SEARCH_ENGINE_H_
+#define _PLATFORM_CONTACT_CONTACT_SEARCH_ENGINE_H_
+
+#include <string>
+#include <map>
+#include <set>
+#include <vector>
+#include <stack>
+#include <dpl/shared_ptr.h>
+#include <dpl/enable_shared_from_this.h>
+#include <API/Filter/IFilterVisitor.h>
+#include <API/Contact/IAddressBook.h>
+#include <API/Contact/IContact.h>
+#include <API/Contact/ContactTypes.h>
+#include <contacts.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class ContactSearchEngine :
+       public TizenApis::Api::Tizen::IFilterVisitor,
+       public DPL::EnableSharedFromThis<ContactSearchEngine>
+{
+public:
+       ContactSearchEngine();
+       virtual ~ContactSearchEngine();
+
+       // setting search options.
+       void setAddressBookId(int id);
+       void setCondition(TizenApis::Api::Tizen::FilterPtr filter);
+       void setSortMode(TizenApis::Api::Tizen::SortModePtr attr = TizenApis::Api::Tizen::SortModePtr(NULL));
+
+       // getting results
+       TizenApis::Api::Contact::ContactArrayPtr getContactSearchResult();
+
+       // inherited from IFilterVisitor
+       virtual void visitPreComposite(TizenApis::Api::Tizen::FilterType& type, int depth);
+       virtual void visitInComposite(TizenApis::Api::Tizen::FilterType& type, int depth);
+       virtual void visitPostComposite(TizenApis::Api::Tizen::FilterType& type, int depth);
+       virtual void visitAttribute(std::string& attrName,
+                       TizenApis::Api::Tizen::MatchFlag& matchFlag,
+                       TizenApis::Api::Tizen::AnyPtr& matchValue,
+                       int depth);
+       virtual void visitAttributeRange(std::string& attrName,
+                       TizenApis::Api::Tizen::AnyPtr& initialValue,
+                       TizenApis::Api::Tizen::AnyPtr& endValue,
+                       int depth);
+
+public:
+       enum ContactSvcPrimitiveType
+       {
+               ContactSvcPrimitiveType_Boolean,
+               ContactSvcPrimitiveType_Int,
+               ContactSvcPrimitiveType_String
+       };
+
+       struct AttributeProperties
+       {
+               const char* viewUri;
+               const unsigned int propertyContactId;
+               const unsigned int propertyId;
+               const ContactSvcPrimitiveType type;
+               const TizenApis::Api::Tizen::PrimitiveType jsType;
+       };
+       typedef std::map<std::string, AttributeProperties> AttributePropertiesMap;
+
+       typedef std::vector<int> ContactIdArray;
+       typedef DPL::SharedPtr<ContactIdArray> ContactIdArrayPtr;
+
+       typedef std::set<int> ContactIdSet;
+       typedef DPL::SharedPtr<ContactIdSet> ContactIdSetPtr;
+
+       typedef std::vector<ContactIdSetPtr> ContactIdSetArray;
+       typedef DPL::SharedPtr<ContactIdSetArray> ContactIdSetArrayPtr;
+
+private:
+       static AttributePropertiesMap attributePropertiesMap;
+
+       int m_addressBookId;
+       bool m_isAddressBookIdSet;
+       bool m_isFilterSet;
+       bool m_isSortModeSet;
+
+       std::stack<ContactIdSetArrayPtr> m_contactIdSetArrayStack;
+       // NULL means ALL
+       ContactIdSetPtr m_filteredContactIds;
+       ContactIdArrayPtr m_sortedContactIds;
+
+       TizenApis::Api::Tizen::SortOrder m_sortOrder;
+       std::string m_attributeNameForSort;
+
+private:
+       TizenApis::Api::Contact::ContactArrayPtr getAllContactsSorted(AttributeProperties& attributeProperties,
+                       bool is_ascending);
+       TizenApis::Api::Contact::ContactArrayPtr getAllContacts();
+       TizenApis::Api::Contact::ContactArrayPtr getContacts(ContactIdArrayPtr& ids);
+       TizenApis::Api::Contact::ContactArrayPtr getContacts(ContactIdSetPtr& ids);
+       TizenApis::Api::Contact::ContactPtr getContact(int id);
+
+       void queryAttributeBool(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+                       bool match_value);
+       void queryAttributeInt(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+                       contacts_match_int_flag_e match, int match_value);
+       void queryAttributeString(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+                       contacts_match_str_flag_e match, const char* match_value);
+       void queryAttributeRangeBool(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+                       bool initial_value_is_set, bool initial_value, bool end_value_is_set, bool end_value);
+       void queryAttributeRangeInt(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+                       bool initial_value_is_set, int initial_value, bool end_value_is_set, int end_value);
+       void queryAttributeRangeString(AttributeProperties& attributeProperties, ContactIdSetPtr& result,
+                       const char* initial_value, const char* end_value);
+       void sortContacts(AttributeProperties& attributeProperties, ContactIdArrayPtr& result,
+                       bool is_ascending, ContactIdSetPtr& ids);
+       void sortContacts(AttributeProperties& attributeProperties, ContactIdArrayPtr& result,
+                       bool is_ascending);
+
+       void getIntersection(ContactIdSetArrayPtr& idSets, ContactIdSetPtr& result);
+       void getUnion(ContactIdSetArrayPtr& idSets, ContactIdSetPtr& result);
+};
+
+typedef DPL::SharedPtr<ContactSearchEngine> ContactSearchEnginePtr;
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_CONTACT_SEARCH_ENGINE_H_
diff --git a/src/platform/Tizen/Contact/ContactUtility.cpp b/src/platform/Tizen/Contact/ContactUtility.cpp
new file mode 100755 (executable)
index 0000000..a268041
--- /dev/null
@@ -0,0 +1,176 @@
+//
+// 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        ContactUtility.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactUtility.h"
+
+#include <time.h>
+#include <string>
+#include <sstream>
+#include <iomanip>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+
+ContactUtility::ContactUtility()
+{
+}
+
+ContactUtility::~ContactUtility()
+{
+}
+
+bool ContactUtility::strToBool(const char *str)
+{
+       if(str == NULL)
+               return false;
+
+       string boolStr(str);
+
+       if (boolStr == "true" || boolStr == "TRUE")
+               return true;
+
+       return false;
+}
+
+int ContactUtility::strToInt(const char* str)
+{
+       if(str == NULL)
+               return 0;
+
+       int result = 0;
+
+       istringstream iss(str);
+       iss >> result;
+
+       return result;
+}
+
+int ContactUtility::strToInt(const string &str)
+{
+       int result = 0;
+
+       istringstream iss(str);
+       iss >> result;
+
+       return result;
+}
+
+string ContactUtility::intToStr(const int value)
+{
+       stringstream oss;
+       oss << value;
+       return oss.str();
+}
+
+int ContactUtility::toDateDbInt(const tm &date)
+{
+       return strToInt(toDateDbStr(date));
+}
+
+string ContactUtility::toDateDbStr(const tm &date)
+{
+       stringstream ss;
+       ss << setfill('0') << setiosflags(ios::right) << setw(4) << (date.tm_year + 1900);
+       ss << setfill('0') << setiosflags(ios::right) << setw(2) << (date.tm_mon + 1);
+       ss << setfill('0') << setiosflags(ios::right) << setw(2) << date.tm_mday;
+
+       return ss.str();
+}
+
+tm ContactUtility::toDateTmFromDateDbInt(int arg)
+{
+       tm date;
+       memset(&date, 0, sizeof(tm));
+
+       if(arg < 0) {
+               ThrowMsg(InvalidArgumentException, "Invalid Date type");
+       }
+
+       int section0to3 = arg / 10000;
+       int section4to5 = (arg / 100) % 100;
+       int section6to7 = arg % 100;
+
+       date.tm_year = section0to3 - 1900;
+       date.tm_mon = section4to5 - 1;
+       date.tm_mday = section6to7;
+
+       return date;
+}
+
+tm ContactUtility::toDateTmFromDateDbStr(const char* arg)
+{
+       if(arg == NULL) {
+               ThrowMsg(InvalidArgumentException, "Invalid Date type");
+       }
+
+       int dateDb;
+       stringstream ss(arg);
+       ss >> dateDb;
+
+       return toDateTmFromDateDbInt(dateDb);
+}
+
+string ContactUtility::convertUriToPath(const string str)
+{
+       string result;
+
+       if(validate("^file:///[\x20-\x7E]+$", str, VALIDATE_MATCH_CASELESS))
+               result = str.substr(string("file://").size());
+       else if(validate("^/[\x20-\x7E]+$", str, VALIDATE_MATCH_CASELESS))
+               result = str;
+
+       return result;
+}
+
+string ContactUtility::convertPathToUri(const string str)
+{
+       string result;
+
+       if(validate("^/[\x20-\x7E]+$", str, VALIDATE_MATCH_CASELESS))
+               result = "file://" + str;
+       else if(validate("^file:///[\x20-\x7E]+$", str, VALIDATE_MATCH_CASELESS))
+               result = str;
+
+       return result;
+}
+
+bool ContactUtility::checkStrIsInt(const std::string &str)
+{
+       return validate("^[\\-]?[0-9]+$", str, VALIDATE_MATCH_CASELESS);
+}
+
+bool ContactUtility::checkStrIsUInt(const std::string &str)
+{
+       return validate("^[0-9]+$", str, VALIDATE_MATCH_CASELESS);
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactUtility.h b/src/platform/Tizen/Contact/ContactUtility.h
new file mode 100755 (executable)
index 0000000..2f1b724
--- /dev/null
@@ -0,0 +1,62 @@
+//
+// 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        ContactUtility.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef TIZENAPIS_PLATFORM_CONTACT_CONTACT_UTILITY_H_
+#define TIZENAPIS_PLATFORM_CONTACT_CONTACT_UTILITY_H_
+
+#include <string>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class ContactUtility
+{
+public:
+       ContactUtility();
+       virtual ~ContactUtility();
+
+       static bool strToBool(const char* str);
+
+       static int strToInt(const char* str);
+       static int strToInt(const std::string &str);
+       static std::string intToStr(const int value);
+
+       static int toDateDbInt(const tm &date);
+       static std::string toDateDbStr(const tm &date);
+       static tm toDateTmFromDateDbInt(int arg);
+       static tm toDateTmFromDateDbStr(const char* arg);
+
+       static std::string convertUriToPath(const std::string str);
+       static std::string convertPathToUri(const std::string str);
+
+       static bool checkStrIsInt(const std::string &str);
+       static bool checkStrIsUInt(const std::string &str);
+};
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // TIZENAPIS_PLATFORM_CONTACT_CONTACT_UTILITY_H_
diff --git a/src/platform/Tizen/Contact/ContactsSvcChangeListenerManager.cpp b/src/platform/Tizen/Contact/ContactsSvcChangeListenerManager.cpp
new file mode 100755 (executable)
index 0000000..24ef48e
--- /dev/null
@@ -0,0 +1,634 @@
+//
+// 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        ContactsSvcChangeListenerManager.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactsSvcChangeListenerManager.h"
+
+#include <contacts.h>
+
+#include <dpl/log/log.h>
+#include <dpl/singleton_impl.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+#include "ContactUtility.h"
+#include "ContactObjectP2AConverter.h"
+#include "ContactsSvcObjectConverter.h"
+#include "Person.h"
+
+IMPLEMENT_SINGLETON(TizenApis::Platform::Contact::ContactsSvcChangeListenerManager)
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Api::Contact;
+
+ContactsSvcChangeListenerManager::ContactsSvcChangeListenerManager() :
+               EventRequestReceiver< EventInvokeContactsChangeListener >(ThreadEnum::NULL_THREAD),
+               m_contactsChangedCallbackRegistered(false),
+               m_personsChangedCallbackRegistered(false),
+               m_latestVersion(0),
+               m_watchIdAcc(0)
+{
+}
+
+ContactsSvcChangeListenerManager::~ContactsSvcChangeListenerManager()
+{
+       if(m_contactsChangedCallbackRegistered)
+       {
+               unregisterContactsSvcContactsChangedCallback();
+       }
+       if(m_personsChangedCallbackRegistered)
+       {
+               unregisterContactsSvcPersonsChangedCallback();
+       }
+}
+
+void ContactsSvcChangeListenerManager::registerContactsChangeListener(IContactsSvcContactsChangeListener *callbacks, int addressBookId)
+{
+       if(callbacks == NULL)
+       {
+               LogWarning("Parameter is NULL.");
+               return;
+       }
+
+
+       ContactsChangeListenerMap::iterator iter = m_contactsChangeListenerMap.begin();
+       for(; iter != m_contactsChangeListenerMap.end(); iter++)
+       {
+               if(iter->second == callbacks)
+                       break;
+       }
+
+       if(iter != m_contactsChangeListenerMap.end())
+       {
+               if(iter->first == addressBookId)
+               {
+                       LogWarning("Callbacks " << callbacks << " is already registered.");
+                       return;
+               }
+
+               ThrowMsg(PlatformException, "Already registered listener (address book id : " << iter->first << ")");
+       }
+
+       if(!m_contactsChangedCallbackRegistered)
+       {
+               registerContactsSvcContactsChangedCallback();
+       }
+
+       ContactsChangeListenerPair pair(addressBookId, callbacks);
+
+       m_contactsChangeListenerMap.insert(pair);
+}
+
+void ContactsSvcChangeListenerManager::unregisterContactsChangeListener(IContactsSvcContactsChangeListener *callbacks)
+{
+       if(callbacks == NULL)
+       {
+               LogWarning("Parameter is NULL.");
+               return;
+       }
+
+       if(m_contactsChangeListenerMap.size() == 0)
+       {
+               LogWarning("No callbacks are registered.");
+               return;
+       }
+
+       ContactsChangeListenerMap::iterator iter = m_contactsChangeListenerMap.begin();
+       for(; iter != m_contactsChangeListenerMap.end(); iter++)
+       {
+               if(iter->second == callbacks)
+                       break;
+       }
+
+       if(iter == m_contactsChangeListenerMap.end())
+       {
+               LogWarning("Callbacks " << callbacks << " are not registered.");
+               return;
+       }
+
+       m_contactsChangeListenerMap.erase(iter);
+
+       if(m_contactsChangeListenerMap.size() == 0)
+       {
+               unregisterContactsSvcContactsChangedCallback();
+       }
+}
+
+void ContactsSvcChangeListenerManager::registerPersonsChangeListener(IContactsSvcPersonsChangeListener *callbacks)
+{
+       if(callbacks == NULL)
+       {
+               LogWarning("Parameter is NULL.");
+               return;
+       }
+
+       PersonsChangeListenerSet::iterator iter = m_personsChangeListenerSet.find(callbacks);
+       if(iter != m_personsChangeListenerSet.end())
+       {
+               LogWarning("Callbacks " << callbacks << " is already registered.");
+               return;
+       }
+
+       registerContactsSvcPersonsChangedCallback();
+       m_personsChangeListenerSet.insert(callbacks);
+}
+
+void ContactsSvcChangeListenerManager::unregisterPersonsChangeListener(IContactsSvcPersonsChangeListener *callbacks)
+{
+       if(callbacks == NULL)
+       {
+               LogWarning("Parameter is NULL.");
+               return;
+       }
+
+       if(m_personsChangeListenerSet.size() == 0)
+       {
+               LogWarning("No callbacks are registered.");
+               return;
+       }
+
+       PersonsChangeListenerSet::iterator iter = m_personsChangeListenerSet.find(callbacks);
+       if(iter == m_personsChangeListenerSet.end())
+       {
+               LogWarning("Callbacks " << callbacks << " are not registered.");
+               return;
+       }
+
+       m_personsChangeListenerSet.erase(iter);
+
+       if(m_personsChangeListenerSet.size() == 0)
+       {
+               unregisterContactsSvcPersonsChangedCallback();
+       }
+}
+
+long ContactsSvcChangeListenerManager::getWatchIdAndInc()
+{
+       return ++m_watchIdAcc;
+}
+
+void ContactsSvcChangeListenerManager::contactsDbChangedCallback(const char* view_uri, void* user_data)
+{
+       LogDebug("entered");
+
+       if(user_data == NULL)
+       {
+               LogWarning("contacts-service listener passed NULL user_data");
+               return;
+       }
+
+       ContactsSvcChangeListenerManager *contactListenerMgr = static_cast<ContactsSvcChangeListenerManager *>(user_data);
+       contactListenerMgr->contactsDbChangedCallback(view_uri);
+}
+
+void ContactsSvcChangeListenerManager::contactsDbChangedCallback(const char* view_uri)
+{
+       LogDebug("entered");
+
+       string view_uri_str = view_uri;
+       if(view_uri_str == _contacts_contact._uri)
+       {
+               // As the contact api works on main thread, event listener is not needed.
+               //EventInvokeContactsChangeListenerPtr event(new EventInvokeContactsChangeListener());
+               //OnRequestReceived(event);
+
+               contactsChangedCallback();
+       }
+}
+
+void ContactsSvcChangeListenerManager::personsDbChangedCallback(const char* view_uri, char* changes, void* user_data)
+{
+       LogDebug("entered");
+
+       if(user_data == NULL)
+       {
+               LogWarning("contacts-service listener passed NULL user_data");
+               return;
+       }
+
+       ContactsSvcChangeListenerManager *contactListenerMgr = static_cast<ContactsSvcChangeListenerManager *>(user_data);
+       contactListenerMgr->personsDbChangedCallback(view_uri, changes);
+}
+
+void ContactsSvcChangeListenerManager::personsDbChangedCallback(const char* view_uri, char* changes)
+{
+       LogDebug("entered");
+       personsChangedCallback(changes);
+}
+
+void ContactsSvcChangeListenerManager::OnRequestReceived(const EventInvokeContactsChangeListenerPtr &event)
+{
+       contactsChangedCallback();
+}
+
+void ContactsSvcChangeListenerManager::contactsChangedCallback()
+{
+       LogDebug("entered");
+       if(!m_contactsChangedCallbackRegistered)
+               return;
+
+       int errorCode = 0;
+
+       ContactsChangeListenerMap::iterator callbacksIter = m_contactsChangeListenerMap.begin();
+       for(; callbacksIter != m_contactsChangeListenerMap.end(); callbacksIter++)
+       {
+               int addressBookId = callbacksIter->first;
+               IContactsSvcContactsChangeListener *callbacks = callbacksIter->second;
+
+               contacts_list_h change_record_list = NULL;
+
+               int latestVersion = 0;
+
+               errorCode = contacts_db_get_changes_by_version(_contacts_contact_updated_info._uri, addressBookId,
+                               m_latestVersion, &change_record_list, &latestVersion);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogDebug("Fail to get the updated contacts for addressbook : " << addressBookId <<
+                                       ", errorCode : " << errorCode);
+                       continue;
+               }
+
+               unsigned int record_count = 0;
+               errorCode = contacts_list_get_count(change_record_list, &record_count);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogDebug("cannot get the updated contact count error : " << errorCode);
+                       continue;
+               }
+
+               if(record_count == 0)
+               {
+                       LogDebug("No updated contacts for address book : " << addressBookId);
+                       continue;
+               }
+
+               contacts_list_first(change_record_list);
+
+               ContactArrayPtr addedContacts(new ContactArray());
+               ContactArrayPtr updatedContacts(new ContactArray());
+               StringArrayPtr removedContactIds(new StringArray());
+
+               for(unsigned int i=0; i<record_count; i++)
+               {
+                       contacts_record_h contact_updated_record = NULL;
+
+                       errorCode = contacts_list_get_current_record_p(change_record_list, &contact_updated_record);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogDebug("Fail contacts_list_get_current_record_p error : " << errorCode);
+                               continue;
+                       }
+
+                       int updatedContactId = 0;
+                       int updatedAddressBookId = 0;
+                       int updatedType = 0;
+
+                       errorCode = contacts_record_get_int(contact_updated_record,
+                                       _contacts_contact_updated_info.contact_id, &updatedContactId);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogDebug("Fail contacts_record_get_int error contact_id : " << errorCode);
+                               continue;
+                       }
+
+                       errorCode = contacts_record_get_int(contact_updated_record,
+                                       _contacts_contact_updated_info.address_book_id ,&updatedAddressBookId);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogDebug("Fail contacts_record_get_int error address_book_id : " << errorCode);
+                               continue;
+                       }
+
+                       errorCode = contacts_record_get_int(contact_updated_record,
+                                       _contacts_contact_updated_info.type ,&updatedType);
+                       if(errorCode != CONTACTS_ERROR_NONE)
+                       {
+                               LogDebug("Fail contacts_record_get_int error type : " << errorCode);
+                               continue;
+                       }
+
+                       if(updatedType == CONTACTS_CHANGE_INSERTED)
+                       {
+                               contacts_record_h contacts_record = NULL;
+                               errorCode = contacts_db_get_record(_contacts_contact._uri, updatedContactId, &contacts_record);
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       LogDebug("Fail contacts_db_get_record error _contacts_contact._uri : " << errorCode);
+                                       continue;
+                               }
+
+                               ContactPtr absContact(NULL);
+
+                               Try
+                               {
+                                       ContactObjectP2AConverterPtr contactObjConverter(
+                                                       new ContactObjectP2AConverter(contacts_record, false) );
+                                       absContact = contactObjConverter->getAbstractContact();
+                               }
+                               Catch(Exception)
+                               {
+                                       LogError("Fail error on converting contact to abs contact : " << _rethrown_exception.GetMessage());
+                                       continue;
+                               }
+
+                               if(absContact != NULL)
+                                       addedContacts->push_back(absContact);
+
+                               if(contacts_record != NULL)
+                                       contacts_record_destroy(contacts_record, true);
+                       }
+                       else if(updatedType == CONTACTS_CHANGE_UPDATED)
+                       {
+                               contacts_record_h contacts_record = NULL;
+                               errorCode = contacts_db_get_record(_contacts_contact._uri, updatedContactId, &contacts_record);
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       LogDebug("Fail contacts_db_get_record error _contacts_contact._uri : " << errorCode);
+                                       continue;
+                               }
+
+                               ContactPtr absContact(NULL);
+
+                               Try
+                               {
+                                       ContactObjectP2AConverterPtr contactObjConverter(
+                                                       new ContactObjectP2AConverter(contacts_record, false) );
+                                       absContact = contactObjConverter->getAbstractContact();
+                               }
+                               Catch(Exception)
+                               {
+                                       LogError("Fail error on converting contact to abs contact : " << _rethrown_exception.GetMessage());
+                                       continue;
+                               }
+                               if(absContact != NULL)
+                                       updatedContacts->push_back(absContact);
+
+                               if(contacts_record != NULL)
+                                       contacts_record_destroy(contacts_record, true);
+                       }
+                       else if(updatedType == CONTACTS_CHANGE_DELETED)
+                       {
+                               removedContactIds->push_back(ContactUtility::intToStr(updatedContactId));
+                       }
+               }
+
+               if(addedContacts->size() != 0)
+                       callbacks->onContactsSvcContactsAdded(addedContacts);
+
+               if(updatedContacts->size() != 0)
+                       callbacks->onContactsSvcContactsUpdated(updatedContacts);
+
+               if(removedContactIds->size() != 0)
+                       callbacks->onContactsSvcContactsRemoved(removedContactIds);
+       }
+
+       errorCode = contacts_db_get_current_version(&m_latestVersion);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogWarning("contacts_db_get_current_version returns error : " << errorCode);
+       }
+}
+
+void ContactsSvcChangeListenerManager::registerContactsSvcContactsChangedCallback()
+{
+       int errorCode = 0;
+
+       if(m_contactsChangedCallbackRegistered)
+       {
+               LogWarning("Callback already registered.");
+               return;
+       }
+
+       errorCode = contacts_db_add_changed_cb(_contacts_contact._uri,
+                       contactsDbChangedCallback, reinterpret_cast<void *>(this));
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogWarning("contacts_db_add_changed_cb(_contacts_contact._uri) returns error : " << errorCode);
+               ThrowMsg(InvalidArgumentException, "Error while registering listener to contacts-service");
+       }
+
+       errorCode = contacts_db_get_current_version(&m_latestVersion);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogWarning("contacts_db_get_current_version returns error : " << errorCode);
+               ThrowMsg(InvalidArgumentException, "Error while registering listener to contacts-service");
+       }
+
+       m_contactsChangedCallbackRegistered = true;
+}
+
+void ContactsSvcChangeListenerManager::unregisterContactsSvcContactsChangedCallback()
+{
+       int errorCode = 0;
+
+       if(!m_contactsChangedCallbackRegistered)
+       {
+               LogWarning("Callback already unregistered.");
+               return;
+       }
+
+       m_latestVersion = 0;
+
+       m_contactsChangedCallbackRegistered = false;
+
+       errorCode = contacts_db_remove_changed_cb(_contacts_contact._uri,
+                       contactsDbChangedCallback, reinterpret_cast<void *>(this));
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogWarning("contacts_db_remove_changed_cb(_contacts_contact._uri) returns error : " << errorCode);
+               ThrowMsg(InvalidArgumentException, "Error while registering listener to contacts-service");
+       }
+}
+
+void ContactsSvcChangeListenerManager::registerContactsSvcPersonsChangedCallback()
+{
+       int errorCode = 0;
+       LogDebug("entered");
+
+       if(m_personsChangedCallbackRegistered)
+       {
+               LogWarning("Callback already registered.");
+               return;
+       }
+
+       errorCode = contacts_db_add_changed_cb_with_info(_contacts_person._uri,
+                       personsDbChangedCallback, reinterpret_cast<void *>(this));
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogWarning("contacts_db_add_changed_cb(_contacts_person._uri) returns error : " << errorCode);
+               ThrowMsg(InvalidArgumentException, "Error while registering listener to contacts-service");
+       }
+
+       m_personsChangedCallbackRegistered = true;
+}
+
+void ContactsSvcChangeListenerManager::unregisterContactsSvcPersonsChangedCallback()
+{
+       int errorCode = 0;
+
+       if(!m_personsChangedCallbackRegistered)
+       {
+               LogWarning("Callback already unregistered.");
+               return;
+       }
+
+       m_personsChangedCallbackRegistered = false;
+
+       errorCode = contacts_db_remove_changed_cb_with_info(_contacts_person._uri,
+                       personsDbChangedCallback, reinterpret_cast<void *>(this));
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogWarning("contacts_db_remove_changed_cb(_contacts_person._uri) returns error : " << errorCode);
+               ThrowMsg(InvalidArgumentException, "Error while registering listener to contacts-service");
+       }
+}
+
+void ContactsSvcChangeListenerManager::personsChangedCallback(char* changes)
+{
+       LogDebug("entered : " << changes);
+       if(!m_personsChangedCallbackRegistered)
+               return;
+
+       int errorCode = 0;
+
+       map<int, int> idList;
+       map<int, int>::iterator it;
+
+       int tmpUpdatedType = 0;
+       int tmpUpdatedContactId = 0;
+       char* ptr;
+       char* sub_ptr;
+
+       ptr = strtok(changes, ",");
+
+       sub_ptr = strtok(ptr, ":");
+       tmpUpdatedType = atoi((const char*)sub_ptr);
+       sub_ptr = strtok(NULL, ptr);
+       tmpUpdatedContactId = atoi((const char*)sub_ptr);
+       idList.insert(pair<int, int>(tmpUpdatedType, tmpUpdatedContactId));
+
+       while(ptr = strtok(NULL, changes))
+       {
+               sub_ptr = strtok(ptr, ":");
+               tmpUpdatedType = atoi((const char*)sub_ptr);
+               sub_ptr = strtok(NULL, ptr);
+               tmpUpdatedContactId = atoi((const char*)sub_ptr);
+               idList.insert(pair<int, int>(tmpUpdatedType, tmpUpdatedContactId));
+       }
+
+       PersonsChangeListenerSet::iterator callbacksIter = m_personsChangeListenerSet.begin();
+       for(; callbacksIter != m_personsChangeListenerSet.end(); callbacksIter++)
+       {
+               IContactsSvcPersonsChangeListener *callbacks = *callbacksIter;
+
+// get id list
+               PersonArrayPtr addedPersons(new PersonArray());
+               PersonArrayPtr updatedPersons(new PersonArray());
+               StringArrayPtr removedPersonIds(new StringArray());
+
+               for(it=idList.begin(); it!=idList.end(); it++)
+               {
+                       int updatedType = it->first;
+                       int updatedContactId = it->second;
+//                     LogDebug("updatedContactId : " << updatedContactId << " , updatedType : " << updatedType);
+
+                       if(updatedType == CONTACTS_CHANGE_INSERTED)
+                       {
+                               contacts_record_h person_record = NULL;
+                               errorCode = contacts_db_get_record(_contacts_person._uri, updatedContactId, &person_record);
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       LogDebug("Fail contacts_db_get_record error _contacts_contact._uri : " << errorCode);
+                                       continue;
+                               }
+
+                               PersonPtr absPerson = PersonPtr(new Person());
+                               Try
+                               {
+                                       ContactsSvcObjectConverter::convertToAbstract(person_record, absPerson);
+                               }
+                               Catch(Exception)
+                               {
+                                       LogError("Fail error on converting contact to abs contact : " << _rethrown_exception.GetMessage());
+                                       continue;
+                               }
+
+                               if(absPerson != NULL)
+                                       addedPersons->push_back(absPerson);
+                               else
+                                       LogDebug("absPerson is null");
+
+                               if(person_record != NULL)
+                                       contacts_record_destroy(person_record, true);
+                       }
+                       else if(updatedType == CONTACTS_CHANGE_UPDATED)
+                       {
+                               contacts_record_h person_record = NULL;
+                               errorCode = contacts_db_get_record(_contacts_person._uri, updatedContactId, &person_record);
+                               if(errorCode != CONTACTS_ERROR_NONE)
+                               {
+                                       LogDebug("Fail contacts_db_get_record error _contacts_contact._uri : " << errorCode);
+                                       continue;
+                               }
+
+                               PersonPtr absPerson = PersonPtr(new Person());
+
+                               Try
+                               {
+                                       ContactsSvcObjectConverter::convertToAbstract(person_record, absPerson);
+                               }
+                               Catch(Exception)
+                               {
+                                       LogError("Fail error on converting contact to abs contact : " << _rethrown_exception.GetMessage());
+                                       continue;
+                               }
+                               if(absPerson != NULL)
+                                       updatedPersons->push_back(absPerson);
+
+                               if(person_record != NULL)
+                                       contacts_record_destroy(person_record, true);
+                       }
+                       else if(updatedType == CONTACTS_CHANGE_DELETED)
+                       {
+                               removedPersonIds->push_back(ContactUtility::intToStr(updatedContactId));
+                       }
+               }
+
+               if(addedPersons->size() != 0)
+                       callbacks->onContactsSvcPersonsAdded(addedPersons);
+
+               if(updatedPersons->size() != 0)
+                       callbacks->onContactsSvcPersonsUpdated(updatedPersons);
+
+               if(removedPersonIds->size() != 0)
+                       callbacks->onContactsSvcPersonsRemoved(removedPersonIds);
+       }
+}
+
+} // Application
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactsSvcChangeListenerManager.h b/src/platform/Tizen/Contact/ContactsSvcChangeListenerManager.h
new file mode 100755 (executable)
index 0000000..1cb087e
--- /dev/null
@@ -0,0 +1,136 @@
+//
+// 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        ContactsSvcChangeListenerManager.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef TIZENAPIS_PLATFORM_CONTACT_CONTACT_LISTENER_MANAGER_H_
+#define TIZENAPIS_PLATFORM_CONTACT_CONTACT_LISTENER_MANAGER_H_
+
+#include <string>
+#include <map>
+#include <set>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Commons/EventReceiver.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/IContact.h>
+#include <API/Contact/IPerson.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class IContactsSvcContactsChangeListener
+{
+public:
+    friend class ContactsSvcChangeListenerManager;
+
+    IContactsSvcContactsChangeListener() {}
+       virtual ~IContactsSvcContactsChangeListener() {}
+
+protected:
+       virtual void onContactsSvcContactsAdded(TizenApis::Api::Contact::ContactArrayPtr &contacts) = 0;
+       virtual void onContactsSvcContactsUpdated(TizenApis::Api::Contact::ContactArrayPtr &contacts) = 0;
+       virtual void onContactsSvcContactsRemoved(TizenApis::Api::Contact::StringArrayPtr &contactIds) = 0;
+};
+
+class IContactsSvcPersonsChangeListener
+{
+public:
+    friend class ContactsSvcChangeListenerManager;
+
+    IContactsSvcPersonsChangeListener() {}
+       virtual ~IContactsSvcPersonsChangeListener() {}
+
+protected:
+       virtual void onContactsSvcPersonsAdded(TizenApis::Api::Contact::PersonArrayPtr &persons) = 0;
+       virtual void onContactsSvcPersonsUpdated(TizenApis::Api::Contact::PersonArrayPtr &persons) = 0;
+       virtual void onContactsSvcPersonsRemoved(TizenApis::Api::Contact::StringArrayPtr &personIds) = 0;
+};
+
+class EventInvokeContactsChangeListener :
+       public WrtDeviceApis::Commons::IEvent<EventInvokeContactsChangeListener>
+{
+};
+typedef DPL::SharedPtr<EventInvokeContactsChangeListener> EventInvokeContactsChangeListenerPtr;
+
+class ContactsSvcChangeListenerManager :
+       public WrtDeviceApis::Commons::EventRequestReceiver< EventInvokeContactsChangeListener >
+{
+public:
+       ContactsSvcChangeListenerManager();
+       virtual ~ContactsSvcChangeListenerManager();
+
+       // Can throw InvalidArgumentException or PlatformException
+       void registerContactsChangeListener(IContactsSvcContactsChangeListener *callbacks, int addressBookId);
+
+       // No throws
+       void unregisterContactsChangeListener(IContactsSvcContactsChangeListener *callbacks);
+
+       // Can throw InvalidArgumentException or PlatformException
+       void registerPersonsChangeListener(IContactsSvcPersonsChangeListener *callbacks);
+
+       // No throws
+       void unregisterPersonsChangeListener(IContactsSvcPersonsChangeListener *callbacks);
+
+       long getWatchIdAndInc();
+
+private:
+       static void contactsDbChangedCallback(const char* view_uri, void* user_data);
+       void contactsDbChangedCallback(const char* view_uri);
+
+       virtual void OnRequestReceived(const EventInvokeContactsChangeListenerPtr &event);
+       void contactsChangedCallback();
+
+       void registerContactsSvcContactsChangedCallback();
+       void unregisterContactsSvcContactsChangedCallback();
+
+       typedef std::multimap<int, IContactsSvcContactsChangeListener *> ContactsChangeListenerMap;
+       typedef std::pair<int, IContactsSvcContactsChangeListener *> ContactsChangeListenerPair;
+       ContactsChangeListenerMap m_contactsChangeListenerMap;
+       bool m_contactsChangedCallbackRegistered;
+
+       void registerContactsSvcPersonsChangedCallback();
+       void unregisterContactsSvcPersonsChangedCallback();
+       static void personsDbChangedCallback(const char* view_uri, char* changes, void* user_data);
+       void personsDbChangedCallback(const char* view_uri, char* changes);
+
+       typedef std::set<IContactsSvcPersonsChangeListener *> PersonsChangeListenerSet;
+       PersonsChangeListenerSet m_personsChangeListenerSet;
+       bool m_personsChangedCallbackRegistered;
+       void personsChangedCallback(char* changes);
+
+       int m_latestVersion;
+
+       long m_watchIdAcc;
+
+public:
+       friend class DPL::Singleton<ContactsSvcChangeListenerManager>;
+};
+
+typedef DPL::Singleton<ContactsSvcChangeListenerManager> ContactsSvcChangeListenerManagerSingleton;
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // TIZENAPIS_PLATFORM_CONTACT_CONTACT_LISTENER_MANAGER_H_
diff --git a/src/platform/Tizen/Contact/ContactsSvcObjectConverter.cpp b/src/platform/Tizen/Contact/ContactsSvcObjectConverter.cpp
new file mode 100755 (executable)
index 0000000..1f5267a
--- /dev/null
@@ -0,0 +1,444 @@
+//
+// 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        ContactObjectP2AConverter.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Converter (contacts_record_h -> TizenApis::Api::Contact::ContactPtr)
+ */
+
+#include "ContactsSvcObjectConverter.h"
+
+#include <vector>
+#include <pcrecpp.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+#include "Contact.h"
+#include "ContactUtility.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+static const char *EMPTY_STRING = "";
+
+ContactsSvcObjectConverter::ContactsSvcObjectConverter()
+{
+}
+
+ContactsSvcObjectConverter::~ContactsSvcObjectConverter()
+{
+}
+
+void ContactsSvcObjectConverter::convertToAbstract(contacts_record_h record, PersonPtr& person)
+{
+       if(record == NULL)
+       {
+               ThrowMsg(InvalidArgumentException, "Platform person object did not set");
+       }
+
+       if(person == NULL)
+       {
+               ThrowMsg(InvalidArgumentException, "Abstract person object did not set");
+       }
+
+       char *charValue = NULL;
+       int intValue = 0;
+       bool boolValue = false;
+
+       int errorCode = 0;
+
+       // id
+       errorCode = contacts_record_get_int(record, _contacts_person.id, &intValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_int (id) (errorCode:" << errorCode << ")");
+
+       person->setId(intValue);
+
+       // displayName
+       errorCode = contacts_record_get_str_p(record, _contacts_person.display_name, &charValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_str_p (display_name) (errorCode:" << errorCode << ")");
+
+       if (charValue)
+               person->setDisplayName(charValue);
+       else
+       {
+               if(person->getDisplayNameIsSet())
+                       person->unsetDisplayName();
+       }
+
+       // contactCount
+       errorCode = contacts_record_get_int(record, _contacts_person.link_count, &intValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_int (link_count) (errorCode:" << errorCode << ")");
+
+       person->setContactCount(intValue);
+
+       // hasPhoneNumber
+       errorCode = contacts_record_get_bool(record, _contacts_person.has_phonenumber, &boolValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_bool (has_phonenumber) (errorCode:" << errorCode << ")");
+
+       person->setHasPhoneNumber(boolValue);
+
+       // hasEmail
+       errorCode = contacts_record_get_bool(record, _contacts_person.has_email, &boolValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_bool (has_email) (errorCode:" << errorCode << ")");
+
+       person->setHasEmail(boolValue);
+
+       // isFavorite
+       errorCode = contacts_record_get_bool(record, _contacts_person.is_favorite, &boolValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_bool (is_favorite) (errorCode:" << errorCode << ")");
+
+       person->setIsFavorite(boolValue);
+
+       // photoURI
+       errorCode = contacts_record_get_str_p(record, _contacts_person.image_thumbnail_path, &charValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_str_p (image_thumbnail_path) (errorCode:" << errorCode << ")");
+
+       if (charValue)
+               person->setPhotoURI(ContactUtility::convertPathToUri(charValue));
+       else
+       {
+               if(person->getPhotoURIIsSet())
+                       person->unsetPhotoURI();
+       }
+
+       // ringtoneURI
+       errorCode = contacts_record_get_str_p(record, _contacts_person.ringtone_path, &charValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_str_p (ringtone_path) (errorCode:" << errorCode << ")");
+
+       if (charValue)
+               person->setRingtoneURI(ContactUtility::convertPathToUri(charValue));
+       else
+       {
+               if(person->getRingtoneURIIsSet())
+                       person->unsetRingtoneURI();
+       }
+
+       // displayContactId
+       errorCode = contacts_record_get_int(record, _contacts_person.display_contact_id, &intValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_int (display_contact_id) (errorCode:" << errorCode << ")");
+
+       person->setDisplayContactId(intValue);
+}
+
+void ContactsSvcObjectConverter::convertToPlatform(PersonPtr& person, contacts_record_h record)
+{
+       if(record == NULL)
+       {
+               ThrowMsg(InvalidArgumentException, "Platform person object did not set");
+       }
+
+       if(person == NULL)
+       {
+               ThrowMsg(InvalidArgumentException, "Abstract person object did not set");
+       }
+
+       int errorCode = 0;
+
+       // isFavorite
+       bool boolValue = person->getIsFavorite();
+       errorCode = contacts_record_set_bool(record, _contacts_person.is_favorite, boolValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               ThrowMsg(PlatformException, "importing isFavorite E (err:" <<
+                               errorCode << ", value:" << boolValue << ")");
+       }
+
+       const char *newValueStr = NULL;
+       char *oldValueStr = NULL;
+       string abstractValueStr;
+       string realPath;
+
+       // photoURI
+       contacts_record_get_str_p(record, _contacts_person.image_thumbnail_path, &oldValueStr);
+       realPath = ContactUtility::convertUriToPath(person->getPhotoURI());
+       person->setPhotoURIRealPath(realPath);
+       abstractValueStr = person->getPhotoURIRealPath();
+       if(oldValueStr != NULL &&
+                       (!person->getPhotoURIIsSet() || person->getPhotoURI().empty()))
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(record, _contacts_person.image_thumbnail_path, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(PlatformException, "importing photoURI E (err:" <<
+                                       errorCode << ", str:" << abstractValueStr << ")");
+               }
+       }
+
+       // ringtoneURI
+       newValueStr = NULL;
+       oldValueStr = NULL;
+       contacts_record_get_str_p(record, _contacts_person.ringtone_path, &oldValueStr);
+       realPath = ContactUtility::convertUriToPath(person->getRingtoneURI());
+       person->setRingtoneURIRealPath(realPath);
+       abstractValueStr = person->getRingtoneURIRealPath();
+       if(oldValueStr != NULL &&
+                       (!person->getRingtoneURIIsSet() || person->getRingtoneURI().empty()))
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(record, _contacts_person.ringtone_path, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(PlatformException, "importing ringtoneURI E (err:" <<
+                                       errorCode << ", str:" << abstractValueStr << ")");
+               }
+       }
+
+       // displayContactId
+//     int intValue = ContactUtility::strToInt(person->getDisplayContactId());
+//     errorCode = contacts_record_set_int(record, _contacts_person.display_contact_id, intValue);
+//     if(errorCode != CONTACTS_ERROR_NONE)
+//     {
+//             ThrowMsg(PlatformException, "importing displayContactId E (err:" <<
+//                             errorCode << ", value:" << intValue << ")");
+//     } // FIXME platform still has problem on this field.
+}
+
+void ContactsSvcObjectConverter::convertToAbstract(contacts_record_h record, ContactPtr& contact)
+{
+
+}
+
+void ContactsSvcObjectConverter::convertToPlatform(ContactPtr& contact, contacts_record_h record)
+{
+
+}
+
+void ContactsSvcObjectConverter::convertToAbstract(contacts_record_h record, ContactGroupPtr& group)
+{
+       if(record == NULL)
+       {
+               ThrowMsg(InvalidArgumentException, "Platform group object did not set");
+       }
+
+       if(group == NULL)
+       {
+               ThrowMsg(InvalidArgumentException, "Abstract group object did not set");
+       }
+
+       char *charValue = NULL;
+       int intValue = 0;
+       bool boolValue = false;
+
+       int errorCode = 0;
+
+       // id
+       errorCode = contacts_record_get_int(record, _contacts_group.id, &intValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_int (id) (errorCode:" << errorCode << ")");
+
+       group->setId(intValue);
+
+       // addressBookId
+       errorCode = contacts_record_get_int(record, _contacts_group.address_book_id, &intValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_int (address_book_id) (errorCode:" << errorCode << ")");
+
+       group->setAddressBookId(intValue);
+
+
+       // name
+       errorCode = contacts_record_get_str_p(record, _contacts_group.name, &charValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_str_p (name) (errorCode:" << errorCode << ")");
+
+       if (charValue)
+               group->setName(charValue);
+       else
+       {
+               if(group->getNameIsSet())
+                       group->unsetName();
+       }
+
+       // photoURI
+       errorCode = contacts_record_get_str_p(record, _contacts_group.image_path, &charValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_str_p (image_path) (errorCode:" << errorCode << ")");
+
+       if (charValue)
+               group->setPhotoURI(ContactUtility::convertPathToUri(charValue));
+       else
+       {
+               if(group->getPhotoURIIsSet())
+                       group->unsetPhotoURI();
+       }
+
+       // ringtoneURI
+       errorCode = contacts_record_get_str_p(record, _contacts_group.ringtone_path, &charValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_str_p (ringtone_path) (errorCode:" << errorCode << ")");
+
+       if (charValue)
+               group->setRingtoneURI(ContactUtility::convertPathToUri(charValue));
+       else
+       {
+               if(group->getRingtoneURIIsSet())
+                       group->unsetRingtoneURI();
+       }
+
+       // isFavorite
+       errorCode = contacts_record_get_bool(record, _contacts_group.is_read_only, &boolValue);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "error on contacts_record_get_bool (is_read_only) (errorCode:" << errorCode << ")");
+
+       group->setReadOnly(boolValue);
+}
+
+void ContactsSvcObjectConverter::convertToPlatform(ContactGroupPtr& group, contacts_record_h record)
+{
+       if(record == NULL)
+       {
+               ThrowMsg(InvalidArgumentException, "Platform group object did not set");
+       }
+
+       if(group == NULL)
+       {
+               ThrowMsg(InvalidArgumentException, "Abstract group object did not set");
+       }
+
+       int errorCode = 0;
+
+//     // addressBookId
+//     //int addressBookId = 0;        // TODO Check what happen if address_book_id is not set
+//     //contacts_record_get_int(record, _contacts_group.address_book_id, &addressBookId);
+//
+//     int intValue = group->getAddressBookId();
+//     errorCode = contacts_record_set_int(record, _contacts_group.address_book_id, intValue);
+//     if(errorCode != CONTACTS_ERROR_NONE)
+//     {
+//             ThrowMsg(PlatformException, "importing displayContactId E (err:" <<
+//                             errorCode << ", value:" << intValue << ")");
+//     }
+
+       const char *newValueStr = NULL;
+       char *oldValueStr = NULL;
+       string abstractValueStr;
+       string realPath;
+
+       // name
+       contacts_record_get_str_p(record, _contacts_group.name, &oldValueStr);
+       abstractValueStr = group->getName();
+       if(oldValueStr != NULL &&
+                       (!group->getNameIsSet() || group->getName().empty()))
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(record, _contacts_group.name, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(PlatformException, "importing name E (err:" <<
+                                       errorCode << ", str:" << abstractValueStr << ")");
+               }
+       }
+
+       // photoURI
+       newValueStr = NULL;
+       oldValueStr = NULL;
+       contacts_record_get_str_p(record, _contacts_group.image_path, &oldValueStr);
+       realPath = ContactUtility::convertUriToPath(group->getPhotoURI());
+       group->setPhotoURIRealPath(realPath);
+       abstractValueStr = group->getPhotoURIRealPath();
+       if(oldValueStr != NULL &&
+                       (!group->getPhotoURIIsSet() || group->getPhotoURI().empty()))
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(record, _contacts_group.image_path, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(PlatformException, "importing photoURI E (err:" <<
+                                       errorCode << ", str:" << abstractValueStr << ")");
+               }
+       }
+
+       // ringtoneURI
+       newValueStr = NULL;
+       oldValueStr = NULL;
+       contacts_record_get_str_p(record, _contacts_group.ringtone_path, &oldValueStr);
+       realPath = ContactUtility::convertUriToPath(group->getRingtoneURI());
+       group->setRingtoneURIRealPath(realPath);
+       abstractValueStr = group->getRingtoneURIRealPath();
+       if(oldValueStr != NULL &&
+                       (!group->getRingtoneURIIsSet() || group->getRingtoneURI().empty()))
+       {
+               newValueStr = EMPTY_STRING;
+       }
+       else if(oldValueStr == NULL || abstractValueStr != oldValueStr)
+       {
+               newValueStr = abstractValueStr.c_str();
+       }
+
+       if(newValueStr != NULL)
+       {
+               errorCode = contacts_record_set_str(record, _contacts_group.ringtone_path, newValueStr);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(PlatformException, "importing ringtoneURI E (err:" <<
+                                       errorCode << ", str:" << abstractValueStr << ")");
+               }
+       }
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactsSvcObjectConverter.h b/src/platform/Tizen/Contact/ContactsSvcObjectConverter.h
new file mode 100755 (executable)
index 0000000..90f7f2e
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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        ContactsSvcObjectConverter.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Converter (contacts_record_h -> TizenApis::Api::Contact::ContactPtr)
+ */
+
+#ifndef _PLATFORM_CONTACT_CONTACTS_SVC_OBJECT_CONVERTER_H_
+#define _PLATFORM_CONTACT_CONTACTS_SVC_OBJECT_CONVERTER_H_
+
+#include <string>
+#include <contacts.h>
+#include <dpl/shared_ptr.h>
+#include <API/Contact/IPerson.h>
+#include <API/Contact/IContact.h>
+#include <API/Contact/ContactGroup.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class ContactsSvcObjectConverter
+{
+public:
+       ContactsSvcObjectConverter();
+       virtual ~ContactsSvcObjectConverter();
+
+       static void convertToAbstract(contacts_record_h record, TizenApis::Api::Contact::PersonPtr& person);
+       static void convertToPlatform(TizenApis::Api::Contact::PersonPtr& person, contacts_record_h record);
+
+       static void convertToAbstract(contacts_record_h record, TizenApis::Api::Contact::ContactPtr& contact);
+       static void convertToPlatform(TizenApis::Api::Contact::ContactPtr& contact, contacts_record_h record);
+
+       static void convertToAbstract(contacts_record_h record, TizenApis::Api::Contact::ContactGroupPtr& group);
+       static void convertToPlatform(TizenApis::Api::Contact::ContactGroupPtr& group, contacts_record_h record);
+};
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_CONTACTS_SVC_OBJECT_CONVERTER_H_
diff --git a/src/platform/Tizen/Contact/ContactsSvcWrapper.cpp b/src/platform/Tizen/Contact/ContactsSvcWrapper.cpp
new file mode 100755 (executable)
index 0000000..37db022
--- /dev/null
@@ -0,0 +1,267 @@
+//
+// 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        ContactsSvcWrapper.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactsSvcWrapper.h"
+
+#include <contacts.h>
+#include <dpl/exception.h>
+#include <dpl/singleton_impl.h>
+#include "AddressBook.h"
+
+IMPLEMENT_SINGLETON(TizenApis::Platform::Contact::ContactsSvcWrapper)
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Api::Contact;
+
+// Caution : This class MUST be used on an identical thread.
+
+ContactsSvcWrapper::ContactsSvcWrapper() :
+       m_opened(false),
+       m_defaultAddressBook(NULL),
+       m_addressBooks(new AddressBookArray())
+{
+       init();
+}
+
+ContactsSvcWrapper::~ContactsSvcWrapper()
+{
+       //when it is last instance then close connection to database
+       if(m_opened)
+       {
+               int ret = contacts_disconnect2();
+               if (ret != CONTACTS_ERROR_NONE)
+               {
+                       //error during closing contacts database
+                       LogError("Error occurred during closing contacts database. (ret:" << ret << ")");
+               }
+       }
+}
+
+AddressBookPtr ContactsSvcWrapper::getAddressBook(const std::string &id)
+{
+       init();
+
+       if(!m_opened) {
+               //when database is not opened then set result as failed
+               LogError("Contact db is not open.");
+               ThrowMsg(PlatformException, "Contact DB is not open.");
+       }
+
+       if(m_idMap.find(id) == m_idMap.end())
+               ThrowMsg(NotFoundException, "No AddressBook id:" << id);
+
+       int index = m_idMap[id];
+
+       if(static_cast<int>(m_addressBooks->size()) <= index)
+               ThrowMsg(NotFoundException, "No AddressBook id:" << id);
+
+       return m_addressBooks->at(index);
+}
+
+AddressBookPtr ContactsSvcWrapper::getDefaultAddressBook()
+{
+       init();
+
+       if(!m_opened) {
+               //when database is not opened then set result as failed
+               LogError("Contact db is not open.");
+               ThrowMsg(PlatformException, "Contact DB is not open.");
+       }
+
+       if(m_addressBooks->size() == 0)
+               ThrowMsg(PlatformException, "Invalid request");
+
+       return m_defaultAddressBook;
+}
+
+AddressBookArrayPtr ContactsSvcWrapper::getAddressBooks()
+{
+       init();
+
+       if(!m_opened) {
+               //when database is not opened then set result as failed
+               LogError("Contact db is not open.");
+               ThrowMsg(PlatformException, "Contact DB is not open.");
+       }
+
+       AddressBookArrayPtr newArray(new AddressBookArray());
+
+       for(AddressBookArray::iterator i = m_addressBooks->begin(); i != m_addressBooks->end(); i++)
+               newArray->push_back(*i);
+
+       return newArray;
+}
+
+void ContactsSvcWrapper::init()
+{
+       if (m_opened)
+               return;
+
+       LogDebug("entered");
+
+       int ret = contacts_connect2();
+       if (ret != CONTACTS_ERROR_NONE)
+       {
+               //error during opening contacts database
+               LogError("Error occurred during opening contacts database. (ret:"
+                               << ret << ")");
+               m_opened = false;
+
+               return;
+       }
+
+       //contacts-service has properly connected.
+       LogDebug("Contact db has properly opened.");
+       m_opened = true;
+
+       loadAddressBooks();
+}
+
+void ContactsSvcWrapper::loadAddressBooks()
+{
+       LogDebug("Loading AddressBook");
+
+       int errorCode = 0;
+       contacts_list_h addressbooks_list = NULL;
+
+       errorCode = contacts_db_get_all_records(_contacts_address_book._uri, 0, 0, &addressbooks_list);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogError("Fail to get addressbook list (ret:" << errorCode << ")");
+               return;
+       }
+
+       unsigned int record_count = 0;
+       errorCode = contacts_list_get_count(addressbooks_list, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE)
+       {
+               LogError("Fail to get addressbook list count (ret:" << errorCode << ")");
+               return;
+       }
+
+       contacts_list_first(addressbooks_list);
+       for(unsigned int i=0; i<record_count; i++)
+       {
+               contacts_record_h contacts_record;
+               errorCode = contacts_list_get_current_record_p(addressbooks_list, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
+               {
+                       LogWarning("Fail to get addressbook record (ret:" << errorCode << ")");
+                       continue;
+               }
+
+               int id, accountId, mode;
+               char *name;
+
+               errorCode = contacts_record_get_int(contacts_record, _contacts_address_book.id, &id);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to get id from address book (ret:" << errorCode << ")");
+                       continue;
+               }
+
+               errorCode = contacts_record_get_int(contacts_record, _contacts_address_book.account_id, &accountId);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to get account id from address book (ret:" << errorCode << ")");
+                       continue;
+               }
+
+               errorCode = contacts_record_get_int(contacts_record, _contacts_address_book.mode, &mode);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to get mode from address book (ret:" << errorCode << ")");
+                       continue;
+               }
+
+               errorCode = contacts_record_get_str_p(contacts_record, _contacts_address_book.name, &name);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to get name from address book (ret:" << errorCode << ")");
+                       continue;
+               }
+
+               LogDebug(" AddressBook [id:" << id << ", name:" << name <<
+                               ", accId:" << accountId << ", mode:" << mode << "]");
+
+               AddressBook *addressBook = new AddressBook(false);
+               addressBook->setId(id);
+               addressBook->setName(name);
+               addressBook->setAccountId(accountId);
+               addressBook->setReadOnly(mode == CONTACTS_ADDRESS_BOOK_MODE_READONLY);
+
+               insert(AddressBookPtr(addressBook));
+
+               errorCode = contacts_list_next(addressbooks_list);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       LogWarning("Fail to get netx address book (ret:" << errorCode << ")");
+                       break;
+               }
+       }
+
+       if(size() == 0) // No address book has been created
+       {
+               AddressBook *addressBook = new AddressBook(false);
+               addressBook->setId(0);
+               addressBook->setName("phone");
+               addressBook->setAccountId(0);
+               addressBook->setReadOnly(false);
+
+               insert(AddressBookPtr(addressBook));
+               LogDebug(" Inserted default address book");
+       }
+
+       // create default address book
+       AddressBook *addressBook = new AddressBook(true);
+       addressBook->setName("default address book");
+       addressBook->setReadOnly(false);
+
+       m_defaultAddressBook = AddressBookPtr(addressBook);
+}
+
+int ContactsSvcWrapper::size() const
+{
+       return m_idMap.size();
+}
+
+void ContactsSvcWrapper::insert(AddressBookPtr addressBook)
+{
+       int index;
+       std::string id = addressBook->getId();
+
+       index = m_addressBooks->size();
+
+       m_idMap[id] = index;
+
+       m_addressBooks->push_back(addressBook);
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/ContactsSvcWrapper.h b/src/platform/Tizen/Contact/ContactsSvcWrapper.h
new file mode 100755 (executable)
index 0000000..1e4cac6
--- /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.
+//
+
+/**
+ * @file        ContactsSvcWrapper.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _PLATFORM_CONTACT_ADDRESS_BOOK_STORAGE_H_
+#define _PLATFORM_CONTACT_ADDRESS_BOOK_STORAGE_H_
+
+#include <string>
+#include <map>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <API/Contact/IAddressBook.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class ContactsSvcWrapper
+{
+public:
+       ContactsSvcWrapper();
+       virtual ~ContactsSvcWrapper();
+
+       TizenApis::Api::Contact::AddressBookPtr getAddressBook(const std::string &id);
+       TizenApis::Api::Contact::AddressBookPtr getDefaultAddressBook();
+       TizenApis::Api::Contact::AddressBookArrayPtr getAddressBooks();
+
+private:
+       void init();
+
+       void loadAddressBooks();
+       void insert(TizenApis::Api::Contact::AddressBookPtr addressBook);
+       int size() const;
+
+private:
+       bool m_opened;
+
+       TizenApis::Api::Contact::AddressBookPtr m_defaultAddressBook;
+       TizenApis::Api::Contact::AddressBookArrayPtr m_addressBooks;
+       std::map<std::string, int> m_idMap;
+};
+typedef DPL::Singleton<ContactsSvcWrapper> ContactsSvcWrapperSingleton;
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_ADDRESS_BOOK_STORAGE_H_
diff --git a/src/platform/Tizen/Contact/Person.cpp b/src/platform/Tizen/Contact/Person.cpp
new file mode 100755 (executable)
index 0000000..97e7f9e
--- /dev/null
@@ -0,0 +1,273 @@
+//
+// 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        Person.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "Person.h"
+
+#include <dpl/log/log.h>
+#include <dpl/exception.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+#include "ContactUtility.h"
+#include "ContactsSvcObjectConverter.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+Person::Person()
+       : IPerson()
+{
+       LogDebug("entered");
+}
+
+Person::Person(contacts_record_h record)
+       : IPerson()
+{
+       LogDebug("entered");
+}
+
+Person::~Person()
+{
+}
+
+void Person::OnRequestReceived(const EventPersonLinkPtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+       contacts_record_h contacts_record = NULL;
+
+       int selfPersonId = 0;
+       int personId = 0;
+
+       Try
+       {
+               if(!event->getPersonIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "person id were not set.");
+
+               string personIdStr = event->getPersonId();
+
+               if(!ContactUtility::checkStrIsUInt(personIdStr))
+                       ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+
+               try {
+                       personId = ContactUtility::strToInt(personIdStr);
+                       selfPersonId = ContactUtility::strToInt(m_id);
+               } catch (...) {
+                       ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
+               }
+
+               errorCode = contacts_db_get_record(_contacts_person._uri, personId, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(contacts_record, true);
+                       ThrowMsg(NotFoundException, "No person (id:" << personId << ")");
+               }
+               contacts_record_destroy(contacts_record, true);
+               contacts_record = NULL;
+
+               LogDebug("Linking person : " << personId);
+
+               errorCode = contacts_person_link_person(selfPersonId, personId);
+               if(errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
+                       ThrowMsg(NotFoundException, "Error during executing contacts_db_delete_record()");
+               else if (errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Error during executing contacts_db_delete_record()");
+
+               errorCode = contacts_db_get_record(_contacts_person._uri, selfPersonId, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(contacts_record, true);
+                       ThrowMsg(NotFoundException, "No person (id:" << selfPersonId << ")");
+               }
+               PersonPtr person = PersonPtr(new Person());
+               ContactsSvcObjectConverter::convertToAbstract(contacts_record, person);
+
+               copy(person);
+
+               contacts_record_destroy(contacts_record, true);
+               contacts_record = NULL;
+
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid person id : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Person doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               return;
+       }
+       Catch (PlatformException) {
+               LogError("Error during linking person : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       Catch (Exception) {
+               LogError("Error during linking person : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+}
+
+void Person::OnRequestReceived(const EventPersonUnlinkPtr &event)
+{
+       LogDebug("entered");
+
+       int errorCode = 0;
+       int selfPersonId;
+       int contactId;
+       contacts_record_h contacts_record = NULL;
+
+       Try
+       {
+               if(!event->getContactIdIsSet())
+                       ThrowMsg(InvalidArgumentException, "contact id were not set.");
+
+               string contactIdStr = event->getContactId();
+
+               if(!ContactUtility::checkStrIsUInt(contactIdStr))
+                       ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
+
+               try {
+                       selfPersonId = ContactUtility::strToInt(m_id);
+                       contactId = ContactUtility::strToInt(contactIdStr);
+               } catch (...) {
+                       ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
+               }
+
+               errorCode = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(contacts_record, true);
+                       ThrowMsg(NotFoundException, "No contact (id:" << contactId << ")");
+               }
+
+               int contactsPersonId = 0;
+               errorCode = contacts_record_get_int(contacts_record, _contacts_simple_contact.person_id, &contactsPersonId);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(contacts_record, true);
+                       ThrowMsg(NotFoundException, "Contact (id:" << contactId << ") is not a member of person");
+               }
+               contacts_record_destroy(contacts_record, true);
+               contacts_record = NULL;
+
+               if(contactsPersonId != selfPersonId)
+               {
+                       ThrowMsg(OutOfRangeException, "Contact (id:" << contactId << ") is not a member of person");
+               }
+
+               LogDebug("Unlinking contact : " << contactId);
+
+               int newPersonId = 0;
+               int errorCode = contacts_person_unlink_contact(selfPersonId, contactId, &newPersonId);
+               if(errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
+                       ThrowMsg(NotFoundException, "Error during executing contacts_person_unlink_contact()");
+               else if (errorCode != CONTACTS_ERROR_NONE)
+                       ThrowMsg(PlatformException, "Error during executing contacts_person_unlink_contact()");
+               LogDebug("newPersonId : " << newPersonId);
+
+               errorCode = contacts_db_get_record(_contacts_person._uri, newPersonId, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       ThrowMsg(NotFoundException, "No person (id:" << newPersonId << ")");
+               }
+               PersonPtr person = PersonPtr(new Person());
+               ContactsSvcObjectConverter::convertToAbstract(contacts_record, person);
+               event->setPerson(person);
+               contacts_record_destroy(contacts_record, true);
+               contacts_record = NULL;
+
+               errorCode = contacts_db_get_record(_contacts_person._uri, selfPersonId, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE)
+               {
+                       contacts_record_destroy(contacts_record, true);
+                       ThrowMsg(NotFoundException, "No person (id:" << selfPersonId << ")");
+               }
+               person = PersonPtr(new Person());
+               ContactsSvcObjectConverter::convertToAbstract(contacts_record, person);
+
+               copy(person);
+
+               contacts_record_destroy(contacts_record, true);
+               contacts_record = NULL;
+
+               event->setResult(true);
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       Catch (InvalidArgumentException)
+       {
+               LogError("Invalid person id : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+               return;
+       }
+       Catch (NotFoundException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::NotFoundException);
+               return;
+       }
+       Catch (OutOfRangeException)
+       {
+               LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::OutOfRangeException);
+               return;
+       }
+       Catch (PlatformException) {
+               LogError("Error during linking person : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+       Catch (Exception) {
+               LogError("Error during linking person : " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+               return;
+       }
+
+       if(contacts_record != NULL)
+               contacts_record_destroy(contacts_record, true);
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/Person.h b/src/platform/Tizen/Contact/Person.h
new file mode 100755 (executable)
index 0000000..5f85fb0
--- /dev/null
@@ -0,0 +1,62 @@
+//
+// 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        Person.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _PLATFORM_CONTACT_PERSON_H_
+#define _PLATFORM_CONTACT_PERSON_H_
+
+#include <string>
+#include <vector>
+#include <contacts.h>
+#include <API/Contact/IPerson.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class Person : public TizenApis::Api::Contact::IPerson
+{
+public:
+       Person();
+       Person(contacts_record_h record);
+       virtual ~Person();
+
+       virtual void link(const TizenApis::Api::Contact::EventPersonLinkPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+       virtual void unlink(const TizenApis::Api::Contact::EventPersonUnlinkPtr &event)
+       {
+               OnRequestReceived(event);
+       }
+
+protected:
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventPersonLinkPtr &event);
+       virtual void OnRequestReceived(const TizenApis::Api::Contact::EventPersonUnlinkPtr &event);
+};
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_PERSON_H_
diff --git a/src/platform/Tizen/Contact/PersonFilterValidator.cpp b/src/platform/Tizen/Contact/PersonFilterValidator.cpp
new file mode 100755 (executable)
index 0000000..57463df
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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        PersonFilterValidator.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "PersonFilterValidator.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Tizen;
+
+static PropertyStructArray properties =
+{
+       {"id",                                          PrimitiveType_String},
+       {"displayName",                         PrimitiveType_String},
+       {"contactCount",                        PrimitiveType_Integer},
+       {"hasPhoneNumber",                      PrimitiveType_Boolean},
+       {"hasEmail",                            PrimitiveType_Boolean},
+       {"isFavorite",                          PrimitiveType_Boolean},
+       {"photoURI",                            PrimitiveType_String},
+       {"ringtoneURI",                         PrimitiveType_String},
+       {"displayContactId",            PrimitiveType_String},
+       {0,     PrimitiveType_NoType}
+};
+
+FilterValidatorPtr PersonFilterValidatorFactory::getPersonFilterValidator()
+{
+    static FilterValidatorPtr theInstance =
+               FilterValidatorPtr(new FilterValidator(properties));
+    return theInstance;
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/PersonFilterValidator.h b/src/platform/Tizen/Contact/PersonFilterValidator.h
new file mode 100755 (executable)
index 0000000..fefe6eb
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// 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        PersonFilterValidator.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _PLATFORM_CONTACT_PERSON_FILTER_VALIDATOR_H_
+#define _PLATFORM_CONTACT_PERSON_FILTER_VALIDATOR_H_
+
+#include <API/Filter/FilterValidator.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class PersonFilterValidatorFactory : private DPL::Noncopyable
+{
+private:
+       PersonFilterValidatorFactory()
+       {
+       }
+
+public:
+       static TizenApis::Api::Tizen::FilterValidatorPtr        getPersonFilterValidator();
+};
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_PERSON_FILTER_VALIDATOR_H_
diff --git a/src/platform/Tizen/Contact/PersonSearchEngine.cpp b/src/platform/Tizen/Contact/PersonSearchEngine.cpp
new file mode 100755 (executable)
index 0000000..e33c486
--- /dev/null
@@ -0,0 +1,457 @@
+//
+// 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        PersonSearchEngine.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "PersonSearchEngine.h"
+
+#include <ctime>
+#include <algorithm>
+#include <Commons/Exception.h>
+#include "Person.h"
+#include "ContactUtility.h"
+#include "ContactsSvcObjectConverter.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+map<string, PersonSearchEngine::FilterPropertyStruct> PersonSearchEngine::attrEnumMap = {
+               {"id",                                          { _contacts_person.id,                  PrimitiveType_Long } },
+               {"displayName",                         { _contacts_person.display_name,        PrimitiveType_String } },
+               {"contactCount",                        { _contacts_person.link_count,          PrimitiveType_Long } },
+               {"hasPhoneNumber",                      { _contacts_person.has_phonenumber,     PrimitiveType_Boolean } },
+               {"hasEmail",                            { _contacts_person.has_email,           PrimitiveType_Boolean } },
+               {"isFavorite",                          { _contacts_person.is_favorite,         PrimitiveType_Boolean } },
+               {"photoURI",                            { _contacts_person.image_thumbnail_path,PrimitiveType_String } },
+               {"ringtoneURI",                         { _contacts_person.ringtone_path,       PrimitiveType_String } },
+               {"displayContactId",            { _contacts_person.display_contact_id,  PrimitiveType_String } },
+};
+
+PersonSearchEngine::PersonSearchEngine() :
+               m_query(NULL),
+               m_filter(NULL)
+{
+       contacts_query_create(_contacts_person._uri, &m_query);
+}
+
+PersonSearchEngine::~PersonSearchEngine()
+{
+       if(m_filter != NULL)
+               contacts_filter_destroy(m_filter);
+
+       if(m_query != NULL)
+               contacts_query_destroy(m_query);
+}
+
+void PersonSearchEngine::setCondition(FilterPtr filter)
+{
+       if(!filter)
+               return;
+
+       IFilterVisitorPtr filterQuery = DPL::StaticPointerCast<IFilterVisitor>(SharedFromThis());
+       filter->travel(filterQuery);
+
+       contacts_query_set_filter(m_query, m_filter);
+}
+
+void PersonSearchEngine::setSortMode(SortModePtr attr)
+{
+       if(attr == NULL)
+               return;
+
+       string attrName = attr->getAttributeName();
+
+       map<string, PersonSearchEngine::FilterPropertyStruct>::iterator iter = attrEnumMap.find(attrName);
+       if(iter == attrEnumMap.end())
+       {
+               ThrowMsg(InvalidArgumentException, "SortMode don't support " << attrName);
+       }
+
+       FilterPropertyStruct property = iter->second;
+
+       bool is_ascending;
+       if(attr->getOrder() == ASCENDING_SORT_ORDER)
+               is_ascending = true;
+       else
+               is_ascending = false;
+
+       contacts_query_set_sort(m_query, property.propertyId, is_ascending);
+}
+
+PersonArrayPtr PersonSearchEngine::getResult()
+{
+       int errorCode = 0;
+       contacts_list_h person_list = NULL;
+
+       PersonArrayPtr persons = PersonArrayPtr(new PersonArray());
+
+       errorCode = contacts_db_get_records_with_query(m_query, 0, 0, &person_list);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "Fail to get contacts_db_get_records_with_query (ret:" << errorCode << ")");
+
+       unsigned int record_count = 0;
+       errorCode = contacts_list_get_count(person_list, &record_count);
+       if(errorCode != CONTACTS_ERROR_NONE)
+               ThrowMsg(PlatformException, "Fail to get contacts_list_get_count (ret:" << errorCode << ")");
+
+       contacts_list_first(person_list);
+       for(unsigned int i=0; i<record_count; i++)
+       {
+               contacts_record_h contacts_record;
+               errorCode = contacts_list_get_current_record_p(person_list, &contacts_record);
+               if(errorCode != CONTACTS_ERROR_NONE || contacts_record == NULL)
+               {
+                       LogWarning("Fail to get group record (ret:" << errorCode << ")");
+                       continue;
+               }
+
+               PersonPtr person = PersonPtr(new Person());
+
+               ContactsSvcObjectConverter::convertToAbstract(contacts_record, person);
+
+               persons->push_back(person);
+
+               contacts_list_next(person_list);
+       }
+
+       if(person_list != NULL)
+               contacts_list_destroy(person_list, true);
+
+       return persons;
+}
+
+void PersonSearchEngine::visitPreComposite(FilterType& type, int depth)
+{
+       int errorCode = 0;
+       contacts_filter_h filter = NULL;
+
+       errorCode = contacts_filter_create(_contacts_person._uri, &filter);
+
+       m_filterStack.push(filter);
+       if(depth == 0)
+       {
+               m_filter = filter;
+       }
+}
+
+void PersonSearchEngine::visitInComposite(FilterType& type, int depth)
+{
+       int errorCode = 0;
+
+       contacts_filter_h filter = NULL;
+       contacts_filter_operator_e operator_type = CONTACTS_FILTER_OPERATOR_OR;
+
+       filter = m_filterStack.top();
+
+       if(type == UNION_FILTER)
+               operator_type = CONTACTS_FILTER_OPERATOR_OR;
+       else if(type == INTERSECTION_FILTER)
+               operator_type = CONTACTS_FILTER_OPERATOR_AND;
+
+       errorCode = contacts_filter_add_operator(filter, operator_type);
+}
+
+void PersonSearchEngine::visitPostComposite(FilterType& type, int depth)
+{
+       int errorCode = 0;
+       contacts_filter_h filter = NULL;
+
+       filter = m_filterStack.top();
+       m_filterStack.pop();
+
+       if(depth != 0)
+       {
+               contacts_filter_h parent_filter = NULL;
+               parent_filter = m_filterStack.top();
+               errorCode = contacts_filter_add_filter(parent_filter, filter);
+       }
+}
+
+void PersonSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag, AnyPtr& matchValue, int depth)
+{
+       int errorCode = 0;
+       contacts_filter_h filter = NULL;
+
+       if(depth != 0)
+       {
+               filter = m_filterStack.top();
+       }
+       else
+       {
+               errorCode = contacts_filter_create(_contacts_person._uri, &filter);
+               m_filterStack.push(filter);
+               m_filter = filter;
+       }
+
+       FilterPropertyStruct property = attrEnumMap[attrName];
+
+       if(property.type == PrimitiveType_Long)
+       {
+               int value = 0;
+               if(attrName == "id")
+               {
+                       string valueStr = matchValue->getString();
+                       value = ContactUtility::strToInt(valueStr);
+               }
+               else
+                       value = matchValue->getLong();
+
+               contacts_match_int_flag_e flag;
+               if(matchFlag == MATCH_EXISTS)
+                       flag = CONTACTS_MATCH_NONE;
+               else
+                       flag = CONTACTS_MATCH_EQUAL;
+
+               errorCode = contacts_filter_add_int(filter, property.propertyId, flag, value);
+       }
+       else if(property.type == PrimitiveType_String)
+       {
+               string value = matchValue->getString();
+
+               contacts_match_str_flag_e flag = CONTACTS_MATCH_EXISTS;
+               if(matchFlag == MATCH_EXACTLY)
+                       flag = CONTACTS_MATCH_EXACTLY;
+               else if(matchFlag == MATCH_FULLSTRING)
+                       flag = CONTACTS_MATCH_FULLSTRING;
+               else if(matchFlag == MATCH_CONTAINS)
+                       flag = CONTACTS_MATCH_CONTAINS;
+               else if(matchFlag == MATCH_STARTSWITH)
+                       flag = CONTACTS_MATCH_STARTSWITH;
+               else if(matchFlag == MATCH_ENDSWITH)
+                       flag = CONTACTS_MATCH_ENDSWITH;
+               else if(matchFlag == MATCH_EXISTS)
+                       flag = CONTACTS_MATCH_EXISTS;
+
+               contacts_filter_add_str(filter, property.propertyId, flag, value.c_str());
+       }
+       else if(property.type == PrimitiveType_Boolean)
+       {
+               bool value = false;
+               value = matchValue->getBool();
+
+               // TODO MATCH_EXISTS
+//             if(matchFlag == MATCH_EXISTS)
+//             else
+
+               errorCode = contacts_filter_add_bool(filter, property.propertyId, value);
+       }
+}
+
+void PersonSearchEngine::visitAttributeRange(string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth)
+{
+       int errorCode = 0;
+       contacts_filter_h filter = NULL;
+
+       if(depth != 0)
+       {
+               filter = m_filterStack.top();
+       }
+       else
+       {
+               errorCode = contacts_filter_create(_contacts_person._uri, &filter);
+               m_filterStack.push(filter);
+               m_filter = filter;
+       }
+
+       FilterPropertyStruct property = attrEnumMap[attrName];
+
+       if(property.type == PrimitiveType_Long)
+       {
+               int initialValueInt = 0;
+               int endValueInt = 0;
+
+               bool initialValueExists = false;
+               bool endValueExists = false;
+
+               if(!initialValue->isNullOrUndefined())
+               {
+                       if(attrName == "id")
+                       {
+                               string valueStr = initialValue->getString();
+                               initialValueInt = ContactUtility::strToInt(valueStr);
+                       }
+                       else
+                               initialValueInt = initialValue->getLong();
+
+                       initialValueExists = true;
+               }
+
+               if(!endValue->isNullOrUndefined())
+               {
+                       if(attrName == "id")
+                       {
+                               string valueStr = endValue->getString();
+                               endValueInt = ContactUtility::strToInt(valueStr);
+                       }
+                       else
+                               endValueInt = endValue->getLong();
+
+                       endValueExists = true;
+               }
+
+
+               if(initialValueExists && endValueExists)
+               {
+                       contacts_filter_h sub_filter = NULL;
+                       if(depth != 0)
+                       {
+                               errorCode = contacts_filter_create(_contacts_person._uri, &sub_filter);
+                       }
+                       else
+                       {
+                               sub_filter = filter;
+                       }
+
+                       errorCode = contacts_filter_add_int(sub_filter, property.propertyId,
+                                       CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, initialValueInt);
+
+                       contacts_filter_add_operator(sub_filter, CONTACTS_FILTER_OPERATOR_AND);
+
+                       errorCode = contacts_filter_add_int(sub_filter, property.propertyId,
+                                       CONTACTS_MATCH_LESS_THAN_OR_EQUAL, endValueInt);
+
+                       if(depth != 0)
+                       {
+                               errorCode = contacts_filter_add_filter(filter, sub_filter);
+                       }
+               }
+               else if(initialValueExists)
+               {
+                       errorCode = contacts_filter_add_int(filter, property.propertyId,
+                                       CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, initialValueInt);
+               }
+               else if(endValueExists)
+               {
+                       errorCode = contacts_filter_add_int(filter, property.propertyId,
+                                       CONTACTS_MATCH_LESS_THAN_OR_EQUAL, endValueInt);
+               }
+       }
+       else if(property.type == PrimitiveType_String)
+       {
+               string initialValueStr = 0;
+               string endValueStr = 0;
+
+               bool initialValueExists = false;
+               bool endValueExists = false;
+
+               if(!initialValue->isNullOrUndefined())
+               {
+                       initialValueStr = initialValue->getLong();
+                       initialValueExists = true;
+               }
+
+               if(!endValue->isNullOrUndefined())
+               {
+                       endValueStr = endValue->getLong();
+                       endValueExists = true;
+               }
+
+
+               if(initialValueExists && endValueExists)
+               {
+                       contacts_filter_h sub_filter = NULL;
+                       if(depth != 0)
+                       {
+                               errorCode = contacts_filter_create(_contacts_person._uri, &sub_filter);
+                       }
+                       else
+                       {
+                               sub_filter = filter;
+                       }
+
+                       errorCode = contacts_filter_add_str(sub_filter, property.propertyId,
+                                       CONTACTS_MATCH_STARTSWITH, initialValueStr.c_str());
+
+                       contacts_filter_add_operator(sub_filter, CONTACTS_FILTER_OPERATOR_AND);
+
+                       errorCode = contacts_filter_add_str(sub_filter, property.propertyId,
+                                       CONTACTS_MATCH_ENDSWITH, endValueStr.c_str());
+
+                       if(depth != 0)
+                       {
+                               errorCode = contacts_filter_add_filter(filter, sub_filter);
+                       }
+               }
+               else if(initialValueExists)
+               {
+                       errorCode = contacts_filter_add_str(filter, property.propertyId,
+                                       CONTACTS_MATCH_STARTSWITH, initialValueStr.c_str());
+               }
+               else if(endValueExists)
+               {
+                       errorCode = contacts_filter_add_str(filter, property.propertyId,
+                                       CONTACTS_MATCH_ENDSWITH, endValueStr.c_str());
+               }
+       }
+       else if(property.type == PrimitiveType_Boolean)
+       {
+               bool initialValueBool = 0;
+               bool endValueBool = 0;
+
+               bool initialValueExists = false;
+               bool endValueExists = false;
+
+               if(!initialValue->isNullOrUndefined())
+               {
+                       initialValueBool = initialValue->getBool();
+                       initialValueExists = true;
+               }
+
+               if(!endValue->isNullOrUndefined())
+               {
+                       endValueBool = endValue->getBool();
+                       endValueExists = true;
+               }
+
+
+               if(initialValueExists && endValueExists)
+               {
+                       if(initialValueBool == endValueBool)
+                       {
+                               if(initialValueBool == true)
+                                       errorCode = contacts_filter_add_bool(filter, property.propertyId, true);
+                               else if(endValueBool == false)
+                                       errorCode = contacts_filter_add_bool(filter, property.propertyId, false);
+                       }
+               }
+               else if(initialValueExists)
+               {
+                       if(initialValueBool == true)
+                               errorCode = contacts_filter_add_bool(filter, property.propertyId, true);
+               }
+               else if(endValueExists)
+               {
+                       if(endValueBool == false)
+                               errorCode = contacts_filter_add_bool(filter, property.propertyId, false);
+               }
+       }
+}
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Contact/PersonSearchEngine.h b/src/platform/Tizen/Contact/PersonSearchEngine.h
new file mode 100755 (executable)
index 0000000..40fc27f
--- /dev/null
@@ -0,0 +1,91 @@
+//
+// 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        PersonSearchEngine.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _PLATFORM_CONTACT_PERSON_SEARCH_ENGINE_H_
+#define _PLATFORM_CONTACT_PERSON_SEARCH_ENGINE_H_
+
+#include <string>
+#include <map>
+#include <vector>
+#include <stack>
+#include <dpl/shared_ptr.h>
+#include <dpl/enable_shared_from_this.h>
+#include <API/Filter/IFilter.h>
+#include <API/Filter/SortMode.h>
+#include <API/Filter/IFilterVisitor.h>
+#include <API/Contact/IPerson.h>
+#include <contacts.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Contact {
+
+class PersonSearchEngine :
+       public TizenApis::Api::Tizen::IFilterVisitor,
+       public DPL::EnableSharedFromThis<PersonSearchEngine>
+{
+public:
+       PersonSearchEngine();
+       virtual ~PersonSearchEngine();
+
+       // setting search options.
+       void setCondition(TizenApis::Api::Tizen::FilterPtr filter = TizenApis::Api::Tizen::FilterPtr(NULL));
+       void setSortMode(TizenApis::Api::Tizen::SortModePtr attr = TizenApis::Api::Tizen::SortModePtr(NULL));
+
+       // getting results
+       TizenApis::Api::Contact::PersonArrayPtr getResult();
+
+       // inherited from IFilterVisitor
+       virtual void visitPreComposite(TizenApis::Api::Tizen::FilterType& type, int depth);
+       virtual void visitInComposite(TizenApis::Api::Tizen::FilterType& type, int depth);
+       virtual void visitPostComposite(TizenApis::Api::Tizen::FilterType& type, int depth);
+       virtual void visitAttribute(std::string& attrName,
+                       TizenApis::Api::Tizen::MatchFlag& matchFlag,
+                       TizenApis::Api::Tizen::AnyPtr& matchValue,
+                       int depth);
+       virtual void visitAttributeRange(std::string& attrName,
+                       TizenApis::Api::Tizen::AnyPtr& initialValue,
+                       TizenApis::Api::Tizen::AnyPtr& endValue,
+                       int depth);
+
+private:
+       contacts_query_h m_query;
+       contacts_filter_h m_filter;
+       std::stack<contacts_filter_h> m_filterStack;
+
+       struct FilterPropertyStruct
+       {
+               const unsigned int propertyId;
+           const TizenApis::Api::Tizen::PrimitiveType type;
+       };
+       static std::map<std::string, FilterPropertyStruct> attrEnumMap;
+};
+
+typedef DPL::SharedPtr<PersonSearchEngine> PersonSearchEnginePtr;
+
+} // Contact
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_CONTACT_PERSON_SEARCH_ENGINE_H_
diff --git a/src/platform/Tizen/Contact/config.cmake b/src/platform/Tizen/Contact/config.cmake
new file mode 100755 (executable)
index 0000000..095fe07
--- /dev/null
@@ -0,0 +1,37 @@
+get_current_path()
+
+pkg_search_module(contacts-service REQUIRED contacts-service2)
+pkg_search_module(pcrecpp REQUIRED libpcrecpp)
+pkg_search_module(download REQUIRED capi-web-url-download)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_CONTACT
+  ${contacts-service_INCLUDE_DIRS}
+  ${pcrecpp_INCLUDE_DIRS}
+  ${download_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_CONTACT
+  ${contacts-service_LIBRARIES}
+  ${pcrecpp_LIBRARIES}
+  ${download_LIBRARIES}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_CONTACT
+  ${CURRENT_PATH}/ContactManager.cpp
+  ${CURRENT_PATH}/AddressBook.cpp
+  ${CURRENT_PATH}/Contact.cpp
+  ${CURRENT_PATH}/Person.cpp
+  ${CURRENT_PATH}/ContactObjectA2PConverter.cpp
+  ${CURRENT_PATH}/ContactObjectP2AConverter.cpp
+  ${CURRENT_PATH}/ContactsSvcObjectConverter.cpp
+  ${CURRENT_PATH}/ContactSearchEngine.cpp
+  ${CURRENT_PATH}/ContactFilterValidator.cpp
+  ${CURRENT_PATH}/ContactsSvcChangeListenerManager.cpp
+  ${CURRENT_PATH}/ContactsSvcWrapper.cpp
+  ${CURRENT_PATH}/ContactUtility.cpp
+  ${CURRENT_PATH}/PersonFilterValidator.cpp
+  ${CURRENT_PATH}/PersonSearchEngine.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/Content/MediaFilterValidator.cpp b/src/platform/Tizen/Content/MediaFilterValidator.cpp
new file mode 100755 (executable)
index 0000000..35cf0c1
--- /dev/null
@@ -0,0 +1,80 @@
+//
+// 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 "MediaFilterValidator.h"
+#include <dpl/log/log.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Content{
+
+static PropertyStructArray folderProperties =
+{
+       {"id",                                  PrimitiveType_String},
+       {"directoryURI",                        PrimitiveType_String},
+       {"storageType",                 PrimitiveType_String},
+       {"title",                               PrimitiveType_String},
+       {"modifiedDate",                PrimitiveType_Time},
+       {0,     PrimitiveType_NoType}
+};
+
+static PropertyStructArray mediaProperties =
+{
+       {"id",                                  PrimitiveType_String},
+       {"type",                                PrimitiveType_String},
+       {"mimeType",                    PrimitiveType_String},
+       {"title",                               PrimitiveType_String},
+       {"contentURI",                          PrimitiveType_String},
+       {"thumbnailURIs",               PrimitiveType_String},
+       {"description",                 PrimitiveType_String},  
+       {"rating",                              PrimitiveType_Int},     
+       {"releasedDate",                PrimitiveType_Time},
+       {"modifiedDate",                PrimitiveType_Time},
+       {"geolocation.latitude",        PrimitiveType_Double},
+       {"geolocation.longitude",       PrimitiveType_Double},  
+       {"album",                               PrimitiveType_String},  
+       {"artists",                             PrimitiveType_String},  
+       {"width",                               PrimitiveType_String},  
+       {"height",                              PrimitiveType_String},                  
+       {"genres",                              PrimitiveType_String},                  
+       {0, PrimitiveType_NoType}
+
+};
+
+
+FilterValidatorPtr MediaFilterValidatorFactory::getMediaFilterValidator(QueryType value)
+{
+       static FilterValidatorPtr theValidatorInstance;
+
+    if(value == QUERY_FOLDER)
+    {  
+       LogDebug("create validator of folder");
+               theValidatorInstance = FilterValidatorPtr(new FilterValidator(folderProperties));
+       }
+       else if(value == QUERY_MEDIA)
+       {
+       LogDebug("create validator of media item");
+               theValidatorInstance = FilterValidatorPtr(new FilterValidator(mediaProperties));
+       }
+          
+   return theValidatorInstance;
+}
+
+} // Media
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Content/MediaFilterValidator.h b/src/platform/Tizen/Content/MediaFilterValidator.h
new file mode 100755 (executable)
index 0000000..02e70d4
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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 _PLATFORM_MEDIA_CONTENT_FILTER_VALIDATOR_H_
+#define _PLATFORM_MEDIA_CONTENT_FILTER_VALIDATOR_H_
+
+#include <API/Filter/FilterValidator.h>
+
+
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+namespace Platform {
+namespace Content {
+
+       
+class MediaFilterValidatorFactory : private DPL::Noncopyable
+{
+       public:
+       typedef enum _QueryType
+       {
+               QUERY_FOLDER, 
+               QUERY_MEDIA 
+       }QueryType;
+       
+private:
+       MediaFilterValidatorFactory()
+       {
+       }
+
+public:
+       static FilterValidatorPtr getMediaFilterValidator(QueryType value);
+};
+
+} // Mediacontent
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_MEDIA_CONTENT_FILTER_VALIDATOR_H_
\ No newline at end of file
diff --git a/src/platform/Tizen/Content/MediaSearchVisitor.cpp b/src/platform/Tizen/Content/MediaSearchVisitor.cpp
new file mode 100755 (executable)
index 0000000..6949a40
--- /dev/null
@@ -0,0 +1,342 @@
+//
+// 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 "time.h"
+#include <iomanip>
+#include <Commons/Exception.h>
+#include "MediaSearchVisitor.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Content {
+
+const string STR_LEFT_BRACKET(" (");
+const string STR_RIGHT_BRACKET(") ");
+const string STR_AND(" AND ");
+const string STR_OR(" OR ");
+const string STR_GREATER_THAN (">");
+const string STR_LESS_THAN ("<");
+const string STR_EQUAL ("=");
+const string STR_S_QUOTATION ("'");
+const string STR_PERCENT ("%");
+
+typedef enum
+{
+       MEDIA_ID = 0,
+       MEDIA_TITLE,
+       MEDIA_FILEPATH,
+       MEDIA_THUMBNAILPATH,
+       MEDIA_CREATEDDATE,
+       MEDIA_MODIFIEDDATE,
+       MEDIA_DESCRIPTION,
+       MEDIA_RATING,
+
+}media_attribute_e;
+
+
+map<string, string> MediaSearchVisitor::attrFolderEnumMap = {
+               {"id",                          "id"},
+               {"directoryURI",                "FOLDER_PATH"},
+               {"title",                       "FOLDER_NAME"},
+               {"storageType",         "FOLDER_STORAGE_TYPE"},         
+               {"modifiedDate",        "FOLDER_MODIFIED_TIME"},                                
+};
+
+map<string, string> MediaSearchVisitor::attrMediaEnumMap = {
+//media item attribues.
+               {"id",                          "MEDIA_ID"},
+               {"type",                        "MEDIA_TYPE"},
+               {"mimeType",            "MEDIA_MIME_TYPE"},
+               {"title",                       "MEDIA_TITLE"},         
+               {"contentURI",          "MEDIA_PATH"},
+               {"thumbnailURIs",       "MEDIA_THUMBNAIL_PATH"},                
+               {"description",         "MEDIA_DESCRIPTION"},           
+               {"rating",                      "MEDIA_RATING"},        
+               {"createdDate",         "MEDIA_ADDED_TIME"},    
+               {"releasedDate",        "MEDIA_YEAR"},  
+               {"modifiedDate",        "MEDIA_MODIFIED_TIME"},                         
+//media image,video,audio attribues.
+               {"geolocation.latitude",        "MEDIA_LATITUDE"}, 
+               {"geolocation.longitude",       "MEDIA_LONGITUDE"}, 
+               {"album",                       "MEDIA_ALBUM"}, 
+               {"artists",                     "MEDIA_ARTIST"}, 
+               {"width",                       "MEDIA_WIDTH"}, 
+               {"height",                      "MEDIA_HEIGHT"},
+               {"genres",                      "MEDIA_GENRE"},
+               {"size",                        "MEDIA_SIZE"},
+
+};
+
+MediaSearchVisitor::MediaSearchVisitor()
+{
+
+}
+
+MediaSearchVisitor::~MediaSearchVisitor()
+{
+
+}
+
+void MediaSearchVisitor::visitPreComposite(FilterType& type, int depth)
+{
+       m_query.append(STR_LEFT_BRACKET);
+}
+
+void MediaSearchVisitor::visitInComposite(FilterType& type, int depth)
+{
+       if(type == UNION_FILTER)
+               m_query.append(STR_OR);
+       else if(type == INTERSECTION_FILTER)
+               m_query.append(STR_AND);
+       else{
+               ThrowMsg(PlatformException, "Filter Type is wrong.");
+       }
+}
+
+void MediaSearchVisitor::visitPostComposite(FilterType& type, int depth)
+{
+       m_query.append(STR_RIGHT_BRACKET);
+}
+
+
+string MediaSearchVisitor::getPlatformAttr(string attrName)
+{
+       string platformAttr;
+       map<string, string>::iterator pos;
+       LogDebug("attrName=" << attrName);
+       LogDebug("queryType=" << queryType);
+
+       if( queryType == QUERY_FOLDER)
+       {
+               pos = attrFolderEnumMap.find(attrName);
+               
+               if(attrFolderEnumMap.end() != pos)
+               {
+                       platformAttr = pos->second;
+               }
+               else
+               {
+                       ThrowMsg(PlatformException, "Attribute(" << attrName << ") is not supported.");
+               }
+       }
+       else if(queryType == QUERY_MEDIA)
+       {
+               pos = attrMediaEnumMap.find(attrName);
+               
+               if(attrMediaEnumMap.end() != pos)
+               {
+                       platformAttr = pos->second;
+               }
+               else
+               {
+                       ThrowMsg(PlatformException, "Attribute(" << attrName << ") is not supported.");
+               }
+
+       }
+       return platformAttr;
+}
+
+
+void MediaSearchVisitor::visitAttribute(string& attrName, MatchFlag& matchFlag, AnyPtr& matchValue, int depth)
+{
+       string attrPlatform = getPlatformAttr(attrName);
+       if(matchValue == NULL)
+       {
+               ThrowMsg(PlatformException, "matchValue is not valid data.");
+       }       
+
+       m_query.append(convertAttribute(attrPlatform, matchValue, matchFlag));
+}
+
+string MediaSearchVisitor::toDateDbStr(tm &date) const
+{
+       time_t time;
+       time = mktime(&date);
+       stringstream ss;
+       ss << time;
+//     ss << setfill('0') << setiosflags(ios::right) << setw(4) << (date.tm_year + 1900);
+//     ss << setfill('0') << setiosflags(ios::right) << setw(2) << (date.tm_mon + 1);
+//     ss << setfill('0') << setiosflags(ios::right) << setw(2) << date.tm_mday;
+
+       return ss.str();
+}
+
+string MediaSearchVisitor::convertAttribute(string &attrName, AnyPtr& matchValue, MatchFlag& matchFlag)
+{
+       string valueStr;
+       string operatorStr;
+       string conditionStr;
+
+       condition_e cond;
+       string matchValueStr;
+
+       if(attrName.compare("MEDIA_TYPE")==0)
+       {
+               if(matchValue->toString().compare("IMAGE")==0)
+                       matchValueStr = "0";
+               else if(matchValue->toString().compare("VIDEO")==0)
+                       matchValueStr = "1";
+               else if(matchValue->toString().compare("AUDIO")==0)
+                       matchValueStr = "3";                    
+               else
+               {
+                       ThrowMsg(PlatformException, "mediaType(" << matchValue->toString() << ") is not supported.");
+               }
+       }
+       else
+       {
+               matchValueStr = matchValue->toString();
+       }
+
+       if(matchValue->getType() == PrimitiveType_Time)
+       {
+               tm date = matchValue->getDateTm();
+               valueStr = toDateDbStr(date);
+               cond = EQUAL;
+       }
+       else
+       {
+               //STARTSWITH('%, ENDSWITH, EXISTS
+               //valueStr = matchValue->toString();
+       
+               ostringstream os;
+
+               if(matchFlag == MATCH_STARTSWITH)
+               {
+                       cond = LIKE;
+                       os << STR_S_QUOTATION << matchValueStr << STR_PERCENT << STR_S_QUOTATION;
+               }
+               else if( matchFlag == MATCH_ENDSWITH )
+               {
+                       cond = LIKE;
+                       os << STR_S_QUOTATION <<  STR_PERCENT << matchValueStr << STR_S_QUOTATION;
+               }
+               else if(  matchFlag ==  MATCH_CONTAINS )
+               {
+                       cond = LIKE;
+                       os << STR_S_QUOTATION <<  STR_PERCENT << matchValueStr << STR_PERCENT << STR_S_QUOTATION;
+               }
+               else
+               {
+                       cond = EQUAL;
+                       os << STR_S_QUOTATION << matchValueStr << STR_S_QUOTATION;
+               }
+               
+               valueStr = os.str();
+       
+       }
+       operatorStr = operatorKey[cond];
+
+       if (attrName.compare("MEDIA_TITLE")==0)
+       {       
+               string imageCond = STR_LEFT_BRACKET;
+               imageCond += STR_LEFT_BRACKET + " MEDIA_TYPE=0 " + STR_RIGHT_BRACKET;
+               imageCond += STR_AND + " MEDIA_DISPLAY_NAME " + operatorStr + valueStr;
+               imageCond += STR_RIGHT_BRACKET;
+
+               string videoNAudioCond = STR_LEFT_BRACKET;
+               videoNAudioCond += STR_LEFT_BRACKET + "MEDIA_TYPE=1 " + STR_OR + "  MEDIA_TYPE=3" + STR_RIGHT_BRACKET;
+               videoNAudioCond += STR_AND + " MEDIA_TITLE " + operatorStr + valueStr;
+               videoNAudioCond += STR_RIGHT_BRACKET;
+
+               conditionStr = STR_LEFT_BRACKET + imageCond + STR_OR + videoNAudioCond + STR_RIGHT_BRACKET;     
+       }
+       else
+       {
+               conditionStr = STR_LEFT_BRACKET + attrName + operatorStr + valueStr + STR_RIGHT_BRACKET;
+       }
+
+       return conditionStr;
+}
+
+
+void MediaSearchVisitor::visitAttributeRange(string& attrName,AnyPtr& initialValue,AnyPtr& endValue,int depth)
+{
+       if(initialValue == NULL || endValue == NULL)
+               return;
+
+       string str;
+       string initialValueStr;
+       string endValueStr;
+
+       string attrPlatform = getPlatformAttr(attrName);
+
+       if(!initialValue->isNullOrUndefined()) 
+       {
+               if(initialValue->getType() == PrimitiveType_Time) 
+               {
+                       tm date = initialValue->getDateTm();
+                       initialValueStr = toDateDbStr(date);
+
+               } 
+               else 
+               {
+                       initialValueStr = initialValue->toString();
+               }
+       }
+
+       if (!endValue->isNullOrUndefined()) 
+       {
+               if(endValue->getType() == PrimitiveType_Time) 
+               {
+                       tm date = endValue->getDateTm();
+                       endValueStr = toDateDbStr(date);
+               }
+               else 
+               {
+                       endValueStr = endValue->toString();
+               }
+       }
+
+       if (!initialValue->isNullOrUndefined() && endValue->isNullOrUndefined()) 
+       {
+               str = STR_LEFT_BRACKET + attrPlatform + STR_GREATER_THAN + STR_EQUAL + 
+                               STR_S_QUOTATION + initialValueStr + STR_S_QUOTATION + STR_RIGHT_BRACKET;
+       }
+       else if(initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) 
+       {
+               str = STR_LEFT_BRACKET + attrPlatform + STR_LESS_THAN + STR_S_QUOTATION + 
+                               endValueStr + STR_S_QUOTATION + STR_RIGHT_BRACKET;
+       } 
+       else if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) 
+       {
+               str = STR_LEFT_BRACKET + attrPlatform + STR_GREATER_THAN + STR_EQUAL + STR_S_QUOTATION + 
+                               initialValueStr + STR_S_QUOTATION + STR_AND + attrPlatform + STR_LESS_THAN + STR_S_QUOTATION + 
+                               endValueStr + STR_S_QUOTATION + STR_RIGHT_BRACKET;
+       }
+
+       m_query.append(str);
+
+}
+
+string MediaSearchVisitor::getResult() const
+{
+       return m_query;
+}      
+
+void MediaSearchVisitor::setQueryType(QueryType value)
+{
+       queryType = value;
+}
+
+
+
+
+} // Contact
+} // Platform
+} // TizenApis
diff --git a/src/platform/Tizen/Content/MediaSearchVisitor.h b/src/platform/Tizen/Content/MediaSearchVisitor.h
new file mode 100755 (executable)
index 0000000..f663f74
--- /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 _PLATFORM_MEDIA_CONTENT_SEARCH_VISITOR_H_
+#define _PLATFORM_MEDIA_CONTENT_SEARCH_VISITOR_H_
+
+#include <map>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <API/Filter/IFilter.h>
+#include <API/Filter/IFilterVisitor.h>
+#include <API/Filter/SortMode.h>
+
+
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+
+
+namespace TizenApis {
+namespace Platform {
+namespace Content {
+       
+typedef enum
+{
+       EQUAL,
+       NOT_EQUAL,
+       GREATER_THAN,
+       LESS_THAN,
+       GREATER_THAN_OR_EQUAL,
+       LESS_THAN_OR_EQUAL,
+       LIKE,
+       EXISTS,
+       CONDITION_MAX
+}condition_e;
+
+static string operatorKey[] =
+{
+       " = ",
+       " NOT IN ",             //!=
+       " > ",
+       " < ",
+       " >= ",
+       " <= ",
+       " LIKE "                // like
+};
+
+class MediaSearchVisitor : public TizenApis::Api::Tizen::IFilterVisitor
+{
+public:
+       typedef enum _QueryType { QUERY_FOLDER, QUERY_MEDIA } QueryType;
+
+       
+       MediaSearchVisitor();
+       virtual ~MediaSearchVisitor();
+
+       virtual void visitPreComposite(FilterType& type, int depth);
+       virtual void visitInComposite(FilterType& type, int depth);
+       virtual void visitPostComposite(FilterType& type, int depth);
+       virtual void visitAttribute(string& attrName, MatchFlag& matchFlag, AnyPtr& matchValue, int depth);
+       virtual void visitAttributeRange(string& attrName,AnyPtr& initialValue,AnyPtr& endValue,int depth);
+
+       string getPlatformAttr(string attrName);
+       string getResult() const;
+
+       void setQueryType(QueryType value);
+       
+private:
+       string toDateDbStr(tm &date) const;
+       string convertAttribute(string &attrname, AnyPtr& matchValue, MatchFlag& matchFlag);
+               
+private:
+       QueryType queryType;
+       string m_query; 
+       static map<string, string> attrFolderEnumMap;
+       static map<string, string> attrMediaEnumMap;
+
+       vector<string> m_condition;
+       
+
+};
+
+typedef DPL::SharedPtr<MediaSearchVisitor> MediaSearchVisitorPtr;
+
+} // Mediacontent
+} // Platform
+} // TizenApis
+
+#endif // _PLATFORM_MEDIA_CONTENT_SEARCH_VISITOR_H_
diff --git a/src/platform/Tizen/Content/MediaWrapper.cpp b/src/platform/Tizen/Content/MediaWrapper.cpp
new file mode 100755 (executable)
index 0000000..9b67f6d
--- /dev/null
@@ -0,0 +1,136 @@
+//
+// 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 <string.h>
+#include <algorithm>
+#include <pcrecpp.h>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include "MediaWrapper.h"
+
+using namespace WrtPlugins::Api;
+
+
+
+namespace WrtPlugins {
+namespace Platform {
+MediaWrapper::MediaWrapper() :
+    m_platformEvent(NULL),
+    m_abstractEvent(NULL)
+{
+    LogDebug("entered");
+    m_abstractEvent = CalendarEventPtr(new CalendarEvent());
+    if (!m_abstractEvent) {
+        ThrowMsg(Commons::UnknownException, "abstract object is not created");
+    }
+}
+
+MediaWrapper::MediaWrapper(media_info_h media) :
+    m_platformEvent(NULL),
+    m_abstractEvent(event)
+{
+    LogDebug("entered");
+}
+
+MediaWrapper::MediaWrapper()
+{
+    LogDebug("entered");
+    freePlatformEvent();
+}
+
+void EventWrapper::displayAbstractEvent()
+{
+    m_abstractEvent->display();
+}
+
+void EventWrapper::displayPlatformEvent()
+{
+    LogDebug("event id: " << calendar_svc_struct_get_int(m_platformEvent,
+                                                         CAL_VALUE_INT_INDEX));
+    LogDebug("event start time: " << calendar_svc_struct_get_time(
+                 m_platformEvent, CAL_VALUE_GMT_START_DATE_TIME,
+                 CAL_TZ_FLAG_GMT));
+    LogDebug("event end time: " << calendar_svc_struct_get_time(m_platformEvent,
+                                                                CAL_VALUE_GMT_END_DATE_TIME,
+                                                                CAL_TZ_FLAG_GMT));
+    LogDebug("event location: " << calendar_svc_struct_get_str(m_platformEvent,
+                                                               CAL_VALUE_TXT_LOCATION));
+    LogDebug("event summary: " << calendar_svc_struct_get_str(m_platformEvent,
+                                                              CAL_VALUE_TXT_SUMMARY));
+    LogDebug("event description: " << calendar_svc_struct_get_str(
+                 m_platformEvent, CAL_VALUE_TXT_DESCRIPTION));
+
+    LogDebug("event isAllDay: " << calendar_svc_struct_get_int(
+                 m_platformEvent, CAL_VALUE_INT_ALL_DAY_EVENT));
+    LogDebug("event organizer: " << calendar_svc_struct_get_str(m_platformEvent,
+                                                               CAL_VALUE_TXT_ORGANIZER_NAME));
+    LogDebug("event lastModifiedDate: " << calendar_svc_struct_get_time(
+                 m_platformEvent, CAL_VALUE_GMT_LAST_MODIFIED_TIME,
+                 CAL_TZ_FLAG_GMT));
+    LogDebug("event visibility: " << calendar_svc_struct_get_int(
+                 m_platformEvent, CAL_VALUE_INT_SENSITIVITY));    
+    LogDebug("event availability: " << calendar_svc_struct_get_int(
+                 m_platformEvent, CAL_VALUE_INT_BUSY_STATUS));
+
+    GList *categoryList = NULL;
+    if (CAL_SUCCESS != calendar_svc_struct_get_list(m_platformEvent,
+                                     CAL_VALUE_LST_MEETING_CATEGORY,
+                                     &categoryList)) {
+        LogError("cannot read category list");
+        return;
+    }
+    cal_value* category = NULL;
+    for (; categoryList; categoryList = g_list_next(categoryList)) {
+        category = static_cast<cal_value*>(categoryList->data);
+        char* categoryName = calendar_svc_value_get_str(category, "category_name");
+        if (NULL == categoryName) {
+            LogError("cannot read category name");
+            return;
+        }
+        LogDebug("event categories: " << categoryName);
+    }
+
+    LogDebug("event uid: " << calendar_svc_struct_get_str(m_platformEvent,
+                                                               CAL_VALUE_TXT_UID));
+    LogDebug("event recurrenceId: " << calendar_svc_struct_get_time(
+                 m_platformEvent, CAL_VALUE_GMT_START_DATE_TIME, CAL_TZ_FLAG_GMT));
+
+    GList *attendees = NULL;
+    if (CAL_SUCCESS != calendar_svc_struct_get_list(m_platformEvent,
+                                     CAL_VALUE_LST_ATTENDEE_LIST,
+                                     &attendees)) {
+        LogError("cannot read attendee list");
+        return;
+    }
+    cal_value* attendee = NULL;
+    for (; attendees; attendees = g_list_next(attendees)) {
+        attendee = static_cast<cal_value*>(attendees->data);
+        char* attendeeName = calendar_svc_value_get_str(attendee, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME);
+        if (NULL == attendeeName) {
+            LogError("cannot read attendee name");
+            return;
+        }
+        LogDebug("event attendees: " << attendeeName);
+    }
+
+    LogDebug("event repeat frequency: " << calendar_svc_struct_get_int(
+                 m_platformEvent, CAL_VALUE_INT_REPEAT_TERM));
+}
+
+}
+}
diff --git a/src/platform/Tizen/Content/MediaWrapper.h b/src/platform/Tizen/Content/MediaWrapper.h
new file mode 100755 (executable)
index 0000000..f5e2e03
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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 _MEDIA_WRAPPER_H_
+#define _MEDIA_WRAPPER_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <media_content.h>
+#include <API/Content/MediacontentMedia.h>
+
+
+namespace WrtPlugins {
+namespace Platform {
+class MediaWrapper
+{
+  public:
+    MediaWrapper();
+    explicit MediaWrapper(media_info_h media);
+    virtual ~MediaWrapper();
+
+  private:
+    void displayAbstractMedia();     //only for debugging
+    void displayPlatformMedia();     //only for debugging
+
+    Api::MediacontentMediaPtr m_media;
+};
+
+}
+}
+#endif
diff --git a/src/platform/Tizen/Content/MediacontentManager.cpp b/src/platform/Tizen/Content/MediacontentManager.cpp
new file mode 100755 (executable)
index 0000000..51d4acb
--- /dev/null
@@ -0,0 +1,1341 @@
+//
+// 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 <vector>
+#include <string>
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <media_content.h>
+#include <Commons/StringUtils.h>
+#include <CommonsJavaScript/Converter.h>
+
+#include "MediacontentManager.h"
+#include "MediaFilterValidator.h"
+
+
+
+using namespace TizenApis::Api::Content;
+using namespace WrtDeviceApis::Commons;
+
+
+namespace TizenApis {
+namespace Platform {
+namespace Content {
+
+
+int MediacontentManager::m_instanceCount = 0;
+
+MediacontentManager::MediacontentManager()
+{
+    LogDebug("entered");
+
+       //protect for pararel execution
+       DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+       if (m_instanceCount == 0)
+       {
+               //when it is first instance then connect to media content service.
+               if( MEDIA_CONTENT_ERROR_NONE != media_content_connect())
+               {       
+                       LogDebug("Media Content Service Connect Fail...");
+                       return;
+               }
+       }
+       //increase counter of instances
+       m_instanceCount++;
+       
+}
+
+MediacontentManager::~MediacontentManager()
+{
+       LogDebug("entered : " << m_instanceCount);
+       DPL::Mutex::ScopedLock mx(&m_constructorMutex);
+       //decrease counter of instances
+       m_instanceCount--;
+       if (m_instanceCount == 0)
+       {
+               LogDebug("instance Count is zero ");
+               //when it is last instance then clse connection to database
+               if ( MEDIA_CONTENT_ERROR_NONE != media_content_disconnect())
+               {
+                       LogDebug("Media Content Service Disconnect Fail...");
+               }
+       }
+}
+
+/*
+void MediacontentManager::OnRequestReceived(const IEventGetMediacontentPtr &event)
+{
+       LogDebug( "OnRequestReceived::entered");
+    //IMediacontentPtr newMediacontent(new Mediacontent());
+    //IMediacontentPtr newMediacontent = MediacontentFactory::getInstance().createMediacontentObject();
+    
+    Try
+    {
+       LogDebug( "get Mediacontent \n");
+//             event->setMediacontent(m_mediaContent);
+               event->setResult(true);
+    }
+    Catch(Exception)
+    {
+        LogError("error occuered during obtaining data");
+        event->setResult(false);
+    }
+    event->setCancelAllowed(true);
+}
+*/
+
+tm MediacontentManager::toDateTm(time_t date)
+{
+       tm tm_date;
+
+       localtime_r(&date, &tm_date);
+
+       return tm_date;
+}
+
+media_content_orientation_e MediacontentManager::convertToOrientation(string orientation)
+{
+       media_content_orientation_e ret = MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE;
+
+       if ( orientation.compare("NORMAL")==0)
+       {
+               ret = MEDIA_CONTENT_ORIENTATION_NORMAL;
+       }
+       else if (orientation.compare("FLIP_HORIZONTAL")==0)
+       {
+               ret = MEDIA_CONTENT_ORIENTATION_HFLIP;
+       }
+       else if (orientation.compare("ROTATE_180")==0)
+       {
+               ret = MEDIA_CONTENT_ORIENTATION_ROT_180;
+       }
+       else if (orientation.compare("FLIP_VERTICAL")==0)
+       {
+               ret = MEDIA_CONTENT_ORIENTATION_VFLIP;
+       }
+       else if (orientation.compare("TRANSPOSE")==0)
+       {
+               ret = MEDIA_CONTENT_ORIENTATION_TRANSPOSE;
+       }
+       else if (orientation.compare("ROTATE_90")==0)
+       {
+               ret = MEDIA_CONTENT_ORIENTATION_ROT_90;
+       }
+       else if (orientation.compare("TRANSVERSE")==0)
+       {
+               ret =MEDIA_CONTENT_ORIENTATION_TRANSVERSE;
+       }
+       else if (orientation.compare("ROTATE_270")==0)
+       {
+               ret =MEDIA_CONTENT_ORIENTATION_ROT_270;
+       }       
+       else
+       {
+               LogDebug("wrong value.");
+               ret = MEDIA_CONTENT_ORIENTATION_NOT_AVAILABLE;
+       }
+
+       return ret;
+}
+
+void MediacontentManager::convertToPlatformFolder(media_folder_h media_folder, MediacontentFolderPtr& newFolder)
+{
+       char* tmpStr = NULL;
+       time_t date;
+       media_content_storage_e storageType;
+
+       if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_folder_id(media_folder, &tmpStr))
+       {
+               if ( tmpStr )
+               {
+                       LogDebug("Folder UUID : " << tmpStr);
+                       newFolder->setFolderUUID(tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+       }
+
+       if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_path(media_folder, &tmpStr))
+       {
+               if ( tmpStr )
+               {               
+                       LogDebug("Folder path : " << tmpStr);
+                       newFolder->setFolderPath(tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+       }
+
+       if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_name(media_folder, &tmpStr))
+       {
+               if ( tmpStr )
+               {               
+                       LogDebug("Folder name : " << tmpStr);
+                       newFolder->setFolderName(tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;  
+               }
+       }
+       
+       if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_modified_time(media_folder, &date))
+       {
+               LogDebug("get Modified Time ");
+               newFolder->setFolderModifiedDate(toDateTm(date));
+       }
+       
+       if (MEDIA_CONTENT_ERROR_NONE == media_folder_get_storage_type(media_folder, &storageType))
+       {       
+               LogDebug("storage Type=" << storageType);
+               string type;
+               if(storageType == MEDIA_CONTENT_STORAGE_INTERNAL )
+               {
+                       type = "INTERNAL";
+               }
+               else if( storageType == MEDIA_CONTENT_STORAGE_EXTERNAL)
+               {
+                       type = "EXTERNAL";
+               }
+               else
+               {
+                       type = "UNKNOWN";
+               }
+               newFolder->setFolderStorageType(type);
+       }
+               
+               
+}
+
+void MediacontentManager::readCommonDataFromMediaInfo(media_info_h info, MediacontentMedia* newMedia)
+{      
+
+       char* tmpStr = NULL;
+       time_t tmpDate;
+       int tmpInt = 0;
+       unsigned long long tmpLongLong = 0;
+       bool tmpBool= false;
+
+       LogDebug("enter Common Data type : " << newMedia->getMediaType());
+       
+       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_id(info, &tmpStr) )
+       {
+               if (tmpStr)
+               {
+                       newMedia->setMediaUUID(tmpStr);
+                       LogDebug("UUID : " << tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+       }
+
+       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_mime_type(info, &tmpStr) )
+       {
+               if (tmpStr)
+               {
+                       newMedia->setMimeType(tmpStr);
+                       LogDebug("MineType : " << tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+       }
+
+       if (MEDIA_CONTENT_ERROR_NONE == media_info_get_display_name(info, &tmpStr) )
+       {
+               if (tmpStr)
+               {
+                       newMedia->setDisplayName(tmpStr);
+                       LogDebug("Display Name : " << tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+       }
+
+       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_file_path(info, &tmpStr) )
+       {
+               if (tmpStr)
+               {
+                       newMedia->setFilePath(tmpStr);
+                       LogDebug("Path : " << tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+       }
+
+       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_thumbnail_path (info, &tmpStr) )
+       {
+               if (tmpStr)
+               {
+                       newMedia->setThumbnailPath(tmpStr);
+                       LogDebug("Thumnail Path : " << tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+       }
+       
+       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_description(info, &tmpStr) )
+       {
+               if (tmpStr)
+               {
+                       newMedia->setDescription(tmpStr);
+                       LogDebug("Desc : " << tmpStr);
+                       free(tmpStr);
+                       tmpStr = NULL;
+               }
+       }
+
+       //newImage->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
+       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_modified_time (info, &tmpDate) )
+       {
+               newMedia->setModifiedDate(toDateTm(tmpDate));
+       }
+
+       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_favorite (info, &tmpBool) )
+       {
+               newMedia->setFavorite(tmpBool);
+               LogDebug("favorite " << tmpBool);
+       }
+
+       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_rating  (info, &tmpInt) )
+       {
+               newMedia->setRating(tmpInt);
+               LogDebug("rating " << tmpInt);
+       }
+
+       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
+       {
+               newMedia->setSize(tmpLongLong);
+               LogDebug("Size : " << tmpLongLong);
+       }
+       
+}
+
+void MediacontentManager::readImageFromMediaInfo( media_info_h info, MediacontentImage* newImage)
+{      
+       char* tmpStr = NULL;
+       double tmpDouble;
+       int tmpInt = 0;
+       
+       if ( info) 
+       {
+               newImage->setMediaType("IMAGE");
+
+               readCommonDataFromMediaInfo(info, newImage);
+
+               image_meta_h img;
+               
+               if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(info, &img))
+               {
+                       //created time
+                       if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_date_taken (img, &tmpStr) )
+                       {       
+                               if ( tmpStr )
+                               {
+                                       struct tm result;
+                                       if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
+                                               LogError( "Couldn't convert supplied date.");
+                                       }
+                               
+                                       LogDebug("image_meta_get_date_taken : " <<  tmpStr); //time??
+                                       newImage->setReleasedDate(result);
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_width(img, &tmpInt) )
+                       {
+                               newImage->setImageWidth(tmpInt);
+                               LogDebug("Image Width " << tmpInt);
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_height(img, &tmpInt) )
+                       {
+                               newImage->setImageHeight(tmpInt);
+                               LogDebug("Image Height " << tmpInt);
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
+                       {
+                               newImage->setImageLatitude(tmpDouble);
+                               LogDebug("Image Latitude " << tmpDouble);
+                       }
+                       
+                       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
+                       {
+                               newImage->setImageLongitude(tmpDouble);
+                               LogDebug("Image Longitude " << tmpDouble);
+                       }
+                                       
+                       media_content_orientation_e orientation;
+                       
+                       if ( MEDIA_CONTENT_ERROR_NONE == image_meta_get_orientation(img, &orientation) )
+                       {       
+       
+                               string orientationStr;
+                               switch(orientation)
+                               {
+                                       case 0:
+                                       case 1: 
+                                               orientationStr = "NORMAL";
+                                               break;
+                                       case 2: 
+                                               orientationStr = "FLIP_HORIZONTAL";
+                                               break;
+                                       case 3: 
+                                               orientationStr = "ROTATE_180";
+                                               break;
+                                       case 4: 
+                                               orientationStr = "FLIP_VERTICAL";
+                                               break;
+                                       case 5: 
+                                               orientationStr = "TRANSPOSE";
+                                               break;
+                                       case 6: 
+                                               orientationStr = "ROTATE_90";
+                                               break;
+                                       case 7: 
+                                               orientationStr = "TRANSVERSE";
+                                               break;
+                                       case 8: 
+                                               orientationStr = "ROTATE_270";
+                                               break;
+                               }       
+                               
+                               newImage->setImageOrientation(orientationStr);
+                               LogDebug(" image Orientation. " << orientationStr);
+
+                       }
+
+
+                       if ( METADATA_EXTRACTOR_ERROR_NONE != image_meta_destroy(img))
+                       {
+                               LogDebug(" image_meta_destroy is fail... ");
+                       }
+                                               
+               }
+               else {
+                       LogDebug("fetch Image Info failed..");                  
+               }
+                       
+       }
+       else
+       {
+               LogDebug("media info is NULL");
+       }
+}
+
+void MediacontentManager::readVideoFromMediaInfo( media_info_h info, MediacontentVideo* newVideo)
+{      
+       char* tmpStr;
+       int tmpInt = 0;
+       double tmpDouble;
+
+       if(info)
+       {
+               newVideo->setMediaType("VIDEO");        
+
+               readCommonDataFromMediaInfo(info, newVideo);    //set common media infomation
+
+               video_meta_h video;
+               
+               if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(info, &video))
+               {
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_recorded_date(video, &tmpStr) )
+                       {
+                               if ( tmpStr )
+                               {       
+                                       struct tm result;
+                                       if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
+                                               LogError( "Couldn't convert supplied date.");
+                                       }
+                                       newVideo->setReleasedDate(result);
+                                       
+                                       LogDebug("audio_meta_get_recorded_date : " << tmpStr);
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+               
+                       if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_album(video, &tmpStr) )
+                       {
+                               if( tmpStr )
+                               {
+                                       newVideo->setVideoAlbum(tmpStr);
+                                       LogDebug(" Video Album. " << tmpStr);
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_title(video, &tmpStr) )
+                       {
+                               if( tmpStr )
+                               {
+                                       newVideo->setDisplayName(tmpStr);
+                                       LogDebug(" Video Title. " << tmpStr);
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_artist(video, &tmpStr) )
+                       {       
+                               if ( tmpStr)
+                               {
+                                       std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
+                                       for( unsigned int i=0; i < artists.size(); i++)
+                                       {
+                                               string artist = artists.at(i);
+                                               LogDebug("Audio artist: " << artist);
+                                               newVideo->appendVideoArtist(artist);
+                                       }
+                                       
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+
+                       
+                       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_longitude(info, &tmpDouble) )
+                       {
+                               newVideo->setVideoLongitude(tmpDouble);
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_latitude(info, &tmpDouble) )
+                       {
+                               newVideo->setVideoLatitude(tmpDouble);
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_width(video, &tmpInt) )
+                       {
+                               newVideo->setVideoWidth(tmpInt);
+                       }
+                       
+                       if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_height(video, &tmpInt) )
+                       {
+                               newVideo->setVideoHeight(tmpInt);
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == video_meta_get_duration(video, &tmpInt) )
+                       {
+                               newVideo->setVideoDuration(tmpInt);
+                       }
+
+                       if ( METADATA_EXTRACTOR_ERROR_NONE != video_meta_destroy(video))
+                       {
+                               LogDebug(" video_meta_destroy is fail... ");
+                       }
+                                               
+               }
+               else
+               {
+                       LogDebug("fetch Video info fail...");
+               }
+       }
+       else
+       {
+               LogDebug("media info is NULL");
+       }
+}
+
+
+void MediacontentManager::readMusicFromMediaInfo( media_info_h info, MediacontentAudio* newAudio)
+{      
+       char* tmpStr;
+       int tmpInt = 0;
+       unsigned long long tmpLongLong = 0;
+               
+       if ( info) 
+       {
+               newAudio->setMediaType("AUDIO");        
+               
+               readCommonDataFromMediaInfo(info, newAudio);    //set common media infomation
+
+               audio_meta_h audio;
+               
+               if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(info, &audio))
+               {       
+                       if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_recorded_date(audio, &tmpStr) )
+                       {
+                               if ( tmpStr )
+                               {       
+                                       struct tm result;
+                                       if (strptime(tmpStr, "%Y:%m:%d %H:%M:%S", &result) == NULL) {
+                                               LogError( "Couldn't convert supplied date.");
+                                       }
+                                       newAudio->setReleasedDate(result);
+                                       
+                                       LogDebug("audio_meta_get_recorded_date : " << tmpStr);
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_title(audio, &tmpStr) )
+                       {
+                               if (tmpStr)
+                               {
+                                       newAudio->setDisplayName(tmpStr);
+                                       LogDebug("Audio Title : " << tmpStr);
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_album(audio, &tmpStr) )
+                       {
+                               if (tmpStr)
+                               {
+                                       newAudio->setAudioAlbum(tmpStr);
+                                       LogDebug("Audio Album : " << tmpStr);
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_artist(audio, &tmpStr) )
+                       {       
+                               if (tmpStr)
+                               {
+                                       std::vector<std::string> artists = String::split(tmpStr, TAG_DELIMETER);
+                                       for( unsigned int i=0; i < artists.size(); i++)
+                                       {
+                                               string artist = artists.at(i);
+                                               LogDebug("Audio artist: " << artist);
+                                               newAudio->appendAudioArtist(artist);
+                                       }
+                                       
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+               
+                       if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_composer(audio, &tmpStr) )
+                       {
+                               if (tmpStr)
+                               {       
+                                       std::vector<std::string> composers = String::split(tmpStr, TAG_DELIMETER);
+                                       for( unsigned int i=0; i < composers.size(); i++)
+                                       {
+                                               string composer = composers.at(i);
+                                               LogDebug("Audio Composer : " << composer);
+                                               newAudio->appendAudioComposer(composer);
+                                       }
+                                       
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+                       
+                       if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_duration(audio, &tmpInt) )
+                       {
+                               newAudio->setAudioDuration(tmpInt);
+                               LogDebug("Audio Duration : " << tmpInt);
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_copyright(audio, &tmpStr) )
+                       {
+                               if (tmpStr)
+                               {
+                                       newAudio->setAudioCopyright(tmpStr);
+                                       LogDebug("Audio CopyRight: " << tmpStr);
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+               
+                       if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_track_num(audio, &tmpStr) )
+                       {       
+                               int trackNum = 0;
+                               if (tmpStr)
+                               {
+                                       LogDebug("trackNum: " << tmpStr);
+                                       try {
+                                               istringstream(tmpStr) >> trackNum;
+                                       } catch (...) {
+                                               LogDebug("Track Number type is wrong. (track number:" << tmpStr << ")");
+                                               trackNum = 0;
+                                       }
+                       
+                                       newAudio->setAudioTrackNum(trackNum);
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_size(info, &tmpLongLong) )
+                       {       
+                               LogDebug("size");
+                               newAudio->setAudioSize(tmpLongLong);
+                               LogDebug("Audio Size: " << tmpLongLong);
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_bit_rate(audio, &tmpInt) )
+                       {       
+                               LogDebug("bitrate");
+                               newAudio->setAudioBitrate(tmpInt);
+                               LogDebug("Audio Bitrate: " << tmpInt);
+                       }
+
+                       if ( MEDIA_CONTENT_ERROR_NONE == audio_meta_get_genre(audio, &tmpStr) )
+                       {       
+                               LogDebug("gener");
+                               if (tmpStr)
+                               {
+                                       std::vector<std::string> genres = String::split(tmpStr, TAG_DELIMETER);
+
+                                       for( unsigned int i=0; i < genres.size(); i++)
+                                       {
+                                               string genre = genres.at(i);
+                                               LogDebug("Audio Genre: " << genre);
+                                               newAudio->appendAudioGenre(genre);
+                                       }
+                                       
+                                       free(tmpStr);
+                                       tmpStr = NULL;
+                               }
+                       }
+                                               
+                       if ( METADATA_EXTRACTOR_ERROR_NONE != audio_meta_destroy(audio))
+                       {
+                               LogDebug(" audio_meta_destroy is fail... ");
+                       }
+                       
+
+               }
+               else
+               {
+                       LogDebug("fetch Music Info fail...");
+               }
+               
+                       
+       }
+       else
+       {
+               LogDebug("media info is NULL");
+       }
+}
+
+
+
+//Callback.
+bool MediacontentManager::mediaFolderCallback(media_folder_h folder, void *user_data)
+{      
+       LogDebug("enter");
+       if (user_data != NULL){
+               IEventFindFolder* event = (IEventFindFolder*)user_data;
+               LogDebug("user data is valide");
+               if ( folder )
+               {
+                       LogDebug("folder is valide");
+                       MediacontentFolderPtr newFolder(new MediacontentFolder());
+                       convertToPlatformFolder(folder, newFolder);
+                       LogDebug("folder type" << newFolder->getFolderStorageType());
+                       
+                       event->addFolder(newFolder);
+               }
+       }
+       else
+       {
+               LogDebug("user data is NULL");
+       }
+       
+       return true;
+
+}
+
+bool MediacontentManager::mediaItemCallback(media_info_h info, void* user_data)
+{
+       if (user_data != NULL){
+               IEventBrowseFolder* event = (IEventBrowseFolder*)user_data;
+
+               media_content_type_e type;
+               
+               if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_type( info, &type) )
+               {
+                       if ( type == MEDIA_CONTENT_TYPE_IMAGE)
+                       {
+                               MediacontentImage *newImage(new MediacontentImage());
+                               readImageFromMediaInfo(info, newImage);
+                               event->addMedia(newImage);
+                       }
+                       else if ( type == MEDIA_CONTENT_TYPE_VIDEO)
+                       {
+                               MediacontentVideo *newVideo(new MediacontentVideo());
+                               readVideoFromMediaInfo(info, newVideo);
+                               event->addMedia(newVideo);
+                       }
+                       else if ( type == MEDIA_CONTENT_TYPE_MUSIC)
+                       {
+                               MediacontentAudio *newVAudio(new MediacontentAudio());
+                               readMusicFromMediaInfo(info, newVAudio);
+                               event->addMedia(newVAudio);
+                       }
+                       else 
+                       {       
+                               LogDebug("other type");
+                       }
+
+               }
+       }
+       else 
+       {
+               LogDebug("event is NULL");      
+       }
+
+       return true;
+}
+
+void MediacontentManager::OnRequestReceived(const IEventFindFolderPtr &eFolder)
+{
+       LogDebug("entered");
+               
+       if ( MEDIA_CONTENT_ERROR_NONE != 
+               media_folder_foreach_folder_from_db (NULL, mediaFolderCallback, eFolder.Get()))
+       {       
+               LogError("error ( media_folder_foreach_folder_from_db ) : ");
+               eFolder->setResult(false);
+       }
+       else
+       {
+               eFolder->setResult(true);
+       }
+
+
+       LogDebug("end");
+}
+
+void MediacontentManager::OnRequestReceived(const IEventBrowseFolderPtr &eBrowse)
+{
+       LogDebug("OnRequestReceived::IEventBrowseFolderPtr entered");
+
+       MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
+       visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA);
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+
+       try{
+               filter_h filter = NULL;
+
+               if(eBrowse->getFilterIsSet() || eBrowse->getFolderIdIsSet() || eBrowse->getSortModesIsSet()
+                       || eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() )
+               {
+                       //set filter
+                       if ( MEDIA_CONTENT_ERROR_NONE == media_filter_create(&filter))
+                       {
+                               if (eBrowse->getFilterIsSet())
+                               {
+                                       string condition;
+                                       FilterPtr jsFilter = eBrowse->getFilter();
+
+                                       FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA);
+                                       bool success = jsFilter->validate(validator);
+
+                                       if(!success)
+                                               ThrowMsg(PlatformException, "Invalid attirbutes.");
+                                       
+                                       IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
+
+                                       jsFilter->travel(IVisitor);
+                                       condition = visitor->getResult();
+
+                                       LogDebug("execute condition [" << condition << "]");
+                                       media_filter_set_condition(filter, condition.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT );  //set condition
+                               }
+
+                               if(eBrowse->getSortModesIsSet()) 
+                               {
+                                       media_content_order_e order;
+
+                                       SortModePtr attr = eBrowse->getSortMode();
+
+                                       if ( attr )
+                                       {
+                                               string attriName = attr->getAttributeName();
+                                               attriName = visitor->getPlatformAttr(attriName);
+                                               LogDebug("Attribute Name [" << attriName << "]");
+
+                                               if (attriName.compare("") != 0) 
+                                               {       
+                                                       if (attr->getOrder() == Api::Tizen::ASCENDING_SORT_ORDER) 
+                                                       {
+                                                               order = MEDIA_CONTENT_ORDER_ASC;
+                                                       } 
+                                                       else 
+                                                       {
+                                                               order = MEDIA_CONTENT_ORDER_DESC;
+                                                       }
+
+                                                       if ( attriName.compare( "MEDIA_TITLE") == 0 )
+                                                       {
+                                                               attriName.append(", MEDIA_DISPLAY_NAME");
+                                                       }
+                                                       if ( MEDIA_CONTENT_ERROR_NONE != 
+                                                               media_filter_set_order(filter, order, attriName.c_str(), MEDIA_CONTENT_COLLATE_DEFAULT ))               //set order
+                                                       {       
+                                                               LogDebug("media_filter_set_order fail...");     
+                                                       }
+                                               }
+                                       }
+                                       
+                               }                               
+
+                               if (eBrowse->getLimitIsSet() ||eBrowse->getOffsetIsSet() ) 
+                               {       
+                                       LogDebug("limit or offset");
+                                       
+                                       int count = -1;
+                                       int offset = 0;
+                                       
+                                       if ( eBrowse->getLimitIsSet() )
+                                       {
+                                               count =  eBrowse->getLimit();
+                                               LogDebug("limit is " << count);
+                                       }
+                                       
+                                       if ( eBrowse->getOffsetIsSet() )
+                                       {
+                                               offset = eBrowse->getOffset();
+                                               LogDebug("offset is " << offset);
+                                       }
+                                       
+                                       if ( MEDIA_CONTENT_ERROR_NONE != media_filter_set_offset(filter, offset, count))
+                                       {
+                                               LogDebug("set limit or offset fail...");
+                                       }
+                               }
+                               
+                       }
+                       else
+                       {
+                               
+                               LogError("error ( media filter create ) : ");
+                               eBrowse->setResult(false);
+                       }
+               }
+
+               if ( eBrowse->getFolderIdIsSet())
+               {       
+                       string folderID = eBrowse->getFolderID();
+                       LogDebug("FolderID :" << folderID);
+                       
+                       if ( MEDIA_CONTENT_ERROR_NONE !=  
+                               media_folder_foreach_media_from_db (folderID.c_str(), filter, mediaItemCallback, eBrowse.Get()))
+                       {       
+                               LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
+                               eBrowse->setResult(false);
+                       }
+                       else
+                       {       
+                               eBrowse->setResult(true);
+                       }
+               }
+               else
+               {
+                       if ( MEDIA_CONTENT_ERROR_NONE !=  
+                               media_info_foreach_media_from_db (filter, mediaItemCallback, eBrowse.Get()))
+                       {       
+                               LogError("error ( media_folder_foreach_folder_from_db ) : " << ret);
+                               eBrowse->setResult(false);
+                       }
+                       else
+                       {       
+                               eBrowse->setResult(true);
+                       }
+               }
+
+               //destory Filter
+               if(filter)
+               {
+                       if ( MEDIA_CONTENT_ERROR_NONE != media_filter_destroy(filter))
+                       {
+                               LogError("media_filter_create Error: " << ret);
+                       }
+               }
+               
+       }
+       catch(const Exception &ex){
+                       LogError("Exception: " << ex.DumpToString());
+                       eBrowse->setResult(false);
+                       return;
+       }
+
+
+       
+}
+
+bool MediacontentManager::updateMediaToDB(MediacontentMediaPtr mediaPtr)
+{      
+       string type  = mediaPtr->getMediaType();        //media type.
+       string mediaId = mediaPtr->getMediaUUID();
+
+       LogDebug("MediaId : " << mediaId);
+       media_info_h media = NULL;
+
+       bool ret = true;
+
+       if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_media_from_db(mediaId.c_str(), &media))
+       {
+                               if ( mediaPtr->isChangedRating())
+                               {
+                                       if ( MEDIA_CONTENT_ERROR_NONE
+                                               != media_info_set_rating(media, mediaPtr->getRating()))
+                                       {
+                                               LogDebug("Error: set rating");
+                                       }
+                               }
+               if ( mediaPtr->isChangedDescription() )
+                               {
+                                       if ( MEDIA_CONTENT_ERROR_NONE
+                                               != media_info_set_description (media, mediaPtr->getDescription().c_str()))
+                                       {
+                                               LogDebug("Error: set description");
+                                       }
+                               }
+               if( mediaPtr->isChangedDisplayName())
+                               {
+                                       if ( MEDIA_CONTENT_ERROR_NONE
+                                               != media_info_set_display_name (media, mediaPtr->getDisplayName().c_str()))
+                                       {
+                                               LogDebug("Error: set displayname");
+                                       }
+                               }
+
+               if(type.compare("IMAGE") ==0 )
+               {
+                       MediacontentImagePtr imagePtr = DPL::DynamicPointerCast<MediacontentImage>(mediaPtr);
+                       
+                       if(imagePtr && (imagePtr->isChangedOrientaion() 
+                               || imagePtr->isChangedLatitude() || imagePtr->isChangedLongitude()))
+                       {
+                               image_meta_h img=NULL;
+                               if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_image(media, &img))
+                               {
+                                       if(imagePtr->isChangedOrientaion())
+                                       {
+                                               if ( MEDIA_CONTENT_ERROR_NONE != 
+                                                       image_meta_set_orientation (img, convertToOrientation(imagePtr->getImageOrientation())))
+                                               {
+                                                       LogDebug("Error: set orientation"); 
+                                                       ret = false;
+                                               }
+                                       }
+                       
+                                       if (  imagePtr->isChangedLatitude() )
+                                       {
+                                               if ( MEDIA_CONTENT_ERROR_NONE != 
+                                                       media_info_set_latitude(media, imagePtr->getImageLatitude())
+                                                       )
+                                               {
+                                                       LogDebug("Error: set Latitude"); 
+                                                       ret = false;
+                                               }
+                                       }
+                                       if (  imagePtr->isChangedLongitude() )
+                                       {
+                                               if ( MEDIA_CONTENT_ERROR_NONE != 
+                                                       media_info_set_longitude(media, imagePtr->getImageLongitude())
+                                                       )
+                                               {
+                                                       LogDebug("Error: set Longitude");
+                                                       ret = false;
+                                               }
+                                       }
+
+                                       if ( MEDIA_CONTENT_ERROR_NONE != image_meta_update_to_db (img) )
+                                       {
+                                               LogDebug("Error: update db");
+                                               ret = false;
+                                       }
+                                                                       
+                                       if ( MEDIA_CONTENT_ERROR_NONE != image_meta_destroy(img))
+                                       {
+                                               LogDebug("Error: destroy media info");  
+                                               ret = false;
+                                       }
+                                       
+                                       img = NULL;
+                                       
+                               }
+                               else
+                               {
+                                       LogDebug("Error: get Image from DB");
+                                       ret = false;
+                               }
+                       }
+                       
+               }
+
+               if(type.compare("VIDEO") ==0 )
+               {       
+                       MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast<MediacontentVideo>(mediaPtr);
+                       if (videoPtr && ( videoPtr->isChangedArtists () ||  videoPtr->isChangedAlbum() 
+                               || videoPtr->isChangedLatitude() ||videoPtr->isChangedLongitude()) )
+                       {
+
+                               video_meta_h video = NULL;
+                               if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_video(media, &video))
+                               {
+#if 0 //NOT support                            
+                                       if (  videoPtr->isChangedPlayCount() )
+                                       {
+                                               if ( MEDIA_CONTENT_ERROR_NONE != 
+                                                       video_meta_set_played_count (video, videoPtr->getVideoPlayCount()))
+                                               {
+                                                       LogDebug("Error: set play count"); 
+                                                       ret = false;
+                                                       
+                                               }       
+                                       }
+                                       
+                                       if (videoPtr->isChangedPlayedTime())
+                                       {
+                                               if ( MEDIA_CONTENT_ERROR_NONE != 
+                                                       video_meta_set_played_position (video, videoPtr->getVideoPlayedTime()))
+                                               {
+                                                       LogDebug("Error: set played time"); 
+                                                       ret = false;
+                                               }
+                                       }
+
+                                       if (videoPtr->isChangedAlbum())
+                                       {
+                                               LogDebug("Not support - Album API"); 
+                                               ret = false;
+                                       }
+
+                                       if (videoPtr->isChangedArtists())
+                                       {
+                                               LogDebug("Not support - Artist API"); 
+                                               ret = false;
+                                       }
+#endif                                                                 
+                                       if (  videoPtr->isChangedLatitude() )
+                                       {
+                                               if ( MEDIA_CONTENT_ERROR_NONE != 
+                                                       media_info_set_latitude(media, videoPtr->getVideoLatitude())
+                                                       )
+                                               {
+                                                       LogDebug("Error: set Latitude"); 
+                                                       ret = false;
+                                               }
+                                       }
+                                       if (  videoPtr->isChangedLongitude() )
+                                       {
+                                               if ( MEDIA_CONTENT_ERROR_NONE != 
+                                                       media_info_set_longitude(media, videoPtr->getVideoLongitude())
+                                                       )
+                                               {
+                                                       LogDebug("Error: set Latitude"); 
+                                                       ret = false;
+                                               }                                               
+                                       }
+                                       
+                                       if ( MEDIA_CONTENT_ERROR_NONE != video_meta_update_to_db (video) )
+                                       {
+                                               LogDebug("Error: update db");
+                                               ret = false;
+                                       }
+                                       
+                                       if ( MEDIA_CONTENT_ERROR_NONE != video_meta_destroy(video))
+                                       {
+                                               LogDebug("Error: destroy video meta");  
+                                               ret = false;
+                                       }
+
+                                       video = NULL;
+                                       
+                               }                               
+                       }
+                       
+               } //video
+
+               
+
+               if(type.compare("AUDIO") ==0 )
+               {
+                       
+                       MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast<MediacontentAudio>(mediaPtr);
+                       if (audioPtr && ( audioPtr->isChangedAudioArtist () ||  audioPtr->isChangedAudioAlbum() 
+                               || audioPtr->isChangedAudioGenre() ||audioPtr->isChangedAudioComposer()
+                               || audioPtr->isChangedAudioTrackNumber()) )
+                       {
+
+                               audio_meta_h audio=NULL;
+                               if ( MEDIA_CONTENT_ERROR_NONE == media_info_get_audio(media, &audio))
+                               {
+#if 0 //NOT support                            
+                                       if (  audioPtr->isChangedPlayCount() )
+                                       {
+                                               if ( MEDIA_CONTENT_ERROR_NONE != 
+                                                       audio_meta_set_played_count (audio, audioPtr->getAudioPlayCount()))
+                                               {
+                                                       LogDebug("Error: set play count"); 
+                                                       ret = false;
+                                               }       
+                                       }
+                                       
+                                       if (audioPtr->isChangedPlayedTime())
+                                       {
+                                               if ( MEDIA_CONTENT_ERROR_NONE != 
+                                                       audio_meta_set_played_position (audio, audioPtr->getAudioPlayedTime()))
+                                               {
+                                                       LogDebug("Error: set played time"); 
+                                                       ret = false;
+                                               }
+                                       }
+
+                                       if (audioPtr->isChangedAudioArtist())
+                                       {
+                                               LogDebug("Not Support API"); 
+                                               ret = false;
+                                       }
+
+                                       if (audioPtr->isChangedAudioAlbum())
+                                       {
+                                               LogDebug("Not Support API"); 
+                                               ret = false;
+                                       }
+
+                                       if (audioPtr->isChangedAudioGenre())
+                                       {
+                                               LogDebug("Not Support API"); 
+                                               ret = false;
+                                       }
+
+                                       if (audioPtr->isChangedAudioComposer())
+                                       {
+                                               LogDebug("Not Support API"); 
+                                               ret = false;
+                                       }
+
+                                       if (audioPtr->isChangedAudioTrackNumber())
+                                       {
+                                               LogDebug("Not Support API"); 
+                                               ret = false;
+                                       }
+#endif
+                                       if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_update_to_db (audio) )
+                                       {
+                                               LogDebug("Error: update db");
+                                               ret = false;
+                                       }
+                                       
+                                       if ( MEDIA_CONTENT_ERROR_NONE != audio_meta_destroy(audio))
+                                       {
+                                               LogDebug("Error: destroy audio meta");
+                                               ret = false;
+                                       }
+                                       audio = NULL;
+                               }
+
+                       }
+
+               }
+               
+               
+               //update media info
+               if ( MEDIA_CONTENT_ERROR_NONE != media_info_update_to_db(media))
+               {
+                       LogDebug("Error: update to DB");
+                       ret = false;
+               }
+       }
+
+       if( media != NULL)
+       {
+               if ( MEDIA_CONTENT_ERROR_NONE !=media_info_destroy(media))
+               {
+                       LogDebug("Error: destroy media info");
+                       ret = false;
+               }
+       }
+       return ret;
+
+}
+
+void MediacontentManager::OnRequestReceived(const IEventUpdateMediaPtr &eMedia)
+{
+    LogDebug("OnRequestReceived::IEventUpdateMediaPtr entered");
+       try
+       {
+               MediacontentMediaPtr mediaPtr = eMedia->getMediaItem();
+
+               if(updateMediaToDB(mediaPtr))
+               {
+                       eMedia->setResult(true);
+                       LogDebug("update success");
+               }
+               else
+               {
+                       eMedia->setResult(false);
+                       ThrowMsg(PlatformException, "DB operation is failed");
+               }
+       }
+    catch (const Exception &ex)
+    {
+        LogError("Exception: " << ex.DumpToString());
+        eMedia->setResult(false);
+    }
+}
+
+
+void MediacontentManager::OnRequestReceived(const IEventUpdateMediaItemsPtr &eItems)
+{
+       LogDebug("OnRequestReceived::IEventUpdateMediaItemsPtr entered");
+
+       try
+       {
+               MediacontentMediaListPtr mediaListPtr = eItems->getMediaItems();
+               if (mediaListPtr->empty()) 
+               { 
+                   LogDebug("Item vector is empty");
+               }
+               else
+               {
+                        for(unsigned int i=0; i<mediaListPtr->size(); i++)
+                       {
+                               
+                               MediacontentMediaPtr mediaPtr = mediaListPtr->at(i);
+                               if(updateMediaToDB(mediaPtr))
+                               {
+                                       eItems->setResult(true);
+                                       LogDebug("update success");
+                               }
+                               else
+                               {
+                                       eItems->setResult(false);
+                                       ThrowMsg(PlatformException, "DB operation is failed");
+                               }
+                               
+                       }
+               }
+       }
+       catch (const Exception &ex)
+       {
+                LogError("Exception: " << ex.DumpToString());
+                eItems->setResult(false);
+       }
+       //eItems->setCancelAllowed(false);
+       
+}
+
+
+
+}
+}
+}
diff --git a/src/platform/Tizen/Content/MediacontentManager.h b/src/platform/Tizen/Content/MediacontentManager.h
new file mode 100755 (executable)
index 0000000..71e1217
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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 _PLATFORM_MEDIA_CONTENT_MANAGER_H_
+#define _PLATFORM_MEDIA_CONTENT_MANAGER_H_
+
+#include <vector>
+#include <list>
+#include <dpl/mutex.h>
+#include <API/Content/IMediacontentManager.h>
+
+#include <ctime>
+#include "API/Content/IEventFindFolder.h"
+#include "API/Content/IEventUpdateMedia.h"
+#include "API/Content/IEventUpdateMediaItems.h"
+
+#include "MediaSearchVisitor.h"
+
+#include <API/Content/MediacontentImage.h>
+#include <API/Content/MediacontentVideo.h>
+#include <API/Content/MediacontentAudio.h>
+#include <API/Content/MediacontentLyrics.h>
+
+#include <media_content.h>
+#include <metadata_extractor.h>
+
+#define MEDIA_DEBUG 0
+#define TAG_DELIMETER '/'  //After reviewing the ID3v2.3 spec the delimiter is a "/" for multiple entries.
+
+using namespace TizenApis::Api::Content;
+
+namespace TizenApis {
+namespace Platform {
+namespace Content {
+
+class MediacontentManager : public Api::Content::IMediacontentManager
+{
+       public:
+       MediacontentManager();
+       virtual ~MediacontentManager();
+       
+       protected:
+//     virtual void OnRequestReceived(const IEventGetMediacontentPtr &event);
+       virtual void OnRequestReceived(const IEventFindFolderPtr &ptr);
+       virtual void OnRequestReceived(const IEventUpdateMediaPtr &ptr);
+       virtual void OnRequestReceived(const IEventBrowseFolderPtr &ptr);
+       virtual void OnRequestReceived(const IEventUpdateMediaItemsPtr &ptr);   
+
+       private:
+       static bool mediaFolderCallback(media_folder_h folder, void *user_data);        
+       static bool mediaItemCallback(media_info_h info, void* user_data);
+       static void convertToPlatformFolder(media_folder_h media_folder, MediacontentFolderPtr& newFolder);
+       bool updateMediaToDB(MediacontentMediaPtr mediaPtr);    
+       string makeQuerySortMode(SortModeArrayPtr attr, MediaSearchVisitor::QueryType value=MediaSearchVisitor::QUERY_FOLDER);
+       static tm toDateTm(time_t date);
+       media_content_orientation_e convertToOrientation(string orientation);
+
+       static void readCommonDataFromMediaInfo(media_info_h info, MediacontentMedia* newMedia);
+       static void readImageFromMediaInfo( media_info_h info, MediacontentImage* newImage);
+       static void readVideoFromMediaInfo( media_info_h info, MediacontentVideo* newVideo);
+       static void readMusicFromMediaInfo( media_info_h info, MediacontentAudio* newAudio);
+
+
+       private:
+       static int m_instanceCount;
+       DPL::Mutex m_constructorMutex;
+
+};
+
+}
+}
+}
+
+#endif /* _PLATFORM_MEDIA_CONTENT_MANAGER_H_ */
diff --git a/src/platform/Tizen/Content/config.cmake b/src/platform/Tizen/Content/config.cmake
new file mode 100755 (executable)
index 0000000..2d06821
--- /dev/null
@@ -0,0 +1,30 @@
+get_current_path()
+
+pkg_search_module(glib REQUIRED glib-2.0)
+pkg_search_module(libpcrecpp REQUIRED libpcrecpp)
+
+pkg_search_module(capi-content-media-content REQUIRED capi-content-media-content)
+pkg_search_module(capi-media-metadata-extractor REQUIRED capi-media-metadata-extractor)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_CONTENT
+  ${glib_INCLUDE_DIRS}
+  ${libpcrecpp_INCLUDE_DIRS}
+  ${capi-content-media-content_INCLUDE_DIRS}
+  ${capi-media-metadata-extractor_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_CONTENT
+  ${glib_LIBRARIES}
+  ${libpcrecpp_LIBRARIES}
+  ${capi-content-media-content_LIBRARIES}  
+  ${capi-media-metadata-extractor_LIBRARIES}  
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_CONTENT
+  ${CURRENT_PATH}/MediaSearchVisitor.cpp
+  ${CURRENT_PATH}/MediaFilterValidator.cpp
+  ${CURRENT_PATH}/MediacontentManager.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/DBus/Connection.cpp b/src/platform/Tizen/DBus/Connection.cpp
new file mode 100755 (executable)
index 0000000..9de9cf6
--- /dev/null
@@ -0,0 +1,345 @@
+//
+// 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 "Connection.h"
+#include <cassert>
+#include <algorithm>
+#include <Commons/Exception.h>
+#include <dpl/log/log.h>
+#include "Message.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace DBus {
+Connection::Connection() :
+    m_connection(NULL),
+    m_messageDispatcher(NULL),
+    m_connected(false)
+{
+    dbus_error_init(&m_error);
+    m_messageDispatcher = new MessageDispatcher(this);
+}
+
+Connection::~Connection()
+{
+    assert(!m_connected && "DBus connection has not been closed.");
+    delete m_messageDispatcher;
+    if (dbus_error_is_set(&m_error)) {
+        dbus_error_free(&m_error);
+    }
+}
+
+void Connection::open(DBusBusType bus)
+{
+    if (m_connected) { return; }
+
+    m_connection = dbus_bus_get(bus, &m_error);
+    if (!m_connection || dbus_error_is_set(&m_error)) {
+        std::string message = m_error.message;
+        dbus_error_free(&m_error);
+        ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,
+                 "Couldn't attach to DBus system bus: " << message);
+    }
+
+    dbus_connection_set_exit_on_disconnect(m_connection, FALSE);
+
+    for (FilterSetIterator it = m_filters.begin(); it != m_filters.end();
+         ++it) {
+        addFilterInternal(*it);
+    }
+
+    if (!dbus_connection_set_watch_functions(m_connection, addWatch,
+                                             removeWatch, toggleWatch, this,
+                                             NULL)) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't set-up watch functions.");
+    }
+
+    if (!dbus_connection_add_filter(m_connection, filterMessage, this, NULL)) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Couldn't set signal handler callback.");
+    }
+
+    m_connected = true;
+}
+
+void Connection::close()
+{
+    LogDebug("ENTER");
+    if (!m_connected) { return; }
+
+    dbus_connection_remove_filter(m_connection, filterMessage, this);
+
+    // Calls removeWatch() automagically.
+    if (!dbus_connection_set_watch_functions(m_connection, NULL, NULL, NULL,
+                                             NULL, NULL)) {
+        DPL::Mutex::ScopedLock lock(&m_watchesMutex);
+        WatchSetIterator it = m_watches.begin();
+        for (; it != m_watches.end(); ++it) {
+            if (it->second->isEnabled()) {
+                m_messageDispatcher->removeDescriptor(it->second->getHandle(),
+                                                      it->second->getType());
+            }
+        }
+        m_watches.clear();
+    }
+
+    // TODO: think how to handle exception on filter removal; 1 - do nothing (now),
+    // 2 - remove the buggy one but throw an exception, 3 - remove the buggy one
+    // and don't throw any exception
+    for (FilterSetIterator it = m_filters.begin(); it != m_filters.end();
+         ++it) {
+        removeFilterInternal(*it);
+    }
+
+    dbus_connection_unref(m_connection);
+
+    m_connected = false;
+}
+
+void Connection::addFilter(const std::string& rule)
+{
+    if (m_connected) {
+        addFilterInternal(rule);
+    }
+    m_filters.insert(rule);
+}
+
+void Connection::removeFilter(const std::string& rule)
+{
+    if (m_connected) {
+        removeFilterInternal(rule);
+    }
+    m_filters.erase(rule);
+}
+
+void Connection::setWorkerThread(DPL::Thread* thread)
+{
+    assert(!m_connected && "Connection has already been established.");
+    m_messageDispatcher->SwitchToThread(thread);
+}
+
+void Connection::addFilterInternal(const std::string& rule)
+{
+    assert(m_connection && "Connection has to be established first.");
+    dbus_bus_add_match(m_connection, rule.c_str(), &m_error);
+    if (dbus_error_is_set(&m_error)) {
+        std::string message = m_error.message;
+        dbus_error_free(&m_error);
+        ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Invalid rule: " << message);
+    }
+}
+
+void Connection::removeFilterInternal(const std::string& rule)
+{
+    assert(m_connection && "Connection has to be established first.");
+    dbus_bus_remove_match(m_connection, rule.c_str(), &m_error);
+    if (dbus_error_is_set(&m_error)) {
+        std::string message = m_error.message;
+        dbus_error_free(&m_error);
+        ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Invalid rule: " << message);
+    }
+}
+
+dbus_bool_t Connection::addWatch(DBusWatch* watch,
+        void* data)
+{
+    LogDebug("ENTER");
+    assert(data && "Connection should be passed as user data.");
+    Connection* this_ = static_cast<Connection*>(data);
+    WatchPtr wrapper(new Watch(watch));
+    if (wrapper->isEnabled()) {
+        this_->m_messageDispatcher->addDescriptor(wrapper->getHandle(),
+                                                  wrapper->getType());
+    }
+    DPL::Mutex::ScopedLock lock(&this_->m_watchesMutex);
+    this_->m_watches[wrapper->getHandle()] = wrapper;
+    return TRUE;
+}
+
+void Connection::removeWatch(DBusWatch* watch,
+        void* data)
+{
+    LogDebug("ENTER");
+    assert(data && "Connection should be passed as user data.");
+    Connection* this_ = static_cast<Connection*>(data);
+    Watch wrapper(watch);
+    if (wrapper.isEnabled()) {
+        this_->m_messageDispatcher->removeDescriptor(wrapper.getHandle(),
+                                                     wrapper.getType());
+    }
+    DPL::Mutex::ScopedLock lock(&this_->m_watchesMutex);
+    this_->m_watches.erase(wrapper.getHandle());
+}
+
+void Connection::toggleWatch(DBusWatch* watch,
+        void* data)
+{
+    LogDebug("ENTER");
+    assert(data && "Connection should be passed as user data.");
+    Connection* this_ = static_cast<Connection*>(data);
+    Watch wrapper(watch);
+    if (wrapper.isEnabled()) {
+        this_->m_messageDispatcher->addDescriptor(wrapper.getHandle(),
+                                                  wrapper.getType());
+    } else {
+        this_->m_messageDispatcher->removeDescriptor(wrapper.getHandle(),
+                                                     wrapper.getType());
+    }
+}
+
+DBusHandlerResult Connection::filterMessage(DBusConnection* connection,
+        DBusMessage* message,
+        void* data)
+{
+    LogDebug("ENTER");
+    if (data) {
+        Connection* this_ = static_cast<Connection*>(data);
+        MessagePtr msg;
+        if (message) {
+            LogInfo(
+                "DBUS message received from interface: " <<
+                dbus_message_get_interface(message));
+            msg.Reset(new Message(message));
+        } else {
+            LogError("DBus message not set, this should not happen!");
+            return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+        }
+
+        FilterSetIterator it = this_->m_filters.begin();
+        for (; it != this_->m_filters.end(); ++it) {
+            // TODO: extend following matching procedure to check not only
+            // interface's name.
+            if ((*it).find(msg->getInterface()) != std::string::npos) {
+                MessageEvent event(msg);
+                this_->EmitEvent(event);
+            }
+        }
+    } else {
+        LogError("User-data not set, this should not happen!");
+    }
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+Connection::MessageDispatcher::MessageDispatcher(Connection* connection) :
+    m_connection(connection)
+{
+    assert(m_connection && "Connection cannot be NULL.");
+    DPL::Event::ControllerEventHandler<AddDescriptorSyncEvent>::Touch();
+    DPL::Event::ControllerEventHandler<RemoveDescriptorSyncEvent>::Touch();
+}
+
+Connection::MessageDispatcher::~MessageDispatcher()
+{
+    SwitchToThread(NULL);
+}
+
+void Connection::MessageDispatcher::addDescriptor(DPL::WaitableHandle handle,
+        DPL::WaitMode::Type mode)
+{
+    LogDebug("ENTER");
+    DPL::WaitableEvent wait;
+    AddDescriptorSyncEvent event(handle, mode, &wait);
+    DPL::Event::ControllerEventHandler<AddDescriptorSyncEvent>::PostEvent(event);
+    DPL::WaitForSingleHandle(wait.GetHandle());
+}
+
+void Connection::MessageDispatcher::removeDescriptor(DPL::WaitableHandle handle,
+        DPL::WaitMode::Type mode)
+{
+    LogDebug("ENTER");
+    DPL::WaitableEvent wait;
+    RemoveDescriptorSyncEvent event(handle, mode, &wait);
+    DPL::Event::ControllerEventHandler<RemoveDescriptorSyncEvent>::PostEvent(event);
+    DPL::WaitForSingleHandle(wait.GetHandle());
+}
+
+void Connection::MessageDispatcher::OnEventReceived(
+        const AddDescriptorSyncEvent& event)
+{
+    LogDebug("ENTER");
+    DPL::WaitableHandleWatchSupport::InheritedContext()->AddWaitableHandleWatch(
+        this,
+        event.GetArg0(),
+        event.GetArg1());
+    event.GetArg2()->Signal();
+}
+
+void Connection::MessageDispatcher::OnEventReceived(
+        const RemoveDescriptorSyncEvent& event)
+{
+    LogDebug("ENTER");
+    DPL::WaitableHandleWatchSupport::InheritedContext()->
+        RemoveWaitableHandleWatch(this, event.GetArg0(), event.GetArg1());
+    event.GetArg2()->Signal();
+}
+
+void Connection::MessageDispatcher::OnWaitableHandleEvent(
+        DPL::WaitableHandle waitableHandle,
+        DPL::WaitMode::Type mode)
+{
+    LogDebug("ENTER");
+    {
+        DPL::Mutex::ScopedLock lock(&m_connection->m_watchesMutex);
+        WatchSetIterator it = m_connection->m_watches.find(waitableHandle);
+        if (it != m_connection->m_watches.end()) {
+            unsigned int flags =
+                (mode == DPL::WaitMode::Write ? DBUS_WATCH_WRITABLE
+                        : DBUS_WATCH_READABLE);
+            while (!dbus_watch_handle(it->second->get(), flags)) {
+                LogError("Too few memory!");
+                // TODO: add some check-point to not loop infinitely
+            }
+        }
+        // TODO: not sure if there is point in dispatching connection when watch not found?
+    }
+    dbus_connection_ref(m_connection->m_connection);
+    while (dbus_connection_dispatch(m_connection->m_connection) ==
+           DBUS_DISPATCH_DATA_REMAINS) {
+    }
+    dbus_connection_unref(m_connection->m_connection);
+}
+
+Connection::Watch::Watch(DBusWatch* watch) : m_watch(watch)
+{
+    assert(m_watch && "Watch cannot be NULL.");
+}
+
+DPL::WaitableHandle Connection::Watch::getHandle() const
+{
+    return dbus_watch_get_unix_fd(m_watch);
+}
+
+DPL::WaitMode::Type Connection::Watch::getType() const
+{
+    if ((dbus_watch_get_flags(m_watch) & DBUS_WATCH_WRITABLE) != 0) {
+        return DPL::WaitMode::Write;
+    }
+    return DPL::WaitMode::Read;
+}
+
+bool Connection::Watch::isEnabled() const
+{
+    return (TRUE == dbus_watch_get_enabled(m_watch));
+}
+
+DBusWatch* Connection::Watch::get() const
+{
+    return m_watch;
+}
+} // DBus
+} // Platform
+} // WrtPlugins
diff --git a/src/platform/Tizen/DBus/Connection.h b/src/platform/Tizen/DBus/Connection.h
new file mode 100755 (executable)
index 0000000..593b880
--- /dev/null
@@ -0,0 +1,142 @@
+//
+// 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_DBUS_CONNECTION_H_
+#define WRTPLUGINS_DBUS_CONNECTION_H_
+
+#include <string>
+#include <map>
+#include <set>
+#include <dbus/dbus.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/generic_event.h>
+#include <dpl/event/event_support.h>
+#include <dpl/event/event_listener.h>
+#include <dpl/waitable_event.h>
+#include <dpl/thread.h>
+#include <dpl/noncopyable.h>
+#include <dpl/event/controller.h>
+#include <dpl/type_list.h>
+#include <dpl/mutex.h>
+#include "MessageEvent.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace DBus {
+class Connection : public DPL::Event::EventSupport<MessageEvent>
+{
+  public:
+    typedef DPL::Event::EventListener<MessageEvent> EventListener;
+
+  public:
+    Connection();
+    ~Connection();
+
+    void open(DBusBusType bus);
+    void close();
+    void addFilter(const std::string& rule);
+    void removeFilter(const std::string& rule);
+    void setWorkerThread(DPL::Thread* thread);
+
+  private:
+    DECLARE_GENERIC_EVENT_3(AddDescriptorSyncEvent,
+                            DPL::WaitableHandle,
+                            DPL::WaitMode::Type,
+                            DPL::WaitableEvent*)
+
+    DECLARE_GENERIC_EVENT_3(RemoveDescriptorSyncEvent,
+                            DPL::WaitableHandle,
+                            DPL::WaitMode::Type,
+                            DPL::WaitableEvent*)
+
+    class MessageDispatcher : public DPL::Event::Controller<DPL::TypeListDecl<
+                                                         AddDescriptorSyncEvent,
+                                                         RemoveDescriptorSyncEvent>
+                                                         ::Type >,
+        private DPL::WaitableHandleWatchSupport::WaitableHandleListener
+    {
+      public:
+        explicit MessageDispatcher(Connection* connection);
+        ~MessageDispatcher();
+        void addDescriptor(DPL::WaitableHandle handle,
+                DPL::WaitMode::Type mode);
+        void removeDescriptor(DPL::WaitableHandle handle,
+                DPL::WaitMode::Type mode);
+
+      protected:
+        void OnEventReceived(const AddDescriptorSyncEvent& event);
+        void OnEventReceived(const RemoveDescriptorSyncEvent& event);
+        void OnWaitableHandleEvent(DPL::WaitableHandle waitableHandle,
+                DPL::WaitMode::Type mode);
+
+      private:
+        Connection* m_connection;
+    };
+
+    class Watch : private DPL::Noncopyable
+    {
+      public:
+        explicit Watch(DBusWatch* watch);
+
+        inline DPL::WaitableHandle getHandle() const;
+        inline DPL::WaitMode::Type getType() const;
+        inline bool isEnabled() const;
+        inline DBusWatch* get() const;
+
+      private:
+        DBusWatch* m_watch;
+    };
+    typedef DPL::SharedPtr<Watch> WatchPtr;
+
+    typedef std::map<DPL::WaitableHandle, WatchPtr> WatchSet;
+    typedef WatchSet::iterator WatchSetIterator;
+
+    typedef std::set<std::string> FilterSet;
+    typedef FilterSet::iterator FilterSetIterator;
+
+  private:
+    static dbus_bool_t addWatch(DBusWatch* watch,
+            void* data);
+    static void removeWatch(DBusWatch* watch,
+            void* data);
+    static void toggleWatch(DBusWatch* watch,
+            void* data);
+    static DBusHandlerResult filterMessage(DBusConnection* connection,
+            DBusMessage* message,
+            void* data);
+
+  private:
+    void addFilterInternal(const std::string& rule);
+    void removeFilterInternal(const std::string& rule);
+
+  private:
+    DBusConnection* m_connection;
+    DBusError m_error;
+
+    MessageDispatcher* m_messageDispatcher;
+    bool m_connected;
+    FilterSet m_filters;
+    WatchSet m_watches;
+    DPL::Mutex m_watchesMutex;
+};
+
+typedef DPL::SharedPtr<Connection> ConnectionPtr;
+} // DBus
+} // Platform
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DBUS_CONNECTION_H_
diff --git a/src/platform/Tizen/DBus/Message.cpp b/src/platform/Tizen/DBus/Message.cpp
new file mode 100755 (executable)
index 0000000..7f6142f
--- /dev/null
@@ -0,0 +1,139 @@
+//
+// 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 "Message.h"
+#include <cassert>
+#include <Commons/Exception.h>
+
+namespace TizenApis  {
+namespace Platform {
+namespace DBus {
+Message::Message(DBusMessage* message) : m_message(message)
+{
+    assert(m_message && "Message cannot be NULL.");
+    addRef();
+}
+
+Message::Message(int type)
+{
+    m_message = dbus_message_new(type);
+    if (!m_message) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Out of memory.");
+    }
+    addRef();
+}
+
+Message::~Message()
+{
+    unref();
+}
+
+int Message::getType() const
+{
+    return dbus_message_get_type(m_message);
+}
+
+std::string Message::getInterface() const
+{
+    const char* interface = dbus_message_get_interface(m_message);
+    return (interface ? interface : std::string());
+}
+
+std::string Message::getPath() const
+{
+    const char* path = dbus_message_get_path(m_message);
+    return (path ? path : std::string());
+}
+
+bool Message::isSignal(const std::string& name) const
+{
+    return (dbus_message_is_signal(m_message,
+                                   getInterface().c_str(),
+                                   name.c_str())
+            == TRUE);
+}
+
+Message::ReadIterator Message::getReadIterator() const
+{
+    return ReadIterator(new ReadIterator_(m_message));
+}
+
+void Message::addRef()
+{
+    m_message = dbus_message_ref(m_message);
+}
+
+void Message::unref()
+{
+    dbus_message_unref(m_message);
+}
+
+Message::ReadIterator_::ReadIterator_(DBusMessage* message)
+{
+    assert(message && "Message cannot be NULL.");
+    m_valid = dbus_message_iter_init(message, &m_iterator);
+}
+
+bool Message::ReadIterator_::next()
+{
+    if (!m_valid) {
+        Throw(WrtDeviceApis::Commons::OutOfRangeException);
+    }
+    return (m_valid = (dbus_message_iter_next(&m_iterator) == TRUE));
+}
+
+bool Message::ReadIterator_::isValid() const
+{
+    return m_valid;
+}
+
+int Message::ReadIterator_::getArgType() const
+{
+    if (!m_valid) {
+        Throw(WrtDeviceApis::Commons::OutOfRangeException);
+    }
+    return dbus_message_iter_get_arg_type(&m_iterator);
+}
+
+int Message::ReadIterator_::getInt() const
+{
+    return static_cast<int>(getArgBasic<dbus_int32_t>(DBUS_TYPE_INT32));
+}
+
+std::string Message::ReadIterator_::getString() const
+{
+    return getArgBasic<const char*>(DBUS_TYPE_STRING);
+}
+
+template<typename T>
+T Message::ReadIterator_::getArgBasic(int type) const
+{
+    if (getArgType() != type) {
+        ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Type mismatch.");
+    }
+
+    if (!m_valid) {
+        Throw(WrtDeviceApis::Commons::OutOfRangeException);
+    }
+
+    T result;
+    dbus_message_iter_get_basic(&m_iterator, &result);
+    return result;
+}
+} // DBus
+} // Platform
+} // WrtPlugins
diff --git a/src/platform/Tizen/DBus/Message.h b/src/platform/Tizen/DBus/Message.h
new file mode 100755 (executable)
index 0000000..37feafc
--- /dev/null
@@ -0,0 +1,86 @@
+//
+// 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_DBUS_MESSAGE_H_
+#define WRTPLUGINS_DBUS_MESSAGE_H_
+
+#include <string>
+#include <dbus/dbus.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/optional.h>
+#include <dpl/noncopyable.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace DBus {
+class Message : private DPL::Noncopyable
+{
+  private:
+    class ReadIterator_;
+
+  public:
+    typedef DPL::SharedPtr<ReadIterator_> ReadIterator;
+
+  public:
+    explicit Message(DBusMessage* message);
+    explicit Message(int type);
+    ~Message();
+
+    int getType() const;
+    std::string getInterface() const;
+    std::string getPath() const;
+    bool isSignal(const std::string& name) const;
+    ReadIterator getReadIterator() const;
+
+  private:
+    // It doesn't need to be non-copyable - DBusMessageIter doesn't require it.
+    class ReadIterator_
+    {
+      public:
+        explicit ReadIterator_(DBusMessage* message);
+
+        bool next();
+        bool isValid() const;
+
+        int getArgType() const;
+
+        int getInt() const;
+        std::string getString() const;
+
+      private:
+        template<typename T>
+        T getArgBasic(int type) const;
+
+      private:
+        mutable DBusMessageIter m_iterator;
+        bool m_valid;
+    };
+
+  private:
+    inline void addRef();
+    inline void unref();
+
+  private:
+    DBusMessage* m_message;
+};
+
+typedef DPL::SharedPtr<Message> MessagePtr;
+} // DBus
+} // Platform
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DBUS_MESSAGE_H_
diff --git a/src/platform/Tizen/DBus/MessageEvent.h b/src/platform/Tizen/DBus/MessageEvent.h
new file mode 100755 (executable)
index 0000000..ef1e835
--- /dev/null
@@ -0,0 +1,32 @@
+//
+// 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_DBUS_MESSAGEEVENT_H_
+#define WRTPLUGINS_DBUS_MESSAGEEVENT_H_
+
+#include <dpl/generic_event.h>
+#include "Message.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace DBus {
+DECLARE_GENERIC_EVENT_1(MessageEvent, MessagePtr)
+} // DBus
+} // Platform
+} // WrtPlugins
+
+#endif // WRTPLUGINS_DBUS_MESSAGEEVENT_H_
diff --git a/src/platform/Tizen/DBus/config.cmake b/src/platform/Tizen/DBus/config.cmake
new file mode 100644 (file)
index 0000000..1cf8150
--- /dev/null
@@ -0,0 +1,16 @@
+get_current_path()
+
+pkg_search_module(dbus REQUIRED dbus-1)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_DBUS
+  ${dbus_INCLUDE_DIRS}
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_DBUS
+  ${dbus_LIBRARIES}
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_DBUS
+  ${CURRENT_PATH}/Connection.cpp
+  ${CURRENT_PATH}/Message.cpp
+)
diff --git a/src/platform/Tizen/Download/DownloadManager.cpp b/src/platform/Tizen/Download/DownloadManager.cpp
new file mode 100755 (executable)
index 0000000..378c638
--- /dev/null
@@ -0,0 +1,785 @@
+//
+// 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 "DownloadManager.h"
+#include <API/Download/DownloadRequest.h>
+#include <dpl/log/log.h>
+
+#include <download.h>
+
+using namespace TizenApis::Api::Download;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Platform {
+namespace Download {
+
+DownloadManager::DownloadManager()
+{
+}
+
+DownloadManager::~DownloadManager()
+{
+}
+
+
+
+static std::string _get_download_error(int err)
+{
+    std::string msg = "";
+
+    switch (err) {
+        case DOWNLOAD_ERROR_INVALID_PARAMETER:
+            msg = "Invalid parameter";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_OUT_OF_MEMORY:
+            msg = "Out of memory";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_NETWORK_UNREACHABLE:
+            msg = "Network is unreachable";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_CONNECTION_TIMED_OUT:
+            msg = "Http session time-out";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_NO_SPACE:
+            msg = "No space left on device";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_FIELD_NOT_FOUND:
+            msg = "Specified field not found";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_INVALID_STATE:
+            msg = "Invalid state";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_CONNECTION_FAILED:
+            msg = "Connection failed";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_INVALID_URL:
+            msg = "Invalid URL";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_INVALID_DESTINATION:
+            msg = "Invalid destination";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_TOO_MANY_DOWNLOADS:
+            msg = "Full of available simultaneous downloads";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_QUEUE_FULL:
+            msg = "Full of available downloading items from server";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_ALREADY_COMPLETED:
+            msg = "The download is already completed";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_FILE_ALREADY_EXISTS:
+            msg = "It is failed to rename the downloaded file";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_CANNOT_RESUME:
+            msg = "It cannot resume";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_TOO_MANY_REDIRECTS:
+            msg = "In case of too may redirects from http response header";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_UNHANDLED_HTTP_CODE:
+            msg = "The download cannot handle the http status value";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_REQUEST_TIMEOUT:
+            msg = "There are no action after client create a download id";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_RESPONSE_TIMEOUT:
+            msg = "It does not call start API in some time although the download is created";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_SYSTEM_DOWN:
+            msg = "There are no response from client after rebooting download daemon";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_ID_NOT_FOUND:
+            msg = "The download id is not existed in download service module";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_NO_DATA:
+            msg = "No data because the set API is not called";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_IO_ERROR:
+            msg = "Internal I/O error";
+            LogError("Platform error [" << err << "] " << msg);
+            break;
+        case DOWNLOAD_ERROR_NONE:
+            // Success
+            break;
+        default:
+            msg = "Unknown error";
+            LogError("Platform error [" << err << "] " << msg);
+    }
+
+    return msg;
+}
+
+
+static void download_state_changed_cb(int download_id, download_state_e state, void *user_data)
+{
+    LogInfo("Download state changed with id: "<<download_id<<", state: "<<state);
+
+    Try
+    {
+        OnDownloadStateChangedPtr eventPtr(new OnDownloadStateChanged());
+        DownloadManager* thisDownloadManager = (DownloadManager*) user_data;
+        int ret;
+
+        eventPtr->setDownloadId((long) download_id);
+        eventPtr->setResult(true);
+
+        switch(state) {
+        case DOWNLOAD_STATE_QUEUED:
+        {
+            eventPtr->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_QUEUED);
+            if (thisDownloadManager->m_changeEmitters[download_id]) {
+                thisDownloadManager->m_changeEmitters[download_id]->emit(eventPtr);
+            }
+            break;
+        }
+        case DOWNLOAD_STATE_PAUSED:
+        {   
+            eventPtr->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_PAUSED);
+            if (thisDownloadManager->m_changeEmitters[download_id]) {
+                thisDownloadManager->m_changeEmitters[download_id]->emit(eventPtr);
+            }
+            break;
+        }
+        case DOWNLOAD_STATE_COMPLETED:
+        {   
+            eventPtr->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_COMPLETED);
+
+            ret = download_unset_state_changed_cb(download_id);
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while unsetting state changed cb: "<<ret);
+            }
+            ret = download_unset_progress_cb(download_id);
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while unsetting progress cb: "<<ret);
+            }
+
+            char* fullPath = NULL;
+            ret = download_get_downloaded_file_path(download_id, &fullPath);
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while getting download full path: "<<ret);
+            }
+
+            if( fullPath ) {
+                eventPtr->setFullPath(fullPath);
+                LogDebug("Full path: "<<fullPath);
+                free(fullPath);
+            }
+
+            if (thisDownloadManager->m_changeEmitters[download_id]) {
+                thisDownloadManager->m_changeEmitters[download_id]->emit(eventPtr);
+            }
+            thisDownloadManager->m_changeEmitters.erase(download_id);
+
+            ret = download_destroy(download_id);
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while destroying download handle: "<<ret);
+            }
+            break;
+        }
+        case DOWNLOAD_STATE_FAILED:
+        {
+            LogError("Download Failed!! download_id=" << download_id);
+
+            eventPtr->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_FAILED);
+
+            eventPtr->setExceptionCode(ExceptionCodes::PlatformException);
+
+            int err = DOWNLOAD_ERROR_NONE;
+            ret = download_get_error(download_id, (download_error_e *)&err);
+            if (DOWNLOAD_ERROR_NONE == ret) {
+                eventPtr->setErrorMessage(_get_download_error(err));
+            } else {
+                LogWarning("Platform error while getting error code: "<<ret);
+            }
+
+            ret = download_unset_state_changed_cb(download_id);
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while unsetting state changed cb: "<<ret);
+            }
+            ret = download_unset_progress_cb(download_id);
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while unsetting progress cb: "<<ret);
+            }
+
+            if (thisDownloadManager->m_changeEmitters[download_id]) {
+                thisDownloadManager->m_changeEmitters[download_id]->emit(eventPtr);
+            }
+            thisDownloadManager->m_changeEmitters.erase(download_id);
+
+            ret = download_destroy(download_id);
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while destroying download handle: "<<ret);
+            }
+            break;
+        }
+        case DOWNLOAD_STATE_CANCELED:
+        {   
+            eventPtr->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_CANCELED);
+
+            ret = download_unset_state_changed_cb(download_id);
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while unsetting state changed cb: "<<ret);
+            }
+            ret = download_unset_progress_cb(download_id);
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while unsetting progress cb: "<<ret);
+            }
+
+            if (thisDownloadManager->m_changeEmitters[download_id]) {
+                thisDownloadManager->m_changeEmitters[download_id]->emit(eventPtr);
+            }
+            thisDownloadManager->m_changeEmitters.erase(download_id);
+
+            ret = download_destroy(download_id);
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while destroying download handle: "<<ret);
+            }
+            break;
+        }
+        case DOWNLOAD_STATE_READY:
+        case DOWNLOAD_STATE_NONE:
+        default:
+        {
+            LogDebug("State change ignored.");
+            break;
+        }
+        }
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+}
+
+static void download_progress_cb(int download_id, unsigned long long received, void *user_data)
+{
+    LogDebug("Download progress with download_id: "<<download_id<<", received: "<<received);
+
+    Try
+    {
+        OnDownloadStateChangedPtr eventPtr(new OnDownloadStateChanged());
+        DownloadManager* thisDownloadManager = (DownloadManager*) user_data;
+
+        unsigned long long totalSize = 0;
+        if(DOWNLOAD_ERROR_NONE!=download_get_content_size(download_id, &totalSize)) {
+            LogWarning("Failed to get the total file size.");
+
+        }
+        eventPtr->setDownloadId((long) download_id);
+        eventPtr->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_DOWNLOADING);
+        eventPtr->setReceivedSize(received);
+        eventPtr->setTotalSize(totalSize);
+        eventPtr->setResult(true);
+
+        if (thisDownloadManager->m_changeEmitters[download_id]) {
+            thisDownloadManager->m_changeEmitters[download_id]->emit(eventPtr);
+        }
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+}
+
+void DownloadManager::OnRequestReceived(const IEventStartDownloadPtr &event)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        DownloadRequestPtr downloadRequest;
+        downloadRequest = event->getDownloadRequest();
+        if (!downloadRequest) {
+            ThrowMsg(NullPointerException, "Download request is NULL.");
+        }
+
+        std::string url = downloadRequest->getUrl();
+        std::string destinationFullPath = downloadRequest->getDestinationFullPath();
+        std::string fileName = downloadRequest->getFileName();
+        LogDebug("url: "<<url<<", destination: "<<destinationFullPath<<", fileName: "<<fileName);
+
+        int ret, download_id;
+
+        ret = download_create(&download_id);
+        if (ret != DOWNLOAD_ERROR_NONE) {
+            ThrowMsg(PlatformException, "Platform error while creating download: " << _get_download_error(ret));
+        }
+
+        ret = download_set_url(download_id, url.c_str());
+        if (ret != DOWNLOAD_ERROR_NONE) {
+            ThrowMsg(PlatformException, "Platform error while setting url: " << _get_download_error(ret));
+        }
+
+        if(!destinationFullPath.empty()) {
+            ret = download_set_destination(download_id, destinationFullPath.c_str());
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while setting destination: " << _get_download_error(ret));
+            }
+        }
+
+        if(!fileName.empty()) {
+            ret = download_set_file_name(download_id, fileName.c_str());
+            if (ret != DOWNLOAD_ERROR_NONE) {
+                ThrowMsg(PlatformException, "Platform error while setting file name: " << _get_download_error(ret));
+            }
+        }
+
+        ret = download_set_state_changed_cb(download_id, download_state_changed_cb, this);
+        if (ret != DOWNLOAD_ERROR_NONE) {
+            ThrowMsg(PlatformException, "Platform error while setting state changed cb: " << _get_download_error(ret));
+        }
+
+        ret = download_set_progress_cb(download_id, download_progress_cb, this);
+        if (ret != DOWNLOAD_ERROR_NONE) {
+            ThrowMsg(PlatformException, "Platform error while setting progress cb: " << _get_download_error(ret));
+        }
+
+        ret = download_start(download_id);
+        if (ret != DOWNLOAD_ERROR_NONE) {
+            ThrowMsg(PlatformException, "Platform error while starting download: " << _get_download_error(ret));
+        }
+
+        LogDebug("download_id: "<<download_id);
+
+        if(event->getEmitter()) {
+            LogDebug("Attaching the emitter...");
+            m_changeEmitters[download_id] = event->getEmitter();
+        } else {
+            LogDebug("Adding the handle only...");
+            m_changeEmitters[download_id];
+        }
+
+        event->setDownloadId((long)download_id);
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::PlatformException);
+    }
+}
+
+void DownloadManager::OnRequestReceived(const IEventSetListenerPtr &event)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        int downloadId = (int)(event->getDownloadId());
+
+        int ret;
+
+        LogDebug("downloadId: "<<downloadId);
+
+        ret = download_set_state_changed_cb(downloadId, download_state_changed_cb, this);
+        if (DOWNLOAD_ERROR_NONE != ret) {
+            if (DOWNLOAD_ERROR_ID_NOT_FOUND == ret) {
+                ThrowMsg(NotFoundException, "Id not found.");
+            } else if (DOWNLOAD_ERROR_INVALID_PARAMETER == ret) {
+                ThrowMsg(InvalidArgumentException, "Id is not valid.");
+            }
+            ThrowMsg(PlatformException, "Platform error while setting state changed cb: " << _get_download_error(ret));
+        }
+        ret = download_set_progress_cb(downloadId, download_progress_cb, this);
+        if (DOWNLOAD_ERROR_NONE != ret) {
+            if (DOWNLOAD_ERROR_ID_NOT_FOUND == ret) {
+                ThrowMsg(NotFoundException, "Id not found.");
+            } else if (DOWNLOAD_ERROR_INVALID_PARAMETER == ret) {
+                ThrowMsg(InvalidArgumentException, "Id is not valid.");
+            }
+            ThrowMsg(PlatformException, "Platform error while setting progress cb: " << _get_download_error(ret));
+        }
+
+        if(event->getEmitter()) {
+            LogDebug("Attaching the emitter with downloadId: "<<downloadId);
+            m_changeEmitters[downloadId] = event->getEmitter();
+        }
+
+        event->setResult(true);
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+    Catch(NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::NotFoundException);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::PlatformException);
+    }
+}
+
+void DownloadManager::OnRequestReceived(const IEventCancelDownloadPtr &event)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        int downloadId = (int)(event->getDownloadId());
+
+        int ret;
+
+        ret = download_cancel(downloadId);
+        if (DOWNLOAD_ERROR_NONE != ret) {
+            if (DOWNLOAD_ERROR_ID_NOT_FOUND == ret) {
+                ThrowMsg(NotFoundException, "Id not found.");
+            } else if (DOWNLOAD_ERROR_INVALID_PARAMETER == ret) {
+                ThrowMsg(InvalidArgumentException, "Id is not valid.");
+            }
+            ThrowMsg(PlatformException, "Platform error while canceling download: " << _get_download_error(ret));
+        }
+
+        event->setResult(true);
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+    Catch(NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::NotFoundException);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void DownloadManager::OnRequestReceived(const IEventPauseDownloadPtr &event)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        int downloadId = (int)(event->getDownloadId());
+
+        int ret;
+
+        ret = download_pause(downloadId);
+        if (DOWNLOAD_ERROR_NONE != ret) {
+            if (DOWNLOAD_ERROR_ID_NOT_FOUND == ret) {
+                ThrowMsg(NotFoundException, "Id not found.");
+            } else if (DOWNLOAD_ERROR_INVALID_PARAMETER == ret) {
+                ThrowMsg(InvalidArgumentException, "Id is not valid.");
+            }
+            ThrowMsg(PlatformException, "Platform error while pausing download: " << _get_download_error(ret));
+        }
+
+        event->setResult(true);
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+    Catch(NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::NotFoundException);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void DownloadManager::OnRequestReceived(const IEventResumeDownloadPtr &event)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        int downloadId = (int)(event->getDownloadId());
+
+        int ret;
+
+        ret = download_start(downloadId);
+        if (DOWNLOAD_ERROR_NONE != ret) {
+            if (DOWNLOAD_ERROR_ID_NOT_FOUND == ret) {
+                ThrowMsg(NotFoundException, "Id not found.");
+            } else if (DOWNLOAD_ERROR_INVALID_PARAMETER == ret) {
+                ThrowMsg(InvalidArgumentException, "Id is not valid.");
+            }
+            ThrowMsg(PlatformException, "Platform error while resuming download: " << _get_download_error(ret));
+        }
+
+        event->setResult(true);
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+    Catch(NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::NotFoundException);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void DownloadManager::OnRequestReceived(const IEventGetStatePtr &event)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        int downloadId = (int)(event->getDownloadId());
+
+        int ret;
+        download_state_e state;
+
+        ret = download_get_state(downloadId, &state);
+        if (DOWNLOAD_ERROR_NONE != ret) {
+            if (DOWNLOAD_ERROR_ID_NOT_FOUND == ret) {
+                ThrowMsg(NotFoundException, "Id not found.");
+            } else if (DOWNLOAD_ERROR_INVALID_PARAMETER == ret) {
+                ThrowMsg(InvalidArgumentException, "Id is not valid.");
+            }
+            ThrowMsg(PlatformException, "Platform error while getting state: " << _get_download_error(ret));
+        }
+
+        if( DOWNLOAD_STATE_READY==state || DOWNLOAD_STATE_QUEUED ==state ) {
+            event->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_QUEUED);
+        } else if( DOWNLOAD_STATE_DOWNLOADING==state ) {
+            event->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_DOWNLOADING);
+        } else if( DOWNLOAD_STATE_PAUSED==state ) {
+            event->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_PAUSED);
+        } else if( DOWNLOAD_STATE_COMPLETED==state ) {
+            event->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_COMPLETED);
+        } else if( DOWNLOAD_STATE_FAILED==state ) {
+            event->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_FAILED);
+        } else if( DOWNLOAD_STATE_CANCELED==state ) {
+            event->setDownloadState(TIZEN_ENUM_DOWNLOAD_STATE_CANCELED);
+        } else {
+            ThrowMsg(NotFoundException, "Wrong download state: "<<state);
+        }
+
+        event->setResult(true);
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+    Catch(NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::NotFoundException);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void DownloadManager::OnRequestReceived(const IEventGetDownloadRequestPtr &event)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        int downloadId = (int)(event->getDownloadId());
+
+        int ret;
+        char* url = NULL;
+        char* destination = NULL;
+        char* fileName = NULL;
+
+        ret = download_get_url(downloadId, &url);
+        if (DOWNLOAD_ERROR_NONE != ret) {
+            if (DOWNLOAD_ERROR_ID_NOT_FOUND == ret) {
+                ThrowMsg(NotFoundException, "Id not found.");
+            } else if (DOWNLOAD_ERROR_INVALID_PARAMETER == ret) {
+                ThrowMsg(InvalidArgumentException, "Id is not valid.");
+            }
+            ThrowMsg(PlatformException, "Platform error while getting url: " << _get_download_error(ret));
+        }
+
+        ret = download_get_destination(downloadId, &destination);
+        if (DOWNLOAD_ERROR_NO_DATA!=ret) {
+            if (DOWNLOAD_ERROR_NONE != ret) {
+                if (DOWNLOAD_ERROR_ID_NOT_FOUND == ret) {
+                    ThrowMsg(NotFoundException, "Id not found.");
+                } else if (DOWNLOAD_ERROR_INVALID_PARAMETER == ret) {
+                    ThrowMsg(InvalidArgumentException, "Id is not valid.");
+                }
+                ThrowMsg(PlatformException, "Platform error while getting destination: " << _get_download_error(ret));
+            }
+        }
+
+        ret = download_get_file_name(downloadId, &fileName);
+        if (DOWNLOAD_ERROR_NO_DATA!=ret) {
+            if (DOWNLOAD_ERROR_NONE != ret) {
+                if (DOWNLOAD_ERROR_ID_NOT_FOUND == ret) {
+                    ThrowMsg(NotFoundException, "Id not found.");
+                } else if (DOWNLOAD_ERROR_INVALID_PARAMETER == ret) {
+                    ThrowMsg(InvalidArgumentException, "Id is not valid.");
+                }
+                ThrowMsg(PlatformException, "Platform error while getting file name: " << _get_download_error(ret));
+            }
+        }
+
+        DownloadRequestPtr downloadRequest( new DownloadRequest() );
+        if(url) {
+            downloadRequest->setUrl(std::string(url));
+            free(url);
+        }
+        if(destination) {
+            downloadRequest->setDestination(std::string(destination));
+            free(destination);
+        }
+        if(fileName) {
+            downloadRequest->setFileName(std::string(fileName));
+            free(fileName);
+        }
+
+        LogDebug("url: "<<downloadRequest->getUrl()<<", destination "<<downloadRequest->getDestination()<<", fileName "<<downloadRequest->getFileName());
+
+        event->setDownloadRequest(downloadRequest);
+
+        event->setResult(true);
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+    Catch(NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::NotFoundException);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void DownloadManager::OnRequestReceived(const IEventGetMIMETypePtr &event)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        int downloadId = (int)(event->getDownloadId());
+
+        int ret;
+        char* MIMEType = NULL;
+
+        ret = download_get_mime_type(downloadId, &MIMEType);
+        if (DOWNLOAD_ERROR_NO_DATA!=ret) {
+            if (DOWNLOAD_ERROR_NONE != ret) {
+                if (DOWNLOAD_ERROR_ID_NOT_FOUND == ret) {
+                    ThrowMsg(NotFoundException, "Id not found.");
+                } else if (DOWNLOAD_ERROR_INVALID_PARAMETER == ret) {
+                    ThrowMsg(InvalidArgumentException, "Id is not valid.");
+                }
+                ThrowMsg(PlatformException, "Platform error while getting MIME type: " << _get_download_error(ret));
+            }
+        } else {
+            LogDebug("No MIME type data available.");
+        }   
+
+        if(MIMEType) {
+            LogDebug("MIMEType: "<<MIMEType);
+            event->setMIMEType(MIMEType);
+            free(MIMEType);
+        }
+
+        event->setResult(true);
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+    Catch(NotFoundException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::NotFoundException);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Download/DownloadManager.h b/src/platform/Tizen/Download/DownloadManager.h
new file mode 100755 (executable)
index 0000000..67ab58a
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// 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 _PLATFORM_DOWNLOAD_MANAGER_H_
+#define _PLATFORM_DOWNLOAD_MANAGER_H_
+
+#include <API/Download/IDownloadManager.h>
+#include <API/Download/OnDownloadStateChanged.h>
+
+#include <map>
+
+namespace TizenApis {
+namespace Platform {
+namespace Download {
+
+class DownloadManager : public Api::Download::IDownloadManager
+{
+  public:
+    DownloadManager();
+    virtual ~DownloadManager();
+
+    std::map<int, Api::Download::OnDownloadStateChangedEmitterPtr> m_changeEmitters;
+
+  protected:
+    virtual void OnRequestReceived(const Api::Download::IEventStartDownloadPtr &event);
+    virtual void OnRequestReceived(const Api::Download::IEventCancelDownloadPtr &event);
+    virtual void OnRequestReceived(const Api::Download::IEventPauseDownloadPtr &event);
+    virtual void OnRequestReceived(const Api::Download::IEventResumeDownloadPtr &event);
+    virtual void OnRequestReceived(const Api::Download::IEventGetStatePtr &event);
+    virtual void OnRequestReceived(const Api::Download::IEventGetDownloadRequestPtr &event);
+    virtual void OnRequestReceived(const Api::Download::IEventGetMIMETypePtr &event);
+    virtual void OnRequestReceived(const Api::Download::IEventSetListenerPtr &event);
+};
+
+}
+}
+}
+
+#endif /* _PLATFORM_DOWNLOAD_MANAGER_H_ */
diff --git a/src/platform/Tizen/Download/config.cmake b/src/platform/Tizen/Download/config.cmake
new file mode 100755 (executable)
index 0000000..bae6bc6
--- /dev/null
@@ -0,0 +1,18 @@
+get_current_path()
+
+pkg_search_module(download REQUIRED capi-web-url-download)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_DOWNLOAD
+  ${download_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_DOWNLOAD
+  ${download_LIBRARIES}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_DOWNLOAD
+  ${CURRENT_PATH}/DownloadManager.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/Filesystem/Manager.cpp b/src/platform/Tizen/Filesystem/Manager.cpp
new file mode 100755 (executable)
index 0000000..2f8e41f
--- /dev/null
@@ -0,0 +1,914 @@
+//
+// 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 "Manager.h"
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <pcrecpp.h>
+#include <ctime>
+#include <sstream>
+#include <dirent.h>
+#include <dpl/log/log.h>
+#include <dpl/scoped_ptr.h>
+
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+#include <API/Filesystem/PathUtils.h>
+#include <API/Filesystem/StorageProperties.h>
+#include "Node.h"
+#include "Utils.h"
+#include <app.h>
+
+using namespace TizenApis::Api::Filesystem;
+
+namespace {
+const char* PATH_DOWNLOADS = "/opt/usr/media/Downloads";
+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";
+}
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+Manager::Locations Manager::m_locations;
+Manager::RootList Manager::m_rootlist;
+Manager::SubRootList Manager::m_subrootlist;
+const std::size_t Manager::m_maxPathLength = 256;
+NodeList Manager::m_openedNodes;
+std::vector<Manager::WatcherPtr> Manager::m_watchers;
+
+bool Manager::fileExists(const std::string &file)
+{
+    errno = 0;
+    struct stat info;
+    memset(&info, 0, sizeof(struct stat));
+    int status = lstat(file.c_str(), &info);
+    if (status == 0) {
+        return true;
+    } else if (errno == ENOENT) {
+        return false;
+    }
+    ThrowMsg(Commons::PlatformException, "Cannot stat file.");
+}
+
+bool Manager::getSupportedDeviceCB(int storage, storage_type_e type, storage_state_e state, const char *path, void *user_data)
+{
+       std::vector<Api::Filesystem::StoragePropertiesPtr>* storageVector = (std::vector<Api::Filesystem::StoragePropertiesPtr>*)user_data;
+       Api::Filesystem::StoragePropertiesPtr storageItem(new StorageProperties());
+
+       int size = 12;
+       char buf[size];
+       std::string lable;
+       std::string fullpath(path);
+       if (type == STORAGE_TYPE_INTERNAL) {
+               snprintf(buf, size, "internal%d", storage);
+               lable.append(buf);
+       } else if (type == STORAGE_TYPE_EXTERNAL) {
+               snprintf(buf, size, "removable%d", storage);
+               lable.append(buf);
+       }
+
+       storageItem->setId(storage);
+       storageItem->setLabel(lable);
+       storageItem->setType((short)type);
+       storageItem->setState((short)state);
+       storageItem->setFullPath(fullpath);
+
+       storageVector->insert(storageVector->end(), storageItem);
+
+       return true;
+}
+
+void Manager::storageStateChangedCB(int storage, storage_state_e state, void *user_data)
+{
+       if (user_data != NULL) {
+               watcherList* m_watcherList = (watcherList *)user_data;
+               watcherList::iterator it = m_watcherList->begin();
+               for(; it!= m_watcherList->end(); ++it) {
+                       (*it)->StorageStateHasChanged(storage, state);
+               }
+       }
+}
+
+void Manager::addOpenedNode(const Api::Filesystem::INodePtr& node)
+{
+    NodeListIterator it = m_openedNodes.begin();
+    for (; it != m_openedNodes.end(); ++it) {
+        if (node.Get() == (*it).Get()) {
+            //node is added already
+            return;
+        }
+    }
+    m_openedNodes.push_back(node);
+}
+
+void Manager::removeOpenedNode(const Api::Filesystem::INodePtr& node)
+{
+    NodeListIterator it = m_openedNodes.begin();
+    for (; it != m_openedNodes.end(); ++it) {
+        if ((*it).Get() == node.Get()) {
+            m_openedNodes.erase(it);
+            break;
+        }
+    }
+}
+
+bool Manager::checkIfOpened(const Api::Filesystem::IPathPtr& path) const
+{
+    NodeListIterator it = m_openedNodes.begin();
+    for (; it != m_openedNodes.end(); ++it) {
+        if (*path == *(*it)->getPath()) {
+            return true;
+        }
+    }
+    return false;
+}
+
+Manager::Manager()
+{
+    static bool initialized = init();
+    (void) initialized;
+}
+
+Manager::~Manager()
+{
+}
+
+StorageList Manager::getStorageList() const
+{
+    return m_locations;
+}
+
+IPathPtr Manager::getBasePath() const
+{
+    Locations::const_iterator it = m_locations.find(m_subrootlist.find(LT_ROOT)->second);
+    if (it == m_locations.end()) {
+        ThrowMsg(Commons::PlatformException, "Base path not available.");
+    }
+    return it->second;
+}
+
+IPathPtr Manager::getLocationPath(LocationType type) const
+{
+    Locations::const_iterator it = m_locations.find(m_subrootlist.find(type)->second);
+    if (it != m_locations.end()) {
+        return it->second->clone();
+    }
+    return IPathPtr();
+}
+
+LocationPaths Manager::getLocationPaths() const
+{
+    LocationPaths result;
+    Locations::const_iterator it = m_locations.begin();
+    for (; it != m_locations.end(); ++it) {
+        result.push_back(it->second->clone());
+    }
+    return result;
+}
+
+LocationTypes Manager::getLocations() const
+{
+    LocationTypes result;
+    SubRootList::const_iterator it = m_subrootlist.begin();
+    for (; it != m_subrootlist.end(); ++it) {
+        result.push_back(it->first);
+    }
+    return result;
+}
+
+void Manager::getNode(const EventResolvePtr& event)
+{
+    EventRequestReceiver<EventResolve>::PostRequest(event);
+}
+
+void Manager::getStorage(const EventGetStoragePtr& event)
+{
+       EventRequestReceiver<EventGetStorage>::PostRequest(event);
+}
+
+void Manager::listStorages(const EventListStoragesPtr& event)
+{
+       EventRequestReceiver<EventListStorages>::PostRequest(event);
+}
+
+std::size_t Manager::getMaxPathLength() const
+{
+    return m_maxPathLength;
+}
+
+void Manager::copy(const EventCopyPtr& event)
+{
+    EventRequestReceiver<EventCopy>::PostRequest(event);
+}
+
+void Manager::move(const EventMovePtr& event)
+{
+    EventRequestReceiver<EventMove>::PostRequest(event);
+}
+
+void Manager::create(const EventCreatePtr& event)
+{
+    EventRequestReceiver<EventCreate>::PostRequest(event);
+}
+
+void Manager::remove(const EventRemovePtr& event)
+{
+    EventRequestReceiver<EventRemove>::PostRequest(event);
+}
+
+void Manager::find(const EventFindPtr& event)
+{
+    EventRequestReceiver<EventFind>::PostRequest(event);
+}
+
+void Manager::find(const Api::Filesystem::IPathPtr& path,
+        const Api::Filesystem::FiltersMap& filters,
+        NodeList& result,
+        const Api::Filesystem::EventFindPtr& event)
+{
+    Try {
+        DIR* dir = opendir(path->getFullPath().c_str());
+        if (!dir) {
+            return;
+        }
+
+        errno = 0;
+        struct dirent* entry = NULL;
+        while ((entry = readdir(dir))) {
+            if (event && event->checkCancelled()) {
+                break;
+            }
+            if (!strcmp(entry->d_name, ".") || !strncmp(entry->d_name, "..", 2)) {
+                continue;
+            }
+            IPathPtr childPath = *path + entry->d_name;
+            struct stat info;
+            memset(&info, 0, sizeof(struct stat));
+            if (lstat(childPath->getFullPath().c_str(), &info) == 0) {
+                if (matchFilters(entry->d_name, info, filters)) {
+                    result.push_back(Node::resolve(childPath));
+                }
+                if (S_ISDIR(info.st_mode)) {
+                    find(childPath, filters, result, event);
+                }
+            }
+        }
+
+        if (errno != 0) {
+            ThrowMsg(Commons::PlatformException,
+                     "Error while reading directory.");
+        }
+
+        if (closedir(dir) != 0) {
+            ThrowMsg(Commons::PlatformException,
+                     "Could not close platform node.");
+        }
+    }
+    Catch(WrtDeviceApis::Commons::Exception) {
+    }
+}
+
+void Manager::copyElement(
+        const std::string &src, const std::string &dest, bool recursive) const
+{
+    LogDebug("Copying src: " << src << " to: " << dest);
+
+    //element is a file:
+    if (EINA_TRUE != ecore_file_is_dir(src.c_str())) {
+        if (EINA_TRUE != ecore_file_cp(src.c_str(), dest.c_str())) {
+            ThrowMsg(Commons::PlatformException, "Failed to copy file");
+        }
+        return;
+    }
+    //element is a directory -> create it:
+    if (EINA_TRUE != ecore_file_mkdir(dest.c_str())) {
+        LogDebug("Failed to create destination directory");
+        ThrowMsg(Commons::PlatformException, "Failed to copy directory");
+    }
+    //copy all elements of directory:
+    if (recursive) {
+        Eina_List* list = ecore_file_ls(src.c_str());
+        void* data;
+        EINA_LIST_FREE(list, data)
+        {
+            Try
+            {
+                copyElement((src + '/' + static_cast<char*>(data)).c_str(),
+                            (dest + '/' + static_cast<char*>(data)).c_str());
+            }
+                       
+            Catch (Commons::Exception) 
+            {
+                 //remove rest of the list
+                EINA_LIST_FREE(list, data)
+                {
+                    free(data);
+                }
+                LogError("Exception: " << _rethrown_exception.GetMessage());
+                ReThrowMsg(Commons::PlatformException, "Failed to copy element");
+            }
+            free(data);
+        }
+    }
+
+}
+
+/*bool Manager::access(const IPathPtr& path,
+        int accessType) const
+{
+    int amode = 0;
+    if (accessType & AT_EXISTS) { amode |= F_OK; }
+    if (accessType & AT_READ) { amode |= R_OK; }
+    if (accessType & AT_WRITE) { amode |= W_OK; }
+    if (accessType & AT_EXEC) { amode |= X_OK; }
+    return (::access(path->getFullPath().c_str(), amode) == 0);
+}*/
+
+long Manager::addStorageStateChangeListener(
+        const EventStorageStateChangedEmitterPtr& emitter)
+{
+       RootList::const_iterator it = m_rootlist.begin();
+       WatcherPtr watcher(new Watcher(emitter));
+       Manager::m_watchers.push_back(watcher);
+
+       for (; it != m_rootlist.end(); ++it) {
+               storage_set_state_changed_cb(it->second, Manager::storageStateChangedCB, (void *)(&m_watchers));
+       }
+
+       watcher->getCurrentStoargeStateForWatch();
+       return static_cast<long>(emitter->getId());
+}
+
+void Manager::removeStorageStateChangeListener(EventStorageStateChangedEmitter::IdType id)
+{
+       watcherList::iterator itWatcher = Manager::m_watchers.begin();
+       bool found = false;
+       for (;itWatcher != Manager::m_watchers.end();) {
+               if (id == (*itWatcher)->getEmitter()->getId()) {
+                       itWatcher = Manager::m_watchers.erase(itWatcher);
+                       found = true;
+                       continue;
+               }
+               ++itWatcher;
+       }
+
+       if (Manager::m_watchers.size() == 0) {
+               RootList::const_iterator itRoot;
+               for (itRoot = m_rootlist.begin(); itRoot != m_rootlist.end(); ++itRoot) {
+                       storage_unset_state_changed_cb(itRoot->second);
+               }
+       }
+
+       if (found == false) {
+//             LogDebug("no exist" << id);
+               ThrowMsg(Commons::NotFoundException, "The " << id << "is not exist");
+       }
+}
+
+bool Manager::matchFilters(const std::string& name,
+        const struct stat& info,
+        const Api::Filesystem::FiltersMap& filters)
+{
+    Api::Filesystem::FiltersMap::const_iterator it = filters.begin();
+    for (; it != filters.end(); ++it) {
+        if (it->first == FF_NAME) {
+            if (!pcrecpp::RE(it->second).PartialMatch(name)) { return false; }
+        } else if (it->first == FF_SIZE) {
+            std::size_t size;
+            std::stringstream ss(it->second);
+            ss >> size;
+            if (!ss ||
+                (size != static_cast<size_t>(info.st_size))) { return false; }
+        } else if (it->first == FF_CREATED) {
+            std::time_t created;
+            std::stringstream ss(it->second);
+            ss >> created;
+            if (!ss || (created != info.st_ctime)) { return false; }
+        } else if (it->first == FF_MODIFIED) {
+            std::time_t modified;
+            std::stringstream ss(it->second);
+            ss >> modified;
+            if (!ss || (modified != info.st_mtime)) { return false; }
+        }
+    }
+    return true;
+}
+
+void Manager::OnRequestReceived(const EventResolvePtr& event)
+{
+    try {
+        event->setResult(Node::resolve(event->getPath()));
+    }
+    catch (const Commons::Exception& ex) 
+    {
+        LogError("Exception: " << ex.GetMessage());
+        event->setExceptionCode(ex.getCode());
+    }
+}
+
+void Manager::OnRequestReceived(const EventGetStoragePtr& event)
+{
+       try {
+
+               Api::Filesystem::StoragePropertiesPtr storage(new StorageProperties());
+
+               RootList::const_iterator it = m_rootlist.find(event->getLabel());
+               if (it == m_rootlist.end()) {
+                       Locations::const_iterator itL = m_locations.find(event->getLabel());
+                       if (itL == m_locations.end()) {
+                               ThrowMsg(Commons::NotFoundException, "Base path not available.");
+                       } else {
+                               storage->setId(0xff);
+                               storage->setLabel(event->getLabel());
+                               storage->setType(StorageProperties::TYPE_INTERNAL);
+                               storage->setState(StorageProperties::STATE_MOUNTED);
+                       }
+               } else {
+                       int id = it->second;
+
+                       storage_type_e currentType;
+                       storage_state_e currentState;
+
+                       storage_get_type(id, &currentType);
+                       storage_get_state(id, &currentState);
+
+                       storage->setId(id);
+                       storage->setLabel(event->getLabel());
+                       storage->setType((short)currentType);
+                       storage->setState((short)currentState);
+               }
+
+               event->setResult(storage);
+    } catch (const Commons::Exception& ex) 
+    {
+        event->setExceptionCode(ex.getCode());
+    }
+}
+
+void Manager::OnRequestReceived(const EventListStoragesPtr& event)
+{
+       try {
+               std::vector<Api::Filesystem::StoragePropertiesPtr> storageList;
+                       
+               storage_foreach_device_supported(Manager::getSupportedDeviceCB, &storageList);
+
+               SubRootList::const_iterator it = m_subrootlist.begin();
+               for (; it != m_subrootlist.end(); ++it) {
+                       if (it->first == LT_ROOT) 
+                               continue;
+                       if (it->first == LT_SDCARD) 
+                               continue;
+                       if (it->first == LT_USBHOST) 
+                               continue;                       
+
+                       addLocalStorage(it->second, storageList);
+               }
+               
+
+               event->setResult(storageList);
+    }  catch (const Commons::Exception& ex) 
+    {
+        event->setExceptionCode(ex.getCode());
+    }
+}
+
+void Manager::OnRequestReceived(const EventCopyPtr& event)
+{
+    Try {
+        INodePtr srcNode = Node::resolve(event->getSource());
+               LogDebug(std::hex << srcNode->getMode() << " " << std::hex << PM_USER_READ);
+        if ((srcNode->getMode() & PM_USER_READ/*PERM_READ*/) == 0) {
+            ThrowMsg(Commons::SecurityException,
+                     "Not enough permissions to read source node.");
+        }
+
+        IPathPtr src = event->getSource();
+        IPathPtr dest = event->getDestination();
+        if (!dest->isAbsolute()) {
+            dest = src->getPath() + *dest;
+        }
+  
+        INodePtr parent;
+        Try {
+            parent = Node::resolve(IPath::create(dest->getPath()));
+        }
+        Catch (Commons::Exception) 
+        {
+            event->setExceptionCode(_rethrown_exception.getCode());
+            ReThrowMsg(Commons::PlatformException,
+                       "Could not get destination's parent node.");
+        }
+
+        if (parent->getType() != NT_DIRECTORY) {
+            ThrowMsg(Commons::PlatformException,
+                     "Destination's parent node is not directory.");
+        }
+
+        std::string realSrc = src->getFullPath();
+        std::string realDest = dest->getFullPath();
+
+       if (realSrc == realDest) {
+                ThrowMsg(Commons::PlatformException,
+                        "Destination is same as source.");
+       }
+               
+
+        errno = 0;
+        struct stat info;
+        memset(&info, 0, sizeof(struct stat));
+        int status = lstat(realDest.c_str(), &info);
+        if ((status != 0) && (errno != ENOENT)) {
+            ThrowMsg(Commons::PlatformException,
+                     "No access to platform destination node.");
+        }
+               
+        if (S_ISDIR(info.st_mode) && srcNode->getType() == NT_FILE) {
+            dest->append("/" + src->getName());
+            realDest = dest->getFullPath();
+            memset(&info, 0, sizeof(struct stat));
+            status = lstat(realDest.c_str(), &info);
+            if ((status != 0) && (errno != ENOENT)) {
+                ThrowMsg(Commons::PlatformException,
+                            "No access to platform destination node.");
+            }
+        }
+
+        if (0 == status) {
+            //no owerwrite flag setted -> exception
+            if ((event->getOptions() & OPT_OVERWRITE) == 0) {
+                ThrowMsg(Commons::PlatformException, "Overwrite is not set.");
+            }
+
+            if (event->checkCancelled()) {
+                //file is not copied yet, so we can cancel it now.
+                event->setCancelAllowed(true);
+                return;
+            }
+
+            //destination exist. Need to be removed
+            Try {
+                INodePtr node = Node::resolve(dest);
+                node->remove(event->getOptions());
+            }
+            catch (const Commons::Exception& ex) 
+            {
+                LogError("Exception: " << ex.GetMessage());
+                event->setExceptionCode(ex.getCode());
+             }
+        }
+        //Destination is not exist. Start copy now.
+               LogDebug(dest->getFullPath().c_str());
+        copyElement(realSrc, realDest);
+
+        event->setResult(Node::resolve(dest));
+    }
+    catch (const Commons::Exception& ex) 
+    {
+        LogError("Exception: " << ex.GetMessage());
+        event->setExceptionCode(ex.getCode());
+    }
+    //file is copied already so we don't allow cancelling anymore.
+    event->setCancelAllowed(false);
+}
+
+void Manager::OnRequestReceived(const EventMovePtr& event)
+{
+    try {
+        IPathPtr src = event->getSource();
+        IPathPtr dest = event->getDestination();
+
+        INodePtr srcNode = Node::resolve(src);
+               LogDebug(std::hex << srcNode->getMode() << " " << std::hex << PM_USER_WRITE);
+        if ((srcNode->getMode() & PM_USER_WRITE/*PERM_WRITE*/) == 0)
+        {
+            ThrowMsg(Commons::SecurityException,
+                     "Not enough permissions to move source node.");
+        }
+
+        if (!dest->isAbsolute()) {
+            dest = src->getPath() + *dest;
+        }
+
+        if (src == dest) {
+            ThrowMsg(Commons::PlatformException,
+                     "Destination is same as source.");
+        }
+
+        INodePtr parent;
+        Try {
+            parent = Node::resolve(IPath::create(dest->getPath()));
+        }
+        Catch(Commons::Exception) 
+        {
+            LogError("Exception: " << _rethrown_exception.GetMessage());
+            ReThrowMsg(Commons::PlatformException,
+                       "Could not get destination's parent node.");
+        }
+
+        if (parent->getType() != NT_DIRECTORY) {
+            ThrowMsg(Commons::PlatformException,
+                     "Destination's parent node is not directory.");
+        }
+
+        errno = 0;
+        struct stat info;
+        memset(&info, 0, sizeof(info));
+        int status = lstat(dest->getFullPath().c_str(), &info);
+        if ((status != 0) && (errno != ENOENT)) {
+            ThrowMsg(Commons::PlatformException,
+                     "No access to platform destination node.");
+        }
+
+        LogDebug(dest->getFullPath().c_str());
+               
+        if (S_ISDIR(info.st_mode) && srcNode->getType() == NT_FILE) {
+                       dest->append("/" + src->getName());
+                       memset(&info, 0, sizeof(info));
+                       status = lstat(dest->getFullPath().c_str(), &info);
+                       if ((status != 0) && (errno != ENOENT)) {
+                   ThrowMsg(Commons::PlatformException,
+                           "No access to platform destination node.");
+                       }
+        } 
+
+               if (status == 0 && 0 == (event->getOptions() & OPT_OVERWRITE)) {
+            ThrowMsg(Commons::PlatformException, "Overwrite is not set.");
+        }
+
+        if (event->checkCancelled()) {
+            //file is not moved yet, so we can cancel it now.
+            event->setCancelAllowed(true);
+            return;
+        }
+
+        errno = 0;
+       
+        LogDebug(dest->getFullPath().c_str());
+               
+        if (0 != ::rename(src->getFullPath().c_str(), dest->getFullPath().c_str()))
+        {
+            int error = errno;
+            switch (error)
+            {
+            case EXDEV:
+                {
+                                       LogDebug(std::hex << srcNode->getMode() << " " << std::hex << PM_USER_READ);
+                    if ((srcNode->getMode() & PM_USER_READ /*PERM_READ*/) == 0)
+                    {
+                        ThrowMsg(Commons::SecurityException,
+                                 "Not enough permissions to move source node.");
+                    }
+                    if (0 == status) {
+                        //destination exist. Need to be removed
+                        Try {
+                            INodePtr node = Node::resolve(dest);
+                            node->remove(event->getOptions());
+                        }
+                        catch (const Commons::Exception& ex) 
+                        {
+                            LogError("Exception: " << ex.GetMessage());
+                            event->setExceptionCode(ex.getCode());
+                            LogError("Exception while removing dest directory");
+                        }
+                    }
+
+                    copyElement(src->getFullPath(),
+                                dest->getFullPath());
+                    //remove source files
+                    Try {
+                        INodePtr node = Node::resolve(event->getSource());
+                        node->remove(event->getOptions());
+                    }
+                    Catch(Commons::Exception) {
+                        LogError("Exception: "
+                                 << _rethrown_exception.GetMessage());
+                    }
+                    break;
+                }
+            default:
+                               // needtofix
+                ThrowMsg(Commons::PlatformException,
+                         "Error on rename: " /*<< DPL::GetErrnoString(error)*/);
+                break;
+            }
+        }
+
+        event->setResult(Node::resolve(dest));
+    }
+    catch (const Commons::Exception& ex) 
+    {
+        LogError("Exception: " << ex.GetMessage());
+        event->setExceptionCode(ex.getCode());
+    }
+
+    event->setCancelAllowed(false);
+}
+
+void Manager::OnRequestReceived(const EventCreatePtr& event)
+{
+    Try {
+    }
+    catch (const Commons::Exception& ex) 
+    {
+        LogError("Exception: " << ex.GetMessage());
+        event->setExceptionCode(ex.getCode());
+    }
+}
+
+void Manager::OnRequestReceived(const EventRemovePtr& event)
+{
+    if (!event->checkCancelled()) {
+        Try {
+            INodePtr node = Node::resolve(event->getPath());
+            node->remove(event->getOptions());
+        }
+        catch (const Commons::Exception& ex) 
+        {
+            LogError("Exception: " << ex.GetMessage());
+            event->setExceptionCode(ex.getCode());
+        }
+        event->setCancelAllowed(false);
+    } else {
+        event->setCancelAllowed(true);
+    }
+}
+
+void Manager::OnRequestReceived(const EventFindPtr& event)
+{
+    try {
+        NodeList result;
+        find(event->getPath(), event->getFilters(), result, event);
+        event->setResult(result);
+    }
+    catch (const Commons::Exception& ex) {
+        LogError("Exception: " << ex.GetMessage());
+        event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
+    }
+    event->setCancelAllowed(true);
+}
+
+void Manager::addLocalStorage(std::string label, std::vector<Api::Filesystem::StoragePropertiesPtr> &storageList)
+{
+       Api::Filesystem::StoragePropertiesPtr storage(new StorageProperties());
+       storage->setId(0xff);
+       storage->setLabel(label);
+       storage->setType(Api::Filesystem::StorageProperties::TYPE_INTERNAL);
+
+       storage_state_e currentState;
+       storage_get_state(0, &currentState);
+       storage->setState((short)currentState);
+
+       storageList.insert(storageList.end(), storage);
+}
+
+void Manager::addWidgetStorage(const std::string &key, const std::string &value)
+{
+       setupLocation(key, value.c_str());
+
+       if (key == "wgt-package")
+       {
+               m_subrootlist[LT_WGTPKG] = key;
+       }
+       else if (key == "wgt-private")
+       {
+               m_subrootlist[LT_WGTPRV] = key;
+       }
+       else if (key == "wgt-private-tmp")
+       {
+               m_subrootlist[LT_WGTPRVTMP] = key;
+       }
+}
+
+bool Manager::init()
+{
+       std::vector<Api::Filesystem::StoragePropertiesPtr> storageList;
+       storage_foreach_device_supported(Manager::getSupportedDeviceCB, &storageList);
+
+       for (size_t i = 0; i < storageList.size(); i++) {
+               m_locations[storageList[i]->getLabel()] = IPath::create(storageList[i]->getFullPath());
+               m_rootlist[storageList[i]->getLabel()] = storageList[i]->getId();
+       }
+
+       /* for Tizen */
+       setupLocation("downloads", PATH_DOWNLOADS);
+       setupLocation("documents", PATH_DOCUMENTS);
+       setupLocation("music", PATH_SOUNDS);
+       setupLocation("images", PATH_IMAGES);
+       setupLocation("videos", PATH_VIDEOS);
+
+       m_subrootlist[LT_ROOT] = "internal0";
+       m_subrootlist[LT_SDCARD] = "removable1";
+       m_subrootlist[LT_USBHOST] = "removable2";
+       m_subrootlist[LT_DOWNLOADS] = "downloads";
+       m_subrootlist[LT_DOCUMENTS] = "documents";
+       m_subrootlist[LT_SOUNDS] = "music";
+       m_subrootlist[LT_IMAGES] = "images";
+       m_subrootlist[LT_VIDEOS] = "videos";
+       return true;
+
+}
+
+void Manager::setupLocation(std::string location, const char* path)
+{
+    if (!nodeExists(path)) {
+        try {
+            makePath(path, 0755);
+        }
+        catch (const Commons::Exception& ex) 
+        {
+            LogError("Exception: " << ex.GetMessage());
+            return;
+        }
+    }
+    m_locations[location] = IPath::create(path);
+}
+
+void Manager::Watcher::getCurrentStoargeStateForWatch()
+{
+       std::string label("");
+       storage_type_e type;
+       storage_state_e state;
+       RootList::const_iterator it = m_rootlist.begin();
+       for (; it != m_rootlist.end(); ++it) {
+               label = it->first;
+               if (label.compare("") != 0) {
+                       Api::Filesystem::StoragePropertiesPtr storageItem(new StorageProperties());
+
+                       if (storage_get_type(it->second, &type) != STORAGE_ERROR_NONE) {
+                               Throw(Commons::PlatformException);
+                       }
+                       if (storage_get_state(it->second, &state) != STORAGE_ERROR_NONE) {
+                               Throw(Commons::PlatformException);
+                       }
+
+                       storageItem->setId(it->second);
+                       storageItem->setLabel(it->first);
+                       storageItem->setType(static_cast<short>(type));
+                       storageItem->setState(static_cast<short>(state));
+
+                       EventStorageStateChangedPtr event(new EventStorageStateChanged());
+
+                       event->setResult(storageItem);
+                       emit(event);
+               }
+       }
+}
+
+void Manager::Watcher::StorageStateHasChanged(int storage, storage_state_e state)
+{
+       Api::Filesystem::StoragePropertiesPtr storageItem(new StorageProperties());
+
+       std::string label;
+       storage_type_e type;
+
+       RootList::const_iterator it = m_rootlist.begin();
+       for (; it != m_rootlist.end(); ++it) {
+               if (it->second == storage) {
+                       label = it->first;
+                       break;
+               }
+       }
+
+       if (storage_get_type(storage, &type) != STORAGE_ERROR_NONE) {
+               Throw(Commons::PlatformException);
+       }
+
+       if (label.compare("") != 0) {
+               storageItem->setId(storage);
+               storageItem->setLabel(label);
+               storageItem->setType(static_cast<short>(type));
+               storageItem->setState(static_cast<short>(state));
+
+               EventStorageStateChangedPtr event(new EventStorageStateChanged());
+
+               event->setResult(storageItem);
+               emit(event);
+       }
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Filesystem/Manager.h b/src/platform/Tizen/Filesystem/Manager.h
new file mode 100755 (executable)
index 0000000..932eab4
--- /dev/null
@@ -0,0 +1,190 @@
+//
+// 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_FILESYSTEMMANAGER_H_
+#define TIZENAPIS_FILESYSTEMMANAGER_H_
+
+#include <string>
+#include <map>
+#include <vector>
+#include <cstddef>
+#include <dpl/shared_ptr.h>
+#include <API/Filesystem/IManager.h>
+#include <API/Filesystem/IPath.h>
+#include <appfw/app_storage.h>
+#include "Node.h"
+#include "Path.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+class Manager : public Api::Filesystem::IManager
+{
+  public:
+    /**
+     * Checks if file exists.
+     * @param real file path.
+     * @return true when file exists, false otherwise.
+     * @throw PlatformException If unable to validate if file exists.
+     */
+    static bool fileExists(const std::string &file);
+    static bool getSupportedDeviceCB(int storage, storage_type_e type, storage_state_e state, const char *path, void *user_data);
+    static void storageStateChangedCB(int storage, storage_state_e state, void *user_data);
+
+  public:
+    Manager();
+    ~Manager();
+
+    Api::Filesystem::IPathPtr getBasePath() const;
+
+    Api::Filesystem::StorageList getStorageList() const;
+
+    Api::Filesystem::IPathPtr getLocationPath(
+            Api::Filesystem::LocationType type) const;
+
+    Api::Filesystem::LocationPaths getLocationPaths() const;
+
+    Api::Filesystem::LocationTypes getLocations() const;
+
+    void getNode(const Api::Filesystem::EventResolvePtr& event);
+
+    void getStorage(const Api::Filesystem::EventGetStoragePtr& event);
+
+    void listStorages(const Api::Filesystem::EventListStoragesPtr& event);
+
+    std::size_t getMaxPathLength() const;
+
+    void copy(const Api::Filesystem::EventCopyPtr& event);
+
+    void move(const Api::Filesystem::EventMovePtr& event);
+
+    void create(const Api::Filesystem::EventCreatePtr& event);
+
+    void remove(const Api::Filesystem::EventRemovePtr& event);
+
+    void find(const Api::Filesystem::EventFindPtr& event);
+
+    /**
+     * Finds files in the filesystem whish match specified filters.
+     * @param path Starting path.
+     * @param filter Filters @see Api::Filesystem::FindFilters.
+     * @param result List with found files.
+     * @param event DPL event, if set then search process can be cancelled
+     * @remarks For filter FF_NAME value is treated as perl like regex pattern.
+     *          Use @Regex::escpae() if you want to treat it as normal string.
+     */
+    void find(
+            const Api::Filesystem::IPathPtr& path,
+            const Api::Filesystem::FiltersMap& filter,
+            Api::Filesystem::NodeList& result,
+            const Api::Filesystem::EventFindPtr& event =
+                Api::Filesystem::EventFindPtr(NULL));
+
+    /**
+     * @warning Operates on specified as it is - it DOES NOT take its real path.
+     *          This is because all filesystem operation will probably change
+     *          their approach to real path and will allow to refer to nodes
+     *          only by virtual roots.
+     */
+/*    bool access(const Api::Filesystem::IPathPtr& path,
+            int accessType) const;*/
+
+    void addOpenedNode(const Api::Filesystem::INodePtr& node);
+    void removeOpenedNode(const Api::Filesystem::INodePtr& node);
+    bool checkIfOpened(const Api::Filesystem::IPathPtr& path) const;
+
+    long addStorageStateChangeListener(const Api::Filesystem::EventStorageStateChangedEmitterPtr& emitter);
+    void removeStorageStateChangeListener(Api::Filesystem::EventStorageStateChangedEmitter::IdType id);
+
+public :
+       class Watcher
+       {
+               private:
+               Api::Filesystem::EventStorageStateChangedEmitterPtr m_emitter;
+
+               public:
+               Watcher(const Api::Filesystem::EventStorageStateChangedEmitterPtr& emitter) :
+                       m_emitter(emitter)
+               {
+               }
+
+               Api::Filesystem::EventStorageStateChangedEmitterPtr getEmitter()
+               {
+                       return m_emitter;
+               }
+
+               void emit(const Api::Filesystem::EventStorageStateChangedPtr& event)
+               {
+                       m_emitter->emit(event);
+               }
+               void getCurrentStoargeStateForWatch();
+               void StorageStateHasChanged(int storage, storage_state_e state);
+       };
+       typedef DPL::SharedPtr<Watcher> WatcherPtr;
+
+  protected:
+    bool matchFilters(const std::string& name,
+            const struct stat& info,
+            const Api::Filesystem::FiltersMap& filter);
+
+    void OnRequestReceived(const Api::Filesystem::EventResolvePtr& event);
+    void OnRequestReceived(const Api::Filesystem::EventGetStoragePtr& event);
+    void OnRequestReceived(const Api::Filesystem::EventListStoragesPtr& event);
+    void OnRequestReceived(const Api::Filesystem::EventCopyPtr& event);
+    void OnRequestReceived(const Api::Filesystem::EventMovePtr& event);
+    void OnRequestReceived(const Api::Filesystem::EventCreatePtr& event);
+    void OnRequestReceived(const Api::Filesystem::EventRemovePtr& event);
+    void OnRequestReceived(const Api::Filesystem::EventFindPtr& event);
+
+    void addLocalStorage(std::string label, std::vector<Api::Filesystem::StoragePropertiesPtr> &storageList);
+       void addWidgetStorage(const std::string &key, const std::string &value);
+  private:
+    typedef std::map<std::string,
+                     Api::Filesystem::IPathPtr> Locations;
+
+    typedef std::map<std::string, int> RootList;
+    typedef std::map<Api::Filesystem::LocationType, std::string> SubRootList;
+  private:
+    /**
+     * Initializes statics of Manager class.
+     * Used only internally.
+     * @return True on success, false otherwsie.
+     */
+    static bool init();
+    static void setupLocation(std::string location, const char* path);
+
+    void copyElement(const std::string &src,
+                     const std::string &dest,
+                     bool recursive = true) const;
+
+  private:
+    static RootList m_rootlist;
+    static SubRootList m_subrootlist;
+    static Locations m_locations; ///< Paths to default locations.
+    static const std::size_t m_maxPathLength; ///< Maximum path length.
+    static Api::Filesystem::NodeList m_openedNodes; ///< List of nodes that has opened streams.
+
+public:
+    typedef std::vector<WatcherPtr> watcherList;
+    static watcherList m_watchers;
+};
+} // Filesystem
+} // Platform
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEMMANAGER_H_
\ No newline at end of file
diff --git a/src/platform/Tizen/Filesystem/Node.cpp b/src/platform/Tizen/Filesystem/Node.cpp
new file mode 100755 (executable)
index 0000000..0c71eeb
--- /dev/null
@@ -0,0 +1,569 @@
+//
+// 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 "Node.h"
+
+#include <algorithm>
+#include <memory>
+#include <typeinfo>
+#include <sys/types.h>
+#include <cstdio>
+#include <unistd.h>
+#include <dirent.h>
+#include <errno.h>
+#include <pcrecpp.h>
+#include <sstream>
+
+#include <Commons/Exception.h>
+#include <API/Filesystem/PathUtils.h>
+#include <API/Filesystem/Enums.h>
+#include "Manager.h"
+#include "NodeFilterMatcher.h"
+
+using namespace TizenApis::Api::Filesystem;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+
+#define MAX_NODE_LENGTH 256
+
+Api::Filesystem::INodePtr Node::resolve(const Api::Filesystem::IPathPtr& path)
+{
+    struct stat info;
+       struct stat syminfo;
+
+    if (lstat(path->getFullPath().c_str(), &info) != 0) {
+        LogError("File: " << path->getFullPath().c_str() << " error no" <<errno);
+
+        switch (errno)
+        {
+        case EACCES:
+            ThrowMsg(Commons::PlatformException, "Node access denied");
+            break;
+        case ENOENT:
+            ThrowMsg(Commons::NotFoundException, "Node does not exist");
+            break;
+        default:
+            ThrowMsg(Commons::PlatformException, "Platform exception fail");
+        }
+    }
+
+    if (!S_ISDIR(info.st_mode) & !S_ISREG(info.st_mode) && !S_ISLNK(info.st_mode)) {
+        ThrowMsg(Commons::PlatformException,
+                 "Platform node is of unsupported type.");
+    }
+
+    NodeType type = S_ISDIR(info.st_mode) ? NT_DIRECTORY : NT_FILE;
+
+    if (S_ISLNK(info.st_mode)) {
+        syminfo = stat(path);
+               
+        type = S_ISDIR(syminfo.st_mode) ? NT_DIRECTORY : NT_FILE;
+        LogDebug(type);
+    }
+
+    NodePtr result(new Node(path, type));
+
+    return DPL::StaticPointerCast<INode>(result);
+}
+
+IPathPtr Node::getPath() const
+{
+    return IPath::create(m_path->getFullPath());
+}
+
+INodePtr Node::getChild(const IPathPtr& path)
+{
+    if (m_type != NT_DIRECTORY) {
+        ThrowMsg(Commons::PlatformException, "Not a directory.");
+    }
+    return Node::resolve(*m_path + *path);
+}
+
+NodeType Node::getType() const
+{
+    return m_type;
+}
+
+int Node::getPermissions() const
+{
+    return m_perms;
+}
+
+void Node::setPermissions(int perms)
+{
+    m_perms = perms;
+}
+
+Node::NameList Node::getChildNames() const
+{
+    if (m_type != NT_DIRECTORY) {
+        ThrowMsg(Commons::PlatformException, "Node is not directory.");
+    }
+
+    if ((m_perms & PERM_READ) == 0) {
+        ThrowMsg(Commons::SecurityException, "No permission.");
+    }
+
+    DIR* dir = opendir(m_path->getFullPath().c_str());
+    if (!dir) {
+        ThrowMsg(Commons::PlatformException,
+                 "Node has been deleted from platform.");
+    }
+
+    NameList result;
+    errno = 0;
+    struct dirent *entry = NULL;
+    while ((entry = readdir(dir))) {
+        if (!strcmp(entry->d_name, ".") || !strncmp(entry->d_name, "..", 2)) {
+            continue;
+        }
+        result.push_back(entry->d_name);
+    }
+    if (errno != 0) {
+        ThrowMsg(Commons::PlatformException, "Error while reading directory.");
+    }
+
+    if (closedir(dir) != 0) {
+        ThrowMsg(Commons::PlatformException, "Could not close platform node.");
+    }
+
+    return result;
+}
+
+NodeList Node::getChildNodes(const NodeFilterPtr& filter) const
+{
+    if (m_type != NT_DIRECTORY) {
+        ThrowMsg(Commons::PlatformException, "Node is not directory.");
+    }
+
+    if ((m_perms & PERM_READ) == 0) {
+        ThrowMsg(Commons::SecurityException, "No permission.");
+    }
+
+    DIR* dir = opendir(m_path->getFullPath().c_str());
+    if (!dir) {
+        ThrowMsg(Commons::PlatformException,
+                 "Node has been deleted from platform.");
+    }
+
+    errno = 0;
+    NodeList result;
+    struct dirent *entry = NULL;
+    while ((entry = readdir(dir))) {
+        if (!strcmp(entry->d_name, ".") || !strncmp(entry->d_name, "..", 2)) {
+            continue;
+        }
+        Try {
+            INodePtr node = Node::resolve(*m_path + entry->d_name);
+            node->setPermissions(getPermissions()); // inherit access rights
+            if (NodeFilterMatcher::match(node, filter)) {
+                result.push_back(node);
+            }
+        }
+        catch (const Commons::Exception& ex) 
+        {
+        }
+    }
+
+    if (errno != 0) {
+        ThrowMsg(Commons::PlatformException, "Error while reading directory.");
+    }
+
+    if (closedir(dir) != 0) {
+        ThrowMsg(Commons::PlatformException, "Could not close platform node.");
+    }
+
+    return result;
+}
+
+void Node::getChildNodes(const EventListNodesPtr& event)
+{
+    LogDebug("ENTER");
+    EventRequestReceiver<EventListNodes>::PostRequest(event);
+}
+
+Api::Filesystem::INodePtr Node::createChild(
+        const Api::Filesystem::IPathPtr& path,
+        NodeType type,
+        int options)
+{
+    if (m_type != NT_DIRECTORY) {
+        ThrowMsg(Commons::PlatformException, "Parent node is not a directory.");
+    }
+
+    if ((m_perms & PERM_WRITE) == 0) {
+        ThrowMsg(Commons::SecurityException, "Not enough permissions.");
+    }
+
+    IPathPtr childPath = *m_path + *path;
+    if (exists(childPath)) {
+        ThrowMsg(Commons::PlatformException, "Node already exists.");
+    }
+
+    NodePtr result;
+    switch (type) {
+    case NT_FILE:
+        result.Reset(createAsFile(childPath, options));
+        break;
+    case NT_DIRECTORY:
+        result.Reset(createAsDirectory(childPath, options));
+        break;
+    default:
+        ThrowMsg(Commons::PlatformException, "Unsupported node type.");
+    }
+    if (!!result) {
+        result->m_perms = m_perms;
+    } else {
+        ThrowMsg(Commons::PlatformException, "Node creation error");
+    }
+
+    return DPL::StaticPointerCast<INode>(result);
+}
+
+IStreamPtr Node::open(int mode)
+{
+    if (m_type == NT_DIRECTORY) {
+        ThrowMsg(Commons::PlatformException,
+                 "Cannot attach stream to directory.");
+    }
+
+    if (((mode & AM_READ) && ((m_perms & PERM_READ) == 0)) ||
+        (((mode & AM_WRITE) ||
+          (mode & AM_APPEND)) && ((m_perms & PERM_WRITE) == 0))) {
+        ThrowMsg(Commons::SecurityException, "Not enough permissions.");
+    }
+
+    DPL::Mutex::ScopedLock lock(&m_openStreamsMutex);
+    StreamPtr stream(new Stream(SharedFromThis(), mode));
+    m_openStreams.insert(stream);
+    IManager::getInstance().addOpenedNode(DPL::StaticPointerCast<INode>(
+                                              SharedFromThis()));
+    return DPL::StaticPointerCast<IStream>(stream);
+}
+
+void Node::open(const EventOpenPtr& event)
+{
+    LogDebug("ENTER");
+    EventRequestReceiver<EventOpen>::PostRequest(event);
+}
+
+void Node::remove(int options)
+{
+    switch (m_type) {
+    case NT_FILE:
+        removeAsFile(m_path);
+        break;
+    case NT_DIRECTORY:
+        removeAsDirectory(m_path, (options & OPT_RECURSIVE));
+        break;
+    }
+}
+
+std::size_t Node::getSize() const
+{
+    if (m_type == NT_DIRECTORY) {
+        ThrowMsg(Commons::PlatformException,
+                 "Getting size for directories is not supported.");
+    }
+
+    struct stat info = stat(m_path);
+    if (!S_ISREG(info.st_mode)) {
+        ThrowMsg(Commons::PlatformException,
+                 "Specified node is not a regular file.");
+    }
+
+    return info.st_size;
+}
+
+std::time_t Node::getCreated() const
+{
+    return stat(m_path).st_ctime;
+}
+
+std::time_t Node::getModified() const
+{
+    return stat(m_path).st_mtime;
+}
+
+// TODO Optimize it, maybe store a flag indicating that node is a root.
+INodePtr Node::getParent() const
+{
+    LocationPaths roots = IManager::getInstance().getLocationPaths();
+    for (LocationPaths::iterator it = roots.begin(); it != roots.end(); ++it) {
+        if (*(*it) == *m_path) {
+            return INodePtr();
+        }
+    }
+    return Node::resolve(IPath::create(m_path->getPath()));
+}
+
+int Node::getMode() const
+{
+    int result = 0;
+    struct stat info = stat(m_path);
+    if (info.st_mode & S_IRUSR) { result |= PM_USER_READ; }
+    if (info.st_mode & S_IWUSR) { result |= PM_USER_WRITE; }
+    if (info.st_mode & S_IXUSR) { result |= PM_USER_EXEC; }
+    if (info.st_mode & S_IRGRP) { result |= PM_GROUP_READ; }
+    if (info.st_mode & S_IWGRP) { result |= PM_GROUP_WRITE; }
+    if (info.st_mode & S_IXGRP) { result |= PM_GROUP_EXEC; }
+    if (info.st_mode & S_IROTH) { result |= PM_OTHER_READ; }
+    if (info.st_mode & S_IWOTH) { result |= PM_OTHER_WRITE; }
+    if (info.st_mode & S_IXOTH) { result |= PM_OTHER_EXEC; }
+    return result;
+}
+
+void Node::read(const EventReadTextPtr& event)
+{
+    LogDebug("ENTER");
+    EventRequestReceiver<EventReadText>::PostRequest(event);
+}
+
+void Node::onStreamClose(const StreamPtr& stream)
+{
+    {
+        DPL::Mutex::ScopedLock lock(&m_openStreamsMutex);
+        m_openStreams.erase(stream);
+    }
+    if (m_openStreams.empty()) {
+        IManager::getInstance().removeOpenedNode(DPL::StaticPointerCast<INode>(
+                                                     SharedFromThis()));
+    }
+}
+
+bool Node::exists(const IPathPtr& path)
+{
+    struct stat info;
+    memset(&info, 0, sizeof(struct stat));
+    int status = lstat(path->getFullPath().c_str(), &info);
+    if ((status == 0) || ((status != 0) && (errno != ENOENT))) {
+        return true;
+    }
+    return false;
+}
+
+struct stat Node::stat(const IPathPtr& path)
+{
+    struct stat result;
+    memset(&result, 0, sizeof(struct stat));
+    if (::stat(path->getFullPath().c_str(),
+                &result) != 0)
+    {
+        LogError("File: " << path->getFullPath().c_str());
+        ThrowMsg(Commons::PlatformException, "Node does not exist or no access");
+    }
+    return result;
+}
+
+Node::Node(const IPathPtr& path,
+        NodeType type) :
+    m_path(path),
+    m_type(type),
+    m_perms(PERM_NONE)
+{
+}
+
+Node* Node::createAsFile(const IPathPtr& path,
+        int /* options */)
+{
+    LogDebug("ENTER");
+    createAsFileInternal(path);
+    return new Node(path, NT_FILE);
+}
+
+void Node::createAsFileInternal(const IPathPtr& path)
+{
+    LogDebug("ENTER");
+    FILE* file = std::fopen(path->getFullPath().c_str(), "wb");
+    if (!file) {
+        ThrowMsg(Commons::PlatformException,
+                 "Platform node could not be created.");
+    }
+    std::fclose(file);
+}
+
+Node* Node::createAsDirectory(const IPathPtr& path,
+        int options)
+{
+    if (options & OPT_RECURSIVE) {
+        PathUtils::PathList parts = PathUtils::getParts(path);
+        PathUtils::PathListIterator it = parts.begin();
+        for (; it != parts.end(); ++it) {
+            if (!exists(*it)) { createAsDirectoryInternal(*it); }
+        }
+    }
+    createAsDirectoryInternal(path);
+    return new Node(path, NT_DIRECTORY);
+}
+
+void Node::createAsDirectoryInternal(const IPathPtr& path)
+{
+    if (mkdir(path->getFullPath().c_str(), S_IRWXU | S_IRWXG | S_IROTH |
+              S_IXOTH) != 0) {
+        ThrowMsg(Commons::PlatformException,
+                 "Platform node could not be created.");
+    }
+}
+
+void Node::removeAsFile(const IPathPtr& path)
+{
+    DPL::Mutex::ScopedLock lock(&m_openStreamsMutex);
+    if (!m_openStreams.empty()) {
+        ThrowMsg(Commons::PlatformException, "Node is locked for I/O.");
+    }
+    if (IManager::getInstance().checkIfOpened(path)) {
+        ThrowMsg(Commons::PlatformException, "Node is locked for I/O.");
+    }
+
+    if (unlink(path->getFullPath().c_str()) != 0) {
+        ThrowMsg(Commons::PlatformException,
+                 "Error while removing platform node.");
+    }
+}
+
+void Node::removeAsDirectory(const IPathPtr& path,
+        bool recursive)
+{
+    if (recursive) {
+        DIR* dir = opendir(path->getFullPath().c_str());
+        if (!dir) {
+            LogError("File: " << path->getFullPath().c_str());
+            ThrowMsg(Commons::PlatformException,
+                     "Node does not exist or access denied.");
+        }
+        errno = 0;
+        struct dirent *entry = NULL;
+        while ((entry = readdir(dir))) {
+            if (!strcmp(entry->d_name, ".") || !strncmp(entry->d_name, "..", 2)) {
+                continue;
+            }
+            IPathPtr subPath = *path + entry->d_name;
+            struct stat info;
+            memset(&info, 0, sizeof(struct stat));
+            if (lstat(subPath->getFullPath().c_str(), &info) == 0) {
+                Try {
+                    if (S_ISDIR(info.st_mode)) {
+                        removeAsDirectory(subPath, true);
+                    } else if (S_ISREG(info.st_mode)) {
+                        removeAsFile(subPath);
+                    }
+                }
+                catch (const Commons::Exception& ex) 
+                {
+                }
+                // TODO: Not sure if above exception should be swallowed.
+            }
+        }
+        closedir(dir);
+    }
+
+    errno = 0;
+    if (rmdir(path->getFullPath().c_str()) != 0) {
+        if (errno == EEXIST) {
+            ThrowMsg(Commons::PlatformException, "Node has child nodes.");
+        }
+        ThrowMsg(Commons::PlatformException,
+                 "Error while removing platform node.");
+    }
+}
+
+void Node::OnRequestReceived(const EventListNodesPtr& event)
+{
+    try {
+        NodeList list = event->getNode()->getChildNodes(event->getFilter());
+        event->setResult(list);
+    }
+    catch (const Commons::Exception& ex) 
+    {
+        LogError("Exception: " << ex.GetMessage());
+        event->setExceptionCode(ex.getCode());
+    }
+
+}
+
+void Node::OnRequestReceived(const EventOpenPtr& event)
+{
+    if (!event->checkCancelled()) {
+        try {
+            IStreamPtr result = open(event->getMode());
+            event->setResult(result);
+        }
+               
+        catch (const Commons::Exception& ex) 
+        {
+            LogError("Exception: " << ex.GetMessage());
+            event->setExceptionCode(ex.getCode());
+        }
+        //event can be cancelled before executing this code.
+        //when it comes here we doesn't allow it anymore
+        event->setCancelAllowed(false);
+    } else {
+        event->setCancelAllowed(true);
+    }
+}
+
+void Node::OnRequestReceived(const EventReadTextPtr& event)
+{
+    Try {
+        event->setResult(readText());
+        LogDebug("LEAVIN GRACEFULLY");
+    }
+    catch (const Commons::Exception& ex) 
+    {
+        LogError("Exception: " << ex.GetMessage());
+        event->setExceptionCode(ex.getCode());
+    }    
+    //this function doesn't change state of the platform,
+    //so we can allow to cancel it and discard results.
+    event->setCancelAllowed(true);
+}
+
+std::string Node::readText()
+{
+    if (m_type != NT_FILE) {
+        ThrowMsg(Commons::PlatformException, "Node is not a file.");
+    }
+
+    if ((m_perms & PERM_READ) == 0) {
+        ThrowMsg(Commons::SecurityException, "No permission.");
+    }
+
+    std::stringstream result;
+    DPL::SharedPtr<Stream> stream(new Stream(SharedFromThis(), AM_READ));
+    while (!stream->isEof()) {
+        result << stream->getLine();
+        if(!stream->isEof())
+            result << '\n';
+    }
+    stream->close();
+    return result.str();
+}
+
+std::string Node::toUri(int /*widgetId*/) const
+{
+    // TODO I believe moving this feature to WrtWrapper would make more sense.
+    return "file://" + m_path->getFullPath();
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Filesystem/Node.h b/src/platform/Tizen/Filesystem/Node.h
new file mode 100755 (executable)
index 0000000..cd4b673
--- /dev/null
@@ -0,0 +1,117 @@
+//
+// 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_FILESYSTEM_NODE_H_
+#define TIZENAPIS_FILESYSTEM_NODE_H_
+
+#include <ctime>
+#include <cstddef>
+#include <sys/stat.h>
+#include <set>
+#include <dpl/shared_ptr.h>
+#include <dpl/enable_shared_from_this.h>
+#include <dpl/mutex.h>
+
+#include <API/Filesystem/Enums.h>
+#include <API/Filesystem/INode.h>
+#include "Path.h"
+#include "Stream.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+class Node : public Api::Filesystem::INode,
+    public DPL::EnableSharedFromThis<Node>
+{
+  public:
+    static Api::Filesystem::INodePtr resolve(
+            const Api::Filesystem::IPathPtr& path);
+
+  public:
+    Api::Filesystem::IPathPtr getPath() const;
+    Api::Filesystem::NodeType getType() const;
+    int getPermissions() const;
+    void setPermissions(int perms);
+    std::size_t getSize() const;
+    std::time_t getCreated() const;
+    std::time_t getModified() const;
+    Api::Filesystem::INodePtr getParent() const;
+    int getMode() const;
+
+    Api::Filesystem::INodePtr getChild(const Api::Filesystem::IPathPtr& path);
+    NameList getChildNames() const;
+    Api::Filesystem::NodeList getChildNodes(
+            const Api::Filesystem::NodeFilterPtr& filter =
+                Api::Filesystem::NodeFilterPtr()) const;
+    void getChildNodes(const Api::Filesystem::EventListNodesPtr& event);
+    Api::Filesystem::INodePtr createChild(
+        const Api::Filesystem::IPathPtr & path,
+        Api::Filesystem::NodeType,
+        int options);
+    Api::Filesystem::IStreamPtr open(int mode);
+    void open(const Api::Filesystem::EventOpenPtr& event);
+    void remove(int options);
+    void read(const Api::Filesystem::EventReadTextPtr& event);
+
+    void onStreamClose(const StreamPtr& stream);
+
+  private:
+    typedef std::set<StreamPtr> StreamList;
+
+  private:
+    static bool exists(const Api::Filesystem::IPathPtr& path);
+    static struct stat stat(const Api::Filesystem::IPathPtr& path);
+
+  private:
+    Node(const Api::Filesystem::IPathPtr& path,
+            Api::Filesystem::NodeType type);
+
+    Node* createAsFile(const Api::Filesystem::IPathPtr& path,
+            int options);
+    void createAsFileInternal(const Api::Filesystem::IPathPtr& path);
+
+    Node* createAsDirectory(const Api::Filesystem::IPathPtr& path,
+            int options);
+    void createAsDirectoryInternal(const Api::Filesystem::IPathPtr& path);
+
+    void removeAsFile(const Api::Filesystem::IPathPtr& path);
+    void removeAsDirectory(const Api::Filesystem::IPathPtr& path,
+            bool recursive);
+
+    void OnRequestReceived(const Api::Filesystem::EventListNodesPtr& event);
+    void OnRequestReceived(const Api::Filesystem::EventOpenPtr& event);
+
+    void OnRequestReceived(const Api::Filesystem::EventReadTextPtr& event);
+    std::string readText();
+
+    std::string toUri(int widgetId) const;
+
+  private:
+    Api::Filesystem::IPathPtr m_path;
+    Api::Filesystem::NodeType m_type;
+    int m_perms;
+    StreamList m_openStreams;
+    mutable DPL::Mutex m_openStreamsMutex;
+};
+
+typedef DPL::SharedPtr<Node> NodePtr;
+} // Filesystem
+} // Platform
+} // TizenApis
+
+#endif /* TIZENAPIS_FILESYSTEM_NODE_H_ */
diff --git a/src/platform/Tizen/Filesystem/NodeFilterMatcher.cpp b/src/platform/Tizen/Filesystem/NodeFilterMatcher.cpp
new file mode 100755 (executable)
index 0000000..187f181
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// 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 "NodeFilterMatcher.h"
+
+#include <pcrecpp.h>
+
+using namespace TizenApis::Api::Filesystem;
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+bool NodeFilterMatcher::match(const INodePtr& value,
+        const NodeFilterPtr& filter)
+{
+    if (filter) {
+        if (!matchString(value->getPath()->getName(), filter->getName())) {
+            return false;
+        }
+
+        if (!matchRange(value->getCreated(),
+                        filter->getMinCreated(),
+                        filter->getMaxCreated())) {
+            return false;
+        }
+
+        if (!matchRange(value->getModified(),
+                        filter->getMinModified(),
+                        filter->getMaxModified())) {
+            return false;
+        }
+
+        if (!matchRange(value->getSize(),
+                        filter->getMinSize(),
+                        filter->getMaxSize())) {
+            return false;
+        }
+    }
+    return true;
+}
+
+bool NodeFilterMatcher::matchString(const std::string& value,
+        const OptionalString& filter)
+{
+    if (!filter.IsNull()) {
+        return pcrecpp::RE(*filter).PartialMatch(value);
+    }
+    return true;
+}
+
+template<typename Type>
+bool NodeFilterMatcher::matchRange(const Type& value,
+        const DPL::Optional<Type>& min,
+        const DPL::Optional<Type>& max)
+{
+    if ((!min.IsNull() && (value < *min)) ||
+        (!max.IsNull() && (value > *max))) {
+        return false;
+    }
+    return true;
+}
+} // Filesystem
+} // Platform
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/Tizen/Filesystem/NodeFilterMatcher.h b/src/platform/Tizen/Filesystem/NodeFilterMatcher.h
new file mode 100755 (executable)
index 0000000..40d7393
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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_FILESYSTEM_NODEFILTERMATCHER_H_
+#define TIZENAPIS_FILESYSTEM_NODEFILTERMATCHER_H_
+
+#include <string>
+#include <dpl/optional.h>
+#include <API/Filesystem/INode.h>
+#include <API/Filesystem/NodeFilter.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+class NodeFilterMatcher
+{
+  public:
+    static bool match(const Api::Filesystem::INodePtr& value,
+            const Api::Filesystem::NodeFilterPtr& filter);
+
+  private:
+    static bool matchString(const std::string& value,
+            const Api::Filesystem::OptionalString& filter);
+
+    template<typename Type>
+    static bool matchRange(const Type& value,
+            const DPL::Optional<Type>& min,
+            const DPL::Optional<Type>& max);
+
+  private:
+    NodeFilterMatcher();
+};
+} // Filesystem
+} // Platform
+} // TizenApis
+
+#endif // TIZENAPIS_FILESYSTEM_NODEFILTERMATCHER_H_
diff --git a/src/platform/Tizen/Filesystem/Path.cpp b/src/platform/Tizen/Filesystem/Path.cpp
new file mode 100755 (executable)
index 0000000..dde85ec
--- /dev/null
@@ -0,0 +1,123 @@
+//
+// 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 <memory>
+#include <algorithm>
+#include <iterator>
+#include <stdlib.h>
+#include <limits.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <Commons/Exception.h>
+#include <Commons/StringUtils.h>
+#include "Path.h"
+
+using namespace TizenApis::Api::Filesystem;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+const Path::SeparatorType Path::m_pathSeparator = '/';
+
+IPathPtr Path::create(const std::string& path)
+{
+    DPL::SharedPtr<Path> result(new Path());
+    result->reset(path);
+    return DPL::StaticPointerCast<IPath>(result);
+}
+
+std::string Path::getFullPath() const
+{
+    return m_fullPath;
+}
+
+std::string Path::getPath() const
+{
+    return m_path;
+}
+
+std::string Path::getName() const
+{
+    return m_name;
+}
+
+IPathPtr Path::append(const std::string& path)
+{
+    reset(m_fullPath + m_pathSeparator + path);
+    return DPL::StaticPointerCast<IPath>(SharedFromThis());
+}
+
+IPathPtr Path::append(const IPathPtr& path)
+{
+    reset(m_fullPath + m_pathSeparator + path->getFullPath());
+    return DPL::StaticPointerCast<IPath>(SharedFromThis());
+}
+
+bool Path::isAbsolute() const
+{
+    return (!m_fullPath.empty() && (m_fullPath[0] == m_pathSeparator));
+}
+
+IPath::SeparatorType Path::getSeparator()
+{
+    return m_pathSeparator;
+}
+
+bool Path::isValid(const std::string& str)
+{
+    return !str.empty();
+}
+
+IPathPtr Path::clone() const
+{
+    return Path::create(m_fullPath);
+}
+
+Path::Path()
+{
+}
+
+void Path::reset(const std::string& str)
+{
+    if (!isValid(str)) {
+        ThrowMsg(Commons::InvalidArgumentException,
+                 "Not a valid path: " + str + ".");
+    }
+
+    std::string tmp = Commons::String::unique(Commons::String::trim(
+                                                  str), m_pathSeparator);
+    std::string::size_type pos = tmp.find_last_of(m_pathSeparator);
+    if (pos == std::string::npos) {
+        m_fullPath = m_name = tmp;
+        m_path.clear();
+    } else {
+        if (0 == pos) {
+            m_fullPath = m_path = m_pathSeparator;
+        } else {
+            m_fullPath = m_path = tmp.substr(0, pos);
+            m_fullPath += m_pathSeparator;
+        }
+        m_name = tmp.substr(pos + 1);
+        m_fullPath += m_name;
+    }
+}
+} // Filesystem
+} // Platform
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/Tizen/Filesystem/Path.h b/src/platform/Tizen/Filesystem/Path.h
new file mode 100755 (executable)
index 0000000..7c88aeb
--- /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 TIZENAPIS_FILESYSTEM_PATH_H_
+#define TIZENAPIS_FILESYSTEM_PATH_H_
+
+#include <string>
+#include <vector>
+#include <dpl/enable_shared_from_this.h>
+#include <API/Filesystem/IPath.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+class Path : public Api::Filesystem::IPath,
+    public DPL::EnableSharedFromThis<Path>
+{
+  public:
+    static Api::Filesystem::IPathPtr create(const std::string& path);
+    static Api::Filesystem::IPath::SeparatorType getSeparator();
+
+  public:
+    std::string getFullPath() const;
+    std::string getPath() const;
+    std::string getName() const;
+    Api::Filesystem::IPathPtr append(const std::string& path);
+    Api::Filesystem::IPathPtr append(const Api::Filesystem::IPathPtr& path);
+    bool isAbsolute() const;
+    Api::Filesystem::IPathPtr clone() const;
+
+  private:
+    /**
+     * Checks whether specified string is a valid path.
+     * @param path String to verify.
+     * @return True when string is a valid path, false otherwise.
+     */
+    static bool isValid(const std::string& str);
+
+  private:
+    Path();
+    void reset(const std::string& str);
+
+  private:
+    static const SeparatorType m_pathSeparator; ///< Path separator.
+
+  private:
+    std::string m_fullPath; ///< Full path.
+    std::string m_path;   ///< Base path.
+    std::string m_name;   ///< Last part of the path.
+};
+} // Filesystem
+} // Platform
+} // TizenApis
+
+#endif /* TIZENAPIS_FILESYSTEM_PATH_H_ */
diff --git a/src/platform/Tizen/Filesystem/Stream.cpp b/src/platform/Tizen/Filesystem/Stream.cpp
new file mode 100755 (executable)
index 0000000..394983d
--- /dev/null
@@ -0,0 +1,308 @@
+//
+// 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 "Stream.h"
+
+#include <stdio.h>
+#include <new>
+#include <dpl/assert.h>
+#include <dpl/scoped_array.h>
+
+#include <Commons/Exception.h>
+#include "Manager.h"
+#include "Node.h"
+
+using namespace TizenApis::Api::Filesystem;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+Stream::Stream(const NodePtr& parent,
+        int mode) :
+    m_parent(parent),
+    m_mode(mode)
+{
+    Assert(m_parent && "Stream needs to have parent.");
+
+    std::ios_base::openmode mode_ = std::ios_base::binary;
+    if (mode & AM_READ) { mode_ |= std::ios_base::in; }
+    if (mode & AM_WRITE) { mode_ |= std::ios_base::out; } else if (mode &
+                                                                   AM_APPEND) {
+        mode_ |= (std::ios_base::app | std::ios_base::out);
+    }
+
+    m_stream.open(m_parent->getPath()->getFullPath().c_str(), mode_);
+    if (!m_stream) {
+        ThrowMsg(Commons::PlatformException, "Could not open stream.");
+    }
+}
+
+Stream::~Stream()
+{
+    close();
+}
+
+Api::Filesystem::IStreamPtr Stream::write(bool arg)
+{
+    return write_(arg);
+}
+
+Api::Filesystem::IStreamPtr Stream::write(unsigned char arg)
+{
+    return write_(arg);
+}
+
+Api::Filesystem::IStreamPtr Stream::write(char arg)
+{
+    return write_(arg);
+}
+
+Api::Filesystem::IStreamPtr Stream::write(int arg)
+{
+    return write_(arg);
+}
+
+Api::Filesystem::IStreamPtr Stream::write(double arg)
+{
+    return write_(arg);
+}
+
+Api::Filesystem::IStreamPtr Stream::write(const std::string& arg)
+{
+    return write_(arg);
+}
+
+Api::Filesystem::IStreamPtr Stream::read(bool& arg)
+{
+    return read_(arg);
+}
+
+Api::Filesystem::IStreamPtr Stream::read(unsigned char& arg)
+{
+    return read_(arg);
+}
+
+Api::Filesystem::IStreamPtr Stream::read(char& arg)
+{
+    return read_(arg);
+}
+
+Api::Filesystem::IStreamPtr Stream::read(int& arg)
+{
+    return read_(arg);
+}
+
+Api::Filesystem::IStreamPtr Stream::read(double& arg)
+{
+    return read_(arg);
+}
+
+Api::Filesystem::IStreamPtr Stream::read(std::string& arg)
+{
+    return read_(arg);
+}
+
+char* Stream::getChars(std::size_t num)
+{
+    checkForReading();
+
+    std::size_t maxChars = num + 1;
+    DPL::ScopedArray<char> result;
+    Try {
+        result.Reset(new char[maxChars]);
+        result[num] = '\0';
+    }
+    Catch(std::bad_alloc) {
+        ThrowMsg(Commons::PlatformException, "Couldn't allocate output buffer.");
+    }
+//    if (m_stream.get(result.Get(), maxChars).bad()) {
+    if (m_stream.read(result.Get(), num).bad()) {
+        ThrowMsg(Commons::PlatformException,
+                 "Error while reading from the stream.");
+    }
+
+    return result.Release();
+}
+
+unsigned char* Stream::getBytes(std::size_t num)
+{
+    checkForReading();
+
+    DPL::ScopedArray<char> buffer;
+    Try {
+        buffer.Reset(new char[num]);
+    }
+    Catch(std::bad_alloc) {
+        ThrowMsg(Commons::PlatformException, "Couldn't allocate output buffer.");
+    }
+    if (m_stream.read(buffer.Get(), num).bad()) {
+        ThrowMsg(Commons::PlatformException,
+                 "Error while reading from the stream.");
+    }
+
+    return static_cast<unsigned char*>(static_cast<void*>(buffer.Release()));
+}
+
+std::size_t Stream::getCount() const
+{
+    if (!isOpen()) {
+        ThrowMsg(Commons::PlatformException, "Stream is closed.");
+    }
+
+    if (!isReadable()) {
+        ThrowMsg(Commons::PlatformException, "Stream is not readable.");
+    }
+
+    return m_stream.gcount();
+}
+
+std::string Stream::getLine()
+{
+    checkForReading();
+
+    std::string result;
+    std::getline(m_stream, result);
+
+    return result;
+}
+
+bool Stream::isOpen() const
+{
+    return m_stream.is_open();
+}
+
+bool Stream::isEof() const
+{
+    return m_stream.eof();
+}
+
+void Stream::close()
+{
+    if (isOpen()) {
+        m_stream.close();
+        m_parent->onStreamClose(SharedFromThis());
+    }
+}
+
+int Stream::getMode() const
+{
+    return m_mode;
+}
+
+long Stream::getPosition() const
+{
+    return static_cast<long>(m_stream.tellg());
+}
+
+void Stream::setPosition(long position)
+{
+    if (m_stream.rdstate() & std::ios_base::eofbit) {
+        m_stream.clear();
+    }
+    if (!(m_stream.seekg(position)) || !(m_stream.seekp(position))) {
+        ThrowMsg(PlatformException, "Could not set position.");
+    }
+}
+
+long Stream::getSize() const
+{
+    std::fstream::streampos pos = m_stream.tellg();
+    if (pos == -1) {
+        return -1;
+    }
+
+    if (!m_stream.seekg(0, std::_S_end)) {
+        return -1;
+    }
+
+    long result = m_stream.tellg();
+    m_stream.seekg(pos, std::_S_beg);
+
+    return (result == -1 ? result : result + 1);
+}
+
+template<typename T>
+Api::Filesystem::IStreamPtr Stream::write_(T arg)
+{
+    checkForWriting();
+
+    if (!(m_stream << arg)) {
+        LogError("Error while writing to the stream.");
+        ThrowMsg(Commons::PlatformException,
+                 "Error while writing to the stream.");
+    }
+    m_stream.flush();
+
+    return DPL::StaticPointerCast<IStream>(SharedFromThis());
+}
+
+template<typename T>
+Api::Filesystem::IStreamPtr Stream::read_(T& arg)
+{
+    checkForReading();
+
+    if (!(m_stream >> arg)) {
+        ThrowMsg(Commons::PlatformException,
+                 "Error while reading from the stream.");
+    }
+
+    return DPL::StaticPointerCast<IStream>(SharedFromThis());
+}
+
+bool Stream::isReadable() const
+{
+    return (m_mode & AM_READ);
+}
+
+bool Stream::isWriteable() const
+{
+    return ((m_mode & AM_WRITE) || (m_mode & AM_APPEND));
+}
+
+void Stream::checkForReading() const
+{
+    if (!isOpen()) {
+        ThrowMsg(Commons::PlatformException, "Stream is closed.");
+    }
+
+    if (isEof()) {
+        ThrowMsg(Commons::PlatformException, "Stream is marked as EOF.");
+    }
+
+    if (!isReadable()) {
+        ThrowMsg(Commons::PlatformException, "Stream is not readable.");
+    }
+}
+
+void Stream::checkForWriting() const
+{
+    if (!isOpen()) {
+        LogError("Stream is closed.");
+        ThrowMsg(Commons::PlatformException, "Stream is closed.");
+    }
+
+    if (!isWriteable()) {
+        LogError("Stream is not writeable.");
+        ThrowMsg(Commons::PlatformException, "Stream is not writeable.");
+    }
+}
+} // Filesystem
+} // Platform
+} // TizenApis
\ No newline at end of file
diff --git a/src/platform/Tizen/Filesystem/Stream.h b/src/platform/Tizen/Filesystem/Stream.h
new file mode 100755 (executable)
index 0000000..2e1efac
--- /dev/null
@@ -0,0 +1,104 @@
+//
+// 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_FILESYSTEM_STREAM_H_
+#define TIZENAPIS_FILESYSTEM_STREAM_H_
+
+#include <cstddef>
+#include <fstream>
+#include <dpl/shared_ptr.h>
+#include <dpl/enable_shared_from_this.h>
+#include <API/Filesystem/IStream.h>
+#include <API/Filesystem/Enums.h>
+#include <API/Filesystem/INode.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+class Node;
+typedef DPL::SharedPtr<Node> NodePtr;
+
+class Stream : public Api::Filesystem::IStream,
+    public DPL::EnableSharedFromThis<Stream>
+{
+    friend class Node;
+
+  public:
+    ~Stream();
+
+    Api::Filesystem::IStreamPtr write(bool arg);
+    Api::Filesystem::IStreamPtr write(unsigned char arg);
+    Api::Filesystem::IStreamPtr write(char arg);
+    Api::Filesystem::IStreamPtr write(int arg);
+    Api::Filesystem::IStreamPtr write(double arg);
+    Api::Filesystem::IStreamPtr write(const std::string& arg);
+
+    Api::Filesystem::IStreamPtr read(bool& arg);
+    Api::Filesystem::IStreamPtr read(unsigned char& arg);
+    Api::Filesystem::IStreamPtr read(char& arg);
+    Api::Filesystem::IStreamPtr read(int& arg);
+    Api::Filesystem::IStreamPtr read(double& arg);
+    Api::Filesystem::IStreamPtr read(std::string& arg);
+
+    unsigned char* getBytes(std::size_t num);
+
+    std::size_t getCount() const;
+
+    char* getChars(std::size_t num);
+
+    std::string getLine();
+
+    bool isOpen() const;
+    bool isEof() const;
+
+    void close();
+
+    long getPosition() const;
+    void setPosition(long position);
+
+    int getMode() const;
+
+    long getSize() const;
+
+  private:
+    template<typename T>
+    Api::Filesystem::IStreamPtr read_(T& arg);
+    template<typename T>
+    Api::Filesystem::IStreamPtr write_(T arg);
+
+    inline bool isReadable() const;
+    inline bool isWriteable() const;
+    void checkForReading() const;
+    void checkForWriting() const;
+
+  private:
+    Stream(const NodePtr& parent,
+            int mode);
+
+  private:
+    NodePtr m_parent;
+    int m_mode;
+    mutable std::fstream m_stream;
+};
+
+typedef DPL::SharedPtr<Stream> StreamPtr;
+} // Filesystem
+} // Platform
+} // TizenApis
+
+#endif /* TIZENAPIS_FILESYSTEM_STREAM_H_ */
diff --git a/src/platform/Tizen/Filesystem/System.cpp b/src/platform/Tizen/Filesystem/System.cpp
new file mode 100755 (executable)
index 0000000..d72a0a1
--- /dev/null
@@ -0,0 +1,35 @@
+//
+// 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 "System.h"
+#include <stdlib.h>
+#include <string.h>
+#include <dpl/scoped_free.h>
+#include <Commons/Exception.h>
+#include "Command.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+void System::run(Command* cmd)
+{
+    cmd->execute();
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Filesystem/System.h b/src/platform/Tizen/Filesystem/System.h
new file mode 100755 (executable)
index 0000000..8bd6541
--- /dev/null
@@ -0,0 +1,36 @@
+//
+// 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_FILESYSTEM_SYSTEM_H_
+#define TIZENAPIS_FILESYSTEM_SYSTEM_H_
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+class Command;
+
+class System
+{
+  public:
+    static void run(Command* cmd);
+};
+}
+}
+}
+
+#endif
diff --git a/src/platform/Tizen/Filesystem/Utils.cpp b/src/platform/Tizen/Filesystem/Utils.cpp
new file mode 100755 (executable)
index 0000000..208a10d
--- /dev/null
@@ -0,0 +1,103 @@
+//
+// 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 <sys/stat.h>
+#include <cerrno>
+#include <cstring>
+#include <cstdlib>
+#include <unistd.h>
+
+#include <Commons/Exception.h>
+#include "Utils.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+namespace {
+int try_mkdir(const char* path,
+        mode_t mode)
+{
+    struct stat st;
+    int err = 0;
+
+    if (::stat(path, &st) != 0) {
+        if (::mkdir(path, mode) != 0) {
+            err = -1;
+        }
+    } else if (!S_ISDIR(st.st_mode)) {
+        errno = ENOTDIR;
+        err = -1;
+    }
+
+    return err;
+}
+
+int mkpath(const char* path,
+        mode_t mode)
+{
+    char* copy = ::strdup(path);
+    if (NULL == copy) {
+        return -1;
+    }
+
+    int err = 0;
+    char* ptr = copy;
+    char* slash = NULL;
+
+    while ((0 == err) && (NULL != (slash = ::strchr(ptr, '/')))) {
+        if (slash != ptr) {
+            *slash = '\0';
+            err = try_mkdir(copy, mode);
+            *slash = '/';
+        }
+        ptr = slash + 1;
+    }
+
+    if (0 == err) {
+        err = try_mkdir(path, mode);
+    }
+
+    ::free(copy);
+    return err;
+}
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+bool nodeExists(const std::string& path)
+{
+    struct stat info;
+    if (stat(path.c_str(), &info) == 0) {
+        if (S_ISDIR(info.st_mode)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+void makePath(const std::string& path,
+        mode_t mode)
+{
+    if (mkpath(path.c_str(), mode) == -1) {
+        ThrowMsg(Commons::PlatformException, "Couldn't create path: " << path);
+    }
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Filesystem/Utils.h b/src/platform/Tizen/Filesystem/Utils.h
new file mode 100755 (executable)
index 0000000..7420e5c
--- /dev/null
@@ -0,0 +1,36 @@
+//
+// 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_FILESYSTEM_UTILS_H_
+#define TIZENAPIS_FILESYSTEM_UTILS_H_
+
+#include <sys/types.h>
+#include <string>
+
+namespace TizenApis {
+namespace Platform {
+namespace Filesystem {
+bool nodeExists(const std::string& path);
+
+void makePath(const std::string& path,
+        mode_t mode);
+}
+}
+}
+
+#endif
diff --git a/src/platform/Tizen/Filesystem/config.cmake b/src/platform/Tizen/Filesystem/config.cmake
new file mode 100755 (executable)
index 0000000..16417dc
--- /dev/null
@@ -0,0 +1,29 @@
+get_current_path()
+
+pkg_search_module(capiappfw REQUIRED capi-appfw-application)
+pkg_search_module(pcrecpp REQUIRED libpcrecpp
+ecore REQUIRED ecore-1)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_FILESYSTEM
+  ${capiappfw_INCLUDE_DIRS}
+  ${pcrecpp_INCLUDE_DIRS}
+  ${ecore_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_FILESYSTEM
+  ${capiappfw_LIBRARIES}
+  ${pcrecpp_LIBRARIES}
+  ${ecore_LIBRARIES}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_FILESYSTEM
+  ${CURRENT_PATH}/Manager.cpp
+  ${CURRENT_PATH}/Node.cpp
+  ${CURRENT_PATH}/Path.cpp
+  ${CURRENT_PATH}/Stream.cpp
+  ${CURRENT_PATH}/NodeFilterMatcher.cpp
+  ${CURRENT_PATH}/Utils.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/Messaging/Attachment.cpp b/src/platform/Tizen/Messaging/Attachment.cpp
new file mode 100755 (executable)
index 0000000..8443472
--- /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.
+//
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <Filesystem/Manager.h>
+#include "Attachment.h"
+
+#include <API/Filesystem/INode.h>
+#include <Tizen/Filesystem/EventGetNodeData.h>
+#include <API/Filesystem/IManager.h>
+
+extern "C" {
+#include <sys/stat.h>
+#include <stdlib.h>
+}
+
+using namespace WrtDeviceApis::Commons;
+using namespace std;
+
+//--------------------------------------------------------------------------
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+Attachment::Attachment()
+{
+    LogDebug("entered");
+}
+
+Attachment::Attachment(const string& fullPath,
+        bool isVirtualPath)
+{
+    LogDebug("entered");
+    init(fullPath, isVirtualPath);
+}
+
+/*
+Attachment::Attachment(email_attachment_info_t* att)
+{
+    LogDebug("entered");
+
+    m_attachShortName = std::string(att->name);        //set shot Name
+    m_isDownloaded = att->downloaded;
+    m_attachmentID = att->attachment_id;
+       
+    LogDebug(" showname = " << m_attachShortName << " isDownloaded = " << m_isDownloaded << " attachmentID = " << m_attachmentID);
+    LogDebug("save name is = " << att->savename);
+    if ( att->savename )
+    {
+       init( att->savename, false);
+    }
+}
+*/
+Attachment::Attachment(email_attachment_data_t* att)
+{
+       LogDebug("entered");
+
+       m_attachShortName = std::string(att->attachment_name);
+       m_isDownloaded = att->save_status;
+       m_attachmentID = att->attachment_id;
+       m_isInlineAttachment =  att->inline_content_status;
+       //m_mimeType = std::string(att->attachment_mime_type);
+       LogDebug(" showname = " << m_attachShortName << " isDownloaded = " << m_isDownloaded << " attachmentID = " << m_attachmentID << "Mime= " << m_mimeType);
+       LogDebug("save name is = " << att->attachment_path << "isInlineAttachment = " << m_isInlineAttachment);
+
+       if ( att->attachment_path)
+       {
+               init( att->attachment_path, false);
+       }
+}
+
+/*
+Attachment::Attachment(const std::string& fullPath, bool isVirtualPath, 
+       const Api::Filesystem::INode& inode):
+       Api::Filesystem::INode(inode)
+{
+       LogDebug("entered , inode");
+       init(fullPath, isVirtualPath);  
+}
+*/
+
+#if 0
+Attachment::Attachment(const std::string& fullPath, bool isVirtualPath, const Api::Filesystem::INode& inode):
+       IAttachment(inode)
+{
+       LogDebug("entered , inode");
+       init(fullPath, isVirtualPath);  
+}
+#endif 
+
+std::string Attachment::getRealPath(const std::string &path) const
+{
+
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+    Try
+    {
+        Api::Filesystem::IPathPtr currentPath = Api::Filesystem::IPath::create(
+                path);
+        return currentPath->getFullPath();
+    }
+
+    Catch(WrtDeviceApis::Commons::Exception) {
+        LogError("invalid path");
+        ReThrow(WrtDeviceApis::Commons::InvalidArgumentException);
+    }
+#endif
+
+       LogDebug(" path = " << path);
+
+       return path;
+
+}
+
+}
+}
+}
+
diff --git a/src/platform/Tizen/Messaging/Attachment.h b/src/platform/Tizen/Messaging/Attachment.h
new file mode 100755 (executable)
index 0000000..ee556c4
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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_ATTACHMENT_H
+#define MESSAGE_ATTACHMENT_H
+
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <API/Messaging/IAttachment.h>
+#include <email-types.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {  
+//--------------------------------------------------------------------------
+
+class Attachment : public Api::Messaging::IAttachment
+{
+  public:
+    explicit Attachment();
+    explicit Attachment(const std::string& fullPath, bool isVirtualPath);
+//    explicit Attachment(email_attachment_info_t* att);
+    explicit Attachment(email_attachment_data_t* att);
+
+   // explicit Attachment( const TizenApis::Api::Filesystem::IPathPtr&, TizenApis::Api::Filesystem::NodeType);
+#if 0
+    explicit Attachment(const std::string& fullPath, bool isVirtualPath, 
+                       const Api::Filesystem::INode& inode);
+#endif
+  private:
+
+    virtual std::string getRealPath(const std::string &path) const;
+};
+
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/BinarySms.cpp b/src/platform/Tizen/Messaging/BinarySms.cpp
new file mode 100755 (executable)
index 0000000..005d3d6
--- /dev/null
@@ -0,0 +1,109 @@
+//
+// 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 "BinarySms.h"
+#include <dpl/log/log.h>
+
+using namespace std;
+using namespace TizenApis::Api::Messaging;
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+BinarySms::BinarySms(const string& id) :
+    IMessage(BINARYSMS, id)
+{
+    LogDebug("enter");
+
+    LogDebug("m_id=" << getIdRef());
+    LogDebug("m_msgType=" << getMessageType());
+}
+
+BinarySms::~BinarySms()
+{
+    LogDebug("enter");
+}
+
+void BinarySms::update(bool /*draftsOnly*/)
+{
+    LogDebug("updating m_id=" << getIdRef());
+}
+
+void BinarySms::readAllData()
+{
+    //#warning "TODO"
+}
+
+void BinarySms::moveToFolder(const FolderType newFolder)
+{
+    //#warning "TODO"
+}
+
+void BinarySms::moveToFolder(const string& newFolder)
+{
+    //#warning "TODO"
+}
+
+void BinarySms::copyToFolder(const FolderType newFolder)
+{
+    //#warning "TODO"
+}
+
+void BinarySms::copyToFolder(const string& newFolder)
+{
+    //#warning "TODO"
+}
+
+void BinarySms::remove()
+{
+    //#warning "TODO"
+}
+
+void BinarySms::updateIsRead()
+{
+    //#warning "TODO"
+}
+
+void BinarySms::updateMessage()
+{
+    //#warning "TODO"
+}
+
+void BinarySms::addMessageToDraft()
+{
+    //#warning "TODO"
+}
+
+void BinarySms::createSendMessage()
+{
+    //#warning "TODO"
+}
+
+int BinarySms::send()
+{
+    //#warning "TODO"
+    return -1;
+}
+
+void BinarySms::sendCancel(int handle)
+{
+    //#warning "TODO"
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/BinarySms.h b/src/platform/Tizen/Messaging/BinarySms.h
new file mode 100755 (executable)
index 0000000..cdb089b
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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 BINARY_SMS_H
+#define BINARY_SMS_H
+
+#include <API/Messaging/IBinarySms.h>
+#include <string>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+class BinarySms :
+    public Api::Messaging::IBinarySms
+{
+  public:
+
+    explicit BinarySms(const std::string& id = "");
+
+    virtual ~BinarySms();
+
+    // implementation of interface of IMessage class
+    virtual void update(bool draftsOnly = false);
+
+    virtual void readAllData();
+
+    virtual void moveToFolder(const Api::Messaging::FolderType newFolder);
+
+    virtual void moveToFolder(const std::string& newFolder);
+
+    virtual void copyToFolder(const Api::Messaging::FolderType newFolder);
+
+    virtual void copyToFolder(const std::string& newFolder);
+
+    virtual void remove();
+
+    virtual void updateIsRead();       
+
+    virtual void updateMessage();              
+
+    virtual void addMessageToDraft();
+
+    virtual void createSendMessage();  
+
+    virtual int send();
+
+    virtual void sendCancel(int handle);
+};
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/CallbackMgr.cpp b/src/platform/Tizen/Messaging/CallbackMgr.cpp
new file mode 100755 (executable)
index 0000000..667d475
--- /dev/null
@@ -0,0 +1,168 @@
+//
+// 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 "CallbackMgr.h"
+#include <dpl/log/log.h>
+#include "MsgServiceHandleMgr.h"
+#include <dpl/singleton_safe_impl.h>
+
+IMPLEMENT_SAFE_SINGLETON(TizenApis::Platform::Messaging::CallbackMgr)
+
+#include "ISendingObserver.h"
+
+extern "C" {
+#include <msg_transport.h>
+#include <msg.h>
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+CallbackMgr::CallbackMgr()
+{
+    LogInfo("enter");
+    // register callback once per process
+    if (NULL == MsgGetCommonHandle()) {
+        LogError("Unable to open handle");
+    } else {
+        if (msg_reg_sent_status_callback(MsgGetCommonHandle(), sendCallback,
+                                         static_cast<void*>(this)) !=
+            MSG_SUCCESS) {
+            LogError("callback registration error");
+        } else {
+            LogDebug("callback registred succesfully");
+        }
+    }
+}
+
+CallbackMgr::~CallbackMgr()
+{
+    LogInfo("enter");
+}
+
+msg_error_t CallbackMgr::registerAndSend(SendingFunction sendingFn,
+        const msg_struct_t& message,
+        ISendingObserver* observer)
+{
+       int tempInt = 0;
+       msg_struct_t req = NULL;
+       msg_struct_t sendOpt = NULL;
+
+       req = msg_create_struct(MSG_STRUCT_REQUEST_INFO);
+       sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+       msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
+       
+       msg_set_struct_handle(req, MSG_REQUEST_MESSAGE_HND, message);
+       msg_set_struct_handle(req, MSG_REQUEST_SENDOPT_HND, sendOpt);
+
+       DPL::Mutex::ScopedLock lock(&m_mutex);
+       msg_error_t err = (*sendingFn)(MsgGetCommonHandle(), req);
+
+       if (err == MSG_SUCCESS)
+       {
+               if (observer)
+               {
+                       msg_struct_list_s *addr_list = NULL;
+                       err = msg_get_list_handle(message, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+                       char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
+                       msg_get_str_value(addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+
+                       msg_get_int_value(req, MSG_REQUEST_REQUESTID_INT, &tempInt);
+                       m_sendRequests[tempInt] = observer;
+                       observer->setSendigRequestId(tempInt);
+                       observer->setRecipient(strNumber);
+               }
+       }
+
+    if (NULL != sendOpt)
+    {
+        msg_release_struct(&sendOpt);
+    }
+    if (NULL != req)
+    {
+        msg_release_struct(&req);
+    }
+
+    return err;
+}
+
+void CallbackMgr::unregister(int reqId)
+{
+        LogDebug(" reqId is : " << reqId);
+    DPL::Mutex::ScopedLock lock(&m_mutex);
+
+    SendReqMap::iterator it = m_sendRequests.find(reqId);
+    if (it == m_sendRequests.end()) {
+        LogWarning("No matching request found");
+        return;
+    }
+    LogInfo("Matching send request found!");
+    m_sendRequests.erase(it);
+}
+
+//void CallbackMgr::sendCallback(MSG_HANDLE_T handle,
+//        MSG_SENT_STATUS_S *sent_status,
+void CallbackMgr::sendCallback(msg_handle_t handle,
+        msg_struct_t sent_status,
+        void *user_param)
+{
+//    LogInfo(
+//        "callback received. Req id = " << sent_status->reqId <<
+//        " Status = " << (int)sent_status->status);
+    CallbackMgr* instance = static_cast<CallbackMgr*>(user_param);
+    if (!instance) {
+        LogError("Empty user data!");
+        return;
+    }
+
+    instance->call(sent_status);
+}
+
+//void CallbackMgr::call(MSG_SENT_STATUS_S *sent_status)
+void CallbackMgr::call(msg_struct_t sent_status)
+{
+       int reqId = 0;
+       int status = MSG_NETWORK_NOT_SEND;
+
+       msg_get_int_value(sent_status, MSG_SENT_STATUS_REQUESTID_INT, &reqId);
+       msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
+
+       DPL::Mutex::ScopedLock lock(&m_mutex);
+
+       //    SendReqMap::iterator it = m_sendRequests.find(sent_status->reqId);
+       if(MSG_NETWORK_SEND_SUCCESS != status 
+               && MSG_NETWORK_SEND_FAIL != status 
+               && MSG_NETWORK_SEND_TIMEOUT != status)
+       {
+               return;
+       }
+
+       SendReqMap::iterator it = m_sendRequests.find(reqId);
+       if (it == m_sendRequests.end()) {
+               LogWarning("No matching request found");
+               return;
+       }
+       LogInfo("Matching send request found!");
+               // call it
+       it->second->sendingCallback(sent_status);
+       m_sendRequests.erase(it);
+
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/CallbackMgr.h b/src/platform/Tizen/Messaging/CallbackMgr.h
new file mode 100755 (executable)
index 0000000..b610886
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// 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 CALLBACKMGR_H_
+#define CALLBACKMGR_H_
+
+#include <map>
+#include <dpl/singleton.h>
+#include <dpl/mutex.h>
+
+extern "C" {
+#include <msg_types.h>
+#include <msg_transport_types.h>
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+class ISendingObserver;
+
+/*
+ *
+ */
+class CallbackMgr
+{
+  protected:
+    CallbackMgr();
+
+//    static void sendCallback(MSG_HANDLE_T handle,
+//            MSG_SENT_STATUS_S *sent_status,
+    static void sendCallback(msg_handle_t handle,
+            msg_struct_t sent_status,
+            void *user_param);
+
+//    void call(MSG_SENT_STATUS_S *sent_status);
+    void call(msg_struct_t sent_status);
+
+  public:
+    ~CallbackMgr();
+
+//    typedef int (*SendingFunction)(MSG_HANDLE_T, MSG_REQUEST_S*);
+    typedef int (*SendingFunction)(msg_handle_t, msg_struct_t);
+
+    // register for sending callback
+    msg_error_t registerAndSend(SendingFunction sendingFn,
+//            const msg_message_t& message,
+            const msg_struct_t& message,
+            ISendingObserver* observer);
+
+    // unregister callback
+    void unregister(int reqId);
+
+  private:
+    DPL::Mutex m_mutex;
+
+    typedef std::map<msg_request_id_t, ISendingObserver*> SendReqMap;
+    SendReqMap m_sendRequests;
+};
+
+typedef DPL::Singleton<CallbackMgr> CallbackMgrSingleton;
+}
+}
+}
+#endif /* CALLBACKMGR_H_ */
diff --git a/src/platform/Tizen/Messaging/Conversation.cpp b/src/platform/Tizen/Messaging/Conversation.cpp
new file mode 100644 (file)
index 0000000..a9e8c65
--- /dev/null
@@ -0,0 +1,877 @@
+//
+// 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 "Conversation.h"
+#include <CommonsJavaScript/JSUtils.h>
+#include <Commons/Exception.h>
+#include "MsgServiceHandleMgr.h"
+#include <API/Messaging/IMessaging.h>
+#include <email-api-mail.h>
+#include <time.h>
+
+// this is msgInternalTypes
+#define MAX_THREAD_DATA_LEN    128
+
+using namespace DPL;
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+Conversation::Conversation()
+{
+
+}
+
+Conversation::Conversation(unsigned int threadId, Api::Messaging::MessageType msgType)
+{
+       LogDebug("Enter");
+       
+       if (msgType == Api::Messaging::EMAIL)
+       {
+               makeConversationFromEmailThreadId(threadId);
+       }
+       else if(msgType == Api::Messaging::EMPTY_MESSAGE)
+       {
+               // do nothing
+       }
+       else
+       {
+               makeConversationFromMsgId(threadId, msgType);
+       }
+}
+       
+Conversation::Conversation(std::string threadId, Api::Messaging::MessageType msgType)
+{
+       LogDebug("Enter");
+       bool result = FALSE;
+       std::istringstream stream(threadId);
+       
+       LogDebug("threadId : " << threadId);
+       
+       unsigned int number = 0;
+       stream >> number;
+       result = makeConversationFromMsgId(number, msgType);
+       if(result == FALSE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException,     "fail to make conversation");
+       }
+}
+
+Conversation::Conversation(unsigned int threadIndex)
+{
+       makeConversationFromThreadIndex(threadIndex);
+}
+
+//Conversation::Conversation(msg_thread_view_t msg_thread)
+Conversation::Conversation(msg_struct_t msg_thread)
+{
+       makeConversationFromThread(msg_thread);
+}
+
+//void Conversation::makeConversationFromThread(msg_thread_view_t msg_thread)
+void Conversation::makeConversationFromThread(msg_struct_t msg_thread) 
+{
+       LogDebug("Enter");
+       msg_handle_t handle = MsgGetCommonHandle();
+
+       msg_struct_list_s convViewList;
+       msg_struct_list_s *addr_list = NULL;
+
+       msg_struct_t msgInfo = NULL;
+       msg_struct_t sendOpt = NULL;
+       
+       msgInfo = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+       sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+       
+       msg_error_t err = MSG_SUCCESS;
+       unsigned int lastMsgIndex = 0;
+       char *tempString = NULL;
+       int addressCount = 0;
+       int index = 0;
+       int tempInt;
+       bool tempBool;
+       char msgData[128] = {0,};
+       m_result = true;
+       int nToCnt;
+
+       try 
+       {
+               //      get thread Id
+               msg_get_int_value(msg_thread, MSG_THREAD_ID_INT, &tempInt);
+               m_Id = tempInt;
+               
+               //      get thread type
+               msg_get_int_value(msg_thread, MSG_THREAD_MSG_TYPE_INT, &tempInt);
+               switch(tempInt)
+               {
+                       case MSG_TYPE_SMS:
+                       case MSG_TYPE_SMS_CB:
+                       case MSG_TYPE_SMS_JAVACB:
+                       case MSG_TYPE_SMS_WAPPUSH:
+                       case MSG_TYPE_SMS_MWI:
+                       case MSG_TYPE_SMS_SYNCML:
+                       case MSG_TYPE_SMS_REJECT:
+                               m_type = Api::Messaging::SMS;
+                               LogDebug("Type:SMS");
+                               break;
+                       case MSG_TYPE_MMS:
+                       case MSG_TYPE_MMS_JAVA:
+                       case MSG_TYPE_MMS_NOTI:
+                               m_type = Api::Messaging::MMS;;
+                               LogDebug("Type:MMS");
+                               break;
+               } 
+               
+               //      get thread time
+               msg_get_int_value(msg_thread, MSG_THREAD_MSG_TIME_INT, &tempInt);
+               m_time = tempInt;
+
+               //      get thread unread count
+               msg_get_int_value(msg_thread, MSG_THREAD_UNREAD_COUNT_INT, &tempInt);
+               m_unreadMessages = tempInt;
+
+               //      get thread preview
+               msg_get_str_value(msg_thread, MSG_THREAD_MSG_DATA_STR, msgData, 128);
+               tempString = msgData; // convert char to string
+
+               if (tempString != NULL)
+               {
+                       m_preview = tempString; 
+                       LogDebug("preview" << m_preview);
+               }
+
+               err = msg_get_conversation_view_list(handle, m_Id, &convViewList);
+               
+               if (err != MSG_SUCCESS)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get conversation(msg) view list fail");
+               }
+
+               //      get thread message count
+               lastMsgIndex = convViewList.nCount - 1;
+               m_messageCount = convViewList.nCount;
+
+               //      get thread read status
+               msg_get_bool_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_READ_BOOL, &tempBool);
+               m_read = tempBool;
+
+               //      get thread last message Id
+               msg_get_int_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_ID_INT, &tempInt);
+               m_lastMessageId = tempInt;
+
+               //      get thread from
+               if (msg_get_message(handle, m_lastMessageId, msgInfo, sendOpt) != MSG_SUCCESS)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get message fail");
+               }
+
+               msg_get_int_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_DIRECTION_INT, &tempInt);
+               int type = tempInt;
+
+               msg_get_list_handle(msgInfo, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+
+               nToCnt = addr_list->nCount;
+
+               if (type == MSG_DIRECTION_TYPE_MT)
+               {
+
+                       if (nToCnt > 0 && nToCnt < MAX_TO_ADDRESS_CNT )
+                       {
+                               char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
+                               msg_get_str_value(addr_list->msg_struct_info[m_lastMessageId], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                               
+                               if (strNumber[0] != '\0')
+                               {
+                                       m_from = strNumber;     // convert char to string
+                               }
+                               else
+                               {
+                                       LogDebug("address is null ");
+                               }
+                       }
+                       else 
+                       {
+                               LogDebug("address count index fail");
+                       }
+                       
+               }
+               else
+               {
+                       LogDebug("Msg direction: MO, from will be omitted");
+               }
+
+               //      get thread subject
+               char strTemp[MAX_SUBJECT_LEN] = {0};
+               msg_get_str_value(msgInfo, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
+               tempString = strTemp;
+               if (tempString != NULL)
+               {
+                       m_subject = tempString; // convert char to string
+               }
+
+               //      get thread to           
+               if (nToCnt > 0 && nToCnt < MAX_TO_ADDRESS_CNT )
+               {
+                       for (index = 0; index < nToCnt; index++)
+                       {
+                               char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
+                               msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                               tempString = strNumber;
+                               if (tempString != NULL)
+                               {
+                                       m_to.push_back(tempString);
+                               }
+                       }
+               }
+               else
+               {
+                       LogDebug("address fetch fail" << addressCount);
+               }
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               m_result = false;
+               LogError("Exception: " << ex.GetMessage());
+       }
+       
+       msg_release_list_struct(&convViewList);
+       msg_release_struct(&msgInfo);
+       msg_release_struct(&sendOpt);
+
+}
+
+
+
+// It is worth for below function to do test for fetching all conversations
+void Conversation::makeConversationFromThreadIndex(unsigned int threadIndex)
+{
+/*
+       LogDebug("Enter");
+       MSG_HANDLE_T handle = MsgGetCommonHandle();
+       MSG_LIST_S convViewList = {0, NULL};
+       MSG_THREAD_VIEW_LIST_S threadViewList = {0, NULL};
+       msg_error_t err = MSG_SUCCESS;
+       unsigned int lastMsgIndex = 0;
+       char *tempString = NULL;
+       int addressCount = 0;
+       int index = 0;
+       
+       m_result = true;
+
+       try 
+       {
+               if (msg_get_thread_view_list(handle, NULL, &threadViewList) != MSG_SUCCESS)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get thread view fail" );
+               }
+
+               if (threadViewList.nCount < 0 || threadIndex >= (unsigned int)threadViewList.nCount)
+               {
+                       LogDebug(threadIndex << ":" << threadViewList.nCount);
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "invalid index reference" );
+               }
+
+               
+               if (msg_thread_view_get_thread_id(threadViewList.msgThreadInfo[threadIndex]) >= 0)
+               {
+                       m_Id = msg_thread_view_get_thread_id(threadViewList.msgThreadInfo[threadIndex]);
+               }
+               
+               switch(msg_thread_view_get_message_type(threadViewList.msgThreadInfo[threadIndex]))
+               {
+                       case MSG_TYPE_SMS:
+                       case MSG_TYPE_SMS_CB:
+                       case MSG_TYPE_SMS_JAVACB:
+                       case MSG_TYPE_SMS_WAPPUSH:
+                       case MSG_TYPE_SMS_MWI:
+                       case MSG_TYPE_SMS_SYNCML:
+                       case MSG_TYPE_SMS_REJECT:
+                               m_type = Api::Messaging::SMS;
+                               LogDebug("Type:SMS");
+                               break;
+                       case MSG_TYPE_MMS:
+                       case MSG_TYPE_MMS_JAVA:
+                       case MSG_TYPE_MMS_NOTI:
+                               m_type = Api::Messaging::MMS;;
+                               LogDebug("Type:MMS");
+                               break;
+//                     default:
+                               // Todo email / chat
+               } 
+               
+               m_time = *(msg_thread_view_get_time(threadViewList.msgThreadInfo[threadIndex]));
+               m_unreadMessages = msg_thread_view_get_unread_cnt(threadViewList.msgThreadInfo[threadIndex]);
+               tempString = (char*)msg_thread_view_get_data(threadViewList.msgThreadInfo[threadIndex]);
+
+               if (tempString != NULL)
+               {
+                       m_preview = tempString; 
+                       LogDebug("preview" << m_preview);
+               }
+
+               
+               err = msg_get_conversation_view_list(handle, m_Id, &convViewList);
+               
+               if (err != MSG_SUCCESS)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get conversation(msg) view list fail");
+               }
+
+               lastMsgIndex = convViewList.nCount - 1;
+               m_messageCount = convViewList.nCount;
+               m_read = msg_is_read(convViewList.msgInfo[lastMsgIndex]);
+               
+               LogDebug("lastMsgIndex:" << lastMsgIndex << ",message count:" << m_messageCount << ",read" << m_read);
+
+               if (msg_get_direction_info(convViewList.msgInfo[lastMsgIndex]) == MSG_DIRECTION_TYPE_MT)
+               {
+                       addressCount = msg_get_address_count(convViewList.msgInfo[lastMsgIndex]);
+
+                       if (addressCount > 0 && addressCount < MAX_TO_ADDRESS_CNT )
+                       {
+                   tempString = (char*)msg_get_ith_address(convViewList.msgInfo[lastMsgIndex], 0);
+                               
+                               if (tempString != NULL)
+                               {
+                                       m_from = tempString;
+                               }
+                               else
+                               {
+                                       LogDebug("address is null ");
+                               }
+                       }
+                       else 
+                       {
+                               LogDebug("address count index fail");
+                       }
+                       LogDebug("from" << m_from);
+               }
+               else
+               {
+                       LogDebug("Msg direction: MO, from will be omitted");
+               }
+
+
+               tempString = (char*)msg_get_subject(convViewList.msgInfo[lastMsgIndex]);
+
+               if (tempString != NULL)
+               {
+                       m_subject = tempString;
+               }
+
+               LogDebug("subject" << m_subject);
+               
+
+               addressCount = msg_get_address_count(convViewList.msgInfo[lastMsgIndex]);
+
+
+               if (addressCount > 0 && addressCount < MAX_TO_ADDRESS_CNT )
+               {
+                       for (index = 0; index < addressCount; index++)
+                       {
+                               tempString = (char*)msg_get_ith_address(convViewList.msgInfo[lastMsgIndex], index);
+
+                               if (tempString != NULL)
+                               {
+                                       m_to.push_back(tempString);
+                               }
+                       }
+                       LogDebug("address count" << addressCount);
+               }
+               else
+               {
+                       LogDebug("address fetch fail" << addressCount);
+               }
+
+               if (msg_get_message_id(convViewList.msgInfo[lastMsgIndex]) >= 0 )
+               {
+                       m_lastMessageId = msg_get_message_id(convViewList.msgInfo[lastMsgIndex]);
+               }
+
+               LogDebug("message id" << m_lastMessageId);
+
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               m_result = false;
+               LogError("Exception: " << ex.GetMessage());
+       }
+       if (convViewList.msgInfo != NULL) 
+       {
+               msg_release_list_struct(&convViewList);
+       }
+
+       if (threadViewList.msgThreadInfo != NULL)
+       {
+               msg_release_thread_view_list(&threadViewList);
+       }
+*/
+
+}
+
+bool Conversation::makeConversationFromMsgId(unsigned int msgId, Api::Messaging::MessageType msgType)
+{
+       LogDebug("Enter");
+
+       msg_handle_t handle = MsgGetCommonHandle();
+
+       msg_struct_t msgInfo = NULL;
+       msg_struct_t sendOpt = NULL;    
+
+       msg_struct_t msg_thread = NULL;
+
+       msg_struct_list_s convViewList;
+       msg_struct_list_s *addr_list = NULL;
+       
+       msg_error_t err = MSG_SUCCESS;
+
+       int tempInt;
+       bool tempBool;
+
+       int nToCnt;
+       
+       unsigned int lastMsgIndex = 0;
+
+       char *tempString = NULL;
+       char msgData[MAX_THREAD_DATA_LEN] = {0,};
+       m_result = true;
+
+       try 
+       {
+               //      get msg from msgId
+               msgInfo = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+               sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+               
+               if (msg_get_message(handle, (msg_message_id_t)msgId, msgInfo, sendOpt) != MSG_SUCCESS)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get message fail");
+               }
+
+               // get threadId from message
+               msg_get_int_value(msgInfo, MSG_MESSAGE_THREAD_ID_INT, &tempInt);
+               m_Id = (unsigned int)tempInt;
+               LogDebug("m_Id : " << m_Id);
+
+               // get Thread
+               msg_thread = msg_create_struct(MSG_STRUCT_THREAD_INFO);
+               err = msg_get_thread(handle, m_Id, msg_thread);
+
+               //      get thread type
+               msg_get_int_value(msg_thread, MSG_THREAD_MSG_TYPE_INT, &tempInt);
+               switch(tempInt)
+               {
+                       case MSG_TYPE_SMS:
+                       case MSG_TYPE_SMS_CB:
+                       case MSG_TYPE_SMS_JAVACB:
+                       case MSG_TYPE_SMS_WAPPUSH:
+                       case MSG_TYPE_SMS_MWI:
+                       case MSG_TYPE_SMS_SYNCML:
+                       case MSG_TYPE_SMS_REJECT:
+                               m_type = Api::Messaging::SMS;
+                               LogDebug("Type:SMS");
+                               break;
+                       case MSG_TYPE_MMS:
+                       case MSG_TYPE_MMS_JAVA:
+                       case MSG_TYPE_MMS_NOTI:
+                               m_type = Api::Messaging::MMS;;
+                               LogDebug("Type:MMS");
+                               break;
+               } 
+
+               //      get thread time
+               msg_get_int_value(msg_thread, MSG_THREAD_MSG_TIME_INT, &tempInt);
+               m_time = tempInt;
+               LogDebug("m_time : " << m_time);
+
+               //      get thread unread count
+               msg_get_int_value(msg_thread, MSG_THREAD_UNREAD_COUNT_INT, &tempInt);
+               m_unreadMessages = tempInt;
+               LogDebug("m_unreadMessages : " << m_unreadMessages);
+
+               //      get thread preview
+               msg_get_str_value(msg_thread, MSG_THREAD_MSG_DATA_STR, msgData, MAX_THREAD_DATA_LEN);
+               tempString = msgData; // convert char to string
+
+               if (tempString != NULL)
+               {
+                       m_preview = tempString; 
+               }
+               LogDebug("m_preview : " << m_preview);
+
+               err = msg_get_conversation_view_list(handle, m_Id, &convViewList);
+                       
+               if (err != MSG_SUCCESS)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get conversation(msg) view list fail");
+               }
+
+               //      get thread message count
+               lastMsgIndex = convViewList.nCount - 1;
+               m_messageCount = convViewList.nCount;
+               LogDebug("m_messageCount : " << m_messageCount);
+
+               //      get thread read status
+               msg_get_bool_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_READ_BOOL, &tempBool);
+               m_read = tempBool;
+               LogDebug("m_read : " << m_read);
+
+               //      get thread last message Id
+               msg_get_int_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_ID_INT, &tempInt);
+               m_lastMessageId = tempInt;
+               LogDebug("m_lastMessageId : " << m_lastMessageId);
+
+               //      get thread from
+               if (msg_get_message(handle, m_lastMessageId, msgInfo, sendOpt) != MSG_SUCCESS)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get message fail");
+               }
+
+               msg_get_int_value(convViewList.msg_struct_info[lastMsgIndex], MSG_CONV_MSG_DIRECTION_INT, &tempInt);
+               int type = tempInt;
+               LogDebug("direction : " << type);
+
+               msg_get_list_handle(msgInfo, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+               nToCnt = addr_list->nCount;
+
+               if (type == MSG_DIRECTION_TYPE_MT)
+               {
+                       
+                       if (nToCnt > 0 && nToCnt < MAX_TO_ADDRESS_CNT )
+                       {
+                               char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
+                               msg_get_str_value(addr_list->msg_struct_info[nToCnt-1], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+
+                               if (strNumber[0] != '\0')
+                               {
+                                       m_from = strNumber; // convert char to string
+                               }
+                               else
+                               {
+                                       LogDebug("address is null ");
+                               }
+                       }               
+                       else 
+                       {
+                               LogDebug("address count index fail");
+                       }
+
+               }
+               else
+               {
+                       LogDebug("Msg direction: MO, from will be omitted");
+                       //      get thread to           
+                       if (nToCnt > 0 && nToCnt < MAX_TO_ADDRESS_CNT )
+                       {
+                               for (int index = 0; index < nToCnt; index++)
+                               {
+                                       char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
+                                       msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                                       tempString = strNumber;
+                                       if (tempString != NULL)
+                                       {
+                                               LogDebug("m_to : " << tempString);
+                                               m_to.push_back(tempString);
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               LogDebug("address fetch fail");
+                       }
+               }
+
+               //      get thread subject
+               char strTemp[MAX_SUBJECT_LEN] = {0};
+               msg_get_str_value(msgInfo, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
+               tempString = strTemp;
+               if (tempString != NULL)
+               {
+                       m_subject = tempString; // convert char to string
+               }               
+               LogDebug("m_subject : " << m_subject);
+               
+       }
+       catch (const WrtDeviceApis::Commons::UnknownException& ex)
+       {
+               m_result = false;
+               LogError("Exception: " << ex.GetMessage());
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex)
+       {
+               m_result = false;
+               LogError("Exception: " << ex.GetMessage());
+       }
+
+       msg_release_list_struct(&convViewList);
+       msg_release_struct(&msgInfo);
+       msg_release_struct(&sendOpt);
+       msg_release_struct(&msg_thread);
+       
+       return m_result;
+}
+
+bool Conversation::makeConversationFromEmailThreadId(unsigned int emailTreadId)
+{
+       LogDebug("Enter");
+       
+       email_mail_list_item_t *resultMail = NULL;
+       email_mail_list_item_t *mailList = NULL;
+       int index = 0;
+       int count = 0;
+
+       email_mail_data_t* mailData = NULL;
+       m_result = true;
+
+       try 
+       {
+               // Todo : will be re-implemented as using email_get_thread_information_ex 
+               if(email_get_thread_information_ex(emailTreadId, &resultMail) != EMAIL_ERROR_NONE) 
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get email thread fail" );
+               }
+
+               if (!resultMail)
+               {
+                       return NULL;
+               }
+
+               //get mail data
+               if (email_get_mail_data(resultMail->mail_id,&mailData) != EMAIL_ERROR_NONE)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get email data fail" );
+               }
+       
+               // account Id
+               m_unreadMessages = 0;
+
+               LogDebug("start email_get_mail_list");
+               if (email_get_mail_list(mailData->account_id, 0, emailTreadId, 0, resultMail->thread_item_count, 
+                       EMAIL_SORT_DATETIME_HIGH, &mailList, &count) != EMAIL_ERROR_NONE)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get email data fail" );
+               }
+               LogDebug("end email_get_mail_list");
+               
+               // unread msg count
+               for (index = 0; index < count; index++)
+               {
+                       if (mailList[index].flags_seen_field)
+                       {
+                               m_unreadMessages++;
+                       }
+                       LogDebug(mailList[index].flags_seen_field);
+               }
+               
+               // message count
+               m_messageCount = resultMail->thread_item_count;
+               // id
+               m_Id = emailTreadId;
+               // type
+               m_type = Api::Messaging::EMAIL;
+
+               // time horrible split 
+               // 2011 11 08 00 35 45
+
+               m_time = resultMail->date_time;
+       
+               // read
+               m_read = (bool)resultMail->flags_seen_field;
+
+               // from
+               if (resultMail->full_address_from[0] != '\0')
+               {
+                       m_from = resultMail->full_address_from;
+                       LogDebug(m_from);
+               }
+
+               // subject
+               if (resultMail->subject[0] != '\0')
+               {
+                       m_subject = resultMail->subject;
+                       LogDebug(m_subject);            
+               }
+
+               if (mailData->full_address_to != NULL)
+               {
+                       LogDebug("Header To " << mailData->full_address_to);
+                       m_to.push_back(mailData->full_address_to);
+               }
+
+               if (mailData->full_address_bcc != NULL)
+               {
+                       LogDebug("Header Bcc " << mailData->full_address_bcc);
+                       m_bcc.push_back(mailData->full_address_bcc);
+               }
+
+               if (mailData->full_address_cc != NULL)
+               {
+                       LogDebug("Header CC " << mailData->full_address_cc);
+                       m_cc.push_back(mailData->full_address_cc);
+               }
+               
+               m_lastMessageId = resultMail->mail_id;
+               LogDebug(m_lastMessageId);              
+               m_result = true;
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               m_result = false;
+               LogError("Exception: " << ex.GetMessage());
+       }
+
+       if (mailData != NULL)
+       {
+               email_free_mail_data(&mailData , 1);
+       }
+       
+       if (resultMail != NULL)
+       {
+               free(resultMail);
+       }
+
+       return m_result;
+
+}
+Conversation::~Conversation()
+{
+}
+
+#if 0
+// setter
+void Conversation::setId(unsigned int id)
+{
+       m_id = id;
+}
+void Conversation::setType(unsigned short type)
+{
+       m_type = type;
+}
+void Conversation::setTime(time_t time)
+{
+       m_time = time;
+}
+void Conversation::setMessageCount(unsigned long messageCount)
+{
+       m_messageCount = messageCount;
+}
+void Conversation::setUnreadMessages(unsigned long unreadMessages)
+{
+       m_unreadMessages = unreadMessages;
+}
+void Conversation::setPreview(unsigned long preview)
+{
+       m_preview = preview;
+}
+void Conversation::setRead(bool read)
+{
+       m_read = read;
+}
+void Conversation::setFrom(std::string from)
+{
+       m_from = from;
+}
+void Conversation::setTo(std::vector<std::string> to)
+{
+       m_to = to;
+}
+void Conversation::setCC(std::vector<std::string> cc)
+{
+       m_cc = cc;
+}
+void Conversation::setBCC(std::vector<std::string> bcc)
+{
+       m_bcc = bcc;
+}
+void Conversation::setLastMessageId(unsigned int id)
+{
+       m_lastMessageId = id;
+}
+#endif
+
+void Conversation::setId(const unsigned int id)
+{
+       m_Id = id;
+}
+
+// getter
+unsigned int Conversation::getId()
+{
+       return m_Id;
+}
+unsigned short Conversation::getType()
+{
+       return m_type;
+}
+time_t Conversation::getTime()
+{
+       return m_time;
+}
+unsigned long Conversation::getMessageCount()
+{
+       return m_messageCount;
+}
+unsigned long Conversation::getUnreadMessages()
+{
+       return m_unreadMessages;
+}
+std::string Conversation::getPreview()
+{
+       return m_preview;
+}
+
+std::string Conversation::getSubject()
+{
+       return m_subject;
+}
+
+
+bool Conversation::getRead()
+{
+       return m_read;
+}
+std::string Conversation::getFrom()
+{
+       return m_from;
+}
+std::vector<std::string> Conversation::getTo()
+{
+       return m_to;
+}
+std::vector<std::string> Conversation::getCC()
+{
+       return m_cc;
+}
+std::vector<std::string> Conversation::getBCC()
+{
+       return m_bcc;
+}
+unsigned int Conversation::getLastMessageId()
+{
+       return m_lastMessageId;
+}
+
+bool Conversation::getResult()
+{
+       return m_result;
+}
+
+}
+}
+}
+
diff --git a/src/platform/Tizen/Messaging/Conversation.h b/src/platform/Tizen/Messaging/Conversation.h
new file mode 100755 (executable)
index 0000000..0e3751a
--- /dev/null
@@ -0,0 +1,111 @@
+//
+// 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 CONVERSATION_H
+#define CONVERSATION_H
+
+#include <dpl/shared_ptr.h>
+#include <map>
+#include <string>
+#include <vector>
+#include <API/Messaging/IConversation.h>
+
+extern "C" {
+#include <msg_storage.h>
+#include <msg.h>
+#include <msg_transport.h>
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+
+class Conversation : public Api::Messaging::IConversation
+{
+public:        
+       Conversation();
+       Conversation(unsigned int threadId, Api::Messaging::MessageType msgType);
+       Conversation(unsigned int threadIndex); // msg thread with index of all thread view for test
+       Conversation(std::string msgId, Api::Messaging::MessageType msgType);
+//     Conversation(msg_thread_view_t msg_thread); // msg thread with thread data
+       Conversation(msg_struct_t msg_thread); // msg thread with thread data   
+
+       ~Conversation();
+
+       // getter
+       unsigned int getId();
+       unsigned short getType();
+       time_t getTime();
+       unsigned long getMessageCount();
+       unsigned long getUnreadMessages();
+       std::string getPreview();
+       std::string getSubject();
+       bool getRead();
+       std::string getFrom();
+       std::vector<std::string> getTo();
+       std::vector<std::string> getCC();
+       std::vector<std::string> getBCC();
+       unsigned int getLastMessageId();
+       bool getResult();
+       bool makeConversationFromMsgId(unsigned int msgId, Api::Messaging::MessageType msgType);
+       void makeConversationFromThreadIndex(unsigned int threadIndex);
+//     void makeConversationFromThread(msg_thread_view_t msg_thread);
+       void makeConversationFromThread(msg_struct_t msg_thread);
+       bool makeConversationFromEmailThreadId(unsigned int emailTreadId);
+       void setId(const unsigned int id);
+#if 0
+       // setter
+       void setId(unsigned int id);
+       void setType(unsigned short type);
+       void setTime(time_t* time);
+       void setMessageCount(unsigned long messageCount);
+       void setUnreadMessages(unsigned long unreadMessages);
+       void setPreview(unsigned long unreadMessages);
+       void setRead(bool read);
+       void setFrom(std::string from);
+       void setTo(std::vector<std::string> to);
+       void setCC(std::vector<std::string> cc);
+       void setBCC(std::vector<std::string> bcc);
+       void setLastMessageId(unsigned int id);
+#endif 
+
+       
+private:       
+       unsigned int m_Id;
+       unsigned short int m_type;
+       time_t m_time;
+       unsigned long m_messageCount;
+       unsigned long m_unreadMessages;
+       std::string m_preview;
+       bool m_read;
+       std::string m_from;
+       std::string m_subject;
+       std::vector<std::string> m_to;
+       std::vector<std::string> m_cc;
+       std::vector<std::string> m_bcc;
+       unsigned int m_lastMessageId;
+       bool m_result;
+
+};
+}
+}
+}
+
+#endif
+
diff --git a/src/platform/Tizen/Messaging/ConversationQueryGenerator.cpp b/src/platform/Tizen/Messaging/ConversationQueryGenerator.cpp
new file mode 100755 (executable)
index 0000000..1f8f336
--- /dev/null
@@ -0,0 +1,134 @@
+//
+// 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 "ConversationQueryGenerator.h"
+#include "API/Messaging/ConversationFilterValidatorFactory.h"
+
+#include <dpl/log/log.h>
+#include <API/Messaging/log.h>
+
+namespace TizenApis {
+
+       namespace Platform {
+               namespace Messaging {
+
+                       const std::string ConversationQueryGenerator::QUERY_PREFIX_SMS   = "WHERE (B.SMS_CNT > 0 OR B.MMS_CNT > 0) AND A.CONV_ID = B.CONV_ID AND (B.MAIN_TYPE=1) AND (";
+                       const std::string ConversationQueryGenerator::QUERY_PREFIX_MMS   = "WHERE (B.SMS_CNT > 0 OR B.MMS_CNT > 0 ) AND A.CONV_ID = B.CONV_ID AND (B.MAIN_TYPE=2) AND (";                       
+                       const std::string ConversationQueryGenerator::QUERY_PREFIX_EMAIL = "WHERE ";
+                       const std::string ConversationQueryGenerator::QUERY_SUFFIX_SMS_MMS   = ") ";
+                       const std::string ConversationQueryGenerator::QUERY_SUFFIX_EMAIL = "";
+
+                       const std::string ConversationQueryGenerator::STRING_DIRECTION = "B.MSG_DIRECTION";
+
+               ConversationQueryGenerator::ConversationQueryGenerator():MessageQueryGenerator() {
+               }
+
+               ConversationQueryGenerator::ConversationQueryGenerator(const Api::Tizen::SortModePtr& sortMode,
+                               const long limit, const long offset):MessageQueryGenerator(sortMode, limit, offset){
+
+               }
+
+               ConversationQueryGenerator::ConversationQueryGenerator(const Api::Tizen::SortModePtr& sortMode,
+                               const long limit, const long offset, const int type):MessageQueryGenerator(sortMode, limit, offset, type){
+
+               }
+               
+
+               ConversationQueryGenerator::~ConversationQueryGenerator() {
+               }
+
+               void ConversationQueryGenerator::setSmsMmsAttributeMap(){
+                       LogDebug("<<<");
+                       attributeMap.clear();
+
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       ConversationFilterValidatorFactory::ATTRIBUTE_ID,          "A.ADDRESS_ID"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       ConversationFilterValidatorFactory::ATTRIBUTE_TYPE,          "B.MAIN_TYPE"));                   
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       ConversationFilterValidatorFactory::ATTRIBUTE_TIMESTAMP,       "B.DISPLAY_TIME"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       ConversationFilterValidatorFactory::ATTRIBUTE_FROM,            "A.ADDRESS_VAL"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       ConversationFilterValidatorFactory::ATTRIBUTE_TO,              "A.ADDRESS_VAL"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW,            "B.MSG_TEXT"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT,    "B.SMS_CNT+B.MMS_CNT"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       ConversationFilterValidatorFactory::ATTRIBUTE_UNREAD_MESSAGES,    "B.UNREAD_CNT"));
+
+                       LogDebug(">>>");
+               }
+
+               std::string ConversationQueryGenerator::getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value){
+                       std::string retClause;
+                       std::string emfAttributeName = convertToEmfAttrName(attrName);
+
+                       if(getMode() == MODE_SMS || getMode() == MODE_MMS){
+                               if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT)==0){
+                                       retClause = emfAttributeName + "=" + value->toString();
+                                       return retClause;
+                               }else if(attrName.compare(ConversationFilterValidatorFactory::ATTRIBUTE_PREVIEW)==0){
+                                       retClause = emfAttributeName + " LIKE '" + value->toString() + "'";
+                                       return retClause;
+                               }
+                       }
+
+                       retClause = MessageQueryGenerator::getMatchExactlyClause(attrName, value);
+                       return retClause;
+               }
+
+               std::string ConversationQueryGenerator::getQueryPrefix(){
+                       if(getMode() == MODE_EMAIL){
+                               return ConversationQueryGenerator::QUERY_PREFIX_EMAIL;
+                       }else if(getMode() == MODE_SMS){
+                               return ConversationQueryGenerator::QUERY_PREFIX_SMS;
+                       }else if(getMode() == MODE_MMS){
+                               return ConversationQueryGenerator::QUERY_PREFIX_MMS;
+                       }else{
+                               MsgLogError("invalid mode:" << getMode());
+                               Throw(WrtDeviceApis::Commons::UnknownException);
+                       }
+               }
+
+               std::string ConversationQueryGenerator::getQuerySuffix(){
+                       if(getMode() == MODE_EMAIL){
+                               return ConversationQueryGenerator::QUERY_SUFFIX_EMAIL;
+                       }else if(getMode() == MODE_SMS || getMode() == MODE_MMS){
+                               return ConversationQueryGenerator::QUERY_SUFFIX_SMS_MMS;
+                       }else{
+                               MsgLogError("invalid mode:" << getMode());
+                               Throw(WrtDeviceApis::Commons::UnknownException);
+                       }
+               }
+
+               std::string ConversationQueryGenerator::getMessageDirectionString(){
+                                       return ConversationQueryGenerator::STRING_DIRECTION;
+                               }
+
+               }       //Messaging
+       }// namespace Platform
+}      //namespace TizenApis
diff --git a/src/platform/Tizen/Messaging/ConversationQueryGenerator.h b/src/platform/Tizen/Messaging/ConversationQueryGenerator.h
new file mode 100755 (executable)
index 0000000..42b8b7a
--- /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 CONVERSATIONQUERYGENERATOR_H_
+#define CONVERSATIONQUERYGENERATOR_H_
+
+#include <API/Filter/IFilterVisitor.h>
+#include "MessageQueryGenerator.h"
+
+namespace TizenApis {
+
+       namespace Platform {
+               namespace Messaging {
+
+
+               class ConversationQueryGenerator : public MessageQueryGenerator{
+
+                       public:
+                               ConversationQueryGenerator();
+                               ConversationQueryGenerator(const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset);
+                               ConversationQueryGenerator(const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset, const int type);
+
+                               virtual ~ConversationQueryGenerator();
+
+                       protected:
+                               virtual void setSmsMmsAttributeMap();
+                               virtual std::string getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+
+                               virtual std::string getQueryPrefix();
+                               virtual std::string getQuerySuffix();
+
+                               virtual std::string getMessageDirectionString();
+
+                       private:
+                               static const std::string QUERY_PREFIX_SMS;
+                               static const std::string QUERY_PREFIX_MMS;                              
+                               static const std::string QUERY_PREFIX_EMAIL;
+                               static const std::string QUERY_SUFFIX_SMS_MMS;
+                               static const std::string QUERY_SUFFIX_EMAIL;
+
+                               static const std::string STRING_DIRECTION;
+               };
+
+               typedef DPL::SharedPtr<ConversationQueryGenerator> ConversationQueryGeneratorPtr;
+
+               }       //Messaging
+       }       //Platform
+}      //TizenApis
+
+#endif /* CONVERSATIONQUERYGENERATOR_H_ */
diff --git a/src/platform/Tizen/Messaging/Email.cpp b/src/platform/Tizen/Messaging/Email.cpp
new file mode 100755 (executable)
index 0000000..37924d9
--- /dev/null
@@ -0,0 +1,1357 @@
+//
+// 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 <unistd.h>
+#include <cstdio>
+#include <cstddef>
+#include <cstdlib>
+#include <ctime>
+#include <email-types.h>
+#include <email-api.h>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <dpl/scoped_fclose.h>
+#include <dpl/scoped_ptr.h>
+#include <Commons/Exception.h>
+#include <Commons/StringUtils.h>
+#include <API/Messaging/MessageFactory.h>
+#include "Messaging.h"
+#include "Email.h"
+#include "EmailService.h"
+#include "EmailUtils.h"
+#include "EmailConverter.h"
+#include "MailSender.h"
+#include "MailSync.h"
+#include "MessagingService.h"
+#include "MessagingServiceManager.h"
+#include "Attachment.h"
+
+#define LOG_ENTER LogDebug("---> ENTER");
+#define LOG_EXIT LogDebug("---> EXIT");
+
+using namespace std;
+using namespace TizenApis::Api::Messaging;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+namespace {
+const char* COMMAND_NAME = "/bin/cp";
+const char* COMMAND_SWITCH_RECURSIVE = "-r";
+//const char* COMMAND_SWITCH_FORCE = "-f";
+}
+
+Email::Email(const string& id) :
+       IMessage(EMAIL, id) {
+       LOG_ENTER
+
+       try {
+               if (getIdRef().empty()) {
+                       //exception
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, " message id is invalid");
+               }
+                               
+               reload();
+       } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
+               LogError("Exception: " << ex.DumpToString());
+       }
+
+       LOG_EXIT
+}
+
+Email::Email(const std::string& id, int accountId) :
+       IMessage(EMAIL, id) 
+{
+       LOG_ENTER
+
+       try {
+               if (getIdRef().empty()) {
+                       //exception
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, " message id is invalid");
+               }
+               
+               LogDebug("Account ID = " << accountId);
+               m_accountId = accountId;
+               reload();
+               
+       } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
+               LogError("Exception: " << ex.DumpToString());
+       }
+
+
+       LOG_EXIT
+}
+
+Email::Email(Api::Messaging::EmailAccountInfo& account) : IMessage(EMAIL)
+{
+    LOG_ENTER
+
+    try {
+         if (getIdRef().empty()) {
+               create(account);
+         }
+       
+        reload();
+    }
+    catch (const WrtDeviceApis::Commons::PlatformException& ex) {
+        LogError("Exception: " << ex.DumpToString());
+    }
+
+    LOG_EXIT
+}
+
+Email::Email(const Api::Messaging::FolderType folder) : IMessage(EMAIL)
+{
+    LOG_ENTER
+
+    try {
+         if (folder == Api::Messaging::TEMP_FOLDER) {
+               create();
+         }
+          else {
+             ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Folder Type is miss-matched");
+          }
+    }
+    catch (const WrtDeviceApis::Commons::PlatformException& ex) {
+        LogError("Exception: " << ex.DumpToString());
+    }
+
+    LOG_EXIT
+}
+
+Email::~Email()
+{
+    LogDebug("ENTER");
+}
+
+int Email::send()
+{
+    LOG_ENTER
+
+    update();
+
+    int handle = MailSender::getInstance().send(
+        Api::Messaging::MessageFactory::convertToEmail(SharedFromThis())
+        );
+
+    return handle;
+    LOG_EXIT
+}
+
+void Email::sendCancel(int handle)
+{
+    LOG_ENTER
+
+    MailSender::getInstance().cancel(handle);
+
+    LOG_EXIT
+}
+
+int Email::downloadBody()
+{
+       LOG_ENTER
+       return MailSync::getInstance().downloadBody( Api::Messaging::MessageFactory::convertToEmail(SharedFromThis()) );
+       LOG_EXIT
+}
+
+void Email::downloadBodyCancel( int handle)
+{      
+       return MailSync::getInstance().cancelDownloadBody(handle);
+}
+
+int Email::downloadAttachment( const Api::Messaging::IAttachmentPtr& attachment)
+{
+       LOG_ENTER
+       return MailSync::getInstance().downloadAttachment( Api::Messaging::MessageFactory::convertToEmail(SharedFromThis()), attachment );
+       LOG_EXIT
+}
+
+void Email::downloadAttachmentCancel( int handle)
+{      
+       LOG_ENTER
+       return MailSync::getInstance().cancelDownloadAttachment(handle);
+       LOG_EXIT
+}
+
+void Email::update(bool draftsOnly)
+{
+    LOG_ENTER
+
+    DPL::Mutex::ScopedLock mx(&m_updateMutex);
+
+    if (!m_mail) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
+    }
+
+    updateSubject();
+    updateBody();
+    updateRecipients();
+    updateAttachments();
+    updateReadStatus();
+
+    email_attachment_data_t* attachment=NULL;
+    int attachmentCount = 0;
+    int error = email_get_attachment_data_list( m_mail->mail_id, &attachment, &attachmentCount);
+    if (EMAIL_ERROR_NONE != error) {
+         LogWarning("Nothing to update or error. [" << error << "]");
+    }
+
+    error = email_update_mail( m_mail.Get(), attachment, attachmentCount, NULL, 0);
+    if (EMAIL_ERROR_NONE != error) {
+         LogWarning("Nothing to update or error. [" << error << "]");
+    }
+
+    if (attachment)
+    {
+           error = email_free_attachment_data(&attachment, attachmentCount);
+           if (EMAIL_ERROR_NONE != error) {
+                 LogWarning("Nothing to update or error. [" << error << "]");
+           }
+    }
+#if 0  
+    LogDebug("getCurrentFolder() = " << getCurrentFolder() );
+    if (!draftsOnly || (getCurrentFolder() == Api::Messaging::DRAFTBOX)) {
+               
+        updateBody();
+        updateSubject();
+        updateRecipients();
+        updateAttachments();
+        updatePriority();
+               
+    } else {
+        LogWarning("Updating only read status. Folder: " << getCurrentFolder());
+    }
+    updateReadStatus();
+
+    //get attachment
+    email_attachment_data_t* attachment=NULL;
+    int attachmentCount = 0;
+    int error = email_get_attachment_data_list( m_mail->mail_id, &attachment, &attachmentCount);
+    if (EMAIL_ERROR_NONE != error) {
+         LogWarning("Nothing to update or error. [" << error << "]");
+    }
+
+    error = email_update_mail( m_mail.Get(), attachment, attachmentCount, NULL, 0);
+    if (EMAIL_ERROR_NONE != error) {
+         LogWarning("Nothing to update or error. [" << error << "]");
+    }
+#endif
+
+    LOG_EXIT
+}
+
+int Email::getAccountID()
+{
+       LOG_ENTER
+
+       if ( m_mail )
+               return m_mail->account_id;
+       else
+               return -1;
+       
+       LOG_EXIT
+}
+
+int Email::getUID()
+{
+       LOG_ENTER
+       
+       if (m_mail)
+               return m_mail->mail_id;
+       else
+               return -1;
+
+       LOG_EXIT
+}
+
+int Email::isBodyDownloaded()
+{
+
+       if (m_mail)
+               if ( m_mail->body_download_status == 1 )        // 1 is fully downloaded body.
+                       return true;
+               else
+                       return false;
+       else
+               return false;
+
+}
+
+bool Email::hasAttachment()
+{      
+       std::size_t attachmentSize = getAttachmentsCount();
+       if ( attachmentSize > 0)
+                       return true;
+               else
+                       return false;
+}
+
+void Email::readAllData()
+{
+    reload();
+}
+
+void Email::moveToFolder(const FolderType newFolder)
+{
+/*
+
+    LOG_ENTER
+    moveToFolder(EmailConverter::toMailboxType(newFolder));
+    LOG_EXIT
+*/
+}
+
+void Email::moveToFolder(const string& newFolder)
+{
+/*
+       Assert(m_mail && "mail is NULL.");
+       
+       update();
+
+       int accountId = m_mail->account_id;
+       int mailId = getIntId();
+
+       emf_mailbox_t* mailbox = EmailService::alloc<emf_mailbox_t>();
+       mailbox->account_id = accountId;
+       mailbox->name = (NULL != newFolder.c_str() ? strdup(newFolder.c_str()) : NULL);
+
+       int error = email_move_mail_to_mailbox(&mailId, 1, mailbox);
+       if (EMF_ERROR_NONE != error) {
+       ThrowMsg(
+           WrtDeviceApis::Commons::PlatformException,
+           "Couldn't move mail to folder: " << newFolder << ". [" <<
+           error << "]");
+       }
+       
+       error = email_free_mailbox(&mailbox, 1);        //free
+       if (EMF_ERROR_NONE != error) {
+           LogError("Failed to destroy mailbox: " << error);
+       }
+*/
+}
+
+void Email::copyToFolder(const FolderType newFolder)
+{
+    LOG_ENTER
+
+    copyToFolder(EmailConverter::toMailboxName(newFolder));
+
+    LOG_EXIT
+}
+
+void Email::copyToFolder(const string& newFolder)
+{
+       LOG_ENTER
+/*             
+       Assert(m_mail && "mail is NULL.");
+
+       update();
+
+       int accountId = m_mail->account_id;
+       ScopedMail mail(EmailService::cloneMail(m_mail.Get())); //clone
+       mail->mailbox_name = (NULL != newFolder.c_str() ? strdup(newFolder.c_str()) : NULL);
+       mail->account_id = accountId;
+       
+       //Attachment
+       email_attachment_data_t* attachment = NULL;
+       int attachmentCount = 0;
+       int error = email_get_attachment_data_list( m_mail->mail_id, &attachment, &attachmentCount);    //get Attachment list
+       if (EMAIL_ERROR_NONE != error) {
+               ThrowMsg( WrtDeviceApis::Commons::PlatformException,
+                       "Couldn't get attachment list: " << newFolder << ". [" << error << "]");
+       }
+       
+       int mailId = EmailService::addMail( mail.Get(), attachment );
+       if (0 == mailId) {
+           ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Cloned mail didn't get new id.");
+       }
+*/     
+    LOG_EXIT
+}
+
+void Email::remove()
+{
+    EmailService::deleteMail(m_accountId, getIntId());
+}
+
+#if 0
+void Email::create()
+{
+    LOG_ENTER
+
+    EmailAccountInfo account = IMessaging::getInstance().getCurrentEmailAccount();
+    m_accountId = account.getIntId();
+    ScopedMail mail(EmailService::createMail(account));
+    ScopedMailbox mailbox(
+        EmailService::getMailboxByType(account.getIntId(),
+                                       EMAIL_MAILBOX_TYPE_DRAFT)
+        );
+    setId(convertId(EmailService::addMailToMailbox(mail.Get(), mailbox.Get())));
+    setFolderType(Api::Messaging::DRAFTBOX);
+    setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
+
+    LOG_EXIT
+}
+#endif
+
+void Email::create()
+{
+    LOG_ENTER
+    setFolderType(Api::Messaging::TEMP_FOLDER);
+    setMessageStatus(Api::Messaging::MESSAGE_STATUS_CREATED);
+    LOG_EXIT
+}
+
+void Email::create( Api::Messaging::EmailAccountInfo& account )
+{
+       LOG_ENTER
+
+       m_accountId = account.getIntId();
+       //MailSender::getInstance();
+       
+      LogDebug("account ID : " << m_accountId);
+       ScopedMail mail(EmailService::createMailData(account));
+       
+       setEmailAccount(account);       //save account
+
+       mail->mailbox_type = EMAIL_MAILBOX_TYPE_DRAFT;
+       
+       setId(convertId(EmailService::addMail(mail.Get(), NULL)));
+       setFolderType(Api::Messaging::DRAFTBOX);
+       setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
+       
+    LOG_EXIT
+}
+
+void Email::reload()
+{
+    LOG_ENTER
+
+    LogDebug("mail ID :" << getIntId());
+    m_mail.Reset(EmailService::readMail(getIntId()));          //reset Mail Data
+
+    readHeader();
+    readBody();
+    readInfo();
+
+    //if (m_mail->head) { readHeader(); }
+    //if (m_mail->body) { readBody(); }
+    //if (m_mail->info) { readInfo(); }
+
+    //m_mailbox.Reset(EmailService::getMailboxByMailId(m_accountId, getIntId()) );
+    //setFolderType(EmailConverter::toFolderType(m_mailbox->mailbox_type));
+    
+    setFolderType(EmailConverter::toFolderType(m_mail->mailbox_type));
+
+    LOG_EXIT
+}
+
+void Email::readHeader()
+{
+    LOG_ENTER
+
+    Assert(m_mail && "Header is NULL.");
+
+    if (m_mail->subject) {
+        setSubject(m_mail->subject);
+    }
+
+    if (m_mail->full_address_to) {
+        appendToRecipients(EmailUtils::stripAddressLine(m_mail->full_address_to));
+    }
+
+    if (m_mail->full_address_cc) {
+        appendCcRecipients(EmailUtils::stripAddressLine(m_mail->full_address_cc));
+    }
+
+    if (m_mail->full_address_bcc) {
+        appendBccRecipients(EmailUtils::stripAddressLine(m_mail->full_address_bcc));
+    }
+
+#if 1
+    struct tm *t = NULL;
+    t = localtime(&m_mail->date_time);
+    struct tm timeinfo;
+       memset(&timeinfo, 0, sizeof(timeinfo));
+    memcpy(t, &timeinfo, sizeof(struct tm));
+    setDateTime(timeinfo); 
+
+#else
+
+       if (m_mail->datetime[0] != '\0')
+       {
+               char buf[MAX_DATETIME_STRING_LENGTH];
+               char *targetBuf = m_mail->datetime;
+               struct tm timeinfo;
+
+               memset(buf, 0x00, sizeof(buf));
+               targetBuf += snprintf(buf, sizeof(buf), "%.4s", targetBuf);
+               timeinfo.tm_year = atoi(buf) - 1900;
+
+               memset(buf, 0x00, sizeof(buf));
+               targetBuf += snprintf(buf, sizeof(buf), "%.2s", targetBuf);
+               timeinfo.tm_mon =  atoi(buf) - 1;
+
+               memset(buf, 0x00, sizeof(buf));
+               targetBuf += snprintf(buf, sizeof(buf), "%.2s", targetBuf);
+               timeinfo.tm_mday =      atoi(buf);
+
+               memset(buf, 0x00, sizeof(buf));
+               targetBuf += snprintf(buf, sizeof(buf), "%.2s", targetBuf);
+               timeinfo.tm_hour = atoi(buf);
+
+               memset(buf, 0x00, sizeof(buf));
+               targetBuf += snprintf(buf, sizeof(buf), "%.2s", targetBuf);
+               timeinfo.tm_min = atoi(buf);
+
+               memset(buf, 0x00, sizeof(buf));
+               targetBuf += snprintf(buf, sizeof(buf), "%.2s", targetBuf);
+               timeinfo.tm_sec = atoi(buf);
+               
+               setDateTime(timeinfo);
+       }
+
+#endif
+       
+#if 0
+    time_t rawtime;
+    time(&rawtime);
+    struct tm tmpTime = *(localtime(&rawtime));
+
+    tmpTime.tm_year = m_mail->head->datetime.year;
+    tmpTime.tm_mon = m_mail->head->datetime.month;
+    tmpTime.tm_mday = m_mail->head->datetime.day;
+    tmpTime.tm_hour = m_mail->head->datetime.hour;
+    tmpTime.tm_min = m_mail->head->datetime.minute;
+    tmpTime.tm_sec = m_mail->head->datetime.second;
+    mktime(&tmpTime);
+    setDateTime(tmpTime);
+#endif
+
+    if (m_mail->full_address_from) {
+        Recipients from;
+        from.setRecipients(m_mail->full_address_from);
+        setSourceAddress(from);
+        setSourceAddressValidity(true); //not needed to update in platform
+    }
+
+    LOG_EXIT
+}
+
+void Email::readBody() {
+       LOG_ENTER
+
+       Assert(m_mail && "Body is NULL.");
+
+       if (m_mail->file_path_plain) {
+               DPL::ScopedFClose file(::fopen(m_mail->file_path_plain, "r"));
+               if (!file) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                       "Cannot read body file: " << m_mail->file_path_plain);
+               }
+               fseek(file.Get(), 0, SEEK_END);
+               long int size = ftell(file.Get());
+
+               if (size < 0) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                       "Cannot read plain body size");
+               }
+               
+               fseek(file.Get(), 0, SEEK_SET);
+               DPL::ScopedPtr<char> data(new char[size + 1]);
+               memset(data.Get(), 0, size + 1);
+        TEMP_FAILURE_RETRY(fread(data.Get(), 1, size, file.Get()) &&
+                           ferror(file.Get()) == 0 ? -1 : 0);
+               setBody(data.Get());
+       }
+
+       //html body.
+       if (m_mail->file_path_html) {
+               DPL::ScopedFClose file(::fopen(m_mail->file_path_html, "r")); //auto close, scopedFClose
+               if (!file) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                       "Cannot read html body file: " << m_mail->file_path_html);
+               }
+
+               fseek(file.Get(), 0, SEEK_END);
+               long int size = ftell(file.Get());
+
+               if (size < 0) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                       "Cannot read html body size");
+               }
+               
+               fseek(file.Get(), 0, SEEK_SET);
+               DPL::ScopedPtr<char> data(new char[size + 1]);
+               memset(data.Get(), 0, size + 1);
+        TEMP_FAILURE_RETRY(fread(data.Get(), 1, size, file.Get()) &&
+                           ferror(file.Get()) == 0 ? -1 : 0);
+               setHtmlBody(data.Get()); //setHtmlBody declarate in Email Calss.
+       }
+
+       //Attachment
+       //email_attachment_info_t* attachment = NULL;
+       email_attachment_data_t* attachment = NULL;
+       int attachmentCount = 0;
+       
+       int error = email_get_attachment_data_list( m_mail->mail_id, &attachment, &attachmentCount);    //get Attachment list
+       if (EMAIL_ERROR_NONE != error) {
+               ThrowMsg( WrtDeviceApis::Commons::PlatformException, "Couldn't get attachment list: ");
+       }
+       
+       if ( attachment && attachmentCount > 0)
+       {
+               LogDebug("reading attachments , attahcment count = " << attachmentCount);
+               int i = 0;
+
+               for ( i = 0; i < attachmentCount; i++)
+               {
+                       Try {
+                               LogDebug("attachment ID :" << attachment[i].attachment_id << " name :" << attachment[i].attachment_name << " download :" << attachment[i].save_status << "savefile :" << attachment[i].attachment_path);
+                               LogDebug("attachment inline status :" << attachment[i].inline_content_status);
+                               IAttachmentPtr tmpAtt(new Attachment());
+                               if (attachment[i].attachment_path)
+                                       tmpAtt->init(attachment[i].attachment_path, false);
+                       
+                               if (tmpAtt)
+                               {
+                                       tmpAtt->rename(std::string(attachment[i].attachment_name));
+                                       tmpAtt->setAttachmentID(attachment[i].attachment_id);
+                                       tmpAtt->setDownloaded(attachment[i].save_status);
+                                       tmpAtt->setIsInlineAttachment((bool)attachment[i].inline_content_status);
+                                       tmpAtt->setNth(i+1);
+                                       LogDebug(" setNth(i+1) : " << i+1);
+                                       if(attachment[i].inline_content_status == 0)
+                                       {
+                                               appendAttachment(tmpAtt);
+                                       }
+                                       else
+                                       {
+                                               appendInlineAttachment(tmpAtt);
+                                       }
+                               }
+                               LogDebug(" append Attachment complete");
+
+                       
+                       }
+                       catch ( const WrtDeviceApis::Commons::Exception& ex )
+                       {
+                               LogError("Error while trying to append attachment " << attachment[i].attachment_path << ": " << ex.DumpToString());
+                       }
+                       
+               }
+
+       }
+       
+       if (attachment)
+       {
+               error = email_free_attachment_data(&attachment, attachmentCount);
+               if (EMAIL_ERROR_NONE != error) {
+                       ThrowMsg( WrtDeviceApis::Commons::PlatformException, " attachment_data free error! ");
+               }
+       }
+
+       LOG_EXIT
+}
+
+void Email::readInfo()
+{
+    LOG_ENTER
+
+    Assert(m_mail && "Info is NULL.");
+
+    setReadStatus(m_mail->flags_seen_field == 1);
+
+    m_accountId = m_mail->account_id;
+
+    setPriority( EmailConverter::toMessagePriority( m_mail->priority ) );
+    setSize(m_mail->mail_size);
+
+    LOG_EXIT
+}
+
+void Email::updateBody()
+{
+    LOG_ENTER
+
+       int error = 0;
+
+    if (isBodyValid()) { return; }
+
+    if (!m_mail) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
+    }
+    if (!m_mail->file_path_plain) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Plain Body is NULL.");
+    }
+// fix email empty plain text
+/*
+    if (!m_mail->file_path_html) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Html Body file is NULL.");
+    }
+*/
+    if((!m_mail->file_path_html) && (strlen(getHtmlBody().c_str()) > 0) ) {
+        char buf[] = "XXXXXX";
+        mode_t mask = umask(S_IWGRP | S_IWOTH);
+        error = mkstemp(buf);
+        umask(mask);
+        std::string htmlFile = buf;
+        htmlFile = EmailUtils::TMP_DIR_PREFIX+htmlFile;
+        LogDebug("htmlFile : " << htmlFile);
+
+//        std::string htmlFile = tmpnam(NULL);
+        FILE* f = fopen(htmlFile.c_str(), "w");
+        if (NULL != f) {
+               fclose(f);
+               }
+        m_mail->file_path_html = strdup(htmlFile.c_str());
+
+        if(!m_mail->file_path_html)
+        {
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Html Body file is NULL.");
+        }
+    }
+   
+    //update plain body.
+    FILE* f = fopen(m_mail->file_path_plain, "w");
+    if (NULL != f) {
+        fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
+        fclose(f);
+    }
+    else
+    {
+         LogDebug("Plain Body file is NULL.");
+         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Plain Body File Open Error");
+    }
+
+    //update html body (if exist)
+    if (m_mail->file_path_html)
+    {
+        //update html body
+        f = fopen(m_mail->file_path_html, "w");
+        if (NULL != f) {
+            //fprintf(f, getHtmlBody().c_str());
+            fwrite(getHtmlBody().c_str(), strlen(getHtmlBody().c_str()), 1, f);
+            fclose(f);
+        }
+    }
+    // fix email empty plain text      
+/*
+    else
+    {
+               LogDebug("Html Body file is NULL.");
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "HTML Body File Open Error");
+    }
+*/
+    m_mail->body_download_status = true;
+       
+    setBodyValidity(true);
+
+    LOG_EXIT
+}
+
+void Email::updateSubject()
+{
+    LOG_ENTER
+
+    if (isSubjectValid()) { return; }
+
+    LogDebug("update subject, msgId=" << getIdRef());
+
+    if (!m_mail) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail not allocated.");
+    }
+    
+    m_mail->subject = String::strdup(getSubjectRef());
+    setSubjectValidity(true);
+
+    LOG_EXIT
+}
+
+void Email::updateReadStatus()
+{
+    LOG_ENTER
+
+    if (isReadStatusValid()) { return; }
+
+    LogDebug("update read, msgId=" << getIdRef());
+
+    if (!m_mail) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail not allocated.");
+    }
+
+    m_mail->flags_seen_field = isRead();
+    setReadStatusValidity(true);
+
+    LOG_EXIT
+}
+
+void Email::updateIsRead()
+{
+    LOG_ENTER
+    if (isReadChangeStatusValid()) {
+        // do not update if not changed
+        return;
+    }
+
+    EmailService::updateSeenFlag(getAccountID(), getIntId(), isReadChangeStatus());
+    setisReadChangeStatusValidity(true);
+    LOG_EXIT
+}
+
+void Email::updateMessage()
+{
+       LOG_ENTER
+       email_meeting_request_t *meeting_req = NULL;
+
+       DPL::Mutex::ScopedLock mx(&m_updateMutex);
+
+       if (!m_mail) {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
+       }
+
+       LogDebug("getCurrentFolder() = " << getCurrentFolder() );
+
+       if(getCurrentFolder() == Api::Messaging::DRAFTBOX)
+       {
+               updateBody();
+               updateSubject();
+               updateRecipients();
+               updateFrom();
+               updateAttachments();
+               updatePriority();
+       }
+       updateReadStatus();
+
+       //get attachment
+       email_attachment_data_t* attachment=NULL;
+       int attachmentCount = 0;
+       int error = email_get_attachment_data_list( m_mail->mail_id, &attachment, &attachmentCount);
+       if (EMAIL_ERROR_NONE != error) {
+               LogWarning("email_get_attachment_data_list [" << error << "]");
+       }
+
+       error = email_get_meeting_request(m_mail->mail_id, &meeting_req);
+       if (EMAIL_ERROR_NONE != error) {
+               LogWarning("email_get_meeting_request() failed [%d]\n" << error);
+       }
+
+       error = email_update_mail( m_mail.Get(), attachment, attachmentCount, meeting_req, 0);
+       if (EMAIL_ERROR_NONE != error) {
+               LogWarning("Nothing to update or error. [" << error << "]");
+       }
+
+       if(meeting_req) {
+               email_free_meeting_request(&meeting_req, 1);
+       }
+
+       if (attachment)
+       {
+               error = email_free_attachment_data(&attachment, attachmentCount);
+               if (EMAIL_ERROR_NONE != error) {
+                       LogWarning("email_free_attachment_data [" << error << "]");
+               }               
+       }
+
+       LOG_EXIT
+}
+
+void Email::createSendMessage()
+{
+       LOG_ENTER
+
+    MailSender::getInstance(); //start email service
+
+       if ( getUID() > 0 && m_accountId > 0)
+       {       
+               update();
+       }
+       else
+       {       
+       DPL::Mutex::ScopedLock mx(&m_updateMutex);
+               
+               Api::Messaging::EmailAccountInfo account = getEmailAccount();
+               m_accountId = account.getIntId();       //set account ID
+               LogDebug("account ID : " << m_accountId);
+               m_mail.Reset(EmailService::createMailData(account));
+               
+               updateSubject();
+               updateBody();
+               updateRecipients();
+               updatePriority();
+               updateReadStatus();
+               
+               email_mailbox_t* mailbox;
+               int error = email_get_mailbox_by_mailbox_type(m_accountId, EMAIL_MAILBOX_TYPE_OUTBOX, &mailbox );
+               if (EMAIL_ERROR_NONE != error) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                       "Couldn't add message to mailbox. [" << error << "]");
+               }
+               if ( mailbox->mailbox_id )
+                       m_mail->mailbox_id = mailbox->mailbox_id;
+               LogDebug("mail MailBox id :" << m_mail->mailbox_id);
+
+               error = email_add_mail(m_mail.Get(), NULL, 0, NULL, 0);
+               if (EMAIL_ERROR_NONE != error) {
+                      ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                               "Couldn't add message to mailbox. [" << error << "]");
+               }
+               
+               LogDebug("message id =" << m_mail->mail_id);
+               
+               setId(convertId(m_mail->mail_id));
+               setFolderType(OUTBOX);
+               setMessageStatus(Api::Messaging::MESSAGE_STATUS_SENDING);
+
+               updateAttachments();    //update Attachment.
+               
+               error = email_free_mailbox(&mailbox, 1);
+               if (EMAIL_ERROR_NONE != error) {
+                       LogError("Failed to destroy mailbox: " << error);
+               }
+
+               LogDebug("m_mail->from" << m_mail->full_address_from);
+
+               email_mail_data_t* result = NULL;
+
+               error = email_get_mail_data(m_mail->mail_id, &result);
+               if (EMAIL_ERROR_NONE != error) {
+                   ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                            "Couldn't find message " << m_mail->mail_id << ". [" << error << "]");
+               }
+
+               if (m_mail->file_path_plain)
+                       free(m_mail->file_path_plain);
+               m_mail->file_path_plain = strdup(result->file_path_plain);
+               
+               if ( m_mail->file_path_html)
+               {
+                       free(m_mail->file_path_html);
+               }
+
+               if(result->file_path_html)
+               {
+                       m_mail->file_path_html = strdup(result->file_path_html);
+               }
+               
+               error = email_free_mail_data(&result, 1);
+               if (EMAIL_ERROR_NONE != error) {
+                   ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                            "Couldn't find message " << m_mail->mail_id << ". [" << error << "]");
+               }               
+
+    }
+       LOG_EXIT
+}
+
+
+void Email::addMessageToDraft()
+{
+    LOG_ENTER
+
+    MailSender::getInstance(); //start email service
+       
+    if ( getUID() > 0 && m_accountId > 0)
+    {  
+               update();
+    }
+    else
+    {  
+               DPL::Mutex::ScopedLock mx(&m_updateMutex);
+               
+               Api::Messaging::EmailAccountInfo account = getEmailAccount();
+               m_accountId = account.getIntId();       //set account ID
+               LogDebug("account ID : " << m_accountId);
+               m_mail.Reset(EmailService::createMailData(account));
+               
+               updateSubject();
+               updateBody();
+               updateRecipients();
+               updatePriority();
+               updateReadStatus();
+               
+               email_mailbox_t* mailbox;
+               int error = email_get_mailbox_by_mailbox_type(m_accountId, EMAIL_MAILBOX_TYPE_DRAFT, &mailbox );
+               if (EMAIL_ERROR_NONE != error) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                       "Couldn't add message to mailbox. [" << error << "]");
+               }
+               if ( mailbox->mailbox_id )
+                       m_mail->mailbox_id = mailbox->mailbox_id;
+               LogDebug("mail MailBox id :" << m_mail->mailbox_id);
+
+               error = email_add_mail(m_mail.Get(), NULL, 0, NULL, 0);
+               if (EMAIL_ERROR_NONE != error) {
+                      ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                               "Couldn't add message to mailbox. [" << error << "]");
+               }
+               
+               LogDebug("message id =" << m_mail->mail_id);
+               
+               setId(convertId(m_mail->mail_id));
+               setFolderType(DRAFTBOX);
+               setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
+
+               updateAttachments();    //update Attachment.
+               
+               error = email_free_mailbox(&mailbox, 1);
+               if (EMAIL_ERROR_NONE != error) {
+                       LogError("Failed to destroy mailbox: " << error);
+               }
+
+               LogDebug("m_mail->from" << m_mail->full_address_from);
+
+               email_mail_data_t* result = NULL;
+
+               error = email_get_mail_data(m_mail->mail_id, &result);
+               if (EMAIL_ERROR_NONE != error) {
+                   ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                            "Couldn't find message " << m_mail->mail_id << ". [" << error << "]");
+               }
+
+               if (m_mail->file_path_plain)
+                       free(m_mail->file_path_plain);
+               m_mail->file_path_plain = strdup(result->file_path_plain);
+               
+               if ( m_mail->file_path_html)
+               {
+                       free(m_mail->file_path_html);
+               }
+
+               if(result->file_path_html)
+               {
+                       m_mail->file_path_html = strdup(result->file_path_html);
+               }
+               
+               error = email_free_mail_data(&result, 1);
+               if (EMAIL_ERROR_NONE != error) {
+                   ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                            "Couldn't find message " << m_mail->mail_id << ". [" << error << "]");
+               }               
+
+    }
+
+    LOG_EXIT
+}
+
+void Email::updateRecipients()
+{
+    LOG_ENTER
+
+    if (getToValidity() && getCcValidity() && getBccValidity()) { return; }
+
+    if (!m_mail) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
+    }
+
+    if (!getToValidity()) {
+        std::string addressLine = EmailUtils::formatAddressLine(getToRecipients());
+        if (m_mail->full_address_to) {
+            free(m_mail->full_address_to);
+        }
+        m_mail->full_address_to = String::strdup(addressLine);
+        setToValidity(true);
+    }
+
+    if (!getCcValidity()) {
+        std::string addressLine = EmailUtils::formatAddressLine(getCcRecipients());
+        if (m_mail->full_address_cc) {
+            free(m_mail->full_address_cc);
+        }
+        m_mail->full_address_cc = String::strdup(addressLine);
+        setCcValidity(true);
+    }
+
+    if (!getBccValidity()) {
+        std::string addressLine = EmailUtils::formatAddressLine(getBccRecipients());
+        if (m_mail->full_address_bcc) {
+            free(m_mail->full_address_bcc);
+        }
+        m_mail->full_address_bcc = String::strdup(addressLine);
+        setBccValidity(true);
+    }
+
+    LOG_EXIT
+}
+
+void Email::updateFrom()
+{
+    LOG_ENTER
+
+    if (getFromValidity()) { return; }
+
+    if (!m_mail) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
+    }
+
+    m_mail->account_id = m_accountId;
+
+    if (m_mail->full_address_from) {
+          free(m_mail->full_address_from);
+    }
+    m_mail->full_address_from = String::strdup(getFrom());
+
+    setFromValidity(true);
+
+    LOG_EXIT
+}
+
+void Email::updateAttachments()
+{
+    LOG_ENTER
+
+    if (isAttachmentsValid()) { return; }
+
+    if (!m_mail) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail is NULL.");
+    }
+
+    email_attachment_data_t* attachment = NULL;
+    int attachmentCount = 0;           
+    email_mailbox_t* mailBox = NULL;
+    int error = 0;
+
+    Try {
+                //clean attachment
+               LogDebug("update attachments, msgId=" << getIdRef());
+               error = email_get_attachment_data_list( m_mail->mail_id, &attachment, &attachmentCount);        //get Attachment list
+               if (EMAIL_ERROR_NONE != error) {
+                       ThrowMsg( WrtDeviceApis::Commons::PlatformException, "Couldn't get attachment list: ");
+               }
+               error = email_get_mailbox_by_mailbox_id(m_mail->mailbox_id, &mailBox);
+               
+               if (EMAIL_ERROR_NONE != error) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                       "Couldn't get mailbox. [" << error << "]");
+               }       
+                
+               if ( attachmentCount > 0 )
+               {
+                       int i = 0;
+                       std::stringstream stream;
+                       for ( i = 0; i < attachmentCount; i++)
+                       {
+                               LogDebug("file name:" << attachment[i].attachment_name << " file path :" << attachment[i].attachment_path);
+                               int attachmentId = attachment[i].attachment_id;
+
+                               int error = email_delete_attachment(attachmentId);
+                               if (EMAIL_ERROR_NONE != error) {
+                                   LogDebug("Error Num = " << error);
+                                   ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                            "Error while adding attachment. [" << error << "]");
+                               }
+                               stream.str("");
+                       }
+
+                       if ( attachment )
+                       {
+                               error = email_free_attachment_data(&attachment, attachmentCount);
+                               if (EMAIL_ERROR_NONE != error) {
+                                       ThrowMsg( WrtDeviceApis::Commons::PlatformException, " attachment_data free error! ");
+                               }
+                       }
+
+               }
+               
+               //set Attachment
+               std::size_t attachmentSize = getAttachmentsCount();
+               std::size_t inlineAttachmentSize = getInlineAttachmentsCount();
+               
+               LogDebug("update attachments, attachmentSize=" << attachmentSize);
+               if (attachmentSize > 0)
+               {
+                       email_attachment_data_t* attachment_info = NULL;
+                       for (std::size_t i = 0; i < attachmentSize; ++i)
+                       {
+                               IAttachmentPtr att = getAttachment(i);
+                               if (!att) {
+                                       continue;
+                               }
+
+                               //copy attachment file
+                               std::stringstream cp_cmd;
+                               char buf[] = "/tmp/XXXXXX";
+                               mode_t mask = umask(S_IWGRP | S_IWOTH);
+                               error = mkstemp(buf);
+                               umask(mask);
+
+                               cp_cmd << COMMAND_NAME;
+                               cp_cmd << " " << COMMAND_SWITCH_RECURSIVE;
+                               cp_cmd << " \"" << att->getFullPath() << "\"";
+                               cp_cmd << " \"" << buf << "\"";
+
+                               attachment_info = EmailService::alloc<email_attachment_data_t>();                                       
+                               attachment_info->attachment_name = String::strdup(att->getShortName());
+                               attachment_info->attachment_path = String::strdup( buf );
+                               attachment_info->save_status = true;
+                               attachment_info->inline_content_status = att->getIsInlineAttachment();
+
+                               LogDebug("Copy Command=" << cp_cmd.str());
+
+                               int result = system(cp_cmd.str().c_str());
+                               if (-1 != result) {
+                                       if (0 != WIFEXITED(result)) {
+                                               if (0 != WEXITSTATUS(result)) {
+                                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Command failed.");
+                                               }
+                                       } else {
+                                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                               "Command terminated abnormally.");
+                                       }
+                               } else {
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't launch command.");
+                               }
+
+                               LogDebug("add Attachment");
+                               int error = email_add_attachment(m_mail->mail_id, attachment_info);
+                               if (EMAIL_ERROR_NONE != error) {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                    "Error while adding attachment. [" << error << "]");
+                               }
+                               else 
+                               {       
+                                       LogDebug(" attachment id : " << attachment_info->attachment_id);
+                                       LogDebug(" attachment inline : " << attachment_info->inline_content_status);
+                                       LogDebug(" setNth(i+1) : " << i+1);
+                                       att->setDownloaded(true);
+                                       att->setIsInlineAttachment(FALSE);
+                                       att->setAttachmentID(attachment_info->attachment_id);
+                                       att->setMessage(SharedFromThis());
+                                       att->setNth(i+1);
+                               }
+                               
+                               if (attachment_info)
+                                       EmailService::freeAttachment(attachment_info);
+                       }       
+                       
+               }
+               LogDebug("update attachments, inlineAttachmentSize=" << inlineAttachmentSize);
+               if (inlineAttachmentSize > 0) 
+               {
+                       email_attachment_data_t* attachment_info = NULL;
+                       for (std::size_t i = 0; i < inlineAttachmentSize; ++i) 
+                       {
+                               IAttachmentPtr att = getInlineAttachment(i);
+                               if (!att) {
+                                       continue;
+                               }
+
+                               //copy attachment file
+                               std::stringstream cp_cmd;
+                               char buf[] = "/tmp/XXXXXX";
+                               mode_t mask = umask(S_IWGRP | S_IWOTH);
+                               error = mkstemp(buf);
+                               umask(mask);
+
+                               cp_cmd << COMMAND_NAME;
+                               cp_cmd << " " << COMMAND_SWITCH_RECURSIVE;
+                               cp_cmd << " \"" << att->getFullPath() << "\"";
+                               cp_cmd << " \"" << buf << "\"";
+
+                               attachment_info = EmailService::alloc<email_attachment_data_t>();                                       
+                               attachment_info->attachment_name = String::strdup(att->getShortName());
+                               attachment_info->attachment_path = String::strdup( buf );
+                               attachment_info->save_status = true;
+                               attachment_info->inline_content_status = att->getIsInlineAttachment();
+
+                               LogDebug("Copy Command=" << cp_cmd.str());
+
+                               int result = system(cp_cmd.str().c_str());
+                               if (-1 != result) {
+                                       if (0 != WIFEXITED(result)) {
+                                               if (0 != WEXITSTATUS(result)) {
+                                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Command failed.");
+                                               }
+                                       } else {
+                                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                               "Command terminated abnormally.");
+                                       }
+                               } else {
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't launch command.");
+                               }
+
+                               LogDebug("add Attachment");
+                               int error = email_add_attachment(m_mail->mail_id, attachment_info);
+                               if (EMAIL_ERROR_NONE != error) {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                        "Error while adding attachment. [" << error << "]");
+                               }
+                               else 
+                               {       
+                                       LogDebug(" attachment id : " << attachment_info->attachment_id);
+                                       LogDebug(" attachment inline : " << attachment_info->inline_content_status);
+                                       LogDebug(" setNth(i+(int)attachmentSize+1) : " << i+(int)attachmentSize+1);
+                                       att->setDownloaded(true);
+                                       att->setIsInlineAttachment(TRUE);
+                                       att->setAttachmentID(attachment_info->attachment_id);
+                                       att->setMessage(SharedFromThis());
+//                                     att->setNth(i+1);
+                                       att->setNth(i + (int)attachmentSize + 1);
+                               }
+                               
+                               if (attachment_info)
+                                       EmailService::freeAttachment(attachment_info);
+                       }       
+                               
+               }
+
+
+       
+       } 
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+          if (attachment) 
+          {
+               int error = email_free_attachment_data(&attachment, attachmentCount);
+               if (EMAIL_ERROR_NONE != error) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                    "Error while adding attachment data [" << error << "]");
+               }
+
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                    "Error attachment Update");
+          }
+       }
+
+    LOG_EXIT
+}
+
+void Email::updatePriority()
+{
+    LOG_ENTER
+
+    if (isPriorityValid()) { return; }
+
+    if (!m_mail) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Mail not allocated.");
+    }
+
+    m_mail->priority = EmailConverter::toMailPriority( getPriority());
+    setPriorityValid(true);
+
+    LOG_EXIT
+}
+
+int Email::getIntId() const
+{
+    return convertId(getIdRef());
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/Email.h b/src/platform/Tizen/Messaging/Email.h
new file mode 100755 (executable)
index 0000000..01f90cd
--- /dev/null
@@ -0,0 +1,146 @@
+//
+// 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 EMAIL_H
+#define EMAIL_H
+
+#include <string>
+#include <dpl/mutex.h>
+#include <API/Messaging/IEmail.h>
+#include <API/Messaging/IMessagingTypes.h>
+#include <API/Messaging/EmailAccountInfo.h>
+
+#include "ScopedMail.h"
+#include "ScopedMailbox.h"
+
+// The email service library
+extern "C" {
+//temporary solution for email-service problem (compilation break)
+#ifndef NOW_REVERT
+//#define NOW_REVERT
+#endif
+#ifndef SUPPORT_CONTACT_ON_SIM
+//#define SUPPORT_CONTACT_ON_SIM
+#endif
+#ifndef _A_PROJECT_
+#define _A_PROJECT_
+#endif
+
+#ifndef _PREVIEW_IN_MAILIST
+#define _PREVIEW_IN_MAILIST
+#endif
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+class Email : public Api::Messaging::IEmail
+{
+  public:
+    explicit Email(const std::string& id = std::string());
+
+    explicit Email(const std::string& id, int accountId);
+
+    explicit Email( Api::Messaging::EmailAccountInfo& account);
+
+    explicit Email(const Api::Messaging::FolderType folder);   
+
+    virtual ~Email();
+
+    virtual int send();
+
+    virtual void sendCancel(int handle);
+
+       virtual int downloadBody();
+
+       virtual void downloadBodyCancel( int handle );
+
+       virtual int downloadAttachment(const Api::Messaging::IAttachmentPtr& attachment);
+
+       virtual void downloadAttachmentCancel( int handle );
+
+    // implementation of interface of IMessage class
+    virtual void update(bool draftsOnly = false);
+
+    virtual void readAllData();
+
+    virtual void moveToFolder(const Api::Messaging::FolderType newFolder);
+
+    virtual void moveToFolder(const std::string& newFolder);
+
+    virtual void copyToFolder(const Api::Messaging::FolderType newFolder);
+
+    virtual void copyToFolder(const std::string& newFolder);
+
+    virtual void remove();
+
+    virtual int getAccountID();
+
+    virtual int getUID();
+
+    virtual int isBodyDownloaded();
+
+    virtual bool hasAttachment();
+
+  private:
+    void create();
+
+    void create( Api::Messaging::EmailAccountInfo& account );
+
+    void reload();
+
+    void readHeader();
+
+    void readBody();
+
+    void readInfo();
+
+    void updateBody();
+
+    void updateRecipients();
+
+    void updateFrom();
+       
+    void updateAttachments();
+
+    void updateSubject();
+
+    void updateReadStatus();
+
+    void updateIsRead();
+       
+    void updateMessage();      
+       
+    void addMessageToDraft();
+       
+    void createSendMessage();          
+       
+    void updatePriority();
+
+    int getIntId() const;
+
+  private:
+    DPL::Mutex m_updateMutex;
+    int m_accountId;
+    ScopedMail m_mail;
+    ScopedMailbox m_mailbox;   //delete?
+};
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/EmailConverter.cpp b/src/platform/Tizen/Messaging/EmailConverter.cpp
new file mode 100755 (executable)
index 0000000..0c7eb44
--- /dev/null
@@ -0,0 +1,141 @@
+//
+// 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 <Commons/Exception.h>
+
+#include "EmailConverter.h"
+
+#define LOG_ENTER LogDebug("---> ENTER");
+#define LOG_EXIT LogDebug("---> EXIT");
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+namespace EmailConverter {
+email_mail_priority_t toMailPriority(Api::Messaging::MessagePriority::Priority priority)
+{
+    LOG_ENTER
+    switch (priority) {
+    case Api::Messaging::MessagePriority::LOW: return EMAIL_MAIL_PRIORITY_LOW;
+    case Api::Messaging::MessagePriority::NORMAL: return EMAIL_MAIL_PRIORITY_NORMAL;
+    case Api::Messaging::MessagePriority::HIGH: return EMAIL_MAIL_PRIORITY_HIGH;
+    default:
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Unsupported priority: " << priority);
+    }
+}
+
+Api::Messaging::MessagePriority::Priority toMessagePriority(email_mail_priority_t priority)
+{
+    LOG_ENTER
+    switch (priority) {
+    case EMAIL_MAIL_PRIORITY_LOW: return Api::Messaging::MessagePriority::LOW;
+    case EMAIL_MAIL_PRIORITY_NORMAL: return Api::Messaging::MessagePriority::NORMAL;
+    case EMAIL_MAIL_PRIORITY_HIGH: return Api::Messaging::MessagePriority::HIGH;
+    default:{
+        // TODO Think it through, log is enough or exception should be thrown.
+        //            ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+        //                     "Unsupported platform priority: " << priority);
+        LogWarning("Unsupported platform priority");
+    }
+    }
+
+    // TODO Fix this. What to return if non-existing priority returned by platform.
+    return Api::Messaging::MessagePriority::NORMAL;
+}
+
+Api::Messaging::MessagePriority::Priority toMessagePriority(unsigned char priority)
+{
+    return toMessagePriority(static_cast<email_mail_priority_t>(priority));
+}
+
+email_mailbox_type_e toMailboxType(Api::Messaging::FolderType folder)
+{
+    LOG_ENTER
+    switch (folder) {
+    case Api::Messaging::INBOX: return EMAIL_MAILBOX_TYPE_INBOX;
+    case Api::Messaging::OUTBOX: return EMAIL_MAILBOX_TYPE_OUTBOX;
+    case Api::Messaging::SENTBOX: return EMAIL_MAILBOX_TYPE_SENTBOX;
+    case Api::Messaging::DRAFTBOX: return EMAIL_MAILBOX_TYPE_DRAFT;
+    case Api::Messaging::SPAMBOX: return EMAIL_MAILBOX_TYPE_SPAMBOX;
+    case Api::Messaging::ALL_FOLDERS: return EMAIL_MAILBOX_TYPE_ALL_EMAILS;
+    case Api::Messaging::USERDEFINED_FOLDER: return EMAIL_MAILBOX_TYPE_USER_DEFINED;
+    default:
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Conversion failed.");
+    }
+}
+
+const char* toMailboxName(Api::Messaging::FolderType folder)
+{
+    LOG_ENTER
+    switch (folder) {
+    case Api::Messaging::INBOX: return EMAIL_INBOX_NAME;
+    case Api::Messaging::OUTBOX: return EMAIL_OUTBOX_NAME;
+    case Api::Messaging::SENTBOX: return EMAIL_SENTBOX_NAME;
+    case Api::Messaging::DRAFTBOX: return EMAIL_DRAFTBOX_NAME;
+    case Api::Messaging::SPAMBOX: return EMAIL_SPAMBOX_NAME;
+    default:
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Mailbox not found. Folder: " << folder);
+    }
+}
+
+Api::Messaging::FolderType toFolderType(email_mailbox_type_e mailboxType)
+{
+    LOG_ENTER
+    switch (mailboxType) {
+    case EMAIL_MAILBOX_TYPE_INBOX: return Api::Messaging::INBOX;
+    case EMAIL_MAILBOX_TYPE_OUTBOX: return Api::Messaging::OUTBOX;
+    case EMAIL_MAILBOX_TYPE_SENTBOX: return Api::Messaging::SENTBOX;
+    case EMAIL_MAILBOX_TYPE_DRAFT: return Api::Messaging::DRAFTBOX;
+    case EMAIL_MAILBOX_TYPE_TRASH: return Api::Messaging::TRASHBOX;
+    case EMAIL_MAILBOX_TYPE_SPAMBOX: return Api::Messaging::SPAMBOX;
+    case EMAIL_MAILBOX_TYPE_ALL_EMAILS: return Api::Messaging::ALL_FOLDERS;
+    case EMAIL_MAILBOX_TYPE_SEARCH_RESULT: return Api::Messaging::SEARCHED;
+    case EMAIL_MAILBOX_TYPE_FLAGGED: return Api::Messaging::FLAGED;
+    case EMAIL_MAILBOX_TYPE_USER_DEFINED: return Api::Messaging::USERDEFINED_FOLDER;
+    default:
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Conversion failed.");
+    }
+}
+
+Api::Messaging::FolderType toFolderType(int mailboxType)
+{
+    LOG_ENTER
+    switch (mailboxType) {
+       case EMAIL_MAILBOX_TYPE_INBOX: return Api::Messaging::INBOX;
+       case EMAIL_MAILBOX_TYPE_OUTBOX: return Api::Messaging::OUTBOX;
+       case EMAIL_MAILBOX_TYPE_SENTBOX: return Api::Messaging::SENTBOX;
+       case EMAIL_MAILBOX_TYPE_DRAFT: return Api::Messaging::DRAFTBOX;
+       case EMAIL_MAILBOX_TYPE_TRASH: return Api::Messaging::TRASHBOX;
+       case EMAIL_MAILBOX_TYPE_SPAMBOX: return Api::Messaging::SPAMBOX;
+       case EMAIL_MAILBOX_TYPE_ALL_EMAILS: return Api::Messaging::ALL_FOLDERS;
+       case EMAIL_MAILBOX_TYPE_SEARCH_RESULT: return Api::Messaging::SEARCHED;
+       case EMAIL_MAILBOX_TYPE_FLAGGED: return Api::Messaging::FLAGED;
+       case EMAIL_MAILBOX_TYPE_USER_DEFINED: return Api::Messaging::USERDEFINED_FOLDER;
+    default:
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Conversion failed.");
+    }
+}
+
+
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/EmailConverter.h b/src/platform/Tizen/Messaging/EmailConverter.h
new file mode 100755 (executable)
index 0000000..85f44a4
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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_MESSAGING_EMAILCONVERTER_H_
+#define _TIZEN_MESSAGING_EMAILCONVERTER_H_
+
+#include <email-types.h>
+
+#include <API/Messaging/MessagePriority.h>
+#include <API/Messaging/IMessagingTypes.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+namespace EmailConverter {
+email_mail_priority_t toMailPriority(Api::Messaging::MessagePriority::Priority priority);
+
+Api::Messaging::MessagePriority::Priority toMessagePriority(email_mail_priority_t priority);
+Api::Messaging::MessagePriority::Priority toMessagePriority(unsigned char priority);
+
+email_mailbox_type_e toMailboxType(Api::Messaging::FolderType folder);
+
+const char* toMailboxName(Api::Messaging::FolderType folder);
+
+Api::Messaging::FolderType toFolderType(email_mailbox_type_e mailboxType);
+Api::Messaging::FolderType toFolderType(int mailboxType);
+
+}
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/EmailService.cpp b/src/platform/Tizen/Messaging/EmailService.cpp
new file mode 100755 (executable)
index 0000000..dd491cb
--- /dev/null
@@ -0,0 +1,313 @@
+//
+// 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 <string>
+#include <sstream>
+
+#include <dpl/assert.h>
+#include <dpl/scoped_free.h>
+
+#include <email-api.h>
+
+#include <Commons/Exception.h>
+#include "EmailUtils.h"
+#include "EmailService.h"
+#include "ScopedMail.h"
+#include "ScopedMailbox.h"
+
+#define LOG_ENTER LogDebug("---> ENTER");
+#define LOG_EXIT LogDebug("---> EXIT");
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+namespace EmailService {
+
+email_mail_data_t* createMailData(const Api::Messaging::EmailAccountInfo& account)
+{
+    LOG_ENTER
+    int error = 0;
+    ScopedMail result(alloc<email_mail_data_t>());
+
+    result->account_id = account.getIntId();
+    result->flags_draft_field = 1;
+    result->priority = EMAIL_MAIL_PRIORITY_NORMAL;
+
+    std::string from = EmailUtils::formatAddress(account.getAddress(), account.getName());
+    result->full_address_from = strdup(from.c_str());
+
+    char buf[] = "XXXXXX";
+    mode_t mask = umask(S_IWGRP | S_IWOTH);
+    error = mkstemp(buf);
+    umask(mask);
+    std::string bodyFile = buf;
+    bodyFile = EmailUtils::TMP_DIR_PREFIX+bodyFile;
+    LogDebug("bodyFile : " << bodyFile);
+
+    FILE* f = fopen(bodyFile.c_str(), "w");
+    if (NULL != f) {
+        fclose(f);
+    }
+
+    result->file_path_plain = strdup(bodyFile.c_str());
+
+// fix email empty plain text
+/*
+    std::string htmlFile = tmpnam(NULL);
+    f = fopen(htmlFile.c_str(), "w");
+    fclose(f);
+    result->file_path_html = strdup(htmlFile.c_str());
+*/
+    result->file_path_html = NULL;
+
+    LOG_EXIT
+    return result.Release();
+}
+
+email_mail_data_t* readMail(int mailId)
+{
+    LOG_ENTER
+    email_mail_data_t* result = NULL;
+    
+    int error = email_get_mail_data(mailId, &result);
+    if (EMAIL_ERROR_NONE != error) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Couldn't find message " << mailId << ". [" << error << "]");
+    }
+
+    LOG_EXIT
+    return result;
+}
+
+void deleteMail(int accountId,
+        int mailId)
+{
+    LOG_ENTER
+    int error;
+    email_mail_data_t *mail = NULL;
+
+    error = email_get_mail_data(mailId, &mail);
+    if (EMAIL_ERROR_NONE != error) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Error while deleting mail. [" << error << "]");
+    }
+
+    error = email_delete_mail(mail->mailbox_id, &mailId, 1, 0);
+    if (EMAIL_ERROR_NONE != error) {
+        email_free_mail_data(&mail,1);
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Error while deleting mail. [" << error << "]");
+    }
+    email_free_mail_data(&mail,1);
+    LOG_EXIT
+}
+
+email_mailbox_t* getMailboxByType(int accountId,
+        email_mailbox_type_e type)
+{
+    LOG_ENTER
+    email_mailbox_t* result = NULL;
+
+    int error = email_get_mailbox_by_mailbox_type(accountId, type, &result);
+    if (EMAIL_ERROR_NONE != error) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Couldn't retrieve mailbox. [" << error << "]");
+    }
+
+    LOG_ENTER
+    return result;
+}
+
+int addMail(email_mail_data_t* mail, email_attachment_data_t* attachment)
+{
+    LOG_ENTER
+    Assert(mail);
+
+    int error = 0;
+    if (!mail->mailbox_id)
+    {
+               //get mail box
+               if ( mail->mailbox_type > 0)
+               {
+                       email_mailbox_t* mailbox;
+                       error = email_get_mailbox_by_mailbox_type(mail->account_id, EMAIL_MAILBOX_TYPE_DRAFT, &mailbox );
+                       if (EMAIL_ERROR_NONE != error) {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                       "Couldn't add message to mailbox. [" << error << "]");
+                       }
+
+//                     if ( mailbox->mailbox_name )
+//                             mail->mailbox_name = strdup(mailbox->mailbox_name);
+
+//                     LogDebug("mail MailBox Name :" << mail->mailbox_name);
+                       
+                       error = email_free_mailbox(&mailbox, 1);
+                  if (EMAIL_ERROR_NONE != error) {
+                      LogError("Failed to destroy mailbox: " << error);
+                  }
+               }                                       
+    }
+
+    error = email_add_mail(mail, attachment, mail->attachment_count, NULL, 0);
+    if (EMAIL_ERROR_NONE != error) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Couldn't add message to mailbox. [" << error << "]");
+    }
+   
+    LOG_EXIT
+    LogDebug("Mail to MailBox, mail id = " << mail->mail_id );
+    return mail->mail_id;
+}
+
+#if 0
+int addMailToMailbox(email_mail_data_t* mail,
+        email_attachment_data_t* attachment, int attachment_count )
+{
+    LOG_ENTER
+    Assert(mail);
+
+    int error = email_add_mail(mail, attachment, attachment_count, NULL, 0);
+    if (EMAIL_ERROR_NONE != error) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Couldn't add message to mailbox. [" << error << "]");
+    }
+
+    LOG_EXIT
+    LogDebug("Mail to MailBox, mail id = " << mail->mail_id );
+    return mail->mail_id;
+}
+#endif
+
+void freeAttachment(email_attachment_data_t* attachment)
+{
+    LOG_ENTER
+    if (NULL == attachment) { return; }
+
+    int error = email_free_attachment_data(&attachment, 1);
+    if (EMAIL_ERROR_NONE != error) {
+        LogWarning("Couldn't free attachment. [" << error << "]");
+    }
+    LOG_EXIT
+}
+/*
+email_mailbox_t* createMailbox(int accountId,
+        const char* name)
+{
+    LOG_ENTER
+    email_mailbox_t* result = alloc<email_mailbox_t>();
+    result->account_id = accountId;
+    result->name = (NULL != name ? strdup(name) : NULL);
+
+    LOG_EXIT
+    return result;
+}
+*/
+       
+// TODO This clonning is not efficent.
+email_mail_data_t* cloneMail(const email_mail_data_t* mail)
+{
+    LOG_ENTER
+    email_mail_data_t* result = readMail(mail->mail_id);
+    result->mail_id = 0;
+    result->account_id = 0;
+
+    LOG_EXIT
+    return result;
+}
+
+email_mailbox_t* getMailboxByMailId(int accountId, int mailId)
+{
+    LOG_ENTER
+/*             
+    char* mailboxName = NULL;
+    int error = email_get_mailbox_name_by_mail_id(mailId, &mailboxName);
+    // Platform may allocate mailboxName and yet return an error code.
+    DPL::ScopedFree<char> freeGuard(mailboxName);
+    if (EMAIL_ERROR_NONE != error) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Couldn't get mailbox name. [" << error << "]");
+    }
+
+    email_mailbox_t* result = NULL;
+    error = email_get_mailbox_by_name(accountId, mailboxName, &result);
+    if (EMAIL_ERROR_NONE != error) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Couldn't get mailbox. [" << error << "]");
+    }
+*/
+    int error;
+
+    email_mailbox_t* result = NULL;
+    email_mail_data_t* mail_data = NULL;
+               
+    error = email_get_mail_data(mailId, &mail_data);
+    if (EMAIL_ERROR_NONE != error) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Couldn't get mailbox data " << mailId << ". [" << error << "]");
+    }
+
+       if (mail_data == NULL) {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException,     "Couldn't get mail_data");
+       }
+
+    error = email_get_mailbox_by_mailbox_id(mail_data->mailbox_id, &result);
+    if (EMAIL_ERROR_NONE != error) {
+        if(mail_data)
+        {
+            email_free_mail_data(&mail_data, 1);
+        }
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Couldn't get mailbox " << mail_data->mailbox_id << ". [" << error << "]");
+    }
+    if(mail_data)
+    {
+        email_free_mail_data(&mail_data, 1);
+    }
+
+    LOG_EXIT
+    return result;
+}
+
+void updateSeenFlag(int accountId, int mailId, bool isReadChangeStatus)
+{
+    LOG_ENTER
+       
+    if ( accountId > -1 )
+    {
+           if (EMAIL_ERROR_NONE != 
+                       email_set_flags_field(accountId, &mailId, 0, EMAIL_FLAGS_SEEN_FIELD, isReadChangeStatus, 1) )
+    {
+        LogWarning("email_modify_seen_flag failed\n");
+    }
+    else
+    {
+        LogWarning("email_modify_seen_flag SUCCESS\n");
+    }
+    }
+    else
+    {
+               LogWarning("Invaild Account ID\n");
+    }
+       
+    LOG_EXIT
+}
+
+
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/EmailService.h b/src/platform/Tizen/Messaging/EmailService.h
new file mode 100755 (executable)
index 0000000..16c74c2
--- /dev/null
@@ -0,0 +1,103 @@
+//
+// 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_MESSAGING_EMAILSERVICE_H_
+#define TIZEN_MESSAGING_EMAILSERVICE_H_
+
+#include <cstring>
+#include <cstdlib>
+#include <new>
+
+#include <email-types.h>
+
+#include <API/Messaging/EmailAccountInfo.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+namespace EmailService {
+template<typename T>
+T* alloc()
+{
+    T* result = static_cast<T*>(::malloc(sizeof(T)));
+    if (NULL == result) {
+        throw std::bad_alloc();
+    }
+    ::memset(result, 0, sizeof(*result));
+    return result;
+}
+
+#if 1
+email_mail_data_t* createMailData(const Api::Messaging::EmailAccountInfo& account);
+
+email_mail_data_t* readMail(int mailId);
+
+email_mailbox_t* getMailboxByType(int accountId,
+        email_mailbox_type_e type);
+
+int addMail(email_mail_data_t* mail, email_attachment_data_t* attachment);
+
+//int addMailToMailbox(email_mail_data_t* mail, email_mailbox_t* mailbox);
+
+void deleteMail(int accountId, int mailId);
+
+void freeAttachment(email_attachment_data_t* attachment);
+
+//email_mailbox_t* createMailbox(int accountId, const char* name);
+
+email_mail_data_t* cloneMail(const email_mail_data_t* mail);
+
+email_mailbox_t* getMailboxByMailId(int accountId, int mailId);
+
+void updateSeenFlag(int accountId, int mailId, bool isReadChangeStatus);
+
+#else 
+
+email_mail_t* createMail(const Api::Messaging::EmailAccountInfo& account);
+
+email_mail_t* readMail(int accountId,
+        int mailId);
+
+email_mailbox_t* getMailboxByType(int accountId,
+        email_mailbox_type_e type);
+
+int addMailToMailbox(email_mail_t* mail,
+        email_mailbox_t* mailbox);
+
+void deleteMail(int accountId,
+        int mailId);
+
+void freeAttachment(email_attachment_info_t* attachment);
+
+email_mailbox_t* createMailbox(int accountId,
+        const char* name);
+
+email_mail_t* cloneMail(const email_mail_t* mail);
+
+email_mailbox_t* getMailboxByMailId(int accountId,
+        int mailId);
+
+void updateSeenFlag(int accountId, int mailId, bool isReadChangeStatus);
+
+#endif
+
+}
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/EmailUtils.cpp b/src/platform/Tizen/Messaging/EmailUtils.cpp
new file mode 100755 (executable)
index 0000000..c7a1f81
--- /dev/null
@@ -0,0 +1,94 @@
+//
+// 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 <sstream>
+#include <pcrecpp.h>
+
+#include <Commons/Exception.h>
+#include <Commons/StringBuilder.h>
+#include <Commons/StringUtils.h>
+#include "EmailUtils.h"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace {
+const char* EMAIL_ADDRESS_REGEX =
+    "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}";
+
+const std::string EMAIL_ADDRESS_REGEX_GROUP =
+    StringBuilder()
+        .append("(")
+        .append(EMAIL_ADDRESS_REGEX)
+        .append(")")
+        .toString();
+}
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+namespace EmailUtils {
+std::string formatAddress(const std::string& address,
+        const std::string& name)
+{
+    if (address.empty()) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Address is empty.");
+    }
+
+    std::stringstream ss;
+    if (!name.empty()) {
+        ss << "\"" << name << "\" ";
+    }
+    ss << "<" << address << ">";
+
+    return ss.str();
+}
+
+std::string formatAddressLine(const Api::Messaging::Recipients& recipients)
+{
+    std::string result;
+    for (size_t i = 0; i < recipients.getRecipientSize(); ++i) {
+        result += formatAddress(recipients.getRecipient(i)) + ";";
+    }
+    return result;
+}
+
+std::string stripAddress(const std::string& address)
+{
+    std::string result;
+    pcrecpp::RE re(EMAIL_ADDRESS_REGEX_GROUP);
+    if (!re.PartialMatch(address, &result)) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't discover email address");
+    }
+    return result;
+}
+
+Api::Messaging::Recipients stripAddressLine(const std::string& addressLine)
+{
+    typedef std::vector<std::string> Addresses;
+
+    Api::Messaging::Recipients result;
+    Addresses addresses = String::split(addressLine, ';');
+    for (Addresses::iterator it = addresses.begin();
+         it != addresses.end();
+         ++it) {
+        result.appendRecipient(stripAddress(*it));
+    }
+    return result;
+}
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/EmailUtils.h b/src/platform/Tizen/Messaging/EmailUtils.h
new file mode 100755 (executable)
index 0000000..b593d1f
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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_MESSAGING_EMAILUTILS_H_
+#define TIZEN_MESSAGING_EMAILUTILS_H_
+
+#include <string>
+
+#include <API/Messaging/Recipient.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+namespace EmailUtils {
+/**
+ * Formats address as: "Name" <address>.
+ * @param address E-mail address.
+ * @param name Name, omitted if empty.
+ * @return Formatted address.
+ */
+std::string formatAddress(const std::string& address,
+        const std::string& name = std::string());
+
+/**
+ * Formats multiple addresses as: "Name1" <address1>;"Name2" <address2>...
+ * @param recipients Recipients to build address line from.
+ * @return Formatted addresses.
+ */
+std::string formatAddressLine(const Api::Messaging::Recipients& recipients);
+
+/**
+ * Extracts bare e-mail address.
+ * @param address Address to strip.
+ * @return E-mail address.
+ */
+std::string stripAddress(const std::string& address);
+
+/**
+ * Extracts recipients bare e-mail addresses.
+ * @param addressLine Address line to split and strip.
+ * @return Recipients.
+ */
+Api::Messaging::Recipients stripAddressLine(const std::string& addressLine);
+
+static const std::string TMP_DIR_PREFIX = "/tmp/";
+
+}
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/EmptyMessage.cpp b/src/platform/Tizen/Messaging/EmptyMessage.cpp
new file mode 100755 (executable)
index 0000000..f2eee70
--- /dev/null
@@ -0,0 +1,126 @@
+//
+// 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 "EmptyMessage.h"
+#include <dpl/log/log.h>
+//#include <Commons/Exception.h>
+//#include <API/Messaging/ReqReceiverMessage.h>
+#include "Messaging.h"
+//#include "CallbackMgr.h"
+//#include "MsgServiceHandleMgr.h"
+
+extern "C" {
+//#include <MapiStorage.h>
+//#include <MapiMessage.h>
+}
+
+using namespace std;
+using namespace TizenApis::Api::Messaging;
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+EmptyMessage::EmptyMessage(const string& id) :
+    IMessage(EMPTY_MESSAGE, id),
+    m_messageData(NULL)
+{
+    LogDebug("enter");
+    LogDebug("m_id=" << getIdRef());
+    LogDebug("m_msgType=" << getMessageType());
+}
+
+EmptyMessage::~EmptyMessage()
+{
+       LogDebug("enter");
+
+       if (m_messageData) {
+               // release platform message structure
+               msg_release_struct(&m_messageData);
+               m_messageData = NULL;
+       }
+}
+
+void EmptyMessage::update(bool /*draftsOnly*/)
+{
+    LogDebug("updating m_id=" << getIdRef());
+}
+
+void EmptyMessage::readAllData()
+{
+    //#warning "TODO"
+}
+
+void EmptyMessage::moveToFolder(const FolderType newFolder)
+{
+    //#warning "TODO"
+}
+
+void EmptyMessage::moveToFolder(const string& newFolder)
+{
+    //#warning "TODO"
+}
+
+void EmptyMessage::copyToFolder(const FolderType newFolder)
+{
+    //#warning "TODO"
+}
+
+void EmptyMessage::copyToFolder(const string& newFolder)
+{
+    //#warning "TODO"
+}
+
+void EmptyMessage::remove()
+{
+    //#warning "TODO"
+}
+
+void EmptyMessage::updateIsRead()
+{
+    //#warning "TODO"
+}
+
+void EmptyMessage::updateMessage()
+{
+    //#warning "TODO"
+}
+
+void EmptyMessage::addMessageToDraft()
+{
+    //#warning "TODO"
+}
+
+void EmptyMessage::createSendMessage()
+{
+    //#warning "TODO"
+}
+
+int EmptyMessage::send()
+{
+    //#warning "TODO"
+    return -1;
+}
+
+void EmptyMessage::sendCancel(int handle)
+{
+    //#warning "TODO"
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/EmptyMessage.h b/src/platform/Tizen/Messaging/EmptyMessage.h
new file mode 100755 (executable)
index 0000000..34c22ff
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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 EMPTYMESSAGE_H
+#define EMPTYMESSAGE_H
+
+#include <API/Messaging/IEmptyMessage.h>
+#include <string>
+extern "C" {
+#include <msg_transport_types.h>
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+class EmptyMessage : public Api::Messaging::IEmptyMessage
+{
+  public:
+    explicit EmptyMessage(const std::string& id = "");
+
+    virtual ~EmptyMessage();
+
+    // implementation of interface of IMessage class
+    virtual void update(bool draftsOnly = false);
+
+    virtual void readAllData();
+
+    virtual void moveToFolder(const Api::Messaging::FolderType newFolder);
+
+    virtual void moveToFolder(const std::string& newFolder);
+
+    virtual void copyToFolder(const Api::Messaging::FolderType newFolder);
+
+    virtual void copyToFolder(const std::string& newFolder);
+
+    virtual void remove();
+
+       virtual void updateIsRead();
+       
+       virtual void updateMessage();
+       
+       virtual void addMessageToDraft();
+       
+       virtual void createSendMessage();
+
+    virtual int send();
+
+    virtual void sendCancel(int handle);
+
+       private:
+         msg_struct_t m_messageData;
+       
+};
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/FolderQueryGenerator.cpp b/src/platform/Tizen/Messaging/FolderQueryGenerator.cpp
new file mode 100755 (executable)
index 0000000..d5a5d6b
--- /dev/null
@@ -0,0 +1,178 @@
+//
+// 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 "FolderQueryGenerator.h"
+#include "API/Messaging/FolderFilterValidatorFactory.h"
+#include "API/Messaging/ConversationFilterValidatorFactory.h"
+
+#include <API/Messaging/IMessagingTypes.h>
+#include <API/Messaging/log.h>
+#include <Commons/Exception.h>
+
+#include <email-types.h>
+
+#include <dpl/log/log.h>
+
+using namespace std;
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+
+       namespace Platform {
+               namespace Messaging {
+
+               const std::string FolderQueryGenerator::STRING_MATCH_EXACTLY         = "EXACTLY";
+               const std::string FolderQueryGenerator::STRING_MATCH_CONTAINS        = "CONTAINS";
+               const std::string FolderQueryGenerator::STRING_MATCH_STARTSWITH      = "STARTSWITH";
+               const std::string FolderQueryGenerator::STRING_MATCH_ENDSWITH        = "ENDSWITH";
+//             const std::string FolderQueryGenerator::STRING_MATCH_CASESENSITIVE   = "CASESENSITIVE";
+
+               const int FolderQueryGenerator::ACCOUNT_ID_NOT_INITIALIZED = -1;
+
+               FolderQueryGenerator::FolderQueryGenerator():m_messageType(ACCOUNT_ID_NOT_INITIALIZED) {
+               }
+
+               FolderQueryGenerator::~FolderQueryGenerator() {
+               }
+
+
+               void FolderQueryGenerator::visitPreComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+               }
+
+               void FolderQueryGenerator::visitInComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+
+                       if(type != INTERSECTION_FILTER){
+                               LogError("[ERROR] >>> invalid Filter type:" << type);
+                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid Fiilter Type");
+                               return;
+                       }
+               }
+
+               void FolderQueryGenerator::visitPostComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+               }
+
+               bool FolderQueryGenerator::getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string retClause;
+                       std::string valueString = value->toString();
+
+                       do{
+                               if(attrName.compare(FolderFilterValidatorFactory::ATTRIBUTE_ACCOUNTID)==0){
+                                       m_accountId = atoi(value->toString().c_str());
+                                       break;
+                               }else if(attrName.compare(FolderFilterValidatorFactory::ATTRIBUTE_FOLDERPATH)==0){
+                                       m_folderPathProcessing = TRUE;                          
+                                       m_folderpath = value->toString();
+                                       break;
+                               }
+                       }while(false);
+
+                       return FALSE;
+               }
+
+               std::string FolderQueryGenerator::getMatchStartsWithClause(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& value){
+                       std::string retClause;
+                       LogDebug("<<< NOT IMPLEMENTED YET");
+                       return retClause;
+               }
+
+               std::string FolderQueryGenerator::getMatchEndsWithClause(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& value){
+                       std::string retClause;
+                       LogDebug("<<< NOT IMPLEMENTED YET");
+                       return retClause;
+               }
+
+               std::string FolderQueryGenerator::getMatchContainsClause(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& value){
+                       std::string retClause;
+                       LogDebug("<<< NOT IMPLEMENTED YET");
+                       return retClause;
+               }
+
+               void FolderQueryGenerator::visitAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                               Api::Tizen::AnyPtr& matchValue, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]");
+
+                       if(matchValue == NULL)
+                               return;
+
+                       LogDebug("matchValue:" << matchValue->toString());
+
+                       visitAttributeEach(attrName, matchFlag, matchValue, depth);
+
+                       LogDebug(">>>");
+               }
+
+               void FolderQueryGenerator::visitAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
+
+                       if(matchFlag == Api::Tizen::MATCH_EXACTLY){
+                               LogDebug("STRING_MATCH_EXACTLY");
+                               getMatchExactlyClause(attrName, value);
+                       }else if(matchFlag == Api::Tizen::MATCH_CONTAINS){
+                               LogDebug("STRING_MATCH_CONTAINS");
+                               getMatchContainsClause(attrName, value);
+                       }else if(matchFlag== Api::Tizen::MATCH_STARTSWITH){
+                               LogDebug("STRING_MATCH_STARTSWITH");
+                               getMatchStartsWithClause(attrName, value);
+                       }else if(matchFlag == Api::Tizen::MATCH_ENDSWITH){
+                               LogDebug("STRING_MATCH_ENDSWITH");
+                               getMatchEndsWithClause(attrName, value);
+                       }else{
+                               LogDebug("[ERROR]invalid match flag[" << matchFlag << "]");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid match flag:[" << matchFlag << "]");
+                       }
+                       LogDebug(">>>");
+               }
+
+               void FolderQueryGenerator::visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth) {
+                       LogDebug("<<< NOT IMPLEMENTED YET");
+               }
+
+               //TODO implement visitID
+               void FolderQueryGenerator::visitID(Api::Tizen::AnyArrayPtr &value, int depth) {
+                       LogDebug("<<< NOT IMPLEMENTED YET");
+               }
+
+               int FolderQueryGenerator::getAccountId()
+               {
+                       return m_accountId;
+               }
+               
+               std::string FolderQueryGenerator::getFolderPath()
+               {
+                       return m_folderpath;
+               }
+
+               bool FolderQueryGenerator::isFolderPathExist()
+               {
+                       LogError("m_folderPathProcessing : " << m_folderPathProcessing);                        
+                       return m_folderPathProcessing;
+               }
+
+               void FolderQueryGenerator::reset(){
+                       m_folderPathProcessing = FALSE;
+                       m_accountId = 0;
+                       m_folderpath.clear();
+               }
+
+
+               }
+       }               //namespace Platform
+}              //namespace WrtPlugins
diff --git a/src/platform/Tizen/Messaging/FolderQueryGenerator.h b/src/platform/Tizen/Messaging/FolderQueryGenerator.h
new file mode 100755 (executable)
index 0000000..b946e42
--- /dev/null
@@ -0,0 +1,104 @@
+//
+// 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 FOLDERQUERYGENERATOR_H_
+#define FOLDERQUERYGENERATOR_H_
+
+#include <API/Filter/IFilterVisitor.h>
+#include <API/Filter/SortMode.h>
+
+#include <map>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+class FolderQueryGenerator: public TizenApis::Api::Tizen::IFilterVisitor {
+
+public:
+       enum QueryGeneratorMode {
+               MODE_EMAIL, MODE_SMS_MMS
+       };
+
+protected:
+       std::map<std::string, std::string> attributeMap;
+
+private:
+       QueryGeneratorMode m_mode;
+       std::string m_query;
+       std::vector<std::string> m_queryVector;
+
+       int m_messageType;
+
+       std::vector<std::string> typeVector;
+
+       std::string m_currentType;
+
+       bool m_folderPathProcessing;
+
+       int m_accountId;
+       std::string m_folderpath;
+
+       static const std::string STRING_MATCH_EXACTLY;
+       static const std::string STRING_MATCH_CONTAINS;
+       static const std::string STRING_MATCH_STARTSWITH;
+       static const std::string STRING_MATCH_ENDSWITH;
+       static const std::string STRING_MATCH_CASESENSITIVE;
+
+       static const int ACCOUNT_ID_NOT_INITIALIZED;
+
+public:
+       FolderQueryGenerator();
+       virtual ~FolderQueryGenerator();
+
+       void visitPreComposite(Api::Tizen::FilterType& type, int depth);
+       void visitInComposite(Api::Tizen::FilterType& type, int depth);
+       void visitPostComposite(Api::Tizen::FilterType& type, int depth);
+       void visitAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                       Api::Tizen::AnyPtr& matchValue, int depth);
+       void visitAttributeRange(std::string& attrName,
+                       Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue,
+                       int depth);
+       void visitID(Api::Tizen::AnyArrayPtr &value, int depth);
+
+       int getAccountId();
+       std::string getFolderPath();
+       bool isFolderPathExist();
+       void reset();
+
+protected:
+       virtual bool getMatchExactlyClause(std::string& attrName,
+                       Api::Tizen::AnyPtr& value);
+       void visitAttributeEach(std::string& attrName,
+                       Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value,
+                       int depth);
+
+private:
+       std::string getMatchStartsWithClause(std::string& attrName,
+                       Api::Tizen::AnyPtr& value);
+       std::string getMatchEndsWithClause(std::string& attrName,
+                       Api::Tizen::AnyPtr& value);
+       std::string getMatchContainsClause(std::string& attrName,
+                       Api::Tizen::AnyPtr& value);
+
+};
+
+typedef DPL::SharedPtr<FolderQueryGenerator> FolderQueryGeneratorPtr;
+} // namespace Platform
+} // namespace WrtPlugins
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/ISendingObserver.h b/src/platform/Tizen/Messaging/ISendingObserver.h
new file mode 100755 (executable)
index 0000000..f6dcf9c
--- /dev/null
@@ -0,0 +1,73 @@
+//
+// 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 ISENDINGOBSERVER_H_
+#define ISENDINGOBSERVER_H_
+
+#include "CallbackMgr.h"
+
+extern "C" {
+#include <msg_transport_types.h>
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+/*
+ *
+ */
+class ISendingObserver
+{
+  public:
+    ISendingObserver() : m_reqId(0)
+    {
+    }
+
+    virtual ~ISendingObserver()
+    {
+        if (m_reqId) {
+            CallbackMgrSingleton::Instance().unregister(m_reqId);
+        }
+    }
+
+    void setSendigRequestId(int id)
+    {
+        m_reqId = id;
+    }
+
+    void setRecipient(const char* arg)
+    {
+        m_recipient = arg;
+    }
+
+    std::string getRecipient() const
+    {
+        return m_recipient;
+    }
+
+//    virtual void sendingCallback(msg_struct_t *sent_status) = 0;
+  virtual void sendingCallback(msg_struct_t sent_status) = 0;
+
+  private:
+    int m_reqId;
+    std::string m_recipient;
+};
+}
+}
+}
+#endif /* ISENDINGOBSERVER_H_ */
diff --git a/src/platform/Tizen/Messaging/MailSender.cpp b/src/platform/Tizen/Messaging/MailSender.cpp
new file mode 100755 (executable)
index 0000000..db3e13f
--- /dev/null
@@ -0,0 +1,316 @@
+//
+// 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 <utility>
+#include <email-types.h>
+#include <email-api.h>
+#include <email-api-network.h>
+#include <email-api-init.h>
+#include <email-api-account.h>
+
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <Commons/Exception.h>
+#include <Commons/ThreadPool.h>
+#include <API/Messaging/ReqReceiverMessage.h>
+#include <API/Messaging/EventSendMessage.h>
+#include <API/Messaging/EventMessagingService.h>
+#include <API/Messaging/EventOnSendingFailed.h>
+#include "MailSender.h"
+#include "NetworkStatus.h"
+#include "Messaging.h"
+
+namespace {
+const char* DBUS_FILTER_NETWORK_STATUS =
+    "type='signal',interface='User.Email.NetworkStatus'";
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+MailSender& MailSender::getInstance()
+{
+    static MailSender instance;
+    return instance;
+}
+
+int MailSender::send(const Api::Messaging::IEmailPtr& mail)
+{
+    Assert(mail && "Mail must not be NULL.");
+
+    int mailId = mail->convertId(mail->getIdRef());
+    LogDebug("send mailId = " << mailId);
+    SendRequestsIterator it = m_requests.find(mailId);
+    if (m_requests.end() != it) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Email: " << mailId << " already requested to be send.");
+    }
+
+    return sendInternal(mail);
+}
+
+void MailSender::cancel(int handle)
+{
+    SendRequestsIterator it = m_requests.find(handle);
+    if (m_requests.end() == it) {
+        //ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+        //         "Email handle : " << handle << " not found.");
+        LogDebug("Email handle" << handle  << " not found!");
+         return;
+    }
+    else
+    {
+         cancelInternal(it->second);
+    }
+}
+
+// TODO Copied from former solution, refactor it.
+void MailSender::OnEventReceived(const DBus::MessageEvent& event)
+{
+    LogDebug("HERE");
+    NetworkStatusPtr msg(new NetworkStatus(event.GetArg0()));
+    int mailId = msg->getMailId();
+    LogDebug("status : " << msg->getStatus() << " mailId : " << mailId);
+    int handle = 0;
+
+    if ( msg->getStatus() == NOTI_SEND_FINISH || msg->getStatus() == NOTI_SEND_FAIL)
+    {
+               //find handle
+               SendRequestsIterator it = m_requests.begin();
+               for (; it != m_requests.end() ; it++)
+               {
+                       if ( it->second.mail->getUID() == mailId)
+                       {
+                               handle = it->first;
+                               LogDebug("handle : " << handle);
+                               break;
+                       }
+               }
+
+               if (msg->getStatus() == NOTI_SEND_FAIL)
+               {
+                       LogDebug(" Error Code : " << msg->getErrorCode());
+               }
+    }
+    else 
+    {
+               if ( msg->getStatus() == NOTI_SEND_START )
+               {
+                       LogDebug("NOTI_SEND_START");
+               }
+               else if ( msg->getStatus() == NOTI_SEND_CANCEL )
+               {
+                       LogDebug("NOTI_SEND_CANCEL");
+               }
+
+               return ;
+    }
+       
+    LogDebug("handle : " << handle);
+       
+    SendRequestsIterator it = m_requests.find(handle); //find reqeuset
+    if (m_requests.end() != it) {
+        switch (msg->getStatus()) {
+        case NOTI_SEND_START:
+            LogInfo("Start sending e-mail: " << mailId);
+            break;
+
+        case NOTI_SEND_FINISH:
+        {
+            const Api::Messaging::IEmailPtr& mail = it->second.mail;
+            //Api::Messaging::EventSendMessageReqReceiver* requestReceiver = mail->getRequestReceiver();
+            Api::Messaging::EventMessagingServiceReqReceiver* requestReceiver = mail->getRequestReceiver();
+               
+            if (requestReceiver) {
+                //Api::Messaging::EventSendMessagePtr event = mail->getSendMessageEvent();
+                Api::Messaging::EventMessagingServicePtr event = mail->getMessagingServiceEvent();
+                    if (event)
+                       {
+                               for (size_t i = 0; i < mail->getToRecipients().getRecipientSize(); ++i) {
+                                       event->m_successRecipients.push_back(mail->getToRecipients().getRecipient(i));
+                               }
+                               for (size_t i = 0; i < mail->getCcRecipients().getRecipientSize(); ++i) {
+                                       event->m_successRecipients.push_back(mail->getCcRecipients().getRecipient(i));
+                               }
+                               for (size_t i = 0; i < mail->getBccRecipients().getRecipientSize(); ++i) {
+                                       event->m_successRecipients.push_back(mail->getBccRecipients().getRecipient(i));
+                               }
+                               
+                               requestReceiver->ManualAnswer(event);
+                       }                
+                
+            }
+                mail->setMessageStatus(Api::Messaging::MESSAGE_STATUS_SENT);
+            LogInfo("E-mail sent: " << mailId);
+            m_requests.erase(mailId);
+            break;
+        }
+
+        case NOTI_SEND_FAIL:
+        {
+            const Api::Messaging::IEmailPtr& mail = it->second.mail;
+            Api::Messaging::EventOnSendingFailedEmitterPtr emitter = mail->getEmitter();
+            //Api::Messaging::EventSendMessageReqReceiver *requestReceiver = mail->getRequestReceiver();
+            Api::Messaging::EventMessagingServiceReqReceiver* requestReceiver = mail->getRequestReceiver();
+            if (emitter) {
+                Api::Messaging::EventOnSendingFailedPtr event(
+                    new Api::Messaging::EventOnSendingFailed()
+                    );
+                switch (msg->getErrorCode()) {
+                case EMAIL_ERROR_NO_SIM_INSERTED:
+                case EMAIL_ERROR_FLIGHT_MODE:
+                    event->setError(
+                        Api::Messaging::EventOnSendingFailed::NO_NETWORKING
+                        );
+                    break;
+
+                case EMAIL_ERROR_SMTP_SEND_FAILURE:
+                case EMAIL_ERROR_NO_SUCH_HOST:
+                case EMAIL_ERROR_CONNECTION_FAILURE:
+                case EMAIL_ERROR_CONNECTION_BROKEN:
+                case EMAIL_ERROR_INVALID_SERVER:
+                case EMAIL_ERROR_NO_RESPONSE:
+                    event->setError(
+                        Api::Messaging::EventOnSendingFailed::NO_CONNECTION
+                        );
+                    break;
+
+                default:
+                    event->setError(Api::Messaging::EventOnSendingFailed::UNKNOWN);
+                }
+                emitter->emit(event);
+            } else if (requestReceiver) {
+                //Api::Messaging::EventSendMessagePtr event = mail->getSendMessageEvent();
+                       Api::Messaging::EventMessagingServicePtr event = mail->getMessagingServiceEvent();
+                event->setExceptionCode(
+                    WrtDeviceApis::Commons::ExceptionCodes::UnknownException
+                    );
+                requestReceiver->ManualAnswer(event);
+            }
+                mail->setMessageStatus(Api::Messaging::MESSAGE_STATUS_FAILED);
+                
+            LogInfo("Sending e-mail: " << mailId <<
+                    " failed with error: " << msg->getErrorCode());
+            m_requests.erase(mailId);
+            break;
+        }
+        }
+    }
+}
+
+MailSender::MailSender() :
+    m_dbusThread(new DPL::Thread()),
+    m_dbus(new DBus::Connection())
+{
+    m_dbusThread->Run();
+
+    m_dbus->setWorkerThread(m_dbusThread.Get());
+    m_dbus->AddListener(this);
+    m_dbus->SwitchAllListenersToThread(
+        ThreadPool::getInstance().getThreadRef(ThreadEnum::MESSAGING_THREAD)
+        );
+    m_dbus->addFilter(DBUS_FILTER_NETWORK_STATUS);
+    m_dbus->open(DBUS_BUS_SYSTEM);
+
+    //start email service
+       if (EMAIL_ERROR_NONE == email_service_begin()) {
+           LogDebug("Email service Begin\n");
+           if (EMAIL_ERROR_NONE == email_open_db()) {
+                   LogDebug("Email open DB success\n");
+           }
+           else{
+                   LogDebug("Email open DB failed\n");
+       }
+       }
+       else{
+           LogDebug("Email service not started\n");
+       }
+
+}
+
+MailSender::~MailSender()
+{
+    m_dbus->RemoveListener(this);
+    m_dbus->close();
+
+    m_dbusThread->Quit();
+
+
+    //close email service
+       if (EMAIL_ERROR_NONE == email_close_db()) {
+               LogDebug("Email Close DB Success\n");
+               if (EMAIL_ERROR_NONE == email_service_end()){
+               LogDebug("Email service close Success\n");
+               }
+               else{
+               LogDebug("Email service end failed\n");
+       }
+       }
+       else{
+               LogDebug("Email Close DB failed\n");
+       }
+       
+}
+
+int MailSender::sendInternal(const Api::Messaging::IEmailPtr& mail)
+{
+    int mailId = mail->convertId(mail->getIdRef());
+
+    email_option_t options = {};
+    options.keep_local_copy = 1;
+    int email_handle=0;
+
+    int error = email_send_mail(mailId,
+                                &email_handle);
+       
+    if (EMAIL_ERROR_NONE != error) {
+               LogDebug("Send Fail error = " << error );
+               m_requests.erase(mailId);
+               mail->setMessageStatus(Api::Messaging::MESSAGE_STATUS_SENDING); 
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                        "Failed to initialize send request. [" << error << "]");
+         return -1;
+    }
+    else
+    {
+               m_requests.insert(std::make_pair(email_handle, SendRequestData(email_handle, mail)));
+    }
+
+    LogDebug("emf Handle : " << email_handle 
+<< "requests size :" << m_requests.size() );
+  
+    return email_handle;       
+}
+
+void MailSender::cancelInternal(const SendRequestData& data)
+{
+    int error = email_cancel_job(data.mail->getAccountID(), data.handle,EMAIL_CANCELED_BY_USER);
+    if (EMAIL_ERROR_NONE != error) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Couldn't cancel sending for email: " <<
+                 data.mail->getIdRef());
+    }
+
+    m_requests.erase(data.handle);
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/MailSender.h b/src/platform/Tizen/Messaging/MailSender.h
new file mode 100755 (executable)
index 0000000..11fccbe
--- /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.
+//
+
+#ifndef MAILSENDER_H_
+#define MAILSENDER_H_
+
+#include <map>
+#include <dpl/event/event_listener.h>
+#include <dpl/thread.h>
+#include <dpl/scoped_ptr.h>
+#include <DBus/Connection.h>
+#include <DBus/MessageEvent.h>
+#include <API/Messaging/IEmail.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+// TODO Not thread-safe, make it.
+class MailSender : private DPL::Event::EventListener<DBus::MessageEvent>
+{
+  public:
+    static MailSender& getInstance();
+
+  public:
+    int send(const Api::Messaging::IEmailPtr& mail);
+    void cancel(int handle);
+
+  protected:
+    void OnEventReceived(const DBus::MessageEvent& event);
+
+  private:
+    struct SendRequestData
+    {
+        int handle;
+        Api::Messaging::IEmailPtr mail;
+
+        explicit SendRequestData(const Api::Messaging::IEmailPtr& mail) :
+            handle(0),
+            mail(mail)
+        {
+        }
+         explicit SendRequestData(const int handle, const Api::Messaging::IEmailPtr& mail) :
+            handle(handle),
+            mail(mail)
+        {
+        }
+    };
+
+    typedef std::map<int, SendRequestData> SendRequests;
+    typedef SendRequests::iterator SendRequestsIterator;
+
+  private:
+    MailSender();
+    ~MailSender();
+
+    int sendInternal(const Api::Messaging::IEmailPtr& data);
+    void cancelInternal(const SendRequestData& data);
+
+  private:
+    DPL::ScopedPtr<DPL::Thread> m_dbusThread;
+    DBus::ConnectionPtr m_dbus;
+    SendRequests m_requests;
+};
+}
+}
+}
+#endif // MAILSENDER_H_
diff --git a/src/platform/Tizen/Messaging/MailSync.cpp b/src/platform/Tizen/Messaging/MailSync.cpp
new file mode 100755 (executable)
index 0000000..0cf64d1
--- /dev/null
@@ -0,0 +1,740 @@
+//
+// 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 <utility>
+#include <email-types.h>
+#include <email-api.h>
+#include <email-api-network.h>
+#include <email-api-init.h>
+#include <email-api-account.h>
+
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <Commons/Exception.h>
+#include <Commons/ThreadPool.h>
+#include <API/Messaging/ReqReceiverMessage.h>
+#include <API/Messaging/EventMessagingService.h>
+#include <API/Messaging/IAttachment.h>
+
+#include "MailSync.h"
+#include "SyncNetworkStatus.h"
+#include <API/Messaging/IMessage.h>
+//for vconf
+#include <vconf.h>
+#include <vconf-keys.h>
+
+namespace {
+const char* DBUS_FILTER_NETWORK_STATUS =
+    "type='signal',interface='User.Email.NetworkStatus'";
+//const char* DBUS_FILTER_EMAIL_RECEIVED =
+//    "type='signal',interface='User.Email.StorageChange'";
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+MailSync& MailSync::getInstance()
+{
+    static MailSync instance;
+    return instance;
+}
+
+MailSync::MailSync() :
+    m_dbusThread(new DPL::Thread()),
+    m_dbus(new DBus::Connection())
+{
+    m_dbusThread->Run();
+
+    m_dbus->setWorkerThread(m_dbusThread.Get());
+    m_dbus->AddListener(this);
+    m_dbus->SwitchAllListenersToThread(
+        ThreadPool::getInstance().getThreadRef(ThreadEnum::MESSAGING_THREAD)
+        );
+    m_dbus->addFilter(DBUS_FILTER_NETWORK_STATUS);
+    m_dbus->open(DBUS_BUS_SYSTEM);
+
+    //start email service
+    int error = email_service_begin();
+       if (error == EMAIL_ERROR_NONE) {
+           LogDebug("Email service Begin\n");
+           if (EMAIL_ERROR_NONE == email_open_db()) {
+                   LogDebug("Email open DB success\n");
+           }
+           else{
+                   LogDebug("Email open DB failed\n");
+       }
+       }
+       else{
+           LogDebug("Email service not started\n");
+           LogDebug("Error : " << error);
+       }
+
+       //get retriving count
+       int slot_size = -1;
+       vconf_get_int("db/private/email-service/slot_size", &(slot_size));
+       if ( slot_size > 0 )
+               m_default_slot_size = slot_size;
+
+       LogDebug( "Slot Size : " << m_default_slot_size );
+       
+}
+
+MailSync::~MailSync()
+{
+    m_dbus->RemoveListener(this);
+    m_dbus->close();
+
+    m_dbusThread->Quit();
+
+    //close email service
+       if (EMAIL_ERROR_NONE == email_close_db()) {
+               LogDebug("Email Close DB Success\n");
+               if (EMAIL_ERROR_NONE == email_service_end())
+               {
+               LogDebug("Email service close Success\n");
+               }
+               else
+               {
+               LogDebug("Email service end failed\n");
+       }
+       }
+       else{
+               LogDebug("Email Close DB failed\n");
+}
+}
+
+int MailSync::downloadBody( const Api::Messaging::IEmailPtr& mail )
+{      
+       if ( mail )
+       {       
+               int mailId = mail->convertId(mail->getIdRef());         // get mail id
+               LogDebug("start attachment, mail Id : " << mail->getIdRef());
+               SyncRequestIterator it;
+               int synType;
+               for( it = m_SyncRequests.begin(); it != m_SyncRequests.end(); ++it)
+               {
+                       synType = it->second.syncType;
+                       LogDebug("synType : " << synType);
+
+                       if( synType != MESSAGING_SERVICE_SYNC_TYPE_DOWNLOAD_BODY )
+                       {
+                               LogDebug("skip");
+                               continue;
+                       }
+                       const Api::Messaging::IEmailPtr& email = it->second.mail;
+                       LogDebug ( "Requests mail ID:" <<  mail->convertId(email->getIdRef()) );
+                       if ( mailId == mail->convertId(email->getIdRef()))
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                       "download Body: " << mailId << " already requested to be download Body.");
+                       }
+               }               
+       }
+       
+       return downloadBodyInternal(mail, mail->getAccountID());
+       
+}
+
+void MailSync::cancelDownloadBody(int handle)
+{
+       Assert(handle > -1);
+
+       SyncRequestIterator it = m_SyncRequests.find(handle);
+       if ( m_SyncRequests.end() != it)
+       {
+               if (  it->second.messagingService )
+                       cancelEmailJobInternal( it->second.messagingService->getAccountID() , it->second.handle);
+               //cancelDownloadBodyInternal(it->second.mail, it->second.handle );
+       }
+       else
+       {
+               LogDebug("Don't find cancel DownloadBody handle : " << handle);
+               //ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "Email: " << mailId << " not found.");
+       }
+       
+}
+
+void MailSync::cancelDownloadAttachment(int handle)
+{
+       Assert(handle > -1);
+
+       SyncRequestIterator it = m_SyncRequests.find(handle);
+       if ( m_SyncRequests.end() != it)
+       {
+               if (  it->second.messagingService )
+                       cancelEmailJobInternal( it->second.messagingService->getAccountID() , it->second.handle);
+               //cancelDownloadBodyInternal(it->second.mail, it->second.handle );
+       }
+       else
+       {
+               LogDebug("Don't find cancel DownloadAttachment handle : " << handle);
+       }
+       
+}
+
+int MailSync::downloadAttachment(const Api::Messaging::IEmailPtr& mail, const Api::Messaging::IAttachmentPtr& attachment)
+{      
+       if ( mail && attachment )
+       {       
+               //int mailId = mail->convertId(mail->getIdRef());               // get mail id
+               LogDebug("start attachment, mail Id : " << mail->getIdRef());
+               SyncRequestIterator it;
+               int synType;
+               for( it = m_SyncRequests.begin(); it != m_SyncRequests.end(); ++it)
+               {
+                       synType = it->second.syncType;
+                       LogDebug("synType : " << synType);
+
+                       if( synType != MESSAGING_SERVICE_SYNC_TYPE_DOWNLOAD_ATTACHMENT )
+                       {
+                               LogDebug("skip");
+                               continue;
+                       }
+
+                       const Api::Messaging::IAttachmentPtr& iattachment = it->second.attachment;
+                       LogDebug ( "Requests Attachment ID:" <<  iattachment->getAttachmentID() << " Input Attachment ID: "  << attachment->getAttachmentID());
+                       if (iattachment->getAttachmentID() == attachment->getAttachmentID())
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                       "Attachment: " << attachment->getAttachmentID() << " already requested to be download Attachment.");
+                       }
+               }
+       }
+
+       return downloadAttachmentInternal(mail, mail->getAccountID(), attachment);
+
+}
+
+int MailSync::syncAccount(const Api::Messaging::IMessagingServicePtr& messagingService, const int limit)
+{
+       LogDebug("syncAccount : " << limit);
+       if (messagingService)
+       {
+               int accountId = messagingService->getAccountID();
+               LogDebug("start sync, account Id : " << accountId);
+               SyncRequestIterator it;
+               int synType;
+               for( it = m_SyncRequests.begin(); it != m_SyncRequests.end(); ++it)
+               {
+                       synType = it->second.syncType;
+                       LogDebug("synType : " << synType);
+                       
+                       if( synType != MESSAGING_SERVICE_SYNC_TYPE_SYNC )
+                       {
+                               LogDebug("skip");
+                               continue;
+                       }
+               
+                       const Api::Messaging::IMessagingServicePtr& messagingService = it->second.messagingService;
+                       if (messagingService && messagingService->getAccountID() == accountId)
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                         "Sync: " << accountId << " already requested to be Sync Account.");
+                       }
+               }
+               return syncAccountInternal(messagingService, limit);
+       }
+       else
+       {
+               LogDebug("messagingService is NULL");
+       }
+
+       LogDebug("end sync" );
+       return -1;
+}      
+
+int MailSync::syncAccountInternal( const Api::Messaging::IMessagingServicePtr& messagingService, const int limit)
+{
+       LogDebug("syncAccountInternal limit: " << limit);
+       
+       int account_id = messagingService->getAccountID();
+       int err = 0;
+//     email_mailbox_t mailbox ;
+       int email_handle = 0;
+       
+//     memset(&mailbox, 0, sizeof(email_mailbox_t));
+//     mailbox.mailbox_name = NULL;                            /* all folders. */
+//     mailbox.account_id = account_id; //set account id.
+       int slot_size;
+       
+       if ( limit < 0 )
+               slot_size = m_default_slot_size;
+       else
+               slot_size = limit;
+       
+       email_set_mail_slot_size(0, 0, slot_size);
+                       
+//     LogDebug("mailbox.account_id " << mailbox.account_id );
+//     err = email_sync_header(&mailbox, &email_handle);
+//     LogDebug("emf_handle " << emf_handle);
+
+       err = email_sync_header(account_id, 0, &email_handle);
+       LogDebug("email_handle " << email_handle);
+
+       if (err != EMAIL_ERROR_NONE) {
+               LogDebug("fail to sync all folders - err : " << err);
+       }
+       else
+       {
+               LogDebug("Insert sync request");
+               SyncRequestData data = SyncRequestData(email_handle,    MESSAGING_SERVICE_SYNC_TYPE_SYNC, messagingService);
+               m_SyncRequests.insert(std::make_pair(email_handle, data));
+       }
+
+       return email_handle;
+}
+
+void MailSync::syncAccountCancel(const int handle)
+{
+       LogDebug("sync cancel");
+       Assert(handle > -1);
+
+       SyncRequestIterator it = m_SyncRequests.find(handle);
+       if ( m_SyncRequests.end() != it)
+       {
+               if (  it->second.messagingService )
+                       cancelEmailJobInternal( it->second.messagingService->getAccountID() , it->second.handle);
+       }
+       else
+       {
+               LogDebug("Don't find cancel Sync handle : " << handle);
+               //ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "Email: " << mailId << " not found.");
+       }       
+}
+
+int MailSync::syncFolder(const Api::Messaging::IMessagingServicePtr& messagingService, const int folder_id, const int limit)
+{
+       LogDebug("sync folder : " << folder_id << " limit : " << limit);
+       
+       if (messagingService)
+       {
+               int accountId = messagingService->getAccountID();
+               LogDebug("start sync, account Id : " << accountId);
+               SyncRequestIterator it;
+               int synType;
+               for( it = m_SyncRequests.begin(); it != m_SyncRequests.end(); ++it)
+               {
+                       synType = it->second.syncType;
+                       LogDebug("synType : " << synType);
+                       
+                       if( synType != MESSAGING_SERVICE_SYNC_TYPE_SYNC_FOLDER )
+                       {
+                               LogDebug("skip");
+                               continue;
+                       }
+               
+                       const Api::Messaging::IMessagingServicePtr& messagingService = it->second.messagingService;
+                       if (messagingService && messagingService->getAccountID() == accountId 
+                               && it->second.folderId == folder_id)
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                         "Sync: " << accountId << " already requested to be Sync Account.");
+                       }
+               }
+               
+               return syncFolderInternal(messagingService, folder_id, limit);
+       }
+       else
+       {
+               LogDebug("messagingService is NULL");
+       }
+
+       return -1;
+               
+}
+
+void MailSync::syncFolderCancel(const int handle)
+{
+       LogDebug("sync Folder Cancel");
+       Assert(handle > -1);
+
+       SyncRequestIterator it = m_SyncRequests.find(handle);
+       if ( m_SyncRequests.end() != it)
+       {
+               if (  it->second.messagingService )
+                       cancelEmailJobInternal( it->second.messagingService->getAccountID() , it->second.handle);
+       }
+       else
+       {
+               LogDebug("Don't find cancel Sync Folder handle : " << handle);
+               //ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "Email: " << mailId << " not found.");
+       }
+}
+
+int MailSync::syncFolderInternal(const Api::Messaging::IMessagingServicePtr& messagingService, const int folder_id, const int limit)
+{
+       LogDebug("Folder Id=" << folder_id << " limit : " << limit);
+
+       int account_id = messagingService->getAccountID();
+
+       int email_handle = 0;
+       int err = 0;
+       int slot_size = 0;
+       email_mailbox_t* mailbox = NULL;
+       
+//     char* mailbox_name = strdup(folderName.c_str());
+       
+       err = email_get_mailbox_by_mailbox_id(folder_id, &mailbox);
+       if (EMAIL_ERROR_NONE != err) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                       "Couldn't set mail solt size. [" << err << "]");
+       }       
+
+       if (mailbox == NULL) {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException,     "Couldn't get mailbox");
+       }
+       
+//     char* mailbox_name = strdup(mailbox->mailbox_name);
+       
+       if ( limit < 0 )
+               slot_size = m_default_slot_size;
+       else
+               slot_size = limit;
+       
+       err = email_set_mail_slot_size(0, mailbox->mailbox_id, slot_size);
+       if (EMAIL_ERROR_NONE != err) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                       "Couldn't set mail solt size. [" << err << "]");
+       }
+       
+//     err = email_sync_header(mailbox, &email_handle);
+       err = email_sync_header(account_id, mailbox->mailbox_id, &email_handle);
+       if (err != EMAIL_ERROR_NONE) {
+               LogDebug("fail to sync folders - err : " << err);
+       }
+       else
+       {
+               LogDebug("Insert sync request");
+
+               SyncRequestData data = SyncRequestData(email_handle,    MESSAGING_SERVICE_SYNC_TYPE_SYNC_FOLDER, messagingService, folder_id);
+               m_SyncRequests.insert(std::make_pair(email_handle, data));
+       }
+
+//     if (mailbox_name)
+//             free(mailbox_name);
+
+       if ( mailbox != NULL )
+       {
+               if  (  EMAIL_ERROR_NONE != email_free_mailbox( &mailbox , 1) )
+                       LogDebug("fail to email_free_mailbox - err ");
+               mailbox = NULL;
+       }
+       
+       return email_handle;
+}
+       
+
+// TODO Copied from former solution, refactor it.
+void MailSync::OnEventReceived(const DBus::MessageEvent& event)
+{
+       LogDebug("OnEventReceived");
+       SyncNetworkStatusPtr syncNetworkStatus(new SyncNetworkStatus(event.GetArg0()));
+       int mailId = syncNetworkStatus->getMailId();    //if email body download mode.
+       int status = syncNetworkStatus->getStatus();
+       int handle = syncNetworkStatus->getHandle();
+
+       LogDebug("mailId : " << mailId << " status : " << status << " handle : " << handle);
+       // if Attachment Load
+       if ( status == NOTI_DOWNLOAD_ATTACH_FINISH ||status == NOTI_DOWNLOAD_ATTACH_FAIL )
+       {
+               int nth = handle;
+               LogDebug(" Debus mailID = " <<  mailId <<  " , Nth = " << nth );
+
+               SyncRequestIterator it = m_SyncRequests.begin();
+               for ( ; it != m_SyncRequests.end(); it++ )
+               {
+                       const Api::Messaging::IEmailPtr& mail = it->second.mail;
+
+                       LogDebug(" request mailID = " <<  mail->getUID() <<  " , Nth = " << (it->second.attachment)->getNth() );
+                       if ( mail->getUID() == mailId && nth == (it->second.attachment)->getNth())
+                       {
+                               Api::Messaging::EventMessagingServiceReqReceiver* requestReceiver = mail->getRequestReceiver();
+                               if ( mail && requestReceiver )
+                               {
+                                       Api::Messaging::EventMessagingServicePtr event = mail->getMessagingServiceEvent();
+
+                                       if (status == NOTI_DOWNLOAD_ATTACH_FINISH)
+                                       {
+                                               LogDebug(" Attachment Finish " );
+                                               const Api::Messaging::IAttachmentPtr& attachment = it->second.attachment;
+                                               if (attachment)
+                                               {
+
+                                                       email_attachment_data_t* attachment_data = NULL;
+                                                       int attachmentId = attachment->getAttachmentID();
+                                                       LogDebug("Attachment ID = " << attachmentId);
+
+                                                       int err = email_get_attachment_data(attachmentId, &attachment_data);
+                                                       if (err == EMAIL_ERROR_NONE) {
+                                                               LogDebug("attachment Name : " << attachment_data->attachment_name);
+                                                               LogDebug("attachment ID : " << attachment_data->attachment_id);
+                                                               attachment->init(attachment_data->attachment_path, false);
+                                                       }
+                                                       else
+                                                       {
+                                                               LogDebug("fail to email_get_attachment_data - err : " << err);
+                                                       }
+
+                                                       if ( attachment_data != NULL )
+                                                       {
+                                                               email_free_attachment_data(&attachment_data, 1);
+                                                       }
+
+                                               }
+
+                                       }
+                                       else
+                                       {
+                                               event->setExceptionCode( WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+                                               LogDebug(" Attachment Failed " );
+                                       }
+
+                                       LogDebug("remove downloadAttachment request");
+                                       LogDebug("handle : " << it->first );
+                                       requestReceiver->ManualAnswer(event);
+                                       m_SyncRequests.erase(it->first);
+
+                               }
+                               break;
+                       }
+               } 
+       }
+       else if ( status == NOTI_DOWNLOAD_ATTACH_START )
+       {
+               LogDebug("DownLoading... attachment : size = " << syncNetworkStatus->getErrorCode());
+               return;
+       }
+
+       SyncRequestIterator it = m_SyncRequests.find(handle);
+       if ( m_SyncRequests.end() != it)
+       {
+               int syncType = it->second.syncType;
+               LogDebug(" Sync ... handle : " << handle << " status : " << status << " SyncType: " << syncType);
+
+               switch(syncType)
+               {
+                       case MESSAGING_SERVICE_SYNC_TYPE_SYNC:
+                       {
+                               LogDebug(" Sync Account");
+                               const Api::Messaging::IMessagingServicePtr& messagingService = it->second.messagingService;
+                               Api::Messaging::EventMessagingServiceReqReceiver* requestReceiver = messagingService->getRequestReceiver();
+
+                               if ( messagingService && requestReceiver)
+                               {
+                                       Api::Messaging::EventMessagingServicePtr event = messagingService->getMessagingServiceEvent();
+                                       if ( status == NOTI_DOWNLOAD_FINISH )
+                                       {
+                                               LogDebug("Sync Success");
+                                               requestReceiver->ManualAnswer(event);
+                                               m_SyncRequests.erase( handle );
+                                       }
+                                       else if ( status == NOTI_DOWNLOAD_FAIL )
+                                       {
+                                               LogDebug("Sync Fail");
+                                               event->setExceptionCode( WrtDeviceApis::Commons::ExceptionCodes::UnknownException );
+                                               requestReceiver->ManualAnswer(event);
+                                               m_SyncRequests.erase( handle );
+                                       }
+                               }
+                               else
+                               {
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "request Receiver is NULL. ");
+                               }
+                               break;
+                       }
+                       case MESSAGING_SERVICE_SYNC_TYPE_SYNC_FOLDER:
+                       {
+                               LogDebug("Sync Folder");
+                               const Api::Messaging::IMessagingServicePtr& messagingService = it->second.messagingService;
+                               Api::Messaging::EventMessagingServiceReqReceiver* requestReceiver = messagingService->getRequestReceiver();
+
+                               if ( messagingService && requestReceiver)
+                               {
+                                       Api::Messaging::EventMessagingServicePtr event = messagingService->getMessagingServiceEvent();
+                                       if ( status == NOTI_DOWNLOAD_FINISH )
+                                       {
+                                               LogDebug("Sync Success");
+                                                       requestReceiver->ManualAnswer(event);
+                                               m_SyncRequests.erase( handle );
+                                       }
+                                       else if ( status == NOTI_DOWNLOAD_FAIL )
+                                       {
+                                               LogDebug("Sync Fail");
+                                               event->setExceptionCode( WrtDeviceApis::Commons::ExceptionCodes::UnknownException );
+                                               requestReceiver->ManualAnswer(event);
+                                               m_SyncRequests.erase( handle );
+                                       }
+                               }
+                               else
+                               {
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "request Receiver is NULL. ");
+                               }
+                               break;
+                       }
+                       case MESSAGING_SERVICE_SYNC_TYPE_DOWNLOAD_BODY:
+                       {
+                               LogDebug(" DownLoad Body");
+                               const Api::Messaging::IEmailPtr& mail = it->second.mail;        // IEmailPtr
+                               Api::Messaging::EventMessagingServiceReqReceiver* requestReceiver = mail->getRequestReceiver();
+                               if (mail && requestReceiver) {
+                                       Api::Messaging::EventMessagingServicePtr event = mail->getMessagingServiceEvent();
+                                       if ( status == NOTI_DOWNLOAD_BODY_FINISH )
+                                       {
+                                               event->m_message->readAllData();
+                                               requestReceiver->ManualAnswer(event);
+                                               m_SyncRequests.erase( handle );
+                                       }
+                                       else if ( status == NOTI_DOWNLOAD_BODY_FAIL )
+                                       {
+                                               event->setExceptionCode( WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+                                               requestReceiver->ManualAnswer(event);
+                                               m_SyncRequests.erase( handle );
+                                       }
+                               }
+                               else
+                               {
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "request Receiver is NULL. ");
+                               }
+                               break;
+                       }
+               }
+       }
+}
+
+int MailSync::downloadBodyInternal( const Api::Messaging::IEmailPtr& mail, int account_id)
+{
+       
+       LogDebug("downloadInternal");
+
+       int err = 0;
+       int mailId = mail->convertId(mail->getIdRef());
+       int email_handle = 0;
+       
+       LogDebug("folder type = " << mail->getCurrentFolder());
+       LogDebug("mail ID :" << mailId );
+
+       err = email_download_body(mailId, 0, &email_handle);
+       if (err != EMAIL_ERROR_NONE) {
+               LogDebug("fail to downloadBody - err : " << err);
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to initialize downloadBody request. [" << err << "]");
+       }
+       else
+       {
+               LogDebug("Insert downloadBody request");
+               LogDebug("handle : " << email_handle);
+               SyncRequestData data = SyncRequestData(email_handle,    MESSAGING_SERVICE_SYNC_TYPE_DOWNLOAD_BODY, mail);
+               m_SyncRequests.insert(std::make_pair(email_handle, data));
+       }
+
+       return email_handle;
+
+}
+
+int MailSync::downloadAttachmentInternal(const Api::Messaging::IEmailPtr& mail, int account_id, const Api::Messaging::IAttachmentPtr& attachment)
+{
+       LogDebug("downloadAttachmentInternal");
+       Assert(mail);
+       
+       int err = 0;
+       int nth = 0;
+       int mailId = mail->convertId(mail->getIdRef());
+       int email_handle = 0;
+       
+       email_mail_data_t* result = NULL;
+
+       int error;
+       error = email_get_mail_data(mailId, &result);
+       if (EMAIL_ERROR_NONE != error) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                "Couldn't find message " << mailId << ". [" << error << "]");
+       }
+
+       LogDebug("Attachment ID :" << attachment->getAttachmentID());   
+       
+       //get nth 
+       std::vector<Api::Messaging::IAttachmentPtr> attachments = mail->getAttachments();
+       std::vector<Api::Messaging::IAttachmentPtr> inlineAttachments = mail->getInlineAttachments();
+       unsigned int attachmentSize = attachments.size();
+       unsigned int inlineAttachmentSize = inlineAttachments.size();
+
+       LogDebug( "attachment sizes = " << attachmentSize << ",inline attachment size : " << inlineAttachmentSize);     
+       for ( unsigned int i = 0 ; i < attachmentSize ; i ++)
+       {
+               LogDebug( "attachment ID is = " << attachments[i]->getAttachmentID());
+               if (attachments[i]->getAttachmentID() == attachment->getAttachmentID())
+               {
+//                     nth = i;
+                       nth = attachments[i]->getNth();
+                       break;
+               }
+       }
+       for ( unsigned int i = 0 ; i < inlineAttachmentSize ; i ++)
+       {
+               LogDebug( "inline attachment ID is = " << inlineAttachments[i]->getAttachmentID());
+               if (inlineAttachments[i]->getAttachmentID() == attachment->getAttachmentID())
+               {
+//                     nth = i;
+                       nth = inlineAttachments[i]->getNth();
+                       break;
+               }
+       }
+
+       LogDebug("nth = " << nth);      
+       LogDebug("attachment Order Index = " << nth);
+       err = email_download_attachment(mailId, nth , &email_handle);
+       if (err != EMAIL_ERROR_NONE) {
+               LogDebug("fail to downloadAttachment - err : " << err);
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to initialize downloadAttachment request. [" << err << "]");
+       }
+       else
+       {
+               LogDebug("Insert downloadAttachment request");
+               LogDebug("handle : " << email_handle);
+               SyncRequestData data = SyncRequestData( email_handle,
+                       MESSAGING_SERVICE_SYNC_TYPE_DOWNLOAD_ATTACHMENT, mail, attachment );
+               m_SyncRequests.insert(std::make_pair(email_handle, data));
+       }
+
+       if ( result )
+               if  (  EMAIL_ERROR_NONE != email_free_mail_data( &result , 1) )
+                       LogDebug("fail to email_free_mail_data - err ");
+       
+       return email_handle;
+}
+
+void MailSync::cancelEmailJobInternal(int accountId, int handle)
+{
+       LogDebug("cancel Email Job, account : " <<accountId << " handle : " << handle);
+
+       int error = email_cancel_job(accountId, handle,EMAIL_CANCELED_BY_USER);
+       if (EMAIL_ERROR_NONE != error) {
+               LogDebug("error code : " << error );
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                "Couldn't cancel email job handle: " << handle);
+       }
+
+       m_SyncRequests.erase(handle);
+}
+
+
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/MailSync.h b/src/platform/Tizen/Messaging/MailSync.h
new file mode 100755 (executable)
index 0000000..4883f39
--- /dev/null
@@ -0,0 +1,185 @@
+//
+// 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 MAILSYNC_H_
+#define MAILSYNC_H_
+
+#include <map>
+#include <dpl/event/event_listener.h>
+#include <dpl/thread.h>
+#include <dpl/scoped_ptr.h>
+#include <DBus/Connection.h>
+#include <DBus/MessageEvent.h>
+#include <API/Messaging/IEmail.h>
+#include <API/Messaging/IAttachment.h>
+#include <API/Messaging/IMessagingService.h>
+#include <API/Messaging/IMessageFolder.h>
+
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+enum MessagingServiceSyncType
+{
+       MESSAGING_SERVICE_SYNC_TYPE_DOWNLOAD_BODY = 1,
+       MESSAGING_SERVICE_SYNC_TYPE_DOWNLOAD_ATTACHMENT,
+       MESSAGING_SERVICE_SYNC_TYPE_SYNC,
+       MESSAGING_SERVICE_SYNC_TYPE_SYNC_FOLDER,
+       MESSAGING_SERVICE_SYNC_TYPE_COUNT,
+};
+
+class MailSync : private DPL::Event::EventListener<DBus::MessageEvent>
+{
+       public :
+               static MailSync& getInstance();
+
+       public :
+               int downloadBody(const Api::Messaging::IEmailPtr& mail);        //downloadBody
+               void cancelDownloadBody(int handle);
+               int downloadAttachment(const Api::Messaging::IEmailPtr& mail, const Api::Messaging::IAttachmentPtr& attachment);
+               void cancelDownloadAttachment(int AttachmentId);
+               int syncAccount(const Api::Messaging::IMessagingServicePtr& messagingService, const int limit);
+               void syncAccountCancel(const int handle);
+               int syncFolder(const Api::Messaging::IMessagingServicePtr& messagingService, const int folder_id, const int limit);
+               void syncFolderCancel(const int handle);
+
+       protected:
+               void OnEventReceived(const DBus::MessageEvent& event);
+       
+       private:
+               
+               struct SyncBodyDownloadRequestData
+               {
+                       int handle;
+                       Api::Messaging::IEmailPtr mail;         //mail
+       
+                       explicit SyncBodyDownloadRequestData(const Api::Messaging::IEmailPtr& mail) :   
+                               handle(0),
+                               mail(mail)
+                       {
+                       }
+               };
+
+               struct SyncRequestData
+               {       
+                       int handle;
+                       int syncType;
+                       Api::Messaging::IEmailPtr mail;                                 //mail
+                       Api::Messaging::IAttachmentPtr attachment;              //attachment
+                       Api::Messaging::IMessagingServicePtr messagingService; //MessagingService
+                       int folderId;
+//                     std::string folderName;         //Folder
+                                                       //Type
+
+                       explicit SyncRequestData (
+                                       int handle,
+                                       int syncType,
+                                       const Api::Messaging::IEmailPtr& mail,
+                                       const Api::Messaging::IAttachmentPtr& attachment,
+                                       const Api::Messaging::IMessagingServicePtr& messagingService,
+                                       int folderId
+//                                     std::string& folderName
+                                       ) :
+                               handle(handle),
+                               syncType(syncType),
+                               mail(mail),
+                               attachment(attachment),
+                               messagingService(messagingService),
+                               folderId(folderId)
+//                             folderName(folderName)                          
+                       {
+                       }
+                       
+                       explicit SyncRequestData (
+                                       int handle,
+                                       int syncType,
+                                       const Api::Messaging::IMessagingServicePtr& messagingService) :
+                               handle(handle),
+                               syncType(syncType),
+                               messagingService(messagingService)
+                       {
+                       }
+
+                       explicit SyncRequestData (
+                                       int handle,
+                                       int syncType,
+                                       const Api::Messaging::IMessagingServicePtr& messagingService,
+                                       int folderId
+//                                     const std::string& folderName
+                                       ) :
+                               handle(handle),
+                               syncType(syncType),
+                               messagingService(messagingService),
+                               folderId(folderId)
+//                             folderName(folderName)
+                       {
+                       }
+
+                       explicit SyncRequestData (
+                                       int handle,
+                                       int syncType,
+                                       const Api::Messaging::IEmailPtr& mail) :
+                               handle(handle),
+                               syncType(syncType),
+                               mail(mail)
+                       {
+                       }
+                       explicit SyncRequestData (
+                                       int handle,
+                                       int syncType,
+                                       const Api::Messaging::IEmailPtr& mail,
+                                       const Api::Messaging::IAttachmentPtr& attachment
+                                       ) :
+                               handle(handle),
+                               syncType(syncType),
+                               mail(mail),
+                               attachment(attachment)
+                       {
+                       }
+
+               };
+
+               typedef std::map<int, SyncRequestData> SyncRequests;
+               typedef SyncRequests::iterator SyncRequestIterator;
+
+       private:
+               MailSync();
+               ~MailSync();
+
+       int syncAccountInternal(const Api::Messaging::IMessagingServicePtr& messagingService, const int limit);
+       int syncFolderInternal(const Api::Messaging::IMessagingServicePtr& messagingService, const int folder_id, const int limit);
+       int downloadBodyInternal( const Api::Messaging::IEmailPtr& mail, int account_id );
+       int downloadAttachmentInternal(const Api::Messaging::IEmailPtr& mail, int account_id, const Api::Messaging::IAttachmentPtr& attachment );
+       
+       void cancelEmailJobInternal(int accountId, int handle);
+
+       //void cancelDownloadAttachmentInternal( const SyncAttachmentDownloadRequests& data );  
+
+       private:
+               DPL::ScopedPtr<DPL::Thread> m_dbusThread;
+               DBus::ConnectionPtr m_dbus;
+               
+               SyncRequests m_SyncRequests;    
+               int m_default_slot_size;                //slot size
+};
+
+}
+}
+}
+
+#endif //MAILSYNC_H_
diff --git a/src/platform/Tizen/Messaging/MessageFolder.cpp b/src/platform/Tizen/Messaging/MessageFolder.cpp
new file mode 100755 (executable)
index 0000000..9036387
--- /dev/null
@@ -0,0 +1,139 @@
+//
+// 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 "MessageFolder.h"
+#include <CommonsJavaScript/JSUtils.h>
+#include <Commons/Exception.h>
+#include "MsgServiceHandleMgr.h"
+#include <API/Messaging/IMessaging.h>
+
+extern "C" {
+#include <msg.h>
+#include <msg_transport.h>
+}
+
+using namespace DPL;
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+       
+MessageFolder::MessageFolder()
+{
+}
+
+MessageFolder::MessageFolder(email_mailbox_t m_mailboxes)
+{
+       m_id = m_mailboxes.mailbox_id;  
+       m_parentid = -1;
+       m_accountid = m_mailboxes.account_id;
+       m_contentType = TYPE_EMAIL;
+       m_name = m_mailboxes.alias;
+       m_path = m_mailboxes.mailbox_name;
+       m_type = getFolderType(m_mailboxes.mailbox_type);
+       if(0 == m_mailboxes.local)
+       {
+               m_synchronizable = TRUE;
+       }else
+       {
+               m_synchronizable = FALSE;
+       }
+}
+
+MessageFolder::~MessageFolder()
+{
+}
+
+void MessageFolder::setName(std::string name)
+{
+       m_name = name;
+}
+void MessageFolder::setSynchronizable(bool synchronizable)
+{
+       m_synchronizable = synchronizable;
+}
+
+
+// getter
+unsigned long MessageFolder::getId()
+{
+       return m_id;
+}
+unsigned long MessageFolder::getParentId()
+{
+       return m_parentid;
+}
+unsigned long MessageFolder::getAccountId()
+{
+       return m_accountid;
+}
+unsigned short MessageFolder::getContentType()
+{
+       return m_contentType;
+}
+std::string MessageFolder::getName()
+{
+       return m_name;
+}
+std::string MessageFolder::getPath()
+{
+       return m_path;
+}
+unsigned short MessageFolder::getType()
+{
+       return m_type;
+}
+
+bool MessageFolder::getSynchronizable()
+{
+       return m_synchronizable;
+}
+
+int MessageFolder::getFolderType(email_mailbox_type_e folderType)
+{
+       if(EMAIL_MAILBOX_TYPE_INBOX == folderType)
+       {
+               return FOLDER_INBOX;
+       }
+       else if(EMAIL_MAILBOX_TYPE_SENTBOX == folderType)
+       {
+               return FOLDER_SENTBOX;
+       }
+       else if(EMAIL_MAILBOX_TYPE_DRAFT == folderType)
+       {
+               return FOLDER_DRAFTS;
+       }
+       else if(EMAIL_MAILBOX_TYPE_OUTBOX == folderType)
+       {
+               return FOLDER_OUTBOX;
+       }
+       else if(EMAIL_MAILBOX_TYPE_ALL_EMAILS != folderType)
+       {
+               return FOLDER_NOTSTANDARD;
+       }
+
+       return FOLDER_NOTSTANDARD;
+}
+
+
+}
+}
+}
+
diff --git a/src/platform/Tizen/Messaging/MessageFolder.h b/src/platform/Tizen/Messaging/MessageFolder.h
new file mode 100755 (executable)
index 0000000..5ee9bed
--- /dev/null
@@ -0,0 +1,91 @@
+//
+// 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 MESSAGEFOLDER_H
+#define MESSAGEFOLDER_H
+
+#include <dpl/shared_ptr.h>
+#include <map>
+#include <string>
+#include <vector>
+#include <API/Messaging/IMessageFolder.h>
+
+#include <email-types.h>
+
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+
+class MessageFolder : public Api::Messaging::IMessageFolder
+{
+public:        
+
+    typedef enum
+       {
+         FOLDER_INBOX = 1,
+         FOLDER_OUTBOX = 2,
+         FOLDER_DRAFTS = 3,
+         FOLDER_SENTBOX = 4,
+         FOLDER_NOTSTANDARD = 7,                 
+       } MsgFolder_FolerType;
+
+       typedef enum
+       {
+         TYPE_SMS = 1,
+         TYPE_MMS = 2,
+         TYPE_EMAIL = 3,
+         TYPE_CHAT = 4,
+       } MsgFolder_ContentType;        
+
+       MessageFolder();
+       MessageFolder(email_mailbox_t m_mailboxes);     
+       ~MessageFolder();
+
+       void setName(std::string name);
+       void setSynchronizable(bool synchronizable);
+       
+       unsigned long getId();
+       unsigned long getParentId();
+       unsigned long getAccountId();
+       unsigned short getContentType();
+       std::string getName();
+       std::string getPath();
+       unsigned short getType();
+       bool getSynchronizable();
+       int getFolderType(email_mailbox_type_e folderType);
+//     int convertFolderId(const string& arg) const;
+       
+private:       
+       unsigned long m_id;
+       unsigned long m_parentid;
+       unsigned long m_accountid;
+       unsigned short m_contentType;
+       std::string m_name;
+       std::string m_path;
+       unsigned short m_type;
+       bool m_synchronizable;
+
+};
+}
+}
+}
+
+#endif
+
diff --git a/src/platform/Tizen/Messaging/MessageQueryGenerator.cpp b/src/platform/Tizen/Messaging/MessageQueryGenerator.cpp
new file mode 100755 (executable)
index 0000000..0e112ea
--- /dev/null
@@ -0,0 +1,878 @@
+//
+// 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 "MessageQueryGenerator.h"
+#include "API/Messaging/MessageFilterValidatorFactory.h"
+#include "API/Messaging/ConversationFilterValidatorFactory.h"
+
+#include <API/Messaging/IMessagingTypes.h>
+#include <API/Messaging/log.h>
+#include <Commons/Exception.h>
+
+#include <email-types.h>
+#include <msg_storage_types.h>
+#include <sstream>
+#include <time.h>
+
+#include <dpl/log/log.h>
+
+using namespace std;
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+
+       namespace Platform {
+               namespace Messaging {
+
+               const std::string MessageQueryGenerator::STRING_MATCH_EXACTLY         = "EXACTLY";
+               const std::string MessageQueryGenerator::STRING_MATCH_CONTAINS        = "CONTAINS";
+               const std::string MessageQueryGenerator::STRING_MATCH_STARTSWITH      = "STARTSWITH";
+               const std::string MessageQueryGenerator::STRING_MATCH_ENDSWITH        = "ENDSWITH";
+//             const std::string MessageQueryGenerator::STRING_MATCH_CASESENSITIVE   = "CASESENSITIVE";
+
+               const std::string MessageQueryGenerator::STRING_WHERE   = "WHERE ";
+               const std::string MessageQueryGenerator::STRING_SUFFIX  = "";
+               const std::string MessageQueryGenerator::STRING_DIRECTION = "A.MSG_DIRECTION";
+
+               const int MessageQueryGenerator::MESSAGE_TYPE_NOT_INITIALIZED = -1;
+
+               MessageQueryGenerator::MessageQueryGenerator():m_messageType(MESSAGE_TYPE_NOT_INITIALIZED) {
+                       m_query.append(getQueryPrefix());
+
+                       m_limit     = 0;
+                       m_offset    = 0;
+                       m_mode = MODE_EMAIL;
+
+                       initAttributeMap();
+               }
+
+               MessageQueryGenerator::MessageQueryGenerator(const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset):
+                               m_messageType(MESSAGE_TYPE_NOT_INITIALIZED){
+                       LogDebug("<<< limit:" << limit << ", offset:" << offset);
+
+                       m_query.append(getQueryPrefix());
+
+                       //TODO check sort mode validation
+                       m_sortMode = sortMode;
+
+                       m_limit = limit;
+                       m_offset = offset;
+                       m_mode = MODE_EMAIL;
+
+                       initAttributeMap();
+               }
+
+               MessageQueryGenerator::MessageQueryGenerator(const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset, const int type):
+                       m_messageType(MESSAGE_TYPE_NOT_INITIALIZED){
+                       LogDebug("<<< limit:" << limit << ", offset:" << offset);
+                       m_query.append(getQueryPrefix());
+
+                       //TODO check sort mode validation
+                       m_sortMode = sortMode;
+
+                       m_limit = limit;
+                       m_offset = offset;
+                       m_serviceType = type;
+                       
+                       if(type == Api::Messaging::SMS)
+                       {
+                               m_mode = MODE_SMS;
+                       }
+                       else if(type == Api::Messaging::MMS)
+                       {
+                               m_mode = MODE_MMS;
+                       }
+                       else
+                       {
+                               m_mode = MODE_EMAIL;
+                       }
+
+                       initAttributeMap();
+               }
+                               
+
+               MessageQueryGenerator::~MessageQueryGenerator() {
+               }
+
+               void MessageQueryGenerator::reset(QueryGeneratorMode mode){
+                       m_query.clear();
+                       m_queryVector.clear();
+
+                       m_limit     = 0;
+                       m_offset    = 0;
+                       m_mode      = mode;
+
+                       m_query.append(getQueryPrefix());
+
+                       initAttributeMap();
+               }
+
+               void MessageQueryGenerator::setEmailAttributeMap(){
+                       attributeMap.clear();
+
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_ID,             "mail_id"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_SERVICE_ID,      "account_id"));                       
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_FOLDER,          "mailbox_id"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP,       "date_time"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_FROM,            "full_address_from"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_TO,              "full_address_to"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_CC,              "full_address_cc"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_BCC,             "full_address_bcc"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_BODY,            "preview_text"));             //TODO check
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_IS_READ,          "mail_status"));     //TODO 1:seen, 2:deleted, 4:flagged, 8:answered, 20:draft
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_PRIORITY,         "isHighPriority"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_SUBJECT,          "subject"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_ATTACHMENT,    "attachment_count"));   
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_TYPE,             "type"));
+
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       ConversationFilterValidatorFactory::ATTRIBUTE_MESSAGE_COUNT,  "thread_item_count"));
+               }
+
+               void MessageQueryGenerator::setSmsMmsAttributeMap(){
+                       LogDebug("<<<");
+                       attributeMap.clear();
+
+                       attributeMap.insert(
+                                                                                                               std::pair<std::string, std::string>(
+                                                                                                                               MessageFilterValidatorFactory::ATTRIBUTE_ID,          "A.MSG_ID"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_FOLDER,          "A.FOLDER_ID"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP,       "A.DISPLAY_TIME"));
+//TODO check sms mms attribute frome, to, cc, bcc
+                                               attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_FROM,            "B.ADDRESS_VAL"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_TO,              "B.ADDRESS_VAL"));
+//                     attributeMap.insert(
+//                                                                                     std::pair<std::string, std::string>(
+//                                                                                                     MessageFilterValidatorFactory::ATTRIBUTE_CC,              "full_address_cc"));
+//                     attributeMap.insert(
+//                                                                                     std::pair<std::string, std::string>(
+//                                                                                                     MessageFilterValidatorFactory::ATTRIBUTE_BCC,             "full_address_bcc"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_BODY,            "A.MSG_TEXT"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_IS_READ,          "A.READ_STATUS"));   //TODO 1:seen, 2:deleted, 4:flagged, 8:answered, 20:draft
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_PRIORITY,         "A.PRIORITY"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_SUBJECT,          "A.SUBJECT"));
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_ATTACHMENT,    "A.ATTACHMENT_COUNT"));                 
+                       attributeMap.insert(
+                                                                                       std::pair<std::string, std::string>(
+                                                                                                       MessageFilterValidatorFactory::ATTRIBUTE_TYPE,             "A.MAIN_TYPE"));
+
+                       LogDebug(">>");
+               }
+
+               void MessageQueryGenerator::initAttributeMap(){
+                       switch (m_mode){
+                               case MODE_EMAIL:
+                                       LogDebug("MODE_EMAIL");
+                                       setEmailAttributeMap();
+                                       break;
+                               case MODE_SMS:
+                               case MODE_MMS:
+                                       LogDebug("MODE_SMS or MODE_MMS");
+                                       setSmsMmsAttributeMap();
+                                       break;
+                               default: //TODO throw exception
+                                       ;
+                       }
+               }
+
+               void MessageQueryGenerator::visitPreComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+                       m_queryVector.push_back("(");
+                       LogDebug("getServiceType = " << getServiceType());                      
+                       LogDebug(">>>");
+               }
+
+               void MessageQueryGenerator::visitInComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+
+                       if(m_typeProcessing == 1){
+                               m_typeProcessing = 0;
+
+                               if(type != INTERSECTION_FILTER){
+                                       LogError("[ERROR] >>> invalid Filter type:" << type);
+                                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid Fiilter Type");
+                               }
+
+                               LogDebug(">>>");
+                               if(m_mode == MODE_EMAIL)
+                               {
+                                       return;
+                               }
+                       }
+
+                       if(type == INTERSECTION_FILTER){
+                               m_queryVector.push_back("AND");
+                       }
+//                     else if(type == UNION_FILTER){
+//                             m_queryVector.push_back("OR");
+//                     }
+                       else{
+                               LogError("[ERROR] invalid Filter type:" << type);
+                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid Fiilter Type");
+                       }
+
+                       LogDebug(">>>");
+               }
+
+               void MessageQueryGenerator::visitPostComposite(Api::Tizen::FilterType& type, int depth){
+                       LogDebug("<<<");
+                       if(m_typeProcessing == 1){
+                               m_typeProcessing = 0;
+                               if(m_mode == MODE_EMAIL)
+                               {
+                                       m_queryVector.erase(m_queryVector.end());
+                               }
+                       }else{
+                       }
+
+                       m_queryVector.push_back(")");
+                       LogDebug(">>>");
+               }
+
+               std::string MessageQueryGenerator::convertToEmfAttrName(std::string attrName){
+                       LogDebug("<<< attrName:[" << attrName << "]");
+
+                       std::string retString;
+
+                       std::map<std::string, std::string>::iterator it = attributeMap.find(attrName);
+                       if(it == attributeMap.end()){
+                               MsgLogWanning("[WANNING] attribute not found : ["<< attrName << "]");
+                       }else{
+                               retString = static_cast<std::string>(attributeMap.find(attrName)->second);
+                       }
+
+                       LogDebug(">> retString:[" << retString << "]");
+                       return retString;
+               }
+
+               std::string MessageQueryGenerator::createTimeString(std::string& timeString)
+               {
+                       LogDebug("<<< timeString:[" << timeString << "]");
+
+                       size_t pos = timeString.find("-",0);
+                       while(pos!= std::string::npos){
+                               timeString.erase(pos,1);
+                               pos = timeString.find('-',0);
+                       }
+
+                       LogDebug(">>> timeString:[" << timeString << "]");
+                       return timeString;
+               }
+
+               std::string MessageQueryGenerator::createFolderType(std::string& value)
+               {
+                       LogDebug("<<< value:[" << value << "]");
+                       std::string retFolderType;
+                       std::ostringstream outstream;
+
+                       if(value.compare("1") == 0){
+                               LogDebug("<<< value:[INBOX]");
+                               outstream << MSG_INBOX_ID;
+                       }else if(value.compare("2") == 0){
+                               LogDebug("<<< value:[OUTBOX]");                 
+                               outstream << MSG_OUTBOX_ID;
+                       }else if(value.compare("3") == 0){
+                               LogDebug("<<< value:[DRAFTBOX]");                       
+                               outstream << MSG_DRAFT_ID;
+                       }else if(value.compare("4") == 0){
+                               LogDebug("<<< value:[SENTBOX]");                        
+                               outstream << MSG_SENTBOX_ID;
+                       }else{
+                               LogDebug("[ERROR] unsupported type:["<< value << "]");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid folder id");
+                       }
+
+                       retFolderType = outstream.str();
+
+                       LogDebug(">>> retFolderType:[" << retFolderType << "]");
+                       return retFolderType;
+               }
+
+               std::string MessageQueryGenerator::createPriorityTypeForEmail(std::string& value)
+               {
+                       LogDebug("<<< value:[" << value << "]");
+                       std::string retPriorityType;
+
+                       if(value.compare("true")==0){
+                               retPriorityType = "1";
+                       }else{
+                               retPriorityType = "3 OR priority=5";
+                       }
+
+                       return retPriorityType;
+               }
+
+               std::string MessageQueryGenerator::createPriorityTypeForSmsMms(std::string& value){
+                       LogDebug("<<< value:[" << value << "]");
+                       std::string retPriorityType;
+
+                       if(value.compare("true")==0){
+                               retPriorityType = "1";
+                       }else if(value.compare("false")==0){
+                               retPriorityType = "0";
+                       }else{
+                               LogError(">>> invalid value:[" << value << "]");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "unsupported value");
+                       }
+
+                       return retPriorityType;
+               }
+
+
+               std::string MessageQueryGenerator::convertToTimeFormat(const std::string& timeString){
+                       LogDebug("<<< timeString:[" << timeString << "]");
+
+                       std::string retString;
+                       retString.append("'");
+
+                       int yearLength = 4;
+                       int nextStart = 0;
+                       retString.append(timeString.substr(0, yearLength));
+                       retString.append("-");
+                       nextStart = nextStart + yearLength;
+
+                       int monthLength = 2;
+                       retString.append(timeString.substr(nextStart, monthLength));
+                       retString.append("-");
+                       nextStart = nextStart + monthLength;
+
+                       int dateLength = 2;
+                       retString.append(timeString.substr(nextStart, dateLength));
+                       retString.append(" ");
+                       nextStart = nextStart + dateLength;
+
+                       int hourLength = 2;
+                       retString.append(timeString.substr(nextStart, hourLength));
+                       retString.append(":");
+                       nextStart = nextStart + hourLength;
+
+                       int minuteLength = 2;
+                       retString.append(timeString.substr(nextStart, minuteLength));
+                       retString.append(":");
+                       nextStart = nextStart + minuteLength;
+
+                       int secondLength = 2;
+                       retString.append(timeString.substr(nextStart, secondLength));
+                       retString.append("'");
+
+                       LogDebug(">>> retString:[" << retString << "]");
+                       return retString;
+               }
+
+               //convert from '20111115000000' to 2011-11-15 00:00:00
+               std::string MessageQueryGenerator::createDateTimeTypeForSmsMms(Api::Tizen::AnyPtr& value){
+                       std::string initialValueStr;
+                       LogDebug("<<< value:[" << value->toString() << "]");
+
+                       if (!value->isNullOrUndefined()) {
+                               if( TizenApis::Api::Tizen::PrimitiveType_Time==value->getType() ) {
+                                       LogDebug("<<<initialValue->getType()[" << value->getType() <<"]");                                      
+                                       tm date = value->getDateTm();
+                                       initialValueStr = toDateDbStr(date);
+                                       LogDebug("<<<valueStr[" << initialValueStr <<"]");
+                               }
+                               else {
+                                       LogError("initialValue->getType() : [" << value->getType() << "]");                                     
+                                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid value Type");
+                               }                               
+                       }
+
+                       std::string tmpValueString = initialValueStr;
+                       std::string secondsSinceType;
+                       secondsSinceType.append("strftime('%s', ");                     //SQL time format function
+                       if(m_mode == MODE_SMS || m_mode == MODE_MMS ){
+                               tmpValueString = convertToTimeFormat(tmpValueString);
+                       }
+
+                       secondsSinceType.append(tmpValueString);
+                       secondsSinceType.append(")");
+
+                       LogDebug(">>> retPriorityType:[" << secondsSinceType << "]");
+                       return secondsSinceType;
+               }
+
+               std::string MessageQueryGenerator::createDateTimeTypeForSmsMms(std::string& timeString){
+                       LogDebug("<<< value:[" << timeString << "]");
+
+                       std::string tmpValueString;
+                       std::string secondsSinceType;
+                       secondsSinceType.append("strftime('%s', ");                     //SQL time format function
+                       if(m_mode == MODE_SMS || m_mode == MODE_MMS ){
+                               tmpValueString = convertToTimeFormat(timeString);
+                       }
+
+                       secondsSinceType.append(tmpValueString);
+                       secondsSinceType.append(")");
+
+                       LogDebug(">>> retPriorityType:[" << secondsSinceType << "]");
+                       return secondsSinceType;
+               }
+
+               std::string MessageQueryGenerator::createDateTimeTypeForEmail(Api::Tizen::AnyPtr& value)
+               {
+                       std::string initialValueStr;
+                       LogDebug("<<< value:[" << value->toString() << "]");
+
+                       if(value->getType() != PrimitiveType_Time){
+                               LogError("[ERROR]>> invalid type");
+                               return NULL;
+                       }
+                               
+                       if (!value->isNullOrUndefined()) {
+                               if( TizenApis::Api::Tizen::PrimitiveType_Time==value->getType() ) {
+                                       LogDebug("<<<initialValue->getType()[" << value->getType() <<"]");                                      
+                                       tm date = value->getDateTm();
+                                       initialValueStr = toDateDbStr(date);
+                                       LogDebug("<<<valueStr[" << initialValueStr <<"]");
+                               }
+                               else {
+                                       LogError("initialValue->getType() : [" << value->getType() << "]");                                     
+                                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid value Type");
+                               }                               
+                       }
+                       return initialValueStr;
+               }
+
+               std::string MessageQueryGenerator::toDateDbStr(const tm &date) const
+               {
+                       stringstream ss;
+                       ss << setfill('0') << setiosflags(ios::right) << setw(4) << (date.tm_year + 1900);
+                       ss << setfill('0') << setiosflags(ios::right) << setw(2) << (date.tm_mon + 1);
+                       ss << setfill('0') << setiosflags(ios::right) << setw(2) << date.tm_mday;
+                       ss << setfill('0') << setiosflags(ios::right) << setw(2) << date.tm_hour;
+                       ss << setfill('0') << setiosflags(ios::right) << setw(2) << date.tm_min;
+                       ss << setfill('0') << setiosflags(ios::right) << setw(2) << date.tm_sec;
+                       return ss.str();
+               }
+
+               std::string MessageQueryGenerator::convertBooleanStringToIntegerString(std::string& booleanString){
+                       std::string retString;
+
+                       if(booleanString.compare("true") == 0){
+                               retString = "1";
+                       }else if(booleanString.compare("false") == 0){
+                               retString = "0";
+                       }else{
+                               LogError("invalid booleanString:[" << booleanString << "]");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid booleanString :[" + booleanString + "]");
+                       }
+                       return retString;
+               }
+
+               std::string MessageQueryGenerator::getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value)
+               {
+                       std::string retClause;
+                       std::string valueString = value->toString();
+                       std::string emfAttributeName = convertToEmfAttrName(attrName);
+
+                       do{
+                               if(m_mode == MODE_EMAIL){
+                                       if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_FROM)==0){
+                                               retClause = emfAttributeName + " LIKE '%%<" + valueString +">'";
+                                               break;
+                                       }else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP)==0){
+                                               retClause = emfAttributeName + "=" + createDateTimeTypeForEmail(value);
+                                               break;
+                                       }else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_PRIORITY)==0){
+                                               retClause = emfAttributeName + "=" + createPriorityTypeForEmail(valueString);
+                                               break;
+                                       }else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_SERVICE_ID)==0){
+                                               retClause = emfAttributeName + "=" + valueString;
+                                               break;
+                                       } else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_FOLDER)==0) {
+                                               retClause = emfAttributeName + "=" + valueString;
+                                               break;
+                                       }
+                               }else if(m_mode == MODE_SMS || m_mode == MODE_MMS ){
+                                       if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_FROM)==0){
+                                               retClause = "("+emfAttributeName + " ='"+ valueString + "' AND " + getMessageDirectionString() + "=1)";
+                                               break;
+                                       }else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TO)==0){
+                                               retClause = "("+emfAttributeName + " ='"+ valueString + "' AND " + getMessageDirectionString() + "=0)";
+                                               break;
+                                       }else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP)==0){
+                                               retClause = emfAttributeName + "=" + createDateTimeTypeForSmsMms(value); //TODO need to check
+                                               break;
+                                       }else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_PRIORITY)==0){
+                                               retClause = emfAttributeName + "=" + createPriorityTypeForSmsMms(valueString);
+                                               break;
+                                       } else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_FOLDER)==0) {
+                                               retClause = emfAttributeName + "=" + createFolderType(valueString);
+                                               break;
+                                       } else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TYPE)==0) {
+                                               retClause = emfAttributeName + "=" + convertMessageTypeToString(valueString);
+                                               break;
+                                       }
+
+                               }
+
+                               if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_IS_READ)==0) {
+                                       retClause = emfAttributeName + "=" + convertBooleanStringToIntegerString(valueString);
+                               } else if (attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_ATTACHMENT) == 0 ) {
+                                       if(valueString.compare("true") == 0){
+                                               retClause = emfAttributeName + " > 0" ;
+                                       } else {
+                                               retClause = emfAttributeName + " = 0" ;
+                                       }
+                               } else {
+                                       retClause = emfAttributeName + " = '" + value->toString() + "'"; //TODO need to check
+                               }
+                       }while(false);
+
+                       return retClause;
+               }
+
+               std::string MessageQueryGenerator::getMatchStartsWithClause(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& value){
+                       std::string retClause;
+                       std::string valueString = value->toString();
+                       std::string emfAttributeName = convertToEmfAttrName(attrName);
+
+                       do{
+                               if(m_mode == MODE_EMAIL){
+                               }else if(m_mode == MODE_SMS || m_mode == MODE_MMS){
+                                       if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_FROM)==0){
+                                               retClause.append("(" + emfAttributeName + " LIKE '" + value->toString() +
+                                                               "%%' AND " + getMessageDirectionString() + "=1) ");
+                                               break;
+                                       }else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TO)==0){
+                                               retClause.append("(" + emfAttributeName + " LIKE '" + value->toString() +
+                                                               "%%' AND " + getMessageDirectionString() +"=0) ");
+                                               break;
+                                       }
+                               }
+
+                               retClause.append(emfAttributeName + " LIKE '" + value->toString() +"%%'");
+                       }while(false);
+
+                       return retClause;
+               }
+
+               std::string MessageQueryGenerator::getMessageDirectionString(){
+                       return MessageQueryGenerator::STRING_DIRECTION;
+               }
+
+               std::string MessageQueryGenerator::getMatchEndsWithClause(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& value){
+                       std::string retClause;
+                       std::string valueString = value->toString();
+                       std::string emfAttributeName = convertToEmfAttrName(attrName);
+
+                       do{
+                               if(m_mode == MODE_EMAIL){
+                               }else if(m_mode == MODE_SMS || m_mode == MODE_MMS){
+                                       if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_FROM)==0){
+                                               retClause.append("(" + emfAttributeName + " LIKE '%%" + value->toString() +
+                                                               "' AND "+ getMessageDirectionString() + "=1) ");
+                                               break;
+                                       }else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TO)==0){
+                                               retClause.append("(" + emfAttributeName + " LIKE '%%" + value->toString() +
+                                                               "' AND " + getMessageDirectionString() + "=0) ");
+                                               break;
+                                       }
+                               }
+
+                               retClause.append(emfAttributeName + " LIKE '%%" + value->toString() +"'");
+                       }while(false);
+
+                       return retClause;
+               }
+
+               std::string MessageQueryGenerator::getMatchContainsClause(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& value){
+                       std::string retClause;
+                       std::string valueString = value->toString();
+                       std::string emfAttributeName = convertToEmfAttrName(attrName);
+
+                       do{
+                               if(m_mode == MODE_EMAIL){
+                               }else if(m_mode == MODE_SMS || m_mode == MODE_MMS){
+                                       if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_FROM)==0){
+                                               retClause.append("(" + emfAttributeName + " LIKE '%%" + value->toString() +
+                                                               "%%' AND " + getMessageDirectionString() + "=1) ");
+                                               break;
+                                       }else if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TO)==0){
+                                               retClause.append("(" + emfAttributeName + " LIKE '%%" + value->toString() +
+                                                               "%%' AND " + getMessageDirectionString() + "=0) ");
+                                               break;
+                                       }
+                               }
+
+                               retClause.append(emfAttributeName + " LIKE '%%" + value->toString() +"%%'");
+                       }while(false);
+
+                       return retClause;
+               }
+
+               void MessageQueryGenerator::visitAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                               Api::Tizen::AnyPtr& matchValue, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]");
+
+                       if(matchValue == NULL)
+                               return;
+
+                       LogDebug("matchValue:" << matchValue->toString());
+
+                       visitAttributeEach(attrName, matchFlag, matchValue, depth);
+
+                       LogDebug(">>>");
+               }
+
+               int MessageQueryGenerator::convertMessageType(std::string& stringType){
+                       LogDebug("<<< stringType:[" << stringType << "]");
+
+                       int retMessageType = -1;
+
+                       if(stringType.compare("messaging.sms") ==0){
+                               retMessageType = Api::Messaging::SMS;
+                       }else if(stringType.compare("messaging.mms") ==0){
+                               retMessageType = Api::Messaging::MMS;
+                       }else if(stringType.compare("messaging.email") ==0){
+                               retMessageType = Api::Messaging::EMAIL;
+                       }else{
+                               MsgLogError("invalid type:[" << stringType << "]");
+                               return -1;
+                       }
+
+                       LogDebug(">>> retMessageType:" << retMessageType);
+                       return retMessageType;
+               }
+
+
+               std::string MessageQueryGenerator::convertMessageTypeToString(std::string& stringType){
+                       LogDebug("<<< value:[" << stringType << "]");
+                       std::string retMessageType;
+                       std::ostringstream outstream;
+
+                       if(stringType.compare("messaging.sms") ==0){
+                               outstream << Api::Messaging::SMS;
+                       }else if(stringType.compare("messaging.mms") ==0){
+                               outstream << Api::Messaging::MMS;
+                       }else if(stringType.compare("messaging.email") ==0){
+                               outstream << Api::Messaging::EMAIL;
+                       }else{
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid msg type");
+                       }
+
+                       retMessageType = outstream.str();
+                       
+                       return retMessageType;
+               }
+
+               void MessageQueryGenerator::visitAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth){
+                       LogDebug("<<< attrName:[" << attrName << "], value:[" << value->toString() << "]");
+
+                       if(attrName.compare("type")==0){
+                               m_typeProcessing = 1;
+                               m_currentType = value->toString();
+
+                               m_messageType = convertMessageType(m_currentType);
+                               if(m_messageType == Api::Messaging::EMAIL)
+                               {
+                                       LogDebug(">>> skip type");
+                                       return;
+                               }
+                       }
+
+                       std::string emfAttributeName = convertToEmfAttrName(attrName);
+
+//                     if(emfAttributeName == NULL){
+//                             LogDebug(">>> emfAttributeName is NULL");
+//                             return;
+//                     }
+                       std::string tmpStringBuffer;
+
+                       if(matchFlag == Api::Tizen::MATCH_EXACTLY){
+                               LogDebug("STRING_MATCH_EXACTLY");
+                               tmpStringBuffer.append(getMatchExactlyClause(attrName, value));
+                       }else if(matchFlag == Api::Tizen::MATCH_CONTAINS){
+                               LogDebug("STRING_MATCH_CONTAINS");
+                               tmpStringBuffer.append(getMatchContainsClause(attrName, value));
+                       }else if(matchFlag == Api::Tizen::MATCH_STARTSWITH){
+                               LogDebug("STRING_MATCH_STARTSWITH");
+                               tmpStringBuffer.append(getMatchStartsWithClause(attrName, value));
+                       }else if(matchFlag == Api::Tizen::MATCH_ENDSWITH){
+                               LogDebug("STRING_MATCH_ENDSWITH");
+                               tmpStringBuffer.append(getMatchEndsWithClause(attrName, value));
+                       }else{
+                               LogDebug("[ERROR]invalid match flag[" << matchFlag << "]");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "invalid match flag:[" << matchFlag << "]");
+                       }
+//                             else if(iter->find(MATCH_CASESENSITIVE)){               //TODO check case sensitive
+//                             }
+                       m_queryVector.push_back(tmpStringBuffer);
+                       LogDebug(">>>");
+               }
+
+               void MessageQueryGenerator::visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth) {
+                       LogDebug("<<< sttrName:[" << attrName <<"]");
+
+                       string initialValueStr;
+                       string endValueStr;
+
+                       if(initialValue == NULL || endValue == NULL)
+                               return;
+                       
+                       std::string tmpStringBuffer;
+
+                       std::string emfAttributeName = convertToEmfAttrName(attrName);
+                       if(attrName.compare(MessageFilterValidatorFactory::ATTRIBUTE_TIMESTAMP)==0){
+
+                               if (!initialValue->isNullOrUndefined()) {
+                                       if( TizenApis::Api::Tizen::PrimitiveType_Time==initialValue->getType() ) {
+                                               LogDebug("<<<initialValue->getType()[" << initialValue->getType() <<"]");                                       
+                                               tm date = initialValue->getDateTm();
+                                               initialValueStr = toDateDbStr(date);
+                                               LogDebug("<<<valueStr[" << initialValueStr <<"]");
+                                       }
+                                       else {
+                                               LogError("initialValue->getType() : [" << initialValue->getType() << "]");                                      
+                                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid initialValue Type");
+                                       }
+                               }
+                               
+                               if (!endValue->isNullOrUndefined()) {
+                                       if( TizenApis::Api::Tizen::PrimitiveType_Time==endValue->getType() ) {
+                                               LogDebug("<<<initialValue->getType()[" << endValue->getType() <<"]");                                   
+                                               tm date = endValue->getDateTm();
+                                               endValueStr = toDateDbStr(date);
+                                       } else {
+                                               LogError("endValue->getType() : [" << endValue->getType() << "]");                                      
+                                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid endValue Type");
+                                       }
+                               }
+
+                               
+                               if(m_mode == MODE_EMAIL){
+                                       tmpStringBuffer.append(emfAttributeName + " BETWEEN " + initialValueStr + " AND " + endValueStr);
+                               }else if(m_mode == MODE_SMS || m_mode == MODE_MMS){
+                                       tmpStringBuffer.append(emfAttributeName + " BETWEEN " +
+                                                       createDateTimeTypeForSmsMms(initialValueStr) + " AND " +
+                                                       createDateTimeTypeForSmsMms(endValueStr));
+                               }
+                       }
+
+                       m_queryVector.push_back(tmpStringBuffer);
+                       LogDebug(">>>");
+               }
+
+               std::string MessageQueryGenerator::getQueryFromVector()
+               {
+                       std::string retString;
+
+                       std::vector<string>::const_iterator it = m_queryVector.begin();
+                       while(it != m_queryVector.end()){
+                               retString.append(*it);
+                               retString.append(" ");
+                               it++;
+                       }
+
+                       LogDebug(">>> retString:" << retString);
+                       return retString;
+               }
+
+               std::string MessageQueryGenerator::getQuery(){
+                       std::stringstream buffer;
+
+                       m_query.append(getQueryFromVector());
+
+                       if(m_query.compare(getQueryPrefix())==0){
+                               return "";
+                       }else{
+                               if(m_sortMode != NULL){
+                                       std::string platformAttrName = convertToEmfAttrName(m_sortMode->getAttributeName());
+                                       std::string sortModeString;
+                                       if(m_sortMode->getOrder() == ASCENDING_SORT_ORDER){
+                                               sortModeString = "ASC";
+                                       }else{
+                                               sortModeString = "DESC";
+                                       }
+
+                                       buffer << " ORDER BY " << platformAttrName << " " << sortModeString;
+                                       if(m_limit != 0){
+                                               buffer << " LIMIT "  << m_offset  << "," << m_limit;
+                                       }
+                               }
+
+                               m_query.append(getQuerySuffix());
+//                             m_query.append(buffer.str());
+                               m_orderLimit.append(buffer.str());
+                               return m_query;
+                       }
+               }
+
+               std::string MessageQueryGenerator::getOrderLimit(){
+                       return m_orderLimit;
+               }
+
+               std::string MessageQueryGenerator::getQueryPrefix(){
+                       return MessageQueryGenerator::STRING_WHERE;
+               }
+
+               std::string MessageQueryGenerator::getQuerySuffix(){
+                       return MessageQueryGenerator::STRING_SUFFIX;
+               }
+
+
+
+               }
+       }               //namespace Platform
+}              //namespace WrtPlugins
diff --git a/src/platform/Tizen/Messaging/MessageQueryGenerator.h b/src/platform/Tizen/Messaging/MessageQueryGenerator.h
new file mode 100755 (executable)
index 0000000..8d89724
--- /dev/null
@@ -0,0 +1,148 @@
+//
+// 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 MESSAGEQUERYGENERATOR_H_
+#define MESSAGEQUERYGENERATOR_H_
+
+#include <API/Filter/IFilterVisitor.h>
+#include <API/Filter/SortMode.h>
+
+#include <map>
+
+namespace TizenApis {
+       namespace Platform {
+               namespace Messaging {
+
+               class MessageQueryGenerator: public TizenApis::Api::Tizen::IFilterVisitor{
+
+                       public:
+                               enum QueryGeneratorMode{
+                                       MODE_EMAIL,
+                                       MODE_SMS,
+                                       MODE_MMS
+                               };
+
+                       protected:
+                               std::map<std::string, std::string> attributeMap;
+
+                       private:
+                               QueryGeneratorMode m_mode;
+                               std::string m_query;
+                               std::string m_orderLimit;                               
+                               std::vector<std::string> m_queryVector;
+
+                               int m_messageType;
+                               int m_serviceType;
+
+                               std::vector<std::string> typeVector;
+
+                               Api::Tizen::SortModePtr m_sortMode;
+                               long m_limit;
+                               long m_offset;
+
+                               int m_typeProcessing;
+                               std::string m_currentType;
+
+                               static const std::string STRING_MATCH_EXACTLY;
+                               static const std::string STRING_MATCH_CONTAINS;
+                               static const std::string STRING_MATCH_STARTSWITH;
+                               static const std::string STRING_MATCH_ENDSWITH;
+                               static const std::string STRING_MATCH_CASESENSITIVE;
+                               static const std::string STRING_WHERE;
+                               static const std::string STRING_SUFFIX;
+                               static const std::string STRING_DIRECTION;
+
+                               static const int MESSAGE_TYPE_NOT_INITIALIZED;
+
+                       public:
+                               MessageQueryGenerator();
+                               MessageQueryGenerator(const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset);
+                               MessageQueryGenerator(const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset, const int type);                            
+                               virtual ~MessageQueryGenerator();
+
+                               void visitPreComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitInComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitPostComposite(Api::Tizen::FilterType& type, int depth);
+                               void visitAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag,
+                                               Api::Tizen::AnyPtr& matchValue, int depth);
+                               void visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth);
+
+                               std::string getQuery();
+                               std::string getOrderLimit();                            
+
+//                             bool containMailType();
+//                             bool containType(int type);
+                               int getMessageType(){
+                                       return m_messageType;
+                               };
+
+                               void setMode(QueryGeneratorMode mode ){
+                                       m_mode = mode;
+                               }
+
+                               QueryGeneratorMode getMode(){
+                                       return m_mode;
+                               }
+
+                               int getServiceType(){
+                                       return m_serviceType;
+                               }                               
+
+                               void reset(QueryGeneratorMode mode);
+
+                       protected:
+                               virtual void setEmailAttributeMap();
+                               virtual void setSmsMmsAttributeMap();
+                               virtual std::string getMatchExactlyClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               virtual std::string getQueryPrefix();
+                               virtual std::string getQuerySuffix();
+                               virtual std::string getMessageDirectionString();
+
+                               std::string convertToEmfAttrName(std::string attrName);
+
+                               void visitAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth);
+                               std::string convertMessageTypeToString(std::string& stringType);                                
+
+                       private:
+                               std::string getMatchStartsWithClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               std::string getMatchEndsWithClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+                               std::string getMatchContainsClause(std::string& attrName, Api::Tizen::AnyPtr& value);
+
+                               std::string createTimeString(std::string& timeString);
+                               std::string createFolderType(std::string& value);
+                               std::string createPriorityTypeForEmail(std::string& value);
+                               std::string createPriorityTypeForSmsMms(std::string& value);
+                               std::string createDateTimeTypeForEmail(Api::Tizen::AnyPtr& value);
+
+                               std::string createDateTimeTypeForSmsMms(Api::Tizen::AnyPtr& value);
+                               std::string createDateTimeTypeForSmsMms(std::string& timeString);                               
+
+                               std::string convertToTimeFormat(const std::string& timeString);
+                               std::string convertBooleanStringToIntegerString(std::string& booleanString);
+                               std::string toDateDbStr(const std::tm &date) const;
+
+                               void initAttributeMap();
+                               std::string getQueryFromVector();
+
+                               int convertMessageType(std::string& stringType);
+               };
+
+               typedef DPL::SharedPtr<MessageQueryGenerator> MessageQueryGeneratorPtr;
+       }               // namespace Platform
+} // namespace WrtPlugins
+}
+#endif /* MESSAGEQUERYGENERATOR_H_ */
diff --git a/src/platform/Tizen/Messaging/Messaging.cpp b/src/platform/Tizen/Messaging/Messaging.cpp
new file mode 100755 (executable)
index 0000000..d7805f2
--- /dev/null
@@ -0,0 +1,2631 @@
+//
+// 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 <email-types.h>
+#include <email-api.h>
+
+#include <Commons/Exception.h>
+#include <Commons/StringUtils.h>
+#include <dpl/log/log.h>
+#include <dpl/scoped_free.h>
+#include "Messaging.h"
+#include "Sms.h"
+#include "Mms.h"
+#include "BinarySms.h"
+#include "Email.h"
+#include "EmailConverter.h"
+
+#include "API/Messaging/log.h"
+
+
+
+#include "API/Messaging/StorageChangesMessageFilterValidatorFactory.h"
+#include "API/Messaging/StorageChangesConversationFilterValidatorFactory.h"
+#include "API/Messaging/StorageChangesFolderFilterValidatorFactory.h"
+#include "MessageQueryGenerator.h"
+
+#include "ConversationQueryGenerator.h"
+#include "FolderQueryGenerator.h"
+
+#include "messageDB/MessageStorageReader.h"
+
+extern "C" {
+#include <msg_storage.h>
+#include <msg.h>
+#include <msg_transport.h>
+}
+
+#include <Commons/ThreadPool.h>
+#include "Conversation.h"
+#include "MessageFolder.h"
+#include <dpl/singleton_safe_impl.h>
+
+IMPLEMENT_SAFE_SINGLETON(TizenApis::Platform::Messaging::MsgServiceHandle)
+
+
+#define LOG_ENTER LogDebug("---> ENTER");
+#define LOG_EXIT LogDebug("---> EXIT");
+
+
+using namespace std;
+using namespace TizenApis::Api::Messaging;
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::Commons;
+
+namespace {
+const char* DBUS_INTERFACE_EMAIL_RECEIVED = "User.Email.StorageChange";
+const char* DBUS_FILTER_EMAIL_RECEIVED =
+    "type='signal',interface='User.Email.StorageChange'";
+
+const int MESSAGE_FIND_LIMIT = 100;
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+int Messaging::m_currentEmailAccountId = 0;
+DPL::Atomic Messaging::m_objCounter;
+
+Messaging& Messaging::getInstance()
+{
+    static Messaging instance;
+    return instance;
+}
+
+Messaging::Messaging() :
+    m_onMessageReceivedHandleMgr(NULL),
+    m_dbusConnection(new DBus::Connection()),
+    m_dbusWorkerThread(new DPL::Thread())
+{
+    Try
+    {
+        const vector<Api::Messaging::EmailAccountInfo> accounts = getEmailAccounts();
+        LogDebug("Number of emails account=" << accounts.size());
+        if (accounts.size() > 0) {
+            // set default email account - first from the list
+            setCurrentEmailAccount(accounts[0]);
+        } else {
+            LogError("no default email account set");
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("No email accounts available");
+    }
+
+    Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+        LogError("No email accounts available");
+        //current email not configured, skipped
+    }
+
+    Catch(WrtDeviceApis::Commons::UnknownException) {
+        LogError("unknown error");
+    }
+
+    // Begin service for email management ?? pmi question if it should be added before email actions
+    if (0 == m_objCounter) {
+        int error = email_service_begin();
+        if (EMAIL_ERROR_NONE != error) {
+            LogError("email_service_begin() returned error " << error);
+        } else {
+            LogInfo("email_service_begin() executed without error");
+        }
+    }
+    ++m_objCounter;
+
+    m_dbusWorkerThread->Run();
+    m_dbusConnection->setWorkerThread(m_dbusWorkerThread);
+    m_dbusConnection->addFilter(DBUS_FILTER_EMAIL_RECEIVED);
+    m_dbusConnection->AddListener(this);
+}
+
+Messaging::~Messaging()
+{
+    // Endservice for email management
+    m_dbusConnection->RemoveListener(this);
+//    m_dbusConnection->setWorkerThread(NULL);
+    m_dbusWorkerThread->Quit();
+    delete m_dbusWorkerThread;
+
+    if (!--m_objCounter) {
+        int error = email_service_end();
+        if (EMAIL_ERROR_NONE != error) {
+            LogError("email_service_end() returned error " << error);
+        } else {
+            LogDebug("email_service_end() executed without error");
+        }
+    }
+}
+
+/*
+void Messaging::getNumberOfMessages(MessageType msgType,
+        FolderType folder,
+        int* readed,
+        int* unReaded)
+{
+    if (NULL == readed ||
+        NULL == unReaded) {
+        LogError("output pointers are NULL");
+        Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+    }
+    *readed = 0;
+    *unReaded = 0;
+    if (Api::Messaging::SMS == msgType) {
+        getNumberOfSms(folder, readed, unReaded);
+    } else if (Api::Messaging::MMS == msgType) {
+        getNumberOfMms(folder, readed, unReaded);
+    } else if (Api::Messaging::EMAIL == msgType) {
+        getNumberOfEmails(folder, readed, unReaded);
+    } else {
+        LogError("wrong message type");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+}
+
+vector<IMessagePtr> Messaging::findMessages(const vector<MessageType>& msgTypes,
+        const string &folder,
+        const Api::Tizen::FilterPtr& filter)
+{
+    LogDebug("enter");
+    vector<IMessagePtr> retVal;
+    back_insert_iterator< vector<IMessagePtr> > biit(retVal);
+    vector<MessageType>::const_iterator it = msgTypes.begin();
+    for (; it != msgTypes.end(); ++it) {
+        LogDebug("Finding messages (" << *it << ")  in folder: " << folder);
+        vector<IMessagePtr> result;
+
+        switch (*it) {
+        case SMS:
+        {
+            FolderType folderEnum = Sms::toFolder(folder);
+            result = findSms(folderEnum, filter);
+            break;
+        }
+        case MMS:
+        {
+            FolderType folderEnum = Mms::toFolder(folder);
+            result = findMms(folderEnum, filter);
+            break;
+        }
+        case EMAIL:
+        {
+            result = findEmail(folder, filter);
+            break;
+        }
+        default:
+            LogError("message type unknown");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+        LogDebug("Found: " << result.size());
+        copy(result.begin(), result.end(), biit);
+    }
+
+    return retVal;
+}
+*/
+std::string Messaging::generateFilterSql(const Api::Tizen::FilterPtr& filter){
+       LogDebug("<<<");
+       std::string filterSql;
+
+       MessageQueryGeneratorPtr queryGenerator(new MessageQueryGenerator());
+       IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+       filter->travel(filterVisitor, 0);
+       filterSql = queryGenerator->getQuery();
+
+       LogDebug(">>> filterSql:[" << filterSql << "]");
+       return filterSql;
+}
+
+/*
+       vector<IMessagePtr> Messaging::findMessages(const vector<MessageType>& msgTypes, FolderType folder,
+                       const Api::Tizen::FilterPtr& filter)
+{
+       LogDebug("enter");
+       vector<IMessagePtr> retVal;
+       back_insert_iterator< vector<IMessagePtr> > biit(retVal);
+
+       std::string filterSql = generateFilterSql(filter);
+
+
+
+       vector<MessageType>::const_iterator it = msgTypes.begin();
+       for (; it != msgTypes.end(); ++it) {
+               LogDebug("Finding messages (" << *it << ")  in folder: " << folder);
+               vector<IMessagePtr>(Messaging::*findFnPtr)(Api::Messaging::FolderType folder, const Api::Tizen::FilterPtr& filter) = NULL;
+
+               switch (*it) {
+                       case SMS:
+                       {
+                               findFnPtr = &Messaging::findSms;
+                               break;
+                       }
+                       case MMS:
+                       {
+                               findFnPtr = &Messaging::findMms;
+                               break;
+                       }
+                       case EMAIL:
+                       {
+                               findFnPtr = &Messaging::findEmail;
+                               break;
+                       }
+                       default:
+                       LogError("message type unknown");
+                       Throw(WrtDeviceApis::Commons::PlatformException);
+               }
+
+               vector<IMessagePtr> result = (this->*findFnPtr)(folder, filter);
+               LogDebug("Found: " << result.size());
+               copy(result.begin(), result.end(), biit);
+       }
+
+       return retVal;
+}
+*/
+       void Messaging::printErrorMessage(int errorCode){
+               switch(errorCode){
+                       case EMAIL_ERROR_MAIL_NOT_FOUND:{
+                               LogDebug("EMAIL_ERROR_MAIL_NOT_FOUND");
+                               break;
+                       }
+                       case EMAIL_ERROR_DB_FAILURE:{
+                               LogDebug("EMAIL_ERROR_DB_FAILURE");
+                               break;
+                       }
+                       default:{
+                               LogDebug("other error message:" << errorCode);
+               }
+       }
+       }
+
+       vector<IMessagePtr> Messaging::createVectorFromeMessageList(const msg_struct_list_s &message_list){
+//     vector<IMessagePtr> Messaging::createVectorFromeMessageList(const msg_struct_list_s message_list){              
+               LogDebug("<<<");
+
+               vector<IMessagePtr> retVal;
+               int tempInt;
+//             int l_msgId = 0;
+               MessageType webApiMsgType;              
+               
+               LogDebug("message_list.nCount:" << message_list.nCount);
+               for (int i = 0; i < message_list.nCount; i++) {
+                       int err = msg_get_int_value(message_list.msg_struct_info[i], MSG_MESSAGE_TYPE_INT, &tempInt);
+                       if(err != MSG_SUCCESS)
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get message type fail");
+                       }
+                       LogDebug("Message type : " << tempInt);
+
+                       switch(tempInt){
+                               case MSG_TYPE_SMS:{
+                                       webApiMsgType = Api::Messaging::SMS;
+                                       break;
+                               }
+                               case MSG_TYPE_MMS:{
+                                       webApiMsgType = Api::Messaging::MMS;
+                                       break;
+                               }
+                               default:{
+                                       LogError("[ERROR]invalid message type:" << tempInt);
+                                       continue;
+                               }
+                       }
+
+//                     int l_msgId = msg_get_message_id(message_list.msgInfo[i]);
+                       err = msg_get_int_value(message_list.msg_struct_info[i], MSG_MESSAGE_ID_INT, &tempInt);
+                       LogDebug("Message Id : " << tempInt);
+                       if(err != MSG_SUCCESS)
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get message id fail");
+                       }
+
+                       Api::Messaging::IMessagePtr msg;
+                       msg = MessageFactory::createMessage(webApiMsgType, tempInt);
+                       retVal.push_back(msg);
+               }       //for
+
+               LogDebug(">>>");
+               return retVal;
+       }
+
+       std::vector<Api::Messaging::IConversationPtr> Messaging::createVectorFromeThreadViewList(const msg_struct_list_s& threadViewList){
+               vector<IConversationPtr> recVec;
+
+               if (threadViewList.nCount <= 0) {
+                       LogDebug("Empty...");
+               }       else    {
+                       for (int i = 0; i < threadViewList.nCount; i++)         {
+//                             Api::Messaging::IConversationPtr convPtr(new Conversation(i));
+                               Api::Messaging::IConversationPtr convPtr(new Conversation(threadViewList.msg_struct_info[i]));
+
+                               recVec.push_back(convPtr);
+                       }
+               }
+
+               return recVec;
+       }
+
+       vector<IMessagePtr> Messaging::querySmsMmsMessages(const std::string& queryString){
+               LogDebug("<<< queryString:[" << queryString <<"]");
+
+               vector<IMessagePtr> retVal;
+               std::string tempString = "";
+//             MSG_LIST_S message_list = {0, NULL};
+               msg_struct_list_s message_list = {0,};
+
+               Try{
+                       msg_error_t res = MSG_ERR_UNKNOWN;
+
+                       MessageStorageReader reader;
+                       reader.MsgStoConnectDB();
+                       res = reader.queryMessage(queryString, tempString, &message_list);
+
+                       if (MSG_SUCCESS != res) {
+                               LogError("msg_get_folder_view_list failed " << res);
+                               Throw(WrtDeviceApis::Commons::PlatformException);
+                       }
+                       reader.MsgStoDisconnectDB();
+
+                       retVal = createVectorFromeMessageList(message_list);
+                       msg_release_list_struct(&message_list);
+               }Catch(WrtDeviceApis::Commons::PlatformException) {
+                       LogError("Problem with message creation, cleaning");
+                       if (message_list.nCount) {
+                               msg_release_list_struct(&message_list);
+                       }
+                       throw;
+               }       //Catch
+
+               LogDebug(">>>");
+               return retVal;
+       }
+
+       vector<IMessagePtr> Messaging::querySmsMmsMessages(const std::string& queryString, const std::string& orderLimitString){
+               LogDebug("<<< queryString:[" << queryString <<"]");
+               LogDebug("<<< orderLimitString:[" << orderLimitString <<"]");           
+
+               vector<IMessagePtr> retVal;
+//             MSG_LIST_S message_list = {0, NULL};
+               msg_struct_list_s message_list = {0,};
+
+               Try{
+                       msg_error_t res = MSG_ERR_UNKNOWN;
+
+                       MessageStorageReader reader;
+                       reader.MsgStoConnectDB();
+                       res = reader.queryMessage(queryString, orderLimitString, &message_list);
+
+                       if (MSG_SUCCESS != res) {
+                               LogError("msg_get_folder_view_list failed " << res);
+                               Throw(WrtDeviceApis::Commons::PlatformException);
+                       }
+                       reader.MsgStoDisconnectDB();
+
+                       retVal = createVectorFromeMessageList(message_list);
+                       LogDebug("<<< message_list.nCount:[" << message_list.nCount <<"]");                     
+                       
+                       msg_release_list_struct(&message_list);
+               }Catch(WrtDeviceApis::Commons::PlatformException) {
+                       LogError("Problem with message creation, cleaning");
+                       if (message_list.nCount) {
+                               msg_release_list_struct(&message_list);
+                       }
+                       throw;
+               }       //Catch
+
+               LogDebug(">>>");
+               return retVal;
+       }
+
+vector<IConversationPtr> Messaging::querySmsMmsConversation(const std::string& sqlWhereClause, const std::string& orderLimitString){
+       LogDebug("sqlWhereClause:[" << sqlWhereClause << "]");
+       LogDebug("<<< orderLimitString:[" << orderLimitString <<"]");           
+
+       std::vector<Api::Messaging::IConversationPtr> recVec;
+//     MSG_THREAD_VIEW_LIST_S threadViewList;
+       msg_struct_list_s threadViewList;
+
+       msg_error_t res = MSG_ERR_UNKNOWN;
+
+       MessageStorageReader reader;
+       reader.MsgStoConnectDB();
+       res = reader.queryConversation(sqlWhereClause, orderLimitString, &threadViewList);
+
+       if (MSG_SUCCESS != res) {
+               LogError("queryConversation failed:" << res);
+               Throw(WrtDeviceApis::Commons::PlatformException);
+       }
+       reader.MsgStoDisconnectDB();
+
+       recVec = createVectorFromeThreadViewList(threadViewList);
+
+       msg_release_list_struct(&threadViewList);
+
+       LogDebug(">>>");
+       return recVec;
+}
+
+vector<IConversationPtr> Messaging::queryEmailConversation(const std::string& sqlWhereClause){
+       LogDebug("sqlWhereClause:[" << sqlWhereClause << "]");
+
+       std::vector<Api::Messaging::IConversationPtr> emailResultVector;
+       email_mail_list_item_t* mailList = NULL;
+       int mailListCount = 0;
+       int errCode = 0;
+       errCode = email_query_mail_list(const_cast<char*>(sqlWhereClause.c_str()), &mailList, &mailListCount);
+
+       if(errCode != EMAIL_ERROR_NONE){
+               LogError("[ERROR]email_query_mail_list failed:" << errCode);
+               printErrorMessage(errCode);
+       }else{
+               LogDebug("message found mailListCount:" << mailListCount);
+               std::map<int, int> checkUnique;
+
+               for(int i=0; i<mailListCount; i++){
+                       if (checkUnique.find(mailList[i].thread_id) == checkUnique.end()){
+                               checkUnique[mailList[i].thread_id] = mailList[i].thread_id;
+                               Api::Messaging::IConversationPtr convPtr(new Conversation(mailList[i].thread_id, Api::Messaging::EMAIL));
+
+                               //TODO for debug
+                               LogDebug("mailList[i].thread_id:[" << mailList[i].thread_id << "]");
+                               LogDebug("mailList[i].full_address_from:[" << mailList[i].full_address_from << "]");
+                               LogDebug("mailList[i].email_address_sender : [" << mailList[i].email_address_sender <<"]");
+                               //LogDebug("mailList[i].datetime:[" << mailList[i].datetime << "]");
+                               LogDebug("mailList[i].subject:[" << mailList[i].subject << "]");
+//                             LogDebug("mailList[i].mailbox_name:[" << mailList[i].mailbox_name << "]");
+                               LogDebug("mailList[i].preview_text:[" << mailList[i].preview_text << "]");
+                               LogDebug("mailList[i].flags_seen_field:[" << mailList[i].flags_seen_field << "]");
+                               LogDebug("mailList[i].priority:[" << mailList[i].priority<< "]");
+
+                               if (convPtr->getResult() == true)
+                               {
+                                       emailResultVector.push_back(convPtr);
+                               }
+                       }       //if
+               }//for
+       }//if
+
+       if (mailList != NULL){
+               free(mailList);
+       }
+
+       LogDebug(">>>");
+       return emailResultVector;
+}
+
+vector<IMessagePtr> Messaging::queryEmailMessage(const std::string& sqlWhereClause){
+       LogDebug("sqlWhereClause:[" << sqlWhereClause << "]");
+
+       vector<IMessagePtr> emailResultVector;
+
+       email_mail_list_item_t* mailList = NULL;
+       int mailListCount = 0;
+       int errCode = 0;
+       errCode = email_query_mail_list(const_cast<char*>(sqlWhereClause.c_str()), &mailList, &mailListCount);
+
+       if(errCode != EMAIL_ERROR_NONE){
+               LogError("[ERROR]email_query_mail_list failed:" << errCode);
+               printErrorMessage(errCode);
+       }else{
+               LogDebug("message found mailListCount:" << mailListCount);
+
+               for(int i=0; i<mailListCount; i++){
+                       //Api::Messaging::IMessagePtr msg = MessageFactory::createMessage(EMAIL, mailList[i].mail_id);
+                       Api::Messaging::IMessagePtr msg = MessageFactory::createEmailMessage(mailList[i].account_id, mailList[i].mail_id);
+                       
+                       //TODO for debug
+                       LogDebug("mailList[i].full_address_from:[" << mailList[i].full_address_from << "]");
+                       LogDebug("mailList[i].email_address_sender : [" << mailList[i].email_address_sender <<"]");
+                       //LogDebug("mailList[i].datetime:[" << mailList[i].datetime << "]");
+                       LogDebug("mailList[i].subject:[" << mailList[i].subject << "]");
+//                     LogDebug("mailList[i].mailbox_name:[" << mailList[i].mailbox_name << "]");
+                       LogDebug("mailList[i].preview_text:[" << mailList[i].preview_text << "]");
+                       LogDebug("mailList[i].flags_seen_field:[" << mailList[i].flags_seen_field << "]");
+                       LogDebug("mailList[i].priority:[" << mailList[i].priority<< "]");
+
+                       emailResultVector.push_back(msg);
+               }//for
+       }//if
+
+       if (mailList != NULL)           {
+               free(mailList);
+       }
+
+       LogDebug(">>>");
+       return emailResultVector;
+}
+/*
+vector<IMessagePtr> Messaging::findMessages(const Api::Tizen::FilterPtr& filter){
+       LogDebug("<<<");
+
+       vector<IMessagePtr> retVal;
+       std::string filterSql;
+
+       MessageQueryGeneratorPtr queryGenerator(new MessageQueryGenerator());
+
+       IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+       filter->travel(filterVisitor, 0);
+       filterSql = queryGenerator->getQuery();
+       LogDebug("filterSql:[" << filterSql <<"]");
+
+       int messageType = queryGenerator->getMessageType();
+       switch(messageType){
+               case Api::Messaging::EMAIL:
+                       LogDebug("message type is EMAIL:[" << messageType <<"]");
+                       retVal = queryEmailMessage(filterSql);
+                       break;
+
+               case Api::Messaging::SMS:
+               case Api::Messaging::MMS:
+                       LogDebug("message type is SMS or MMS:[" << messageType <<"]");
+                       queryGenerator->reset(MessageQueryGenerator::MODE_SMS_MMS);
+                       filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+                       filter->travel(filterVisitor);
+                       filterSql = queryGenerator->getQuery();
+                       retVal = querySmsMmsMessages(filterSql);
+                       break;
+
+               default:
+                       LogError("[ERROR] >>> invlid message type:[" << messageType <<"]");
+                       return retVal;
+       }
+
+       LogDebug(">>>");
+       return retVal;
+}
+*/
+/*
+//TODO refactoring
+vector<IMessagePtr> Messaging::findMessages(const Api::Tizen::FilterPtr& filter, const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset)
+{
+       LogDebug("<<<");
+
+       vector<IMessagePtr> retVal;
+       std::string filterSql;
+
+       MessageQueryGeneratorPtr queryGenerator(new MessageQueryGenerator(sortMode, limit, offset));
+
+       IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+       filter->travel(filterVisitor, 0);
+       filterSql = queryGenerator->getQuery();
+       LogDebug("filterSql:[" << filterSql <<"]");
+
+       int messageType = queryGenerator->getMessageType();
+       switch(messageType){
+               case Api::Messaging::EMAIL:
+                       LogDebug("message type is EMAIL:[" << messageType <<"]");
+                       retVal = queryEmailMessage(filterSql);
+                       break;
+
+               case Api::Messaging::SMS:
+               case Api::Messaging::MMS:
+                       LogDebug("message type is SMS or MMS:[" << messageType <<"]");
+                       queryGenerator->reset(MessageQueryGenerator::MODE_SMS_MMS);
+                       filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+                       filter->travel(filterVisitor);
+                       filterSql = queryGenerator->getQuery();
+                       retVal = querySmsMmsMessages(filterSql);
+                       break;
+
+               default:
+                       MsgLogError("[ERROR] >>> invlid message type:[" << messageType <<"]");
+                       return retVal;
+       }
+
+       LogDebug(">>>");
+       return retVal;
+}
+*/
+vector<IMessagePtr> Messaging::findMessages(const Api::Tizen::FilterPtr& filter, const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset, const int type)
+{
+       LogDebug("<<<");
+
+       vector<IMessagePtr> retVal;
+       std::string filterSql;
+       std::string orderLimitSql ="";
+       std::string typeAndString = "AND A.MAIN_TYPE=";
+       std::string typeString = "A.MAIN_TYPE=";
+
+       MessageQueryGeneratorPtr queryGenerator(new MessageQueryGenerator(sortMode, limit, offset, type));
+
+       IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+       filter->travel(filterVisitor, 0);
+       filterSql = queryGenerator->getQuery();
+       orderLimitSql = queryGenerator->getOrderLimit();
+       LogDebug("filterSql:[" << filterSql <<"]");
+       LogDebug("orderLimitSql:[" << orderLimitSql <<"]");
+
+       int messageType = queryGenerator->getMessageType();
+       if(messageType != -1)
+       {
+               if(messageType != type)
+               {
+                       LogDebug("filter messageType and service msg type is diff");            
+                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid Fiilter Type");
+               }
+       }
+       switch(type){
+               case Api::Messaging::EMAIL:
+                       LogDebug("message type is EMAIL:[" << messageType <<"]");
+                       retVal = queryEmailMessage(filterSql);
+                       break;
+
+               case Api::Messaging::SMS:
+                       LogDebug("message type is SMS :[" << messageType <<"]");
+                       typeString.append("1");
+                       typeAndString.append("1");
+                       if(filterSql.length() == 0)
+                       {
+                               filterSql.append(typeString);
+                               LogDebug("filterSql:[" << filterSql <<"]");
+                       }
+                       else
+                       {
+                               filterSql.append(typeAndString);
+                               LogDebug("filterSql:[" << filterSql <<"]");                             
+                       }
+                       LogDebug("filterSql:[" << filterSql <<"]");
+                       LogDebug("orderLimitSql.length():[" << orderLimitSql.length() <<"]");
+                       retVal = querySmsMmsMessages(filterSql, orderLimitSql);
+                       LogDebug("filterSql:[" << filterSql <<"]");                             
+                       break;                  
+               case Api::Messaging::MMS:
+                       LogDebug("message type is MMS:[" << messageType <<"]");
+                       typeString.append("2");
+                       typeAndString.append("2");
+                       if(filterSql.length() == 0)
+                       {
+                               filterSql.append(typeString);
+                               LogDebug("filterSql:[" << filterSql <<"]");
+                       }
+                       else
+                       {
+                               filterSql.append(typeAndString);
+                               LogDebug("filterSql:[" << filterSql <<"]");                     
+                       }
+                       LogDebug("filterSql:[" << filterSql <<"]");                     
+                       LogDebug("orderLimitSql.length():[" << orderLimitSql.length() <<"]");
+                       retVal = querySmsMmsMessages(filterSql, orderLimitSql);
+                       LogDebug("filterSql:[" << filterSql <<"]");                     
+                       break;
+
+               default:
+                       MsgLogError("[ERROR] >>> invlid message type:[" << messageType <<"]");
+                       return retVal;
+       }
+
+       LogDebug(">>>");
+       return retVal;
+}
+
+/*
+vector<string> Messaging::getMessageIds(MessageType msgType,
+        FolderType folder)
+{
+    switch (msgType) {
+    case SMS:
+        return getSmsIds(folder);
+    case MMS:
+        return getMmsIds(folder);
+    case EMAIL:
+        return getEmailIds(folder);
+    default:
+        LogError("not supported message type");
+        Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+    }
+}
+
+vector<string> Messaging::getSmsIds(FolderType folder)
+{
+    vector<string> retVal;
+    msg_message_t msg = msg_new_message();
+    MSG_LIST_S folder_list_view = { 0, NULL };
+
+    Try
+    {
+        const MSG_SORT_RULE_S sort_rules = { MSG_SORT_BY_DISPLAY_TIME, true };
+        msg_error_t res = MSG_ERR_UNKNOWN;
+        const msg_folder_id_t platformFolder = convertFolderToPlatform(folder);
+        res = msg_get_folder_view_list(
+                MsgGetCommonHandle(), platformFolder, &sort_rules,
+                &folder_list_view);
+
+        if (MSG_SUCCESS != res) {
+            LogError("msg_Get_folder_view_list failed" << res);
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+
+        for (int i = 0; i < folder_list_view.nCount; i++) {
+            if (MSG_TYPE_SMS ==
+                               msg_get_message_type(folder_list_view.
+                                                     msgInfo[i])) {
+                               int l_msgId = msg_get_message_id(
+                        folder_list_view.msgInfo[i]);
+                ostringstream stream;
+                stream << l_msgId;
+                retVal.push_back(stream.str());
+            }
+        }
+
+               msg_release_list_struct(&folder_list_view);
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("Problem with message creation, cleaning");
+        if (folder_list_view.nCount) {
+                       msg_release_list_struct(&folder_list_view);
+        }
+        if (msg) {
+            msg_release_message(&msg);
+        }
+        throw;
+    }
+
+    return retVal;
+}
+
+vector<string> Messaging::getMmsIds(FolderType folder)
+{
+    vector<string> retVal;
+    msg_message_t msg = msg_new_message();
+    MSG_LIST_S folder_list_view = { 0, NULL };
+
+    Try
+    {
+        const MSG_SORT_RULE_S sort_rules = { MSG_SORT_BY_DISPLAY_TIME, true };
+        msg_error_t res = MSG_ERR_UNKNOWN;
+        const msg_folder_id_t platformFolder = convertFolderToPlatform(folder);
+        res = msg_get_folder_view_list(
+                MsgGetCommonHandle(), platformFolder, &sort_rules,
+                &folder_list_view);
+
+        if (MSG_SUCCESS != res) {
+            LogError("msg_Get_folder_view_list failed" << res);
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+
+        for (int i = 0; i < folder_list_view.nCount; i++) {
+            if (MSG_TYPE_MMS ==
+                               msg_get_message_type(folder_list_view.
+                                                     msgInfo[i])) {
+                               int l_msgId = msg_get_message_id(
+                        folder_list_view.msgInfo[i]);
+                ostringstream stream;
+                stream << l_msgId;
+                retVal.push_back(stream.str());
+            }
+        }
+
+               msg_release_list_struct(&folder_list_view);
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("Problem with message creation, cleaning");
+        if (folder_list_view.nCount) {
+                       msg_release_list_struct(&folder_list_view);
+        }
+        if (msg) {
+            msg_release_message(&msg);
+        }
+        throw;
+    }
+
+    return retVal;
+}
+
+vector<string> Messaging::getEmailIds(FolderType folder)
+{
+    vector<string> retVal;
+
+    //TODO
+    LogError("TODO");
+    Throw(WrtDeviceApis::Commons::UnknownException);
+
+    return retVal;
+}
+*/
+vector<EmailAccountInfo> Messaging::getEmailAccounts() const
+{
+       LogError("enter");
+       email_account_t* accounts = NULL;
+       int count = 0;
+       Try {
+               if (!email_get_account_list(&accounts, &count)) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't get e-mail accounts.");
+               }
+
+               LogError(       "count : " << count);
+
+               if (0 == count) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "No e-mail account found.");
+               }
+
+               vector<Api::Messaging::EmailAccountInfo> result;
+               for (int i = 0; i < count; ++i) 
+               {
+                       if(accounts[i].incoming_server_user_name  !=  NULL)
+                       {
+                               LogError("server user name is NULL");
+                               Api::Messaging::EmailAccountInfo account(accounts[i].account_id,
+                                                                                       accounts[i].incoming_server_user_name,
+                                                                                       accounts[i].user_email_address);
+                               result.push_back(account);
+                       }
+                       else
+                       {
+                               LogError("normal case");
+                               std::string Unknown = "UNKNOWN";
+                               Api::Messaging::EmailAccountInfo account(accounts[i].account_id,
+                                                                                       Unknown,
+                                                                                       accounts[i].user_email_address);
+                               result.push_back(account);
+                       }
+               }
+
+               if (accounts != NULL) {
+                       email_free_account(&accounts, count);
+               }
+               LogError("end");
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               if (accounts != NULL) {
+                       email_free_account(&accounts, count);
+               }
+               LogError("PlatformException");
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "No e-mail account found.");
+       }
+       Catch(WrtDeviceApis::Commons::UnknownException) {
+               if (accounts != NULL) {
+                       email_free_account(&accounts, count);
+               }
+               LogError("UnknownException");
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't convert e-mail account id");
+       }
+}
+
+int Messaging::getEmailAccountId(const std::string& account)
+{
+    int retVal = 0;
+    string tmpAccount = account;
+    email_account_t *pAccountArray = NULL;
+    int iCount = 0;
+
+    Try
+    {
+        if (account.empty()) {
+            tmpAccount = getCurrentEmailAccount().getAddress();
+            if (tmpAccount.empty()) {
+                LogError(
+                    "current email account is not set, possible that no account created");
+                Throw(WrtDeviceApis::Commons::PlatformException);
+            }
+        }
+
+        if (!email_get_account_list(&pAccountArray, &iCount)) {
+            LogError("email_get_account_list error");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+
+        if (0 == iCount) {
+            LogError("no email account exist");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+
+        for (int i = 0; i < iCount; i++) {
+            string tmp = pAccountArray[i].user_email_address;
+            if (tmp == tmpAccount) {
+                m_currentEmailAccountId = pAccountArray[i].account_id;
+                retVal = m_currentEmailAccountId;
+                break;
+            }
+        }
+
+        if (0 == m_currentEmailAccountId) {
+            LogError("wrong email account ID");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+
+        if (pAccountArray != NULL) {
+            LogDebug("free account, ptr=" << pAccountArray);
+            email_free_account(&pAccountArray, iCount);
+        }
+
+        if (0 == retVal) {
+            LogError("no email account created");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("exception catch, platform exception");
+        if (pAccountArray != NULL) {
+            email_free_account(&pAccountArray, iCount);
+        }
+        throw;
+    }
+
+    return retVal;
+}
+
+void Messaging::fetchEmailHeaders()
+{
+/*
+       email_mailbox_t *mailbox = NULL;
+       int handle = 0;
+       int error = 0;
+       mailbox = static_cast<email_mailbox_t*>(calloc(sizeof (email_mailbox_t), 1));
+       if (!mailbox) {
+               LogError("calloc failed");
+               return;
+       }
+       mailbox->account_id = m_currentEmailAccountId;
+       mailbox->mailbox_name = strdup(EMAIL_INBOX_NAME);
+       //    if (EMAIL_ERROR_NONE != email_sync_header(mailbox, &handle)) {
+       if (EMAIL_ERROR_NONE != email_sync_header(mailbox->account_id, 0, &handle)) {
+               LogError("email_sync_header failed");
+       }
+       error = email_free_mailbox(&mailbox, 1);
+       LogError("email_free_mailbox : " << error);
+*/
+}
+
+int Messaging::convertFolderToPlatform(const FolderType folder)
+{
+    msg_folder_id_t platfromFolderId;
+    switch (folder) {
+    case INBOX:
+        platfromFolderId = MSG_INBOX_ID;
+        break;
+    case DRAFTBOX:
+        platfromFolderId = MSG_DRAFT_ID;
+        break;
+    case OUTBOX:
+        platfromFolderId = MSG_OUTBOX_ID;
+        break;
+    case SENTBOX:
+        platfromFolderId = MSG_SENTBOX_ID;
+        break;
+    case SPAMBOX:
+    // intentionally not break in platform is no spambox
+    default:
+        LogError("Invalid folder: " << folder);
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+
+    return platfromFolderId;
+}
+
+int Messaging::convertFolderToPlatform(const std::string &folder)
+{
+//    MSG_FOLDER_LIST_S folderList = { 0, NULL };
+
+    int result = 0;
+/*     
+    Try
+    {
+        if (MSG_SUCCESS !=
+            msg_get_folder_list(MsgGetCommonHandle(), &folderList)) {
+            LogError("msg_get_folder_list error");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+        for (int i = 0; i < folderList.nCount; ++i) {
+            if (MSG_FOLDER_TYPE_USER_DEF ==
+                folderList.folderInfo[i].folderType &&
+                NULL != folderList.folderInfo[i].folderName &&
+                folder == folderList.folderInfo[i].folderName) {
+                result = folderList.folderInfo[i].folderId;
+                break;
+            }
+        }
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        if (folderList.nCount) {
+            msg_release_folder_list(&folderList);
+        }
+        throw;
+    }
+    if (folderList.nCount) {
+        msg_release_folder_list(&folderList);
+    }
+*/
+    return result;
+}
+
+void Messaging::addOnMessageReceived(
+        const Api::Messaging::EmitterMessageReceivedPtr& emitter, const Api::Tizen::FilterPtr& filter, int funtionIndex)
+{
+    LogDebug("ENTER");
+
+    if(filter != NULL)
+    {
+        Try
+        {
+            LogDebug("funtionIndex = " << funtionIndex);    
+            bool isValidFilter = validateFilter(filter, funtionIndex);
+            if(isValidFilter == false){
+                LogError("[ERROR]this filter is invalid");
+                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+            }    
+        }
+        Catch(WrtDeviceApis::Commons::PlatformException) {
+            throw;
+        }
+    }else
+    {
+        LogDebug("filter is NULL");    
+    }
+
+       
+    m_onMessageReceived.attach(emitter);
+    EmittersMessageReceived::LockType lock = m_onMessageReceived.getLock();
+    if ((m_onMessageReceived.size() == 1)&&((m_onConversationReceived.size() + m_onFolderReceived.size()) == 0)) {
+        m_onMessageReceivedHandleMgr = MsgServiceHandleMgrPtr(
+                new MsgServiceHandleMgr());
+        int err;
+        Try{
+            err = msg_reg_storage_change_callback(
+            m_onMessageReceivedHandleMgr->getHandle(),
+            onMessageStorageChanged,
+            this);
+        }
+        Catch(WrtDeviceApis::Commons::PlatformException){
+            LogDebug("addOnMessageReceived failed");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+
+        if (err != MSG_SUCCESS) {
+            LogError("Couldn't register on MMS received callback, err=" << err);
+        }
+
+        m_dbusConnection->open(DBUS_BUS_SYSTEM);
+    }
+}
+
+void Messaging::addOnMessageReceived(
+        const Api::Messaging::EmitterConversationReceivedPtr& emitter, const Api::Tizen::FilterPtr& filter, int funtionIndex)
+{
+    LogDebug("ENTER");
+
+    if(filter != NULL)
+    {
+        Try
+        {
+            LogDebug("funtionIndex = " << funtionIndex);    
+            bool isValidFilter = validateFilter(filter, funtionIndex);
+            if(isValidFilter == false){
+                LogError("[ERROR]this filter is invalid");
+                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+            }    
+        }
+        Catch(WrtDeviceApis::Commons::PlatformException) {
+            throw;
+        }
+    }else
+    {
+        LogDebug("filter is NULL");    
+    }
+
+       
+    m_onConversationReceived.attach(emitter);
+    EmittersConversationReceived::LockType lock = m_onConversationReceived.getLock();
+    if ((m_onConversationReceived.size() == 1)&&((m_onMessageReceived.size() + m_onFolderReceived.size()) == 0)) {
+        m_onMessageReceivedHandleMgr = MsgServiceHandleMgrPtr(
+                new MsgServiceHandleMgr());
+        int err;
+        Try{
+            err = msg_reg_storage_change_callback(
+            m_onMessageReceivedHandleMgr->getHandle(),
+            onMessageStorageChanged,
+            this);
+        }
+        Catch(WrtDeviceApis::Commons::PlatformException){
+            LogDebug("addOnMessageReceived failed");                           
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+
+        if (err != MSG_SUCCESS) {
+            LogError("Couldn't register on MMS received callback, err=" << err);
+        }
+
+        m_dbusConnection->open(DBUS_BUS_SYSTEM);
+    }
+}
+
+void Messaging::addOnMessageReceived(
+        const Api::Messaging::EmitterFolderReceivedPtr& emitter, const Api::Tizen::FilterPtr& filter, int funtionIndex)
+{
+    LogDebug("ENTER");
+
+    if(filter != NULL)
+    {
+        Try
+        {
+            LogDebug("funtionIndex = " << funtionIndex);    
+            bool isValidFilter = validateFilter(filter, funtionIndex);
+            if(isValidFilter == false){
+                LogError("[ERROR]this filter is invalid");
+                Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+            }    
+        }
+        Catch(WrtDeviceApis::Commons::PlatformException) {
+            throw;
+        }
+    }else
+    {
+        LogDebug("filter is NULL");    
+    }
+
+       
+    m_onFolderReceived.attach(emitter);
+    EmittersFolderReceived::LockType lock = m_onFolderReceived.getLock();
+    if ((m_onFolderReceived.size() == 1)&&((m_onMessageReceived.size() + m_onConversationReceived.size()) == 0)) {
+        m_onMessageReceivedHandleMgr = MsgServiceHandleMgrPtr(
+                new MsgServiceHandleMgr());
+        int err;
+
+        Try
+        {
+            err = msg_reg_storage_change_callback(
+            m_onMessageReceivedHandleMgr->getHandle(),
+            onMessageStorageChanged,
+            this);
+        }
+        Catch(WrtDeviceApis::Commons::PlatformException){
+            LogDebug("addOnMessageReceived failed");                           
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+
+        if (err != MSG_SUCCESS) {
+            LogError("Couldn't register on MMS received callback, err=" << err);
+//             Throw(WrtDeviceApis::Commons::UnknownException);
+        }
+
+        m_dbusConnection->open(DBUS_BUS_SYSTEM);
+    }
+}
+
+bool Messaging::validateFilter(const Api::Tizen::FilterPtr& filter, const int funtionIndex){
+       LogDebug("<<<");
+
+       bool retBool = false;
+       LogDebug("funtionIndex = " << funtionIndex);    
+
+       if(filter != NULL){
+               if(funtionIndex == 0)
+               {
+                       Platform::Messaging::StorageChangesMessageFilterValidatorPtr validatorMsg =
+                                       Platform::Messaging::StorageChangesMessageFilterValidatorFactory::getStorageChangesMessageFilterValidator();
+
+                       FilterValidatorPtr filterValidatorMsg = DPL::StaticPointerCast<FilterValidator>(validatorMsg);
+                       retBool = filter->validate(filterValidatorMsg);
+               }else if(funtionIndex == 1)
+               {
+                       Platform::Messaging::StorageChangesConversationFilterValidatorPtr validatorConv =
+                                       Platform::Messaging::StorageChangesConversationFilterValidatorFactory::getStorageChangesConversationFilterValidator();
+
+                       FilterValidatorPtr filterValidatorConv = DPL::StaticPointerCast<FilterValidator>(validatorConv);
+                       retBool = filter->validate(filterValidatorConv);
+               }else if(funtionIndex == 2)
+               {
+                       Platform::Messaging::StorageChangesFolderFilterValidatorPtr validatorFolder =
+                                       Platform::Messaging::StorageChangesFolderFilterValidatorFactory::getStorageChangesFolderFilterValidator();
+
+                       FilterValidatorPtr filterValidatorFolder = DPL::StaticPointerCast<FilterValidator>(validatorFolder);
+                       retBool = filter->validate(filterValidatorFolder);
+               }
+               
+               if(retBool == false){
+                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               }
+       }else{
+               LogDebug("filter is NULL");
+               retBool = false;
+       }
+
+       LogDebug(">>> retBool:" << retBool);
+       return retBool;
+
+}
+
+
+void Messaging::removeOnMessageMsgReceived(Api::Messaging::EmitterMessageReceived::IdType id)
+{
+    LogDebug("ENTER");
+    m_onMessageReceived.detach(id);
+    EmittersMessageReceived::LockType lock = m_onMessageReceived.getLock();
+    if ((m_onMessageReceived.size()+m_onConversationReceived.size()+m_onFolderReceived.size()) == 0) {
+        m_onMessageReceivedHandleMgr = MsgServiceHandleMgrPtr(NULL);
+        m_dbusConnection->close();
+    }
+}
+
+void Messaging::removeOnMessageConvReceived(Api::Messaging::EmitterConversationReceived::IdType id)
+{
+    LogDebug("ENTER");
+    m_onConversationReceived.detach(id);
+    EmittersConversationReceived::LockType lock = m_onConversationReceived.getLock();
+    if ((m_onMessageReceived.size()+m_onConversationReceived.size()+m_onFolderReceived.size()) == 0) {
+        m_onMessageReceivedHandleMgr = MsgServiceHandleMgrPtr(NULL);
+        m_dbusConnection->close();
+    }
+}
+
+void Messaging::removeOnMessageFolderReceived(Api::Messaging::EmitterFolderReceived::IdType id)
+{
+    LogDebug("ENTER");
+    m_onFolderReceived.detach(id);
+    EmittersFolderReceived::LockType lock = m_onFolderReceived.getLock();
+    if ((m_onMessageReceived.size()+m_onConversationReceived.size()+m_onFolderReceived.size()) == 0) {
+        m_onMessageReceivedHandleMgr = MsgServiceHandleMgrPtr(NULL);
+        m_dbusConnection->close();
+    }
+}
+
+void Messaging::OnEventReceived(const DBus::MessageEvent& event)
+{
+       LogDebug("ENTER");
+       EventMessageReceivedPtr jsEvent(new EventMessageReceived());
+       DBus::MessagePtr message = event.GetArg0();
+
+       if (!message) 
+       {
+               jsEvent->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::PlatformException);
+               m_onMessageReceived.emit(jsEvent);
+       } 
+       else 
+       {
+               if (message->getInterface() == DBUS_INTERFACE_EMAIL_RECEIVED) 
+               {
+                       int account_id = 0, mail_id = 0, thread_id = 0, status = 0;
+                       std::string name;
+                       email_mailbox_t m_mailboxes;            
+
+                       DBus::Message::ReadIterator it = message->getReadIterator();
+                       for (int i = 0; it->isValid(); it->next(), ++i) 
+                       {
+                               if ((i == 0) && (it->getArgType() == DBUS_TYPE_INT32)) 
+                               {
+                                       status = it->getInt();
+                                       LogInfo("status: " << status);                                  
+                               } 
+                               else if ((i == 1) && (it->getArgType() == DBUS_TYPE_INT32)) 
+                               {
+                                       account_id = it->getInt();
+                                       LogInfo("account_id: " << account_id);                                  
+                               } 
+                               else if ((i == 2) && (it->getArgType() == DBUS_TYPE_INT32)) 
+                               {
+                                       mail_id = it->getInt();
+                                       LogInfo("mail_id: " << mail_id);                                                                                
+                               } 
+                               else if ((i == 3) && (it->getArgType() == DBUS_TYPE_STRING)) 
+                               {
+                                       name = it->getString();
+                                       LogInfo("name: " << name);                                                                              
+                               } 
+                               else if ((i == 4) && (it->getArgType() == DBUS_TYPE_INT32)) 
+                               {
+                                       thread_id = it->getInt();
+                                       LogInfo("thread_id: " << thread_id);                                                                            
+                               }
+                       }
+
+                       if ((mail_id > 0) && (NOTI_MAIL_ADD == status)) 
+                       { // TODO also RECEIVE_THREAD_ITEM?
+                               LogInfo("Email received. mail_id: " << mail_id);
+
+                               IMessagePtr msg = MessageFactory::createMessage(EMAIL, mail_id);
+                               IConversationPtr conversation(new Conversation(thread_id, EMAIL));
+
+                               // TODO Temporary fix: ignore messages from OUTBOX, SENTBOX & DRAFTBOX -> most probably we added them
+                               Api::Messaging::FolderType folder = msg->getCurrentFolder();
+                               jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_ADDED);
+
+                               if (OUTBOX != folder && SENTBOX != folder && DRAFTBOX != folder)
+                               {
+                                       jsEvent->setMessage(msg);
+                                       jsEvent->setConversation(conversation);
+
+                                       if(m_onMessageReceived.size() > 0){
+                                               m_onMessageReceived.emit(jsEvent);
+                                       }
+
+                                       if(m_onConversationReceived.size() > 0){
+                                       m_onConversationReceived.emit(jsEvent);
+                                       }
+
+                               } else {
+                                       LogWarning("New email message in ignored folder: " << folder);
+                               }
+                       }
+                       else if ((mail_id > 0) && (NOTI_MAIL_DELETE == status))
+                       { // TODO also RECEIVE_THREAD_ITEM?
+                               LogInfo("Email received. delete type: " << mail_id);
+
+                               std::vector<std::string> strIds = String::split(name, ',');
+
+                               std::stringstream stream;
+                               for (std::vector<std::string>::iterator it = strIds.begin(); it != strIds.end(); ++it)
+                               {
+                                       LogDebug("ID is :" << *it);
+
+                                       if ( (*it).length() > 0 ) //vaild id
+                                       {
+                                               stream<< *it;
+                                               int id;
+                                               stream >> id;
+
+                                               IMessagePtr msg = MessageFactory::createMessage(EMPTY_MESSAGE, id);
+                                               IConversationPtr conversation(new Conversation());
+
+                                               Api::Messaging::FolderType folder = msg->getCurrentFolder();
+                                               jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_DELETED);
+
+                                               if (true) { // if (OUTBOX != folder && SENTBOX != folder && DRAFTBOX != folder)
+                                                       jsEvent->setMessage(msg);
+                                                       jsEvent->setConversation(conversation);
+                                                       if(m_onMessageReceived.size() > 0){
+                                                               m_onMessageReceived.emit(jsEvent);
+                                                       }
+                                               }
+                                               else {
+                                                       LogWarning("New email message in ignored folder: " << folder);
+                                               }
+                                       }
+
+                                       stream.clear();
+                               } //for
+
+                       }
+                       else if ((mail_id > 0) && (NOTI_MAIL_UPDATE == status)) 
+                       { // TODO also RECEIVE_THREAD_ITEM?
+                               LogInfo("Email received. mail_id: " << mail_id);
+
+                               IMessagePtr msg = MessageFactory::createMessage(EMAIL, mail_id);
+                               IConversationPtr conversation(new Conversation(thread_id, EMAIL));
+
+                               Api::Messaging::FolderType folder = msg->getCurrentFolder();
+                               jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_UPDATED);
+
+                               if (true) { // if (OUTBOX != folder && SENTBOX != folder && DRAFTBOX != folder)
+                                       jsEvent->setMessage(msg);
+                                       jsEvent->setConversation(conversation);
+                                       if(m_onMessageReceived.size() > 0)
+                                               m_onMessageReceived.emit(jsEvent);
+                                       if(m_onConversationReceived.size() > 0)
+                                               m_onConversationReceived.emit(jsEvent);
+                               } else {
+                                       LogWarning("New email message in ignored folder: " << folder);
+                               }
+                       }
+                       else if ((mail_id > 0) && (NOTI_THREAD_DELETE == status))
+                       { // TODO also RECEIVE_THREAD_ITEM?
+                               LogInfo("Email received. delete thread Id : " << mail_id);
+
+                               IConversationPtr conversation(new Conversation());
+                               conversation->setId((unsigned int)mail_id);
+                               jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_DELETED);
+                               jsEvent->setConversation(conversation);
+
+                               if(m_onConversationReceived.size() > 0){
+                                       m_onConversationReceived.emit(jsEvent);
+                               }
+                       }
+                       else if (NOTI_MAILBOX_ADD == status)
+                       {
+                               LogInfo("Emailbox received. account Id: " << account_id);
+                               LogInfo("name Id: " << name);
+                               LogInfo("mailBox Id: " << mail_id);
+
+                               email_mailbox_t* mail_box = NULL;
+
+                               if (EMAIL_ERROR_NONE != email_get_mailbox_by_mailbox_id(mail_id, &mail_box)) {
+                                       LogError("Couldn't retrieve message or it has been malformed.");
+                               }
+
+                               if(mail_box != NULL)
+                               {
+                                       m_mailboxes = *mail_box;
+                                       Api::Messaging::IMessageFolderPtr folderPtr(new MessageFolder(m_mailboxes));
+                                       jsEvent->setMessageFolder(folderPtr);
+                                       jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_ADDED);
+                                       if(m_onFolderReceived.size() > 0)
+                                       {
+                                               m_onFolderReceived.emit(jsEvent);
+                                       }
+                               
+                               }
+
+                               if ( mail_box )
+                               {
+                                       if(  EMAIL_ERROR_NONE != email_free_mailbox( &mail_box , 1) )
+                                               LogDebug("fail to email_free_mailbox - err ");
+                               }
+
+                       }
+                       else if (NOTI_MAILBOX_UPDATE == status) 
+                       {
+                               LogInfo("Emailbox received. account Id: " << account_id);
+                               LogInfo("name Id: " << name);
+                               LogInfo("mailBox Id: " << mail_id);
+
+                               email_mailbox_t* mail_box = NULL;
+
+                               if (EMAIL_ERROR_NONE != email_get_mailbox_by_mailbox_id(mail_id, &mail_box)) {
+                                       LogError("Couldn't retrieve message or it has been malformed.");
+                               }
+
+                               if(mail_box != NULL)
+                               {
+                                       m_mailboxes = *mail_box;
+
+                                       Api::Messaging::IMessageFolderPtr folderPtr(new MessageFolder(m_mailboxes));
+                                       jsEvent->setMessageFolder(folderPtr);
+                                       jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_UPDATED);
+                                       
+                                       if(m_onFolderReceived.size() > 0)
+                                       {
+                                               m_onFolderReceived.emit(jsEvent);
+                                       }
+                               }
+
+                               if ( mail_box )
+                               {
+                                       if(  EMAIL_ERROR_NONE != email_free_mailbox( &mail_box , 1) )
+                                               LogDebug("fail to email_free_mailbox - err ");
+                               }               
+                       }
+                       else if (NOTI_MAILBOX_DELETE == status) 
+                       {
+                               LogInfo("Emailbox received. account Id: " << account_id);
+                               LogInfo("name Id: " << name);
+                               LogInfo("mailBox Id: " << mail_id);
+
+                               // make empty mailbox
+                               m_mailboxes.mailbox_id = mail_id;
+                               m_mailboxes.account_id = account_id;
+                               m_mailboxes.alias = (char *)"";
+                               m_mailboxes.mailbox_name = (char *)"";
+
+                               Api::Messaging::IMessageFolderPtr folderPtr(new MessageFolder(m_mailboxes));
+                               jsEvent->setMessageFolder(folderPtr);
+                               jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_DELETED);
+
+                               if(m_onFolderReceived.size() > 0)
+                               {
+                                       m_onFolderReceived.emit(jsEvent);
+                               }
+                       }
+                       else 
+                       {
+                               LogError("Couldn't retrieve message or it has been malformed.");
+                       }
+               } 
+               else // DBUS_INTERFACE_EMAIL_RECEIVED
+               {
+                       LogDebug("Wrong DBus interface, skipping it.");
+               }
+       }
+}
+
+void Messaging::onMessageStorageChanged(msg_handle_t handle,
+        msg_storage_change_type_t storageChangeType,
+        msg_id_list_s *pMsgIdList,
+        void* data)
+{
+
+    LogDebug("ENTER");
+
+    msg_error_t err = MSG_SUCCESS;
+
+    if(storageChangeType == MSG_STORAGE_CHANGE_CONTACT)
+    {
+        LogDebug("storageChangeType is MSG_STORAGE_CHANGE_CONTACT");   
+        return;
+    }
+       
+    Messaging* this_ = static_cast<Messaging*>(data);
+    if (this_) 
+    {
+        Try {
+            int msgCount = pMsgIdList->nCount;
+            LogDebug("msgCount = "<< msgCount);
+
+            for(int index = 0; index < msgCount; index++)
+            {
+
+            LogDebug("storageChangeType = "<< storageChangeType);
+                       
+                if(storageChangeType == MSG_STORAGE_CHANGE_DELETE)
+                {
+                    IMessagePtr message = MessageFactory::createMessage(EMPTY_MESSAGE, pMsgIdList->msgIdList[index]);
+                    IConversationPtr conversation(new Conversation());                                 
+                    EventMessageReceivedPtr event(new EventMessageReceived());
+                    event->setMessage(message);
+                    event->setConversation(conversation);
+                    event->setMsg_Event_Type(EventMessageReceived::MSG_DELETED);
+
+                    if(this_->m_onMessageReceived.size() > 0){
+                        this_->m_onMessageReceived.emit(event);
+                    }
+                    if(this_->m_onConversationReceived.size() > 0){
+                        this_->m_onConversationReceived.emit(event);
+                    }
+                }
+                else
+                {
+                    msg_struct_t msg = NULL;
+                    msg_struct_t sendOpt = NULL;
+                    msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+                    sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+                       
+                    err = msg_get_message(handle, pMsgIdList->msgIdList[index], msg, sendOpt);
+
+                    if (err != MSG_SUCCESS)
+                    {
+                        LogDebug("Get Message Failed!");
+                        LogDebug("err" << err);        
+                        msg_release_struct(&msg);
+                        msg_release_struct(&sendOpt);
+                        msg = NULL;
+                        sendOpt = NULL;
+                        return;
+                    }
+                    int msgType = 0;
+                    msg_get_int_value(msg, MSG_MESSAGE_TYPE_INT, &msgType);
+                    LogDebug("msgType : " << msgType); 
+                    if((msgType > MSG_TYPE_INVALID) && ( msgType <= MSG_TYPE_SMS_REJECT))
+                    {
+                        if(msgType  != MSG_TYPE_MMS_NOTI)
+                        {
+                            int msgId = 0;
+                            msg_get_int_value(msg, MSG_MESSAGE_ID_INT, &msgId);
+                            IMessagePtr message = MessageFactory::createMessage(
+                                                                                SMS,
+                                                                                msgId,
+                                                                                msg
+                                                                                );
+                            ISmsPtr sms = MessageFactory::convertToSms(message);
+                            IConversationPtr conversation(new Conversation(message->getId(), SMS));
+                            EventMessageReceivedPtr event(new EventMessageReceived());
+                            event->setMessage(message);
+                            event->setConversation(conversation);
+
+                            if(storageChangeType == MSG_STORAGE_CHANGE_INSERT)
+                            {
+                                LogDebug("MSG_STORAGE_CHANGE_INSERT");
+                                event->setMsg_Event_Type(EventMessageReceived::MSG_ADDED);
+                            }
+                            else if(storageChangeType == MSG_STORAGE_CHANGE_UPDATE)
+                            {
+                                LogDebug("MSG_STORAGE_CHANGE_UPDATE");
+                                event->setMsg_Event_Type(EventMessageReceived::MSG_UPDATED);
+                            }
+
+                            if(this_->m_onMessageReceived.size() > 0){
+                                this_->m_onMessageReceived.emit(event);
+                            }
+                            if(this_->m_onConversationReceived.size() > 0){
+                                this_->m_onConversationReceived.emit(event);
+                            }
+                        }
+                        else
+                        {
+                            LogError("Ignore this sms, this is mms noti.");
+                        }
+                    }
+                    else if((msgType >= MSG_TYPE_MMS) && (msgType <= MSG_TYPE_MMS_NOTI))
+                    {
+                        if(msgType  != MSG_TYPE_MMS_NOTI)
+                        {
+                            int msgId = 0;
+                            msg_get_int_value(msg, MSG_MESSAGE_ID_INT, &msgId);
+                            IMessagePtr message = MessageFactory::createMessage(
+                                                                                MMS,
+//                                                                                msg_get_message_id(
+                                                                                msgId,
+                                                                                msg
+                                                                                );
+                            IMmsPtr mms = MessageFactory::convertToMms(message);
+                            IConversationPtr conversation(new Conversation(message->getId(), MMS));
+                            EventMessageReceivedPtr event(new EventMessageReceived());
+                            event->setMessage(message);
+                            event->setConversation(conversation);
+
+                            if(storageChangeType == MSG_STORAGE_CHANGE_INSERT)
+                            {
+                                event->setMsg_Event_Type(EventMessageReceived::MSG_ADDED);
+                            }
+                            else if(storageChangeType == MSG_STORAGE_CHANGE_UPDATE)
+                            {
+                                event->setMsg_Event_Type(EventMessageReceived::MSG_UPDATED);
+                            }
+//                             else if(storageChangeType == MSG_STORAGE_CHANGE_DELETE)
+//                             {
+//                                 event->setMsg_Event_Type(EventMessageReceived::MSG_DELETED);
+//                             }
+
+                            if(this_->m_onMessageReceived.size() > 0){
+                                this_->m_onMessageReceived.emit(event);
+                            }
+                            if(this_->m_onConversationReceived.size() > 0){
+                                this_->m_onConversationReceived.emit(event);
+                            }
+                        }
+                        else
+                        {
+                            LogError("Ignore this mms, this is mms noti.");
+                        }
+                    }
+                                       
+                    if(msg != NULL)
+                    {
+                          LogError("release msg : " << msg);
+                          msg_release_struct(&msg);
+                    }
+                    msg_release_struct(&sendOpt);
+                }
+            }
+        }
+        Catch(WrtDeviceApis::Commons::ConversionException) {
+            LogError("Couldn't convert message to sms.");
+        }
+        Catch(WrtDeviceApis::Commons::PlatformException) {
+            LogError("onMessageStorageChanged platform exception");
+        }              
+    }
+}
+
+/*
+void Messaging::onSmsReceived(MSG_HANDLE_T handle,
+        msg_message_t msg,
+        void* data)
+{
+    LogDebug("ENTER");
+    Messaging* this_ = static_cast<Messaging*>(data);
+    if (this_) {
+        Try {
+                       if(msg_get_message_type(msg) != MSG_TYPE_MMS_NOTI)
+                       {
+            IMessagePtr message = MessageFactory::createMessage(
+                    SMS,
+                    msg_get_message_id(
+                        msg));
+            ISmsPtr sms = MessageFactory::convertToSms(message);
+            IConversationPtr conversation(new Conversation(message->getId(), SMS));
+                       
+            EventMessageReceivedPtr event(new EventMessageReceived());
+            event->setMessage(message);
+            event->setConversation(conversation);
+                       event->setMsg_Event_Type(EventMessageReceived::MSG_ADDED);
+                       this_->m_onMessageReceived.emit(event);
+        }
+                       else
+                       {
+                               LogError("Ignore this sms, this is mms noti.");
+                       }
+        }
+        Catch(WrtDeviceApis::Commons::ConversionException) {
+            LogError("Couldn't convert message to sms.");
+        }
+    }
+}
+
+void Messaging::onMmsReceived(MSG_HANDLE_T handle,
+        msg_message_t msg,
+        void* data)
+{
+    LogDebug("ENTER");
+    Messaging* this_ = static_cast<Messaging*>(data);
+    if (this_) {
+        Try {
+            IMessagePtr message = MessageFactory::createMessage(
+                    MMS,
+                    msg_get_message_id(
+                        msg));
+            IMmsPtr mms = MessageFactory::convertToMms(message);
+            IConversationPtr conversation(new Conversation(message->getId(), MMS));
+            EventMessageReceivedPtr event(new EventMessageReceived());
+            event->setMessage(message);
+            event->setConversation(conversation);
+                       event->setMsg_Event_Type(EventMessageReceived::MSG_ADDED);
+                       this_->m_onMessageReceived.emit(event);
+        }
+        Catch(WrtDeviceApis::Commons::ConversionException) {
+            LogError("Couldn't convert message to mms.");
+        }
+    }
+}
+
+void Messaging::getNumberOfEmails(Api::Messaging::FolderType folder,
+        int* read,
+        int* unread)
+{
+    LOG_ENTER
+
+    email_mailbox_t mailbox = {};
+    mailbox.account_id = 0; // means for all accounts
+    mailbox.name = String::strdup(
+            EmailConverter::toMailboxName(folder)
+            );
+
+    int error = email_count_mail(&mailbox, read, unread);
+    free(mailbox.name);
+
+    if (EMAIL_ERROR_NONE != error) {
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                 "Couldn't get number of emails. [" << error << "]");
+    }
+
+    LOG_EXIT
+}
+
+void Messaging::getNumberOfSms(Api::Messaging::FolderType folder,
+        int* read,
+        int* unread)
+{
+    getNumberOfSmsMms(folder, read, unread, SMS);
+}
+
+void Messaging::getNumberOfMms(Api::Messaging::FolderType folder,
+        int* read,
+        int* unread)
+{
+    getNumberOfSmsMms(folder, read, unread, MMS);
+}
+
+void Messaging::getNumberOfSmsMms(Api::Messaging::FolderType folder,
+        int* read,
+        int* unread,
+        Api::Messaging::MessageType msgType)
+{
+    MSG_LIST_S folderListView = { 0, NULL };
+
+    *read = 0;
+    *unread = 0;
+
+    Try
+    {
+        MSG_MESSAGE_TYPE_T msgTypePlatform;
+        if (SMS == msgType) {
+            msgTypePlatform = MSG_TYPE_SMS;
+        } else if (MMS == msgType) {
+            msgTypePlatform = MSG_TYPE_MMS;
+        } else {
+            LogError("no supported message type in this method");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+
+        msg_folder_id_t msgFolderId;
+        switch (folder) {
+        case INBOX:
+            msgFolderId = MSG_INBOX_ID;
+            break;
+        case OUTBOX:
+            msgFolderId = MSG_OUTBOX_ID;
+            break;
+        case SENTBOX:
+            msgFolderId = MSG_SENTBOX_ID;
+            break;
+        case DRAFTBOX:
+            msgFolderId = MSG_DRAFT_ID;
+            break;
+        default:
+            LogError("wrong folder type");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+            break;
+        }
+
+        const MSG_SORT_RULE_S sort_rules = { MSG_SORT_BY_DISPLAY_TIME, true };
+        if (msg_get_folder_view_list(MsgGetCommonHandle(), msgFolderId,
+                                     &sort_rules,
+                                     &folderListView) != MSG_SUCCESS) {
+            LogDebug(
+                "msg_get_folder_view_list empty or failed, msgFolderId=" <<
+                (int) msgFolderId);
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+        // go thtough all message to check type of message
+        LogDebug("msgCount=" << (int) folderListView.nCount);
+        for (int msg_cnt = 0; msg_cnt < folderListView.nCount; msg_cnt++) {
+            LogDebug("msgMainType=" <<
+                                        (int) msg_get_message_type(folderListView.
+                                                                       msgInfo[
+                                                                msg_cnt]) <<
+                     ", searching for = " << (int) msgTypePlatform);
+            if (msgTypePlatform ==
+                               msg_get_message_type(folderListView.msgInfo[
+                                                     msg_cnt])) {
+                if (msg_is_read(folderListView.msgInfo[msg_cnt]))
+                {
+                    (*read)++;
+                } else {
+                    (*unread)++;
+                }
+            }
+        }
+               msg_release_list_struct(&folderListView);
+
+        LogDebug("readed=" << *read << ", unReaded=" << *unread);
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        if (folderListView.nCount) {
+                       msg_release_list_struct(&folderListView);
+        }
+        throw;
+    }
+}
+
+       vector<Api::Messaging::IMessagePtr> Messaging::findSms(Api::Messaging::FolderType folder, const Api::Tizen::FilterPtr& filter)
+       {
+               LogDebug("<<<");
+
+               vector<Api::Messaging::IMessagePtr> retVal;
+               msg_message_t msg = msg_new_message();
+               MSG_LIST_S folder_list_view = {0, NULL};
+
+               Try{
+                       const MSG_SORT_RULE_S sort_rules = {MSG_SORT_BY_DISPLAY_TIME, true};
+                       msg_error_t res = MSG_ERR_UNKNOWN;
+                       const msg_folder_id_t platformFolder = convertFolderToPlatform(folder);
+                       res = msg_get_folder_view_list(MsgGetCommonHandle(), platformFolder, &sort_rules, &folder_list_view);
+
+                       if (MSG_SUCCESS != res) {
+                               LogError("msg_get_folder_view_list failed " << res);
+                               Throw(WrtDeviceApis::Commons::PlatformException);
+                       }
+
+                       for (int i = 0; i < folder_list_view.nCount; i++) {
+                               if (MSG_TYPE_SMS == msg_get_message_type(folder_list_view.msgInfo[i])) {
+                                       int l_msgId = msg_get_message_id(folder_list_view.msgInfo[i]);
+                                       Api::Messaging::IMessagePtr msg = MessageFactory::createMessage(SMS, l_msgId);
+
+                                       //                if (!filter || !filter->isValid() ||
+                                       //                    filter->compare(MessageFactory::convertToSms(msg))) {
+                                                           retVal.push_back(msg);
+                                       //                }
+                               }
+                       }
+
+                       msg_release_list_struct(&folder_list_view);
+               }Catch(WrtDeviceApis::Commons::PlatformException) {
+                       LogError("Problem with message creation, cleaning");
+                       if (folder_list_view.nCount) {
+                               msg_release_list_struct(&folder_list_view);
+                       }
+                       if (msg) {
+                               msg_release_message(&msg);
+                       }
+                       throw;
+               }
+
+               LogDebug(">>>");
+               return retVal;
+       }
+
+       vector<Api::Messaging::IMessagePtr> Messaging::findMms(Api::Messaging::FolderType folder,
+                       const Api::Tizen::FilterPtr& filter)
+       {
+               vector<Api::Messaging::IMessagePtr> retVal;
+               msg_message_t msg = msg_new_message();
+               MSG_LIST_S folder_list_view = {0, NULL};
+
+               Try
+               {
+                       const MSG_SORT_RULE_S sort_rules = {MSG_SORT_BY_DISPLAY_TIME, true};
+                       msg_error_t res = MSG_ERR_UNKNOWN;
+                       const msg_folder_id_t platformFolder = convertFolderToPlatform(folder);
+                       res = msg_get_folder_view_list(
+                                       MsgGetCommonHandle(), platformFolder, &sort_rules,
+                                       &folder_list_view);
+
+                       if (MSG_SUCCESS != res) {
+                               LogError("msg_Get_folder_view_list failed" << res);
+                               Throw(WrtDeviceApis::Commons::PlatformException);
+                       }
+
+                       for (int i = 0; i < folder_list_view.nCount; i++) {
+                               if (MSG_TYPE_MMS ==
+                                               msg_get_message_type(folder_list_view.
+                                                               msgInfo[i])) {
+                                       int l_msgId = msg_get_message_id(
+                                                       folder_list_view.msgInfo[i]);
+                                       Api::Messaging::IMessagePtr msg = MessageFactory::createMessage(MMS, l_msgId);
+                               }
+                       }
+
+                       msg_release_list_struct(&folder_list_view);
+               }
+
+               Catch(WrtDeviceApis::Commons::PlatformException) {
+                       LogError("Problem with message creation, cleaning");
+                       if (folder_list_view.nCount) {
+                               msg_release_list_struct(&folder_list_view);
+                       }
+                       if (msg) {
+                               msg_release_message(&msg);
+                       }
+                       throw;
+               }
+
+               return retVal;
+       }
+*/
+void Messaging::createFolder(MessageType msgType,
+        const string& userFolder)
+{
+    switch (msgType) {
+    case Api::Messaging::SMS:
+    case Api::Messaging::MMS:
+        createMsgServiceFolder(userFolder);
+        break;
+    case Api::Messaging::EMAIL:
+        createEmailFolder(userFolder);
+        break;
+    default:
+        LogError("msg not supported");
+        Throw(WrtDeviceApis::Commons::UnknownException);
+    }
+}
+
+void Messaging::createMsgServiceFolder(const std::string& userFolder)
+{
+/*
+    if (userFolder.length() > MAX_FOLDER_NAME_SIZE) {
+        LogError("folder name to long");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+
+    MSG_FOLDER_INFO_S folderInfo;
+
+    folderInfo.folderId = 0;
+    strncpy(folderInfo.folderName, userFolder.c_str(), userFolder.length());
+
+    folderInfo.folderType = MSG_FOLDER_TYPE_USER_DEF;
+
+    if (msg_add_folder(MsgGetCommonHandle(), &folderInfo) != MSG_SUCCESS) {
+        LogError("msg_add_folder failed");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+*/
+}
+
+void Messaging::createEmailFolder(const std::string& userFolder)
+{
+    //TODO
+    LogError("TODO");
+    Throw(WrtDeviceApis::Commons::UnknownException);
+}
+
+void Messaging::deleteFolder(MessageType msgType,
+        const string& userFolder)
+{
+    switch (msgType) {
+    case Api::Messaging::SMS:
+    case Api::Messaging::MMS:
+        deleteMsgServiceFolder(userFolder);
+        break;
+    case Api::Messaging::EMAIL:
+        deleteEmailFolder(userFolder);
+        break;
+    default:
+        LogError("msg not supported");
+        Throw(WrtDeviceApis::Commons::UnknownException);
+    }
+}
+
+void Messaging::deleteMsgServiceFolder(const string& userFolder)
+{
+/*
+    Try
+    {
+        int platformFolderId = convertFolderToPlatform(userFolder);
+        if (MSG_SUCCESS !=
+            msg_delete_folder(MsgGetCommonHandle(), platformFolderId)) {
+            LogError("msg_get_folder_list failed");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        throw;
+    }
+*/
+}
+
+void Messaging::deleteEmailFolder(const string& userFolder)
+{
+    //TODO
+    LogError("TODO");
+    Throw(WrtDeviceApis::Commons::UnknownException);
+}
+
+vector<string> Messaging::getFolderNames(MessageType msgType)
+{
+    switch (msgType) {
+    case Api::Messaging::SMS:
+    case Api::Messaging::MMS:
+        return getFolderNamesMsgService();
+    case Api::Messaging::EMAIL:
+        return getFolderNamesEmail();
+    default:
+        LogError("msg not supported");
+        Throw(WrtDeviceApis::Commons::UnknownException);
+    }
+}
+
+vector<string> Messaging::getFolderNamesMsgService()
+{
+    vector<string> retVal;
+//    MSG_FOLDER_LIST_S msgFolderList = { 0, NULL }; // output data
+/*
+    msg_struct_list_s msgFolderList = {0,};
+
+    Try
+    {
+        if (msg_get_folder_list(MsgGetCommonHandle(),
+                                &msgFolderList) != MSG_SUCCESS) {
+            LogError("msg_get_folder_list failed");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+
+        LogDebug("number of folder=" << msgFolderList.nCount);
+        for (int i = 0; i < msgFolderList.nCount; i++) {
+            LogDebug("folderName=" << msgFolderList.folderInfo[i].folderName);
+            LogDebug("folderId=" << (int) msgFolderList.folderInfo[i].folderId);
+            LogDebug(
+                "folderType=" <<
+                (int) msgFolderList.folderInfo[i].folderType);
+            retVal.push_back(msgFolderList.folderInfo[i].folderName);
+        }
+        (void) msg_release_folder_list(&msgFolderList);
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        if (msgFolderList.nCount) {
+            (void) msg_release_folder_list(&msgFolderList);
+        }
+        throw;
+    }
+    */
+    return retVal;
+}
+
+vector<string> Messaging::getFolderNamesEmail()
+{
+    vector<string> retVal;
+
+    string tmpStr;
+    email_mailbox_t* mailboxes = NULL;
+    int mailboxesCount;
+    string emailAccountName;
+    Api::Messaging::EmailAccountInfo account = getCurrentEmailAccount();
+
+    Try
+    {
+        if (!email_get_mailbox_list(account.getIntId(), -1, &mailboxes,
+                                    &mailboxesCount) || !mailboxes) {
+            LogError("error during get mailboxes");
+        }
+               if(mailboxes == NULL)
+               {
+            LogError("error during get mailboxes");
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                        "Couldn't get mailboxes");
+               }
+        for (int i = 0; i < mailboxesCount; i++) {
+            retVal.push_back(mailboxes->mailbox_name);
+            LogDebug("mailbox found, name=" << mailboxes->mailbox_name);
+            mailboxes++;
+        }
+               if(mailboxes != NULL)
+               {
+             if(  EMAIL_ERROR_NONE != email_free_mailbox( &mailboxes , mailboxesCount) )
+                                       LogDebug("fail to email_free_mailbox - err ");
+               }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        // nothing to clean, re-throw exception
+        throw;
+    }
+
+    return retVal;
+}
+/*
+vector<Api::Messaging::IMessagePtr> Messaging::findEmail(const std::string &folder,
+               const Api::Tizen::FilterPtr& filter)
+{
+    vector<Api::Messaging::IMessagePtr> retVal;
+
+    Api::Messaging::EmailAccountInfo account = getCurrentEmailAccount();
+    if (account.getId().empty()) {
+        LogWarning("No valid email accounts. Skipping");
+        return retVal;
+    }
+
+    int accountId = account.getIntId();
+
+    // number of found emails
+    int count = 0;
+    // start index
+    int startIndex = 0;
+
+    do {
+        email_mail_list_item_t* results = NULL;
+        int err = email_get_mail_list(accountId,
+                                         folder.c_str(),
+                                         EMAIL_LIST_TYPE_NORMAL,
+                                         startIndex,
+                                         MESSAGE_FIND_LIMIT,
+                                         EMAIL_SORT_DATETIME_HIGH,
+                                         &results,
+                                         &count);
+        DPL::ScopedFree<email_mail_list_item_t> autoFree(results);
+        (void)autoFree;
+        if (EMAIL_ERROR_MAIL_NOT_FOUND == err || results == NULL) {
+            LogWarning("No emails found in mailbox: " << folder);
+            break;
+        } else if (EMAIL_ERROR_NONE != err) {
+            LogError(
+                "Unable to get mail list for mailbox: " << folder <<
+                ", Error: " << err);
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+
+        // apply filter
+        for (int i = 0; i < count; ++i) {
+            Api::Messaging::IMessagePtr msg = MessageFactory::createMessage(EMAIL, results[i].mail_id);
+
+
+            if (!filter
+//                     || filter->compare(MessageFactory::convertToEmail(msg))         //TODO implemnet compare in filter
+                       ) {
+                retVal.push_back(msg);
+            }
+        }
+
+        startIndex += count;
+    }
+    while (count >= MESSAGE_FIND_LIMIT);
+
+    return retVal;
+}
+
+vector<Api::Messaging::IMessagePtr> Messaging::findEmail(Api::Messaging::FolderType folder,
+               const Api::Tizen::FilterPtr& filter)
+{
+    vector<Api::Messaging::IMessagePtr> result;
+
+    Api::Messaging::EmailAccountInfo account = getCurrentEmailAccount();
+    if (account.getId().empty()) {
+        LogWarning("No valid email accounts.");
+        return result;
+    }
+
+    string name;
+    try {
+        name = EmailConverter::toMailboxName(folder);
+    }
+    catch (const WrtDeviceApis::Commons::PlatformException& ex) {
+        LogWarning(ex.DumpToString());
+        return result;
+    }
+
+    int accountId = account.getIntId();
+    int startIndex = 0;
+    int count = 0;
+    do {
+        email_mail_list_item_t* messages = NULL;
+        int error = email_get_mail_list(accountId,
+                                           name.c_str(),
+                                           EMAIL_LIST_TYPE_NORMAL,
+                                           startIndex,
+                                           MESSAGE_FIND_LIMIT,
+                                           EMAIL_SORT_DATETIME_HIGH,
+                                           &messages,
+                                           &count);
+        DPL::ScopedFree<email_mail_list_item_t> freeGuard(messages);
+        if ((EMAIL_ERROR_MAIL_NOT_FOUND == error) || (NULL == messages)) {
+            LogWarning("No emails found in mailbox: " << name);
+            break;
+        } else if (EMAIL_ERROR_NONE != error) {
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                     "Couldn't get mail list from mailbox: " << name <<
+                     ". [" << error << "]");
+        }
+
+        for (int i = 0; i < count; ++i) {
+            Api::Messaging::IMessagePtr msg =
+                MessageFactory::createMessage(EMAIL, messages[i].mail_id);
+            if (!filter
+//                     ||filter->compare(MessageFactory::convertToEmail(msg))          //TODO implement compare in filter 
+                ) {
+                result.push_back(msg);
+            }
+        }
+
+        startIndex += count;
+    }
+    while (count >= MESSAGE_FIND_LIMIT);
+
+    return result;
+}
+*/
+int Messaging::getConversationId(const int& msgId, const MessageType& msgtype)
+{
+       LogDebug("Enter");
+       
+       switch(msgtype)
+       {
+               case EMAIL:
+               {
+                       int index = 0, count = 0;
+//                     char *mailBox = NULL;
+                       email_mail_list_item_t *mailList = NULL;
+                       email_mail_data_t* result = NULL;
+                       
+                       LogDebug("Current Account " << m_currentEmailAccountId);
+
+                       try 
+                       {
+                               
+                               if (EMAIL_ERROR_NONE != email_get_mail_data(msgId, &result)) {
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                                        "Couldn't get conversatino Id " << msgId );
+                               }
+
+                               if (email_get_mail_list(m_currentEmailAccountId, result->mailbox_id, EMAIL_LIST_TYPE_NORMAL, 0, MESSAGE_FIND_LIMIT, 
+                                       EMAIL_SORT_DATETIME_HIGH, &mailList, &count) != EMAIL_ERROR_NONE)
+                               {
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get email list fail" );
+                               }
+
+                               email_free_mail_data(&result,1);
+                               
+                               for (index = 0; index < count; index++)
+                               {
+                                       if (mailList[index].mail_id == (int)msgId)
+                                       {
+                                               return mailList[index].thread_id;
+                                       }
+                               }
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "can not find msg" );
+                       }
+                       catch (const WrtDeviceApis::Commons::Exception& ex) 
+                       {
+//                             if (mailBox)
+//                                     free(mailBox);
+                               email_free_mail_data(&result,1);
+                               LogError("Exception: " << ex.GetMessage());
+                               throw;  
+                       }
+                       return MSG_ERR_INVALID_MSG_TYPE;
+               }
+               break;
+               case SMS:
+               case MMS:
+               {
+                       msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+                       msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+                       msg_handle_t handle = MsgGetCommonHandle();
+                       msg_error_t err = MSG_SUCCESS;
+
+                       err = msg_get_message(handle, msgId, msg, sendOpt);
+
+                       if( err < MSG_SUCCESS )
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                               "can not find msg id(" << msgId << ")");
+                       }
+
+                       int threadId = 0;
+                       err = msg_get_int_value(msg, MSG_MESSAGE_THREAD_ID_INT, &threadId);
+
+                       LogDebug(err);
+                       
+                       if( err < MSG_SUCCESS )
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                               "can not find thread with msg id(" << msgId << ")");
+                       }
+                       msg_release_struct(&msg);
+                       msg_release_struct(&sendOpt);
+
+                       return threadId;
+               }
+               break;
+               default:
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                               "Wrong Type (" << msgId << ")");
+                       return MSG_ERR_INVALID_MSG_TYPE;
+               
+       }
+}
+/*
+std::vector<Api::Messaging::IConversationPtr> Messaging::queryConversations(const Api::Tizen::SortModePtr& sortMode,
+               const Api::Tizen::FilterPtr& filter, long limit, long offset)
+{
+       LogDebug("Enter");
+
+       std::vector<Api::Messaging::IConversationPtr> result;
+       std::string filterSql;
+       std::string orderLimitSql ="";  
+
+       ConversationQueryGeneratorPtr queryGenerator(new ConversationQueryGenerator(sortMode, limit, offset));
+       IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+       filter->travel(filterVisitor, 0);
+
+       LogDebug("filterSql:[" << filterSql <<"]");
+
+       int conversationType = queryGenerator->getMessageType();
+       switch(conversationType){
+               case Api::Messaging::EMAIL:{
+                       LogDebug("type is EMAIL:[" << conversationType <<"]");
+                       queryGenerator->reset(MessageQueryGenerator::MODE_EMAIL);
+                       filter->travel(filterVisitor, 0);
+                       filterSql = queryGenerator->getQuery();
+                       result = queryEmailConversation(filterSql);
+                       break;
+               }
+
+               case Api::Messaging::SMS:{
+                       LogDebug("type is SMS:[" << conversationType <<"]");
+                       queryGenerator->reset(MessageQueryGenerator::MODE_SMS_MMS);
+                       IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+                       filter->travel(filterVisitor, 0);
+                       filterSql = queryGenerator->getQuery();
+                       LogDebug("filterSql:[" << filterSql <<"]");
+                       LogDebug("orderLimitSql:[" << orderLimitSql <<"]");
+                       result = querySmsMmsConversation(filterSql, orderLimitSql);
+                       break;
+               }
+
+               case Api::Messaging::MMS:{
+                       LogDebug("type is MMS:[" << conversationType <<"]");
+                       queryGenerator->reset(MessageQueryGenerator::MODE_SMS_MMS);
+                       IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+                       filter->travel(filterVisitor, 0);
+                       filterSql = queryGenerator->getQuery(); 
+                       LogDebug("filterSql:[" << filterSql <<"]");
+                       LogDebug("orderLimitSql:[" << orderLimitSql <<"]");
+                       result = querySmsMmsConversation(filterSql, orderLimitSql);
+                       break;
+               }
+
+               default:{
+                       LogError("[ERROR] >>> invlid type:[" << conversationType <<"]");
+                return result;
+               }
+       }       //switch
+
+       return result;
+}
+*/
+std::vector<Api::Messaging::IConversationPtr> Messaging::queryConversations(const Api::Tizen::FilterPtr& filter, 
+               const Api::Tizen::SortModePtr& sortMode, int type, long limit, long offset)
+{
+       LogDebug("Enter");
+
+       std::vector<Api::Messaging::IConversationPtr> result;
+       std::string filterSql;
+       std::string orderLimitSql ="";
+
+       ConversationQueryGeneratorPtr queryGenerator(new ConversationQueryGenerator(sortMode, limit, offset, type));
+       IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+       filter->travel(filterVisitor, 0);
+
+       LogDebug("filterSql:[" << filterSql <<"]");
+       int conversationType = queryGenerator->getMessageType();
+       if(conversationType != -1)
+       {
+               if(conversationType != type)
+               {
+                       LogDebug("filter conversationType and service msg type is diff");               
+                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "invalid Fiilter Type");
+               }
+       }
+       switch(type){
+               case Api::Messaging::EMAIL:{
+                       LogDebug("type is EMAIL:[" << conversationType <<"]");
+                       queryGenerator->reset(MessageQueryGenerator::MODE_EMAIL);
+                       filter->travel(filterVisitor, 0);
+                       filterSql = queryGenerator->getQuery();
+                       result = queryEmailConversation(filterSql);
+                       break;
+               }
+
+               case Api::Messaging::SMS:{
+                       LogDebug("type is SMS:[" << conversationType <<"]");
+                       queryGenerator->reset(MessageQueryGenerator::MODE_SMS);
+                       IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+                       filter->travel(filterVisitor, 0);
+                       filterSql = queryGenerator->getQuery();
+                       orderLimitSql = queryGenerator->getOrderLimit();
+                       LogDebug("filterSql:[" << filterSql <<"]");
+                       LogDebug("orderLimitSql:[" << orderLimitSql <<"]");                     
+                       result = querySmsMmsConversation(filterSql, orderLimitSql);
+                       break;
+               }
+
+               case Api::Messaging::MMS:{
+                       LogDebug("type is MMS:[" << conversationType <<"]");
+                       queryGenerator->reset(MessageQueryGenerator::MODE_MMS);
+                       IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+                       filter->travel(filterVisitor, 0);
+                       filterSql = queryGenerator->getQuery();
+                       orderLimitSql = queryGenerator->getOrderLimit();        
+                       LogDebug("filterSql:[" << filterSql <<"]");
+                       LogDebug("orderLimitSql:[" << orderLimitSql <<"]");
+                       result = querySmsMmsConversation(filterSql, orderLimitSql);
+                       break;
+               }
+
+               default:{
+                       LogError("[ERROR] >>> invlid type:[" << conversationType <<"]");
+                return result;
+               }
+       }       //switch
+
+       return result;
+}
+/*
+bool Messaging::deleteConversations(const Api::Tizen::SortModePtr& sortMode, const Api::Tizen::FilterPtr& filter)
+{
+       LogDebug("Enter");
+
+       std::vector<Api::Messaging::IConversationPtr> conversationsToDelete = queryConversations(sortMode, filter);
+       return deleteConversations(conversationsToDelete);
+}
+*/
+bool Messaging::deleteConversations(const std::vector<Api::Messaging::IConversationPtr>& conversations)
+{
+       LogDebug("Enter");
+
+       if (conversations.size() == 0)
+               return false;
+       
+       if (conversations[0]->getType() == Api::Messaging::EMAIL)
+       {
+               LogDebug("Enter-Email");
+               int threadId = 0;
+
+               for (std::size_t i = 0; i < conversations.size(); ++i) 
+               {
+                       threadId = conversations[i]->getId();
+                       
+                       if (email_delete_thread(threadId, false) != EMAIL_ERROR_NONE)
+                       {
+                               return false;
+                       }
+               }
+       }
+       else
+       {
+               LogDebug("Enter-Msg");
+               msg_thread_id_t threadId = 0;
+               msg_handle_t handle = MsgGetCommonHandle();
+               
+               for (std::size_t i = 0; i < conversations.size(); ++i) 
+               {
+                       threadId = conversations[i]->getId();
+                       if (msg_delete_thread_message_list(handle, threadId, FALSE) != MSG_SUCCESS)
+                       {
+                               return false;
+                       }
+               }
+       }
+       return true;
+}
+
+std::vector<Api::Messaging::IMessageFolderPtr> Messaging::queryFolders(const Api::Tizen::FilterPtr& filter)
+{
+       LogDebug("Enter");
+
+       email_mailbox_t* mailboxes = NULL;
+       email_mailbox_t* mailboxes_org = NULL;
+       email_mailbox_t m_mailboxes;
+       int mailboxesCount;
+       int error = 0;
+
+       std::vector<Api::Messaging::IMessageFolderPtr> result;
+       std::string folderName;
+       int accountId = 0;
+
+    Api::Messaging::EmailAccountInfo account = getCurrentEmailAccount();
+       
+       if (account.getId().empty()) {
+               LogWarning("No valid email accounts. Skipping");
+               return result;
+       }
+
+       const vector<Api::Messaging::EmailAccountInfo> accounts = getEmailAccounts();
+
+       FolderQueryGeneratorPtr queryGenerator(new FolderQueryGenerator());
+       
+       IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<IFilterVisitor>(queryGenerator);
+       queryGenerator->reset();
+       filter->travel(filterVisitor, 0);
+       accountId = queryGenerator->getAccountId();
+
+       if(accountId == 0)
+       {
+               LogWarning("No valid email accounts. accountId : 0");
+               return result;  
+       }
+
+       if(queryGenerator->isFolderPathExist() == 1){
+/*             
+                       folderName = queryGenerator->getFolderPath();
+       
+               if(email_get_mailbox_by_name(accountId, folderName.c_str(), &mailboxes) != 1)
+               {
+                       LogError("error during get mailboxes");         
+                       return result;                          
+               }
+
+               m_mailboxes = *mailboxes;                       
+               Api::Messaging::IMessageFolderPtr folderPtr(new MessageFolder(m_mailboxes));
+               result.push_back(folderPtr);
+*/
+       }else{
+
+               if (!email_get_mailbox_list(accountId, -1, &mailboxes, &mailboxesCount) || !mailboxes) 
+               {
+                       LogError("error during get mailboxes");
+                       return result;          
+               }
+
+               mailboxes_org = mailboxes;
+
+               if (mailboxesCount <= 0)
+               {
+                       LogDebug("Empty...");
+               }
+               else 
+               {
+                       LogDebug("found mailboxs : " << mailboxesCount);                
+                       for (int i = 0; i < mailboxesCount; i++)
+                       {
+               
+                               m_mailboxes = *mailboxes;                       
+                               Api::Messaging::IMessageFolderPtr folderPtr(new MessageFolder(m_mailboxes));
+                               result.push_back(folderPtr);
+                               mailboxes++;                    
+                       }
+               }
+
+               mailboxes = mailboxes_org;
+               
+               if(mailboxes != NULL)
+               {
+                       error = email_free_mailbox(&mailboxes,mailboxesCount);
+                       LogError("email_free_mailbox : " << error);                     
+               }
+       }
+
+       LogDebug("End");
+
+       return result;
+
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/Messaging.h b/src/platform/Tizen/Messaging/Messaging.h
new file mode 100755 (executable)
index 0000000..40f5492
--- /dev/null
@@ -0,0 +1,241 @@
+//
+// 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 MESSAGING_H
+#define MESSAGING_H
+
+#include <vector>
+#include <string>
+#include <dpl/atomic.h>
+#include <dpl/thread.h>
+extern "C" {
+#include <msg_types.h>
+#include <msg_storage_types.h>
+}
+#include <dpl/event/event_listener.h>
+#include <API/Messaging/IMessaging.h>
+#include <API/Messaging/IMessage.h>
+#include <API/Messaging/EmailAccountInfo.h>
+#include <Commons/Emitters.h>
+#include <DBus/Connection.h>
+#include <DBus/MessageEvent.h>
+#include "MsgServiceHandleMgr.h"
+
+#include <API/Filter/IFilter.h>
+#include <API/Messaging/IConversation.h>
+#include <API/Messaging/IMessageFolder.h>
+#include <API/Filter/SortMode.h>
+
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+class Messaging : public Api::Messaging::IMessaging,
+    private DPL::Event::EventListener<DBus::MessageEvent>
+{
+  public:
+    static Messaging& getInstance();
+
+  public:
+    virtual ~Messaging();
+
+/*
+    virtual void getNumberOfMessages(Api::Messaging::MessageType msgType,
+            Api::Messaging::FolderType folder,
+            int* readed,
+            int* unReaded);
+
+    virtual std::vector<Api::Messaging::IMessagePtr> findMessages(
+            const std::vector<Api::Messaging::MessageType>& msgTypes,
+            Api::Messaging::FolderType folder,
+            const Api::Tizen::FilterPtr& filter);
+
+    virtual std::vector<Api::Messaging::IMessagePtr> findMessages(
+            const std::vector<Api::Messaging::MessageType>& msgTypes,
+            const std::string &folder,
+            const Api::Tizen::FilterPtr& filter);
+
+    virtual std::vector<Api::Messaging::IMessagePtr> findMessages(const Api::Tizen::FilterPtr& filter,
+               const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset);
+*/             
+    virtual std::vector<Api::Messaging::IMessagePtr> findMessages(const Api::Tizen::FilterPtr& filter,
+               const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset, const int type);
+//    virtual std::vector<Api::Messaging::IMessagePtr> findMessages(const Api::Tizen::FilterPtr& filter);
+
+//    virtual std::vector<std::string> getMessageIds(Api::Messaging::MessageType msgType,
+//            Api::Messaging::FolderType folder);
+
+    virtual void createFolder(Api::Messaging::MessageType msgType,
+            const std::string& userFolder);
+
+    virtual void deleteFolder(Api::Messaging::MessageType msgType,
+            const std::string& userFolder);
+
+    virtual std::vector<std::string> getFolderNames(Api::Messaging::MessageType msgType);
+
+    virtual std::vector<Api::Messaging::EmailAccountInfo> getEmailAccounts() const;
+
+    int getEmailAccountId(const std::string& account);
+
+    void fetchEmailHeaders();
+
+    static int convertFolderToPlatform(const Api::Messaging::FolderType folder);
+
+    /**
+     * Gets folder id by given folder name.
+     * @return Folder id or 0 if not found
+     * @throw PlatformException on platform error.
+     */
+    static int convertFolderToPlatform(const std::string &folder);
+
+    void addOnMessageReceived(const Api::Messaging::EmitterMessageReceivedPtr& emitter, const Api::Tizen::FilterPtr& filter, const int funtionIndex);
+
+    void addOnMessageReceived(const Api::Messaging::EmitterConversationReceivedPtr& emitter, const Api::Tizen::FilterPtr& filter, const int funtionIndex);
+
+    void addOnMessageReceived(const Api::Messaging::EmitterFolderReceivedPtr& emitter, const Api::Tizen::FilterPtr& filter, const int funtionIndex);
+
+    bool validateFilter(const Api::Tizen::FilterPtr& filter, const int funtionIndex);
+
+    void removeOnMessageMsgReceived(Api::Messaging::EmitterMessageReceived::IdType id);
+
+    void removeOnMessageConvReceived(Api::Messaging::EmitterConversationReceived::IdType id);
+
+    void removeOnMessageFolderReceived(Api::Messaging::EmitterFolderReceived::IdType id);
+
+//    std::vector<Api::Messaging::IConversationPtr> queryConversations(const Api::Tizen::SortModePtr& sortMode, const Api::Tizen::FilterPtr& filter, long limit=0, long offset=0);
+
+    std::vector<Api::Messaging::IConversationPtr> queryConversations(const Api::Tizen::FilterPtr& filter, const Api::Tizen::SortModePtr& sortMode, int type, long limit=0, long offset=0);
+
+//    bool deleteConversations(const Api::Tizen::SortModePtr& sortMode, const Api::Tizen::FilterPtr& filter);
+
+    bool deleteConversations(const std::vector<Api::Messaging::IConversationPtr>& conversations);
+
+    std::vector<Api::Messaging::IMessageFolderPtr> queryFolders(const Api::Tizen::FilterPtr& filter);
+
+    int getConversationId(const int& msgId, const Api::Messaging::MessageType& msgType);
+
+               private:
+    std::string generateFilterSql(const Api::Tizen::FilterPtr& filter);
+
+    std::vector<Api::Messaging::IConversationPtr> queryEmailConversation(const std::string& sqlWhereClause);
+    std::vector<Api::Messaging::IConversationPtr> querySmsMmsConversation(const std::string& sqlWhereClause, const std::string& orderLimitString);
+
+//    std::vector<Api::Messaging::IMessagePtr> querySmsMmsMessages(const Api::Tizen::FilterPtr& filter, const Api::Tizen::SortModePtr& sortMode, const long limit, const long offset);
+    std::vector<Api::Messaging::IMessagePtr> querySmsMmsMessages(const std::string& sqlWhereClause);
+    std::vector<Api::Messaging::IMessagePtr> querySmsMmsMessages(const std::string& sqlWhereClause, const std::string& orderLimitString);
+    std::vector<Api::Messaging::IMessagePtr> queryEmailMessage(const std::string& sqlWhereClause);
+
+//    std::vector<Api::Messaging::IMessagePtr> createVectorFromeMessageList(const MSG_LIST_S& message_list);
+//    std::vector<Api::Messaging::IConversationPtr> createVectorFromeThreadViewList(const MSG_THREAD_VIEW_LIST_S& message_list);
+    std::vector<Api::Messaging::IMessagePtr> createVectorFromeMessageList(const msg_struct_list_s &message_list);
+    std::vector<Api::Messaging::IConversationPtr> createVectorFromeThreadViewList(const msg_struct_list_s& message_list);
+
+  public:
+    static int m_currentEmailAccountId;
+
+    static DPL::Atomic m_objCounter;
+
+  protected:
+    void OnEventReceived(const DBus::MessageEvent& event);
+
+  private:
+    typedef WrtDeviceApis::Commons::Emitters<Api::Messaging::EmitterMessageReceived> EmittersMessageReceived;
+    typedef WrtDeviceApis::Commons::Emitters<Api::Messaging::EmitterConversationReceived> EmittersConversationReceived;
+    typedef WrtDeviceApis::Commons::Emitters<Api::Messaging::EmitterFolderReceived> EmittersFolderReceived;
+
+  private:
+    Messaging();
+
+    static void onMessageStorageChanged(msg_handle_t handle,
+            msg_storage_change_type_t storageChangeType,
+//            MSG_MSGID_LIST_S *pMsgIdList,
+            msg_id_list_s *pMsgIdList,
+            void* data);
+/*
+    static void onSmsReceived(MSG_HANDLE_T handle,
+            msg_message_t msg,
+            void* data);
+    static void onMmsReceived(MSG_HANDLE_T handle,
+            msg_message_t msg,
+            void* data);
+*/
+  private:
+/*
+    void getNumberOfEmails(Api::Messaging::FolderType folder,
+            int* read,
+            int* unread);
+
+    void getNumberOfSms(Api::Messaging::FolderType folder,
+            int* read,
+            int* unread);
+
+    void getNumberOfMms(Api::Messaging::FolderType folder,
+            int* read,
+            int* unread);
+
+    void getNumberOfSmsMms(Api::Messaging::FolderType folder,
+            int* read,
+            int* unread,
+            Api::Messaging::MessageType msgType);
+
+    virtual std::vector<Api::Messaging::IMessagePtr> findSms(Api::Messaging::FolderType folder,
+               const Api::Tizen::FilterPtr& filter);
+
+    virtual std::vector<Api::Messaging::IMessagePtr> findMms(Api::Messaging::FolderType folder,
+               const Api::Tizen::FilterPtr& filter);
+
+    virtual std::vector<Api::Messaging::IMessagePtr> findEmail(Api::Messaging::FolderType folder,
+               const Api::Tizen::FilterPtr& filter);
+
+    virtual std::vector<Api::Messaging::IMessagePtr> findEmail(const std::string &folder,
+               const Api::Tizen::FilterPtr& filter);
+
+    std::vector<std::string> getSmsIds(Api::Messaging::FolderType folder);
+
+    std::vector<std::string> getMmsIds(Api::Messaging::FolderType folder);
+
+    std::vector<std::string> getEmailIds(Api::Messaging::FolderType folder);
+*/
+
+    void createMsgServiceFolder(const std::string& userFolder);
+
+    void createEmailFolder(const std::string& userFolder);
+
+    void deleteMsgServiceFolder(const std::string& userFolder);
+
+    void deleteEmailFolder(const std::string& userFolder);
+
+    std::vector<std::string> getFolderNamesMsgService();
+
+    std::vector<std::string> getFolderNamesEmail();
+
+
+    void printErrorMessage(int errorCode);
+
+  private:
+    EmittersMessageReceived m_onMessageReceived;
+    EmittersConversationReceived m_onConversationReceived;
+    EmittersFolderReceived m_onFolderReceived;
+    MsgServiceHandleMgrPtr m_onMessageReceivedHandleMgr;
+    DBus::ConnectionPtr m_dbusConnection;
+    DPL::Thread* m_dbusWorkerThread;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/MessagingService.cpp b/src/platform/Tizen/Messaging/MessagingService.cpp
new file mode 100755 (executable)
index 0000000..78f50a1
--- /dev/null
@@ -0,0 +1,322 @@
+//
+// 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 <API/Messaging/EventMessagingService.h>
+#include <API/Messaging/EmailAccountInfo.h>
+#include "MessagingService.h"
+#include "MailSync.h"
+#include "API/Messaging/EventMessagingService.h"
+
+#include <email-types.h>
+#include <email-api.h>
+
+using namespace DPL;
+using namespace std;
+using namespace TizenApis::Api::Messaging;
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+MessagingService::MessagingService() :
+       m_initialized(false)
+{
+    LogDebug("Enter");
+}
+
+MessagingService::~MessagingService() {
+       LogDebug("Leave");
+
+       m_opRequests.clear();   //clean Messaging Service Handles
+}
+
+//public function.
+
+void MessagingService::initialize() {
+       LogDebug("<<<");
+       m_initialized = true;
+
+       
+       LogDebug(">>>");
+}
+
+void MessagingService::setMessagingServiceType(int type)
+{
+       setType(type);
+}
+
+void MessagingService::setMessagingServiceName(const string& name)
+{
+       setName(name);  
+}
+
+void MessagingService::setMessagingServiceId(int serviceId)
+{
+       setId(serviceId);       
+}
+
+int MessagingService::sync(const Api::Messaging::IMessagingServicePtr& messagingService, const int limit)
+{
+       LogDebug("<<<");
+       
+       return MailSync::getInstance().syncAccount( messagingService, limit );
+}
+
+void MessagingService::syncCancel(int handle)
+{
+       LogDebug("<<<");
+       return MailSync::getInstance().syncAccountCancel(handle);
+}
+
+int MessagingService::syncFolder(const Api::Messaging::IMessagingServicePtr& messagingService, const int folder_id, const int limit)
+{
+       LogDebug("<<<");
+       return MailSync::getInstance().syncFolder( messagingService, folder_id, limit);
+}
+
+void MessagingService::syncFolderCancel(int handle)
+{
+       LogDebug("<<<");
+       return MailSync::getInstance().syncFolderCancel(handle);
+}
+
+//operation.
+int MessagingService::createOpId(int type)
+{
+
+       int cnt = m_opRequests.size();  //item count.
+       int index = 0;
+
+       if (cnt > 0)
+       {
+               //OpRequestsIterator it = std::max_element(m_opRequests.begin(), m_opRequests.end(), MessagingService::OpRequest_comparer);
+//             OpRequestsIterator it = m_opRequests.end();
+               OpRequestsIterator it;
+               int lastIndex = 0;
+               for( it = m_opRequests.begin(); it != m_opRequests.end(); ++it)
+               {
+                       lastIndex = it->first;
+               }
+
+               if ( (cnt * MESSAGING_SERVICE_OP_COUNT) >=  lastIndex )
+               {
+                       index = ( lastIndex + MESSAGING_SERVICE_OP_COUNT - ( lastIndex % MESSAGING_SERVICE_OP_COUNT) ) + type;
+               }
+               else
+               {
+                       int preValue = 0;
+
+                       OpRequestsIterator iter;
+       
+                       for( iter = m_opRequests.begin(); iter != m_opRequests.end(); ++iter)
+                       {
+                               int currentValue = iter->first;
+                               
+                               if ( currentValue - preValue > MESSAGING_SERVICE_OP_COUNT)
+                               {
+                                       index = ( preValue + MESSAGING_SERVICE_OP_COUNT - ( preValue % MESSAGING_SERVICE_OP_COUNT) ) + type;
+                                       break;
+                               }
+                               else
+                               {
+                                       index = ( currentValue + MESSAGING_SERVICE_OP_COUNT - ( currentValue % MESSAGING_SERVICE_OP_COUNT) ) + type;
+                               }
+                       }
+                       
+               }
+               
+       }
+       else
+       {
+               index = type;
+       }
+               
+       LogDebug("m_opRequests size : " << cnt );
+       LogDebug("index " << index);
+       m_opRequests.insert(std::make_pair(index, MessagingServiceOpData(0,type)));
+
+       return index;   
+}
+
+int MessagingService::getHandleFromOpId(int opIdx)
+{
+    LogDebug("operation index size : " << opIdx);
+
+    int handle = -1;
+       
+    OpRequestsIterator it = m_opRequests.find(opIdx);
+    if ( m_opRequests.end() != it)
+    {
+               handle = it->second.handle;
+    }
+
+    LogDebug("index " << handle);
+    return handle;
+
+}
+
+Api::Messaging::IMessagePtr MessagingService::getMessageFromOpId(int opIdx)
+{
+       LogDebug("operation index : " << opIdx);
+       OpRequestsIterator it = m_opRequests.find(opIdx);
+       IMessagePtr msg;
+       if ( m_opRequests.end() != it)
+       {
+               msg = it->second.message;
+       }
+
+       return msg;
+}
+
+Api::Messaging::EventMessagingServicePtr MessagingService::getEventFromOpId(int opIdx)
+{
+       LogDebug("operation index : " << opIdx);
+       OpRequestsIterator it = m_opRequests.find(opIdx);
+       EventMessagingServicePtr event;
+       if ( m_opRequests.end() != it)
+       {
+               LogDebug("Find Event");
+               event = it->second.event;
+       }
+
+       return event;
+}
+
+void MessagingService::setHandleToOpId(int opIdx, int handle)
+{
+       LogDebug("operation index : " << opIdx);
+       OpRequestsIterator it = m_opRequests.find(opIdx);
+
+       if ( m_opRequests.end() != it)
+       {
+               LogDebug(" find Message ");
+               it->second.handle = handle;
+       }
+       
+}
+
+void MessagingService::setMessageToOpId(int opIdx, Api::Messaging::IMessagePtr& message)
+{
+       LogDebug("operation index : " << opIdx);
+       OpRequestsIterator it = m_opRequests.find(opIdx);
+
+       if ( m_opRequests.end() != it)
+       {
+               LogDebug("set Message ");
+               it->second.message = message;
+       }
+}
+
+void MessagingService::setEventToOpId(int opIdx, Api::Messaging::EventMessagingServicePtr & event)
+{
+       LogDebug("operation index : " << opIdx);
+       OpRequestsIterator it = m_opRequests.find(opIdx);
+
+       if ( m_opRequests.end() != it)
+       {
+               LogDebug("set Message ");
+               if (event)
+               {
+                       LogDebug("vaild event ");
+                       it->second.event = event;
+               }
+       }
+}
+
+int MessagingService::getOpTypeFromOpId(int opIdx)
+{
+    LogDebug("operation index : " << opIdx);
+
+    int type = 0;
+       
+    OpRequestsIterator it = m_opRequests.find(opIdx);
+    if ( m_opRequests.end() != it)
+    {
+               type = it->second.type;
+    }
+
+    LogDebug("type " << type);
+    return type;
+}
+
+int MessagingService::deleteOpId(int opIdx)
+{
+       
+       OpRequestsIterator it = m_opRequests.find(opIdx);
+       if ( m_opRequests.end() != it)
+       {
+               m_opRequests.erase(it); //delete
+               LogDebug("delete Request : " << m_opRequests.size());
+       }
+       return opIdx;
+}
+
+void MessagingService::cancelOperation(int opId, int handle, int eventType, Api::Messaging::IMessagePtr& message)
+{
+       if (handle > 0)
+       {
+               if (eventType == MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY
+                       || eventType == MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT)
+               {
+                       Api::Messaging::IEmailPtr email = DPL::DynamicPointerCast<IEmail >(message);
+                       if (email) 
+                       {
+                               if ( eventType == MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY )
+                               {       
+                                       LogDebug("Cancel Download Body , handle = " << handle);
+                                       email->downloadBodyCancel(handle);
+                               }
+                               else if ( eventType == MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT)
+                               {
+                                       LogDebug("Cancel Download Attachment , handle = " << handle);
+                                       email->downloadAttachmentCancel(handle);
+                               }                               
+                       }
+                       else
+                       {
+                               ThrowMsg(  WrtDeviceApis::Commons::ConversionException, "Conversion IMessage to IEmail error");
+                       }
+
+               }
+               else if (eventType == MESSAGING_SERVICE_EVENT_TYPE_SYNC)
+               {
+                       syncCancel(handle);
+               }
+               else if (eventType == MESSAGING_SERVICE_EVENT_TYPE_SYNC_FOLDER)
+               {
+                       syncFolderCancel(handle);
+               }
+               else if (eventType == MESSAGING_SERVICE_EVENT_TYPE_SEND_MESSAGE)
+               {
+                       message->sendCancel(handle);
+                       deleteOpId(opId);
+               }
+               else
+               {
+
+               }
+                                               
+       }
+       
+}
+
+}
+}      //namespace Platform
+}      //namespace WrtPlugins
+
diff --git a/src/platform/Tizen/Messaging/MessagingService.h b/src/platform/Tizen/Messaging/MessagingService.h
new file mode 100755 (executable)
index 0000000..362ea5a
--- /dev/null
@@ -0,0 +1,112 @@
+//
+// 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_PLATFORM_MESSAGING_SERVICE_H_
+#define WRTPLUGINS_PLATFORM_MESSAGING_SERVICE_H_
+
+#include <map>
+#include <dpl/generic_event.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+
+#include <API/Messaging/IMessagingService.h>
+#include <API/Messaging/EventMessagingService.h>
+
+//#include <Commons/Emitters.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+//DECLARE_GENERIC_EVENT_0(JobDoneEvent)        //for manual answer  (async call)
+//=============================================================================
+class MessagingService: 
+   public Api::Messaging::IMessagingService
+{
+public:
+       MessagingService();
+       virtual ~MessagingService();
+       //interface     
+       //virtual void createMessage(const Api::Messaging::EventMessagingServicePtr& event);
+       void setMessagingServiceType(int type);
+       void setMessagingServiceName(const std::string& name);
+       void setMessagingServiceId(int serviceId);
+               
+       virtual int sync(const Api::Messaging::IMessagingServicePtr& messagingService, const int limit);
+       virtual void syncCancel(int handle);
+       virtual int syncFolder(const Api::Messaging::IMessagingServicePtr& messagingService, const int folder_id, const int limit);
+       virtual void syncFolderCancel(int handle);
+
+       virtual void cancelOperation(int opId, int handle, int eventType, Api::Messaging::IMessagePtr& message);
+
+       int createOpId(int type);
+       int getHandleFromOpId(int opId);
+       int getOpTypeFromOpId(int opId);
+       Api::Messaging::IMessagePtr getMessageFromOpId(int opId);
+       Api::Messaging::EventMessagingServicePtr getEventFromOpId(int opId);
+       
+       void setHandleToOpId(int opId, int handle);
+       void setMessageToOpId(int opId, Api::Messaging::IMessagePtr& message);
+       void setEventToOpId(int opId, Api::Messaging::EventMessagingServicePtr& event);
+       int deleteOpId(int opId);
+
+protected:
+       //virtual void OnRequestReceived(const Api::Messaging::EventMessagingServicePtr& event);
+
+private:
+       
+       int create_messaging_service();
+       void initialize();
+       bool m_initialized;
+
+       //EventGetMessagingServicePtr plugin_event;
+
+       enum {
+               MessagingServiceManager_ERROR_NONE = 0,
+               MessagingServiceManager_ERROR_INVALID_PARAMETER = 1,
+               MessagingServiceManager_ERROR_PLATFORM_SERVICE_NOT_AVAILABLE = 2,
+               MessagingServiceManager_ERROR_UNKNOWN = 3,
+       };
+
+       struct MessagingServiceOpData
+       {
+               unsigned int handle;
+               unsigned short type;
+               Api::Messaging::IMessagePtr message;
+               Api::Messaging::EventMessagingServicePtr event;
+
+               explicit MessagingServiceOpData(int handle, int type) :
+                   handle(handle),
+                   type(type),
+                   message(NULL),
+                   event(NULL)
+               {
+               }
+       };
+       
+       typedef std::map<int, MessagingServiceOpData> OpRequests;
+       typedef OpRequests::iterator OpRequestsIterator;        
+
+       OpRequests m_opRequests;        // create operation
+       
+};
+
+
+}
+}
+}
+#endif /* WRTPLUGINS_PLATFORM_MESSAGING_SERVICE_H_ */
diff --git a/src/platform/Tizen/Messaging/MessagingServiceManager.cpp b/src/platform/Tizen/Messaging/MessagingServiceManager.cpp
new file mode 100755 (executable)
index 0000000..664c1a2
--- /dev/null
@@ -0,0 +1,242 @@
+//
+// 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 <API/Messaging/EventGetMessagingService.h>
+#include "MessagingServiceManager.h"
+#include "MessagingService.h"
+
+//for email service
+#include <email-types.h>
+#include <email-api.h>
+
+using namespace std;
+using namespace DPL;
+using namespace TizenApis::Api::Messaging;
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {  
+
+MessagingServiceManager::MessagingServiceManager() :
+       m_initialized(false), 
+       messaging_service_handler(-1) 
+{
+    LogDebug("Enter");
+
+}
+
+MessagingServiceManager::~MessagingServiceManager() {
+       LogDebug("Leave");
+}
+
+std::vector<Api::Messaging::EmailAccountInfo> MessagingServiceManager::getEmailAccounts()
+{
+       email_account_t* accounts = NULL;
+       int count = 0;
+       std::vector<Api::Messaging::EmailAccountInfo> result;
+       
+       Try {
+               if (email_get_account_list(&accounts, &count)) {
+                       if (0 < count)
+                       {
+                               std::stringstream stream;
+                               for (int i = 0; i < count; ++i) {
+                                       stream << "[" << accounts[i].account_name << "] " << accounts[i].incoming_server_user_name;
+                                       LogDebug("account ID :" << accounts[i].account_id << "Name :" << accounts[i].incoming_server_user_name << "Addr :" << accounts[i].user_email_address );
+                                       Api::Messaging::EmailAccountInfo account(accounts[i].account_id,
+                                                                 stream.str(),
+                                                                 accounts[i].user_email_address );
+                                       result.push_back(account);
+                                       stream.str("");
+                               }
+
+                       }
+                       if (accounts != NULL) {
+                               email_free_account(&accounts, count);
+                       }
+               }               
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+
+               if (accounts != NULL) {
+                       email_free_account(&accounts, count);
+               }
+      }
+               
+       return result;
+}
+
+//public function.
+void MessagingServiceManager::getMessagingServiceManager(const EventGetMessagingServicePtr& event) {
+       LogDebug("<<<");
+
+       LogDebug("event->getAccountID():" << event->getAccountID());
+
+       if (m_initialized == false) {
+               initialize();
+       }
+
+       EventRequestReceiver<EventGetMessagingService>::PostRequest(event);
+
+       LogDebug(">>>");
+}
+
+//get the request which posted from the standard layer
+void MessagingServiceManager::OnRequestReceived(const EventGetMessagingServicePtr& event)
+{
+       LogDebug("<<<");
+       
+       try 
+       {
+               m_messagingServices.clear();    //clear services
+               if (m_messagingServices.empty())
+               {
+                       //ToDo: The Message Service Code will be inserted here.
+                       LogDebug("Message Service Type : " << event->getMessagingServiceType());
+                       if ( event->getMessagingServiceType() == Api::Messaging::SMS)
+                       {
+                               MessagingService* messagingService = new MessagingService();
+                               messagingService->setMessagingServiceType(Api::Messaging::SMS);
+                               messagingService->setMessagingServiceName("messaging.sms");
+                               messagingService->setMessagingServiceId(Api::Messaging::SMS_ACCOUNT_ID);
+                               
+                               //ToDol: set messaging Service instance.
+                               m_messagingServices.push_back(Api::Messaging::IMessagingServicePtr(messagingService));
+                       }
+                       else if ( event->getMessagingServiceType() == Api::Messaging::MMS)
+                       {
+                               MessagingService* messagingService = new MessagingService();
+                               messagingService->setMessagingServiceType(Api::Messaging::MMS);
+                               messagingService->setMessagingServiceName("messaging.mms");
+                               messagingService->setMessagingServiceId(Api::Messaging::MMS_ACCOUNT_ID);
+                               
+                               m_messagingServices.push_back(Api::Messaging::IMessagingServicePtr(messagingService));
+                       }
+                       else if (event->getMessagingServiceType() == Api::Messaging::EMAIL)
+                       {       
+                               std::vector<Api::Messaging::EmailAccountInfo> EmailAccounts = getEmailAccounts();
+                               LogDebug("get Account list, size:" << EmailAccounts.size());
+                               
+                               int idx = 0;
+                               for ( idx = 0 ; idx < (int)EmailAccounts.size(); idx++)
+                               {
+                                       LogDebug("Account ID:" << EmailAccounts[idx].getIntId() );
+
+                                       MessagingService* messagingService = NULL;
+                                       messagingService = new MessagingService();
+                                       messagingService->setMessagingServiceType(Api::Messaging::EMAIL);
+                                       messagingService->setCurrentEmailAccount( EmailAccounts[idx] );
+
+                                       LogDebug("Account ID:" << event->getAccountID());
+                                       if ( event->getAccountID() >= 0 )
+                                       {
+                                               if (event->getAccountID() == EmailAccounts[idx].getIntId())
+                                                       m_messagingServices.push_back(Api::Messaging::IMessagingServicePtr(messagingService));
+                                               else
+                                                       delete messagingService;        //remove service.
+                                       }
+                                       else 
+                                       {
+                                               m_messagingServices.push_back(Api::Messaging::IMessagingServicePtr(messagingService));
+                                       }
+                                       
+                               }
+                                                                                       
+                       }
+
+               }
+               
+               event->setMessagingServicesRef(m_messagingServices);    //set message services
+       }
+       catch (WrtDeviceApis::Commons::Exception &exc)
+       {
+               LogError("Exception has occurred: " << std::hex << exc.getCode());
+       event->setExceptionCode(exc.getCode());
+       }
+
+       LogDebug(">>>");
+}
+
+// create platform's resources. For examples, it could be camera handle, location handle and so on.
+
+void MessagingServiceManager::initialize() {
+       LogDebug("<<<");
+
+       if (!m_initialized) {
+       //              retVal = create_messaging_service();
+       //              if(retVal != MessagingServiceManager_ERROR_NONE){
+       //                      ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Couldn't init MEssagingServiceManager module.");
+       //              }
+                       m_initialized = true;
+       }
+       
+       LogDebug(">>>");
+}
+
+#if 0
+void MessagingServiceManager::getEmailAccountList( vector<Api::Messaging::EmailAccountInfo>& accounts )
+{
+       LogDebug("<<<");
+
+       email_account_t* email_accounts = NULL;
+       int count = 0;
+       Try {
+               if (!email_get_account_list(&email_accounts, &count)) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                       "Couldn't get e-mail accounts.");
+               }
+
+               if (0 == count) {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "No e-mail account found.");
+               }
+       
+               for (int i = 0; i < count; ++i) {
+                       //make email account info.
+
+                       LogDebug("account id :" << email_accounts[i].account_id );
+                       LogDebug("account name :" << email_accounts[i].user_name );
+                       LogDebug("account addr :" << email_accounts[i].email_addr );
+
+                       Api::Messaging::EmailAccountInfo account(email_accounts[i].account_id,
+                                                  email_accounts[i].incoming_server_user_name,
+                                            email_accounts[i].user_email_address);
+                       if (std::find(accounts.begin(), accounts.end(), account) == accounts.end()) {
+                               LogDebug( "push " << email_accounts[i].account_id <<  "account" );
+                               accounts.push_back(account);
+                       }
+               }
+
+               if (email_accounts != NULL) {
+                       email_free_account(&email_accounts, count);     //free
+               }
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               if (email_accounts != NULL) {
+                       email_free_account(&email_accounts, count);
+               }
+               throw;
+       }
+       
+       LogDebug(">>>");
+}
+#endif
+
+}
+}      //namespace Platform
+}      //namespace WrtPlugins
diff --git a/src/platform/Tizen/Messaging/MessagingServiceManager.h b/src/platform/Tizen/Messaging/MessagingServiceManager.h
new file mode 100755 (executable)
index 0000000..1ab6b04
--- /dev/null
@@ -0,0 +1,83 @@
+//
+// 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_PLATFORM_MESSAGING_SERVICE_MANAGER_H_
+#define WRTPLUGINS_PLATFORM_MESSAGING_SERVICE_MANAGER_H_
+
+#include <map>
+#include <dpl/generic_event.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+//#include <Commons/Emitters.h>
+
+#include <API/Messaging/IMessagingServiceManager.h>
+#include <API/Messaging/MessagingFactory.h>
+#include <API/Messaging/EmailAccountInfo.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+//DECLARE_GENERIC_EVENT_0(JobDoneEvent)
+//=============================================================================
+class MessagingServiceManager: 
+   public Api::Messaging::IMessagingServiceManager
+{
+
+    friend class Api::Messaging::MessagingFactory;
+public:
+       virtual ~MessagingServiceManager();
+
+       //virtual void getMessagingService(const EventGetMessagingServicePtr& event);
+       virtual void getMessagingServiceManager (const Api::Messaging::EventGetMessagingServicePtr& event);
+       
+       static std::vector<Api::Messaging::EmailAccountInfo> m_EmailAccounts;
+       
+protected:
+       MessagingServiceManager();
+       virtual void OnRequestReceived(const Api::Messaging::EventGetMessagingServicePtr& event);
+
+private:
+       
+#if 0  
+       void getMessagingServiceAll(const Api::Messaging::EventGetMessagingServicePtr& event);
+       void getMessagingServiceAccount(const Api::Messaging::EventGetMessagingServicePtr& event);
+#endif
+
+       void initialize();
+       int create_messaging_service();
+#if 0
+       void getEmailAccountList(std::vector<Api::Messaging::EmailAccountInfo>& accounts);
+#endif
+       std::vector<Api::Messaging::EmailAccountInfo> getEmailAccounts();
+
+       bool m_initialized;
+       
+       enum {
+               MessagingServiceManager_ERROR_NONE = 0,
+               MessagingServiceManager_ERROR_INVALID_PARAMETER = 1,
+               MessagingServiceManager_ERROR_PLATFORM_SERVICE_NOT_AVAILABLE = 2,
+               MessagingServiceManager_ERROR_UNKNOWN = 3,
+       };
+
+       int messaging_service_handler;          //for test, now temporary.
+};
+
+}
+}
+}
+#endif /* WRTPLUGINS_PLATFORM_MESSAGING_SERVICE_MANAGER_H_ */
diff --git a/src/platform/Tizen/Messaging/Mms.cpp b/src/platform/Tizen/Messaging/Mms.cpp
new file mode 100755 (executable)
index 0000000..c1fda02
--- /dev/null
@@ -0,0 +1,1423 @@
+//
+// 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 "Mms.h"
+
+#include <vector>
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <API/Messaging/ReqReceiverMessage.h>
+#include "Messaging.h"
+#include "CallbackMgr.h"
+#include "MsgServiceHandleMgr.h"
+
+extern "C" {
+#include <msg.h>
+#include <msg_storage.h>
+}
+
+
+namespace {
+const char* TEXT_AREA = "Text";
+const char* TEXT_FILE_EXTENSION = ".txt";
+const char* TEXT_DIR_PREFIX = "/tmp/";
+const int WHITE_COLOR = 0xffffff;
+const int BLACK_COLOR = 0x000000;
+const int ROOT_LAYOUT_WIDTH = 100;
+const int ROOT_LAYOUT_HEIGHT = 100;
+const char* EMPTY_ID = "0";
+}
+
+using namespace std;
+using namespace TizenApis::Api::Messaging;
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+Mms::Mms(const string& id) :
+    IMessage(MMS, id),
+//    m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
+    m_messageData(NULL)
+{
+       LogDebug("m_id=" << getIdRef());
+       LogDebug("m_msgType=" << getMessageType());
+
+       char buf[] = "XXXXXX";
+       mode_t mask = umask(S_IWGRP | S_IWOTH);
+       int i = mkstemp(buf);
+       LogDebug("buf : " << buf << " i : " << i);
+       umask(mask);
+       m_bodyFilePath = buf;
+       m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
+
+       LogDebug("m_bodyFilePath : " << m_bodyFilePath);
+
+       if (getIdRef().empty()) {
+               LogDebug("create new message");
+               createNewMessage();
+       } else {
+               LogDebug("read existing message");
+               readExistingMessage();
+       }
+}
+
+Mms::Mms(const string& id, const msg_struct_t msg_data) :
+       IMessage(MMS, id),
+//     m_bodyFilePath(string(tmpnam(NULL)) + TEXT_FILE_EXTENSION),
+       m_messageData(msg_data)
+{
+       LogDebug("m_id=" << getIdRef());
+       LogDebug("m_msgType=" << getMessageType());
+
+       char buf[] = "XXXXXX";
+       mode_t mask = umask(S_IWGRP | S_IWOTH);
+       int i = mkstemp(buf);
+       LogDebug("buf : " << buf << " i : " << i);
+       umask(mask);
+       m_bodyFilePath = buf;
+       m_bodyFilePath = TEXT_DIR_PREFIX+m_bodyFilePath+TEXT_FILE_EXTENSION;
+       
+       LogDebug("m_bodyFilePath : " << m_bodyFilePath);
+       
+       readRecipientList(m_messageData);
+       readPriority(m_messageData);
+       readSubject(m_messageData);
+       readBodyAndAttachments(m_messageData);
+       readFolder(m_messageData);
+       readDateTime(m_messageData);
+       readReadStatus(m_messageData);
+       readMessageStatus(m_messageData);
+//     setMessageStatus(Api::Messaging::MESSAGE_STATUS_LOADED);
+
+}
+
+Mms::~Mms()
+{
+    LogDebug("enter");
+
+    if (m_messageData) {
+        // release platform message structure
+//        msg_release_message(&m_messageData);
+        msg_release_struct(&m_messageData);
+    }
+
+    //remove tmp file
+    //trying to remove file, return value is skipped
+    if (!m_bodyFilePath.empty()) {
+        LogDebug("remove tmp file=" << m_bodyFilePath);
+        (void) ::remove(m_bodyFilePath.c_str());
+    }
+}
+
+void Mms::createNewMessage()
+{
+    if (m_messageData) {
+        msg_release_struct(&m_messageData);
+        m_messageData = NULL;
+    }
+
+    char strSubject[MAX_SUBJECT_LEN] = {0,};
+
+    m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+    msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+//    msg_struct_t option = NULL;
+
+    // initialize platform message structure
+    msg_set_int_value(m_messageData, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS);
+    msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
+    msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, strSubject, MAX_SUBJECT_LEN);
+
+    setMmsType(MULTIPART_MIXED);
+    setReadStatus(false);
+    setMessageStatus(Api::Messaging::MESSAGE_STATUS_CREATED);
+
+       msg_release_struct(&sendOpt);
+    LogDebug("Message created successfully, Id: " << getIdRef());
+}
+
+void Mms::readExistingMessage()
+{
+       LogDebug("entered");
+
+       if (getIdRef().empty() || (EMPTY_ID == getIdRef())) 
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
+       }
+
+       msg_release_struct(&m_messageData);
+       m_messageData = NULL;
+       msg_struct_t sendOpt = NULL;
+
+       Try {
+
+               m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+               sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+
+               // trying to get message from platform
+               if (MSG_SUCCESS != msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), m_messageData, sendOpt)) 
+               {
+                       LogError("get message error");
+                       Throw(WrtDeviceApis::Commons::PlatformException);
+               }
+               LogDebug("message found with msgId=" << getIdRef());
+
+               // read all mms dat to abstraction layer
+               readRecipientList(m_messageData);
+               readPriority(m_messageData);
+               readSubject(m_messageData);
+               readBodyAndAttachments(m_messageData);
+               readFolder(m_messageData);
+               readDateTime(m_messageData);
+               readReadStatus(m_messageData);
+               readMessageStatus(m_messageData);
+
+               msg_release_struct(&sendOpt);
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               LogError("exception");
+               // nothing to do
+               msg_release_struct(&sendOpt);
+       }
+}
+
+void Mms::readDateTime(msg_struct_t& messageData)
+{
+//  tm* time = localtime(msg_get_time(messageData));
+//    tm dateT = getDateTime();
+    int tempInt = 0;
+    msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
+
+    LogError("readDateTime : " <<tempInt);
+
+    tm* time = localtime((time_t*)&tempInt);
+    if (!time) {
+        LogError("localtime failed");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+    setDateTime(*time);
+}
+
+void Mms::readReadStatus(msg_struct_t& messageData)
+{
+    bool tempBool = 0;
+    msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
+    setReadStatus(tempBool);
+}
+
+void Mms::readFolder(msg_struct_t& messageData)
+{
+    int tempValue = 0;
+    msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
+
+    switch (tempValue) {
+    case MSG_INBOX_ID:
+        setFolderType(Api::Messaging::INBOX);
+        break;
+    case MSG_OUTBOX_ID:
+        setFolderType(Api::Messaging::OUTBOX);
+        break;
+    case MSG_SENTBOX_ID:
+        setFolderType(Api::Messaging::SENTBOX);
+        break;
+    case MSG_DRAFT_ID:
+        setFolderType(Api::Messaging::DRAFTBOX);
+        break;
+    default:
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
+    }
+}
+
+void Mms::readMessageStatus(msg_struct_t& messageData)
+{
+       int tempValue = 0;
+       msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
+
+       LogDebug("readMessageStatus folder : " << tempValue);
+
+       switch (tempValue) {
+               case MSG_INBOX_ID:
+                       setMessageStatus(Api::Messaging::MESSAGE_STATUS_LOADED);
+                       break;
+               case MSG_OUTBOX_ID:
+                       setMessageStatus(Api::Messaging::MESSAGE_STATUS_SENDING);
+                       break;
+               case MSG_SENTBOX_ID:
+                       setMessageStatus(Api::Messaging::MESSAGE_STATUS_SENT);
+                       break;
+               case MSG_DRAFT_ID:
+                       setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
+                       break;
+               default:
+                       setMessageStatus(Api::Messaging::MESSAGE_STATUS_LOADED);
+                       break;
+       }
+}
+
+void Mms::readPriority(msg_struct_t& messageData)
+{
+//    switch (msg_get_priority_info(messageData)) {
+    int tempInt = 0;
+    msg_get_int_value(messageData, MSG_MESSAGE_PRIORITY_INT, &tempInt);
+    switch (tempInt) {
+    case MSG_MESSAGE_PRIORITY_LOW:
+        setPriority(MessagePriority::LOW);
+        break;
+    case MSG_MESSAGE_PRIORITY_NORMAL:
+        setPriority(MessagePriority::NORMAL);
+        break;
+    case MSG_MESSAGE_PRIORITY_HIGH:
+        setPriority(MessagePriority::HIGH);
+        break;
+    default:
+        LogError("Wrong priority type");
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong priority type");
+    }
+}
+
+void Mms::readRecipientList(msg_struct_t& messageData)
+{
+       std::string phoneNumber;
+//     int recipientCount = msg_get_address_count(messageData);
+//     LogDebug("Recipient count " << recipientCount);
+
+       msg_struct_list_s *addr_list;
+       msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+
+       int tempInt = 0;
+       char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
+
+       int recipientCount = addr_list->nCount;
+       LogDebug("Recipient count " << recipientCount);
+
+       for (int i = 0; i < recipientCount; ++i) 
+       {
+//        int type = msg_get_direction_info(messageData);
+               msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
+               int type = tempInt;
+               LogDebug("Direction: " << type);
+
+               if (MSG_DIRECTION_TYPE_MT == type) 
+               {
+                       msg_struct_t addr_info = addr_list->msg_struct_info[i];
+                       memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
+                       msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                       phoneNumber = strNumber;
+               
+                       if (validatePhoneNumber(phoneNumber)) 
+                       {
+                               setSourceAddress(phoneNumber);
+                               setFrom(phoneNumber);
+                       }
+                       LogDebug("MT number: " << phoneNumber);
+               } 
+               else if (MSG_DIRECTION_TYPE_MO == type) 
+               {
+                       msg_struct_t addr_info = addr_list->msg_struct_info[i];
+                       memset(strNumber, 0x00, sizeof(MAX_ADDRESS_VAL_LEN));
+                       msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                       msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
+                       LogDebug("MO number: " << strNumber);
+                       LogDebug("Type : " << tempInt);
+                       switch (tempInt) 
+                       {
+                               case MSG_RECIPIENTS_TYPE_TO:
+                                       appendToRecipients(strNumber);
+                                       break;
+                               case MSG_RECIPIENTS_TYPE_CC:
+                                       appendCcRecipients(strNumber);
+                                       break;
+                               case MSG_RECIPIENTS_TYPE_BCC:
+                                       appendBccRecipients(strNumber);
+                                       break;
+                               default:
+                               LogError("Wrong type of recipient");
+                       }
+               } 
+               else 
+               {
+                       LogError("Wrong type of recipient");
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
+               }
+       }
+}
+
+void Mms::readSubject(msg_struct_t& messageData)
+{
+    char strTemp[MAX_SUBJECT_LEN] = {0};
+    msg_get_str_value(messageData, MSG_MESSAGE_SUBJECT_STR, strTemp, MAX_SUBJECT_LEN);
+//    setSubject(msg_get_subject(messageData));
+    LogError("readSubject : " << strTemp);
+    setSubject(strTemp);
+}
+
+void Mms::readBodyAndAttachments(msg_struct_t& messageData)
+{
+
+       int pageLen, mediaLen, attachLen, tempInt;
+
+       msg_struct_t mms_struct = NULL;
+
+       msg_list_handle_t page_list = NULL;
+       msg_list_handle_t media_list = NULL;
+       msg_list_handle_t attach_list = NULL;
+       
+       msg_struct_t page = NULL;
+       msg_struct_t media = NULL;
+       msg_struct_t attach = NULL;
+
+       mms_struct = msg_create_struct(MSG_STRUCT_MMS);
+       msg_get_mms_struct(messageData, mms_struct );
+
+       char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
+       char szFileName[MSG_FILENAME_LEN_MAX] = {0,};
+
+       msg_get_list_handle(mms_struct, MSG_MMS_PAGE_LIST_HND, (void **)&page_list);
+       pageLen = msg_list_length(page_list);
+
+       if (pageLen > 0) {
+               setMmsType(MULTIPART_RELATED);
+       } else {
+               setMmsType(MULTIPART_MIXED);
+       }
+
+       LogDebug("page count: " << pageLen);
+
+       for (int p = 0; p < pageLen; ++p) 
+       {
+               LogDebug("page " << p);
+               page = (msg_struct_t)msg_list_nth_data(page_list, p);
+               
+               if (NULL  == page) {
+                       LogError("returned page is null, continue");
+                       continue;
+               }
+               
+               msg_get_list_handle(page, MSG_MMS_PAGE_MEDIA_LIST_HND, (void **)&media_list);
+               mediaLen = msg_list_length(media_list);
+
+               for (int m = 0; m < mediaLen; ++m) 
+               {
+                       LogDebug("media file " << m);
+                       media = (msg_struct_t)msg_list_nth_data(media_list, m);
+                       if (NULL == media) 
+                       {
+                               LogError("returned media is null, continue");
+                               continue;
+                       }
+
+                       msg_get_int_value(media, MSG_MMS_MEDIA_TYPE_INT, &tempInt);
+
+                       memset(szFilePath, 0, sizeof(szFilePath));
+                       msg_get_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
+                       
+                       if ((0 == p) && (MMS_SMIL_MEDIA_TEXT == tempInt)) 
+                       {
+                               //text value on first page goes to body attribute
+                               LogDebug("setting body from " << szFilePath);
+                               
+                               FILE* f = NULL;
+                               f = fopen(szFilePath, "r");
+                               if (!f) 
+                               {
+                                       LogError("cannot read file with body" << szFilePath);
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                       "Cannot read file with body");
+                               }
+                               fseek(f, 0, SEEK_END);
+                               long int size = ftell(f);
+                               fseek(f, 0, SEEK_SET);
+                               char* data = new (nothrow) char[size + 1];
+                               size_t error;
+                               if (data) {
+                                       memset(data, 0, size + 1);
+                                       error = fread(data, 1, size, f);
+                                       setBody(data);
+                                       delete[] data;
+                               } else {
+                                       LogError("body is not set");
+                               }
+                               LogDebug("message body: '" << getBody() << "'");
+                               fclose(f);
+                       } 
+                       else 
+                       {
+                               LogDebug("adding attachment " << szFilePath);
+
+                               IAttachmentPtr attachment = appendAttachment(szFilePath, false);
+                               //attachment->setMessage(this); //set IMessagePtr
+
+                               memset(szFileName, 0, sizeof(szFileName));
+                               msg_get_str_value(media, MSG_MMS_MEDIA_FILENAME_STR, szFileName, sizeof(szFileName));
+                               if ((szFileName[0] =! '\0' )&& (strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0)) 
+                               {
+                                       LogDebug("renaming to " << szFileName);
+                                       attachment->rename(szFileName);
+                               }
+                               else if (MMS_SMIL_MEDIA_TEXT == tempInt) 
+                               {
+                                       std::stringstream newName;
+                                       newName << "body_page_" << p + 1 << ".txt";
+                                       LogDebug("renaming to " << newName.str());
+                                       attachment->rename(newName.str());
+                               }
+                       }
+               }
+       }
+
+       msg_get_list_handle(mms_struct, MSG_MMS_ATTACH_LIST_HND, (void **)&attach_list);
+       
+       attachLen= msg_list_length(attach_list);
+
+       LogDebug("attachment count: " << attachLen);
+       for (int a = 0; a < attachLen; ++a) 
+       {
+               attach = (msg_struct_t)msg_list_nth_data(attach_list, a);
+               if (NULL == attach) 
+               {
+                       LogError("attachment is null, continue");
+                       continue;
+               }
+
+               memset(szFilePath, 0, sizeof(szFilePath));
+               memset(szFileName, 0, sizeof(szFileName));
+
+               msg_get_str_value(attach, MSG_MMS_ATTACH_FILEPATH_STR, szFilePath, sizeof(szFilePath));
+               msg_get_str_value(attach, MSG_MMS_ATTACH_FILENAME_STR, szFileName, sizeof(szFileName));
+               
+               IAttachmentPtr att = appendAttachment(szFilePath, false);
+               if ((szFileName[0] =! '\0') &&
+                       strnlen(szFileName, MSG_FILENAME_LEN_MAX) > 0) {
+                       LogDebug("renaming to " << szFileName);
+                       att->rename(szFileName);
+               }
+       }
+       msg_release_struct(&mms_struct);
+}
+
+bool Mms::hasAttachment()
+{
+       std::size_t attachmentSize = getAttachmentsCount();
+       if ( attachmentSize > 0)
+               return true;
+       else
+               return false;
+}
+
+void Mms::update(bool draftsOnly)
+{
+    LogDebug("updating m_id=" << getIdRef());
+
+    if (!m_messageData) {
+        //error if platform message not exists
+        LogError("message can not be updated");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+
+    //update mms data from abstraction
+    if (!draftsOnly || getCurrentFolder() == Api::Messaging::DRAFTBOX) {
+        updateSubject();
+        updateBodyAndAttachments();
+        updateRecipientList();
+        updatePriority();
+    }
+    updateReadStatus();
+}
+
+void Mms::updatePriority()
+{
+    if (isPriorityValid()) {
+        return;
+    }
+    int priority = -1;
+    LogInfo("MMS updating priority");
+
+    //set priority in platform
+    switch (getPriority()) {
+    case MessagePriority::LOW:
+        priority = MSG_MESSAGE_PRIORITY_LOW;
+        break;
+    case MessagePriority::NORMAL:
+        priority = MSG_MESSAGE_PRIORITY_NORMAL;
+        break;
+    case MessagePriority::HIGH:
+        priority = MSG_MESSAGE_PRIORITY_HIGH;
+        break;
+    default:
+        LogError("Wrong priority");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+    LogInfo("priority : " << priority);
+
+    if (MSG_SUCCESS !=
+       msg_set_int_value(m_messageData, MSG_MESSAGE_PRIORITY_INT, priority)){
+        
+        LogError("Error during setting priority");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+}
+
+void Mms::updateRecipientList()
+{
+    // check if abstraction recipient value has been changed
+    if (getToRecipients().isValid() &&
+        getBccRecipients().isValid() &&
+        getCcRecipients().isValid()) {
+        return;
+    }
+
+    LogInfo("MMS updating platform recipients");
+
+    // reset addresses in platform structure
+//    msg_reset_address(m_messageData);
+       msg_struct_list_s *addr_list = NULL;
+       msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+       int nToCnt = 0;
+       nToCnt = addr_list->nCount;
+
+       LogInfo("addr_list->nCount" << addr_list->nCount);
+       
+       if (nToCnt > 0)         
+       {               
+               for (int i = 0; i < nToCnt; i++) {      
+                       msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, (char *)"", 0);
+                       msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, (char *)"", 0);
+                       msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
+                       msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_UNKNOWN);
+                       msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, 0);
+               }
+               nToCnt = 0;
+               addr_list->nCount = nToCnt;
+       }               
+
+       LogInfo("addr_list->nCount" << addr_list->nCount);
+
+       vector<string> to = getToRecipients().getRecipients();
+       vector<string> cc = getCcRecipients().getRecipients();
+       vector<string> bcc = getBccRecipients().getRecipients();
+
+       // update addresses in platform structure
+       if (to.size()) 
+       {
+               LogInfo("updating to");
+               for (size_t i = 0; i < to.size(); i++) 
+               {
+                       if (i >= MAX_TO_ADDRESS_CNT) 
+                       {
+                               LogError("max number of recipient exceeded");
+                               break;
+                       }
+                       LogDebug("adding to[" << i << "]=" << to[i]);
+
+                       msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
+
+                       if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, 
+                               MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS) 
+                       {
+                               LogError("problem with adding to address");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
+                       }
+                       
+                       if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, 
+                               const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS) 
+                       {
+                               LogError("problem with adding to address");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
+                       }
+                       nToCnt ++;
+               }
+               addr_list->nCount = nToCnt;
+               LogError("nToCnt : " << nToCnt);
+               LogError("addr_list->nCount: " <<addr_list->nCount);
+               
+       }
+       
+       LogInfo("addr_list->nCount" << addr_list->nCount);
+
+       if (cc.size()) 
+       {
+               LogInfo("updating cc");
+               for (size_t i = 0; i < cc.size(); i++) 
+               {
+                       if (nToCnt >= MAX_TO_ADDRESS_CNT) 
+                       {
+                               LogError("max number of recipient exceeded");
+                               break;
+                       }
+                       LogDebug("adding cc[" << i << "]=" << cc[i]);
+
+                       msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
+
+                       if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, 
+                               MSG_RECIPIENTS_TYPE_CC) != MSG_SUCCESS) 
+                       {
+                               LogError("problem with adding cc address");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
+                       }
+                       
+                       if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, 
+                               const_cast<char*>(cc[i].c_str()), cc[i].size()) != MSG_SUCCESS) 
+                       {
+                               LogError("problem with adding cc address");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding cc address");
+                       }
+                       nToCnt ++;
+               }
+               addr_list->nCount = nToCnt;
+               LogError("nToCnt : " << nToCnt);
+               LogError("addr_list->nCount: " <<addr_list->nCount);
+       }
+
+       LogInfo("addr_list->nCount" << addr_list->nCount);
+
+       if (bcc.size()) 
+       {
+               LogInfo("updating bcc");
+               for (size_t i = 0; i < bcc.size(); i++) 
+               {
+                       if (nToCnt >= MAX_TO_ADDRESS_CNT) 
+                       {
+                               LogError("max number of recipient exceeded");
+                               break;
+                       }
+                       LogDebug("adding bcc[" << i << "]=" << bcc[i]);
+
+                       msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
+
+                       if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, 
+                               MSG_RECIPIENTS_TYPE_BCC) != MSG_SUCCESS) 
+                       {
+                               LogError("problem with adding bcc address");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
+                       }
+                       
+                       if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, 
+                               const_cast<char*>(bcc[i].c_str()), bcc[i].size()) != MSG_SUCCESS) 
+                       {
+                               LogError("problem with adding bcc address");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding bcc address");
+                       }
+                       nToCnt ++;
+               }
+               addr_list->nCount = nToCnt;
+               LogError("nToCnt : " << nToCnt);
+               LogError("addr_list->nCount: " <<addr_list->nCount);
+       }
+
+       LogInfo("addr_list->nCount" << addr_list->nCount);              
+       setToValidity(true);
+       setCcValidity(true);
+       setBccValidity(true);
+}
+
+void Mms::updateSubject()
+{
+    // check if abstraction subject value has been changed
+    if (isSubjectValid()) {
+        return;
+    }
+    LogInfo("updating platform subject: " << getSubjectRef());
+    if (MSG_SUCCESS !=
+//        msg_set_subject(m_messageData, getSubjectRef().c_str())) {
+       msg_set_str_value(m_messageData, MSG_MESSAGE_SUBJECT_STR, const_cast<char*>(getSubjectRef().c_str()), MAX_SUBJECT_LEN)) {
+
+        LogError("problem with setting subject");
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
+    }
+    setSubjectValidity(true);
+}
+
+void Mms::updateBodyAndAttachments()
+{
+               // check if attachment or body source address value has been changed
+               if (isAttachmentsValid() && isBodyValid()) {
+                       return;
+               }
+       
+//             MMS_MESSAGE_DATA_S *mmsData = NULL;
+               msg_struct_t mms_struct = NULL;
+//             msg_struct_t old_mms_struct = NULL;// THIS
+//             int ret;// THIS
+
+               LogInfo("updating platform body and attachment");
+       
+               Try
+               {
+                       msg_struct_t region[1];
+                       msg_struct_t page[1];
+                       msg_struct_t media[1];
+                       msg_struct_t smil_text[1];
+                       
+                       if (getMessageType() != MMS) {
+                               LogError("Wrong msg type");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong msg type");
+                       }
+//                     mmsData = msg_mms_create_message();
+                       mms_struct = msg_create_struct(MSG_STRUCT_MMS);
+//                     old_mms_struct = msg_create_struct(MSG_STRUCT_MMS);// THIS
+
+//                     ret = msg_get_mms_struct(m_messageData, old_mms_struct);// THIS
+//                     LogError("ret " << ret);// THIS
+//                     ret = msg_release_struct(&old_mms_struct);// THIS
+//                     LogError("ret " << ret);// THIS
+
+                       if (!mms_struct) {
+                               LogError("create message body failed");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "create message body failed");
+                       }
+       
+                       //body
+                       if (!getBodyRef().empty()) {
+                               FILE* f = NULL;
+                               f = fopen(m_bodyFilePath.c_str(), "w");
+                               if (!f) {
+                                       LogError("cannot create file with body" << m_bodyFilePath);
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                                        "cannot create file with body");
+                               }
+                               LogDebug("body file: " << m_bodyFilePath);
+                               fwrite(getBodyRef().c_str(), strlen(getBodyRef().c_str()), 1, f);
+                        
+                               fclose(f);
+
+                               LogDebug("getBodyRef(): " << getBodyRef());
+
+                               msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_INT, ROOT_LAYOUT_WIDTH);
+                               msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
+                               msg_set_int_value(mms_struct, MSG_MMS_ROOTLAYOUT_BGCOLOR_INT, WHITE_COLOR);
+                               msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL, true);
+                               msg_set_bool_value(mms_struct, MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL, true);
+                               
+                               msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_REGION, &region[0]);
+                               msg_set_str_value(region[0], MSG_MMS_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
+                               msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_INT, 0);
+                               msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_TOP_INT, 0);
+                               msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_INT, ROOT_LAYOUT_WIDTH);
+                               msg_set_int_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_INT, ROOT_LAYOUT_HEIGHT);
+                               msg_set_int_value(region[0], MSG_MMS_REGION_BGCOLOR_INT, WHITE_COLOR);
+                               
+                               msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_LEFT_PERCENT_BOOL, true);
+                               msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_TOP_PERCENT_BOOL, true);
+                               msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_WIDTH_PERCENT_BOOL, true);
+                               msg_set_bool_value(region[0], MSG_MMS_REGION_LENGTH_HEIGHT_PERCENT_BOOL, true);
+
+                               msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_PAGE, &page[0]);
+                               msg_set_int_value(page[0], MSG_MMS_PAGE_PAGE_DURATION_INT, 0);
+                               
+                               msg_mms_add_item(page[0], MSG_STRUCT_MMS_MEDIA, &media[0]);
+                               msg_set_int_value(media[0], MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT);
+                               msg_set_str_value(media[0], MSG_MMS_MEDIA_REGION_ID_STR, const_cast<char*>(TEXT_AREA), 4);
+                               int error;
+                               error = msg_set_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, const_cast<char*>(m_bodyFilePath.c_str()),MSG_FILEPATH_LEN_MAX);
+                               LogDebug("bodyFile Path= " << m_bodyFilePath);
+                               LogDebug("error= " << error);
+                               char szFilePath[MSG_FILEPATH_LEN_MAX] = {0,};
+                               memset(szFilePath, 0, sizeof(szFilePath));
+                               msg_get_str_value(media[0], MSG_MMS_MEDIA_FILEPATH_STR, szFilePath, sizeof(szFilePath));
+                               LogDebug("bodyFile Path= " << m_bodyFilePath);
+
+                               msg_get_struct_handle(media[0], MSG_MMS_MEDIA_SMIL_TEXT_HND, &smil_text[0]);
+                               msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_COLOR_INT, BLACK_COLOR);
+                               msg_set_int_value(smil_text[0], MSG_MMS_SMIL_TEXT_SIZE_INT, MMS_SMIL_FONT_SIZE_NORMAL);
+                               msg_set_bool_value(smil_text[0], MSG_MMS_SMIL_TEXT_BOLD_BOOL, true);
+                               
+                       }
+                       
+                       //attachments
+                       struct stat buffer;
+                       int errnum = 0;
+
+                       msg_struct_t attachment[20];                    
+                       
+                       for (size_t i = 0; i < getAttachmentsRef().size(); ++i) {
+                               Api::Messaging::IAttachmentPtr att = getAttachment(i);
+                               if (!att) {
+                                       continue;
+                               }
+       
+                               LogDebug("Add attachment=" << att->getFullPath());
+                               //checking file
+                               errnum = stat(att->getFullPath().c_str(), &buffer);
+                               LogDebug("errnum=" << errnum);
+
+                               if (errnum != 0) {
+                                       LogError("Opening file: " << att->getFullPath().c_str());
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                                        "cannot open attachment file");
+                               }
+       
+                               //this function should return valid pointer
+
+                               msg_mms_add_item(mms_struct, MSG_STRUCT_MMS_ATTACH, &attachment[i]);
+                               msg_set_str_value(attachment[i], MSG_MMS_ATTACH_FILEPATH_STR, const_cast<char*>(att->getFullPath().c_str()), MSG_FILEPATH_LEN_MAX);
+                               
+                               LogDebug("Attachment added");
+       
+                               //reset errno
+                               errnum = 0;
+                       }
+       
+               if (MSG_SUCCESS !=msg_set_mms_struct(m_messageData, mms_struct))
+               {
+                       LogError("set message body error");
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "set message body error");
+               }
+
+               msg_release_struct(&mms_struct);
+
+               setAttachmentsValidity(true);
+               setBodyValidity(true);
+               
+               }
+               Catch(WrtDeviceApis::Commons::PlatformException) {
+                       LogError("Platform error");
+                       msg_release_struct(&mms_struct);
+                       throw;
+               }
+}
+
+
+void Mms::updateReadStatus()
+{
+    if (isReadStatusValid()) {
+        return;
+    }
+
+    LogInfo("updating platform read status: " << isRead());
+//    if (MSG_SUCCESS != msg_set_read_status(m_messageData, isRead())) {
+    if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
+        LogError("problem with setting subject");
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
+    }
+
+    setReadStatusValidity(true);
+}
+
+void Mms::updateIsRead()
+{
+    LogDebug("updating m_id=" << getIdRef());
+
+    if (!m_messageData) {
+        //error if platform message not exists
+        LogError("message can not be updated");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+       
+    // check if abstraction from m_isReadChange value has been changed
+    if (isReadChangeStatusValid()) {
+        // do not update if not changed
+        return;
+    }
+
+    Try
+    {
+        if (this->getIdRef().empty()) {
+            LogError("existing msgId is zero, remove msg not done");
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                     "existing msgId is zero, remove msg not done");
+        }
+
+        if (MSG_SUCCESS !=
+            msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
+        {
+            LogError("Failed to update isRead");
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
+        }
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("platform error occurs");
+    }
+    setisReadChangeStatusValidity(true);
+
+}
+
+void Mms::updateMessage()
+{
+       LogDebug("updating m_id=" << getIdRef());
+       msg_error_t err = MSG_SUCCESS;
+       msg_struct_t msg = NULL;
+       msg_struct_t sendOpt = NULL;
+       
+       if (!m_messageData) {
+               //error if platform message not exists
+               LogError("message can not be updated");
+               Throw(WrtDeviceApis::Commons::PlatformException);
+       }
+
+       
+       Try
+       {
+               msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+               sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);                        
+               
+               err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
+               
+               if (err != MSG_SUCCESS)
+               {
+                       LogError("Get Message Failed!");
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
+               }
+       
+               if (this->getIdRef().empty()) {
+                       LogError("existing msgId is zero, update msg not done");
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                       "existing msgId is zero, update msg not done");
+               }
+               
+               update(TRUE);
+               
+               if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
+               {
+                       LogError("Failed to update message");
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
+               }
+               msg_release_struct(&msg);
+               msg_release_struct(&sendOpt);
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               msg_release_struct(&msg);
+               msg_release_struct(&sendOpt);
+               LogError("platform error occurs");
+       }
+}
+
+
+void Mms::createSendMessage()
+{
+    LogDebug("convert m_id= " << convertId(getIdRef()));       
+
+    //prepare for add sms to draft folder
+    if (!m_messageData) {
+        //error if platform message not exists
+        LogError("message can not be updated");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+
+    //update all sms data
+    if (getCurrentFolder() == Api::Messaging::DRAFTBOX) {
+               LogDebug("update all mms data");
+        updateSubject();
+        updateBodyAndAttachments();
+        updateRecipientList();
+        updatePriority();
+    }
+
+    Try
+    {
+        int msgId = 0;
+//        MSG_SENDINGOPT_S option = { false, false, false };
+//        option.option.smsSendOpt.bReplyPath = true;
+        // trying to get message from platform
+
+//        msg_struct_t sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+//        msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
+
+
+//        const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
+
+//        msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
+//        msg_set_int_value(m_messageData, MSG_MESSAGE_FOLDER_ID_INT, 4);
+//        msg_set_int_value(m_messageData, MSG_MESSAGE_NETWORK_STATUS_INT, MSG_NETWORK_NOT_SEND);
+
+        setId(convertId(msgId));
+        setFolderType(Api::Messaging::DRAFTBOX);
+        setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("remove message error");
+        if (m_messageData) {
+            //releasing platform message structure
+//            msg_release_message(&m_messageData);
+            msg_release_struct(&m_messageData);                
+        }
+        throw;
+    }
+
+}      
+
+void Mms::addMessageToDraft()
+{
+       LogDebug("convert m_id= " << convertId(getIdRef()));
+
+       msg_struct_t sendOpt = NULL;
+
+       //prepare for add sms to draft folder
+       if (!m_messageData) {
+               //error if platform message not exists
+               LogError("message can not be updated");
+               Throw(WrtDeviceApis::Commons::PlatformException);
+       }
+
+       //update all mms data
+       if (getCurrentFolder() == Api::Messaging::DRAFTBOX) {
+               updateSubject();
+               updateBodyAndAttachments();
+               updateRecipientList();
+               updatePriority();
+       }
+
+       Try
+       {
+               int msgId = -1;
+               sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+
+               // trying to add message
+               LogDebug("add message");
+               int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
+               if (ret < MSG_SUCCESS) {
+                       LogError("msg_add_message failed, error code=" << ret);
+                       Throw(WrtDeviceApis::Commons::PlatformException);
+               }
+               else
+               {
+                       msgId = ret;
+               }
+
+               LogDebug("Message ID : " << msgId);
+               if (msgId < 0)
+               {
+                       LogDebug("Message ID is invailded ");
+                       Throw(WrtDeviceApis::Commons::PlatformException);
+               }
+
+               msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
+
+               setId(convertId(msgId));
+               setFolderType(Api::Messaging::DRAFTBOX);
+               setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
+
+               msg_release_struct(&sendOpt);
+
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               LogError("add draft message error");
+               msg_release_struct(&sendOpt);
+               throw;
+       }
+
+}      
+
+void Mms::readAllData()
+{
+    readExistingMessage();
+}
+
+void Mms::moveToFolder(const FolderType newFolder)
+{
+/*
+    update();
+
+    Try
+    {
+        msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
+                newFolder);
+
+        if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
+                                   platfromFolderId) != MSG_SUCCESS) {
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Error during movinf message");
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("remove message error");
+        throw;
+    }
+*/
+}
+
+void Mms::moveToFolder(const string& newFolder)
+{
+/*
+    update();
+
+    Try
+    {
+        msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(
+                newFolder);
+
+        if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
+                                   platfromFolderId) != MSG_SUCCESS) {
+            LogError("msg_move_msg_to_folder error");
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_move_msg_to_folder error");
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("remove message error");
+        throw;
+    }
+    */
+}
+
+void Mms::copyToFolder(const FolderType newFolder)
+{
+/*
+    update();
+
+    msg_message_t msg = msg_new_message();
+
+    Try
+    {
+        MSG_SENDINGOPT_S option = { false, false, false };
+        option.option.smsSendOpt.bReplyPath = true;
+        if (MSG_SUCCESS ==
+            msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
+                            &option)) {
+            const msg_folder_id_t platfromFolderId =
+                Messaging::convertFolderToPlatform(newFolder);
+            msg_set_message_id(msg, 0);
+            msg_set_folder_id(msg, platfromFolderId);
+
+            int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
+            if (error != MSG_SUCCESS) {
+                LogError("msg_add_message failed, error code=" << error);
+                ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
+            }
+        }
+        if (msg) {
+            msg_release_message(&msg);
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("remove message error");
+        if (msg) {
+            msg_release_message(&msg);
+        }
+        throw;
+    }
+*/
+}
+
+void Mms::copyToFolder(const string& newFolder)
+{
+/*
+    update();
+
+    msg_message_t msg = msg_new_message();
+
+    Try
+    {
+        MSG_SENDINGOPT_S option = { false, false, false };
+        option.option.smsSendOpt.bReplyPath = true;
+        if (MSG_SUCCESS ==
+            msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
+                            &option)) {
+            const msg_folder_id_t platfromFolderId =
+                Messaging::convertFolderToPlatform(newFolder);
+            msg_set_message_id(msg, 0);
+            msg_set_folder_id(msg, platfromFolderId);
+
+            int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
+            if (error != MSG_SUCCESS) {
+                LogError("msg_add_message failed, error code=" << error);
+                ThrowMsg(WrtDeviceApis::Commons::PlatformException, "msg_add_message failed");
+            }
+        }
+        if (msg) {
+            msg_release_message(&msg);
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("remove message error");
+        if (msg) {
+            msg_release_message(&msg);
+        }
+        throw;
+    }
+*/
+}
+
+void Mms::remove()
+{
+    LogDebug("delete m_id=" << getIdRef());
+
+    Try
+    {
+        if (this->getIdRef().empty()) {
+            LogError("existing msgId is zero, remove msg not done");
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                     "existing msgId is zero, remove msg not done");
+        }
+
+        if (MSG_SUCCESS !=
+            msg_delete_message(MsgGetCommonHandle(),
+                               convertId(getIdRef()))) {
+            LogError("Failed to delete Message");
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to delete Message");
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("platform error occurs");
+    }
+}
+
+int Mms::send()
+{
+       LogDebug("sending message, id=" << getIdRef());
+       Try
+       {
+               //prepare for sending sms/mms
+               update();
+
+               LogDebug("Start Sending Message...");
+
+               LogDebug("trying to send mms");
+               msg_error_t err = CallbackMgrSingleton::Instance().registerAndSend(msg_mms_send_message, m_messageData, this);
+
+               if (err != MSG_SUCCESS) 
+               {
+                       LogError("Sending Message (submit request) failed!!! err=" << err);
+                       setMessageStatus(MESSAGE_STATUS_FAILED);
+                       goto ERROR;
+               }
+
+               setMessageStatus(MESSAGE_STATUS_SENDING);
+
+               LogDebug("Sending Message request is submitted!");
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               LogError("message is not send, manually run callback");
+               goto ERROR;
+       }
+
+       return 0;
+
+       ERROR:
+       ReqReceiverMessage *requestReceiver = getRequestReceiver();
+       if (requestReceiver) {
+               LogError("send Error");
+               EventMessagingServicePtr event = getMessagingServiceEvent();
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+               requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService>::ManualAnswer(event);
+       }
+       return 0;
+}
+
+void Mms::sendingCallback(msg_struct_t sent_status)
+{
+//     LogInfo("sendingCallback callback received. Req id = " <<
+//     sent_status->reqId << " Status = " << (int)sent_status->status);
+//     msg_struct_t request_data = NULL;
+//     msg_get_struct_handle(sent_status, MSG_STRUCT_REQUEST_INFO, (void **)request_data);
+//     msg_get_int_value(request_data, MSG_REQUEST_REQUESTID_INT, &tempInt);
+       int status = MSG_NETWORK_SEND_FAIL;
+       msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
+       
+       LogDebug("status : " << status);
+       
+       if (MSG_NETWORK_SEND_SUCCESS == status) {
+               LogDebug("sending ok");
+               setSendingStatusOk();
+               setMessageStatus(MESSAGE_STATUS_SENT);
+       } else {
+               LogError("sending failed: " << static_cast<unsigned int>(status));
+               setSendingStatusFailed();
+               setMessageStatus(MESSAGE_STATUS_FAILED);
+       }
+}
+
+void Mms::sendCancel(int handle)
+{
+    LogDebug("sending message, id=" << getIdRef());
+    //#warning "TODO"
+    LogDebug("handle =" << handle);
+}
+
+void Mms::setSendingStatusOk()
+{
+    //success callback should be executed here
+       ReqReceiverMessage *requestReceiver = getRequestReceiver();
+       msg_struct_list_s *addr_list = NULL;
+       char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
+       int nToCnt;
+       
+       if (requestReceiver) {
+               LogInfo("calling JS success callback");
+               EventMessagingServicePtr event = getMessagingServiceEvent();
+               event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
+
+               msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+
+               nToCnt = addr_list->nCount;
+
+               for ( int index=0; index < nToCnt; index++)
+               {
+                       msg_get_str_value(addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                       event->m_successRecipients.push_back(strNumber);
+               }
+         
+               requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
+       }
+}
+
+void Mms::setSendingStatusFailed()
+{      
+    //error callback should be executed here
+       EventOnSendingFailedEmitterPtr emitter = getEmitter();
+       msg_struct_list_s *addr_list = NULL;
+       char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
+       int nToCnt;
+       
+       if (emitter) 
+       {
+               EventOnSendingFailedPtr event(new EventOnSendingFailed);
+               event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
+               emitter->emit(event);
+       } 
+       else 
+       {
+               ReqReceiverMessage *requestReceiver = getRequestReceiver();
+               EventMessagingServicePtr event = getMessagingServiceEvent();
+               if (requestReceiver) 
+               {
+                       LogError("calling JS error callback");
+                       event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+                       msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+                       nToCnt = addr_list->nCount;
+
+                       LogDebug("nToCnt : " << nToCnt);
+
+                       for ( int index=0; index < nToCnt; index++)
+                       {
+                               msg_get_str_value(addr_list->msg_struct_info[index], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                               event->m_failRecipients.push_back(strNumber);
+                       }
+
+               requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
+               }
+       }
+}
+
+Api::Messaging::FolderType Mms::toFolder(const std::string &folder)
+{
+    if (folder == "INBOX") {
+        return INBOX;
+    } else if (folder == "OUTBOX") {
+        return OUTBOX;
+    } else if (folder == "SENTBOX") {
+        return SENTBOX;
+    } else if (folder == "DRAFTBOX") {
+        return DRAFTBOX;
+    }
+    ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/Mms.h b/src/platform/Tizen/Messaging/Mms.h
new file mode 100755 (executable)
index 0000000..12f8750
--- /dev/null
@@ -0,0 +1,126 @@
+//
+// 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 MMS_H
+#define MMS_H
+
+#include <API/Messaging/IMms.h>
+#include <API/Messaging/MmsSlides.h>
+#include "MmsSlide.h"
+#include "ISendingObserver.h"
+
+extern "C" {
+#include <msg_types.h>
+#include <msg_transport.h>
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+class Mms : public Api::Messaging::IMms,
+    public ISendingObserver,
+    public Api::Messaging::MmsSlides
+{
+  public:
+    explicit Mms(const std::string& id = "");
+
+    explicit Mms(const std::string& id, const msg_struct_t msg_data);
+
+    ~Mms();
+
+    // implementation of interface of IMessage class
+    virtual void update(bool draftsOnly = false);
+
+    virtual void readAllData();
+
+    virtual void moveToFolder(const Api::Messaging::FolderType newFolder);
+
+    virtual void moveToFolder(const std::string& newFolder);
+
+    virtual void copyToFolder(const Api::Messaging::FolderType newFolder);
+
+    virtual void copyToFolder(const std::string& newFolder);
+
+    virtual void remove();
+
+    virtual int send();
+
+    virtual void sendingCallback(msg_struct_t sent_status);
+
+    virtual void sendCancel(int handle);
+
+    virtual bool hasAttachment();
+
+    void setSendingStatusOk();
+
+    void setSendingStatusFailed();
+
+    static Api::Messaging::FolderType toFolder(const std::string &folder);
+
+  private:
+
+    void updatePriority();
+
+    void updateRecipientList();
+
+    void updateSubject();
+       
+    void updateBodyAndAttachments();
+
+       void updateReadStatus();
+
+    void updateIsRead();       
+
+    void updateMessage();      
+
+    void addMessageToDraft();
+
+    void createSendMessage();
+
+    void readPriority(msg_struct_t& messageData);
+
+    void readRecipientList(msg_struct_t& messageData);
+
+    void readSubject(msg_struct_t& messageData);
+
+    void readBodyAndAttachments(msg_struct_t& messageData);
+
+    void readFolder(msg_struct_t& messageData);
+
+    void readDateTime(msg_struct_t& messageData);
+
+    void readReadStatus(msg_struct_t& messageData);
+
+    void readMessageStatus(msg_struct_t& messageData); 
+
+    void createNewMessage();
+
+    void readExistingMessage();
+
+  private:
+
+    std::string m_bodyFilePath;
+
+    msg_struct_t m_messageData;
+};
+
+typedef DPL::SharedPtr<Mms> MmsPtr;
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/MmsSlide.cpp b/src/platform/Tizen/Messaging/MmsSlide.cpp
new file mode 100755 (executable)
index 0000000..2835a1d
--- /dev/null
@@ -0,0 +1,17 @@
+//
+// 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.
+//
+
diff --git a/src/platform/Tizen/Messaging/MmsSlide.h b/src/platform/Tizen/Messaging/MmsSlide.h
new file mode 100755 (executable)
index 0000000..13e8d2c
--- /dev/null
@@ -0,0 +1,37 @@
+//
+// 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_MMS_SLIDE_H
+#define TIZEN_MMS_SLIDE_H
+
+#include <API/Messaging/IMmsSlide.h>
+#include <API/Messaging/MmsSlide.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+class MmsSlide :
+    public virtual Api::Messaging::IMmsSlide,
+    public Api::Messaging::MmsSlide
+{
+};
+}
+}
+}
+#endif
+
diff --git a/src/platform/Tizen/Messaging/MsgServiceHandleMgr.h b/src/platform/Tizen/Messaging/MsgServiceHandleMgr.h
new file mode 100755 (executable)
index 0000000..b8cc054
--- /dev/null
@@ -0,0 +1,107 @@
+//
+// 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 MSGSERVICEHANDLEMGR_H
+#define MSGSERVICEHANDLEMGR_H
+
+#include <dpl/singleton.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/thread.h>
+#include <Commons/Exception.h>
+
+extern "C" {
+#include <msg.h>
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+/*
+ * Class used for msg service handle manager
+ */
+class MsgServiceHandleMgr
+{
+  public:
+    MsgServiceHandleMgr() : m_msgHandle(NULL)
+    {
+        LogInfo("enter");
+        // open one handle per all messaging
+        if (MSG_SUCCESS != msg_open_msg_handle(&m_msgHandle)) {
+            LogError("Unable to open handle");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+    }
+
+  public:
+    ~MsgServiceHandleMgr()
+    {
+        LogInfo("enter");
+        if (!!m_msgHandle) {
+            msg_close_msg_handle(&m_msgHandle);
+        }
+    }
+
+    msg_handle_t getHandle() const
+    {
+        if (!m_msgHandle) {
+            LogError("Messaging handle not initialized");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+        return m_msgHandle;
+    }
+
+  private:
+    msg_handle_t m_msgHandle;
+};
+
+typedef DPL::SharedPtr<MsgServiceHandleMgr> MsgServiceHandleMgrPtr;
+typedef DPL::ThreadLocalVariable<MsgServiceHandleMgrPtr> TlvMsgServiceHandleMgr;
+
+class MsgServiceHandle
+{
+  protected:
+    MsgServiceHandle()
+    {
+    }
+
+  public:
+    ~MsgServiceHandle()
+    {
+    }
+
+    msg_handle_t getHandle()
+    {
+        if (m_tlvHandleMgr.IsNull()) {
+            m_tlvHandleMgr = MsgServiceHandleMgrPtr(new MsgServiceHandleMgr());
+        }
+        return (*m_tlvHandleMgr)->getHandle();
+    }
+
+  private:
+    TlvMsgServiceHandleMgr m_tlvHandleMgr;
+};
+
+typedef DPL::Singleton<MsgServiceHandle> MsgServiceHandleSingleton;
+
+#define MsgGetCommonHandle() MsgServiceHandleSingleton::Instance().getHandle()
+}
+}
+}
+#endif /* MSGSERVICEHANDLEMGR_H */
+
diff --git a/src/platform/Tizen/Messaging/NetworkStatus.cpp b/src/platform/Tizen/Messaging/NetworkStatus.cpp
new file mode 100755 (executable)
index 0000000..7f00b9b
--- /dev/null
@@ -0,0 +1,86 @@
+//
+// 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 "NetworkStatus.h"
+
+namespace {
+const char* DBUS_INTERFACE_NETWORK_STATUS = "User.Email.NetworkStatus";
+const int DBUS_MESSAGE_PARAMETERS_NUMBER = 5;
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+NetworkStatus::NetworkStatus(const DBus::MessagePtr& message)
+{
+    Assert(message->getInterface() == DBUS_INTERFACE_NETWORK_STATUS);
+    initialize(message);
+}
+
+int NetworkStatus::getStatus() const
+{
+    return m_status;
+}
+
+int NetworkStatus::getAccountId() const
+{
+    return m_accountId;
+}
+
+std::string NetworkStatus::getSource() const
+{
+    return m_source;
+}
+
+int NetworkStatus::getMailId() const
+{
+    return m_mailId;
+}
+
+int NetworkStatus::getErrorCode() const
+{
+    return m_errorCode;
+}
+
+void NetworkStatus::initialize(const DBus::MessagePtr& message)
+{
+    DBus::Message::ReadIterator it = message->getReadIterator();
+    for (int i = 0; i < DBUS_MESSAGE_PARAMETERS_NUMBER; it->next(), ++i) {
+        if (!it->isValid()) {
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Missing some properties.");
+        }
+
+        switch (i) {
+        case 0: m_status = it->getInt();
+            break;
+        case 1: m_accountId = it->getInt();
+            break;
+        case 2: m_source = it->getString();
+            break;
+        case 3: m_mailId = it->getInt();
+            break;
+        case 4: m_errorCode = it->getInt();
+            break;
+        }
+    }
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/NetworkStatus.h b/src/platform/Tizen/Messaging/NetworkStatus.h
new file mode 100755 (executable)
index 0000000..d0d2903
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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 NETWORKSTATUS_H_
+#define NETWORKSTATUS_H_
+
+#include <string>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+#include <DBus/Message.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+class NetworkStatus : private DPL::Noncopyable
+{
+  public:
+    explicit NetworkStatus(const DBus::MessagePtr& message);
+
+    int getStatus() const;
+    int getAccountId() const;
+    std::string getSource() const;
+    int getMailId() const;
+    int getErrorCode() const;
+
+  private:
+    void initialize(const DBus::MessagePtr& message);
+
+  private:
+    int m_status;
+    int m_accountId;
+    /*
+     * Not sure what it stores. According to source code of Email application
+     * it can contain string "ACTIVESYNC" or name of the file which stores body.
+     */
+    std::string m_source;
+    int m_mailId;
+    int m_errorCode;
+};
+
+typedef DPL::SharedPtr<NetworkStatus> NetworkStatusPtr;
+}
+}
+}
+
+#endif // NETWORKSTATUS_H_
diff --git a/src/platform/Tizen/Messaging/ScopedMail.h b/src/platform/Tizen/Messaging/ScopedMail.h
new file mode 100755 (executable)
index 0000000..f596297
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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_MESSAGING_SCOPEDMAIL_H_
+#define TIZEN_MESSAGING_SCOPEDMAIL_H_
+
+#include <dpl/log/log.h>
+#include <dpl/scoped_ptr.h>
+#include <email-types.h>
+#include <email-api-mail.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+struct ScopedMailPolicy
+{
+    typedef email_mail_data_t* Type;
+
+    static Type NullValue()
+    {
+        LogDebug("NullValue");
+        return NULL;
+    }
+
+    static void Destroy(Type mail)
+    {
+          LogDebug("Destroy");
+        if (NullValue() != mail) {
+                LogDebug("email_free_mail_data");
+            int error = email_free_mail_data(&mail, 1);
+            if (EMAIL_ERROR_NONE != error) {
+                LogError("Failed to destroy mail: " << error);
+            }
+        }
+    }
+};
+
+typedef DPL::ScopedPtr<email_mail_data_t, ScopedMailPolicy> ScopedMail;
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/ScopedMailAttachment.h b/src/platform/Tizen/Messaging/ScopedMailAttachment.h
new file mode 100755 (executable)
index 0000000..5d49241
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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_MESSAGING_SCOPEDMAILATTACHMENT_H_
+#define TIZEN_MESSAGING_SCOPEDMAILATTACHMENT_H_
+
+#include <dpl/log/log.h>
+#include <dpl/scoped_ptr.h>
+#include <email-types.h>
+#include <email-api-mail.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+struct ScopedMailAttachmentPolicy
+{
+    typedef email_attachment_data_t* Type;
+
+    static Type NullValue()
+    {
+        LogDebug("NullValue");
+        return NULL;
+    }
+
+    static void Destroy(Type attachment)
+    {
+          LogDebug("Destroy");
+        if (NullValue() != attachment) {
+                LogDebug("email_free_attachment_info");
+            int error = email_free_attachment_info(&attachment);
+            if (EMAIL_ERROR_NONE != error) {
+                LogError("Failed to destroy mail Attachment: " << error);
+            }
+        }
+    }
+};
+
+typedef DPL::ScopedPtr<email_attachment_data_t, ScopedMailAttachmentPolicy> ScopedMailAttachment;
+}
+}
+}
+#endif //TIZEN_MESSAGING_SCOPEDMAILATTACHMENT_H_
\ No newline at end of file
diff --git a/src/platform/Tizen/Messaging/ScopedMailbox.h b/src/platform/Tizen/Messaging/ScopedMailbox.h
new file mode 100755 (executable)
index 0000000..6b8a432
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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_MESSAGING_SCOPEDMAILBOX_H_
+#define TIZEN_MESSAGING_SCOPEDMAILBOX_H_
+
+#include <dpl/log/log.h>
+#include <dpl/scoped_ptr.h>
+#include <email-types.h>
+#include <email-api-mail.h>
+#include <email-api-mailbox.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+struct ScopedMailboxPolicy
+{
+    typedef email_mailbox_t* Type;
+
+    static Type NullValue()
+    {
+        LogDebug("NullValue");
+        return NULL;
+    }
+
+    static void Destroy(Type mailbox)
+    {  
+          LogDebug("Destroy");
+        if (NullValue() != mailbox) {
+                LogDebug("email_free_mailbox");
+            int error = email_free_mailbox(&mailbox, 1);
+            if (EMAIL_ERROR_NONE != error) {
+                LogError("Failed to destroy mailbox: " << error);
+            }
+        }
+    }
+};
+
+typedef DPL::ScopedPtr<email_mailbox_t, ScopedMailboxPolicy> ScopedMailbox;
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/Sms.cpp b/src/platform/Tizen/Messaging/Sms.cpp
new file mode 100755 (executable)
index 0000000..9d93e42
--- /dev/null
@@ -0,0 +1,1178 @@
+//
+// 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 "Sms.h"
+#include <dpl/log/log.h>
+#include <Commons/Exception.h>
+#include <API/Messaging/ReqReceiverMessage.h>
+#include "Messaging.h"
+#include "CallbackMgr.h"
+#include "MsgServiceHandleMgr.h"
+
+extern "C" {
+#include <msg_storage.h>
+}
+
+using namespace std;
+using namespace TizenApis::Api::Messaging;
+
+namespace {
+const char* EMPTY_ID = "0";
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+Sms::Sms(const string& id) :
+    IMessage(SMS, id),
+    m_messageData(NULL)
+{
+    LogDebug("enter");
+    LogDebug("m_id=" << getIdRef());
+    LogDebug("m_msgType=" << getMessageType());
+
+    if (getIdRef().empty()) {
+        createNewMessage();
+    } else {
+        readExistingMessage();
+    }
+
+    Touch();
+}
+
+Sms::Sms(const std::string& id, const msg_struct_t msg_data) :
+       IMessage(SMS, id),
+       m_messageData(NULL)
+{
+       LogDebug("enter");
+       LogDebug("m_id=" << getIdRef());
+       LogDebug("m_msgType=" << getMessageType());
+
+       LogDebug("created msg_data : " << msg_data);
+       m_messageData = createNewCopyOfPLatformMsgWithAddressList(msg_data);
+       LogDebug("created m_messageData : " << m_messageData);
+
+       readRecipientList(m_messageData);
+       readBody(m_messageData);
+       readFolder(m_messageData);
+       readDateTime(m_messageData);
+       readReadStatus(m_messageData);
+       readSize(m_messageData);
+       readMessageStatus(m_messageData);
+//     setMessageStatus(Api::Messaging::MESSAGE_STATUS_LOADED);
+       Touch();
+}
+
+Sms::~Sms()
+{
+    LogDebug("enter");
+
+    if (m_messageData) {
+        // release platform message structure
+               LogDebug("release m_messageData : " << m_messageData);
+        msg_release_struct(&m_messageData);
+    }
+}
+
+void Sms::update(bool draftsOnly)
+{
+    LogDebug("updating m_id=" << getIdRef());
+
+    if (!m_messageData) {
+        //error if platform message not exists
+        LogError("message can not be updated");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+
+    //update all sms data
+    if (!draftsOnly || getCurrentFolder() == Api::Messaging::DRAFTBOX) {
+        updateBody();
+        updateFrom();
+        updateTo();
+        updateSourceAddress();
+    }
+    updateReadStatus();
+}
+
+void Sms::readAllData()
+{
+    readExistingMessage();
+}
+
+void Sms::moveToFolder(const FolderType newFolder)
+{
+/*
+    update();
+
+    Try
+    {
+        const msg_folder_id_t platfromFolderId =
+            Messaging::convertFolderToPlatform(newFolder);
+
+        //call platform api to move message to other folder
+        if (msg_move_msg_to_folder(MsgGetCommonHandle(), convertId(getId()),
+                                   platfromFolderId) != MSG_SUCCESS) {
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("remove message error");
+        throw;
+    }
+*/
+}
+
+void Sms::moveToFolder(const std::string& newFolder)
+{
+//    update();
+    //TODO
+}
+
+void Sms::copyToFolder(const FolderType newFolder)
+{
+/*
+    update();
+
+    msg_message_t msg = msg_new_message();
+
+    Try
+    {
+        MSG_SENDINGOPT_S option = { false, false, false };
+        option.option.smsSendOpt.bReplyPath = true;
+        // trying to get message from platform
+        if (MSG_SUCCESS ==
+            msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg,
+                            &option)) {
+            const msg_folder_id_t platfromFolderId =
+                Messaging::convertFolderToPlatform(newFolder);
+            // new id will me set (initialize to 0)
+            msg_set_message_id(msg, 0);
+            msg_set_folder_id(msg, platfromFolderId);
+
+            // trying to add message
+            int error = msg_add_message(MsgGetCommonHandle(), msg, &option);
+            if (error != MSG_SUCCESS) {
+                LogError("msg_add_message failed, error code=" << error);
+                Throw(WrtDeviceApis::Commons::PlatformException);
+            }
+
+            //releasing platform message structure
+            msg_release_message(&msg);
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("remove message error");
+        if (msg) {
+            //releasing platform message structure
+            msg_release_message(&msg);
+        }
+        throw;
+    }
+*/
+}
+
+void Sms::copyToFolder(const std::string& newFolder)
+{
+//    update();
+    //TODO
+}
+
+int Sms::send()
+{
+       LogDebug("sending message, id=" << getIdRef());
+       Try{
+               if(m_messageData == NULL)
+               {
+                       //prepare for sending sms
+                       update();
+               }
+               MsgGetCommonHandle();
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) 
+       {
+               LogDebug("getHandle failed");
+               Throw(WrtDeviceApis::Commons::PlatformException);
+       }
+
+    // split the message
+       SendRequest req;
+
+       msg_struct_list_s *addr_list = NULL;
+       msg_struct_list_s *new_addr_list = NULL;
+       char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
+       int nToCnt;
+       int tempInt;
+       int tempIdInt;
+
+       msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);  
+       msg_get_int_value(m_messageData, MSG_MESSAGE_ID_INT, &tempIdInt);
+
+       nToCnt = addr_list->nCount;
+       LogDebug("nToCnt : " << nToCnt);
+
+       for (int i = 0; i < nToCnt; ++i) 
+       {
+               msg_struct_t new_msg = createNewCopyOfPLatformMsg(m_messageData);
+               msg_set_int_value(new_msg, MSG_MESSAGE_ID_INT, tempIdInt);
+
+               msg_get_list_handle(new_msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
+
+               msg_get_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
+               LogDebug("RECIPIENT_TYPE : " << tempInt);
+               if(MSG_RECIPIENTS_TYPE_TO != tempInt) 
+               {
+                       LogDebug("skip");
+                       continue;
+               }
+
+               msg_get_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+               msg_set_str_value(new_addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+               msg_set_int_value(new_addr_list->msg_struct_info[0], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_TO);              
+               new_addr_list->nCount = 1;
+
+               setMessageStatus(MESSAGE_STATUS_SENDING);
+
+               req.queue.push(new_msg);                
+       }
+
+
+       DPL::Mutex::ScopedLock lock(&m_mutex);
+       m_sendRequests.push(req);
+
+    // schedule sending
+       PostEvent(0);
+
+       LogDebug("sending method finished");
+
+       return 0;               //sms handle is -1;
+}
+
+void Sms::sendingCallback(msg_struct_t sent_status)
+{
+//    LogInfo(
+//        "sendingCallback callback received. Req id = " <<
+//        sent_status->reqId << " Status = " << (int)sent_status->status <<
+//        ", Recipient=" << getRecipient());
+    int status = MSG_NETWORK_SEND_FAIL;
+
+    msg_get_int_value(sent_status, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status);
+
+    DPL::Mutex::ScopedLock lock(&m_mutex);
+
+    if (status != MSG_NETWORK_SEND_SUCCESS) {
+        m_sendRequests.front().failed = true; // TODO mutex
+        //send callback, error for recipient
+        setSendingStatusFailed(getRecipient());
+        setMessageStatus(MESSAGE_STATUS_FAILED);
+    } else {
+        setSendingStatusOk(getRecipient());
+        setMessageStatus(MESSAGE_STATUS_SENT);
+    }
+       
+    msg_release_struct(&currentQueue().front());
+    currentQueue().pop();
+
+    //schedule another sub message send
+    PostEvent(0);
+}
+
+void Sms::OnEventReceived(const int&)
+{
+    LogDebug("enter");
+    // send another one
+    sendSubMessage();
+}
+
+Api::Messaging::FolderType Sms::toFolder(const std::string &folder)
+{
+    if (folder == "INBOX") {
+        return INBOX;
+    } else if (folder == "OUTBOX") {
+        return OUTBOX;
+    } else if (folder == "SENTBOX") {
+        return SENTBOX;
+    } else if (folder == "DRAFTBOX") {
+        return DRAFTBOX;
+    }
+    ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Invalid folder");
+}
+
+void Sms::sendSubMessage()
+{
+    LogDebug("enter");
+
+    DPL::Mutex::ScopedLock lock(&m_mutex);
+
+    // if current request queue gets empty, try next one
+    while (!m_sendRequests.empty()) {
+        // send as long as the sending fails until there are no more messages
+        for (msg_error_t err = MSG_ERR_UNKNOWN;
+             err != MSG_SUCCESS && !currentQueue().empty(); ) 
+       {
+            err = CallbackMgrSingleton::Instance().registerAndSend(
+                    msg_sms_send_message,
+                    currentQueue().front(),
+                    this);
+            LogInfo("Sending Message (submit request) result:" << err);
+            if (err != MSG_SUCCESS) {
+                LogError("Sending Message (submit request) failed!!! err=" << err);
+                msg_release_struct(&currentQueue().front());
+                currentQueue().pop();
+                m_sendRequests.front().failed = true;
+                //send callback, error for recipient
+                setSendingStatusFailed(getRecipient());
+            }
+        }
+
+        // empty queue -> notify about results
+        if (currentQueue().empty()) {
+               /*
+            if (m_sendRequests.front().failed) {
+                setSendingStatusFailed();
+            } else {
+                setSendingStatusOk();
+            }
+            */
+            // this request is finished, try next one
+            m_sendRequests.pop();
+            continue;
+        }
+        break;
+    }
+}
+
+void Sms::setSendingStatusOk(const string &recipient)
+{
+    LogDebug("enter, success number is : " << recipient);
+    //success callback should be executed here
+    ReqReceiverMessage *requestReceiver = getRequestReceiver();
+    if (requestReceiver) {
+        EventMessagingServicePtr event = getMessagingServiceEvent();
+        event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
+        event->m_successRecipients.push_back(recipient);
+
+        msg_struct_list_s *addr_list = NULL;    
+        msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+        
+         if ( event->m_successRecipients.size() + event->m_failRecipients.size() == (unsigned int)addr_list->nCount)
+        {
+               requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
+        }
+        
+#if 0
+        EventSendMessagePtr event = getSendMessageEvent();
+        event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::None);
+        event->m_successRecipients.push_back(recipient);
+         //LogDebug("total address size : " << msg_get_address_count(m_messageData) << " Status size : " << event->m_successRecipients.size() + event->m_failRecipients.size());
+        if ( event->m_successRecipients.size() + event->m_failRecipients.size() == (unsigned int)msg_get_address_count(m_messageData))
+        {
+               requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventSendMessage >::ManualAnswer(event);
+        }
+#endif
+               
+    }
+}
+
+void Sms::setSendingStatusFailed(const string &recipient)
+{
+    LogDebug("enter, fail number is : " << recipient);
+    //error callback should be executed here
+    EventOnSendingFailedEmitterPtr emitter = getEmitter();
+    if (emitter) {
+        EventOnSendingFailedPtr event(new EventOnSendingFailed);
+        event->setError(EventOnSendingFailed::UNKNOWN); // TODO error codes
+        emitter->emit(event);
+    } else {
+        ReqReceiverMessage *requestReceiver = getRequestReceiver();
+        if (requestReceiver) {
+            LogError("calling JS error callback");
+            EventMessagingServicePtr event = getMessagingServiceEvent();
+            event->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::UnknownException);
+               event->m_successRecipients.push_back(recipient);
+               msg_struct_list_s *addr_list = NULL;    
+               msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+               
+                if ( event->m_successRecipients.size() + event->m_failRecipients.size() == (unsigned int)addr_list->nCount)
+                {
+                  requestReceiver->WrtDeviceApis::Commons::EventRequestReceiver< EventMessagingService >::ManualAnswer(event);
+                }
+
+        }
+    }
+}
+
+void Sms::remove()
+{
+    Try
+    {
+        // delete message from platform
+        if (msg_delete_message(MsgGetCommonHandle(),
+                               convertId(getId())) != MSG_SUCCESS) {
+            LogError("delete message failed");
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        } else {
+            LogDebug("message deleted succesfully");
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("remove message error");
+        throw;
+    }
+}
+
+void Sms::createNewMessage()
+{
+    LogDebug("enter");
+    if (m_messageData) {
+        // release platform message if it was created previously
+        msg_release_struct(&m_messageData);
+        m_messageData = NULL;
+    }
+    // create new platform message
+    LogDebug("create messeage instance");
+    m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+    LogDebug("created message : " << m_messageData);
+       
+    Try
+    {
+        //default message initialization
+        // update sms data
+        updateBody();
+        updateTo();
+
+       setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
+
+        tm dateT = getDateTime();
+        msg_set_int_value(m_messageData, MSG_MESSAGE_DISPLAY_TIME_INT, (int)mktime(&dateT));
+
+         setMessageStatus(Api::Messaging::MESSAGE_STATUS_CREATED);
+        LogDebug("Message created successfully, msgId=" << getId());
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        msg_release_struct(&m_messageData);
+        m_messageData = NULL;
+        LogError("Problem with message creation, cleaning");
+    }
+}
+
+void Sms::readExistingMessage()
+{
+       if (getIdRef().empty() || (EMPTY_ID == getIdRef())) {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Empty id.");
+       }
+
+       // release old data
+       if (m_messageData) {
+               // release platform message if it was created previously
+               msg_release_struct(&m_messageData);
+               m_messageData = NULL;
+       }
+       msg_struct_t sendOpt = NULL;
+
+       Try {
+               // create new platform structure
+               m_messageData = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+               sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+
+               msg_message_id_t l_id = convertId(getIdRef());
+               LogDebug("reading message id=" << l_id);
+               // trying to get message from platform
+               if (MSG_SUCCESS == msg_get_message(MsgGetCommonHandle(), l_id, m_messageData, sendOpt)) 
+               {
+                       LogDebug("message found with msgId=" << getIdRef());
+
+                       // read all mms dat to abstraction layer
+                       readRecipientList(m_messageData);
+                       readBody(m_messageData);
+                       readFolder(m_messageData);
+                       readDateTime(m_messageData);
+                       readReadStatus(m_messageData);
+                       readSize(m_messageData);
+                       readMessageStatus(m_messageData);
+
+               } else {
+                       LogError("message not found with msgId=" << getIdRef());
+                       setId("");
+                       Throw(WrtDeviceApis::Commons::PlatformException);
+               }
+
+               msg_release_struct(&sendOpt);
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               LogError("exception");
+               // nothing to do
+               msg_release_struct(&sendOpt);
+       }
+}
+
+void Sms::updateBody()
+{
+    // check if abstraction body value has been changed
+    if (isBodyValid()) {
+        return;
+    }
+    LogInfo("updating platfoprm body");
+
+    // change body value in platform structure
+    if (  getBodyRef().length() >  0)
+    {
+               if (msg_set_str_value(m_messageData, MSG_MESSAGE_SMS_DATA_STR, 
+                       const_cast<char*>(getBodyRef().c_str()), getBodyRef().length()) != MSG_SUCCESS)
+               {
+        LogError("problem with update Body");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+       }
+    // set flag as true - platform synchronized with abstraction
+    setBodyValidity(true);
+}
+    // set flag as true - platform synchronized with abstraction
+}
+
+void Sms::updateTo()
+{
+       // check if abstraction recipient value has been changed
+       if (getToRecipients().isValid()) {
+               return;
+       }
+
+       LogInfo("SMS updating platform recipients");
+
+       msg_struct_list_s *addr_list = NULL;
+       msg_get_list_handle(m_messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+       int nToCnt = addr_list->nCount;
+
+       LogInfo("nToCnt size  " << nToCnt);
+
+       if (nToCnt > 0)
+       {
+               for (int i = 0; i < nToCnt; i++) {
+                       msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, (char *)"", 0);
+                       msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_DISPLAYNAME_STR, (char *)"", 0);
+                       msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
+                       msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, MSG_RECIPIENTS_TYPE_UNKNOWN);
+                       msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_CONTACT_ID_INT, 0);
+               }
+               nToCnt = 0;
+               addr_list->nCount = nToCnt;
+       }
+
+       vector<string> to = getToRecipients().getRecipients();
+       // update addresses in platform structure
+       if (to.size())
+       {
+               LogInfo("updating to");
+               for (size_t i = 0; i < to.size(); i++)
+               {
+                       string tmpAddr = to[i];
+                       if(validatePhoneNumber(tmpAddr))
+                       {
+                               if (i >= MAX_TO_ADDRESS_CNT)
+                               {
+                                       LogError("max number of recipient exceeded");
+                                       break;
+                               }
+                               LogDebug("adding to[" << i << "]=" << to[i]);
+
+                               msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN);
+
+                               if (msg_set_int_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT,
+                               MSG_RECIPIENTS_TYPE_TO) != MSG_SUCCESS)
+                               {
+                                       LogError("problem with adding to address");
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
+                               }
+
+                               if(msg_set_str_value(addr_list->msg_struct_info[i], MSG_ADDRESS_INFO_ADDRESS_VALUE_STR,
+                               const_cast<char*>(to[i].c_str()), to[i].size()) != MSG_SUCCESS)
+                               {
+                                       LogError("problem with adding to address");
+                                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with adding to address");
+                               }
+
+                               addr_list->nCount ++;
+                               LogDebug("addr_list->nCount =" << addr_list->nCount);
+                       }
+                       else
+                       {
+                               LogError("wrong phone number format");
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "wrong phone number format");                               
+                       }
+               }
+       }
+
+       setToValidity(true);
+
+}
+
+void Sms::updateFrom()
+{
+    // check if abstraction from field value has been changed
+    if (getFromValidity()) {
+        // do not update if not changed
+        return;
+    }
+    LogInfo("updating platform from");
+
+    //TODO
+
+    // set flag as true - platform synchronized with abstraction
+    setFromValidity(true);
+}
+
+void Sms::updateSourceAddress()
+{
+    // check if abstraction source address value has been changed
+    if (getSourceAddressValidity()) {
+        // do not update if not changed
+        return;
+    }
+    LogInfo("updating platform source address");
+
+    //TODO
+
+    // set flag as true - platform synchronized with abstraction
+    setSourceAddressValidity(true);
+}
+
+void Sms::updateReadStatus()
+{
+    LogInfo("updating platform read status: " << isRead());
+    if (isReadStatusValid()) {
+        // do not update if not changed
+        return;
+    }
+    if (MSG_SUCCESS != msg_set_bool_value(m_messageData, MSG_MESSAGE_READ_BOOL, isRead())) {
+        LogError("problem with setting subject");
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Problem with setting subject");
+    }
+    setReadStatusValidity(true);
+}
+
+void Sms::updateIsRead()
+{
+    LogDebug("updating m_id=" << getIdRef());
+
+    if (!m_messageData) {
+        //error if platform message not exists
+        LogError("message can not be updated");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+       
+    // check if abstraction from m_isReadChange value has been changed
+    if (isReadChangeStatusValid()) {
+        // do not update if not changed
+        return;
+    }
+       
+    Try
+    {
+        if (this->getIdRef().empty()) {
+            LogError("existing msgId is zero, remove msg not done");
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                    "existing msgId is zero, remove msg not done");
+        }
+
+        if (MSG_SUCCESS !=
+            msg_update_read_status(MsgGetCommonHandle(), convertId(getIdRef()), isReadChangeStatus()))
+        {
+            LogError("Failed to update isRead");
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update isRead");
+        }
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("platform error occurs");
+    }
+    setisReadChangeStatusValidity(true);
+       
+}
+
+void Sms::updateMessage()
+{
+       LogDebug("updating m_id=" << getIdRef());
+       msg_error_t err = MSG_SUCCESS;
+       
+       msg_struct_t msg = NULL;
+       msg_struct_t sendOpt = NULL;
+       
+       if (!m_messageData) {
+               //error if platform message not exists
+               LogError("message can not be updated");
+               Throw(WrtDeviceApis::Commons::PlatformException);
+       }
+       
+       Try
+       {
+
+               msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+               sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+               
+               err = msg_get_message(MsgGetCommonHandle(), convertId(getIdRef()), msg, sendOpt);
+               
+               if (err != MSG_SUCCESS)
+               {
+                       LogError("Get Message Failed!");
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
+               }
+       
+               if (this->getIdRef().empty()) {
+                       LogError("existing msgId is zero, update msg not done");
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException,
+                                       "existing msgId is zero, update msg not done");
+               }
+               
+               update(TRUE);
+               
+               if (MSG_SUCCESS != msg_update_message(MsgGetCommonHandle(), m_messageData, sendOpt))
+               {
+                       LogError("Failed to update message");
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Failed to update message");
+               }
+               msg_release_struct(&msg);
+               msg_release_struct(&sendOpt);
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               msg_release_struct(&msg);
+               msg_release_struct(&sendOpt);
+               LogError("platform error occurs");
+       }
+}
+
+void Sms::createSendMessage()
+{
+       LogDebug("convert m_id= " << convertId(getIdRef()));    
+
+       //prepare for add sms to draft folder
+       if (!m_messageData) {
+               //error if platform message not exists
+               LogError("message can not be updated");
+               Throw(WrtDeviceApis::Commons::PlatformException);
+       }
+
+       //update all sms data
+       if (getCurrentFolder() == Api::Messaging::DRAFTBOX) {
+               LogDebug("update all sms data");
+               updateBody();
+               updateFrom();
+               updateTo();
+               updateSourceAddress();
+       }
+
+       Try
+       {
+               int msgId = 0;
+//             MSG_SENDINGOPT_S option = { false, false, false };
+//             option.option.smsSendOpt.bReplyPath = true;
+               // trying to get message from platform
+
+//             const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
+
+//             msg_set_message_id(m_messageData, msgId);               
+//             msg_set_folder_id(m_messageData, platfromFolderId);
+//             msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
+
+               setId(convertId(msgId));
+               setFolderType(Api::Messaging::DRAFTBOX);
+               setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               LogError("remove message error");
+               if (m_messageData) {
+                       //releasing platform message structure
+                       msg_release_struct(&m_messageData);
+                       m_messageData = NULL;
+               }
+               throw;
+       }
+
+}
+
+
+
+void Sms::addMessageToDraft()
+{
+    LogDebug("convert m_id= " << convertId(getIdRef()));       
+    msg_struct_t sendOpt = NULL;
+
+    //prepare for add sms to draft folder
+    if (!m_messageData) {
+        //error if platform message not exists
+        LogError("message can not be updated");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+
+    //update all sms data
+    if (getCurrentFolder() == Api::Messaging::DRAFTBOX) {
+        LogDebug("update all sms data");
+        updateBody();
+        updateFrom();
+        updateTo();
+        updateSourceAddress();
+    }
+
+    Try
+    {
+       sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT);
+       msg_set_bool_value(sendOpt, MSG_SEND_OPT_SETTING_BOOL, false);
+        int msgId = -1;
+//        MSG_SENDINGOPT_S option = { false, false, false };
+//        option.option.smsSendOpt.bReplyPath = true;
+        // trying to get message from platform
+
+//        const msg_folder_id_t platfromFolderId = Messaging::convertFolderToPlatform(DRAFTBOX);
+
+//        msg_set_message_id(m_messageData, 0);                
+//        msg_set_folder_id(m_messageData, platfromFolderId);
+//        msg_set_network_status(m_messageData, MSG_NETWORK_NOT_SEND);
+
+        // trying to add message
+        int ret = msg_add_message(MsgGetCommonHandle(), m_messageData, sendOpt);
+        if (ret < MSG_SUCCESS) {
+            LogError("msg_add_message failed, error code=" << ret);
+            Throw(WrtDeviceApis::Commons::PlatformException);
+        }
+       else
+       {
+               msgId = ret;    
+       }
+                       
+         LogDebug("Message ID : " << msgId);
+         if (msgId < 0)
+         {
+                LogDebug("Message ID is invailded ");
+                Throw(WrtDeviceApis::Commons::PlatformException);
+         }
+         
+         msg_set_int_value(m_messageData, MSG_MESSAGE_ID_INT, msgId);
+
+         setId(convertId(msgId));
+        setFolderType(Api::Messaging::DRAFTBOX);
+        setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
+         LogDebug("Message Status " <<  getMessageStatus());
+
+#if 0
+         if ( folder_list_view.nCount )
+               msg_release_list_struct(&folder_list_view);
+#endif   
+       msg_release_struct(&sendOpt);
+
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("remove message error");
+        if (m_messageData) {
+            //releasing platform message structure
+            msg_release_struct(&m_messageData);
+            m_messageData = NULL;
+            msg_release_struct(&sendOpt);
+        }
+        throw;
+    }
+
+}
+
+void Sms::readRecipientList(msg_struct_t& messageData)
+{
+       std::string phoneNumber;
+//     int recipientCount = msg_get_address_count(messageData);
+//     LogDebug("Recipient count " << recipientCount);
+
+       msg_struct_list_s *addr_list;
+       msg_get_list_handle(messageData, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+
+       int tempInt = 0;
+       char strNumber[MAX_ADDRESS_VAL_LEN] = {0,};
+
+       int recipientCount = addr_list->nCount;
+       LogDebug("Recipient count " << recipientCount);
+
+       
+       for (int i = 0; i < recipientCount; ++i) 
+{
+               msg_get_int_value(messageData, MSG_MESSAGE_DIRECTION_INT, &tempInt);
+               int type = tempInt;
+
+               if (MSG_DIRECTION_TYPE_MT == type) 
+               {
+                       msg_struct_t addr_info = addr_list->msg_struct_info[i];
+                       msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                       phoneNumber = strNumber;
+               
+                       if (validatePhoneNumber(phoneNumber)) 
+                       {
+                               setSourceAddress(phoneNumber);
+                               setFrom(phoneNumber);
+                       }
+                       LogDebug("MT number: " << phoneNumber);
+            }
+               else if (MSG_DIRECTION_TYPE_MO == type) 
+               {
+                       msg_struct_t addr_info = addr_list->msg_struct_info[i];
+                       msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, strNumber, MAX_ADDRESS_VAL_LEN);
+                       LogDebug("MO number: " << strNumber);
+                       appendToRecipients(strNumber);
+               } 
+               else 
+               {
+                       LogError("Wrong type of recipient");
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Wrong type of recipient");
+        }
+    }
+}
+
+void Sms::readBody(msg_struct_t& messageData)
+{
+    //set abstraction body value
+    int tempInt;
+    msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
+    LogError("body Size : " <<tempInt);
+    char msgText[tempInt+1];
+    memset(msgText, 0, tempInt+1);
+    msg_get_str_value(messageData, MSG_MESSAGE_SMS_DATA_STR, msgText, tempInt);
+//    setBody(msg_sms_get_message_body(messageData));
+    LogError("body : " <<msgText);
+    setBody(msgText);
+}
+
+void Sms::readFolder(msg_struct_t& messageData)
+{
+    int tempInt = 0;
+    msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
+    LogError("Folder : " <<tempInt);
+
+    switch (tempInt) {
+    case MSG_INBOX_ID:
+        setFolderType(Api::Messaging::INBOX);
+        break;
+    case MSG_OUTBOX_ID:
+        setFolderType(Api::Messaging::OUTBOX);
+        break;
+    case MSG_SENTBOX_ID:
+        setFolderType(Api::Messaging::SENTBOX);
+        break;
+    case MSG_DRAFT_ID:
+        setFolderType(Api::Messaging::DRAFTBOX);
+        break;
+    default:
+        LogError("Wrong folder id");
+        ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Unsupported folder id.");
+    }
+}
+
+void Sms::readMessageStatus(msg_struct_t& messageData)
+{
+       int tempValue = 0;
+       msg_get_int_value(messageData, MSG_MESSAGE_FOLDER_ID_INT, &tempValue);
+       LogDebug("readMessageStatus folder : " << tempValue);
+
+       switch (tempValue) {
+               case MSG_INBOX_ID:
+                       setMessageStatus(Api::Messaging::MESSAGE_STATUS_LOADED);
+                       break;
+               case MSG_OUTBOX_ID:
+                       setMessageStatus(Api::Messaging::MESSAGE_STATUS_SENDING);
+                       break;
+               case MSG_SENTBOX_ID:
+                       setMessageStatus(Api::Messaging::MESSAGE_STATUS_SENT);
+                       break;
+               case MSG_DRAFT_ID:
+                       setMessageStatus(Api::Messaging::MESSAGE_STATUS_DRAFT);
+                       break;
+               default:
+                       setMessageStatus(Api::Messaging::MESSAGE_STATUS_LOADED);
+                       break;                  
+       }
+}
+
+
+void Sms::readDateTime(msg_struct_t& messageData)
+{
+//  tm* time = localtime(msg_get_time(messageData));
+//    tm dateT = getDateTime();
+    int tempInt = 0;
+    msg_get_int_value(messageData, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
+
+    LogError("readDateTime : " <<tempInt);
+
+    tm* time = localtime((time_t*)&tempInt);
+    if (!time) {
+        LogError("localtime failed");
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+    setDateTime(*time);
+}
+
+void Sms::readReadStatus(msg_struct_t& messageData)
+{
+    // get read status
+    bool tempBool = 0;
+    msg_get_bool_value(messageData, MSG_MESSAGE_READ_BOOL, &tempBool);
+    LogError("readReadStatus : " <<tempBool);
+    setReadStatus(tempBool);
+}
+
+void Sms::readSize(msg_struct_t& messageData)
+{
+    int tempInt;
+    msg_get_int_value(messageData, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
+//    setSize(msg_get_message_body_size(messageData));
+    LogError("readSize : " <<tempInt);
+    setSize(tempInt);
+}
+
+msg_struct_t Sms::createNewCopyOfPLatformMsg(const msg_struct_t src) const
+{
+       int tempInt;
+       bool tempBool;
+       
+       msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+
+       msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
+
+       msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
+
+       msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
+       char tempStr[tempInt+1];
+       memset(tempStr, 0, tempInt+1);
+
+       msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
+       msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
+
+       msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
+
+//    msg_set_network_status(msg, msg_get_network_status(src));
+       msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT,  tempInt);
+
+//    msg_set_encode_type(msg, msg_get_encode_type(src));
+       msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT,  tempInt);
+
+//    msg_set_read_status(msg, msg_is_read(src));
+       msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
+       msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
+
+//       msg_set_protect_status(msg, msg_is_protected(src));
+       msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
+       msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
+
+//       msg_set_priority_info(msg, msg_get_priority_info(src));
+       msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT,  tempInt);
+
+//       msg_set_direction_info(msg, msg_get_direction_info(src));
+       msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT,  tempInt);
+
+//       msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
+       msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT,  tempInt);
+       msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT,  tempInt);
+
+    return msg;
+}
+
+msg_struct_t Sms::createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const
+{
+       int tempInt;
+       bool tempBool;
+       msg_struct_list_s *addr_list;
+       msg_struct_list_s *new_addr_list;
+       
+       msg_struct_t msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);
+
+       msg_get_int_value(src, MSG_MESSAGE_STORAGE_ID_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_STORAGE_ID_INT, tempInt);
+
+       msg_get_int_value(src, MSG_MESSAGE_FOLDER_ID_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, tempInt);
+
+       msg_get_int_value(src, MSG_MESSAGE_DATA_SIZE_INT, &tempInt);
+       char tempStr[tempInt+1];
+       memset(tempStr, 0, tempInt+1);
+
+       msg_get_str_value(src, MSG_MESSAGE_SMS_DATA_STR, tempStr, tempInt);
+       msg_set_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, tempStr, strlen(tempStr));
+
+       msg_get_int_value(src, MSG_MESSAGE_DISPLAY_TIME_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, tempInt);
+
+//    msg_set_network_status(msg, msg_get_network_status(src));
+       msg_get_int_value(src, MSG_MESSAGE_NETWORK_STATUS_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_NETWORK_STATUS_INT,  tempInt);
+
+//    msg_set_encode_type(msg, msg_get_encode_type(src));
+       msg_get_int_value(src, MSG_MESSAGE_ENCODE_TYPE_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_ENCODE_TYPE_INT,  tempInt);
+
+//    msg_set_read_status(msg, msg_is_read(src));
+       msg_get_bool_value(src, MSG_MESSAGE_READ_BOOL, &tempBool);
+       msg_set_bool_value(msg, MSG_MESSAGE_READ_BOOL, tempBool);
+
+//       msg_set_protect_status(msg, msg_is_protected(src));
+       msg_get_bool_value(src, MSG_MESSAGE_PROTECTED_BOOL, &tempBool);
+       msg_set_bool_value(msg, MSG_MESSAGE_PROTECTED_BOOL, tempBool);
+
+//       msg_set_priority_info(msg, msg_get_priority_info(src));
+       msg_get_int_value(src, MSG_MESSAGE_PRIORITY_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_PRIORITY_INT,  tempInt);
+
+//       msg_set_direction_info(msg, msg_get_direction_info(src));
+       msg_get_int_value(src, MSG_MESSAGE_DIRECTION_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_DIRECTION_INT,  tempInt);
+
+//       msg_set_port(msg, msg_get_dest_port(src), msg_get_src_port(src));
+       msg_get_int_value(src, MSG_MESSAGE_DEST_PORT_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_DEST_PORT_INT,  tempInt);
+       msg_get_int_value(src, MSG_MESSAGE_SRC_PORT_INT, &tempInt);
+       msg_set_int_value(msg, MSG_MESSAGE_SRC_PORT_INT,  tempInt);
+
+// copy addr list
+       msg_get_list_handle(src, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&addr_list);
+       msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&new_addr_list);
+
+       new_addr_list->nCount = addr_list->nCount;
+
+       for(int i=0; i<addr_list->nCount; i++)
+       {
+               msg_struct_t addr_info = NULL;
+               msg_struct_t new_addr_info = NULL;
+               char addr_value[MAX_ADDRESS_VAL_LEN] = {0,};
+               
+               //get original address
+               addr_info = addr_list->msg_struct_info[i];
+               msg_get_str_value(addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
+               msg_get_int_value(addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, &tempInt);
+
+               //copy original address
+               new_addr_info = new_addr_list->msg_struct_info[i];
+               msg_set_str_value(new_addr_info, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, addr_value, MAX_ADDRESS_VAL_LEN);
+               msg_set_int_value(new_addr_info, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, tempInt);
+       }
+
+    return msg;
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/Sms.h b/src/platform/Tizen/Messaging/Sms.h
new file mode 100755 (executable)
index 0000000..65e2196
--- /dev/null
@@ -0,0 +1,145 @@
+//
+// 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 SMS_H
+#define SMS_H
+
+#include <API/Messaging/ISms.h>
+#include "ISendingObserver.h"
+#include <queue>
+
+extern "C" {
+#include <msg_transport.h>
+#include <msg.h>
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+class Sms : public Api::Messaging::ISms,
+    public ISendingObserver,
+        public DPL::Event::Controller<DPL::TypeListDecl<int>::Type >
+{
+  public:
+    explicit Sms(const std::string& id = "");
+
+    explicit Sms(const std::string& id, const msg_struct_t msg_data);
+
+    virtual ~Sms();
+
+    // implementation of interface of IMessage class
+    virtual void update(bool draftsOnly = false);
+
+    virtual void readAllData();
+
+    virtual void moveToFolder(const Api::Messaging::FolderType newFolder);
+
+    virtual void moveToFolder(const std::string& newFolder);
+
+    virtual void copyToFolder(const Api::Messaging::FolderType newFolder);
+
+    virtual void copyToFolder(const std::string& newFolder);
+
+    virtual void remove();
+
+    virtual int send();
+
+    virtual void sendCancel(int handle)
+    {
+    }
+
+    virtual void sendingCallback(msg_struct_t sent_status);
+
+    virtual void OnEventReceived(const int& /*event*/);
+
+    static Api::Messaging::FolderType toFolder(const std::string &folder);
+
+  private:
+    void sendSubMessage();
+
+    void setSendingStatusOk(const std::string &recipient = std::string());
+
+    void setSendingStatusFailed(const std::string &recipient = std::string());
+
+    void createNewMessage();
+
+    void readExistingMessage();
+
+    void updateBody();
+
+    void updateTo();
+
+    void updateFrom();
+
+    void updateSourceAddress();
+
+    void updateReadStatus();
+
+    void updateIsRead();
+
+    void updateMessage();
+       
+    void addMessageToDraft();
+
+    void createSendMessage();
+
+    void readRecipientList(msg_struct_t& messageData);
+
+    void readBody(msg_struct_t& messageData);
+
+    void readFolder(msg_struct_t& messageData);
+
+    void readDateTime(msg_struct_t& messageData);
+
+    void readReadStatus(msg_struct_t& messageData);
+
+    void readSize(msg_struct_t& messageData);
+
+    void readMessageStatus(msg_struct_t& messageData); 
+
+    std::queue<msg_struct_t>& currentQueue()
+    {
+        return m_sendRequests.front().queue;
+    }
+
+    msg_struct_t createNewCopyOfPLatformMsg(const msg_struct_t src) const;
+
+    msg_struct_t createNewCopyOfPLatformMsgWithAddressList(const msg_struct_t src) const;
+
+  private:
+    msg_struct_t m_messageData;
+    bool m_sendingFailed;
+    DPL::Mutex m_mutex;
+
+    struct SendRequest
+    {
+        // queue of sub messages for each recipient
+        std::queue<msg_struct_t> queue;
+        bool failed;
+
+        SendRequest() : failed(false)
+        {
+        }
+    };
+    // queue of send requests
+    std::queue<SendRequest> m_sendRequests;
+};
+}
+}
+}
+#endif
diff --git a/src/platform/Tizen/Messaging/SyncNetworkStatus.cpp b/src/platform/Tizen/Messaging/SyncNetworkStatus.cpp
new file mode 100755 (executable)
index 0000000..527e92a
--- /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 <dpl/assert.h>
+#include <Commons/Exception.h>
+#include "SyncNetworkStatus.h"
+#include <dpl/log/log.h>
+
+namespace {
+const char* DBUS_INTERFACE_NETWORK_STATUS = "User.Email.NetworkStatus";
+const int DBUS_MESSAGE_PARAMETERS_NUMBER = 5;
+}
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+
+SyncNetworkStatus::SyncNetworkStatus(const DBus::MessagePtr& message)
+{
+    Assert(message->getInterface() == DBUS_INTERFACE_NETWORK_STATUS);
+    initialize(message);
+}
+
+int SyncNetworkStatus::getStatus() const
+{
+    return m_status;
+}
+
+int SyncNetworkStatus::getHandle() const
+{
+    return m_handle;
+}
+
+std::string SyncNetworkStatus::getSource() const
+{
+    return m_source;
+}
+
+int SyncNetworkStatus::getMailId() const
+{
+    return m_mailId;
+}
+
+int SyncNetworkStatus::getErrorCode() const
+{
+    return m_errorCode;
+}
+
+void SyncNetworkStatus::initialize(const DBus::MessagePtr& message)
+{
+    DBus::Message::ReadIterator it = message->getReadIterator();
+    for (int i = 0; i < DBUS_MESSAGE_PARAMETERS_NUMBER; it->next(), ++i) {
+        if (!it->isValid()) {
+            ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Missing some properties.");
+        }
+
+        switch (i) {
+        case 0: m_status = it->getInt();
+                LogDebug("status :" << m_status);
+            break;
+        case 1: m_mailId = it->getInt();
+                LogDebug("mail ID :" << m_mailId);
+            break;
+        case 2: m_source = it->getString();
+                LogDebug("source :" << m_source);
+            break;
+        case 3: m_handle = it->getInt();
+                LogDebug("handle :" << m_handle);
+            break;
+        case 4: m_errorCode = it->getInt();
+                LogDebug("error Code :" << m_errorCode);
+            break;
+        }
+    }
+}
+}
+}
+}
diff --git a/src/platform/Tizen/Messaging/SyncNetworkStatus.h b/src/platform/Tizen/Messaging/SyncNetworkStatus.h
new file mode 100755 (executable)
index 0000000..974afa8
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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 SYNCNETWORKSTATUS_H_
+#define SYNCNETWORKSTATUS_H_
+
+#include <string>
+#include <dpl/noncopyable.h>
+#include <dpl/shared_ptr.h>
+#include <DBus/Message.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Messaging {
+class SyncNetworkStatus : private DPL::Noncopyable
+{
+  public:
+    explicit SyncNetworkStatus(const DBus::MessagePtr& message);
+
+    int getStatus() const;
+    int getHandle() const;
+    std::string getSource() const;
+    int getMailId() const;
+    int getErrorCode() const;
+
+  private:
+    void initialize(const DBus::MessagePtr& message);
+
+  private:
+    int m_status;
+    int m_handle;
+    /*
+     * Not sure what it stores. According to source code of Email application
+     * it can contain string "ACTIVESYNC" or name of the file which stores body.
+     */
+    std::string m_source;
+    int m_mailId;
+    int m_errorCode;
+};
+
+typedef DPL::SharedPtr<SyncNetworkStatus> SyncNetworkStatusPtr;
+}
+}
+}
+#endif // SYNCNETWORKSTATUS_H_
\ No newline at end of file
diff --git a/src/platform/Tizen/Messaging/config.cmake b/src/platform/Tizen/Messaging/config.cmake
new file mode 100755 (executable)
index 0000000..95bdf0b
--- /dev/null
@@ -0,0 +1,73 @@
+get_current_path()
+
+pkg_search_module(msg-service-module REQUIRED msg-service)
+pkg_search_module(email-service-module REQUIRED email-service)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_MESSAGING
+  ${msg-service-module_INCLUDE_DIRS}
+  ${email-service-module_INCLUDE_DIRS}
+  ${INCLUDES_PLATFORM_IMPLEMENTATION_DBUS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_MESSAGING
+  ${msg-service-module_LIBRARIES}
+  ${email-service-module_LIBRARIES}
+  ${LIBS_PLATFORM_IMPLEMENTATION_DBUS}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_MESSAGING
+    ${CURRENT_PATH}/MessagingServiceManager.cpp
+    ${CURRENT_PATH}/MessagingService.cpp
+    
+    ${CURRENT_PATH}/Attachment.cpp
+    ${CURRENT_PATH}/BinarySms.cpp
+    ${CURRENT_PATH}/Email.cpp
+    ${CURRENT_PATH}/Messaging.cpp
+    ${CURRENT_PATH}/Mms.cpp
+    ${CURRENT_PATH}/Sms.cpp
+    ${CURRENT_PATH}/EmptyMessage.cpp
+    ${CURRENT_PATH}/CallbackMgr.cpp
+    ${CURRENT_PATH}/NetworkStatus.cpp
+    ${CURRENT_PATH}/SyncNetworkStatus.cpp
+    ${CURRENT_PATH}/MailSender.cpp
+    ${CURRENT_PATH}/MailSync.cpp
+    ${CURRENT_PATH}/EmailService.cpp
+    ${CURRENT_PATH}/EmailUtils.cpp
+    ${CURRENT_PATH}/EmailConverter.cpp
+    ${CURRENT_PATH}/MessageQueryGenerator.cpp
+    ${CURRENT_PATH}/Conversation.cpp
+    ${CURRENT_PATH}/MessageFolder.cpp
+    ${CURRENT_PATH}/ConversationQueryGenerator.cpp
+    ${CURRENT_PATH}/FolderQueryGenerator.cpp    
+    ${CURRENT_PATH}/messageDB/MsgSqliteWrapper.cpp
+    ${CURRENT_PATH}/messageDB/MessageStorageReader.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/IManager.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/IPath.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/INode.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/IStream.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/EventCopy.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/EventFind.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/EventResolve.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/EventMove.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/EventRemove.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/EventOpen.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/EventListNodes.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/EventReadText.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/NodeFilter.cpp
+ #   ${CURRENT_PATH}/../../API/Filesystem/PathUtils.cpp
+ #   ${CURRENT_PATH}/../Filesystem/System.cpp
+ #   ${CURRENT_PATH}/../Filesystem/Manager.cpp
+ #   ${CURRENT_PATH}/../Filesystem/Utils.cpp
+ #   ${CURRENT_PATH}/../Filesystem/Path.cpp
+ #   ${CURRENT_PATH}/../Filesystem/Node.cpp
+ #   ${CURRENT_PATH}/../Filesystem/Stream.cpp
+ #   ${CURRENT_PATH}/../Filesystem/NodeFilterMatcher.cpp
+ #   ${CURRENT_PATH}/../Filesystem/Command.cpp
+ #   ${CURRENT_PATH}/../Filesystem/MoveCommand.cpp
+ #   ${CURRENT_PATH}/../Filesystem/RemoveCommand.cpp
+ #   ${CURRENT_PATH}/../Filesystem/CopyCommand.cpp
+   ${SRCS_PLATFORM_IMPLEMENTATION_DBUS}
+  PARENT_SCOPE 
+)
diff --git a/src/platform/Tizen/Messaging/messageDB/MessageStorageReader.cpp b/src/platform/Tizen/Messaging/messageDB/MessageStorageReader.cpp
new file mode 100755 (executable)
index 0000000..fe7d994
--- /dev/null
@@ -0,0 +1,606 @@
+//
+// 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 "MessageStorageReader.h"
+#include "MsgSqliteWrapper.h"
+
+#include <dpl/log/log.h>
+
+#define MAX_THREAD_ADDR_LEN    40
+#define MAX_THREAD_NAME_LEN    195
+#define MAX_THREAD_DATA_LEN    128
+
+namespace{
+//TODO copied from MsgInternalTypes.h
+       typedef unsigned char MSG_MAIN_TYPE_T;
+       typedef unsigned char MSG_SUB_TYPE_T;
+       typedef unsigned char MSG_CLASS_TYPE_T;
+
+       typedef struct
+       {
+               msg_address_type_t              addressType;                                                                                                    /**< The type of an address in case of an Email or a mobile phone */
+               msg_recipient_type_t    recipientType;                                                                                                  /**< The type of recipient address in case of To, Cc, and Bcc */
+               msg_contact_id_t                        contactId;                                                                                                                      /**< The contact ID of address */
+               char                                                                            addressVal[MAX_ADDRESS_VAL_LEN+1];              /**< The actual value of an address */
+               char                                                                            displayName[MAX_DISPLAY_NAME_LEN+1];    /**< The display name of an address */
+       } MSG_ADDRESS_INFO_S;
+
+       typedef struct _msg_struct{
+               int type;
+               void *data;
+       }msg_struct_s;
+
+       typedef struct
+       {
+               msg_message_id_t                msgId;                                                                  /**< Indicates the message ID of this message. */
+               msg_thread_id_t                 threadId;                                                               /**< Indicates the thread ID. */
+               msg_folder_id_t                 folderId;                                                               /**< Indicates the folder ID. see enum _MSG_FOLDER_TYPE_E */
+               MSG_MAIN_TYPE_T                 mainType;                                                               /**< Message main type. See enum _MSG_MAIN_TYPE_E */
+               MSG_SUB_TYPE_T                  subType;                                                                /**< Message sub type. See enum _MSG_SUB_TYPE_E */
+               MSG_CLASS_TYPE_T                classType;                                                              /**< Message class type. See enum _MSG_CLASS_TYPE_E */
+               msg_storage_id_t                storageId;                                                              /**< Indicates where the message is saved. see enum _MSG_FOLDER_TYPE_E*/
+               msg_struct_list_s               *addr_list;
+               char                                    replyAddress[MAX_PHONE_NUMBER_LEN+1];   /**< Indicates the reply address. */
+               char                                    subject[MAX_SUBJECT_LEN+1];                                     /**< Indicates the message subject. */
+               time_t                                  displayTime;                                                                                                    /**< Indicates the display time related to the specific operation. */
+               msg_network_status_t    networkStatus;                                                  /**< Indicates the network status of the message. */
+               msg_encode_type_t               encodeType;                                                     /**< Indicates the string encoding type. */
+               bool                                    bRead;                                                                                                                          /**< Indicates whether the message is read or not. */
+               bool                                    bProtected;                                                                                                     /**< Indicates whether the message is protected or not. */
+               bool                                    bBackup;                                                                                                                        /**< Indicates whether the message was restored from PC. */
+               msg_priority_type_t     priority;                                                               /**< Indicates the priority of the message. */
+               msg_direction_type_t    direction;                                                              /**< Indicates whether the message is MO or MT, affecting address. */
+               bool                                    bPortValid;                                                             /**< Indicates whether port information is used or not. */
+               unsigned short                  dstPort;                                                                /**< Recipient port number, not greater than 16 bit */
+               unsigned short                  srcPort;                                                                /**< Sender port number, not greater than 16 bit */
+               int                                     attachCount;                                                                                                    /**< Indicates the count of attached files in mms. */
+               char                                    thumbPath[MSG_FILEPATH_LEN_MAX+1];
+               size_t                                  dataSize;                                                                                                                       /**< Indicates the data size. The unit is byte. */
+               void                                    *pData;                                                                                                                         /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
+               void                                    *pMmsData;                                                                                                              /**< Indicates the message payload information as a body. default character encoding is UTF-8*/
+       } MSG_MESSAGE_HIDDEN_S;
+
+
+       /**
+        *      @brief  Represents message information for thread view.
+        */
+       typedef struct
+       {
+               msg_thread_id_t                 threadId;                                                                                                                       /**< Indicates the thread ID of this peer. */
+               char                                    threadName[MAX_THREAD_NAME_LEN+1];              /**< Indicates the name of this peer. > */
+               MSG_MAIN_TYPE_T                 mainType;                                                               /**< Indicates the latest msg main type. */
+               MSG_SUB_TYPE_T                  subType;                                                                /**< Indicates the latest msg sub type. */
+               char                                    threadData[MAX_THREAD_DATA_LEN+1];              /**< Indicates the latest msg data. */
+               time_t                                  threadTime;                                                                                                     /**< Indicates the latest msg time. */
+               msg_direction_type_t    direction;                                                                                                                      /**< Indicates whether the message is MO or MT (affecting address). */
+               int                                     unreadCnt;                                                                                                              /**< Indicates the unread messages from the Peer. */
+               int                                     smsCnt;                                                                                                                 /**< Indicates the SMS messages from the Peer. */
+               int                                     mmsCnt;                                                                                                                 /**< Indicates the MMS messages from the Peer. */
+               bool                                    bProtected;                                                                                                     /**< Indicates whether the thread includes protected messages.  */
+       } MSG_THREAD_VIEW_S;
+
+       enum _MSG_MAIN_TYPE_E
+       {
+               MSG_UNKNOWN_TYPE = 0,           /**< Unknown main type */
+               MSG_SMS_TYPE,                           /**< SMS */
+               MSG_MMS_TYPE,                           /**< MMS */
+       };
+
+}//namespace
+
+enum _MSG_SUB_TYPE_E
+{
+       /* SMS Specific Message Type */
+       MSG_NORMAL_SMS = 0,                     /**< Text SMS message */
+       MSG_CB_SMS,                                     /**< Cell Broadcasting  message */
+       MSG_JAVACB_SMS,                         /**< JAVA Cell Broadcasting  message */
+       MSG_TYPE0_SMS,                                  /**< Short Message Type 0 */
+       MSG_REPLACE_TYPE1_SMS,          /**< Replace Short Message Type 1 */
+       MSG_REPLACE_TYPE2_SMS,          /**< Replace Short Message Type 2 */
+       MSG_REPLACE_TYPE3_SMS,          /**< Replace Short Message Type 3 */
+       MSG_REPLACE_TYPE4_SMS,          /**< Replace Short Message Type 4 */
+       MSG_REPLACE_TYPE5_SMS,          /**< Replace Short Message Type 5 */
+       MSG_REPLACE_TYPE6_SMS,          /**< Replace Short Message Type 6 */
+       MSG_REPLACE_TYPE7_SMS,          /**< Replace Short Message Type 7 */
+       MSG_WAP_SI_SMS,                         /**< WAP Push Message SI */
+       MSG_WAP_SL_SMS,                         /**< WAP Push Message SL */
+       MSG_WAP_CO_SMS,                         /**< WAP Push Message CO */
+       MSG_MWI_VOICE_SMS,                      /**< MWI Message Voice */
+       MSG_MWI_FAX_SMS,                                /**< MWI Message Fax */
+       MSG_MWI_EMAIL_SMS,                      /**< MWI Message Email */
+       MSG_MWI_OTHER_SMS,                      /**< MWI Message Other */
+       MSG_STATUS_REPORT_SMS,          /**< SMS-STATUS-REPORT */
+       MSG_SYNCML_CP,                          /**< SyncML Message CP */
+       MSG_LBS_SMS,                                    /**< LBS Message */
+       MSG_REJECT_SMS,                         /**< Reject Message */
+       MSG_CONCAT_SIM_SMS,                     /**< Concatenated Message in SIM */
+
+       /* MMS Specific Message Type */
+       MSG_SENDREQ_MMS = 24,                                   /**< MMS Send Request message */
+       MSG_SENDCONF_MMS,                               /**< MMS Send Confirm message */
+       MSG_NOTIFICATIONIND_MMS,                        /**< MMS Notification Indication message */
+       MSG_GET_MMS,                                            /**< MMS GET MMS message */
+       MSG_NOTIFYRESPIND_MMS,                  /**< MMS Notify Response Indication message */
+       MSG_RETRIEVE_MMS,                                       /**< MMS Retrive MMS message */
+       MSG_RETRIEVE_AUTOCONF_MMS,              /**< MMS Retrieve Confirm message by auto retrieving*/
+       MSG_RETRIEVE_MANUALCONF_MMS,    /**< MMS Retrieve Confirm message by manual retrieving*/
+       MSG_ACKNOWLEGEIND_MMS,                  /**< MMS Acknowledge Indication message */
+       MSG_DELIVERYIND_MMS,                            /**< MMS Delivery Indication message */
+       MSG_READRECIND_MMS,                             /**< MMS Read Receive Indication message */
+       MSG_READORGIND_MMS,                             /**< MMS Read Origin Indication message */
+       MSG_FORWARD_MMS,                                        /**< MMS Forward message */
+       MSG_FORWARDREQ_MMS,                             /**< MMS Forward Request message */
+       MSG_FORWARDCONF_MMS,                    /**< MMS Forward Confirm message */
+       MSG_READREPLY_MMS,                              /**< MMS Read Reply message */
+       MSG_SENDREQ_JAVA_MMS,                   /**< MMS Send Request message for JAVA MMS */
+
+       MSG_ETWS_SMS,
+};
+
+
+
+MessageStorageReader::MessageStorageReader() {
+       // TODO Auto-generated constructor stub
+
+}
+
+MessageStorageReader::~MessageStorageReader() {
+       // TODO Auto-generated destructor stub
+}
+
+msg_error_t MessageStorageReader::MsgStoConnectDB(){
+       return MSG_SUCCESS;
+}
+
+msg_error_t MessageStorageReader::MsgStoDisconnectDB(){
+       if (dbHandle.disconnect() != MSG_SUCCESS){
+               LogError(">>>[ERROR] DB Disconnect Fail");
+               return MSG_ERR_DB_DISCONNECT;
+       }
+
+       LogDebug(">>>");
+
+       return MSG_SUCCESS;
+}
+
+int MessageStorageReader::queryMessage(const std::string& whereClause, const std::string& orderLimit, /*out*/msg_struct_list_s *pMsgList){
+       LogDebug("<<< whereClause:[" << whereClause << "]");
+
+       // Clear Out Parameter
+       pMsgList->nCount = 0;
+       pMsgList->msg_struct_info = NULL;
+
+       int rowCnt = 0;
+       int index = 26; // numbers of index
+
+       char firstName[MAX_DISPLAY_NAME_LEN+1], lastName[MAX_DISPLAY_NAME_LEN+1];
+       char displayName[MAX_DISPLAY_NAME_LEN+1];
+
+       std::ostringstream oStream;
+       std::string stringSqlQuery;
+       std::string tmpWhereClause;     
+
+       // Get Name Order
+//     int order = MsgGetContactNameOrder();
+       int order = 0;
+
+               oStream << "SELECT A.MSG_ID, A.CONV_ID, A.FOLDER_ID, A.STORAGE_ID, A.MAIN_TYPE, A.SUB_TYPE, \
+A.DISPLAY_TIME, A.DATA_SIZE, A.NETWORK_STATUS, A.READ_STATUS, A.PROTECTED, A.BACKUP, A.PRIORITY, \
+A.MSG_DIRECTION, A.SCHEDULED_TIME, A.SUBJECT, A.MSG_TEXT, B.ADDRESS_TYPE, B.RECIPIENT_TYPE, \
+B.CONTACT_ID, B.ADDRESS_VAL, B.DISPLAY_NAME, B.FIRST_NAME, B.LAST_NAME, A.ATTACHMENT_COUNT, A.THUMB_PATH \
+FROM " << MSGFW_MESSAGE_TABLE_NAME << " A, " << MSGFW_ADDRESS_TABLE_NAME << " B ";
+
+
+       if(whereClause.length()==0){
+               tmpWhereClause.append("WHERE ");
+       }else{
+               tmpWhereClause.append(whereClause);
+               tmpWhereClause.append(" ");
+               tmpWhereClause.append("AND ");
+       }
+
+       tmpWhereClause.append("(A.CONV_ID = B.CONV_ID AND B.ADDRESS_ID <> 0) ");
+
+       if(orderLimit.length() == 0)
+       {
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
+       }
+       else
+       {
+               tmpWhereClause.append(orderLimit);
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
+       }
+       LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
+
+
+       oStream << tmpWhereClause;
+       stringSqlQuery = oStream.str();
+
+       LogDebug("stringSqlQuery:[" << stringSqlQuery << "]");
+       msg_error_t err = dbHandle.getTable(stringSqlQuery.c_str(), &rowCnt);
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               LogDebug("MSG_ERR_DB_NORECORD");                
+               dbHandle.freeTable();
+
+               return MSG_SUCCESS;
+       } else if (err != MSG_SUCCESS) {
+               LogDebug("Get table fail. "<< stringSqlQuery);
+
+               dbHandle.freeTable();
+
+               return err;
+       }
+       
+       pMsgList->nCount = rowCnt;
+
+       LogDebug("pMsgList->nCount ="<<  pMsgList->nCount);
+
+       pMsgList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t) * rowCnt];
+
+       MSG_MESSAGE_HIDDEN_S *pTmp = NULL;
+       msg_struct_s *msg = NULL;
+
+       for (int i = 0; i < rowCnt; i++) {
+               pMsgList->msg_struct_info[i] = (msg_struct_t)new msg_struct_s;
+
+               msg = (msg_struct_s *)pMsgList->msg_struct_info[i];
+
+               msg->type = MSG_STRUCT_MESSAGE_INFO;
+               msg->data = (int *)new char[sizeof(MSG_MESSAGE_HIDDEN_S)];
+
+               pTmp = (MSG_MESSAGE_HIDDEN_S *)msg->data;
+
+               memset(pTmp, 0x00, sizeof(MSG_MESSAGE_HIDDEN_S));
+
+               pTmp->pData = NULL;
+               pTmp->pMmsData = NULL;
+
+               pTmp->msgId = dbHandle.getColumnToInt(index++);
+               pTmp->threadId = dbHandle.getColumnToInt(index++);
+               pTmp->folderId = dbHandle.getColumnToInt(index++);
+               pTmp->storageId = dbHandle.getColumnToInt(index++);
+               pTmp->mainType = dbHandle.getColumnToInt(index++);
+               pTmp->subType = dbHandle.getColumnToInt(index++);
+               pTmp->displayTime = (time_t)dbHandle.getColumnToInt(index++);
+               pTmp->dataSize = dbHandle.getColumnToInt(index++);
+               pTmp->networkStatus = dbHandle.getColumnToInt(index++);
+               pTmp->bRead = dbHandle.getColumnToInt(index++);
+               pTmp->bProtected = dbHandle.getColumnToInt(index++);
+               pTmp->bBackup = dbHandle.getColumnToInt(index++);
+               pTmp->priority = dbHandle.getColumnToInt(index++);
+               pTmp->direction= dbHandle.getColumnToInt(index++);
+               index++; // This field is reserved.
+
+               dbHandle.getColumnToString(index++, MAX_SUBJECT_LEN, pTmp->subject);
+
+               if (pTmp->mainType == MSG_MMS_TYPE &&
+                       (pTmp->networkStatus == MSG_NETWORK_RETRIEVING || pTmp->networkStatus == MSG_NETWORK_RETRIEVE_FAIL || pTmp->subType == MSG_NOTIFICATIONIND_MMS)) {
+                       pTmp->pData = NULL;
+                       index++;
+               } else {
+                       LogDebug("pTmp->dataSize = "<< pTmp->dataSize);
+                       pTmp->pData = (void *)new char[pTmp->dataSize + 2];
+                       memset(pTmp->pData, 0x00, pTmp->dataSize + 2);
+
+                       dbHandle.getColumnToString(index++, pTmp->dataSize+1, (char *)pTmp->pData);
+               }
+
+               msg_struct_list_s *addr_list = (msg_struct_list_s *)new msg_struct_list_s;
+               msg_struct_s *addr_info = NULL;
+               MSG_ADDRESS_INFO_S *address = NULL;
+
+               addr_list->nCount = 1;
+               addr_list->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t *)*MAX_TO_ADDRESS_CNT];
+
+               msg_struct_s *pTmpAddr = NULL;
+
+               for (int i = 0; i < MAX_TO_ADDRESS_CNT; i++) {
+                       addr_list->msg_struct_info[i] = (msg_struct_t)new char[sizeof(msg_struct_s)];
+                       pTmpAddr = (msg_struct_s *)addr_list->msg_struct_info[i];
+                       pTmpAddr->type = MSG_STRUCT_ADDRESS_INFO;
+                       pTmpAddr->data = new MSG_ADDRESS_INFO_S;
+                       memset(pTmpAddr->data, 0x00, sizeof(MSG_ADDRESS_INFO_S));
+
+                       addr_list->msg_struct_info[i] = (msg_struct_t)pTmpAddr;
+               }
+
+               addr_info = (msg_struct_s *)addr_list->msg_struct_info[0];
+               address = (MSG_ADDRESS_INFO_S *)addr_info->data;
+               address->addressType = dbHandle.getColumnToInt(index++);
+               address->recipientType = dbHandle.getColumnToInt(index++);
+               address->contactId = dbHandle.getColumnToInt(index++);
+
+               dbHandle.getColumnToString(index++, MAX_ADDRESS_VAL_LEN, address->addressVal);
+
+               memset(displayName, 0x00, sizeof(displayName));
+               dbHandle.getColumnToString(index++, MAX_DISPLAY_NAME_LEN, displayName);
+
+               memset(firstName, 0x00, sizeof(firstName));
+               dbHandle.getColumnToString(index++, MAX_DISPLAY_NAME_LEN, firstName);
+
+               memset(lastName, 0x00, sizeof(lastName));
+               dbHandle.getColumnToString(index++, MAX_DISPLAY_NAME_LEN, lastName);
+
+               if (strlen(displayName) <= 0) {
+                       if (order == 0) {
+                               if (firstName[0] != '\0') {
+                                       strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
+                               }
+
+                               if (lastName[0] != '\0') {
+                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                                       strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                               }
+                       }
+/*
+                       else if (order == 1) {
+                               if (lastName[0] != '\0') {
+                                       strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
+                                       strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                               }
+
+                               if (firstName[0] != '\0') {
+                                       strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                               }
+                       }
+*/
+               }
+
+               strncpy(address->displayName, displayName, MAX_DISPLAY_NAME_LEN);
+
+               pTmp->addr_list = addr_list;
+
+               pTmp->attachCount = dbHandle.getColumnToInt(index++);
+
+               dbHandle.getColumnToString(index++, MSG_FILEPATH_LEN_MAX, pTmp->thumbPath);
+
+       }
+       dbHandle.freeTable();
+
+       LogDebug(">>>");
+       return MSG_SUCCESS;
+}
+
+int MessageStorageReader::queryConversation(const std::string& whereClause, const std::string& orderLimit,
+//             /*out*/MSG_THREAD_VIEW_LIST_S *pThreadViewList){
+       /*out*/msg_struct_list_s *pThreadViewList){
+
+       pThreadViewList->nCount = 0;
+       pThreadViewList->msg_struct_info = NULL;
+
+       int rowCnt = 0;
+       int index = 10; // numbers of index
+
+       std::ostringstream oStream;
+       std::string stringSqlQuery;
+
+       std::string tmpWhereClause;
+       LogDebug("<<< whereClause:[" << whereClause << "]");
+       if(whereClause.length()==0){
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");              
+               tmpWhereClause.append("WHERE (B.SMS_CNT > 0 OR B.MMS_CNT > 0) AND A.CONV_ID = B.CONV_ID ");
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");                      
+       }else{
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");      
+               tmpWhereClause.append(whereClause);
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");      
+       }
+
+       if(orderLimit.length() == 0)
+       {
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
+       }
+       else
+       {
+               tmpWhereClause.append(orderLimit);
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
+       }
+
+       oStream << "SELECT B.CONV_ID, B.UNREAD_CNT, B.SMS_CNT, B.MMS_CNT, \
+B.MAIN_TYPE, B.SUB_TYPE, B.MSG_DIRECTION, B.DISPLAY_TIME, B.DISPLAY_NAME, B.MSG_TEXT \
+FROM " << MSGFW_ADDRESS_TABLE_NAME << " A, "  << MSGFW_CONVERSATION_TABLE_NAME  << " B ";
+
+       oStream << tmpWhereClause;
+       stringSqlQuery = oStream.str();
+       LogDebug("stringSqlQuery:[" << stringSqlQuery << "]");
+
+       msg_error_t err = dbHandle.getTable(stringSqlQuery.c_str(), &rowCnt);
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               dbHandle.freeTable();
+               return MSG_SUCCESS;
+       } else if (err != MSG_SUCCESS) {
+               LogDebug("stringSqlQuery:[" << stringSqlQuery << "]");
+               dbHandle.freeTable();
+               return err;
+       }
+
+       if (rowCnt < 1) {
+               LogDebug("rowCnt is %d"<< rowCnt);
+               dbHandle.freeTable();
+               return err;
+       }
+
+       pThreadViewList->nCount = rowCnt;
+
+       LogDebug("pThreadViewList->nCount [" << pThreadViewList->nCount << "]");
+
+       pThreadViewList->msg_struct_info = (msg_struct_t *)new char[sizeof(msg_struct_t)*rowCnt];
+
+       MSG_THREAD_VIEW_S *pTmp = NULL;
+       msg_struct_s *thread_t = NULL;
+
+       for (int i = 0; i < rowCnt; i++) {
+               thread_t = (msg_struct_s *)new msg_struct_s;
+               pThreadViewList->msg_struct_info[i] = (msg_struct_t)thread_t;
+
+               thread_t->type = MSG_STRUCT_THREAD_INFO;
+               thread_t->data = new MSG_THREAD_VIEW_S;
+
+               pTmp = (MSG_THREAD_VIEW_S *)thread_t->data;
+               memset(pTmp, 0x00, sizeof(MSG_THREAD_VIEW_S));
+
+               pTmp->threadId = dbHandle.getColumnToInt(index++);
+
+               pTmp->unreadCnt = dbHandle.getColumnToInt(index++);
+               pTmp->smsCnt = dbHandle.getColumnToInt(index++);
+               pTmp->mmsCnt = dbHandle.getColumnToInt(index++);
+
+               pTmp->mainType = dbHandle.getColumnToInt(index++);
+               pTmp->subType = dbHandle.getColumnToInt(index++);
+
+               pTmp->direction = dbHandle.getColumnToInt(index++);
+               pTmp->threadTime = (time_t)dbHandle.getColumnToInt(index++);
+
+               memset(pTmp->threadName, 0x00, sizeof(pTmp->threadName));
+               dbHandle.getColumnToString(index++, MAX_THREAD_NAME_LEN, pTmp->threadName);
+
+               memset(pTmp->threadData, 0x00, sizeof(pTmp->threadData));
+               dbHandle.getColumnToString(index++, MAX_THREAD_DATA_LEN, pTmp->threadData);
+       }
+
+       dbHandle.freeTable();
+
+
+/*
+       pThreadViewList->nCount = 0;
+       pThreadViewList->msgThreadInfo = NULL;
+
+       int rowCnt = 0;
+       int index = 12; // numbers of index
+
+       std::ostringstream oStream;
+       std::string stringSqlQuery;
+
+       std::string tmpWhereClause;
+       LogDebug("<<< whereClause:[" << whereClause << "]");
+       if(whereClause.length()==0){
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");              
+               tmpWhereClause.append("WHERE A.ADDRESS_ID <> 0 AND A.CONV_ID = B.CONV_ID AND A.CONV_ID = C.CONV_ID ");
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");                      
+       }else{
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");      
+               tmpWhereClause.append(whereClause);
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");      
+       }
+
+       if(orderLimit.length() == 0)
+       {
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
+       }
+       else
+       {
+               tmpWhereClause.append(orderLimit);
+               LogDebug("<<< tmpWhereClause:[" << tmpWhereClause << "]");
+       }
+
+       oStream << "SELECT A.ADDRESS_ID, A.DISPLAY_NAME, A.FIRST_NAME, A.LAST_NAME, \
+C.UNREAD_CNT, C.SMS_CNT, C.MMS_CNT, B.MAIN_TYPE, B.SUB_TYPE, B.MSG_DIRECTION, B.DISPLAY_TIME, B.MSG_TEXT \
+FROM " << MSGFW_ADDRESS_TABLE_NAME << " A, " << MSGFW_MESSAGE_TABLE_NAME << " B, " << MSGFW_CONVERSATION_TABLE_NAME << " C " ;
+
+       oStream << tmpWhereClause;
+       stringSqlQuery = oStream.str();
+       LogDebug("stringSqlQuery:[" << stringSqlQuery << "]");
+
+       msg_error_t err = dbHandle.getTable(stringSqlQuery.c_str(), &rowCnt);
+
+       if (err == MSG_ERR_DB_NORECORD) {
+               dbHandle.freeTable();
+
+               return MSG_SUCCESS;
+       } else if (err != MSG_SUCCESS) {
+               LogDebug("stringSqlQuery:[" << stringSqlQuery << "]");
+
+               dbHandle.freeTable();
+
+               return err;
+       }
+
+       char firstName[MAX_THREAD_NAME_LEN+1], lastName[MAX_THREAD_NAME_LEN+1];
+       char displayName[MAX_DISPLAY_NAME_LEN+1];
+
+       int order = 0;
+
+       pThreadViewList->nCount = rowCnt;
+
+       LogDebug("pThreadViewList->nCount [" << pThreadViewList->nCount << "]");
+
+       pThreadViewList->msgThreadInfo = (msg_thread_view_t*) new char[sizeof(MSG_THREAD_VIEW_S*) * rowCnt];
+
+       MSG_THREAD_VIEW_S* pTmp = NULL;
+
+       for (int i = 0; i < rowCnt; i++) {
+                       pThreadViewList->msgThreadInfo[i] = (msg_thread_view_t) new char[sizeof(MSG_THREAD_VIEW_S)];
+
+                       pTmp = (MSG_THREAD_VIEW_S*) pThreadViewList->msgThreadInfo[i];
+
+                       pTmp->threadId = dbHandle.getColumnToInt(index++);
+
+                       memset(displayName, 0x00, sizeof(displayName));
+                       dbHandle.getColumnToString(index++, MAX_THREAD_NAME_LEN, displayName);
+
+                       memset(firstName, 0x00, sizeof(firstName));
+                       dbHandle.getColumnToString(index++, MAX_THREAD_NAME_LEN, firstName);
+
+                       memset(lastName, 0x00, sizeof(lastName));
+                       dbHandle.getColumnToString(index++, MAX_THREAD_NAME_LEN, lastName);
+
+                       if (strlen(displayName) <= 0) {
+                               if (order == 0) {
+                                       if (firstName[0] != '\0') {
+                                               strncpy(displayName, firstName, MAX_DISPLAY_NAME_LEN);
+                                       }
+
+                                       if (lastName[0] != '\0') {
+                                               strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                                               strncat(displayName, lastName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                                       }
+                               } else if (order == 1) {
+                                       if (lastName[0] != '\0') {
+                                               strncpy(displayName, lastName, MAX_DISPLAY_NAME_LEN);
+                                               strncat(displayName, " ", MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                                       }
+
+                                       if (firstName[0] != '\0') {
+                                               strncat(displayName, firstName, MAX_DISPLAY_NAME_LEN-strlen(displayName));
+                                       }
+                               }
+                       }                       
+
+                       memset(pTmp->threadName, 0x00, sizeof(pTmp->threadName));
+                       strncpy(pTmp->threadName, displayName, MAX_THREAD_NAME_LEN);
+
+                       pTmp->unreadCnt = dbHandle.getColumnToInt(index++);
+                       pTmp->smsCnt = dbHandle.getColumnToInt(index++);
+                       pTmp->mmsCnt = dbHandle.getColumnToInt(index++);
+
+                       pTmp->threadType.mainType = dbHandle.getColumnToInt(index++);
+                       pTmp->threadType.subType = dbHandle.getColumnToInt(index++);
+
+                       pTmp->direction = dbHandle.getColumnToInt(index++);
+                       pTmp->threadTime = (time_t) dbHandle.getColumnToInt(index++);
+
+                       memset(pTmp->threadData, 0x00, sizeof(pTmp->threadData));
+                       dbHandle.getColumnToString(index++, MAX_THREAD_DATA_LEN, pTmp->threadData);
+               }
+
+       dbHandle.freeTable();
+*/
+       return MSG_SUCCESS;
+}
+
diff --git a/src/platform/Tizen/Messaging/messageDB/MessageStorageReader.h b/src/platform/Tizen/Messaging/messageDB/MessageStorageReader.h
new file mode 100755 (executable)
index 0000000..fe47af9
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// 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 MessageStorageReader_H_
+#define MessageStorageReader_H_
+
+#include "msg_types.h"
+#include "MsgSqliteWrapper.h"
+#include "msg_storage_types.h"
+
+#include <string>
+
+class MessageStorageReader {
+       private:
+               MsgDbHandler dbHandle;
+
+       public:
+               MessageStorageReader();
+               virtual ~MessageStorageReader();
+
+               msg_error_t MsgStoConnectDB();
+               msg_error_t MsgStoDisconnectDB();
+
+       public:
+               int queryMessage(const std::string& whereClause, const std::string& orderLimit, /*out*/msg_struct_list_s *pMsgFolderViewList);
+               int queryConversation(const std::string& whereClause, const std::string& orderLimit, /*out*/msg_struct_list_s *pThreadViewList  );
+};
+
+#endif /* MessageStorageReader_H_ */
diff --git a/src/platform/Tizen/Messaging/messageDB/MsgSqliteWrapper.cpp b/src/platform/Tizen/Messaging/messageDB/MsgSqliteWrapper.cpp
new file mode 100755 (executable)
index 0000000..7a6b004
--- /dev/null
@@ -0,0 +1,864 @@
+//
+// 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 <stdio.h> 
+#include <stddef.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <dpl/log/log.h>
+//#include "MsgDebug.h"
+#include "MsgSqliteWrapper.h"
+
+extern "C"
+{
+       #include <db-util.h>
+}
+
+/*==================================================================================================
+                                     VARIABLES
+==================================================================================================*/
+#if 1
+__thread sqlite3 *handle = NULL;
+__thread sqlite3_stmt *stmt = NULL;
+//__thread char **result = NULL;
+
+#endif
+
+/*==================================================================================================
+                                     IMPLEMENTATION OF MsgDbHandler - Member Functions
+==================================================================================================*/
+MsgDbHandler::MsgDbHandler()
+{
+       handle = NULL;
+       stmt = NULL;
+       result = NULL;
+}
+
+
+MsgDbHandler::~MsgDbHandler()
+{
+       if(handle != NULL)
+               disconnect();
+
+       if(stmt != NULL)
+               finalizeQuery();
+
+       if(result != NULL)
+               freeTable();            
+}
+
+
+msg_error_t MsgDbHandler::connect()
+{
+       int ret = 0;
+       
+       if (handle == NULL)
+       {
+               char strDBName[64];
+
+               memset(strDBName, 0x00, sizeof(strDBName));
+               snprintf(strDBName, 64, "%s", MSGFW_DB_NAME);
+       
+               ret = db_util_open(strDBName, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
+               
+               if (ret == SQLITE_OK)
+               {
+                       LogDebug("DB Connect Success : [" << handle << "]");
+                       return MSG_SUCCESS;
+               }
+               else
+               {
+                       LogDebug("DB Connect Fail [" << ret << "]");
+                       return MSG_ERR_DB_CONNECT;
+               }
+       }
+       else
+       {
+               LogDebug("DB Connect exist : [" << handle << "]");
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgDbHandler::disconnect()
+{
+       int ret = 0;
+       
+       if (handle != NULL)
+       {
+               ret = db_util_close(handle);
+
+               if (ret == SQLITE_OK)
+               {
+                       handle = NULL;
+                       LogDebug("DB Disconnect Success");
+                       return MSG_SUCCESS;
+               }
+               else
+               {
+                       LogDebug("DB Disconnect Fail [" << ret << "]");
+                       return MSG_ERR_DB_DISCONNECT;
+               }
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+bool MsgDbHandler::checkTableExist(const char *pTableName)
+{
+       char strQuery[256];
+       int nRowCnt = 0, nResult = 0;
+       
+       /* Formulate the Query */
+       memset(strQuery, 0x00, sizeof(strQuery));
+       snprintf(strQuery, sizeof(strQuery), "select count(name) from sqlite_master where name='%s'", pTableName);
+
+       if (getTable(strQuery, &nRowCnt) != MSG_SUCCESS)
+       {
+               freeTable();
+               return false;
+       }
+
+       nResult = getColumnToInt(1);
+       LogDebug("Result [" << nResult << "]");
+
+       freeTable();
+
+       if (nResult > 0)
+               return true;
+       else
+               return false;
+}
+
+
+msg_error_t MsgDbHandler::execQuery(const char *pQuery)
+{
+       int ret = 0;
+       
+       if (!pQuery)
+               return MSG_ERR_INVALID_PARAMETER;
+
+       if(connect() != MSG_SUCCESS)
+               return MSG_ERR_DB_DISCONNECT;
+       
+       ret = sqlite3_exec(handle, pQuery, 0, 0, NULL);
+
+       if (ret == SQLITE_OK)
+       {
+               LogDebug("Execute Query Success");
+               return MSG_SUCCESS;
+       }
+       else
+       {
+               LogDebug("Execute Query Fail [" << ret << "]");
+
+               return MSG_ERR_DB_EXEC;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgDbHandler::getTable(const char *pQuery, int *pRowCnt)
+{
+       int ret = 0;
+       
+       *pRowCnt = 0;
+
+       if(connect() != MSG_SUCCESS)
+               return MSG_ERR_DB_DISCONNECT;
+
+       freeTable();
+       ret = sqlite3_get_table(handle, pQuery, &result, pRowCnt, 0, NULL);
+       
+       if (ret == SQLITE_OK)
+       {
+               if (*pRowCnt == 0)    // when the no record return 'MSG_ERR_DB_NORECORD'
+               {
+                       LogDebug("No Query Result");
+                       return MSG_ERR_DB_NORECORD;
+               }
+
+               LogDebug("Get Table Success");
+               return MSG_SUCCESS;
+       }
+       else
+       {
+               LogDebug("Get Table Fail [" << ret << "]");
+               return MSG_ERR_DB_GETTABLE;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+void MsgDbHandler::freeTable()
+{
+       if (result)
+       {
+               sqlite3_free_table(result);
+               result = NULL;
+       }
+}
+
+
+msg_error_t MsgDbHandler::bindText(const char *pBindStr, int index)
+{
+       int ret = 0;
+
+       if (pBindStr != NULL)
+               ret = sqlite3_bind_text(stmt, index, pBindStr, (strlen(pBindStr) + sizeof(unsigned char)), SQLITE_STATIC);
+
+       return ret;
+}
+
+
+msg_error_t MsgDbHandler::bindBlob(const void * pBindBlob, int size, int index)
+{
+       int ret = 0;
+       
+       ret = sqlite3_bind_blob(stmt, index, pBindBlob, size, SQLITE_STATIC);
+
+       return ret;
+}
+
+
+msg_error_t MsgDbHandler::prepareQuery(const char *pQuery)
+{
+       int ret = 0;
+       
+       stmt = NULL;
+
+       if(connect() != MSG_SUCCESS)
+               return MSG_ERR_DB_DISCONNECT;
+
+
+       if ((ret = sqlite3_prepare_v2(handle, pQuery, strlen(pQuery), &stmt, NULL)) == SQLITE_OK)
+       {
+               LogDebug("Prepare Query Success");
+               return MSG_SUCCESS;
+       }
+       else
+       {
+               LogDebug("Prepare Query Fail [" << ret << "]");
+               return MSG_ERR_DB_PREPARE;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgDbHandler::stepQuery()
+{
+       int ret = 0;
+
+       ret = sqlite3_step(stmt);
+
+       if (ret == SQLITE_ROW)
+       {
+               LogDebug("MsgStepQuery() SQLITE_ROW");
+               return MSG_ERR_DB_ROW;
+       }
+       else if (ret == SQLITE_DONE)
+       {
+               LogDebug("MsgStepQuery() SQLITE_DONE");
+               return MSG_ERR_DB_DONE;
+       }
+       else
+       {
+               LogDebug("MsgStepQuery() Fail [" << ret << "]");
+               return MSG_ERR_DB_STEP;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+void MsgDbHandler::finalizeQuery()
+{
+       if(stmt != NULL)
+               sqlite3_finalize(stmt);
+       stmt = NULL;
+}
+
+
+int MsgDbHandler::columnInt(int ColumnIndex)
+{
+       return sqlite3_column_int(stmt, ColumnIndex);
+}
+
+
+const unsigned char* MsgDbHandler::columnText(int ColumnIndex)
+{
+       return sqlite3_column_text(stmt, ColumnIndex);
+}
+
+
+const void* MsgDbHandler::columnBlob(int ColumnIndex)
+{
+       return sqlite3_column_blob(stmt, ColumnIndex);
+}
+
+
+msg_error_t MsgDbHandler::beginTrans()
+{
+       int ret = 0;
+
+       if(connect() != MSG_SUCCESS)
+               return MSG_ERR_DB_DISCONNECT;
+
+
+       ret = sqlite3_exec(handle, "BEGIN deferred;", 0, 0, NULL);
+       
+       if (ret == SQLITE_OK)
+       {
+               LogDebug("Begin Transaction Success");
+               return MSG_SUCCESS;
+       }
+       else
+       {
+               LogDebug("Begin Transaction Fail [" << ret << "]");
+               return MSG_ERR_DB_EXEC;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgDbHandler::endTrans(bool Success)
+{
+       int ret = 0;
+
+       if(connect() != MSG_SUCCESS)
+               return MSG_ERR_DB_DISCONNECT;
+
+
+       if (Success == true)
+       {
+               ret = sqlite3_exec(handle, "END;", 0, 0, NULL);
+       }
+       else
+       {
+               ret = sqlite3_exec(handle, "rollback", 0, 0, NULL);
+               ret = sqlite3_exec(handle, "END;", 0, 0, NULL);
+       }
+
+       if (ret == SQLITE_OK)
+       {
+               LogDebug("End Transaction Success");
+               return MSG_SUCCESS;
+       }
+       else
+       {
+               LogDebug("End Transaction Fail [" << ret << "]");
+               return MSG_ERR_DB_EXEC;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+int MsgDbHandler::getColumnToInt(int RowIndex)
+{
+       char* pTemp = result[RowIndex];
+
+       int nTemp = 0;
+
+       if (pTemp == NULL)
+       {
+               LogDebug("NULL");
+               return nTemp;
+       }
+
+       nTemp = (int)strtol(pTemp, (char**)NULL, 10);
+       
+//     nTemp = atoi(pTemp);
+
+       return nTemp;
+}
+
+
+char MsgDbHandler::getColumnToChar(int RowIndex)
+{
+       char* pTemp = result[RowIndex];
+
+       if (pTemp == NULL)
+       {
+               LogDebug("NULL");
+               return '\0';
+       }
+
+       return *pTemp;
+}
+
+
+void MsgDbHandler::getColumnToString(int RowIndex, int Length, char *pString)
+{
+       char* pTemp = result[RowIndex];
+
+       if (pTemp == NULL)
+       {
+               LogDebug("NULL");
+               return;
+       }
+       
+       strncpy(pString, pTemp, Length);
+}
+
+
+msg_error_t MsgDbHandler::getRowId(const char *pTableName, unsigned int *pRowId)
+{
+       int ret = 0, nRowId = 0, nRowCnt = 0;
+       char strQuery[256];
+
+       if (pTableName == NULL || pRowId == NULL)
+               return MSG_ERR_INVALID_PARAMETER;
+
+       LogDebug("Table Name [" << pTableName << "]");
+
+       memset(strQuery, 0x00, sizeof(strQuery));
+       snprintf(strQuery, sizeof(strQuery), "select max(rowid) from %s", pTableName);
+
+       ret = getTable(strQuery, &nRowCnt);
+
+       if (ret == SQLITE_OK)
+       {
+               nRowId = getColumnToInt(1);
+               
+               if ((nRowCnt <= 1) && (nRowId == 0))
+                       *pRowId = 1;
+               else    
+                       *pRowId = nRowId + 1;
+       }
+       else
+       {
+               LogDebug("MsgGetRowId failed");
+               *pRowId = 0;
+               freeTable();
+               return MSG_ERR_DB_GETTABLE;             
+       }
+
+       freeTable();
+               
+       LogDebug("Row ID [" << *pRowId << "]");
+
+       return MSG_SUCCESS;
+}
+
+
+/*==================================================================================================
+                                     FUNCTION IMPLEMENTATION
+==================================================================================================*/
+#if 0
+msg_error_t MsgConnectDB()
+{
+       int ret = 0;
+       
+       char strDBName[64];
+
+       memset(strDBName, 0x00, sizeof(strDBName));
+       snprintf(strDBName, 64, "%s", MSGFW_DB_NAME);
+
+       if (gDBHandle == NULL)
+       {
+       
+#ifdef INCLUDE_SQLITE3 
+               ret = sqlite3_open(strDBName, &gDBHandle);
+#else
+               ret = db_util_open(strDBName, &gDBHandle, DB_UTIL_REGISTER_HOOK_METHOD);
+#endif
+               
+               if (ret == SQLITE_OK)
+               {
+                       LogDebug("DB Connect Success");
+                       return MSG_SUCCESS;
+               }
+               else
+               {
+                       LogDebug("DB Connect Fail [" << ret "]");
+                       return MSG_ERR_DB_CONNECT;
+               }
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgDisconnectDB()
+{
+       int ret = 0;
+       
+       if (gDBHandle != NULL)
+       {
+
+#ifdef INCLUDE_SQLITE3 
+               ret = sqlite3_close(gDBHandle);
+#else
+               ret = db_util_close(gDBHandle);
+#endif
+
+               if (ret == SQLITE_OK)
+               {
+                       gDBHandle = NULL;
+                       LogDebug("DB Disconnect Success");
+                       return MSG_SUCCESS;
+               }
+               else
+               {
+                       LogDebug("DB Disconnect Fail [" << ret << "]");
+                       return MSG_ERR_DB_DISCONNECT;
+               }
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+bool MsgIsTableExist(const char *pTableName)
+{
+       char strQuery[256];
+       int nRowCnt = 0, nResult = 0;
+       
+       /* Formulate the Query */
+       memset(strQuery, 0x00, sizeof(strQuery));
+       snprintf(strQuery, sizeof(strQuery), "select count(name) from sqlite_master where name='%s'", pTableName);
+
+       if (MsgGetTable(strQuery, &nRowCnt) != MSG_SUCCESS)
+       {
+               MsgFreeTable();
+               return false;
+       }
+
+       nResult = MsgGetColumnToInt(1);
+       LogDebug("Result [" << nResult << "]");
+
+       MsgFreeTable();
+
+       if (nResult > 0)
+               return true;
+       else
+               return false;
+}
+
+
+msg_error_t MsgExecQuery(const char *pQuery)
+{
+       int ret = 0;
+       
+       if (!pQuery)
+               return MSG_ERR_INVALID_PARAMETER;
+
+       ret = sqlite3_exec(gDBHandle, pQuery, 0, 0, NULL);
+
+       if (ret == SQLITE_OK)
+       {
+               LogDebug("Execute Query Success");
+               return MSG_SUCCESS;
+       }
+       else
+       {
+               LogDebug("Execute Query Fail [" << ret << "]");
+               return MSG_ERR_DB_EXEC;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgGetTable(const char *pQuery, int *pRowCnt)
+{
+       int ret = 0;
+       
+       *pRowCnt = 0;
+
+       ret = sqlite3_get_table(gDBHandle, pQuery, &gQueryResult, pRowCnt, 0, NULL);
+       
+       if (ret == SQLITE_OK)
+       {
+               if (*pRowCnt == 0)    // when the no record return 'MSG_ERR_DB_NORECORD'
+               {
+                       LogDebug("No Query Result");
+                       return MSG_ERR_DB_NORECORD;
+               }
+
+               LogDebug("Get Table Success");
+               return MSG_SUCCESS;
+       }
+       else
+       {
+               LogDebug("Get Table Fail [" << ret << "]");
+               return MSG_ERR_DB_GETTABLE;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+void MsgFreeTable()
+{
+       if (gQueryResult)
+       {
+               sqlite3_free_table(gQueryResult);
+               gQueryResult = NULL;
+       }
+}
+
+/* End of supporting two queries simultaneously*/
+
+msg_error_t MsgBindText(const char *pBindStr, int index)
+{
+       int ret = 0;
+
+       if (pBindStr != NULL)
+               ret = sqlite3_bind_text(gStmt, index, pBindStr, (strlen(pBindStr) + sizeof(unsigned char)), SQLITE_STATIC);
+
+       return ret;
+}
+
+
+msg_error_t MsgBindBlob(const void * pBindBlob, int size, int index)
+{
+       int ret = 0;
+       
+       ret = sqlite3_bind_blob(gStmt, index, pBindBlob, size, SQLITE_STATIC);
+
+       return ret;
+}
+
+
+msg_error_t MsgPrepareQuery(const char *pQuery)
+{
+       int ret = 0;
+       
+       gStmt = NULL;
+
+       if ((ret = sqlite3_prepare_v2(gDBHandle, pQuery, strlen(pQuery), &gStmt, NULL)) == SQLITE_OK)
+       {
+               LogDebug("Prepare Query Success");
+               return MSG_SUCCESS;
+       }
+       else
+       {
+               LogDebug("Prepare Query Fail [" << ret "]");
+               return MSG_ERR_DB_PREPARE;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgStepQuery()
+{
+       int ret = 0;
+
+       ret = sqlite3_step(gStmt);
+
+       if (ret == SQLITE_ROW)
+       {
+               LogDebug("MsgStepQuery() SQLITE_ROW");
+               return MSG_ERR_DB_ROW;
+       }
+       else if (ret == SQLITE_DONE)
+       {
+               LogDebug("MsgStepQuery() SQLITE_DONE");
+               return MSG_ERR_DB_DONE;
+       }
+       else
+       {
+               LogDebug("MsgStepQuery() Fail [" << ret << "]");
+               return MSG_ERR_DB_STEP;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+void MsgFinalizeQuery()
+{
+       sqlite3_finalize(gStmt);
+       gStmt = NULL;
+}
+
+
+int MsgColumnInt(int ColumnIndex)
+{
+       return sqlite3_column_int(gStmt, ColumnIndex);
+}
+
+
+const unsigned char* MsgColumnText(int ColumnIndex)
+{
+       return sqlite3_column_text(gStmt, ColumnIndex);
+}
+
+
+const void* MsgColumnBlob(int ColumnIndex)
+{
+       return sqlite3_column_blob(gStmt, ColumnIndex);
+}
+
+
+msg_error_t MsgBeginTrans()
+{
+       int ret = 0;
+
+       ret = sqlite3_exec(gDBHandle, "BEGIN deferred;", 0, 0, NULL);
+       
+       if (ret == SQLITE_OK)
+       {
+               LogDebug("Begin Transaction Success");
+               return MSG_SUCCESS;
+       }
+       else
+       {
+               LogDebug("Begin Transaction Fail [" << ret "]");
+               return MSG_ERR_DB_EXEC;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+msg_error_t MsgEndTrans(bool Success)
+{
+       int ret = 0;
+
+       if (Success == true)
+       {
+               ret = sqlite3_exec(gDBHandle, "END;", 0, 0, NULL);
+       }
+       else
+       {
+               ret = sqlite3_exec(gDBHandle, "rollback", 0, 0, NULL);
+               ret = sqlite3_exec(gDBHandle, "END;", 0, 0, NULL);
+       }
+
+       if (ret == SQLITE_OK)
+       {
+               LogDebug("End Transaction Success");
+               return MSG_SUCCESS;
+       }
+       else
+       {
+               LogDebug("End Transaction Fail [" << ret << "]");
+               return MSG_ERR_DB_EXEC;
+       }
+
+       return MSG_SUCCESS;
+}
+
+
+int MsgGetColumnToInt(int RowIndex)
+{
+       char* pTemp = gQueryResult[RowIndex];
+
+       int nTemp = 0;
+
+       if (pTemp == NULL)
+       {
+               LogDebug("NULL");
+               return nTemp;
+       }
+
+       nTemp = (int)strtol(pTemp, (char**)NULL, 10);
+       
+//     nTemp = atoi(pTemp);
+
+       return nTemp;
+}
+
+
+char MsgGetColumnToChar(int RowIndex)
+{
+       char* pTemp = gQueryResult[RowIndex];
+
+       if (pTemp == NULL)
+       {
+               LogDebug("NULL");
+               return NULL;
+       }
+
+       return *pTemp;
+}
+
+
+void MsgGetColumnToString(int RowIndex, int Length, char *pString)
+{
+       char* pTemp = gQueryResult[RowIndex];
+
+       if (pTemp == NULL)
+       {
+               LogDebug("NULL");
+               return;
+       }
+       
+       strncpy(pString, pTemp, Length);
+}
+
+
+msg_error_t MsgGetRowId(const char *pTableName, unsigned int *pRowId)
+{
+       int ret = 0, nRowId = 0, nRowCnt = 0;
+       char strQuery[256];
+
+       if (pTableName == NULL || pRowId == NULL)
+               return MSG_ERR_INVALID_PARAMETER;
+
+       LogDebug("Table Name [" << pTableName << "]");
+
+       memset(strQuery, 0x00, sizeof(strQuery));
+       snprintf(strQuery, sizeof(strQuery), "select max(rowid) from %s", pTableName);
+
+       ret = MsgGetTable(strQuery, &nRowCnt);
+
+       if (ret == SQLITE_OK)
+       {
+               nRowId = MsgGetColumnToInt(1);
+               
+               if ((nRowCnt <= 1) && (nRowId == 0))
+                       *pRowId = 1;
+               else    
+                       *pRowId = nRowId + 1;
+       }
+       else
+       {
+               LogDebug("MsgGetRowId failed");
+               *pRowId = 0;
+               MsgFreeTable();
+               return MSG_ERR_DB_GETTABLE;             
+       }
+
+       MsgFreeTable();
+               
+       LogDebug("Row ID [" << *pRowId << "]");
+
+       return MSG_SUCCESS;
+}
+#endif
+
+void MsgReleaseMemoryDB()
+{
+       int freeSize = 0;
+       
+       freeSize = sqlite3_release_memory(-1);
+
+       LogDebug("freed memory size (bytes) : [" << freeSize << "]");
+}
diff --git a/src/platform/Tizen/Messaging/messageDB/MsgSqliteWrapper.h b/src/platform/Tizen/Messaging/messageDB/MsgSqliteWrapper.h
new file mode 100755 (executable)
index 0000000..2865518
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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 MSG_SQLITE_WRAPPER_H
+#define MSG_SQLITE_WRAPPER_H
+
+/*==================================================================================================
+                                    INCLUDE FILES
+==================================================================================================*/
+#include "msg_types.h"
+
+
+/*==================================================================================================
+                                    DEFINES
+==================================================================================================*/
+#define MSGFW_DB_NAME                  "/opt/usr/dbspace/.msg_service.db"
+
+#define MSGFW_MESSAGE_TABLE_NAME               "MSG_MESSAGE_TABLE"
+#define MSGFW_FOLDER_TABLE_NAME                        "MSG_FOLDER_TABLE"
+#define MSGFW_ADDRESS_TABLE_NAME               "MSG_ADDRESS_TABLE"
+#define MSGFW_CONVERSATION_TABLE_NAME          "MSG_CONVERSATION_TABLE"
+#define MSGFW_SIM_MSG_TABLE_NAME               "MSG_SIM_TABLE"
+#define MSGFW_FILTER_TABLE_NAME                        "MSG_FILTER_TABLE"
+#define MSGFW_PUSH_MSG_TABLE_NAME              "MSG_PUSH_TABLE"
+#define MSGFW_CB_MSG_TABLE_NAME                        "MSG_CBMSG_TABLE"
+#define MMS_PLUGIN_MESSAGE_TABLE_NAME          "MSG_MMS_MESSAGE_TABLE"
+#define MSGFW_SYNCML_MSG_TABLE_NAME            "MSG_SYNCML_TABLE"
+#define MSGFW_SCHEDULED_MSG_TABLE_NAME         "MSG_SCHEDULED_TABLE"
+#define MSGFW_SMS_SENDOPT_TABLE_NAME           "MSG_SMS_SENDOPT_TABLE"
+
+#define MAX_QUERY_LEN                                  3072
+#define MAX_FOLDER_NAME_LEN                    20
+#define MAX_ACCOUNT_NAME_LEN                   51
+
+
+/*==================================================================================================
+                                     FUNCTION PROTOTYPES
+==================================================================================================*/
+void                                   MsgReleaseMemoryDB();
+
+
+/*==================================================================================================
+                                     CLASS DEFINITIONS
+==================================================================================================*/
+class MsgDbHandler
+{
+public:
+       MsgDbHandler();
+       ~MsgDbHandler();
+
+       msg_error_t connect();
+       msg_error_t disconnect();
+
+       bool checkTableExist(const char *pTableName);
+       msg_error_t execQuery(const char *pQuery);
+       msg_error_t getTable(const char *pQuery, int *pRowCnt);
+       void freeTable();
+       msg_error_t bindText(const char *pBindStr, int index);
+       msg_error_t bindBlob(const void * pBindBlob, int size, int index);
+       msg_error_t prepareQuery(const char *pQuery);
+       msg_error_t stepQuery();
+       void finalizeQuery();
+       int columnInt(int ColumnIndex);
+       const unsigned char* columnText(int ColumnIndex);
+       const void* columnBlob(int ColumnIndex);
+       msg_error_t beginTrans();
+       msg_error_t endTrans(bool Success);
+       int getColumnToInt(int RowIndex);
+       char getColumnToChar(int RowIndex);
+       void getColumnToString(int RowIndex, int Length, char *pString);
+       msg_error_t getRowId(const char *pTableName, unsigned int *pRowId);
+
+private:
+
+//     sqlite3 *handle;
+//     sqlite3_stmt *stmt;
+       char **result;
+
+};
+
+#endif // MSG_SQLITE_WRAPPER_H
+
diff --git a/src/platform/Tizen/NFC/NFCAdapter.cpp b/src/platform/Tizen/NFC/NFCAdapter.cpp
new file mode 100755 (executable)
index 0000000..ab59e68
--- /dev/null
@@ -0,0 +1,290 @@
+//
+// 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 <dpl/scoped_ptr.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <nfc.h>
+#include "NFCDefaultAdapter.h"
+#include "NFCAdapter.h"
+#include "NFCUtil.h"
+
+using namespace TizenApis::Api::NFC;
+using namespace DPL;
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+
+NFCAdapter::NFCAdapter() {
+       LogDebug("NFCAdapter");
+       if (!NFCDefaultAdapterSingleton::Instance().isSupported())
+               ThrowMsg(UnsupportedException, "Not Support");
+
+       m_NFCTagEmitterPtr.Reset();
+       m_NFCTargetEmitterPtr.Reset();
+       m_tagFilter.Reset();
+       m_EventNFCChangedSetPoweredPtr.Reset();
+       m_eventNFCSetCardEmulationPtr.Reset();
+       m_NFCChangedCardEmulations.Reset();
+}
+
+NFCAdapter::~NFCAdapter() {
+       LogDebug("Enter");
+       unsetTagListener();
+       unsetPeerListener();
+       m_EventNFCChangedSetPoweredPtr.Reset();
+       m_eventNFCSetCardEmulationPtr.Reset();
+       unsetCardEmulationChangeListener();
+}
+
+int NFCAdapter::setTagListener(const EventNFCChangedEmitterPtr& emitter, const TagFilterPtr& filter) {
+       LogDebug(" NFCAdapter::setTagListener Entered");
+       if (m_NFCTagEmitterPtr.Get() != NULL)
+               ThrowMsg(PlatformException, "It has already set Tag Listener");
+
+       m_NFCTagEmitterPtr = emitter;
+       m_tagFilter = filter;
+
+       return NFCDefaultAdapterSingleton::Instance().setTagListener(this);
+}
+
+int NFCAdapter::setPeerListener(const EventNFCChangedEmitterPtr& emitter) {
+       LogDebug(" NFCAdapter::setPeerListener Entered");
+
+       if (m_NFCTargetEmitterPtr.Get() != NULL)
+               ThrowMsg(PlatformException, "It has already set Peer Listener");
+
+       m_NFCTargetEmitterPtr = emitter;
+       return NFCDefaultAdapterSingleton::Instance().setPeerListener(this);
+}
+void NFCAdapter::unsetTagListener() {
+       LogDebug(" NFCAdapter::unsetTagListener Entered");
+       m_NFCTagEmitterPtr.Reset();
+       m_tagFilter.Reset();
+       NFCDefaultAdapterSingleton::Instance().unsetTagListener(this);
+}
+
+void NFCAdapter::unsetPeerListener() {
+       LogDebug(" NFCAdapter::unsetPeerListener Entered");
+       m_NFCTargetEmitterPtr.Reset();
+       NFCDefaultAdapterSingleton::Instance().unsetPeerListener(this);
+}
+
+void NFCAdapter::NFCTagHasDetected(void *props)
+{
+       if (m_NFCTagEmitterPtr.Get() != NULL) {
+               if ((props != NULL) && (m_tagFilter->getFilterSize() > 0)) {
+                       nfc_tag_type_e tagType;
+
+                       if (nfc_tag_get_type((nfc_tag_h)props, &tagType) == NFC_ERROR_NONE) {
+                               LogDebug("NFCAdapter::NFCTagHasDetected Tag real type : " << tagType);
+                               int cnt;
+                               for (cnt = 0; cnt < m_tagFilter->getFilterSize(); cnt++) {
+                                       NFCUtil util;
+                                       if (util.convertTonfcTagType(static_cast<unsigned short>(tagType)) == m_tagFilter->getFilterValue(cnt))
+                                               break;
+                               }
+                               if (cnt == m_tagFilter->getFilterSize()) {
+                                       LogDebug("Filter doesn't have this tag type ");
+                                       return;
+                               }
+                       } else {
+                               LogDebug("It can't get real nfc tag type");
+                               int cnt;
+                               for (cnt = 0; cnt < m_tagFilter->getFilterSize(); cnt++) {
+                                       if (NFC_TAGTYPE_GENERIC_PICC == m_tagFilter->getFilterValue(cnt))
+                                               break;
+                               }
+
+                               if (cnt == m_tagFilter->getFilterSize()) {
+                                       LogDebug("Filter doesn't have this tag type ");
+                                       return;
+                               }
+
+                       }
+               }
+               EventNFCChangedPtr event(new EventNFCChanged());
+               if (props == NULL)
+                       event->setNFCStatus(NFC_DETATCHED);
+               else
+                       event->setNFCStatus(NFC_ATTATCHED);
+
+               event->setNFCProperties(props);
+               event->setNFCType(NFC_TAG_TYPE);
+               LogDebug("emit event with nfc tag info");
+               m_NFCTagEmitterPtr->emit(event);
+       }
+}
+
+void NFCAdapter::NFCTargetHasDetected(void *props)
+{
+       if (m_NFCTargetEmitterPtr.Get() != NULL) {
+               EventNFCChangedPtr event(new EventNFCChanged());
+               if (props == NULL)
+                       event->setNFCStatus(NFC_DETATCHED);
+               else
+                       event->setNFCStatus(NFC_ATTATCHED);
+               event->setNFCProperties(props);
+               event->setNFCType(NFC_TARGET_TYPE);
+               LogDebug("emit event with nfc target info");
+               m_NFCTargetEmitterPtr->emit(event);
+       }
+}
+
+void *NFCAdapter::getCachedMessage() {
+       return NFCDefaultAdapterSingleton::Instance().getCachedMessage();
+}
+
+bool NFCAdapter::getPowerState() {
+       return NFCDefaultAdapterSingleton::Instance().getPowerState();
+}
+
+void NFCAdapter::setPowered(const EventNFCChangedSetPoweredPtr& event) {
+       LogDebug("Enter");
+       EventRequestReceiver<EventNFCChangedSetPowered>::PostRequest(event);
+}
+
+void NFCAdapter::OnRequestReceived(const EventNFCChangedSetPoweredPtr& event) {
+       if (getPowerState() == event->getState()) {
+               event->setResult(true);
+               return;
+       }
+       if (m_EventNFCChangedSetPoweredPtr.Get() !=NULL) {
+               event->setResult(false);
+               event->setError(Commons::JSTizenException::SERVICE_NOT_AVAILABLE);
+               event->setErrorMessage("Progressing Identical Operation");
+               return;
+       }
+
+       event->switchToManualAnswer();
+       m_EventNFCChangedSetPoweredPtr = event;
+       Try {
+               NFCDefaultAdapterSingleton::Instance().setPowered(event->getState(), this);
+               return;
+       } Catch(PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setError(Commons::JSTizenException::SERVICE_NOT_AVAILABLE);
+               event->setErrorMessage("Progressing Identical Operation");
+               EventRequestReceiver<EventNFCChangedSetPowered>::ManualAnswer(event);
+       } Catch(WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               setPoweredManualAnswer(NFC_ERROR_OPERATION_FAILED);
+       }
+}
+
+void NFCAdapter::setPoweredManualAnswer(int error) {
+       if (m_EventNFCChangedSetPoweredPtr.Get() != NULL) {
+               if (error == NFC_ERROR_NONE) {
+                       m_EventNFCChangedSetPoweredPtr->setResult(true);
+               } else {
+                       NFCUtil util;
+                       m_EventNFCChangedSetPoweredPtr->setResult(false);
+                       m_EventNFCChangedSetPoweredPtr->setError(util.getNFCErrorString(error));
+                       m_EventNFCChangedSetPoweredPtr->setErrorMessage(util.getNFCErrorMessage(error));
+               }
+               EventRequestReceiver<EventNFCChangedSetPowered>::ManualAnswer(m_EventNFCChangedSetPoweredPtr);
+               m_EventNFCChangedSetPoweredPtr.Reset();
+       }
+}
+
+EventNFCSEType NFCAdapter::getSEType() {
+       return NFCDefaultAdapterSingleton::Instance().getSEType();
+}
+
+void NFCAdapter::setCardEmulation(const EventNFCSetCardEmulationPtr& event) {
+       LogDebug("Enter");
+       EventRequestReceiver<EventNFCSetCardEmulation>::PostRequest(event);
+}
+
+void NFCAdapter::OnRequestReceived(const EventNFCSetCardEmulationPtr& event) {
+       if (getSEType() == event->getSEType()) {
+               event->setResult(true);
+               return;
+       }
+       if (m_eventNFCSetCardEmulationPtr.Get() !=NULL) {
+               event->setResult(false);
+               event->setError(Commons::JSTizenException::SERVICE_NOT_AVAILABLE);
+               event->setErrorMessage("Progressing Identical Operation");
+               return;
+       }
+
+       event->switchToManualAnswer();
+       m_eventNFCSetCardEmulationPtr = event;
+       Try {
+               NFCDefaultAdapterSingleton::Instance().setCardEmulation(event->getSEType(), this);
+               return;
+       } Catch(PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               event->setResult(false);
+               event->setError(Commons::JSTizenException::SERVICE_NOT_AVAILABLE);
+               event->setErrorMessage("Progressing Identical Operation");
+               EventRequestReceiver<EventNFCSetCardEmulation>::ManualAnswer(event);
+       } Catch(WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               setCardEmulationManualAnswer(NFC_ERROR_OPERATION_FAILED);
+       }
+}
+
+void NFCAdapter::setCardEmulationManualAnswer(int error) {
+       if (m_eventNFCSetCardEmulationPtr.Get() != NULL) {
+               if (error == NFC_ERROR_NONE) {
+                       m_eventNFCSetCardEmulationPtr->setResult(true);
+               } else {
+                       NFCUtil util;
+                       m_eventNFCSetCardEmulationPtr->setResult(false);
+                       if (error == NFC_ERROR_INVALID_PARAMETER) {
+                               m_eventNFCSetCardEmulationPtr->setError(Commons::JSTizenException::NOT_FOUND_ERROR);
+                               m_eventNFCSetCardEmulationPtr->setErrorMessage("Not Found Error");
+                       } else {
+                               m_eventNFCSetCardEmulationPtr->setError(util.getNFCErrorString(error));
+                               m_eventNFCSetCardEmulationPtr->setErrorMessage(util.getNFCErrorMessage(error));
+                       }
+               }
+               EventRequestReceiver<EventNFCSetCardEmulation>::ManualAnswer(m_eventNFCSetCardEmulationPtr);
+               m_eventNFCSetCardEmulationPtr.Reset();
+       }
+}
+
+void NFCAdapter::setCardEmulationChangeListener(const EventNFCChangedCardEmulationEmitterPtr& emitter) {
+       LogDebug("Entered");
+
+       if (m_NFCChangedCardEmulations.Get() != NULL)
+               ThrowMsg(PlatformException, "It has already set Card Emulation Change Listener");
+
+       m_NFCChangedCardEmulations = emitter;
+
+       NFCDefaultAdapterSingleton::Instance().setCardEmulationChangeListener(this);
+}
+
+void NFCAdapter::seChanged(EventNFCSEType seType) {
+       if (m_NFCChangedCardEmulations.Get() != NULL) {
+               EventNFCChangedCardEmulationPtr event(new EventNFCChangedCardEmulation());
+               event->setSEType(seType);
+               LogDebug("emit event with seChanged(type:" << seType << ")");
+               m_NFCChangedCardEmulations->emit(event);
+       }
+}
+void NFCAdapter::unsetCardEmulationChangeListener() {
+       m_NFCChangedCardEmulations.Reset();
+       NFCDefaultAdapterSingleton::Instance().unsetCardEmulationChangeListener(this);
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/NFC/NFCAdapter.h b/src/platform/Tizen/NFC/NFCAdapter.h
new file mode 100755 (executable)
index 0000000..039a5b7
--- /dev/null
@@ -0,0 +1,86 @@
+//
+// 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 _NFCADAPTER_H_
+#define _NFCADAPTER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/Emitters.h>
+
+#include <API/NFC/INFCAdapter.h>
+#include <API/NFC/NFCFactory.h>
+#include <API/NFC/EventNFCChanged.h>
+
+using namespace TizenApis::Api::NFC;
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+class NFCAdapter : public INFCAdapter
+{
+       friend class  NFCFactory;
+    public:
+               NFCAdapter();
+       virtual  ~NFCAdapter();
+
+public:
+     /**
+     * watchNFCTag
+     */
+       virtual int setTagListener(const EventNFCChangedEmitterPtr& emitter, const TagFilterPtr& filter);
+       virtual int setPeerListener(const EventNFCChangedEmitterPtr& emitter);
+       /**
+     * clearWatch
+     */
+       virtual void unsetTagListener();
+       virtual void unsetPeerListener();
+
+       void NFCTagHasDetected(void *props);
+       void NFCTargetHasDetected(void *props);
+
+       virtual void *getCachedMessage();
+
+       virtual bool getPowerState();
+       virtual void setPowered(const EventNFCChangedSetPoweredPtr& event);
+       void setPoweredManualAnswer(int error);
+
+       virtual EventNFCSEType getSEType();
+       virtual void setCardEmulation(const EventNFCSetCardEmulationPtr& event);
+       void setCardEmulationManualAnswer(int error);
+
+       virtual void setCardEmulationChangeListener(const EventNFCChangedCardEmulationEmitterPtr& event);
+       void seChanged(EventNFCSEType seType);
+       virtual void unsetCardEmulationChangeListener();
+private:
+       EventNFCChangedEmitterPtr m_NFCTagEmitterPtr;
+       EventNFCChangedEmitterPtr m_NFCTargetEmitterPtr;
+       EventNFCChangedSetPoweredPtr m_EventNFCChangedSetPoweredPtr;
+       EventNFCSetCardEmulationPtr m_eventNFCSetCardEmulationPtr;
+       EventNFCChangedCardEmulationEmitterPtr m_NFCChangedCardEmulations;
+       TagFilterPtr m_tagFilter;
+  protected:
+       virtual void OnRequestReceived(const EventNFCChangedSetPoweredPtr& event);
+       virtual void OnRequestReceived(const EventNFCSetCardEmulationPtr& event);
+};
+
+}
+}
+}
+
+#endif /* _NFCADAPTER_H_ */
diff --git a/src/platform/Tizen/NFC/NFCDefaultAdapter.cpp b/src/platform/Tizen/NFC/NFCDefaultAdapter.cpp
new file mode 100755 (executable)
index 0000000..11222fb
--- /dev/null
@@ -0,0 +1,477 @@
+//
+// 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 <dpl/scoped_ptr.h>
+#include <dpl/singleton_impl.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <nfc.h>
+#include "NFCDefaultAdapter.h"
+#include "NFCUtil.h"
+
+using namespace TizenApis::Api::NFC;
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Platform::NFC::NFCDefaultAdapter)
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+namespace
+{
+       static void TagDetectedCallback(nfc_discovered_type_e type, nfc_tag_h tag, void *data) {
+               LogDebug("Callback TagDetectedCallback.");
+
+               if (data) {
+                       if (NFC_DISCOVERED_TYPE_ATTACHED == type) {
+                               (static_cast<NFCDefaultAdapter*>(data))->NFCTagHasDetected((void *)tag);
+                       } else {
+                               (static_cast<NFCDefaultAdapter*>(data))->NFCTagHasDetected(NULL);
+                       }
+               } else {
+                       LogError("Callback private data is NULL.");
+               }
+
+       }
+
+       static void TargetDetectedCallback(nfc_discovered_type_e type, nfc_p2p_target_h target, void *data) {
+               LogDebug("Callback TargetDetectedCallback.");
+
+               if (data) {
+                       if (NFC_DISCOVERED_TYPE_ATTACHED == type) {
+                               (static_cast<NFCDefaultAdapter*>(data))->NFCTargetHasDetected((void *)target);
+                       } else {
+                               (static_cast<NFCDefaultAdapter*>(data))->NFCTargetHasDetected(NULL);
+                       }
+               } else {
+                       LogError("Callback private data is NULL.");
+               }
+
+       }
+       static void NFCInitializeCompletedCallback(nfc_error_e result, void *user_data) {
+               LogDebug("Callback NFCInitializeCompletedCallback. result : " << (int)result);
+               if (user_data && (result == NFC_ERROR_NONE))
+                       (static_cast<NFCDefaultAdapter*>(user_data))->getCurrentNFC();
+       }
+       static void NFCSetActivationCompletedCallback(nfc_error_e error, void *user_data) {
+               LogDebug("Callback NFCSetActivationCompletedCallback.");
+               NFCDefaultAdapterSingleton::Instance().setPoweredManualAnswer(error);
+       }
+       static void NFCSetCardEmulationCompletedCallback(nfc_error_e error, void *user_data) {
+               LogDebug("Callback NFCSetActivationCompletedCallback.");
+               NFCDefaultAdapterSingleton::Instance().setCardEmulationManualAnswer(error, user_data);
+       }
+       static void NFCSetSEEventCallback(nfc_se_event_e event, void *user_data) {
+               LogDebug("Callback NFCSetSEEventCallback.");
+               if (event == NFC_SE_EVENT_SE_TYPE_CHANGED)
+                       NFCDefaultAdapterSingleton::Instance().seChanged();
+       }
+}//private namespace
+
+NFCDefaultAdapter::NFCDefaultAdapter()
+       :m_initialized(false) {
+       LogDebug("Platform::NFC Enter");
+
+       m_NFCTagListeners.clear();
+       m_NFCTargetListeners.clear();
+       m_NFCChangedSETypes.clear();
+       m_poweredAdapter = NULL;
+       m_seType = NFC_SE_INVALID;
+}
+
+NFCDefaultAdapter::~NFCDefaultAdapter() {
+       LogDebug("Enter");
+       deinitialze();
+}
+
+bool NFCDefaultAdapter::isSupported() {
+       return nfc_manager_is_supported();
+}
+
+void NFCDefaultAdapter::deinitialze() {
+       LogDebug("Enter");
+       int result = -1;
+
+       m_NFCTagListeners.clear();
+       m_NFCTargetListeners.clear();
+       m_poweredAdapter = NULL;
+
+       nfc_manager_unset_tag_discovered_cb();
+       nfc_manager_unset_p2p_target_discovered_cb();
+
+       if(m_initialized == true)
+       {
+               result = nfc_manager_deinitialize ();
+               if (result !=NFC_ERROR_NONE) {
+                       LogInfo("failed to deinitialize nfc");
+               }
+       }
+       m_initialized = false;
+
+       LogDebug("destroy nfc");
+}
+
+int NFCDefaultAdapter::setTagListener(NFCAdapter * adapter) {
+       LogDebug(" NFCDefaultAdapter::setTagListener Entered");
+       int result = -1;
+
+       m_NFCTagListeners.push_back(adapter);
+
+       if (!m_initialized) {
+               if (initialize() != NFC_ERROR_NONE) {
+                       m_NFCTagListeners.clear();
+                       ThrowMsg(PlatformException, "Could not initialize NFC.");
+               }
+       } else {
+               nfc_tag_h currentTag;
+               if (nfc_manager_get_connected_tag(&currentTag) == NFC_ERROR_NONE)
+                       adapter->NFCTagHasDetected((void *)currentTag);
+       }
+
+       if (m_NFCTagListeners.size() > 1)
+               return 0;
+
+       result = nfc_manager_set_tag_discovered_cb (TagDetectedCallback, this);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE) {
+               m_NFCTagListeners.pop_back();
+               util.throwNFCException(result, "failed to set callback of nfc_manager_set_tag_discovered_cb");
+       }
+
+       LogInfo("NFCDefaultAdapter::setTagListener : result << " << result);
+       return result;
+}
+
+int NFCDefaultAdapter::setPeerListener(NFCAdapter *adapter) {
+       LogDebug(" NFCDefaultAdapter::setPeerListener Entered");
+       int result = -1;
+
+       m_NFCTargetListeners.push_back(adapter);
+
+       if (!m_initialized) {
+               if (initialize() != NFC_ERROR_NONE) {
+                       m_NFCTargetListeners.clear();
+                       ThrowMsg(PlatformException, "Could not initialize NFC.");
+               }
+       } else {
+               nfc_p2p_target_h currentTarget;
+               if (nfc_manager_get_connected_target(&currentTarget) == NFC_ERROR_NONE)
+                       adapter->NFCTargetHasDetected((void *)currentTarget);
+       }
+
+       if (m_NFCTargetListeners.size() > 1)
+               return 0;
+
+       result = nfc_manager_set_p2p_target_discovered_cb (TargetDetectedCallback, this);
+
+       NFCUtil Util;
+       if (result != NFC_ERROR_NONE) {
+               m_NFCTargetListeners.pop_back();
+               Util.throwNFCException(result, "failed to set callback of nfc_manager_set_p2p_target_discovered_cb");
+       }
+
+       LogInfo("NFCDefaultAdapter::setPeerListener : result << " << result);
+       return result;
+}
+
+void NFCDefaultAdapter::unsetTagListener(NFCAdapter * adapter) {
+       LogDebug(" NFCDefaultAdapter::unsetTagListener Entered");
+
+       if (!m_initialized) {
+               if (initialize() != NFC_ERROR_NONE) {
+                       ThrowMsg(PlatformException, "Could not initialize NFC.");
+               }
+       }
+
+       std::vector<NFCAdapter *>::iterator it;
+       for (it = m_NFCTagListeners.begin(); it != m_NFCTagListeners.end(); ++it) {
+               if (*it == adapter) {
+                       m_NFCTagListeners.erase(it);
+                       LogDebug("emitter is removed. (" << m_NFCTagListeners.size() << ")");
+                       break;
+               }
+       }
+
+       if (m_NFCTagListeners.empty())
+               nfc_manager_unset_tag_discovered_cb ();
+}
+
+void NFCDefaultAdapter::unsetPeerListener(NFCAdapter * adapter) {
+       LogDebug(" NFCDefaultAdapter::unsetPeerListener Entered");
+
+       if (!m_initialized) {
+               if (initialize() != NFC_ERROR_NONE) {
+                       ThrowMsg(PlatformException, "Could not initialize NFC.");
+               }
+       }
+
+       std::vector<NFCAdapter *>::iterator it;
+       for (it = m_NFCTargetListeners.begin(); it != m_NFCTargetListeners.end(); ++it) {
+               if (*it == adapter) {
+                       m_NFCTargetListeners.erase(it);
+                       LogDebug("emitter is removed. (" << m_NFCTargetListeners.size() << ")");
+                       break;
+               }
+       }
+
+       if (m_NFCTargetListeners.empty())
+               nfc_manager_unset_p2p_target_discovered_cb();
+
+}
+
+void NFCDefaultAdapter::NFCTagHasDetected(void *props)
+{
+       LogDebug("NFCDefaultAdapter::NFCTagHasDetected Enter type");
+
+       std::vector<NFCAdapter *>::iterator it;
+       for (it = m_NFCTagListeners.begin(); it != m_NFCTagListeners.end(); ++it) {
+               (*it)->NFCTagHasDetected(props);
+       }
+}
+
+void NFCDefaultAdapter::NFCTargetHasDetected(void *props)
+{
+       std::vector<NFCAdapter *>::iterator it;
+       for (it = m_NFCTargetListeners.begin(); it != m_NFCTargetListeners.end(); ++it) {
+               (*it)->NFCTargetHasDetected(props);
+       }
+}
+
+void NFCDefaultAdapter::getCurrentNFC() {
+       LogDebug("Enter");
+
+       if (!m_initialized) {
+               LogError("No Initialized");
+               return;
+       }
+
+       if (!m_NFCTagListeners.empty()) {
+               nfc_tag_h currentTag;
+               if (nfc_manager_get_connected_tag(&currentTag) == NFC_ERROR_NONE) {
+                       NFCTagHasDetected((void *)currentTag);
+                       return;
+               }
+       }
+
+       if (!m_NFCTargetListeners.empty()) {
+               nfc_p2p_target_h currentTarget;
+               if (nfc_manager_get_connected_target(&currentTarget) == NFC_ERROR_NONE) {
+                       NFCTargetHasDetected((void *)currentTarget);
+               }
+       }
+}
+
+int NFCDefaultAdapter::initialize() {
+       LogDebug("NFCDefaultAdapter::initialize Entered");
+       int result = -1;
+       //nfc_manager_deinitialize();
+       result = nfc_manager_initialize(NFCInitializeCompletedCallback, this);
+       if (result != NFC_ERROR_NONE) {
+               LogError("Could not initialize NFC.");
+               m_initialized = false;
+       } else {
+               m_initialized = true;
+               nfc_manager_set_tag_filter(NFC_TAG_FILTER_ALL_ENABLE);
+       }
+       return result;
+}
+
+void *NFCDefaultAdapter::getCachedMessage() {
+       LogDebug("Entered");
+       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);
+}
+
+bool NFCDefaultAdapter::getPowerState() {
+       return nfc_manager_is_activated();
+}
+
+void NFCDefaultAdapter::setPowered(const bool state, NFCAdapter * poweredAdapter) {
+       LogDebug("Enter");
+       try {
+               if (m_poweredAdapter != NULL) {
+                       ThrowMsg(PlatformException, "Progressing Identical Operation");
+                       return;
+               } else if (getPowerState() == state) {
+                       poweredAdapter->setPoweredManualAnswer(NFC_ERROR_NONE);
+                       return;
+               }
+
+               int result = NFC_ERROR_NONE;
+               if (!m_initialized)
+                       result = initialize();
+
+               if (result == NFC_ERROR_NONE) {
+                       m_poweredAdapter = poweredAdapter;
+                       result = nfc_manager_set_activation(state, NFCSetActivationCompletedCallback, NULL);
+               }
+
+               if (result != NFC_ERROR_NONE) {
+                       poweredAdapter->setPoweredManualAnswer(result);
+                       m_poweredAdapter = NULL;
+               }
+       } catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogError("Exception: " << ex.GetMessage());
+               poweredAdapter->setPoweredManualAnswer(NFC_ERROR_OPERATION_FAILED);
+               m_poweredAdapter = NULL;
+       }
+}
+
+void NFCDefaultAdapter::setPoweredManualAnswer(int error) {
+       if (m_poweredAdapter != NULL) {
+               m_poweredAdapter->setPoweredManualAnswer(error);
+               m_poweredAdapter = NULL;
+       }
+}
+
+EventNFCSEType NFCDefaultAdapter::getSEType() {
+       LogDebug("Enter");
+       nfc_se_type_e type = NFC_SE_TYPE_DISABLE;
+       if (nfc_manager_get_card_emulation_se_type(&type) == NFC_ERROR_NONE) {
+               NFCUtil util;
+               if (util.convertTonfcSEType(type) != NFC_SE_INVALID)
+                       return util.convertTonfcSEType(type);
+       }
+       ThrowMsg(PlatformException, "Wrong SE Type or operation to get SE Type is failed");
+}
+
+void NFCDefaultAdapter::setCardEmulation(const EventNFCSEType seType, NFCAdapter * adapter) {
+       LogDebug("Enter");
+       try {
+               if (getSEType() == seType) {
+                       adapter->setCardEmulationManualAnswer(NFC_ERROR_NONE);
+                       seChanged();
+                       return;
+               }
+
+               nfc_se_type_e nfcSeType = NFC_SE_TYPE_DISABLE;
+               if (seType == NFC_SE_NONE)
+                       nfcSeType = NFC_SE_TYPE_DISABLE;
+               else if (seType == NFC_SE_ESE)
+                       nfcSeType = NFC_SE_TYPE_ESE;
+               else if (seType == NFC_SE_UICC)
+                       nfcSeType = NFC_SE_TYPE_UICC;
+               else
+                       ThrowMsg(PlatformException, "Wrong SE TYPE");
+
+               int result = NFC_ERROR_NONE;
+               if (!m_initialized)
+                       result = initialize();
+
+               if (result == NFC_ERROR_NONE) {
+                       result = nfc_manager_set_card_emulation_se_type(nfcSeType, NFCSetCardEmulationCompletedCallback, (void *)adapter);
+               }
+
+               if (result != NFC_ERROR_NONE)
+                       adapter->setCardEmulationManualAnswer(result);
+       } catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogError("Exception: " << ex.GetMessage());
+               adapter->setCardEmulationManualAnswer(NFC_ERROR_OPERATION_FAILED);
+       }
+}
+
+void NFCDefaultAdapter::setCardEmulationManualAnswer(int error, void *adapter) {
+       if (adapter != NULL) {
+               ((NFCAdapter *)adapter)->setCardEmulationManualAnswer(error);
+               if (error == NFC_ERROR_NONE)
+                       seChanged();
+       }
+}
+
+void NFCDefaultAdapter::setCardEmulationChangeListener(NFCAdapter *adapter) {
+       LogDebug("Entered");
+       int result = -1;
+
+       m_NFCChangedSETypes.push_back(adapter);
+
+       if (!m_initialized) {
+               if (initialize() != NFC_ERROR_NONE) {
+                       m_NFCChangedSETypes.clear();
+                       ThrowMsg(PlatformException, "Could not initialize NFC.");
+               }
+       }
+       if (m_NFCChangedSETypes.size() > 1)
+               return;
+
+       m_seType = getSEType();
+       result = nfc_manager_set_se_event_cb(NFCSetSEEventCallback, this);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE) {
+               m_NFCTargetListeners.pop_back();
+               util.throwNFCException(result, "failed to set callback of nfc_manager_set_p2p_target_discovered_cb");
+       }
+
+       LogInfo("NFCDefaultAdapter::setPeerListener : result << " << result);
+}
+
+void NFCDefaultAdapter::unsetCardEmulationChangeListener(NFCAdapter * adapter) {
+       LogDebug("Entered");
+
+       if (!m_initialized) {
+               if (initialize() != NFC_ERROR_NONE) {
+                       ThrowMsg(PlatformException, "Could not initialize NFC.");
+               }
+       }
+
+       std::vector<NFCAdapter *>::iterator it;
+       for (it = m_NFCChangedSETypes.begin(); it != m_NFCChangedSETypes.end(); ++it) {
+               if (*it == adapter) {
+                       m_NFCChangedSETypes.erase(it);
+                       LogDebug("emitter is removed. (" << m_NFCChangedSETypes.size() << ")");
+                       break;
+               }
+       }
+
+       if (m_NFCChangedSETypes.empty()) {
+               nfc_manager_unset_se_event_cb();
+               m_seType = NFC_SE_INVALID;
+       }
+}
+
+void NFCDefaultAdapter::seChanged() {
+       if (m_seType != NFC_SE_INVALID) {
+               if (m_seType != getSEType()) {
+                       m_seType = getSEType();
+                       std::vector<NFCAdapter *>::iterator it;
+                       for (it = m_NFCChangedSETypes.begin(); it != m_NFCChangedSETypes.end(); ++it) {
+                               (*it)->seChanged(m_seType);
+                       }
+               }
+       }
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/NFC/NFCDefaultAdapter.h b/src/platform/Tizen/NFC/NFCDefaultAdapter.h
new file mode 100755 (executable)
index 0000000..8932928
--- /dev/null
@@ -0,0 +1,97 @@
+//
+// 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 _NFCDEFAULTADAPTER_H_
+#define _NFCDEFAULTADAPTER_H_
+
+#include <vector>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Commons/Emitters.h>
+
+#include <API/NFC/EventNFCChanged.h>
+#include "NFCAdapter.h"
+
+using namespace TizenApis::Api::NFC;
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+class NFCDefaultAdapter
+{
+    public:
+               NFCDefaultAdapter();
+       virtual  ~NFCDefaultAdapter();
+
+public:
+     /**
+     * watchNFCTag
+     */
+       int setTagListener(NFCAdapter* adapter);
+       int setPeerListener(NFCAdapter * adapter);
+       /**
+     * clearWatch
+     */
+       void unsetTagListener(NFCAdapter * adapter);
+       void unsetPeerListener(NFCAdapter * adapter);
+
+       void NFCTagHasDetected(void *props);
+       void NFCTargetHasDetected(void *props);
+
+       void *getCachedMessage();
+       void getCurrentNFC();
+
+       bool getPowerState();
+       void setPowered(const bool state, NFCAdapter * adapter);
+       void setPoweredManualAnswer(int error);
+
+       EventNFCSEType getSEType();
+       void setCardEmulation(const EventNFCSEType seType, NFCAdapter * adapter);
+       void setCardEmulationManualAnswer(int error, void *adapter);
+
+       void setCardEmulationChangeListener(NFCAdapter *adapter);
+       void seChanged();
+       void unsetCardEmulationChangeListener(NFCAdapter * adapter);
+
+       bool isSupported();
+       void deinitialze();
+private:
+       /**
+     * Initialize NFC.
+     */
+       int initialize();
+
+       std::vector<NFCAdapter *> m_NFCTagListeners;
+       std::vector<NFCAdapter *> m_NFCTargetListeners;
+       std::vector<NFCAdapter *> m_NFCChangedSETypes;
+        
+       NFCAdapter * m_poweredAdapter;
+       bool m_initialized;
+       EventNFCSEType m_seType;
+
+       friend class DPL::Singleton<NFCDefaultAdapter>;
+
+};
+typedef DPL::Singleton<NFCDefaultAdapter> NFCDefaultAdapterSingleton;
+
+}
+}
+}
+
+#endif /* _NFCDEFAULTADAPTER_H_ */
diff --git a/src/platform/Tizen/NFC/NFCTag.cpp b/src/platform/Tizen/NFC/NFCTag.cpp
new file mode 100755 (executable)
index 0000000..76bd5f8
--- /dev/null
@@ -0,0 +1,460 @@
+//
+// 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 <Commons/Exception.h>
+#include <Tizen/Common/JSTizenException.h>
+
+#include "NFCTag.h"
+#include "NFCUtil.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+
+using namespace Api::NFC;
+
+namespace
+{
+       /**
+       * Callback method called by platform as interval time.
+       * @param event_type Platform magnetic evet type
+       * @param event Platform sensor event data
+       * @param this_ User data pointer.
+       */
+       static bool TagInformationCallback(const char *key, const unsigned char *value, int value_size, void *user_data) {
+               LogDebug("Callback TagInformationCallback.");
+               if (user_data) {
+                       NFCUtil util;
+                       std::vector<unsigned char> tagInfo = util.toVector(value, value_size);
+                       (static_cast<NFCTag*>(user_data))->makeTagProperties(key, tagInfo);
+                       return TRUE;
+               }
+               LogDebug("Error! TagInformationCallback is Null.");
+               return false;
+       }
+
+       static void TagReadCallback(nfc_error_e result , nfc_ndef_message_h message , void * data) {
+               LogDebug("Callback TagReadCallback.");
+               if (data) {
+                       NFCTag *tagPtr = (NFCTag *)((EventNFCPtrs<EventTagActionRead> *)data)->getThisPtr();
+                       if (tagPtr) {
+                               EventTagActionReadPtr event = ((EventNFCPtrs<EventTagActionRead> *)data)->getEventPtrs();
+                               LogDebug("message handler :" << message);
+
+                               unsigned char *rawdata;
+                               int size;
+                               if (nfc_ndef_message_get_rawdata(message, &rawdata, &size) != NFC_ERROR_NONE) {
+                                       LogError("Can't get record's rawdata");
+                                       return;
+                               }
+
+                               NFCUtil util;
+                               std::vector<unsigned char> readData = util.toVector(rawdata, size);
+                               if (rawdata)
+                                       free(rawdata);
+                               tagPtr->readNdefManualAnswer((int)result, readData, event);
+                       }
+               
+               } else {
+                       LogDebug("Error! TagReadCallback is Null.");
+               }
+       }
+
+       static void TagWriteCallback(nfc_error_e result, void *data) {
+               LogDebug("Callback TagWriteCallback.");
+               if (data) {
+                       ((NFCTag *)data)->writeNdefManualAnswer((int)result);
+               } else {
+                       LogDebug("Error! TagWriteCallback is Null.");
+               }               
+       }
+
+       static void TagTransceiveCallback(nfc_error_e result, unsigned char *buffer, int buffer_size,  void *data) {
+               LogDebug("Callback TagTransceiveCallback.");
+               if (data) {
+                       NFCUtil util;
+                       std::vector<unsigned char> responseData = util.toVector(buffer, buffer_size)    ;
+                       ((NFCTag *)data)->transceiveManualAnswer((int)result, responseData);
+               } else {
+                       LogDebug("Error! TagTransceiveCallback is Null.");
+               }               
+       }
+
+       static void TagFormatCallback(nfc_error_e result, void *data) {
+               LogDebug("Callback TagFormatCallback.");
+               if (data) {
+                       ((NFCTag *)data)->formatManualAnswer((int)result);              
+               } else {
+                       LogDebug("Error! TagFormatCallback is Null.");
+               }               
+       }
+}//private namespace
+
+NFCTag::NFCTag(void *tagHandle)
+{
+       LogDebug("entered");
+
+       handle = (nfc_tag_h)tagHandle;
+
+       m_EventTagActionWritePtr.Reset();
+       m_EventTagActionTransceivePtr.Reset();
+       m_EventTagActionFormatPtr.Reset();
+}
+
+NFCTag::~NFCTag()
+{
+       LogDebug("entered");
+       handle = NULL;
+}
+
+bool NFCTag::isConnected() {
+       nfc_tag_h curHandle = NULL;
+       if (nfc_manager_get_connected_tag(&curHandle) == NFC_ERROR_NONE) {
+               if (curHandle == handle)
+                       return true;
+       }
+       return false;
+}
+
+nfcTagType NFCTag::getTagType() {
+       nfc_tag_type_e type = NFC_UNKNOWN_TARGET;
+       int result = nfc_tag_get_type(handle, &type);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get tag Type");
+
+       return util.convertTonfcTagType(type);
+}
+
+bool NFCTag::isNDEFSupport() {
+       bool isNDEF = FALSE;
+       int result = nfc_tag_is_support_ndef(handle, &isNDEF);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get if Ndef is supported");
+
+       return isNDEF;
+}
+long NFCTag::getNdefSize(){
+       unsigned int ndefSize;
+       int result = nfc_tag_get_ndef_size(handle, &ndefSize);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get Ndef size");
+
+       return static_cast<long>(ndefSize);
+}
+std::vector<NFCTagProperties> NFCTag::getProperties() {
+       LogDebug("Enter");
+       props.clear();
+       int result = nfc_tag_foreach_information(handle, TagInformationCallback, this);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get Ndef Properties");
+
+       return props;
+}
+
+void NFCTag::makeTagProperties(const char *key, std::vector<unsigned char> &value) {
+       NFCTagProperties newProp;
+       newProp.key = key;
+       newProp.value = value;
+       props.push_back(newProp);
+}
+
+void NFCTag::readNdef(const EventTagActionReadPtr& event) {
+       LogDebug("Enter");
+       if (!isNDEFSupport())
+               ThrowMsg(WrtDeviceApis::Commons::UnsupportedException, "Not Support NDEF");
+
+       EventRequestReceiver<EventTagActionRead>::PostRequest(event);
+}
+
+void NFCTag::writeNdef(const EventTagActionWritePtr& event) {
+       LogDebug("Enter");
+       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);
+
+                       return;
+               }
+       }
+       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Can't copy NdefMessage");
+}
+
+void NFCTag::transceive(const EventTagActionTransceivePtr& event) {
+       LogDebug("Enter");
+
+       if (m_EventTagActionTransceivePtr.Get() != NULL)
+               EventTagActionTransceives.push_back(event);
+       else
+               EventRequestReceiver<EventTagActionTransceive>::PostRequest(event);
+}
+
+void NFCTag::format(const EventTagActionFormatPtr& event) {
+       LogDebug("Enter");
+       EventRequestReceiver<EventTagActionFormat>::PostRequest(event);
+}
+
+void NFCTag::readNdefManualAnswer(int result, std::vector<unsigned char> &data, const EventTagActionReadPtr &event)
+{
+       LogDebug("Enter");
+       if ((nfc_error_e)result == NFC_ERROR_NONE) {
+               event->setResult(TRUE);
+               event->setReadNdefResult(data);
+       } else {
+               NFCUtil util;
+               event->setResult(FALSE);
+               event->setError(util.getNFCErrorString(result));
+               event->setErrorMessage(util.getNFCErrorMessage(result));
+       }
+       EventRequestReceiver<EventTagActionRead>::ManualAnswer(event);
+
+       std::vector<TagReadDataPtr>::iterator it;
+       for (it = EventTagActionsReads.begin(); it != EventTagActionsReads.end(); ++it) {
+               if ((*it)->getEventPtrs() == event) {
+                       EventTagActionsReads.erase(it);
+                       LogDebug("event is removed. (" << EventTagActionsReads.size() << ")");
+                       break;
+               }
+       }
+}
+
+void NFCTag::writeNdefManualAnswer(int result)
+{
+       LogDebug("Enter");
+       if (m_EventTagActionWritePtr.Get() != NULL) {
+               if (nfc_ndef_message_destroy(static_cast<nfc_ndef_message_h>(m_EventTagActionWritePtr->getNdefForWriting())) != NFC_ERROR_NONE)
+                       LogError("Can't destroy NdefMessage");
+
+               if ((nfc_error_e)result == NFC_ERROR_NONE) {
+                       m_EventTagActionWritePtr->setResult(TRUE);
+               } else {
+                       NFCUtil util;
+                       m_EventTagActionWritePtr->setResult(FALSE);
+                       m_EventTagActionWritePtr->setError(util.getNFCErrorString(result));
+                       m_EventTagActionWritePtr->setErrorMessage(util.getNFCErrorMessage(result));
+               }
+               EventRequestReceiver<EventTagActionWrite>::ManualAnswer(m_EventTagActionWritePtr);
+
+               m_EventTagActionWritePtr.Reset();
+               if (EventTagActionWrites.size() > 0) {
+                       EventTagActionWritePtr event = EventTagActionWrites.front();
+                       EventTagActionWrites.erase(EventTagActionWrites.begin());
+                       LogDebug("EventTagActionWrites is removed. (" << EventTagActionWrites.size() << ")");
+                       EventRequestReceiver<EventTagActionWrite>::PostRequest(event);
+               }
+       }
+}
+
+void NFCTag::transceiveManualAnswer(int result , std::vector<unsigned char> &data)
+{
+       LogDebug("Enter");
+       if (m_EventTagActionTransceivePtr.Get() != NULL) {
+               if ((nfc_error_e)result == NFC_ERROR_NONE) {
+                       m_EventTagActionTransceivePtr->setResult(TRUE);
+                       m_EventTagActionTransceivePtr->setTransceiveBuffer(data);
+               } else {
+                       NFCUtil util;
+                       m_EventTagActionTransceivePtr->setResult(FALSE);
+                       m_EventTagActionTransceivePtr->setError(util.getNFCErrorString(result));
+                       m_EventTagActionTransceivePtr->setErrorMessage(util.getNFCErrorMessage(result));
+               }
+               EventRequestReceiver<EventTagActionTransceive>::ManualAnswer(m_EventTagActionTransceivePtr);
+
+               m_EventTagActionTransceivePtr.Reset();
+               if (EventTagActionTransceives.size() > 0) {
+                       EventTagActionTransceivePtr event = EventTagActionTransceives.front();
+                       EventTagActionTransceives.erase(EventTagActionTransceives.begin());
+                       LogDebug("EventTagActionWrites is removed. (" << EventTagActionTransceives.size() << ")");
+                       EventRequestReceiver<EventTagActionTransceive>::PostRequest(event);
+               }
+       }
+}
+
+void NFCTag::formatManualAnswer(int result)
+{
+       LogDebug("Enter");
+       if (m_EventTagActionFormatPtr.Get() != NULL) {
+               if ((nfc_error_e)result == NFC_ERROR_NONE) {
+                       m_EventTagActionFormatPtr->setResult(TRUE);
+               } else {
+                       NFCUtil util;
+                       m_EventTagActionFormatPtr->setResult(FALSE);
+                       m_EventTagActionFormatPtr->setError(util.getNFCErrorString(result));
+                       m_EventTagActionFormatPtr->setErrorMessage(util.getNFCErrorMessage(result));
+               }
+               EventRequestReceiver<EventTagActionFormat>::ManualAnswer(m_EventTagActionFormatPtr);
+               m_EventTagActionFormatPtr.Reset();
+       }
+}
+
+void NFCTag::OnRequestReceived(const EventTagActionReadPtr& event) {
+       LogDebug("Enter");
+       
+       try {
+               event->switchToManualAnswer();
+
+               TagReadDataPtr data( new EventNFCPtrs<EventTagActionRead>(event, this));
+               EventTagActionsReads.push_back(data);
+               int result = nfc_tag_read_ndef(handle, TagReadCallback, data.Get());
+
+               NFCUtil util;
+               std::string error = util.getNFCErrorString(result);
+               if (error != "") {
+                       event->setResult(false);
+                       event->setError(error);
+                       event->setErrorMessage(util.getNFCErrorMessage(result));
+                       EventRequestReceiver<EventTagActionRead>::ManualAnswer(event);
+
+                       std::vector<TagReadDataPtr>::iterator it;
+                       for (it = EventTagActionsReads.begin(); it != EventTagActionsReads.end(); ++it) {
+                               if ((*it)->getEventPtrs() == event) {
+                                       EventTagActionsReads.erase(it);
+                                       LogDebug("event is removed. (" << EventTagActionsReads.size() << ")");
+                                       break;
+                               }
+                       }
+               }
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogError("Exception: " << ex.GetMessage());
+               event->setResult(false);
+       
+               EventRequestReceiver<EventTagActionRead>::ManualAnswer(event);
+       }
+       
+}
+
+void NFCTag::OnRequestReceived(const EventTagActionWritePtr& event) {
+       try {
+               event->switchToManualAnswer();
+
+               m_EventTagActionWritePtr = event;
+
+               int result = nfc_tag_write_ndef(handle, (nfc_ndef_message_h)event->getNdefForWriting(),TagWriteCallback, this);
+
+               NFCUtil util;
+               std::string error = util.getNFCErrorString(result);
+               if (error != "") {
+                       writeNdefManualAnswer(result);
+               }
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogError("Exception: " << ex.GetMessage());
+
+                if (event != m_EventTagActionWritePtr)
+                       m_EventTagActionWritePtr = event;
+               writeNdefManualAnswer(NFC_ERROR_OPERATION_FAILED);
+       }
+}
+
+void NFCTag::OnRequestReceived(const EventTagActionTransceivePtr& event) {
+       NFCUtil util;
+       try {
+               event->switchToManualAnswer();
+               
+               m_EventTagActionTransceivePtr = event;
+
+               unsigned char *buffer = util.toCharPtr(event->getTransceiveBuffer());
+               int result = nfc_tag_transceive(handle, buffer, event->getTransceiveBufferSize(), TagTransceiveCallback, this);
+
+               if (buffer)
+                       free(buffer);
+
+               std::string error = util.getNFCErrorString(result);
+               if (error != "") {
+                       std::vector<unsigned char> emptyData;
+                       transceiveManualAnswer(result, emptyData);
+               }
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogError("Exception: " << ex.GetMessage());
+
+               std::vector<unsigned char> emptyData;
+               transceiveManualAnswer(NFC_ERROR_OPERATION_FAILED, emptyData);
+       }
+       
+}
+
+void NFCTag::OnRequestReceived(const EventTagActionFormatPtr& event) {
+       
+       try {
+               event->switchToManualAnswer();
+
+               if (m_EventTagActionFormatPtr.Get() != NULL) {
+                       event->setResult(false);
+                       event->setError(Commons::JSTizenException::SERVICE_NOT_AVAILABLE);
+                       event->setErrorMessage("Progressing Identical Operation");
+                       EventRequestReceiver<EventTagActionFormat>::ManualAnswer(event);
+                       return;
+               }
+               m_EventTagActionFormatPtr = event;
+               
+               NFCUtil util;
+               LogDebug("key size :" <<  event->getKeySize());
+
+               unsigned char *key = util.toCharPtr(event->getKey());
+               int result = nfc_tag_format_ndef(handle, key, event->getKeySize(), TagFormatCallback, this);
+
+               if (key)
+                       free(key);
+
+               std::string error = util.getNFCErrorString(result);
+               if (error != "") {
+                       event->setResult(false);
+                       event->setError(error);
+                       event->setErrorMessage(util.getNFCErrorMessage(result));
+                       EventRequestReceiver<EventTagActionFormat>::ManualAnswer(event);
+                       m_EventTagActionFormatPtr.Reset();
+               }
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogError("Exception: " << ex.GetMessage());
+               event->setResult(false);
+               
+               EventRequestReceiver<EventTagActionFormat>::ManualAnswer(event);
+               m_EventTagActionFormatPtr.Reset();
+       }
+       
+}
+
+
+}
+}
+}
diff --git a/src/platform/Tizen/NFC/NFCTag.h b/src/platform/Tizen/NFC/NFCTag.h
new file mode 100755 (executable)
index 0000000..c89fc06
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// 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 _NFCTAG_H_
+#define _NFCTAG_H_
+
+#include <API/NFC/INFCTag.h>
+#include <nfc.h>
+
+using namespace TizenApis::Api::NFC;
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+typedef DPL::SharedPtr<EventNFCPtrs<EventTagActionRead>> TagReadDataPtr;
+
+class NFCTag : public INFCTag
+{
+       friend class  NFCFactory;
+    public:
+               NFCTag(void *tagHandle);
+       virtual  ~NFCTag();
+
+       virtual bool isConnected();
+       virtual nfcTagType getTagType();
+       virtual bool isNDEFSupport();
+       virtual long getNdefSize();
+       virtual std::vector<NFCTagProperties> getProperties();
+       virtual void readNdef(const EventTagActionReadPtr& event);
+       virtual void writeNdef(const EventTagActionWritePtr& event);
+       virtual void transceive(const EventTagActionTransceivePtr& event);
+       virtual void format(const EventTagActionFormatPtr& event);
+
+       void readNdefManualAnswer(int result , std::vector<unsigned char> &data, const EventTagActionReadPtr &event);
+       void writeNdefManualAnswer(int result );
+       void transceiveManualAnswer(int result , std::vector<unsigned char> &data);
+       void formatManualAnswer(int result);
+
+       void makeTagProperties(const char *key, std::vector<unsigned char> &value);
+    private:
+       EventTagActionWritePtr m_EventTagActionWritePtr;
+       EventTagActionTransceivePtr m_EventTagActionTransceivePtr;
+       EventTagActionFormatPtr m_EventTagActionFormatPtr;
+
+       std::vector<TagReadDataPtr> EventTagActionsReads;
+       std::vector<EventTagActionWritePtr> EventTagActionWrites;
+       std::vector<EventTagActionTransceivePtr> EventTagActionTransceives;
+
+    protected:
+       nfc_tag_h handle;
+       std::vector<NFCTagProperties> props;
+       virtual void OnRequestReceived(const EventTagActionReadPtr& event);
+       virtual void OnRequestReceived(const EventTagActionWritePtr& event);
+       virtual void OnRequestReceived(const EventTagActionTransceivePtr& event);
+       virtual void OnRequestReceived(const EventTagActionFormatPtr& event);
+};
+
+
+}
+}
+}
+
+#endif /* _NFCTAG_H_ */
diff --git a/src/platform/Tizen/NFC/NFCTarget.cpp b/src/platform/Tizen/NFC/NFCTarget.cpp
new file mode 100755 (executable)
index 0000000..87329c4
--- /dev/null
@@ -0,0 +1,212 @@
+//
+// 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 <Commons/Exception.h>
+
+#include "NFCTarget.h"
+#include "NFCUtil.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+
+using namespace Api::NFC;
+using namespace WrtDeviceApis;
+
+namespace
+{
+       /**
+       * Callback method called by platform as interval time.
+       * @param event_type Platform magnetic evet type
+       * @param event Platform sensor event data
+       * @param this_ User data pointer.
+       */
+       static void TargetReceivedCallback(nfc_p2p_target_h target, nfc_ndef_message_h message, void *user_data) {
+               LogDebug("Callback TargetReceivedCallback.");
+               if (user_data) {
+                       unsigned char *rawdata;
+                       int size;
+                       if (nfc_ndef_message_get_rawdata(message, &rawdata, &size) != NFC_ERROR_NONE) {
+                               LogError("Can't get rawdata of message");
+                               return;
+                       }
+
+                       NFCUtil util;
+                       std::vector<unsigned char> receiveData = util.toVector(rawdata, size);
+                       if (rawdata)
+                               free(rawdata);
+                       ((NFCTarget *)user_data)->receiveNdef(receiveData);
+               } else {
+                       LogDebug("Error! TargetReceivedCallback is Null.");
+               }
+       }
+
+       static void TargetSentCallback(nfc_error_e result, void *user_data) {
+               LogDebug("Callback TargetSentCallback.");
+               if (user_data) {
+                       ((NFCTarget *)user_data)->sendNDEFManualAnswer((unsigned int)result);
+
+               } else {
+                       LogDebug("Error! TargetSentCallback is Null.");
+               }
+       }
+}//private namespace
+
+NFCTarget::NFCTarget(void *targetHandle)
+{
+       LogDebug("entered");
+
+       if (targetHandle == NULL)
+               ThrowMsg(Commons::UnknownException, "Target Handler is Null Pointer.");
+
+       handle = (nfc_p2p_target_h)targetHandle;
+       LogDebug("handle:"<<targetHandle);
+       m_isSetReceiveListenter = false;
+       m_EventTargetActionSendPtr.Reset();
+}
+
+NFCTarget::~NFCTarget()
+{
+       LogDebug("entered");
+       handle = NULL;
+}
+
+bool NFCTarget::isConnected() {
+       nfc_p2p_target_h curHandle = NULL;
+       if (nfc_manager_get_connected_target(&curHandle) == NFC_ERROR_NONE) {
+               if (curHandle == handle)
+                       return true;
+       }
+       return false;
+}
+
+void NFCTarget::setReceiveNDEFListener(const EventTargetActionReceiveEmitterPtr& event) {
+       LogDebug("Enter");
+       if (m_isSetReceiveListenter == true)
+               ThrowMsg(Commons::AlreadyInUseException, "Already set Listener");
+
+       m_emitter = event;
+       m_isSetReceiveListenter = true;
+
+       int result = nfc_p2p_set_data_received_cb(handle, TargetReceivedCallback, this);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE) {
+               m_isSetReceiveListenter = false;
+               util.throwNFCException(result, "Can't set Receive Ndef Listener");
+       }
+}
+
+void NFCTarget::receiveNdef(std::vector<unsigned char>&messageData) {
+       LogDebug("Enter");
+       if ((m_isSetReceiveListenter == true) && (m_emitter.Get() != NULL)) {
+               EventTargetActionReceivePtr event(new EventTargetActionReceive());
+               event->setReadNdefResult(messageData);
+               m_emitter->emit(event);
+       }
+}
+
+void NFCTarget::unsetReceiveNDEFListener() {
+       LogDebug("Enter");
+       if (m_isSetReceiveListenter == true) {
+               nfc_p2p_unset_data_received_cb(handle);
+               LogDebug("Success to unset Listener");
+       } else {
+               LogDebug("No set Listener");
+       }
+       m_isSetReceiveListenter = false;
+}
+
+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;
+
+       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;
+               }
+       }
+       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Can't copy NdefMessage");
+}
+
+void NFCTarget::sendNDEFManualAnswer(unsigned int result) {
+       LogDebug("Enter");
+       if (m_EventTargetActionSendPtr.Get() != NULL) {
+               if (nfc_ndef_message_destroy(static_cast<nfc_ndef_message_h>(m_EventTargetActionSendPtr->getMessageForSending())) != NFC_ERROR_NONE)
+                       LogError("Can't destroy NdefMessage");
+
+               if ((nfc_error_e)result == NFC_ERROR_NONE) {
+                       m_EventTargetActionSendPtr->setResult(TRUE);
+               } else {
+                       NFCUtil util;
+                       m_EventTargetActionSendPtr->setResult(FALSE);
+                       m_EventTargetActionSendPtr->setError(util.getNFCErrorString(result));
+                       m_EventTargetActionSendPtr->setErrorMessage(util.getNFCErrorMessage(result));
+               }
+               EventRequestReceiver<EventTargetActionSend>::ManualAnswer(m_EventTargetActionSendPtr);
+
+               m_EventTargetActionSendPtr.Reset();
+
+               if (m_EventTargetActionSends.size() > 0) {
+                       EventTargetActionSendPtr event = m_EventTargetActionSends.front();
+                       m_EventTargetActionSends.erase(m_EventTargetActionSends.begin());
+                       LogDebug("m_EventTargetActionSends is removed. (" << m_EventTargetActionSends.size() << ")");
+                       EventRequestReceiver<EventTargetActionSend>::PostRequest(event);
+               }
+       }
+}
+
+void NFCTarget::OnRequestReceived(const EventTargetActionSendPtr& event) {
+       LogDebug("Enter");
+       try {
+               event->switchToManualAnswer();
+               m_EventTargetActionSendPtr = event;
+
+               nfc_ndef_message_h message = (nfc_ndef_message_h)event->getMessageForSending();
+               int result = nfc_p2p_send(handle, message, TargetSentCallback, this);
+
+               NFCUtil util;
+               std::string error = util.getNFCErrorString(result);
+               if (error != "") {
+                       sendNDEFManualAnswer(result);
+               }
+       } catch (const Commons::Exception& ex) {
+               LogError("Exception: " << ex.GetMessage());
+               if (event != m_EventTargetActionSendPtr)
+                       m_EventTargetActionSendPtr = event;
+               sendNDEFManualAnswer(NFC_ERROR_OPERATION_FAILED);
+       }
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/NFC/NFCTarget.h b/src/platform/Tizen/NFC/NFCTarget.h
new file mode 100755 (executable)
index 0000000..4fdf104
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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 _NFCTARGET_H_
+#define _NFCTARGET_H_
+
+#include <API/NFC/INFCTarget.h>
+#include <nfc.h>
+
+using namespace TizenApis::Api::NFC;
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+
+class NFCTarget : public INFCTarget
+{
+       friend class  NFCFactory;
+    public:
+               NFCTarget(void *tagHandle);
+       virtual  ~NFCTarget();
+
+       virtual bool isConnected();
+       virtual void setReceiveNDEFListener(const EventTargetActionReceiveEmitterPtr& event);
+       void receiveNdef(std::vector<unsigned char>&messageData);
+       virtual void unsetReceiveNDEFListener();
+       virtual void sendNDEF(const EventTargetActionSendPtr& event);
+       void sendNDEFManualAnswer(unsigned int result);
+    protected:
+       nfc_p2p_target_h handle;
+       EventTargetActionReceiveEmitterPtr m_emitter;
+       bool m_isSetReceiveListenter;
+       EventTargetActionSendPtr m_EventTargetActionSendPtr;
+       std::vector<EventTargetActionSendPtr> m_EventTargetActionSends;
+       virtual void OnRequestReceived(const EventTargetActionSendPtr& event);
+};
+
+
+}
+}
+}
+
+#endif /* _NFCTARGET_H_ */
diff --git a/src/platform/Tizen/NFC/NFCUtil.cpp b/src/platform/Tizen/NFC/NFCUtil.cpp
new file mode 100755 (executable)
index 0000000..816b2f6
--- /dev/null
@@ -0,0 +1,364 @@
+//
+// 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/Exception.h>
+#include <Tizen/Common/JSTizenException.h>
+
+#include "NFCUtil.h"
+#include <dpl/log/log.h>
+#include <nfc.h>
+
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+
+using namespace Api::NFC;
+
+std::vector<unsigned char> NFCUtil::toVector(const unsigned char *ch, const int size) {
+       std::vector<unsigned char> vec;
+       if (ch && (size > 0)) {
+               int i;
+               
+               for (i = 0; i < size; i++)
+                       vec.push_back(ch[i]);
+
+               LogDebug("result:" << byteToString(ch, size));
+       } else
+               LogDebug("result: NULL");
+       return vec;
+}
+
+unsigned char *NFCUtil::toCharPtr(std::vector<unsigned char> vec) {
+       if (vec.size() > 0) {
+               unsigned char * chr = (unsigned char *) malloc(vec.size() * sizeof(unsigned char));
+               for (int i = 0; i < static_cast<int>(vec.size()); i++)
+                       chr[i] = vec.at(i);
+
+               return chr;
+       }
+
+       return NULL;
+}
+
+char *NFCUtil::byteToString(std::vector<unsigned char> *buffer){
+       static char localbuffer[256];
+       memset(localbuffer, 0, 256);
+       if (buffer->size() > 0) {
+               unsigned char *charBuf = toCharPtr(*buffer);
+               if (charBuf) {
+                       if (buffer->size() > 255) {
+                               memcpy(localbuffer, charBuf, 255);
+                               LogDebug("size is " << buffer->size() << ". Too Big! It will copy some of data(255 bytes)");
+                       } else
+                               memcpy(localbuffer, charBuf, buffer->size());
+
+                       free(charBuf);
+               } else
+                       LogDebug("Size is 0");
+       } else
+               LogDebug("Size is 0");
+       return localbuffer;     
+}
+
+char *NFCUtil::byteToString(const unsigned char* buffer, const int size){
+       if (size > 255)
+               LogDebug("size is " << size << ". Too Big! It will copy some of data(255 bytes)");
+
+       static char localbuffer[256];
+       memset(localbuffer, 0, 256);
+       if (size > 0)
+               memcpy(localbuffer, buffer, size > 255 ? 255 : size);
+       else
+               LogDebug("Size is 0");
+       return localbuffer;     
+}
+
+nfcTagType NFCUtil::convertTonfcTagType(const unsigned short type) {
+       switch (static_cast<nfc_tag_type_e>(type)) {
+       case NFC_GENERIC_PICC:
+               return NFC_TAGTYPE_GENERIC_PICC;
+       case NFC_ISO14443_A_PICC:
+               return NFC_TAGTYPE_ISO14443_A_PICC;
+       case NFC_ISO14443_4A_PICC:
+               return NFC_TAGTYPE_ISO14443_4A_PICC;
+       case NFC_ISO14443_3A_PICC:
+               return NFC_TAGTYPE_ISO14443_3A_PICC;
+       case NFC_MIFARE_MINI_PICC:
+               return NFC_TAGTYPE_MIFARE_MINI_PICC;
+       case NFC_MIFARE_1K_PICC:
+               return NFC_TAGTYPE_MIFARE_1K_PICC;
+       case NFC_MIFARE_4K_PICC:
+               return NFC_TAGTYPE_MIFARE_4K_PICC;
+       case NFC_MIFARE_ULTRA_PICC:
+               return NFC_TAGTYPE_MIFARE_ULTRA_PICC;
+       case NFC_MIFARE_DESFIRE_PICC:
+               return NFC_TAGTYPE_MIFARE_DESFIRE_PICC;
+       case NFC_ISO14443_B_PICC:
+               return NFC_TAGTYPE_ISO14443_B_PICC;
+       case NFC_ISO14443_4B_PICC:
+               return NFC_TAGTYPE_ISO14443_4B_PICC;
+       case NFC_ISO14443_BPRIME_PICC:
+               return NFC_TAGTYPE_ISO14443_BPRIME_PICC;
+       case NFC_FELICA_PICC:
+               return NFC_TAGTYPE_FELICA_PICC;
+       case NFC_JEWEL_PICC:
+               return NFC_TAGTYPE_JEWEL_PICC;
+       case NFC_ISO15693_PICC:
+               return NFC_TAGTYPE_ISO15693_PICC;
+       case NFC_UNKNOWN_TARGET:
+       default :
+               return NFC_TAGTYPE_UNKNOWN_TARGET;
+       }
+}
+
+unsigned short NFCUtil::convertToTNF(nfcTNF tnf) {
+       switch (tnf) {
+               case NFC_TNF_WELL_KNOWN:
+                       return static_cast<unsigned short>(NFC_RECORD_TNF_WELL_KNOWN);
+               case NFC_TNF_MIME_MEDIA:
+                       return static_cast<unsigned short>(NFC_RECORD_TNF_MIME_MEDIA);
+               case NFC_TNF_URI:
+                       return static_cast<unsigned short>(NFC_RECORD_TNF_URI);
+               case NFC_TNF_EXTERNAL_RTD:
+                       return static_cast<unsigned short>(NFC_RECORD_TNF_EXTERNAL_RTD);
+               case NFC_TNF_UNKNOWN:
+                       return static_cast<unsigned short>(NFC_RECORD_TNF_UNKNOWN);
+               case NFC_TNF_UNCHANGED:
+                       return static_cast<unsigned short>(NFC_RECORD_TNF_UNCHAGNED);
+               case NFC_TNF_EMPTY:
+               default:
+                       return static_cast<unsigned short>(NFC_RECORD_TNF_EMPTY);
+       }
+}
+
+nfcTNF NFCUtil::convertTonfcTNF(unsigned short tnf) {
+       switch (static_cast<nfc_record_tnf_e>(tnf)) {
+               case NFC_RECORD_TNF_WELL_KNOWN:
+                       return NFC_TNF_WELL_KNOWN;
+               case NFC_RECORD_TNF_MIME_MEDIA:
+                       return NFC_TNF_MIME_MEDIA;
+               case NFC_RECORD_TNF_URI:
+                       return NFC_TNF_URI;
+               case NFC_RECORD_TNF_EXTERNAL_RTD:
+                       return NFC_TNF_EXTERNAL_RTD;
+               case NFC_RECORD_TNF_UNKNOWN:
+                       return NFC_TNF_UNKNOWN;
+               case NFC_RECORD_TNF_UNCHAGNED:
+                       return NFC_TNF_UNCHANGED;
+               case NFC_RECORD_TNF_EMPTY:
+               default:
+                       return NFC_TNF_EMPTY;
+       }
+}
+
+EventNFCSEType NFCUtil::convertTonfcSEType(unsigned short type) {
+       switch (static_cast<nfc_se_type_e>(type)) {
+               case NFC_SE_TYPE_DISABLE:
+                       return NFC_SE_NONE;
+               case NFC_SE_TYPE_ESE:
+                       return NFC_SE_ESE;
+               case NFC_SE_TYPE_UICC:
+                       return NFC_SE_UICC;
+               default:
+                       LogDebug("Wrong SE Type : " << type);
+                       return NFC_SE_INVALID;
+       }
+}
+
+NdefRecordData NFCUtil::getNDEFRecordData(void *handle) {
+       nfc_ndef_record_h recordHandle = static_cast<nfc_ndef_record_h>(handle);
+
+       NdefRecordData recordData;
+
+       nfc_record_tnf_e tnf;
+       unsigned char *typeName, *id, *payload;
+       int typeSize, idSize, payloadSize;
+
+       int result = nfc_ndef_record_get_tnf(recordHandle, &tnf);
+       throwNFCException(result, "Can't get record's tnf");
+
+       result = nfc_ndef_record_get_type(recordHandle, &typeName, &typeSize);
+       throwNFCException(result, "Can't get record's type");
+
+       result = nfc_ndef_record_get_id(recordHandle, &id, &idSize);
+       throwNFCException(result, "Can't get record's id");
+
+       result = nfc_ndef_record_get_payload(recordHandle, &payload, &payloadSize);
+       throwNFCException(result, "Can't get record's payload");
+
+       LogDebug("tnf : " <<tnf);
+       LogDebug("typeName : " << byteToString(typeName, typeSize));
+       LogDebug("payload : " << byteToString(payload, payloadSize));
+
+       recordData.properties.tnf = convertTonfcTNF(static_cast<unsigned short>(tnf));
+       recordData.properties.typeName = toVector(typeName, typeSize);
+       recordData.properties.id = toVector(id, idSize);
+       recordData.payload = toVector(payload, payloadSize);
+
+       return recordData;
+}
+
+bool NFCUtil::copyNDEFRecord(void **src, void **dest) {
+       nfc_ndef_record_h *srcHandle, *destHandle;
+       srcHandle = (nfc_ndef_record_h *)src;
+       destHandle = (nfc_ndef_record_h *)dest;
+
+       NdefRecordData recordData = getNDEFRecordData(*srcHandle);
+
+       unsigned char *typeName = toCharPtr(recordData.properties.typeName);
+       unsigned char *id = toCharPtr(recordData.properties.id);
+       unsigned char *payload = toCharPtr(recordData.payload);
+
+       if (nfc_ndef_record_create(destHandle, static_cast<nfc_record_tnf_e>(convertToTNF(recordData.properties.tnf)), typeName, recordData.properties.typeName.size(),
+               id, recordData.properties.id.size(), payload, recordData.payload.size()) != NFC_ERROR_NONE) {
+               if (typeName)
+                       free(typeName);
+               if (id)
+                       free(id);
+               if (payload)
+                       free(payload);
+
+               return false;
+       }
+
+       if (typeName)
+               free(typeName);
+       if (id)
+               free(id);
+       if (payload)
+               free(payload);
+
+       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) {
+               case NFC_ERROR_NONE:
+                       return "";
+               case NFC_ERROR_INVALID_PARAMETER:
+               case NFC_ERROR_INVALID_NDEF_MESSAGE:
+               case NFC_ERROR_INVALID_RECORD_TYPE:
+                       return Commons::JSTizenException::INVALID_VALUES_ERROR;
+               case NFC_ERROR_NO_DEVICE:
+               case NFC_ERROR_OUT_OF_MEMORY:
+               case NFC_ERROR_OPERATION_FAILED:
+               case NFC_ERROR_DEVICE_BUSY:
+                       return Commons::JSTizenException::UNKNOWN_ERROR;
+               case NFC_ERROR_NOT_ACTIVATED:
+                       return Commons::JSTizenException::SERVICE_NOT_AVAILABLE;
+               case NFC_ERROR_NOT_SUPPORTED:
+                       return Commons::JSTizenException::NOT_SUPPORTED_ERROR;
+               case NFC_ERROR_TIMED_OUT:
+                       return Commons::JSTizenException::TIMEOUT_ERROR;
+       }
+       return Commons::JSTizenException::UNKNOWN_ERROR;
+}
+
+std::string NFCUtil::getNFCErrorMessage(const int errorCode) {
+       LogDebug ("Errorcode : " << errorCode);
+       switch(errorCode) {
+               case NFC_ERROR_NONE:
+                       return "";
+               case NFC_ERROR_INVALID_PARAMETER:
+                       return "Invalid Parameter";
+               case NFC_ERROR_INVALID_NDEF_MESSAGE:
+                       return "Invalid NDEF Message";
+               case NFC_ERROR_INVALID_RECORD_TYPE:
+                       return "Invalid Record Type";
+               case NFC_ERROR_NO_DEVICE:
+                       return "No Device";
+               case NFC_ERROR_OUT_OF_MEMORY:
+                       return "Out Of Memory";
+               case NFC_ERROR_NOT_SUPPORTED:
+                       return "NFC Not Supported";
+               case NFC_ERROR_OPERATION_FAILED:
+                       return "Operation Failed";
+               case NFC_ERROR_DEVICE_BUSY:
+                       return "Device Busy";
+               case NFC_ERROR_NOT_ACTIVATED:
+                       return "NFC Not Activated";
+               case NFC_ERROR_TIMED_OUT:
+                       return "Time Out";
+               case NFC_ERROR_READ_ONLY_NDEF:
+                       return "Read Only NDEF";
+               case NFC_ERROR_NO_SPACE_ON_NDEF:
+                       return "No Space On NDEF";
+               case NFC_ERROR_NO_NDEF_MESSAGE:
+                       return "No NDEF Message";
+               case NFC_ERROR_NOT_NDEF_FORMAT:
+                       return "Not NDEF Format";
+       }
+       return "UnknownError";
+}
+
+void NFCUtil::throwNFCException(const int errorCode, const std::string &message) {
+       LogDebug ("Errorcode : " << static_cast<unsigned int>(errorCode));
+       LogDebug ("Message : " << message);
+
+       switch(errorCode) {
+               case NFC_ERROR_NONE:
+                       return;
+               case NFC_ERROR_INVALID_PARAMETER:
+               case NFC_ERROR_INVALID_NDEF_MESSAGE:
+               case NFC_ERROR_INVALID_RECORD_TYPE:
+                       ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, message);
+                       break;
+               case NFC_ERROR_NOT_ACTIVATED:
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, message);
+                       break;
+               case NFC_ERROR_NOT_SUPPORTED:
+               case NFC_ERROR_OPERATION_FAILED:
+               case NFC_ERROR_DEVICE_BUSY:
+               case NFC_ERROR_NO_DEVICE:
+               case NFC_ERROR_TIMED_OUT:
+               case NFC_ERROR_OUT_OF_MEMORY:
+               default:
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, message);
+                       break;
+       }
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/NFC/NFCUtil.h b/src/platform/Tizen/NFC/NFCUtil.h
new file mode 100755 (executable)
index 0000000..2902439
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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 _NFCUTIL_H_
+#define _NFCUTIL_H_
+
+#include <vector>
+#include <API/NFC/NdefRecordProperties.h>
+#include <API/NFC/EventNFCChanged.h>
+#include <API/NFC/INFCTag.h>
+
+using namespace TizenApis::Api::NFC;
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+
+class NFCUtil 
+{
+
+    public:
+               NFCUtil() {}
+       virtual  ~NFCUtil() {}
+       std::vector<unsigned char> toVector(const unsigned char *ch, const int size);
+       unsigned char *toCharPtr(std::vector<unsigned char> vec) ;
+       char *byteToString(const unsigned char* buffer, const int size);
+       char *byteToString(std::vector<unsigned char> *buffer);
+       nfcTagType convertTonfcTagType(const unsigned short type);
+       unsigned short convertToTNF(nfcTNF tnf);
+       nfcTNF convertTonfcTNF(unsigned short tnf);
+       EventNFCSEType convertTonfcSEType(unsigned short type);
+       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);
+};
+
+}
+}
+}
+
+#endif /* _NFCUTIL_H_ */
diff --git a/src/platform/Tizen/NFC/NdefMessage.cpp b/src/platform/Tizen/NFC/NdefMessage.cpp
new file mode 100755 (executable)
index 0000000..edeeadf
--- /dev/null
@@ -0,0 +1,231 @@
+//
+// 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 <Commons/Exception.h>
+
+#include "NdefMessage.h"
+#include "NFCUtil.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+
+using namespace Api::NFC;
+using namespace WrtDeviceApis::Commons;
+
+NdefMessage::NdefMessage()
+{
+       LogDebug("entered");
+       NFCUtil util;
+       int result = nfc_ndef_message_create(&handle);
+
+       if (result != NFC_ERROR_NONE) {
+               handle = NULL;
+               util.throwNFCException(result, "Can't create Ndef Message");
+       }
+}
+
+NdefMessage::NdefMessage(void *messageHandle)
+{
+       LogDebug("entered");
+
+       if (messageHandle == NULL) {
+               handle = NULL;
+               ThrowMsg(UnknownException, "Message Handler is Null Pointer.");
+       }
+
+       handle = static_cast<nfc_ndef_message_h>(messageHandle);
+}
+
+NdefMessage::NdefMessage(std::vector<void *> &ndefRcords)
+{
+       LogDebug("entered");
+
+       _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);
+}
+
+NdefMessage::~NdefMessage()
+{
+       LogDebug("entered");
+       if (handle != NULL)
+               nfc_ndef_message_destroy(handle);
+}
+
+void NdefMessage::_makeMessage(std::vector<void *> &ndefRcords) {
+       NFCUtil util;
+       int result = nfc_ndef_message_create(&handle);
+
+       if (result != NFC_ERROR_NONE) {
+               handle = NULL;
+               util.throwNFCException(result, "Can't create Ndef Message");
+       }
+
+       for (int i = 0 ; i < static_cast<int>(ndefRcords.size()); i++) {
+               nfc_ndef_record_h insertRecord;
+
+               if (!util.copyNDEFRecord(&ndefRcords[i], (void **)(&insertRecord))) {
+                       LogDebug("copyNDEFRecord fail!");
+                       ThrowMsg(UnknownException, "Can't copy Record");
+               }
+
+               result = nfc_ndef_message_append_record(handle, insertRecord);
+
+               if (result != NFC_ERROR_NONE) {
+                       LogError(i << " record can't be inserted. " << insertRecord << " : " << handle);
+                       util.throwNFCException(result, "Can't insert record in Ndef Message");
+               }
+       }
+}
+
+void *NdefMessage::getHandle() {
+       return (void *)handle;
+}
+
+void *NdefMessage::getRecordHandle(const long index) {
+       nfc_ndef_record_h recordHandle;
+       int result = nfc_ndef_message_get_record(handle, static_cast<int>(index), &recordHandle);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get Ndef Record");
+
+       return (void *)recordHandle;
+}
+
+long NdefMessage::getRecordCount() {
+       int count;
+       int result = nfc_ndef_message_get_record_count(handle, &count);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get Record Count");
+
+       LogDebug("record Count : " << count);
+       return static_cast<long>(count);
+}
+
+std::vector<unsigned char> NdefMessage::toByte() {
+       unsigned char *rawdata;
+       int size;
+       NFCUtil util;
+
+       if (getRecordCount() == 0)
+               return util.toVector(NULL, 0);
+
+       int result = nfc_ndef_message_get_rawdata(handle, &rawdata, &size);
+
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get serial bytes of NDEF message");
+
+       LogDebug(rawdata);
+       std::vector<unsigned char> byteData = util.toVector(rawdata, size);
+       if (rawdata)
+               free(rawdata);
+
+       return byteData;
+}
+
+NdefRecordData NdefMessage::getNDEFRecord(const long index) {
+       nfc_ndef_record_h recordHandle;
+       int result = nfc_ndef_message_get_record(handle, static_cast<int>(index), &recordHandle);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get Ndef Record");
+
+       NdefRecordData recordData;
+
+       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);
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/NFC/NdefMessage.h b/src/platform/Tizen/NFC/NdefMessage.h
new file mode 100755 (executable)
index 0000000..8417813
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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 _NDEFMESSAGE_H_
+#define _NDEFMESSAGE_H_
+
+#include <API/NFC/INdefMessage.h>
+#include <nfc.h>
+
+using namespace TizenApis::Api::NFC;
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+
+class NdefMessage : public INdefMessage
+{
+       friend class  NFCFactory;
+    public:
+               NdefMessage();
+               NdefMessage(void *messageHandle);
+               NdefMessage(std::vector<void *> &ndefRcords);
+               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);
+    private:
+       nfc_ndef_message_h handle;
+       void _makeMessage(std::vector<void *> &ndefRcords);
+};
+
+}
+}
+}
+
+#endif /* _NDEFMESSAGE_H_ */
diff --git a/src/platform/Tizen/NFC/NdefRecord.cpp b/src/platform/Tizen/NFC/NdefRecord.cpp
new file mode 100755 (executable)
index 0000000..ad4bd62
--- /dev/null
@@ -0,0 +1,381 @@
+//
+// 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 <Commons/Exception.h>
+
+#include "NdefRecord.h"
+#include "NFCUtil.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+
+using namespace Api::NFC;
+using namespace WrtDeviceApis::Commons;
+
+NdefRecord::NdefRecord()
+{
+       handle = NULL;
+}
+
+NdefRecord::NdefRecord(std::vector<unsigned char> data)
+{
+       LogDebug("entered");
+
+       nfc_ndef_message_h messageHandle;
+       NFCUtil util;
+       unsigned char *rawdata = util.toCharPtr(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);
+               rawdata = NULL;
+               util.throwNFCException(result, "Can't create Ndef Record");
+       }
+
+       int count;
+       result = nfc_ndef_message_get_record_count(messageHandle, &count);
+       if ((result != NFC_ERROR_NONE) || (count != 1)) {
+               nfc_ndef_message_destroy(messageHandle);
+               messageHandle = NULL;
+               if (rawdata)
+                       free(rawdata);
+               rawdata = NULL;
+               util.throwNFCException(result, "Can't create Ndef Record");
+       }
+
+       nfc_ndef_record_h recordHandle;
+       result = nfc_ndef_message_get_record(messageHandle, 0, &recordHandle);
+       if (result != NFC_ERROR_NONE) {
+               nfc_ndef_message_destroy(messageHandle);
+               messageHandle = NULL;
+               if (rawdata)
+                       free(rawdata);
+               rawdata = NULL;
+               util.throwNFCException(result, "Can't create Ndef Record");
+       }
+
+       if (!util.copyNDEFRecord((void **)&recordHandle, (void **)&handle)) {
+               nfc_ndef_message_destroy(messageHandle);
+               if (rawdata)
+                       free(rawdata);
+               ThrowMsg(UnknownException, "Can't copy Ndef Record");
+       }
+
+       nfc_ndef_message_destroy(messageHandle);
+       if (rawdata)
+               free(rawdata);
+}
+
+NdefRecord::NdefRecord(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload)
+{
+       LogDebug("entered");
+
+       NFCUtil util;
+
+       unsigned char * recordPayload = util.toCharPtr(payload);
+       unsigned char * typeName = util.toCharPtr(ndefRecordProperties.typeName);
+       unsigned char * id = util.toCharPtr(ndefRecordProperties.id);
+
+       LogDebug("typeName : " << util.byteToString(typeName, ndefRecordProperties.typeName.size()));
+       int result = nfc_ndef_record_create(&handle, static_cast<nfc_record_tnf_e>(util.convertToTNF(ndefRecordProperties.tnf)), typeName, ndefRecordProperties.typeName.size(),
+               id, ndefRecordProperties.id.size(), recordPayload, payload.size()) ;
+       if (recordPayload)
+               free(recordPayload);
+       if (typeName)
+               free(typeName);
+       if (id)
+               free(id);
+
+       if (result != NFC_ERROR_NONE) {
+               handle = NULL;
+               util.throwNFCException(result, "Can't create Ndef Record");
+       }
+}
+
+NdefRecord::NdefRecord(const std::string &text, const std::string &langCode, const short encodeType)
+{
+       LogDebug("entered");
+
+       int result = nfc_ndef_record_create_text(&handle, text.c_str(), langCode.c_str(), _convertToEncodeType(static_cast<nfcTextEncodeUTF>(encodeType)));
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE) {
+               handle = NULL;
+               util.throwNFCException(result, "Can't create Ndef Text Record");
+       }
+}
+
+NdefRecord::NdefRecord(const std::string &uri)
+{
+       LogDebug("entered");
+
+       int result = nfc_ndef_record_create_uri(&handle, uri.c_str());
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE) {
+               handle = NULL;
+               util.throwNFCException(result, "Can't create Ndef Uri Record");
+       }
+}
+
+NdefRecord::NdefRecord(const std::string &mimeType, const std::vector<unsigned char> data)
+{
+       LogDebug("entered");
+
+       NFCUtil util;
+
+       unsigned char *mimeData = util.toCharPtr(data);
+       int result = nfc_ndef_record_create_mime(&handle, mimeType.c_str(), mimeData, static_cast<int>(data.size()));
+
+       if (mimeData)
+               free(mimeData);
+
+       if (result != NFC_ERROR_NONE) {
+               handle = NULL;
+               util.throwNFCException(result, "Can't create Ndef Mime Record");
+       }
+}
+
+NdefRecord::~NdefRecord()
+{
+       LogDebug("entered");
+       if (handle != NULL)
+               nfc_ndef_record_destroy(handle);
+}
+
+nfc_encode_type_e NdefRecord::_convertToEncodeType(const nfcTextEncodeUTF type) {
+       switch(type) {
+               case NFC_TEXT_ENCODE_UTF_8:
+                       return NFC_ENCODE_UTF_8;
+               case NFC_TEXT_ENCODE_UTF_16:
+                       return NFC_ENCODE_UTF_16;
+       }
+}
+
+nfcTextEncodeUTF NdefRecord::_convertToNfcEncodeType(const nfc_encode_type_e type) {
+       switch(type) {
+               case NFC_ENCODE_UTF_8:
+                       return NFC_TEXT_ENCODE_UTF_8;
+               case NFC_ENCODE_UTF_16:
+                       return NFC_TEXT_ENCODE_UTF_16;
+       }
+}
+
+void *NdefRecord::getHandle() {
+       return (void *)handle;
+}
+
+NdefRecordProperties NdefRecord::getNDEFRecordProperties() {
+       LogDebug("entered");
+       NdefRecordProperties props;
+       NFCUtil util;
+
+       props.tnf = getTNF();
+       LogDebug("tnf : " << props.tnf);
+       props.typeName = getTypeName();
+       props.id = getID();
+       LogDebug("typeName : " << util.byteToString(&props.typeName));
+
+       return props;
+}
+
+nfcTNF NdefRecord::getTNF() {
+       nfc_record_tnf_e tnf;
+       int result = nfc_ndef_record_get_tnf(handle, &tnf);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get record's tnf");
+
+       return util.convertTonfcTNF(static_cast<unsigned short>(tnf));
+}
+
+std::vector<unsigned char> NdefRecord::getTypeName() {
+       unsigned char *typeName;
+       int typeSize;
+       int result = nfc_ndef_record_get_type(handle, &typeName, &typeSize);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get record's type");
+
+       return util.toVector(typeName, typeSize);
+}
+
+std::vector<unsigned char> NdefRecord::getID() {
+       unsigned char *id;
+       int idSize;
+       int result = nfc_ndef_record_get_id(handle, &id, &idSize);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get record's id");
+
+       return util.toVector(id, idSize);
+}
+
+bool NdefRecord::getText(char **text) {
+       LogDebug("entered");
+
+       int result = nfc_ndef_record_get_text(handle, text);
+       if (result == NFC_ERROR_INVALID_RECORD_TYPE)
+               return false;
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get text of record");
+
+       LogDebug("text : " << *text);
+       return true;
+}
+
+bool NdefRecord::getLangCode(char **langCode) {
+       LogDebug("entered");
+
+       int result = nfc_ndef_record_get_langcode(handle, langCode);
+       if (result == NFC_ERROR_INVALID_RECORD_TYPE)
+               return false;
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get langcode of record");
+
+       LogDebug("langCode : " << *langCode);
+       return true;
+}
+bool NdefRecord::getEncodeType(nfcTextEncodeUTF *encodeType) {
+       LogDebug("entered");
+
+       nfc_encode_type_e type;
+       int result = nfc_ndef_record_get_encode_type(handle, &type);
+       if (result == NFC_ERROR_INVALID_RECORD_TYPE)
+               return false;
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get encode type of record");
+
+       *encodeType = _convertToNfcEncodeType(type);
+       LogDebug("encodeType : " << *encodeType);
+       return true;
+}
+
+bool NdefRecord::getUri(char **uri) {
+       LogDebug("entered");
+       int result = nfc_ndef_record_get_uri(handle, uri);
+       if (result == NFC_ERROR_INVALID_RECORD_TYPE)
+               return false;
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get uri of record");
+
+       LogDebug("uri : " << *uri);
+       return true;
+}
+
+bool NdefRecord::getMimeType(char **mimeType) {
+       LogDebug("entered");
+       int result = nfc_ndef_record_get_mime_type(handle, mimeType);
+       if (result == NFC_ERROR_INVALID_RECORD_TYPE)
+               return false;
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get mime type of record");
+
+       LogDebug("mimeType : " << *mimeType);
+       return true;
+}
+std::vector<unsigned char> NdefRecord::getPayload() {
+       LogDebug("entered");
+       int size;
+       unsigned char *recordbuffer;
+       int result = nfc_ndef_record_get_payload(handle, &recordbuffer, &size);
+
+       NFCUtil util;
+       if (result != NFC_ERROR_NONE)
+               util.throwNFCException(result, "Can't get record's payload");
+
+       LogDebug("payload : " << util.byteToString(recordbuffer, size));
+       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;
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/NFC/NdefRecord.h b/src/platform/Tizen/NFC/NdefRecord.h
new file mode 100755 (executable)
index 0000000..2af7e66
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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 _NDEFRECORD_H_
+#define _NDEFRECORD_H_
+
+#include <vector>
+#include <API/NFC/INdefRecord.h>
+#include <nfc.h>
+
+using namespace TizenApis::Api::NFC;
+
+namespace TizenApis {
+namespace Platform {
+namespace NFC {
+
+class NdefRecord : public INdefRecord
+{
+       friend class  NFCFactory;
+    public:
+               NdefRecord();
+               NdefRecord(const NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+               NdefRecord(std::vector<unsigned char> data);
+               NdefRecord(const std::string &text, const std::string &langCode, const short encodeType);
+               NdefRecord(const std::string &uri);
+               NdefRecord(const std::string &mimeType, const std::vector<unsigned char> data);
+       virtual  ~NdefRecord();
+       virtual void *getHandle();
+       virtual NdefRecordProperties getNDEFRecordProperties();
+       virtual nfcTNF getTNF();
+       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);
+       virtual bool getUri(char **uri);
+       virtual bool getMimeType(char **mimeType);
+    private:
+       nfc_ndef_record_h handle;
+       nfc_encode_type_e _convertToEncodeType(const nfcTextEncodeUTF type);
+       nfcTextEncodeUTF _convertToNfcEncodeType(const nfc_encode_type_e type);
+};
+
+}
+}
+}
+
+#endif /* _NDEFRECORD_H_ */
diff --git a/src/platform/Tizen/NFC/config.cmake b/src/platform/Tizen/NFC/config.cmake
new file mode 100755 (executable)
index 0000000..9c9fad8
--- /dev/null
@@ -0,0 +1,24 @@
+get_current_path()
+
+pkg_search_module(capi-network-nfc REQUIRED capi-network-nfc)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_NFC
+  ${capi-network-nfc_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_NFC
+  ${capi-network-nfc_LIBRARIES}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_NFC
+  ${CURRENT_PATH}/NFCDefaultAdapter.cpp
+  ${CURRENT_PATH}/NFCAdapter.cpp
+  ${CURRENT_PATH}/NFCTag.cpp
+  ${CURRENT_PATH}/NdefMessage.cpp
+  ${CURRENT_PATH}/NdefRecord.cpp
+  ${CURRENT_PATH}/NFCTarget.cpp
+  ${CURRENT_PATH}/NFCUtil.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/NetworkBearerSelection/NetworkBearerSelection.cpp b/src/platform/Tizen/NetworkBearerSelection/NetworkBearerSelection.cpp
new file mode 100755 (executable)
index 0000000..7bcb144
--- /dev/null
@@ -0,0 +1,316 @@
+//
+// 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 <Commons/Exception.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/NetworkBearerSelection/OnNetworkBearerSelectionStateChanged.h>
+#include "NetworkBearerSelection.h"
+#include <netdb.h>
+#include <arpa/inet.h>
+
+using namespace TizenApis::Api::NetworkBearerSelection;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace DPL;
+
+namespace TizenApis {
+namespace Platform {
+namespace NetworkBearerSelection {
+    
+static void connection_state_changed_callback(connection_profile_state_e state, void* user_data)
+{
+    if(user_data != NULL) {
+        LogDebug("Callback registration Succeeded");
+        NewtorkBearerSelectionPendingEvent *pendingEvent = (NewtorkBearerSelectionPendingEvent *)user_data;
+        NetworkBearerSelection *networkBearerSelection = (NetworkBearerSelection *)pendingEvent->getThisObject();
+        EventNetworkBearerSelectionPtr event = pendingEvent->getEvent();
+
+        if (state == CONNECTION_PROFILE_STATE_DISCONNECTED) {
+            networkBearerSelection->makeCallback(event, CONNECTION_STATE_DISCONNECTED);
+        } else if (state == CONNECTION_PROFILE_STATE_CONNECTED) {
+            networkBearerSelection->makeCallback(event, CONNECTION_STATE_CONNECTED);
+        }
+    
+        delete pendingEvent;
+        pendingEvent = NULL;
+        user_data = NULL;
+    }
+}
+
+static void connection_opened_callback(connection_error_e result, void* user_data)
+{
+       if (result ==  CONNECTION_ERROR_NONE) {
+        LogDebug("Connection open Succeeded");
+        if(user_data != NULL) {
+            NewtorkBearerSelectionPendingEvent *pendingEvent = (NewtorkBearerSelectionPendingEvent *)user_data;
+            NetworkBearerSelection *networkBearerSelection = (NetworkBearerSelection *)pendingEvent->getThisObject();
+            EventNetworkBearerSelectionPtr event = pendingEvent->getEvent();
+
+            networkBearerSelection->registStateChangeListener(event);
+
+            delete pendingEvent;
+            pendingEvent = NULL;
+            user_data = NULL;
+        }
+    }
+}
+
+static void connection_closed_callback(connection_error_e result, void* user_data)
+{
+       if (result ==  CONNECTION_ERROR_NONE) {
+               LogDebug("Connection close Succeeded");
+        if (user_data != NULL) {
+            NewtorkBearerReleasePendingEvent *pendingEvent = (NewtorkBearerReleasePendingEvent *)user_data;
+            NetworkBearerSelection *networkBearerSelection = (NetworkBearerSelection *)pendingEvent->getThisObject();
+            EventNetworkBearerReleasePtr event = pendingEvent->getEvent();
+
+            networkBearerSelection->deregistStateChangeListener(event);
+
+            delete pendingEvent;
+            pendingEvent = NULL;
+            user_data = NULL;
+        }
+    }
+}
+
+static void connection_removed_callback(connection_error_e result, void* user_data)
+{
+    if (user_data != NULL) {
+        if (result ==  CONNECTION_ERROR_NONE) {
+            LogDebug("Connection close Succeeded");
+            NewtorkBearerSelectionPendingEvent *pendingEvent = (NewtorkBearerSelectionPendingEvent *)user_data;
+            NetworkBearerSelection *networkBearerSelection = (NetworkBearerSelection *)pendingEvent->getThisObject();
+            EventNetworkBearerSelectionPtr event = pendingEvent->getEvent();            
+
+            networkBearerSelection->removeStateChangeListener(event);
+
+            delete pendingEvent;
+            pendingEvent = NULL;
+        }
+
+        user_data = NULL;
+    }
+}
+
+NetworkBearerSelection::NetworkBearerSelection() : m_connectionHandle(NULL),
+                                                   m_profileHandle(NULL)
+{
+    int ret = connection_create(&m_connectionHandle);
+
+       if (CONNECTION_ERROR_NONE == ret) {
+               LogDebug("Client registration success");
+       } else {
+               LogDebug("Client registration failed");
+        m_connectionHandle = NULL;
+       }    
+}
+
+NetworkBearerSelection::~NetworkBearerSelection()
+{
+    if(m_connectionHandle != NULL) {
+        LogDebug("Client deregistration success");
+        connection_destroy(m_connectionHandle);
+    } else {
+        LogDebug("Client deregistration failed");
+    }
+}
+
+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");
+
+    if (checkProfileHandle() == false) {
+        reLaunchConnection(event);
+        return;
+    }
+
+    connection_profile_iterator_h profileIter;
+
+    int ret = connection_get_profile_iterator(m_connectionHandle, CONNECTION_ITERATOR_TYPE_REGISTERED, &profileIter);
+       if (ret != CONNECTION_ERROR_NONE) {
+        LogDebug("Fail to get profile iterator");
+        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");
+            return;
+       }
+    }
+
+    NewtorkBearerSelectionPendingEvent *pendingEvent = new NewtorkBearerSelectionPendingEvent((void *)this, event);
+
+    if (connection_open_profile(m_connectionHandle, m_profileHandle, connection_opened_callback, pendingEvent) != CONNECTION_ERROR_NONE) {
+        LogDebug("Connection open Failed");
+        delete pendingEvent;
+        pendingEvent = NULL;
+    }
+}
+
+void NetworkBearerSelection::OnRequestReceived(const EventNetworkBearerReleasePtr &event)
+{
+    LogDebug("enter");
+    if (event->getDomainName().compare(m_domainName) == 0) {
+        event->switchToManualAnswer();
+
+        if (connection_profile_unset_state_changed_cb(m_profileHandle) != CONNECTION_ERROR_NONE) {
+            LogDebug("unset callback is failed");
+            return;
+        }        
+        
+        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;
+            pendingEvent = NULL;
+            EventRequestReceiver<EventNetworkBearerRelease>::ManualAnswer(event);
+            return;
+        }
+    } else {
+        event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+}
+
+void NetworkBearerSelection::reLaunchConnection(const EventNetworkBearerSelectionPtr &event)
+{
+    LogDebug("enter");
+
+    if (connection_profile_unset_state_changed_cb(m_profileHandle) != CONNECTION_ERROR_NONE) {
+        LogDebug("unset callback is failed");        
+        return;
+    }
+
+    NewtorkBearerSelectionPendingEvent *pendingEvent = new NewtorkBearerSelectionPendingEvent((void *)this, event);
+
+    if (connection_close_profile(m_connectionHandle, m_profileHandle, connection_removed_callback, pendingEvent) != CONNECTION_ERROR_NONE) {
+        LogDebug("connection close failed");
+        delete pendingEvent;
+        pendingEvent = NULL;
+    }
+}
+
+void NetworkBearerSelection::removeStateChangeListener(const EventNetworkBearerSelectionPtr &event)
+{
+    LogDebug("enter");
+
+    m_profileHandle = NULL;
+    connection_profile_iterator_h profileIter;
+
+    int ret = connection_get_profile_iterator(m_connectionHandle, CONNECTION_ITERATOR_TYPE_REGISTERED, &profileIter);
+    if (ret != CONNECTION_ERROR_NONE) {
+        LogDebug("Fail to get profile iterator");
+        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");
+            return;
+        }
+    }
+
+    NewtorkBearerSelectionPendingEvent *pendingEvent = new NewtorkBearerSelectionPendingEvent((void *)this, event);
+
+    if (connection_open_profile(m_connectionHandle, m_profileHandle, connection_opened_callback, pendingEvent) != CONNECTION_ERROR_NONE) {
+        LogDebug("Connection open Failed");
+        delete pendingEvent;
+        pendingEvent = NULL;
+    }
+}
+
+void NetworkBearerSelection::registStateChangeListener(const EventNetworkBearerSelectionPtr &event)
+{
+    LogDebug("enter");
+    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!");
+    }
+       else {
+        LogDebug("Interface name : " << interfaceName);
+       }
+
+    host_entry = gethostbyname(event->getDomainName().c_str());
+
+    if(!host_entry) {
+        LogDebug("gethostbyname is failed");
+        makeCallback(event, CONNECTION_STATE_ERROR);
+        return;
+    }
+
+    hostAddr = inet_ntoa( *(struct in_addr*)host_entry->h_addr_list[0]);
+    LogDebug("hostAddr : " << hostAddr);
+
+    NewtorkBearerSelectionPendingEvent *pendingEvent = new NewtorkBearerSelectionPendingEvent((void *)this, event);
+    connection_profile_set_state_changed_cb(m_profileHandle, connection_state_changed_callback, pendingEvent);
+    connection_add_route(m_connectionHandle, interfaceName, hostAddr);
+}
+
+void NetworkBearerSelection::deregistStateChangeListener(const EventNetworkBearerReleasePtr &event)
+{
+    LogDebug("enter");
+    m_profileHandle = NULL;
+
+       EventRequestReceiver<EventNetworkBearerRelease>::ManualAnswer(event);         
+}
+
+void NetworkBearerSelection::makeCallback(const EventNetworkBearerSelectionPtr &event, connectionStateType state)
+{
+    LogDebug("enter");
+    OnNetworkBearerSelectionStateChangedEmitterPtr emitter = event->getEmitter();
+       OnNetworkBearerSelectionStateChangedPtr listener(new OnNetworkBearerSelectionStateChanged());    
+
+    m_domainName = event->getDomainName();    
+
+    listener->setConnectionStateType(state);
+
+    if (state == CONNECTION_STATE_ERROR) {
+        listener->setExceptionCode(ExceptionCodes::InvalidArgumentException);
+    }
+
+    emitter->emit(listener);
+}
+
+bool NetworkBearerSelection::checkProfileHandle()
+{
+    if(m_profileHandle == NULL) {
+        return true;
+    }
+    return false;
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/NetworkBearerSelection/NetworkBearerSelection.h b/src/platform/Tizen/NetworkBearerSelection/NetworkBearerSelection.h
new file mode 100755 (executable)
index 0000000..96490cc
--- /dev/null
@@ -0,0 +1,111 @@
+//
+// 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_PLATFORM_NETWORKBEARERSELECTION_H_
+#define WRTPLUGINS_PLATFORM_NETWORKBEARERSELECTION_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <API/NetworkBearerSelection/NetworkBearerSelectionFactory.h>
+#include <API/NetworkBearerSelection/INetworkBearerSelection.h>
+#include <API/NetworkBearerSelection/EventNetworkBearerSelection.h>
+#include <API/NetworkBearerSelection/EventNetworkBearerRelease.h>
+#include <API/NetworkBearerSelection/OnNetworkBearerSelectionStateChanged.h>
+#include <CommonsJavaScript/Converter.h>
+#include <net_connection.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace NetworkBearerSelection {
+
+class NetworkBearerSelection : public Api::NetworkBearerSelection::INetworkBearerSelection
+{
+    friend class TizenApis::Api::NetworkBearerSelection::NetworkBearerSelectionFactory;
+    friend class TizenApis::Api::NetworkBearerSelection::EventNetworkBearerSelection;
+    friend class TizenApis::Api::NetworkBearerSelection::EventNetworkBearerRelease;
+
+  public:
+    NetworkBearerSelection();    
+    virtual ~NetworkBearerSelection();
+    virtual void requestRouteToHost(const Api::NetworkBearerSelection::EventNetworkBearerSelectionPtr &event);
+    virtual void releaseRouteToHost(const Api::NetworkBearerSelection::EventNetworkBearerReleasePtr &event);
+    void reLaunchConnection(const Api::NetworkBearerSelection::EventNetworkBearerSelectionPtr &event);;
+    void removeStateChangeListener(const Api::NetworkBearerSelection::EventNetworkBearerSelectionPtr &event);
+    void registStateChangeListener(const Api::NetworkBearerSelection::EventNetworkBearerSelectionPtr &event);
+    void deregistStateChangeListener(const Api::NetworkBearerSelection::EventNetworkBearerReleasePtr &event);    
+    void makeCallback(const Api::NetworkBearerSelection::EventNetworkBearerSelectionPtr &event, const Api::NetworkBearerSelection::connectionStateType state);
+    bool checkProfileHandle();
+
+  protected:
+    virtual void OnRequestReceived(const Api::NetworkBearerSelection::EventNetworkBearerSelectionPtr &event);
+    virtual void OnRequestReceived(const Api::NetworkBearerSelection::EventNetworkBearerReleasePtr &event);    
+
+  private:
+    connection_h m_connectionHandle;
+    connection_profile_h m_profileHandle;
+    std::string m_domainName;
+};
+
+class NewtorkBearerSelectionPendingEvent
+{
+  public:
+    NewtorkBearerSelectionPendingEvent(void *thisObject, const Api::NetworkBearerSelection::EventNetworkBearerSelectionPtr &event) :
+        m_thisObject(thisObject),
+        m_event(event)
+    {
+    }
+
+    virtual ~NewtorkBearerSelectionPendingEvent()
+    {
+    }
+
+    void* getThisObject() const { return m_thisObject; }
+    Api::NetworkBearerSelection::EventNetworkBearerSelectionPtr getEvent() const { return m_event; }
+    
+  private:
+    void *m_thisObject;
+    Api::NetworkBearerSelection::EventNetworkBearerSelectionPtr m_event;
+};
+
+class NewtorkBearerReleasePendingEvent
+{
+  public:
+    NewtorkBearerReleasePendingEvent(void *thisObject, const Api::NetworkBearerSelection::EventNetworkBearerReleasePtr &event) :
+        m_thisObject(thisObject),
+        m_event(event)
+    {
+    }
+
+    virtual ~NewtorkBearerReleasePendingEvent()
+    {
+    }
+
+    void* getThisObject() const { return m_thisObject; }
+    Api::NetworkBearerSelection::EventNetworkBearerReleasePtr getEvent() const { return m_event; }
+    
+  private:
+    void *m_thisObject;
+    Api::NetworkBearerSelection::EventNetworkBearerReleasePtr m_event;
+};
+
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/Tizen/NetworkBearerSelection/config.cmake b/src/platform/Tizen/NetworkBearerSelection/config.cmake
new file mode 100755 (executable)
index 0000000..d7c9e29
--- /dev/null
@@ -0,0 +1,18 @@
+get_current_path()
+
+pkg_search_module(capi-network-connection REQUIRED capi-network-connection)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_NETWORKBEARERSELECTION
+  ${capi-network-connection_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_NETWORKBEARERSELECTION
+  ${capi-network-connection_LIBRARIES}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_NETWORKBEARERSELECTION
+  ${CURRENT_PATH}/NetworkBearerSelection.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/Notification/NotificationManager.cpp b/src/platform/Tizen/Notification/NotificationManager.cpp
new file mode 100644 (file)
index 0000000..90bbcce
--- /dev/null
@@ -0,0 +1,479 @@
+//
+// 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 <API/Notification/NotificationFactory.h>
+#include "NotificationManager.h"
+#include "StatusNotification.h"
+#include <notification.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Notification{
+
+#define DEFAULT_ICON_PATH "/opt/share/icons/default/"
+
+typedef struct noti_s *noti_h;
+
+struct noti_s {
+        notification_h raw_handle;
+        bool ongoing;
+        bool posted;
+        bool removed;
+        char *icon;
+        struct tm *time;
+        char *title;
+        char *content;
+        service_h service;
+        char *sound;
+        bool vibration;
+};
+
+
+NotificationManager::NotificationManager()
+{
+}
+
+NotificationManager::~NotificationManager() 
+{
+}
+
+namespace {
+
+static bool ui_notification_get_notification_cb(ui_notification_h notification, void *user_data)
+{
+       LogDebug("OK");
+       
+       if (user_data != NULL)
+       {
+               std::vector<ui_notification_h>* notifications = (std::vector<ui_notification_h>*)user_data;
+               ui_notification_h clone = NULL;
+
+               if (ui_notification_clone(&clone, notification) == UI_NOTIFICATION_ERROR_NONE)
+               {
+                       if (clone)
+                       {
+                               notifications->push_back(clone);                                
+                       }
+               }
+               else 
+               {
+                       if (clone)
+                       {
+                               free(clone);                            
+                       }
+               }
+       }
+       return true;
+}
+
+static bool ui_notification_find_notification_cb(ui_notification_h notification, void *user_data)
+{
+       NotificationManager::FindHandleType* handleType = (NotificationManager::FindHandleType*)user_data;
+       
+       ui_notification_h clone = NULL;
+       char *title = NULL;
+
+       std::string strTime;
+       std::stringstream strstream;
+       std::string key;
+       struct tm *value = NULL;
+       time_t unixtime;
+
+       
+       if (user_data != NULL) 
+       {
+               try {
+
+                       // temp solution for id
+                       if (ui_notification_get_time(notification, &value) != UI_NOTIFICATION_ERROR_NONE)
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::Exception, "get time error");
+                       }
+                       unixtime = mktime(value);
+                       strstream << unixtime;
+                       strstream >> strTime;
+
+
+                       if (ui_notification_get_title(notification, &title) != UI_NOTIFICATION_ERROR_NONE)
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::Exception, "get title error");
+                       }
+                       
+                       key = strTime + title;
+                       LogDebug(key << "...." << handleType->id);
+
+                       if (key != handleType->id)
+                       {
+                               if(value)
+                                       free(value);
+                               return true;
+                       }
+                               
+                       if (ui_notification_clone(&clone, notification) == UI_NOTIFICATION_ERROR_NONE)
+                       {
+                               if (clone)
+                               {
+                                       handleType->foundHandle = clone;
+                               }
+                       }
+                       else 
+                       {
+                               if (clone)
+                               {
+                                       free(clone);                            
+                               }
+                       }
+
+                       if (title)
+                               free(title);
+                       if (value)
+                               free(value);
+
+                       return false;
+               }
+               Catch (WrtDeviceApis::Commons::Exception) 
+               {
+                       LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+                       
+                       if (clone)
+                               free(clone);
+                       if (title)
+                               free(title);
+                       if (value)
+                               free(value);
+               }
+       }
+       else 
+       {
+               LogDebug("User data null");
+       }
+       return true;
+
+}
+
+}
+
+
+
+
+void NotificationManager::post(TizenApis::Api::Notification::INotificationPtr notification)
+{
+       ui_notification_h handle = (ui_notification_h)notification->getNotificationHandle();
+       
+       if (handle == NULL)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object is NULL");
+       }
+
+       time_t current = time(NULL);
+       struct tm *value = localtime(&current);
+       
+       if (ui_notification_set_time(handle, value)  != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification posted time error");
+       }
+
+       if (ui_notification_post(handle) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object post fail");
+       }
+       
+       updateProgress(notification);
+}
+
+void NotificationManager::update(TizenApis::Api::Notification::INotificationPtr notification)
+{
+       ui_notification_h handle = (ui_notification_h)notification->getNotificationHandle();
+
+       LogDebug("Start Update");
+       
+       if (handle == NULL)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object is NULL");
+       }
+       
+       
+        notification_h noti = ((noti_h)handle)->raw_handle;
+       
+       bool bUpdate = false;
+
+       if(noti)
+       {
+               char *tmp = NULL;
+               char *uiTmp = NULL;
+               //title
+               if (notification_get_text (noti, NOTIFICATION_TEXT_TYPE_TITLE, &tmp) == NOTIFICATION_ERROR_NONE)
+               {
+                       if ( ui_notification_get_title(handle, &uiTmp) == UI_NOTIFICATION_ERROR_NONE)
+                       {
+                               std::string title(tmp);
+                               if ( title.compare(uiTmp))
+                               {
+                                       bUpdate = true;
+                               }
+                               
+                       }
+               }
+       
+               if(uiTmp)
+               {
+                       free(uiTmp);
+                       uiTmp = NULL;
+               }
+               tmp = NULL;
+               //content
+               if (notification_get_text (noti, NOTIFICATION_TEXT_TYPE_CONTENT, &tmp) == NOTIFICATION_ERROR_NONE)
+               {
+                       if ( ui_notification_get_content(handle, &uiTmp) == UI_NOTIFICATION_ERROR_NONE)
+                       {
+                               if (tmp)
+                               {
+                                       std::string content(tmp);
+                                       if ( content.compare(uiTmp))
+                                       {
+                                               bUpdate = true;
+                                       }
+                               }
+                       }
+               }
+       
+               if(uiTmp)
+               {
+                       free(uiTmp);
+                       uiTmp = NULL;
+               }
+               tmp = NULL;
+               
+       }
+
+       if (notification->getStatusType() == StatusNotification::TYPE_PROGRESS)
+       {       
+               updateProgress(notification);
+               if (bUpdate)
+               {
+                       if (ui_notification_update(handle) != UI_NOTIFICATION_ERROR_NONE)
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object post fail");
+                       }
+               }
+       }
+       else
+       {
+               if (ui_notification_update(handle) != UI_NOTIFICATION_ERROR_NONE)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Notification Object post fail");
+               }
+       }
+
+}
+
+
+// need to make sure id uniqueness
+void NotificationManager::cancel(std::string id)
+{
+       FindHandleType findHandle = {0,};
+       findHandle.id = id;
+
+       LogDebug("OK");
+       
+       if (ui_notification_foreach_notification_posted(true, ui_notification_find_notification_cb, (void*)&findHandle) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get progress notification fail");
+       }
+
+       if (ui_notification_foreach_notification_posted(false, ui_notification_find_notification_cb, (void*)&findHandle) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get simple notification fail");
+       }
+
+       if (findHandle.foundHandle == NULL)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "can not found");
+       }
+       
+       if (ui_notification_cancel(findHandle.foundHandle) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "notification cancel fail");
+       }
+}
+
+
+void NotificationManager::cancelAll()
+{
+// no error??
+       ui_notification_cancel_all();
+}
+
+// need to make sure id uniqueness
+TizenApis::Api::Notification::INotificationPtr NotificationManager::get(std::string id)
+{
+       FindHandleType findHandle = {0,};
+       findHandle.id = id;
+       bool ongoing = false;
+       std::string statsType = StatusNotification::TYPE_SIMPLE;
+                       
+       if (ui_notification_foreach_notification_posted(true, ui_notification_find_notification_cb, (void*)&findHandle) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get progress notification fail");
+       }
+
+       if (ui_notification_foreach_notification_posted(false, ui_notification_find_notification_cb, (void*)&findHandle) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get simple notification fail");
+       }
+
+       if (findHandle.foundHandle == NULL)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "can not found");
+       }
+
+       if (ui_notification_is_ongoing(findHandle.foundHandle , &ongoing) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification type error");
+       }
+       
+       if (ongoing)
+       {
+               TizenApis::Api::Notification::INotificationPtr
+                       notificationProgress(TizenApis::Api::Notification::NotificationFactory::getInstance().getNotification(true));
+               notificationProgress->setNotificationHandle((void*)findHandle.foundHandle);
+
+               LogDebug(notificationProgress->getContent() );
+               
+               if (notificationProgress->getContent() == StatusNotification::TYPE_PROGRESS)
+               {
+                       statsType = StatusNotification::TYPE_PROGRESS;
+                       notificationProgress->setStatusType(statsType);
+               }
+               else 
+               {
+                       statsType = StatusNotification::TYPE_ONGOING;
+                       notificationProgress->setStatusType(statsType);
+               }
+               
+               return notificationProgress;
+       }
+       else
+       {
+               TizenApis::Api::Notification::INotificationPtr 
+                       notificationSimple(TizenApis::Api::Notification::NotificationFactory::getInstance().getNotification());
+               notificationSimple->setNotificationHandle((void*)findHandle.foundHandle);
+               notificationSimple->setStatusType(statsType);
+
+               return notificationSimple;
+       }
+}
+
+std::vector<TizenApis::Api::Notification::INotificationPtr> NotificationManager::getAll()
+{
+       int index = 0;
+       bool ongoing = false;
+       std::string statsType = StatusNotification::TYPE_SIMPLE;
+
+       LogDebug("OK");
+       
+       std::vector<ui_notification_h> postedNotification;
+
+       if (ui_notification_foreach_notification_posted(true, ui_notification_get_notification_cb, (void*)&postedNotification) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get progress notification fail");
+       }
+
+       if (ui_notification_foreach_notification_posted(false, ui_notification_get_notification_cb, (void*)&postedNotification) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get simple notification fail");
+       }
+
+       std::vector<TizenApis::Api::Notification::INotificationPtr> data;
+
+       for (index = 0; index < postedNotification.size(); index++)
+       {
+               TizenApis::Api::Notification::INotificationPtr ptr;
+
+               if (ui_notification_is_ongoing(postedNotification[index], &ongoing) != UI_NOTIFICATION_ERROR_NONE)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification type error");
+               }
+
+               if (ongoing)
+               {
+                       TizenApis::Api::Notification::INotificationPtr
+                               notificationProgress(TizenApis::Api::Notification::NotificationFactory::getInstance().getNotification(true));
+                       notificationProgress->setNotificationHandle((void*)postedNotification[index]);
+
+                       if (notificationProgress->getContent() == StatusNotification::TYPE_PROGRESS)
+                       {
+                               statsType = StatusNotification::TYPE_PROGRESS;
+                               notificationProgress->setStatusType(statsType);
+                       }
+                       else 
+                       {
+                               statsType = StatusNotification::TYPE_ONGOING;
+                               notificationProgress->setStatusType(statsType);
+                       }
+
+                       ptr = notificationProgress;
+               }
+               else
+               {
+                       TizenApis::Api::Notification::INotificationPtr 
+                               notificationSimple(TizenApis::Api::Notification::NotificationFactory::getInstance().getNotification());
+                       notificationSimple->setNotificationHandle((void*)postedNotification[index]);
+
+                       statsType = StatusNotification::TYPE_SIMPLE;
+                       notificationSimple->setStatusType(statsType);
+                       ptr = notificationSimple;
+               }
+               
+               data.push_back(ptr);
+       }
+
+       return data;
+}
+
+void NotificationManager::updateProgress(TizenApis::Api::Notification::INotificationPtr notification) 
+{
+       if (notification->getStatusType() != StatusNotification::TYPE_PROGRESS)
+       {
+               LogDebug("Type is not progress");
+               return;
+       }
+
+       double value = notification->getProgressValue();
+
+       if (value < 0.0)
+       {
+               LogDebug("Error" << value);
+               return;
+       }
+
+       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");
+       }
+}
+
+}
+}
+}
+
diff --git a/src/platform/Tizen/Notification/NotificationManager.h b/src/platform/Tizen/Notification/NotificationManager.h
new file mode 100644 (file)
index 0000000..823ee50
--- /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 TIZENAPIS_PLATFORM_NOTIFICATION_MANAGER_H_
+#define TIZENAPIS_PLATFORM_NOTIFICATION_MANAGER_H_
+
+#include <API/Notification/NotificationFactory.h>
+#include <API/Notification/INotificationManager.h>
+#include <API/Notification/INotification.h>
+#include <app.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Notification {
+
+
+class NotificationManager : TizenApis::Api::Notification::INotificationManager
+{
+public:
+       friend class TizenApis::Api::Notification::NotificationFactory;
+
+       virtual ~NotificationManager();
+       void post(TizenApis::Api::Notification::INotificationPtr notification);
+       void update(TizenApis::Api::Notification::INotificationPtr notification);
+       void cancel(std::string id);
+       void cancelAll();
+       TizenApis::Api::Notification::INotificationPtr get(std::string id);
+       std::vector<TizenApis::Api::Notification::INotificationPtr> getAll();
+
+       typedef struct {
+               ui_notification_h foundHandle;
+               std::string id;
+       } FindHandleType;
+       
+protected:
+       NotificationManager();
+private:
+       void updateProgress(TizenApis::Api::Notification::INotificationPtr notification);
+       
+};
+
+
+}
+}
+}
+
+#endif 
+
+
diff --git a/src/platform/Tizen/Notification/StatusNotification.cpp b/src/platform/Tizen/Notification/StatusNotification.cpp
new file mode 100644 (file)
index 0000000..3ac99d4
--- /dev/null
@@ -0,0 +1,693 @@
+//
+// 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 <sstream>
+#include "StatusNotification.h"
+
+namespace TizenApis {
+namespace Platform {
+namespace Notification{
+
+const std::string StatusNotification::TYPE_STATUS = "STATUS";
+const std::string StatusNotification::TYPE_SIMPLE = "SIMPLE";
+const std::string StatusNotification::TYPE_PROGRESS = "PROGRESS";
+const std::string StatusNotification::TYPE_ONGOING = "ONGOING";
+
+StatusNotification::StatusNotification()
+{
+       m_notificationHandle = NULL;
+       m_progressValue = 0.0;
+       m_statusType = TYPE_SIMPLE;     
+}
+
+StatusNotification::StatusNotification(bool progress)
+{
+       m_notificationHandle = NULL;
+       m_progressValue = 0.0;
+
+       if (ui_notification_create(progress, &m_notificationHandle) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               if (m_notificationHandle != NULL)
+               {
+                       ui_notification_destroy(m_notificationHandle);
+               }
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle creation error");
+       }
+
+       LogDebug("Noti Address" << m_notificationHandle);
+}
+
+
+StatusNotification::~StatusNotification() 
+{
+       if (m_notificationHandle != NULL)
+       {
+               ui_notification_destroy(m_notificationHandle);
+       }
+}
+
+namespace {
+       
+static bool service_extra_data_cb(service_h service, const char *key, void *user_data)
+{
+       char **value = NULL;
+       int length = 0;
+
+       if (user_data != NULL && key != NULL)
+       {       
+               LogDebug("OK");
+
+               TizenApis::Api::Application::ApplicationControlPtr* appControl = 
+                       (TizenApis::Api::Application::ApplicationControlPtr*)(user_data);
+
+               TizenApis::Api::Application::ApplicationControlDataPtr data(new TizenApis::Api::Application::ApplicationControlData());
+               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)
+               {
+                       if (value && length != 0)
+                       {
+                               data->setKey(key);
+                               
+                               for (index = 0; index < length; index++)
+                               {
+                                       keyValue.push_back(value[index]);
+                               }
+                               
+                               data->setValue(keyValue);
+                               (*appControl)->addAppControlData(data);
+                       }
+               }
+       }
+       if(value)
+       {
+          int index = 0;
+          for(index = 0; index < length; index++)
+          { 
+               free(value[index]);
+          }
+          free(value);
+       }
+       return true;
+}
+}
+
+std::string StatusNotification::getId()
+{
+       std::string title = commonGetter(OPERATION_TITLE);
+       std::string strTime;
+       std::stringstream strstream;
+       
+       time_t unixtime = (time_t)getPostedTime();
+
+       strstream << unixtime;
+       strstream >> strTime;
+       
+       return strTime + title;
+}
+
+std::string StatusNotification::getType()
+{
+       return TYPE_STATUS;
+}
+
+time_t StatusNotification::getPostedTime()
+{
+       struct tm *value = NULL;
+       time_t postedTime;
+       
+       if (ui_notification_get_time(m_notificationHandle, &value)  != UI_NOTIFICATION_ERROR_NONE)
+       {
+               if (value)
+               {
+                       free(value);
+               }
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification posted time error");
+       }
+
+       if (value == NULL)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "get notification posted error");
+       }
+       postedTime = mktime(value);
+       free(value);
+
+       return postedTime;
+}
+
+std::string StatusNotification::getTitle()
+{
+       return commonGetter(OPERATION_TITLE);
+}
+
+
+void StatusNotification::setTitle(const std::string& title)
+{
+       const char *titleStr = title.c_str();
+
+       LogDebug(titleStr);
+       
+       if (ui_notification_set_title(m_notificationHandle, titleStr)  != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification title error");
+       }       
+}
+
+std::string StatusNotification::getContent()
+{
+       return commonGetter(OPERATION_CONTENT);
+}
+
+void StatusNotification::setContent(const std::string& content)
+{
+       const char *contentStr = content.c_str();
+
+       LogDebug(contentStr);
+
+       if (ui_notification_set_content(m_notificationHandle, contentStr)  != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification cotent error");
+       }       
+}
+
+
+std::string StatusNotification::getStatusType()
+{
+       return m_statusType;
+}
+
+void StatusNotification::setStatusType(const std::string& statusType)
+{
+//     LogDebug("OK" << statusType);
+       
+       if (statusType != TYPE_PROGRESS && statusType != TYPE_ONGOING && statusType != TYPE_SIMPLE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "abnormal status type");
+       }
+       m_statusType = statusType;
+}
+
+std::string StatusNotification::getIconPath()
+{
+       std::string iconPath = commonGetter(OPERATION_ICON);
+
+       // ignore default icon path to return null
+       if (iconPath.find("/opt/share/icons/default/") != std::string::npos)
+       {
+               iconPath = "";
+       }
+       return iconPath;
+}
+
+void StatusNotification::setIconPath(const std::string& iconPath)
+{
+       const char *iconStr = iconPath.c_str();
+
+       LogDebug(iconStr);
+
+       if (ui_notification_set_icon(m_notificationHandle, iconStr)  != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification icon error");
+       }       
+}
+
+std::string StatusNotification::getSoundPath()
+{
+       return commonGetter(OPERATION_SOUND);
+}
+
+void StatusNotification::setSoundPath(const std::string& soundPath)
+{
+       const char *path = soundPath.c_str();
+
+       LogDebug(path);
+       
+       if (ui_notification_set_sound(m_notificationHandle, path)  != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification posted time error");
+       }
+}
+
+bool StatusNotification::getVibration()
+{
+       bool vibration = false;
+
+       if (ui_notification_get_vibration(m_notificationHandle, &vibration) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification type error");
+       }
+       return vibration;
+}
+
+void StatusNotification::setVibration(const bool& vibration)
+{
+       if (ui_notification_set_vibration(m_notificationHandle, vibration)  != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification posted time error");
+       }
+}
+
+
+
+void* StatusNotification::getNotificationHandle()
+{
+       return m_notificationHandle;
+}
+
+void StatusNotification::setNotificationHandle(void *handle)
+{
+       if (handle == NULL)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "notification handle null error");
+       }
+
+       if (m_notificationHandle != NULL)
+       {
+               ui_notification_destroy(m_notificationHandle);
+       }
+       
+       m_notificationHandle = (ui_notification_h)handle;       
+}
+
+TizenApis::Api::Application::ApplicationControlPtr StatusNotification::getApplicationControl()
+{
+       service_h service = NULL;
+       char *tempStr = NULL;
+       TizenApis::Api::Application::ApplicationControlPtr appControl(new TizenApis::Api::Application::ApplicationControl());
+       int error = 0;
+//     LogDebug("OK");
+       
+       try {
+               
+               if (error = ui_notification_get_service(m_notificationHandle, &service) != UI_NOTIFICATION_ERROR_NONE)
+               {
+                       LogDebug(error);
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service error");
+               }
+
+               if (service == NULL)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "get notification service ok, but service null");                        
+               }
+               
+               appControl->setService_h(service);
+
+               // mandatory
+               if (error = service_get_operation(service,      &tempStr) != SERVICE_ERROR_NONE)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification service operation error");                 
+               }
+
+               if (tempStr) 
+               {
+                       appControl->setOperation(tempStr);
+                       free(tempStr);
+                       tempStr = NULL;
+               }
+               else 
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "get notification service operation ok, but null");                      
+               }
+
+               // optional
+               if (error =  service_get_mime(service, &tempStr) == SERVICE_ERROR_NONE)
+               {
+                       if (tempStr) 
+                       {
+                               appControl->setMime(tempStr);
+                               free(tempStr);
+                               tempStr = NULL;
+                       }
+
+               }
+
+               // optional
+               if (error = service_get_uri(service, &tempStr) == SERVICE_ERROR_NONE)
+               {
+                       if (tempStr) 
+                       {
+                               appControl->setUri(tempStr);
+                               free(tempStr);
+                               tempStr = NULL;
+                       }
+               }
+
+               if (error = service_get_category(service, &tempStr) == SERVICE_ERROR_NONE)
+               {
+                       if (tempStr) 
+                       {
+                               appControl->setCategory(tempStr);
+                               free(tempStr);
+                               tempStr = NULL;
+                       }
+               }
+
+               // optional
+               if (error =  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");
+               }
+
+               return appControl;
+               
+       }
+       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
+               {
+                       ReThrowMsg(WrtDeviceApis::Commons::UnknownException, _rethrown_exception.GetMessage());
+               }
+
+
+       }
+
+       return appControl;
+}
+
+
+void StatusNotification::setApplicationControl(TizenApis::Api::Application::ApplicationControlPtr appControl)
+{
+       service_h service = NULL;
+//     LogDebug("OK");
+
+       if (ui_notification_get_service(m_notificationHandle, &service) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get a notification service error");
+       }
+
+       if(service == NULL && service_create(&service) != SERVICE_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service creation error");
+       }
+
+       // mandatory
+       if (appControl->getOperation().size() != 0)
+       {
+               if (service_set_operation(service, appControl->getOperation().c_str()) != SERVICE_ERROR_NONE)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set operation error");
+               }
+       }
+       
+       // optional
+       if (appControl->getUri().size() != 0)
+       {
+               if (service_set_uri(service, appControl->getUri().c_str() ) != SERVICE_ERROR_NONE)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set uri error");
+               }
+       }
+
+       // optional
+       if (appControl->getMime().size() != 0)
+       {
+               if (service_set_mime(service, appControl->getMime().c_str() ) != SERVICE_ERROR_NONE)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set mime error");
+               }
+       }
+
+       //optional category
+       if (appControl->getCategory().size() != 0)
+       {
+               if (service_set_category(service, appControl->getCategory().c_str()) != SERVICE_ERROR_NONE)
+                {
+                        ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set category error");
+                }
+       }
+
+       std::vector<TizenApis::Api::Application::ApplicationControlDataPtr> appControlDataArray = appControl->getAppControlDataArray();
+       size_t index = 0, indexArray = 0;
+
+       LogDebug (" App Control Datas Count : " << appControlDataArray.size());
+
+       TizenApis::Api::Application::ApplicationControlDataArray::iterator iter;
+       for(iter = appControlDataArray.begin(); iter != appControlDataArray.end(); iter++)
+       {
+               TizenApis::Api::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]);
+               }
+
+               const char* strKey = key.c_str();
+               if ( value.size() == 1)
+               {
+                       if (service_add_extra_data(service, strKey, arrayValue[0]) != SERVICE_ERROR_NONE)
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set extra data error");     
+                       }       
+               }
+               else 
+               {
+                       if (service_add_extra_data_array(service, strKey, arrayValue, value.size()) != SERVICE_ERROR_NONE)
+                       {
+                               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set extra data error");                     
+                       }
+
+               }
+               
+               if (arrayValue)
+                       free(arrayValue);
+               
+       }
+       
+       if (ui_notification_set_service(m_notificationHandle, service) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set service error");                        
+       }
+
+       if(service)
+       {
+               if ( service_destroy(service) != SERVICE_ERROR_NONE)
+               {
+                    ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service destroy error");
+               }               
+       }       
+}
+
+void StatusNotification::setApplicationId(const std::string& appId)
+{
+       service_h service = NULL;
+       char* operation = NULL;
+       LogDebug("OK - " << appId);
+
+       if (ui_notification_get_service(m_notificationHandle, &service) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get a notification service error");
+       }
+
+       // no operation set before
+       if(service == NULL)
+       {
+               if (service_create(&service) != SERVICE_ERROR_NONE)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service creation error");
+               }
+       }
+
+       if (service_get_operation(service,      &operation) != SERVICE_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service get operation error");
+       }
+
+       if (operation) 
+       {
+               free(operation);
+       }
+       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");  
+       }
+
+       if (ui_notification_set_service(m_notificationHandle, service) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service set service error");                        
+       }
+
+       if(service)
+       {
+               if ( service_destroy(service) != SERVICE_ERROR_NONE)
+               {
+                    ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service destroy error");
+               }               
+       }
+}
+
+std::string StatusNotification::getApplicationId()
+{
+       std::string retString = "";
+       service_h service = NULL;
+       char* appIdStr = NULL;
+       if (ui_notification_get_service(m_notificationHandle, &service) != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get a notification service error");
+       }
+
+       if (service != NULL) 
+       {
+               if (service_get_app_id(service, &appIdStr) != UI_NOTIFICATION_ERROR_NONE)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get a appId error");
+               }
+
+               if (appIdStr != NULL)
+               {
+                       retString = appIdStr;
+                       free(appIdStr);
+               }
+       }
+       LogDebug(retString);
+       if(service)
+       {
+               if ( service_destroy(service) != SERVICE_ERROR_NONE)
+               {
+                    ThrowMsg(WrtDeviceApis::Commons::UnknownException, "service destroy error");
+               }               
+       }
+
+       return retString;
+}
+
+double StatusNotification::getProgressValue()
+{
+       return m_progressValue;
+}
+
+void StatusNotification::setProgressValue(const unsigned short& progressValue)
+{
+       LogDebug("ProgressValue = " << progressValue);
+
+       double value = 0;
+       value = (double)progressValue/ (double)100;
+
+       if (progressValue > 100)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "range error");
+       }
+       
+       m_progressValue = value;
+       
+}
+
+std::string StatusNotification::commonGetter(getOperationType operation)
+{
+       LogDebug("OK");
+               
+       std::string retString = "";
+       std::string errorMsg = "";
+       char *strValue = NULL;
+       
+       int error = UI_NOTIFICATION_ERROR_INVALID_PARAMETER;
+       
+       switch (operation)
+       {
+               case OPERATION_TITLE:
+                       error = ui_notification_get_title(m_notificationHandle, &strValue);
+                       errorMsg = "get title error";
+                       break;
+               case OPERATION_CONTENT:
+                       error = ui_notification_get_content(m_notificationHandle, &strValue);
+                       errorMsg = "get content error";
+                       break;
+               case OPERATION_ICON:
+                       error = ui_notification_get_icon(m_notificationHandle, &strValue);
+                       errorMsg = "get icon error";
+                       break;
+               case OPERATION_SOUND:
+                       error = ui_notification_get_sound(m_notificationHandle, &strValue);
+                       errorMsg = "get sound error";
+                       break;
+       }
+
+       if (error != UI_NOTIFICATION_ERROR_NONE)
+       {
+               if (strValue)
+               {
+                       free(strValue);
+               }
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, errorMsg);
+       }
+
+       if (strValue)
+       {
+               retString = strValue;
+//             LogDebug(retString << " " << strValue);
+               free(strValue);
+       }
+
+       LogDebug(retString);
+       
+       return retString;
+}
+
+/*
+
+void StatusNotification::setPostedTime(time_t postedTime)
+{
+       time_t current = (time_t)postedTime;
+       struct tm *value = localtime(&current);
+       
+       if (ui_notification_set_time(m_notificationHandle, value)  != UI_NOTIFICATION_ERROR_NONE)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification posted time error");
+       }
+}*/
+
+
+
+}
+}
+}
+
diff --git a/src/platform/Tizen/Notification/StatusNotification.h b/src/platform/Tizen/Notification/StatusNotification.h
new file mode 100644 (file)
index 0000000..be42ed7
--- /dev/null
@@ -0,0 +1,94 @@
+//
+// 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_NOTIFICATION_H_
+#define TIZENAPIS_PLATFORM_NOTIFICATION_H_
+
+#include <API/Notification/NotificationFactory.h>
+#include <API/Notification/INotification.h>
+#include <app.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Notification {
+
+
+class StatusNotification : TizenApis::Api::Notification::INotification
+{
+public:
+       friend class TizenApis::Api::Notification::NotificationFactory;
+
+       ~StatusNotification();
+       // notification
+       std::string getId();
+       std::string getType();
+       time_t getPostedTime();
+       std::string getTitle();
+       void setTitle(const std::string& title);
+       std::string getContent();       
+       void setContent(const std::string& content);
+
+       // status notification
+       std::string getStatusType();
+       void setStatusType(const std::string& progressType);
+       std::string getIconPath();
+       void setIconPath(const std::string& iconPath);
+       std::string getSoundPath();
+       void setSoundPath(const std::string& soundPath);
+       bool getVibration();
+       void setVibration(const bool& vibration);
+       TizenApis::Api::Application::ApplicationControlPtr getApplicationControl();
+       void setApplicationControl(TizenApis::Api::Application::ApplicationControlPtr appControl);
+       std::string getApplicationId();
+       void setApplicationId(const std::string& appId);
+       double getProgressValue();
+       void setProgressValue(const unsigned short& progressValue);
+       void* getNotificationHandle();
+       void setNotificationHandle(void *handle);
+
+       static const std::string TYPE_STATUS;
+       static const std::string TYPE_SIMPLE;
+       static const std::string TYPE_PROGRESS; 
+       static const std::string TYPE_ONGOING;  
+
+protected:
+       StatusNotification();
+       StatusNotification(bool progress);
+       ui_notification_h m_notificationHandle; 
+       double m_progressValue;
+       std::string m_statusType;       
+private:
+       typedef enum {
+               OPERATION_TITLE,
+               OPERATION_CONTENT,
+               OPERATION_ICON,
+               OPERATION_SOUND
+       } getOperationType;
+
+       std::string commonGetter(getOperationType operation);
+
+};
+
+
+}
+}
+}
+
+#endif 
+
+
diff --git a/src/platform/Tizen/Notification/config.cmake b/src/platform/Tizen/Notification/config.cmake
new file mode 100644 (file)
index 0000000..f42e987
--- /dev/null
@@ -0,0 +1,23 @@
+get_current_path()
+
+pkg_search_module(capi-appfw-application REQUIRED capi-appfw-application)
+pkg_search_module(noti REQUIRED notification)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_NOTIFICATION
+        ${capi-appfw-application_INCLUDE_DIRS}
+        ${noti_INCLUDE_DIRS}    
+        PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_NOTIFICATION
+        ${capi-appfw-application_LIBRARIES}
+        ${noti_LIBRARIES}
+        PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_NOTIFICATION
+  ${CURRENT_PATH}/NotificationManager.cpp
+  ${CURRENT_PATH}/StatusNotification.cpp
+  PARENT_SCOPE
+)
+
diff --git a/src/platform/Tizen/Power/PowerManager.cpp b/src/platform/Tizen/Power/PowerManager.cpp
new file mode 100755 (executable)
index 0000000..4945b25
--- /dev/null
@@ -0,0 +1,418 @@
+//
+// 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 "PowerManager.h"
+#include <dpl/log/log.h>
+#include <power.h>
+#include <pmapi.h>
+#include <device.h>
+
+using namespace TizenApis::Api::Power;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Platform {
+namespace Power {
+
+PowerManager::PowerManager()
+{
+    LogDebug("entered");
+    m_currentScreenRequestState = UNDEFINED_STATE;
+    m_currentCpuRequestState = UNDEFINED_STATE;
+    m_currentScreenState = UNDEFINED_STATE;
+    m_emitter = OnPowerStateChangedEmitterPtr(NULL);
+}
+
+PowerManager::~PowerManager()
+{
+    LogDebug("entered");
+    if( m_emitter ){
+        LogDebug("Removing power state emitter.");
+        power_unset_changed_cb();
+        m_emitter = OnPowerStateChangedEmitterPtr(NULL);
+    }
+}
+
+static void statetChangedCb(power_state_e state, void *user_data)
+{
+    LogDebug("Power state changed to: "<<state);
+
+    PowerState changedState = SCREEN_NORMAL_STATE;
+    if(POWER_STATE_NORMAL==state) {
+        changedState = SCREEN_NORMAL_STATE;
+    } else if (POWER_STATE_SCREEN_DIM==state) {
+        changedState = SCREEN_DIM_STATE;
+    } else if (POWER_STATE_SCREEN_OFF==state) {
+        changedState = SCREEN_OFF_STATE;
+    } else {
+        LogWarning("Wrong power state.");
+    }
+
+    OnPowerStateChangedPtr eventPtr(new OnPowerStateChanged());
+    Try
+    {
+        PowerManager* thisPowerManager = (PowerManager*) user_data;
+
+        LogDebug("Old state: "<<thisPowerManager->m_currentScreenState);
+        eventPtr->setPreviousState(thisPowerManager->m_currentScreenState);
+        eventPtr->setChangedState(changedState);
+        eventPtr->setResult(true);
+        thisPowerManager->m_currentScreenState = changedState;
+        thisPowerManager->m_emitter->emit(eventPtr);
+    }
+    Catch (Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+}
+
+void PowerManager::OnRequestReceived(const IEventRequestPtr &event)
+{
+    Try
+    {
+        PowerResource resource = event->getResource();
+        PowerState state = event->getState();
+        LogDebug("resource: "<<resource<<", state: "<<state);
+
+        int ret;
+        if( SCREEN_RESOURCE==resource ) {
+            if( SCREEN_DIM_STATE==state ) {
+                ret = power_lock_state(POWER_STATE_SCREEN_DIM, 0);
+                if( POWER_ERROR_NONE!=ret ) {
+                    ThrowMsg(PlatformException, "Platform error: "<<ret);
+                }
+            } else if( SCREEN_NORMAL_STATE==state ) {
+                ret = power_lock_state(POWER_STATE_NORMAL, 0);
+                if( POWER_ERROR_NONE!=ret ) {
+                    ThrowMsg(PlatformException, "Platform error: "<<ret);
+                }
+            } else if( SCREEN_BRIGHT_STATE==state ) {
+                int maxBrightness = 100;
+                ret = device_get_max_brightness(0, &maxBrightness);
+                if( DEVICE_ERROR_NONE!=ret) {
+                    LogWarning("Platform error while getting max brightness: "<<ret);
+                }
+
+                ret = device_set_brightness(0, maxBrightness);
+                if( DEVICE_ERROR_NONE!=ret) {
+                    ThrowMsg(PlatformException, "Platform error while setting max brightness: "<<ret);
+                } else {
+                    LogDebug("Succeeded setting the brightness to a max level: "<<maxBrightness);
+                }
+
+                ret = power_lock_state(POWER_STATE_NORMAL, 0);
+                if( POWER_ERROR_NONE!=ret ) {
+                    ThrowMsg(PlatformException, "Platform error while locking state: "<<ret);
+                }
+            } else {
+               ThrowMsg(UnknownException, "Wrong power state.");
+            }
+
+            m_currentScreenRequestState = state;
+        } else if( CPU_RESOURCE==resource ) {
+            if( CPU_AWAKE_STATE==state ) {
+                ret = power_lock_state(POWER_STATE_SCREEN_OFF, 0);
+                if( POWER_ERROR_NONE!=ret ) {
+                    ThrowMsg(PlatformException, "Platform error: "<<ret);
+                }
+            } else { 
+                ThrowMsg(UnknownException, "Wrong power state.");
+            }
+
+            m_currentCpuRequestState = state;
+        } else {
+                ThrowMsg(UnknownException, "Wrong power resource.");
+        }
+
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void PowerManager::OnRequestReceived(const IEventReleasePtr &event)
+{
+    Try
+    {
+        PowerResource resource = event->getResource();
+        LogDebug("resource: "<<resource);
+
+        int ret;
+
+        if( SCREEN_RESOURCE==resource ) {
+            ret = power_unlock_state(POWER_STATE_SCREEN_DIM);
+            if( POWER_ERROR_NONE!=ret ) {
+                LogDebug("Platform return value from dim unlock: "<<ret);
+            }
+
+            ret = power_unlock_state(POWER_STATE_NORMAL);
+            if( POWER_ERROR_NONE!=ret ) {
+                LogDebug("Platform return value from normal unlock: "<<ret);
+            }
+
+            ret = device_set_brightness_from_settings(0);
+            if( DEVICE_ERROR_NONE!=ret) {
+                ThrowMsg(PlatformException, "Platform error while restoring brightness: "<<ret);
+            } else {
+                LogDebug("Succeeded restoring the brightness to setting value.");
+            }
+
+            m_currentScreenRequestState = UNDEFINED_STATE;
+
+            if(CPU_AWAKE_STATE==m_currentCpuRequestState) {
+                ret = power_lock_state(POWER_STATE_SCREEN_OFF, 0);
+                if( POWER_ERROR_NONE!=ret ) {
+                    ThrowMsg(PlatformException, "Platform error while locing cpu sate."<<ret);
+                }
+            }
+        } else if( CPU_RESOURCE==resource ) {
+            ret = power_unlock_state(POWER_STATE_SCREEN_OFF);
+            if( POWER_ERROR_NONE!=ret ) {
+                LogDebug("Platform return value from off unlock: "<<ret);
+            }
+
+            m_currentCpuRequestState = UNDEFINED_STATE;
+        } else {
+            ThrowMsg(UnknownException, "Wrong power resource.");
+        }
+
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void PowerManager::OnRequestReceived(const IEventSetScreenStateChangeListenerPtr &event)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        int ret;
+
+        if(event->getEmitter()) {
+            LogDebug("Setting the power state emitter.");
+            if(!m_emitter) {
+                ret = power_set_changed_cb(statetChangedCb, this);
+                if( POWER_ERROR_NONE!=ret ) {
+                    ThrowMsg(PlatformException, "Platform error: "<<ret);
+                }
+            }
+            m_emitter = event->getEmitter();
+        }
+
+        power_state_e state = power_get_state();
+        if(POWER_STATE_NORMAL==state) {
+            m_currentScreenState = SCREEN_NORMAL_STATE;
+            if(SCREEN_BRIGHT_STATE==m_currentScreenRequestState) {
+                m_currentScreenState = SCREEN_BRIGHT_STATE;
+            }
+        } else if (POWER_STATE_SCREEN_DIM==state) {
+            m_currentScreenState = SCREEN_DIM_STATE;
+        } else if (POWER_STATE_SCREEN_OFF==state) {
+            m_currentScreenState = SCREEN_OFF_STATE;
+        } else {
+            LogWarning("Wrong power state.");
+        }
+
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void PowerManager::OnRequestReceived(const IEventUnsetScreenStateChangeListenerPtr &event)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        int ret;
+
+        if( m_emitter ){
+            LogDebug("Removing power state emitter.");
+            ret = power_unset_changed_cb();
+            if( POWER_ERROR_NONE!=ret ) {
+                LogDebug("Platform return value from unset changed cb: "<<ret);
+            }
+            m_emitter = OnPowerStateChangedEmitterPtr(NULL);
+        }
+
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void PowerManager::OnRequestReceived(const IEventGetScreenBrightnessPtr &event)
+{
+    Try
+    {
+        int ret, brightness;
+
+        ret = device_get_brightness(0, &brightness);
+        if( DEVICE_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Platform error while getting brightness."<<ret);
+        } else {
+            LogDebug("Brightness value: "<<brightness);
+        }
+
+        event->setBrightness((double)(brightness/100.0));
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void PowerManager::OnRequestReceived(const IEventSetScreenBrightnessPtr &event)
+{
+    Try
+    {
+        int ret;
+
+        ret = device_set_brightness(0, (int)(event->getBrightness()*100));
+        if( DEVICE_ERROR_NONE!=ret ) {
+            ThrowMsg(PlatformException, "Platform error while setting brightness."<<ret);
+        } else {
+            LogDebug("Set the brightness value: "<<event->getBrightness()*100);
+        }
+
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void PowerManager::OnRequestReceived(const IEventIsScreenOnPtr &event)
+{
+    Try
+    {
+        power_state_e state = power_get_state();
+        if(POWER_STATE_SCREEN_OFF==state) {
+            event->setIsScreenOn(false);
+        } else {
+            event->setIsScreenOn(true);
+        }
+
+        LogDebug("Screen on flag: "<<event->getIsScreenOn());
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void PowerManager::OnRequestReceived(const IEventRestoreScreenBrightnessPtr &event)
+{
+    Try
+    {
+        int ret;
+
+        ret = device_set_brightness_from_settings(0);
+        if( DEVICE_ERROR_NONE!=ret) {
+            ThrowMsg(PlatformException, "Platform error while restoring brightness: "<<ret);
+        } else {
+            LogDebug("Succeeded restoring the brightness to setting value.");
+        }
+
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void PowerManager::OnRequestReceived(const IEventTurnScreenOnPtr &event)
+{
+    Try
+    {
+        int ret;
+
+        ret = pm_change_state(LCD_NORMAL);
+        if( ret<0 ) {
+            ThrowMsg(PlatformException, "Platform error while changing screen state: "<<ret);
+        } else {
+            LogDebug("Succeeded turning on the screen.");
+        }
+
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+void PowerManager::OnRequestReceived(const IEventTurnScreenOffPtr &event)
+{
+    Try
+    {
+        int ret;
+
+        ret = pm_change_state(LCD_OFF);
+        if( ret<0 ) {
+            ThrowMsg(PlatformException, "Platform error while changing screen state: "<<ret);
+        } else {
+            LogDebug("Succeeded turning off the screen.");
+        }
+
+        event->setResult(true);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        event->setResult(false);
+        event->setExceptionCode(ExceptionCodes::UnknownException);
+    }
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/Power/PowerManager.h b/src/platform/Tizen/Power/PowerManager.h
new file mode 100755 (executable)
index 0000000..c53fe22
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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 _PLATFORM_POWER_MANAGER_H_
+#define _PLATFORM_POWER_MANAGER_H_
+
+#include <API/Power/IPowerManager.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Power {
+
+class PowerManager : public Api::Power::IPowerManager
+{
+  public:
+    PowerManager();
+    virtual ~PowerManager();
+
+  protected:
+    virtual void OnRequestReceived(const Api::Power::IEventRequestPtr &event);
+    virtual void OnRequestReceived(const Api::Power::IEventReleasePtr &event);
+    virtual void OnRequestReceived(const Api::Power::IEventSetScreenStateChangeListenerPtr &event);
+    virtual void OnRequestReceived(const Api::Power::IEventUnsetScreenStateChangeListenerPtr &event);
+    virtual void OnRequestReceived(const Api::Power::IEventGetScreenBrightnessPtr &event);
+    virtual void OnRequestReceived(const Api::Power::IEventSetScreenBrightnessPtr &event);
+    virtual void OnRequestReceived(const Api::Power::IEventIsScreenOnPtr &event);
+    virtual void OnRequestReceived(const Api::Power::IEventRestoreScreenBrightnessPtr &event);
+    virtual void OnRequestReceived(const Api::Power::IEventTurnScreenOnPtr &event);
+    virtual void OnRequestReceived(const Api::Power::IEventTurnScreenOffPtr &event);
+
+  public:
+    Api::Power::PowerState m_currentScreenRequestState;
+    Api::Power::PowerState m_currentCpuRequestState;
+    Api::Power::PowerState m_currentScreenState;
+    Api::Power::OnPowerStateChangedEmitterPtr m_emitter;
+};
+
+}
+}
+}
+
+#endif /* _PLATFORM_POWER_MANAGER_H_ */
diff --git a/src/platform/Tizen/Power/config.cmake b/src/platform/Tizen/Power/config.cmake
new file mode 100755 (executable)
index 0000000..665816d
--- /dev/null
@@ -0,0 +1,24 @@
+get_current_path()
+
+pkg_search_module(power REQUIRED capi-system-power)
+pkg_search_module(pmapi REQUIRED pmapi)
+pkg_search_module(device REQUIRED capi-system-device)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_POWER
+  ${power_INCLUDE_DIRS}
+  ${pmapi_INCLUDE_DIRS}
+  ${device_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_POWER
+  ${power_LIBRARIES}
+  ${pmapi_LIBRARIES}
+  ${device_LIBRARIES}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_POWER
+  ${CURRENT_PATH}/PowerManager.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/SystemSetting/SystemSetting.cpp b/src/platform/Tizen/SystemSetting/SystemSetting.cpp
new file mode 100755 (executable)
index 0000000..fba1ba8
--- /dev/null
@@ -0,0 +1,282 @@
+//
+// 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 <Commons/Exception.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include "SystemSetting.h"
+#include <netdb.h>
+#include <arpa/inet.h>
+#include <string.h>
+
+
+#include <system_settings.h>
+
+using namespace TizenApis::Api::SystemSetting;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace DPL;
+
+namespace TizenApis {
+namespace Platform {
+namespace SystemSetting {
+    
+SystemSetting::SystemSetting()
+{
+}
+
+SystemSetting::~SystemSetting()
+{
+}
+
+void SystemSetting::setWallpaper(const EventSetWallpaperPtr &event)
+{
+    LogDebug("enter");
+    EventRequestReceiver<EventSetWallpaper>::PostRequest(event);
+}
+
+void SystemSetting::setRingtone(const EventSetRingtonePtr &event)
+{
+    LogDebug("enter");
+    EventRequestReceiver<EventSetRingtone>::PostRequest(event);
+}
+
+void SystemSetting::setProperty(const EventSetSettingPtr &event)
+{
+    LogDebug("enter");
+    EventRequestReceiver<EventSetSetting>::PostRequest(event);
+}
+
+void SystemSetting::getProperty(const EventGetSettingPtr &event)
+{
+    LogDebug("enter");
+    EventRequestReceiver<EventGetSetting>::PostRequest(event);
+}
+
+std::string SystemSetting::getProperty(const Api::SystemSetting::SettingType settingType)
+{
+       LogDebug("enter");
+       int ret = SYSTEM_SETTINGS_ERROR_NONE;
+
+       char *value = NULL;
+       std::string gettingValue;
+
+       if(settingType == Api::SystemSetting::HOME_SCREEN )
+       {
+               LogDebug("home screen");
+               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &value);
+               LogDebug("result : " << ret << " value: "<< value);
+       }
+       else if(settingType == Api::SystemSetting::LOCK_SCREEN )
+       {
+               LogDebug("lock screen");
+               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &value);
+               LogDebug("result : " << ret << " value: "<< value);
+       }else if(settingType == Api::SystemSetting::INCOMMING_CALL )
+       {
+               LogDebug("call");
+               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &value);
+               LogDebug("result : " << ret << " value: "<< value);
+       }
+       else if(settingType == Api::SystemSetting::NOTIFICATION_EMAIL )
+       {
+               LogDebug("email");
+               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, &value);
+               LogDebug("result : " << ret << " value: "<< value);
+       }
+
+
+       if(ret == SYSTEM_SETTINGS_ERROR_NONE)
+       {
+               LogDebug("success");
+               gettingValue = value;
+               return value;
+       }
+       else
+       {
+               LogDebug("PlatformException");
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "PlatformException");
+       }
+}
+
+void SystemSetting::OnRequestReceived(const EventSetWallpaperPtr &event)
+{
+       LogDebug("enter");
+       int ret = SYSTEM_SETTINGS_ERROR_NONE;
+
+       std::string wallpaperUri = event->getWallpaperURI();
+       std::string wallpaperType = event->getWallpaperType();
+
+       if(strcmp(wallpaperType.c_str(), "HOME_SCREEN") == 0 )
+       {
+               LogDebug("home screen : " << wallpaperUri.c_str());
+               ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, wallpaperUri.c_str());
+       }
+       else if(strcmp(wallpaperType.c_str(), "LOCK_SCREEN") == 0 )
+       {
+               LogDebug("lock screen : " << wallpaperUri.c_str());
+               ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, wallpaperUri.c_str());
+       }
+
+       if(ret == SYSTEM_SETTINGS_ERROR_NONE)
+       {
+               LogDebug("success");
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       else
+       {
+               LogDebug("PlatformException");
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+       LogDebug("end");
+}
+
+void SystemSetting::OnRequestReceived(const EventSetRingtonePtr &event)
+{
+       LogDebug("enter");
+       int ret = SYSTEM_SETTINGS_ERROR_NONE;
+
+       std::string ringtoneUri = event->getRingtoneURI();
+       std::string ringtoneType = event->getRingtoneType();
+
+       if(strcmp(ringtoneType.c_str(), "INCOMING_CALL") == 0 )
+       {
+               LogDebug("call  : " << ringtoneUri.c_str());
+               ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, ringtoneUri.c_str());
+       }
+       else if(strcmp(ringtoneType.c_str(), "NOTIFICATION_EMAIL") == 0 )
+       {
+               // TODO need manage-api
+               LogDebug("email  : " << ringtoneUri.c_str());
+               ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, ringtoneUri.c_str());
+       }
+
+       if(ret == SYSTEM_SETTINGS_ERROR_NONE)
+       {
+               LogDebug("success");
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       else
+       {
+               LogDebug("PlatformException");
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+       LogDebug("end");
+}
+
+void SystemSetting::OnRequestReceived(const EventSetSettingPtr &event)
+{
+       LogDebug("enter");
+       int ret = SYSTEM_SETTINGS_ERROR_NONE;
+
+       std::string settingValue = event->getSettingValue();
+       Api::SystemSetting::SettingType settingType = event->getSettingType();
+
+       if(settingType == Api::SystemSetting::HOME_SCREEN )
+       {
+               LogDebug("home screen : " << settingValue.c_str());
+               ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, settingValue.c_str());
+               LogDebug("result : " << ret);
+       }
+       else if(settingType == Api::SystemSetting::LOCK_SCREEN )
+       {
+               LogDebug("lock screen : " << settingValue.c_str());
+               ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, settingValue.c_str());
+               LogDebug("result : " << ret);
+       }else if(settingType == Api::SystemSetting::INCOMMING_CALL )
+       {
+               LogDebug("call  : " << settingValue.c_str());
+               ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, settingValue.c_str());
+               LogDebug("result : " << ret);
+       }
+       else if(settingType == Api::SystemSetting::NOTIFICATION_EMAIL )
+       {
+               LogDebug("email  : " << settingValue.c_str());
+               ret = system_settings_set_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, settingValue.c_str());
+               LogDebug("result : " << ret);
+       }
+
+
+       if(ret == SYSTEM_SETTINGS_ERROR_NONE)
+       {
+               LogDebug("success");
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       else
+       {
+               LogDebug("PlatformException");
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+       LogDebug("end");
+}
+
+void SystemSetting::OnRequestReceived(const EventGetSettingPtr &event)
+{
+       LogDebug("enter");
+       int ret = SYSTEM_SETTINGS_ERROR_NONE;
+
+       std::string settingValue;
+       Api::SystemSetting::SettingType settingType = event->getSettingType();
+       char *value = NULL;
+
+       if(settingType == Api::SystemSetting::HOME_SCREEN )
+       {
+               LogDebug("home screen");
+               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &value);
+               LogDebug("result : " << ret);
+       }
+       else if(settingType == Api::SystemSetting::LOCK_SCREEN )
+       {
+               LogDebug("lock screen");
+               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &value);
+               LogDebug("result : " << ret);
+       }else if(settingType == Api::SystemSetting::INCOMMING_CALL )
+       {
+               LogDebug("call");
+               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &value);
+               LogDebug("result : " << ret);
+       }
+       else if(settingType == Api::SystemSetting::NOTIFICATION_EMAIL )
+       {
+               LogDebug("email");
+               ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, &value);
+               LogDebug("result : " << ret);
+       }
+
+
+       if(ret == SYSTEM_SETTINGS_ERROR_NONE)
+       {
+               LogDebug("success");
+               event->setExceptionCode(ExceptionCodes::None);
+       }
+       else
+       {
+               LogDebug("PlatformException");
+               event->setExceptionCode(ExceptionCodes::PlatformException);
+       }
+
+       settingValue = value;
+       event->setSettingValue(settingValue);
+
+       LogDebug("end");
+}
+
+
+}
+}
+}
diff --git a/src/platform/Tizen/SystemSetting/SystemSetting.h b/src/platform/Tizen/SystemSetting/SystemSetting.h
new file mode 100755 (executable)
index 0000000..5031714
--- /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 WRTPLUGINS_PLATFORM_SYSTEMSETTING_H_
+#define WRTPLUGINS_PLATFORM_SYSTEMSETTING_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <API/SystemSetting/SystemSettingFactory.h>
+#include <API/SystemSetting/ISystemSetting.h>
+#include <API/SystemSetting/EventSetWallpaper.h>
+#include <API/SystemSetting/EventSetRingtone.h>
+#include <API/SystemSetting/EventSetSetting.h>
+#include <API/SystemSetting/EventGetSetting.h>
+#include <CommonsJavaScript/Converter.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace SystemSetting {
+
+class SystemSetting : public Api::SystemSetting::ISystemSetting
+{
+       friend class TizenApis::Api::SystemSetting::SystemSettingFactory;
+       friend class TizenApis::Api::SystemSetting::EventSetWallpaper;
+       friend class TizenApis::Api::SystemSetting::EventSetRingtone;
+       friend class TizenApis::Api::SystemSetting::EventSetSetting;
+       friend class TizenApis::Api::SystemSetting::EventGetSetting;
+
+       public:
+               SystemSetting();
+               virtual ~SystemSetting();
+               virtual void setWallpaper(const Api::SystemSetting::EventSetWallpaperPtr &event);
+               virtual void setRingtone(const Api::SystemSetting::EventSetRingtonePtr &event);
+               virtual void setProperty(const Api::SystemSetting::EventSetSettingPtr &event);
+               virtual void getProperty(const Api::SystemSetting::EventGetSettingPtr &event);
+               virtual std::string getProperty(const Api::SystemSetting::SettingType settingType);
+
+       protected:
+               virtual void OnRequestReceived(const Api::SystemSetting::EventSetWallpaperPtr &event);
+               virtual void OnRequestReceived(const Api::SystemSetting::EventSetRingtonePtr &event);
+               virtual void OnRequestReceived(const Api::SystemSetting::EventSetSettingPtr &event);
+               virtual void OnRequestReceived(const Api::SystemSetting::EventGetSettingPtr &event);
+
+       private:
+               std::string m_domainName;
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/Tizen/SystemSetting/config.cmake b/src/platform/Tizen/SystemSetting/config.cmake
new file mode 100644 (file)
index 0000000..55866cc
--- /dev/null
@@ -0,0 +1,18 @@
+get_current_path()
+
+pkg_search_module(capi-system-system-settings REQUIRED capi-system-system-settings)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_SYSTEMSETTING
+  ${capi-system-system-settings_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_SYSTEMSETTING
+  ${capi-system-system-settings_LIBRARIES}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_SYSTEMSETTING
+  ${CURRENT_PATH}/SystemSetting.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/Systeminfo/Systeminfo.cpp b/src/platform/Tizen/Systeminfo/Systeminfo.cpp
new file mode 100755 (executable)
index 0000000..b4d0a98
--- /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 <fstream>
+#include <stddef.h>
+#include <cassert>
+#include <pcrecpp.h>
+#include <dpl/log/log.h>
+#include <math.h>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include "Systeminfo.h"
+
+using namespace TizenApis::Api::Systeminfo;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace DPL;
+
+namespace TizenApis {
+namespace Platform {
+namespace Systeminfo {
+
+namespace {
+
+void BatteryValueCallback(keynode_t *node, void *event_ptr)
+{
+    if(event_ptr) {
+        ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_BATTERY);
+    }
+}
+
+void DisplayValueCallback(keynode_t *node, void* event_ptr)
+{
+    if(event_ptr) {
+        ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DISPLAY);
+    }
+}
+
+void NetworkTypeValueCallback(connection_type_e type, void* event_ptr)
+{
+    if(event_ptr) {
+        ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK);
+    }
+}
+
+void NetworkValueCallback(const char* ipv4_address, const char* ipv6_address, void* event_ptr)
+{
+    if(event_ptr) {
+        ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_NETWORK_ALL);
+    }
+}
+
+static Eina_Bool StorageValueCallback(void* event_ptr)
+{
+    if(event_ptr) {
+        ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_STORAGE);
+    }
+    return ECORE_CALLBACK_RENEW;
+}
+
+static Eina_Bool CpuValueCallback(void* event_ptr)
+{
+    if(event_ptr) {
+        ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_CPU);
+    }
+    return ECORE_CALLBACK_RENEW;
+}
+
+void OrientationValueCallback(unsigned int event_type, sensor_event_data_t *event , void *event_ptr)
+{
+    LogDebug("enter");
+    if(event_ptr) {
+        ((Systeminfo*)event_ptr)->getWatchValue(WATCH_TYPE_DEVICE_ORIENTATION);
+    }
+}
+
+}
+
+#define STORAGE_INTERNAL_PATH   "/opt/usr/media"
+#define STORAGE_SDCARD_PATH     "/opt/storage/sdcard"
+#define STORAGE_USBHOST_PATH    "/opt/storage/usb"
+#define DISPLAY_BRIGHTNESS_DIVIDE_VALUE 100
+#define WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE 100
+#define CPU_POWER_DEVICE_VALUE          100
+
+#define RADIAN_VALUE (57.2957)
+
+enum {
+    STORAGE_TYPE_UNKNOWN = 0,
+    STORAGE_TYPE_INTERNAL = 1,
+    STORAGE_TYPE_MMC = 2,
+    STORAGE_TYPE_USBHOST = 3
+};
+
+Systeminfo::OptionalProperty Systeminfo::m_Property;
+
+Systeminfo::Systeminfo() : m_networkRegist(REGIST_NOT),
+    m_storageTimer(NULL),
+                        m_cpuTimer(NULL),
+    m_sensorHandle(0),
+    m_connectionHandle(NULL)
+{
+    EventMgrPtr eventMgrPtr(new EventMgr());
+    m_EventMgrPtr = eventMgrPtr;
+    if (m_Property.IsNull()) {
+        mapProperties properties;
+        properties["BATTERY"] = BasePropertyPtr(new Battery());
+        m_Property = properties;
+        (*m_Property)["CPU"] = BasePropertyPtr(new Cpu());
+        (*m_Property)["STORAGE"] = BasePropertyPtr(new Storage());
+        (*m_Property)["DISPLAY"] = BasePropertyPtr(new Display());
+        (*m_Property)["NETWORK"] = BasePropertyPtr(new Network());
+        (*m_Property)["WIFI_NETWORK"] = BasePropertyPtr(new WifiNetwork());
+        (*m_Property)["CELLULAR_NETWORK"] = BasePropertyPtr(new CellularNetwork());
+        (*m_Property)["SIM"] = BasePropertyPtr(new SIM());
+        (*m_Property)["DEVICE_ORIENTATION"] = BasePropertyPtr(new DeviceOrientation());
+        (*m_Property)["BUILD"] = BasePropertyPtr(new Build());
+    }
+
+    int ret = connection_create(&m_connectionHandle);
+
+       if (CONNECTION_ERROR_NONE == ret) {
+               LogDebug("Network Client registration success");
+       } else {
+               LogDebug("Network Client registration success");
+        m_connectionHandle = NULL;
+    }
+
+    m_sensorHandle = sf_connect(ACCELEROMETER_SENSOR);
+    if (m_sensorHandle < 0) {
+        LogDebug ("sensor attach fail");
+    } else {
+        LogDebug("m_sensorHandle : " << m_sensorHandle);
+        int state = sf_start(m_sensorHandle, 0);
+        if(state < 0) {
+            LogDebug("failed");
+        }
+    }
+}
+
+Systeminfo::~Systeminfo()
+{
+       int state = 0;
+    if (m_storageTimer) {
+        ecore_timer_freeze(m_storageTimer);
+        ecore_timer_del(m_storageTimer);
+        m_storageTimer = NULL;
+    }
+    if (m_cpuTimer) {
+        ecore_timer_freeze(m_cpuTimer);
+        ecore_timer_del(m_cpuTimer);
+        m_cpuTimer = NULL;
+    }
+    m_EventMgrPtr->clearAllEvent();
+
+    if(m_connectionHandle != NULL) {
+        LogDebug("Network Client deregistration success");
+        connection_destroy(m_connectionHandle);
+    } else {
+        LogDebug("Network Client deregistration failed");
+    }
+
+       state = sf_stop(m_sensorHandle);
+       LogDebug("handle 1  state = " << state);
+
+       state = sf_disconnect(m_sensorHandle);
+       LogDebug("handle  state =" << state);
+}
+
+Api::Systeminfo::DeviceCapabilitiesPropertiesPtr Systeminfo::getCapabilities()
+{
+    LogDebug("enter");
+    DeviceCapabilitiesPropertiesPtr deviceCapabilities(new DeviceCapabilitiesProperties());
+    bool bluetooth = false, nfc = false, wifi = false, wifiDirect = false, fmRadio = false, cameraFront = false,
+        cameraFrontFlash = false, cameraBack = false, cameraBackFlash = false, isAccelerometer = false, isGyroscope = false,
+        isMagnetometer = false, isProximity = false, location = false, locationGps = false, locationWps = false, 
+        microphone = false, usbHost = false, usbAccessory = false, screenOutputRca = false, screenOutputHdmi = false,
+        sipVoip = false, speechRecognition = false, isBarometer = false;
+    int multiTouchCount = 0;
+    char* inputKeyboard = NULL;
+    char* platformVersion = NULL;
+    char* platformName = NULL;
+    char* platformCoreCpuArch = NULL;
+    char* platformCoreFpuArch = NULL;
+    char* duid = NULL;
+    char* openglesVersion = NULL;
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_BLUETOOTH_SUPPORTED, &bluetooth) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("bluetooth : " << bluetooth);
+        deviceCapabilities->bluetooth = bluetooth;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_NFC_SUPPORTED, &nfc) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("nfc : " << nfc);
+        deviceCapabilities->nfc = nfc;
+    }
+    if (system_info_get_value_int(SYSTEM_INFO_KEY_MULTI_POINT_TOUCH_COUNT, &multiTouchCount) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("multiTouchCount : " << multiTouchCount);
+        deviceCapabilities->multiTouchCount = multiTouchCount;
+    }
+
+    if (system_info_get_value_string(SYSTEM_INFO_KEY_KEYBOARD_TYPE, &inputKeyboard) == SYSTEM_INFO_ERROR_NONE) {
+        if (inputKeyboard != NULL) {
+            LogDebug("inputKeyboard : " << inputKeyboard);
+            deviceCapabilities->inputKeyboard = inputKeyboard;
+            free(inputKeyboard);
+        }
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_WIFI_SUPPORTED, &wifi) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("wifi : " << wifi);
+        deviceCapabilities->wifi = wifi;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_WIFI_DIRECT_SUPPORTED, &wifiDirect) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("wifiDirect : " << wifiDirect);
+        deviceCapabilities->wifiDirect = wifiDirect;
+    }
+
+    if (system_info_get_value_string(SYSTEM_INFO_KEY_OPENGLES_VERSION, &openglesVersion) == SYSTEM_INFO_ERROR_NONE) {
+        if (openglesVersion!= NULL) {
+            LogDebug("openglesVersion : " << openglesVersion);
+            if (strcmp(openglesVersion, "1.0") == 0) {
+                deviceCapabilities->openglesVersion1_1 = true;
+                deviceCapabilities->openglesVersion2_0 = false;
+            } else if (strcmp(openglesVersion, "2.0") == 0) {
+                deviceCapabilities->openglesVersion1_1 = false;
+                deviceCapabilities->openglesVersion2_0 = true;
+            } else if (strcmp(openglesVersion, "1.0/2.0") == 0) {
+                deviceCapabilities->openglesVersion1_1 = true;
+                deviceCapabilities->openglesVersion2_0 = true;
+            }
+            free(openglesVersion);
+        }
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_FMRADIO_SUPPORTED, &fmRadio) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("fmRadio : " << fmRadio);
+        deviceCapabilities->fmRadio = fmRadio;
+    }
+
+    if (system_info_get_value_string(SYSTEM_INFO_KEY_TIZEN_VERSION, &platformVersion) == SYSTEM_INFO_ERROR_NONE) {
+        if (platformVersion) {
+            LogDebug("platformVersion : " << platformVersion);
+            deviceCapabilities->platformVersion = platformVersion;
+            free(platformVersion);
+        }
+    }
+
+    if (system_info_get_value_string(SYSTEM_INFO_KEY_PLATFORM_NAME, &platformName) == SYSTEM_INFO_ERROR_NONE) {
+        if (platformName) {
+            LogDebug("platformName : " << platformName);
+            deviceCapabilities->platformName = platformName;
+            free(platformName);
+        }
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_FRONT_CAMERA_SUPPORTED, &cameraFront) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("cameraFront : " << cameraFront);
+        deviceCapabilities->cameraFront = cameraFront;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_FRONT_CAMERA_FLASH_SUPPORTED, &cameraFrontFlash) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("cameraFrontFlash : " << cameraFrontFlash);
+        deviceCapabilities->cameraFrontFlash = cameraFrontFlash;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_BACK_CAMERA_SUPPORTED, &cameraBack) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("cameraBack : " << cameraBack);
+        deviceCapabilities->cameraBack = cameraBack;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_BACK_CAMERA_FLASH_SUPPORTED, &cameraBackFlash) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("cameraBackFlash : " << cameraBackFlash);
+        deviceCapabilities->cameraBackFlash = cameraBackFlash;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_CPS_SUPPORTED, &location) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("location : " << location);
+        deviceCapabilities->location = location;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_GPS_SUPPORTED, &locationGps) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("locationGps : " << locationGps);
+        deviceCapabilities->locationGps = locationGps;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_WPS_SUPPORTED, &locationWps) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("locationWps : " << locationWps);
+        deviceCapabilities->locationWps = locationWps;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_MICROPHONE_SUPPORTED, &microphone) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("microphone : " << microphone);
+        deviceCapabilities->microphone = microphone;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_USB_HOST_SUPPORTED, &usbHost) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("usbHost : " << usbHost);
+        deviceCapabilities->usbHost = usbHost;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_USB_ACCESSORY_SUPPORTED, &usbAccessory) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("usbAccessory : " << usbAccessory);
+        deviceCapabilities->usbAccessory = usbAccessory;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_RCA_SUPPORTED, &screenOutputRca) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("screenOutputRca : " << screenOutputRca);
+        deviceCapabilities->screenOutputRca = screenOutputRca;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_HDMI_SUPPORTED, &screenOutputHdmi) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("screenOutputHdmi : " << screenOutputHdmi);
+        deviceCapabilities->screenOutputHdmi = screenOutputHdmi;
+    }
+
+    if (system_info_get_value_string(SYSTEM_INFO_KEY_CORE_CPU_ARCH, &platformCoreCpuArch) == SYSTEM_INFO_ERROR_NONE) {
+        if (platformCoreCpuArch) {
+            LogDebug("platformCoreCpuArch : " << platformCoreCpuArch);
+            deviceCapabilities->platformCoreCpuArch = platformCoreCpuArch;
+            free(platformCoreCpuArch);
+        }
+    }
+
+    if (system_info_get_value_string(SYSTEM_INFO_KEY_CORE_FPU_ARCH, &platformCoreFpuArch) == SYSTEM_INFO_ERROR_NONE) {
+        if (platformCoreFpuArch) {
+            LogDebug("platformCoreFpuArch : " << platformCoreFpuArch);
+            deviceCapabilities->platformCoreFpuArch = platformCoreFpuArch;
+            free(platformCoreFpuArch);
+        }
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_SIP_VOIP_SUPPORTED, &sipVoip) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("sipVoip : " << sipVoip);
+        deviceCapabilities->sipVoip = sipVoip;
+    }
+
+    if (system_info_get_value_string(SYSTEM_INFO_KEY_DEVICE_UUID, &duid) == SYSTEM_INFO_ERROR_NONE) {
+        if (duid) {
+            LogDebug("duid : " << duid);
+            deviceCapabilities->duid = duid;
+            free(duid);
+        }
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_SPEECH_RECOGNITION_SUPPORTED, &speechRecognition) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("speechRecognition : " << speechRecognition);
+        deviceCapabilities->speechRecognition = speechRecognition;
+    }
+
+    if (system_info_get_value_bool(SYSTEM_INFO_KEY_BAROMETER_SENSOR_SUPPORTED, &isBarometer) == SYSTEM_INFO_ERROR_NONE) {
+        LogDebug("barometer : " << isBarometer);
+        deviceCapabilities->barometer = isBarometer;
+    }
+
+    if (sensor_is_supported(SENSOR_ACCELEROMETER, &isAccelerometer) == SENSOR_ERROR_NONE) {
+        LogDebug("accelerometer : " << isAccelerometer);
+        deviceCapabilities->accelerometer = isAccelerometer;
+    }
+
+    if (sensor_is_supported(SENSOR_MAGNETIC, &isMagnetometer) == SENSOR_ERROR_NONE) {
+        LogDebug("magnetometer : " << isMagnetometer);
+        deviceCapabilities->magnetometer = isMagnetometer;
+    }
+
+    if (sensor_is_supported(SENSOR_GYROSCOPE, &isGyroscope) == SENSOR_ERROR_NONE) {
+        LogDebug("gyroscope : " << isGyroscope);
+        deviceCapabilities->gyroscope = isGyroscope;
+    }
+
+    if (sensor_is_supported(SENSOR_PROXIMITY, &isProximity) == SENSOR_ERROR_NONE) {
+        LogDebug("proximity : " << isProximity);
+        deviceCapabilities->proximity = isProximity;
+    }
+
+    return deviceCapabilities;
+}
+
+void Systeminfo::get(const EventGetSysteminfoPtr& event)
+{
+    EventRequestReceiver<EventGetSysteminfo>::PostRequest(event);
+}
+
+void Systeminfo::watch(const EventWatchSysteminfoPtr& event)
+{
+    if(event->getWatchType() == WATCH_TYPE_UNKNOWN) {
+        LogDebug("watch method is not supported");
+        event->setId(-1);
+        return;
+    }
+
+    event->setSysteminfoPtr(this);
+    m_EventMgrPtr->addEvent(event, event->getWatchType());
+
+    EventRequestReceiver<EventWatchSysteminfo>::PostRequest(event);
+}
+
+void Systeminfo::clearWatch(const long id)
+{
+    if (id < 1) {
+        Throw(InvalidArgumentException);
+    } else {
+        int watchType = m_EventMgrPtr->getWatchType(id);
+        switch(watchType) {
+            case WATCH_TYPE_BATTERY:
+                if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
+                    vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback);
+                    vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback);
+                }
+                break;
+            case WATCH_TYPE_DISPLAY:
+                if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
+                    vconf_ignore_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback);
+                }
+                break;
+            case WATCH_TYPE_NETWORK:
+                if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
+                    connection_unset_type_changed_cb(m_connectionHandle);
+                }
+                break;
+            case WATCH_TYPE_WIFINETWORK:
+                if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
+                    if (m_networkRegist == REGIST_WIFI) {
+                        connection_unset_ip_address_changed_cb(m_connectionHandle);
+                        m_networkRegist = REGIST_NOT;
+                    } else if (m_networkRegist== REGIST_ALL) {
+                        m_networkRegist = REGIST_CELLULAR;
+                    }
+                }
+                break;
+            case WATCH_TYPE_CELLULARNETWORK:
+                if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
+                    if (m_networkRegist == REGIST_CELLULAR) {
+                        connection_unset_ip_address_changed_cb(m_connectionHandle);
+                        m_networkRegist = REGIST_NOT;
+                    } else if (m_networkRegist== REGIST_ALL) {
+                        m_networkRegist = REGIST_WIFI;
+                    }
+                }
+                break;
+            case WATCH_TYPE_STORAGE:
+                if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
+                    if (m_storageTimer) {
+                        ecore_timer_freeze(m_storageTimer);
+                        ecore_timer_del(m_storageTimer);
+                        m_storageTimer = NULL;
+                    }
+                }
+                break;
+            case WATCH_TYPE_CPU:
+                if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
+                    if (m_cpuTimer) {
+                        ecore_timer_freeze(m_cpuTimer);
+                        ecore_timer_del(m_cpuTimer);
+                        m_cpuTimer = NULL;
+                    }
+                }
+                break;
+            case WATCH_TYPE_DEVICE_ORIENTATION:
+                if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
+                    int state = sf_unregister_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK);
+                    if (state < 0) {
+                        LogDebug("sf_unregister_event fail to gather data\n");
+                    }
+                }
+                break;
+            case WATCH_TYPE_UNKNOWN:
+                Throw(InvalidArgumentException);
+                break;
+        }
+        m_EventMgrPtr->removeEvent(id, watchType);
+    }
+}
+
+BasePropertyPtr Systeminfo::getBasePropertyPtr(JSContextRef context, JSValueRef property)
+{
+    Converter converter(context);
+    std::string l_property = converter.toString(property);
+    mapProperties::iterator it = (*m_Property).find(l_property);
+    if (it == (*m_Property).end()) {
+        LogError("not existing property");
+        Throw(InvalidArgumentException);
+        return BasePropertyPtr(NULL);
+    }
+
+    return it->second;
+}
+
+void Systeminfo::getWatchValue(const int watchType)
+{
+    if (watchType == WATCH_TYPE_BATTERY) {
+        EventBatteryList eventList = m_EventMgrPtr->getEventBatteryList();
+        for (EventBatteryList::iterator it = eventList.begin(); it != eventList.end(); it++) {
+                (*it)->getWatchValue();
+            }
+    } else if (watchType == WATCH_TYPE_DISPLAY) {
+        EventDisplayList eventList = m_EventMgrPtr->getEventDisplayList();
+        for (EventDisplayList::iterator it = eventList.begin(); it != eventList.end(); it++) {
+            (*it)->getWatchValue();
+        }
+    } else if (watchType == WATCH_TYPE_NETWORK) {
+        EventNetworkList eventList = m_EventMgrPtr->getEventNetworkList();
+        for (EventNetworkList::iterator it = eventList.begin(); it != eventList.end(); it++) {
+            (*it)->getWatchValue();
+        }
+    } else if (watchType == WATCH_TYPE_NETWORK_ALL) {
+        EventWifiNetworkList eventListWifi = m_EventMgrPtr->getEventWifiNetworkList();
+        EventWifiNetworkList eventListCellular = m_EventMgrPtr->getEventCellularNetworkList();
+        if (eventListWifi.size() > 0) {
+            for (EventWifiNetworkList::iterator it = eventListWifi.begin(); it != eventListWifi.end(); it++) {
+                (*it)->getWatchValue();
+            }
+        }
+        if (eventListCellular.size() > 0) {
+            for (EventCellularNetworkList::iterator it = eventListCellular.begin(); it != eventListCellular.end(); it++) {
+                (*it)->getWatchValue();
+            }
+        }
+    } else if (watchType == WATCH_TYPE_CPU) {
+        EventCpuList eventList = m_EventMgrPtr->getEventCpuList();
+        for (EventCpuList::iterator it = eventList.begin(); it != eventList.end(); it++) {
+            (*it)->getWatchValue();
+        }
+    } else if (watchType == WATCH_TYPE_STORAGE) {
+        EventStorageList eventList = m_EventMgrPtr->getEventStorageList();
+        for (EventStorageList::iterator it = eventList.begin(); it != eventList.end(); it++) {
+        int storageCnt = 1;
+        int sdcardState = 0;
+        int usbhostState = 0;
+        if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0) {
+            if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED) {
+                storageCnt++;
+            }
+        }
+        if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
+            if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
+                storageCnt++;
+            }
+        }
+        LogDebug("storage cnt : " << storageCnt);
+            (*it)->getWatchValue(storageCnt);
+        }
+    }else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
+        EventDeviceOrientationList eventList = m_EventMgrPtr->getEventDeviceOrientationList();
+        for (EventDeviceOrientationList::iterator it = eventList.begin(); it != eventList.end(); it++) {
+            (*it)->getWatchValue();
+        }
+    }
+}
+
+connection_h Systeminfo::getConnectionHandle()
+{
+    return m_connectionHandle;
+}
+
+JSValueRef Systeminfo::getCpuValue(JSContextRef context)
+{
+    LogDebug("enter");
+    Converter converter(context);
+
+    CpuPropertiesPtr cpuPtr(new CpuProperties());
+    FILE *fp = NULL;
+    unsigned long long usr = 0, nice = 0, system = 0, idle = 0, cpuUsage = 0, diffIdle = 0, total = 0;
+
+    fp = fopen("/proc/stat", "r");
+    if(fp == NULL) {
+        return JSValueMakeNull(context);
+    }
+    
+    if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
+        total = usr + nice + system + idle - m_cpuInfo.usr - m_cpuInfo.nice - m_cpuInfo.system - m_cpuInfo.idle;
+        diffIdle = idle-m_cpuInfo.idle;
+        if ((total > 0) && (diffIdle > 0)) {
+            cpuUsage = diffIdle * 100 / total;
+        cpuPtr->load = (double)cpuUsage / 100.0;
+        m_cpuInfo.usr = usr;
+        m_cpuInfo.system = system;
+        m_cpuInfo.nice = nice;
+        m_cpuInfo.idle = idle;        
+            LogDebug("cpu load : " << cpuPtr->load);
+        }
+    }
+
+    fclose(fp);
+    return Tizen1_0::JSCpuInfo::createJSObject(context, cpuPtr);
+}
+
+void Systeminfo::OnRequestReceived(const EventGetSysteminfoPtr& event)
+{
+    LogDebug("enter");
+    event->processGetValue((void *)m_connectionHandle);
+}
+
+void Systeminfo::OnRequestReceived(const EventWatchSysteminfoPtr& event)
+{
+    WatchOption watchOption = event->getWatchOption();
+
+    event->switchToManualAnswer();
+    event->setCancelAllowed(true);
+
+    switch(event->getWatchType()) {
+        case WATCH_TYPE_BATTERY:
+            if ((m_EventMgrPtr->getEventBatteryList()).size() == 1) {
+                vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CAPACITY, BatteryValueCallback, (void *)this);
+                vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, BatteryValueCallback, (void *)this);
+            }
+            break;
+        case WATCH_TYPE_DISPLAY:
+            if ((m_EventMgrPtr->getEventDisplayList()).size() == 1) {
+                vconf_notify_key_changed(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, DisplayValueCallback, (void *)this);
+            }
+            break;
+        case WATCH_TYPE_NETWORK:
+            if ((m_EventMgrPtr->getEventNetworkList()).size() == 1) {
+                connection_set_type_changed_cb(m_connectionHandle, NetworkTypeValueCallback, (void *)this);
+            }
+            break;
+        case WATCH_TYPE_WIFINETWORK:
+            if ((m_EventMgrPtr->getEventWifiNetworkList()).size() == 1) {
+                if (m_networkRegist == REGIST_NOT) {
+                    connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
+                    m_networkRegist = REGIST_WIFI;
+                } else if (m_networkRegist== REGIST_CELLULAR) {
+                    m_networkRegist = REGIST_ALL;
+                }
+            }
+            break;
+        case WATCH_TYPE_CELLULARNETWORK:
+            if ((m_EventMgrPtr->getEventCellularNetworkList()).size() == 1) {
+                if (m_networkRegist == REGIST_NOT) {
+                    connection_set_ip_address_changed_cb(m_connectionHandle, NetworkValueCallback, (void *)this);
+                    m_networkRegist = REGIST_CELLULAR;
+                } else if (m_networkRegist== REGIST_WIFI) {
+                    m_networkRegist = REGIST_ALL;
+                }
+            }
+            break;
+        case WATCH_TYPE_STORAGE:
+            if ((m_EventMgrPtr->getEventStorageList()).size() == 1) {
+                if (!m_storageTimer) {
+                    m_storageTimer = ecore_timer_add(1, StorageValueCallback, this);
+                    ecore_timer_thaw(m_storageTimer);
+                }
+            }
+            break;
+        case WATCH_TYPE_CPU:
+            if ((m_EventMgrPtr->getEventCpuList()).size() == 1) {
+                if (!m_cpuTimer) {
+                    m_cpuTimer = ecore_timer_add(1, CpuValueCallback, this);
+                    ecore_timer_thaw(m_cpuTimer);
+                }
+            }
+            break;
+        case WATCH_TYPE_DEVICE_ORIENTATION:
+            LogDebug("regist sensor");
+            if ((m_EventMgrPtr->getEventDeviceOrientationList()).size() == 1) {
+                int state = sf_register_event(m_sensorHandle, ACCELEROMETER_EVENT_ROTATION_CHECK, NULL, OrientationValueCallback, (void *)this);
+                if (state < 0) {
+                    LogDebug("sensor_register_cb fail to gather data");
+                } else if (state == 0) {
+                    LogDebug("sensor_register_cb success to gather data");
+                }
+            } else {
+                LogDebug("already regist");
+            }
+            break;
+    }
+    event->processGetValue();
+    event->setTimer();
+}
+
+////////////////////////////////////////////////////////////////////////////////////////
+
+Systeminfo::EventMgr::EventMgr()
+{
+}
+
+Systeminfo::EventMgr::~EventMgr()
+{
+}
+
+void Systeminfo::EventMgr::clearAllEvent()
+{
+    DPL::Mutex::ScopedLock lock(&m_synchro);
+
+    while (!m_eventBatteryList.empty()) {
+        EventWatchSysteminfoPtr event = m_eventBatteryList.front();
+        LogDebug("removing EventId=" << event->getId());
+        event->clearWatch();
+        m_eventBatteryList.pop_front();
+    }
+    while (!m_eventDisplayList.empty()) {
+        EventWatchSysteminfoPtr event = m_eventDisplayList.front();
+        LogDebug("removing EventId=" << event->getId());
+        event->clearWatch();
+        m_eventDisplayList.pop_front();
+    }
+    while (!m_eventWifiNetworkList.empty()) {
+        EventWatchSysteminfoPtr event = m_eventWifiNetworkList.front();
+        LogDebug("removing EventId=" << event->getId());
+        event->clearWatch();
+        m_eventWifiNetworkList.pop_front();
+    }
+    while (!m_eventCelluarNetworkList.empty()) {
+        EventWatchSysteminfoPtr event = m_eventCelluarNetworkList.front();
+        LogDebug("removing EventId=" << event->getId());
+        event->clearWatch();
+        m_eventCelluarNetworkList.pop_front();
+    }
+    while (!m_eventStorageList.empty()) {
+        EventWatchSysteminfoPtr event = m_eventStorageList.front();
+        LogDebug("removing EventId=" << event->getId());
+        event->clearWatch();
+        m_eventStorageList.pop_front();
+    }
+    while (!m_eventCpuList.empty()) {
+        EventWatchSysteminfoPtr event = m_eventCpuList.front();
+        LogDebug("removing EventId=" << event->getId());
+        event->clearWatch();
+        m_eventCpuList.pop_front();
+    }
+    while (!m_eventSimList.empty()) {
+        EventWatchSysteminfoPtr event = m_eventSimList.front();
+        LogDebug("removing EventId=" << event->getId());
+        event->clearWatch();
+        m_eventSimList.pop_front();
+    }
+    while (!m_eventDeviceOrientationList.empty()) {
+        EventWatchSysteminfoPtr event = m_eventDeviceOrientationList.front();
+        LogDebug("removing EventId=" << event->getId());
+        event->clearWatch();
+        m_eventDeviceOrientationList.pop_front();
+    }
+}
+
+void Systeminfo::EventMgr::addEvent(const EventWatchSysteminfoPtr& arg, const int watchType)
+{
+    DPL::Mutex::ScopedLock lock(&m_synchro);
+
+    if (watchType == WATCH_TYPE_BATTERY){
+        m_eventBatteryList.push_back(arg);
+        LogDebug("Event Battery list size=" << m_eventBatteryList.size());
+    } else if (watchType == WATCH_TYPE_DISPLAY) {
+        m_eventDisplayList.push_back(arg);
+        LogDebug("Event display list size=" << m_eventDisplayList.size());
+    } else if (watchType == WATCH_TYPE_WIFINETWORK) {
+        m_eventWifiNetworkList.push_back(arg);
+        LogDebug("Event wifi network list size=" << m_eventWifiNetworkList.size());
+    } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
+        m_eventCelluarNetworkList.push_back(arg);
+        LogDebug("Event cellular network list size=" << m_eventCelluarNetworkList.size());
+    } else if (watchType == WATCH_TYPE_STORAGE) {
+        m_eventStorageList.push_back(arg);
+        LogDebug("Event storage list size=" << m_eventStorageList.size());
+    } else if (watchType == WATCH_TYPE_CPU) {
+        m_eventCpuList.push_back(arg);
+        LogDebug("Event cpu list size=" << m_eventCpuList.size());
+    } else if (watchType == WATCH_TYPE_SIM) {
+        m_eventSimList.push_back(arg);
+        LogDebug("Event sim list size=" << m_eventSimList.size());
+    } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
+        m_eventDeviceOrientationList.push_back(arg);
+        LogDebug("Event device orientation list size=" << m_eventDeviceOrientationList.size());
+    } else if (watchType == WATCH_TYPE_NETWORK) {
+        m_eventNetworkList.push_back(arg);
+        LogDebug("Event network list size=" << m_eventNetworkList.size());
+    }
+}
+
+void Systeminfo::EventMgr::removeEvent(WatchId id, const int watchType)
+{
+    DPL::Mutex::ScopedLock lock(&m_synchro);
+    LogDebug("Event id : " << id);
+
+    EventWatchSysteminfoPtr event(NULL);
+
+    LogDebug("trying to delete event, id=" << id);
+
+    if (watchType == WATCH_TYPE_BATTERY) {
+        for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
+            if (id == (*it)->getId()) {
+                event = *it;
+                break;
+            }
+        }
+        if (!event) {
+            LogError("event id not in the list, nothing to do");
+            return;
+        }
+
+        LogDebug("event Battery list size=" << m_eventBatteryList.size());
+        m_eventBatteryList.remove(event);
+        LogDebug( "event removed, event Battery list size=" << m_eventBatteryList.size());
+    } else if (watchType == WATCH_TYPE_DISPLAY) {
+        for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
+            if (id == (*it)->getId()) {
+                event = *it;
+                break;
+            }
+        }
+        if (!event) {
+            LogError("event id not in the list, nothing to do");
+            return;
+        }
+
+        LogDebug("event display list size=" << m_eventDisplayList.size());
+        m_eventDisplayList.remove(event);
+        LogDebug( "event removed, event display list size=" << m_eventDisplayList.size());
+    } else if (watchType == WATCH_TYPE_WIFINETWORK) {
+        for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
+        if (id == (*it)->getId()) {
+            event = *it;
+            break;
+        }
+    }
+    if (!event) {
+        LogError("event id not in the list, nothing to do");
+        return;
+    }
+
+        LogDebug("event wifi network list size=" << m_eventWifiNetworkList.size());
+        m_eventWifiNetworkList.remove(event);
+        LogDebug( "event removed, event wifi network list size=" << m_eventCelluarNetworkList.size());
+    } else if (watchType == WATCH_TYPE_CELLULARNETWORK) {
+        for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
+            if (id == (*it)->getId()) {
+                event = *it;
+                break;
+            }
+        }
+        if (!event) {
+            LogError("event id not in the list, nothing to do");
+            return;
+        }
+
+        LogDebug("event cellular network list size=" << m_eventCelluarNetworkList.size());
+        m_eventCelluarNetworkList.remove(event);
+        LogDebug( "event removed, event cellular network list size=" << m_eventCelluarNetworkList.size());
+    } else if (watchType == WATCH_TYPE_STORAGE) {
+        for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
+            if (id == (*it)->getId()) {
+                event = *it;
+                break;
+            }
+        }
+        if (!event) {
+            LogError("event id not in the list, nothing to do");
+            return;
+        }
+
+        LogDebug("event storage list size=" << m_eventStorageList.size());
+        m_eventStorageList.remove(event);
+        LogDebug( "event removed, event storage list size=" << m_eventStorageList.size());
+    } else if (watchType == WATCH_TYPE_CPU) {
+        for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
+            if (id == (*it)->getId()) {
+                event = *it;
+                break;
+            }
+        }
+        if (!event) {
+            LogError("event id not in the list, nothing to do");
+            return;
+        }
+
+        LogDebug("event cpu list size=" << m_eventCpuList.size());
+        m_eventCpuList.remove(event);
+        LogDebug( "event removed, event cpu list size=" << m_eventCpuList.size());
+    } else if (watchType == WATCH_TYPE_SIM) {
+        for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
+            if (id == (*it)->getId()) {
+                event = *it;
+                break;
+            }
+        }
+        if (!event) {
+            LogError("event id not in the list, nothing to do");
+            return;
+        }
+
+        LogDebug("event sim list size=" << m_eventSimList.size());
+        m_eventSimList.remove(event);
+        LogDebug( "event removed, event sim list size=" << m_eventSimList.size());
+    } else if (watchType == WATCH_TYPE_DEVICE_ORIENTATION) {
+        for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
+            if (id == (*it)->getId()) {
+                event = *it;
+                break;
+            }
+        }
+        if (!event) {
+            LogError("event id not in the list, nothing to do");
+            return;
+        }
+
+        LogDebug("event device orientation list size=" << m_eventDeviceOrientationList.size());
+        m_eventDeviceOrientationList.remove(event);
+        LogDebug( "event removed, event device orientation list size=" << m_eventDeviceOrientationList.size());
+    } else if (watchType == WATCH_TYPE_NETWORK) {
+        for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
+            if (id == (*it)->getId()) {
+                event = *it;
+                break;
+            }
+        }
+        if (!event) {
+            LogError("event id not in the list, nothing to do");
+            return;
+        }
+
+        LogDebug("event network list size=" << m_eventNetworkList.size());
+        m_eventNetworkList.remove(event);
+        LogDebug( "event removed, event network list size=" << m_eventNetworkList.size());
+    }
+}
+
+const int Systeminfo::EventMgr::getWatchType(const long id)
+{
+    DPL::Mutex::ScopedLock lock(&m_synchro);
+
+    EventWatchSysteminfoPtr event(NULL);
+
+    for (EventBatteryList::iterator it = m_eventBatteryList.begin(); it != m_eventBatteryList.end(); it++) {
+        if (id == (*it)->getId()) {
+            event = *it;
+            break;
+        }
+    }
+
+    for (EventDisplayList::iterator it = m_eventDisplayList.begin(); it != m_eventDisplayList.end(); it++) {
+        if (id == (*it)->getId()) {
+            event = *it;
+            break;
+        }
+    }
+
+    for (EventWifiNetworkList::iterator it = m_eventWifiNetworkList.begin(); it != m_eventWifiNetworkList.end(); it++) {
+        if (id == (*it)->getId()) {
+            event = *it;
+            break;
+        }
+    }
+
+    for (EventCellularNetworkList::iterator it = m_eventCelluarNetworkList.begin(); it != m_eventCelluarNetworkList.end(); it++) {
+        if (id == (*it)->getId()) {
+            event = *it;
+            break;
+        }
+    }
+
+    for (EventStorageList::iterator it = m_eventStorageList.begin(); it != m_eventStorageList.end(); it++) {
+        if (id == (*it)->getId()) {
+            event = *it;
+            break;
+        }
+    }
+
+    for (EventCpuList::iterator it = m_eventCpuList.begin(); it != m_eventCpuList.end(); it++) {
+        if (id == (*it)->getId()) {
+            event = *it;
+            break;
+        }
+    }
+
+    for (EventSimList::iterator it = m_eventSimList.begin(); it != m_eventSimList.end(); it++) {
+        if (id == (*it)->getId()) {
+            event = *it;
+            break;
+        }
+    }
+
+    for (EventDeviceOrientationList::iterator it = m_eventDeviceOrientationList.begin(); it != m_eventDeviceOrientationList.end(); it++) {
+        if (id == (*it)->getId()) {
+            event = *it;
+            break;
+        }
+    }
+
+    for (EventNetworkList::iterator it = m_eventNetworkList.begin(); it != m_eventNetworkList.end(); it++) {
+        if (id == (*it)->getId()) {
+            event = *it;
+            break;
+        }
+    }
+
+    if (!event) {
+        LogError("event id not in the list, nothing to do");
+        return WATCH_TYPE_UNKNOWN;
+    }
+
+    return event->getWatchType();
+}
+
+EventBatteryList Systeminfo::EventMgr::getEventBatteryList()
+{
+    return m_eventBatteryList;
+}
+
+EventDisplayList Systeminfo::EventMgr::getEventDisplayList()
+{
+    return m_eventDisplayList;
+}
+
+EventNetworkList Systeminfo::EventMgr::getEventNetworkList()
+{
+    return m_eventNetworkList;
+}
+
+EventWifiNetworkList Systeminfo::EventMgr::getEventWifiNetworkList()
+{
+    return m_eventWifiNetworkList;
+}
+
+EventCellularNetworkList Systeminfo::EventMgr::getEventCellularNetworkList()
+{
+    return m_eventCelluarNetworkList;
+}
+
+EventStorageList Systeminfo::EventMgr::getEventStorageList()
+{
+    return m_eventStorageList;
+}
+
+EventCpuList Systeminfo::EventMgr::getEventCpuList()
+{
+    return m_eventCpuList;
+}
+
+EventSimList Systeminfo::EventMgr::getEventSimList()
+{
+    return m_eventSimList;
+}
+
+EventDeviceOrientationList Systeminfo::EventMgr::getEventDeviceOrientationList()
+{
+    return m_eventDeviceOrientationList;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////
+
+PROPERTY_GET_SYSTEMINFO_DEFINITION(Battery) {
+    BatteryPropertiesPtr BatteryPtr(new BatteryProperties());
+    int value=0;
+    int value2=0;
+
+    if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value) != 0) {
+        return JSValueMakeNull(context);
+    } else {
+        BatteryPtr->level = (double)(value)/CPU_POWER_DEVICE_VALUE;
+    }
+
+    if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value2) != 0) {
+        return JSValueMakeNull(context);
+    } else {
+        BatteryPtr->isCharging = (value2 == 0) ? false : true;
+    }
+
+    return Tizen1_0::JSBatteryInfo::createJSObject(context, BatteryPtr);
+}
+
+PROPERTY_GET_SYSTEMINFO_DEFINITION(Cpu) {
+    Converter converter(context);
+
+    CpuPropertiesPtr cpuPtr(new CpuProperties());
+    FILE *fp = NULL;
+    unsigned long long usr = 0, nice = 0, system = 0, idle = 0, total = 0, cpuUsage = 0;
+
+    fp = fopen("/proc/stat", "r");
+    if(fp == NULL) {
+        return JSValueMakeNull(context);
+    }
+    
+    if (fscanf(fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle) > 0) {
+        total = usr + nice + system + idle;
+        if ((total > 0) && (idle > 0)) {
+            cpuUsage = idle * 100 / total;
+        cpuPtr->load = (double)cpuUsage / 100.0;
+            LogDebug("cpu load : " << cpuPtr->load);
+        }
+    }
+
+    fclose(fp);
+    return Tizen1_0::JSCpuInfo::createJSObject(context, cpuPtr);
+}
+
+PROPERTY_GET_SYSTEMINFO_DEFINITION(Storage) {
+    Converter converter(context);
+    int sdcardState=0;
+    int usbhostState=0;
+    int storageCnt=0;
+    struct statfs fs;
+    StoragePropertiesPtr internal(new StorageProperties());
+    StoragePropertiesPtr mmc(new StorageProperties());
+    StoragePropertiesPtr usbhost(new StorageProperties());
+    std::vector <JSObjectRef> storagelist;
+    
+    if (statfs(STORAGE_INTERNAL_PATH, &fs) < 0) {
+        return JSValueMakeNull(context);
+    }
+
+    internal->type = "INTERNAL";
+    internal->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
+    internal->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
+    internal->isRemoveable = false;
+    storagelist.push_back(Tizen1_0::JSStorageInfo::createJSObject(context, internal));
+    storageCnt++;
+
+    if(vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState) == 0){
+        if(sdcardState == VCONFKEY_SYSMAN_MMC_MOUNTED){
+            storageCnt++;
+            if (statfs(STORAGE_SDCARD_PATH, &fs) < 0) {
+                return JSValueMakeNull(context);
+            }
+            mmc->type = "MMC";
+            mmc->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
+            mmc->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
+            mmc->isRemoveable = true;
+            storagelist.push_back(Tizen1_0::JSStorageInfo::createJSObject(context, mmc));
+        }
+    }
+
+    if(vconf_get_int(VCONFKEY_SYSMAN_USB_HOST_STATUS, &usbhostState) == 0) {
+        if(usbhostState == VCONFKEY_SYSMAN_USB_HOST_CONNECTED) {
+            storageCnt++;
+            if (statfs(STORAGE_USBHOST_PATH, &fs) < 0)    {
+                return JSValueMakeNull(context);
+            }
+            usbhost->type = "USB_HOST";
+            usbhost->capacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_blocks;
+            usbhost->availableCapacity = (unsigned long long)fs.f_bsize * (unsigned long long)fs.f_bavail;
+            usbhost->isRemoveable = true;
+            storagelist.push_back(Tizen1_0::JSStorageInfo::createJSObject(context, usbhost));
+        }
+    }
+
+    return JSObjectMakeArray(context, storageCnt, storagelist.data(), NULL);
+}
+
+PROPERTY_GET_SYSTEMINFO_DEFINITION(Display) {
+    Converter converter(context);
+
+    DisplayPropertiesPtr display(new DisplayProperties());
+    int brightness=0, dotsPerInchX=0, dotsPerInchY=0, physicalW=0, physicalH=0, resolutionW=0, resolutionH=0;
+
+    if(vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness) == 0) {
+        display->brightness = (double)(brightness)/DISPLAY_BRIGHTNESS_DIVIDE_VALUE;
+        LogDebug("brightness : " << display->brightness);
+    }
+
+    if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &resolutionW) == SYSTEM_INFO_ERROR_NONE) {
+        display->resolutionWidth = resolutionW;
+        LogDebug("resolutionWidth : " << display->resolutionWidth);
+    }
+    if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_HEIGHT, &resolutionH) == SYSTEM_INFO_ERROR_NONE) {
+        display->resolutionHeight = resolutionH;
+        LogDebug("resolutionHeight : " << display->resolutionHeight);
+    }
+    if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchX) == SYSTEM_INFO_ERROR_NONE) {
+        display->dotsPerInchWidth = dotsPerInchX;
+        LogDebug("dotsPerInchWidth : " << display->dotsPerInchWidth);
+    }
+    if (system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &dotsPerInchY) == SYSTEM_INFO_ERROR_NONE) {
+        display->dotsPerInchHeight = dotsPerInchY;
+        LogDebug("dotsPerInchHeight : " << display->dotsPerInchHeight);
+    }
+    if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &physicalH) == SYSTEM_INFO_ERROR_NONE) {
+        display->physicalHeight = physicalH;
+        LogDebug("physicalHeight : " << display->physicalHeight);
+    }
+    if (system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &physicalW) == SYSTEM_INFO_ERROR_NONE) {
+        display->physicalWidth = physicalW;
+        LogDebug("physicalWidth : " << display->physicalWidth);
+    }
+
+    return Tizen1_0::JSDisplayInfo::createJSObject(context, display);
+}
+
+PROPERTY_GET_SYSTEMINFO_DEFINITION(Network) {
+    LogDebug("enter");
+    Converter converter(context);
+    NetworkPropertiesPtr Network(new NetworkProperties());
+    connection_h connectionHandle = (connection_h)handle;    
+    connection_type_e connectionType;
+    int networkType = 0;
+
+    if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
+        LogDebug("get connection type is failed");
+        return Tizen1_0::JSNetworkInfo::createJSObject(context, Network);
+    }
+
+    if (connectionType == CONNECTION_TYPE_WIFI) {
+        LogDebug("wifi network");
+        Network->networkType= "WIFI";
+    } else if (connectionType == CONNECTION_TYPE_CELLULAR) {
+        if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) {
+            if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) {
+                Network->networkType= "NONE";
+            } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) {
+                Network->networkType= "2G";
+            } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) {
+                Network->networkType= "2.5";
+            } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) {
+                Network->networkType= "3G";
+            } else {
+                Network->networkType= "NONE";
+            }
+        }
+    } else {
+        Network->networkType= "NONE";
+    }
+
+    return Tizen1_0::JSNetworkInfo::createJSObject(context, Network);
+}
+
+PROPERTY_GET_SYSTEMINFO_DEFINITION(WifiNetwork) {
+    Converter converter(context);
+    WifiNetworkPropertiesPtr wifiNetwork(new WifiNetworkProperties());
+    connection_h connectionHandle = (connection_h)handle;    
+    connection_type_e connectionType;
+    connection_profile_h profileHandle = NULL;
+    connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
+    char* ipAddr = NULL;
+    char* bssid = NULL;
+    int rssi = 0;
+
+    if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
+        return Tizen1_0::JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
+    }
+
+    if (connectionType == CONNECTION_TYPE_WIFI) {
+        wifiNetwork->status = "ON";
+    } else {
+        wifiNetwork->status = "OFF";
+        return Tizen1_0::JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
+    }
+
+    if (connection_get_current_profile(connectionHandle, &profileHandle) != CONNECTION_ERROR_NONE) {
+        return Tizen1_0::JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
+    }
+
+    if (connection_profile_get_wifi_bssid(profileHandle, &bssid) == CONNECTION_ERROR_NONE) {
+        wifiNetwork->ssid = bssid;
+        free(bssid);
+    }
+
+    if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
+        wifiNetwork->ipAddress = ipAddr;
+        free(ipAddr);
+    }
+
+    if (connection_profile_get_wifi_rssi(profileHandle, &rssi) == CONNECTION_ERROR_NONE) {
+        wifiNetwork->signalStrength = (double) rssi/WIFI_SIGNAL_STRENGTH_DIVIDE_VALUE;
+    }
+
+    return Tizen1_0::JSWifiNetworkInfo::createJSObject(context, wifiNetwork);
+}
+
+PROPERTY_GET_SYSTEMINFO_DEFINITION(CellularNetwork) {
+    Converter converter(context);
+    CellularNetworkPropertiesPtr cellularNetwork(new CellularNetworkProperties());
+    connection_h connectionHandle = (connection_h)handle;    
+    connection_type_e connectionType;
+    connection_profile_h profileHandle = NULL;
+    connection_address_family_e addressFamily = CONNECTION_ADDRESS_FAMILY_IPV4;
+    char* ipAddr = NULL;
+    char* apn = NULL;
+    int plmn = 0, cellid = 0, lac = 0, isRoaming = 0;
+
+    if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) == 0) {
+        cellularNetwork->mcc = plmn / 1000;
+        cellularNetwork->mnc = plmn % 1000;
+    }
+    
+    if (vconf_get_int(VCONFKEY_TELEPHONY_CELLID, &cellid) == 0) {
+        cellularNetwork->cellId = cellid;
+    }
+    
+    if (vconf_get_int(VCONFKEY_TELEPHONY_LAC, &lac) == 0) {
+        cellularNetwork->lac = lac;
+    }
+
+    if (vconf_get_int(VCONFKEY_TELEPHONY_SVC_ROAM, &isRoaming) == 0) {
+        if (isRoaming) {
+            cellularNetwork->isRoaming = true;
+        } else {
+            cellularNetwork->isRoaming = false;
+        }
+    }
+
+    if (connection_get_type(connectionHandle, &connectionType) != CONNECTION_ERROR_NONE) {
+        return Tizen1_0::JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
+    }
+
+    if (connectionType == CONNECTION_TYPE_CELLULAR) {
+        cellularNetwork->status = "ON";
+        if (connection_get_current_profile(connectionHandle, &profileHandle) == CONNECTION_ERROR_NONE) {
+            if (connection_profile_get_cellular_apn(profileHandle, &apn) == CONNECTION_ERROR_NONE) {
+                cellularNetwork->apn = apn;
+                free(apn);
+            }
+        
+            if (connection_profile_get_ip_address(profileHandle, addressFamily, &ipAddr) == CONNECTION_ERROR_NONE) {
+                cellularNetwork->ipAddress = ipAddr;
+                free(ipAddr);
+            }
+        }
+    } else {
+        cellularNetwork->status = "OFF";
+    }
+
+    return Tizen1_0::JSCellularNetworkInfo::createJSObject(context, cellularNetwork);
+}
+
+PROPERTY_GET_SYSTEMINFO_DEFINITION(SIM) {
+    Converter converter(context);
+    SIMPropertiesPtr SIM(new SIMProperties());
+
+    char* full_name = NULL;
+    char* short_name = NULL;
+    char* msisdn = NULL;
+    char* icc_id = NULL;
+    char* mcc = NULL;
+    char* mnc = NULL;
+    char* msin = NULL;
+    char* spn = NULL;
+    int ret = SIM_ERROR_NONE;
+
+    ret = sim_get_cphs_operator_name(&full_name, &short_name);
+    if (ret == SIM_ERROR_NONE) {
+        if (full_name) {
+            SIM->operatorName = full_name;
+            LogDebug("operatorName : " << SIM->operatorName);
+            free(full_name);
+        } else if (short_name) {
+            SIM->operatorName = short_name;
+            LogDebug("operatorName : " << SIM->operatorName);
+            free(short_name);
+        }
+    }
+
+    ret = sim_get_subscriber_number(&msisdn);
+    if (ret == SIM_ERROR_NONE) {
+        if (msisdn) {
+            SIM->msisdn = msisdn;
+            LogDebug("msisdn : " << SIM->msisdn);
+            free(msisdn);
+        }
+    }
+
+    ret = sim_get_icc_id(&icc_id);
+    if (ret == SIM_ERROR_NONE) {
+        if (icc_id) {
+            SIM->iccid = icc_id;
+            LogDebug("iccid : " << SIM->iccid);
+            free(icc_id);
+        }
+    }
+
+    ret = sim_get_mcc(&mcc);
+    if (ret == SIM_ERROR_NONE) {
+        if (mcc) {
+            SIM->mcc = atoi(mcc);
+            LogDebug("mcc : " << SIM->mcc);
+            free(mcc);
+        }
+    }
+
+    ret = sim_get_mnc(&mnc);
+    if (ret == SIM_ERROR_NONE) {
+        if (mnc) {
+            SIM->mnc = atoi(mnc);
+            LogDebug("mnc : " << SIM->mnc);
+            free(mnc);
+        }
+    }
+
+    ret = sim_get_msin(&msin);
+    if (ret == SIM_ERROR_NONE) {
+        if (msin) {
+            SIM->msin = msin;
+            LogDebug("msin : " << SIM->msin);
+            free(msin);
+        }
+    }
+
+    ret = sim_get_spn(&spn);
+    if (ret == SIM_ERROR_NONE) {
+        if (spn) {
+            SIM->spn = spn;
+            LogDebug("spn : " << SIM->spn);
+            free(spn);
+        }
+    }
+
+    return Tizen1_0::JSSIMInfo::createJSObject(context, SIM);
+}
+
+PROPERTY_GET_SYSTEMINFO_DEFINITION(DeviceOrientation) {
+    LogDebug("enter");
+    Converter converter(context);
+    DeviceOrientationPropertiesPtr deviceOrientation(new DeviceOrientationProperties());
+
+    unsigned long rotation = 0;
+    int handleOrientaion = 0;
+
+    handleOrientaion = sf_connect(ACCELEROMETER_SENSOR);
+    LogDebug("handleOrientaion : " << handleOrientaion);
+    if (handleOrientaion < 0) {
+        LogDebug ("sensor attach fail");
+        return Tizen1_0::JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
+    }
+    int state = sf_start(handleOrientaion, 0);
+    if(state < 0) {
+        LogDebug("start failed");
+    }
+
+    int ret_val = sf_check_rotation(&rotation);
+    if (ret_val < 0) {
+        LogDebug("sf_check_rotation fail to gather data\n");
+    }
+
+    LogDebug(" rotation value = " << rotation);
+
+    switch (rotation) {
+        case 0:
+        case ROTATION_PORTRAIT_TOP:
+            LogDebug("my_callback_func received data (PORTRAIT_TOP|HEAD_CENTER)\n");
+            deviceOrientation->status = "PORTRAIT_PRIMARY";
+            break;
+        case ROTATION_LANDSCAPE_RIGHT:
+            LogDebug("my_callback_func received data (LANDSCAPE|HEAD_RIGHT)\n");
+            deviceOrientation->status = "LANDSCAPE_PRIMARY";
+            break;
+        case ROTATION_PORTRAIT_BTM:
+            LogDebug("my_callback_func received data (PORTRAIT_BTM|HEAD_CENTER)\n");
+            deviceOrientation->status = "PORTRAIT_SECONDARY";
+            break;
+        case ROTATION_LANDSCAPE_LEFT:
+            LogDebug("my_callback_func received data (LANDSCAPE|HEAD_LEFT)\n");
+            deviceOrientation->status = "LANDSCAPE_SECONDARY";
+            break;
+        default:
+            LogDebug(" received data unexpected\n");
+            break;
+    }
+
+       state = sf_stop(handleOrientaion);
+       LogDebug("handleOrientaion 1  state = " << state);
+
+       state = sf_disconnect(handleOrientaion);
+       LogDebug("handleOrientaion  state =" << state);
+
+    return Tizen1_0::JSDeviceOrientationInfo::createJSObject(context, deviceOrientation);
+}
+
+PROPERTY_GET_SYSTEMINFO_DEFINITION(Build) {
+    LogDebug("enter");
+    Converter converter(context);
+    BuildPropertiesPtr Build(new BuildProperties());
+
+    char* model = NULL;
+
+    if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &model) == SYSTEM_INFO_ERROR_NONE) {
+        if (model != NULL) {
+            LogDebug("model : " << model);
+            Build->model = model;
+            free(model);
+        }
+    }
+
+    return Tizen1_0::JSBuildInfo::createJSObject(context, Build);
+}
+
+
+}
+}
+}
diff --git a/src/platform/Tizen/Systeminfo/Systeminfo.h b/src/platform/Tizen/Systeminfo/Systeminfo.h
new file mode 100755 (executable)
index 0000000..674bd41
--- /dev/null
@@ -0,0 +1,217 @@
+//
+// 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_PLATFORM_SYSTEMINFO_H_
+#define WRTPLUGINS_PLATFORM_SYSTEMINFO_H_
+
+#include <map>
+#include <vector>
+#include <string>
+#include <sys/vfs.h>
+#include <vconf.h>
+#include <sensor.h>
+#include <sensors.h>
+#include <net_connection.h>
+#include <sim.h>
+#include <system_info.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/noncopyable.h>
+#include <API/Systeminfo/ISysteminfo.h>
+#include <API/Systeminfo/SysteminfoFactory.h>
+#include <API/Systeminfo/EventGetSysteminfo.h>
+#include <API/Systeminfo/EventWatchSysteminfo.h>
+#include <API/Systeminfo/BaseProperties.h>
+#include <Commons/Emitters.h>
+#include <CommonsJavaScript/Converter.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace Systeminfo {
+
+enum {
+    WATCH_TYPE_UNKNOWN = 0,
+    WATCH_TYPE_BATTERY = 1,
+    WATCH_TYPE_DISPLAY = 2,
+    WATCH_TYPE_WIFINETWORK = 3,
+    WATCH_TYPE_CELLULARNETWORK = 4,
+    WATCH_TYPE_NETWORK = 5,
+    WATCH_TYPE_STORAGE = 6,
+    WATCH_TYPE_CPU = 8,
+    WATCH_TYPE_SIM = 9,
+    WATCH_TYPE_DEVICE_ORIENTATION = 10,
+    WATCH_TYPE_NETWORK_ALL = 11
+};
+
+enum {
+    REGIST_NOT = 0,
+    REGIST_WIFI = 1,
+    REGIST_CELLULAR =2,
+    REGIST_ALL = 3
+};
+
+struct cpuInfo {
+    unsigned long long usr;
+    unsigned long long nice;
+    unsigned long long system;
+    unsigned long long idle;
+    unsigned long long usage;
+    cpuInfo() : usr(0), nice(0), system(0), idle(0), usage(0)
+    {
+    }
+};
+
+typedef DPL::Atomic::ValueType WatchId;
+
+#define PROPERTY_DECLARATION(className, propertyName, watchType) \
+    class className : public Api::Systeminfo::BaseProperty { \
+      public: \
+        explicit className() : Api::Systeminfo::BaseProperty() { \
+        } \
+        JSValueRef getValue(JSContextRef context, void* handle) const; \
+        const char* getProperty() const \
+        { \
+            return propertyName; \
+        } \
+        const int getWatchType() const \
+        { \
+            return watchType; \
+        } \
+    };
+
+#define PROPERTY_GET_SYSTEMINFO_DEFINITION(className) JSValueRef className::getValue( \
+        JSContextRef context, void* handle) const
+
+PROPERTY_DECLARATION(Battery, "BATTERY", WATCH_TYPE_BATTERY)
+PROPERTY_DECLARATION(Cpu, "CPU", WATCH_TYPE_CPU)
+PROPERTY_DECLARATION(Storage, "STORAGE", WATCH_TYPE_STORAGE)
+PROPERTY_DECLARATION(Display, "DISPLAY", WATCH_TYPE_DISPLAY)
+PROPERTY_DECLARATION(Network, "NETWORK", WATCH_TYPE_NETWORK)
+PROPERTY_DECLARATION(WifiNetwork, "WIFI_NETWORK", WATCH_TYPE_WIFINETWORK)
+PROPERTY_DECLARATION(CellularNetwork, "CELLULAR_NETWORK", WATCH_TYPE_CELLULARNETWORK)
+PROPERTY_DECLARATION(SIM, "SIM", WATCH_TYPE_SIM)
+PROPERTY_DECLARATION(DeviceOrientation, "DEVICE_ORIENTATION", WATCH_TYPE_DEVICE_ORIENTATION)
+PROPERTY_DECLARATION(Build, "BUILD", WATCH_TYPE_UNKNOWN)
+
+
+typedef std::list<Api::Systeminfo::EventWatchSysteminfoPtr> EventBatteryList;
+typedef std::list<Api::Systeminfo::EventWatchSysteminfoPtr> EventDisplayList;
+typedef std::list<Api::Systeminfo::EventWatchSysteminfoPtr> EventNetworkList;
+typedef std::list<Api::Systeminfo::EventWatchSysteminfoPtr> EventWifiNetworkList;
+typedef std::list<Api::Systeminfo::EventWatchSysteminfoPtr> EventCellularNetworkList;
+typedef std::list<Api::Systeminfo::EventWatchSysteminfoPtr> EventStorageList;
+typedef std::list<Api::Systeminfo::EventWatchSysteminfoPtr> EventCpuList;
+typedef std::list<Api::Systeminfo::EventWatchSysteminfoPtr> EventSimList;
+typedef std::list<Api::Systeminfo::EventWatchSysteminfoPtr> EventDeviceOrientationList;
+
+class Systeminfo : public Api::Systeminfo::ISysteminfo
+{
+    friend class TizenApis::Api::Systeminfo::SysteminfoFactory;
+    friend class TizenApis::Api::Systeminfo::EventWatchSysteminfo;;
+
+  public:
+    
+    virtual ~Systeminfo();
+    virtual Api::Systeminfo::DeviceCapabilitiesPropertiesPtr getCapabilities();
+    virtual void get(const Api::Systeminfo::EventGetSysteminfoPtr& event);
+    virtual void watch(const Api::Systeminfo::EventWatchSysteminfoPtr& event);    
+    virtual Api::Systeminfo::BasePropertyPtr getBasePropertyPtr(JSContextRef context, JSValueRef property);
+    virtual void clearWatch(const long id);
+    void getWatchValue(const int watchType);
+    connection_h getConnectionHandle();
+    JSValueRef getCpuValue(JSContextRef context);
+
+       class EventMgr
+       {
+      public:
+        EventMgr();
+        ~EventMgr();
+
+        void clearAllEvent();
+        void addEvent(const Api::Systeminfo::EventWatchSysteminfoPtr& arg, const int watchType);
+        void removeEvent(WatchId id, const int watchType);
+        const int getWatchType(const long id);
+        EventBatteryList getEventBatteryList();
+        EventDisplayList getEventDisplayList();
+        EventNetworkList getEventNetworkList();
+        EventWifiNetworkList getEventWifiNetworkList();
+        EventCellularNetworkList getEventCellularNetworkList();
+        EventStorageList getEventStorageList();
+        EventCpuList getEventCpuList();
+        EventSimList getEventSimList();
+        EventDeviceOrientationList getEventDeviceOrientationList();
+               
+      private:
+        EventBatteryList m_eventBatteryList;
+        EventDisplayList m_eventDisplayList;
+        EventNetworkList m_eventNetworkList;
+        EventWifiNetworkList m_eventWifiNetworkList;
+        EventCellularNetworkList m_eventCelluarNetworkList;
+        EventStorageList m_eventStorageList;
+        EventCpuList m_eventCpuList;
+        EventSimList m_eventSimList;
+        EventDeviceOrientationList m_eventDeviceOrientationList;
+        DPL::Mutex m_synchro;
+    };
+    typedef DPL::SharedPtr<EventMgr> EventMgrPtr;
+
+  protected:
+    Systeminfo();
+    virtual void OnRequestReceived(const Api::Systeminfo::EventGetSysteminfoPtr& event);
+    virtual void OnRequestReceived(const Api::Systeminfo::EventWatchSysteminfoPtr& event);
+
+  private:
+    typedef std::map<std::string, Api::Systeminfo::BasePropertyPtr > mapProperties;
+    typedef DPL::Optional<mapProperties> OptionalProperty;
+
+    static OptionalProperty m_Property;
+    int m_networkRegist;
+    DPL::Mutex m_initializationMutex;
+    EventMgrPtr m_EventMgrPtr;
+    Ecore_Timer *m_storageTimer;
+    Ecore_Timer *m_cpuTimer;
+    int m_sensorHandle;
+    connection_h m_connectionHandle;
+    cpuInfo m_cpuInfo;
+};
+
+class SysteminfoAsyncPendingEvent
+{
+    public:
+    SysteminfoAsyncPendingEvent(void *thisObject, const Api::Systeminfo::EventGetSysteminfoPtr &event) :
+        m_thisObject(thisObject),
+        m_event(event)
+    {
+    }
+
+    virtual ~SysteminfoAsyncPendingEvent()
+    {
+    }
+
+    void* getThisObject() const { return m_thisObject; }
+    Api::Systeminfo::EventGetSysteminfoPtr getEvent() const { return m_event; }
+
+  private:
+    void *m_thisObject;
+    Api::Systeminfo::EventGetSysteminfoPtr m_event;
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/platform/Tizen/Systeminfo/config.cmake b/src/platform/Tizen/Systeminfo/config.cmake
new file mode 100755 (executable)
index 0000000..5559b4b
--- /dev/null
@@ -0,0 +1,30 @@
+get_current_path()
+
+pkg_search_module(capi-telephony-sim REQUIRED capi-telephony-sim)
+pkg_search_module(capi-network-connection REQUIRED capi-network-connection)
+pkg_search_module(capi-system-info REQUIRED capi-system-info)
+pkg_search_module(capi-system-sensor REQUIRED capi-system-sensor)
+pkg_search_module(sys_sensor REQUIRED sensor)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_SYSTEMINFO
+  ${capi-telephony-sim_INCLUDE_DIRS}
+  ${capi-network-connection_INCLUDE_DIRS}
+  ${capi-system-info_INCLUDE_DIRS}
+  ${capi-system-sensor_INCLUDE_DIRS}
+  ${sys_sensor_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_SYSTEMINFO
+  ${capi-telephony-sim_LIBRARIES}
+  ${capi-network-connection_LIBRARIES}
+  ${capi-system-info_LIBRARIES}
+  ${capi-system-sensor_LIBRARIES}
+  ${sys_sensor_LIBRARIES}
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_SYSTEMINFO
+  ${CURRENT_PATH}/Systeminfo.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/TimeUtil/TZDate.cpp b/src/platform/Tizen/TimeUtil/TZDate.cpp
new file mode 100755 (executable)
index 0000000..0140c07
--- /dev/null
@@ -0,0 +1,698 @@
+//
+// 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 <Commons/Exception.h>
+
+#include <unicode/timezone.h>
+#include <unicode/vtzone.h>
+#include <unicode/smpdtfmt.h>
+
+#include "TZDate.h"
+#include "TimeUtilTools.h"
+
+using namespace TizenApis::Api::TimeUtil;
+using namespace WrtDeviceApis;
+
+namespace TizenApis {
+namespace Platform {
+namespace TimeUtil {
+
+TZDate::TZDate(const bool isNotNull)
+{
+       LogDebug("entered");
+
+       if (isNotNull == FALSE) {
+               myCalendar = NULL;
+       } else {
+               UErrorCode ec = U_ZERO_ERROR;
+               TimeUtilTools util;
+               myCalendar = Calendar::createInstance(ec);
+
+               if (U_SUCCESS(ec)) {
+                       util.printDate(myCalendar);
+               }
+               else {
+                       myCalendar = NULL;
+                       ThrowMsg(Commons::PlatformException, "Can't make to ICU Calendar");
+               }
+       }
+}
+
+TZDate::TZDate(const std::string &timezone)
+{
+       LogDebug("entered");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       TimeUtilTools util;
+       myCalendar = Calendar::createInstance(util.makeTimeZone(timezone) ,ec);
+
+       if (U_SUCCESS(ec)) {
+               TimeUtilTools util;
+               util.printDate(myCalendar);
+               if (!util.compareTimeZoneName(myCalendar, timezone)) {
+                       myCalendar = NULL;
+                       ThrowMsg(Commons::InvalidArgumentException, "Unsupported Timezone.");
+               }
+       } else {
+               myCalendar = NULL;
+               ThrowMsg(Commons::PlatformException, "Can't make to ICU Calendar");
+       }
+
+}
+
+TZDate::TZDate(const TZDateProperties &properties)
+{
+       LogDebug("entered");
+
+       TimeUtilTools util;
+       myCalendar = _makeCalendar(properties);
+       if (myCalendar != NULL) {
+               if (!util.compareTimeZoneName(myCalendar, properties.timezone)) {
+                       delete myCalendar;
+                       myCalendar = NULL;
+                       ThrowMsg(Commons::InvalidArgumentException, "Unsupported Timezone.");
+               }
+       } else
+               ThrowMsg(Commons::PlatformException, "Can't make to ICU Calendar");
+}
+
+TZDate::~TZDate()
+{
+       LogDebug("entered");
+
+       if (myCalendar != NULL)
+               delete myCalendar;
+
+       myCalendar = NULL;
+}
+
+bool  TZDate::isNull()
+{
+       if (myCalendar == NULL)
+               return TRUE;
+
+       return FALSE;
+}
+
+Calendar *TZDate::_makeCalendar(const TZDateProperties &properties)
+{
+       LogDebug("entered");
+       UErrorCode ec = U_ZERO_ERROR;
+       TimeUtilTools util;
+
+       Calendar *cal = NULL;
+       if (properties.timezone == "")
+               cal = Calendar::createInstance(ec);
+       else
+               cal = Calendar::createInstance(util.makeTimeZone(properties.timezone) ,ec);
+
+       if ((cal != NULL) && U_SUCCESS(ec)) {
+               cal->set(util.toint32_t(properties.year), util.toint32_t(properties.month),
+                       util.toint32_t(properties.day), util.toint32_t(properties.hours), util.toint32_t(properties.minutes), util.toint32_t(properties.seconds));
+               cal->set(UCAL_MILLISECOND, util.toint32_t(properties.milliseconds));
+               return cal;
+       }
+
+       return NULL;
+}
+
+std::string TZDate::_getTimezoneName(Calendar *cal)
+{
+       UnicodeString id;
+       TimeUtilTools util;
+
+       cal->getTimeZone().getID(id);
+       std::string s_result = util.toString(id);
+       LogDebug(s_result);
+       return s_result;
+}
+
+const UCalendarDateFields TZDate::_convertDateField(const TZDateFields field)
+{
+       switch (field) {
+       case TZDATE_ERA:
+               return UCAL_ERA;
+               break;
+       case TZDATE_YEAR:
+               return UCAL_YEAR;
+               break;
+       case TZDATE_MONTH:
+               return UCAL_MONTH;
+               break;
+       case TZDATE_WEEK_OF_YEAR:
+               return UCAL_WEEK_OF_YEAR;
+               break;
+       case TZDATE_WEEK_OF_MONTH:
+               return UCAL_WEEK_OF_MONTH;
+               break;
+       case TZDATE_DATE:
+               return UCAL_DATE;
+               break;
+       case TZDATE_DAY_OF_YEAR:
+               return UCAL_DAY_OF_YEAR;
+               break;
+       case TZDATE_DAY_OF_WEEK:
+               return UCAL_DAY_OF_WEEK;
+               break;
+       case TZDATE_DAY_OF_WEEK_IN_MONTH:
+               return UCAL_DAY_OF_WEEK_IN_MONTH;
+               break;
+       case TZDATE_AM_PM:
+               return UCAL_AM_PM;
+               break;
+       case TZDATE_HOUR:
+               return UCAL_HOUR;
+               break;
+       case TZDATE_HOUR_OF_DAY:
+               return UCAL_HOUR_OF_DAY;
+               break;
+       case TZDATE_MINUTE:
+               return UCAL_MINUTE;
+               break;
+       case TZDATE_SECOND:
+               return UCAL_SECOND;
+               break;
+       case TZDATE_MILLISECOND:
+               return UCAL_MILLISECOND;
+               break;
+       case TZDATE_ZONE_OFFSET:
+               return UCAL_ZONE_OFFSET;
+               break;
+       case TZDATE_DST_OFFSET:
+               return UCAL_DST_OFFSET;
+               break;
+       default:
+               return UCAL_FIELD_COUNT;
+       }
+}
+
+TZDateProperties TZDate::_makeProperties(Calendar *cal)
+{
+       TZDateProperties result;
+       TimeUtilTools util;
+
+       result.year = _get(TZDATE_YEAR, cal);
+       result.month = _get(TZDATE_MONTH,cal);
+       result.day = _get(TZDATE_DATE, cal);
+       result.hours = _get(TZDATE_HOUR_OF_DAY, cal);
+       result.minutes = _get(TZDATE_MINUTE, cal);
+       result.seconds = _get(TZDATE_SECOND, cal);
+       result.milliseconds = _get(TZDATE_MILLISECOND, cal);
+       result.timezone=  _getTimezoneName(cal);
+
+       return result;
+}
+
+std::string TZDate::getTimezone()
+{
+       return _getTimezoneName(myCalendar);
+}
+
+TZDateProperties TZDate::toTimezone(const std::string timezone) {
+       TimeUtilTools util;
+       Calendar *newCalendar = myCalendar->clone();
+       newCalendar->setTimeZone(*(util.makeTimeZone(timezone)));
+
+       if (!util.compareTimeZoneName(newCalendar, timezone)) {
+               delete newCalendar;
+               ThrowMsg(Commons::InvalidArgumentException, "Unsupported Timezone.");
+       }
+
+       TZDateProperties newProps =  _makeProperties(newCalendar);
+       delete newCalendar;
+
+       return newProps;
+}
+
+long TZDate::_get(const TZDateFields field, Calendar *cal)
+{
+       LogDebug("<<<");
+
+       if (_convertDateField(field) == UCAL_FIELD_COUNT){
+               LogDebug(">>> UCAL_FIELD_COUNT");
+               return -1;
+       }
+
+       UErrorCode ec = U_ZERO_ERROR;
+       TimeUtilTools util;
+       int32_t value = cal->get(_convertDateField(field), ec);
+       if (U_SUCCESS(ec)) {
+               long result = util.tolong(value);
+
+               LogDebug(">>> result:" << result);
+               return result;
+       }
+       ThrowMsg(Commons::PlatformException, "Can't get Calendar value");
+}
+long TZDate::get(const TZDateFields field)
+{
+       LogDebug("<<<");
+
+       long result = _get(field, myCalendar);
+       if (field == TZDATE_DAY_OF_WEEK)
+               result--;
+       return result;
+}
+
+void TZDate::set(const TZDateFields field, const long value)
+{
+       if (_convertDateField(field) == UCAL_FIELD_COUNT)
+               return;
+
+       TimeUtilTools util;
+       myCalendar->set(_convertDateField(field), util.toint32_t(value));
+       LogDebug("Field : " << field << " value : " << get(field));
+}
+
+long TZDate::getUTC(const TZDateFields field)
+{
+       if (_convertDateField(field) == UCAL_FIELD_COUNT)
+               return -1;
+
+       UErrorCode ec = U_ZERO_ERROR;
+       TimeUtilTools util;
+
+       Calendar *utcCalendar = myCalendar->clone();
+       utcCalendar->setTimeZone(*(TimeZone::getGMT()));
+
+       int32_t value = utcCalendar->get(_convertDateField(field), ec);
+       delete utcCalendar;
+
+       if (U_SUCCESS(ec)) {
+               long result = util.tolong(value);
+               if (field == TZDATE_DAY_OF_WEEK)
+                       result--;
+               LogDebug("result : " << result);
+
+               return result;
+       }
+
+       ThrowMsg(Commons::PlatformException, "Can't get UTC Calendar value");
+}
+
+void TZDate::setUTC(const TZDateFields field, const long value)
+{
+       if (_convertDateField(field) == UCAL_FIELD_COUNT)
+               return;
+
+       TimeUtilTools util;
+       UErrorCode ec = U_ZERO_ERROR;
+
+       long myValue = get(field);
+       long utcValue = getUTC(field);
+       if (field == TZDATE_DAY_OF_WEEK)
+               utcValue++;
+       set(field, myValue + value - utcValue);
+
+       if (!U_SUCCESS(ec))
+               ThrowMsg(Commons::PlatformException, "Can't set UTC Calendar value");
+}
+
+long long TZDate::difference(const TZDateProperties &prop) {
+       LogDebug("entered");
+
+       TimeUtilTools util;
+       UErrorCode ec = U_ZERO_ERROR;
+
+       Calendar *otherCalendar = _makeCalendar(prop);
+
+       if (!util.compareTimeZoneName(otherCalendar, prop.timezone)) {
+               delete otherCalendar;
+               ThrowMsg(Commons::InvalidArgumentException, "Unsupported Timezone.");
+       }
+
+       UDate myTime = myCalendar->getTime(ec);
+
+       if (U_SUCCESS(ec)) {
+               UDate otherTime = otherCalendar->getTime(ec);
+               if (U_SUCCESS(ec)) {
+                       LogDebug("myCalendar");
+                       util.printDate(myCalendar);
+                       LogDebug("otherCalendar");
+                       util.printDate(otherCalendar);
+                       delete otherCalendar;
+
+                       LogDebug("myTime : " <<myTime);
+                       LogDebug("otherTime : " << otherTime);
+
+                       return static_cast<long long>(myTime - otherTime);
+               }
+       }
+       delete otherCalendar;
+       ThrowMsg(Commons::PlatformException, "Calendar error in difference");
+}
+
+TZDateProperties TZDate::addDuration(const DurationProperties &duration) {
+       LogDebug("entered");
+       UErrorCode ec = U_ZERO_ERROR;
+
+       TimeUtilTools util;
+
+       Calendar *cal = myCalendar->clone();
+       long long length = duration.length;
+       short unit = duration.unit;
+       int msec=0, sec=0, min=0, hour=0;
+       long long day=0;
+
+       if (unit == MSECS_UNIT) {
+               msec = length % 1000;
+               length /= 1000;
+               unit = SECONDS_UNIT;
+       }
+       if ((length != 0) && (unit == SECONDS_UNIT)) {
+               sec = length % 60;
+               length /= 60;
+               unit = MINUTES_UNIT;
+       }
+       if ((length != 0) && (unit == MINUTES_UNIT)) {
+               min = length % 60;
+               length /= 60;
+               unit = HOURS_UNIT;
+       }
+       if ((length != 0) && (unit == HOURS_UNIT)) {
+               hour = length % 24;
+               length /= 24;
+               unit = DAYS_UNIT;
+       }
+       day = length;
+       LogDebug("day:"<<day<<" hour:"<<hour<<" min:"<<min<<" sec:"<<sec<<" msec:"<<msec);
+       try {
+               if (msec != 0) {
+                       cal->add(UCAL_MILLISECOND, util.toint32_t(msec), ec);
+                       if (!U_SUCCESS(ec))
+                               Throw(Commons::PlatformException);
+               }
+               if (sec != 0) {
+                       cal->add(UCAL_SECOND, util.toint32_t(sec), ec);
+                       if (!U_SUCCESS(ec))
+                               Throw(Commons::PlatformException);
+               }
+               if (min != 0) {
+                       cal->add(UCAL_MINUTE, util.toint32_t(min), ec);
+                       if (!U_SUCCESS(ec))
+                               Throw(Commons::PlatformException);
+               }
+               if (hour != 0) {
+                       cal->add(UCAL_HOUR_OF_DAY, util.toint32_t(hour), ec);
+                       if (!U_SUCCESS(ec))
+                               Throw(Commons::PlatformException);
+               }
+
+               UDate oldValue = cal->getTime(ec);
+               if (!U_SUCCESS(ec))
+                       Throw(Commons::PlatformException);
+
+               while (day != 0) {
+                       LogDebug("1st day : " << day);
+                       int amount = 0;
+
+                       if (day < INT_MIN)
+                               amount = INT_MIN;
+                       else if (day > INT_MAX)
+                               amount = INT_MAX;
+                       else
+                               amount = day;
+
+                       day -= amount;
+                       LogDebug("amount : " << amount);
+                       LogDebug("2nd day : " << day);
+                       cal->add(UCAL_DATE, util.toint32_t(amount), ec);
+                       if (!U_SUCCESS(ec))
+                               Throw(Commons::PlatformException);
+
+                       UDate newValue = cal->getTime(ec);
+                       if (!U_SUCCESS(ec))
+                               Throw(Commons::PlatformException);
+
+                       int diff = static_cast<int>((newValue - oldValue) / 24 / 60 / 60 / 1000);
+                       LogDebug("diff : " << diff);
+                       if (diff != amount) {
+                               Throw(Commons::OutOfRangeException);
+                       }
+                       oldValue = newValue;
+               } ;
+       } catch (Commons::PlatformException) {
+               delete cal;
+               ThrowMsg(Commons::PlatformException, "Calendar error in addDuration");
+       } catch (Commons::OutOfRangeException) {
+               delete cal;
+               ThrowMsg(Commons::OutOfRangeException, "The result is beyond the scope that TZDate can handle.");
+       }
+
+       TZDateProperties result = _makeProperties(cal);
+       util.printDate(cal);
+       delete cal;
+
+       if (!U_SUCCESS(ec))
+               ThrowMsg(Commons::PlatformException, "Calendar error in addDuration");
+       return result;
+}
+
+TZDateProperties TZDate::toUTC() {
+       LogDebug("entered");
+       TimeUtilTools util;
+       TZDateProperties result;
+       Calendar *utcCalendar = myCalendar->clone();
+
+       try {
+               utcCalendar->setTimeZone(*(TimeZone::getGMT()));
+               result = _makeProperties(utcCalendar);
+               util.printDate(utcCalendar);
+               delete utcCalendar;
+       } catch (Commons::PlatformException) {
+               delete utcCalendar;
+               ThrowMsg(Commons::PlatformException, "Calendar error in toUTC");
+       }
+
+       return result;
+}
+
+TZDateProperties TZDate::toLocalTimezone() {
+       LogDebug("entered");
+       TimeUtilTools util;
+       TZDateProperties result;
+       Calendar *localCalendar = myCalendar->clone();
+
+       try {
+               localCalendar->setTimeZone(*(TimeZone::createDefault()));
+
+               result = _makeProperties(localCalendar);
+               util.printDate(localCalendar);
+               delete localCalendar;
+       } catch (Commons::PlatformException) {
+               delete localCalendar;
+               ThrowMsg(Commons::PlatformException, "Calendar error in toLocalTimezone");
+       }
+       return result;  
+}
+
+double TZDate::getTime() {
+       LogDebug("entered");
+       UErrorCode ec = U_ZERO_ERROR;
+
+       UDate date = myCalendar->getTime(ec);
+       if (U_SUCCESS(ec))
+               return static_cast<double>(date);
+
+       ThrowMsg(Commons::PlatformException, "can't get time");
+}
+
+bool TZDate::setTime(const double time) {
+       LogDebug("entered");
+       UErrorCode ec = U_ZERO_ERROR;
+
+       myCalendar->setTime(static_cast<UDate>(time), ec);
+       if (U_SUCCESS(ec))
+               return true;
+
+       return false;
+}
+
+ std::string TZDate::toDateString(bool bLocale)  {
+       UErrorCode ec = U_ZERO_ERROR;
+       UnicodeString str;
+       TimeUtilTools util;
+
+       DateFormat *fmt = new SimpleDateFormat(util.getDateTimeFormat(TimeUtilTools::DATE_FORMAT, bLocale), (bLocale ? Locale::getDefault() : Locale::getEnglish()), ec);
+       if (U_SUCCESS(ec)) {
+               fmt->setCalendar(*myCalendar);
+               fmt->format(myCalendar->getTime(ec), str);
+               delete fmt;
+
+               if (U_SUCCESS(ec)) {
+                       std::string result = util.toString(str);
+                       str.remove();
+
+                       LogDebug (result);
+                       return result;
+               }
+       }
+
+       ThrowMsg(Commons::PlatformException, "can't make SimpleDateFormat or can't get time");
+ }
+
+  std::string TZDate::toTimeString(bool bLocale)  {
+       UErrorCode ec = U_ZERO_ERROR;
+       UnicodeString str;
+       TimeUtilTools util;
+
+       DateFormat *fmt = new SimpleDateFormat(util.getDateTimeFormat(TimeUtilTools::TIME_FORMAT, bLocale), (bLocale ? Locale::getDefault() : Locale::getEnglish()), ec);
+       if (U_SUCCESS(ec)) {
+               fmt->setCalendar(*myCalendar);
+               fmt->format(myCalendar->getTime(ec), str);
+               delete fmt;
+
+               if (U_SUCCESS(ec)) {
+                       std::string result = util.toString(str);
+                       str.remove();
+                       LogDebug (result);
+                       return result;
+               }
+       }
+
+       ThrowMsg(Commons::PlatformException, "can't make SimpleDateFormat or can't get time");
+ }
+ std::string TZDate::toString(bool bLocale) {
+       LogDebug("entered");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       UnicodeString str;
+       TimeUtilTools util;
+
+       DateFormat *fmt = new SimpleDateFormat(util.getDateTimeFormat(TimeUtilTools::DATETIME_FORMAT, bLocale), (bLocale ? Locale::getDefault() : Locale::getEnglish()), ec);
+       if (U_SUCCESS(ec)) {
+               fmt->setCalendar(*myCalendar);
+               fmt->format(myCalendar->getTime(ec), str);
+               delete fmt;
+
+               if (U_SUCCESS(ec)) {
+                       std::string result = util.toString(str);
+                       str.remove();
+                       LogDebug (result);
+                       return result;
+               }
+       }
+       ThrowMsg(Commons::PlatformException, "can't make SimpleDateFormat or can't get time");
+}
+
+std::string TZDate::getTimezoneAbbreviation() {
+       LogDebug("entered");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       UnicodeString str;
+       TimeUtilTools util;
+
+       DateFormat *fmt = new SimpleDateFormat(UnicodeString("V"), Locale::getEnglish(), ec);
+       if (U_SUCCESS(ec)) {
+               fmt->setCalendar(*myCalendar);
+               fmt->format(myCalendar->getTime(ec), str);
+               delete fmt;
+
+               if (U_SUCCESS(ec)) {
+                       std::string result = util.toString(str);
+                       str.remove();
+
+                       LogDebug (result);
+
+                       return result;
+               }
+       }
+       ThrowMsg(Commons::PlatformException, "can't make SimpleDateFormat or can't get time");
+}
+
+long TZDate::secondsFromUTC() {
+       LogDebug("entered");
+       UErrorCode ec = U_ZERO_ERROR;
+       TimeUtilTools util;
+
+       int32_t zoneOffset = myCalendar->get(UCAL_ZONE_OFFSET, ec);
+       if (!U_SUCCESS(ec))
+               ThrowMsg(Commons::PlatformException, "can't get zone offset");
+
+       int32_t dstOffset = myCalendar->get(UCAL_DST_OFFSET, ec);
+       if (!U_SUCCESS(ec))
+               ThrowMsg(Commons::PlatformException, "can't get dst offset");
+
+       long result = -((util.tolong(zoneOffset + dstOffset)) / MILLISTOSEC);
+
+       LogDebug("result : " << result);
+       return result;
+}
+
+bool TZDate::isDST() {
+       LogDebug("entered");
+       UErrorCode ec = U_ZERO_ERROR;
+       TimeUtilTools util;
+       UBool result = myCalendar->inDaylightTime(ec);
+
+       if (!U_SUCCESS(ec))
+               ThrowMsg(Commons::PlatformException, "can't inDaylightTime value from ICU");
+
+       return static_cast<bool>(result);
+}
+
+TZDateProperties TZDate::getDSTTransition(DSTTransition trans) {
+       LogDebug("entered");
+       TimeUtilTools util;
+       UErrorCode ec = U_ZERO_ERROR;
+       TZDateProperties props;
+       UDate dstTransitionDate = myCalendar->getTime(ec);
+       UBool result = false;
+
+       if (U_SUCCESS(ec)) {
+               UnicodeString *id = util.toUnicodeString(getTimezone());
+
+               VTimeZone *vtz = VTimeZone::createVTimeZoneByID(*id);
+               delete id;
+
+               TimeZoneTransition tzTrans;
+               if (vtz->useDaylightTime() == TRUE) {
+                       if (trans == NEXT_TRANSITION)
+                               result = vtz->getNextTransition(dstTransitionDate, FALSE,  tzTrans);
+                       else
+                               result = vtz->getPreviousTransition(dstTransitionDate, FALSE,  tzTrans);
+                       if (result == TRUE) {
+                               LogDebug("result is TRUE");
+                               dstTransitionDate = tzTrans.getTime();
+                       }
+               }
+               delete vtz;
+
+               if (result == false)
+                       return props;
+
+               Calendar *dstTransCalendar = myCalendar->clone();
+               dstTransCalendar->setTime(dstTransitionDate, ec);
+               if (U_SUCCESS(ec)) {
+                       props =  _makeProperties(dstTransCalendar);
+                       delete dstTransCalendar;
+                       return props;
+               }
+               delete dstTransCalendar;
+       }
+       ThrowMsg(Commons::PlatformException, "can't getDSTTransition value from ICU");
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/TimeUtil/TZDate.h b/src/platform/Tizen/TimeUtil/TZDate.h
new file mode 100755 (executable)
index 0000000..2a63490
--- /dev/null
@@ -0,0 +1,88 @@
+//
+// 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 _TZDATE_H_
+#define _TZDATE_H_
+
+#include <string>
+#include <ctime>
+
+#include <API/TimeUtil/ITZDate.h>
+#include <unicode/calendar.h>
+
+using namespace TizenApis::Api::TimeUtil;
+
+namespace TizenApis {
+namespace Platform {
+namespace TimeUtil {
+       
+class TZDate : public ITZDate
+{
+
+       friend class TimeUtilFactory;
+       
+       public:
+               TZDate(const bool isNotNull);
+               TZDate(const std::string &timezone);
+               TZDate(const TZDateProperties &properties); 
+               virtual      ~TZDate();
+
+               virtual bool  isNull();
+               virtual long get(const TZDateFields field);
+               virtual std::string getTimezone();
+               virtual TZDateProperties toTimezone(const std::string timezone);
+               virtual void set(const TZDateFields field, const long value);
+
+               virtual long getUTC(const TZDateFields field);
+               virtual void setUTC(const TZDateFields field, const long value);
+
+               virtual long long difference(const TZDateProperties &prop);
+               virtual TZDateProperties addDuration(const DurationProperties &duration);
+               virtual TZDateProperties toUTC();
+               virtual TZDateProperties toLocalTimezone();
+
+               virtual double getTime();
+               virtual bool setTime(const double time);
+               virtual std::string toDateString(bool bLocale = false) ;
+               virtual std::string toTimeString(bool bLocale = false);
+               virtual std::string toString(bool bLocale = false);
+
+               virtual std::string getTimezoneAbbreviation();
+               virtual long secondsFromUTC();          
+               virtual bool isDST();
+               virtual TZDateProperties getDSTTransition(DSTTransition trans);
+
+       private:
+               long _get(const TZDateFields field, Calendar *cal);
+               std::string _getTimezoneName(Calendar *cal);
+               const UCalendarDateFields _convertDateField(const TZDateFields field);
+
+               Calendar * _makeCalendar(const TZDateProperties &properties);
+               TZDateProperties _makeProperties(Calendar *cal);
+
+               Calendar *myCalendar;
+        
+};
+
+}
+}
+}
+
+#endif /* _DATETIME_H_ */
diff --git a/src/platform/Tizen/TimeUtil/TimeUtil.cpp b/src/platform/Tizen/TimeUtil/TimeUtil.cpp
new file mode 100755 (executable)
index 0000000..2381e49
--- /dev/null
@@ -0,0 +1,206 @@
+//
+// 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 <ctime>
+#include <vconf.h>
+
+#include <Commons/Exception.h>
+
+#include <API/TimeUtil/TZDateProperties.h>
+
+#include <unicode/ustring.h>
+#include <unicode/timezone.h>
+#include <unicode/calendar.h>
+#include <unicode/strenum.h>
+#include <unicode/datefmt.h>
+
+#include "TimeUtil.h"
+#include "TimeUtilTools.h"
+
+using namespace TizenApis::Api::TimeUtil;
+using namespace WrtDeviceApis;
+
+namespace TizenApis {
+namespace Platform {
+namespace TimeUtil {
+
+namespace {
+       static void changedTimezoneCallback(keynode_t* node, void* user_data) {
+               LogDebug("entered KeyName:" << vconf_keynode_get_name(node));
+               if (!strcmp(vconf_keynode_get_name(node), VCONFKEY_SETAPPL_TIMEZONE_ID) && (vconf_keynode_get_type(node) == VCONF_TYPE_STRING)) {
+                       char *timezoneID = vconf_keynode_get_str(node);
+                       if (timezoneID != NULL) {
+                               LogDebug("Changed Timezone : " << timezoneID);
+                               TimeUtilTools util;
+                               UnicodeString *id = util.toUnicodeString(timezoneID);
+                               TimeZone *tz = TimeZone::createTimeZone(*id);
+                               delete id;
+
+                               TimeZone::setDefault(*tz);
+                       }
+               }
+       }
+}//private namespace
+
+TimeUtil::TimeUtil()
+{
+       LogDebug("entered");
+       bRegisteredChangedTimezone = false;
+       if (vconf_notify_key_changed(VCONFKEY_SETAPPL_TIMEZONE_ID, changedTimezoneCallback, NULL) == 0) {
+               LogDebug("Success to register changedTimezoneCallback");
+               bRegisteredChangedTimezone = true;
+       }
+}
+
+TimeUtil::~TimeUtil()
+{
+       LogDebug("entered");
+       if (bRegisteredChangedTimezone) {
+               vconf_ignore_key_changed(VCONFKEY_SETAPPL_TIMEZONE_ID, changedTimezoneCallback);
+       }
+}
+
+void TimeUtil::setCurrentTZDate(const TZDateProperties &tzdate){
+       ThrowMsg(Commons::UnsupportedException, "Not support to set current DateTime");
+}
+
+std::string TimeUtil::getLocalTimezone() {
+       LogDebug("entered");
+       UnicodeString idResult;
+
+       TimeZone* zone = TimeZone::createDefault();
+       UnicodeString id;
+       zone->getID(id);
+
+       delete zone;
+
+       try {
+               TimeUtilTools util;
+                std::string s_result = util.toString(id);
+                LogDebug("result : " << s_result);
+
+               return s_result;
+       } catch (Commons::PlatformException) {
+               LogError("can't get the local timezone's name");
+       }
+
+       ThrowMsg(Commons::PlatformException, "Can't get Local Timezone");
+}
+
+
+std::string TimeUtil::getUTCTimezone() {
+       LogDebug("entered");
+       UnicodeString id;
+
+       const TimeZone *utcTimezone = TimeZone::getGMT();
+       utcTimezone->getID(id);
+
+       try {
+               TimeUtilTools util;
+               std::string s_result = util.toString(id);
+
+                LogDebug("result : " << s_result);
+               
+               return s_result;
+       } catch(Commons::PlatformException) {
+               LogError("can't get the UTC timezone's name");
+       }
+
+       ThrowMsg(Commons::PlatformException, "Can't get UTC Timezone");
+}
+       
+std::vector<std::string> TimeUtil::getAvailableTimezones(){
+       UErrorCode ec = U_ZERO_ERROR;
+       StringEnumeration * tzen = TimeZone::createEnumeration();
+       const char *str = NULL;
+       int32_t count = tzen->count(ec);
+       std::vector<std::string> timezones;
+       
+       LogDebug("count: " << count);
+
+       if (U_SUCCESS(ec)) {
+               int i = 0;
+               
+               do {
+                       int32_t resultLen = 0;
+                       
+                       str = tzen->next(&resultLen, ec);
+                       if(U_SUCCESS(ec)) {
+                               std::string timezone = str;
+                               timezones.push_back(timezone);
+                               i++;
+                       }
+               }while((str!=NULL) && (i < count));     
+       } else {
+               ThrowMsg(Commons::PlatformException, "Can't get timezones list");
+       }
+       return timezones;;
+}
+
+std::string TimeUtil::getDateFormat(const bool b_shortFormat) {
+       LogDebug("entered");
+       TimeUtilTools util;
+       UnicodeString timeFormat = util.getDateTimeFormat((b_shortFormat ? TimeUtilTools::DATE_SHORT_FORMAT : TimeUtilTools::DATE_FORMAT), true);
+       timeFormat = timeFormat.findAndReplace("E", "D");
+
+       if (timeFormat.indexOf("MMM") > 0) {
+               if (timeFormat.indexOf("MMMM") > 0)
+                       timeFormat = timeFormat.findAndReplace("MMMM", "M");
+               else
+                       timeFormat = timeFormat.findAndReplace("MMM", "M");
+       } else {
+               timeFormat = timeFormat.findAndReplace("M", "m");
+       }
+
+       int32_t i = 0;
+       
+       while (i < timeFormat.length()) {
+               if (timeFormat[i] == timeFormat[i+1])
+                       timeFormat.remove(i, 1);
+               else
+                       i++;
+       }
+       LogDebug("result : " << util.toString(timeFormat));
+       return util.toString(timeFormat);
+}
+
+std::string TimeUtil::getTimeFormat(){
+       LogDebug("entered");
+       TimeUtilTools util;
+       UnicodeString timeFormat = util.getDateTimeFormat(TimeUtilTools::TIME_FORMAT, true);
+       timeFormat = timeFormat.findAndReplace("H", "h");
+       timeFormat = timeFormat.findAndReplace("a", "ap");
+
+       int32_t i = 0;
+       
+       while (i < timeFormat.length()) {
+               if (timeFormat[i] == timeFormat[i+1])
+                       timeFormat.remove(i, 1);
+               else
+                       i++;
+       }
+       LogDebug("result : " << util.toString(timeFormat));
+       return util.toString(timeFormat);
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/TimeUtil/TimeUtil.h b/src/platform/Tizen/TimeUtil/TimeUtil.h
new file mode 100755 (executable)
index 0000000..6098c46
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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 _TIMEUTIL_H_
+#define _TIMEUTIL_H_
+
+#include <dpl/mutex.h>
+#include <dpl/shared_ptr.h>
+#include <string>
+#include <API/TimeUtil/ITimeUtil.h>
+#include <unicode/unistr.h>
+
+using namespace TizenApis::Api::TimeUtil;
+
+namespace TizenApis {
+namespace Platform {
+namespace TimeUtil {
+       
+class TimeUtil : public ITimeUtil
+{
+       friend class TimeUtilFactory;
+
+    public:
+                    TimeUtil();
+       virtual      ~TimeUtil();
+       virtual void setCurrentTZDate(const TZDateProperties &tzdate);
+       virtual std::string getLocalTimezone();
+       virtual std::string getUTCTimezone();
+       virtual std::vector<std::string> getAvailableTimezones();
+       virtual std::string getDateFormat(const bool b_shortFormat);
+       virtual std::string getTimeFormat();
+    private:
+       bool bRegisteredChangedTimezone;
+};
+
+}
+}
+}
+
+#endif /* _TIMEUTIL_H_ */
diff --git a/src/platform/Tizen/TimeUtil/TimeUtilTools.cpp b/src/platform/Tizen/TimeUtil/TimeUtilTools.cpp
new file mode 100755 (executable)
index 0000000..9ce4688
--- /dev/null
@@ -0,0 +1,173 @@
+//
+// 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 <unicode/ustring.h>
+#include <unicode/udat.h>
+#include <unicode/dtptngen.h>
+
+#include <string.h>
+#include <vconf.h>
+
+#include <Commons/Exception.h>
+
+#include "TimeUtilTools.h"
+#include <dpl/log/log.h>
+
+namespace TizenApis {
+namespace Platform {
+namespace TimeUtil {
+
+using namespace WrtDeviceApis;
+
+long TimeUtilTools::tolong(const int32_t num)
+{
+       return static_cast<long>(num);
+}
+
+int32_t TimeUtilTools::toint32_t(const long long num)
+{
+       return static_cast<int32_t>(num);
+}
+
+int32_t TimeUtilTools::toint32_t(const long num)
+{
+       return static_cast<int32_t>(num);
+}
+
+int32_t TimeUtilTools::toint32_t(const int num)
+{
+       return static_cast<int32_t>(num);
+}
+
+UnicodeString *TimeUtilTools::toUnicodeString(const std::string str)
+{
+       UnicodeString *id = new UnicodeString(str.c_str());
+
+       return id;
+}
+
+std::string TimeUtilTools::toString(UnicodeString uniStr)
+{
+       int bufferLen = sizeof(UChar)*static_cast<int>(uniStr.length()) + 1;
+       char *resultBuffer = (char *)malloc(bufferLen);
+       if (!resultBuffer)
+               ThrowMsg(Commons::PlatformException, "memory allocation error");
+       memset(resultBuffer, 0, bufferLen);
+       CheckedArrayByteSink sink(resultBuffer, bufferLen);
+       uniStr.toUTF8(sink);
+       if (sink.Overflowed())
+               ThrowMsg(Commons::PlatformException, "Converting error");
+       
+       std::string str(resultBuffer);
+       free(resultBuffer);
+       LogDebug(str);
+       return str;
+}
+
+TimeZone *TimeUtilTools::makeTimeZone(const std::string &name)
+{
+       LogDebug("entered timezone name : " << name);
+
+       UnicodeString *id = toUnicodeString(name);
+
+       TimeZone *tz = TimeZone::createTimeZone(*id);
+       delete id;
+
+       return tz;
+}
+
+bool TimeUtilTools::compareTimeZoneName(Calendar *cal, const std::string &name) {
+       UnicodeString id;
+       cal->getTimeZone().getID(id);
+       std::string timezone = toString(id);
+
+       if ((timezone != name) && (timezone == "Etc/Unknown"))
+               return false;
+
+       return true;
+}
+
+UnicodeString TimeUtilTools::getDateTimeFormat(DateTimeFormatType type, bool bLocale) {
+       UErrorCode ec = U_ZERO_ERROR;
+       DateTimePatternGenerator *dateTimepatten = DateTimePatternGenerator::createInstance((bLocale ? Locale::getDefault() : Locale::getEnglish()), ec);
+       if (U_SUCCESS(ec)) {
+               UnicodeString patten;
+               LogDebug("Type : " << type);
+               if (type == DATE_FORMAT)
+                       patten = dateTimepatten->getBestPattern(UDAT_YEAR_MONTH_WEEKDAY_DAY, ec);
+               else if (type == DATE_SHORT_FORMAT)
+                       patten = dateTimepatten->getBestPattern(UDAT_YEAR_NUM_MONTH_DAY, ec);
+               else {
+                       int ret = 0;
+                       int value = 0;
+                       ret = vconf_get_int(VCONFKEY_REGIONFORMAT_TIME1224, &value);
+                       // if failed, set default time format
+                       if (-1 == ret) {
+                               value = VCONFKEY_TIME_FORMAT_12;
+                       }
+
+                       std::string skeletone;
+                       if (type != TIME_FORMAT) 
+                               skeletone = UDAT_YEAR_MONTH_WEEKDAY_DAY;
+                       if (value == VCONFKEY_TIME_FORMAT_12)
+                               skeletone += "hhmmss";
+                       else
+                               skeletone += "HHmmss";
+
+                       UnicodeString *skeletoneUniStr = toUnicodeString(skeletone);
+                       patten = dateTimepatten->getBestPattern(*skeletoneUniStr, ec);
+                       delete skeletoneUniStr;
+
+                       if (!bLocale)
+                               patten += " 'GMT'Z v'";
+               }
+       LogDebug("pattern : " << toString(patten));
+       return patten;
+
+       }
+
+       return "";
+}
+
+void TimeUtilTools::printDate(Calendar *cal)
+{
+       UErrorCode ec = U_ZERO_ERROR;
+       
+       if (cal == NULL)
+               return;
+       
+       LogDebug("year : " << tolong(cal->get(UCAL_YEAR, ec)));
+       LogDebug("month : " << tolong(cal->get(UCAL_MONTH, ec)));
+       LogDebug("day : " << tolong(cal->get(UCAL_DATE, ec)));
+       LogDebug("hours : " << tolong(cal->get(UCAL_HOUR, ec)));
+       LogDebug("hours of day : " << tolong(cal->get(UCAL_HOUR_OF_DAY, ec)));
+       LogDebug("AM/PM : " << tolong(cal->get(UCAL_AM_PM, ec)));
+       LogDebug("dayofweek : " << tolong(cal->get(UCAL_DAY_OF_WEEK, ec)));
+       LogDebug("minues : " << tolong(cal->get(UCAL_MINUTE, ec)));
+       LogDebug("seconds : " << tolong(cal->get(UCAL_SECOND, ec)));
+       LogDebug("miliseconds : " << tolong(cal->get(UCAL_MILLISECOND, ec)));
+       LogDebug("zone offset : " << tolong(cal->get(UCAL_ZONE_OFFSET, ec)));
+       LogDebug("dst offset : " << tolong(cal->get(UCAL_DST_OFFSET, ec)));
+       LogDebug("is leap month? : " << tolong(cal->get(UCAL_IS_LEAP_MONTH, ec)));
+}
+
+}
+}
+}
diff --git a/src/platform/Tizen/TimeUtil/TimeUtilTools.h b/src/platform/Tizen/TimeUtil/TimeUtilTools.h
new file mode 100755 (executable)
index 0000000..6432d78
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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 _TIMEUTILTOOLS_H_
+#define _TIMEUTILTOOLS_H_
+
+#include <unicode/unistr.h>
+#include <unicode/timezone.h>
+#include <unicode/calendar.h>
+#include <ctime>
+
+namespace TizenApis {
+namespace Platform {
+namespace TimeUtil {
+
+#define MILLISTOSEC 1000
+
+class TimeUtilTools 
+{
+
+    public:
+       enum DateTimeFormatType {
+               TIME_FORMAT,
+               DATE_FORMAT,
+               DATE_SHORT_FORMAT,
+               DATETIME_FORMAT
+       };
+               TimeUtilTools() {}
+       virtual  ~TimeUtilTools() {}
+       long tolong(const int32_t num);
+       int32_t toint32_t(const long long num);
+       int32_t toint32_t(const long num);
+       int32_t toint32_t(const int num);
+       UnicodeString *toUnicodeString(const std::string str);
+       std::string toString(UnicodeString uniStr);
+       TimeZone *makeTimeZone(const std::string &name);
+       bool compareTimeZoneName(Calendar *cal, const std::string &name);
+       void printDate(Calendar *cal);
+       UnicodeString getDateTimeFormat(DateTimeFormatType type, bool bLocale);
+};
+
+}
+}
+}
+
+#endif /* _TIMEUTILTOOLS_H_ */
diff --git a/src/platform/Tizen/TimeUtil/config.cmake b/src/platform/Tizen/TimeUtil/config.cmake
new file mode 100755 (executable)
index 0000000..12338da
--- /dev/null
@@ -0,0 +1,19 @@
+get_current_path()
+
+pkg_search_module(pkgs_time REQUIRED icu-i18n icu-io icu-le icu-lx icu-uc)
+
+set(INCLUDES_PLATFORM_IMPLEMENTATION_TIMEUTIL
+  ${pkgs_time_INCLUDE_DIRS}
+  PARENT_SCOPE
+)
+
+set(LIBS_PLATFORM_IMPLEMENTATION_TIMEUTIL
+  PARENT_SCOPE
+)
+
+set(SRCS_PLATFORM_IMPLEMENTATION_TIMEUTIL
+  ${CURRENT_PATH}/TimeUtil.cpp
+  ${CURRENT_PATH}/TZDate.cpp
+  ${CURRENT_PATH}/TimeUtilTools.cpp
+  PARENT_SCOPE
+)
diff --git a/src/platform/Tizen/config.cmake b/src/platform/Tizen/config.cmake
new file mode 100644 (file)
index 0000000..0e9bcc9
--- /dev/null
@@ -0,0 +1,18 @@
+include_config_file(DBus)
+include_config_file(Content)
+include_config_file(Calendar)
+include_config_file(Contact)
+include_config_file(Callhistory)
+include_config_file(Bluetooth)
+include_config_file(Application)
+include_config_file(Messaging)
+include_config_file(TimeUtil)
+include_config_file(Systeminfo)
+include_config_file(NFC)
+include_config_file(Filesystem)
+include_config_file(Account)
+include_config_file(Power)
+include_config_file(Notification)
+include_config_file(Download)
+include_config_file(NetworkBearerSelection)
+include_config_file(SystemSetting)
diff --git a/src/standards/CMakeLists.txt b/src/standards/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b204dff
--- /dev/null
@@ -0,0 +1,6 @@
+set(STANDARD_FILE_DESTINATION /usr/lib/wrt-plugins)
+
+add_subdirectory(Tizen)
+#add_subdirectory(W3C)
+
+#INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/standard-features-list DESTINATION ${STANDARD_FILE_DESTINATION})
diff --git a/src/standards/Tizen/Alarm/AlarmAbsolute.cpp b/src/standards/Tizen/Alarm/AlarmAbsolute.cpp
new file mode 100755 (executable)
index 0000000..7e6ae7d
--- /dev/null
@@ -0,0 +1,126 @@
+//
+// 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 "AlarmAbsolute.h"
+#include "alarm_common.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Alarm {
+
+AlarmAbsolute::AlarmAbsolute()
+{
+    m_isRecurrence = false;
+    service_create(&m_service_handle);
+    service_add_extra_data(m_service_handle, ALARM_TYPE_KEY, ALARM_TYPE_ABSOLUTE_VALUE);
+    service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_NONE);
+    m_recurrenceType = AbsoluteRecurrence::NoRecurrence;
+    m_id = -1;
+}
+
+AlarmAbsolute::AlarmAbsolute(service_h handle)
+{
+    service_clone(&m_service_handle, handle);
+    m_id = -1;
+}
+
+AlarmAbsolute::~AlarmAbsolute()
+{
+    service_destroy(m_service_handle);
+}
+
+int AlarmAbsolute::getId() const
+{
+    return m_id;
+}
+
+void AlarmAbsolute::setId(const int id)
+{
+    m_id = id;
+}
+
+bool AlarmAbsolute::isRecurrence()
+{
+    return m_isRecurrence;
+}
+
+void AlarmAbsolute::setIsRecurrence(bool value)
+{
+    m_isRecurrence = value;
+}
+
+void AlarmAbsolute::setDate(struct tm date)
+{
+    char strDate[19]; 
+    m_date = date;
+
+    snprintf(strDate, sizeof(strDate),  "%d %d %d %d %d %d",m_date.tm_year, m_date.tm_mon, 
+                m_date.tm_mday,  m_date.tm_hour, m_date.tm_min,  m_date.tm_sec);
+
+    LogInfo("setDate encrypted string = " << strDate);
+    service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_DATE_KEY, strDate);
+
+    LogInfo("AlarmAbsolute Date = " << " Sec: " << m_date.tm_sec << ", Min: "<< m_date.tm_min
+    << ", Hour:" << m_date.tm_hour << ", Day: " << m_date.tm_mday << ", MON: " << m_date.tm_mon 
+    << ", Year: " <<  m_date.tm_year);
+}
+
+struct tm AlarmAbsolute::getDate()
+{
+    return m_date;
+}
+
+void AlarmAbsolute::setInterval(int interval)
+{
+    m_interval = interval;
+    m_recurrenceType = AbsoluteRecurrence::Interval;
+    service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_INTERVAL);
+}
+
+int AlarmAbsolute::getInterval()
+{
+    return m_interval;
+}
+
+void AlarmAbsolute::setByDayRecurrence(std::vector<std::string> &daysOfTheWeek)
+{
+    m_recurrenceType = AbsoluteRecurrence::ByDayValue;
+    m_daysOfTheWeek = daysOfTheWeek;
+    service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_BYDAYVALUE);
+}
+
+std::vector<std::string> AlarmAbsolute::getByDayRecurrence()
+{
+    return m_daysOfTheWeek;
+}
+
+AbsoluteRecurrence::Type AlarmAbsolute::getRecurrenceType()
+{
+    return m_recurrenceType;
+}
+
+service_h AlarmAbsolute::getService() {
+    return m_service_handle;
+}
+}
+}
+}
+
diff --git a/src/standards/Tizen/Alarm/AlarmAbsolute.h b/src/standards/Tizen/Alarm/AlarmAbsolute.h
new file mode 100755 (executable)
index 0000000..c95d5ac
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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_ALARMABSOLUTE_H_
+#define TIZENAPIS_API_ALARMABSOLUTE_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <time.h>
+#include <app.h>
+#include "alarm_common.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Alarm {
+
+class AlarmAbsolute;
+typedef DPL::SharedPtr<AlarmAbsolute> AlarmAbsolutePtr;
+typedef std::vector<AlarmAbsolutePtr> AlarmAbsoluteArrayPtr;
+
+class AlarmAbsolute
+{
+  public:
+    AlarmAbsolute();
+    AlarmAbsolute(service_h handle);
+    ~AlarmAbsolute();
+    int getId() const;
+    void setId(const int id);
+    void setDate(struct tm date);
+    struct tm getDate();
+    void setInterval(int interval);
+    int getInterval();
+    bool isRecurrence();
+    void setIsRecurrence(bool value);
+    void setByDayRecurrence(std::vector<std::string> &daysOfTheWeek);
+    std::vector<std::string> getByDayRecurrence();
+    AbsoluteRecurrence::Type getRecurrenceType();
+    service_h getService();
+
+  private:
+    int m_id;
+    struct tm m_date;
+    bool m_isRecurrence;
+    int m_interval;
+    service_h m_service_handle;
+    std::vector<std::string> m_daysOfTheWeek;
+    AbsoluteRecurrence::Type m_recurrenceType;
+    
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Alarm/AlarmConverter.cpp b/src/standards/Tizen/Alarm/AlarmConverter.cpp
new file mode 100755 (executable)
index 0000000..85ec8ac
--- /dev/null
@@ -0,0 +1,270 @@
+//
+// 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 <vector>
+#include <app.h>
+#include <time.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include "AlarmConverter.h"
+#include "JSAlarmAbsolute.h"
+#include "AlarmAbsolute.h"
+#include "JSAlarmRelative.h"
+#include "AlarmRelative.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Alarm {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Alarm;
+
+AlarmConverter::AlarmConverter(JSContextRef context) : WrtDeviceApis::CommonsJavaScript::Converter(context)
+{
+
+}
+
+AlarmConverter::~AlarmConverter()
+{
+
+}
+
+int AlarmConverter::toNativeAlarmValue(std::vector<std::string> daysOfTheWeek)
+{
+    int nativeValue = 0;
+
+    for( unsigned int i=0; i<daysOfTheWeek.size(); i++ )
+    {
+        if( daysOfTheWeek[i]=="SU" )
+            nativeValue = nativeValue | ALARM_WEEK_FLAG_SUNDAY;
+        else if( daysOfTheWeek[i]=="MO" )
+            nativeValue = nativeValue | ALARM_WEEK_FLAG_MONDAY ;
+        else if( daysOfTheWeek[i]=="TU" )
+            nativeValue = nativeValue | ALARM_WEEK_FLAG_TUESDAY ;
+        else if( daysOfTheWeek[i]=="WE" )
+            nativeValue = nativeValue | ALARM_WEEK_FLAG_WEDNESDAY;
+        else if( daysOfTheWeek[i]=="TH" )
+            nativeValue = nativeValue | ALARM_WEEK_FLAG_THURSDAY ;
+        else if( daysOfTheWeek[i]=="FR" )
+            nativeValue = nativeValue | ALARM_WEEK_FLAG_FRIDAY ;
+        else if( daysOfTheWeek[i]=="SA" )
+            nativeValue = nativeValue | ALARM_WEEK_FLAG_SATURDAY ;
+    }
+    return nativeValue; 
+}
+
+std::vector<std::string> AlarmConverter::convertFlagToDaysOfTheWeek(int byDayValue)
+{
+    std::vector<std::string> daysOfTheWeek;
+   
+    if(byDayValue & ALARM_WEEK_FLAG_SUNDAY)
+        daysOfTheWeek.push_back("SU");
+    if(byDayValue & ALARM_WEEK_FLAG_MONDAY)
+        daysOfTheWeek.push_back("MO");
+    if(byDayValue & ALARM_WEEK_FLAG_TUESDAY)
+        daysOfTheWeek.push_back("TU");
+    if(byDayValue & ALARM_WEEK_FLAG_WEDNESDAY)
+        daysOfTheWeek.push_back("WE");
+    if(byDayValue & ALARM_WEEK_FLAG_THURSDAY)
+        daysOfTheWeek.push_back("TH");
+    if(byDayValue & ALARM_WEEK_FLAG_FRIDAY)
+        daysOfTheWeek.push_back("FR");
+    if(byDayValue & ALARM_WEEK_FLAG_SATURDAY)
+        daysOfTheWeek.push_back("SA");
+
+    return daysOfTheWeek;
+}
+
+service_h AlarmConverter::toService(std::string id)
+{
+    service_h service;
+    service_create(&service);
+    LogError("[ILOVEFILM] Enter AlarmConverter toService std package = "  << id.c_str());    
+
+    service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+    service_set_package(service, id.c_str());
+    return service;
+}
+service_h AlarmConverter::toService(std::string id, std::string page)
+{
+    service_h service;
+    service_create(&service);
+
+    LogError("[ILOVEFILM] Enter AlarmConverter toService std package = "  << id.c_str());    
+    
+    service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+    service_set_package(service, id.c_str());
+    return service;
+}
+
+bool AlarmConverter::toAlarmAbsolutePtr(int id, service_h handle, AlarmAbsolutePtr privateData)
+{   
+    char* dateString;
+    char* alarmType;
+    struct tm date;
+       memset(&date, 0, sizeof(tm));
+    int error = ALARM_ERROR_NONE;
+
+    LogInfo("Enter AlarmConverter.toAlarmAbsolutePtr");
+
+    error = service_get_extra_data(handle, ALARM_ALSOLUTE_DATE_KEY, &dateString);
+
+    LogInfo("Date Strng = " << dateString);
+    if(error != SERVICE_ERROR_NONE) 
+    {
+        LogError("Fail to get AlarmDelay");
+        return false;
+    }
+    sscanf(dateString, "%d %d %d %d %d %d", &date.tm_year, &date.tm_mon,
+        &date.tm_mday,  &date.tm_hour, &date.tm_min,  &date.tm_sec);
+    mktime(&date);
+
+    LogInfo("Converter AlarmAbsolute Date  = " << " Sec: " << date.tm_sec << ", Min: "<< date.tm_min
+    << ", Hour: " << date.tm_hour << ", Day: " << date.tm_mday << ", MON: " << date.tm_mon 
+    << ", Year: " << date.tm_year);
+
+    service_get_extra_data(handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, &alarmType);
+
+    if(!strcmp(alarmType, ALARM_ALSOLUTE_RECURRENCE_TYPE_INTERVAL)) {
+        int interval = 0;
+        alarm_get_scheduled_period(id, &interval);
+        LogInfo("interval type alarm: "<<interval);
+        privateData->setInterval(interval);        
+    } else if(!strcmp(alarmType, ALARM_ALSOLUTE_RECURRENCE_TYPE_BYDAYVALUE)) {
+        int byDayValue =0;
+        error = alarm_get_scheduled_recurrence_week_flag(id, &byDayValue);
+        LogInfo("daysOfWeek type alarm: "<<byDayValue<<", error: "<<error);
+        if(error==ALARM_ERROR_NONE && byDayValue>0) {
+            std::vector<std::string> result;
+            result = convertFlagToDaysOfTheWeek(byDayValue);
+            privateData->setByDayRecurrence(result);
+        } else {
+            LogInfo("Can't get the recurrence week flag.");
+        }
+    }
+
+    privateData->setId(id);
+    privateData->setDate(date);
+
+    return true;
+}
+
+bool AlarmConverter::toAlarmRelativePtr(int id, service_h handle, AlarmRelativePtr privateData)
+{
+    int interval = 0;
+    char* delayString;
+    int delay;
+
+    int error = ALARM_ERROR_NONE;
+    error = alarm_get_scheduled_period(id, &interval);
+    if(error != ALARM_ERROR_NONE) {
+        interval = 0;
+    } 
+
+    error = service_get_extra_data(handle, ALARM_RELATIVE_DELAY_KEY, &delayString);
+    if(error != SERVICE_ERROR_NONE) 
+    {
+        LogError("Fail to get AlarmDelay");
+        return false;
+    }
+    delay = atoi(delayString);
+    free(delayString);
+
+    privateData->setId(id);
+    privateData->setDelay(delay);
+    privateData->setPeriod(interval);
+
+    return true;
+}
+
+int AlarmConverter::toNativeInterval(std::string freq, std::string interval)
+{
+    int freqInSecond = 0;
+    int intervalValue = toInt(interval);
+
+    if (!freq.compare(ALARM_PROPERTY_MINUTELY_RECURRENCE))
+        freqInSecond = 60;
+    else if (!freq.compare(ALARM_PROPERTY_HOURLY_RECURRENCE))
+        freqInSecond = 3600;
+    else if (!freq.compare(ALARM_PROPERTY_DAILY_RECURRENCE))
+        freqInSecond = 3600*24;
+    else if (!freq.compare(ALARM_PROPERTY_WEEKLY_RECURRENCE))
+        freqInSecond = 3600 * 24 * 7;    
+
+    return freqInSecond * intervalValue;
+}
+
+bool AlarmConverter::toAlarmService(service_h service, TizenApis::Api::Application::ApplicationControlPtr appservice)
+    {
+    if (appservice->getOperation().compare("") != 0) {
+       LogDebug("operation is "<<appservice->getOperation());
+       service_set_operation(service, appservice->getOperation().c_str() );
+    } else {
+       LogDebug("Error. operation is madatory field. cannot be null");
+       return false;
+    }
+
+    if (appservice->getUri().compare("") != 0) {
+       LogDebug("uri is not null");
+       service_set_uri(service, appservice->getUri().c_str() );
+    }
+
+    if (appservice->getMime().compare("") != 0) {
+       LogDebug("mime is "<<appservice->getMime());
+       service_set_mime(service, appservice->getMime().c_str() );
+    }
+
+    LogDebug(">>> appservice->getAppControlDataArray");
+    std::vector<TizenApis::Api::Application::ApplicationControlDataPtr> appControlDataArray = appservice->getAppControlDataArray();
+
+    if (!appControlDataArray.empty()) {
+               std::string key;
+       const char** arr = NULL;                                
+       LogDebug("serviceDataArray.size() : "<<appControlDataArray.size());
+
+       for (size_t i = 0; i < appControlDataArray.size(); ++i) {
+                       key = appControlDataArray.at(i)->getKey();
+               if (key.empty()) {
+                    return false;
+               }
+               std::vector<std::string> valueArray = appControlDataArray.at(i)->getValue();
+               size_t size = valueArray.size();
+               
+               arr = (const char**)calloc(sizeof(char*), size);
+
+               for (size_t j = 0; j < size; j++) {
+                       arr[j] = valueArray.at(j).c_str();
+               }
+               
+               service_add_extra_data_array(service, key.c_str(), arr, size);
+
+               if (arr)
+                       free(arr);
+       }
+    }
+    return true;
+}
+
+}
+}
+}
+
diff --git a/src/standards/Tizen/Alarm/AlarmConverter.h b/src/standards/Tizen/Alarm/AlarmConverter.h
new file mode 100755 (executable)
index 0000000..57deb58
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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 _JS_TIZEN_ALARM_CONVERTER_H_
+#define _JS_TIZEN_ALARM_CONVERTER_H_
+
+#include <dpl/log/log.h>
+#include <vector>
+#include <string>
+#include <app.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Application/JSApplicationControl.h>
+#include <API/Application/ApplicationControl.h>
+#include <Tizen/Application/ApplicationConverter.h>
+#include "JSAlarmAbsolute.h"
+#include "AlarmAbsolute.h"
+#include "JSAlarmRelative.h"
+#include "AlarmRelative.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Alarm {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Alarm;
+
+class AlarmConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+public:
+    using Converter::toJSValueRef;
+    explicit AlarmConverter(JSContextRef context);
+    virtual ~AlarmConverter();
+
+    int toNativeAlarmValue(std::vector<std::string> daysOfTheWeek);
+    std::vector<std::string> convertFlagToDaysOfTheWeek(int byDayValue);
+    int toNativeValue(int interval);
+    std::vector<std::string> toPrivateValue(int byDayValue);
+    service_h toService(std::string id);
+    service_h toService(std::string id, std::string page);
+    bool toAlarmAbsolutePtr(int id, service_h handle, AlarmAbsolutePtr ptr);
+    bool toAlarmRelativePtr(int id, service_h handle, AlarmRelativePtr ptr);
+    int toNativeInterval(std::string freq, std::string interval);
+    bool toAlarmService(service_h alarm_service, TizenApis::Api::Application::ApplicationControlPtr ptr);
+};
+
+typedef ConverterFactory<AlarmConverter> AlarmConverterFactory;
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_ALARM_CONVERTER_H_ */
diff --git a/src/standards/Tizen/Alarm/AlarmRelative.cpp b/src/standards/Tizen/Alarm/AlarmRelative.cpp
new file mode 100755 (executable)
index 0000000..d60fdec
--- /dev/null
@@ -0,0 +1,103 @@
+//
+// 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 "AlarmRelative.h"
+#include "alarm_common.h"
+#include <Tizen/TimeUtil/JSTimeDuration.h>
+#include <app.h>
+
+namespace TizenApis {
+namespace Api {
+namespace Alarm {
+
+AlarmRelative::AlarmRelative()
+{
+    m_isRecurrence = false;
+    service_create(&m_service_handle);
+    service_add_extra_data(m_service_handle, ALARM_TYPE_KEY, ALARM_TYPE_RELATIVE_VALUE);
+    m_Period = 0;
+    m_id = -1;
+}
+
+AlarmRelative::AlarmRelative(service_h handle)
+{
+    service_clone(&m_service_handle, handle);
+    m_Period = 0;
+    m_id = -1;
+}
+
+AlarmRelative::~AlarmRelative()
+{
+    service_destroy(m_service_handle);
+}
+
+int AlarmRelative::getId() const
+{
+    return m_id;
+}
+
+void AlarmRelative::setId(const int id)
+{
+    m_id = id;
+}
+
+bool AlarmRelative::isRecurrence()
+{
+    return m_isRecurrence;
+}
+
+void AlarmRelative::setIsRecurrence(bool value)
+{
+    m_isRecurrence = value;
+}
+
+void AlarmRelative::setDelay(int delay)
+{
+    char result[12];
+    snprintf(result, sizeof(result), "%d", delay);
+    service_add_extra_data(m_service_handle, ALARM_RELATIVE_DELAY_KEY, result);
+    m_delay = delay;
+}
+
+int AlarmRelative::getDelay()
+{
+    return m_delay;
+}
+
+void AlarmRelative::setPeriod(int value)
+{
+    LogInfo("Param Peroid =  " << value);
+    m_Period = value;
+    LogInfo("Setted Period =  " << m_Period);
+}
+
+int AlarmRelative::getPeriod()
+{
+    LogInfo("return Period =  " << m_Period);
+    return m_Period;
+}
+
+service_h AlarmRelative::getService() 
+{
+    return m_service_handle;
+}
+
+}
+}
+}
+
diff --git a/src/standards/Tizen/Alarm/AlarmRelative.h b/src/standards/Tizen/Alarm/AlarmRelative.h
new file mode 100755 (executable)
index 0000000..3756481
--- /dev/null
@@ -0,0 +1,73 @@
+//
+// 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_ALARMRELATIVE_H_
+#define TIZENAPIS_API_ALARMRELATIVE_H_
+
+#include <string>
+#include <vector>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <time.h>
+#include <app.h>
+#include "alarm_common.h"
+
+namespace TizenApis {
+namespace Api {
+namespace Alarm {
+
+class AlarmRelative;
+typedef DPL::SharedPtr<AlarmRelative> AlarmRelativePtr;
+typedef std::vector<AlarmRelativePtr> AlarmRelativeArrayPtr;
+
+class AlarmRelative
+{
+  public:
+    typedef enum {
+        ALARM_TYPE_DELAY,
+        ALARM_TYPE_DATE,
+        ALARM_TYPE_INVALID,
+    } alarm_type_e;
+    
+    AlarmRelative();
+    AlarmRelative(service_h handle);
+    ~AlarmRelative();
+    void setIsRecurrence(bool value);
+    int getId() const;
+    void setId(const int id);
+    void setDelay(int delay);
+    int getDelay();
+    bool isRecurrence();
+    void setPeriod(int value);
+    int getPeriod();
+    service_h getService();
+
+  private:
+    int m_id;
+    int m_delay;
+    bool m_isRecurrence;
+    int m_Period;
+    service_h m_service_handle;
+    
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Alarm/CMakeLists.txt b/src/standards/Tizen/Alarm/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..56d1ef0
--- /dev/null
@@ -0,0 +1,37 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-alarm")
+
+pkg_search_module(alarm REQUIRED capi-appfw-application)
+
+include_directories(${alarm_INCLUDE_DIRS})
+
+set(CMAKE_INSTALL_RPATH
+               ${CMAKE_INSTALL_RPATH}
+               ${CMAKE_INSTALL_PREFIX}/tizen-2.0-tizen
+               ${CMAKE_INSTALL_PREFIX}/tizen-2.0-application
+)
+
+set(SRCS
+  AlarmAbsolute.cpp
+  AlarmConverter.cpp
+  AlarmRelative.cpp
+  JSAlarmAbsolute.cpp
+  JSAlarmManager.cpp
+  JSAlarmRelative.cpp
+  plugin_initializer.cpp
+  plugin_config.cpp
+)
+set(CMAKE_INSTALL_RPATH
+    ${CMAKE_INSTALL_RPATH}
+    "${CMAKE_INSTALL_PREFIX}/tizen-2.0-alarm"
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  wrt-plugins-tizen-2.0-tizen-impl
+  wrt-plugins-tizen-2.0-application-impl
+  ${LIBS_COMMON}
+  ${alarm_LIBRARIES}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION tizen-2.0-alarm)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION tizen-2.0-alarm)
diff --git a/src/standards/Tizen/Alarm/JSAlarmAbsolute.cpp b/src/standards/Tizen/Alarm/JSAlarmAbsolute.cpp
new file mode 100755 (executable)
index 0000000..38e8349
--- /dev/null
@@ -0,0 +1,388 @@
+//
+// 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/JSUtils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "AlarmAbsolute.h"
+#include "AlarmConverter.h"
+#include <app.h>
+#include <time.h>
+
+#include "plugin_config.h"
+#include "JSAlarmAbsolute.h"
+#include "JSAlarmManager.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Alarm {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Alarm;
+
+JSClassRef JSAlarmAbsolute::m_jsClassRef = NULL;
+
+JSClassDefinition JSAlarmAbsolute::m_jsClassInfo = {
+               0,
+               kJSClassAttributeNone,
+               TIZEN_ALARM_ABSOLUTE_INTERFACE,
+               NULL,
+               m_property,
+               m_function,
+               initialize,
+               finalize,
+               NULL, //hasProperty,
+               NULL, //getProperty,
+               NULL, //setProperty,
+               NULL, //deleteProperty,Geolocation
+               NULL, //getPropertyNames,
+               NULL,
+               constructor, // constructor
+               hasInstance,
+               NULL
+};
+
+JSStaticFunction JSAlarmAbsolute::m_function[] = { 
+       { ALARM_FUNCTION_API_GET_NEXT_SCHEDULED_DATE, JSAlarmAbsolute::getNextScheduledDate, kJSPropertyAttributeNone },
+       { 0, 0, 0 }
+};
+
+JSStaticValue JSAlarmAbsolute::m_property[] = {
+       { TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_ID, getId, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_DATE, getDate, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_PERIOD, getInterval, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_DAYSOFTHEWEEK, getDaysOfTheWeek, NULL, kJSPropertyAttributeReadOnly },
+       { 0, 0, 0, 0 }                                                                                            
+};
+
+const JSClassRef JSAlarmAbsolute::getClassRef() 
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_jsClassInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSAlarmAbsolute::getClassInfo() 
+{
+       return &m_jsClassInfo;
+}
+
+void JSAlarmAbsolute::initialize(JSContextRef context, JSObjectRef object) 
+{
+}
+void JSAlarmAbsolute::finalize(JSObjectRef object) 
+{
+    JSAlarmAbsolutePriv *priv = static_cast<JSAlarmAbsolutePriv*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        LogError("Private object is null");
+    }
+    delete priv;
+
+}
+
+bool JSAlarmAbsolute::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+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]);
+                if(daysOfTheWeek.size() >0) {
+                    privateData->setByDayRecurrence(daysOfTheWeek);    
+                }
+            } else {
+                int interval  = converter.toInt(arguments[1]);
+                if(interval <0) {
+                                       ThrowMsg(InvalidArgumentException, "Invalid period value.");
+                }
+                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;
+}
+
+AlarmAbsolutePtr JSAlarmAbsolute::getPrivData(JSObjectRef object)
+{
+    JSAlarmAbsolutePriv *priv = static_cast<JSAlarmAbsolutePriv*>(JSObjectGetPrivate(object));
+    if (!priv) {
+               ThrowMsg(ConversionException, "Object is null.");
+    }
+    AlarmAbsolutePtr result = priv->getObject();
+    if (!result) {
+               ThrowMsg(ConversionException, "Private object is null.");
+    }
+    return result;
+}
+
+JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, const int id)
+{
+    AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute());   
+    privateData->setId(id);
+    
+    JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData);
+    if (!priv) {
+               ThrowMsg(ConversionException, "Object is null.");
+    }
+    return  JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+}
+
+JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, AlarmAbsolutePtr privateData)
+{
+    JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData);
+    if (!priv) {
+               ThrowMsg(ConversionException, "Object is null.");
+    }
+    return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+}
+
+JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, struct tm date, int interval)
+{
+    AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute());
+    privateData->setDate(date);
+
+    JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData);
+    if (!priv) {
+               ThrowMsg(ConversionException, "Object is null.");
+    }
+    return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+}
+
+JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, struct tm date)
+{
+    AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute());
+    privateData->setDate(date);
+
+    JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData);
+    if (!priv) {
+               ThrowMsg(ConversionException, "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 = " << TizenApis::Tizen1_0::Alarm::JSAlarmManager::gContext);
+
+    struct tm date;
+    Converter converter(ctx);
+    int id;
+    Try
+    {
+        AlarmAbsolutePtr privateData = getPrivData(thisObject);
+        id = privateData->getId(); 
+        int err = alarm_get_scheduled_date(id, &date);
+        JSValueRef result = converter.toJSValueRef(date);
+
+        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());
+       }
+}
+
+JSValueRef JSAlarmAbsolute::getDate(JSContextRef ctx,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    Converter converter(ctx);
+    struct tm date;
+    Try
+    {
+        AlarmAbsolutePtr privateData = getPrivData(object);
+        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 
+        << "  Year : " <<  date.tm_year);
+
+        JSValueRef args[6];
+        args[0] = JSValueMakeNumber(ctx, date.tm_year + 1900);
+        args[1] = JSValueMakeNumber(ctx, date.tm_mon);
+        args[2] = JSValueMakeNumber(ctx, date.tm_mday);
+        args[3] = JSValueMakeNumber(ctx, date.tm_hour);
+        args[4] = JSValueMakeNumber(ctx, date.tm_min);
+        args[5] = JSValueMakeNumber(ctx, date.tm_sec);
+
+        JSObjectRef result = JSObjectMakeDate(ctx, 6, args, exception);
+        return result;
+    }
+       Catch(Exception)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(ctx);
+}
+
+JSValueRef JSAlarmAbsolute::getId(JSContextRef ctx,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    Converter converter(ctx);
+    int id;
+    Try
+    {
+        AlarmAbsolutePtr privateData = getPrivData(object);
+        Converter converter(ctx);
+        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());
+       }
+       return JSValueMakeUndefined(ctx);
+}
+
+JSValueRef JSAlarmAbsolute::getInterval(JSContextRef ctx,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    Converter converter(ctx);
+    int interval;
+     Try
+    {
+        AlarmAbsolutePtr privateData = getPrivData(object);
+        AbsoluteRecurrence::Type alarmType = privateData->getRecurrenceType();
+       
+        if(alarmType == AbsoluteRecurrence::Interval) {
+            interval = privateData->getInterval();
+            return converter.toJSValueRef(interval);
+        } else {
+            return JSValueMakeNull(ctx);    
+        }
+    }
+       Catch(Exception)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(ctx);
+}
+
+JSValueRef JSAlarmAbsolute::getDaysOfTheWeek(JSContextRef ctx,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    Converter converter(ctx);
+    
+    Try {
+        JSObjectRef jsResult = JSCreateArrayObject(ctx, 0, NULL);
+        AlarmAbsolutePtr privateData = getPrivData(object);
+        std::vector<std::string> daysOfTheWeek = privateData->getByDayRecurrence();
+
+        if(daysOfTheWeek.size() >0)
+        {
+            if (jsResult == NULL) 
+            {
+                ThrowMsg(NullPointerException, "Could not create js array object");
+            }
+
+            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");
+                }
+            }
+        }
+
+        return jsResult;
+       }
+       Catch(Exception)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(ctx);
+}
+
+} // Alarm
+} // Tizen1_0 
+} // TizenApis
+
+
diff --git a/src/standards/Tizen/Alarm/JSAlarmAbsolute.h b/src/standards/Tizen/Alarm/JSAlarmAbsolute.h
new file mode 100755 (executable)
index 0000000..6fcf203
--- /dev/null
@@ -0,0 +1,93 @@
+//
+// 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 _JS_TIZEN_JSALARMABSOLUTE
+#define _JS_TIZEN_JSALARMABSOLUTE
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Application/IApplicationManager.h>
+#include "AlarmAbsolute.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Alarm {
+
+using namespace TizenApis::Api::Alarm;
+
+#define TIZEN_ALARM_ABSOLUTE_INTERFACE "AlarmAbsolute"
+
+#define TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_ID "id"
+#define TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_DATE "date"
+#define TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_PERIOD "period"
+#define TIZEN_ALARM_ABSOLUTE_ATTRIBUTE_DAYSOFTHEWEEK "daysOfTheWeek"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<AlarmAbsolutePtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSAlarmAbsolutePriv;
+
+class JSAlarmAbsolute {
+public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSValueRef createJSObject(JSContextRef context, const int id);
+    static JSValueRef createJSObject(JSContextRef context, AlarmAbsolutePtr privateData);
+    static JSValueRef createJSObject(JSContextRef context, struct tm date, int interval);
+    static JSValueRef createJSObject(JSContextRef context, struct tm date);
+    static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+    
+
+protected:
+    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 getNextScheduledDate(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+    
+private:
+    static Api::Alarm::AlarmAbsolutePtr getPrivData(JSObjectRef object);
+
+    static JSValueRef getDate(JSContextRef context,
+                                        JSObjectRef object,
+                                        JSStringRef propertyName,
+                                        JSValueRef* exception);
+   
+    static JSValueRef getId(JSContextRef context,
+                                        JSObjectRef object,
+                                        JSStringRef propertyName,
+                                        JSValueRef* exception);
+
+    static JSValueRef getInterval(JSContextRef context,
+                                                JSObjectRef object,
+                                                JSStringRef propertyName,
+                                                JSValueRef* exception);
+    
+    static JSValueRef getDaysOfTheWeek(JSContextRef context,
+                                                JSObjectRef object,
+                                                JSStringRef propertyName,
+                                                JSValueRef* exception);
+    
+
+    static JSClassDefinition m_jsClassInfo;
+    static JSClassRef m_jsClassRef;
+    static JSStaticFunction m_function[];
+    static JSStaticValue m_property[];
+};
+
+}// Alarm
+} // Tizen1_0
+} // TizenApis
+
+#endif
diff --git a/src/standards/Tizen/Alarm/JSAlarmManager.cpp b/src/standards/Tizen/Alarm/JSAlarmManager.cpp
new file mode 100755 (executable)
index 0000000..cfbe5ab
--- /dev/null
@@ -0,0 +1,588 @@
+//
+// 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 <vector>
+#include <app.h>
+#include <time.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Commons/Exception.h>
+#include <Commons/Regex.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Application/JSApplicationControl.h>
+#include <API/Application/ApplicationControl.h>
+#include <Tizen/Application/ApplicationConverter.h>
+
+#include <ail.h>
+
+#include "plugin_config.h"
+#include "AlarmConverter.h"
+#include "JSAlarmAbsolute.h"
+#include "AlarmAbsolute.h"
+#include "JSAlarmRelative.h"
+#include "AlarmRelative.h"
+#include "JSAlarmManager.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Alarm {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Alarm;
+
+static bool alarm_iterate_callback(int alarm_id, void *user_data)
+{
+    std::vector<int> *alarmIds = reinterpret_cast<std::vector<int>*>(user_data);
+   
+    alarmIds->push_back(alarm_id);
+    return true;
+}
+
+JSClassRef JSAlarmManager::m_jsClassRef = NULL;
+
+JSClassDefinition JSAlarmManager::m_jsClassInfo = {
+        0,
+        kJSClassAttributeNone,
+        TIZEN_ALARM_INTERFACE,
+        NULL,
+        m_property,
+        m_function,
+        initialize,
+        finalize,
+        NULL, //hasProperty,
+        NULL, //getProperty,
+        NULL, //setProperty,
+        NULL, //deleteProperty,Geolocation
+        NULL, //getPropertyNames,
+        NULL,
+        NULL, // constructor
+        hasInstance,
+        NULL
+};
+
+JSStaticFunction JSAlarmManager::m_function[] = {    
+        { ALARM_FUNCTION_API_ADD, JSAlarmManager::add,kJSPropertyAttributeNone },
+        { ALARM_FUNCTION_API_REMOVE, JSAlarmManager::remove,kJSPropertyAttributeNone },
+        { ALARM_FUNCTION_API_REMOVE_ALL, JSAlarmManager::removeAll,kJSPropertyAttributeNone },
+        { ALARM_FUNCTION_API_GET_ALL, JSAlarmManager::getAll,kJSPropertyAttributeNone },
+        { ALARM_FUNCTION_API_GET, JSAlarmManager::get,kJSPropertyAttributeNone },
+        { 0, 0, 0 }
+};
+
+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 },
+               { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSAlarmManager::getClassRef() 
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_jsClassInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSAlarmManager::getClassInfo() 
+{
+    return &m_jsClassInfo;
+}
+
+JSContextRef JSAlarmManager::gContext = NULL;
+
+void JSAlarmManager::initialize(JSContextRef ctx, JSObjectRef object) 
+{
+    gContext = ctx;
+    LogInfo("GContext = " << gContext);
+}
+
+void JSAlarmManager::finalize(JSObjectRef object) 
+{
+}
+
+bool JSAlarmManager::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSAlarmManager::add(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+       service_h service;
+       struct tm startDate;
+       int delay = 0;
+       int alarm_id;
+       std::string applicationId;
+       std::string page;
+
+       AceSecurityStatus status = ALARM_CHECK_ACCESS(ALARM_FUNCTION_API_ADD);
+       TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
+
+       Validator check(ctx, exception);
+       AlarmConverter converter(ctx);
+       TizenApis::Tizen1_0::Application::ApplicationConverter applicationConverter(ctx);
+
+       Try {
+               if(argumentCount < 2) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+               }
+
+               if(argumentCount >= 2) {
+            if( JSValueIsNull(ctx, arguments[1]) || JSValueIsUndefined(ctx, arguments[1]) ) {
+                ThrowMsg(InvalidArgumentException, "Wrong application id.");
+            }
+                       applicationId = converter.toString(arguments[1]);
+                       LogDebug("package:[" << applicationId << "]");
+               }
+
+               if(JSValueIsObjectOfClass(ctx, arguments[0], JSAlarmAbsolute::getClassRef())) {
+                       // AlarmAbsolute obj
+                       JSObjectRef alarmObj = JSValueToObject(ctx, arguments[0], exception);
+                       JSAlarmAbsolutePriv *priv = static_cast<JSAlarmAbsolutePriv*>(JSObjectGetPrivate(alarmObj));
+                       if (!priv) {
+                               ThrowMsg(ConversionException, "Object is null.");
+                       }
+                       AlarmAbsolutePtr alarmPtr = priv->getObject();
+                       if (!alarmPtr) {
+                               ThrowMsg(ConversionException, "Private object is null.");
+                       }
+
+                       startDate = alarmPtr->getDate();
+                       service = alarmPtr->getService();
+
+                       if(argumentCount >=3) {
+                               // It's service object
+                               if(JSValueIsObjectOfClass(ctx, arguments[2], TizenApis::Tizen1_0::Application::JSApplicationControl::getClassRef())) {
+                                       TizenApis::Api::Application::ApplicationControlPtr appService = applicationConverter.toApplicationControl(arguments[2]);
+                                       if(converter.toAlarmService(service, appService) == false) {
+                                               ThrowMsg(ConversionException, "Wrong parameter type.");
+                                       }
+                               } else if (JSValueIsNull(ctx, arguments[2]) || JSValueIsUndefined(ctx, arguments[2])) {
+                    service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+                               } else {
+                    ThrowMsg(ConversionException, "Wrong third parameter.");
+                               }
+                       } else {
+                               service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+                       }
+
+                       LogDebug("applicationId:[" << applicationId << "]");
+                       service_set_app_id(service, applicationId.c_str());
+
+                       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{
+                               LogDebug("err:[" << err << "]");
+                               ThrowMsg(PlatformException, "Alarm scheduling failed.");
+                       }
+               } else if(JSValueIsObjectOfClass(ctx, arguments[0], JSAlarmRelative::getClassRef())) {
+                       JSObjectRef alarmObj = JSValueToObject(ctx, arguments[0], exception);
+                       JSAlarmRelativePriv *priv = static_cast<JSAlarmRelativePriv*>(JSObjectGetPrivate(alarmObj));
+                       if (!priv) {
+                               ThrowMsg(ConversionException, "Object is null.");
+                       }
+
+                       AlarmRelativePtr alarmPtr = priv->getObject();
+                       if (!alarmPtr) {
+                               ThrowMsg(ConversionException, "Private object is null.");
+                       }
+
+                       delay = alarmPtr->getDelay();
+                       int interval = alarmPtr->getPeriod();
+                       service = alarmPtr->getService();
+
+                       if(argumentCount >=3) {
+                               // It's service object
+                               if(JSValueIsObjectOfClass(ctx, arguments[2], TizenApis::Tizen1_0::Application::JSApplicationControl::getClassRef())) {
+                                       TizenApis::Api::Application::ApplicationControlPtr appService = applicationConverter.toApplicationControl(arguments[2]);
+                                       if(converter.toAlarmService(service, appService) == false) {
+                                               ThrowMsg(ConversionException, "Wrong third parameter type.");
+                                       }
+                               } else if (JSValueIsNull(ctx, arguments[2]) || JSValueIsUndefined(ctx, arguments[2])) {
+                    service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+                               } else {
+                    ThrowMsg(ConversionException, "Wrong third parameter.");
+                               }
+                       } else {
+                               service_set_operation(service, SERVICE_OPERATION_DEFAULT);
+                       }
+
+                       LogDebug("applicationId:[" << applicationId << "]");
+                       service_set_app_id(service, applicationId.c_str());
+
+                       int err = alarm_schedule_after_delay(service, delay, interval, &alarm_id);
+
+                       if(err == ALARM_ERROR_NONE) {
+                               alarmPtr->setId(alarm_id);
+                       }else{
+                               LogDebug("err:[" << err << "]");
+                       }
+               } else {
+                       ThrowMsg(ConversionException, "Wrong first parameter type.");
+               }
+       } 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());
+       }
+
+       return JSValueMakeUndefined(ctx);
+}
+
+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 {
+        if(argumentCount < 1 ) {
+            value = JSValueMakeUndefined(ctx);
+            id = converter.toInt(value);
+        } else {
+            id = converter.toInt(arguments[0]);
+        }
+
+        if(id <= 0) {
+            ThrowMsg(InvalidArgumentException, "Invalid id value.");
+        }
+
+        err = alarm_cancel(id);
+
+        if(err != ALARM_ERROR_NONE)
+        {
+            if(err == ALARM_ERROR_INVALID_PARAMETER) {
+                               ThrowMsg(NotFoundException, "Alarm not found.");
+            }
+            else {
+                ThrowMsg(PlatformException, "Unknown error occurred.");
+            }
+        }
+       } 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);
+}
+
+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) {
+            LogWarning("Alarm system may not be ready yet.");
+            alarmIds.clear();
+        } else if(ALARM_ERROR_NONE != error) {
+            LogInfo("Error occurred while getting all alarms: "<<error);
+            ThrowMsg(PlatformException, "Unknown error occurred.");
+        }
+
+        JSObjectRef jsResult = JSCreateArrayObject(ctx, 0, NULL);
+        int elementIndex = 0;
+
+        LogInfo("Alarms id size: " << alarmIds.size());
+        for(unsigned int i = 0; i < alarmIds.size(); i++)
+        {
+            service_h handle = NULL;
+            char* alarmType = NULL;
+            error = alarm_get_service(alarmIds.at(i), &handle);
+            if(ALARM_ERROR_NONE!=error) {
+                LogInfo("Getting service failed: "<<error);
+                continue;
+            }
+
+            error =service_get_extra_data(handle, ALARM_TYPE_KEY, &alarmType);
+            if(SERVICE_ERROR_NONE!=error) {
+                LogInfo("Getting data failed: "<<error);
+                service_destroy(handle);
+                continue;
+            }
+
+            LogInfo("Alarm id: " << alarmIds.at(i));
+            LogInfo("Alarm Type: " << alarmType);
+
+            if(!strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE)) {
+                LogInfo("Enter getAll Natvie alarm id = " << alarmIds.at(i));
+                AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(handle));
+                LogInfo("Success to make Native alarmPtr");
+
+                if(converter.toAlarmAbsolutePtr(alarmIds.at(i), handle, privateData) == false) {
+                    ThrowMsg(ConversionException, "Absolute alarm conversion failed.");
+                }
+
+                JSValueRef obj = JSAlarmAbsolute::createJSObject(ctx, privateData);
+                if(!JSSetArrayElement(ctx, jsResult, elementIndex, obj))
+                {
+                   ThrowMsg(UnknownException, "JS array creation failed.");
+                }
+            } else if( !strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE)) {
+                AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(handle));
+                if(converter.toAlarmRelativePtr(alarmIds.at(i), handle, privateData) == false) {
+                    ThrowMsg(ConversionException, "Relative alarm conversion failed.");
+                }
+                JSValueRef obj = JSAlarmRelative::createJSObject(ctx, privateData);
+                if(!JSSetArrayElement(ctx, jsResult, elementIndex, obj))
+                {
+                    ThrowMsg(UnknownException, "JS array creation failed.");
+                }
+            }
+            service_destroy(handle);
+            elementIndex++;
+        }
+        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 (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());
+    }
+}
+
+JSValueRef JSAlarmManager::get(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], 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");
+        }
+
+               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);
+}
+
+JSValueRef JSAlarmManager::getMin(JSContextRef ctx,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    Converter converter(ctx);
+    return converter.toJSValueRef(60);
+}
+
+
+JSValueRef JSAlarmManager::getHour(JSContextRef ctx,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    Converter converter(ctx);
+    return converter.toJSValueRef(3600);
+}
+
+JSValueRef JSAlarmManager::getDay(JSContextRef ctx,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    Converter converter(ctx);
+    return converter.toJSValueRef(86400);
+}
+
+JSValueRef JSAlarmManager::getWeek(JSContextRef ctx,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    Converter converter(ctx);
+    return converter.toJSValueRef(604800);
+}
+
+static ail_cb_ret_e appinfoCallback(const ail_appinfo_h appinfo, void *user_data)
+{
+       if (appinfo == NULL || user_data == NULL) {
+               return AIL_CB_RET_CANCEL;
+       }
+
+       char** pkgStrPtr = (char**)user_data;
+       char* tmpStr = NULL;
+       ail_error_e ret;
+
+       ret = ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &tmpStr);
+       if (ret != AIL_ERROR_OK) {
+               return AIL_CB_RET_CONTINUE;
+       }
+
+       if (tmpStr != NULL) {
+               *pkgStrPtr = strdup(tmpStr);
+       }
+       return AIL_CB_RET_CANCEL;
+}
+
+// get package name by id
+char* JSAlarmManager::getPackageById(const char* appId)
+{
+       LogDebug("<<< appId:[" << appId << "]");
+
+       ail_filter_h filter;
+       ail_error_e ret;
+       char* pkg = NULL;
+
+       if (appId == NULL) {
+               return NULL;
+       }
+
+
+       ret = ail_filter_new(&filter);
+       if (ret != AIL_ERROR_OK) {
+               return NULL;
+       }
+
+       ret = ail_filter_add_str(filter, AIL_PROP_X_SLP_PACKAGEID_STR , appId);
+       if (ret != AIL_ERROR_OK) {
+               ail_filter_destroy(filter);
+               return NULL;
+       }
+
+       ail_filter_list_appinfo_foreach(filter, appinfoCallback, &pkg);
+       ail_filter_destroy(filter);
+
+       LogDebug(">>> pkg:[" << pkg << "]");
+       return pkg;
+}
+
+} // Alarm
+} // Tizen1_0 
+} // TizenApis
+
diff --git a/src/standards/Tizen/Alarm/JSAlarmManager.h b/src/standards/Tizen/Alarm/JSAlarmManager.h
new file mode 100755 (executable)
index 0000000..07a6480
--- /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 _JS_TIZEN_ALARM_MANAGER
+#define _JS_TIZEN_ALARM_MANAGER
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Alarm {
+
+#define TIZEN_ALARM_INTERFACE "AlarmManager"
+
+#define TIZEN_ALARM_CONSTANT_PERIOD_MINUTE "PERIOD_MINUTE"
+#define TIZEN_ALARM_CONSTANT_PERIOD_HOUR "PERIOD_HOUR"
+#define TIZEN_ALARM_CONSTANT_PERIOD_DAY "PERIOD_DAY"
+#define TIZEN_ALARM_CONSTANT_PERIOD_WEEK "PERIOD_WEEK"
+
+class JSAlarmManager {
+public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSContextRef gContext;
+
+protected:
+    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 add(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);  
+    
+private:
+    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);
+
+    static JSClassDefinition m_jsClassInfo;
+    static JSClassRef m_jsClassRef;
+    static JSStaticFunction m_function[];
+    static JSStaticValue m_property[];
+
+};
+
+}
+} // Tizen1_0
+} // TizenApis
+
+#endif
diff --git a/src/standards/Tizen/Alarm/JSAlarmRelative.cpp b/src/standards/Tizen/Alarm/JSAlarmRelative.cpp
new file mode 100755 (executable)
index 0000000..74b0916
--- /dev/null
@@ -0,0 +1,335 @@
+//
+// 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/JSUtils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "plugin_config.h"
+
+#include "AlarmRelative.h"
+#include "AlarmConverter.h"
+#include "JSAlarmRelative.h"
+#include "JSAlarmManager.h"
+
+#include <app.h>
+#include <time.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Alarm {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Alarm;
+
+JSClassRef JSAlarmRelative::m_jsClassRef = NULL;
+
+JSClassDefinition JSAlarmRelative::m_jsClassInfo = {
+       0,
+       kJSClassAttributeNone,
+       TIZEN_ALARM_RELATIVE_INTERFACE,
+       NULL,
+       m_property,
+       m_function,
+       initialize,
+       finalize,
+       NULL, //hasProperty,
+       NULL, //getProperty,
+       NULL, //setProperty,
+       NULL, //deleteProperty,Geolocation
+       NULL, //getPropertyNames,
+       NULL,
+       constructor, // constructor
+       hasInstance,
+       NULL
+};
+
+JSStaticFunction JSAlarmRelative::m_function[] = { 
+        { ALARM_FUNCTION_API_GET_REMAINING_SECONDS, JSAlarmRelative::getRemainingSeconds, kJSPropertyAttributeNone },
+        { 0, 0, 0 }
+};
+
+JSStaticValue JSAlarmRelative::m_property[] = {
+       { TIZEN_ALARM_RELATIVE_ATTRIBUTE_ID, getId, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_ALARM_RELATIVE_ATTRIBUTE_DELAY, getDelay, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_ALARM_RELATIVE_ATTRIBUTE_PERIOD, getPeriod, NULL, kJSPropertyAttributeReadOnly },
+       { 0, 0, 0, 0 }                                                                                            
+};
+
+const JSClassRef JSAlarmRelative::getClassRef() 
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_jsClassInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSAlarmRelative::getClassInfo() 
+{
+       return &m_jsClassInfo;
+}
+
+void JSAlarmRelative::initialize(JSContextRef context, JSObjectRef object) 
+{
+}
+void JSAlarmRelative::finalize(JSObjectRef object) 
+{
+    JSAlarmRelativePriv *priv = static_cast<JSAlarmRelativePriv*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        LogError("Private object is null");
+    }
+    delete priv;
+}
+
+bool JSAlarmRelative::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+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());
+       }
+
+    return NULL;
+}
+
+AlarmRelativePtr JSAlarmRelative::getPrivData(JSObjectRef object)
+{
+    JSAlarmRelativePriv *priv = static_cast<JSAlarmRelativePriv*>(JSObjectGetPrivate(object));
+    if (!priv) {
+               ThrowMsg(ConversionException, "Object is null.");
+    }
+    AlarmRelativePtr result = priv->getObject();
+    if (!result) {
+               ThrowMsg(ConversionException, "Private object is null.");
+    }
+    return result;
+}
+
+JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, AlarmRelativePtr privateData)
+{
+    JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(context, privateData);
+    if (!priv) {
+               ThrowMsg(ConversionException, "Object is null.");
+    }
+    return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+}
+
+JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, int delay, int interval)
+{
+    AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative());
+    privateData->setDelay(delay);
+    privateData->setPeriod(interval);
+    
+    JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(context, privateData);
+    if (!priv) {
+               ThrowMsg(ConversionException, "Object is null.");
+    }
+    return JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+}
+
+JSValueRef JSAlarmRelative::getRemainingSeconds(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception)
+{
+    struct tm date;
+    struct tm current;
+    time_t currentTime;
+    time_t nextTime;
+    Converter converter(ctx);
+    int id;
+
+    Try {
+        AlarmRelativePtr privateData = getPrivData(thisObject);
+        id = privateData->getId();
+
+        int err = alarm_get_scheduled_date(id, &date);
+        if(err != ALARM_ERROR_NONE)
+        {
+            if(err == ALARM_ERROR_INVALID_PARAMETER) {
+                return JSValueMakeNull(ctx);
+            } else  {
+                ThrowMsg(PlatformException, "Unknown exception occurred.");
+            }
+        }
+
+        alarm_get_current_time(&current);
+
+        nextTime = mktime(&date);
+        currentTime = mktime(&current);
+
+        int result = nextTime - currentTime;
+
+        LogDebug("nextTime: "<<nextTime<<", currentTime: "<<currentTime<<", result: "<<result);
+
+        if(result <0) {
+            // It is impossible
+            ThrowMsg(Exception, "Invalid result value.");
+        }
+
+        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());
+       }
+}
+
+JSValueRef JSAlarmRelative::getId(JSContextRef ctx,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    Converter converter(ctx);
+    int id;
+    Try
+    {
+        AlarmRelativePtr privateData = getPrivData(object);
+        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());
+       }
+       return JSValueMakeUndefined(ctx);
+}
+
+JSValueRef JSAlarmRelative::getDelay(JSContextRef ctx,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    Converter converter(ctx);
+    int delay;
+    Try
+    {
+        AlarmRelativePtr privateData = getPrivData(object);
+        delay = privateData->getDelay();
+        LogInfo("JSAlarmRelative delay = " << delay);
+        if(delay >= 0) {
+            return converter.toJSValueRef(delay);
+        } else {
+            // Impossible
+            ThrowMsg(Exception, "Invalid delay value.");
+        }
+    }
+       Catch(Exception)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(ctx);
+}
+
+JSValueRef JSAlarmRelative::getPeriod(JSContextRef ctx,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+
+    Converter converter(ctx);
+    int period =0;
+    Try
+    {
+        AlarmRelativePtr privateData = getPrivData(object);
+        period = privateData->getPeriod();
+        LogInfo("JSAlarmRelative interval = " << period);
+         if(period <=0) {
+            return JSValueMakeNull(ctx);
+        } else {
+            return converter.toJSValueRef(period);
+        }
+    }
+       Catch(Exception)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(ctx);
+}
+
+} // Alarm
+} // Tizen1_0 
+} // TizenApis
+
+
diff --git a/src/standards/Tizen/Alarm/JSAlarmRelative.h b/src/standards/Tizen/Alarm/JSAlarmRelative.h
new file mode 100755 (executable)
index 0000000..f4b437d
--- /dev/null
@@ -0,0 +1,84 @@
+//
+// 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 _JS_TIZEN_ALARMRELATIVE
+#define _JS_TIZEN_ALARMRELATIVE
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Application/IApplicationManager.h>
+#include "AlarmRelative.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Alarm {
+
+using namespace TizenApis::Api::Alarm;
+
+#define TIZEN_ALARM_RELATIVE_INTERFACE "AlarmRelative"
+
+#define TIZEN_ALARM_RELATIVE_ATTRIBUTE_ID "id"
+#define TIZEN_ALARM_RELATIVE_ATTRIBUTE_DELAY "delay"
+#define TIZEN_ALARM_RELATIVE_ATTRIBUTE_PERIOD "period"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<AlarmRelativePtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSAlarmRelativePriv;
+
+class JSAlarmRelative {
+public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSValueRef createJSObject(JSContextRef context, AlarmRelativePtr privateData);
+    static JSValueRef createJSObject(JSContextRef context, int delay, int interval);
+    static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+protected:
+    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 getRemainingDuration(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+    static JSValueRef getRemainingSeconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+
+private:
+    static Api::Alarm::AlarmRelativePtr getPrivData(JSObjectRef object);
+   
+    static JSValueRef getId(JSContextRef context,
+                                        JSObjectRef object,
+                                        JSStringRef propertyName,
+                                        JSValueRef* exception);
+
+    static JSValueRef getDelay(JSContextRef context,
+                                                JSObjectRef object,
+                                                JSStringRef propertyName,
+                                                JSValueRef* exception);
+
+    static JSValueRef getPeriod(JSContextRef context,
+                                                JSObjectRef object,
+                                                JSStringRef propertyName,
+                                                JSValueRef* exception);
+
+    static JSClassDefinition m_jsClassInfo;
+    static JSClassRef m_jsClassRef;
+    static JSStaticFunction m_function[];
+    static JSStaticValue m_property[];
+};
+
+}// Alarm
+} // Tizen1_0
+} // TizenApis
+
+#endif
diff --git a/src/standards/Tizen/Alarm/alarm_common.h b/src/standards/Tizen/Alarm/alarm_common.h
new file mode 100755 (executable)
index 0000000..f86de27
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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_ALARM_COMMON_H_
+#define TIZENAPIS_API_ALARM_COMMON_H_
+
+namespace TizenApis {
+namespace Api {
+namespace Alarm {
+
+// Alarm Type
+#define ALARM_TYPE_KEY "TYPE"
+#define ALARM_TYPE_ABSOLUTE_VALUE "ABSOLUTE"
+#define ALARM_TYPE_RELATIVE_VALUE "RELATIVE"
+
+// Absolute Alarm Recurrence
+#define ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY "RECURRENCE"
+#define ALARM_ALSOLUTE_RECURRENCE_TYPE_INTERVAL "INTERVAL"
+#define ALARM_ALSOLUTE_RECURRENCE_TYPE_BYDAYVALUE "BYDAYVALUE"
+#define ALARM_ALSOLUTE_RECURRENCE_TYPE_NONE "NONE"
+#define ALARM_ABSOLUTE_FREQUENCY_KEY "FREQUENCY"
+#define ALARM_ABSOLUTE_FREQUENCY_INTERVAL "FREQUENCY_INTERVAL"
+#define ALARM_ALSOLUTE_DATE_KEY "DATE"
+
+// Relative Alarm Delay
+#define ALARM_RELATIVE_DELAY_KEY "RELATIVE_DELAY"
+
+// Frequency
+#define ALARM_PROPERTY_MINUTELY_RECURRENCE    "MINUTELY"
+#define ALARM_PROPERTY_HOURLY_RECURRENCE    "HOURLY"
+#define ALARM_PROPERTY_DAILY_RECURRENCE    "DAILY"
+#define ALARM_PROPERTY_WEEKLY_RECURRENCE   "WEEKLY"
+#define ALARM_PROPERTY_MONTHLY_RECURRENCE  "MONTHLY"
+#define ALARM_PROPERTY_YEARLY_RECURRENCE   "YEARLY"
+
+namespace AbsoluteRecurrence 
+{
+    typedef enum
+    {
+        NoRecurrence,
+        ByDayValue,
+        Interval,
+    }Type;
+}
+
+}
+}
+}
+#endif
diff --git a/src/standards/Tizen/Alarm/config.xml b/src/standards/Tizen/Alarm/config.xml
new file mode 100755 (executable)
index 0000000..66c81fa
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+       <library-name>libwrt-plugins-tizen-2.0-alarm.so</library-name>
+       <feature-install-uri>alarm.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/alarm</name>
+               <device-capability>alarm</device-capability>
+       </api-feature>
+
+</plugin-properties>
diff --git a/src/standards/Tizen/Alarm/plugin_config.cpp b/src/standards/Tizen/Alarm/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..8f7cc99
--- /dev/null
@@ -0,0 +1,107 @@
+//
+// 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 ALARM_FEATURE_API "http://tizen.org/privilege/alarm"
+
+#define ALARM_DEVICE_CAP "alarm"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Alarm {
+
+static FunctionMapping createAlarmFunctions();
+
+static FunctionMapping AlarmFunctions =
+    createAlarmFunctions();
+
+DEFINE_FUNCTION_GETTER(Alarm, AlarmFunctions);
+
+static FunctionMapping createAlarmFunctions()
+{
+    /**
+     * Device capabilities
+     */        
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_ALARM, ALARM_DEVICE_CAP);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_ALARM);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_ALARM, DEVICE_CAP_ALARM);
+
+    /**
+     * Api Features
+     */
+    ACE_CREATE_FEATURE(FEATURE_ALARM, ALARM_FEATURE_API);
+
+    ACE_CREATE_FEATURE_LIST(ALARM_FEATURES);
+    ACE_ADD_API_FEATURE(ALARM_FEATURES, FEATURE_ALARM);
+
+    /**
+     * Functions
+     */
+    FunctionMapping alarmMapping;
+
+    // add
+    AceFunction addFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADD,
+            ALARM_FUNCTION_API_ADD,
+            ALARM_FEATURES,
+            DEVICE_LIST_ALARM);
+    
+    alarmMapping.insert(std::make_pair(
+                                ALARM_FUNCTION_API_ADD,
+                                addFunc));
+
+    // remove
+    AceFunction removeFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_REMOVE,
+            ALARM_FUNCTION_API_REMOVE,
+            ALARM_FEATURES,
+            DEVICE_LIST_ALARM);
+    
+    alarmMapping.insert(std::make_pair(
+                                ALARM_FUNCTION_API_REMOVE,
+                                removeFunc));
+
+
+    // removeAll
+    AceFunction removeAllFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_REMOVE_ALL,
+            ALARM_FUNCTION_API_REMOVE_ALL,
+            ALARM_FEATURES,
+            DEVICE_LIST_ALARM);
+    
+    alarmMapping.insert(std::make_pair(
+                                ALARM_FUNCTION_API_REMOVE_ALL,
+                                removeAllFunc));
+
+    return alarmMapping;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Alarm/plugin_config.h b/src/standards/Tizen/Alarm/plugin_config.h
new file mode 100755 (executable)
index 0000000..a1ae05e
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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.
+//\r
+\r
+#ifndef _ALARM_PLUGIN_CONFIG_H_\r
+#define _ALARM_PLUGIN_CONFIG_H_\r
+\r
+#include <string>\r
+#include <Commons/FunctionDeclaration.h>\r
+\r
+#define ALARM_FUNCTION_API_GET_ALL "getAll"\r
+#define ALARM_FUNCTION_API_GET "get"\r
+#define ALARM_FUNCTION_API_ADD "add"\r
+#define ALARM_FUNCTION_API_REMOVE "remove"\r
+#define ALARM_FUNCTION_API_REMOVE_ALL "removeAll"\r
+#define ALARM_FUNCTION_API_GET_NEXT_SCHEDULED_DATE "getNextScheduledDate"\r
+#define ALARM_FUNCTION_API_GET_REMAINING_SECONDS "getRemainingSeconds"\r
+\r
+namespace TizenApis {\r
+namespace Tizen1_0 {\r
+namespace Alarm {\r
+\r
+DECLARE_FUNCTION_GETTER(Alarm);\r
+\r
+#define ALARM_CHECK_ACCESS(functionName)                     \\r
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(                \\r
+        getAlarmFunctionData,           \\r
+        functionName)\r
+}\r
+}\r
+}\r
+#endif\r
+\r
diff --git a/src/standards/Tizen/Alarm/plugin_initializer.cpp b/src/standards/Tizen/Alarm/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..72894c6
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <Commons/Exception.h>
+#include "JSAlarmManager.h"
+#include "JSAlarmAbsolute.h"
+#include "JSAlarmRelative.h"
+
+#define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[Tizen\\AlarmManager ] on_widget_start_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess initialization failed");
+    }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[Tizen\\AlarmManager ] on_widget_stop_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+PLUGIN_CLASS_MAP_BEGIN
+PLUGIN_CLASS_MAP_ADD_CLASS(
+        WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "alarm",
+        (js_class_template_getter)TizenApis::Tizen1_0::Alarm::JSAlarmManager::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(
+       WRT_JS_EXTENSION_OBJECT_TIZEN,
+       TIZEN_ALARM_ABSOLUTE_INTERFACE,
+       (js_class_template_getter)TizenApis::Tizen1_0::Alarm::JSAlarmAbsolute::getClassRef,
+       NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(
+       WRT_JS_EXTENSION_OBJECT_TIZEN,
+       TIZEN_ALARM_RELATIVE_INTERFACE,
+       (js_class_template_getter)TizenApis::Tizen1_0::Alarm::JSAlarmRelative::getClassRef,
+       NULL)
+PLUGIN_CLASS_MAP_END
+
diff --git a/src/standards/Tizen/Application/ApplicationAsyncCallbackManager.cpp b/src/standards/Tizen/Application/ApplicationAsyncCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..baab4a0
--- /dev/null
@@ -0,0 +1,32 @@
+//
+// 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 "ApplicationAsyncCallbackManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::Application::ApplicationAsyncCallbackManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+} // Application
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Application/ApplicationAsyncCallbackManager.h b/src/standards/Tizen/Application/ApplicationAsyncCallbackManager.h
new file mode 100755 (executable)
index 0000000..fc1006a
--- /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_APPLICATION_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_APPLICATION_ASYNC_CALLBACK_MANAGER_H_
+
+#include <dpl/singleton.h>
+#include <Tizen/Common/AsyncCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+class ApplicationAsyncCallbackManager : public TizenApis::Commons::AsyncCallbackManager
+{
+public:
+       ApplicationAsyncCallbackManager()
+       {
+       }
+
+       virtual ~ApplicationAsyncCallbackManager()
+       {
+       }
+
+       friend class DPL::Singleton<ApplicationAsyncCallbackManager>;
+};
+
+typedef DPL::Singleton<ApplicationAsyncCallbackManager> ApplicationAsyncCallbackManagerSingleton;
+
+} // Application
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_APPLICATION_ASYNC_CALLBACK_MANAGER_H_
diff --git a/src/standards/Tizen/Application/ApplicationController.cpp b/src/standards/Tizen/Application/ApplicationController.cpp
new file mode 100755 (executable)
index 0000000..83d8dc0
--- /dev/null
@@ -0,0 +1,632 @@
+//
+// 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/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ApplicationController.h"
+#include "ApplicationConverter.h"
+#include "JSApplicationEventCallbackManager.h"
+#include "ApplicationAsyncCallbackManager.h"
+#include "ApplicationInformationEventPrivateData.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Application;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+ApplicationController::ApplicationController(JSContextRef context, IApplicationManagerPtr application) :
+               EventApplicationLaunchEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventApplicationKillEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventApplicationLaunchAppControlEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventApplicationLaunchAppControlReplyEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventApplicationFindAppControlEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventApplicationGetAppsContextEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventApplicationGetAppsInfoEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventApplicationInstallEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventApplicationAppInfoEventListenerListener(ThreadEnum::NULL_THREAD),
+               ApplicationPrivObject(context, application)
+{
+       LogDebug("ApplicationController constructed : " << this);
+       if (!application) {
+               LogWarning("controller has no application object");
+       }
+}
+
+ApplicationController::~ApplicationController()
+{
+       LogDebug("ApplicationController destructed : " << this);
+}
+
+void ApplicationController::OnAnswerReceived(const EventApplicationLaunchPtr &event)
+{
+       ApplicationAsyncAnswerHandler::launch(event);
+}
+
+void ApplicationController::OnAnswerReceived(const EventApplicationKillPtr &event)
+{
+       ApplicationAsyncAnswerHandler::kill(event);
+}
+
+void ApplicationController::OnAnswerReceived(const EventApplicationLaunchAppControlPtr &event)
+{
+       ApplicationAsyncAnswerHandler::launchAppControl(event);
+}
+
+void ApplicationController::OnAnswerReceived(const EventApplicationLaunchAppControlReplyPtr &event)
+{
+       ApplicationAsyncAnswerHandler::launchAppControlReply(event);
+}
+
+void ApplicationController::OnAnswerReceived(const EventApplicationFindAppControlPtr &event)
+{
+       ApplicationAsyncAnswerHandler::findAppControl(event);
+}
+
+void ApplicationController::OnAnswerReceived(const EventApplicationGetAppsContextPtr &event)
+{
+       ApplicationAsyncAnswerHandler::getAppsContext(event);
+}
+
+void ApplicationController::OnAnswerReceived(const EventApplicationGetAppsInfoPtr &event)
+{
+       ApplicationAsyncAnswerHandler::getAppsInfo(event);
+}
+
+void ApplicationController::OnAnswerReceived(const EventApplicationInstallPtr &event)
+{
+       ApplicationAsyncAnswerHandler::install(event);
+}
+
+void ApplicationController::onAnswerReceived(const EventApplicationAppInfoEventListenerPtr &event)
+{
+       ApplicationAsyncAnswerHandler::eventListener(event);
+}
+
+void ApplicationAsyncAnswerHandler::launch(const EventApplicationLaunchPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ApplicationAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::InvalidArgumentException:
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "given app id is not found");
+                       break;
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "platform exception");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR,"unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       Try {
+               callbackManager->callOnSuccess();
+               return;
+       } Catch(Exception) {
+               LogError("error during processing answer" << _rethrown_exception.GetMessage());
+               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+
+               callbackManager->callOnError(error);
+               return;
+       }
+}
+
+void ApplicationAsyncAnswerHandler::kill(const EventApplicationKillPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ApplicationAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR,"given package is not found");
+                       break;
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR,"platform exception");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::INVALID_VALUES_ERROR, "invalid value");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR,"unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       Try {
+               callbackManager->callOnSuccess();
+               return;
+       } Catch(Exception) {
+               LogError("error during processing answer" << _rethrown_exception.GetMessage());
+               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+
+               callbackManager->callOnError(error);
+               return;
+       }
+}
+
+void ApplicationAsyncAnswerHandler::launchAppControl(const EventApplicationLaunchAppControlPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ApplicationAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR,"given package is not found");
+                       break;
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR,"platform exception");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR,"unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       Try {
+               callbackManager->callOnSuccess();
+               return;
+       } Catch(Exception) {
+               LogError("error during processing answer" << _rethrown_exception.GetMessage());
+               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+
+               callbackManager->callOnError(error);
+               return;
+       }
+}
+
+void ApplicationAsyncAnswerHandler::launchAppControlReply(const EventApplicationLaunchAppControlReplyPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ApplicationAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               callbackManager->callOnError();
+               return;
+       }
+
+       Try {
+               ApplicationControlDataArrayPtr appControlDataArray = event->getAppControlDataArray();
+               if(appControlDataArray == NULL)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException, "No reply");
+               }
+
+               ApplicationConverterFactory::ConverterType converter =
+                       ApplicationConverterFactory::getConverter(gContext);
+               JSValueRef result = converter->toJSValueRef(*appControlDataArray);
+
+               LogDebug("replyCallbackManager onsuccess");
+
+               callbackManager->callOnSuccess(result);
+               return;
+       } Catch(Exception) {
+               callbackManager->callOnError();
+               return;
+       }
+}
+
+void ApplicationAsyncAnswerHandler::findAppControl(const EventApplicationFindAppControlPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ApplicationAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR,"given package is not found");
+                       break;
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR,"platform exception");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR,"unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       Try {
+               ApplicationInformationArrayPtr appInfos = event->getAppInfos();
+               ApplicationControlPtr appControl = event->getAppControl();
+
+               ApplicationConverterFactory::ConverterType converter =
+                       ApplicationConverterFactory::getConverter(gContext);
+
+               JSValueRef result[2];
+               result[0] = converter->toJSValueRef(appInfos);
+               result[1] = converter->toJSValueRef(appControl);
+
+               callbackManager->callOnSuccess(result, 2);
+               return;
+       } Catch(Exception) {
+               LogError("error during processing answer" << _rethrown_exception.GetMessage());
+               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+
+               callbackManager->callOnError(error);
+               return;
+       }
+}
+
+void ApplicationAsyncAnswerHandler::getAppsContext(const EventApplicationGetAppsContextPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ApplicationAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR,"given package is not found");
+                       break;
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR,"platform exception");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR,"unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       Try {
+               ApplicationContextArrayPtr appContextArray = event->getAppContextArray();
+
+               ApplicationConverterFactory::ConverterType converter =
+                       ApplicationConverterFactory::getConverter(gContext);
+
+               JSValueRef result = converter->toJSValueRef(appContextArray);
+
+               callbackManager->callOnSuccess(result);
+               return;
+       } Catch(Exception) {
+               LogError("error during processing answer" << _rethrown_exception.GetMessage());
+               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+
+               callbackManager->callOnError(error);
+               return;
+       }
+}
+
+void ApplicationAsyncAnswerHandler::getAppsInfo(const EventApplicationGetAppsInfoPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ApplicationAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR,"given package is not found");
+                       break;
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR,"platform exception");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR,"unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       Try {
+               ApplicationInformationArrayPtr appInfoArray = event->getAppInfoArray();
+
+               ApplicationConverterFactory::ConverterType converter =
+                       ApplicationConverterFactory::getConverter(gContext);
+
+               JSValueRef result = converter->toJSValueRef(appInfoArray);
+
+               callbackManager->callOnSuccess(result);
+               return;
+       } Catch(Exception) {
+               LogError("error during processing answer" << _rethrown_exception.GetMessage());
+               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+
+               callbackManager->callOnError(error);
+               return;
+       }
+}
+
+void ApplicationAsyncAnswerHandler::install(const EventApplicationInstallPtr &event)
+{
+       LogDebug("<<<");
+       ApplicationInformationEventPrivateDataPtr privateData =
+                       DPL::StaticPointerCast<ApplicationInformationEventPrivateData>(event->getPrivateData());
+
+       ApplicationAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(privateData->getOnInstalled());
+       ApplicationAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(privateData->getOnUninstalled());
+       ApplicationAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(privateData->getOnUpdated());
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               LogDebug("OnAnswerReceived");
+               Try {
+                       LogDebug("Event Type: " << event->getEventType());
+                       if (event->getEventType() == EventApplicationInstall::APPLICATION_INSTALL_INSTALL) {
+                               JSCallbackManagerPtr callbackManager = privateData->getOnInstalled();
+                               if (callbackManager) {
+                                       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(callbackManager->getContext());
+                                       JSValueRef jsresult = converter->toJSValueRefFromApplicationInformation(event->getApplicationInformation());
+                                       callbackManager->callOnSuccess(jsresult);
+                               }
+                       } else if (event->getEventType() == EventApplicationInstall::APPLICATION_INSTALL_UNINSTALL) {
+                               JSCallbackManagerPtr callbackManager = privateData->getOnUninstalled();
+                               if (callbackManager) {
+                                       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(callbackManager->getContext());
+                                       LogDebug("Uninstalled AppId: " << event->getAppId());
+                                       JSValueRef jsresult = converter->toJSValueRef(event->getAppId());
+                                       callbackManager->callOnSuccess(jsresult);
+                               }
+                       } else if (event->getEventType() == EventApplicationInstall::APPLICATION_INSTALL_UPDATE) {
+                               JSCallbackManagerPtr callbackManager = privateData->getOnUpdated();
+                               if (callbackManager) {
+                                       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(callbackManager->getContext());
+                                       JSValueRef jsresult = converter->toJSValueRefFromApplicationInformation(event->getApplicationInformation());
+                                       callbackManager->callOnSuccess(jsresult);
+                               }
+                       } else {
+                               LogError("unknown event type");
+                               JSCallbackManagerPtr callbackManager = privateData->getOnInstalled();
+                               if (callbackManager) {
+                                       JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(callbackManager->getContext(),JSTizenException::UNKNOWN_ERROR,"unknown error");
+                                       callbackManager->callOnError(errorObject);
+                               }
+                       }
+
+               } Catch(WrtDeviceApis::Commons::Exception) {
+                       LogError("error during function executing");
+               }
+       } else {
+               LogDebug("Operation failed. Exception code: " << event->getExceptionCode());
+
+               JSValueRef errorObject = NULL;
+               JSCallbackManagerPtr callbackManager;
+               if (event->getEventType() == EventApplicationInstall::APPLICATION_INSTALL_INSTALL) {
+                       callbackManager = privateData->getOnInstalled();
+               } else if (event->getEventType() == EventApplicationInstall::APPLICATION_INSTALL_UNINSTALL) {
+                       callbackManager = privateData->getOnUninstalled();
+               } else if (event->getEventType() == EventApplicationInstall::APPLICATION_INSTALL_UPDATE) {
+                       callbackManager = privateData->getOnUpdated();
+               } else {
+                       callbackManager = privateData->getOnInstalled();
+               }
+
+               if(callbackManager != NULL) {
+                       JSContextRef context = callbackManager->getContext();
+
+                       WrtDeviceApis::Commons::ExceptionCodes::Enumeration exception = event->getExceptionCode();
+                       switch (exception) {
+                       case WrtDeviceApis::Commons::ExceptionCodes::NotFoundException:
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::NOT_FOUND_ERROR,"given package is not found");
+                               break;
+                       case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"platform exception");
+                               break;
+                       default:
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"unknown error");
+                               break;
+                       }
+                       callbackManager->callOnError(errorObject);
+               }
+       }
+}
+
+void ApplicationAsyncAnswerHandler::eventListener(const EventApplicationAppInfoEventListenerPtr &event)
+{
+       LogDebug("entered");
+       JSApplicationEventCallbackManagerPtr callbackManager =
+               DPL::StaticPointerCast<JSApplicationEventCallbackManager>(event->getPrivateData());
+       if (!callbackManager)
+       {
+               LogError("no callback manager");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       ApplicationConverterFactory::ConverterType converter =
+                       ApplicationConverterFactory::getConverter(gContext);
+
+       Try {
+               if(event->getType() == EventApplicationAppInfoEventListener::OnInstalled)
+               {
+                       ApplicationInformationPtr appInfo = event->getAppInfo();
+                       if(appInfo == NULL)
+                       {
+                               LogError("AppInfo did not set.");
+                               return;
+                       }
+                       JSValueRef result = converter->toJSValueRefFromApplicationInformation(appInfo);
+                       callbackManager->callOnInstalled(result);
+               }
+               else if(event->getType() == EventApplicationAppInfoEventListener::OnUpdated)
+               {
+                       ApplicationInformationPtr appInfo = event->getAppInfo();
+                       if(appInfo == NULL)
+                       {
+                               LogError("AppInfo did not set.");
+                               return;
+                       }
+                       JSValueRef result = converter->toJSValueRefFromApplicationInformation(appInfo);
+                       callbackManager->callOnUpdated(result);
+               }
+               else if(event->getType() == EventApplicationAppInfoEventListener::OnUninstalled)
+               {
+                       ApplicationInformationPtr appInfo = event->getAppInfo();
+                       std::string appId = appInfo->getAppId();
+                       if(appId == "")
+                       {
+                               LogError("AppId did not set.");
+                               return;
+                       }
+                       JSValueRef result = converter->toJSValueRef(appId);
+                       callbackManager->callOnUninstalled(result);
+               }
+               else
+               {
+                       LogError("Event callback type is wrong.");
+                       return;
+               }
+       } Catch (Exception) {
+               LogError("Conversion error");
+               return;
+       }
+}
+
+} // Application
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Application/ApplicationController.h b/src/standards/Tizen/Application/ApplicationController.h
new file mode 100755 (executable)
index 0000000..7ea931b
--- /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_APPLICATION_APPLICATION_CONTROLLER_H_
+#define _TIZEN_APPLICATION_APPLICATION_CONTROLLER_H_
+
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/EventReceiver.h>
+#include <Commons/EventListener.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSPendingOperationPrivateObject.h>
+#include <CommonsJavaScript/JSPendingOperation.h>
+#include <API/Application/IApplicationManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Application::IApplicationManagerPtr,
+                                                          WrtDeviceApis::CommonsJavaScript::NoOwnership> ApplicationPrivObject;
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Application::EventApplicationLaunch>
+               EventApplicationLaunchEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Application::EventApplicationKill>
+               EventApplicationKillEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Application::EventApplicationLaunchAppControl>
+               EventApplicationLaunchAppControlEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Application::EventApplicationLaunchAppControlReply>
+               EventApplicationLaunchAppControlReplyEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Application::EventApplicationFindAppControl>
+               EventApplicationFindAppControlEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Application::EventApplicationGetAppsContext>
+               EventApplicationGetAppsContextEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Application::EventApplicationGetAppsInfo>
+               EventApplicationGetAppsInfoEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Application::EventApplicationInstall>
+               EventApplicationInstallEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventListener<TizenApis::Api::Application::EventApplicationAppInfoEventListener>
+               EventApplicationAppInfoEventListenerListener;
+
+class ApplicationController :
+       public EventApplicationLaunchEventAnswerReceiver,
+       public EventApplicationKillEventAnswerReceiver,
+       public EventApplicationLaunchAppControlEventAnswerReceiver,
+       public EventApplicationLaunchAppControlReplyEventAnswerReceiver,
+       public EventApplicationFindAppControlEventAnswerReceiver,
+       public EventApplicationGetAppsContextEventAnswerReceiver,
+       public EventApplicationGetAppsInfoEventAnswerReceiver,
+       public EventApplicationInstallEventAnswerReceiver,
+       public EventApplicationAppInfoEventListenerListener,
+       public ApplicationPrivObject
+{
+public:
+       ApplicationController(JSContextRef context,
+                       TizenApis::Api::Application::IApplicationManagerPtr application);
+       virtual ~ApplicationController();
+protected:
+       void     OnAnswerReceived(const TizenApis::Api::Application::EventApplicationLaunchPtr &event);
+       void     OnAnswerReceived(const TizenApis::Api::Application::EventApplicationKillPtr &event);
+       void     OnAnswerReceived(const TizenApis::Api::Application::EventApplicationLaunchAppControlPtr &event);
+       void     OnAnswerReceived(const TizenApis::Api::Application::EventApplicationLaunchAppControlReplyPtr &event);
+       void     OnAnswerReceived(const TizenApis::Api::Application::EventApplicationFindAppControlPtr &event);
+       void     OnAnswerReceived(const TizenApis::Api::Application::EventApplicationGetAppsContextPtr &event);
+       void     OnAnswerReceived(const TizenApis::Api::Application::EventApplicationGetAppsInfoPtr &event);
+       void     OnAnswerReceived(const TizenApis::Api::Application::EventApplicationInstallPtr &event);
+       void     onAnswerReceived(const TizenApis::Api::Application::EventApplicationAppInfoEventListenerPtr &event);
+};
+
+typedef DPL::SharedPtr<ApplicationController> ApplicationControllerPtr;
+
+//common part
+class ApplicationAsyncAnswerHandler
+{
+public:
+       static void launch(const TizenApis::Api::Application::EventApplicationLaunchPtr &event);
+       static void kill(const TizenApis::Api::Application::EventApplicationKillPtr &event);
+       static void launchAppControl(const TizenApis::Api::Application::EventApplicationLaunchAppControlPtr &event);
+       static void launchAppControlReply(const TizenApis::Api::Application::EventApplicationLaunchAppControlReplyPtr &event);
+       static void findAppControl(const TizenApis::Api::Application::EventApplicationFindAppControlPtr &event);
+       static void getAppsContext(const TizenApis::Api::Application::EventApplicationGetAppsContextPtr &event);
+       static void getAppsInfo(const TizenApis::Api::Application::EventApplicationGetAppsInfoPtr &event);
+       static void install(const TizenApis::Api::Application::EventApplicationInstallPtr &event);
+       static void eventListener(const TizenApis::Api::Application::EventApplicationAppInfoEventListenerPtr &event);
+};
+
+} // Application
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_APPLICATION_APPLICATION_CONTROLLER_H_
diff --git a/src/standards/Tizen/Application/ApplicationConverter.cpp b/src/standards/Tizen/Application/ApplicationConverter.cpp
new file mode 100755 (executable)
index 0000000..b5c0914
--- /dev/null
@@ -0,0 +1,398 @@
+//
+// 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/JSUtils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Commons/RegexUtils.h>
+#include <Commons/Exception.h>
+
+#include "ApplicationConverter.h"
+#include "JSApplication.h"
+#include "JSApplicationInformation.h"
+#include "JSApplicationContext.h"
+#include "JSApplicationControlData.h"
+#include "JSApplicationControlData.h"
+#include "JSApplicationControl.h"
+#include "JSRequestedApplicationControl.h"
+#include "JSApplicationInstallInfo.h"
+#include "JSApplicationCert.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace Api::Application;
+
+ApplicationConverter::ApplicationConverter(JSContextRef context) : Converter(context)
+{
+}
+
+ApplicationConverter::~ApplicationConverter()
+{
+}
+
+
+JSValueRef ApplicationConverter::toJSValueRefFromApplication(const ApplicationPtr &arg)
+{
+       LogDebug("entered to toJSValueRefFromApplication ");
+       if(arg == NULL) {
+               Throw(Commons::ConversionException);
+       }
+       return CommonsJavaScript::JSUtils::makeObject(m_context, JSApplication::getClassRef(), arg);
+       //return NULL;
+}
+
+
+JSValueRef ApplicationConverter::toJSValueRefFromApplicationCert(const ApplicationCertPtr &arg)
+{
+       LogDebug("entered to toJSValueRefFromApplicationCert ");
+       if(arg == NULL) {
+               Throw(Commons::ConversionException);
+       }
+       return CommonsJavaScript::JSUtils::makeObject(m_context, JSApplicationCert::getClassRef(), arg);
+       //return NULL;
+}
+
+
+JSValueRef ApplicationConverter::toJSValueRefFromeApplicationCerts(const ApplicationCertArrayPtr &arg)
+{
+       if(arg == NULL) {
+               Throw(Commons::InvalidArgumentException);
+       }
+       return toJSValueRef_(*arg, &ApplicationConverter::toJSValueRefFromApplicationCert, this);
+}
+
+
+JSValueRef ApplicationConverter::toJSValueRefFromApplicationInformation(const ApplicationInformationPtr &arg)
+{
+       if(arg == NULL) {
+               Throw(Commons::ConversionException);
+       }
+       return CommonsJavaScript::JSUtils::makeObject(m_context, JSApplicationInformation::getClassRef(), arg);
+}
+
+ApplicationInformationPtr ApplicationConverter::toApplicationInformation(const JSValueRef &jsValue)
+{
+       if(JSApplicationInformation::isObjectOfClass(m_context, jsValue))
+               return JSApplicationInformation::getApplicationInformation(m_context, jsValue);
+
+       const ScopedJSStringRef nameStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_INFORMATION_NAME));
+       const ScopedJSStringRef appIdStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_INFORMATION_ID));
+       const ScopedJSStringRef iconPathStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_INFORMATION_ICONPATH));
+       const ScopedJSStringRef versionStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_INFORMATION_VERSION));
+       const ScopedJSStringRef showStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_INFORMATION_SHOW));
+    const ScopedJSStringRef installDateStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_INFORMATION_INSTALL_DATE));
+       const ScopedJSStringRef installSizeStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_INFORMATION_INSTALL_SIZE));
+
+       JSObjectRef jsObject = toJSObjectRef(jsValue);
+
+       JSValueRef nameData = JSObjectGetProperty(m_context, jsObject, nameStr.get(), NULL);
+       JSValueRef appIdStrData = JSObjectGetProperty(m_context, jsObject, appIdStr.get(), NULL);
+       JSValueRef iconPathData = JSObjectGetProperty(m_context, jsObject, iconPathStr.get(), NULL);
+       JSValueRef versionData = JSObjectGetProperty(m_context, jsObject, versionStr.get(), NULL);      
+       JSValueRef showData = JSObjectGetProperty(m_context, jsObject, showStr.get(), NULL);    
+       JSValueRef installDateData = JSObjectGetProperty(m_context, jsObject, installDateStr.get(), NULL);
+       JSValueRef installSizeData = JSObjectGetProperty(m_context, jsObject, installSizeStr.get(), NULL);
+
+       std::string name;
+       std::string appid;
+       std::string iconPath;
+       std::string version;
+       bool show;
+       time_t installDate;
+       long installSize;
+
+       ApplicationInformationPtr result(new ApplicationInformation());
+       if (!result) {
+               Throw(Commons::ConversionException);
+       }
+
+       if (!JSValueIsUndefined(m_context, nameData)) {
+               name = toString(nameData);
+               result->setName(name);
+       }
+       if (!JSValueIsUndefined(m_context, appIdStrData)) {
+               appid = toString(appIdStrData);
+               result->setAppId(appid);
+       }
+       if (!JSValueIsUndefined(m_context, iconPathData)) {
+               iconPath = toString(iconPathData);
+               result->setIconPath(iconPath);
+       }
+       if (!JSValueIsUndefined(m_context, versionData)) {
+               version = toString(versionData);
+               result->setVersion(version);
+       }
+       if (!JSValueIsUndefined(m_context, showData)) {
+               show = toBool(showData);
+               result->setShow(show);
+       }
+       if (!JSValueIsUndefined(m_context, installDateData)) {
+               installDate = toDateTimeT(installDateData);
+               result->setInstallDate(installDate);
+       }
+       if (!JSValueIsUndefined(m_context, installSizeData)) {
+               installSize = toDateTimeT(installSizeData);
+               result->setInstallSize(installSize);
+       }
+       return result;
+}
+
+ApplicationInstallInfoPtr ApplicationConverter::toApplicationInstallInfo(const JSValueRef &jsValue)
+{
+       if(JSApplicationInstallInfo::isObjectOfClass(m_context, jsValue))
+               return JSApplicationInstallInfo::getApplicationInstallInfo(m_context, jsValue);
+
+       const ScopedJSStringRef filePathStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_INSTALL_INFO_FILEPATH));
+       const ScopedJSStringRef algorithmStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_INSTALL_INFO_ALGORITHM));
+       const ScopedJSStringRef keyStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_INSTALL_INFO_KEY));
+       const ScopedJSStringRef packageFormatStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_INSTALL_INFO_PACKAGEFORMAT));
+
+       JSObjectRef jsObject = toJSObjectRef(jsValue);
+
+       JSValueRef filePathData = JSObjectGetProperty(m_context, jsObject, filePathStr.get(), NULL);
+       JSValueRef algorithmData = JSObjectGetProperty(m_context, jsObject, algorithmStr.get(), NULL);
+       JSValueRef keyData = JSObjectGetProperty(m_context, jsObject, keyStr.get(), NULL);
+       JSValueRef packageFormatData = JSObjectGetProperty(m_context, jsObject, packageFormatStr.get(), NULL);
+
+       ApplicationInstallInfoPtr result(new ApplicationInstallInfo());
+       if (!result) {
+               Throw(Commons::ConversionException);
+       }
+
+       if (!JSValueIsUndefined(m_context, filePathData)) {
+               result->setFilePath(toString(filePathData));
+       }
+       if (!JSValueIsUndefined(m_context, algorithmData)) {
+               result->setAlgorithm(toString(algorithmData));
+       }
+       if (!JSValueIsUndefined(m_context, keyData)) {
+               result->setKey(toString(keyData));
+       }
+       if (!JSValueIsUndefined(m_context, packageFormatData)) {
+               result->setPackageFormat(toString(packageFormatData));
+       }
+       
+       return result;
+}
+
+JSValueRef ApplicationConverter::toJSValueRef(const ApplicationInstallInfoPtr &arg)
+{
+       if(arg == NULL) {
+               Throw(Commons::ConversionException);
+       }
+       return CommonsJavaScript::JSUtils::makeObject(m_context, JSApplicationInstallInfo::getClassRef(), arg);
+}
+
+JSValueRef ApplicationConverter::toJSValueRef(const ApplicationInformationArrayPtr &arg)
+{
+       if(arg == NULL) {
+               Throw(Commons::InvalidArgumentException);
+       }
+       return toJSValueRef_(*arg, &ApplicationConverter::toJSValueRefFromApplicationInformation, this);
+}
+
+ApplicationInformationArrayPtr ApplicationConverter::toApplicationInformationArray(const JSValueRef &jsValue)
+{
+       ApplicationInformationArrayPtr result(new ApplicationInformationArray());
+
+       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(toApplicationInformation(element));
+    }
+    return result;
+}
+
+JSValueRef ApplicationConverter::toJSValueRefFromApplicationContext(const ApplicationContextPtr &arg)
+{
+       if(arg == NULL) {
+               Throw(Commons::InvalidArgumentException);
+       }
+       return CommonsJavaScript::JSUtils::makeObject(m_context, JSApplicationContext::getClassRef(), arg);
+}
+
+ApplicationContextPtr ApplicationConverter::toApplicationContext(const JSValueRef &jsValue)
+{
+       if(JSApplicationContext::isObjectOfClass(m_context, jsValue))
+               return JSApplicationContext::getApplicationContext(m_context, jsValue);
+
+       const ScopedJSStringRef appIdStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_CONTEXT_APP_ID));
+       const ScopedJSStringRef contextIdStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_CONTEXT_ID));
+
+       JSObjectRef jsObject = toJSObjectRef(jsValue);
+
+       JSValueRef appIdStrData = JSObjectGetProperty(m_context, jsObject, appIdStr.get(), NULL);
+       JSValueRef contextIdStrData = JSObjectGetProperty(m_context, jsObject, contextIdStr.get(), NULL);
+
+       std::string appid;
+       std::string contextid;
+
+       ApplicationContextPtr result(new ApplicationContext());
+       if (!result) {
+               Throw(Commons::ConversionException);
+       }
+
+       if (!JSValueIsUndefined(m_context, appIdStrData)) {
+               appid = toString(appIdStrData);
+               result->setAppId(appid);
+       }
+       if (!JSValueIsUndefined(m_context, contextIdStrData)) {
+               contextid = toString(contextIdStrData);
+               result->setContextId(contextid);
+       }
+       
+       return result;
+}
+
+JSValueRef ApplicationConverter::toJSValueRef(const ApplicationContextArrayPtr &arg)
+{
+       if(arg == NULL) {
+               Throw(Commons::ConversionException);
+       }
+       return toJSValueRef_(*arg, &ApplicationConverter::toJSValueRefFromApplicationContext, this);
+}
+
+ApplicationContextArrayPtr ApplicationConverter::toApplicationContextArray(const JSValueRef &jsValue)
+{
+       ApplicationContextArrayPtr result(new ApplicationContextArray());
+
+       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(toApplicationContext(element));
+    }
+    return result;
+}
+
+
+JSValueRef ApplicationConverter::toJSValueRef(const RequestedApplicationControlPtr &arg)
+{
+       LogDebug("entered to toJSValueRefFromRequestedApplicationControl" );
+       if(arg == NULL) {
+               Throw(Commons::InvalidArgumentException);
+       }
+       return CommonsJavaScript::JSUtils::makeObject(m_context, JSRequestedApplicationControl::getClassRef(), arg);
+}
+
+RequestedApplicationControlPtr ApplicationConverter::toRequestedApplicationControl(const JSValueRef &jsValue)
+{
+       if(JSRequestedApplicationControl::isObjectOfClass(m_context, jsValue)) {
+               return JSRequestedApplicationControl::getRequestedApplicationControl(m_context, jsValue);
+       } else {
+           ThrowMsg(Commons::ConversionException, "Wrong parameter type.");
+       }
+}
+
+
+JSValueRef ApplicationConverter::toJSValueRef(const ApplicationControlPtr &arg)
+{
+       LogDebug("entered");
+       if(arg == NULL) {
+               Throw(Commons::InvalidArgumentException);
+       }
+       return JSApplicationControl::createJSObject(m_context, arg);
+}
+
+ApplicationControlPtr ApplicationConverter::toApplicationControl(const JSValueRef &jsValue)
+{
+       if(JSApplicationControl::isObjectOfClass(m_context, jsValue)) {
+               return JSApplicationControl::getApplicationControl(m_context, jsValue);
+       } else {
+           ThrowMsg(Commons::ConversionException, "Wrong parameter type.");
+       }
+}
+
+JSValueRef ApplicationConverter::toJSValueRef(const ApplicationControlDataPtr &arg)
+{
+       LogDebug("entered");
+       return CommonsJavaScript::JSUtils::makeObject(m_context, JSApplicationControlData::getClassRef(), arg);
+}
+
+ApplicationControlDataPtr ApplicationConverter::toApplicationControlData(const JSValueRef &jsValue)
+{
+       if(JSApplicationControlData::isObjectOfClass(m_context, jsValue))
+               return JSApplicationControlData::getApplicationControlData(m_context, jsValue);
+
+       const ScopedJSStringRef appControlDataKeyStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_CONTROL_DATA_KEY));
+       const ScopedJSStringRef appControlDataValueStr(JSStringCreateWithUTF8CString(TIZEN_APPLICATION_CONTROL_DATA_VALUE));
+
+       JSObjectRef jsObject = toJSObjectRef(jsValue);
+
+       JSValueRef appControlDataKeyData = JSObjectGetProperty(m_context, jsObject, appControlDataKeyStr.get(), NULL);
+       JSValueRef appControlDataValueData = JSObjectGetProperty(m_context, jsObject, appControlDataValueStr.get(), NULL);
+
+       ApplicationControlDataPtr result(new ApplicationControlData());
+       if (!result) {
+               Throw(Commons::ConversionException);
+       }
+
+       if (!JSValueIsUndefined(m_context, appControlDataKeyData)) {
+               result->setKey(toString(appControlDataKeyData));
+       }
+
+       if (!JSValueIsUndefined(m_context, appControlDataValueData)) {
+               result->setValue(toVectorOfStrings(appControlDataValueData));
+       }
+       return result;
+}
+
+JSValueRef ApplicationConverter::toJSValueRef(const std::vector<ApplicationControlDataPtr> &arg)
+{
+    JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+
+    if (jsResult == NULL) {
+        ThrowMsg(Commons::ConversionException, "Could not create js array object");
+    }
+
+    for (std::size_t i = 0; i < arg.size(); ++i) {
+        JSValueRef tmpVal = toJSValueRef(arg[i]);
+        if (!JSSetArrayElement(m_context, jsResult, i, tmpVal)) {
+            ThrowMsg(Commons::ConversionException, "Could not insert value into js array");
+        }
+    }
+
+    return jsResult;   
+}
+
+std::vector<ApplicationControlDataPtr> ApplicationConverter::toApplicationControlDataArray(const JSValueRef &jsValue)
+{
+    if (JSValueIsNull(m_context, jsValue) || JSValueIsUndefined(m_context, jsValue)) {
+        return std::vector<ApplicationControlDataPtr>();
+    }
+
+    if (!JSIsArrayValue(m_context, jsValue)) {
+        ThrowMsg(Commons::ConversionException, "Argument is not an JS array.");
+    }
+
+    std::vector<ApplicationControlDataPtr> result;
+    JSObjectRef objArg = toJSObjectRef(jsValue);
+    for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); ++i) {
+        JSValueRef element = JSGetArrayElement(m_context, objArg, i);
+        result.push_back(toApplicationControlData(element));
+    }
+    return result;     
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Application/ApplicationConverter.h b/src/standards/Tizen/Application/ApplicationConverter.h
new file mode 100755 (executable)
index 0000000..5fa8243
--- /dev/null
@@ -0,0 +1,71 @@
+//
+// 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_APPLICATION_CONVERTER_H_
+#define TIZENAPIS_TIZEN_APPLICATION_CONVERTER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/Converter.h>
+#include <API/Application/IApplicationManager.h>
+#include <API/Application/ApplicationInformation.h>
+#include <API/Application/ApplicationContext.h>
+#include <API/Application/ApplicationControlData.h>
+#include <API/Application/ApplicationControl.h>
+#include <API/Application/ApplicationInstallInfo.h>
+#include <API/Application/ApplicationCert.h>
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+class ApplicationConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+public:
+       using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
+public:
+       explicit ApplicationConverter(JSContextRef context);
+       virtual ~ApplicationConverter();
+       JSValueRef toJSValueRefFromApplication(const Api::Application::ApplicationPtr &arg);
+       JSValueRef toJSValueRefFromApplicationInformation(const Api::Application::ApplicationInformationPtr &arg);
+       JSValueRef toJSValueRefFromApplicationCert(const Api::Application::ApplicationCertPtr &arg);
+       JSValueRef toJSValueRefFromeApplicationCerts(const Api::Application::ApplicationCertArrayPtr &arg);
+       Api::Application::ApplicationInformationPtr toApplicationInformation(const JSValueRef &jsValue);
+       JSValueRef toJSValueRef(const Api::Application::ApplicationInformationArrayPtr &arg);
+       Api::Application::ApplicationInformationArrayPtr toApplicationInformationArray(const JSValueRef &jsValue);
+       JSValueRef toJSValueRefFromApplicationContext(const Api::Application::ApplicationContextPtr &arg);
+       Api::Application::ApplicationContextPtr toApplicationContext(const JSValueRef &jsValue);
+       JSValueRef toJSValueRef(const Api::Application::ApplicationContextArrayPtr &arg);
+       Api::Application::ApplicationContextArrayPtr toApplicationContextArray(const JSValueRef &jsValue);
+       JSValueRef toJSValueRef(const Api::Application::RequestedApplicationControlPtr &arg);
+       Api::Application::RequestedApplicationControlPtr toRequestedApplicationControl(const JSValueRef &jsValue);
+       JSValueRef toJSValueRef(const Api::Application::ApplicationControlPtr &arg);
+       Api::Application::ApplicationControlPtr toApplicationControl(const JSValueRef &jsValue);
+       JSValueRef toJSValueRef(const Api::Application::ApplicationControlDataPtr &arg);
+       Api::Application::ApplicationControlDataPtr toApplicationControlData(const JSValueRef &jsValue);
+       JSValueRef toJSValueRef(const std::vector<Api::Application::ApplicationControlDataPtr> &arg);
+       std::vector<Api::Application::ApplicationControlDataPtr> toApplicationControlDataArray(const JSValueRef &jsValue);
+
+       Api::Application::ApplicationInstallInfoPtr toApplicationInstallInfo(const JSValueRef &jsValue);
+       JSValueRef toJSValueRef(const Api::Application::ApplicationInstallInfoPtr &arg);
+};
+
+typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<ApplicationConverter> ApplicationConverterFactory;
+}
+}
+}
+#endif
diff --git a/src/standards/Tizen/Application/ApplicationInformationEventPrivateData.h b/src/standards/Tizen/Application/ApplicationInformationEventPrivateData.h
new file mode 100755 (executable)
index 0000000..7c19763
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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_APPLICATION_INFORMATION_EVENT_PRIVATE_DATA_H_
+#define TIZENAPIS_TIZEN_APPLICATION_INFORMATION_EVENT_PRIVATE_DATA_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {        
+
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+class ApplicationInformationEventPrivateData : public WrtDeviceApis::Commons::IEventPrivateData
+{
+  public:
+    ApplicationInformationEventPrivateData(const JSCallbackManagerPtr& onInstalled,
+                                                                     const JSCallbackManagerPtr& onUpdated, 
+                                                                     const JSCallbackManagerPtr& onUninstalled):
+        m_onInstalled(onInstalled),
+        m_onUpdated(onUpdated),
+        m_onUninstalled(onUninstalled)
+    {
+    }
+
+    JSCallbackManagerPtr getOnInstalled() const
+    {
+        return m_onInstalled;
+    }
+    JSCallbackManagerPtr getOnUpdated() const
+    {
+        return m_onUpdated;
+    }
+    JSCallbackManagerPtr getOnUninstalled() const
+    {
+        return m_onUninstalled;
+    }
+
+private:
+    JSCallbackManagerPtr m_onInstalled;
+    JSCallbackManagerPtr m_onUpdated;
+    JSCallbackManagerPtr m_onUninstalled;
+};
+
+typedef DPL::SharedPtr<ApplicationInformationEventPrivateData> ApplicationInformationEventPrivateDataPtr;
+}
+}
+}
+#endif
diff --git a/src/standards/Tizen/Application/ApplicationListenerManager.cpp b/src/standards/Tizen/Application/ApplicationListenerManager.cpp
new file mode 100755 (executable)
index 0000000..4ea082b
--- /dev/null
@@ -0,0 +1,31 @@
+//
+// 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 "ApplicationListenerManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::Application::ApplicationListenerManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+} // Application
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Application/ApplicationListenerManager.h b/src/standards/Tizen/Application/ApplicationListenerManager.h
new file mode 100755 (executable)
index 0000000..8529589
--- /dev/null
@@ -0,0 +1,99 @@
+//
+// 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_APPLICATION_LISTENER_MANAGER_H_
+#define _TIZEN_APPLICATION_LISTENER_MANAGER_H_
+
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Tizen/Common/IListenerManager.h>
+#include "JSApplicationManager.h"
+#include "ApplicationController.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+class ApplicationListenerManager : public TizenApis::Commons::IListenerController
+{
+public:
+       ApplicationListenerManager()
+       {
+       }
+
+       virtual ~ApplicationListenerManager()
+       {
+       }
+};
+typedef DPL::Singleton<ApplicationListenerManager> ApplicationListenerManagerSingleton;
+
+class ApplicationListenerCanceller : public TizenApis::Commons::IListenerItem
+{
+public:
+       ApplicationListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
+               TizenApis::Commons::IListenerItem(context, object, watchId)
+       {
+       }
+
+       virtual ~ApplicationListenerCanceller()
+       {
+       }
+
+       virtual void cancelListener()
+       {
+               ApplicationController *priv = static_cast<ApplicationController*>(JSObjectGetPrivate(m_object));
+
+               if(!priv)
+               {
+                       LogError("Object has no private object.");
+                       return;
+               }
+
+               TizenApis::Api::Application::IApplicationManagerPtr application(priv->getObject());
+
+               Try
+               {
+                       LogDebug("Remove a listener");
+                       TizenApis::Api::Application::EventApplicationRemoveAppInfoEventListenerPtr event(
+                                       new TizenApis::Api::Application::EventApplicationRemoveAppInfoEventListener());
+
+                       event->setWatchId(m_watchId);
+                       event->setForSynchronousCall();
+
+                       Try {
+                               LogDebug("Remove change listener");
+                               application->removeAppInfoEventListener(event);
+                       } Catch(WrtDeviceApis::Commons::Exception) {
+                               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+                       }
+               }
+               Catch(WrtDeviceApis::Commons::Exception)
+               {
+                       LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               }
+       }
+};
+typedef DPL::SharedPtr<ApplicationListenerCanceller> ApplicationListenerCancellerPtr;
+
+} // Application
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_APPLICATION_LISTENER_MANAGER_H_
diff --git a/src/standards/Tizen/Application/ApplicationUtil.cpp b/src/standards/Tizen/Application/ApplicationUtil.cpp
new file mode 100755 (executable)
index 0000000..e784b63
--- /dev/null
@@ -0,0 +1,138 @@
+//
+// 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 "ApplicationUtil.h"
+#include <dpl/assert.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+ApplicationUtil::ApplicationUtil(JSContextRef context,
+        JSValueRef* exception) :
+    m_context(context),
+    m_exception(exception)
+{
+    Assert(NULL != m_context && "Context cannot be NULL.");
+}
+
+ApplicationUtil::~ApplicationUtil()
+{
+}
+
+bool ApplicationUtil::isObject(const JSValueRef& arg)
+{
+    return !JSValueIsNull(m_context, arg) &&
+                  !JSValueIsUndefined(m_context, arg) &&
+           JSValueIsObject(m_context, arg);
+}
+
+bool ApplicationUtil::isString(const JSValueRef& arg)
+{
+    return !JSValueIsNull(m_context, arg) &&
+                  !JSValueIsUndefined(m_context, arg) &&
+           JSValueIsString(m_context, arg);
+}
+
+bool ApplicationUtil::isFunction(const JSValueRef& arg)
+{
+       Converter converter(m_context);
+       return !JSValueIsNull(m_context, arg) &&
+                       !JSValueIsUndefined(m_context, arg) &&
+                       JSObjectIsFunction(m_context, converter.toJSObjectRef(arg));
+}
+
+bool ApplicationUtil::isArray(const JSValueRef& arg)
+{
+       Converter converter(m_context);
+    return !JSValueIsNull(m_context, arg) &&
+                  !JSValueIsUndefined(m_context, arg) &&
+           JSIsArrayValue(m_context, arg);
+}
+
+bool ApplicationUtil::isNullOrString(const JSValueRef& arg)
+{
+    return !JSValueIsUndefined(m_context, arg) &&
+                  (JSValueIsNull(m_context, arg) ||
+           JSValueIsString(m_context, arg));
+}
+
+bool ApplicationUtil::isNullOrObject(const JSValueRef& arg)
+{
+    return !JSValueIsUndefined(m_context, arg) &&
+                  (JSValueIsNull(m_context, arg) ||
+           JSValueIsObject(m_context, arg));
+}
+
+bool ApplicationUtil::isNullOrFunction(const JSValueRef& arg)
+{
+    Converter converter(m_context);
+    return !JSValueIsUndefined(m_context, arg) && 
+                  (JSValueIsNull(m_context, arg) ||
+           JSObjectIsFunction(m_context, converter.toJSObjectRef(arg)));
+}
+
+bool ApplicationUtil::isNullOrArray(const JSValueRef& arg)
+{
+    Converter converter(m_context);
+    return !JSValueIsUndefined(m_context, arg) && 
+                  (JSValueIsNull(m_context, arg) ||
+           JSIsArrayValue(m_context, arg));
+}
+
+bool ApplicationUtil::isNullOrUndefined(const JSValueRef& arg)
+{
+    return (JSValueIsNull(m_context, arg) ||
+            JSValueIsUndefined(m_context, arg));
+}
+
+bool ApplicationUtil::isNullOrUndefinedOrString(const JSValueRef& arg)
+{
+    return (JSValueIsNull(m_context, arg) ||
+                  JSValueIsUndefined(m_context, arg) ||
+           JSValueIsString(m_context, arg));
+}
+
+bool ApplicationUtil::isNullOrUndefinedOrObject(const JSValueRef& arg)
+{
+    return (JSValueIsNull(m_context, arg) ||
+                  JSValueIsUndefined(m_context, arg) ||
+           JSValueIsObject(m_context, arg));
+}
+
+bool ApplicationUtil::isNullOrUndefinedOrFunction(const JSValueRef& arg)
+{
+    Converter converter(m_context);
+    return (JSValueIsNull(m_context, arg) ||
+                  JSValueIsUndefined(m_context, arg) ||
+           JSObjectIsFunction(m_context, converter.toJSObjectRef(arg)));
+}
+
+bool ApplicationUtil::isNullOrUndefinedOrArray(const JSValueRef& arg)
+{
+    Converter converter(m_context);
+    return (JSValueIsNull(m_context, arg) ||
+                  JSValueIsUndefined(m_context, arg) ||
+           JSIsArrayValue(m_context, arg));
+}
+
+
+}
+} // 
+} // 
diff --git a/src/standards/Tizen/Application/ApplicationUtil.h b/src/standards/Tizen/Application/ApplicationUtil.h
new file mode 100755 (executable)
index 0000000..f9166ab
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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_APPLICATION_UTIL_H_
+#define TIZENAPIS_PLATFORM_APPLICATION_UTIL_H_
+
+#include <CommonsJavaScript/Converter.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+class ApplicationUtil
+{
+  public:
+    explicit ApplicationUtil(JSContextRef context,
+            JSValueRef* exception = NULL);
+    virtual ~ApplicationUtil();
+
+       bool isObject(const JSValueRef& arg);
+       bool isString(const JSValueRef& arg);
+       bool isFunction(const JSValueRef& arg);
+       bool isArray(const JSValueRef& arg);
+       bool isNullOrString(const JSValueRef& arg);
+       bool isNullOrObject(const JSValueRef& arg);
+       bool isNullOrFunction(const JSValueRef& arg);
+       bool isNullOrArray(const JSValueRef& arg);
+    bool isNullOrUndefined(const JSValueRef& arg);
+       bool isNullOrUndefinedOrString(const JSValueRef& arg);
+       bool isNullOrUndefinedOrObject(const JSValueRef& arg);
+       bool isNullOrUndefinedOrFunction(const JSValueRef& arg);
+       bool isNullOrUndefinedOrArray(const JSValueRef& arg);
+
+  protected:
+    JSContextRef m_context;
+    JSValueRef* m_exception;
+};
+}
+} // 
+} // 
+
+#endif
+
diff --git a/src/standards/Tizen/Application/CMakeLists.txt b/src/standards/Tizen/Application/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..6867b86
--- /dev/null
@@ -0,0 +1,51 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-application")
+set(DESTINATION_NAME "tizen-2.0-application")
+set(TARGET_IMPL_NAME "wrt-plugins-tizen-2.0-application-impl")
+
+include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_APPLICATION})
+
+set(CMAKE_INSTALL_RPATH
+  ${CMAKE_INSTALL_RPATH}
+  ${CMAKE_INSTALL_PREFIX}/${DESTINATION_NAME}
+)
+
+set(SRCS_IMPL
+  ${SRCS_PLATFORM_API_APPLICATION}
+  ${SRCS_PLATFORM_IMPLEMENTATION_APPLICATION}
+  plugin_config.cpp  
+  ApplicationAsyncCallbackManager.cpp
+  ApplicationController.cpp
+  ApplicationConverter.cpp
+  ApplicationListenerManager.cpp
+  ApplicationUtil.cpp
+  JSApplication.cpp
+  JSApplicationManager.cpp
+  JSApplicationContext.cpp
+  JSApplicationControl.cpp
+  JSApplicationControlData.cpp
+  JSRequestedApplicationControl.cpp
+  JSApplicationEventCallbackManager.cpp
+  JSApplicationInformation.cpp
+  JSApplicationCert.cpp
+  JSApplicationInstallInfo.cpp
+)
+
+add_library(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
+
+target_link_libraries(${TARGET_IMPL_NAME}
+  ${LIBS_COMMON}
+  ${LIBS_PLATFORM_IMPLEMENTATION_APPLICATION}
+)
+
+set(SRCS
+  plugin_initializer.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${TARGET_IMPL_NAME}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
+
diff --git a/src/standards/Tizen/Application/JSApplication.cpp b/src/standards/Tizen/Application/JSApplication.cpp
new file mode 100755 (executable)
index 0000000..48dee42
--- /dev/null
@@ -0,0 +1,270 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "ApplicationController.h"
+#include "ApplicationConverter.h"
+#include "plugin_config.h"
+#include "JSApplicationManager.h"
+#include "JSApplication.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {        
+       
+using namespace TizenApis::Api::Application;
+using namespace TizenApis::Commons;
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+       
+JSClassRef JSApplication::m_classRef = NULL;
+
+JSClassDefinition JSApplication::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_APPLICATION,
+    0,
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    NULL,     //HasProperty,
+    getProperty,       //GetProperty,
+    NULL,     //SetProperty,
+    NULL,     //DeleteProperty,
+    NULL,     //GetPropertyNames,
+    NULL,     //CallAsFunction,
+    NULL,     //CallAsConstructor,
+    NULL,
+    NULL,     //ConvertToType
+};
+
+
+JSStaticValue JSApplication::m_property[] = {
+    { TIZEN_APPLICATION_APP_INFO, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_APPLICATION_APP_CONTEXT_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSApplication::m_function[] = {
+               { APPLICATION_FUNCTION_API_EXIT, JSApplication::exit, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_HIDE, JSApplication::hide, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_GET_REQUESTED_APP_CONTROL, JSApplication::getRequestedAppControl, kJSPropertyAttributeNone },                        
+               { 0, 0, 0 }
+};
+
+
+JSClassRef JSApplication::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+void JSApplication::initialize(JSContextRef context, JSObjectRef object)
+{
+       LogInfo(">> initialize");
+}
+
+void JSApplication::finalize(JSObjectRef object)
+{
+    LogInfo(">> finalize");
+    JSApplicationPriv* priv = static_cast<JSApplicationPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting JSApplication object");
+    delete priv;               
+}
+
+bool JSApplication::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ApplicationPtr JSApplication::getPrivData(JSObjectRef object)
+{
+       JSApplicationPriv *priv = static_cast<JSApplicationPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ApplicationPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSValueRef JSApplication::getProperty(JSContextRef context,
+       JSObjectRef object,
+       JSStringRef propertyName,
+       JSValueRef* exception)
+{
+       Try     {
+               ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+               ApplicationPtr privateData = getPrivData(object);
+       
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_APP_INFO)) {
+                       return converter->toJSValueRefFromApplicationInformation(privateData->getAppInfo());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_APP_CONTEXT_ID)) {
+                       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");
+    }
+       
+       return NULL;
+}
+
+
+JSValueRef JSApplication::exit(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+
+// @20121206-wscho: privilege policy is changed
+#if 0
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_EXIT);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+#endif
+
+       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);
+}
+
+JSValueRef JSApplication::hide(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+
+// @20121206-wscho: privilege policy is changed
+#if 0
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_HIDE);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+#endif
+
+       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);
+}
+
+
+JSValueRef JSApplication::getRequestedAppControl(JSContextRef context,
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+
+       JSApplicationPriv *priv = static_cast<JSApplicationPriv*>(JSObjectGetPrivate(thisObject));
+
+// @20121206-wscho: privilege policy is changed
+#if 0
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_GET_REQUESTED_APP_CONTROL);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+#endif
+
+       Try {
+               if (!priv) {
+                       ThrowMsg(ConversionException, "Object is null.");
+               }
+               
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+       EventApplicationGetRequestedAppControlPtr event(new EventApplicationGetRequestedAppControl());
+               ApplicationPtr app = priv->getObject();
+
+               JSObjectRef windowObject = JSContextGetGlobalObject(context);
+               JSValueRef encodedBundle = JSObjectGetProperty(context, 
+                                                                                                       windowObject, 
+                                                                                                       ScopedJSStringRef(JSStringCreateWithUTF8CString("__bundle")).get(), 
+                                                                                                       exception);
+               if (JSValueIsUndefined(context, encodedBundle) || JSValueIsNull(context, encodedBundle)) {
+                       LogError("encodedBundle"+converter->toString(encodedBundle));
+                       return JSValueMakeNull(context);
+               }
+
+               event->setEncodedBundle(converter->toString(encodedBundle));
+               app->getRequestedAppControl(event);
+               
+               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException) {
+                       ThrowMsg(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());
+       }
+}
+
+
+}
+}
+}
diff --git a/src/standards/Tizen/Application/JSApplication.h b/src/standards/Tizen/Application/JSApplication.h
new file mode 100755 (executable)
index 0000000..7476445
--- /dev/null
@@ -0,0 +1,126 @@
+//
+// 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_JS_APPLICATION_H_
+#define TIZENAPIS_TIZEN_JS_APPLICATION_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <dpl/shared_ptr.h>
+#include <Tizen/Application/Application.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+#define TIZEN_INTERFACE_APPLICATION "Application"
+
+#define TIZEN_APPLICATION_APP_INFO "appInfo"
+#define TIZEN_APPLICATION_APP_CONTEXT_ID "contextId"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::Application::ApplicationPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSApplicationPriv;
+
+class JSApplication {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+/*
+       static JSValueRef createJSObject(JSContextRef context,
+                       const std::string &name,
+                       const std::string &package,
+                       const std::string &iconPath,
+                       const std::string &version,
+                       const bool &show,
+                       const std::vector<std::string> &categories,
+                       const time_t &installDate,
+                       const long &installSize);
+*/
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+/*
+       static Api::Application::ApplicationInformationPtr 
+               getApplicationInformation(JSContextRef context, JSValueRef value);
+*/
+       /**
+        * hide the application based on application context.
+        */
+       static JSValueRef hide(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * exit current application
+        */
+       static JSValueRef exit(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * get request application control
+        */
+       static JSValueRef getRequestedAppControl(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+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[];
+
+       /**
+        * This structure describes a statically declared function property.
+        */
+       static JSStaticFunction m_function[];   
+
+       static JSClassRef m_classRef;
+
+       static Api::Application::ApplicationPtr getPrivData(JSObjectRef object);
+
+       static JSValueRef getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception);
+
+};
+
+}
+}
+}
+#endif //TIZENAPIS_TIZEN_JS_APPLICATION_H_
diff --git a/src/standards/Tizen/Application/JSApplicationCert.cpp b/src/standards/Tizen/Application/JSApplicationCert.cpp
new file mode 100644 (file)
index 0000000..eeea794
--- /dev/null
@@ -0,0 +1,134 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <API/Application/ApplicationCert.h>
+#include "JSApplicationCert.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {        
+       
+using namespace WrtDeviceApis;
+using namespace Api::Application;
+using namespace TizenApis::Commons;
+
+
+JSClassRef JSApplicationCert::m_classRef = NULL;
+
+JSClassDefinition JSApplicationCert::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_APPLICATION_CERT,
+    0,
+    m_property,
+    0,
+    initialize,
+    finalize,
+    NULL,     //HasProperty,
+    getProperty,       //GetProperty,
+    NULL,     //SetProperty,
+    NULL,     //DeleteProperty,
+    NULL,     //GetPropertyNames,
+    NULL,     //CallAsFunction,
+    NULL,     //CallAsConstructor,
+    NULL,
+    NULL,     //ConvertToType
+};
+
+JSStaticValue JSApplicationCert::m_property[] = {
+    { TIZEN_APPLICATION_CERT_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_APPLICATION_CERT_VALUE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+JSClassRef JSApplicationCert::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+
+void JSApplicationCert::initialize(JSContextRef context, JSObjectRef object)
+{
+       LogInfo(">> initialize");
+}
+
+void JSApplicationCert::finalize(JSObjectRef object)
+{
+    LogInfo(">> finalize");
+    JSApplicationCertPriv* priv = static_cast<JSApplicationCertPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting JSApplicationCert object");
+    delete priv;               
+}
+
+bool JSApplicationCert::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ApplicationCertPtr JSApplicationCert::getPrivData(JSObjectRef object)
+{
+       JSApplicationCertPriv *priv = static_cast<JSApplicationCertPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ApplicationCertPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+
+JSValueRef JSApplicationCert::getProperty(JSContextRef context,
+       JSObjectRef object,
+       JSStringRef propertyName,
+       JSValueRef* exception)
+{
+       Try     {
+               CommonsJavaScript::Converter converter(context);
+               ApplicationCertPtr privateData = getPrivData(object);
+
+               LogError("JSApplicationCert::getProperty = " << propertyName);
+       
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CERT_TYPE)) {
+                       return converter.toJSValueRef(privateData->getType());          
+               } 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");
+    }
+       
+       return JSValueMakeUndefined(context);
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Application/JSApplicationCert.h b/src/standards/Tizen/Application/JSApplicationCert.h
new file mode 100644 (file)
index 0000000..98852ac
--- /dev/null
@@ -0,0 +1,84 @@
+//
+// 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_JS_APPLICATION_CERT_H_
+#define TIZENAPIS_TIZEN_JS_APPLICATION_CERT_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <dpl/shared_ptr.h>
+#include <API/Application/ApplicationCert.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+#define TIZEN_INTERFACE_APPLICATION_CERT "ApplicationCert"
+
+#define TIZEN_APPLICATION_CERT_TYPE            "type"
+#define TIZEN_APPLICATION_CERT_VALUE   "value"
+
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::Application::ApplicationCertPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSApplicationCertPriv;
+
+class JSApplicationCert {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(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 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 Api::Application::ApplicationCertPtr getPrivData(JSObjectRef object);
+
+       static JSValueRef getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception);
+
+};
+
+}
+}
+}
+#endif
diff --git a/src/standards/Tizen/Application/JSApplicationContext.cpp b/src/standards/Tizen/Application/JSApplicationContext.cpp
new file mode 100755 (executable)
index 0000000..321f98f
--- /dev/null
@@ -0,0 +1,172 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <API/Application/ApplicationContext.h>
+#include "JSApplicationContext.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {        
+       
+using namespace WrtDeviceApis;
+using namespace Api::Application;
+using namespace TizenApis::Commons;
+
+JSClassRef JSApplicationContext::m_classRef = NULL;
+
+JSClassDefinition JSApplicationContext::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_APPLICATION_CONTEXT,
+    0,
+    m_property,
+    0,
+    initialize,
+    finalize,
+    NULL,     //HasProperty,
+    getProperty,       //GetProperty,
+    NULL,    //SetProperty,
+    NULL,     //DeleteProperty,
+    NULL,     //GetPropertyNames,
+    NULL,     //CallAsFunction,
+    NULL,     //CallAsConstructor,
+    NULL,
+    NULL,     //ConvertToType
+};
+
+JSStaticValue JSApplicationContext::m_property[] = {
+    { TIZEN_APPLICATION_CONTEXT_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_APPLICATION_CONTEXT_APP_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+JSClassRef JSApplicationContext::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+JSValueRef JSApplicationContext::createJSObject(JSContextRef context,
+       const std::string &appId,
+       const std::string &contextId)
+{
+       ApplicationContextPtr privateData = ApplicationContextPtr(new ApplicationContext());
+       privateData->setAppId(appId);
+       privateData->setContextId(contextId);
+       
+       JSApplicationContextPriv *priv = new JSApplicationContextPriv(context, privateData);
+       
+       JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsValueRef) {
+               LogError("object creation error");
+               return JSValueMakeUndefined(context);
+       }
+       
+       return jsValueRef;
+}
+
+void JSApplicationContext::initialize(JSContextRef context, JSObjectRef object)
+{
+       LogInfo(">> initialize");
+}
+
+void JSApplicationContext::finalize(JSObjectRef object)
+{
+    LogInfo(">> finalize");
+    JSApplicationContextPriv* priv = static_cast<JSApplicationContextPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting JSApplicationContext object");
+    delete priv;               
+}
+
+bool JSApplicationContext::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ApplicationContextPtr JSApplicationContext::getPrivData(JSObjectRef object)
+{
+       JSApplicationContextPriv *priv = static_cast<JSApplicationContextPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       
+       ApplicationContextPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       
+       return result;
+}
+
+ApplicationContextPtr JSApplicationContext::getApplicationContext(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       
+       JSApplicationContextPriv *priv = static_cast<JSApplicationContextPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       
+       return priv->getObject();
+}
+
+
+JSValueRef JSApplicationContext::getProperty(JSContextRef context,
+       JSObjectRef object,
+       JSStringRef propertyName,
+       JSValueRef* exception)
+{
+       Try     {
+               CommonsJavaScript::Converter converter(context);
+               ApplicationContextPtr privateData = getPrivData(object);
+       
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTEXT_APP_ID)) {
+                       return converter.toJSValueRef(privateData->getAppId());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTEXT_ID)) {
+                       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");
+    }
+       
+       return JSValueMakeUndefined(context);
+}
+
+
+}
+}
+}
diff --git a/src/standards/Tizen/Application/JSApplicationContext.h b/src/standards/Tizen/Application/JSApplicationContext.h
new file mode 100755 (executable)
index 0000000..991b24f
--- /dev/null
@@ -0,0 +1,93 @@
+//
+// 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_JS_APPLICATION_CONTEXT_H_
+#define TIZENAPIS_TIZEN_JS_APPLICATION_CONTEXT_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <dpl/shared_ptr.h>
+#include <API/Application/ApplicationContext.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+#define TIZEN_INTERFACE_APPLICATION_CONTEXT "ApplicationContext"
+
+#define TIZEN_APPLICATION_CONTEXT_ID "id"
+#define TIZEN_APPLICATION_CONTEXT_APP_ID "appId"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::Application::ApplicationContextPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSApplicationContextPriv;
+
+class JSApplicationContext {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static JSValueRef createJSObject(JSContextRef context,
+                       const std::string &appId,
+                       const std::string &contextId);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static Api::Application::ApplicationContextPtr getApplicationContext(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 Api::Application::ApplicationContextPtr getPrivData(JSObjectRef object);
+
+       static JSValueRef getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception);
+
+};
+
+}
+}
+}
+#endif
diff --git a/src/standards/Tizen/Application/JSApplicationControl.cpp b/src/standards/Tizen/Application/JSApplicationControl.cpp
new file mode 100755 (executable)
index 0000000..f8662e0
--- /dev/null
@@ -0,0 +1,296 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+
+#include "plugin_config.h"
+
+#include "ApplicationConverter.h"
+#include "ApplicationUtil.h"
+#include "JSApplicationControl.h"
+
+using namespace TizenApis::Api::Application;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+JSClassRef JSApplicationControl::m_jsClassRef = NULL;
+
+JSClassDefinition JSApplicationControl::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_APPLICATION_CONTROL,
+    0,
+    m_property,
+    NULL,
+    initialize,
+    finalize,
+    NULL,     //HasProperty,
+    getProperty,
+    setProperty,     //SetProperty,
+    NULL,     //DeleteProperty,
+    NULL,     //GetPropertyNames,
+    NULL,     //CallAsFunction,
+    constructor,     //CallAsConstructor,
+    hasInstance,
+    NULL,     //ConvertToType
+};
+
+JSStaticValue JSApplicationControl::m_property[] = {
+    { TIZEN_APPLICATION_CONTROL_OPERATION, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_APPLICATION_CONTROL_URI, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_APPLICATION_CONTROL_MIME, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_APPLICATION_CONTROL_CATEGORY, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_APPLICATION_CONTROL_DATA, getProperty, setProperty, kJSPropertyAttributeNone },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassDefinition* JSApplicationControl::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+const JSClassRef JSApplicationControl::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+       
+    return m_jsClassRef;
+}
+
+JSObjectRef JSApplicationControl::createJSObject(JSContextRef context, const ApplicationControlPtr &appsvc)
+{
+        LogInfo(">> createJSObject");
+    JSApplicationControlPriv *priv = new JSApplicationControlPriv(context, appsvc);
+
+    if (!priv) {
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
+    }
+       
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+
+ApplicationControlPtr JSApplicationControl::getApplicationControl(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       
+       JSApplicationControlPriv *priv = static_cast<JSApplicationControlPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       return priv->getObject();
+}
+
+ApplicationControlPtr JSApplicationControl::getPrivateData(JSObjectRef object)
+{
+       JSApplicationControlPriv* priv = static_cast<JSApplicationControlPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       
+       return priv->getObject();
+}
+
+
+void JSApplicationControl::initialize(JSContextRef context,JSObjectRef object)
+{
+    LogInfo(">> initialize");
+}
+
+void JSApplicationControl::finalize(JSObjectRef object)
+{
+    LogInfo(">> finalize");
+    JSApplicationControlPriv* priv = static_cast<JSApplicationControlPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting ApplicationControl object");
+    delete priv;
+}
+
+JSObjectRef JSApplicationControl::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 operation = "";
+               std::string uri = "";
+               std::string mime = "";
+               std::string category = "";
+               std::vector<ApplicationControlDataPtr> appControlDataArray;
+
+               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;
+               
+       }
+}
+       
+
+bool JSApplicationControl::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ApplicationControlPtr JSApplicationControl::getPrivData(JSObjectRef object)
+{
+       LogDebug("entered");
+       JSApplicationControlPriv *priv = static_cast<JSApplicationControlPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ApplicationControlPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+
+JSValueRef JSApplicationControl::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    JSApplicationControlPriv *priv = static_cast<JSApplicationControlPriv*>(JSObjectGetPrivate(object));
+    if (!priv) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error.");
+       }
+
+    Try {
+        ApplicationControlPtr appsvc = priv->getObject();
+               ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_OPERATION)) {
+            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());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_MIME)) {
+            LogDebug("JSApplicationControl::getProperty::mime " << appsvc->getMime());
+            return converter->toJSValueRef(appsvc->getMime());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_CATEGORY)) {
+            LogDebug("JSApplicationControl::getProperty::category " << appsvc->getCategory());
+            return converter->toJSValueRef(appsvc->getCategory());
+               }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);
+    }
+
+       /* 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);
+               ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+       
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_OPERATION)) {
+                       privateData->setOperation(converter->toString(value));
+                       return true;
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_URI)) {
+                       privateData->setUri(converter->toString(value));
+                       return true;
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_MIME)) {
+                       privateData->setMime(converter->toString(value));
+                       return true;
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_CATEGORY)) {
+                       privateData->setCategory(converter->toString(value));
+                       return true;
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_DATA)) {
+                       privateData->setAppControlDataArray(converter->toApplicationControlDataArray(value));
+                       return true;
+               } 
+
+       } Catch(WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+        JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
+    }
+       
+       return false;
+}
+
+
+bool JSApplicationControl::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+
+}
+}
+}
diff --git a/src/standards/Tizen/Application/JSApplicationControl.h b/src/standards/Tizen/Application/JSApplicationControl.h
new file mode 100755 (executable)
index 0000000..2344d9e
--- /dev/null
@@ -0,0 +1,130 @@
+//
+// 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_JS_APPLICATION_CONTROL_H_
+#define TIZENAPIS_TIZEN_JS_APPLICATION_CONTROL_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Application/ApplicationControl.h>
+#include "JSApplicationControlData.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+#define TIZEN_INTERFACE_APPLICATION_CONTROL "ApplicationControl"
+
+#define TIZEN_APPLICATION_CONTROL_OPERATION "operation"
+#define TIZEN_APPLICATION_CONTROL_URI "uri"
+#define TIZEN_APPLICATION_CONTROL_MIME "mime"
+#define TIZEN_APPLICATION_CONTROL_CATEGORY "category"
+#define TIZEN_APPLICATION_CONTROL_DATA "data"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Application::ApplicationControlPtr>::Type JSApplicationControlPriv;
+
+class JSApplicationControl {
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       /**
+         * create an JSObject for callback function(onAnswerReceived).
+         */
+       static JSObjectRef createJSObject(JSContextRef context,
+                          const Api::Application::ApplicationControlPtr &appsvc);
+
+       /**
+        * The Constructor of ApplicationControl
+        */
+       static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static Api::Application::ApplicationControlPtr getApplicationControl(JSContextRef context, JSValueRef value);
+       /**
+         * return private data
+         */
+       static Api::Application::ApplicationControlPtr getPrivateData(JSObjectRef object);
+
+
+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 Api::Application::ApplicationControlPtr getPrivData(JSObjectRef object);
+
+  /**
+     * 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 an object is used as the target of an 'instanceof' expression.
+     */
+    static bool hasInstance(JSContextRef context,
+            JSObjectRef constructor,
+            JSValueRef possibleInstance,
+            JSValueRef* exception);
+
+  /**
+     * This structure contains properties and callbacks that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+  /**
+     * This structure describes a statically declared value property.
+     */
+    static JSStaticValue m_property[];
+
+       /**
+        * This structure describes a statically declared function property.
+        */
+       static JSStaticFunction m_function[];
+
+
+    static JSClassRef m_jsClassRef;
+
+};
+
+} //
+} //TizenApis
+}
+#endif
diff --git a/src/standards/Tizen/Application/JSApplicationControlData.cpp b/src/standards/Tizen/Application/JSApplicationControlData.cpp
new file mode 100755 (executable)
index 0000000..314966e
--- /dev/null
@@ -0,0 +1,229 @@
+//
+// 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 <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+
+#include "JSApplicationControlData.h"
+#include "ApplicationConverter.h"
+#include "ApplicationUtil.h"
+
+using namespace TizenApis::Api::Application;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+JSClassRef JSApplicationControlData::m_classRef = NULL;
+
+JSClassDefinition JSApplicationControlData::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       TIZEN_INTERFACE_APPLICATION_CONTROL_DATA,
+       NULL,
+       m_property,
+       m_functions,
+       initialize,
+       finalize,
+       NULL, //hasProperty,
+       getProperty, //GetProperty,
+       setProperty, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //getPropertyNames,
+       NULL,
+       constructor,
+       NULL,
+       NULL, //ConvertToType,
+};
+
+JSStaticValue JSApplicationControlData::m_property[] = {
+       { TIZEN_APPLICATION_CONTROL_DATA_KEY, getProperty, setProperty, kJSPropertyAttributeNone },
+       { TIZEN_APPLICATION_CONTROL_DATA_VALUE, getProperty, setProperty, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSApplicationControlData::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSApplicationControlData::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+JSValueRef JSApplicationControlData::createJSObject(JSContextRef context,
+               const std::string &key,
+               const std::vector<std::string> &value)
+{
+       ApplicationControlDataPtr privateData = ApplicationControlDataPtr(new ApplicationControlData());
+
+       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);
+       }
+       
+       return jsValueRef;
+}
+
+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;
+       }
+}
+
+void JSApplicationControlData::initialize(JSContextRef context, JSObjectRef object)
+{
+       LogInfo(">> initialize");
+}
+
+void JSApplicationControlData::finalize(JSObjectRef object)
+{
+    LogInfo(">> finalize");
+    JSApplicationControlDataPriv* priv = static_cast<JSApplicationControlDataPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting ApplicationControl object");
+    delete priv;       
+}
+
+bool JSApplicationControlData::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ApplicationControlDataPtr JSApplicationControlData::getPrivData(JSObjectRef object)
+{
+       LogDebug("entered");
+       JSApplicationControlDataPriv *priv = static_cast<JSApplicationControlDataPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ApplicationControlDataPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+ApplicationControlDataPtr JSApplicationControlData::getApplicationControlData(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSApplicationControlDataPriv *priv = static_cast<JSApplicationControlDataPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+
+JSValueRef JSApplicationControlData::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try     {
+               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+               ApplicationControlDataPtr privateData = getPrivData(object);
+               
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_DATA_KEY)) {
+                       return converter.toJSValueRef(privateData->getKey());
+               } 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);
+    }
+       
+       return JSValueMakeUndefined(context);
+}
+
+bool JSApplicationControlData::setProperty(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception)
+{
+       Try     {
+               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+               ApplicationControlDataPtr privateData = getPrivData(object);
+               
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_DATA_KEY)) {
+                       privateData->setKey(converter.toString(value));
+                       return true;
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL_DATA_VALUE)) {
+                       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");
+    }
+       
+       return false;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Application/JSApplicationControlData.h b/src/standards/Tizen/Application/JSApplicationControlData.h
new file mode 100755 (executable)
index 0000000..b3985e4
--- /dev/null
@@ -0,0 +1,108 @@
+//
+// 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_JS_APPLICATION_CONTROL_DATA_H_
+#define TIZENAPIS_TIZEN_JS_APPLICATION_CONTROL_DATA_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Application/ApplicationControlData.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+#define TIZEN_INTERFACE_APPLICATION_CONTROL_DATA "ApplicationControlData"
+
+#define TIZEN_APPLICATION_CONTROL_DATA_KEY "key"
+#define TIZEN_APPLICATION_CONTROL_DATA_VALUE "value"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::Application::ApplicationControlDataPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSApplicationControlDataPriv;
+
+class JSApplicationControlData {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static JSValueRef createJSObject(JSContextRef context,
+                       const std::string &key,
+                       const std::vector<std::string> &value);
+
+       static JSObjectRef constructor(JSContextRef ctx, 
+                       JSObjectRef constructor, 
+                       size_t argumentCount, 
+                       const JSValueRef arguments[], 
+                       JSValueRef* exception);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static Api::Application::ApplicationControlDataPtr 
+               getApplicationControlData(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 Api::Application::ApplicationControlDataPtr getPrivData(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);
+
+};
+
+}
+} 
+}
+#endif
+
diff --git a/src/standards/Tizen/Application/JSApplicationEventCallbackManager.cpp b/src/standards/Tizen/Application/JSApplicationEventCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..422107a
--- /dev/null
@@ -0,0 +1,249 @@
+//
+// 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 "JSApplicationEventCallbackManager.h"
+#include <dpl/log/log.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+JSApplicationEventCallbackManagerPtr JSApplicationEventCallbackManager::createObject(JSContextRef context)
+{
+       return JSApplicationEventCallbackManagerPtr( new JSApplicationEventCallbackManager(context) );
+}
+
+JSApplicationEventCallbackManager::JSApplicationEventCallbackManager(JSContextRef context,
+               JSObjectRef onInstalled,
+               JSObjectRef onUpdated,
+               JSObjectRef onUninstalled,
+               JSObjectRef onError ) :
+               m_onInstalled(NULL),
+               m_onUpdated(NULL),
+               m_onUninstalled(NULL),
+               m_onError(NULL),
+               m_context(context),
+               m_object(NULL)
+{
+       setOnInstalled(onInstalled);
+       setOnUpdated(onUpdated);
+       setOnUninstalled(onUninstalled);
+    setOnError(onError);
+}
+
+JSApplicationEventCallbackManager::~JSApplicationEventCallbackManager()
+{
+       if(m_onInstalled)
+       {
+               JSValueUnprotect(m_context, m_onInstalled);
+       }
+
+       if(m_onUpdated)
+       {
+               JSValueUnprotect(m_context, m_onUpdated);
+       }
+
+       if(m_onUninstalled)
+       {
+               JSValueUnprotect(m_context, m_onUninstalled);
+       }
+
+    if(m_onError)
+    {
+        JSValueUnprotect(m_context, m_onError);
+    }
+}
+
+void JSApplicationEventCallbackManager::setOnInstalled( JSValueRef onInstalled )
+{
+       if (onInstalled)
+       {
+               if (m_onInstalled != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onInstalled);
+               }
+
+               m_onInstalled = JSValueToObject( m_context, onInstalled, NULL );
+
+               if (m_onInstalled != NULL)
+               {
+                       JSValueProtect(m_context, m_onInstalled);
+               }
+       }
+}
+
+JSValueRef JSApplicationEventCallbackManager::getOnInstalled() const
+{
+       return m_onInstalled;
+}
+
+void JSApplicationEventCallbackManager::setOnUpdated( JSValueRef onUpdated )
+{
+       if (onUpdated)
+       {
+               if (m_onUpdated != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onUpdated);
+               }
+
+               m_onUpdated = JSValueToObject( m_context, onUpdated, NULL );
+
+               if (m_onUpdated != NULL)
+               {
+                       JSValueProtect(m_context, m_onUpdated);
+               }
+       }
+}
+
+JSValueRef JSApplicationEventCallbackManager::getOnUpdated() const
+{
+       return m_onUpdated;
+}
+
+void JSApplicationEventCallbackManager::setOnUninstalled( JSValueRef onUninstalled )
+{
+       if (onUninstalled)
+       {
+               if (m_onUninstalled != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onUninstalled);
+               }
+
+               m_onUninstalled = JSValueToObject( m_context, onUninstalled, NULL );
+
+               if (m_onUninstalled != NULL)
+               {
+                       JSValueProtect(m_context, m_onUninstalled);
+               }
+       }
+}
+
+JSValueRef JSApplicationEventCallbackManager::getOnUninstalled() const
+{
+       return m_onUninstalled;
+}
+
+void JSApplicationEventCallbackManager::setOnError( JSValueRef onError )
+{
+    if (onError)
+    {
+        if (m_onError != NULL)
+        {
+            JSValueUnprotect(m_context, m_onError);
+        }
+
+        m_onError = JSValueToObject( m_context, onError, NULL );
+
+        if (m_onError != NULL)
+        {
+            JSValueProtect(m_context, m_onError);
+        }
+    }
+}
+
+JSValueRef JSApplicationEventCallbackManager::getOnError() const
+{
+    return m_onError;
+}
+
+void JSApplicationEventCallbackManager::setContext( JSContextRef context )
+{
+    m_context = context;
+}
+
+void JSApplicationEventCallbackManager::setObject( JSObjectRef object )
+{
+    m_object = object;
+}
+
+JSObjectRef JSApplicationEventCallbackManager::getObject() const
+{
+    return m_object;
+}
+
+void JSApplicationEventCallbackManager::callOnInstalled( JSValueRef appInfo )
+{
+    if ( m_onInstalled == NULL )
+    {
+        //LogDebug("oninstalled callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { appInfo };
+    makeCallback( m_context, NULL, m_onInstalled, "oninstalled", objParam, 1 );
+}
+
+void JSApplicationEventCallbackManager::callOnUpdated( JSValueRef appInfo )
+{
+    if ( m_onUpdated == NULL )
+    {
+        //LogDebug("onupdated callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { appInfo };
+    makeCallback( m_context, NULL, m_onUpdated, "onupdated", objParam, 1 );
+}
+
+void JSApplicationEventCallbackManager::callOnUninstalled( JSValueRef appId )
+{
+    if ( m_onUninstalled == NULL )
+    {
+        //LogDebug("onuninstalled callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { appId };
+    makeCallback( m_context, NULL, m_onUninstalled, "onuninstalled", objParam, 1 );
+}
+
+void JSApplicationEventCallbackManager::callOnError( JSValueRef error )
+{
+    if ( m_onError == NULL )
+    {
+        //LogDebug("Error callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { error };
+    makeCallback( m_context, NULL, m_onError, "onerror", objParam, 1 );
+}
+
+void JSApplicationEventCallbackManager::makeCallback(JSContextRef context, JSObjectRef object, JSObjectRef callback, const char *szName, JSValueRef argv[], unsigned argc)
+{
+
+    if (callback == NULL)
+    {
+        LogError("callback is NULL");
+        return;
+    }
+
+    if (JSObjectIsFunction(context, callback))
+    {
+        if (argc == 0)
+        {
+                //LogDebug("Calling object directly, no arguments");
+                JSObjectCallAsFunction(context, callback, object, 0, NULL, NULL);
+        }
+        else
+        {
+                //LogDebug("Calling object directly, one argument");
+                JSObjectCallAsFunction(context, callback, object, argc, argv, NULL);
+        }
+        return;
+    }
+}
+
+} // Application
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Application/JSApplicationEventCallbackManager.h b/src/standards/Tizen/Application/JSApplicationEventCallbackManager.h
new file mode 100755 (executable)
index 0000000..ed53e55
--- /dev/null
@@ -0,0 +1,86 @@
+//
+// 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_APPLICATION_JS_APPLICATION_EVENT_CALLBACK_MANAGER_H_
+#define _TIZEN_APPLICATION_JS_APPLICATION_EVENT_CALLBACK_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <JavaScriptCore/JavaScript.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+class JSApplicationEventCallbackManager;
+typedef DPL::SharedPtr<JSApplicationEventCallbackManager> JSApplicationEventCallbackManagerPtr;
+
+class JSApplicationEventCallbackManager : public WrtDeviceApis::Commons::IEventPrivateData
+{
+private:
+       JSApplicationEventCallbackManager() {}
+       JSApplicationEventCallbackManager( JSContextRef context,
+                       JSObjectRef onInstalled = NULL,
+                       JSObjectRef onUpdated = NULL,
+                       JSObjectRef onUninstalled = NULL,
+                       JSObjectRef onError = NULL );
+
+public:
+       static JSApplicationEventCallbackManagerPtr createObject(JSContextRef context);
+
+       virtual ~JSApplicationEventCallbackManager();
+
+       void    setContext( JSContextRef context );
+       JSContextRef getContext() const { return m_context; }
+
+       void    setOnInstalled( JSValueRef onInstalled );
+       JSValueRef getOnInstalled() const;
+       void    setOnUpdated( JSValueRef onUpdated );
+       JSValueRef getOnUpdated() const;
+       void    setOnUninstalled( JSValueRef onUninstalled );
+       JSValueRef getOnUninstalled() const;
+       void    setOnError( JSValueRef onError );
+       JSValueRef getOnError() const;
+       void    setObject( JSObjectRef object );
+       JSObjectRef getObject() const;
+
+       void    callOnInstalled( JSValueRef contacts );
+       void    callOnUpdated( JSValueRef contacts );
+       void    callOnUninstalled( JSValueRef contactIds );
+       void    callOnError( JSValueRef error );
+
+private:
+       void    makeCallback(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef callback,
+                       const char *szName,
+                       JSValueRef argv[],
+                       unsigned argc);
+
+       JSObjectRef  m_onInstalled;
+       JSObjectRef  m_onUpdated;
+       JSObjectRef  m_onUninstalled;
+       JSObjectRef  m_onError;
+       JSContextRef m_context;
+       JSObjectRef  m_object;
+};
+
+} // Application
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_APPLICATION_JS_APPLICATION_EVENT_CALLBACK_MANAGER_H_
diff --git a/src/standards/Tizen/Application/JSApplicationInformation.cpp b/src/standards/Tizen/Application/JSApplicationInformation.cpp
new file mode 100755 (executable)
index 0000000..dcac759
--- /dev/null
@@ -0,0 +1,198 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <API/Application/ApplicationInformation.h>
+#include "JSApplicationInformation.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {        
+       
+using namespace WrtDeviceApis;
+using namespace Api::Application;
+using namespace TizenApis::Commons;
+
+
+JSClassRef JSApplicationInformation::m_classRef = NULL;
+
+JSClassDefinition JSApplicationInformation::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_APPLICATION_INFORMATION,
+    0,
+    m_property,
+    0,
+    initialize,
+    finalize,
+    NULL,     //HasProperty,
+    getProperty,       //GetProperty,
+    NULL,     //SetProperty,
+    NULL,     //DeleteProperty,
+    NULL,     //GetPropertyNames,
+    NULL,     //CallAsFunction,
+    NULL,     //CallAsConstructor,
+    NULL,
+    NULL,     //ConvertToType
+};
+
+JSStaticValue JSApplicationInformation::m_property[] = {
+    { TIZEN_APPLICATION_INFORMATION_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_APPLICATION_INFORMATION_NAME, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_APPLICATION_INFORMATION_ICONPATH, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_APPLICATION_INFORMATION_VERSION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_APPLICATION_INFORMATION_SHOW, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_APPLICATION_INFORMATION_CATEGORIES, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_APPLICATION_INFORMATION_INSTALL_DATE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_APPLICATION_INFORMATION_INSTALL_SIZE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+JSClassRef JSApplicationInformation::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+JSValueRef JSApplicationInformation::createJSObject(JSContextRef context,
+               const std::string &name,
+               const std::string &appId,
+               const std::string &iconPath,
+               const std::string &version,
+               const bool &show,
+               const std::vector<std::string> &categories,
+               const time_t &installDate,
+               const long &installSize)
+{
+       ApplicationInformationPtr privateData = ApplicationInformationPtr(new ApplicationInformation());
+       privateData->setName(name);
+       privateData->setAppId(appId);
+       privateData->setIconPath(iconPath);
+       privateData->setVersion(version);
+       privateData->setShow(show);
+       privateData->setCategories(categories);
+       privateData->setInstallDate(installDate);
+       privateData->setInstallSize(installSize);
+       
+       JSApplicationInformationPriv *priv = new JSApplicationInformationPriv(context, privateData);
+       
+       JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsValueRef) {
+               LogError("object creation error");
+               return JSValueMakeUndefined(context);
+       }
+       
+       return jsValueRef;
+}
+
+void JSApplicationInformation::initialize(JSContextRef context, JSObjectRef object)
+{
+       LogInfo(">> initialize");
+}
+
+void JSApplicationInformation::finalize(JSObjectRef object)
+{
+    LogInfo(">> finalize");
+    JSApplicationInformationPriv* priv = static_cast<JSApplicationInformationPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting JSApplicationInformation object");
+    delete priv;               
+}
+
+bool JSApplicationInformation::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ApplicationInformationPtr JSApplicationInformation::getPrivData(JSObjectRef object)
+{
+       JSApplicationInformationPriv *priv = static_cast<JSApplicationInformationPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ApplicationInformationPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+ApplicationInformationPtr JSApplicationInformation::getApplicationInformation(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       
+       JSApplicationInformationPriv *priv = static_cast<JSApplicationInformationPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       
+       return priv->getObject();
+}
+
+JSValueRef JSApplicationInformation::getProperty(JSContextRef context,
+       JSObjectRef object,
+       JSStringRef propertyName,
+       JSValueRef* exception)
+{
+       Try     {
+               CommonsJavaScript::Converter converter(context);
+               ApplicationInformationPtr privateData = getPrivData(object);
+       
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INFORMATION_NAME)) {
+                       return converter.toJSValueRef(privateData->getName());          
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INFORMATION_ID)) {
+                       return converter.toJSValueRef(privateData->getAppId());         
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INFORMATION_ICONPATH)) {
+                       return converter.toJSValueRef(privateData->getIconPath());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INFORMATION_VERSION)) {
+                       return converter.toJSValueRef(privateData->getVersion());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INFORMATION_SHOW)) {
+                       return converter.toJSValueRef(privateData->getShow());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INFORMATION_CATEGORIES)) {
+                       return converter.toJSValueRef(privateData->getCategories());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INFORMATION_INSTALL_DATE)) {
+                       return converter.toJSValueRef(privateData->getInstallDate());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INFORMATION_INSTALL_SIZE)) {
+                       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");
+    }
+       
+       return JSValueMakeUndefined(context);
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Application/JSApplicationInformation.h b/src/standards/Tizen/Application/JSApplicationInformation.h
new file mode 100755 (executable)
index 0000000..d7a48df
--- /dev/null
@@ -0,0 +1,107 @@
+//
+// 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_JS_APPLICATION_INFORMATION_H_
+#define TIZENAPIS_TIZEN_JS_APPLICATION_INFORMATION_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <dpl/shared_ptr.h>
+#include <API/Application/ApplicationInformation.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+#define TIZEN_INTERFACE_APPLICATION_INFORMATION "ApplicationInformation"
+
+#define TIZEN_APPLICATION_INFORMATION_ID "id"
+#define TIZEN_APPLICATION_INFORMATION_NAME "name"
+#define TIZEN_APPLICATION_INFORMATION_ICONPATH "iconPath"
+#define TIZEN_APPLICATION_INFORMATION_VERSION "version"
+#define TIZEN_APPLICATION_INFORMATION_SHOW "show"
+#define TIZEN_APPLICATION_INFORMATION_CATEGORIES "categories"
+#define TIZEN_APPLICATION_INFORMATION_INSTALL_DATE "installDate"
+#define TIZEN_APPLICATION_INFORMATION_INSTALL_SIZE "size"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::Application::ApplicationInformationPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSApplicationInformationPriv;
+
+class JSApplicationInformation {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static JSValueRef createJSObject(JSContextRef context,
+                       const std::string &name,
+                       const std::string &package,
+                       const std::string &iconPath,
+                       const std::string &version,
+                       const bool &show,
+                       const std::vector<std::string> &categories,
+                       const time_t &installDate,
+                       const long &installSize);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static Api::Application::ApplicationInformationPtr 
+               getApplicationInformation(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 Api::Application::ApplicationInformationPtr getPrivData(JSObjectRef object);
+
+       static JSValueRef getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception);
+
+};
+
+}
+}
+}
+#endif
diff --git a/src/standards/Tizen/Application/JSApplicationInstallInfo.cpp b/src/standards/Tizen/Application/JSApplicationInstallInfo.cpp
new file mode 100755 (executable)
index 0000000..91c974f
--- /dev/null
@@ -0,0 +1,179 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <API/Application/ApplicationInstallInfo.h>
+#include "JSApplicationInstallInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {        
+       
+using namespace WrtDeviceApis;
+using namespace Api::Application;
+using namespace TizenApis::Commons;
+
+JSClassRef JSApplicationInstallInfo::m_classRef = NULL;
+
+//TODO: recheck
+JSClassDefinition JSApplicationInstallInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_APPLICATION_INSTALL_INFO,
+    0,
+    m_property,
+    0,
+    initialize,
+    finalize,
+    NULL,     //HasProperty,
+    getProperty,       //GetProperty,
+    NULL,     //SetProperty,
+    NULL,     //DeleteProperty,
+    NULL,     //GetPropertyNames,
+    NULL,     //CallAsFunction,
+    NULL,     //CallAsConstructor,
+    NULL,
+    NULL,     //ConvertToType
+};
+
+JSStaticValue JSApplicationInstallInfo::m_property[] = {
+    { TIZEN_APPLICATION_INSTALL_INFO_FILEPATH, getProperty, NULL, kJSPropertyAttributeNone },
+    { TIZEN_APPLICATION_INSTALL_INFO_ALGORITHM, getProperty, NULL, kJSPropertyAttributeNone },
+    { TIZEN_APPLICATION_INSTALL_INFO_KEY, getProperty, NULL, kJSPropertyAttributeNone },
+    { TIZEN_APPLICATION_INSTALL_INFO_PACKAGEFORMAT, getProperty, NULL, kJSPropertyAttributeNone },
+    { 0, 0, 0, 0 }
+};
+
+JSClassRef JSApplicationInstallInfo::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+JSValueRef JSApplicationInstallInfo::createJSObject(JSContextRef context,
+               const std::string &filePath,
+               const std::string &algorithm,
+               const std::string &key,
+               const std::string &packageFormat)
+{
+       ApplicationInstallInfoPtr privateData = ApplicationInstallInfoPtr(new ApplicationInstallInfo());
+       privateData->setFilePath(filePath);
+       privateData->setAlgorithm(algorithm);
+       privateData->setKey(key);
+       privateData->setPackageFormat(packageFormat);
+       
+       JSApplicationInstallInfoPriv *priv = new JSApplicationInstallInfoPriv(context, privateData);
+       
+       JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsValueRef) {
+               LogError("object creation error");
+               return JSValueMakeUndefined(context);
+       }
+       
+       return jsValueRef;
+}
+
+void JSApplicationInstallInfo::initialize(JSContextRef context, JSObjectRef object)
+{
+       LogInfo(">> initialize");
+}
+
+void JSApplicationInstallInfo::finalize(JSObjectRef object)
+{
+    LogInfo(">> finalize");
+    JSApplicationInstallInfoPriv* priv = static_cast<JSApplicationInstallInfoPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting JSApplicationInstallInfo object");
+    delete priv;               
+}
+
+bool JSApplicationInstallInfo::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ApplicationInstallInfoPtr JSApplicationInstallInfo::getPrivData(JSObjectRef object)
+{
+       JSApplicationInstallInfoPriv *priv = static_cast<JSApplicationInstallInfoPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ApplicationInstallInfoPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+ApplicationInstallInfoPtr JSApplicationInstallInfo::getApplicationInstallInfo(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       
+       JSApplicationInstallInfoPriv *priv = static_cast<JSApplicationInstallInfoPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       
+       return priv->getObject();
+}
+
+JSValueRef JSApplicationInstallInfo::getProperty(JSContextRef context,
+       JSObjectRef object,
+       JSStringRef propertyName,
+       JSValueRef* exception)
+{
+       Try     {
+               CommonsJavaScript::Converter converter(context);
+               ApplicationInstallInfoPtr privateData = getPrivData(object);
+       
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INSTALL_INFO_FILEPATH)) {
+                       return converter.toJSValueRef(privateData->getFilePath());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INSTALL_INFO_ALGORITHM)) {
+                       return converter.toJSValueRef(privateData->getAlgorithm());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INSTALL_INFO_KEY)) {
+                       return converter.toJSValueRef(privateData->getKey());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_INSTALL_INFO_PACKAGEFORMAT)) {
+                       return converter.toJSValueRef(privateData->getPackageFormat());
+               }
+
+       } Catch(WrtDeviceApis::Commons::Exception) {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+               JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
+    }
+       
+       return JSValueMakeUndefined(context);
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Application/JSApplicationInstallInfo.h b/src/standards/Tizen/Application/JSApplicationInstallInfo.h
new file mode 100755 (executable)
index 0000000..f5e8506
--- /dev/null
@@ -0,0 +1,99 @@
+//
+// 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_JS_APPLICATION_INSTALL_INFO_H_
+#define TIZENAPIS_TIZEN_JS_APPLICATION_INSTALL_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <dpl/shared_ptr.h>
+#include <API/Application/ApplicationInstallInfo.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+#define TIZEN_INTERFACE_APPLICATION_INSTALL_INFO "ApplicationInstallInfo"
+
+#define TIZEN_APPLICATION_INSTALL_INFO_FILEPATH "filePath"
+#define TIZEN_APPLICATION_INSTALL_INFO_ALGORITHM "algorithm"
+#define TIZEN_APPLICATION_INSTALL_INFO_KEY "key"
+#define TIZEN_APPLICATION_INSTALL_INFO_PACKAGEFORMAT "packageFormat"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::Application::ApplicationInstallInfoPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSApplicationInstallInfoPriv;
+
+class JSApplicationInstallInfo {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static JSValueRef createJSObject(JSContextRef context,
+                       const std::string &filePath,
+                       const std::string &algorithm,
+                       const std::string &key,
+                       const std::string &packageFormat);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static Api::Application::ApplicationInstallInfoPtr
+               getApplicationInstallInfo(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 Api::Application::ApplicationInstallInfoPtr getPrivData(JSObjectRef object);
+
+       static JSValueRef getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception);
+
+};
+
+}
+}
+}
+#endif
diff --git a/src/standards/Tizen/Application/JSApplicationManager.cpp b/src/standards/Tizen/Application/JSApplicationManager.cpp
new file mode 100644 (file)
index 0000000..c1d4e02
--- /dev/null
@@ -0,0 +1,1476 @@
+//
+// 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 <memory>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <API/Application/ApplicationFactory.h>
+#include "plugin_config.h"
+#include "ApplicationController.h"
+#include "JSApplicationManager.h"
+#include "ApplicationConverter.h"
+#include "ApplicationUtil.h"
+#include "JSApplicationControl.h"
+#include "ApplicationAsyncCallbackManager.h"
+#include "ApplicationListenerManager.h"
+#include "ApplicationInformationEventPrivateData.h"
+#include "JSApplicationEventCallbackManager.h"
+#include <bundle.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+using namespace TizenApis::Api::Application;
+using namespace TizenApis::Commons;
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassRef JSApplicationManager::m_jsClassRef = NULL;
+
+JSClassDefinition JSApplicationManager::m_classInfo = {
+               0,
+               kJSClassAttributeNone,
+               TIZEN_INTERFACE_APPLICATION_MANAGER,
+               NULL,
+               NULL,
+               m_function,
+               initialize,
+               finalize,
+               NULL, //hasProperty,
+               NULL, //getProperty,
+               NULL, //setProperty,
+               NULL, //deleteProperty,
+               NULL, //getPropertyNames,
+               NULL,
+               NULL,
+               hasInstance,
+               NULL
+};
+
+JSStaticFunction JSApplicationManager::m_function[] = {
+               { APPLICATION_FUNCTION_API_GET_CURRENT_APP, JSApplicationManager::getCurrentApplication, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_LAUNCH, JSApplicationManager::launch, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_KILL, JSApplicationManager::kill, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_SET_USER_AGENT, JSApplicationManager::setUserAgent, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_GET_APPS_INFO, JSApplicationManager::getAppsInfo, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_GET_APPS_CONTEXT, JSApplicationManager::getAppsContext, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_GET_APP_INFO, JSApplicationManager::getAppInfo, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_GET_APP_CONTEXT, JSApplicationManager::getAppContext, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_ADD_APP_INFO_EVENT_LISTENER, JSApplicationManager::addAppInfoEventListener, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_REMOVE_APP_INFO_EVENT_LISTENER, JSApplicationManager::removeAppInfoEventListener, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_LAUNCH_APP_CONTROL, JSApplicationManager::launchAppControl, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_FIND_APP_CONTROL, JSApplicationManager::findAppControl, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_INSTALL_APP, JSApplicationManager::install, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_UNINSTALL_APP, JSApplicationManager::uninstall, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_UPDATE_APP, JSApplicationManager::update, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_GET_APP_CERTS, JSApplicationManager::getAppCerts, kJSPropertyAttributeNone },
+               { 0, 0, 0 }
+};
+
+const JSClassRef JSApplicationManager::getClassRef() 
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSApplicationManager::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+void JSApplicationManager::initialize(JSContextRef context, JSObjectRef object) 
+{
+       LogDebug(">>> JSApplicationManager::initialize");
+       ApplicationController* priv = static_cast<ApplicationController*>(JSObjectGetPrivate(object));
+
+       if (!priv) {
+               IApplicationManagerPtr applications(ApplicationFactory::getInstance().createApplication());
+               priv = new ApplicationController(context, applications);
+               
+               if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+                       LogError("Object can't store private data.");
+                       delete priv;
+               }
+       } else {
+               LogDebug("private date is already exist");
+       }
+}
+
+void JSApplicationManager::finalize(JSObjectRef object) 
+{
+       ApplicationController* priv = static_cast<ApplicationController*> (JSObjectGetPrivate(object));
+       JSObjectSetPrivate(object, NULL);
+       delete priv;
+}
+
+bool JSApplicationManager::hasInstance(JSContextRef context, 
+       JSObjectRef constructor, 
+       JSValueRef possibleInstance, 
+       JSValueRef* exception) 
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+
+JSValueRef JSApplicationManager::getCurrentApplication(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       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");
+       }
+
+// @20121206-wscho: privilege policy is changed
+#if 0
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_GET_CURRENT_APP);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+#endif
+
+       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.");
+               }
+
+               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());
+       }
+}
+
+
+
+JSValueRef JSApplicationManager::launch(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       JSContextRef gContext;
+       ApplicationController *controller;
+
+       Try     {
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "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);
+
+    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.");
+               }
+       }
+
+       callbackManager->setObject(thisObject);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+
+       EventApplicationLaunchPtr event(new EventApplicationLaunch());
+       
+               if (argumentCount > 0) {
+                       event->setAppId(converter->toString(arguments[0]));
+               } else {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+               }
+
+               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);
+}
+
+JSValueRef JSApplicationManager::kill(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       JSContextRef gContext;
+       ApplicationController *controller;
+
+       Try     {
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "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);
+
+       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.");
+               }
+       }
+
+       callbackManager->setObject(thisObject);
+
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+       EventApplicationKillPtr event(new EventApplicationKill());
+
+               std::string appContextId;
+               if (argumentCount > 0) {
+                       appContextId = converter->toString(arguments[0]);
+               } else {
+            ThrowMsg(ConversionException, "Wrong first parameter type.");
+               }
+
+               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);
+}
+
+
+JSValueRef JSApplicationManager::setUserAgent(JSContextRef context,
+       JSObjectRef object,
+       JSObjectRef thisObject,
+       size_t argumentCount,
+       const JSValueRef arguments[],
+       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");
+       }
+
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_SET_USER_AGENT);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+//     AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_EXIT);
+//     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       if (argumentCount < 1) {
+               LogError("Wrong parameters");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error");
+       }
+
+       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");
+               }
+
+               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);
+}
+
+JSValueRef JSApplicationManager::launchAppControl(JSContextRef context,
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       JSContextRef gContext;
+       ApplicationController *controller;
+
+       Try     {
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "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 {
+
+       ApplicationUtil util(context, exception);
+
+
+       if (argumentCount > 2) {
+               if (util.isFunction(arguments[2])) {
+                       callbackManager->setOnSuccess(arguments[2]);
+               } else if (!util.isNullOrUndefined(arguments[2])) {
+                       ThrowMsg(ConversionException, "Wrong third parameter type.");
+               }
+       }
+
+       if (argumentCount > 3) {
+               if (util.isFunction(arguments[3])) {
+                       callbackManager->setOnError(arguments[3]);
+               } else if (!util.isNullOrUndefined(arguments[3])) {
+                       ThrowMsg(ConversionException, "Wrong fourth parameter type.");
+               }
+       }
+
+       callbackManager->setObject(thisObject);
+
+       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.isFunction(onsuccess) || !util.isFunction(onfail)) {
+                    ThrowMsg(ConversionException, "Wrong fifth parameter type.");
+                               }
+
+                               callbackManagerReply = JSCallbackManager::createObject(gContext, onsuccess, onfail);
+                               callbackManagerReply->setObject(thisObject);
+
+                       } else if (!util.isNullOrUndefined(arguments[4])) {
+                ThrowMsg(ConversionException, "Wrong fifth parameter type.");
+                       }
+               }
+
+       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); 
+
+               event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+               event->setForAsynchronousCall(controller);
+
+               if(callbackManagerReply != NULL)
+               {
+                       EventApplicationLaunchAppControlReplyPtr eventReply(new EventApplicationLaunchAppControlReply());
+                       eventReply->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManagerReply));
+                       eventReply->setForAsynchronousCall(controller);
+
+                       event->setEventReply(eventReply);
+               }
+
+               appmgr->launchAppControl(event);
+
+               if(callbackManagerReply != NULL)
+                       ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManagerReply, gContext);
+
+               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);
+}
+
+JSValueRef JSApplicationManager::findAppControl(JSContextRef context,
+       JSObjectRef object,
+       JSObjectRef thisObject,
+       size_t argumentCount,
+       const JSValueRef arguments[],
+       JSValueRef* exception)
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       JSContextRef gContext;
+       ApplicationController *controller;
+
+       Try     {
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "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_FIND_APP_CONTROL);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
+       Try {
+
+       if (argumentCount <= 1) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+       }
+
+       ApplicationUtil util(context, exception);
+       if ((argumentCount > 1) && util.isFunction(arguments[1])) {
+               callbackManager->setOnSuccess(arguments[1]);
+       } else {
+            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.");
+               }
+       }
+
+       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.");
+               }
+
+               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);
+}
+
+JSValueRef JSApplicationManager::getAppsContext(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       JSContextRef gContext;
+       ApplicationController *controller;
+
+       Try     {
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "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_GET_APPS_CONTEXT);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    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.");
+               }
+       }
+
+       callbackManager->setObject(thisObject);
+
+       EventApplicationGetAppsContextPtr event(new EventApplicationGetAppsContext());
+
+               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);
+}
+
+JSValueRef JSApplicationManager::getAppContext(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       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");
+       }
+
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_GET_APP_CONTEXT);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Try {
+       EventApplicationGetAppContextPtr event(new EventApplicationGetAppContext());
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+
+               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;
+                       }
+               }
+
+               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());
+       }
+}
+
+JSValueRef JSApplicationManager::getAppsInfo(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       JSContextRef gContext;
+       ApplicationController *controller;
+
+       Try     {
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "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_GET_APPS_INFO);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    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.");
+               }
+       }
+
+       callbackManager->setObject(thisObject);
+
+       EventApplicationGetAppsInfoPtr event(new EventApplicationGetAppsInfo());
+
+               event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+               event->setForAsynchronousCall(controller);
+               appmgr->getAppsInfo(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);
+}
+
+JSValueRef JSApplicationManager::getAppInfo(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       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");
+       }
+
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_GET_APP_INFO);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Try {
+       EventApplicationGetAppInfoPtr event(new EventApplicationGetAppInfo());
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+
+               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.");
+               } else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) {
+                       ThrowMsg(Exception, "Unknown error occurred.");
+               }
+
+               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());
+       }
+}
+
+JSValueRef JSApplicationManager::addAppInfoEventListener(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       JSContextRef gContext;
+       ApplicationController *controller;
+
+       Try     {
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "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_ADD_APP_INFO_EVENT_LISTENER);      
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Try {
+       if (argumentCount == 0) {
+               ThrowMsg(ConversionException, "Wrong parameter type.");
+       }
+
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+
+               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");
+
+           ApplicationUtil util(context, exception);
+               if (!util.isFunction(onInstalled) || !util.isFunction(onUpdated) || !util.isFunction(onUninstalled)) {
+            ThrowMsg(ConversionException, "Wrong first parameter type.");
+               }
+
+               JSApplicationEventCallbackManagerPtr callbackManager =
+                               JSApplicationEventCallbackManager::createObject(gContext);
+               callbackManager->setOnInstalled(onInstalled);
+               callbackManager->setOnUpdated(onUpdated);
+               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;
+                       }
+               }
+
+               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));
+               TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+               ApplicationListenerManagerSingleton::Instance().registerListener(listenerItem, gContext);
+
+               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");
+       }
+}
+
+JSValueRef JSApplicationManager::removeAppInfoEventListener(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       JSContextRef gContext;
+       ApplicationController *controller;
+
+       Try     {
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "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_REMOVE_APP_INFO_EVENT_LISTENER);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try {
+       if (argumentCount == 0) {
+               ThrowMsg(ConversionException, "Wrong parameter type.");
+       }
+
+               ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+
+       EventApplicationRemoveAppInfoEventListenerPtr event(new EventApplicationRemoveAppInfoEventListener());
+
+               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));
+       TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::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());
+       }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSApplicationManager::install(JSContextRef context,
+       JSObjectRef object,
+       JSObjectRef thisObject,
+       size_t argumentCount,
+       const JSValueRef arguments[],
+       JSValueRef* exception)
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       JSContextRef gContext;
+       ApplicationController *controller;
+
+       Try     {
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "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_INSTALL_APP);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Try {
+       if (argumentCount < 2) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+       }
+
+               ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+               ApplicationInstallInfoPtr appInstallInfo;
+               appInstallInfo = converter->toApplicationInstallInfo(arguments[0]);
+
+               JSObjectRef cbObj = converter->toJSObjectRef(arguments[1]);
+               JSValueRef onInstalled = JSUtils::getJSPropertyOrUndefined(context, cbObj, "oninstalled");
+               JSValueRef onUpdated = JSUtils::getJSPropertyOrUndefined(context, cbObj, "onupdated");
+               JSValueRef onUninstalled = JSUtils::getJSPropertyOrUndefined(context, cbObj, "onuninstalled");
+
+               ApplicationUtil util(context, exception);
+               if (!util.isFunction(onInstalled) || !util.isFunction(onUpdated) || !util.isFunction(onUninstalled)) {
+               ThrowMsg(ConversionException, "Wrong second parameter type.");
+               }
+
+               JSCallbackManagerPtr onInstalledCbm = JSCallbackManager::createObject(gContext, onInstalled);
+               JSCallbackManagerPtr onUpdatedCbm   = JSCallbackManager::createObject(gContext, onUpdated);
+               JSCallbackManagerPtr onUninstalledCbm = JSCallbackManager::createObject(gContext, onUninstalled);
+               if (argumentCount > 2) {
+                       if (util.isFunction(arguments[2])) {
+                               onInstalledCbm->setOnError(arguments[2]);
+                       } else if (!util.isNullOrUndefined(arguments[2])) {
+                ThrowMsg(ConversionException, "Wrong third parameter type.");
+                       }
+               }
+               onInstalledCbm->setObject(thisObject);
+               onUpdatedCbm->setObject(thisObject);
+               onUninstalledCbm->setObject(thisObject);
+
+               ApplicationInformationEventPrivateDataPtr privateData(new ApplicationInformationEventPrivateData(onInstalledCbm, onUpdatedCbm, onUninstalledCbm));
+
+
+               EventApplicationInstallPtr event(new EventApplicationInstall());
+               event->setEventType(EventApplicationInstall::APPLICATION_INSTALL_INSTALL);
+               event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData> (privateData));
+               event->setAppInstallInfo(appInstallInfo);
+               event->setForAsynchronousCall(controller);
+
+               appmgr->install(event);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(onInstalledCbm, gContext);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(onUpdatedCbm, gContext);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(onUninstalledCbm, 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());
+               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 JSValueMakeUndefined(context);
+}
+
+JSValueRef JSApplicationManager::uninstall(JSContextRef context,
+       JSObjectRef object,
+       JSObjectRef thisObject,
+       size_t argumentCount,
+       const JSValueRef arguments[],
+       JSValueRef* exception)
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       JSContextRef gContext;
+       ApplicationController *controller;
+
+       Try     {
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "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_UNINSTALL_APP);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Try {
+       if (argumentCount < 2) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+       }
+
+               ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+               std::string appid = converter->toString(arguments[0]);
+
+               JSObjectRef cbObj = converter->toJSObjectRef(arguments[1]);
+               JSValueRef onInstalled = JSUtils::getJSPropertyOrUndefined(context, cbObj, "oninstalled");
+               JSValueRef onUpdated = JSUtils::getJSPropertyOrUndefined(context, cbObj, "onupdated");
+               JSValueRef onUninstalled = JSUtils::getJSPropertyOrUndefined(context, cbObj, "onuninstalled");
+
+               ApplicationUtil util(context, exception);
+               if (!util.isFunction(onInstalled) || !util.isFunction(onUpdated) || !util.isFunction(onUninstalled)) {
+            ThrowMsg(ConversionException, "Wrong second parameter type.");
+               }
+
+               JSCallbackManagerPtr onInstalledCbm = JSCallbackManager::createObject(gContext, onInstalled);
+               JSCallbackManagerPtr onUpdatedCbm   = JSCallbackManager::createObject(gContext, onUpdated);
+               JSCallbackManagerPtr onUninstalledCbm = JSCallbackManager::createObject(gContext, onUninstalled);
+               if (argumentCount > 2) {
+                       if (util.isFunction(arguments[2])) {
+                               onUninstalledCbm->setOnError(arguments[2]);
+                       } else if (!util.isNullOrUndefined(arguments[2])) {
+                ThrowMsg(ConversionException, "Wrong third parameter type.");
+                       }
+               }
+               onInstalledCbm->setObject(thisObject);
+               onUpdatedCbm->setObject(thisObject);
+               onUninstalledCbm->setObject(thisObject);
+
+               ApplicationInformationEventPrivateDataPtr privateData(new ApplicationInformationEventPrivateData(onInstalledCbm, onUpdatedCbm, onUninstalledCbm));
+
+               EventApplicationInstallPtr event(new EventApplicationInstall());
+               event->setEventType(EventApplicationInstall::APPLICATION_INSTALL_UNINSTALL);
+               event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData> (privateData));
+               event->setAppId(appid);
+               event->setForAsynchronousCall(controller);
+
+               appmgr->uninstall(event);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(onInstalledCbm, gContext);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(onUpdatedCbm, gContext);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(onUninstalledCbm, 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());
+               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 JSValueMakeUndefined(context);
+}
+
+JSValueRef JSApplicationManager::update(JSContextRef context,
+       JSObjectRef object,
+       JSObjectRef thisObject,
+       size_t argumentCount,
+       const JSValueRef arguments[],
+       JSValueRef* exception)
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       JSContextRef gContext;
+       ApplicationController *controller;
+
+       Try     {
+               controller = static_cast<ApplicationController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "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_UPDATE_APP);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Try {
+       if (argumentCount < 2) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+       }
+
+               ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+               ApplicationInstallInfoPtr appInstallInfo = converter->toApplicationInstallInfo(arguments[0]);
+
+               JSObjectRef cbObj = converter->toJSObjectRef(arguments[1]);
+               JSValueRef onInstalled = JSUtils::getJSPropertyOrUndefined(context, cbObj, "oninstalled");
+               JSValueRef onUpdated = JSUtils::getJSPropertyOrUndefined(context, cbObj, "onupdated");
+               JSValueRef onUninstalled = JSUtils::getJSPropertyOrUndefined(context, cbObj, "onuninstalled");
+
+               ApplicationUtil util(context, exception);
+               if (!util.isFunction(onInstalled) || !util.isFunction(onUpdated) || !util.isFunction(onUninstalled)) {
+            ThrowMsg(ConversionException, "Wrong second parameter type.");
+               }
+
+               JSCallbackManagerPtr onInstalledCbm = JSCallbackManager::createObject(gContext, onInstalled);
+               JSCallbackManagerPtr onUpdatedCbm   = JSCallbackManager::createObject(gContext, onUpdated);
+               JSCallbackManagerPtr onUninstalledCbm = JSCallbackManager::createObject(gContext, onUninstalled);
+               if (argumentCount > 2) {
+                       if (util.isFunction(arguments[2])) {
+                               onUpdatedCbm->setOnError(arguments[2]);
+                       } else if (!util.isNullOrUndefined(arguments[2])) {
+                ThrowMsg(ConversionException, "Wrong third parameter type.");
+                       }
+               }
+               onInstalledCbm->setObject(thisObject);
+               onUpdatedCbm->setObject(thisObject);
+               onUninstalledCbm->setObject(thisObject);
+
+               ApplicationInformationEventPrivateDataPtr privateData(new ApplicationInformationEventPrivateData(onInstalledCbm, onUpdatedCbm, onUninstalledCbm));
+
+               EventApplicationInstallPtr event(new EventApplicationInstall());
+               event->setEventType(EventApplicationInstall::APPLICATION_INSTALL_UPDATE);
+               event->setPrivateData(DPL::StaticPointerCast<IEventPrivateData> (privateData));
+               event->setAppInstallInfo(appInstallInfo);
+               event->setForAsynchronousCall(controller);
+
+               appmgr->update(event);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(onInstalledCbm, gContext);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(onUpdatedCbm, gContext);
+               ApplicationAsyncCallbackManagerSingleton::Instance().registerCallbackManager(onUninstalledCbm, 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());
+               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 JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSApplicationManager::getAppCerts(JSContextRef context,
+       JSObjectRef object,
+       JSObjectRef thisObject,
+       size_t argumentCount,
+       const JSValueRef arguments[],
+       JSValueRef* exception)
+{
+       LogDebug("entered");
+       IApplicationManagerPtr appmgr;
+       ApplicationController *controller;
+
+       LogError("JSApplicationManager::getAppCerts");
+
+
+       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");
+       }
+
+       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);
+
+               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.");
+               } else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) {
+                       ThrowMsg(Exception, "Unknown error occurred.");
+               }
+
+               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());
+       }
+
+}
+
+
+void JSApplicationManager::setTitleProperty(JSContextRef context, std::string propertyValue){
+       LogDebug("<<<propertyValue:[" << propertyValue << "]");
+
+       WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+       // get window object
+       JSObjectRef windowObject = JSContextGetGlobalObject(context);
+
+       // get title object
+       JSObjectRef documentObject = converter.toJSObjectRef(JSObjectGetProperty(context,
+                       windowObject,
+                       ScopedJSStringRef(JSStringCreateWithUTF8CString("document")).get(),
+                       NULL));
+
+       JSObjectSetProperty(context,
+                       documentObject,
+                       ScopedJSStringRef(JSStringCreateWithUTF8CString("title")).get(),
+                       JSValueMakeString(context, JSStringCreateWithUTF8CString("tizen://dummy#$#@##")),
+                       kJSPropertyAttributeNone,
+                       NULL);
+
+       JSObjectSetProperty(context,
+                       documentObject,
+                       ScopedJSStringRef(JSStringCreateWithUTF8CString("title")).get(),
+                       JSValueMakeString(context, JSStringCreateWithUTF8CString(propertyValue.c_str())),
+                       kJSPropertyAttributeNone,
+                       NULL);
+
+       LogDebug(">>>");
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Application/JSApplicationManager.h b/src/standards/Tizen/Application/JSApplicationManager.h
new file mode 100644 (file)
index 0000000..f659605
--- /dev/null
@@ -0,0 +1,172 @@
+//
+// 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_JS_APPLICATION_MANAGER_H_
+#define TIZENAPIS_TIZEN_JS_APPLICATION_MANAGER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Application/IApplicationManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+#define TIZEN_INTERFACE_APPLICATION_MANAGER "ApplicationManager"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject
+               <TizenApis::Api::Application::IApplicationManagerPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSApplicationManagerPriv;
+
+class JSApplicationManager {
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       static void setTitleProperty(JSContextRef context, std::string propertyValue);
+
+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);
+
+       /**
+        * Gets a current application
+        */
+       static JSValueRef getCurrentApplication(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Launches a application with given application id
+        */
+       static JSValueRef launch(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Kills the application based on application context.
+        */
+       static JSValueRef kill(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+
+       /**
+        * exit current application
+        */
+       static JSValueRef setUserAgent(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Gets the list of installed packages.
+        */
+       static JSValueRef getAppsInfo(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Gets the list of running packages.
+        */
+       static JSValueRef getAppsContext(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);   
+
+       /**
+        * Gets the application information of based on the package name.
+        */
+       static JSValueRef getAppInfo(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Gets the current application Context
+        */
+       static JSValueRef getAppContext(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Watch for changes on installed applicaiton.
+        */
+       static JSValueRef addAppInfoEventListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Unset installed Applications listener
+        */
+       static JSValueRef removeAppInfoEventListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Launch a application control
+        */
+       static JSValueRef launchAppControl(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Find application info list with application control
+        */
+       static JSValueRef findAppControl(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Install an application
+        */
+       static JSValueRef install(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Uninstall an application
+        */
+       static JSValueRef uninstall(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Update an application
+        */
+       static JSValueRef update(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Get certificate information of given application
+        */
+       static JSValueRef getAppCerts(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 function property.
+        */
+       static JSStaticFunction m_function[];
+
+       static JSClassRef m_jsClassRef;
+};
+
+}
+}
+}
+#endif
diff --git a/src/standards/Tizen/Application/JSRequestedApplicationControl.cpp b/src/standards/Tizen/Application/JSRequestedApplicationControl.cpp
new file mode 100644 (file)
index 0000000..c2e0193
--- /dev/null
@@ -0,0 +1,285 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+
+#include "plugin_config.h"
+
+#include "ApplicationConverter.h"
+#include "ApplicationUtil.h"
+#include "JSRequestedApplicationControl.h"
+
+using namespace TizenApis::Api::Application;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+JSClassRef JSRequestedApplicationControl::m_jsClassRef = NULL;
+
+JSClassDefinition JSRequestedApplicationControl::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_APPLICATION_CONTROL_PROVIDER_MANAGER,
+    0,
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    NULL,     //HasProperty,
+    getProperty,
+    NULL,     //SetProperty,
+    NULL,     //DeleteProperty,
+    NULL,     //GetPropertyNames,
+    NULL,     //CallAsFunction,
+    NULL,     //CallAsConstructor,
+    hasInstance,
+    NULL,     //ConvertToType
+};
+
+JSStaticValue JSRequestedApplicationControl::m_property[] = {
+    { TIZEN_APPLICATION_CONTROL, getProperty, NULL, kJSPropertyAttributeNone },
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSRequestedApplicationControl::m_function[] = {
+               { APPLICATION_FUNCTION_API_REPLY_RESULT, JSRequestedApplicationControl::replyResult, kJSPropertyAttributeNone },
+               { APPLICATION_FUNCTION_API_REPLY_FAILURE, JSRequestedApplicationControl::replyFailure,kJSPropertyAttributeNone },
+               { 0, 0, 0 }
+};
+
+const JSClassDefinition* JSRequestedApplicationControl::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSRequestedApplicationControl::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+       
+    return m_jsClassRef;
+}
+
+JSObjectRef JSRequestedApplicationControl::createJSObject(JSContextRef context, const RequestedApplicationControlPtr &appsvc)
+{
+       LogInfo(">> createJSObject");
+    JSRequestedApplicationControlPriv *priv = new JSRequestedApplicationControlPriv(context, appsvc);
+
+    if (!priv) {
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
+    }
+       
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+
+
+void JSRequestedApplicationControl::initialize(JSContextRef context,JSObjectRef object)
+{
+    LogInfo(">> initialize");
+}
+
+void JSRequestedApplicationControl::finalize(JSObjectRef object)
+{
+    LogInfo(">> finalize");
+    JSRequestedApplicationControlPriv* priv = static_cast<JSRequestedApplicationControlPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting ApplicationControl object");
+    delete priv;
+}
+
+
+bool JSRequestedApplicationControl::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+RequestedApplicationControlPtr JSRequestedApplicationControl::getRequestedApplicationControl(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       
+       JSRequestedApplicationControlPriv *priv = static_cast<JSRequestedApplicationControlPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       return priv->getObject();
+}
+
+
+RequestedApplicationControlPtr JSRequestedApplicationControl::getPrivData(JSObjectRef object)
+{
+       LogDebug("entered");
+       JSRequestedApplicationControlPriv *priv = static_cast<JSRequestedApplicationControlPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       RequestedApplicationControlPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSValueRef JSRequestedApplicationControl::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    JSRequestedApplicationControlPriv *priv = static_cast<JSRequestedApplicationControlPriv*>(JSObjectGetPrivate(object));
+    if (!priv) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error.");
+       }
+
+    Try {
+        RequestedApplicationControlPtr providerMgr = priv->getObject();
+               ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_APPLICATION_CONTROL)) {
+            LogDebug("JSRequestedApplicationControl::getProperty::appControl " << providerMgr->getAppControl());
+            return converter->toJSValueRef(providerMgr->getAppControl());
+        } 
+
+    } Catch(WrtDeviceApis::Commons::Exception) {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSDOMExceptionFactory::UnknownException.make(context, exception);
+    }
+
+       /* do not return undefined object to find method */
+    return NULL;
+}
+
+
+bool JSRequestedApplicationControl::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSRequestedApplicationControl::replyResult(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+       JSRequestedApplicationControlPriv *priv = static_cast<JSRequestedApplicationControlPriv*>(JSObjectGetPrivate(thisObject));
+
+// @20121206-wscho: privilege policy is changed
+#if 0
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_REPLY_RESULT);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+#endif
+
+       Try {
+        if (!priv) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+       ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context);
+
+               RequestedApplicationControlPtr providerMgr = priv->getObject();
+               std::vector<ApplicationControlDataPtr> resultArray;
+               if (argumentCount > 0) {
+                       resultArray = converter->toApplicationControlDataArray(arguments[0]);
+               }
+               providerMgr->replyResult(resultArray);
+       } 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 (NullPointerException) {
+           LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_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);
+}
+
+JSValueRef JSRequestedApplicationControl::replyFailure(JSContextRef context, 
+       JSObjectRef object, 
+       JSObjectRef thisObject, 
+       size_t argumentCount,
+       const JSValueRef arguments[], 
+       JSValueRef* exception) 
+{
+       LogDebug("entered");
+       JSRequestedApplicationControlPriv *priv = static_cast<JSRequestedApplicationControlPriv*>(JSObjectGetPrivate(thisObject));
+
+// @20121206-wscho: privilege policy is changed
+#if 0
+       AceSecurityStatus status = APPLICATION_CHECK_ACCESS(APPLICATION_FUNCTION_API_REPLY_RESULT);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+#endif
+
+       Try {
+        if (!priv) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+               RequestedApplicationControlPtr providerMgr = priv->getObject();
+               providerMgr->replyFailure();
+       } 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 (NullPointerException) {
+           LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_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);
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Application/JSRequestedApplicationControl.h b/src/standards/Tizen/Application/JSRequestedApplicationControl.h
new file mode 100644 (file)
index 0000000..4a6df61
--- /dev/null
@@ -0,0 +1,136 @@
+//
+// 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_JS_REQUESTED_APPLICATION_CONTROL_H_
+#define TIZENAPIS_TIZEN_JS_REQUESTED_APPLICATION_CONTROL_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Application/ApplicationControl.h>
+#include <API/Application/RequestedApplicationControl.h>
+#include "JSApplicationControl.h"
+#include "JSApplicationControlData.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+#define TIZEN_INTERFACE_APPLICATION_CONTROL_PROVIDER_MANAGER "RequestedApplicationControl"
+#define TIZEN_APPLICATION_CONTROL "appControl"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Application::RequestedApplicationControlPtr>::Type JSRequestedApplicationControlPriv;
+
+class JSRequestedApplicationControl {
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       /**
+         * create an JSObject for callback function(onAnswerReceived).
+         */
+       static JSObjectRef createJSObject(JSContextRef context,
+                          const Api::Application::RequestedApplicationControlPtr &appsvc);
+
+       /**
+        * The Constructor of ApplicationControl
+        */
+       static JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       /**
+        * Send Success Result
+        */
+       static JSValueRef replyResult(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       /**
+        * Send Failure Result
+        */
+       static JSValueRef replyFailure(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+                       const JSValueRef arguments[], JSValueRef* exception);
+
+       static Api::Application::RequestedApplicationControlPtr getRequestedApplicationControl(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 Api::Application::RequestedApplicationControlPtr getPrivData(JSObjectRef object);
+
+
+  /**
+     * 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 an object is used as the target of an 'instanceof' expression.
+     */
+    static bool hasInstance(JSContextRef context,
+            JSObjectRef constructor,
+            JSValueRef possibleInstance,
+            JSValueRef* exception);
+
+  /**
+     * This structure contains properties and callbacks that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+  /**
+     * This structure describes a statically declared value property.
+     */
+    static JSStaticValue m_property[];
+
+       /**
+        * This structure describes a statically declared function property.
+        */
+       static JSStaticFunction m_function[];
+
+
+    static JSClassRef m_jsClassRef;
+
+};
+
+} //
+} //TizenApis
+}
+#endif
diff --git a/src/standards/Tizen/Application/config.xml b/src/standards/Tizen/Application/config.xml
new file mode 100755 (executable)
index 0000000..b06e28c
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+       <library-name>libwrt-plugins-tizen-2.0-application.so</library-name>
+       <feature-install-uri>application.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/application.launch</name>
+        <device-capability>application.launch</device-capability>
+    </api-feature>
+    
+    <api-feature>
+        <name>http://tizen.org/privilege/application.kill</name>
+        <device-capability>application.kill</device-capability>
+    </api-feature>   
+    
+    <api-feature>
+        <name>http://tizen.org/privilege/application.read</name>
+        <device-capability>application.read</device-capability>
+    </api-feature>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/application.install</name>
+        <device-capability>application.install</device-capability>
+    </api-feature>
+    
+</plugin-properties>
diff --git a/src/standards/Tizen/Application/plugin_config.cpp b/src/standards/Tizen/Application/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..cabc9dd
--- /dev/null
@@ -0,0 +1,339 @@
+//
+// 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 APPLICATION_FEATURE_API_LAUNCH "http://tizen.org/privilege/application.launch"
+#define APPLICATION_FEATURE_API_KILL   "http://tizen.org/privilege/application.kill"
+#define APPLICATION_FEATURE_API_READ   "http://tizen.org/privilege/application.read"
+#define APPLICATION_FEATURE_API_INSTALL        "http://tizen.org/privilege/application.install"
+
+#define APPLICATION_DEVICE_CAP_LAUNCH  "application.launch"
+#define APPLICATION_DEVICE_CAP_KILL            "application.kill"
+#define APPLICATION_DEVICE_CAP_READ            "application.read"
+#define APPLICATION_DEVICE_CAP_INSTALL "application.install"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+static FunctionMapping createApplicationFunctions();
+
+static FunctionMapping ApplicationFunctions =
+    createApplicationFunctions();
+
+DEFINE_FUNCTION_GETTER(Application, ApplicationFunctions);
+
+static FunctionMapping createApplicationFunctions()
+{
+    /**
+     * Device capabilities
+     */        
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_LAUNCH, APPLICATION_DEVICE_CAP_LAUNCH);
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_KILL, APPLICATION_DEVICE_CAP_KILL);
+       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_READ, APPLICATION_DEVICE_CAP_READ);
+       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_INSTALL, APPLICATION_DEVICE_CAP_INSTALL);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_LAUNCH);
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_KILL);
+       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_READ);      
+       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_INSTALL);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_LAUNCH, DEVICE_CAP_APPLICATION_LAUNCH);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_KILL, DEVICE_CAP_APPLICATION_KILL);
+       ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_READ, DEVICE_CAP_APPLICATION_READ);
+       ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_INSTALL, DEVICE_CAP_APPLICATION_INSTALL);
+
+    /**
+     * Api Features
+     */
+    ACE_CREATE_FEATURE(FEATURE_APPLICATION_LAUNCH, APPLICATION_FEATURE_API_LAUNCH);
+       ACE_CREATE_FEATURE(FEATURE_APPLICATION_KILL, APPLICATION_FEATURE_API_KILL);
+    ACE_CREATE_FEATURE(FEATURE_APPLICATION_READ, APPLICATION_FEATURE_API_READ);
+    ACE_CREATE_FEATURE(FEATURE_APPLICATION_INSTALL, APPLICATION_FEATURE_API_INSTALL);
+
+    ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_LAUNCH);
+    ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_LAUNCH, FEATURE_APPLICATION_LAUNCH);
+
+    ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_KILL);
+    ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_KILL, FEATURE_APPLICATION_KILL);
+
+    ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_READ);
+    ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_READ, FEATURE_APPLICATION_READ);
+
+    ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_INSTALL);
+    ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_INSTALL, FEATURE_APPLICATION_INSTALL);
+
+    /**
+     * Functions
+     */
+    FunctionMapping applicationMapping;
+
+    // launch
+    AceFunction launchFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_LAUNCH,
+            APPLICATION_FUNCTION_API_LAUNCH,
+            APPLICATION_FEATURES_APPLICATION_LAUNCH,
+            DEVICE_LIST_APPLICATION_LAUNCH);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_LAUNCH,
+                               launchFunc));
+
+    // launchAppControl
+    AceFunction launchAppControlFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_LAUNCH_APP_CONTROL,
+            APPLICATION_FUNCTION_API_LAUNCH_APP_CONTROL,
+            APPLICATION_FEATURES_APPLICATION_LAUNCH,
+            DEVICE_LIST_APPLICATION_LAUNCH);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_LAUNCH_APP_CONTROL,
+                               launchAppControlFunc));
+
+       // kill
+    AceFunction killFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_KILL,
+            APPLICATION_FUNCTION_API_KILL,
+            APPLICATION_FEATURES_APPLICATION_KILL,
+            DEVICE_LIST_APPLICATION_KILL);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_KILL,
+                               killFunc));
+
+
+
+    // getAppsInfo
+    AceFunction getAppsInfoFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_APPLICATION_INFORMATIONS,
+            APPLICATION_FUNCTION_API_GET_APPS_INFO,
+            APPLICATION_FEATURES_APPLICATION_READ,
+            DEVICE_LIST_APPLICATION_READ);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_GET_APPS_INFO,
+                               getAppsInfoFunc));
+
+    // getAppInfo
+    AceFunction getAppInfoFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_APPLICATION_INFORMATION,
+            APPLICATION_FUNCTION_API_GET_APP_INFO,
+            APPLICATION_FEATURES_APPLICATION_READ,
+            DEVICE_LIST_APPLICATION_READ);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_GET_APP_INFO,
+                               getAppInfoFunc));
+
+    // getAppsContext
+    AceFunction getAppsContextFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_RUNNING_APPLICATION_CONTEXTS,
+            APPLICATION_FUNCTION_API_GET_APPS_CONTEXT,
+            APPLICATION_FEATURES_APPLICATION_READ,
+            DEVICE_LIST_APPLICATION_READ);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_GET_APPS_CONTEXT,
+                               getAppsContextFunc));
+
+    // getAppContext
+    AceFunction getAppContextFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_CURRENT_APPLICATION_CONTEXT,
+            APPLICATION_FUNCTION_API_GET_APP_CONTEXT,
+            APPLICATION_FEATURES_APPLICATION_READ,
+            DEVICE_LIST_APPLICATION_READ);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_GET_APP_CONTEXT,
+                               getAppContextFunc));
+
+    // getAppsContext
+    AceFunction findAppControlFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_RUNNING_APPLICATION_CONTEXTS,
+            APPLICATION_FUNCTION_API_FIND_APP_CONTROL,
+            APPLICATION_FEATURES_APPLICATION_READ,
+            DEVICE_LIST_APPLICATION_READ);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_FIND_APP_CONTROL,
+                               findAppControlFunc));
+
+    // addAppInfoEventListener
+    AceFunction addAppInfoEventListenerFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADD_APPLICATION_INFORMATION_EVENT_LISTENER,
+            APPLICATION_FUNCTION_API_ADD_APP_INFO_EVENT_LISTENER,
+            APPLICATION_FEATURES_APPLICATION_READ,
+            DEVICE_LIST_APPLICATION_READ);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_ADD_APP_INFO_EVENT_LISTENER,
+                               addAppInfoEventListenerFunc));
+
+    // removeAppInfoEventListener
+    AceFunction removeAppInfoEventListenerFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_REMOVE_APPLICATION_INFORMATION_EVENT_LISTENER,
+            APPLICATION_FUNCTION_API_REMOVE_APP_INFO_EVENT_LISTENER,
+            APPLICATION_FEATURES_APPLICATION_READ,
+            DEVICE_LIST_APPLICATION_READ);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_REMOVE_APP_INFO_EVENT_LISTENER,
+                               removeAppInfoEventListenerFunc));
+
+       // setUserAgent
+    AceFunction setUserAgentFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_SET_USER_AGENT,
+            APPLICATION_FUNCTION_API_SET_USER_AGENT,
+            APPLICATION_FEATURES_APPLICATION_READ,
+            DEVICE_LIST_APPLICATION_READ);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_SET_USER_AGENT,
+                               setUserAgentFunc));
+
+       // getAppCerts
+    AceFunction getAppCertsFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_APP_CERTS,
+            APPLICATION_FUNCTION_API_GET_APP_CERTS,
+            APPLICATION_FEATURES_APPLICATION_READ,
+            DEVICE_LIST_APPLICATION_READ);
+
+    applicationMapping.insert(std::make_pair(
+                               APPLICATION_FUNCTION_API_GET_APP_CERTS,
+                               getAppCertsFunc));
+
+
+
+    // install
+    AceFunction installFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_INSTALL_APP,
+            APPLICATION_FUNCTION_API_INSTALL_APP,
+            APPLICATION_FEATURES_APPLICATION_INSTALL,
+            DEVICE_LIST_APPLICATION_INSTALL);
+    applicationMapping.insert(std::make_pair(
+                                                          APPLICATION_FUNCTION_API_INSTALL_APP,
+                               installFunc));
+
+    // uninstall
+    AceFunction uninstallFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_UNINSTALL_APP,
+            APPLICATION_FUNCTION_API_UNINSTALL_APP,
+            APPLICATION_FEATURES_APPLICATION_INSTALL,
+            DEVICE_LIST_APPLICATION_INSTALL);
+    applicationMapping.insert(std::make_pair(
+                                                          APPLICATION_FUNCTION_API_UNINSTALL_APP,
+                                                          uninstallFunc));
+
+    // update
+    AceFunction updateFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_UPDATE_APP,
+            APPLICATION_FUNCTION_API_UPDATE_APP,
+            APPLICATION_FEATURES_APPLICATION_INSTALL,
+            DEVICE_LIST_APPLICATION_INSTALL);
+    applicationMapping.insert(std::make_pair(
+                                                          APPLICATION_FUNCTION_API_UPDATE_APP,
+                                                          updateFunc));
+
+// @20121206-wscho: privilege change
+#if 0
+               // getRequestedAppControl
+               AceFunction getReqAppControlFunc = ACE_CREATE_FUNCTION(
+                               FUNCTION_GET_REQ_APPLICATION_CONTROL,
+                               APPLICATION_FUNCTION_API_GET_REQUESTED_APP_CONTROL,
+                               APPLICATION_FEATURES_APPLICATION_READ,
+                               DEVICE_LIST_APPLICATION_READ);
+       
+               applicationMapping.insert(std::make_pair(
+                                                                  APPLICATION_FUNCTION_API_GET_REQUESTED_APP_CONTROL,
+                                                                  getReqAppControlFunc));
+       
+               // replyResult
+               AceFunction replyResultFunc = ACE_CREATE_FUNCTION(
+                               FUNCTION_REPLY_RESULT,
+                               APPLICATION_FUNCTION_API_REPLY_RESULT,
+                               APPLICATION_FEATURES_APPLICATION_READ,
+                               DEVICE_LIST_APPLICATION_READ);
+       
+               applicationMapping.insert(std::make_pair(
+                                                                  APPLICATION_FUNCTION_API_REPLY_RESULT,
+                                                                  replyResultFunc));
+       
+               // replyFailure
+               AceFunction replyFailureFunc = ACE_CREATE_FUNCTION(
+                               FUNCTION_REPLY_FAILURE,
+                               APPLICATION_FUNCTION_API_REPLY_FAILURE,
+                               APPLICATION_FEATURES_APPLICATION_READ,
+                               DEVICE_LIST_APPLICATION_READ);
+       
+               applicationMapping.insert(std::make_pair(
+                                                                  APPLICATION_FUNCTION_API_REPLY_FAILURE,
+                                                                  replyFailureFunc));
+       
+               // getCurrentApplication
+               AceFunction getcurrAppFunc = ACE_CREATE_FUNCTION(
+                               FUNCTION_GET_CURRENT_APPLICATION,
+                               APPLICATION_FUNCTION_API_GET_CURRENT_APP,
+                               APPLICATION_FEATURES_APPLICATION_READ,
+                               DEVICE_LIST_APPLICATION_READ);
+       
+               applicationMapping.insert(std::make_pair(
+                                                                  APPLICATION_FUNCTION_API_GET_CURRENT_APP,
+                                                                  getcurrAppFunc));
+       
+               // exit
+               AceFunction exitFunc = ACE_CREATE_FUNCTION(
+                               FUNCTION_EXIT,
+                               APPLICATION_FUNCTION_API_EXIT,
+                               APPLICATION_FEATURES_APPLICATION_READ,
+                               DEVICE_LIST_APPLICATION_READ);
+       
+               applicationMapping.insert(std::make_pair(
+                                                                  APPLICATION_FUNCTION_API_EXIT,
+                                                                  exitFunc));
+       
+               // hide
+               AceFunction hideFunc = ACE_CREATE_FUNCTION(
+                               FUNCTION_HIDE,
+                               APPLICATION_FUNCTION_API_HIDE,
+                               APPLICATION_FEATURES_APPLICATION_READ,
+                               DEVICE_LIST_APPLICATION_READ);
+       
+               applicationMapping.insert(std::make_pair(
+                                                                  APPLICATION_FUNCTION_API_HIDE,
+                                                                  hideFunc));
+#endif
+
+
+
+       return applicationMapping;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Application/plugin_config.h b/src/standards/Tizen/Application/plugin_config.h
new file mode 100755 (executable)
index 0000000..8998bf3
--- /dev/null
@@ -0,0 +1,73 @@
+//\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
+\r
+#ifndef _APPLICATOIN_PLUGIN_CONFIG_H_\r
+#define _APPLICATOIN_PLUGIN_CONFIG_H_\r
+\r
+#include <string>\r
+#include <Commons/FunctionDeclaration.h>\r
+\r
+// feature : install\r
+#define APPLICATION_FUNCTION_API_INSTALL_APP           "install"\r
+#define APPLICATION_FUNCTION_API_UNINSTALL_APP         "uninstall"\r
+#define APPLICATION_FUNCTION_API_UPDATE_APP                "update"\r
+\r
+// feature : launch\r
+#define APPLICATION_FUNCTION_API_LAUNCH                        "launch"\r
+#define APPLICATION_FUNCTION_API_LAUNCH_APP_CONTROL    "launchAppControl"\r
+\r
+// feature : kill\r
+#define APPLICATION_FUNCTION_API_KILL                          "kill"\r
+\r
+// feature : read\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_GET_APP_CONTEXT                               "getAppContext"\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
+// partner\r
+#define APPLICATION_FUNCTION_API_SET_USER_AGENT                                        "setUserAgent"\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
+\r
+namespace TizenApis {\r
+namespace Tizen1_0 {\r
+namespace Application {\r
+\r
+DECLARE_FUNCTION_GETTER(Application);\r
+\r
+#define APPLICATION_CHECK_ACCESS(functionName)                     \\r
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(     \\r
+        getApplicationFunctionData,                                \\r
+        functionName)\r
+\r
+}\r
+}\r
+}\r
+#endif\r
+\r
diff --git a/src/standards/Tizen/Application/plugin_initializer.cpp b/src/standards/Tizen/Application/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..78a110b
--- /dev/null
@@ -0,0 +1,94 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include "JSApplicationManager.h"
+#include "JSApplicationControl.h"
+#include "ApplicationAsyncCallbackManager.h"
+#include "ApplicationListenerManager.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Application {
+
+void on_widget_start_callback(int widgetId) {
+       LogDebug("[Tizen1_0\\Application] on_widget_start_callback ("<<widgetId<<")");
+    Try {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    } Catch(WrtDeviceApis::Commons::Exception) {
+        LogError("WrtAccess initialization failed");
+    }  
+}
+
+void on_widget_stop_callback(int widgetId) {
+       LogDebug("[Tizen1_0\\Application] on_widget_stop_callback ("<<widgetId<<")");
+    Try {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+    } Catch(WrtDeviceApis::Commons::Exception) {
+        LogError("WrtAccess deinitialization failed");
+    }  
+}
+
+void on_frame_load_callback(const void * context)
+{
+    LogDebug("[Tizen\\application] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LogDebug("[Tizen\\application] on_frame_unload_callback (" << context << ")");
+
+    TizenApis::Tizen1_0::Application::ApplicationAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+    TizenApis::Tizen1_0::Application::ApplicationListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+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,
+               "application",
+               (js_class_template_getter)TizenApis::Tizen1_0::Application::JSApplicationManager::getClassRef,
+               NULL)
+
+       PLUGIN_CLASS_MAP_ADD_CLASS(
+               WRT_JS_EXTENSION_OBJECT_TIZEN,
+               TIZEN_INTERFACE_APPLICATION_CONTROL,
+               (js_class_template_getter)TizenApis::Tizen1_0::Application::JSApplicationControl::getClassRef,
+               NULL)
+
+       PLUGIN_CLASS_MAP_ADD_CLASS(
+               WRT_JS_EXTENSION_OBJECT_TIZEN,
+               TIZEN_INTERFACE_APPLICATION_CONTROL_DATA,
+               (js_class_template_getter)TizenApis::Tizen1_0::Application::JSApplicationControlData::getClassRef,
+               NULL)
+
+PLUGIN_CLASS_MAP_END
+
+} //Application
+} //Tizen1_0
+} //TizenApis
+
diff --git a/src/standards/Tizen/Bluetooth/BluetoothAdapterListener.cpp b/src/standards/Tizen/Bluetooth/BluetoothAdapterListener.cpp
new file mode 100644 (file)
index 0000000..11677f7
--- /dev/null
@@ -0,0 +1,370 @@
+//
+// 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 <API/Bluetooth/BluetoothFactory.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include "BluetoothMultiCallback.h"
+#include "JSBluetoothSocket.h"
+#include "JSBluetoothServiceHandler.h"
+#include "JSBluetoothAdapter.h"
+#include "BluetoothConverter.h"
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+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/standards/Tizen/Bluetooth/BluetoothAdapterListener.h b/src/standards/Tizen/Bluetooth/BluetoothAdapterListener.h
new file mode 100644 (file)
index 0000000..71b4b7c
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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 <API/Bluetooth/IBluetoothAdapterManager.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <API/Bluetooth/EventBTServiceOnConnect.h>
+#include <API/Bluetooth/EventBTUnregisterRFCOMM.h>
+
+
+using namespace TizenApis::Api;
+using namespace TizenApis::Api::Bluetooth;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0{
+
+       
+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/standards/Tizen/Bluetooth/BluetoothClass.cpp b/src/standards/Tizen/Bluetooth/BluetoothClass.cpp
new file mode 100644 (file)
index 0000000..16c8247
--- /dev/null
@@ -0,0 +1,258 @@
+//
+// 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 "BluetoothClass.h"
+#include <CommonsJavaScript/JSUtils.h>
+
+using namespace DPL;
+
+namespace TizenApis {
+namespace Tizen1_0{
+       
+std::map<std::string,int> BluetoothClass::m_serviceConstants;
+
+BluetoothClass::BluetoothClass()
+{
+       initConstants();
+       m_readOnly = false;
+}
+
+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;
+}
+
+int BluetoothClass::getMinor()
+{
+       return m_minor;
+}
+
+void BluetoothClass::setMinor(int minor)
+{
+       m_minor = minor;
+}
+
+std::vector<int> BluetoothClass::getServices()
+{
+       return m_services;
+}
+
+void BluetoothClass::setServices(int device)
+{
+       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;
+}
+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));
+}
+}
+}
+
diff --git a/src/standards/Tizen/Bluetooth/BluetoothClass.h b/src/standards/Tizen/Bluetooth/BluetoothClass.h
new file mode 100644 (file)
index 0000000..8e275b2
--- /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 TIZENAPIS_TIZEN_BLUETOOTH_CLASS_H_
+#define TIZENAPIS_TIZEN_BLUETOOTH_CLASS_H_
+
+#include <dpl/shared_ptr.h>
+#include <map>
+#include <string>
+#include <vector>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+class BluetoothClass;
+typedef DPL::SharedPtr<BluetoothClass> BluetoothClassPtr;
+
+#define MAJOR_SHIFT 7
+#define MINOR_SHIFT 1
+#define SERVICE_SHIFT 12
+
+#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)
+
+
+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;
+};
+}
+}
+#endif
diff --git a/src/standards/Tizen/Bluetooth/BluetoothConverter.cpp b/src/standards/Tizen/Bluetooth/BluetoothConverter.cpp
new file mode 100644 (file)
index 0000000..1bc3717
--- /dev/null
@@ -0,0 +1,362 @@
+//
+// 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 <API/Bluetooth/BluetoothProperty.h>
+#include "BluetoothConverter.h"
+#include "JSBluetoothDevice.h"
+
+#include <pcrecpp.h>
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+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 = toFunction(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<TizenApis::Api::Bluetooth::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/standards/Tizen/Bluetooth/BluetoothConverter.h b/src/standards/Tizen/Bluetooth/BluetoothConverter.h
new file mode 100644 (file)
index 0000000..6a85ec7
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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 <API/Bluetooth/BTDevice.h>
+#include "BluetoothMultiCallback.h"
+
+#ifndef TIZENAPIS_TIZEN_BLUETOOTH_CONVERTER_H_
+#define TIZENAPIS_TIZEN_BLUETOOTH_CONVERTER_H_
+
+namespace TizenApis {
+namespace Tizen1_0 {
+       
+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<TizenApis::Api::Bluetooth::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/standards/Tizen/Bluetooth/BluetoothDeviceManagerListener.cpp b/src/standards/Tizen/Bluetooth/BluetoothDeviceManagerListener.cpp
new file mode 100644 (file)
index 0000000..72eddf2
--- /dev/null
@@ -0,0 +1,84 @@
+//
+// 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 <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "BluetoothDeviceManagerListener.h"
+#include "JSBluetoothSocket.h"
+
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+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/standards/Tizen/Bluetooth/BluetoothDeviceManagerListener.h b/src/standards/Tizen/Bluetooth/BluetoothDeviceManagerListener.h
new file mode 100644 (file)
index 0000000..7a8e748
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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 <API/Bluetooth/IBluetoothDeviceManager.h>
+
+using namespace TizenApis::Api;
+using namespace TizenApis::Api::Bluetooth;
+using namespace WrtDeviceApis::Commons;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+       
+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/standards/Tizen/Bluetooth/BluetoothMultiCallback.cpp b/src/standards/Tizen/Bluetooth/BluetoothMultiCallback.cpp
new file mode 100644 (file)
index 0000000..1fdcc25
--- /dev/null
@@ -0,0 +1,97 @@
+//
+// 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 TizenApis {
+namespace Tizen1_0 {
+
+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/standards/Tizen/Bluetooth/BluetoothMultiCallback.h b/src/standards/Tizen/Bluetooth/BluetoothMultiCallback.h
new file mode 100644 (file)
index 0000000..7c78b67
--- /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 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 TizenApis {
+namespace Tizen1_0 {
+
+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/standards/Tizen/Bluetooth/BluetoothSocketListener.cpp b/src/standards/Tizen/Bluetooth/BluetoothSocketListener.cpp
new file mode 100644 (file)
index 0000000..58279ac
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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 <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "BluetoothSocketListener.h"
+#include "BluetoothMultiCallback.h"
+#include "JSBluetoothSocket.h"
+
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+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/standards/Tizen/Bluetooth/BluetoothSocketListener.h b/src/standards/Tizen/Bluetooth/BluetoothSocketListener.h
new file mode 100644 (file)
index 0000000..c512ad1
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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 <API/Bluetooth/IBluetoothSocketManager.h>
+#include <dpl/noncopyable.h>
+#include <API/Bluetooth/EventBTSocketNotification.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+
+using namespace TizenApis::Api;
+using namespace TizenApis::Api::Bluetooth;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+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/standards/Tizen/Bluetooth/CMakeLists.txt b/src/standards/Tizen/Bluetooth/CMakeLists.txt
new file mode 100644 (file)
index 0000000..600e1c7
--- /dev/null
@@ -0,0 +1,40 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-bluetooth")
+
+include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_BLUETOOTH})
+
+#set(LIBS_PLATFORM_IMPLEMENTATION_BLUETOOTH
+#      ${LIBS_PLATFORM_IMPLEMENTATION_BLUETOOTH}
+#)
+
+
+set(SRCS 
+       ${SRCS_PLATFORM_IMPLEMENTATION_BLUETOOTH}       
+       ${SRCS_PLATFORM_API_BLUETOOTH}
+       plugin_initializer.cpp
+       plugin_config.cpp
+       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
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+       ${LIBS_COMMON}
+       ${LIBS_PLATFORM_IMPLEMENTATION_BLUETOOTH}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION tizen-2.0-bluetooth)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION tizen-2.0-bluetooth)
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothAdapter.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothAdapter.cpp
new file mode 100644 (file)
index 0000000..442ba53
--- /dev/null
@@ -0,0 +1,1386 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Commons/Exception.h>
+#include "JSBluetoothAdapter.h"
+#include <API/Bluetooth/IBluetoothAdapterManager.h>
+#include <API/Bluetooth/BluetoothFactory.h>
+#include <API/Bluetooth/BluetoothProperty.h>
+#include "BluetoothAdapterListener.h"
+#include "BluetoothMultiCallback.h"
+#include "BluetoothConverter.h"
+#include "plugin_config.h"
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+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
+};
+
+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_properties[] = {
+       {"address", getAddress, NULL, kJSPropertyAttributeReadOnly},
+       {"name", getName, NULL, kJSPropertyAttributeReadOnly},
+       {"powered", getPowered, NULL, kJSPropertyAttributeReadOnly},            
+       {"visible", getVisible, NULL, kJSPropertyAttributeReadOnly},            
+
+       {0, 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);
+}
+
+
+JSValueRef JSBluetoothAdapter::getAddress(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 address = BluetoothAdapterManager->getAddress();
+               return converter.toJSValueRef(address);
+       }
+       Catch (WrtDeviceApis::Commons::Exception) 
+       {
+               LogWarning("Exception"<<_rethrown_exception.GetMessage());
+       }
+       
+       return NULL;
+
+}
+
+
+JSValueRef JSBluetoothAdapter::getVisible(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());
+               bool visibility = BluetoothAdapterManager->getVisibility();
+               return converter.toJSValueRef(visibility);
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("Exception"<<_rethrown_exception.GetMessage());
+       }
+
+       return NULL;
+
+}
+
+
+
+const JSClassRef JSBluetoothAdapter::getClassRef() 
+{
+       if (!m_jsClassRef) 
+       {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSBluetoothAdapter::getClassInfo() 
+{
+       return &m_classInfo;
+}
+
+
+void JSBluetoothAdapter::initialize(JSContextRef context, 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 ");
+       }
+}
+
+void JSBluetoothAdapter::finalize(JSObjectRef object) 
+{
+       LogDebug("JSBluetoothAdapter::Finalrize");
+
+       JSBluetoothAdapterPriv* priv = static_cast<JSBluetoothAdapterPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+       {
+               JSObjectSetPrivate(object, NULL);
+               LogDebug("Deleting BluetoothAdapterManager");
+               delete priv;
+       }
+
+
+}
+
+bool JSBluetoothAdapter::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) 
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+
+JSObjectRef JSBluetoothAdapter::createJSObject(JSContextRef context)
+{
+       IBluetoothAdapterManagerPtr BluetoothAdapterManager(BluetoothFactory::getInstance().getBluetoothAdapterManager());
+       JSBluetoothAdapterPriv* priv = new JSBluetoothAdapterPriv( context, BluetoothAdapterManager);
+
+       return JSObjectMake(context, getClassRef(), priv);
+
+}
+
+JSValueRef JSBluetoothAdapter::getPowered(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());
+               bool powered = BluetoothAdapterManager->getPowered();
+               return converter.toJSValueRef(powered);
+       }       
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("Exception"<<_rethrown_exception.GetMessage());
+       }
+
+       return NULL;
+}
+
+
+JSValueRef JSBluetoothAdapter::setPowered(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);
+}
+
+JSValueRef JSBluetoothAdapter::setVisible(JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception) 
+{
+       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);                                                        
+
+               }
+                
+               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);
+}
+
+JSValueRef JSBluetoothAdapter::discoveryDevices(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);
+
+}
+
+JSValueRef JSBluetoothAdapter::stopDiscovery(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);
+
+}
+
+
+JSValueRef JSBluetoothAdapter::getKnownDevices(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);
+}
+
+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) 
+{
+       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);
+
+}
+
+JSValueRef JSBluetoothAdapter::destroyBonding(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);
+}
+
+
+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);
+
+}
+
+
+}
+}
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothAdapter.h b/src/standards/Tizen/Bluetooth/JSBluetoothAdapter.h
new file mode 100644 (file)
index 0000000..e10da1a
--- /dev/null
@@ -0,0 +1,152 @@
+//
+// 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_JS_BLUETOOTH_ADAPTER_H_
+#define TIZENAPIS_TIZEN_JS_BLUETOOTH_ADAPTER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Bluetooth/IBluetoothAdapterManager.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+using namespace TizenApis::Api::Bluetooth;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef PrivateObjectT<Api::Bluetooth::IBluetoothAdapterManagerPtr>::Type JSBluetoothAdapterPriv;
+
+class BluetoothCreateBondingPrivateData : public IEventPrivateData
+{
+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 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[];
+
+       static JSClassRef m_jsClassRef;
+       static bool m_AdapterEnabled;
+};
+
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothClass.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothClass.cpp
new file mode 100644 (file)
index 0000000..eee1291
--- /dev/null
@@ -0,0 +1,309 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "JSBluetoothClass.h"
+#include "plugin_config.h"
+
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassDefinition JSBluetoothClass::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "BluetoothClass",
+       NULL,
+       m_properties,
+       m_function,
+       initialize,
+       finalize,
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+       
+JSStaticFunction JSBluetoothClass::m_function[] =
+{
+       { "hasService", JSBluetoothClass::hasService, kJSPropertyAttributeNone },
+
+       { 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}
+};
+
+
+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)
+{
+       BluetoothClassPtr btClass(new BluetoothClass());
+       JSBluetoothClassPriv* priv = new JSBluetoothClassPriv( context, btClass);
+       btClass->setReadOnly();
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSObjectRef JSBluetoothClass::createJSObject(JSContextRef context, int device)
+{
+       BluetoothClassPtr btClass(new BluetoothClass());
+       JSBluetoothClassPriv* priv = new JSBluetoothClassPriv( context, btClass);
+
+       btClass->fromInt(device);
+       btClass->setReadOnly();
+       
+       return JSObjectMake(context, getClassRef(), priv);
+
+}
+
+JSObjectRef JSBluetoothClass::createJSObject(JSContextRef context, BluetoothDeviceDataClass devClass)
+{
+       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);
+}
+
+
+void JSBluetoothClass::finalize(JSObjectRef object) 
+{
+       JSBluetoothClassPriv* priv = static_cast<JSBluetoothClassPriv*>(JSObjectGetPrivate(object));
+
+       LogDebug("JSBluetoothClass::Finalrize");
+
+       if (priv != NULL) 
+       {
+               JSObjectSetPrivate(object, NULL);
+               delete priv;
+       }
+}
+
+bool JSBluetoothClass::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) 
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSBluetoothClass::getProperty(JSContextRef context,
+                                                                               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 JSValueMakeNull(context);
+}
+
+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;
+
+               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");
+       }
+}
+}
+}
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothClass.h b/src/standards/Tizen/Bluetooth/JSBluetoothClass.h
new file mode 100644 (file)
index 0000000..f754b0c
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// 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_JS_BLUETOOTH_CLASS_H_
+#define TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_H_
+
+#include <JavaScriptCore/JavaScript.h>
+ #include "BluetoothClass.h"
+#include <API/Bluetooth/BTDevice.h>
+ #include <CommonsJavaScript/PrivateObject.h>
+
+using namespace TizenApis::Api; 
+using namespace TizenApis::Api::Bluetooth; 
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+       
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+
+typedef PrivateObjectT<BluetoothClassPtr>::Type JSBluetoothClassPriv;
+
+class JSBluetoothClass {
+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);
+
+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;
+};
+
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMajor.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMajor.cpp
new file mode 100644 (file)
index 0000000..8849026
--- /dev/null
@@ -0,0 +1,181 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "JSBluetoothClassDeviceMajor.h"
+#include "plugin_config.h"
+
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassDefinition JSBluetoothClassDeviceMajor::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "BluetoothClassDeviceMajor",
+       NULL,
+       m_properties,
+       NULL,
+       initialize,
+       finalize,
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+       
+
+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}
+};
+
+
+const JSClassRef JSBluetoothClassDeviceMajor::getClassRef() 
+{
+       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) 
+{
+       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 ");                
+       }
+}
+
+
+JSObjectRef JSBluetoothClassDeviceMajor::createJSObject(JSContextRef context)
+{
+       BluetoothClassPtr btClass(new BluetoothClass());
+       JSBluetoothClassDeviceMajorPriv* priv = new JSBluetoothClassDeviceMajorPriv( context, btClass);
+       btClass->setReadOnly();
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+
+void JSBluetoothClassDeviceMajor::finalize(JSObjectRef object) 
+{
+       JSBluetoothClassDeviceMajorPriv* priv = static_cast<JSBluetoothClassDeviceMajorPriv*>(JSObjectGetPrivate(object));
+
+       LogDebug("JSBluetoothClassDeviceMajor::Finalrize");
+
+       if (priv != NULL) 
+       {
+               JSObjectSetPrivate(object, NULL);
+               delete priv;
+       }
+}
+
+bool JSBluetoothClassDeviceMajor::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) {
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSBluetoothClassDeviceMajor::getProperty(JSContextRef context,
+                                                                               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;
+}
+}
+}
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMajor.h b/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMajor.h
new file mode 100644 (file)
index 0000000..97a6c32
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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_JS_BLUETOOTH_CLASS_DEVICE_MAJOR_H_
+#define TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_DEVICE_MAJOR_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "BluetoothClass.h"
+#include <API/Bluetooth/BTDevice.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<BluetoothClassPtr>::Type JSBluetoothClassDeviceMajorPriv;
+
+class JSBluetoothClassDeviceMajor {
+public:
+       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;
+};
+
+}
+}
+
+#endif
+
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMinor.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMinor.cpp
new file mode 100644 (file)
index 0000000..a51bb26
--- /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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "JSBluetoothClassDeviceMinor.h"
+#include "plugin_config.h"
+
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassDefinition JSBluetoothClassDeviceMinor::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "BluetoothClassDeviceMinor",
+       NULL,
+       m_properties,
+       NULL,
+       initialize,
+       finalize,
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+
+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}
+};
+
+
+const JSClassRef JSBluetoothClassDeviceMinor::getClassRef() 
+{
+       if (!m_jsClassRef) 
+       {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSBluetoothClassDeviceMinor::getClassInfo() 
+{
+       return &m_classInfo;
+}
+
+JSClassRef JSBluetoothClassDeviceMinor::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceMinor::getClassInfo());
+
+void JSBluetoothClassDeviceMinor::initialize(JSContextRef context, JSObjectRef object) 
+{
+       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 ");                
+       }
+}
+
+
+JSObjectRef JSBluetoothClassDeviceMinor::createJSObject(JSContextRef context)
+{
+       BluetoothClassPtr btClass(new BluetoothClass());
+       JSBluetoothClassDeviceMinorPriv* priv = new JSBluetoothClassDeviceMinorPriv( context, btClass);
+       btClass->setReadOnly();
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+
+void JSBluetoothClassDeviceMinor::finalize(JSObjectRef object) 
+{
+       JSBluetoothClassDeviceMinorPriv* priv = static_cast<JSBluetoothClassDeviceMinorPriv*>(JSObjectGetPrivate(object));
+
+       LogDebug("JSBluetoothClassDeviceMinor::Finalrize");
+
+       if (priv != NULL) 
+       {
+               JSObjectSetPrivate(object, NULL);
+               delete priv;
+       }
+}
+
+bool JSBluetoothClassDeviceMinor::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) 
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSBluetoothClassDeviceMinor::getProperty(JSContextRef context,
+                                                                               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;
+}
+}
+}
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMinor.h b/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceMinor.h
new file mode 100644 (file)
index 0000000..ee07eda
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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_JS_BLUETOOTH_CLASS_H_
+#define TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_H_
+
+#include <JavaScriptCore/JavaScript.h>
+ #include "BluetoothClass.h"
+#include <API/Bluetooth/BTDevice.h>
+ #include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<BluetoothClassPtr>::Type JSBluetoothClassDeviceMinorPriv;
+
+class JSBluetoothClassDeviceMinor 
+{
+public:
+       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;
+};
+
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceService.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceService.cpp
new file mode 100644 (file)
index 0000000..d6230fc
--- /dev/null
@@ -0,0 +1,181 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "JSBluetoothClassDeviceService.h"
+#include "plugin_config.h"
+
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassDefinition JSBluetoothClassDeviceService::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "BluetoothClassDeviceService",
+       NULL,
+       m_properties,
+       NULL,
+       initialize,
+       finalize,
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+       
+
+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}
+};
+
+
+const JSClassRef JSBluetoothClassDeviceService::getClassRef() 
+{
+       if (!m_jsClassRef) 
+       {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSBluetoothClassDeviceService::getClassInfo() 
+{
+       return &m_classInfo;
+}
+
+JSClassRef JSBluetoothClassDeviceService::m_jsClassRef = JSClassCreate(JSBluetoothClassDeviceService::getClassInfo());
+
+void JSBluetoothClassDeviceService::initialize(JSContextRef context, JSObjectRef object) 
+{
+       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 ");              
+       }
+}
+
+
+JSObjectRef JSBluetoothClassDeviceService::createJSObject(JSContextRef context)
+{
+       BluetoothClassPtr btClass(new BluetoothClass());
+       JSBluetoothClassDeviceServicePriv* priv = new JSBluetoothClassDeviceServicePriv( context, btClass);
+       btClass->setReadOnly();
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+void JSBluetoothClassDeviceService::finalize(JSObjectRef object) 
+{
+       JSBluetoothClassDeviceServicePriv* priv = static_cast<JSBluetoothClassDeviceServicePriv*>(JSObjectGetPrivate(object));
+
+       LogDebug("JSBluetoothClassDeviceService::Finalrize");
+
+       if (priv != NULL) 
+       {
+               JSObjectSetPrivate(object, NULL);
+               delete priv;
+       }
+}
+
+bool JSBluetoothClassDeviceService::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) 
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSBluetoothClassDeviceService::getProperty(JSContextRef context,
+                                                                               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;
+}
+}
+}
+
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceService.h b/src/standards/Tizen/Bluetooth/JSBluetoothClassDeviceService.h
new file mode 100644 (file)
index 0000000..12802d5
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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_JS_BLUETOOTH_CLASS_DEVICE_SERVICE_H_
+#define TIZENAPIS_TIZEN_JS_BLUETOOTH_CLASS_DEVICE_SERVICE_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "BluetoothClass.h"
+#include <API/Bluetooth/BTDevice.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<BluetoothClassPtr>::Type JSBluetoothClassDeviceServicePriv;
+
+class JSBluetoothClassDeviceService 
+{
+public:
+       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;
+};
+}
+}
+
+#endif
+
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothDevice.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothDevice.cpp
new file mode 100644 (file)
index 0000000..9e76197
--- /dev/null
@@ -0,0 +1,502 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "JSBluetoothDevice.h"
+#include <API/Bluetooth/IBluetoothDeviceManager.h>
+#include <API/Bluetooth/BluetoothFactory.h>
+#include "BluetoothDeviceManagerListener.h"
+#include <API/Bluetooth/BluetoothProperty.h>
+#include "JSBluetoothClass.h"
+#include "BluetoothConverter.h"
+#include "plugin_config.h"
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+JSClassDefinition JSBluetoothDevice::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "BluetoothDevice",
+       NULL,
+       m_properties,
+       m_function,
+       initialize,
+       finalize,
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+JSStaticFunction JSBluetoothDevice::m_function[] =
+{
+       { "connectToServiceByUUID", JSBluetoothDevice::connectToServiceByUUID, kJSPropertyAttributeNone },
+       { 0, 0, 0 }
+};
+
+JSStaticValue JSBluetoothDevice::m_properties[] = {
+       {"name", getName, NULL, kJSPropertyAttributeReadOnly},
+       {"address", getAddress, NULL, kJSPropertyAttributeReadOnly},
+       {"deviceClass", getDeviceClass, NULL, kJSPropertyAttributeReadOnly},
+       {"isBonded", getBondProperty, NULL, kJSPropertyAttributeReadOnly},
+       {"isTrusted", getTrustProperty, NULL, kJSPropertyAttributeReadOnly},
+       {"isConnected", getConnectProperty, NULL, kJSPropertyAttributeReadOnly},
+       {"uuids", getUuids, NULL, kJSPropertyAttributeReadOnly},        
+       {0, 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) 
+{
+       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");
+       }
+
+
+}
+
+void JSBluetoothDevice::finalize(JSObjectRef object) 
+{
+       LogDebug("Finalrize");
+
+       JSBluetoothDevicePriv* priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+       {
+               JSObjectSetPrivate(object, NULL);
+               LogDebug("Deleting BluetoothManager");
+               delete priv;
+       }
+}
+
+
+bool JSBluetoothDevice::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) 
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+
+JSObjectRef JSBluetoothDevice::createJSObject(JSContextRef context, BluetoothDeviceData device)
+{
+       IBluetoothDeviceManagerPtr BluetoothManager(BluetoothFactory::getInstance().getBluetoothDeviceManager());
+       BluetoothManager->setDevice(device);
+       
+       JSBluetoothDevicePriv* priv = new JSBluetoothDevicePriv( context, BluetoothManager);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+
+
+JSValueRef JSBluetoothDevice::getName(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 name = BluetoothDeviceManager->getNameProperty();
+               LogDebug("name" << name);       
+               return converter.toJSValueRef(name);
+       }
+       Catch (WrtDeviceApis::Commons::Exception) 
+       {
+               LogWarning("Exception"<<_rethrown_exception.GetMessage());
+       }
+       
+       return NULL;
+}
+
+JSValueRef JSBluetoothDevice::getAddress(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::getDeviceClass(JSContextRef context,
+                                                       JSObjectRef object,
+                                                       JSStringRef propertyName,
+                                                       JSValueRef* exception)
+{
+       LogDebug("Enter");      
+
+       JSBluetoothDevicePriv *priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(object));
+
+       Try 
+       {
+               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);        
+               
+               JSObjectRef adapterObject = JSBluetoothClass::createJSObject(priv->getContext(), devClass);
+               return adapterObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception) 
+       {
+               LogWarning("Exception"<<_rethrown_exception.GetMessage());
+       }
+       
+       return NULL;
+
+}
+JSValueRef JSBluetoothDevice::getBondProperty(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 isBonded = BluetoothDeviceManager->getBondProperty();
+
+               LogDebug("isBonded " << isBonded);      
+               
+               return converter.toJSValueRef(isBonded);
+       }
+       Catch(WrtDeviceApis::Commons::Exception) 
+       {
+               LogWarning("Exception"<<_rethrown_exception.GetMessage());
+       }
+       
+       return NULL;
+}
+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 NULL;
+}
+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 NULL;
+       
+}
+
+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 NULL;
+       
+}
+
+
+       
+
+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);
+}
+}
+}
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothDevice.h b/src/standards/Tizen/Bluetooth/JSBluetoothDevice.h
new file mode 100644 (file)
index 0000000..d829159
--- /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 TIZENAPIS_TIZEN_JS_BLUETOOTH_DEVICE_H_
+#define TIZENAPIS_TIZEN_JS_BLUETOOTH_DEVICE_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <API/Bluetooth/IBluetoothDeviceManager.h>
+#include <CommonsJavaScript/PrivateObject.h>
+using namespace TizenApis::Api;
+using namespace TizenApis::Api::Bluetooth;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef PrivateObjectT<Api::Bluetooth::IBluetoothDeviceManagerPtr>::Type JSBluetoothDevicePriv;
+
+class JSBluetoothDevice 
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+       static const JSClassRef getClassRef();
+       static JSObjectRef createJSObject(JSContextRef context, BluetoothDeviceData 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 getDeviceClass(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);
+       static JSClassDefinition m_classInfo;
+       static JSStaticFunction m_function[];
+       static JSStaticValue m_properties[];
+       static JSClassRef m_jsClassRef;
+};
+
+} 
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothManager.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothManager.cpp
new file mode 100644 (file)
index 0000000..82c9dd9
--- /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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <API/Bluetooth/BluetoothFactory.h>
+#include <API/Bluetooth/IBluetoothAdapterManager.h>
+#include <API/Bluetooth/BluetoothProperty.h>
+#include "JSBluetoothManager.h"
+#include "JSBluetoothAdapter.h"
+#include "JSBluetoothClassDeviceMajor.h"
+#include "JSBluetoothClassDeviceMinor.h"
+#include "JSBluetoothClassDeviceService.h"
+#include "plugin_config.h"
+
+
+using namespace TizenApis::Api::Bluetooth;
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Commons;
+
+namespace {
+       #define DEVICE_MAJOR "deviceMajor"
+       #define DEVICE_MINOR "deviceMinor"
+       #define DEVICE_SERVICE "deviceService"
+}
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassRef JSBluetoothManager::m_jsClassRef = NULL;
+
+JSClassDefinition JSBluetoothManager::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "BluetoothManager",
+       NULL,
+       m_properties,
+       m_function,
+       initialize,
+       finalize,
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL,
+       NULL,
+       NULL,
+       NULL
+};
+
+
+JSStaticFunction JSBluetoothManager::m_function[] =
+{
+       { "getDefaultAdapter", getDefaultAdapter, kJSPropertyAttributeNone },
+       { 0, 0, 0 }
+};
+
+
+JSStaticValue JSBluetoothManager::m_properties[] = 
+{
+       {DEVICE_MAJOR, getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {DEVICE_MINOR, getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {DEVICE_SERVICE, getProperty, NULL, kJSPropertyAttributeReadOnly},      
+       {0, 0, 0, 0}
+};
+
+
+
+const JSClassRef JSBluetoothManager::getClassRef() 
+{
+       if (!m_jsClassRef) 
+       {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+JSValueRef JSBluetoothManager::getDefaultAdapter(JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception) 
+{
+       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");
+       }
+}
+
+void JSBluetoothManager::getPropertyNames(JSContextRef context,
+                                       JSObjectRef object,
+                                       JSPropertyNameAccumulatorRef propertyNames)
+{
+}
+
+
+JSValueRef JSBluetoothManager::getProperty(JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception)
+{
+       LogDebug("OK"); 
+       
+       try 
+       {
+               if(JSStringIsEqualToUTF8CString(propertyName, DEVICE_MAJOR)) 
+               {
+                       return JSBluetoothClassDeviceMajor::createJSObject(context);
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, DEVICE_MINOR)) 
+               {
+                       return JSBluetoothClassDeviceMinor::createJSObject(context);
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, DEVICE_SERVICE)) 
+               {
+                       return JSBluetoothClassDeviceService::createJSObject(context);
+               }
+
+       }
+       Catch (WrtDeviceApis::Commons::ConversionException)
+       {
+               LogError("ConversionException");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error");
+       }
+       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
+       {
+               LogError("InvalidArgumentException");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error");
+       }
+       Catch(WrtDeviceApis::Commons::Exception) 
+       {
+               LogError("UnkownException");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Unkown error");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+
+
+const JSClassDefinition* JSBluetoothManager::getClassInfo() 
+{
+       return &m_classInfo;
+}
+
+
+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;
+               }
+       }
+}
+
+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;
+       }
+}
+
+bool JSBluetoothManager::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) 
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+}
+}
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothManager.h b/src/standards/Tizen/Bluetooth/JSBluetoothManager.h
new file mode 100644 (file)
index 0000000..fb3b5f9
--- /dev/null
@@ -0,0 +1,56 @@
+//
+// 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_JS_BLUETOOTH_H_
+#define TIZENAPIS_TIZEN_JS_BLUETOOTH_H_
+
+#include <JavaScriptCore/JavaScript.h>
+ #include <CommonsJavaScript/PrivateObject.h>
+
+using namespace WrtDeviceApis;
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<void>::Type JSBluetoothManagerPriv;
+
+class JSBluetoothManager 
+{
+public:
+       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 getDefaultAdapter(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 void getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
+       static JSClassDefinition m_classInfo;
+       static JSStaticFunction m_function[];
+       static JSStaticValue m_properties[];
+       static JSClassRef m_jsClassRef;
+};
+}
+} 
+
+#endif
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothServiceHandler.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothServiceHandler.cpp
new file mode 100644 (file)
index 0000000..6f1ba8d
--- /dev/null
@@ -0,0 +1,409 @@
+//
+// 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 "JSBluetoothServiceHandler.h"
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <API/Bluetooth/BluetoothProperty.h>
+#include "BluetoothConverter.h"
+#include "BluetoothAdapterListener.h"
+#include <API/Bluetooth/BluetoothFactory.h>
+#include <bluetooth.h>
+#include "plugin_config.h"
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+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
+};
+
+
+
+
+JSStaticValue JSBluetoothServiceHandler::m_properties[] = 
+{
+       {"uuid", getUuid, NULL, kJSPropertyAttributeReadOnly},
+       {"onconnect", NULL, setOnConnect, kJSPropertyAttributeNone},
+       {"name", getName, NULL, kJSPropertyAttributeReadOnly},                  
+       {"isConnected", getIsConnected, NULL, kJSPropertyAttributeReadOnly},                    
+       {0, 0, 0, 0}
+};
+
+JSStaticFunction JSBluetoothServiceHandler::m_function[] =
+{
+       {"unregister", JSBluetoothServiceHandler::unregisterRFCOMMService, 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);
+
+}
+
+
+
+const JSClassRef JSBluetoothServiceHandler::getClassRef() 
+{
+       if (!m_jsClassRef) 
+       {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+
+void JSBluetoothServiceHandler::getPropertyNames(JSContextRef context,
+                                       JSObjectRef object,
+                                       JSPropertyNameAccumulatorRef propertyNames)
+{
+}
+
+
+bool JSBluetoothServiceHandler::setOnConnect(JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef value,
+                                       JSValueRef* exception)
+
+{
+       LogDebug("OK");
+       
+       try 
+       {
+               JSBluetoothServiceHandlerPriv *priv = static_cast<JSBluetoothServiceHandlerPriv*>(JSObjectGetPrivate(object));
+               BluetoothConverter converter(priv->getContext());
+               JSValueRef successCallback = NULL;
+               JSValueRef errorCallback = NULL;
+
+               if (priv == NULL)
+               {
+                       ThrowMsg(UnknownException, "private object null");
+               }
+
+               JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
+
+               if (cbm == NULL)
+               {
+                       ThrowMsg(ConversionException, "callback manager creation fail");
+               }
+
+               successCallback = converter.toFunction(value);
+               
+               cbm->setOnSuccess(successCallback);
+               cbm->setOnError(errorCallback);
+               //cbm->setObject(object);
+
+               IBluetoothServiceHandlerManagerPtr BluetoothServiceHandlerManager(priv->getObject());
+               EventBTServiceOnConnectEmitterPtr emitter(new EventBTServiceOnConnectEmitter);
+
+               emitter->setListener(&BluetoothAdapterListener::getInstance());
+               emitter->setEventPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(cbm));
+               BluetoothServiceHandlerManager->setServiceHandlerListener(emitter);
+                               
+               return true;
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               LogError("Exception: " << ex.GetMessage());
+
+               switch (ex.getCode())
+               {
+               case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                       JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
+                       break;
+               case WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException:
+                       JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error");
+                       break;
+               case WrtDeviceApis::Commons::ExceptionCodes::Exception:
+               default:
+                       JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Unkown error");
+               }
+       }       
+       return false;
+
+}
+
+
+       
+
+JSValueRef JSBluetoothServiceHandler::getUuid(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 uuid = BluetoothServiceHandlerManager->getUUID();
+               return converter.toJSValueRef(uuid);
+
+       }       
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               LogWarning("Exception: " << ex.GetMessage());
+       }       
+       
+       return NULL;
+}
+
+
+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 NULL;
+}
+
+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 NULL;
+}
+
+const JSClassDefinition* JSBluetoothServiceHandler::getClassInfo() 
+{
+       return &m_classInfo;
+}
+
+
+
+
+
+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::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);
+}
+
+
+}
+}
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothServiceHandler.h b/src/standards/Tizen/Bluetooth/JSBluetoothServiceHandler.h
new file mode 100644 (file)
index 0000000..77537cb
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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_JS_BLUETOOTH_SERVICE_HANDLER_H_
+#define TIZENAPIS_TIZEN_JS_BLUETOOTH_SERVICE_HANDLER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Bluetooth/IBluetoothServiceHandlerManager.h>
+
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef PrivateObjectT<Api::Bluetooth::IBluetoothServiceHandlerManagerPtr>::Type JSBluetoothServiceHandlerPriv;
+
+class JSBluetoothServiceHandler 
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+       static const JSClassRef getClassRef();
+
+       static JSObjectRef createJSObject(JSContextRef context, std::string name, std::string uuid, int registerSock);
+
+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 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;
+};
+}
+} 
+
+#endif
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothSocket.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothSocket.cpp
new file mode 100644 (file)
index 0000000..62e4a3a
--- /dev/null
@@ -0,0 +1,524 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <API/Bluetooth/BluetoothFactory.h>
+#include <API/Bluetooth/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 "plugin_config.h"
+
+using namespace std;
+using namespace DPL;
+using namespace TizenApis::Api;
+using namespace TizenApis::Api::Bluetooth;
+using namespace TizenApis::Commons;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+JSClassDefinition JSBluetoothSocket::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "BluetoothSocket",
+       NULL,
+       m_properties,
+       m_function,
+       initialize,
+       finalize,
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+JSStaticValue JSBluetoothSocket::m_properties[] = 
+{
+       {"uuid", getProperty, NULL, kJSPropertyAttributeReadOnly},
+//     {"protocol", getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {"state", getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {"peer", getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {"onerror", NULL, setProperty, kJSPropertyAttributeNone},
+       {"onmessage", NULL, setProperty, kJSPropertyAttributeNone},
+       {"onclose", NULL, setProperty, kJSPropertyAttributeNone},
+       {0, 0, 0, 0}
+};
+
+
+JSStaticFunction JSBluetoothSocket::m_function[] =
+{
+       { "writeData", JSBluetoothSocket::writeData, kJSPropertyAttributeNone },
+       { "readData", JSBluetoothSocket::readData, kJSPropertyAttributeNone },
+       { "close", JSBluetoothSocket::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));
+               IBluetoothSocketManagerPtr BluetoothSocketManager(priv->getObject());
+               BluetoothConverter converter(priv->getContext());
+               
+               if (priv == NULL)
+               {
+                       ThrowMsg(ConversionException, "private object null");
+               }
+
+               EventBTSocketNotificationEmitterPtr emitter = BluetoothSocketManager->getSocketNotifier();
+       
+               if (BluetoothSocketManager == NULL || emitter == NULL)
+               {
+                       LogError("BluetoothManager or event or listener NULL");
+                       Throw(WrtDeviceApis::Commons::UnknownException);        
+               }
+               
+               BluetoothSocketNotifierPrivateDataPtr privData = 
+                               DPL::DynamicPointerCast<BluetoothSocketNotifierPrivateData>(emitter->getEventPrivateData());
+
+               if (privData == NULL)
+               {
+                       LogError("privData NULL");
+                       Throw(WrtDeviceApis::Commons::UnknownException);        
+               }
+               
+               converter.setBluetoothSocketNotifierCallback(propertyName, value, object, privData);
+               emitter->setListener(&BluetoothSocketListener::getInstance());
+               emitter->setEventPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privData));
+
+               return true;
+       }
+       catch (WrtDeviceApis::Commons::Exception& ex) 
+       {
+               LogError("Exception: " << ex.GetMessage());
+
+               switch (ex.getCode())
+               {
+               case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                       JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
+                       break;
+               case WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException:
+                       JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error");
+                       break;
+               case WrtDeviceApis::Commons::ExceptionCodes::Exception:
+               default:
+                       JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Unkown error");
+               }
+       }       
+       return false;
+
+}
+
+void JSBluetoothSocket::initialize(JSContextRef context, JSObjectRef object) 
+{
+       LogDebug("JSBluetoothSocket::initialize ");
+       
+}
+
+void JSBluetoothSocket::finalize(JSObjectRef object) 
+{
+       LogDebug("JSBluetoothSocket::Finalrize");
+
+       JSBluetoothSocketPriv *priv = static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+       {
+               delete priv;
+               JSObjectSetPrivate(object, NULL);
+       }
+}
+
+bool JSBluetoothSocket::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) 
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSObjectRef JSBluetoothSocket::createJSObject(JSContextRef context, BluetoothSocketData socketData)
+{
+       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");
+               }
+       }               
+
+       
+}
+
+JSObjectRef JSBluetoothSocket::createJSObject(JSContextRef context, BluetoothSocketData socketData, EventBTReadDataType readData)
+{
+       IBluetoothSocketManagerPtr BluetoothSocketManager(BluetoothFactory::getInstance().getBluetoothSocketManager());
+       JSBluetoothSocketPriv* priv = new JSBluetoothSocketPriv( context, BluetoothSocketManager);
+       BluetoothSocketManager->setSocketData(socketData);
+       BluetoothSocketManager->setReadData(readData);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+JSValueRef JSBluetoothSocket::getProperty(JSContextRef context,
+                                                       JSObjectRef object,
+                                                       JSStringRef propertyName,
+                                                       JSValueRef* exception)
+{
+       LogDebug("OK"); 
+
+       
+       try 
+       {
+               JSBluetoothSocketPriv *priv = static_cast<JSBluetoothSocketPriv*>(JSObjectGetPrivate(object));
+               IBluetoothSocketManagerPtr BluetoothSocketManager(priv->getObject());
+               BluetoothConverter converter(priv->getContext());
+
+               if (priv == NULL)
+               {
+                       LogError("priv null");
+                       Throw(WrtDeviceApis::Commons::ConversionException);     
+               }
+
+               if(JSStringIsEqualToUTF8CString(propertyName, "uuid")) 
+               {
+                       std::string uuid = BluetoothSocketManager->getUUID();
+                       return converter.toJSValueRef(uuid);
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, "protocol")) 
+               {
+                       unsigned short int protocol = BluetoothSocketManager->getProtocol();
+                       return converter.toBluetoothProtocolJSValue(protocol);
+
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, "state")) 
+               {
+                       unsigned short int state = BluetoothSocketManager->getState();
+                       return converter.toBluetoothStateJSValue(state);
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, "peer")) 
+               {
+                       BluetoothDeviceData device = BluetoothSocketManager->getPeer();
+                       JSObjectRef adapterObject = JSBluetoothDevice::createJSObject(priv->getContext(), device);
+                       return adapterObject;
+               }
+       }
+       
+       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::INVALID_VALUES_ERROR, "invalid value error");
+       }
+       Catch (WrtDeviceApis::Commons::InvalidArgumentException) 
+       {
+               LogError("InvalidArgumentException");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error");
+       }
+       Catch (WrtDeviceApis::Commons::UnknownException) 
+       {
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Unkown error");
+       }
+       Catch(WrtDeviceApis::Commons::Exception) 
+       {
+               LogError("UnkownException");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Unkown error");
+       }       
+
+       return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSBluetoothSocket::writeData(JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               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");
+       }
+}
+
+
+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());
+
+               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");
+       }       
+}
+
+
+JSValueRef JSBluetoothSocket::close(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");
+       }               
+}
+}
+}
+
diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothSocket.h b/src/standards/Tizen/Bluetooth/JSBluetoothSocket.h
new file mode 100644 (file)
index 0000000..54a1c78
--- /dev/null
@@ -0,0 +1,94 @@
+//
+// 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_JS_BLUETOOTH_SOCKET_H_
+#define TIZENAPIS_TIZEN_JS_BLUETOOTH_SOCKET_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Bluetooth/BTDevice.h>
+#include <API/Bluetooth/IBluetoothSocketManager.h>
+
+using namespace WrtDeviceApis::CommonsJavaScript;
+  
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef  PrivateObjectT<Api::Bluetooth::IBluetoothSocketManagerPtr>::Type JSBluetoothSocketPriv;
+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);
+
+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 JSClassDefinition m_classInfo;
+       static JSStaticFunction m_function[];
+       static JSStaticValue m_properties[];
+
+       static JSClassRef m_jsClassRef;
+       
+};
+
+} 
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Bluetooth/config.xml b/src/standards/Tizen/Bluetooth/config.xml
new file mode 100644 (file)
index 0000000..d203993
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+       <library-name>libwrt-plugins-tizen-2.0-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>
+</plugin-properties>
+
diff --git a/src/standards/Tizen/Bluetooth/plugin_config.cpp b/src/standards/Tizen/Bluetooth/plugin_config.cpp
new file mode 100644 (file)
index 0000000..49d1791
--- /dev/null
@@ -0,0 +1,149 @@
+//
+// 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 <map>
+#include <utility>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include "plugin_config.h"
+
+#define BLUETOOTH_FEATURE_API_ADMIN "http://tizen.org/privilege/bluetooth.admin"
+#define BLUETOOTH_FEATURE_API_GAP "http://tizen.org/privilege/bluetooth.gap"
+#define BLUETOOTH_FEATURE_API_SPP "http://tizen.org/privilege/bluetooth.spp"
+
+#define BLUETOOTH_DEVICE_CAP_ADMIN "bluetooth.admin"
+#define BLUETOOTH_DEVICE_CAP_GAP "bluetooth.gap"
+#define BLUETOOTH_DEVICE_CAP_SPP "bluetooth.spp"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+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();
+
+DEFINE_FUNCTION_GETTER(Bluetooth, BluetoothFunctions);
+
+static WrtDeviceApis::Commons::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_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_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_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);
+
+
+       FunctionMapping BluetoothFunctions;
+
+       for (int index = BLUETOOTH_FUNCTION_API_ADAPTER_SET_NAME; 
+               index <= BLUETOOTH_FUNCTION_API_ADAPTER_SET_VISIBLE; 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));
+       }
+
+
+       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;
+}
+} 
+}
+
+#undef BLUETOOTH_FEATURE_API 
+#undef BLUETOOTH_FEATURE_API_GAP 
+#undef BLUETOOTH_FEATURE_API_SPP 
+#undef BLUETOOTH_DEVICE_CAP_GAP 
+#undef BLUETOOTH_DEVICE_CAP_SPP 
diff --git a/src/standards/Tizen/Bluetooth/plugin_config.h b/src/standards/Tizen/Bluetooth/plugin_config.h
new file mode 100644 (file)
index 0000000..595b1e2
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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_JS_BLUETOOTH_PLUGIN_CONFIG_H_
+#define TIZENAPIS_TIZEN_JS_BLUETOOTH_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+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[];
+
+DECLARE_FUNCTION_GETTER(Bluetooth);
+
+#define BLUETOOTH_CHECK_ACCESS(functionName)                       \
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(                \
+        getBluetoothFunctionData,             \
+        functionName)
+}
+}
+
+#endif 
diff --git a/src/standards/Tizen/Bluetooth/plugin_initializer.cpp b/src/standards/Tizen/Bluetooth/plugin_initializer.cpp
new file mode 100644 (file)
index 0000000..82609fd
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+
+
+#include "JSBluetoothManager.h"
+#include "JSBluetoothAdapter.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+void on_widget_start_callback(int widgetId)
+{
+       LogDebug("[Tizen\\Bluetooth ] on_widget_start_callback ("<<widgetId<<")");
+       Try
+       {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+       }
+       Catch(Commons::Exception)
+       {
+               LogError("WrtAccess initialization failed");
+       }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+       LogDebug("[Tizen\\Bluetooth] on_widget_stop_callback ("<<widgetId<<")");
+       Try
+       {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+       }
+       Catch(Commons::Exception)
+       {
+               LogError("WrtAccess deinitialization failed");
+       }
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+#define BLUETOOTH "bluetooth"
+//#define BLUETOOTH_ADAPTER "adapter"
+
+PLUGIN_CLASS_MAP_BEGIN
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, BLUETOOTH,
+      (js_class_template_getter)TizenApis::Tizen1_0::JSBluetoothManager::getClassRef,NULL)
+//PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN "." BLUETOOTH,BLUETOOTH_ADAPTER,
+//      (js_class_template_getter)TizenApis::Tizen1_0::JSBluetoothAdapter::getClassRef,NULL)
+PLUGIN_CLASS_MAP_END
+
diff --git a/src/standards/Tizen/CMakeLists.txt b/src/standards/Tizen/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..712ca49
--- /dev/null
@@ -0,0 +1,52 @@
+SET( CMAKE_INSTALL_RPATH
+  ${wrt-deviceapis-commons_LIBRARY_DIRS})
+
+pkg_search_module(wrt-plugins-widgetdb REQUIRED wrt-plugins-widgetdb)
+set(LIBS_WIDGETDB ${wrt-plugins-widgetdb_LIBRARIES})
+
+### tizen common module
+set(COMMON_TARGET_NAME       "wrt-plugins-tizen-2.0-common")
+set(COMMON_DESTINATION_NAME  "tizen-2.0-tizen")
+
+set(CMAKE_INSTALL_RPATH
+  ${CMAKE_INSTALL_RPATH}
+  ${CMAKE_INSTALL_PREFIX}/${COMMON_DESTINATION_NAME}
+)
+
+ADD_DEFINITIONS("-DAPPLICATION_API_BACKWARD_COMPATIBILITY")
+
+add_subdir(Common)
+
+set(LIBS_COMMON
+  ${LIBS_COMMON}
+  ${COMMON_TARGET_NAME}
+)
+### tizen common module end
+
+add_subdir(Tizen)
+add_subdir(Content)
+add_subdir(Calendar)
+add_subdir(Contact)
+add_subdir(Bluetooth)
+add_subdir(Application)
+add_subdir(Messaging)
+add_subdir(Callhistory)
+add_subdir(TimeUtil)
+add_subdir(Systeminfo)
+add_subdir(NFC)
+add_subdir(Filesystem)
+add_subdir(Alarm)
+add_subdir(Power)
+add_subdir(Notification)
+add_subdir(Download)
+add_subdir(NetworkBearerSelection)
+add_subdir(SystemSetting)
+#add_subdir(Push)
+#add_subdir(SecureStorage)
+#add_subdir(DeviceInteraction)
+#add_subdir(Accelerometer)
+#add_subdir(Orientation)
+#add_subdir(Gyroscope)
+#add_subdir(Light)
+#add_subdir(Magnetic)
+#add_subdir(Proximity)
diff --git a/src/standards/Tizen/Calendar/CMakeLists.txt b/src/standards/Tizen/Calendar/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..2fd29b3
--- /dev/null
@@ -0,0 +1,48 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-calendar")
+set(DESTINATION_NAME  "tizen-2.0-calendar")
+
+set(CMAKE_INSTALL_RPATH
+    ${CMAKE_INSTALL_RPATH}
+    ${CMAKE_INSTALL_PREFIX}/tizen-2.0-tizen
+    ${CMAKE_INSTALL_PREFIX}/tizen-2.0-time
+    ${CMAKE_INSTALL_PREFIX}/tizen-2.0-contact
+)
+
+set(SRCS
+  ${SRCS_PLATFORM_API_CALENDAR}
+  ${SRCS_PLATFORM_IMPLEMENTATION_CALENDAR}
+  CalendarResponseDispatcher.cpp
+  CalendarConverter.cpp
+  JSCalendarEvent.cpp
+  JSCalendarTask.cpp
+  JSCalendarItemProperties.cpp
+  JSCalendarEventId.cpp
+  JSCalendar.cpp
+  JSCalendarManager.cpp
+  JSCalendarAttendee.cpp
+  JSCalendarRecurrenceRule.cpp
+  JSCalendarAlarm.cpp
+  JSStringArray.cpp
+  JSNumberArray.cpp
+  JSTZDateArray.cpp
+  CalendarAsyncCallbackManager.cpp
+  CalendarListenerManager.cpp
+  plugin_initializer.cpp
+  plugin_config.cpp
+)
+
+include_directories(
+  ${INCLUDES_PLATFORM_IMPLEMENTATION_CALENDAR}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${LIBS_COMMON}
+  ${LIBS_PLATFORM_IMPLEMENTATION_CALENDAR}
+  wrt-plugins-tizen-2.0-tizen-impl
+  wrt-plugins-tizen-2.0-time-impl
+  wrt-plugins-tizen-2.0-contact-impl
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
diff --git a/src/standards/Tizen/Calendar/CalendarAsyncCallbackManager.cpp b/src/standards/Tizen/Calendar/CalendarAsyncCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..5f95015
--- /dev/null
@@ -0,0 +1,23 @@
+//
+// 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 "CalendarAsyncCallbackManager.h"
+#include <dpl/singleton_impl.h>
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::Calendar::CalendarAsyncCallbackManager)
+
diff --git a/src/standards/Tizen/Calendar/CalendarAsyncCallbackManager.h b/src/standards/Tizen/Calendar/CalendarAsyncCallbackManager.h
new file mode 100755 (executable)
index 0000000..7aa51a0
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// 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_CALENDAR_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_CALENDAR_ASYNC_CALLBACK_MANAGER_H_
+
+#include <dpl/singleton.h>
+#include <Tizen/Common/AsyncCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+class CalendarAsyncCallbackManager : public TizenApis::Commons::AsyncCallbackManager
+{
+public:
+       CalendarAsyncCallbackManager()
+       {
+       }
+
+       virtual ~CalendarAsyncCallbackManager()
+       {
+       }
+
+       friend class DPL::Singleton<CalendarAsyncCallbackManager>;
+};
+
+typedef DPL::Singleton<CalendarAsyncCallbackManager> CalendarAsyncCallbackManagerSingleton;
+
+} // Calendar
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CALENDAR_ASYNC_CALLBACK_MANAGER_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/Calendar/CalendarConverter.cpp b/src/standards/Tizen/Calendar/CalendarConverter.cpp
new file mode 100755 (executable)
index 0000000..33f7647
--- /dev/null
@@ -0,0 +1,1021 @@
+//
+// 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/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include "JSCalendarEvent.h"
+#include "JSCalendarTask.h"
+#include "JSCalendarItemProperties.h"
+#include "JSCalendarEventId.h"
+#include "CalendarConverter.h"
+#include "JSCalendar.h"
+#include "JSCalendarManager.h"
+#include "JSCalendarAttendee.h"
+#include "JSCalendarRecurrenceRule.h"
+#include "JSCalendarAlarm.h"
+#include "JSStringArray.h"
+#include "JSNumberArray.h"
+#include "JSTZDateArray.h"
+
+#include <Tizen/TimeUtil/TimeUtilConverter.h>
+#include <API/TimeUtil/DurationProperties.h>
+#include <Tizen/Tizen/JSSimpleCoordinates.h>
+#include <Tizen/Contact/ContactConverter.h>
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace {
+const int DEFAULT_EVENT_INTERVAL = 1;
+}
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+CalendarConverter::CalendarConverter(JSContextRef context, CalendarEvent::CalendarType calendarType) : Converter(context)
+{
+    m_calendarType = calendarType;
+}
+
+CalendarConverter::~CalendarConverter()
+{
+}
+
+JSValueRef CalendarConverter::toJSValueRefEvent(const CalendarEventPtr& arg)
+{
+    return JSUtils::makeObject(m_context, JSCalendarEvent::getClassRef(), arg);
+}
+
+JSValueRef CalendarConverter::toJSValueRefTask(const CalendarEventPtr& arg)
+{
+    return JSUtils::makeObject(m_context, JSCalendarTask::getClassRef(), arg);
+}
+
+JSValueRef CalendarConverter::toJSValueRefEventArray(const CalendarEventListPtr &arg)
+{
+    return toJSValueRef_(*arg, &CalendarConverter::toJSValueRefEvent, this);
+}
+
+JSValueRef CalendarConverter::toJSValueRefTaskArray(const CalendarEventListPtr &arg)
+{
+    return toJSValueRef_(*arg, &CalendarConverter::toJSValueRefTask, this);
+}
+
+JSValueRef CalendarConverter::toJSValueRefCalendar(const ICalendarPtr& arg)
+{
+    CalendarPrivObject *priv = new CalendarPrivObject(m_context, arg);
+    return JSObjectMake(m_context, JSCalendar::getClassRef(), priv);
+}
+
+JSValueRef CalendarConverter::toJSValueRef(const std::vector<ICalendarPtr> &arg)
+{
+    return toJSValueRef_(arg, &CalendarConverter::toJSValueRefCalendar, this);
+}
+
+JSValueRef CalendarConverter::toJSValueRef(const StringArrayPtr &arg)
+{
+       return JSStringArray::createArray(m_context, arg);
+}
+
+JSValueRef CalendarConverter::toJSValueRefNumberArray(const NumberArrayPtr &arg)
+{
+       return JSNumberArray::createArray(m_context, arg);
+}
+
+JSValueRef CalendarConverter::toJSValueRefTZDateArray(const NumberArrayPtr &arg)
+{
+       return JSTZDateArray::createArray(m_context, arg);
+}
+
+StringArrayPtr CalendarConverter::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;
+}
+
+NumberArrayPtr CalendarConverter::toNumberArray(const JSValueRef &jsValue)
+{
+       if(JSNumberArray::isObjectOfClass(m_context, jsValue))
+               return JSNumberArray::getNumberArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "NumberArray is not array.");
+
+       NumberArrayPtr result = NumberArrayPtr(new NumberArray());
+       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((long long int) (toLongLong(element)));
+    }
+    LogDebug("First number: "<<result->at(0));
+    return result;
+}
+
+NumberArrayPtr CalendarConverter::toTZDateArray(const JSValueRef &jsValue)
+{
+       if(JSNumberArray::isObjectOfClass(m_context, jsValue))
+               return JSNumberArray::getNumberArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "NumberArray is not array.");
+
+    TimeUtilConverter timeConverter(m_context);
+
+       NumberArrayPtr result = NumberArrayPtr(new NumberArray());
+       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((long long int) (timeConverter.getTimeInMilliseconds(element)/1000));
+    }
+    LogDebug("First value: "<<result->at(0));
+    return result;
+}
+
+EventAlarm::EventAlarmType CalendarConverter::toEventAlarmType(std::string alarmMethod)
+const
+{
+    if (!alarmMethod.compare(TIZEN_CALENDAR_PROPERTY_DISPLAY_ALARM))
+        return EventAlarm::SILENT_ALARM;
+    else if (!alarmMethod.compare(TIZEN_CALENDAR_PROPERTY_SOUND_ALARM))
+        return EventAlarm::SOUND_ALARM;
+    else
+        ThrowMsg(ConversionException, "Invalid alarm type.");
+
+    return EventAlarm::UNDEFINED_ALARM_TYPE;
+}
+
+std::string CalendarConverter::toTizenValue(EventAlarm::EventAlarmType abstractValue) const
+{
+    switch (abstractValue) {
+    case EventAlarm::SILENT_ALARM:
+        return TIZEN_CALENDAR_PROPERTY_DISPLAY_ALARM;
+    case EventAlarm::SOUND_ALARM:
+        return TIZEN_CALENDAR_PROPERTY_SOUND_ALARM;
+    default:
+        break;
+    }
+    ThrowMsg(ConversionException, "Invalid alarm type");
+}
+
+CalendarEvent::EventStatus CalendarConverter::toEventStatus(std::string tizenValue) const
+{
+    if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_TENTATIVE_STATUS))
+        return CalendarEvent::TENTATIVE_STATUS;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_CONFIRMED_STATUS))
+        return CalendarEvent::CONFIRMED_STATUS;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_CANCELLED_STATUS))
+        return CalendarEvent::CANCELLED_STATUS;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_NEEDS_ACTION_STATUS))
+        return CalendarEvent::NEEDS_ACTION_STATUS;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_IN_PROCESS_STATUS))
+        return CalendarEvent::IN_PROCESS_STATUS;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_COMPLETED_STATUS))
+        return CalendarEvent::COMPLETED_STATUS;
+    else
+        ThrowMsg(ConversionException, "Invalid status type.");
+
+    return CalendarEvent::UNDEFINED_STATUS;
+}
+
+std::string CalendarConverter::toTizenValue(CalendarEvent::EventStatus abstractValue)
+const
+{
+    switch (abstractValue) {
+    case CalendarEvent::TENTATIVE_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_TENTATIVE_STATUS;
+    case CalendarEvent::CONFIRMED_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_CONFIRMED_STATUS;
+    case CalendarEvent::CANCELLED_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_CANCELLED_STATUS;
+    case CalendarEvent::NEEDS_ACTION_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_NEEDS_ACTION_STATUS;
+    case CalendarEvent::IN_PROCESS_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_IN_PROCESS_STATUS;
+    case CalendarEvent::COMPLETED_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_COMPLETED_STATUS;
+    default:
+        {
+            if (CalendarEvent::TASK_TYPE==m_calendarType) {
+                return TIZEN_CALENDAR_PROPERTY_NEEDS_ACTION_STATUS;
+            } else {
+                return TIZEN_CALENDAR_PROPERTY_CONFIRMED_STATUS;
+            }
+            break;
+        }
+    }
+}
+
+EventRecurrenceRule::EventRecurrence CalendarConverter::toRecurrenceFrequency(
+        std::string tizenValue) const
+{
+    if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_DAILY_RECURRENCE))
+        return EventRecurrenceRule::DAILY_RECURRENCE;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_WEEKLY_RECURRENCE))
+        return EventRecurrenceRule::WEEKLY_RECURRENCE;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_MONTHLY_RECURRENCE))
+        return EventRecurrenceRule::MONTHLY_RECURRENCE;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_YEARLY_RECURRENCE))
+        return EventRecurrenceRule::YEARLY_RECURRENCE;
+    else
+        ThrowMsg(ConversionException, "Invalid recurrence frequency type.");
+
+    return EventRecurrenceRule::UNDEFINED_RECURRENCE;
+}
+
+std::string CalendarConverter::toTizenValue(
+        EventRecurrenceRule::EventRecurrence abstractValue) const
+{
+    switch (abstractValue) {
+    case EventRecurrenceRule::DAILY_RECURRENCE:
+        return TIZEN_CALENDAR_PROPERTY_DAILY_RECURRENCE;
+    case EventRecurrenceRule::WEEKLY_RECURRENCE:
+        return TIZEN_CALENDAR_PROPERTY_WEEKLY_RECURRENCE;
+    case EventRecurrenceRule::MONTHLY_RECURRENCE:
+        return TIZEN_CALENDAR_PROPERTY_MONTHLY_RECURRENCE;
+    case EventRecurrenceRule::YEARLY_RECURRENCE:
+        return TIZEN_CALENDAR_PROPERTY_YEARLY_RECURRENCE;
+    case EventRecurrenceRule::NO_RECURRENCE:
+    default:
+        return "";
+        break;
+    }
+}
+
+EventRecurrenceRulePtr CalendarConverter::toEventRecurrenceRule(JSValueRef rrule)
+{
+    EventRecurrenceRulePtr result(new EventRecurrenceRule());
+    const ScopedJSStringRef frequencyStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_FREQUENCY));
+    const ScopedJSStringRef intervalStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_INTERVAL));
+    const ScopedJSStringRef untilDateStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_UNTIL_DATE));
+    const ScopedJSStringRef occurrenceCountStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_OCCURRENCE_COUNT));
+    //const ScopedJSStringRef daysOfTheMonthStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_DAYS_OF_THE_MONTH));
+    const ScopedJSStringRef daysOfTheWeekStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_DAYS_OF_THE_WEEK));
+    //const ScopedJSStringRef daysOfTheYearStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_DAYS_OF_THE_YEAR));
+    //const ScopedJSStringRef weeksOfTheYearStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_WEEKS_OF_THE_YEAR));
+    const ScopedJSStringRef setPositionsStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_SET_POSITIONS));
+    const ScopedJSStringRef exceptionsStr(JSStringCreateWithUTF8CString(TIZEN_RECURRENCE_RULE_EXCEPTIONS));
+
+    JSObjectRef arg = toJSObjectRef(rrule);
+
+    JSValueRef frequencyData = JSObjectGetProperty(m_context, arg, frequencyStr.get(), NULL);
+    JSValueRef intervalData = JSObjectGetProperty(m_context, arg, intervalStr.get(), NULL);
+    JSValueRef untilDateData = JSObjectGetProperty(m_context, arg, untilDateStr.get(), NULL);
+    JSValueRef occurrenceCountData = JSObjectGetProperty(m_context, arg, occurrenceCountStr.get(), NULL);
+    //JSValueRef daysOfTheMonthData = JSObjectGetProperty(m_context, arg, daysOfTheMonthStr.get(), NULL);
+    JSValueRef daysOfTheWeekData = JSObjectGetProperty(m_context, arg, daysOfTheWeekStr.get(), NULL);
+    //JSValueRef daysOfTheYearData = JSObjectGetProperty(m_context, arg, daysOfTheYearStr.get(), NULL);
+    //JSValueRef weeksOfTheYearData = JSObjectGetProperty(m_context, arg, weeksOfTheYearStr.get(), NULL);
+    JSValueRef setPositionsData = JSObjectGetProperty(m_context, arg, setPositionsStr.get(), NULL);
+    JSValueRef exceptionsData = JSObjectGetProperty(m_context, arg, exceptionsStr.get(), NULL);
+
+    if (!JSValueIsUndefined(m_context, frequencyData)) {
+        result->setFrequency(toRecurrenceFrequency(toString(frequencyData)));
+    }
+    if (!JSValueIsUndefined(m_context, intervalData)) {
+        result->setInterval(toInt(intervalData));
+    }
+    if (!JSValueIsUndefined(m_context, untilDateData)) {
+        if (!JSValueIsNull(m_context, untilDateData)) {
+            TimeUtilConverter timeUtilConverter(m_context);
+            result->setEndDate((long long int) (timeUtilConverter.getTimeInMilliseconds(untilDateData)/1000));
+            result->setTimeZone(timeUtilConverter.getPropertiesInTZDate(untilDateData).timezone);
+        } else {
+            result->setEndDate(0);
+        }
+    }
+    if (!JSValueIsUndefined(m_context, occurrenceCountData)) {
+        result->setOccurrenceCount(toLong(occurrenceCountData));
+    }
+    /*if (!JSValueIsUndefined(m_context, daysOfTheMonthData)) {
+        result->setDaysOfTheMonth(toVectorOfInts(daysOfTheMonthData));
+    }*/
+    if (!JSValueIsUndefined(m_context, daysOfTheWeekData)) {
+        result->setDaysOfTheWeek(toStringArray(daysOfTheWeekData));
+    }
+    /*if (!JSValueIsUndefined(m_context, daysOfTheYearData)) {
+        result->setDaysOfTheYear(toVectorOfInts(daysOfTheYearData));
+    }
+    if (!JSValueIsUndefined(m_context, weeksOfTheYearData)) {
+        result->setWeeksOfTheYear(toVectorOfInts(weeksOfTheYearData));
+    }*/
+    if (!JSValueIsUndefined(m_context, setPositionsData)) {
+        result->setSetPositions(toNumberArray(setPositionsData));
+    }
+    if (!JSValueIsUndefined(m_context, exceptionsData)) {
+        result->setExceptions(toTZDateArray(exceptionsData));
+    }
+
+    return result;
+}
+
+CalendarEvent::EventVisibility CalendarConverter::toEventVisibility(std::string tizenValue)
+const
+{
+    if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_PUBLIC_VISIBILITY))
+        return CalendarEvent::PUBLIC_VISIBILITY;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_PRIVATE_VISIBILITY))
+        return CalendarEvent::PRIVATE_VISIBILITY;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_CONFIDENTIAL_VISIBILITY))
+        return CalendarEvent::CONFIDENTIAL_VISIBILITY;
+    else
+        ThrowMsg(ConversionException, "Invalid visibility type.");
+
+    return CalendarEvent::UNDEFINED_VISIBILITY;
+}
+
+std::string CalendarConverter::toTizenValue(
+        CalendarEvent::EventVisibility abstractValue) const
+{
+    switch (abstractValue) {
+    case CalendarEvent::PUBLIC_VISIBILITY:
+        return TIZEN_CALENDAR_PROPERTY_PUBLIC_VISIBILITY;
+    case CalendarEvent::PRIVATE_VISIBILITY:
+        return TIZEN_CALENDAR_PROPERTY_PRIVATE_VISIBILITY;
+    case CalendarEvent::CONFIDENTIAL_VISIBILITY:
+        return TIZEN_CALENDAR_PROPERTY_CONFIDENTIAL_VISIBILITY;
+    default:
+        break;
+    }
+
+    return TIZEN_CALENDAR_PROPERTY_PUBLIC_VISIBILITY;
+}
+
+CalendarEvent::EventAvailability CalendarConverter::toEventAvailability(std::string tizenValue)
+const
+{
+    if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_BUSY))
+        return CalendarEvent::BUSY_FB;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_BUSY_UNAVAILABLE_FB))
+        return CalendarEvent::BUSY_UNAVAILABLE_FB;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_FREE))
+        return CalendarEvent::FREE_FB;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_BUSY_TENTATIVE))
+        return CalendarEvent::BUSY_TENTATIVE_FB;
+    else
+        ThrowMsg(ConversionException, "Invalid availability type.");
+
+    return CalendarEvent::UNDEFINED_AVAILABILITY;
+}
+
+std::string CalendarConverter::toTizenValue(
+        CalendarEvent::EventAvailability abstractValue) const
+{
+    switch (abstractValue) {
+    case CalendarEvent::BUSY_FB:
+        return TIZEN_CALENDAR_PROPERTY_BUSY;
+    case CalendarEvent::BUSY_UNAVAILABLE_FB:
+        return TIZEN_CALENDAR_PROPERTY_BUSY_UNAVAILABLE_FB;
+    case CalendarEvent::FREE_FB:
+        return TIZEN_CALENDAR_PROPERTY_FREE;
+    case CalendarEvent::BUSY_TENTATIVE_FB:
+        return TIZEN_CALENDAR_PROPERTY_BUSY_TENTATIVE;
+    default:
+        break;
+    }
+
+    return TIZEN_CALENDAR_PROPERTY_BUSY;
+}
+
+EventAttendee::EventAttendeeRole CalendarConverter::toEventAttendeeRole(std::string tizenValue)
+const
+{
+    if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_REQ_PARTICIPANT_ROLE))
+        return EventAttendee::REQ_PARTICIPANT_ROLE;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_OPT_PARTICIPANT_ROLE))
+        return EventAttendee::OPT_PARTICIPANT_ROLE;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_NON_PARTICIPANT_ROLE))
+        return EventAttendee::NON_PARTICIPANT_ROLE;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_CHAIR_ROLE))
+        return EventAttendee::CHAIR_ROLE;
+    else
+        ThrowMsg(ConversionException, "Invalid attendee role type.");
+
+    return EventAttendee::UNDEFINED_ATTENDEE_ROLE;
+}
+
+std::string CalendarConverter::toTizenValue(
+        EventAttendee::EventAttendeeRole abstractValue) const
+{
+    switch (abstractValue) {
+    case EventAttendee::REQ_PARTICIPANT_ROLE:
+        return TIZEN_CALENDAR_PROPERTY_REQ_PARTICIPANT_ROLE;
+    case EventAttendee::OPT_PARTICIPANT_ROLE:
+        return TIZEN_CALENDAR_PROPERTY_OPT_PARTICIPANT_ROLE;
+    case EventAttendee::NON_PARTICIPANT_ROLE:
+        return TIZEN_CALENDAR_PROPERTY_NON_PARTICIPANT_ROLE;
+    case EventAttendee::CHAIR_ROLE:
+        return TIZEN_CALENDAR_PROPERTY_CHAIR_ROLE;
+    default:
+        break;
+    }
+    return TIZEN_CALENDAR_PROPERTY_REQ_PARTICIPANT_ROLE;
+}
+
+EventAttendee::EventAttendeeStatus CalendarConverter::toEventAttendeeStatus(std::string tizenValue)
+const
+{
+    if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_PENDING_STATUS))
+        return EventAttendee::PENDING_AT_STATUS;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_ACCEPTED_STATUS))
+        return EventAttendee::ACCEPTED_AT_STATUS;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_DECLINED_STATUS))
+        return EventAttendee::DECLINED_AT_STATUS;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_TENTATIVE_STATUS))
+        return EventAttendee::TENTATIVE_AT_STATUS;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_DELEGATED_STATUS))
+        return EventAttendee::DELEGATED_AT_STATUS;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_COMPLETED_STATUS))
+        return EventAttendee::COMPLETED_AT_STATUS;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_IN_PROCESS_STATUS))
+        return EventAttendee::IN_PROCESS_AT_STATUS;
+    else
+        ThrowMsg(ConversionException, "Invalid attendee status type.");
+
+    return EventAttendee::UNDEFINED_ATTENDEE_STATUS;
+}
+
+std::string CalendarConverter::toTizenValue(
+        EventAttendee::EventAttendeeStatus abstractValue) const
+{
+    switch (abstractValue) {
+    case EventAttendee::PENDING_AT_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_PENDING_STATUS;
+    case EventAttendee::ACCEPTED_AT_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_ACCEPTED_STATUS;
+    case EventAttendee::DECLINED_AT_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_DECLINED_STATUS;
+    case EventAttendee::TENTATIVE_AT_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_TENTATIVE_STATUS;
+    case EventAttendee::DELEGATED_AT_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_DELEGATED_STATUS;
+    case EventAttendee::COMPLETED_AT_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_COMPLETED_STATUS;
+    case EventAttendee::IN_PROCESS_AT_STATUS:
+        return TIZEN_CALENDAR_PROPERTY_IN_PROCESS_STATUS;
+    default:
+        break;
+    }
+    return TIZEN_CALENDAR_PROPERTY_PENDING_STATUS;
+}
+
+EventAttendee::EventAttendeeType CalendarConverter::toEventAttendeeType(std::string tizenValue)
+const
+{
+    if(!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_INDIVIDUAL_TYPE))
+        return EventAttendee::INDIVIDUAL_TYPE;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_GROUP_TYPE))
+        return EventAttendee::GROUP_TYPE;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_RESOURCE_TYPE))
+        return EventAttendee::RESOURCE_TYPE;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_ROOM_TYPE))
+        return EventAttendee::ROOM_TYPE;
+    else if (!tizenValue.compare(TIZEN_CALENDAR_PROPERTY_UNKNOWN_TYPE))
+        return EventAttendee::UNKNOWN_TYPE;
+    else
+        ThrowMsg(ConversionException, "Invalid attendee type.");
+
+    return EventAttendee::INDIVIDUAL_TYPE;
+}
+
+std::string CalendarConverter::toTizenValue(
+        EventAttendee::EventAttendeeType abstractValue) const
+{
+    switch (abstractValue) {
+    case EventAttendee::INDIVIDUAL_TYPE:
+        return TIZEN_CALENDAR_PROPERTY_INDIVIDUAL_TYPE;
+    case EventAttendee::GROUP_TYPE:
+        return TIZEN_CALENDAR_PROPERTY_GROUP_TYPE;
+    case EventAttendee::RESOURCE_TYPE:
+        return TIZEN_CALENDAR_PROPERTY_RESOURCE_TYPE;
+    case EventAttendee::ROOM_TYPE:
+        return TIZEN_CALENDAR_PROPERTY_ROOM_TYPE;
+    case EventAttendee::UNKNOWN_TYPE:
+        return TIZEN_CALENDAR_PROPERTY_UNKNOWN_TYPE;
+    default:
+        break;
+    }
+
+    return TIZEN_CALENDAR_PROPERTY_INDIVIDUAL_TYPE;
+}
+
+JSValueRef CalendarConverter::toFunctionOrNull(const JSValueRef& arg)
+{
+    if (Validator(m_context).isCallback(arg)) {
+        return arg;
+    } else if (!JSValueIsNull(m_context,
+                              arg) && !JSValueIsUndefined(m_context, arg)) {
+        ThrowMsg(ConversionException, "Not a function nor JS null.");
+    }
+    return NULL;
+}
+
+JSValueRef CalendarConverter::toFunction(const JSValueRef& arg)
+{
+    if (Validator(m_context).isCallback(arg)) {
+        return arg;
+    }
+    ThrowMsg(ConversionException, "Not a function.");
+}
+
+StringArrayPtr CalendarConverter::toCategories(JSValueRef categories)
+{
+    StringArrayPtr result(new StringArray());
+    *result = toVectorOfStrings(categories);
+    return result;
+}
+
+EventAttendeePtr CalendarConverter::toAttendee(JSValueRef attendee)
+{
+    EventAttendeePtr result(new EventAttendee());
+    const ScopedJSStringRef nameStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_NAME));
+    const ScopedJSStringRef uriStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_URI));
+    const ScopedJSStringRef roleStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_ROLE));
+    const ScopedJSStringRef statusStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_STATUS));
+    const ScopedJSStringRef RSVPStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_RSVP));
+    const ScopedJSStringRef typeStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_TYPE));
+    const ScopedJSStringRef groupStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_GROUP));
+    const ScopedJSStringRef delegatorURIStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_DELEGATORURI));
+    const ScopedJSStringRef delegateURIStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_DELEGATEURI));
+    const ScopedJSStringRef contactRefStr(JSStringCreateWithUTF8CString(TIZEN_ATTENDEE_CONTACT_REF));
+
+    JSObjectRef arg = toJSObjectRef(attendee);
+
+    JSValueRef nameData = JSObjectGetProperty(m_context, arg, nameStr.get(), NULL);
+    JSValueRef uriData = JSObjectGetProperty(m_context, arg, uriStr.get(), NULL);
+    JSValueRef roleData = JSObjectGetProperty(m_context, arg, roleStr.get(), NULL);
+    JSValueRef statusData = JSObjectGetProperty(m_context, arg, statusStr.get(), NULL);
+    JSValueRef RSVPData = JSObjectGetProperty(m_context, arg, RSVPStr.get(), NULL);
+    JSValueRef typeData = JSObjectGetProperty(m_context, arg, typeStr.get(), NULL);
+    JSValueRef groupData = JSObjectGetProperty(m_context, arg, groupStr.get(), NULL);
+    JSValueRef delegatorURIData = JSObjectGetProperty(m_context, arg, delegatorURIStr.get(), NULL);
+    JSValueRef delegateURIData = JSObjectGetProperty(m_context, arg, delegateURIStr.get(), NULL);
+    JSValueRef contactRefData = JSObjectGetProperty(m_context, arg, contactRefStr.get(), NULL);
+
+    if (!JSValueIsUndefined(m_context, nameData)) {
+        result->setName(toString(nameData));
+    }
+    if (!JSValueIsUndefined(m_context, uriData)) {
+        result->setURI(toString(uriData));
+    }
+    if (!JSValueIsUndefined(m_context, roleData)) {
+        result->setRole(toEventAttendeeRole(toString(roleData)));
+    }
+    if (!JSValueIsUndefined(m_context, statusData)) {
+        result->setStatus(toEventAttendeeStatus(toString(statusData)));
+    }
+    if (!JSValueIsUndefined(m_context, RSVPData)) {
+        result->setRSVP(toBool(RSVPData));
+    }
+    if (!JSValueIsUndefined(m_context, typeData)) {
+        result->setType(toEventAttendeeType(toString(typeData)));
+    }
+    if (!JSValueIsUndefined(m_context, groupData)) {
+        result->setGroup(toString(groupData));
+    }
+    if (!JSValueIsUndefined(m_context, delegatorURIData)) {
+        result->setDelegatorURI(toString(delegatorURIData));
+    }
+    if (!JSValueIsUndefined(m_context, delegateURIData)) {
+        result->setDelegateURI(toString(delegateURIData));
+    }
+    if (!JSValueIsUndefined(m_context, contactRefData)) {
+        TizenApis::Tizen1_0::Contact::ContactConverter contactConverter(m_context);
+        result->setContactId(contactConverter.toContactRef(contactRefData)->getContactId());
+        result->setAddressBookId(contactConverter.toContactRef(contactRefData)->getAddressBookId());
+    }
+
+    return result;
+}
+
+EventAttendeeListPtr CalendarConverter::toVectorOfAttendeesFromDictionary(JSValueRef attendees)
+{
+    EventAttendeeListPtr result(new EventAttendeeList());
+
+    std::vector<EventAttendeePtr> resultVector;
+    JSObjectRef objArg = toJSObjectRef(attendees);
+    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);
+        resultVector.push_back(toAttendee(element));
+    }
+
+    *result = resultVector;
+    return result;
+}
+
+EventAttendeeListPtr CalendarConverter::toVectorOfAttendeesFromReference(JSValueRef attendees)
+{
+    EventAttendeeListPtr result(new EventAttendeeList());
+
+    std::vector<EventAttendeePtr> resultVector;
+    JSObjectRef objArg = toJSObjectRef(attendees);
+    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);
+        resultVector.push_back(JSCalendarAttendee::getPrivateObject(JSValueToObject(m_context, element, NULL)));
+    }
+
+    *result = resultVector;
+    return result;
+}
+
+EventAlarmPtr CalendarConverter::toEventAlarm(JSValueRef alarm)
+{
+    EventAlarmPtr result(new EventAlarm());
+    const ScopedJSStringRef absoluteDateStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ALARM_ABSOLUTE_DATE));
+    const ScopedJSStringRef beforeStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ALARM_BEFORE));
+    const ScopedJSStringRef methodStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ALARM_METHOD));
+    const ScopedJSStringRef descriptionStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ALARM_DESCRIPTION));
+
+    JSObjectRef arg = toJSObjectRef(alarm);
+
+    JSValueRef absoluteDateData = JSObjectGetProperty(m_context, arg, absoluteDateStr.get(), NULL);
+    JSValueRef beforeData = JSObjectGetProperty(m_context, arg, beforeStr.get(), NULL);
+    JSValueRef methodData = JSObjectGetProperty(m_context, arg, methodStr.get(), NULL);
+    JSValueRef descriptionData = JSObjectGetProperty(m_context, arg, descriptionStr.get(), NULL);
+
+    if (!JSValueIsUndefined(m_context, absoluteDateData)) {
+        TimeUtilConverter timeConverter(m_context);
+        result->setAbsoluteDate((long long int) (timeConverter.getTimeInMilliseconds(absoluteDateData)/1000));
+    }
+    if (!JSValueIsUndefined(m_context, beforeData)) {
+        TimeUtilConverter timeConverter(m_context);
+        result->setDuration(timeConverter.getDurationPropertis(beforeData));
+    }
+    if (!JSValueIsUndefined(m_context, methodData)) {
+        std::string method = toString(methodData);
+        std::vector<EventAlarm::EventAlarmType> convertedMethods;
+        convertedMethods.push_back(toEventAlarmType(method));
+        result->setMethods(convertedMethods);
+    }
+    if (!JSValueIsUndefined(m_context, descriptionData)) {
+        result->setDescription(toString(descriptionData));
+    }
+
+    return result;
+}
+
+EventAlarmListPtr CalendarConverter::toVectorOfEventAlarmsFromDictionary(JSValueRef alarms)
+{
+    EventAlarmListPtr result(new EventAlarmList());
+
+    std::vector<EventAlarmPtr> resultVector;
+    JSObjectRef objArg = toJSObjectRef(alarms);
+    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);
+        resultVector.push_back(toEventAlarm(element));
+    }
+
+    *result = resultVector;
+    return result;
+}
+
+EventAlarmListPtr CalendarConverter::toVectorOfEventAlarmsFromReference(JSValueRef alarms)
+{
+    EventAlarmListPtr result(new EventAlarmList());
+
+    std::vector<EventAlarmPtr> resultVector;
+    JSObjectRef objArg = toJSObjectRef(alarms);
+    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);
+        resultVector.push_back(JSCalendarAlarm::getPrivateObject(JSValueToObject(m_context, element, NULL)));
+    }
+
+    *result = resultVector;
+    return result;
+}
+
+CalendarEventPtr CalendarConverter::toEvent(const JSValueRef event)
+{
+    CalendarEventPtr result(new CalendarEvent());
+    const ScopedJSStringRef descriptionStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_DESCRIPTION));
+    const ScopedJSStringRef summaryStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_SUMMARY));
+    const ScopedJSStringRef startTimeStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_START_DATE));
+    const ScopedJSStringRef durationStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_DURATION));
+    const ScopedJSStringRef locationStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_LOCATION));
+    const ScopedJSStringRef categoriesStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_CATEGORIES));
+    const ScopedJSStringRef statusStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_STATUS));
+    const ScopedJSStringRef alarmsStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_ALARMS));
+    const ScopedJSStringRef isAllDayStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_IS_ALL_DAY));
+    const ScopedJSStringRef organizerStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_ORGANIZER));
+    const ScopedJSStringRef attendeesStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_ATTENDEES));
+    const ScopedJSStringRef geolocationStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_GEOLOCATION));
+    const ScopedJSStringRef visibilityStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_VISIBILITY));
+    const ScopedJSStringRef availabilityStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_EVENT_AVAILABILITY));
+    const ScopedJSStringRef recurrenceRuleStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_EVENT_RECURRENCE_RULE));
+    const ScopedJSStringRef priorityStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_ITEM_PRIORITY));
+    const ScopedJSStringRef endDateStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_EVENT_END_DATE));
+    const ScopedJSStringRef dueDateStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_TASK_DUE_DATE));
+    const ScopedJSStringRef completedDateStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_TASK_COMPLETED_DATE));
+    const ScopedJSStringRef progressStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_TASK_PROGRESS));
+
+    JSObjectRef arg = toJSObjectRef(event);
+
+    JSValueRef descriptionData = JSObjectGetProperty(m_context, arg, descriptionStr.get(), NULL);
+    JSValueRef summaryData = JSObjectGetProperty(m_context, arg, summaryStr.get(), NULL);
+    JSValueRef startTimeData = JSObjectGetProperty(m_context, arg, startTimeStr.get(), NULL);
+    JSValueRef durationData = JSObjectGetProperty(m_context, arg, durationStr.get(), NULL);
+    JSValueRef locationData = JSObjectGetProperty(m_context, arg, locationStr.get(), NULL);
+    JSValueRef categoriesData = JSObjectGetProperty(m_context, arg, categoriesStr.get(), NULL);
+    JSValueRef statusData = JSObjectGetProperty(m_context, arg, statusStr.get(), NULL);
+    JSValueRef alarmsData = JSObjectGetProperty(m_context, arg, alarmsStr.get(), NULL);
+    JSValueRef isAllDayData = JSObjectGetProperty(m_context, arg, isAllDayStr.get(), NULL);
+    JSValueRef organizerData = JSObjectGetProperty(m_context, arg, organizerStr.get(), NULL);
+    JSValueRef attendeesData = JSObjectGetProperty(m_context, arg, attendeesStr.get(), NULL);
+    JSValueRef geolocationData = JSObjectGetProperty(m_context, arg, geolocationStr.get(), NULL);
+    JSValueRef visibilityData = JSObjectGetProperty(m_context, arg, visibilityStr.get(), NULL);
+    JSValueRef availabilityData = JSObjectGetProperty(m_context, arg, availabilityStr.get(), NULL);
+    JSValueRef recurrenceRuleData = JSObjectGetProperty(m_context, arg, recurrenceRuleStr.get(), NULL);
+    JSValueRef priorityData = JSObjectGetProperty(m_context, arg, priorityStr.get(), NULL);
+    JSValueRef endDateData = JSObjectGetProperty(m_context, arg, endDateStr.get(), NULL);
+    JSValueRef dueDateData = JSObjectGetProperty(m_context, arg, dueDateStr.get(), NULL);
+    JSValueRef completedDateData = JSObjectGetProperty(m_context, arg, completedDateStr.get(), NULL);
+    JSValueRef progressData = JSObjectGetProperty(m_context, arg, progressStr.get(), NULL);
+
+    TimeUtilConverter timeUtilConverter(m_context);
+
+    if (!JSValueIsUndefined(m_context, descriptionData)) {
+        result->setDescription(toString(descriptionData));
+    }
+
+    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));
+        }
+    }
+    
+    if (!JSValueIsUndefined(m_context, durationData)) {
+        long length = timeUtilConverter.getDurationLength(durationData);
+        int unit = timeUtilConverter.getDurationUnit(durationData);
+        LogInfo("duration length: "<<length<<", unit "<<unit);
+        if (length < 0) {
+            ThrowMsg(ConversionException, "Wrong duration length.");
+        }
+        if( SECONDS_UNIT==unit ) {
+            result->setEndTime(result->getStartTime() + length);
+        } else if ( MINUTES_UNIT==unit ) {
+            result->setEndTime(result->getStartTime() + length*60);
+        } else if ( HOURS_UNIT==unit ) {
+            result->setEndTime(result->getStartTime() + length*60*60);
+        } else if ( DAYS_UNIT==unit ) {
+            result->setEndTime(result->getStartTime() + length*24*60*60);
+        } else {
+            ThrowMsg(ConversionException, "Wrong duration unit.");
+        }
+    }
+    if (!JSValueIsUndefined(m_context, locationData)) {
+        result->setLocation(toString(locationData));
+    }
+    if (!JSValueIsUndefined(m_context, categoriesData)) {
+        StringArrayPtr categories(new StringArray());
+        *categories = toVectorOfStrings(categoriesData);
+        result->setCategories(categories);
+    }
+    
+    if (!JSValueIsUndefined(m_context, statusData)) {
+        result->setStatus(toEventStatus(toString(statusData)));
+    } else {
+        result->setStatus(CalendarEvent::CONFIRMED_STATUS);
+    }
+    if (!JSValueIsUndefined(m_context, alarmsData)) {
+        EventAlarmListPtr alarms = toVectorOfEventAlarmsFromReference(alarmsData);
+        result->setAlarms(alarms);
+    }
+    if (!JSValueIsUndefined(m_context, isAllDayData)) {
+        result->setIsAllDay(toBool(isAllDayData));
+    }
+    if (!JSValueIsUndefined(m_context, organizerData)) {
+        result->setOrganizer(toString(organizerData));
+    }
+    if (!JSValueIsUndefined(m_context, attendeesData)) {
+        EventAttendeeListPtr attendees = toVectorOfAttendeesFromReference(attendeesData);
+        result->setAttendees(attendees);
+    }
+    if (!JSValueIsUndefined(m_context, geolocationData)) {
+        TizenApis::Api::Tizen::SimpleCoordinatesPtr geoLocation =
+            TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::getSimpleCoordinates(m_context, geolocationData);
+        result->setLatitude(geoLocation->getLatitude());
+        result->setLongitude(geoLocation->getLongitude());
+    }
+    if (!JSValueIsUndefined(m_context, visibilityData)) {
+        result->setVisibility(toEventVisibility(toString(visibilityData)));
+    }
+    if (!JSValueIsUndefined(m_context, availabilityData)) {
+        result->setAvailability(toEventAvailability(toString(availabilityData)));
+    }
+    if (!JSValueIsUndefined(m_context, recurrenceRuleData)) {
+        result->setRecurrenceRule(JSCalendarRecurrenceRule::getPrivateObject(JSValueToObject(m_context, recurrenceRuleData, NULL)));
+    }
+    if (!JSValueIsUndefined(m_context, priorityData)) {
+        result->setPriority(toTaskPriority(toString(priorityData)));
+    }
+    if (!JSValueIsUndefined(m_context, endDateData)) {
+        if( result->getTimeZone().empty() ) {
+            result->setTimeZone(timeUtilConverter.getPropertiesInTZDate(endDateData).timezone);
+        }
+        result->setEndTime((long long int) (timeUtilConverter.getTimeInMilliseconds(endDateData)/1000));
+    }
+    if (!JSValueIsUndefined(m_context, dueDateData)) {
+        if( result->getTimeZone().empty() ) {
+            result->setTimeZone(timeUtilConverter.getPropertiesInTZDate(dueDateData).timezone);
+        }
+        result->setEndTime((long long int) (timeUtilConverter.getTimeInMilliseconds(dueDateData)/1000));
+    }
+    if (!JSValueIsUndefined(m_context, completedDateData)) {
+        if( result->getTimeZone().empty() ) {
+            result->setTimeZone(timeUtilConverter.getPropertiesInTZDate(completedDateData).timezone);
+        }
+        result->setCompletedDate((long long int) (timeUtilConverter.getTimeInMilliseconds(completedDateData)/1000));
+    }
+    if (!JSValueIsUndefined(m_context, progressData)) {
+        result->setProgress(toInt(progressData));
+    }
+    LogDebug("timezone: "<<result->getTimeZone());
+
+    return result;
+}
+
+CalendarEventListPtr CalendarConverter::toVectorOfEvents(JSValueRef events)
+{
+    CalendarEventListPtr result(new CalendarEventList());
+
+    std::vector<CalendarEventPtr> resultVector;
+    JSObjectRef objArg = toJSObjectRef(events);
+    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);
+        JSObjectRef arg = JSValueToObject(m_context, element, NULL);
+        resultVector.push_back(JSCalendarEvent::getPrivateObject(arg));
+    }
+
+    *result = resultVector;
+    return result;
+}
+
+CalendarEventListPtr CalendarConverter::toVectorOfEventsFromProperty(JSValueRef events)
+{
+    CalendarEventListPtr result(new CalendarEventList());
+
+    std::vector<CalendarEventPtr> resultVector;
+    JSObjectRef objArg = toJSObjectRef(events);
+    LogDebug("array length "<<JSGetArrayLength(m_context, objArg));
+    for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); i++) {
+        resultVector.push_back(toEvent(JSGetArrayElement(m_context, objArg, i)));
+    }
+
+    *result = resultVector;
+    return result;
+}
+
+EventIdPtr CalendarConverter::toEventId(JSValueRef eventId)
+{
+    EventIdPtr result(new EventId());
+    const ScopedJSStringRef uidStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_EVENT_ID_UID));
+    const ScopedJSStringRef recurrenceIdStr(JSStringCreateWithUTF8CString(TIZEN_CALENDAR_EVENT_ID_RECURRENCEID));
+
+    JSObjectRef arg = toJSObjectRef(eventId);
+
+    JSValueRef uidData = JSObjectGetProperty(m_context, arg, uidStr.get(), NULL);
+    JSValueRef recurrenceIdData = JSObjectGetProperty(m_context, arg, recurrenceIdStr.get(), NULL);
+
+    if (!JSValueIsUndefined(m_context, uidData)) {
+        result->setUId(toString(uidData));
+    }
+    if (!JSValueIsUndefined(m_context, recurrenceIdData)) {
+        result->setRecurrenceId(toString(recurrenceIdData));
+   }
+
+    return result;
+}
+
+EventIdListPtr CalendarConverter::toVectorOfEventIds(JSValueRef eventIds)
+{
+    EventIdListPtr result(new EventIdList());
+
+    std::vector<EventIdPtr> resultVector;
+    JSObjectRef objArg = toJSObjectRef(eventIds);
+    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);
+        EventIdPtr idPtr = JSCalendarEventId::getPrivateObject(JSValueToObject(m_context, element, NULL));
+        idPtr->setCalendarType(CalendarEvent::EVENT_TYPE);
+        resultVector.push_back(idPtr);
+    }
+
+    *result = resultVector;
+    return result;
+}
+
+std::vector<long long int> CalendarConverter::toVectorOfTimeFromTZDate(JSValueRef dates)
+{
+    std::vector<long long int> result;
+    TimeUtilConverter converter(m_context);
+
+    JSObjectRef objArg = toJSObjectRef(dates);
+    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);
+        result.push_back((long long int) (converter.getTimeInMilliseconds(element)/1000));
+    }
+
+    return result;
+}
+
+std::string CalendarConverter::toTizenValue(Api::Calendar::CalendarEvent::TaskPriority abstractValue) const
+{
+    switch (abstractValue) {
+    case CalendarEvent::HIGH_PRIORITY:
+        return TIZEN_CALENDAR_PROPERTY_HIGH_PRIORITY;
+    case CalendarEvent::MEDIUM_PRIORITY:
+        return TIZEN_CALENDAR_PROPERTY_MEDIUM_PRIORITY;
+    case CalendarEvent::LOW_PRIORITY:
+        return TIZEN_CALENDAR_PROPERTY_LOW_PRIORITY;
+    default:
+        break;
+    }
+    return TIZEN_CALENDAR_PROPERTY_LOW_PRIORITY;
+}
+
+CalendarEvent::TaskPriority CalendarConverter::toTaskPriority(std::string priority) const
+{
+    if (!priority.compare(TIZEN_CALENDAR_PROPERTY_HIGH_PRIORITY))
+        return CalendarEvent::HIGH_PRIORITY;
+    else if (!priority.compare(TIZEN_CALENDAR_PROPERTY_MEDIUM_PRIORITY))
+        return CalendarEvent::MEDIUM_PRIORITY;
+    else if (!priority.compare(TIZEN_CALENDAR_PROPERTY_LOW_PRIORITY))
+        return CalendarEvent::LOW_PRIORITY;
+    else
+        ThrowMsg(ConversionException, "Invalid priority type.");
+
+    return CalendarEvent::UNDEFINED_PRIORITY;
+}
+
+CalendarEvent::CalendarType CalendarConverter::toCalendarType(std::string type) const
+{
+    if (!type.compare(TIZEN_CALENDAR_PROPERTY_TYPE_EVENT))
+        return CalendarEvent::EVENT_TYPE;
+    else if (!type.compare(TIZEN_CALENDAR_PROPERTY_TYPE_TASK))
+        return CalendarEvent::TASK_TYPE;
+    else
+        ThrowMsg(ConversionException, "Invalid calendar type.");
+
+    return CalendarEvent::UNDEFINED_TYPE;
+}
+
+CalendarEvent::VObjectFormat CalendarConverter::toVObjectFormat(std::string format) const
+{
+    if (!format.compare(TIZEN_CALENDAR_PROPERTY_VCALENDAR_20_FORMAT))
+        return CalendarEvent::ICALENDAR_20;
+    else if (!format.compare(TIZEN_CALENDAR_PROPERTY_VCALENDAR_10_FORMAT))
+        return CalendarEvent::VCALENDAR_10;
+    else
+        ThrowMsg(ConversionException, "Invalid format type.");
+
+    return CalendarEvent::UNDEFINED_FORMAT;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Calendar/CalendarConverter.h b/src/standards/Tizen/Calendar/CalendarConverter.h
new file mode 100755 (executable)
index 0000000..4c10b54
--- /dev/null
@@ -0,0 +1,113 @@
+//
+// 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 _JS_TIZEN_CALENDAR_CONVERTER_H_
+#define _JS_TIZEN_CALENDAR_CONVERTER_H_
+
+#include <vector>
+#include <string>
+#include <API/Calendar/ICalendar.h>
+#include <API/Calendar/EventAttendee.h>
+#include <API/Calendar/EventAlarm.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+class CalendarConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+  public:
+    using Converter::toJSValueRef;
+  public:
+    explicit CalendarConverter(JSContextRef context, TizenApis::Api::Calendar::CalendarEvent::CalendarType calendarType=TizenApis::Api::Calendar::CalendarEvent::EVENT_TYPE);
+    virtual ~CalendarConverter();
+
+    TizenApis::Api::Calendar::CalendarEventPtr toEvent(const JSValueRef event);
+    TizenApis::Api::Calendar::CalendarEventListPtr toVectorOfEvents(JSValueRef events);
+    TizenApis::Api::Calendar::CalendarEventListPtr toVectorOfEventsFromProperty(JSValueRef events);
+    TizenApis::Api::Calendar::StringArrayPtr toCategories(JSValueRef categories);
+    TizenApis::Api::Calendar::EventAttendeePtr toAttendee(JSValueRef attendee);
+    TizenApis::Api::Calendar::EventAttendeeListPtr toVectorOfAttendeesFromDictionary(JSValueRef attendees);
+    TizenApis::Api::Calendar::EventAttendeeListPtr toVectorOfAttendeesFromReference(JSValueRef attendees);
+
+    TizenApis::Api::Calendar::EventAlarm::EventAlarmType toEventAlarmType(std::string tizenValue) const;
+    TizenApis::Api::Calendar::CalendarEvent::EventStatus toEventStatus(std::string tizenValue) const;
+    TizenApis::Api::Calendar::EventRecurrenceRule::EventRecurrence toRecurrenceFrequency(std::string tizenValue) const;
+    TizenApis::Api::Calendar::EventRecurrenceRulePtr toEventRecurrenceRule(JSValueRef rrule);
+
+    TizenApis::Api::Calendar::CalendarEvent::EventVisibility toEventVisibility(std::string tizenValue) const;
+    TizenApis::Api::Calendar::CalendarEvent::EventAvailability toEventAvailability(std::string tizenValue) const;
+    TizenApis::Api::Calendar::EventAttendee::EventAttendeeRole toEventAttendeeRole(std::string tizenValue) const;
+    TizenApis::Api::Calendar::EventAttendee::EventAttendeeStatus toEventAttendeeStatus(std::string tizenValue) const;
+    TizenApis::Api::Calendar::EventAttendee::EventAttendeeType toEventAttendeeType(std::string tizenValue) const;
+
+    std::string toTizenValue(TizenApis::Api::Calendar::EventAlarm::EventAlarmType abstractValue) const;
+    std::string toTizenValue(TizenApis::Api::Calendar::CalendarEvent::EventStatus abstractValue) const;
+    std::string toTizenValue(TizenApis::Api::Calendar::EventRecurrenceRule::EventRecurrence abstractValue) const;
+    std::string toTizenValue(TizenApis::Api::Calendar::CalendarEvent::EventVisibility abstractValue) const;
+    std::string toTizenValue(TizenApis::Api::Calendar::CalendarEvent::EventAvailability abstractValue) const;
+    std::string toTizenValue(TizenApis::Api::Calendar::EventAttendee::EventAttendeeRole abstractValue) const;
+    std::string toTizenValue(TizenApis::Api::Calendar::EventAttendee::EventAttendeeStatus abstractValue) const;
+    std::string toTizenValue(TizenApis::Api::Calendar::EventAttendee::EventAttendeeType abstractValue) const;
+    std::string toTizenValue(TizenApis::Api::Calendar::CalendarEvent::TaskPriority abstractValue) const;
+
+    JSValueRef toJSValueRefEvent(const TizenApis::Api::Calendar::CalendarEventPtr& arg);
+    JSValueRef toJSValueRefTask(const TizenApis::Api::Calendar::CalendarEventPtr& arg);
+    JSValueRef toJSValueRefEventArray(const TizenApis::Api::Calendar::CalendarEventListPtr &arg);
+    JSValueRef toJSValueRefTaskArray(const TizenApis::Api::Calendar::CalendarEventListPtr &arg);
+    JSValueRef toJSValueRefCalendar(const TizenApis::Api::Calendar::ICalendarPtr& arg);
+    JSValueRef toJSValueRef(const std::vector<TizenApis::Api::Calendar::ICalendarPtr> &arg);
+    JSValueRef toJSValueRef(const TizenApis::Api::Calendar::StringArrayPtr &arg);
+    JSValueRef toJSValueRefNumberArray(const TizenApis::Api::Calendar::NumberArrayPtr &arg);
+    JSValueRef toJSValueRefTZDateArray(const TizenApis::Api::Calendar::NumberArrayPtr &arg);
+    TizenApis::Api::Calendar::StringArrayPtr toStringArray(const JSValueRef &jsValue);
+    TizenApis::Api::Calendar::NumberArrayPtr toNumberArray(const JSValueRef &jsValue);
+    TizenApis::Api::Calendar::NumberArrayPtr toTZDateArray(const JSValueRef &jsValue);
+
+    TizenApis::Api::Calendar::EventAlarmPtr toEventAlarm(JSValueRef alarm);
+    TizenApis::Api::Calendar::EventAlarmListPtr toVectorOfEventAlarmsFromDictionary(JSValueRef alarms);
+    TizenApis::Api::Calendar::EventAlarmListPtr toVectorOfEventAlarmsFromReference(JSValueRef alarms);
+    TizenApis::Api::Calendar::EventIdPtr toEventId(JSValueRef eventId);
+    TizenApis::Api::Calendar::EventIdListPtr toVectorOfEventIds(JSValueRef eventIds);
+    std::vector<long long int> toVectorOfTimeFromTZDate(JSValueRef dates);
+    TizenApis::Api::Calendar::CalendarEvent::TaskPriority toTaskPriority(std::string priority) const;
+       TizenApis::Api::Calendar::CalendarEvent::CalendarType toCalendarType(std::string type) const;
+       TizenApis::Api::Calendar::CalendarEvent::VObjectFormat toVObjectFormat(std::string type) const;
+
+    /**
+     * @throw InvalidArgumentException If not a callback nor JS null.
+     */
+    JSValueRef toFunctionOrNull(const JSValueRef& arg);
+
+    /**
+     * @throw ConversionException If JS null.
+     * @throw InvalidArgumentException If not a callback nor JS null.
+     */
+    JSValueRef toFunction(const JSValueRef& arg);
+
+  private:
+    TizenApis::Api::Calendar::CalendarEvent::CalendarType m_calendarType;
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_CALENDAR_CONVERTER_H_ */
diff --git a/src/standards/Tizen/Calendar/CalendarListenerManager.cpp b/src/standards/Tizen/Calendar/CalendarListenerManager.cpp
new file mode 100755 (executable)
index 0000000..46e05fa
--- /dev/null
@@ -0,0 +1,23 @@
+//
+// 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 "CalendarListenerManager.h"
+#include <dpl/singleton_impl.h>
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::Calendar::CalendarListenerManager)
+
diff --git a/src/standards/Tizen/Calendar/CalendarListenerManager.h b/src/standards/Tizen/Calendar/CalendarListenerManager.h
new file mode 100755 (executable)
index 0000000..a6463c1
--- /dev/null
@@ -0,0 +1,91 @@
+//
+// 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_CALENDAR_LISTENER_MANAGER_H_
+#define _TIZEN_CALENDAR_LISTENER_MANAGER_H_
+
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Tizen/Common/IListenerManager.h>
+#include "CalendarResponseDispatcher.h"
+#include "JSCalendar.h"
+#include <API/Calendar/ICalendar.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+using namespace TizenApis::Api::Calendar;
+
+class CalendarListenerManager : public TizenApis::Commons::IListenerController
+{
+public:
+       CalendarListenerManager()
+       {
+       }
+
+       virtual ~CalendarListenerManager()
+       {
+       }
+};
+typedef DPL::Singleton<CalendarListenerManager> CalendarListenerManagerSingleton;
+
+class CalendarListenerCanceller : public TizenApis::Commons::IListenerItem
+{
+public:
+       CalendarListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
+               TizenApis::Commons::IListenerItem(context, object, watchId)
+       {
+       }
+
+       virtual ~CalendarListenerCanceller()
+       {
+       }
+
+       virtual void cancelListener()
+       {
+               CalendarPrivObject *privateObject = static_cast<CalendarPrivObject*>(JSObjectGetPrivate(m_object));
+               if (!privateObject) {
+                       LogWarning("Object is null.");
+                       return;
+               }
+
+               ICalendarPtr calendar = privateObject->getObject();
+
+               Try {
+                       LogDebug("Remove change listeners for calendar.");
+
+                       IEventClearWatchPtr dplEvent(new IEventClearWatch());
+                       dplEvent->setWatchId(m_watchId);
+                       dplEvent->setForSynchronousCall();
+                       calendar->clearWatch(dplEvent);
+               } Catch(WrtDeviceApis::Commons::Exception) {
+                       LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               }
+       }
+};
+typedef DPL::SharedPtr<CalendarListenerCanceller> CalendarListenerCancellerPtr;
+
+} // Calendar
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CALENDAR_LISTENER_MANAGER_H_
diff --git a/src/standards/Tizen/Calendar/CalendarMultiCallback.h b/src/standards/Tizen/Calendar/CalendarMultiCallback.h
new file mode 100755 (executable)
index 0000000..bf4ef46
--- /dev/null
@@ -0,0 +1,130 @@
+//
+// 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 _CALENDAR_MULTI_CALLBACK_H_
+#define _CALENDAR_MULTI_CALLBACK_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Calendar/CalendarEvent.h"
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+struct CalendarEventsSuccessCallback {
+    JSValueRef onSuccess;
+    JSValueRef onEventSuccess;
+    JSValueRef onEventError;
+
+    CalendarEventsSuccessCallback()
+        : onSuccess(NULL),
+        onEventSuccess(NULL),
+        onEventError(NULL)
+    { }
+};
+
+class CalendarEventsCallbackPrivateData : public WrtDeviceApis::Commons::IEventPrivateData 
+{
+public:
+    CalendarEventsCallbackPrivateData(const JSCallbackManagerPtr& onSuccess,
+        const JSCallbackManagerPtr& onEvent): m_onSuccess(onSuccess),
+        m_onEvent(onEvent)
+    {
+    }
+
+    JSCallbackManagerPtr getOnSuccess() const
+       {
+        return m_onSuccess;
+       }
+    JSCallbackManagerPtr getOnEvent() const
+       {
+        return m_onEvent;
+    }
+
+private:
+       JSCallbackManagerPtr m_onSuccess;
+       JSCallbackManagerPtr m_onEvent;
+};
+typedef DPL::SharedPtr<CalendarEventsCallbackPrivateData> CalendarEventsCallbackPrivateDataPtr;
+
+struct CalendarChangeCallback {
+    JSValueRef onAdded;
+    JSValueRef onUpdated;
+    JSValueRef onDeleted;
+    //JSValueRef onCalendarReset;
+
+    CalendarChangeCallback()
+        : onAdded(NULL),
+        onUpdated(NULL),
+        onDeleted(NULL)
+        //onCalendarReset(NULL)
+    { }
+};
+
+class CalendarChangeCallbackPrivateData : public WrtDeviceApis::Commons::IEventPrivateData
+{
+public:
+    CalendarChangeCallbackPrivateData(const JSCallbackManagerPtr& onAdded,
+        const JSCallbackManagerPtr& onUpdated, const JSCallbackManagerPtr& onDeleted):
+        //const JSCallbackManagerPtr& onCalendarReset):
+        m_onAdded(onAdded),
+        m_onUpdated(onUpdated),
+        m_onDeleted(onDeleted)
+        //m_onCalendarReset(onCalendarReset)
+    {
+    }
+
+    JSCallbackManagerPtr getOnAdded() const
+    {
+        return m_onAdded;
+    }
+    JSCallbackManagerPtr getOnUpdated() const
+    {
+        return m_onUpdated;
+    }
+    JSCallbackManagerPtr getOnDeleted() const
+    {
+        return m_onDeleted;
+    }
+
+       /*
+    JSCallbackManagerPtr getOnCalendarReset() const
+    {
+        return m_onCalendarReset;
+    }
+    */
+
+    private:
+    JSCallbackManagerPtr m_onAdded;
+    JSCallbackManagerPtr m_onUpdated;
+    JSCallbackManagerPtr m_onDeleted;
+    //JSCallbackManagerPtr m_onCalendarReset;
+};
+typedef DPL::SharedPtr<CalendarChangeCallbackPrivateData> CalendarChangeCallbackPrivateDataPtr;
+
+}
+}
+}
+
+#endif /* _CALENDAR_MULTI_CALLBACK_H_ */
diff --git a/src/standards/Tizen/Calendar/CalendarResponseDispatcher.cpp b/src/standards/Tizen/Calendar/CalendarResponseDispatcher.cpp
new file mode 100755 (executable)
index 0000000..a4e7f68
--- /dev/null
@@ -0,0 +1,339 @@
+//
+// 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 "CalendarResponseDispatcher.h"
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include "CalendarConverter.h"
+#include "JSCalendarEventId.h"
+#include "CalendarMultiCallback.h"
+#include <API/Calendar/EventId.h>
+
+#include "CalendarAsyncCallbackManager.h"
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+CalendarResponseDispatcher& CalendarResponseDispatcher::getInstance()
+{
+    static CalendarResponseDispatcher instance;
+    return instance;
+}
+
+CalendarResponseDispatcher::CalendarResponseDispatcher() :
+    GetCalendarsEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+    CalendarEventsEventAnswerReceiverAdds(ThreadEnum::NULL_THREAD),
+    CalendarEventsEventAnswerReceiverDeletes(ThreadEnum::NULL_THREAD),
+    CalendarEventsEventAnswerReceiverUpdates(ThreadEnum::NULL_THREAD),
+    CalendarEventsEventAnswerReceiverFind(ThreadEnum::NULL_THREAD),
+    CalendarEventsEventAnswerReceiverExpand(ThreadEnum::NULL_THREAD),
+    OnEventsChangedListener(ThreadEnum::NULL_THREAD)
+{
+}
+
+CalendarResponseDispatcher::~CalendarResponseDispatcher()
+{
+}
+
+void CalendarResponseDispatcher::OnAnswerReceived(const IEventGetCalendarsPtr &event)
+{
+    JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+    if (!cbm) {
+        LogError("no callback manager");
+        return;
+    }
+
+    Try
+    {  
+               CalendarAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+
+        if (event->getResult()) {
+            CalendarConverter converter(cbm->getContext());
+            const std::vector<ICalendarPtr> &results = event->getCalendars();
+            LogDebug("found calendars: " << results.size());
+            JSValueRef result = converter.toJSValueRef(results);
+            cbm->callOnSuccess(result);
+            return;
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("error during processing answer");
+    }
+    JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+            cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+    cbm->callOnError(errorObject);
+}
+
+void CalendarResponseDispatcher::OnAnswerReceived(const IEventAddEventsPtr &event)
+{
+    JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+    Try
+    {
+        if (!cbm) {
+            LogDebug("no callback manager");
+            return;
+        }
+
+               CalendarAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+
+        if (event->getResult()) {
+            LogDebug("result success");
+            CalendarConverter converter(cbm->getContext());
+
+            JSValueRef result;
+            if (CalendarEvent::TASK_TYPE==event->getCalendarType()) {
+                result = converter.toJSValueRefTaskArray(event->getEvents());
+            } else {
+                result = converter.toJSValueRefEventArray(event->getEvents());
+            }
+
+            cbm->callOnSuccess(result);
+            return;
+        }
+        LogDebug("result fail");
+    }
+    Catch(ConversionException)
+    {
+        LogError("cannot convert event");
+    }
+    JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+            cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+    cbm->callOnError(errorObject);
+}
+
+void CalendarResponseDispatcher::OnAnswerReceived(const IEventUpdateEventsPtr &event)
+{
+    JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+    if (!cbm) {
+        LogDebug("no callback manager");
+        return;
+    }
+
+       CalendarAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+
+    if (event->getResult()) {
+        cbm->callOnSuccess();
+    } else {
+        JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+        cbm->callOnError(errorObject);
+    }
+}
+
+void CalendarResponseDispatcher::OnAnswerReceived(const IEventDeleteEventsPtr &event)
+{
+    JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+    if (!cbm) {
+        LogDebug("no callback manager");
+        return;
+    }
+
+       CalendarAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+
+    if (event->getResult()) {
+        cbm->callOnSuccess();
+    } else {
+        JSValueRef errorObject;
+        if (event->getExceptionCode() ==
+            ExceptionCodes::NotFoundException) {
+            errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                    cbm->getContext(), TizenApis::Commons::JSTizenException::NOT_FOUND_ERROR);
+        } else {
+            errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                    cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+        }
+        cbm->callOnError(errorObject);
+    }
+}
+
+void CalendarResponseDispatcher::OnAnswerReceived(const IEventFindEventsPtr &event)
+{
+    JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+    if (!cbm) {
+        LogError("no callback manager");
+        return;
+    }
+    Try
+    {
+               CalendarAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+
+        if (event->getResult()) {
+            CalendarConverter converter(cbm->getContext());
+
+            JSValueRef result;
+            if (CalendarEvent::TASK_TYPE==event->getCalendarType()) {
+                result = converter.toJSValueRefTaskArray(event->getEvents());
+            } else {
+                result = converter.toJSValueRefEventArray(event->getEvents());
+            }
+            cbm->callOnSuccess(result);
+            return;
+        } else {
+            JSValueRef errorObject;
+            if (event->getExceptionCode() == ExceptionCodes::InvalidArgumentException) {
+                errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                        cbm->getContext(), TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
+            } else if (event->getExceptionCode() == ExceptionCodes::NotFoundException) {
+                errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                        cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+            } else {
+                errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                        cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+            }
+            cbm->callOnError(errorObject);
+            return;
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("error during processing answer");
+        JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+        cbm->callOnError(errorObject);
+    }
+}
+
+void CalendarResponseDispatcher::OnAnswerReceived(const IEventExpandEventRecurrencePtr &event)
+{
+    JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+    Try
+    {
+        if (!cbm) {
+            LogDebug("no callback manager");
+            return;
+        }
+
+               CalendarAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+
+        if (event->getResult()) {
+            CalendarConverter converter(cbm->getContext());
+            cbm->callOnSuccess(converter.toJSValueRefEventArray(event->getExpandedEventList()));
+            return;
+        } else {
+            JSValueRef errorObject;
+            if (event->getExceptionCode()==ExceptionCodes::InvalidArgumentException) {
+                errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                        cbm->getContext(), TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
+            } else if (event->getExceptionCode()==ExceptionCodes::NotFoundException) {
+                errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                        cbm->getContext(), TizenApis::Commons::JSTizenException::NOT_FOUND_ERROR);
+            } else {
+                errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                        cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+            }
+            cbm->callOnError(errorObject);
+            return;
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("error during processing answer");
+        JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+        cbm->callOnError(errorObject);
+    }
+}
+
+void CalendarResponseDispatcher::onAnswerReceived(const OnEventsChangedPtr& event)
+{
+    CalendarChangeCallbackPrivateDataPtr multiCallbacks =
+        DPL::StaticPointerCast<CalendarChangeCallbackPrivateData>(event->getPrivateData());
+    JSContextRef context = multiCallbacks->getOnAdded()->getContext();
+
+    CalendarConverter converter(context);
+    JSValueRef result;
+
+    Try
+    {
+        switch (event->getStatus())
+        {
+            case OnEventsChanged::ON_ADD:
+            {
+                if (CalendarEvent::TASK_TYPE==event->getCalendarType()) {
+                    result = converter.toJSValueRefTaskArray(event->getEventList());
+                } else {
+                    result = converter.toJSValueRefEventArray(event->getEventList());
+                }
+
+                multiCallbacks->getOnAdded()->callOnSuccess(result);
+                break;
+            }
+            case OnEventsChanged::ON_UPDATE:
+            {
+                if (CalendarEvent::TASK_TYPE==event->getCalendarType()) {
+                    result = converter.toJSValueRefTaskArray(event->getEventList());
+                } else {
+                    result = converter.toJSValueRefEventArray(event->getEventList());
+                }
+                multiCallbacks->getOnUpdated()->callOnSuccess(result);
+                break;
+            }
+            case OnEventsChanged::ON_DELETE:
+            {
+                CalendarEventListPtr eventList = event->getEventList();
+
+                JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+                if (NULL == jsResult) {
+                    ThrowMsg(ConversionException, "Could not create js array object");
+                }
+
+                for (std::size_t i = 0; i < eventList->size(); i++) {
+                    EventIdPtr eventId( new EventId() );
+                    eventId->setUId(eventList->at(i)->getUId());
+                    std::stringstream ss;
+                    std::time_t rid = eventList->at(i)->getRecurrenceId();
+                    ss<<rid;
+                    eventId->setRecurrenceId(ss.str());
+                    JSValueRef tmpVal =JSCalendarEventId::createJSCalendarEventId(context, eventId);
+                    if (!JSSetArrayElement(context, jsResult, i, tmpVal)) {
+                        ThrowMsg(ConversionException, "Could not create js array element");
+                    }
+                }
+
+                multiCallbacks->getOnDeleted()->callOnSuccess(jsResult);
+                break;
+            }
+            //case OnEventsChanged::ON_CALENDAR_RESET:
+            default:
+            {
+                LogDebug("Invalid status!");
+                break;
+            }
+        }
+    }
+    Catch(ConversionException)
+    {
+        LogError("cannot convert change event");
+    }
+    Catch(Exception)
+    {
+        LogError("exception occurred while handling change noti callback!");
+    }
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Calendar/CalendarResponseDispatcher.h b/src/standards/Tizen/Calendar/CalendarResponseDispatcher.h
new file mode 100755 (executable)
index 0000000..8710f49
--- /dev/null
@@ -0,0 +1,79 @@
+ //
+ // 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 _CALENDAR_RESPONSEDISPATCHER_H_
+#define _CALENDAR_RESPONSEDISPATCHER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <Commons/EventListener.h>
+#include <API/Calendar/IEventGetCalendars.h>
+#include <API/Calendar/IEventAddEvents.h>
+#include <API/Calendar/IEventDeleteEvents.h>
+#include <API/Calendar/IEventFindEvents.h>
+#include <API/Calendar/IEventUpdateEvents.h>
+#include <API/Calendar/IEventExpandEventRecurrence.h>
+#include <API/Calendar/OnEventsChanged.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Calendar::IEventGetCalendars>
+GetCalendarsEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Calendar::IEventAddEvents>
+CalendarEventsEventAnswerReceiverAdds;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Calendar::IEventDeleteEvents>
+CalendarEventsEventAnswerReceiverDeletes;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Calendar::IEventUpdateEvents>
+CalendarEventsEventAnswerReceiverUpdates;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Calendar::IEventFindEvents>
+CalendarEventsEventAnswerReceiverFind;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Calendar::IEventExpandEventRecurrence>
+CalendarEventsEventAnswerReceiverExpand;
+typedef WrtDeviceApis::Commons::EventListener<TizenApis::Api::Calendar::OnEventsChanged>
+OnEventsChangedListener;
+
+class CalendarResponseDispatcher :
+       public GetCalendarsEventAnswerReceiver,
+    public CalendarEventsEventAnswerReceiverAdds,
+    public CalendarEventsEventAnswerReceiverDeletes,
+    public CalendarEventsEventAnswerReceiverUpdates,
+    public CalendarEventsEventAnswerReceiverFind,
+    public CalendarEventsEventAnswerReceiverExpand,
+    public OnEventsChangedListener
+{
+  public:
+    static CalendarResponseDispatcher& getInstance();
+    void onAnswerReceived(const TizenApis::Api::Calendar::OnEventsChangedPtr& event);
+  private:
+    CalendarResponseDispatcher();
+    virtual ~CalendarResponseDispatcher();
+  protected:
+    void OnAnswerReceived(const TizenApis::Api::Calendar::IEventGetCalendarsPtr &event);
+    void OnAnswerReceived(const TizenApis::Api::Calendar::IEventAddEventsPtr &event);
+    void OnAnswerReceived(const TizenApis::Api::Calendar::IEventDeleteEventsPtr &event);
+    void OnAnswerReceived(const TizenApis::Api::Calendar::IEventUpdateEventsPtr &event);
+    void OnAnswerReceived(const TizenApis::Api::Calendar::IEventFindEventsPtr &event);
+    void OnAnswerReceived(const TizenApis::Api::Calendar::IEventExpandEventRecurrencePtr &event);
+};
+
+}
+}
+}
+
+#endif /* _CALENDAR_RESPONSEDISPATCHER_H_ */
diff --git a/src/standards/Tizen/Calendar/JSCalendar.cpp b/src/standards/Tizen/Calendar/JSCalendar.cpp
new file mode 100755 (executable)
index 0000000..1cc4eba
--- /dev/null
@@ -0,0 +1,1154 @@
+//
+// 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 <API/Calendar/ICalendar.h>
+#include <API/Calendar/EventId.h>
+#include <API/Calendar/CalendarFactory.h>
+
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Tizen/Tizen/FilterConverter.h>
+#include <Tizen/TimeUtil/TimeUtilConverter.h>
+
+#include "JSCalendarManager.h"
+#include "CalendarConverter.h"
+#include "JSCalendar.h"
+#include "JSCalendarEvent.h"
+#include "JSCalendarTask.h"
+#include "JSCalendarItemProperties.h"
+#include "JSCalendarEventId.h"
+#include "plugin_config.h"
+#include "CalendarResponseDispatcher.h"
+#include "CalendarMultiCallback.h"
+
+#include "CalendarAsyncCallbackManager.h"
+#include "CalendarListenerManager.h"
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+#define TIZEN_CALENDAR_ATTRIBUTENAME "Calendar"
+
+namespace TizenApis {
+namespace Tizen1_0 { 
+namespace Calendar {
+
+JSClassDefinition JSCalendar::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_CALENDAR_ATTRIBUTENAME,
+    NULL,
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
+};
+
+JSStaticValue JSCalendar::m_property[] = {
+    { TIZEN_CALENDAR_PROPERTY_NAME, JSCalendar::getPropertyName,
+      NULL, kJSPropertyAttributeReadOnly },
+    /*{ TIZEN_CALENDAR_PROPERTY_ACCOUNT_SERVICE_ID, JSCalendar::getPropertyAccountServiceId,
+      NULL, kJSPropertyAttributeReadOnly },*/
+    { TIZEN_CALENDAR_PROPERTY_ID, JSCalendar::getPropertyId,
+      NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSCalendar::m_function[] = {
+    { CALENDAR_FUNCTION_API_ADD, add, kJSPropertyAttributeNone },
+    { CALENDAR_FUNCTION_API_ADD_BATCH, addBatch, kJSPropertyAttributeNone },
+    { CALENDAR_FUNCTION_API_UPDATE, update, kJSPropertyAttributeNone },
+    { CALENDAR_FUNCTION_API_UPDATE_BATCH, updateBatch, kJSPropertyAttributeNone },
+    { CALENDAR_FUNCTION_API_REMOVE, remove, kJSPropertyAttributeNone },
+    { CALENDAR_FUNCTION_API_REMOVE_BATCH, removeBatch, kJSPropertyAttributeNone },
+    { CALENDAR_FUNCTION_API_FIND, find, kJSPropertyAttributeNone },
+    { CALENDAR_FUNCTION_API_ADD_CHANGE_LISTENER, addChangeListener, kJSPropertyAttributeNone },
+    { CALENDAR_FUNCTION_API_REMOVE_CHANGE_LISTENER, removeChangeListener, kJSPropertyAttributeNone },
+    { CALENDAR_FUNCTION_API_GET, get, kJSPropertyAttributeNone },
+
+    { 0, 0, 0 }
+};
+
+JSClassRef JSCalendar::m_jsClassRef = JSClassCreate(JSCalendar::getClassInfo());
+
+void JSCalendar::initialize(JSContextRef context, JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogDebug("Create calendar private object.");
+        ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
+        CalendarPrivObject *priv = new CalendarPrivObject(context, calendar);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    } else {
+        LogDebug("Private object already set.");
+    }
+}
+
+void JSCalendar::finalize(JSObjectRef object)
+{
+    CalendarPrivObject *priv = static_cast<CalendarPrivObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+const JSClassRef JSCalendar::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSCalendar::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSValueRef JSCalendar::add(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarPrivObject *privateObject =
+        static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_ADD);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
+
+        if (argumentCount<1) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        if (CalendarEvent::EVENT_TYPE==calendar->getType()) {
+            if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarEvent::getClassRef())) {
+                ThrowMsg(ConversionException, "Wrong first parameter type.");
+            }
+        } else if (CalendarEvent::TASK_TYPE==calendar->getType()) {
+            if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarTask::getClassRef())) {
+                ThrowMsg(ConversionException, "Wrong first parameter type.");
+            }
+        } else {
+            ThrowMsg(ConversionException, "Wrong calendar type.");
+        }
+
+        JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
+        CalendarEventPtr event = JSCalendarEvent::getPrivateObject(arg);
+        if (!event) {
+            ThrowMsg(ConversionException, "Parameter conversion failed.");
+        }
+
+        IEventAddEventPtr dplEvent(new IEventAddEvent());
+        dplEvent->setEvent(event);
+        dplEvent->setForSynchronousCall();
+        calendar->addEvent(dplEvent);
+
+        if (dplEvent->getResult()) {
+            LogDebug("Add result successful.");
+            return JSValueMakeUndefined(context);
+        } else {
+            ThrowMsg(UnknownException, "Adding failed by unknown reason.");
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendar::addBatch(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarPrivObject *privateObject =
+        static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_ADD_BATCH);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        ICalendarPtr calendar = getCalendar(context, thisObject, NULL);
+
+        JSContextRef globalContext = privateObject->getContext();
+        CalendarConverter converter(context);
+
+        if (argumentCount<1) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        CalendarEventListPtr events;
+        if (!JSIsArrayValue(context, arguments[0])) {
+            ThrowMsg(ConversionException, "Wrong first parameter type.");
+        }
+        events = converter.toVectorOfEvents(arguments[0]);
+        if (!events) {
+            ThrowMsg(ConversionException, "First parameter conversion failed.");
+        }
+
+        JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
+        if (argumentCount>=2) {
+            cbm->setOnSuccess(converter.toFunctionOrNull(arguments[1]));
+        }
+        if (argumentCount>=3) {
+            cbm->setOnError(converter.toFunctionOrNull(arguments[2]));
+        }
+
+               cbm->setObject(thisObject);
+
+        LogDebug("Proceed the event to the platform.");
+
+        IEventAddEventsPtr dplEvent(new IEventAddEvents());
+        dplEvent->setCalendarType(calendar->getType());
+        dplEvent->setEvents(events);
+        dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
+        dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
+        calendar->addEvents(dplEvent);
+
+               CalendarAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+        return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendar::update(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarPrivObject *privateObject =
+        static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_UPDATE);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        ICalendarPtr calendar = getCalendar(context, thisObject, exception);
+
+        if (argumentCount<1) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        if (argumentCount>=1) {
+            if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarEvent::getClassRef()) &&
+            !JSValueIsObjectOfClass(context, arguments[0], JSCalendarTask::getClassRef())) {
+                ThrowMsg(ConversionException, "Wrong first parameter type.");
+            }
+        } else {
+            ThrowMsg(ConversionException, "Wrong first parameter type.");
+        }
+
+        CalendarConverter converter(context);
+
+        JSObjectRef arg = JSValueToObject(context, arguments[0], exception);
+        CalendarEventPtr item = JSCalendarEvent::getPrivateObject(arg);
+        if (!item) {
+            ThrowMsg(ConversionException, "Parameter conversion failed.");
+        }
+
+        bool updateAllInstances = true; // Set the default value.
+        if (argumentCount>=2) {
+            updateAllInstances = converter.toBool(arguments[1]);
+        }
+
+        IEventUpdateEventPtr dplEvent(new IEventUpdateEvent());
+        dplEvent->setEvent(item);
+        dplEvent->setUpdateAllInstances(updateAllInstances);
+        dplEvent->setForSynchronousCall();
+        calendar->updateEvent(dplEvent);
+
+        if (dplEvent->getResult()) {
+            return JSValueMakeUndefined(context);
+        } else {
+            ThrowMsg(UnknownException, "Updating failed by unknown reason.");
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendar::updateBatch(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarPrivObject *privateObject =
+        static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_UPDATE_BATCH);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        JSContextRef globalContext = privateObject->getContext();
+
+        ICalendarPtr calendar = getCalendar(context, thisObject, exception);
+
+        CalendarConverter converter(context);
+
+        if (argumentCount>=1) {
+            if (!JSIsArrayValue(context, arguments[0])) {
+                ThrowMsg(ConversionException, "Wrong first parameter type.");
+            }
+        } else {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+        CalendarEventListPtr events;
+        events = converter.toVectorOfEvents(arguments[0]);
+        if (!events) {
+            ThrowMsg(ConversionException, "Third parameter conversion failed.");
+        }
+
+        JSValueRef onSuccess = NULL;
+        if (argumentCount>=2) {
+            onSuccess = converter.toFunctionOrNull(arguments[1]);
+        }
+        JSValueRef onError = NULL;
+        if (argumentCount>=3) {
+            onError = converter.toFunctionOrNull(arguments[2]);
+        }
+        JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, onSuccess, onError);
+
+        bool updateAllInstances = true; // Set the default value.
+        if( argumentCount>=4 ) {
+            updateAllInstances = converter.toBool(arguments[3]);
+        }
+
+               cbm->setObject(thisObject);
+
+        LogDebug("Proceed the event to the platform.");
+
+        IEventUpdateEventsPtr dplEvent(new IEventUpdateEvents());
+        dplEvent->setEvents(events);
+        dplEvent->setUpdateAllInstances(updateAllInstances);
+        dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
+        dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
+        calendar->updateEvents(dplEvent);
+
+               CalendarAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+        return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendar::remove(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarPrivObject *privateObject =
+        static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_REMOVE);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        ICalendarPtr calendar = getCalendar(context, thisObject, exception);
+
+        EventIdPtr itemId;
+        CalendarConverter converter(context);
+
+        if (CalendarEvent::EVENT_TYPE==calendar->getType()) {
+            if (argumentCount<1) {
+                ThrowMsg(ConversionException, "Wrong parameter type.");
+            }
+
+            if (!JSValueIsObjectOfClass(context, arguments[0], JSCalendarEventId::getClassRef())) {
+                ThrowMsg(ConversionException, "Wrong parameter type.");
+            }
+            itemId = JSCalendarEventId::getPrivateObject(JSValueToObject(context, arguments[0], NULL));
+            if (!itemId) {
+                ThrowMsg(ConversionException, "Parameter conversion failed.");
+            }
+            itemId->setCalendarType(CalendarEvent::EVENT_TYPE);
+        } else if (CalendarEvent::TASK_TYPE==calendar->getType()) {
+            EventIdPtr result( new EventId() );
+            if (argumentCount>=1) {
+                result->setUId(converter.toString(arguments[0]));
+            }
+            itemId = result;
+            itemId->setCalendarType(CalendarEvent::TASK_TYPE);
+        } else {
+            ThrowMsg(ConversionException, "Parameter conversion failed.");
+        }
+
+        IEventDeleteEventPtr dplEvent(new IEventDeleteEvent());
+        dplEvent->setEventId(itemId);
+        dplEvent->setForSynchronousCall();
+        calendar->deleteEvent(dplEvent);
+
+        if (dplEvent->getResult()) {
+            LogInfo("Successfully deleted.");
+            return JSValueMakeUndefined(context);
+        } else {
+            if (dplEvent->getExceptionCode() == ExceptionCodes::NotFoundException) {
+                ThrowMsg(NotFoundException, "Item not found.");
+            } else {
+                ThrowMsg(UnknownException, "Removing failed by unnkown reason.");
+            }
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendar::removeBatch(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarPrivObject *privateObject =
+        static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_REMOVE_BATCH);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        ICalendarPtr calendar = getCalendar(context, thisObject, exception);
+        JSContextRef globalContext = privateObject->getContext();
+
+        CalendarConverter converter(context);
+
+        if (argumentCount>=1) {
+            if (!JSIsArrayValue(context, arguments[0])) {
+                ThrowMsg(ConversionException, "Wrong first parameter type.");
+            }
+        } else {
+                       ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        // Pick one array element to determine its type.
+        JSObjectRef objArg = converter.toJSObjectRef(arguments[0]);
+        JSValueRef element;
+        if (JSGetArrayLength(context, objArg)>0) {
+            element = JSGetArrayElement(context, objArg, 0);
+        } else {
+            ThrowMsg(ConversionException, "Wrong first parameter type.");
+        }
+
+        EventIdListPtr itemIds;
+        if (JSValueIsObjectOfClass(context, element, JSCalendarEventId::getClassRef())) {
+            itemIds = converter.toVectorOfEventIds(arguments[0]);
+            if (!itemIds) {
+                ThrowMsg(ConversionException, "Parameter conversion failed.");
+            }
+        } else if (JSValueIsString(context, element)) {
+            std::vector<std::string> idStrings = converter.toVectorOfStrings(arguments[0]);
+            EventIdListPtr result(new EventIdList());
+            for (unsigned int i=0; i<idStrings.size(); i++) {
+                EventIdPtr idPtr( new EventId() );
+                idPtr->setUId(idStrings[i]);
+                idPtr->setCalendarType(CalendarEvent::TASK_TYPE);
+                result->push_back(idPtr);
+            }
+            itemIds = result;
+        } else {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        JSValueRef onSuccess = NULL;
+        if (argumentCount>=2) {
+            onSuccess = converter.toFunctionOrNull(arguments[1]);
+        }
+        JSValueRef onError = NULL;
+        if (argumentCount>=3) {
+            onError = converter.toFunctionOrNull(arguments[2]);
+        }
+        JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, onSuccess, onError);
+
+               cbm->setObject(thisObject);
+
+        LogDebug("Proceed the event to the platform.");
+
+        IEventDeleteEventsPtr dplEvent(new IEventDeleteEvents());
+        dplEvent->setEventIds(itemIds);
+        dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
+        dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
+        calendar->deleteEvents(dplEvent);
+
+               CalendarAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+        return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendar::find(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarPrivObject *privateObject =
+        static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_FIND);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        ICalendarPtr calendar = getCalendar(context, thisObject, exception);
+
+        JSContextRef globalContext = privateObject->getContext();
+
+        Validator validator(context, exception);
+        CalendarConverter converter(context);
+        TizenApis::Tizen1_0::Tizen::FilterConverterFactory::ConverterType filterConverter = TizenApis::Tizen1_0::Tizen::FilterConverterFactory::getConverter(context);
+
+        if (argumentCount<1) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        JSValueRef onSuccess = NULL;
+        if (argumentCount>=1) {
+            onSuccess = converter.toFunction(arguments[0]);
+        }
+        JSValueRef onError = NULL;
+        if (argumentCount>=2) {
+            onError = converter.toFunctionOrNull(arguments[1]);
+        }
+        JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, onSuccess, onError);
+
+               cbm->setObject(thisObject);
+
+        LogDebug("Proceed the find event to the platform.");
+
+        IEventFindEventsPtr dplEvent(new IEventFindEvents());
+        dplEvent->setCalendarType(calendar->getType());
+        dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
+        dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
+
+        if (argumentCount>=3) {
+            if (JSValueIsObject(context, arguments[2])) {
+                dplEvent->setGenericFilter(filterConverter->toFilter(arguments[2]));
+            } else if (JSValueIsNull(context, arguments[2]) || JSValueIsUndefined(context, arguments[2])) {
+                               LogDebug("Use default filter.");
+            } else {
+                ThrowMsg(ConversionException, "Wrong third parameter type.");
+            }
+        }
+        if (argumentCount>=4) {
+            if (JSValueIsObject(context, arguments[3])) {
+                // Though the sortMode is a single type, we save it in an array internally.
+                TizenApis::Api::Tizen::SortModeArrayPtr sortModes(new TizenApis::Api::Tizen::SortModeArray());
+                sortModes->push_back(filterConverter->toSortMode(arguments[3]));
+                dplEvent->setSortModes(sortModes);
+                       } else if (JSValueIsNull(context, arguments[3]) || JSValueIsUndefined(context, arguments[3])) {
+                               LogDebug("Use default sort mode.");
+            } else {
+                ThrowMsg(ConversionException, "Wrong fourth parameter type.");
+            }
+        }
+
+        calendar->findEvents(dplEvent);
+
+               CalendarAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+               return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendar::get(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarPrivObject *privateObject =
+        static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_GET);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        ICalendarPtr calendar = getCalendar(context, thisObject, exception);
+        JSContextRef globalContext = privateObject->getContext();
+
+        EventIdPtr itemId;
+        CalendarConverter converter(context);
+        if (CalendarEvent::EVENT_TYPE==calendar->getType()) {
+            if (argumentCount<1) {
+                ThrowMsg(ConversionException, "Wrong parameter type.");
+            }
+
+            if (JSValueIsObjectOfClass(context, arguments[0], JSCalendarEventId::getClassRef())) {
+                itemId = JSCalendarEventId::getPrivateObject(JSValueToObject(context, arguments[0], NULL));
+                if (!itemId) {
+                    ThrowMsg(ConversionException, "Parameter conversion failed.");
+                }
+                itemId->setCalendarType(CalendarEvent::EVENT_TYPE);
+            } else {
+                ThrowMsg(ConversionException, "Wrong parameter type.");
+            }
+        } else if (CalendarEvent::TASK_TYPE==calendar->getType()) {
+            EventIdPtr result( new EventId() );
+            itemId = result;
+            if (argumentCount>=1) {
+                itemId->setUId(converter.toString(arguments[0]));
+            }
+            itemId->setCalendarType(CalendarEvent::TASK_TYPE);
+        } else {
+            ThrowMsg(ConversionException, "Wrong calendar type.");
+        }
+
+        IEventGetPtr dplEvent(new IEventGet());
+        dplEvent->setForSynchronousCall();
+        dplEvent->setItemId(itemId);
+        calendar->get(dplEvent);
+
+        // Process the found item.
+        if (dplEvent->getResult()) {
+                       if (CalendarEvent::EVENT_TYPE==calendar->getType()) {
+                // Use global context for the expandRecurrence api in event.
+                   return JSCalendarEvent::createJSCalendarEvent(globalContext, dplEvent->getItem());
+                       } else if (CalendarEvent::TASK_TYPE==calendar->getType()) {
+                   return JSCalendarTask::createJSCalendarTask(context, dplEvent->getItem());
+                       } else {
+                   ThrowMsg(UnknownException, "Wrong calendar type.");
+                       }
+        } else {
+            if(ExceptionCodes::NotFoundException==dplEvent->getExceptionCode()) {
+                ThrowMsg(NotFoundException, "Item not found.");
+            } else {
+                ThrowMsg(UnknownException, "Getting an item failed by unknown reason.");
+            }
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendar::addChangeListener(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarPrivObject *privateObject =
+        static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_ADD_CHANGE_LISTENER);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        ICalendarPtr calendar = getCalendar(context, thisObject, exception);
+        JSContextRef globalContext = privateObject->getContext();
+
+        CalendarConverter converter(context);
+
+        if (argumentCount>=1) {
+            if (!JSValueIsObject(context, arguments[0])) {
+                ThrowMsg(ConversionException, "Wrong first parameter type.");
+            }
+        } else {
+            ThrowMsg(ConversionException, "Wrong first parameter type.");
+        }
+
+        JSObjectRef objectCallbacks = converter.toJSObjectRef(arguments[0]);
+        CalendarChangeCallback result;
+        Validator validator(context);
+
+        result.onAdded = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onitemsadded");
+        if (validator.isNullOrUndefined(result.onAdded)) {
+            result.onAdded = NULL;
+        } else if(!validator.isCallback(result.onAdded)) {
+            ThrowMsg(ConversionException, "Wrong first parameter type.");
+        }
+
+        result.onUpdated = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onitemsupdated");
+        if (validator.isNullOrUndefined(result.onUpdated)) {
+            result.onUpdated = NULL;
+        } else if(!validator.isCallback(result.onUpdated)) {
+            ThrowMsg(ConversionException, "Wrong first parameter type.");
+        }
+
+        result.onDeleted = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onitemsremoved");
+        if (validator.isNullOrUndefined(result.onDeleted)) {
+            result.onDeleted = NULL;
+        } else if(!validator.isCallback(result.onDeleted)) {
+            ThrowMsg(ConversionException, "Wrong first parameter type.");
+        }
+
+        if (!result.onAdded && !result.onUpdated && !result.onDeleted) {
+            ThrowMsg(ConversionException, "Wrong second parameter type.");
+        }
+
+        JSCallbackManagerPtr onAddedCbm = JSCallbackManager::createObject(globalContext, result.onAdded, NULL);
+        JSCallbackManagerPtr onUpdatedCbm = JSCallbackManager::createObject(globalContext, result.onUpdated, NULL);
+        JSCallbackManagerPtr onDeletedCbm = JSCallbackManager::createObject(globalContext, result.onDeleted, NULL);
+
+        LogDebug("Make change emitter and process sync operation.");
+
+        CalendarChangeCallbackPrivateDataPtr privData(new CalendarChangeCallbackPrivateData(
+            onAddedCbm, onUpdatedCbm, onDeletedCbm));
+        OnEventsChangedEmitterPtr emitter(new OnEventsChangedEmitter());
+        emitter->setListener(&CalendarResponseDispatcher::getInstance());
+        emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(privData));
+
+        IEventWatchChangesPtr dplEvent(new IEventWatchChanges());
+        dplEvent->setEmitter(emitter);
+        dplEvent->setForSynchronousCall();
+        calendar->watchChanges(dplEvent);
+
+        long watchId;
+        if (dplEvent->getResult()) {
+            watchId = dplEvent->getWatchId();
+
+                       CalendarListenerCancellerPtr canceller = CalendarListenerCancellerPtr(new CalendarListenerCanceller(globalContext, thisObject, watchId));
+                       TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+                       CalendarListenerManagerSingleton::Instance().registerListener(listenerItem, globalContext);
+
+            LogDebug("Returning the watchId "<<watchId);
+            return converter.toJSValueRefLong(watchId);
+        } else {
+            ThrowMsg(UnknownException, "Adding change listener failed by unknown reason.");
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendar::removeChangeListener(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarPrivObject *privateObject =
+        static_cast<CalendarPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_REMOVE_CHANGE_LISTENER);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        ICalendarPtr calendar = getCalendar(context, thisObject, exception);
+
+        JSContextRef globalContext = privateObject->getContext();
+
+        long watchId = -1;
+        CalendarConverter converter(context);
+        if (argumentCount>=1) {
+            watchId = converter.toLong(arguments[0]);
+        } else {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        LogDebug("Make sync operation with watchId: "<<watchId);
+
+        IEventClearWatchPtr dplEvent(new IEventClearWatch());
+        dplEvent->setWatchId(watchId);
+        dplEvent->setForSynchronousCall();
+        calendar->clearWatch(dplEvent);
+
+               CalendarListenerCancellerPtr canceller = CalendarListenerCancellerPtr(new CalendarListenerCanceller(globalContext, thisObject, watchId));
+               TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+               CalendarListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+
+        return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendar::getPropertyName(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ICalendarPtr calendar = getCalendar(context, object, exception);
+        Converter converter(context);
+        return converter.toJSValueRef(calendar->getName());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCalendar::getPropertyAccountServiceId(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ICalendarPtr calendar = getCalendar(context, object, exception);
+        Converter converter(context);
+        return converter.toJSValueRefLong(calendar->getAccountId());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCalendar::getPropertyId(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ICalendarPtr calendar = getCalendar(context, object, exception);
+        Converter converter(context);
+        return converter.toJSValueRef(calendar->getId());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+ICalendarPtr JSCalendar::getCalendar(JSContextRef ctx,
+        const JSObjectRef object,
+        JSValueRef* exception)
+{
+    CalendarPrivObject *priv =
+        static_cast<CalendarPrivObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        return priv->getObject();
+    }
+    ThrowMsg(NullPointerException, "Private object is NULL.");
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Calendar/JSCalendar.h b/src/standards/Tizen/Calendar/JSCalendar.h
new file mode 100755 (executable)
index 0000000..c67f0c3
--- /dev/null
@@ -0,0 +1,208 @@
+//
+// 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 _JS_TIZEN_CALENDAR_H_
+#define _JS_TIZEN_CALENDAR_H_
+
+#include <vector>
+#include <string>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Calendar/ICalendar.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+#define TIZEN_CALENDAR_PROPERTY_NAME "name"
+//#define TIZEN_CALENDAR_PROPERTY_ACCOUNT_SERVICE_ID "accountServiceId"
+#define TIZEN_CALENDAR_PROPERTY_ID "id"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Calendar::ICalendarPtr,
+                               WrtDeviceApis::CommonsJavaScript::NoOwnership> CalendarPrivObject;
+
+class JSCalendar
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+  private:
+    /**
+     * 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;
+
+    /**
+     * 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 getPropertyName(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static JSValueRef getPropertyAccountServiceId(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static JSValueRef getPropertyId(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    /**
+     * Add a calendar item.
+     */
+    static JSValueRef add(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Add calendar items.
+     */
+    static JSValueRef addBatch(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Update an item.
+     */
+    static JSValueRef update(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Update items.
+     */
+    static JSValueRef updateBatch(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Remove a calendar item.
+     */
+    static JSValueRef remove(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Remove calendar items.
+     */
+    static JSValueRef removeBatch(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Search for calendar items using tizen generic filter.
+     */
+    static JSValueRef find(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Watch changes
+     */
+    static JSValueRef addChangeListener(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Clear watch
+     */
+    static JSValueRef removeChangeListener(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Get an item from id
+     */
+    static JSValueRef get(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     *  Returns calendar stored as private object
+     */
+    static Api::Calendar::ICalendarPtr getCalendar(JSContextRef ctx,
+            const JSObjectRef object,
+            JSValueRef* exception);
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_CALENDAR_H_ */
+
diff --git a/src/standards/Tizen/Calendar/JSCalendarAlarm.cpp b/src/standards/Tizen/Calendar/JSCalendarAlarm.cpp
new file mode 100755 (executable)
index 0000000..bdb45de
--- /dev/null
@@ -0,0 +1,321 @@
+//
+// 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 "JSCalendarAlarm.h"
+#include "CalendarConverter.h"
+#include <dpl/log/log.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <CommonsJavaScript/Converter.h>
+#include <Tizen/TimeUtil/TimeUtilConverter.h>
+#include <Tizen/TimeUtil/JSTZDate.h>
+#include <Tizen/TimeUtil/JSTimeDuration.h>
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+JSClassDefinition JSCalendarAlarm::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_CALENDAR_ALARM,
+    0,
+    m_property,
+    NULL, //m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL, //callAsFunction,
+    constructor,
+    NULL, //hasInstance,
+    NULL, //convertToType,
+};
+
+JSStaticValue JSCalendarAlarm::m_property[] = {
+    { TIZEN_CALENDAR_ALARM_ABSOLUTE_DATE, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ALARM_BEFORE, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ALARM_METHOD, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ALARM_DESCRIPTION, getProperty, setProperty, kJSPropertyAttributeNone },
+
+    { 0, 0, 0, 0 }
+};
+
+JSClassRef JSCalendarAlarm::m_jsClassRef = JSClassCreate(
+        JSCalendarAlarm::getClassInfo());
+
+const JSClassDefinition* JSCalendarAlarm::getClassInfo()
+{
+    return &(m_classInfo);
+}
+
+JSClassRef JSCalendarAlarm::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+JSObjectRef JSCalendarAlarm::createJSCalendarAlarm(JSContextRef context, EventAlarmPtr alarm)
+{
+    EventAlarmPrivateObject *priv = new EventAlarmPrivateObject(context, alarm);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+EventAlarmPtr JSCalendarAlarm::getPrivateObject(JSObjectRef object)
+{
+    EventAlarmPrivateObject *priv =
+        static_cast<EventAlarmPrivateObject*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+    }
+    EventAlarmPtr result = priv->getObject();
+    if (!result) {
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+    }
+    return result;
+}
+
+void JSCalendarAlarm::setPrivateObject(const EventAlarmPtr &alarm,
+        JSContextRef ctx,
+        const JSObjectRef object)
+{
+    Try
+    {
+        EventAlarmPrivateObject *priv =
+            static_cast<EventAlarmPrivateObject*>(JSObjectGetPrivate(object));
+        delete priv;
+        priv = new EventAlarmPrivateObject(ctx, alarm);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Error during replacing alarm object.");
+    }
+}
+
+JSObjectRef JSCalendarAlarm::constructor(JSContextRef context,
+    JSObjectRef constructor,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception)
+{
+    Try
+    {
+        if (argumentCount<1) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        CalendarConverter converter(context);
+        TimeUtilConverter timeConverter(context);
+
+        EventAlarmPtr alarm( new EventAlarm() );
+
+        if (JSValueIsObjectOfClass(context, arguments[0], JSTZDate::getClassRef())){
+            LogDebug("absoluteDate case");
+            long long int absoluteDate = (long long int) (timeConverter.getTimeInMilliseconds(arguments[0])/1000);
+            alarm->setAbsoluteDate(absoluteDate);
+            alarm->setTimeZone(timeConverter.getPropertiesInTZDate(arguments[0]).timezone);
+
+            if (argumentCount>=2) {
+                std::string method = converter.toString(arguments[1]);
+                std::vector<EventAlarm::EventAlarmType> convertedMethods;
+                convertedMethods.push_back(converter.toEventAlarmType(method));
+                alarm->setMethods(convertedMethods);
+            }
+            if (argumentCount>=3) {
+                alarm->setDescription(converter.toString(arguments[2]));
+            }
+        } else if (JSValueIsObjectOfClass(context, arguments[0], JSTimeDuration::getClassRef())){
+            LogDebug("before case");
+            alarm->setDuration(timeConverter.getDurationPropertis(arguments[0]));
+
+            if (argumentCount>=2) {
+                std::string method = converter.toString(arguments[1]);
+                std::vector<EventAlarm::EventAlarmType> convertedMethods;
+                convertedMethods.push_back(converter.toEventAlarmType(method));
+                alarm->setMethods(convertedMethods);
+            }
+            if (argumentCount>=3) {
+                alarm->setDescription(converter.toString(arguments[2]));
+            }
+        } else {
+            ThrowMsg(ConversionException, "Wrong first parameter type.");
+        }
+
+        return createJSCalendarAlarm(context, alarm);
+    }
+    Catch(UnsupportedException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(ConversionException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+
+    return NULL;
+}
+
+void JSCalendarAlarm::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogDebug("Create calendar alarm private object.");
+        EventAlarmPtr alarm( new EventAlarm() );
+        EventAlarmPrivateObject *priv = new EventAlarmPrivateObject(context, alarm);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    } else {
+        LogDebug("Private object already set.");
+    }
+}
+
+void JSCalendarAlarm::finalize(JSObjectRef object)
+{
+    EventAlarmPrivateObject* priv = static_cast<EventAlarmPrivateObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+JSValueRef JSCalendarAlarm::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("enter");
+    CalendarConverter converter(context);
+    Try
+    {
+        EventAlarmPrivateObject* priv =
+            static_cast<EventAlarmPrivateObject*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            ThrowMsg(NullPointerException, "Private object is NULL.");
+        }
+        EventAlarmPtr alarm = priv->getObject();
+
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_ABSOLUTE_DATE)) {
+            if (!alarm) {
+                ThrowMsg(NullPointerException, "Alarm object is NULL.");
+            }
+
+            if (UNDEFINED_TIME==alarm->getAbsoluteDate()) {
+                return JSValueMakeNull(context);
+            } else {
+                TimeUtilConverter timeConverter(context);
+                return timeConverter.toJSValueRefTZDate((double)(alarm->getAbsoluteDate()*1000.0), alarm->getTimeZone());
+            }
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_BEFORE)) {
+            return JSTimeDuration::createJSObject(context, alarm->getDuration());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_DESCRIPTION)) {
+            return converter.toJSValueRef(alarm->getDescription());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_METHOD)) {
+            return converter.toJSValueRef(converter.toTizenValue(alarm->getMethods().at(0)));
+        }
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarAlarm::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    CalendarConverter converter(context);
+    Try
+    {
+        EventAlarmPrivateObject* priv =
+            static_cast<EventAlarmPrivateObject*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            ThrowMsg(NullPointerException, "Private object is NULL.");
+        }
+        EventAlarmPtr alarm = priv->getObject();
+
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_ABSOLUTE_DATE)) {
+            if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
+                ThrowMsg(ConversionException, "Wrong absoluteDate type.");
+            }
+            TimeUtilConverter timeConverter(context);
+            long long int absoluteDate = (long long int) (timeConverter.getTimeInMilliseconds(value)/1000);
+            alarm->setAbsoluteDate(absoluteDate);
+
+            if( alarm->getTimeZone().empty() ) {
+                std::string timeZone = timeConverter.getPropertiesInTZDate(value).timezone;
+                alarm->setTimeZone(timeZone);
+            }
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_BEFORE)) {
+            if (!JSValueIsObjectOfClass(context, value, JSTimeDuration::getClassRef())) {
+                ThrowMsg(ConversionException, "Wrong before type.");
+            }
+            TimeUtilConverter timeConverter(context);
+            alarm->setDuration(timeConverter.getDurationPropertis(value));
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_DESCRIPTION)) {
+            alarm->setDescription(converter.toString(value));
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_METHOD)) {
+            std::string method = converter.toString(value);
+            std::vector<EventAlarm::EventAlarmType> convertedMethods;
+            convertedMethods.push_back(converter.toEventAlarmType(method));
+            alarm->setMethods(convertedMethods);
+            return true;
+        }
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    return false;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Calendar/JSCalendarAlarm.h b/src/standards/Tizen/Calendar/JSCalendarAlarm.h
new file mode 100755 (executable)
index 0000000..a6caa2e
--- /dev/null
@@ -0,0 +1,110 @@
+//
+// 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 _JS_CALENDAR_ALARM_H_
+#define _JS_CALENDAR_ALARM_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Calendar/EventAlarm.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+#define TIZEN_INTERFACE_CALENDAR_ALARM "CalendarAlarm"
+
+#define TIZEN_CALENDAR_ALARM_ABSOLUTE_DATE "absoluteDate"
+#define TIZEN_CALENDAR_ALARM_BEFORE "before"
+#define TIZEN_CALENDAR_ALARM_METHOD "method"
+#define TIZEN_CALENDAR_ALARM_DESCRIPTION "description"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Calendar::EventAlarmPtr,
+            WrtDeviceApis::CommonsJavaScript::NoOwnership> EventAlarmPrivateObject;
+
+class JSCalendarAlarm
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static JSClassRef getClassRef();
+
+    static JSObjectRef createJSCalendarAlarm(JSContextRef context, TizenApis::Api::Calendar::EventAlarmPtr alarm);
+
+    static TizenApis::Api::Calendar::EventAlarmPtr getPrivateObject(JSObjectRef object);
+
+    static void setPrivateObject(const TizenApis::Api::Calendar::EventAlarmPtr &alarm,
+            JSContextRef ctx,
+            const JSObjectRef object);
+
+  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);
+
+       /**
+        * Constructor for the CalendarAlarm interface.
+        */
+       static JSObjectRef constructor(JSContextRef context,
+                   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 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 /* _JS_CALENDAR_ALARM_H_ */
diff --git a/src/standards/Tizen/Calendar/JSCalendarAttendee.cpp b/src/standards/Tizen/Calendar/JSCalendarAttendee.cpp
new file mode 100755 (executable)
index 0000000..3b67b11
--- /dev/null
@@ -0,0 +1,339 @@
+//
+// 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 "JSCalendarAttendee.h"
+#include <dpl/log/log.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <CommonsJavaScript/Converter.h>
+#include "CalendarConverter.h"
+
+#include "Tizen/Contact/JSContactRef.h"
+#include <Tizen/Contact/ContactConverter.h>
+#include <API/Contact/ContactRef.h>
+#include <API/TimeUtil/DurationProperties.h>
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+JSClassDefinition JSCalendarAttendee::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_CALENDAR_ATTENDEE,
+    0,
+    m_property,
+    NULL, //m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL, //callAsFunction,
+    constructor,
+    NULL, //hasInstance,
+    NULL, //convertToType,
+};
+
+JSStaticValue JSCalendarAttendee::m_property[] = {
+    { TIZEN_ATTENDEE_NAME, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_ATTENDEE_URI, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_ATTENDEE_ROLE, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_ATTENDEE_STATUS, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_ATTENDEE_RSVP, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_ATTENDEE_TYPE, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_ATTENDEE_GROUP, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_ATTENDEE_DELEGATORURI, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_ATTENDEE_DELEGATEURI, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_ATTENDEE_CONTACT_REF, getProperty, setProperty, kJSPropertyAttributeNone },
+
+    { 0, 0, 0, 0 }
+};
+
+JSClassRef JSCalendarAttendee::m_jsClassRef = JSClassCreate(
+        JSCalendarAttendee::getClassInfo());
+
+const JSClassDefinition* JSCalendarAttendee::getClassInfo()
+{
+    return &(m_classInfo);
+}
+
+JSClassRef JSCalendarAttendee::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+JSObjectRef JSCalendarAttendee::createJSCalendarAttendee(JSContextRef context, EventAttendeePtr attendee)
+{
+    AttendeePrivateObject *priv = new AttendeePrivateObject(context, attendee);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+void JSCalendarAttendee::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogDebug("Create calendar attendee private object.");
+        EventAttendeePtr attendee( new EventAttendee() );
+        AttendeePrivateObject *priv = new AttendeePrivateObject(context, attendee);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    } else {
+        LogDebug("Private object already set.");
+    }
+}
+
+void JSCalendarAttendee::finalize(JSObjectRef object)
+{
+    LogDebug("enter");
+    AttendeePrivateObject* priv = static_cast<AttendeePrivateObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+EventAttendeePtr JSCalendarAttendee::getPrivateObject(JSObjectRef object)
+{
+    AttendeePrivateObject *priv =
+        static_cast<AttendeePrivateObject*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        ThrowMsg(NullPointerException, "Private object is null.");
+    }
+    EventAttendeePtr result = priv->getObject();
+    if (!result) {
+        ThrowMsg(NullPointerException, "Private object is null.");
+    }
+    return result;
+}
+
+void JSCalendarAttendee::setPrivateObject(const EventAttendeePtr &attendee,
+        JSContextRef ctx,
+        const JSObjectRef object)
+{
+    Try
+    {
+        AttendeePrivateObject *priv =
+            static_cast<AttendeePrivateObject*>(JSObjectGetPrivate(object));
+        delete priv;
+        priv = new AttendeePrivateObject(ctx, attendee);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Error during replacing attendee object");
+    }
+}
+
+JSObjectRef JSCalendarAttendee::constructor(JSContextRef context,
+    JSObjectRef constructor,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception)
+{
+    Try
+    {
+        CalendarConverter converter(context);
+        EventAttendeePtr attendee;
+
+        if (argumentCount==0) {
+            EventAttendeePtr result(new EventAttendee());
+            attendee = result;
+        } else if (argumentCount==1) {
+            EventAttendeePtr result(new EventAttendee());
+            attendee = result;
+            attendee->setURI(converter.toString(arguments[0]));
+        } else if (argumentCount>=2) {
+            if (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1])) {
+                EventAttendeePtr result(new EventAttendee());
+                attendee = result;
+            } else {
+                if (!JSValueIsObject(context, arguments[1])) {
+                    ThrowMsg(ConversionException, "Wrong second parameter type.");
+                }
+
+                attendee = converter.toAttendee(arguments[1]);
+                if (!attendee) {
+                    ThrowMsg(ConversionException, "Parameter conversion failed.");
+                }
+            }
+            attendee->setURI(converter.toString(arguments[0]));
+        }
+
+        return createJSCalendarAttendee(context, attendee);
+    }
+    Catch(UnsupportedException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(ConversionException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+
+    return NULL;
+}
+
+JSValueRef JSCalendarAttendee::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("enter");
+    CalendarConverter converter(context);
+    Try
+    {
+        AttendeePrivateObject* priv =
+            static_cast<AttendeePrivateObject*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            ThrowMsg(NullPointerException, "Private object is NULL.");
+        }
+        EventAttendeePtr attendee = priv->getObject();
+
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_NAME)) {
+            return converter.toJSValueRef(attendee->getName());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_URI)) {
+            return converter.toJSValueRef(attendee->getURI());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_ROLE)) {
+            return converter.toJSValueRef(converter.toTizenValue(attendee->getRole()));
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_STATUS)) {
+            return converter.toJSValueRef(converter.toTizenValue(attendee->getStatus()));
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_RSVP)) {
+            return converter.toJSValueRef(attendee->getRSVP());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_TYPE)) {
+           return converter.toJSValueRef(converter.toTizenValue(attendee->getType()));
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_GROUP)) {
+            return converter.toJSValueRef(attendee->getGroup());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_DELEGATORURI)) {
+            return converter.toJSValueRef(attendee->getDelegatorURI());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_DELEGATEURI)) {
+            return converter.toJSValueRef(attendee->getDelegateURI());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_CONTACT_REF)) {
+            TizenApis::Tizen1_0::Contact::ContactConverter contactConverter(context);
+            TizenApis::Api::Contact::ContactRefPtr contactRefPtr( new TizenApis::Api::Contact::ContactRef() );
+            contactRefPtr->setContactId(attendee->getContactId());
+            contactRefPtr->setAddressBookId(attendee->getAddressBookId());
+            return contactConverter.toJSValueRef(contactRefPtr);
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarAttendee::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    CalendarConverter converter(context);
+    Try
+    {
+        AttendeePrivateObject* priv =
+            static_cast<AttendeePrivateObject*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            ThrowMsg(NullPointerException, "Attendee object is NULL.");
+        }
+        EventAttendeePtr attendee = priv->getObject();
+
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_NAME)) {
+            std::string name = converter.toString(value);
+            attendee->setName(name);
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_URI)) {
+            std::string uri = converter.toString(value);
+            attendee->setURI(uri);
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_ROLE)) {
+            std::string role = converter.toString(value);
+            attendee->setRole(converter.toEventAttendeeRole(role));
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_STATUS)) {
+            std::string status = converter.toString(value);
+            attendee->setStatus(converter.toEventAttendeeStatus(status));
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_RSVP)) {
+            bool RSVP = converter.toBool(value);
+            attendee->setRSVP(RSVP);
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_TYPE)) {
+            std::string type = converter.toString(value);
+            attendee->setType(converter.toEventAttendeeType(type));
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_GROUP)) {
+            std::string group = converter.toString(value);
+            attendee->setGroup(group);
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_DELEGATORURI)) {
+            std::string delegatorURI = converter.toString(value);
+            attendee->setDelegatorURI(delegatorURI);
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_DELEGATEURI)) {
+            std::string delegateURI = converter.toString(value);
+            attendee->setDelegateURI(delegateURI);
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_CONTACT_REF)) {
+            if (!JSValueIsObjectOfClass(context, value, TizenApis::Tizen1_0::Contact::JSContactRef::getClassRef())) {
+                ThrowMsg(ConversionException, "Wrong contactRef type.");
+            }
+
+            TizenApis::Tizen1_0::Contact::ContactConverter contactConverter(context);
+            attendee->setContactId(contactConverter.toContactRef(value)->getContactId());
+            attendee->setAddressBookId(contactConverter.toContactRef(value)->getAddressBookId());
+            return true;
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR);
+    return false;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Calendar/JSCalendarAttendee.h b/src/standards/Tizen/Calendar/JSCalendarAttendee.h
new file mode 100755 (executable)
index 0000000..ee7af56
--- /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.
+//
+
+
+#ifndef _JS_CALENDAR_ATTENDEE_H_
+#define _JS_CALENDAR_ATTENDEE_H_
+
+#include <string>
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Calendar/CalendarEvent.h>
+#include <API/Calendar/EventAttendee.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+#define TIZEN_INTERFACE_CALENDAR_ATTENDEE "CalendarAttendee"
+
+#define TIZEN_ATTENDEE_NAME "name"
+#define TIZEN_ATTENDEE_URI "uri"
+#define TIZEN_ATTENDEE_ROLE "role"
+#define TIZEN_ATTENDEE_STATUS "status"
+#define TIZEN_ATTENDEE_RSVP "RSVP"
+#define TIZEN_ATTENDEE_TYPE "type"
+#define TIZEN_ATTENDEE_GROUP "group"
+#define TIZEN_ATTENDEE_DELEGATORURI "delegatorURI"
+#define TIZEN_ATTENDEE_DELEGATEURI "delegateURI"
+#define TIZEN_ATTENDEE_CONTACT_REF "contactRef"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Calendar::EventAttendeePtr,
+       WrtDeviceApis::CommonsJavaScript::NoOwnership> AttendeePrivateObject;
+
+class JSCalendarAttendee
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static JSClassRef getClassRef();
+
+    static JSObjectRef createJSCalendarAttendee(JSContextRef context, TizenApis::Api::Calendar::EventAttendeePtr event);
+
+    static TizenApis::Api::Calendar::EventAttendeePtr getPrivateObject(JSObjectRef object);
+
+    static void setPrivateObject(const TizenApis::Api::Calendar::EventAttendeePtr &attendee,
+            JSContextRef ctx,
+            const JSObjectRef object);
+
+  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);
+
+       /**
+        * Constructor for the CalendarAttendee interface.
+        */
+       static JSObjectRef constructor(JSContextRef context,
+                   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 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 /* _JS_CALENDAR_ATTENDEE_H_ */
diff --git a/src/standards/Tizen/Calendar/JSCalendarEvent.cpp b/src/standards/Tizen/Calendar/JSCalendarEvent.cpp
new file mode 100755 (executable)
index 0000000..47de567
--- /dev/null
@@ -0,0 +1,459 @@
+//
+// 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 <ctime>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <API/Calendar/EventId.h>
+#include "JSCalendarEvent.h"
+#include "JSCalendarItemProperties.h"
+#include "CalendarConverter.h"
+#include "JSCalendarEventId.h"
+#include "plugin_config.h"
+#include "CalendarResponseDispatcher.h"
+#include <Tizen/TimeUtil/TimeUtilConverter.h>
+#include <Tizen/TimeUtil/JSTZDate.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "CalendarAsyncCallbackManager.h"
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+JSClassDefinition JSCalendarEvent::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_CALENDAR_EVENT,
+    JSCalendarItemProperties::getClassRef(),
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    constructor,
+    NULL, //HasInstance,
+    NULL  //ConvertToType
+};
+
+JSStaticValue JSCalendarEvent::m_property[] = {
+    { TIZEN_CALENDAR_EVENT_ID, getPropertyId,
+      NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_CALENDAR_EVENT_LAST_MODIFICATION_DATE, getPropertyLastModificationDate,
+      NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_CALENDAR_EVENT_IS_DETACHED, getPropertyIsDetached,
+      NULL, kJSPropertyAttributeReadOnly },
+
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSCalendarEvent::m_function[] = {
+    { CALENDAR_FUNCTION_API_EXPAND_RECURRENCE, expandRecurrence, kJSPropertyAttributeNone },
+
+    { 0, 0, 0 }
+};
+
+JSClassRef JSCalendarEvent::m_jsClassRef = JSClassCreate(JSCalendarEvent::getClassInfo());
+
+ICalendarPtr JSCalendarEvent::m_calendar = CalendarFactory::getInstance().createCalendarObject();
+
+void JSCalendarEvent::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogDebug("Create calendar event private object.");
+        CalendarEventPtr event( new CalendarEvent() );
+        CalendarEventPrivObject *priv = new CalendarEventPrivObject(context, event);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    } else {
+        LogDebug("Private object already set.");
+    }
+
+    if (m_calendar) {
+        m_calendar->setType(CalendarEvent::EVENT_TYPE);
+        LogDebug("Calendar object type is set to event.");
+    }
+}
+
+void JSCalendarEvent::finalize(JSObjectRef object)
+{
+    LogDebug("enter");
+    CalendarEventPrivObject* priv = static_cast<CalendarEventPrivObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+JSObjectRef JSCalendarEvent::constructor(JSContextRef context,
+    JSObjectRef constructor,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception)
+{
+    Try
+    {
+               CalendarEventPrivObject* privateObject = static_cast<CalendarEventPrivObject*>(JSObjectGetPrivate(constructor));
+               JSContextRef globalContext = privateObject->getContext();
+
+        CalendarConverter converter(globalContext);
+        CalendarEventPtr event;
+
+        if (argumentCount==0) {
+            CalendarEventPtr result(new CalendarEvent());
+            event = result;
+        } else if (argumentCount==1) {
+            LogInfo("eventInitDict case");
+            if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
+                CalendarEventPtr result(new CalendarEvent());
+                event = result;
+            } else if (JSValueIsObject(context, arguments[0])) {
+                event = converter.toEvent(arguments[0]);
+                if (!event) {
+                    ThrowMsg(ConversionException, "Parameter conversion failed.");
+                }
+            } else {
+                ThrowMsg(ConversionException, "Parameter conversion failed.");
+            }
+        } else if (argumentCount>=2) {
+            LogInfo("event stringRepresentation case");
+            std::string eventStr;
+            CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
+            eventStr = converter.toString(arguments[0]);
+            format = converter.toVObjectFormat(converter.toString(arguments[1]));
+
+            IEventCreateEventFromStringPtr dplEvent(new IEventCreateEventFromString());
+            dplEvent->setEventString(eventStr);
+            dplEvent->setFormat(format);
+            dplEvent->setForSynchronousCall();
+            m_calendar->createEventFromString(dplEvent);
+
+            // Process the returned object.
+            if (dplEvent->getResult()) {
+                LogInfo("Successfully created an event.");
+                event = dplEvent->getEvent();
+            } else {
+                if (dplEvent->getExceptionCode()==ExceptionCodes::InvalidArgumentException) {
+                    ThrowMsg(InvalidArgumentException, "Wrong string to convert.");
+                } else {
+                    ThrowMsg(UnknownException, "Converting string failed.");
+                }
+            }
+        }
+
+        return createJSCalendarEvent(globalContext, event);
+    }
+    Catch(UnsupportedException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(ConversionException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+
+    return NULL;
+}
+
+JSObjectRef JSCalendarEvent::createJSCalendarEvent(JSContextRef context, CalendarEventPtr event)
+{
+    CalendarEventPrivObject *priv = new CalendarEventPrivObject(context, event);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassRef JSCalendarEvent::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSCalendarEvent::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+CalendarEventPtr JSCalendarEvent::getPrivateObject(JSObjectRef object)
+{
+    CalendarEventPrivObject *priv =
+        static_cast<CalendarEventPrivObject*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    CalendarEventPtr result = priv->getObject();
+    if (!result) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    return result;
+}
+
+void JSCalendarEvent::setPrivateObject(const CalendarEventPtr &event,
+        JSContextRef ctx,
+        const JSObjectRef object)
+{
+    Try
+    {
+        CalendarEventPrivObject *priv =
+            static_cast<CalendarEventPrivObject*>(JSObjectGetPrivate(object));
+        delete priv;
+        priv = new CalendarEventPrivObject(ctx, event);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Error during replacing event object");
+    }
+}
+
+JSValueRef JSCalendarEvent::expandRecurrence(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarEventPrivObject *privateObject =
+        static_cast<CalendarEventPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_EXPAND_RECURRENCE);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        CalendarEventPtr event = privateObject->getObject();
+        if (!event) {
+            ThrowMsg(ConversionException, "Parameter conversion failed.");
+        }
+
+        JSContextRef globalContext = privateObject->getContext();
+        CalendarConverter converter(context);
+
+        std::time_t startDate = 0;
+        std::time_t endDate = INT_MAX; // about 60 years in 4 bytes system.
+        TimeUtilConverter timeConverter(context);
+        if (argumentCount>=1) {
+            if (JSValueIsObjectOfClass(context, arguments[0], JSTZDate::getClassRef())) {
+                startDate = (long long int) (timeConverter.getTimeInMilliseconds(arguments[0])/1000);
+                LogInfo("startDate: "<<startDate);
+            } else {
+                ThrowMsg(ConversionException, "Wrong first parameter type.");
+            }
+        }
+        if (argumentCount>=2) {
+            if (JSValueIsObjectOfClass(context, arguments[1], JSTZDate::getClassRef())) {
+                endDate = (long long int) (timeConverter.getTimeInMilliseconds(arguments[1])/1000);
+                LogInfo("endDate: "<<endDate);
+            } else {
+                ThrowMsg(ConversionException, "Wrong second parameter type.");
+            }
+        }
+
+        JSValueRef onError = argumentCount > 3 ? converter.toFunctionOrNull(arguments[3]) : NULL;
+
+        JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError);
+
+        Validator validator(context);
+        if (validator.isCallback(arguments[2])) {
+            cbm->setOnSuccess(arguments[2]);
+        } else {
+            ThrowMsg(ConversionException, "Wrong third parameter type.");
+        }
+
+               cbm->setObject(thisObject);
+
+        LogDebug("Proceed the expand event to the platform.");
+
+        IEventExpandEventRecurrencePtr dplEvent(new IEventExpandEventRecurrence());
+        dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
+        dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
+        dplEvent->setEvent(event);
+        dplEvent->setStartDate(startDate);
+        dplEvent->setEndDate(endDate);
+        m_calendar->expandEventRecurrence(dplEvent);
+
+               CalendarAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+        return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendarEvent::getPropertyId(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPrivObject *privateObject =
+            static_cast<CalendarEventPrivObject*>(JSObjectGetPrivate(object));
+        CalendarEventPtr event = privateObject->getObject();
+
+        EventIdPtr eventId( new EventId() );
+
+           if (UNDEFINED_ITEM_ID==event->getId()) {
+            return JSValueMakeNull(context);
+           } else {
+               eventId->setUId(event->getUId());
+           }
+
+        std::stringstream ss;
+        std::time_t rid = event->getRecurrenceId();
+        ss<<rid;
+        eventId->setRecurrenceId(ss.str());
+        return JSCalendarEventId::createJSCalendarEventId(context, eventId);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCalendarEvent::getPropertyLastModificationDate(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPrivObject *privateObject =
+            static_cast<CalendarEventPrivObject*>(JSObjectGetPrivate(object));
+        CalendarEventPtr event = privateObject->getObject();
+        if (!event) {
+            ThrowMsg(NullPointerException, "Event object is NULL.");
+        }
+
+        if (UNDEFINED_TIME==event->getLastModifiedDate()) {
+            return JSValueMakeNull(context);
+        } else {
+            TimeUtilConverter timeConverter(context);
+            return timeConverter.toJSValueRefTZDate((double)(event->getLastModifiedDate()*1000.0), event->getTimeZone());
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCalendarEvent::getPropertyIsDetached(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr event = getPrivateObject(object);
+        if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
+            return JSValueMakeUndefined(context);
+        }
+
+        Converter converter(context);
+        return converter.toJSValueRef(event->getIsDetached());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarEvent::validate(JSContextRef ctx,
+        const JSObjectRef object,
+        JSValueRef* exception)
+{
+    CalendarEventPrivObject *priv =
+        static_cast<CalendarEventPrivObject*>(JSObjectGetPrivate(object));
+    if (priv == NULL) {
+        return false;
+    }
+    CalendarEventPtr event = priv->getObject();
+    if (!event) {
+        return false;
+    }
+    return event->validate();
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Calendar/JSCalendarEvent.h b/src/standards/Tizen/Calendar/JSCalendarEvent.h
new file mode 100755 (executable)
index 0000000..bf60217
--- /dev/null
@@ -0,0 +1,138 @@
+//
+// 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 _JS_CALENDAR_EVENT_H_
+#define _JS_CALENDAR_EVENT_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <API/Calendar/CalendarEvent.h>
+#include <API/Calendar/ICalendar.h>
+#include <API/Calendar/CalendarFactory.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+#define TIZEN_INTERFACE_CALENDAR_EVENT "CalendarEvent"
+
+#define TIZEN_CALENDAR_EVENT_ID "id"
+#define TIZEN_CALENDAR_EVENT_LAST_MODIFICATION_DATE "lastModificationDate"
+#define TIZEN_CALENDAR_EVENT_IS_DETACHED "isDetached"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Calendar::CalendarEventPtr,
+       WrtDeviceApis::CommonsJavaScript::NoOwnership> CalendarEventPrivObject;
+
+class JSCalendarEvent
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+    static TizenApis::Api::Calendar::CalendarEventPtr getPrivateObject(JSObjectRef object);
+
+    static void setPrivateObject(const TizenApis::Api::Calendar::CalendarEventPtr &event,
+            JSContextRef ctx,
+            const JSObjectRef object);
+
+    static bool validate(JSContextRef ctx,
+            const JSObjectRef object,
+            JSValueRef* exception);
+
+       static JSObjectRef createJSCalendarEvent(JSContextRef context, TizenApis::Api::Calendar::CalendarEventPtr event);
+
+  private:
+    /**
+     * 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;
+
+       /**
+        * The calendar object to be used for asynchronous platform function invocation.
+        */
+       static TizenApis::Api::Calendar::ICalendarPtr m_calendar;
+
+    /**
+     * 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);
+
+       /**
+        * Constructor for the CalendarEvent interface.
+        */
+       static JSObjectRef constructor(JSContextRef context,
+    JSObjectRef constructor,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception);
+
+    /**
+     * Expand event instances from a recurring event
+     */
+    static JSValueRef expandRecurrence(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Getters and setters for properties
+     */
+    static JSValueRef getPropertyId(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getPropertyLastModificationDate(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getPropertyIsDetached(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+};
+
+}
+}
+}
+
+#endif /* _JS_CALENDAR_EVENT_H_ */
diff --git a/src/standards/Tizen/Calendar/JSCalendarEventId.cpp b/src/standards/Tizen/Calendar/JSCalendarEventId.cpp
new file mode 100755 (executable)
index 0000000..c50de40
--- /dev/null
@@ -0,0 +1,271 @@
+//
+// 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 "JSCalendarEventId.h"
+#include "CalendarConverter.h"
+#include <dpl/log/log.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <CommonsJavaScript/Converter.h>
+#include <Tizen/TimeUtil/TimeUtilConverter.h>
+#include <Tizen/TimeUtil/JSTZDate.h>
+#include <sstream>
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+JSClassDefinition JSCalendarEventId::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_CALENDAR_EVENT_ID,
+    0,
+    m_property,
+    NULL, //m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL, //callAsFunction,
+    constructor,
+    NULL, //hasInstance,
+    NULL, //convertToType,
+};
+
+JSStaticValue JSCalendarEventId::m_property[] = {
+    { TIZEN_CALENDAR_EVENT_ID_UID, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_EVENT_ID_RECURRENCEID, getProperty, setProperty, kJSPropertyAttributeNone },
+    { 0, 0, 0, 0 }
+};
+
+JSClassRef JSCalendarEventId::m_jsClassRef = JSClassCreate(
+        JSCalendarEventId::getClassInfo());
+
+const JSClassDefinition* JSCalendarEventId::getClassInfo()
+{
+    return &(m_classInfo);
+}
+
+JSClassRef JSCalendarEventId::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+EventIdPtr JSCalendarEventId::getPrivateObject(JSObjectRef object)
+{
+    EventIdPrivateObject *priv =
+        static_cast<EventIdPrivateObject*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    EventIdPtr result = priv->getObject();
+    if (!result) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    return result;
+}
+
+void JSCalendarEventId::setPrivateObject(const EventIdPtr &eventId,
+        JSContextRef ctx,
+        const JSObjectRef object)
+{
+    Try
+    {
+        EventIdPrivateObject *priv =
+            static_cast<EventIdPrivateObject*>(JSObjectGetPrivate(object));
+        delete priv;
+        priv = new EventIdPrivateObject(ctx, eventId);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Error during replacing event id object.");
+    }
+}
+
+JSObjectRef JSCalendarEventId::createJSCalendarEventId(JSContextRef context, EventIdPtr eventId)
+{
+    EventIdPrivateObject *priv = new EventIdPrivateObject(context, eventId);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+void JSCalendarEventId::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogDebug("Create calendar event id private object.");
+        EventIdPtr eventId( new EventId() );
+        EventIdPrivateObject *priv = new EventIdPrivateObject(context, eventId);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    } else {
+        LogDebug("Private object already set.");
+    }
+}
+
+void JSCalendarEventId::finalize(JSObjectRef object)
+{
+    LogDebug("enter");
+    EventIdPrivateObject* priv = static_cast<EventIdPrivateObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+JSObjectRef JSCalendarEventId::constructor(JSContextRef context,
+    JSObjectRef constructor,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception)
+{
+    Try
+    {
+        CalendarConverter converter(context);
+        EventIdPtr eventId;
+
+        if (argumentCount==0) {
+            EventIdPtr result( new EventId());
+            eventId = result;
+        } else if (argumentCount==1) {
+            EventIdPtr result( new EventId());
+            eventId = result;
+            eventId->setUId(converter.toString(arguments[0]));
+        } else if (argumentCount>=2) {
+            EventIdPtr result( new EventId());
+            eventId = result;
+            eventId->setUId(converter.toString(arguments[0]));
+            eventId->setRecurrenceId(converter.toString(arguments[1]));
+        }
+
+        return createJSCalendarEventId(context, eventId);
+    }
+    Catch(UnsupportedException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(ConversionException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+
+    return NULL;
+}
+
+JSValueRef JSCalendarEventId::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("enter");
+    Try
+    {
+        EventIdPrivateObject* priv = static_cast<EventIdPrivateObject*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            ThrowMsg(NullPointerException, "Private object is NULL.");
+        }
+
+        EventIdPtr eventId = priv->getObject();
+        if (!eventId) {
+            ThrowMsg(NullPointerException, "EventId is NULL.");
+        }
+
+        Converter converter(context);
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_EVENT_ID_UID)) {
+            if (eventId->getUId()==UNDEFINED_ID) {
+                return JSValueMakeNull(context);
+            } else {
+                return converter.toJSValueRef(eventId->getUId());
+            }
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_EVENT_ID_RECURRENCEID)) {
+            if (eventId->getRecurrenceId()==UNDEFINED_ID) {
+                return JSValueMakeNull(context);
+            } else {
+                return converter.toJSValueRef(eventId->getRecurrenceId());
+            }
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarEventId::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        EventIdPrivateObject* priv = static_cast<EventIdPrivateObject*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            ThrowMsg(NullPointerException, "Private object is NULL.");
+        }
+
+        EventIdPtr eventId = priv->getObject();
+        Converter converter(context);
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_EVENT_ID_UID)) {
+            std::string uid = converter.toString(value);
+            eventId->setUId(uid);
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_EVENT_ID_RECURRENCEID)) {
+            std::string recurrenceId = converter.toString(value);
+            eventId->setRecurrenceId(recurrenceId);
+            return true;
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR);
+    return false;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Calendar/JSCalendarEventId.h b/src/standards/Tizen/Calendar/JSCalendarEventId.h
new file mode 100755 (executable)
index 0000000..943d87b
--- /dev/null
@@ -0,0 +1,109 @@
+//
+// 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 _JS_CALEMDAR_EVENT_ID_H_
+#define _JS_CALEMDAR_EVENT_ID_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Calendar/EventId.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+#define TIZEN_INTERFACE_CALENDAR_EVENT_ID "CalendarEventId"
+
+#define TIZEN_CALENDAR_EVENT_ID_UID "uid"
+#define TIZEN_CALENDAR_EVENT_ID_RECURRENCEID "rid"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Calendar::EventIdPtr,
+                               WrtDeviceApis::CommonsJavaScript::NoOwnership> EventIdPrivateObject;
+
+class JSCalendarEventId
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static JSClassRef getClassRef();
+
+    static JSObjectRef createJSCalendarEventId(JSContextRef context, TizenApis::Api::Calendar::EventIdPtr eventId);
+
+    static TizenApis::Api::Calendar::EventIdPtr getPrivateObject(JSObjectRef object);
+
+    static void setPrivateObject(const TizenApis::Api::Calendar::EventIdPtr &eventId,
+            JSContextRef ctx,
+            const JSObjectRef object);
+
+  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);
+
+       /**
+        * Constructor for the CalendarEventId interface.
+        */
+       static JSObjectRef constructor(JSContextRef context,
+                   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 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 /* _JS_CALEMDAR_EVENT_ID_H_ */
diff --git a/src/standards/Tizen/Calendar/JSCalendarItemProperties.cpp b/src/standards/Tizen/Calendar/JSCalendarItemProperties.cpp
new file mode 100755 (executable)
index 0000000..07c1552
--- /dev/null
@@ -0,0 +1,1389 @@
+//
+// 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 <ctime>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Tizen/TimeUtil/TimeUtilConverter.h>
+#include <Tizen/TimeUtil/JSTZDate.h>
+#include <Tizen/Tizen/JSSimpleCoordinates.h>
+#include <API/Calendar/EventAlarm.h>
+#include <API/Calendar/EventId.h>
+#include <API/Calendar/ICalendar.h>
+#include <API/Calendar/CalendarFactory.h>
+#include "API/TimeUtil/DurationProperties.h"
+#include "JSCalendarItemProperties.h"
+#include "CalendarConverter.h"
+#include "JSCalendarEventId.h"
+#include "JSCalendarAlarm.h"
+#include "JSCalendarRecurrenceRule.h"
+#include "JSCalendarAttendee.h"
+#include "JSCalendarEvent.h"
+#include "JSCalendarTask.h"
+#include "plugin_config.h"
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+#define TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME "CalendarItemProperties"
+
+JSClassDefinition JSCalendarItemProperties::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_CALENDAR_ITEM_PROPERTIES_ATTRIBUTENAME,
+    0,
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL  //ConvertToType
+};
+
+JSStaticValue JSCalendarItemProperties::m_property[] = {
+    // Item Properties
+    { TIZEN_CALENDAR_ITEM_DESCRIPTION, getPropertyDescription,
+      setPropertyDescription, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_SUMMARY, getPropertySummary,
+      setPropertySummary, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_START_DATE, getPropertyStartTime,
+      setPropertyStartTime, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_LOCATION, getPropertyLocation,
+      setPropertyLocation, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_GEOLOCATION, getPropertyGeolocation,
+      setPropertyGeolocation, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_ORGANIZER, getPropertyOrganizer,
+      setPropertyOrganizer, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_VISIBILITY, getPropertyVisibility,
+      setPropertyVisibility, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_STATUS, getPropertyStatus,
+      setPropertyStatus, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_ALARMS, getPropertyAlarms,
+      setPropertyAlarms, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_CATEGORIES, getPropertyCategories,
+      setPropertyCategories, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_DURATION, getPropertyDuration,
+      setPropertyDuration, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_IS_ALL_DAY, getPropertyIsAllDay,
+      setPropertyIsAllDay, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_ATTENDEES, getPropertyAttendees,
+      setPropertyAttendees, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_EVENT_RECURRENCE_RULE, getPropertyRecurrenceRule,
+      setPropertyRecurrenceRule, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_EVENT_AVAILABILITY, getPropertyAvailability,
+      setPropertyAvailability, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_TASK_DUE_DATE, getPropertyDueDate,
+      setPropertyDueDate, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_TASK_COMPLETED_DATE, getPropertyCompletedDate,
+      setPropertyCompletedDate, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_TASK_PROGRESS, getPropertyProgress,
+      setPropertyProgress, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_ITEM_PRIORITY, getPropertyPriority,
+      setPropertyPriority, kJSPropertyAttributeNone },
+    { TIZEN_CALENDAR_EVENT_END_DATE, getPropertyEndDate,
+      setPropertyEndDate, kJSPropertyAttributeNone },
+
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSCalendarItemProperties::m_function[] = {
+    { CALENDAR_FUNCTION_API_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
+    { CALENDAR_FUNCTION_API_CLONE, clone, kJSPropertyAttributeNone },
+
+    { 0, 0, 0 }
+};
+
+JSClassRef JSCalendarItemProperties::m_jsClassRef = JSClassCreate(JSCalendarItemProperties::getClassInfo());
+
+void JSCalendarItemProperties::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogDebug("Create calendar item private object.");
+        CalendarEventPtr item( new CalendarEvent() );
+        CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    } else {
+        LogDebug("Private object already set.");
+    }
+}
+
+void JSCalendarItemProperties::finalize(JSObjectRef object)
+{
+    CalendarItemPropertiesPrivObject *priv = static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+const JSClassRef JSCalendarItemProperties::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSCalendarItemProperties::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+CalendarEventPtr JSCalendarItemProperties::getPrivateObject(JSObjectRef object)
+{
+    CalendarItemPropertiesPrivObject *priv =
+        static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    CalendarEventPtr result = priv->getObject();
+    if (!result) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    return result;
+}
+
+void JSCalendarItemProperties::setPrivateObject(const CalendarEventPtr &event,
+        JSContextRef ctx,
+        const JSObjectRef object)
+{
+    Try
+    {
+        CalendarItemPropertiesPrivObject *priv =
+            static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
+        delete priv;
+        priv = new CalendarItemPropertiesPrivObject(ctx, event);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Error during replacing event object");
+    }
+}
+
+JSObjectRef JSCalendarItemProperties::createJSCalendarItemProperties(JSContextRef context, CalendarEventPtr item)
+{
+    CalendarItemPropertiesPrivObject *priv = new CalendarItemPropertiesPrivObject(context, item);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSCalendarItemProperties::convertToString(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarItemPropertiesPrivObject *privateObject =
+        static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CONVERT_TO_STRING);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        CalendarEventPtr item = privateObject->getObject();
+        if (!item) {
+            ThrowMsg(ConversionException, "Parameter conversion failed.");
+        }
+
+        CalendarConverter converter(context);
+
+        CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
+        if (argumentCount>=1) {
+            format = converter.toVObjectFormat(converter.toString(arguments[0]));
+        } else {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        ICalendarPtr calendar = CalendarFactory::getInstance().createCalendarObject();
+        calendar->setType(item->getCalendarType());
+
+        IEventExportEventToStringPtr dplEvent(new IEventExportEventToString());
+        dplEvent->setEvent(item);
+        dplEvent->setFormat(format);
+        dplEvent->setForSynchronousCall();
+        calendar->exportEventToString(dplEvent);
+
+        if (dplEvent->getResult()) {
+            return converter.toJSValueRef(dplEvent->getEventString());
+        } else {
+            ThrowMsg(UnknownException, "Converting to string failed by unknown reason.");
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendarItemProperties::clone(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarItemPropertiesPrivObject *privateObject =
+        static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_CLONE);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        CalendarEventPtr item = privateObject->getObject(); // item to copy
+        if (!item) {
+            ThrowMsg(ConversionException, "Parameter conversion failed.");
+        }
+        JSContextRef globalContext = privateObject->getContext();
+
+        // Call the copy constructor.
+        CalendarEventPtr clonedItem( new CalendarEvent(*item));
+
+        // Reset the id.
+        clonedItem->resetId();
+        clonedItem->setRecurrenceId(UNDEFINED_ITEM_ID);
+
+               if (CalendarEvent::TASK_TYPE==clonedItem->getCalendarType()) {
+               return JSCalendarTask::createJSCalendarTask(context, clonedItem);
+               } else if (CalendarEvent::EVENT_TYPE==clonedItem->getCalendarType()) {
+            // Use global context for potential async api invocation.
+            return JSCalendarEvent::createJSCalendarEvent(globalContext, clonedItem);
+               } else {
+                       ThrowMsg(ConversionException, "Wrong object type.");
+               }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyDescription(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        Converter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        return converter.toJSValueRef(event->getDescription());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyDescription(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        Converter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        std::string description = converter.toString(value);
+        event->setDescription(description);
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertySummary(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        Converter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        return converter.toJSValueRef(event->getSubject());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertySummary(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        Converter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        std::string subject = converter.toString(value);
+        event->setSubject(subject);
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyStartTime(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarItemPropertiesPrivObject *privateObject =
+            static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
+        TimeUtilConverter timeConverter(context);
+        CalendarEventPtr event = privateObject->getObject();
+
+        LogInfo("start time before converted to TZDate: "<<event->getStartTime()<<", time zone: "<<event->getTimeZone());
+        if (UNDEFINED_TIME==event->getStartTime()) {
+            return JSValueMakeUndefined(context);
+        } else {
+            return timeConverter.toJSValueRefTZDate((double)(event->getStartTime()*1000.0), event->getTimeZone());
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyStartTime(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        CalendarEventPtr event = getPrivateObject(object);
+        TimeUtilConverter converter(context);
+        std::time_t duration = event->getEndTime() - event->getStartTime();
+        if (duration<0) {
+            duration = 0;
+        }
+
+        long long int startTime = (long long int) (converter.getTimeInMilliseconds(value)/1000);
+        event->setStartTime(startTime);
+        event->setEndTime(startTime + duration);
+
+        std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
+        event->setTimeZone(timeZone);
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyLocation(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        Converter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        return converter.toJSValueRef(event->getLocation());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyLocation(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        Converter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        std::string location = converter.toString(value);
+        event->setLocation(location);
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyCategories(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarConverter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        StringArrayPtr categories = event->getCategories();
+        if (categories) {
+            return converter.toJSValueRef(categories);
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyCategories(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr event = getPrivateObject(object);
+        CalendarConverter converter(context);
+               event->setCategories(converter.toStringArray(value));
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyStatus(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarConverter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        std::string status = converter.toTizenValue(event->getStatus());
+        return converter.toJSValueRef(status);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyStatus(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    CalendarEventPtr event(NULL);
+    Try
+    {
+        event = getPrivateObject(object);
+        CalendarConverter converter(context);
+        CalendarEvent::EventStatus status =
+            converter.toEventStatus(converter.toString(value));
+        event->setStatus(status);
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyAlarms(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr event = getPrivateObject(object);
+
+        JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+        if (NULL == jsResult) {
+            ThrowMsg(NullPointerException, "Can not create array object.");
+        }
+        for( unsigned int i=0; i<event->getAlarms()->size(); i++) {
+            if (!JSSetArrayElement(context, jsResult, i, JSCalendarAlarm::createJSCalendarAlarm(context, event->getAlarms()->at(i)))) {
+               ThrowMsg(UnknownException, "Can not insert value into array.");
+            }
+        }
+        return jsResult;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyAlarms(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    CalendarEventPtr event(NULL);
+    Try
+    {
+        event = getPrivateObject(object);
+        CalendarConverter converter(context);
+
+        EventAlarmListPtr alarms = converter.toVectorOfEventAlarmsFromReference(value);
+
+        event->setAlarms(alarms);
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyOrganizer(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        Converter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        return converter.toJSValueRef(event->getOrganizer());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyOrganizer(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        Converter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        std::string organizer = converter.toString(value);
+        event->setOrganizer(organizer);
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyVisibility(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarConverter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        std::string visibility = converter.toTizenValue(event->getVisibility());
+        return converter.toJSValueRef(visibility);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyVisibility(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    CalendarEventPtr event(NULL);
+    Try
+    {
+        event = getPrivateObject(object);
+        CalendarConverter converter(context);
+        CalendarEvent::EventVisibility visibility =
+            converter.toEventVisibility(converter.toString(value));
+        event->setVisibility(visibility);
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyGeolocation(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr event = getPrivateObject(object);
+        TizenApis::Api::Tizen::SimpleCoordinatesPtr geoLocation(
+            new TizenApis::Api::Tizen::SimpleCoordinates(event->getLatitude(), event->getLongitude()) );
+
+        return TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::createJSObject(context, geoLocation);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyGeolocation(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr event = getPrivateObject(object);
+        TizenApis::Api::Tizen::SimpleCoordinatesPtr geoLocation =
+            TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
+
+        event->setLatitude(geoLocation->getLatitude());
+        event->setLongitude(geoLocation->getLongitude());
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyDuration(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr event = getPrivateObject(object);
+
+        TimeUtilConverter converter(context);
+        long length = event->getEndTime() - event->getStartTime(); // in seconds only
+        LogDebug("event->getStartTime():"<< event->getStartTime() << ", length:" << length);
+        return converter.makeMillisecondDurationObject( length*1000 );
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyDuration(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr event = getPrivateObject(object);
+        TimeUtilConverter converter(context);
+        long length = converter.getDurationLength(value);
+        int unit = converter.getDurationUnit(value);
+        if (length < 0) {
+            TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
+            return false;
+        }
+        if( SECONDS_UNIT==unit ) {
+            event->setEndTime(event->getStartTime() + length);
+        } else if ( MINUTES_UNIT==unit ) {
+            event->setEndTime(event->getStartTime() + length*60);
+        } else if ( HOURS_UNIT==unit ) {
+            event->setEndTime(event->getStartTime() + length*60*60);
+        } else if ( DAYS_UNIT==unit ) {
+            event->setEndTime(event->getStartTime() + length*24*60*60);
+        } else if ( MSECS_UNIT==unit ) {
+            event->setEndTime(event->getStartTime() + length/1000);
+        } else {
+            TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR);
+            return false;
+        }
+
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyRecurrenceRule(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarItemPropertiesPrivObject *priv =
+            static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
+
+        CalendarEventPtr event = getPrivateObject(object);
+        EventRecurrenceRulePtr rrule;
+        if (event->getIsDetached()) {
+            LogDebug("This is a detached event.");
+            return JSValueMakeUndefined(context);
+        } else {
+            rrule = event->getRecurrenceRule();
+        }
+
+        if (EventRecurrenceRule::NO_RECURRENCE==rrule->getFrequency()) {
+            return JSValueMakeUndefined(context);
+        } else {
+            return JSCalendarRecurrenceRule::createJSCalendarRecurrenceRule(priv->getContext(), rrule);
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyRecurrenceRule(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    CalendarEventPtr event(NULL);
+    Try
+    {
+        event = getPrivateObject(object);
+        if (event->getIsDetached()) {
+            LogWarning("Can't set the recurrenceRule of a detached event!");
+            TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::NOT_SUPPORTED_ERROR);
+        }
+        event->setRecurrenceRule(JSCalendarRecurrenceRule::getPrivateObject(JSValueToObject(context, value, NULL)));
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyIsAllDay(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarConverter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        return converter.toJSValueRef(event->getIsAllDay());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyIsAllDay(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr event = getPrivateObject(object);
+        Converter converter(context);
+        event->setIsAllDay(converter.toBool(value));
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyAvailability(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarConverter converter(context);
+        CalendarEventPtr event = getPrivateObject(object);
+        std::string availability = converter.toTizenValue(event->getAvailability());
+        return converter.toJSValueRef(availability);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyAvailability(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    CalendarEventPtr event(NULL);
+    Try
+    {
+        event = getPrivateObject(object);
+        CalendarConverter converter(context);
+        CalendarEvent::EventAvailability availability =
+            converter.toEventAvailability(converter.toString(value));
+        event->setAvailability(availability);
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyAttendees(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr event = getPrivateObject(object);
+        EventAttendeeListPtr attendees = event->getAttendees();
+        if (attendees) {
+            JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+            if (NULL == jsResult) {
+                ThrowMsg(NullPointerException, "Can not create array object.");
+            }
+            for(unsigned int i=0; i<attendees->size(); i++) {
+                if (!JSSetArrayElement(context, jsResult, i, JSCalendarAttendee::createJSCalendarAttendee(context, attendees->at(i)))) {
+                   ThrowMsg(UnknownException, "Can not insert value into array.");
+                }
+            }
+            return jsResult;
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyAttendees(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr event = getPrivateObject(object);
+        CalendarConverter converter(context);
+        event->setAttendees(converter.toVectorOfAttendeesFromReference(value));
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyDueDate(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+        {
+        CalendarItemPropertiesPrivObject *privateObject =
+            static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
+        CalendarEventPtr task = privateObject->getObject();
+        if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
+            return JSValueMakeUndefined(context);
+        }
+        if (!task) {
+            ThrowMsg(NullPointerException, "Task object is NULL.");
+        }
+
+        if (UNDEFINED_TIME==task->getEndTime()) {
+            return JSValueMakeUndefined(context);
+        } else {
+            TimeUtilConverter timeConverter(context);
+            return timeConverter.toJSValueRefTZDate((double)(task->getEndTime()*1000.0), task->getTimeZone());
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyDueDate(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr task = getPrivateObject(object);
+        if (!task) {
+            ThrowMsg(NullPointerException, "Task object is NULL.");
+        }
+        if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
+            ThrowMsg(InvalidArgumentException, "Wrong type of calendar.");
+        }
+        if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        TimeUtilConverter converter(context);
+        long long int dueDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
+
+        task->setEndTime(dueDate);
+
+        if( task->getTimeZone().empty() ) {
+            std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
+            task->setTimeZone(timeZone);
+        }
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyCompletedDate(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarItemPropertiesPrivObject *privateObject =
+            static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
+        CalendarEventPtr task = privateObject->getObject();
+        if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
+            return JSValueMakeUndefined(context);
+        }
+        if (!task) {
+            ThrowMsg(NullPointerException, "Task object is NULL.");
+        }
+
+        if (UNDEFINED_TIME==task->getCompletedDate()) {
+            return JSValueMakeUndefined(context);
+        } else {
+            TimeUtilConverter timeConverter(context);
+            return timeConverter.toJSValueRefTZDate((double)(task->getCompletedDate()*1000.0), task->getTimeZone());
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyCompletedDate(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr task = getPrivateObject(object);
+        if (!task) {
+            ThrowMsg(NullPointerException, "Task object is NULL.");
+        }
+        if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
+            ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
+        }
+        if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        TimeUtilConverter converter(context);
+        long long int completedDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
+
+        task->setCompletedDate(completedDate);
+
+        if( task->getTimeZone().empty() ) {
+            std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
+            task->setTimeZone(timeZone);
+        }
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyProgress(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr task = getPrivateObject(object);
+        if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
+            return JSValueMakeUndefined(context);
+        }
+
+        Converter converter(context);
+        return converter.toJSValueRef(task->getProgress());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyProgress(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr task = getPrivateObject(object);
+        if(CalendarEvent::TASK_TYPE != task->getCalendarType()) {
+            return JSValueMakeUndefined(context);
+        }
+
+        Converter converter(context);
+        int progress = converter.toInt(value);
+        task->setProgress(progress);
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyPriority(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarConverter converter(context);
+        CalendarEventPtr item = getPrivateObject(object);
+        if (!item) {
+            ThrowMsg(NullPointerException, "Item object is NULL.");
+        }
+
+        std::string priority = converter.toTizenValue(item->getPriority());
+        return converter.toJSValueRef(priority);
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyPriority(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    CalendarEventPtr item = getPrivateObject(object);
+    Try
+    {
+        CalendarConverter converter(context);
+        CalendarEvent::TaskPriority priority =
+            converter.toTaskPriority(converter.toString(value));
+        item->setPriority(priority);
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+JSValueRef JSCalendarItemProperties::getPropertyEndDate(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarItemPropertiesPrivObject *privateObject =
+            static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
+        CalendarEventPtr event = privateObject->getObject();
+        if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
+            return JSValueMakeUndefined(context);
+        }
+        if (!event) {
+            ThrowMsg(NullPointerException, "Event object is NULL.");
+        }
+
+        if (UNDEFINED_TIME==event->getEndTime()) {
+            return JSValueMakeUndefined(context);
+        } else {
+            TimeUtilConverter timeConverter(context);
+            return timeConverter.toJSValueRefTZDate((double)(event->getEndTime()*1000.0), event->getTimeZone());
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarItemProperties::setPropertyEndDate(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarEventPtr event = getPrivateObject(object);
+        if (!event) {
+            ThrowMsg(NullPointerException, "Event object is NULL.");
+        }
+        if(CalendarEvent::EVENT_TYPE != event->getCalendarType()) {
+            ThrowMsg(InvalidArgumentException, "Wrong calendar type.");
+        }
+        if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        TimeUtilConverter converter(context);
+        long long int endDate = (long long int) (converter.getTimeInMilliseconds(value)/1000);
+
+        event->setEndTime(endDate);
+
+        if( event->getTimeZone().empty() ) {
+            std::string timeZone = converter.getPropertiesInTZDate(value).timezone;
+            event->setTimeZone(timeZone);
+        }
+        return true;
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+}
+
+bool JSCalendarItemProperties::validate(JSContextRef ctx,
+        const JSObjectRef object,
+        JSValueRef* exception)
+{
+    CalendarItemPropertiesPrivObject *priv =
+        static_cast<CalendarItemPropertiesPrivObject*>(JSObjectGetPrivate(object));
+    if (priv == NULL) {
+        return false;
+    }
+    CalendarEventPtr event = priv->getObject();
+    if (!event) {
+        return false;
+    }
+    return event->validate();
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Calendar/JSCalendarItemProperties.h b/src/standards/Tizen/Calendar/JSCalendarItemProperties.h
new file mode 100755 (executable)
index 0000000..b0e5053
--- /dev/null
@@ -0,0 +1,321 @@
+//
+// 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 _JS_CALENDAR_ITEM_PROPERTIES_H_
+#define _JS_CALENDAR_ITEM_PROPERTIES_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <API/Calendar/CalendarEvent.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+// Common CalendarItemProperties
+#define TIZEN_CALENDAR_ITEM_DESCRIPTION "description"
+#define TIZEN_CALENDAR_ITEM_SUMMARY "summary"
+#define TIZEN_CALENDAR_ITEM_IS_ALL_DAY "isAllDay"
+#define TIZEN_CALENDAR_ITEM_START_DATE "startDate"
+#define TIZEN_CALENDAR_ITEM_DURATION "duration"
+#define TIZEN_CALENDAR_ITEM_LOCATION "location"
+#define TIZEN_CALENDAR_ITEM_GEOLOCATION "geolocation"
+#define TIZEN_CALENDAR_ITEM_ORGANIZER "organizer"
+#define TIZEN_CALENDAR_ITEM_VISIBILITY "visibility"
+#define TIZEN_CALENDAR_ITEM_STATUS "status"
+#define TIZEN_CALENDAR_ITEM_PRIORITY  "priority"
+#define TIZEN_CALENDAR_ITEM_ALARMS "alarms"
+#define TIZEN_CALENDAR_ITEM_CATEGORIES "categories"
+#define TIZEN_CALENDAR_ITEM_ATTENDEES "attendees"
+
+// CalendarTaskProperties
+#define TIZEN_CALENDAR_TASK_DUE_DATE  "dueDate"
+#define TIZEN_CALENDAR_TASK_COMPLETED_DATE  "completedDate"
+#define TIZEN_CALENDAR_TASK_PROGRESS "progress"
+
+// CalendarEventProperties
+#define TIZEN_CALENDAR_EVENT_END_DATE  "endDate"
+#define TIZEN_CALENDAR_EVENT_AVAILABILITY "availability"
+#define TIZEN_CALENDAR_EVENT_RECURRENCE_RULE "recurrenceRule"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Calendar::CalendarEventPtr, 
+       WrtDeviceApis::CommonsJavaScript::NoOwnership> CalendarItemPropertiesPrivObject;
+
+class JSCalendarItemProperties
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+    static TizenApis::Api::Calendar::CalendarEventPtr getPrivateObject(JSObjectRef object);
+
+    static void setPrivateObject(const TizenApis::Api::Calendar::CalendarEventPtr &event,
+            JSContextRef ctx,
+            const JSObjectRef object);
+
+       static JSObjectRef createJSCalendarItemProperties(JSContextRef context, TizenApis::Api::Calendar::CalendarEventPtr geo);
+
+    static bool validate(JSContextRef ctx,
+            const JSObjectRef object,
+            JSValueRef* exception);
+
+  private:
+    /**
+     * 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;
+
+    /**
+     * 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);
+
+    /**
+     * Export a string from item
+     */
+    static JSValueRef convertToString(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Copy item object contents except id
+     */
+    static JSValueRef clone(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Getters and setters for properties
+     */
+    static JSValueRef getPropertyDescription(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyDescription(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertySummary(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertySummary(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyStartTime(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyStartTime(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyLocation(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyLocation(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyGeolocation(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyGeolocation(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyOrganizer(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyOrganizer(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyVisibility(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyVisibility(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyStatus(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyStatus(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyAlarms(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyAlarms(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyCategories(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyCategories(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyIsAllDay(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyIsAllDay(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyDuration(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyDuration(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyAttendees(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyAttendees(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyAvailability(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyAvailability(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyRecurrenceRule(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyRecurrenceRule(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyDueDate(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyDueDate(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyCompletedDate(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyCompletedDate(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyProgress(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyProgress(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyPriority(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyPriority(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static JSValueRef getPropertyEndDate(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static bool setPropertyEndDate(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+};
+
+}
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Calendar/JSCalendarManager.cpp b/src/standards/Tizen/Calendar/JSCalendarManager.cpp
new file mode 100755 (executable)
index 0000000..8e50f87
--- /dev/null
@@ -0,0 +1,351 @@
+//
+// 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 <string>
+#include <API/Calendar/ICalendar.h>
+#include <API/Calendar/ICalendarManager.h>
+#include <API/Calendar/CalendarFactory.h>
+
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "JSCalendarManager.h"
+#include "JSCalendar.h"
+#include "CalendarConverter.h"
+#include "CalendarResponseDispatcher.h"
+#include "plugin_config.h"
+
+#include "CalendarAsyncCallbackManager.h"
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+#define TIZEN_CALENDAR_MANAGER_ATTRIBUTENAME "calendar"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+JSClassDefinition JSCalendarManager::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_CALENDAR_MANAGER_ATTRIBUTENAME,
+    0,
+    NULL,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL  //ConvertToType
+};
+
+JSStaticFunction JSCalendarManager::m_function[] = {
+    { CALENDAR_FUNCTION_API_GET_CALENDARS,
+      getCalendars, kJSPropertyAttributeNone },
+
+    { CALENDAR_FUNCTION_API_GET_DEFAULT_CALENDAR,
+      getDefaultCalendar, kJSPropertyAttributeNone },
+
+    { CALENDAR_FUNCTION_API_GET_CALENDAR,
+      getCalendar, kJSPropertyAttributeNone },
+
+    { 0, 0, 0 }
+};
+
+JSClassRef JSCalendarManager::m_jsClassRef = JSClassCreate(
+        JSCalendarManager::getClassInfo());
+
+void JSCalendarManager::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogDebug("Create calendar manager private object.");
+        ICalendarManagerPtr calendarManager = CalendarFactory::getInstance().createCalendarManagerObject();
+        CalendarManagerPrivObject *privateObject = new CalendarManagerPrivObject(context, calendarManager);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(privateObject))) {
+            delete privateObject;
+        }
+    } else {
+        LogDebug("Private object already set.");
+    }
+}
+
+void JSCalendarManager::finalize(JSObjectRef object)
+{
+    CalendarManagerPrivObject *priv = static_cast<CalendarManagerPrivObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+JSValueRef JSCalendarManager::getCalendars(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarManagerPrivObject *privateObject =
+        static_cast<CalendarManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_GET_CALENDARS);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        CalendarConverter converter(context);
+
+        JSContextRef globalContext = privateObject->getContext();
+
+        JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
+
+        CalendarEvent::CalendarType calendarType = CalendarEvent::UNDEFINED_TYPE;
+        if (argumentCount>=1) {
+            calendarType = converter.toCalendarType(converter.toString(arguments[0]));
+        }
+
+        if (argumentCount>=2) {
+            cbm->setOnSuccess(converter.toFunction(arguments[1]));
+        } else {
+            ThrowMsg(ConversionException, "Wrong parameter count.");
+        }
+
+        if (argumentCount>=3) {
+            cbm->setOnError(converter.toFunctionOrNull(arguments[2]));
+        }
+
+               cbm->setObject(thisObject);
+
+        IEventGetCalendarsPtr dplEvent(new IEventGetCalendars());
+        dplEvent->setType(calendarType);
+        dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
+        dplEvent->setForAsynchronousCall(&CalendarResponseDispatcher::getInstance());
+        privateObject->getObject()->getCalendars(dplEvent);
+
+               CalendarAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+        return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSCalendarManager::getDefaultCalendar(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarManagerPrivObject *privateObject =
+        static_cast<CalendarManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_GET_DEFAULT_CALENDAR);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        JSContextRef globalContext = privateObject->getContext();
+
+        CalendarConverter converter(globalContext);
+        CalendarEvent::CalendarType calendarType = CalendarEvent::UNDEFINED_TYPE;
+        if (argumentCount>=1) {
+            calendarType = converter.toCalendarType(converter.toString(arguments[0]));
+        } else {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        IEventGetDefaultCalendarPtr dplEvent(new IEventGetDefaultCalendar());
+        dplEvent->setForSynchronousCall();
+        dplEvent->setType(calendarType);
+        privateObject->getObject()->getDefaultCalendar(dplEvent);
+
+        if (dplEvent->getResult()) {
+            if( dplEvent->getCalendar() ) {
+                return converter.toJSValueRefCalendar(dplEvent->getCalendar());
+            } else {
+                LogError("Default calendar not found.");
+            }
+        } else {
+            ThrowMsg(UnknownException, "Getting default calendar failed by unknown reason.");
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_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);
+}
+
+JSValueRef JSCalendarManager::getCalendar(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    CalendarManagerPrivObject *privateObject =
+        static_cast<CalendarManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = CALENDAR_CHECK_ACCESS(CALENDAR_FUNCTION_API_GET_CALENDAR);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        JSContextRef globalContext = privateObject->getContext();
+
+        CalendarConverter converter(globalContext);
+
+        CalendarEvent::CalendarType calendarType = CalendarEvent::UNDEFINED_TYPE;
+        if (argumentCount>=1) {
+            calendarType = converter.toCalendarType(converter.toString(arguments[0]));
+        } else {
+            ThrowMsg(ConversionException, "Wrong parameter count.");
+        }
+
+        std::string calendarId;
+        if (argumentCount>=2) {
+            calendarId = converter.toString(arguments[1]);
+        }
+
+        IEventGetCalendarPtr dplEvent(new IEventGetCalendar());
+        dplEvent->setForSynchronousCall();
+        dplEvent->setId(calendarId);
+        dplEvent->setType(calendarType);
+        privateObject->getObject()->getCalendar(dplEvent);
+
+        // Process the result.
+        if (dplEvent->getResult()) {
+            if( dplEvent->getCalendar() ) {
+                return converter.toJSValueRefCalendar(dplEvent->getCalendar());
+            } else {
+                ThrowMsg(NotFoundException, "Calendar not found.");
+            }
+        } else {
+            ThrowMsg(UnknownException, "Getting calendar failed by unknown reason.");
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+const JSClassRef JSCalendarManager::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSCalendarManager::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Calendar/JSCalendarManager.h b/src/standards/Tizen/Calendar/JSCalendarManager.h
new file mode 100755 (executable)
index 0000000..c2d824f
--- /dev/null
@@ -0,0 +1,165 @@
+//
+// 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 _JS_TIZEN_CALENDAR_MANAGER_H_
+#define _JS_TIZEN_CALENDAR_MANAGER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Calendar/ICalendarManager.h>
+#include <API/Calendar/ICalendar.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Calendar::ICalendarManagerPtr,
+                               WrtDeviceApis::CommonsJavaScript::NoOwnership> CalendarManagerPrivObject;
+
+#define TIZEN_CALENDAR_PROPERTY_VCALENDAR_20_FORMAT         "ICALENDAR_20"
+#define TIZEN_CALENDAR_PROPERTY_VCALENDAR_10_FORMAT         "VCALENDAR_10"
+
+#define TIZEN_CALENDAR_PROPERTY_TENTATIVE_STATUS        "TENTATIVE"
+#define TIZEN_CALENDAR_PROPERTY_CONFIRMED_STATUS        "CONFIRMED"
+#define TIZEN_CALENDAR_PROPERTY_CANCELLED_STATUS        "CANCELLED"
+#define TIZEN_CALENDAR_PROPERTY_NEEDS_ACTION_STATUS     "NEEDS_ACTION"
+#define TIZEN_CALENDAR_PROPERTY_IN_PROCESS_STATUS       "IN_PROCESS"
+#define TIZEN_CALENDAR_PROPERTY_COMPLETED_STATUS        "COMPLETED"
+#define TIZEN_CALENDAR_PROPERTY_PENDING_STATUS      "PENDING"
+#define TIZEN_CALENDAR_PROPERTY_ACCEPTED_STATUS     "ACCEPTED"
+#define TIZEN_CALENDAR_PROPERTY_DECLINED_STATUS     "DECLINED"
+#define TIZEN_CALENDAR_PROPERTY_DELEGATED_STATUS    "DELEGATED"
+
+#define TIZEN_CALENDAR_PROPERTY_HIGH_PRIORITY           "HIGH"
+#define TIZEN_CALENDAR_PROPERTY_MEDIUM_PRIORITY         "MEDIUM"
+#define TIZEN_CALENDAR_PROPERTY_LOW_PRIORITY            "LOW"
+
+#define TIZEN_CALENDAR_PROPERTY_PUBLIC_VISIBILITY           "PUBLIC"
+#define TIZEN_CALENDAR_PROPERTY_PRIVATE_VISIBILITY          "PRIVATE"
+#define TIZEN_CALENDAR_PROPERTY_CONFIDENTIAL_VISIBILITY     "CONFIDENTIAL"
+
+#define TIZEN_CALENDAR_PROPERTY_BUSY                    "BUSY"
+#define TIZEN_CALENDAR_PROPERTY_BUSY_UNAVAILABLE_FB     "BUSY_UNAVAILABLE"
+#define TIZEN_CALENDAR_PROPERTY_FREE                    "FREE"
+#define TIZEN_CALENDAR_PROPERTY_BUSY_TENTATIVE          "BUSY_TENTATIVE"
+
+#define TIZEN_CALENDAR_PROPERTY_REQ_PARTICIPANT_ROLE    "REQ_PARTICIPANT"
+#define TIZEN_CALENDAR_PROPERTY_OPT_PARTICIPANT_ROLE    "OPT_PARTICIPANT"
+#define TIZEN_CALENDAR_PROPERTY_NON_PARTICIPANT_ROLE    "NON_PARTICIPANT"
+#define TIZEN_CALENDAR_PROPERTY_CHAIR_ROLE              "CHAIR"
+
+#define TIZEN_CALENDAR_PROPERTY_INDIVIDUAL_TYPE     "INDIVIDUAL"
+#define TIZEN_CALENDAR_PROPERTY_GROUP_TYPE          "GROUP"
+#define TIZEN_CALENDAR_PROPERTY_RESOURCE_TYPE       "RESOURCE"
+#define TIZEN_CALENDAR_PROPERTY_ROOM_TYPE           "ROOM"
+#define TIZEN_CALENDAR_PROPERTY_UNKNOWN_TYPE        "UNKNOWN"
+
+//#define TIZEN_CALENDAR_PROPERTY_NO_RECURRENCE       "NO_RECURRENCE"
+#define TIZEN_CALENDAR_PROPERTY_DAILY_RECURRENCE    "DAILY"
+#define TIZEN_CALENDAR_PROPERTY_WEEKLY_RECURRENCE   "WEEKLY"
+#define TIZEN_CALENDAR_PROPERTY_MONTHLY_RECURRENCE  "MONTHLY"
+#define TIZEN_CALENDAR_PROPERTY_YEARLY_RECURRENCE   "YEARLY"
+
+//#define TIZEN_CALENDAR_PROPERTY_NO_ALARM            "NO_ALARM"
+#define TIZEN_CALENDAR_PROPERTY_DISPLAY_ALARM        "DISPLAY"
+#define TIZEN_CALENDAR_PROPERTY_SOUND_ALARM         "SOUND"
+
+#define TIZEN_CALENDAR_PROPERTY_TYPE_EVENT         "EVENT"
+#define TIZEN_CALENDAR_PROPERTY_TYPE_TASK         "TASK"
+
+class JSCalendarManager
+{
+  public:
+    enum TizenAlarmType
+    {
+        NO_ALARM = 0,
+        SILENT_ALARM = 1,
+        SOUND_ALARM = 2,
+        INVALID_ALARM = 10000
+    };
+    
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+
+  private:
+    /**
+     * 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[];
+
+    /**
+     * This structure contains properties and callbacks
+     * that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+    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);
+
+    /**
+     * Get Calendars.
+     */
+    static JSValueRef getCalendars(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Get a default calendar.
+     */
+    static JSValueRef getDefaultCalendar(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Get a calendar.
+     */
+    static JSValueRef getCalendar(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+};
+
+}
+}
+}
+#endif /* _JS_TIZEN_CALENDAR_MANAGER_H_ */
diff --git a/src/standards/Tizen/Calendar/JSCalendarRecurrenceRule.cpp b/src/standards/Tizen/Calendar/JSCalendarRecurrenceRule.cpp
new file mode 100755 (executable)
index 0000000..3e7bd88
--- /dev/null
@@ -0,0 +1,341 @@
+//
+// 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 "JSCalendarRecurrenceRule.h"
+#include <dpl/log/log.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <CommonsJavaScript/Converter.h>
+#include "CalendarConverter.h"
+#include <Tizen/TimeUtil/TimeUtilConverter.h>
+#include <Tizen/TimeUtil/JSTZDate.h>
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+JSClassDefinition JSCalendarRecurrenceRule::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_CALENDAR_RECURRENCE_RULE,
+    0,
+    m_property,
+    NULL, //m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL, //callAsFunction,
+    constructor,
+    NULL, //hasInstance,
+    NULL, //convertToType,
+};
+
+JSStaticValue JSCalendarRecurrenceRule::m_property[] = {
+    { TIZEN_RECURRENCE_RULE_FREQUENCY, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_RECURRENCE_RULE_INTERVAL, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_RECURRENCE_RULE_UNTIL_DATE, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_RECURRENCE_RULE_OCCURRENCE_COUNT, getProperty, setProperty, kJSPropertyAttributeNone },
+//    { TIZEN_RECURRENCE_RULE_DAYS_OF_THE_MONTH, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_RECURRENCE_RULE_DAYS_OF_THE_WEEK, getProperty, setProperty, kJSPropertyAttributeNone },
+//    { TIZEN_RECURRENCE_RULE_DAYS_OF_THE_YEAR, getProperty, setProperty, kJSPropertyAttributeNone },
+//    { TIZEN_RECURRENCE_RULE_WEEKS_OF_THE_YEAR, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_RECURRENCE_RULE_SET_POSITIONS, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_RECURRENCE_RULE_EXCEPTIONS, getProperty, setProperty, kJSPropertyAttributeNone },
+
+    { 0, 0, 0, 0 }
+};
+
+JSClassRef JSCalendarRecurrenceRule::m_jsClassRef = JSClassCreate(
+        JSCalendarRecurrenceRule::getClassInfo());
+
+const JSClassDefinition* JSCalendarRecurrenceRule::getClassInfo()
+{
+    return &(m_classInfo);
+}
+
+JSClassRef JSCalendarRecurrenceRule::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+JSObjectRef JSCalendarRecurrenceRule::createJSCalendarRecurrenceRule(JSContextRef context, EventRecurrenceRulePtr rule)
+{
+    RecurrenceRulePrivateObject *priv = new RecurrenceRulePrivateObject(context, rule);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+void JSCalendarRecurrenceRule::initialize(JSContextRef context, JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogDebug("Create calendar rrule private object.");
+        EventRecurrenceRulePtr rrule( new EventRecurrenceRule() );
+        RecurrenceRulePrivateObject *priv = new RecurrenceRulePrivateObject(context, rrule);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    } else {
+        LogDebug("Private object already set.");
+    }
+}
+
+void JSCalendarRecurrenceRule::finalize(JSObjectRef object)
+{
+    LogDebug("enter");
+    RecurrenceRulePrivateObject* priv = static_cast<RecurrenceRulePrivateObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+EventRecurrenceRulePtr JSCalendarRecurrenceRule::getPrivateObject(JSObjectRef object)
+{
+    RecurrenceRulePrivateObject *priv =
+        static_cast<RecurrenceRulePrivateObject*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        ThrowMsg(NullPointerException, "Private object is null.");
+    }
+    EventRecurrenceRulePtr result = priv->getObject();
+    if (!result) {
+        ThrowMsg(NullPointerException, "Private object is null.");
+    }
+    return result;
+}
+
+void JSCalendarRecurrenceRule::setPrivateObject(const EventRecurrenceRulePtr &rrule,
+        JSContextRef ctx,
+        const JSObjectRef object)
+{
+    Try
+    {
+        RecurrenceRulePrivateObject *priv =
+            static_cast<RecurrenceRulePrivateObject*>(JSObjectGetPrivate(object));
+        delete priv;
+        priv = new RecurrenceRulePrivateObject(ctx, rrule);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Error during replacing rrule object.");
+    }
+}
+
+JSObjectRef JSCalendarRecurrenceRule::constructor(JSContextRef context,
+    JSObjectRef constructor,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception)
+{
+    Try
+    {
+        CalendarConverter converter(context);
+        EventRecurrenceRulePtr rrule;
+
+        if (argumentCount==0) {
+            EventRecurrenceRulePtr result( new EventRecurrenceRule());
+            rrule = result;
+        } else if (argumentCount==1) {
+            EventRecurrenceRulePtr result( new EventRecurrenceRule());
+            rrule = result;
+            rrule->setFrequency(converter.toRecurrenceFrequency(converter.toString(arguments[0])));
+        } else if (argumentCount>=2) {
+            if (JSValueIsNull(context, arguments[1]) || JSValueIsUndefined(context, arguments[1])) {
+                EventRecurrenceRulePtr result( new EventRecurrenceRule());
+                rrule = result;
+            } else {
+                if (!JSValueIsObject(context, arguments[1])) {
+                    ThrowMsg(ConversionException, "Wrong second parameter type.");
+                }
+
+                rrule = converter.toEventRecurrenceRule(arguments[1]);
+                if (!rrule) {
+                    ThrowMsg(ConversionException, "Parameter conversion failed.");
+                }
+            }
+            rrule->setFrequency(converter.toRecurrenceFrequency(converter.toString(arguments[0])));
+        }
+
+        return createJSCalendarRecurrenceRule(context, rrule);
+    }
+    Catch(UnsupportedException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(ConversionException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+
+    return NULL;
+}
+
+JSValueRef JSCalendarRecurrenceRule::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("enter");
+    CalendarConverter converter(context);
+    TimeUtilConverter timeConverter(context);
+    Try
+    {
+        RecurrenceRulePrivateObject* priv =
+            static_cast<RecurrenceRulePrivateObject*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            ThrowMsg(NullPointerException, "Private object is NULL.");
+        }
+        EventRecurrenceRulePtr rrule = priv->getObject();
+        if (!rrule) {
+            ThrowMsg(NullPointerException, "recurrenceRule is NULL.");
+        }
+
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_FREQUENCY)) {
+            return converter.toJSValueRef(converter.toTizenValue(rrule->getFrequency()));
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_INTERVAL)) {
+            return converter.toJSValueRef(rrule->getInterval());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_UNTIL_DATE)) {
+            if (UNDEFINED_TIME==rrule->getEndDate()) {
+                return JSValueMakeNull(context);
+            } else {
+                return timeConverter.toJSValueRefTZDate((double)(rrule->getEndDate()*1000.0), rrule->getTimeZone());
+            }
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_OCCURRENCE_COUNT)) {
+            return converter.toJSValueRefLong(rrule->getOccurrenceCount());
+        //} 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)) {
+           return converter.toJSValueRef(rrule->getDaysOfTheWeek());
+        //} else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_DAYS_OF_THE_YEAR)) {
+            //return converter.toJSValueRef(rrule->getDaysOfTheYear());
+        //} else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_WEEKS_OF_THE_YEAR)) {
+            //return converter.toJSValueRef(rrule->getWeeksOfTheYear());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_SET_POSITIONS)) {
+            return converter.toJSValueRefNumberArray(rrule->getSetPositions());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_EXCEPTIONS)) {
+            return converter.toJSValueRefTZDateArray(rrule->getExceptions());
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarRecurrenceRule::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    CalendarConverter converter(context);
+    Try
+    {
+        RecurrenceRulePrivateObject* priv =
+            static_cast<RecurrenceRulePrivateObject*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            ThrowMsg(NullPointerException, "Private object is NULL.");
+        }
+        EventRecurrenceRulePtr rrule = priv->getObject();
+
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_FREQUENCY)) {
+            std::string frequency = converter.toString(value);
+            rrule->setFrequency(converter.toRecurrenceFrequency(frequency));
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_INTERVAL)) {
+            int interval = converter.toInt(value);
+            rrule->setInterval(interval);
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_UNTIL_DATE)) {
+            if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) {
+                ThrowMsg(ConversionException, "Wrong untilDate type.");
+            }
+            TimeUtilConverter timeConverter(context);
+            long long int untilDate = (long long int) (timeConverter.getTimeInMilliseconds(value)/1000);
+            rrule->setEndDate(untilDate);
+/*
+            if( rrule->getTimeZone().empty() ) {
+                std::string timeZone = timeConverter.getPropertiesInTZDate(value).timezone;
+                rrule->setTimeZone(timeZone);
+            }
+*/
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_OCCURRENCE_COUNT)) {
+            long occurrenceCount = converter.toLong(value);
+            rrule->setOccurrenceCount(occurrenceCount);
+            return true;
+        /*} else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_DAYS_OF_THE_MONTH)) {
+            std::vector<int> daysOfTheMonth = converter.toVectorOfInts(value);
+            rrule->setDaysOfTheMonth(daysOfTheMonth);
+            return true;*/
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_DAYS_OF_THE_WEEK)) {
+            rrule->setDaysOfTheWeek(converter.toStringArray(value));
+            return true;
+        /*} else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_DAYS_OF_THE_YEAR)) {
+            std::vector<int> daysOfTheYear = converter.toVectorOfInts(value);
+            rrule->setDaysOfTheYear(daysOfTheYear);
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_WEEKS_OF_THE_YEAR)) {
+            std::vector<int> weekOfTheYear = converter.toVectorOfInts(value);
+            rrule->setWeeksOfTheYear(weekOfTheYear);
+            return true;*/
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_SET_POSITIONS)) {
+            rrule->setSetPositions(converter.toNumberArray(value));
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_EXCEPTIONS)) {
+            rrule->setExceptions(converter.toTZDateArray(value));
+            return true;
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR);
+    return false;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Calendar/JSCalendarRecurrenceRule.h b/src/standards/Tizen/Calendar/JSCalendarRecurrenceRule.h
new file mode 100755 (executable)
index 0000000..3e06fca
--- /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.
+//
+
+
+#ifndef _JS_CALENDAR_RECURRENCE_RULE_H_
+#define _JS_CALENDAR_RECURRENCE_RULE_H_
+
+#include <string>
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Calendar/CalendarEvent.h>
+#include <API/Calendar/EventRecurrenceRule.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+#define TIZEN_INTERFACE_CALENDAR_RECURRENCE_RULE "CalendarRecurrenceRule"
+
+#define TIZEN_RECURRENCE_RULE_FREQUENCY "frequency"
+#define TIZEN_RECURRENCE_RULE_INTERVAL "interval"
+#define TIZEN_RECURRENCE_RULE_UNTIL_DATE "untilDate"
+#define TIZEN_RECURRENCE_RULE_OCCURRENCE_COUNT "occurrenceCount"
+//#define TIZEN_RECURRENCE_RULE_DAYS_OF_THE_MONTH "daysOfTheMonth"
+#define TIZEN_RECURRENCE_RULE_DAYS_OF_THE_WEEK "daysOfTheWeek"
+//#define TIZEN_RECURRENCE_RULE_DAYS_OF_THE_YEAR "daysOfTheYear"
+//#define TIZEN_RECURRENCE_RULE_WEEKS_OF_THE_YEAR "weeksOfTheYear"
+#define TIZEN_RECURRENCE_RULE_SET_POSITIONS "setPositions"
+#define TIZEN_RECURRENCE_RULE_EXCEPTIONS "exceptions"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Calendar::EventRecurrenceRulePtr,
+       WrtDeviceApis::CommonsJavaScript::NoOwnership> RecurrenceRulePrivateObject;
+
+class JSCalendarRecurrenceRule
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static JSClassRef getClassRef();
+
+    static JSObjectRef createJSCalendarRecurrenceRule(JSContextRef context, TizenApis::Api::Calendar::EventRecurrenceRulePtr rule);
+
+    static TizenApis::Api::Calendar::EventRecurrenceRulePtr getPrivateObject(JSObjectRef object);
+
+    static void setPrivateObject(const TizenApis::Api::Calendar::EventRecurrenceRulePtr &rrule,
+            JSContextRef ctx,
+            const JSObjectRef object);
+
+  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);
+
+       /**
+        * Constructor for the CalendarRecurrenceRule interface.
+        */
+       static JSObjectRef constructor(JSContextRef context,
+                   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 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 /* _JS_CALENDAR_RECURRENCE_RULE_H_ */
diff --git a/src/standards/Tizen/Calendar/JSCalendarTask.cpp b/src/standards/Tizen/Calendar/JSCalendarTask.cpp
new file mode 100755 (executable)
index 0000000..3c95ec8
--- /dev/null
@@ -0,0 +1,312 @@
+//
+// 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 <ctime>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <API/Calendar/EventId.h>
+#include <API/Calendar/ICalendar.h>
+#include <API/Calendar/CalendarFactory.h>
+#include "JSCalendarTask.h"
+#include "JSCalendarItemProperties.h"
+#include "CalendarConverter.h"
+#include "JSCalendarEventId.h"
+#include <Tizen/TimeUtil/TimeUtilConverter.h>
+#include <Tizen/TimeUtil/JSTZDate.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+
+using namespace TizenApis::Api::Calendar;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+JSClassDefinition JSCalendarTask::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_INTERFACE_CALENDAR_TASK,
+    JSCalendarItemProperties::getClassRef(),
+    m_property,
+    NULL, //m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    constructor,
+    NULL, //HasInstance,
+    NULL  //ConvertToType
+};
+
+JSStaticValue JSCalendarTask::m_property[] = {
+    //Task properties
+    { TIZEN_CALENDAR_TASK_ID, getPropertyId,
+      NULL, kJSPropertyAttributeReadOnly },
+    { TIZEN_CALENDAR_TASK_LAST_MODIFICATION_DATE, getPropertyLastModificationDate,
+      NULL, kJSPropertyAttributeReadOnly },
+
+    { 0, 0, 0, 0 }
+};
+
+JSClassRef JSCalendarTask::m_jsClassRef = JSClassCreate(JSCalendarTask::getClassInfo());
+
+ICalendarPtr JSCalendarTask::m_calendar = CalendarFactory::getInstance().createCalendarObject();
+
+void JSCalendarTask::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogDebug("Create calendar task private object.");
+        CalendarEventPtr task( new CalendarEvent() );
+        CalendarTaskPrivObject *priv = new CalendarTaskPrivObject(context, task);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    } else {
+        LogDebug("Private object already set.");
+    }
+
+    if (m_calendar) {
+        m_calendar->setType(CalendarEvent::TASK_TYPE);
+        LogDebug("Calendar object type is set to task.");
+    }
+}
+
+void JSCalendarTask::finalize(JSObjectRef object)
+{
+    CalendarTaskPrivObject* priv = static_cast<CalendarTaskPrivObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+JSObjectRef JSCalendarTask::constructor(JSContextRef context,
+    JSObjectRef constructor,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception)
+{
+    Try
+    {
+        CalendarConverter converter(context);
+        CalendarEventPtr task;
+
+        if (argumentCount==0) {
+            CalendarEventPtr result(new CalendarEvent());
+            task = result;
+        } else if (argumentCount==1) {
+            LogInfo("taskInitDict case");
+            if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) {
+                CalendarEventPtr result(new CalendarEvent());
+                task = result;
+            } else if (JSValueIsObject(context, arguments[0])) {
+                task = converter.toEvent(arguments[0]);
+                if (!task) {
+                    ThrowMsg(ConversionException, "Parameter conversion failed.");
+                }
+            } else {
+                ThrowMsg(ConversionException, "Parameter conversion failed.");
+            }
+        } else if (argumentCount>=2) {
+            LogInfo("task stringRepresentation case");
+            std::string eventStr;
+            CalendarEvent::VObjectFormat format = CalendarEvent::UNDEFINED_FORMAT;
+            eventStr = converter.toString(arguments[0]);
+            format = converter.toVObjectFormat(converter.toString(arguments[1]));
+
+            IEventCreateEventFromStringPtr dplEvent(new IEventCreateEventFromString());
+            dplEvent->setEventString(eventStr);
+            dplEvent->setFormat(format);
+            dplEvent->setForSynchronousCall();
+            m_calendar->createEventFromString(dplEvent);
+
+            // Process the returned object.
+            if (dplEvent->getResult()) {
+                LogInfo("Successfully created a task.");
+                task = dplEvent->getEvent();
+            } else {
+                if (dplEvent->getExceptionCode()==ExceptionCodes::InvalidArgumentException) {
+                    ThrowMsg(InvalidArgumentException, "Wrong string to convert.");
+                } else {
+                    ThrowMsg(UnknownException, "Converting string failed.");
+                }
+            }
+        }
+
+        task->setCalendarType(CalendarEvent::TASK_TYPE);
+        return createJSCalendarTask(context, task);
+    }
+    Catch(UnsupportedException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(ConversionException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+
+    return NULL;
+}
+
+JSObjectRef JSCalendarTask::createJSCalendarTask(JSContextRef context, CalendarEventPtr task)
+{
+    CalendarTaskPrivObject *priv = new CalendarTaskPrivObject(context, task);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassRef JSCalendarTask::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSCalendarTask::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+CalendarEventPtr JSCalendarTask::getPrivateObject(JSObjectRef object)
+{
+    CalendarTaskPrivObject *priv =
+        static_cast<CalendarTaskPrivObject*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    CalendarEventPtr result = priv->getObject();
+    if (!result) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    return result;
+}
+
+void JSCalendarTask::setPrivateObject(const CalendarEventPtr &event,
+        JSContextRef ctx,
+        const JSObjectRef object)
+{
+    Try
+    {
+        CalendarTaskPrivObject *priv =
+            static_cast<CalendarTaskPrivObject*>(JSObjectGetPrivate(object));
+        delete priv;
+        priv = new CalendarTaskPrivObject(ctx, event);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Error during replacing task object");
+    }
+}
+
+JSValueRef JSCalendarTask::getPropertyId(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarTaskPrivObject *privateObject =
+            static_cast<CalendarTaskPrivObject*>(JSObjectGetPrivate(object));
+        CalendarEventPtr task = privateObject->getObject();
+
+        if (task->getUId()==UNDEFINED_ID) {
+            return JSValueMakeNull(context);
+        } else {
+            return Converter(context).toJSValueRef(task->getUId());
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCalendarTask::getPropertyLastModificationDate(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        CalendarTaskPrivObject *privateObject =
+            static_cast<CalendarTaskPrivObject*>(JSObjectGetPrivate(object));
+        CalendarEventPtr task = privateObject->getObject();
+        if (!task) {
+            ThrowMsg(NullPointerException, "Task object is NULL.");
+        }
+
+        if (UNDEFINED_TIME==task->getLastModifiedDate()) {
+            return JSValueMakeNull(context);
+        } else {
+            TimeUtilConverter timeConverter(context);
+            return timeConverter.toJSValueRefTZDate((double)(task->getLastModifiedDate()*1000.0), task->getTimeZone());
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSCalendarTask::validate(JSContextRef ctx,
+        const JSObjectRef object,
+        JSValueRef* exception)
+{
+    CalendarTaskPrivObject *priv =
+        static_cast<CalendarTaskPrivObject*>(JSObjectGetPrivate(object));
+    if (priv == NULL) {
+        return false;
+    }
+    CalendarEventPtr event = priv->getObject();
+    if (!event) {
+        return false;
+    }
+    return event->validate();
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Calendar/JSCalendarTask.h b/src/standards/Tizen/Calendar/JSCalendarTask.h
new file mode 100755 (executable)
index 0000000..37edc22
--- /dev/null
@@ -0,0 +1,121 @@
+//
+// 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 _JS_CALENDAR_TASK_H_
+#define _JS_CALENDAR_TASK_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <API/Calendar/CalendarEvent.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+#define TIZEN_INTERFACE_CALENDAR_TASK "CalendarTask"
+
+#define TIZEN_CALENDAR_TASK_ID "id"
+#define TIZEN_CALENDAR_TASK_LAST_MODIFICATION_DATE "lastModificationDate"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Calendar::CalendarEventPtr,
+       WrtDeviceApis::CommonsJavaScript::NoOwnership> CalendarTaskPrivObject;
+
+class JSCalendarTask
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+    static TizenApis::Api::Calendar::CalendarEventPtr getPrivateObject(JSObjectRef object);
+
+    static void setPrivateObject(const TizenApis::Api::Calendar::CalendarEventPtr &event,
+            JSContextRef ctx,
+            const JSObjectRef object);
+
+    static bool validate(JSContextRef ctx,
+            const JSObjectRef object,
+            JSValueRef* exception);
+
+       static JSObjectRef createJSCalendarTask(JSContextRef context, TizenApis::Api::Calendar::CalendarEventPtr task);
+
+  private:
+    /**
+     * 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;
+
+       /**
+        * The calendar object to be used for asynchronous platform function invocation.
+        */
+       static TizenApis::Api::Calendar::ICalendarPtr m_calendar;
+
+    /**
+     * 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);
+
+       /**
+        * Constructor for the CalendarTask interface.
+        */
+       static JSObjectRef constructor(JSContextRef context,
+    JSObjectRef constructor,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception);
+
+    /**
+     * Getters and setters for properties
+     */
+    static JSValueRef getPropertyId(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getPropertyLastModificationDate(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+};
+
+}
+}
+}
+
+#endif /* _JS_CALENDAR_TASK_H_ */
diff --git a/src/standards/Tizen/Calendar/JSNumberArray.cpp b/src/standards/Tizen/Calendar/JSNumberArray.cpp
new file mode 100755 (executable)
index 0000000..cd41ceb
--- /dev/null
@@ -0,0 +1,598 @@
+//
+// 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 <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <CommonsJavaScript/Converter.h>
+#include "JSNumberArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+using namespace TizenApis::Api::Calendar;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSNumberArray::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 JSNumberArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSNumberArray::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 JSNumberArray::m_jsClassRef = JSClassCreate(
+               JSNumberArray::getClassInfo());
+
+JSValueRef JSNumberArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               NumberArrayPtr numbers = priv->getObject();
+               if (numbers) {
+                       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(numbers->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSNumberArray::createArray(JSContextRef context,
+               const NumberArrayPtr &numbers)
+{
+       JSNumberArrayPriv *priv = new JSNumberArrayPriv(context, numbers);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSNumberArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSNumberArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+bool JSNumberArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+NumberArrayPtr JSNumberArray::getNumberArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSNumberArrayPriv* priv = static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSNumberArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSNumberArray::finalize(JSObjectRef object)
+{
+       JSNumberArrayPriv* priv =
+               static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSNumberArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               NumberArrayPtr numbers = priv->getObject();
+               if (index < numbers->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSNumberArray::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);
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               NumberArrayPtr numbers = priv->getObject();
+               if (index < numbers->size()) {
+                       long long int result = numbers->at(index);
+            LogInfo("index: "<<index<<", result: "<<result);
+            return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSNumberArray::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);
+               long long int number = 0;
+               if (!JSValueIsUndefined(context, value)) {
+                       number = converter->toLongLong(value);
+               }
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               NumberArrayPtr numbers = priv->getObject();
+               if (!numbers) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (numbers->size() <= index) {
+                       numbers->resize(index + 1);
+               }
+               (*numbers)[index] = number;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSNumberArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+    Converter converter(context);
+
+       Try
+       {
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               NumberArrayPtr numbers = priv->getObject();
+
+               int count = numbers->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 JSNumberArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               NumberArrayPtr numbers = NumberArrayPtr(new NumberArray());
+               JSNumberArrayPriv *newPrivateObject = new JSNumberArrayPriv(
+                               context,
+                               numbers);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current numbers
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               for (size_t i = 0; i < currentNumbers->size(); ++i) {
+                       numbers->push_back(currentNumbers->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 numbers
+                       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);
+                               numbers->push_back(converter->toLong(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSNumberArray::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);
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               if (argumentCount > 0 && JSValueIsNumber(context, arguments[0])) {
+                       separator = converter->toLong(arguments[0]);
+               }
+               for (size_t i = 0; i < currentNumbers->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       result += currentNumbers->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 JSNumberArray::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);
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               if (currentNumbers->size() > 0) {
+                       long long int result = currentNumbers->at(
+                                       currentNumbers->size() - 1);
+                       currentNumbers->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNumberArray::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);
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentNumbers->push_back(converter->toLong(arguments[i]));
+               }
+               return converter->toJSValueRef(currentNumbers->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSNumberArray::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);
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               std::reverse(currentNumbers->begin(), currentNumbers->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNumberArray::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);
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               if (currentNumbers->size() > 0) {
+                       long long int result = currentNumbers->at(0);
+                       currentNumbers->erase(currentNumbers->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNumberArray::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);
+               NumberArrayPtr numbers = NumberArrayPtr(new NumberArray());
+               JSNumberArrayPriv *newPrivateObject = new JSNumberArrayPriv(
+                               context,
+                               numbers);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current numbers
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentNumbers->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentNumbers->size()) {
+                               last = currentNumbers->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       numbers->push_back(currentNumbers->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSNumberArray::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);
+               JSNumberArrayPriv* priv =
+                       static_cast<JSNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               std::sort(currentNumbers->begin(), currentNumbers->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNumberArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNumberArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSNumberArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNumberArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Calendar
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Calendar/JSNumberArray.h b/src/standards/Tizen/Calendar/JSNumberArray.h
new file mode 100755 (executable)
index 0000000..93861ca
--- /dev/null
@@ -0,0 +1,183 @@
+//
+// 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_CALENDAR_JS_NUMBER_ARRAY_H_
+#define _TIZEN_CALENDAR_JS_NUMBER_ARRAY_H_
+
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Calendar/CalendarEvent.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Calendar::NumberArrayPtr>::Type JSNumberArrayPriv;
+
+class JSNumberArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Calendar::NumberArrayPtr &Numbers);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Calendar::NumberArrayPtr getNumberArray(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 long long int &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[];
+};
+
+} // Calendar
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CALENDAR_JS_NUMBER_ARRAY_H_
diff --git a/src/standards/Tizen/Calendar/JSStringArray.cpp b/src/standards/Tizen/Calendar/JSStringArray.cpp
new file mode 100755 (executable)
index 0000000..40a0c57
--- /dev/null
@@ -0,0 +1,597 @@
+//
+// 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 <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "CalendarConverter.h"
+#include "JSStringArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+using namespace TizenApis::Api::Calendar;
+using namespace TizenApis::Commons;
+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);
+               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);
+               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)
+{
+    CalendarConverter converter(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);
+}
+
+} // Calendar
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Calendar/JSStringArray.h b/src/standards/Tizen/Calendar/JSStringArray.h
new file mode 100755 (executable)
index 0000000..c63628b
--- /dev/null
@@ -0,0 +1,182 @@
+//
+// 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_CALENDAR_JS_STRING_ARRAY_H_
+#define _TIZEN_CALENDAR_JS_STRING_ARRAY_H_
+
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Calendar/CalendarEvent.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Calendar::StringArrayPtr>::Type JSStringArrayPriv;
+
+class JSStringArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Calendar::StringArrayPtr &Strings);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Calendar::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[];
+};
+
+} // Calendar
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CALENDAR_JS_STRING_ARRAY_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/Calendar/JSTZDateArray.cpp b/src/standards/Tizen/Calendar/JSTZDateArray.cpp
new file mode 100755 (executable)
index 0000000..590f63d
--- /dev/null
@@ -0,0 +1,602 @@
+//
+// 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 <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <CommonsJavaScript/Converter.h>
+#include "JSTZDateArray.h"
+#include <Tizen/TimeUtil/TimeUtilConverter.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 TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+using namespace TizenApis::Api::Calendar;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSTZDateArray::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 JSTZDateArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSTZDateArray::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 JSTZDateArray::m_jsClassRef = JSClassCreate(
+               JSTZDateArray::getClassInfo());
+
+JSValueRef JSTZDateArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               NumberArrayPtr numbers = priv->getObject();
+               if (numbers) {
+                       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(numbers->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSTZDateArray::createArray(JSContextRef context,
+               const NumberArrayPtr &numbers)
+{
+       JSTZDateArrayPriv *priv = new JSTZDateArrayPriv(context, numbers);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSTZDateArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSTZDateArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+bool JSTZDateArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+NumberArrayPtr JSTZDateArray::getTZDateArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSTZDateArrayPriv* priv = static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSTZDateArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSTZDateArray::finalize(JSObjectRef object)
+{
+       JSTZDateArrayPriv* priv =
+               static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSTZDateArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               NumberArrayPtr numbers = priv->getObject();
+               if (index < numbers->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSTZDateArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+    TimeUtilConverter timeConverter(context);
+
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               NumberArrayPtr numbers = priv->getObject();
+               if (index < numbers->size()) {
+                       long long int result = numbers->at(index);
+            LogInfo("index: "<<index<<", result: "<<result);
+            return timeConverter.toJSValueRefTZDate((double)(result*1000.0), "");
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSTZDateArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+    TimeUtilConverter timeConverter(context);
+
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               long long int number = 0;
+               if (!JSValueIsUndefined(context, value)) {
+                       number = timeConverter.getTimeInMilliseconds(value)/1000;
+               }
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               NumberArrayPtr numbers = priv->getObject();
+               if (!numbers) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (numbers->size() <= index) {
+                       numbers->resize(index + 1);
+               }
+               (*numbers)[index] = number;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSTZDateArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+    Converter converter(context);
+
+       Try
+       {
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               NumberArrayPtr numbers = priv->getObject();
+
+               int count = numbers->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 JSTZDateArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               NumberArrayPtr numbers = NumberArrayPtr(new NumberArray());
+               JSTZDateArrayPriv *newPrivateObject = new JSTZDateArrayPriv(
+                               context,
+                               numbers);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current numbers
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               for (size_t i = 0; i < currentNumbers->size(); ++i) {
+                       numbers->push_back(currentNumbers->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 numbers
+                       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);
+                               numbers->push_back(converter->toLong(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSTZDateArray::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);
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               if (argumentCount > 0 && JSValueIsNumber(context, arguments[0])) {
+                       separator = converter->toLong(arguments[0]);
+               }
+               for (size_t i = 0; i < currentNumbers->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       result += currentNumbers->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 JSTZDateArray::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);
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               if (currentNumbers->size() > 0) {
+                       long long int result = currentNumbers->at(
+                                       currentNumbers->size() - 1);
+                       currentNumbers->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSTZDateArray::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);
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentNumbers->push_back(converter->toLong(arguments[i]));
+               }
+               return converter->toJSValueRef(currentNumbers->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSTZDateArray::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);
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               std::reverse(currentNumbers->begin(), currentNumbers->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSTZDateArray::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);
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               if (currentNumbers->size() > 0) {
+                       long long int result = currentNumbers->at(0);
+                       currentNumbers->erase(currentNumbers->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSTZDateArray::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);
+               NumberArrayPtr numbers = NumberArrayPtr(new NumberArray());
+               JSTZDateArrayPriv *newPrivateObject = new JSTZDateArrayPriv(
+                               context,
+                               numbers);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current numbers
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentNumbers->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentNumbers->size()) {
+                               last = currentNumbers->size() - 1;
+                       }
+               }
+
+               for (size_t i = first; i <= last; ++i) {
+                       numbers->push_back(currentNumbers->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSTZDateArray::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);
+               JSTZDateArrayPriv* priv =
+                       static_cast<JSTZDateArrayPriv*>(JSObjectGetPrivate(thisObject));
+               NumberArrayPtr currentNumbers = priv->getObject();
+               std::sort(currentNumbers->begin(), currentNumbers->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSTZDateArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSTZDateArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSTZDateArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSTZDateArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Calendar
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Calendar/JSTZDateArray.h b/src/standards/Tizen/Calendar/JSTZDateArray.h
new file mode 100755 (executable)
index 0000000..12e2c99
--- /dev/null
@@ -0,0 +1,183 @@
+//
+// 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_CALENDAR_JS_TZDATE_ARRAY_H_
+#define _TIZEN_CALENDAR_JS_TZDATE_ARRAY_H_
+
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Calendar/CalendarEvent.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Calendar::NumberArrayPtr>::Type JSTZDateArrayPriv;
+
+class JSTZDateArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Calendar::NumberArrayPtr &Numbers);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Calendar::NumberArrayPtr getTZDateArray(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 long long int &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[];
+};
+
+} // Calendar
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CALENDAR_JS_TZDATE_ARRAY_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/Calendar/config.xml b/src/standards/Tizen/Calendar/config.xml
new file mode 100755 (executable)
index 0000000..ca8b2e0
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+    <library-name>libwrt-plugins-tizen-2.0-calendar.so</library-name>
+    <feature-install-uri>calendar.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/calendar.read</name>
+        <device-capability>calendar.read</device-capability>
+    </api-feature>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/calendar.write</name>
+        <device-capability>calendar.write</device-capability>
+    </api-feature>
+
+</plugin-properties>
\ No newline at end of file
diff --git a/src/standards/Tizen/Calendar/plugin_config.cpp b/src/standards/Tizen/Calendar/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..f3cd9e6
--- /dev/null
@@ -0,0 +1,258 @@
+//
+// 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 CALENDAR_FEATURE_API_READ  "http://tizen.org/privilege/calendar.read"
+#define CALENDAR_FEATURE_API_WRITE "http://tizen.org/privilege/calendar.write"
+
+#define CALENDAR_DEVICE_CAP_READ "calendar.read"
+#define CALENDAR_DEVICE_CAP_WRITE "calendar.write"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+static FunctionMapping createCalendarFunctions();
+
+static FunctionMapping CalendarFunctions = createCalendarFunctions();
+
+DEFINE_FUNCTION_GETTER(Calendar, CalendarFunctions);
+
+static FunctionMapping createCalendarFunctions()
+{
+    /**
+     * Device capabilities
+     */
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_CALENDAR_READ, CALENDAR_DEVICE_CAP_READ);
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_CALENDAR_WRITE, CALENDAR_DEVICE_CAP_WRITE);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_CALENDAR_READ);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_CALENDAR_READ, DEVICE_CAP_CALENDAR_READ);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_CALENDAR_WRITE);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_CALENDAR_WRITE, DEVICE_CAP_CALENDAR_WRITE);
+
+    /**
+     * Api Features
+     */
+    ACE_CREATE_FEATURE(FEATURE_CALENDAR_READ, CALENDAR_FEATURE_API_READ);
+    ACE_CREATE_FEATURE(FEATURE_CALENDAR_WRITE, CALENDAR_FEATURE_API_WRITE);
+
+    ACE_CREATE_FEATURE_LIST(CALENDAR_FEATURES_CALENDAR_READ);
+    ACE_ADD_API_FEATURE(CALENDAR_FEATURES_CALENDAR_READ, FEATURE_CALENDAR_READ);
+
+    ACE_CREATE_FEATURE_LIST(CALENDAR_FEATURES_CALENDAR_WRITE);
+    ACE_ADD_API_FEATURE(CALENDAR_FEATURES_CALENDAR_WRITE, FEATURE_CALENDAR_WRITE);
+
+    /**
+     * Functions
+     */
+    FunctionMapping calendarMapping;
+
+    //getCalendars
+    AceFunction getCalendarsFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_CALENDARS,
+            CALENDAR_FUNCTION_API_GET_CALENDARS,
+            CALENDAR_FEATURES_CALENDAR_READ,
+            DEVICE_LIST_CALENDAR_READ);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_GET_CALENDARS,
+                               getCalendarsFunc));
+
+    //getDefaultCalendar
+    AceFunction getDefaultCalendarFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_DEFAULT_CALENDAR,
+            CALENDAR_FUNCTION_API_GET_DEFAULT_CALENDAR,
+            CALENDAR_FEATURES_CALENDAR_READ,
+            DEVICE_LIST_CALENDAR_READ);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_GET_DEFAULT_CALENDAR,
+                               getDefaultCalendarFunc));
+
+    //getCalendar
+    AceFunction getCalendarFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_CALENDAR,
+            CALENDAR_FUNCTION_API_GET_CALENDAR,
+            CALENDAR_FEATURES_CALENDAR_READ,
+            DEVICE_LIST_CALENDAR_READ);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_GET_CALENDAR,
+                               getCalendarFunc));
+
+    //find
+    AceFunction findFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_FIND,
+            CALENDAR_FUNCTION_API_FIND,
+            CALENDAR_FEATURES_CALENDAR_READ,
+            DEVICE_LIST_CALENDAR_READ);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_FIND,
+                               findFunc));
+
+    //add
+    AceFunction addFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADD,
+            CALENDAR_FUNCTION_API_ADD,
+            CALENDAR_FEATURES_CALENDAR_WRITE,
+            DEVICE_LIST_CALENDAR_WRITE);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_ADD,
+                               addFunc));
+
+    //addBatch
+    AceFunction addBatchFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADD_BATCH,
+            CALENDAR_FUNCTION_API_ADD_BATCH,
+            CALENDAR_FEATURES_CALENDAR_WRITE,
+            DEVICE_LIST_CALENDAR_WRITE);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_ADD_BATCH,
+                               addBatchFunc));
+
+    //update
+    AceFunction updateFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_UPDATE,
+            CALENDAR_FUNCTION_API_UPDATE,
+            CALENDAR_FEATURES_CALENDAR_WRITE,
+            DEVICE_LIST_CALENDAR_WRITE);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_UPDATE,
+                               updateFunc));
+
+    //updateBatch
+    AceFunction updateBatchFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_UPDATE_BATCH,
+            CALENDAR_FUNCTION_API_UPDATE_BATCH,
+            CALENDAR_FEATURES_CALENDAR_WRITE,
+            DEVICE_LIST_CALENDAR_WRITE);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_UPDATE_BATCH,
+                               updateBatchFunc));
+
+    //remove
+    AceFunction removeFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_REMOVE,
+            CALENDAR_FUNCTION_API_REMOVE,
+            CALENDAR_FEATURES_CALENDAR_WRITE,
+            DEVICE_LIST_CALENDAR_WRITE);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_REMOVE,
+                               removeFunc));
+
+    //removeBatch
+    AceFunction removeBatchFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_REMOVE_BATCH,
+            CALENDAR_FUNCTION_API_REMOVE_BATCH,
+            CALENDAR_FEATURES_CALENDAR_WRITE,
+            DEVICE_LIST_CALENDAR_WRITE);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_REMOVE_BATCH,
+                               removeBatchFunc));
+
+    //convertToString
+    AceFunction convertToStringFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONVERT_TO_STRING,
+            CALENDAR_FUNCTION_API_CONVERT_TO_STRING,
+            CALENDAR_FEATURES_CALENDAR_READ,
+            DEVICE_LIST_CALENDAR_READ);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_CONVERT_TO_STRING,
+                               convertToStringFunc));
+
+    //addChangeListener
+    AceFunction addChangeListenerFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADD_CHANGE_LISTENER,
+            CALENDAR_FUNCTION_API_ADD_CHANGE_LISTENER,
+            CALENDAR_FEATURES_CALENDAR_READ,
+            DEVICE_LIST_CALENDAR_READ);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_ADD_CHANGE_LISTENER,
+                               addChangeListenerFunc));
+
+    //removeChangeListener
+    AceFunction removeChangeListenerFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_REMOVE_CHANGE_LISTENER,
+            CALENDAR_FUNCTION_API_REMOVE_CHANGE_LISTENER,
+            CALENDAR_FEATURES_CALENDAR_READ,
+            DEVICE_LIST_CALENDAR_READ);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_REMOVE_CHANGE_LISTENER,
+                               removeChangeListenerFunc));
+
+    //expandRecurrence
+    AceFunction expandRecurrenceFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_EXPAND_RECURRENCE,
+            CALENDAR_FUNCTION_API_EXPAND_RECURRENCE,
+            CALENDAR_FEATURES_CALENDAR_READ,
+            DEVICE_LIST_CALENDAR_READ);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_EXPAND_RECURRENCE,
+                               expandRecurrenceFunc));
+
+    //get
+    AceFunction getFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET,
+            CALENDAR_FUNCTION_API_GET,
+            CALENDAR_FEATURES_CALENDAR_READ,
+            DEVICE_LIST_CALENDAR_READ);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_GET,
+                               getFunc));
+
+    //clone
+    AceFunction cloneFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CLONE,
+            CALENDAR_FUNCTION_API_CLONE,
+            CALENDAR_FEATURES_CALENDAR_READ,
+            DEVICE_LIST_CALENDAR_READ);
+
+    calendarMapping.insert(std::make_pair(
+                               CALENDAR_FUNCTION_API_CLONE,
+                               getFunc));
+
+    return calendarMapping;
+}
+
+}
+} 
+}
diff --git a/src/standards/Tizen/Calendar/plugin_config.h b/src/standards/Tizen/Calendar/plugin_config.h
new file mode 100755 (executable)
index 0000000..ad1dfdb
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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 _CALENDAR_PLUGIN_CONFIG_H_
+#define _CALENDAR_PLUGIN_CONFIG_H_
+
+#include <string>
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+// Functions from calendar manager
+#define CALENDAR_FUNCTION_API_GET_CALENDARS "getCalendars"
+#define CALENDAR_FUNCTION_API_GET_DEFAULT_CALENDAR "getDefaultCalendar"
+#define CALENDAR_FUNCTION_API_GET_CALENDAR "getCalendar"
+
+// Functions from calendar
+#define CALENDAR_FUNCTION_API_ADD "add"
+#define CALENDAR_FUNCTION_API_ADD_BATCH "addBatch"
+#define CALENDAR_FUNCTION_API_UPDATE "update"
+#define CALENDAR_FUNCTION_API_UPDATE_BATCH "updateBatch"
+#define CALENDAR_FUNCTION_API_REMOVE "remove"
+#define CALENDAR_FUNCTION_API_REMOVE_BATCH "removeBatch"
+#define CALENDAR_FUNCTION_API_FIND "find"
+#define CALENDAR_FUNCTION_API_CONVERT_TO_STRING "convertToString"
+#define CALENDAR_FUNCTION_API_ADD_CHANGE_LISTENER "addChangeListener"
+#define CALENDAR_FUNCTION_API_REMOVE_CHANGE_LISTENER "removeChangeListener"
+#define CALENDAR_FUNCTION_API_EXPAND_RECURRENCE "expandRecurrence"
+#define CALENDAR_FUNCTION_API_GET "get"
+#define CALENDAR_FUNCTION_API_CLONE "clone"
+
+DECLARE_FUNCTION_GETTER(Calendar);
+
+#define CALENDAR_CHECK_ACCESS(functionName) \
+       aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >( \
+       getCalendarFunctionData, \
+       functionName)
+}
+}
+}
+
+#endif //  _CALENDAR_PLUGIN_CONFIG_H_
diff --git a/src/standards/Tizen/Calendar/plugin_initializer.cpp b/src/standards/Tizen/Calendar/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..10f82ce
--- /dev/null
@@ -0,0 +1,117 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <Commons/Exception.h>
+#include "JSCalendarManager.h"
+#include "JSCalendarEvent.h"
+#include "JSCalendarTask.h"
+#include "JSCalendarAttendee.h"
+#include "JSCalendarRecurrenceRule.h"
+#include "JSCalendarEventId.h"
+#include "JSCalendarAlarm.h"
+
+#include "CalendarAsyncCallbackManager.h"
+#include "CalendarListenerManager.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Calendar {
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[Tizen\\Calendar] on_widget_start_callback (" << widgetId << ")");
+
+       Try {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+       } Catch (Exception) {
+               LogError("WrtAccess initialization failed");
+       }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[Tizen\\Calendar] on_widget_stop_callback (" << widgetId << ")");
+
+       Try {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+       } Catch (Exception) {
+               LogError("WrtAccess deinitialization failed");
+       }
+}
+
+void on_frame_load_callback(const void * context)
+{
+    LogDebug("[Tizen\\Calendar] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LogDebug("[Tizen\\Calendar] on_frame_unload_callback (" << context << ")");
+
+       TizenApis::Tizen1_0::Calendar::CalendarAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+       TizenApis::Tizen1_0::Calendar::CalendarListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+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,
+        "calendar",
+        (js_class_template_getter)JSCalendarManager::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        TIZEN_INTERFACE_CALENDAR_EVENT,
+        (js_class_template_getter)JSCalendarEvent::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        TIZEN_INTERFACE_CALENDAR_TASK,
+        (js_class_template_getter)JSCalendarTask::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        TIZEN_INTERFACE_CALENDAR_ATTENDEE,
+        (js_class_template_getter)JSCalendarAttendee::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        TIZEN_INTERFACE_CALENDAR_RECURRENCE_RULE,
+        (js_class_template_getter)JSCalendarRecurrenceRule::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        TIZEN_INTERFACE_CALENDAR_EVENT_ID,
+        (js_class_template_getter)JSCalendarEventId::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        TIZEN_INTERFACE_CALENDAR_ALARM,
+        (js_class_template_getter)JSCalendarAlarm::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_END
+
+}
+}
+}
+
diff --git a/src/standards/Tizen/Callhistory/CMakeLists.txt b/src/standards/Tizen/Callhistory/CMakeLists.txt
new file mode 100644 (file)
index 0000000..684ae37
--- /dev/null
@@ -0,0 +1,36 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-callhistory")
+set(DESTINATION_NAME "tizen-2.0-callhistory")
+
+include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_CALLHISTORY})
+
+set(CMAKE_INSTALL_RPATH
+  ${CMAKE_INSTALL_RPATH}
+  ${CMAKE_INSTALL_PREFIX}/tizen-2.0-tizen
+)
+
+set(SRCS
+  ${SRCS_PLATFORM_API_CALLHISTORY}
+  ${SRCS_PLATFORM_IMPLEMENTATION_CALLHISTORY}
+  CallHistoryMultiCallback.cpp
+  CallHistoryStaticController.cpp
+  CallHistoryListenerManager.cpp
+  CallHistoryAsyncCallbackManager.cpp
+  Converter.cpp
+  JSCallHistory.cpp
+  JSCallHistoryEntry.cpp
+  JSRemoteParty.cpp
+  ResponseDispatcher.cpp
+  plugin_config.cpp
+  plugin_initializer.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  wrt-plugins-tizen-2.0-tizen-impl
+  ${LIBS_COMMON}
+  ${LIBS_PLATFORM_IMPLEMENTATION_CALLHISTORY}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
+
diff --git a/src/standards/Tizen/Callhistory/CallHistoryAsyncCallbackManager.cpp b/src/standards/Tizen/Callhistory/CallHistoryAsyncCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..973fb5d
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// 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 "CallHistoryAsyncCallbackManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::CallHistoryAsyncCallbackManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Callhistory/CallHistoryAsyncCallbackManager.h b/src/standards/Tizen/Callhistory/CallHistoryAsyncCallbackManager.h
new file mode 100755 (executable)
index 0000000..9704c93
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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_CALLHISTORY_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_CALLHISTORY_ASYNC_CALLBACK_MANAGER_H_
+
+#include <dpl/singleton.h>
+#include <Tizen/Common/AsyncCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+class CallHistoryAsyncCallbackManager : public TizenApis::Commons::AsyncCallbackManager
+{
+public:
+       CallHistoryAsyncCallbackManager()
+       {
+       }
+
+       virtual ~CallHistoryAsyncCallbackManager()
+       {
+       }
+
+       friend class DPL::Singleton<CallHistoryAsyncCallbackManager>;
+};
+
+typedef DPL::Singleton<CallHistoryAsyncCallbackManager> CallHistoryAsyncCallbackManagerSingleton;
+
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CALLHISTORY_ASYNC_CALLBACK_MANAGER_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/Callhistory/CallHistoryListenerManager.cpp b/src/standards/Tizen/Callhistory/CallHistoryListenerManager.cpp
new file mode 100755 (executable)
index 0000000..878ece8
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// 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 "CallHistoryListenerManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::CallHistoryListenerManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Callhistory/CallHistoryListenerManager.h b/src/standards/Tizen/Callhistory/CallHistoryListenerManager.h
new file mode 100755 (executable)
index 0000000..1c2135b
--- /dev/null
@@ -0,0 +1,81 @@
+//
+// 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_CALLHISTORY_LISTENER_MANAGER_H_
+#define _TIZEN_CALLHISTORY_LISTENER_MANAGER_H_
+
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Tizen/Common/IListenerManager.h>
+#include "JSCallHistory.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace TizenApis::Api::Callhistory;
+
+class CallHistoryListenerManager : public TizenApis::Commons::IListenerController
+{
+public:
+       CallHistoryListenerManager()
+       {
+       }
+
+       virtual ~CallHistoryListenerManager()
+       {
+       }
+};
+typedef DPL::Singleton<CallHistoryListenerManager> CallHistoryListenerManagerSingleton;
+
+class CallHistoryListenerCanceller : public TizenApis::Commons::IListenerItem
+{
+public:
+       CallHistoryListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
+               TizenApis::Commons::IListenerItem(context, object, watchId)
+       {
+       }
+
+       virtual ~CallHistoryListenerCanceller()
+       {
+       }
+
+       virtual void cancelListener()
+       {
+               JSCallHistoryPriv *priv = static_cast<JSCallHistoryPriv*> (JSObjectGetPrivate(m_object));
+
+               if (!priv) {
+                       LogWarning("Object has no private object");
+                       return;
+               }
+
+               try {
+                       ICallHistoryPtr callHistory(priv->getObject());
+                       callHistory->removeListener(m_watchId);
+               } Catch(WrtDeviceApis::Commons::Exception) {
+                       LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               }
+       }
+};
+typedef DPL::SharedPtr<CallHistoryListenerCanceller> CallHistoryListenerCancellerPtr;
+
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CALLHISTORY_LISTENER_MANAGER_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/Callhistory/CallHistoryMultiCallback.cpp b/src/standards/Tizen/Callhistory/CallHistoryMultiCallback.cpp
new file mode 100755 (executable)
index 0000000..2d99195
--- /dev/null
@@ -0,0 +1,42 @@
+//
+// 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 "CallHistoryMultiCallback.h"
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+EventCallHistoryListenerPrivateData::EventCallHistoryListenerPrivateData(
+                       const JSCallbackManagerPtr& onAdded, const JSCallbackManagerPtr& onChanged) :
+                       m_onAdded(onAdded), m_onChanged(onChanged)
+{
+}
+
+JSCallbackManagerPtr EventCallHistoryListenerPrivateData::getOnAdded() const
+{
+       return m_onAdded;
+}
+
+JSCallbackManagerPtr EventCallHistoryListenerPrivateData::getOnChanged() const
+{
+       return m_onChanged;
+}
+
+}
+}
+
diff --git a/src/standards/Tizen/Callhistory/CallHistoryMultiCallback.h b/src/standards/Tizen/Callhistory/CallHistoryMultiCallback.h
new file mode 100755 (executable)
index 0000000..13a5b21
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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_CALLHISTORY_MULTI_CALLBACK_H_
+#define TIZENAPIS_TIZEN_CALLHISTORY_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 TizenApis {
+namespace Tizen1_0 {
+
+struct CallHistoryChangeCB
+{
+       JSValueRef onAdded;
+       JSValueRef onChanged;
+
+       CallHistoryChangeCB() :
+               onAdded(NULL),
+               onChanged(NULL)
+       { }
+};
+
+class EventCallHistoryListenerPrivateData : public WrtDeviceApis::Commons::IEventPrivateData
+{
+public:
+       EventCallHistoryListenerPrivateData(const JSCallbackManagerPtr& onAdded,
+                       const JSCallbackManagerPtr& onChanged);
+
+       JSCallbackManagerPtr getOnAdded() const;
+       JSCallbackManagerPtr getOnChanged() const;
+
+private:
+       JSCallbackManagerPtr m_onAdded;
+       JSCallbackManagerPtr m_onChanged;
+};
+
+typedef DPL::SharedPtr<EventCallHistoryListenerPrivateData> EventCallHistoryListenerPrivateDataPtr;
+
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Callhistory/CallHistoryStaticController.cpp b/src/standards/Tizen/Callhistory/CallHistoryStaticController.cpp
new file mode 100755 (executable)
index 0000000..0e010c7
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// 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 <Commons/IEvent.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include "CallHistoryStaticController.h"
+#include "Converter.h"
+
+using namespace TizenApis::Api::Callhistory;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+CallHistoryStaticController& CallHistoryStaticController::getInstance()
+{
+    static CallHistoryStaticController controller;
+    return controller;
+}
+
+CallHistoryStaticController::CallHistoryStaticController() :
+       WrtDeviceApis::Commons::EventListener<EventCallHistoryListener>(ThreadEnum::NULL_THREAD)
+{
+}
+
+void CallHistoryStaticController::onAnswerReceived(const EventCallHistoryListenerPtr& event)
+{
+       EventCallHistoryListenerPrivateDataPtr multiCallbacks = 
+               DPL::DynamicPointerCast<EventCallHistoryListenerPrivateData>(event->getPrivateData());
+
+       if (multiCallbacks == NULL) {
+               return;
+       }
+
+       if ((multiCallbacks->getOnAdded() == NULL)  || (multiCallbacks->getOnChanged() == NULL)) {
+               return; 
+       }
+
+       JSCallbackManagerPtr defaultCbm = multiCallbacks->getOnAdded(); 
+       JSContextRef context = defaultCbm->getContext();
+       Converter converter(context);
+
+       try {
+               JSValueRef result = converter.toJSValueRef(event->getResult(), context);
+               
+               switch (event->getResultState()) {
+               case EventCallHistoryListener::ADDED :
+                       multiCallbacks->getOnAdded()->callOnSuccess(result);
+                       break;
+               case EventCallHistoryListener::CHANGED :
+                       multiCallbacks->getOnChanged()->callOnSuccess(result);
+                       break;                  
+               }
+       } catch(ConversionException) {
+               LogError("Conversion exception while processing EventCallHistoryListener");
+       }
+}
+
+}
+}
diff --git a/src/standards/Tizen/Callhistory/CallHistoryStaticController.h b/src/standards/Tizen/Callhistory/CallHistoryStaticController.h
new file mode 100755 (executable)
index 0000000..806975b
--- /dev/null
@@ -0,0 +1,42 @@
+//
+// 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_CALL_STATIC_CONTROLLER_H_
+#define TIZENAPIS_TIZEN_CALL_STATIC_CONTROLLER_H_
+
+#include <Commons/EventReceiver.h>
+#include <Commons/EventListener.h>
+#include <API/Callhistory/EventCallHistoryListener.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class CallHistoryStaticController : 
+       public WrtDeviceApis::Commons::EventListener<Api::Callhistory::EventCallHistoryListener>
+{
+public:
+       static CallHistoryStaticController& getInstance();
+
+       void onAnswerReceived(const Api::Callhistory::EventCallHistoryListenerPtr& event);
+
+protected:
+       CallHistoryStaticController();
+};
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Callhistory/Converter.cpp b/src/standards/Tizen/Callhistory/Converter.cpp
new file mode 100755 (executable)
index 0000000..1a2712a
--- /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 "Converter.h"
+#include <dpl/log/log.h>
+
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <API/Callhistory/CallHistoryDefine.h>
+#include "JSCallHistoryEntry.h"
+#include "JSRemoteParty.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Callhistory;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+Converter::Converter(JSContextRef context) : WrtDeviceApis::CommonsJavaScript::Converter(context)
+{
+       static bool init = initializeAllowedProperties();
+       (void) init;
+}
+
+std::vector<unsigned long> Converter::toVectorOfULongs(const JSValueRef& jsValue)
+{
+    return toVectorOfT_(jsValue, &Converter::toULong);
+}
+
+CallHistoryEntryList Converter::toVectorOfCallHistoryEntryProperties(const JSValueRef& jsValue)
+{
+       if (JSValueIsNull(m_context, jsValue) || JSValueIsUndefined(m_context, jsValue)) {
+               ThrowMsg(Commons::ConversionException, "Undefined history entry");
+       }
+
+       if (!JSIsArrayValue(m_context, jsValue)) {
+               ThrowMsg(Commons::ConversionException, "Argument is not an JS array.");
+       }
+
+       try {
+               CallHistoryEntryList result;
+               JSObjectRef objArg = toJSObjectRef(jsValue);
+               for (std::size_t i = 0; i < JSGetArrayLength(m_context, objArg); ++i) {
+                       JSValueRef element = JSGetArrayElement(m_context, objArg, i);
+                       result.push_back(toCallHistoryEntryProperties(element));
+               }
+               return result;
+       } catch (Commons::ConversionException& ex) {
+               ThrowMsg(Commons::ConversionException, ex.GetMessage());
+       } catch (Commons::InvalidArgumentException& ex) {
+               ThrowMsg(Commons::InvalidArgumentException, ex.GetMessage());
+       } catch (Commons::Exception& ex) {
+               ThrowMsg(Commons::Exception, ex.GetMessage());
+       }
+
+}
+
+StringArrayPtr Converter::toStringArray(const JSValueRef &jsValue)
+{
+       StringArrayPtr result(new StringArray());
+       try {
+               if (!JSValueIsNull(m_context, jsValue)) {
+                       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));
+                       }
+               }
+       } catch (Commons::ConversionException& ex) {
+               ThrowMsg(Commons::ConversionException, ex.GetMessage());
+       } catch (Commons::InvalidArgumentException& ex) {
+               ThrowMsg(Commons::InvalidArgumentException, ex.GetMessage());
+       } catch (Commons::Exception& ex) {
+               ThrowMsg(Commons::Exception, ex.GetMessage());
+       }
+       return result;
+}
+
+RemotePartyListPtr Converter::toRemotePartyList(const JSValueRef &jsValue)
+{
+       RemotePartyListPtr result(new RemotePartyList());
+       try {
+               if (!JSValueIsNull(m_context, jsValue)) {
+                       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(toRemoteParty(element));
+                       }
+               }
+       } catch (Commons::ConversionException& ex) {
+               ThrowMsg(Commons::ConversionException, ex.GetMessage());
+       } catch (Commons::InvalidArgumentException& ex) {
+               ThrowMsg(Commons::InvalidArgumentException, ex.GetMessage());
+       } catch (Commons::Exception& ex) {
+               ThrowMsg(Commons::Exception, ex.GetMessage());
+       }
+       return result;
+}
+
+RemotePartyPtr Converter::toRemoteParty(const JSValueRef &jsValue)
+{
+       try {
+               return JSRemoteParty::getRemoteParty(m_context, jsValue);
+       } catch (Commons::ConversionException& ex) {
+               ThrowMsg(Commons::ConversionException, ex.GetMessage());
+       } catch (Commons::Exception& ex) {
+               ThrowMsg(Commons::Exception, ex.GetMessage());
+       }
+}
+
+CallHistoryEntryPropertiesPtr Converter::toCallHistoryEntryProperties(const JSValueRef &jsValue)
+{
+       try {
+               return JSCallHistoryEntry::getCallHistoryEntry(m_context, jsValue);
+       } catch (Commons::ConversionException& ex) {
+               ThrowMsg(Commons::ConversionException, ex.GetMessage());
+       } catch (Commons::Exception& ex) {
+               ThrowMsg(Commons::Exception, ex.GetMessage());
+       }
+}
+
+EventCallHistoryListenerPrivateDataPtr 
+       Converter::toEventCallHistoryListenerPrivateData(const JSValueRef &jsValue, JSContextRef context)
+{
+       if (JSValueIsNull(m_context, jsValue) || JSValueIsUndefined(m_context, jsValue)) {
+               ThrowMsg(Commons::ConversionException, "Type missmatch error : Listener callback is null or undefined");
+       }
+       if (!JSValueIsObject(m_context, jsValue) || JSObjectIsFunction(m_context, toJSObjectRef(jsValue))) {
+               ThrowMsg(Commons::ConversionException, "Type missmatch error : Listener callback");
+       }
+
+       JSObjectRef objectCallbacks = toJSObjectRef(jsValue);
+       CallHistoryChangeCB result;
+
+       result.onAdded = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, "onadded");
+       result.onChanged = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, "onchanged");
+
+       JSCallbackManagerPtr onAddedCbm = JSCallbackManager::createObject(context);
+       JSCallbackManagerPtr onChangedCbm = JSCallbackManager::createObject(context);
+
+       if (!JSValueIsNull(m_context, result.onAdded) && !JSValueIsUndefined(m_context, result.onAdded)) {
+               if (JSObjectIsFunction(m_context, toJSObjectRef(result.onAdded))) {
+                       onAddedCbm->setOnSuccess(result.onAdded);
+               } else {
+                       ThrowMsg(Commons::ConversionException, "Type missmatch error : onadded callback");
+               }
+       }
+
+       if (!JSValueIsNull(m_context, result.onChanged) && !JSValueIsUndefined(m_context, result.onChanged)) {
+               if (JSObjectIsFunction(m_context, toJSObjectRef(result.onChanged))) {
+                       onChangedCbm->setOnSuccess(result.onChanged);
+               } else {                        
+                       ThrowMsg(Commons::ConversionException, "Type missmatch error : onchanged callback");
+               }
+       }
+
+       return EventCallHistoryListenerPrivateDataPtr(new EventCallHistoryListenerPrivateData(onAddedCbm, onChangedCbm));
+}
+
+JSValueRef Converter::toJSValueRef(const Api::Callhistory::CallHistoryEntryListPtr& arg, JSContextRef context)
+{
+       JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+       if (!jsResult) {
+               ThrowMsg(Commons::ConversionException, "Could not create js array object");
+       }
+       Api::Callhistory::CallHistoryEntryProperties tmpCallEntry;
+
+       try {
+               for (size_t i = 0; i < (*arg).size(); i++) {
+                       tmpCallEntry = *((*arg)[i]);
+                       JSObjectRef jsObject = JSCallHistoryEntry::createJSObject(context, tmpCallEntry);
+                       if (!jsObject) {
+                               ThrowMsg(Commons::ConversionException, "Could not create JS object.");
+                       }
+
+                       if (!JSSetArrayElement(m_context, jsResult, i, jsObject)) {
+                               ThrowMsg(Commons::ConversionException, "Could not insert value into js array");
+                       }
+               }
+       } catch (Commons::ConversionException& ex) {
+               ThrowMsg(Commons::ConversionException, ex.GetMessage());
+       } catch (Commons::InvalidArgumentException& ex) {
+               ThrowMsg(Commons::InvalidArgumentException, ex.GetMessage());
+       } catch (Commons::Exception& ex) {
+               ThrowMsg(Commons::Exception, ex.GetMessage());
+       }
+       return jsResult;
+}
+
+JSValueRef Converter::toJSValueRef(const Api::Callhistory::StringArrayPtr &arg, JSContextRef context)
+{
+       JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+       if (!jsResult) {
+               ThrowMsg(Commons::ConversionException, "Could not create js array object");
+       }
+
+       for (size_t i = 0; i < (*arg).size(); i++) {
+               if (!JSSetArrayElement(m_context, jsResult, i, toJSValueRef((*arg)[i]))) {
+                       ThrowMsg(Commons::ConversionException, "Could not insert value into js array");
+               }
+       }
+
+       return jsResult;
+}
+
+JSValueRef Converter::toJSValueRef(const Api::Callhistory::RemotePartyListPtr& arg, JSContextRef context)
+{
+       JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+       if (!jsResult) {
+               ThrowMsg(Commons::ConversionException, "Could not create js array object");
+       }
+
+       Api::Callhistory::RemoteParty tmpRemoteParty;
+
+       try {
+               for (size_t i = 0; i < (*arg).size(); i++) {
+                       tmpRemoteParty = *((*arg)[i]);
+                       JSObjectRef jsObject = JSRemoteParty::createJSObject(context, tmpRemoteParty);
+                       if (!jsObject) {
+                               ThrowMsg(Commons::ConversionException, "Could not create JS object.");
+                       }
+
+                       if (!JSSetArrayElement(m_context, jsResult, i, jsObject)) {
+                               ThrowMsg(Commons::ConversionException, "Could not insert value into js array");
+                       }
+               }
+       } catch (Commons::ConversionException& ex) {
+               ThrowMsg(Commons::ConversionException, ex.GetMessage());
+       } catch (Commons::InvalidArgumentException& ex) {
+               ThrowMsg(Commons::InvalidArgumentException, ex.GetMessage());
+       } catch (Commons::Exception& ex) {
+               ThrowMsg(Commons::Exception, ex.GetMessage());
+       }
+       return jsResult;
+}
+
+bool Converter::initializeAllowedProperties()
+{
+       return true;
+}
+
+}
+}
+
diff --git a/src/standards/Tizen/Callhistory/Converter.h b/src/standards/Tizen/Callhistory/Converter.h
new file mode 100755 (executable)
index 0000000..a4c95a0
--- /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_APIS_CALL_CONVERTER_H_
+#define TIZEN_APIS_CALL_CONVERTER_H_
+
+#include <vector>
+#include <string>
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/Converter.h>
+#include <API/Callhistory/CallHistoryEntryProperties.h>
+#include <API/Callhistory/RemoteParty.h>
+#include <Tizen/Contact/ContactConverter.h>
+#include "CallHistoryMultiCallback.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class Converter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+public:
+       using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
+
+public:
+       explicit Converter(JSContextRef context);
+
+       std::vector<unsigned long> toVectorOfULongs(const JSValueRef& jsValue);
+
+       Api::Callhistory::CallHistoryEntryList toVectorOfCallHistoryEntryProperties(const JSValueRef& jsValue);
+
+       Api::Callhistory::StringArrayPtr toStringArray(const JSValueRef &jsValue);
+
+       Api::Callhistory::RemotePartyListPtr toRemotePartyList(const JSValueRef &jsValue);
+
+       Api::Callhistory::RemotePartyPtr toRemoteParty(const JSValueRef &jsValue);
+
+       Api::Callhistory::CallHistoryEntryPropertiesPtr toCallHistoryEntryProperties(const JSValueRef &jsValue);
+
+       EventCallHistoryListenerPrivateDataPtr toEventCallHistoryListenerPrivateData(const JSValueRef &jsValue, JSContextRef context);
+
+       JSValueRef toJSValueRef(const Api::Callhistory::CallHistoryEntryListPtr &arg, JSContextRef context);
+
+       JSValueRef toJSValueRef(const Api::Callhistory::StringArrayPtr &arg, JSContextRef context);
+
+       JSValueRef toJSValueRef(const Api::Callhistory::RemotePartyListPtr& arg, JSContextRef context);
+
+private:
+       bool initializeAllowedProperties();
+};
+
+typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<Converter> ConverterFactory;
+typedef ConverterFactory::ConverterType ConverterPtr;
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/standards/Tizen/Callhistory/JSCallHistory.cpp b/src/standards/Tizen/Callhistory/JSCallHistory.cpp
new file mode 100755 (executable)
index 0000000..e04f3d9
--- /dev/null
@@ -0,0 +1,533 @@
+//
+// 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 <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Tizen/FilterConverter.h>
+#include <API/Callhistory/EventFindCallHistory.h>
+#include <API/Callhistory/EventRemoveBatch.h>
+#include <API/Callhistory/EventRemoveAll.h>
+#include <API/Callhistory/EventCallHistoryListener.h>
+#include <API/Callhistory/CallHistoryFactory.h>
+#include <API/Callhistory/ICallHistory.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h> 
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "JSCallHistoryEntry.h"
+#include "JSCallHistory.h"
+#include "CallHistoryStaticController.h"
+#include "CallHistoryMultiCallback.h"
+#include "ResponseDispatcher.h"
+#include "Converter.h"
+#include "plugin_config.h"
+#include "CallHistoryAsyncCallbackManager.h"
+#include "CallHistoryListenerManager.h"
+
+using namespace std;
+using namespace DPL;
+using namespace TizenApis::Api::Tizen;
+using namespace TizenApis::Api::Callhistory;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Tizen1_0::Tizen;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassRef JSCallHistory::m_jsClassRef = NULL;
+
+JSClassDefinition JSCallHistory::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "callhistory",
+       NULL,
+       m_property,
+       m_function,
+       initialize,
+       finalize,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+JSStaticValue JSCallHistory::m_property[] = {
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSCallHistory::m_function[] =
+{
+       { "find", JSCallHistory::find, kJSPropertyAttributeNone },
+       { "remove",      JSCallHistory::remove,      kJSPropertyAttributeNone },
+       { "removeBatch",      JSCallHistory::removeBatch,      kJSPropertyAttributeNone },
+       { "removeAll",      JSCallHistory::removeAll,      kJSPropertyAttributeNone },
+       { "addChangeListener",      JSCallHistory::addChangeListener,      kJSPropertyAttributeNone },
+       { "removeChangeListener",      JSCallHistory::removeChangeListener,      kJSPropertyAttributeNone },
+       { 0, 0, 0 }
+};
+
+const JSClassRef JSCallHistory::getClassRef() {
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSCallHistory::getClassInfo(){
+       return &m_classInfo;
+}
+
+void JSCallHistory::initialize(JSContextRef context, JSObjectRef object) {
+       JSCallHistoryPriv* priv = static_cast<JSCallHistoryPriv*>(JSObjectGetPrivate(object));
+
+       if (priv == NULL) {
+               ICallHistoryPtr CallHistory(CallHistoryFactory::getInstance().getCallHistoryObject());
+               priv = new JSCallHistoryPriv(context, CallHistory);
+               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+                       delete priv;
+               }
+       }
+}
+
+void JSCallHistory::finalize(JSObjectRef object) {
+       JSCallHistoryPriv* priv = static_cast<JSCallHistoryPriv*>(JSObjectGetPrivate(object));
+       if (priv != NULL) {
+               JSObjectSetPrivate(object, NULL);
+               delete priv;
+       }
+}
+
+JSObjectRef JSCallHistory::createJSObject(JSContextRef context, JSObjectRef object)
+{
+       ICallHistoryPtr CallHistory(CallHistoryFactory::getInstance().getCallHistoryObject());
+       JSCallHistoryPriv* priv = new JSCallHistoryPriv(context, CallHistory);
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+bool JSCallHistory::hasInstance(JSContextRef context, JSObjectRef constructor,
+       JSValueRef possibleInstance, JSValueRef* exception) {
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSCallHistory::find(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+       const JSValueRef arguments[], JSValueRef* exception) {
+
+       AceSecurityStatus status = CALLHISTORY_CHECK_ACCESS(
+                       CALL_HISTORY_FUNCTION_API_FIND);
+
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       if (argumentCount < 1) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       JSCallHistoryPriv *priv = static_cast<JSCallHistoryPriv*> (JSObjectGetPrivate(thisObject));
+
+       if (!priv) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
+       }
+
+       JSContextRef gContext = priv->getContext();
+       WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+       Validator check(context, exception);
+
+       JSCallbackManagerPtr cbm(JSCallbackManager::createObject(gContext));
+
+       try {
+               if (argumentCount >= 1) {
+                       if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0])) {
+                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : success callback ");
+                       } else if (!JSObjectIsFunction(context, converter.toJSObjectRef(arguments[0]))) {
+                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : success callback ");
+                       }
+                       cbm->setOnSuccess(arguments[0]);
+               }
+
+               if (argumentCount >= 2) {
+                       if (!JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1])) {
+                               if (!JSObjectIsFunction(context, converter.toJSObjectRef(arguments[1]))) {
+                                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : error callback ");
+                               }
+                               cbm->setOnError(arguments[1]);
+                       }
+               }
+
+               if (argumentCount >= 3) {
+                       if (!JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2])) {
+                               if (!JSValueIsObject(context, arguments[2])) {
+                                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : filter");
+                               }
+                       }
+               }
+
+               cbm->setObject(thisObject);
+
+               FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+               EventFindCallHistoryPtr event(new EventFindCallHistory());
+               ICallHistoryPtr callHistory(priv->getObject());
+
+               event->setPrivateData(StaticPointerCast<IEventPrivateData> (cbm));
+               event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
+
+               if (argumentCount >= 3) {
+                       if (!check.isNullOrUndefined(arguments[2])) {
+                               FilterPtr filter = filterConverter->toFilter(arguments[2]);
+                               event ->setFilter(filter);
+                       }
+               }
+
+               if (argumentCount >= 4) {
+                       if (!check.isNullOrUndefined(arguments[3])) {
+                               event->setSortMode(filterConverter->toSortMode(arguments[3]));
+                       }
+               }
+
+               if (argumentCount >= 5) {
+                       if (!check.isNullOrUndefined(arguments[4])) {
+                               event->setLimit(converter.toULong(arguments[4]));
+                       }
+               }
+
+               if (argumentCount >= 6) {
+                       if (!check.isNullOrUndefined(arguments[5])) {
+                               event->setOffset(converter.toULong(arguments[5]));
+                       }
+               }
+               callHistory->find(event);
+               CallHistoryAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, gContext);
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCallHistory::remove(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+       const JSValueRef arguments[], JSValueRef* exception) {
+
+       AceSecurityStatus status = CALLHISTORY_CHECK_ACCESS(
+                       CALL_HISTORY_FUNCTION_API_REMOVE);
+
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       if (argumentCount < 1) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       JSCallHistoryPriv *priv = static_cast<JSCallHistoryPriv*> (JSObjectGetPrivate(thisObject));
+
+       if (!priv) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
+       }
+
+       Converter converter(context);
+
+       try {
+               if (!JSValueIsObjectOfClass(context, arguments[0], JSCallHistoryEntry::getClassRef())) {
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : CallHistoryEntry");
+               }
+
+               ICallHistoryPtr callHistory(priv->getObject());
+               CallHistoryEntryPropertiesPtr entry = converter.toCallHistoryEntryProperties(arguments[0]);
+               callHistory->remove(entry->getEntryId());
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCallHistory::removeBatch(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+       const JSValueRef arguments[], JSValueRef* exception) {
+
+       AceSecurityStatus status = CALLHISTORY_CHECK_ACCESS(
+                       CALL_HISTORY_FUNCTION_API_REMOVE_BATCH);
+
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       if (argumentCount < 1) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       JSCallHistoryPriv *priv = static_cast<JSCallHistoryPriv*> (JSObjectGetPrivate(thisObject));
+
+       if (!priv) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
+       }
+
+       JSContextRef gContext = priv->getContext();
+       Converter converter(context);
+
+       JSCallbackManagerPtr cbm(JSCallbackManager::createObject(gContext));
+       try {
+               if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0])) {
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid values error : CallHistoryEntry array");
+               } else if (!JSIsArrayValue(context, arguments[0])) {
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : CallHistoryEntry array");
+               }
+
+               if (argumentCount >= 2) {
+                       if (!JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1])) {
+                               if (!JSObjectIsFunction(context, converter.toJSObjectRef(arguments[1]))) {
+                                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : success callback");
+                               }
+                               cbm->setOnSuccess(arguments[1]);
+                       }
+               }
+
+               if (argumentCount >= 3) {
+                       if (!JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2])) {
+                               if (!JSObjectIsFunction(context, converter.toJSObjectRef(arguments[2]))) {
+                                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : error callback");
+                               }
+                               cbm->setOnError(arguments[2]);
+                       }
+               }
+
+               cbm->setObject(thisObject);
+               
+               EventRemoveBatchPtr event(new EventRemoveBatch());
+               ICallHistoryPtr callHistory(priv->getObject());
+
+               event->setPrivateData(StaticPointerCast<IEventPrivateData> (cbm));
+               event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
+
+               CallHistoryEntryList entryList = converter.toVectorOfCallHistoryEntryProperties(arguments[0]);
+
+               std::vector<unsigned long> entryIds;
+
+               if (entryList.size() > 0) {
+                       for (unsigned int i = 0; i < entryList.size(); i++) {
+                               entryIds.push_back(entryList[i]->getEntryId());
+                       }
+                       event->setEntryIds(entryIds);
+                       callHistory->removeBatch(event);
+                       CallHistoryAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, gContext);
+               } else {
+                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error : Entry array is empty"));
+               }
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCallHistory::removeAll(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+       const JSValueRef arguments[], JSValueRef* exception) {
+
+       AceSecurityStatus status = CALLHISTORY_CHECK_ACCESS(
+                       CALL_HISTORY_FUNCTION_API_REMOVE_ALL);
+
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       JSCallHistoryPriv *priv = static_cast<JSCallHistoryPriv*> (JSObjectGetPrivate(thisObject));
+
+       if (!priv) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
+       }
+
+       JSContextRef gContext = priv->getContext();
+       Converter converter(context);
+
+       JSCallbackManagerPtr cbm(JSCallbackManager::createObject(gContext));
+
+       try {
+               if (argumentCount >= 1) {
+                       if (!JSValueIsNull(context, arguments[0]) && !JSValueIsUndefined(context, arguments[0])) {
+                               if (!JSObjectIsFunction(context, converter.toJSObjectRef(arguments[0]))) {
+                                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : success callback");
+                               }
+                               cbm->setOnSuccess(arguments[0]);
+                       }
+               }
+
+               if (argumentCount >= 2) {
+                       if (!JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1])) {
+                               if (!JSObjectIsFunction(context, converter.toJSObjectRef(arguments[1]))) {
+                                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : error callback");
+                               }
+                               cbm->setOnError(arguments[1]);
+                       }
+               }
+
+               cbm->setObject(thisObject);
+               EventRemoveAllPtr event(new EventRemoveAll());
+               ICallHistoryPtr callHistory(priv->getObject());
+
+               event->setPrivateData(StaticPointerCast<IEventPrivateData> (cbm));
+               event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
+               callHistory->removeAll(event);
+               CallHistoryAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, gContext);
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCallHistory::deleteRecording(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+       const JSValueRef arguments[], JSValueRef* exception) {
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSCallHistory::addChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+       const JSValueRef arguments[], JSValueRef* exception) {
+
+       AceSecurityStatus status = CALLHISTORY_CHECK_ACCESS(
+                       CALL_HISTORY_FUNCTION_API_ADDLISTENER);
+
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       if (argumentCount < 1) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       JSCallHistoryPriv *priv = static_cast<JSCallHistoryPriv*> (JSObjectGetPrivate(thisObject));
+
+       if (!priv) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
+       }
+
+       JSContextRef gContext = priv->getContext();
+       Converter converter(context);
+
+       try {
+               long id = 0;
+               if (argumentCount >= 1) {
+                       EventCallHistoryListenerPrivateDataPtr privData(converter.toEventCallHistoryListenerPrivateData(arguments[0], gContext));
+
+                       Api::Callhistory::EventCallHistoryListenerEmitterPtr emitter(new Api::Callhistory::EventCallHistoryListenerEmitter);
+                       emitter->setListener(&CallHistoryStaticController::getInstance());
+                       emitter->setEventPrivateData(DPL::StaticPointerCast<Api::Callhistory::EventCallHistoryListener::PrivateDataType>(privData));
+
+                       ICallHistoryPtr callHistory(priv->getObject());
+                       id = callHistory->addListener(emitter);
+
+                       CallHistoryListenerCancellerPtr canceller = CallHistoryListenerCancellerPtr(new CallHistoryListenerCanceller(gContext, thisObject, id));
+                       TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+                       CallHistoryListenerManagerSingleton::Instance().registerListener(listenerItem, gContext);
+               }
+
+               return converter.toJSValueRefLong(id);
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       }
+
+}
+
+JSValueRef JSCallHistory::removeChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+       const JSValueRef arguments[], JSValueRef* exception) {
+
+       AceSecurityStatus status = CALLHISTORY_CHECK_ACCESS(
+                       CALL_HISTORY_FUNCTION_API_REMOVELISTENER);
+
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       if (argumentCount < 1) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       JSCallHistoryPriv *priv = static_cast<JSCallHistoryPriv*> (JSObjectGetPrivate(thisObject));
+
+       if (!priv) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
+       }
+
+       JSContextRef gContext = priv->getContext();
+       Converter converter(context);
+       Validator check(context, exception);
+
+       try {
+               long id = 0;
+               if (argumentCount >= 1) {
+                       if (check.isNullOrUndefined(arguments[0])) {
+                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error : handle");
+                       }
+
+                       id = static_cast<long>(converter.toLong(arguments[0]));
+               }
+
+               if (id != 0) {
+                       ICallHistoryPtr callHistory(priv->getObject());
+                       callHistory->removeListener(id);
+               } else {
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error : handle");
+               }
+
+               CallHistoryListenerCancellerPtr canceller = CallHistoryListenerCancellerPtr(new CallHistoryListenerCanceller(gContext, thisObject, id));
+               TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+               CallHistoryListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+}
+}
+
diff --git a/src/standards/Tizen/Callhistory/JSCallHistory.h b/src/standards/Tizen/Callhistory/JSCallHistory.h
new file mode 100755 (executable)
index 0000000..4d762db
--- /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.
+//
+
+#ifndef TIZEN_APIS_JS_CALLHISTORY_H_
+#define TIZEN_APIS_JS_CALLHISTORY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Callhistory/ICallHistory.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Callhistory::ICallHistoryPtr>::Type JSCallHistoryPriv;
+
+class JSCallHistory
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       static JSObjectRef createJSObject(JSContextRef context, JSObjectRef object);
+private:
+       static void initialize(JSContextRef context, JSObjectRef object);
+
+       static void finalize(JSObjectRef object);
+
+       static JSValueRef getProperty(JSContextRef context, JSObjectRef object,
+                       JSStringRef propertyName, JSValueRef* exception);
+
+       static bool hasInstance(JSContextRef context, JSObjectRef constructor,
+                       JSValueRef possibleInstance, JSValueRef* exception);
+
+
+       static JSValueRef find(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 removeBatch(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 deleteRecording(JSContextRef context, JSObjectRef object,
+                       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef addChangeListener(JSContextRef context, JSObjectRef object,
+                       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef removeChangeListener(JSContextRef context, JSObjectRef object,
+                       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSClassDefinition m_classInfo;
+
+       static JSStaticValue m_property[];
+
+       static JSStaticFunction m_function[];
+
+       static JSClassRef m_jsClassRef;
+
+};
+
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Callhistory/JSCallHistoryEntry.cpp b/src/standards/Tizen/Callhistory/JSCallHistoryEntry.cpp
new file mode 100755 (executable)
index 0000000..8ac1820
--- /dev/null
@@ -0,0 +1,232 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <API/Callhistory/CallHistoryEntryProperties.h>
+#include <API/Callhistory/CallHistoryFactory.h>
+#include <API/Callhistory/ICallHistoryEntry.h>
+#include <API/Callhistory/CallHistoryDefine.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include "JSCallHistoryEntry.h"
+#include "JSRemoteParty.h"
+#include "Converter.h"
+
+#include <string>
+#include <sstream>
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace std;
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace Api::Callhistory;
+using namespace TizenApis::Commons;
+
+JSClassDefinition JSCallHistoryEntry::m_classInfo = {
+       0,
+       kJSClassAttributeNone,
+       "callhistoryentry",
+       0,
+       m_property,
+       0,
+       initialize,
+       finalize,
+       NULL,     //HasProperty,
+       getProperty,
+       NULL,     //SetProperty,
+       NULL,     //DeleteProperty,
+       NULL,     //GetPropertyNames,
+       NULL,     //CallAsFunction,
+       NULL,     //CallAsConstructor,
+       hasInstance,
+       NULL,     //ConvertToType
+};
+
+JSStaticValue JSCallHistoryEntry::m_property[] = {
+       { STR_ENTRY_ID, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_CALL_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_TAGS, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_REMOTE_PARTIES, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_START_TIME, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_DURATION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_DIRECTION, getProperty, setProperty, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSCallHistoryEntry::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSCallHistoryEntry::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+JSClassRef JSCallHistoryEntry::m_jsClassRef = JSClassCreate(JSCallHistoryEntry::getClassInfo());
+
+JSObjectRef JSCallHistoryEntry::createJSObject(JSContextRef context,
+        const CallHistoryEntryProperties &entryInfo)
+{
+       CallHistoryEntryPropertiesPtr callHistoryEntryProps(new CallHistoryEntryProperties(entryInfo));
+       JSCallHistoryEntryPriv *priv = new JSCallHistoryEntryPriv(context, CallHistoryEntryPropertiesPtr(callHistoryEntryProps));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
+       }
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+CallHistoryEntryPropertiesPtr JSCallHistoryEntry::getCallHistoryEntry(JSContextRef context, JSValueRef value)
+{
+       if (!JSValueIsObjectOfClass(context, value, getClassRef())) {
+               Throw(WrtDeviceApis::Commons::ConversionException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::ConversionException);
+       }
+       JSCallHistoryEntryPriv *priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::ConversionException);
+       }
+       return priv->getObject();
+}
+
+void JSCallHistoryEntry::initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSCallHistoryEntry::finalize(JSObjectRef object)
+{
+       JSCallHistoryEntryPriv* priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
+       if (priv != NULL) {
+               JSObjectSetPrivate(object, NULL);
+               delete priv;
+       }
+}
+
+JSValueRef JSCallHistoryEntry::getProperty(JSContextRef context,
+       JSObjectRef object,
+       JSStringRef propertyName,
+       JSValueRef* exception)
+{
+       JSCallHistoryEntryPriv *priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
+       }
+
+       try {
+               CallHistoryEntryPropertiesPtr entryInfo = priv->getObject();
+               Converter convert(context);
+
+               if (JSStringIsEqualToUTF8CString(propertyName, STR_ENTRY_ID)) {
+                       std::ostringstream stream;
+               stream << entryInfo->getEntryId();
+               std::string idStr = stream.str();
+                       return convert.toJSValueRef(idStr);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_CALL_TYPE)) {
+                       return convert.toJSValueRef(entryInfo->getCallType());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_TAGS)) {
+                       return convert.toJSValueRef(entryInfo->getTags(), context);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_REMOTE_PARTIES)) {
+                       return convert.toJSValueRef(entryInfo->getRemoteParties(), context);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_START_TIME)) {
+                       return convert.toJSValueRef(entryInfo->getStartTime());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DURATION)) {
+                       return convert.toJSValueRef(entryInfo->getDuration());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DIRECTION)) {
+                       return convert.toJSValueRef(entryInfo->getDirection());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_DURATION)) {
+                       return convert.toJSValueRef(entryInfo->getDuration());
+               }
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSCallHistoryEntry::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       JSCallHistoryEntryPriv *priv = static_cast<JSCallHistoryEntryPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
+       }
+
+       Converter converter(context);
+       try {
+               if (JSStringIsEqualToUTF8CString(propertyName, STR_DIRECTION)) {
+                       CallHistoryEntryPropertiesPtr entryInfo = priv->getObject();
+                       if (entryInfo != NULL) {
+                               ICallHistoryEntryPtr callHistoryEntry(CallHistoryFactory::getInstance().getCallHistoryEntryObject());
+                               std::string direction(converter.toString(value));
+
+                               if (callHistoryEntry != NULL) {
+                                       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");
+       }
+
+       return false;
+}
+bool JSCallHistoryEntry::hasInstance(JSContextRef context,
+       JSObjectRef constructor,
+       JSValueRef possibleInstance,
+       JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+}
+}
+
diff --git a/src/standards/Tizen/Callhistory/JSCallHistoryEntry.h b/src/standards/Tizen/Callhistory/JSCallHistoryEntry.h
new file mode 100755 (executable)
index 0000000..b3ec736
--- /dev/null
@@ -0,0 +1,73 @@
+//
+// 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_JS_CALLINFO_H_
+#define TIZENAPIS_TIZEN_JS_CALLINFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Callhistory/CallHistoryEntryProperties.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Callhistory::CallHistoryEntryPropertiesPtr>::Type JSCallHistoryEntryPriv;
+
+class JSCallHistoryEntry
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       static JSObjectRef createJSObject(JSContextRef context,
+               const Api::Callhistory::CallHistoryEntryProperties &entryInfo);
+
+       static Api::Callhistory::CallHistoryEntryPropertiesPtr getCallHistoryEntry(JSContextRef context, JSValueRef value);
+
+private:
+       static void initialize(JSContextRef context,
+               JSObjectRef object);
+
+       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 bool hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception);
+
+       static JSClassDefinition m_classInfo;
+
+       static JSStaticValue m_property[];
+
+       static JSClassRef m_jsClassRef;
+};
+} 
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Callhistory/JSRemoteParty.cpp b/src/standards/Tizen/Callhistory/JSRemoteParty.cpp
new file mode 100755 (executable)
index 0000000..a172256
--- /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 <cassert>
+#include <memory>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h> 
+#include <API/Callhistory/CallHistoryDefine.h>
+#include <API/Callhistory/RemoteParty.h>
+#include "JSRemoteParty.h"
+#include "Converter.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace Api::Callhistory;
+using namespace TizenApis::Commons;
+
+JSClassDefinition JSRemoteParty::m_classInfo = {
+       0,
+       kJSClassAttributeNone,
+       "remoteparty",
+       0,
+       m_property,
+       0,
+       initialize,
+       finalize,
+       NULL,     //HasProperty,
+       getProperty,
+       NULL,     //SetProperty,
+       NULL,     //DeleteProperty,
+       NULL,     //GetPropertyNames,
+       NULL,     //CallAsFunction,
+       NULL,     //CallAsConstructor,
+       hasInstance,
+       NULL,     //ConvertToType
+};
+
+JSStaticValue JSRemoteParty::m_property[] = {
+       { STR_REMOTE_PARTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_PERSIONID, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSRemoteParty::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSRemoteParty::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+JSClassRef JSRemoteParty::m_jsClassRef = JSClassCreate(JSRemoteParty::getClassInfo());
+
+JSObjectRef JSRemoteParty::createJSObject(JSContextRef context,
+        const RemoteParty &remoteParty)
+{
+       RemotePartyPtr RemotePartyProps(new RemoteParty(remoteParty));
+       JSRemotePartyPriv *priv = new JSRemotePartyPriv(context, RemotePartyPtr(RemotePartyProps));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object");
+       }
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+RemotePartyPtr JSRemoteParty::getRemoteParty(JSContextRef context, JSValueRef value)
+{
+       if (!JSValueIsObjectOfClass(context, value, getClassRef())) {
+               Throw(WrtDeviceApis::Commons::ConversionException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::ConversionException);
+       }
+       JSRemotePartyPriv *priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::ConversionException);
+       }
+       return priv->getObject();
+}
+
+void JSRemoteParty::initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSRemoteParty::finalize(JSObjectRef object)
+{
+       JSRemotePartyPriv* priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
+       if (priv != NULL) {
+               JSObjectSetPrivate(object, NULL);
+               delete priv;
+       }
+}
+
+JSValueRef JSRemoteParty::getProperty(JSContextRef context,
+       JSObjectRef object,
+       JSStringRef propertyName,
+       JSValueRef* exception)
+{
+       JSRemotePartyPriv *priv = static_cast<JSRemotePartyPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error : Invalid private pointer");
+       }
+
+       try {
+               RemotePartyPtr remoteParty = priv->getObject();
+               Converter convert(context);
+
+               if (JSStringIsEqualToUTF8CString(propertyName, STR_REMOTE_PARTY)) {
+                       return convert.toJSValueRef(remoteParty->getRemoteParty());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_PERSIONID)) {
+                       return convert.toJSValueRef(remoteParty->getPersonId());
+               }
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSRemoteParty::hasInstance(JSContextRef context,
+       JSObjectRef constructor,
+       JSValueRef possibleInstance,
+       JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+}
+}
+
diff --git a/src/standards/Tizen/Callhistory/JSRemoteParty.h b/src/standards/Tizen/Callhistory/JSRemoteParty.h
new file mode 100755 (executable)
index 0000000..11b612f
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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_JS_REMOTEPARTY_H_
+#define TIZENAPIS_TIZEN_JS_REMOTEPARTY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Callhistory/RemoteParty.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Callhistory::RemotePartyPtr>::Type JSRemotePartyPriv;
+
+class JSRemoteParty
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       static JSObjectRef createJSObject(JSContextRef context,
+               const Api::Callhistory::RemoteParty &remoteParty);
+
+       static Api::Callhistory::RemotePartyPtr getRemoteParty(JSContextRef context, JSValueRef value);
+
+private:
+       static void initialize(JSContextRef context,
+               JSObjectRef object);
+
+       static void finalize(JSObjectRef object);
+
+       static JSValueRef getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception);
+
+       static bool hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception);
+
+       static JSClassDefinition m_classInfo;
+
+       static JSStaticValue m_property[];
+
+       static JSClassRef m_jsClassRef;
+};
+} 
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Callhistory/ResponseDispatcher.cpp b/src/standards/Tizen/Callhistory/ResponseDispatcher.cpp
new file mode 100755 (executable)
index 0000000..ac1a2d3
--- /dev/null
@@ -0,0 +1,124 @@
+//
+// 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 "ResponseDispatcher.h"
+
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+
+#include <Commons/Exception.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h> 
+#include "JSCallHistory.h"
+#include "Converter.h"
+#include "CallHistoryAsyncCallbackManager.h"
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+ResponseDispatcher& ResponseDispatcher::getInstance()
+{
+       static ResponseDispatcher dispatcher;
+       return dispatcher;
+}
+
+ResponseDispatcher::ResponseDispatcher() :
+       EventAnswerReceiver<Api::Callhistory::EventFindCallHistory>(ThreadEnum::NULL_THREAD),
+       EventAnswerReceiver<Api::Callhistory::EventRemoveBatch>(ThreadEnum::NULL_THREAD),
+       EventAnswerReceiver<Api::Callhistory::EventRemoveAll>(ThreadEnum::NULL_THREAD)
+{
+}
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Callhistory::EventFindCallHistoryPtr& event)
+{
+       JSCallbackManagerPtr data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!data)
+               return;
+
+       CallHistoryAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data);
+       
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               Converter converter(data->getContext());
+               try {
+                       data->callOnSuccess(converter.toJSValueRef(event->getResult(), data->getContext()));
+               } catch(WrtDeviceApis::Commons::ConversionException) {
+                       data->callOnError(JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::UNKNOWN_ERROR, "Unknown error"));
+               } catch(WrtDeviceApis::Commons::Exception) {
+                       data->callOnError(JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::UNKNOWN_ERROR, "Unknown error"));
+               }
+       } else {
+               JSObjectRef jsException = NULL;
+               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               } else {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::UNKNOWN_ERROR, "Unknown error");
+               }
+               data->callOnError(jsException);
+       }
+}
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Callhistory::EventRemoveBatchPtr& event)
+{
+       JSCallbackManagerPtr data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!data)
+               return;
+
+       CallHistoryAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data);
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               data->callOnSuccess();
+       } else {
+               JSObjectRef jsException = NULL;
+               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               } else {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::UNKNOWN_ERROR, "Unknown error");
+               }
+               data->callOnError(jsException);
+       }
+}
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Callhistory::EventRemoveAllPtr& event)
+{
+       JSCallbackManagerPtr data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!data)
+               return;
+
+       CallHistoryAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data);
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               data->callOnSuccess();
+       } else {
+               JSObjectRef jsException = NULL;
+               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               } else {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::UNKNOWN_ERROR, "Unknown error");
+               }
+               data->callOnError(jsException);
+       }
+}
+
+}
+} 
+
diff --git a/src/standards/Tizen/Callhistory/ResponseDispatcher.h b/src/standards/Tizen/Callhistory/ResponseDispatcher.h
new file mode 100755 (executable)
index 0000000..567f749
--- /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 TIZENAPIS_TIZEN_CALL_RESPONSEDISPATCHER_H_
+#define TIZENAPIS_TIZEN_CALL_RESPONSEDISPATCHER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <Commons/EventReceiver.h>
+#include <API/Callhistory/EventFindCallHistory.h>
+#include <API/Callhistory/EventRemoveBatch.h>
+#include <API/Callhistory/EventRemoveAll.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class ResponseDispatcher : 
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Callhistory::EventFindCallHistory>,
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Callhistory::EventRemoveBatch>,
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Callhistory::EventRemoveAll>
+{
+public:
+       static ResponseDispatcher& getInstance();
+
+       void OnAnswerReceived(const Api::Callhistory::EventFindCallHistoryPtr& event);
+       void OnAnswerReceived(const Api::Callhistory::EventRemoveBatchPtr& event);
+       void OnAnswerReceived(const Api::Callhistory::EventRemoveAllPtr& event);
+
+protected:
+       ResponseDispatcher();
+};
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Callhistory/config.xml b/src/standards/Tizen/Callhistory/config.xml
new file mode 100755 (executable)
index 0000000..8ec7fd8
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+       <library-name>libwrt-plugins-tizen-2.0-callhistory.so</library-name>
+       <feature-install-uri>callhistory.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/callhistory.read</name>
+               <device-capability>callhistory.read</device-capability>
+       </api-feature>
+
+       <api-feature>
+               <name>http://tizen.org/privilege/callhistory.write</name>
+               <device-capability>callhistory.write</device-capability>
+       </api-feature>
+</plugin-properties>
+
diff --git a/src/standards/Tizen/Callhistory/plugin_config.cpp b/src/standards/Tizen/Callhistory/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..f300cf7
--- /dev/null
@@ -0,0 +1,127 @@
+//
+// 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 <map>
+#include <utility>
+
+#include <dpl/assert.h>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+
+#define CALL_HISTORY_FEATURE_API_READ "http://tizen.org/privilege/callhistory.read"
+#define CALL_HISTORY_FEATURE_API_WRITE "http://tizen.org/privilege/callhistory.write"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+const char* CALL_HISTORY_DEVICE_CAP_READ = "callhistory.read";
+const char* CALL_HISTORY_DEVICE_CAP_WRITE = "callhistory.write";
+
+const char* CALL_HISTORY_FUNCTION_API_FIND = "find";
+const char* CALL_HISTORY_FUNCTION_API_REMOVE = "remove";
+const char* CALL_HISTORY_FUNCTION_API_REMOVE_BATCH = "removeBatch";
+const char* CALL_HISTORY_FUNCTION_API_REMOVE_ALL = "removeAll";
+const char* CALL_HISTORY_FUNCTION_API_ADDLISTENER = "addListener";
+const char* CALL_HISTORY_FUNCTION_API_REMOVELISTENER = "removeListener";
+
+
+static WrtDeviceApis::Commons::FunctionMapping createCallHistoryFunctions();
+
+static WrtDeviceApis::Commons::FunctionMapping CallHistoryFunctions = createCallHistoryFunctions();
+
+DEFINE_FUNCTION_GETTER(CallHistory, CallHistoryFunctions);
+
+static WrtDeviceApis::Commons::FunctionMapping createCallHistoryFunctions()
+{
+       using namespace WrtDeviceApis::Commons;
+
+       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_CALL_HISTORY_READ, CALL_HISTORY_DEVICE_CAP_READ);
+       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_CALL_HISTORY_WRITE, CALL_HISTORY_DEVICE_CAP_WRITE);
+
+       ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+
+       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_CALL_HISTORY_READ);
+       ACE_ADD_DEVICE_CAP(DEVICE_LIST_CALL_HISTORY_READ, DEVICE_CAP_CALL_HISTORY_READ);
+
+       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_CALL_HISTORY_WRITE);
+       ACE_ADD_DEVICE_CAP(DEVICE_LIST_CALL_HISTORY_WRITE, DEVICE_CAP_CALL_HISTORY_WRITE);
+
+       ACE_CREATE_FEATURE(FEATURE_CALL_HISTORY_READ, CALL_HISTORY_FEATURE_API_READ);
+       ACE_CREATE_FEATURE(FEATURE_CALL_HISTORY_WRITE, CALL_HISTORY_FEATURE_API_WRITE);
+
+       ACE_CREATE_FEATURE_LIST(CALL_FEATURES_CALL_HISTORY_READ);
+       ACE_ADD_API_FEATURE(CALL_FEATURES_CALL_HISTORY_READ, FEATURE_CALL_HISTORY_READ);
+
+       ACE_CREATE_FEATURE_LIST(CALL_FEATURES_CALL_HISTORY_WRITE);
+       ACE_ADD_API_FEATURE(CALL_FEATURES_CALL_HISTORY_WRITE, FEATURE_CALL_HISTORY_WRITE);
+
+       FunctionMapping CallHistoryMapping;
+
+       AceFunction findFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_FIND,
+                       CALL_HISTORY_FUNCTION_API_FIND,
+                       CALL_FEATURES_CALL_HISTORY_READ,
+                       EMPTY_DEVICE_LIST);
+
+       CallHistoryMapping.insert(std::make_pair(CALL_HISTORY_FUNCTION_API_FIND, findFunc));
+
+       AceFunction removeFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_REMOVE,
+                       CALL_HISTORY_FUNCTION_API_REMOVE,
+                       CALL_FEATURES_CALL_HISTORY_WRITE,
+                       EMPTY_DEVICE_LIST);
+
+       CallHistoryMapping.insert(std::make_pair(CALL_HISTORY_FUNCTION_API_REMOVE, removeFunc));
+
+       AceFunction removeBatchFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_REMOVE_BATCH,
+                       CALL_HISTORY_FUNCTION_API_REMOVE_BATCH,
+                       CALL_FEATURES_CALL_HISTORY_WRITE,
+                       EMPTY_DEVICE_LIST);
+
+       CallHistoryMapping.insert(std::make_pair(CALL_HISTORY_FUNCTION_API_REMOVE_BATCH, removeBatchFunc));
+
+       AceFunction removeAllFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_REMOVE_ALL,
+                       CALL_HISTORY_FUNCTION_API_REMOVE_ALL,
+                       CALL_FEATURES_CALL_HISTORY_WRITE,
+                       EMPTY_DEVICE_LIST);
+
+       CallHistoryMapping.insert(std::make_pair(CALL_HISTORY_FUNCTION_API_REMOVE_ALL, removeAllFunc));
+
+       AceFunction addListenerFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_ADD_LISTENER,
+                       CALL_HISTORY_FUNCTION_API_ADDLISTENER,
+                       CALL_FEATURES_CALL_HISTORY_READ,
+                       EMPTY_DEVICE_LIST);
+
+       CallHistoryMapping.insert(std::make_pair(CALL_HISTORY_FUNCTION_API_ADDLISTENER, addListenerFunc));
+
+       AceFunction removeListenerFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_REMOVE_LISTENER,
+                       CALL_HISTORY_FUNCTION_API_REMOVELISTENER,
+                       CALL_FEATURES_CALL_HISTORY_READ,
+                       EMPTY_DEVICE_LIST);
+
+       CallHistoryMapping.insert(std::make_pair(CALL_HISTORY_FUNCTION_API_REMOVELISTENER, removeListenerFunc));
+
+       return CallHistoryMapping;
+}
+
+}
+}
diff --git a/src/standards/Tizen/Callhistory/plugin_config.h b/src/standards/Tizen/Callhistory/plugin_config.h
new file mode 100755 (executable)
index 0000000..7d2369f
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// 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 _CALLHISTORY_PLUGIN_CONFIG_H_
+#define _CALLHISTORY_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+extern const char* CALL_HISTORY_FUNCTION_API_FIND;
+extern const char* CALL_HISTORY_FUNCTION_API_REMOVE;
+extern const char* CALL_HISTORY_FUNCTION_API_REMOVE_BATCH;
+extern const char* CALL_HISTORY_FUNCTION_API_REMOVE_ALL;
+extern const char* CALL_HISTORY_FUNCTION_API_ADDLISTENER;
+extern const char* CALL_HISTORY_FUNCTION_API_REMOVELISTENER;
+
+DECLARE_FUNCTION_GETTER(CallHistory);
+
+}
+}
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+#define CALLHISTORY_CHECK_ACCESS(functionName) \
+    WrtDeviceApis::Commons::aceCheckAccess<AceFunctionGetter, \
+    WrtDeviceApis::Commons::DefaultArgsVerifier<> >(                \
+        getCallHistoryFunctionData,         \
+        functionName)
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Callhistory/plugin_initializer.cpp b/src/standards/Tizen/Callhistory/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..99b8d0d
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <Commons/Exception.h>
+#include "JSCallHistory.h"
+#include "CallHistoryAsyncCallbackManager.h"
+#include "CallHistoryListenerManager.h"
+
+#define CALLHISTORY "callhistory"
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+void on_widget_start_callback(int widgetId) {
+       LogDebug("[Tizen\\callhistory] on_widget_start_callback (" << widgetId << ")");
+       try {
+               WrtAccessSingleton::Instance().initialize(widgetId);
+       } catch(WrtDeviceApis::Commons::Exception) {
+               LogError("WrtAccess initialization failed");
+       }
+}
+
+void on_widget_stop_callback(int widgetId) {
+       LogDebug("[Tizen\\callhistory] on_widget_stop_callback (" << widgetId << ")");
+       try {
+               WrtAccessSingleton::Instance().deinitialize(widgetId);
+       } catch(WrtDeviceApis::Commons::Exception) {
+               LogError("WrtAccess deinitialization failed");
+       }
+}
+
+void on_frame_load_callback(const void * context)
+{
+    LogDebug("[Tizen\\callhistory] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LogDebug("[Tizen\\callhistory] on_frame_unload_callback (" << context << ")");
+
+    TizenApis::Tizen1_0::CallHistoryAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+    TizenApis::Tizen1_0::CallHistoryListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+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,
+        CALLHISTORY,
+        (js_class_template_getter)TizenApis::Tizen1_0::JSCallHistory::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_END
+
diff --git a/src/standards/Tizen/Common/AsyncCallbackManager.h b/src/standards/Tizen/Common/AsyncCallbackManager.h
new file mode 100755 (executable)
index 0000000..b0cf119
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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        AsyncCallbackManager.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_COMMONS_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_COMMONS_ASYNC_CALLBACK_MANAGER_H_
+
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/type_list.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+namespace TizenApis {
+namespace Commons {
+
+class AsyncCallbackManager
+{
+public:
+       typedef std::map<WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr, JSContextRef>  JSCallbackManagerMap;
+       typedef typename JSCallbackManagerMap::iterator                                         JSCallbackManagerMapIter;
+       typedef std::pair<WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr,JSContextRef>  JSCallbackManagerPair;
+
+       AsyncCallbackManager()
+       {
+       };
+
+       virtual ~AsyncCallbackManager()
+       {
+               m_map.clear();
+       };
+
+       virtual void registerCallbackManager(WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr &cbm, const JSContextRef context)
+       {
+               LogDebug("Registering an callback manager on context:" << context);
+               m_map.insert(JSCallbackManagerPair(cbm, context));
+       }
+
+       virtual void unregisterContext(const JSContextRef context)
+       {
+               LogDebug("Unregistering all callback managers on context:" << context);
+               for(JSCallbackManagerMapIter i=m_map.begin(); i!=m_map.end(); i++)
+               {
+                       if(i->second == context)
+                       {
+                               LogDebug("unregister a callback manager");
+                               i->first->setOnSuccess(NULL);
+                               i->first->setOnError(NULL);
+                               // This function does not remove cbm from multimap.
+                               // It only prohibit plugin invoke javascript callback.
+                       }
+               }
+       }
+
+       virtual void unregisterCallbackManager(const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr &cbm)
+       {
+               LogDebug("Unregistering an callback manager");
+               JSCallbackManagerMapIter i = m_map.find(cbm);
+
+               if(i == m_map.end())
+               {
+                       LogWarning("nothing to unregister");
+                       // Something wrong
+                       return;
+               }
+
+               m_map.erase(i);
+       }
+
+private:
+       JSCallbackManagerMap m_map;
+};
+
+} // Commons
+} // TizenApis
+
+#endif // _TIZEN_COMMONS_ASYNC_CALLBACK_MANAGER_H_
diff --git a/src/standards/Tizen/Common/CMakeLists.txt b/src/standards/Tizen/Common/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..f1e1038
--- /dev/null
@@ -0,0 +1,16 @@
+set(SRCS
+  JSTizenException.cpp
+  TizenExceptionData.cpp
+  JSTizenExceptionFactory.cpp
+  JSWebAPIError.cpp
+)
+
+add_library(${COMMON_TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${COMMON_TARGET_NAME}
+  #${LIBS_WIDGETDB}
+  ${LIBS_COMMON}
+  #${wrt-plugins-plugin-manager_LIBRARIES}
+)
+
+INSTALL(TARGETS ${COMMON_TARGET_NAME} LIBRARY DESTINATION ${COMMON_DESTINATION_NAME})
diff --git a/src/standards/Tizen/Common/IListenerManager.h b/src/standards/Tizen/Common/IListenerManager.h
new file mode 100755 (executable)
index 0000000..0ade1ab
--- /dev/null
@@ -0,0 +1,155 @@
+//
+// 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        IListenerManager.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_COMMONS_ILISTENER_MANAGER_H_
+#define _TIZEN_COMMONS_ILISTENER_MANAGER_H_
+
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Commons {
+
+class IListenerItem;
+typedef DPL::SharedPtr<IListenerItem> IListenerItemPtr;
+
+class IListenerItem
+{
+public:
+       IListenerItem(JSContextRef context, JSObjectRef object, long watchId) :
+               m_context(context),
+               m_object(object),
+               m_watchId(watchId)
+       {
+       }
+
+       virtual ~IListenerItem()
+       {
+       }
+
+       virtual void protectObject()
+       {
+               LogDebug("Protect object:" << m_object);
+
+               JSValueProtect(m_context, m_object);
+       }
+
+       virtual void unprotectObject()
+       {
+               LogDebug("Unprotect object:" << m_object);
+
+               JSValueUnprotect(m_context, m_object);
+       }
+
+       virtual void cancelListener()
+       {
+               LogWarning("IListenerItem MUST be used as an inherited shape.");
+               LogWarning("If this log has been printed, it must be used with wrong usage.");
+       }
+
+       virtual bool equal(const TizenApis::Commons::IListenerItemPtr &other) const
+       {
+               if(!other)
+                       return false;
+
+               if(m_object == other->m_object && m_watchId == other->m_watchId)
+                       return true;
+
+               return false;
+       }
+
+protected:
+       JSContextRef    m_context;
+       JSObjectRef             m_object;
+       long                    m_watchId;
+};
+
+class IListenerController
+{
+public:
+       typedef std::multimap<JSContextRef, IListenerItemPtr>   ListenerMap;
+       typedef typename ListenerMap::iterator                  ListenerMapIter;
+       typedef std::pair<JSContextRef, IListenerItemPtr>       ListenerPair;
+       typedef std::pair<ListenerMapIter, ListenerMapIter>     ListenerMapIterPair;
+
+       IListenerController()
+       {
+       }
+
+       virtual ~IListenerController()
+       {
+       }
+
+       virtual void registerListener(IListenerItemPtr &canceller, const JSContextRef context)
+       {
+               LogDebug("Registering a listener on context:" << context);
+
+               canceller->protectObject();
+               m_map.insert(ListenerPair(context, canceller));
+       }
+
+       virtual void unregisterContext(const JSContextRef context)
+       {
+               LogDebug("Unregistering all listeners on context:" << context);
+
+               ListenerMapIterPair iterPair = m_map.equal_range(context);
+
+               for(ListenerMapIter i=iterPair.first; i!=iterPair.second; i++)
+               {
+                       LogDebug("Unregistering a listener");
+                       i->second->cancelListener();
+                       i->second->unprotectObject();
+               }
+
+               m_map.erase(context);
+       }
+
+       virtual void unregisterListener(const IListenerItemPtr &canceller)
+       {
+               LogDebug("Unregistering a listener");
+
+               for(ListenerMapIter i=m_map.begin(); i!=m_map.end(); i++)
+               {
+                       if(i->second->equal(canceller))
+                       {
+                               LogDebug("Found object");
+                               i->second->unprotectObject();
+
+                               m_map.erase(i);
+
+                               break;
+                       }
+               }
+       }
+
+private:
+       ListenerMap m_map;
+};
+
+} // Commons
+} // TizenApis
+
+#endif // _TIZEN_COMMONS_ILISTENER_MANAGER_H_
diff --git a/src/standards/Tizen/Common/JSTizenException.cpp b/src/standards/Tizen/Common/JSTizenException.cpp
new file mode 100644 (file)
index 0000000..af0f803
--- /dev/null
@@ -0,0 +1,144 @@
+//
+// 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 "JSTizenException.h"
+
+#include <dpl/log/log.h>
+
+#include <CommonsJavaScript/Converter.h>
+
+namespace TizenApis {
+       namespace Commons {
+
+               const std::string JSTizenException::UNKNOWN_ERROR           = "UnknownError";
+               const std::string JSTizenException::TYPE_MISMATCH_ERROR     = "TypeMismatchError";
+               const std::string JSTizenException::INVALID_VALUES_ERROR    = "InvalidValuesError";
+               const std::string JSTizenException::TIMEOUT_ERROR           = "TimeoutError";
+               const std::string JSTizenException::IO_ERROR                = "IOError";
+               const std::string JSTizenException::NOT_SUPPORTED_ERROR     = "NotSupportedError";
+               const std::string JSTizenException::PERMISSION_DENIED_ERROR = "SecurityError";
+               const std::string JSTizenException::NOT_FOUND_ERROR         = "NotFoundError";
+               const std::string JSTizenException::SERVICE_NOT_AVAILABLE   = "ServiceNotAvailableError";
+               const std::string JSTizenException::NETWORK_ERROR           = "NetworkError";
+               const std::string JSTizenException::INVALID_ACCESS_ERROR    = "InvalidAccessError";
+
+               namespace{
+                       #define PLUGIN_NAME       "TizenException"
+                       #define PROPERTY_NAME     "name"
+                       #define PROPERTY_MESSAGE  "message"
+
+                       const std::string PROPERTY_ERROR[] = {
+                                       TizenApis::Commons::JSTizenException::UNKNOWN_ERROR,
+                                       TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR,
+                                       TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR,
+                                       TizenApis::Commons::JSTizenException::TIMEOUT_ERROR,
+                                       TizenApis::Commons::JSTizenException::IO_ERROR,
+                                       TizenApis::Commons::JSTizenException::NOT_SUPPORTED_ERROR,
+                                       TizenApis::Commons::JSTizenException::PERMISSION_DENIED_ERROR,
+                                       TizenApis::Commons::JSTizenException::NOT_FOUND_ERROR,
+                                       TizenApis::Commons::JSTizenException::NETWORK_ERROR,
+                                       TizenApis::Commons::JSTizenException::INVALID_ACCESS_ERROR,
+                       };
+               }
+
+               JSClassRef JSTizenException::m_classRef = NULL;
+
+               JSClassDefinition JSTizenException::m_classInfo = {
+                       0,
+                       kJSClassAttributeNone,
+                       PLUGIN_NAME,
+                       0,
+                       m_properties,
+                       NULL, //__function,
+                       initialize,
+                       finalize,
+                       hasProperty,
+                       NULL,
+                       NULL, //SetProperty,
+                       NULL, //DeleteProperty,
+                       NULL,
+                       NULL, //CallAsFunction,
+                       NULL, //CallAsConstructor,
+                       hasInstance,
+                       NULL, //ConvertToType,
+               };
+
+               JSStaticValue JSTizenException::m_properties[] = {
+                       { PROPERTY_NAME,    getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { PROPERTY_MESSAGE, getStaticProperty, NULL, kJSPropertyAttributeReadOnly },
+                       { 0, 0, 0, 0 }
+               };
+
+               const JSClassDefinition* JSTizenException::getClassInfo() {
+                       return &m_classInfo;
+               }
+
+               JSClassRef JSTizenException::getClassRef() {
+                       if (!m_classRef) {
+                               m_classRef = JSClassCreate(&m_classInfo);
+                       }
+                       return m_classRef;
+               }
+
+               void JSTizenException::initialize(JSContextRef /*context*/, JSObjectRef /*object*/) {
+               }
+
+               void JSTizenException::finalize(JSObjectRef object) {
+                       PrivateObject* privateObject = static_cast<PrivateObject*> (JSObjectGetPrivate(object));
+                       if (privateObject) {
+                               JSObjectSetPrivate(object, NULL);
+                               delete privateObject;
+                       }
+               }
+
+               bool JSTizenException::hasProperty(JSContextRef /*context*/, JSObjectRef /*object*/, JSStringRef propertyName) {
+                       const size_t size = sizeof(PROPERTY_ERROR) / sizeof(PROPERTY_ERROR[0]);
+                       for (size_t i = 0; i < size; ++i) {
+                               if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_ERROR[i].c_str())) {
+                                       return true;
+                               }
+                       }
+                       return false;
+               }
+
+               JSValueRef JSTizenException::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_NAME)) {
+//                                     return converter.toJSValueRef(privateObject->getObject()->getName());
+//                             } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_MESSAGE)) {
+//                                     return converter.toJSValueRef(privateObject->getObject()->getMessage());
+//                             }
+//                     } catch (const WrtDeviceApis::Commons::ConversionException& ex) {
+//                             LogError("Exception: " << ex.GetMessage());
+//                     }
+
+                       return JSValueMakeUndefined(context);
+               }
+
+               bool JSTizenException::hasInstance(JSContextRef context, JSObjectRef /*constructor*/, JSValueRef possibleInstance, JSValueRef* /*exception*/) {
+                       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+               }
+               
+       }// Commons
+}      //TizenApis
diff --git a/src/standards/Tizen/Common/JSTizenException.h b/src/standards/Tizen/Common/JSTizenException.h
new file mode 100644 (file)
index 0000000..8be78e1
--- /dev/null
@@ -0,0 +1,98 @@
+//
+// 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 JSTIZENEXCEPTION_H_
+#define JSTIZENEXCEPTION_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+#include "TizenExceptionData.h"
+
+namespace TizenApis {
+
+       namespace Commons {
+
+               /**
+                * @deprecated
+                * TizenException is deprecated. use JSWebAPIError instead.
+               */
+               class JSTizenException {
+                       public:
+                               typedef  WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenExceptionDataPtr>::Type PrivateObject;
+
+                       public:
+                               static const std::string UNKNOWN_ERROR;
+                               static const std::string TYPE_MISMATCH_ERROR;
+                               static const std::string INVALID_VALUES_ERROR;
+                               static const std::string TIMEOUT_ERROR;
+                               static const std::string IO_ERROR;
+                               static const std::string NOT_SUPPORTED_ERROR;
+                               static const std::string PERMISSION_DENIED_ERROR;
+                               static const std::string NOT_FOUND_ERROR;
+                               static const std::string SERVICE_NOT_AVAILABLE;
+                               static const std::string NETWORK_ERROR;
+                               static const std::string INVALID_ACCESS_ERROR;
+                         public:
+                               static JSClassRef getClassRef();
+
+                               static const JSClassDefinition* getClassInfo();
+
+                       private:
+                               /**
+                                * The callback invoked when an object is first created.
+                                */
+                               static void initialize(JSContextRef context, JSObjectRef object);
+
+                               /**
+                                * The callback invoked when an object is finalized.
+                                */
+                               static void finalize(JSObjectRef object);
+
+                               /**
+                                * The callback invoked when getting a property's value.
+                                */
+                               static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+
+                               /**
+                                * The callback invoked when getting a property's value.
+                                */
+                               static JSValueRef 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);
+
+                               /**
+                                * 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;
+               };
+
+       }
+
+}
+
+#endif /* JSTIZENEXCEPTION_H_ */
diff --git a/src/standards/Tizen/Common/JSTizenExceptionFactory.cpp b/src/standards/Tizen/Common/JSTizenExceptionFactory.cpp
new file mode 100644 (file)
index 0000000..19c31ef
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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 "JSTizenExceptionFactory.h"
+
+#include <dpl/assert.h>
+#include <dpl/log/log.h>
+
+#include <CommonsJavaScript/JSUtils.h>
+
+#include "TizenExceptionData.h"
+#include "JSWebAPIError.h"
+
+namespace TizenApis {
+
+       namespace Commons {
+
+               JSTizenExceptionFactory::JSTizenExceptionFactory() {
+               }
+
+               JSTizenExceptionFactory::~JSTizenExceptionFactory() {
+               }
+
+               JSObjectRef JSTizenExceptionFactory::makeErrorObject(JSContextRef context, const std::string& name, const std::string& message) {
+
+                       int code = JSWebAPIError::convertToWebAPIErrorCode(name);
+
+                       JSWebAPIError::PrivateObject::ObjectType data(new TizenExceptionData(code, name, message));
+                       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(context, JSWebAPIError::getClassRef(), data);
+               }
+
+               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);
+
+                       JSWebAPIError::PrivateObject::ObjectType data(new TizenExceptionData(code, name, message));
+                       *exception = WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(context, JSWebAPIError::getClassRef(), data);
+                       return JSValueMakeUndefined(context);
+               }
+
+       }       // Commons
+
+}      //TizenApis
diff --git a/src/standards/Tizen/Common/JSTizenExceptionFactory.h b/src/standards/Tizen/Common/JSTizenExceptionFactory.h
new file mode 100644 (file)
index 0000000..ec16ee1
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// 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 JSTIZENEXCEPTIONFACTORY_H_
+#define JSTIZENEXCEPTIONFACTORY_H_
+
+
+#include <string>
+#include <dpl/noncopyable.h>
+#include <JavaScriptCore/JavaScript.h>
+
+namespace TizenApis {
+
+       namespace Commons {
+
+               class JSTizenExceptionFactory : public DPL::Noncopyable {
+                       public:
+                               JSTizenExceptionFactory();
+                               virtual ~JSTizenExceptionFactory();
+
+                       public:
+                               static JSObjectRef makeErrorObject(JSContextRef context, const std::string& name, const std::string& message=std::string());
+                               static JSValueRef  postException  (JSContextRef context, JSValueRef* exception, const std::string& name, const std::string& message=std::string());
+               };
+
+       }       //Commons
+
+}      //TizenApis
+
+#endif /* JSTIZENEXCEPTIONFACTORY_H_ */
diff --git a/src/standards/Tizen/Common/JSWebAPIError.cpp b/src/standards/Tizen/Common/JSWebAPIError.cpp
new file mode 100644 (file)
index 0000000..137b691
--- /dev/null
@@ -0,0 +1,298 @@
+//
+// 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 "JSWebAPIError.h"
+
+#include <dpl/log/log.h>
+
+#include <CommonsJavaScript/Converter.h>
+
+namespace TizenApis {
+       namespace Commons {
+
+               namespace{
+                       #define PLUGIN_NAME       "WebAPIError"
+                       #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 JSWebAPIError::m_classRef = NULL;
+
+               JSClassDefinition JSWebAPIError::m_classInfo = {
+                       0,
+                       kJSClassAttributeNone,
+                       PLUGIN_NAME,
+                       0,
+                       m_properties,
+                       NULL, //__function,
+                       initialize,
+                       finalize,
+                       NULL,
+                       NULL,
+                       NULL, //SetProperty,
+                       NULL, //DeleteProperty,
+                       NULL,
+                       NULL, //CallAsFunction,
+                       NULL, //CallAsConstructor,
+                       hasInstance,
+                       NULL, //ConvertToType,
+               };
+
+               JSStaticValue JSWebAPIError::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* JSWebAPIError::getClassInfo() {
+                       return &m_classInfo;
+               }
+
+               JSClassRef JSWebAPIError::getClassRef() {
+                       if (!m_classRef) {
+                               m_classRef = JSClassCreate(&m_classInfo);
+                       }
+                       return m_classRef;
+               }
+
+               void JSWebAPIError::initialize(JSContextRef /*context*/, JSObjectRef /*object*/) {
+               }
+
+               void JSWebAPIError::finalize(JSObjectRef object) {
+                       PrivateObject* privateObject = static_cast<PrivateObject*> (JSObjectGetPrivate(object));
+                       if (privateObject) {
+                               JSObjectSetPrivate(object, NULL);
+                               delete privateObject;
+                       }
+               }
+
+               JSValueRef JSWebAPIError::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);
+               }
+
+               bool JSWebAPIError::hasInstance(JSContextRef context, JSObjectRef /*constructor*/, JSValueRef possibleInstance, JSValueRef* /*exception*/) {
+                       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+               }
+
+               int JSWebAPIError::convertToWebAPIErrorCode(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;
+               }
+
+       } /* namespace Commons */
+} /* namespace TizenApis */
diff --git a/src/standards/Tizen/Common/JSWebAPIError.h b/src/standards/Tizen/Common/JSWebAPIError.h
new file mode 100644 (file)
index 0000000..dfae7a1
--- /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 JSWEBAPIERROR_H_
+#define JSWEBAPIERROR_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+#include "JSTizenException.h"
+
+namespace TizenApis {
+       namespace Commons {
+
+               class JSWebAPIError {
+                       public:
+                               typedef  WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenExceptionDataPtr>::Type PrivateObject;
+
+                               static JSClassRef getClassRef();
+                               static const JSClassDefinition* getClassInfo();
+
+                               static int convertToWebAPIErrorCode(const std::string& errorName);
+
+                       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);
+
+                               /**
+                                * 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;
+
+                       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,
+
+                               };      //WebAPIError
+               };
+
+       } /* namespace Commons */
+} /* namespace TizenApis */
+#endif /* JSWEBAPIERROR_H_ */
diff --git a/src/standards/Tizen/Common/SecurityExceptions.h b/src/standards/Tizen/Common/SecurityExceptions.h
new file mode 100755 (executable)
index 0000000..1123419
--- /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 TIZENAPIS_COMMONS_JS_SECURITYEXCEPTIONS_H_
+#define TIZENAPIS_COMMONS_JS_SECURITYEXCEPTIONS_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "JSTizenExceptionFactory.h"
+
+namespace TizenApis {
+namespace Commons {
+
+/**
+ * synchronously checks access status and throws JS Security exception if
+ * necessary
+ */
+       #define TIZEN_SYNC_ACCESS_HANDLER(status, context, exception) \
+       do { \
+               switch (status) { \
+                       case AceSecurityStatus::InternalError: \
+                               return JSTizenExceptionFactory::postException(context, exception, \
+                                               JSTizenException::UNKNOWN_ERROR); \
+                               break; \
+                       case AceSecurityStatus::AccessDenied:                                  \
+                               return JSTizenExceptionFactory::postException(context, exception, \
+                                       JSTizenException::PERMISSION_DENIED_ERROR); \
+                               break; \
+                       default: \
+                               break; \
+               } \
+       } while (0)
+
+/**
+ * checks access status and returns an error through JSCallbackManager if
+ * necessary
+ */
+#define TIZEN_ASYNC_CBM_ACCESS_HANDLER(status, context, cbm) \
+       do { \
+               switch (status) { \
+               case AceSecurityStatus::InternalError: \
+                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, \
+                                       "SECURITY_ERROR", "internal error")); \
+                       return JSValueMakeNull(context); \
+               case AceSecurityStatus::AccessDenied: \
+                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, \
+                                               JSTizenException::PERMISSION_DENIED_ERROR, "PERMISSION_DENIED_ERROR")); \
+                       return JSValueMakeNull(context); \
+               default: \
+                       break; \
+               } \
+       } while (0)
+
+}
+}
+#endif /*TIZENAPIS_COMMONS_JS_SECURITYEXCEPTIONS_H_ */
+
diff --git a/src/standards/Tizen/Common/TizenExceptionData.cpp b/src/standards/Tizen/Common/TizenExceptionData.cpp
new file mode 100644 (file)
index 0000000..a87b3dd
--- /dev/null
@@ -0,0 +1,41 @@
+//
+// 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 "TizenExceptionData.h"
+namespace TizenApis {
+       namespace Commons {
+
+               TizenExceptionData::TizenExceptionData(int code, const std::string& name, const std::string& message) :
+               m_code(code), m_name(name), m_message(message) {
+               }
+
+               TizenExceptionData::~TizenExceptionData() {
+               }
+
+               int TizenExceptionData::getCode() const {
+                       return m_code;
+               }
+
+               std::string TizenExceptionData::getName() const {
+                       return m_name;
+               }
+
+               std::string TizenExceptionData::getMessage() const {
+                       return m_message;
+               }
+       } // Commons
+} // TizenApis
diff --git a/src/standards/Tizen/Common/TizenExceptionData.h b/src/standards/Tizen/Common/TizenExceptionData.h
new file mode 100755 (executable)
index 0000000..1a1a251
--- /dev/null
@@ -0,0 +1,47 @@
+//
+// 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 TIZENEXCEPTIONDATA_H_
+#define TIZENEXCEPTIONDATA_H_
+
+#include <string>
+#include <dpl/shared_ptr.h>
+
+namespace TizenApis {
+namespace Commons {
+
+class TizenExceptionData {
+       public:
+               TizenExceptionData(int code, const std::string& name, const std::string& message = std::string());
+               virtual ~TizenExceptionData();
+
+               int getCode() const;
+               std::string getName() const;
+               std::string getMessage() const;
+
+       private :
+               int m_code;
+               std::string m_name;
+               std::string m_message;
+};
+
+typedef DPL::SharedPtr<TizenExceptionData> TizenExceptionDataPtr;
+
+} // Commons
+} // TizenApis
+
+#endif /* TIZENEXCEPTIONDATA_H_ */
diff --git a/src/standards/Tizen/Contact/AddressBookController.cpp b/src/standards/Tizen/Contact/AddressBookController.cpp
new file mode 100755 (executable)
index 0000000..8be321d
--- /dev/null
@@ -0,0 +1,465 @@
+//
+// 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        ContactManagerController.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "AddressBookController.h"
+#include "ContactConverter.h"
+#include "JSAddressBookChangeCallbackManager.h"
+#include "ContactAsyncCallbackManager.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+AddressBookController::AddressBookController(JSContextRef context, AddressBookPtr addressBook) :
+               EventAddressBookAddBatchEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventAddressBookUpdateBatchEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventAddressBookRemoveBatchEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventAddressBookFindEventAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventAddressBookChangeListenerListener(ThreadEnum::NULL_THREAD),
+               AddressBookPrivObject(context, addressBook)
+{
+       LogDebug("AddressBookController constructed : " << this);
+       if (!addressBook) {
+               LogWarning("controller has no addressBook object");
+       }
+}
+
+AddressBookController::~AddressBookController()
+{
+       LogDebug("AddressBookController destructed : " << this);
+}
+
+void AddressBookAsyncAnswerHandler::addBatch(const EventAddressBookAddBatchPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ContactAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid value error");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       Try {
+               if (!event->getResult())
+                       ThrowMsg(PlatformException, "No result.");
+
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
+               ContactArrayPtr contacts = event->getContacts();
+
+               JSValueRef result = converter->toJSValueRef(contacts);
+
+               callbackManager->callOnSuccess(result);
+               return;
+       } Catch(Exception) {
+               LogError("error during processing answer" << _rethrown_exception.GetMessage());
+               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+
+               callbackManager->callOnError(error);
+               return;
+       }
+}
+
+void AddressBookAsyncAnswerHandler::updateBatch(const EventAddressBookUpdateBatchPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ContactAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid value error");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       callbackManager->callOnSuccess();
+}
+
+void AddressBookAsyncAnswerHandler::removeBatch(const EventAddressBookRemoveBatchPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ContactAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid value error");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       callbackManager->callOnSuccess();
+}
+
+void AddressBookAsyncAnswerHandler::find(const EventAddressBookFindPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager)
+       {
+               LogError("no callback manager");
+               return;
+       }
+
+       ContactAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_SUPPORTED_ERROR, "Not support such a filter");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid value error");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       Try {
+               if (!event->getResult())
+                       ThrowMsg(PlatformException, "No result.");
+
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
+               ContactArrayPtr contacts = event->getContacts();
+
+               JSValueRef result = converter->toJSValueRef(contacts);
+
+               callbackManager->callOnSuccess(result);
+               return;
+       } Catch(Exception) {
+               LogError("error during processing answer" << _rethrown_exception.GetMessage());
+               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+
+               callbackManager->callOnError(error);
+               return;
+       }
+}
+
+void AddressBookAsyncAnswerHandler::changeListenerError(const EventAddressBookChangeListenerPtr &event)
+{
+       LogDebug("entered");
+       JSValueRef errorObject;
+
+       JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!cbm)
+       {
+               LogError("no callback manager");
+               return;
+       }
+
+       JSContextRef gContext = cbm->getContext();
+
+       if (event->getExceptionCode() == ExceptionCodes::NotFoundException)
+               errorObject = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "Not found error");
+       else
+               errorObject = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+
+       cbm->callOnError(errorObject);
+}
+
+void AddressBookAsyncAnswerHandler::changeListenerContactAdded(const EventAddressBookChangeListenerPtr &event)
+{
+       LogDebug("entered");
+       JSAddressBookChangeCallbackManagerPtr cbm =
+               DPL::StaticPointerCast<JSAddressBookChangeCallbackManager>(event->getPrivateData());
+       if (!cbm)
+       {
+               LogError("no callback manager");
+               return;
+       }
+
+       EventInfoAddressBookChangePtr _eventInfo = event->getEventInfo();
+       if(_eventInfo->getCallbackType() != EventInfoAddressBookChange::OnContactsAdded)
+       {
+               LogError("wrong type");
+               return;
+       }
+
+       EventInfoAddressBookChangeAddedPtr eventInfo = DPL::DynamicPointerCast<EventInfoAddressBookChangeAdded>(_eventInfo);
+
+       if (!eventInfo->getContactsIsSet())
+       {
+               LogError("no data set");
+               return;
+       }
+
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(cbm->getContext());
+
+       JSValueRef contacts;
+       Try {
+               contacts = converter->toJSValueRef(eventInfo->getContacts());
+       } Catch (Exception) {
+               LogError("Conversion error");
+               return;
+       }
+
+       cbm->callOnContactsAdded(contacts);
+}
+
+void AddressBookAsyncAnswerHandler::changeListenerContactUpdated(const EventAddressBookChangeListenerPtr &event)
+{
+       LogDebug("entered");
+       JSAddressBookChangeCallbackManagerPtr cbm =
+               DPL::StaticPointerCast<JSAddressBookChangeCallbackManager>(event->getPrivateData());
+       if (!cbm)
+       {
+               LogError("no callback manager");
+               return;
+       }
+
+       EventInfoAddressBookChangePtr _eventInfo = event->getEventInfo();
+       if(_eventInfo->getCallbackType() != EventInfoAddressBookChange::OnContactsUpdated)
+       {
+               LogError("wrong type");
+               return;
+       }
+
+       EventInfoAddressBookChangeUpdatedPtr eventInfo = DPL::DynamicPointerCast<EventInfoAddressBookChangeUpdated>(_eventInfo);
+
+       if (!eventInfo->getContactsIsSet())
+       {
+               LogError("no data set");
+               return;
+       }
+
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(cbm->getContext());
+
+       JSValueRef contacts;
+       Try {
+               contacts = converter->toJSValueRef(eventInfo->getContacts());
+       } Catch (Exception) {
+               LogError("Conversion error");
+               return;
+       }
+
+       cbm->callOnContactsUpdated(contacts);
+}
+
+void AddressBookAsyncAnswerHandler::changeListenerContactRemoved(const EventAddressBookChangeListenerPtr &event)
+{
+       LogDebug("entered");
+       JSAddressBookChangeCallbackManagerPtr cbm =
+               DPL::StaticPointerCast<JSAddressBookChangeCallbackManager>(event->getPrivateData());
+       if (!cbm)
+       {
+               LogError("no callback manager");
+               return;
+       }
+
+       EventInfoAddressBookChangePtr _eventInfo = event->getEventInfo();
+       if(_eventInfo->getCallbackType() != EventInfoAddressBookChange::OnContactsRemoved)
+       {
+               LogError("wrong type");
+               return;
+       }
+
+       EventInfoAddressBookChangeRemovedPtr eventInfo = DPL::DynamicPointerCast<EventInfoAddressBookChangeRemoved>(_eventInfo);
+       if (!eventInfo->getContactIdsIsSet())
+       {
+               LogError("no data set");
+               return;
+       }
+
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(cbm->getContext());
+
+       JSValueRef contactIds;
+       Try {
+               contactIds = converter->toJSValueRef(eventInfo->getContactIds());
+       } Catch (Exception) {
+               LogError("Conversion error");
+               return;
+       }
+
+       cbm->callOnContactsDeleted(contactIds);
+}
+
+void AddressBookController::OnAnswerReceived(const EventAddressBookAddBatchPtr &event)
+{
+       AddressBookAsyncAnswerHandler::addBatch(event);
+}
+
+void AddressBookController::OnAnswerReceived(const EventAddressBookUpdateBatchPtr &event)
+{
+       AddressBookAsyncAnswerHandler::updateBatch(event);
+}
+
+void AddressBookController::OnAnswerReceived(const EventAddressBookRemoveBatchPtr &event)
+{
+       AddressBookAsyncAnswerHandler::removeBatch(event);
+}
+
+void AddressBookController::OnAnswerReceived(const EventAddressBookFindPtr &event)
+{
+       AddressBookAsyncAnswerHandler::find(event);
+}
+
+void AddressBookController::onAnswerReceived(const EventAddressBookChangeListenerPtr &event)
+{
+       EventInfoAddressBookChangePtr eventInfo = event->getEventInfo();
+       if(eventInfo == NULL)
+       {
+               LogError("wrong type");
+               return;
+       }
+
+       EventInfoAddressBookChange::CallbackType type = eventInfo->getCallbackType();
+       if(type == EventInfoAddressBookChange::OnContactsAdded)
+               AddressBookAsyncAnswerHandler::changeListenerContactAdded(event);
+       else if(type == EventInfoAddressBookChange::OnContactsUpdated)
+               AddressBookAsyncAnswerHandler::changeListenerContactUpdated(event);
+       else if(type == EventInfoAddressBookChange::OnContactsRemoved)
+               AddressBookAsyncAnswerHandler::changeListenerContactRemoved(event);
+       else if(type == EventInfoAddressBookChange::OnError)
+               AddressBookAsyncAnswerHandler::changeListenerError(event);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/AddressBookController.h b/src/standards/Tizen/Contact/AddressBookController.h
new file mode 100755 (executable)
index 0000000..5dc53a7
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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        AddressBookController.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_ADDRESS_BOOK_CONTROLLER_H_
+#define _TIZEN_CONTACT_ADDRESS_BOOK_CONTROLLER_H_
+
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <Commons/EventReceiver.h>
+#include <Commons/EventListener.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSPendingOperationPrivateObject.h>
+#include <CommonsJavaScript/JSPendingOperation.h>
+#include <API/Contact/IAddressBook.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::AddressBookPtr,
+                                                          WrtDeviceApis::CommonsJavaScript::NoOwnership> AddressBookPrivObject;
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventAddressBookAddBatch> EventAddressBookAddBatchEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventAddressBookUpdateBatch> EventAddressBookUpdateBatchEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventAddressBookRemoveBatch> EventAddressBookRemoveBatchEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventAddressBookFind> EventAddressBookFindEventAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventListener<TizenApis::Api::Contact::EventAddressBookChangeListener> EventAddressBookChangeListenerListener;
+
+class AddressBookController :
+       public EventAddressBookAddBatchEventAnswerReceiver,
+       public EventAddressBookUpdateBatchEventAnswerReceiver,
+       public EventAddressBookRemoveBatchEventAnswerReceiver,
+       public EventAddressBookFindEventAnswerReceiver,
+       public EventAddressBookChangeListenerListener,
+       public AddressBookPrivObject
+{
+public:
+       AddressBookController(JSContextRef context,
+                       TizenApis::Api::Contact::AddressBookPtr addressBook);
+       virtual ~AddressBookController();
+protected:
+       void     OnAnswerReceived(const TizenApis::Api::Contact::EventAddressBookAddBatchPtr &event);
+       void     OnAnswerReceived(const TizenApis::Api::Contact::EventAddressBookUpdateBatchPtr &event);
+       void     OnAnswerReceived(const TizenApis::Api::Contact::EventAddressBookRemoveBatchPtr &event);
+       void     OnAnswerReceived(const TizenApis::Api::Contact::EventAddressBookFindPtr &event);
+       void     onAnswerReceived(const TizenApis::Api::Contact::EventAddressBookChangeListenerPtr &event);
+};
+
+typedef DPL::SharedPtr<AddressBookController> AddressBookControllerPtr;
+
+//common part
+class AddressBookAsyncAnswerHandler
+{
+public:
+       static void addBatch(const TizenApis::Api::Contact::EventAddressBookAddBatchPtr &event);
+       static void updateBatch(const TizenApis::Api::Contact::EventAddressBookUpdateBatchPtr &event);
+       static void removeBatch(const TizenApis::Api::Contact::EventAddressBookRemoveBatchPtr &event);
+       static void find(const TizenApis::Api::Contact::EventAddressBookFindPtr &event);
+       static void changeListenerError(const TizenApis::Api::Contact::EventAddressBookChangeListenerPtr &event);
+       static void changeListenerContactAdded(const TizenApis::Api::Contact::EventAddressBookChangeListenerPtr &event);
+       static void changeListenerContactUpdated(const TizenApis::Api::Contact::EventAddressBookChangeListenerPtr &event);
+       static void changeListenerContactRemoved(const TizenApis::Api::Contact::EventAddressBookChangeListenerPtr &event);
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_ADDRESS_BOOK_CONTROLLER_H_
diff --git a/src/standards/Tizen/Contact/CMakeLists.txt b/src/standards/Tizen/Contact/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..b61cb2e
--- /dev/null
@@ -0,0 +1,73 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-contact")
+set(DESTINATION_NAME "tizen-2.0-contact")
+set(TARGET_IMPL_NAME "wrt-plugins-tizen-2.0-contact-impl")
+
+include_directories(
+  ${INCLUDES_PLATFORM_IMPLEMENTATION_CONTACT}
+)
+
+set(CMAKE_INSTALL_RPATH
+  ${CMAKE_INSTALL_RPATH}
+  ${CMAKE_INSTALL_PREFIX}/${DESTINATION_NAME}
+  ${CMAKE_INSTALL_PREFIX}/tizen-2.0-tizen
+)
+
+set(SRCS_IMPL
+  ${SRCS_PLATFORM_API_CONTACT}
+  ${SRCS_PLATFORM_IMPLEMENTATION_CONTACT}
+  AddressBookController.cpp
+  ContactAsyncCallbackManager.cpp
+  ContactListenerManager.cpp
+  ContactConverter.cpp
+  ContactManagerController.cpp
+  JSContact.cpp
+  JSContactArray.cpp
+  JSAddressBook.cpp
+  JSAddressBookChangeCallbackManager.cpp
+  JSAddressBookArray.cpp
+  JSContactGroup.cpp
+  JSContactGroupArray.cpp
+  JSPerson.cpp
+  JSPersonArray.cpp
+  JSContactRef.cpp
+  JSContactName.cpp
+  JSContactAnniversary.cpp
+  JSContactAnniversaryArray.cpp
+  #JSAttributesOfInterestArray.cpp
+  JSContactAddress.cpp
+  JSContactAddressArray.cpp
+  JSContactAddressTypeArray.cpp
+  JSContactManager.cpp
+  JSContactManagerChangeCallbackManager.cpp
+  JSContactPhoneNumber.cpp
+  JSContactPhoneNumberArray.cpp
+  JSContactPhoneNumberTypeArray.cpp
+  JSContactEmailAddress.cpp
+  JSContactEmailAddressArray.cpp
+  JSContactEmailAddressTypeArray.cpp
+  JSContactOrganization.cpp
+  JSContactOrganizationArray.cpp
+  JSStringArray.cpp
+  JSContactWebSite.cpp
+  JSContactWebSiteArray.cpp
+  plugin_config.cpp
+)
+
+add_library(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
+target_link_libraries(${TARGET_IMPL_NAME}
+  wrt-plugins-tizen-2.0-tizen-impl
+  ${LIBS_PLATFORM_IMPLEMENTATION_CONTACT}
+  ${LIBS_COMMON}
+)
+
+set(SRCS
+  plugin_initializer.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${TARGET_IMPL_NAME}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
diff --git a/src/standards/Tizen/Contact/ContactAsyncCallbackManager.cpp b/src/standards/Tizen/Contact/ContactAsyncCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..05a3e60
--- /dev/null
@@ -0,0 +1,38 @@
+//
+// 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        ContactAsyncCallbackManager.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactAsyncCallbackManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::Contact::ContactAsyncCallbackManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/ContactAsyncCallbackManager.h b/src/standards/Tizen/Contact/ContactAsyncCallbackManager.h
new file mode 100755 (executable)
index 0000000..2fef77a
--- /dev/null
@@ -0,0 +1,55 @@
+//
+// 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        ContactAsyncCallbackManager.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_CONTACT_ASYNC_CALLBACK_MANAGER_H_
+
+#include <dpl/singleton.h>
+#include <Tizen/Common/AsyncCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+class ContactAsyncCallbackManager : public TizenApis::Commons::AsyncCallbackManager
+{
+public:
+       ContactAsyncCallbackManager()
+       {
+       }
+
+       virtual ~ContactAsyncCallbackManager()
+       {
+       }
+
+       friend class DPL::Singleton<ContactAsyncCallbackManager>;
+};
+
+typedef DPL::Singleton<ContactAsyncCallbackManager> ContactAsyncCallbackManagerSingleton;
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_ASYNC_CALLBACK_MANAGER_H_
diff --git a/src/standards/Tizen/Contact/ContactConverter.cpp b/src/standards/Tizen/Contact/ContactConverter.cpp
new file mode 100755 (executable)
index 0000000..b2bf1b8
--- /dev/null
@@ -0,0 +1,1428 @@
+//
+// 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        ContactConverter.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactConverter.h"
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Commons/RegexUtils.h>
+#include <API/Contact/ContactFactory.h>
+
+#include "AddressBookController.h"
+#include "JSAddressBook.h"
+#include "JSAddressBookArray.h"
+#include "JSContact.h"
+#include "JSContactArray.h"
+#include "JSPerson.h"
+#include "JSPersonArray.h"
+#include "JSContactGroup.h"
+#include "JSContactGroupArray.h"
+#include "JSContactRef.h"
+#include "JSContactName.h"
+#include "JSContactAnniversary.h"
+#include "JSContactAnniversaryArray.h"
+#include "JSContactAddress.h"
+#include "JSContactAddressArray.h"
+#include "JSContactAddressTypeArray.h"
+#include "JSContactManager.h"
+#include "JSContactPhoneNumber.h"
+#include "JSContactPhoneNumberArray.h"
+#include "JSContactPhoneNumberTypeArray.h"
+#include "JSContactEmailAddress.h"
+#include "JSContactEmailAddressArray.h"
+#include "JSContactEmailAddressTypeArray.h"
+#include "JSContactOrganization.h"
+#include "JSContactOrganizationArray.h"
+#include "JSContactWebSite.h"
+#include "JSContactWebSiteArray.h"
+#include "JSStringArray.h"
+
+#define CONTACT_ATTRIBUTE_ACCOUNT_ID "accountId"
+#define CONTACT_ATTRIBUTE_ADDITIONAL_INFORMATION "additionalInformation"
+#define CONTACT_ATTRIBUTE_ADDRESSES "addresses"
+#define CONTACT_ATTRIBUTE_ANNIVERSARIES "anniversaries"
+//#define CONTACT_ATTRIBUTE_ATTRIBUTES_OF_INTEREST "attributesOfInterest"
+#define CONTACT_ATTRIBUTE_BIRTHDAY "birthday"
+#define CONTACT_ATTRIBUTE_CITY "city"
+#define CONTACT_ATTRIBUTE_CONTACT_ID "contactId"
+#define CONTACT_ATTRIBUTE_CONTACT_URI "contactURI"
+#define CONTACT_ATTRIBUTE_COUNTRY "country"
+#define CONTACT_ATTRIBUTE_COUNTY "county"
+#define CONTACT_ATTRIBUTE_DATE "date"
+#define CONTACT_ATTRIBUTE_DEPARTMENT "department"
+#define CONTACT_ATTRIBUTE_DISPLAY_NAME "displayName"
+#define CONTACT_ATTRIBUTE_EMAIL "email"
+#define CONTACT_ATTRIBUTE_EMAILS "emails"
+#define CONTACT_ATTRIBUTE_FIRST_NAME "firstName"
+#define CONTACT_ATTRIBUTE_GROUP_IDS "groupIds"
+#define CONTACT_ATTRIBUTE_ID "id"
+#define CONTACT_ATTRIBUTE_IS_DEFAULT "isDefault"
+#define CONTACT_ATTRIBUTE_IS_FAVORITE "isFavorite"
+#define CONTACT_ATTRIBUTE_LABEL "label"
+#define CONTACT_ATTRIBUTE_LAST_NAME "lastName"
+#define CONTACT_ATTRIBUTE_LAST_UPDATED "lastUpdated"
+#define CONTACT_ATTRIBUTE_LOGO_URI "logoURI"
+#define CONTACT_ATTRIBUTE_MIDDLE_NAME "middleName"
+#define CONTACT_ATTRIBUTE_NAME "name"
+#define CONTACT_ATTRIBUTE_NICKNAMES "nicknames"
+#define CONTACT_ATTRIBUTE_NOTES "notes"
+#define CONTACT_ATTRIBUTE_NUMBER "number"
+#define CONTACT_ATTRIBUTE_OFFICE "office"
+#define CONTACT_ATTRIBUTE_ORGANIZATIONS "organizations"
+#define CONTACT_ATTRIBUTE_PHONE_NUMBERS "phoneNumbers"
+#define CONTACT_ATTRIBUTE_PHONETIC_FIRST_NAME "phoneticFirstName"
+#define CONTACT_ATTRIBUTE_PHONETIC_LAST_NAME "phoneticLastName"
+#define CONTACT_ATTRIBUTE_PHOTO_URI  "photoURI"
+#define CONTACT_ATTRIBUTE_POSITION "position"
+#define CONTACT_ATTRIBUTE_POSTAL_CODE "postalCode"
+#define CONTACT_ATTRIBUTE_PREFIX "prefix"
+#define CONTACT_ATTRIBUTE_READ_ONLY "readOnly"
+#define CONTACT_ATTRIBUTE_REGION "region"
+#define CONTACT_ATTRIBUTE_RINGTONE_URI "ringtoneURI"
+#define CONTACT_ATTRIBUTE_ROLE "role"
+#define CONTACT_ATTRIBUTE_SUFFIX "suffix"
+#define CONTACT_ATTRIBUTE_STREET_ADDRESS "streetAddress"
+#define CONTACT_ATTRIBUTE_TITLE "title"
+#define CONTACT_ATTRIBUTE_TYPE "type"
+#define CONTACT_ATTRIBUTE_TYPES "types"
+#define CONTACT_ATTRIBUTE_URL "url"
+#define CONTACT_ATTRIBUTE_URLS "urls"
+
+#define STR_CONTACT_EMPTY_STRING ""
+
+#define STR_CONTACT_EMAIL_TYPE_WORK "WORK"
+#define STR_CONTACT_EMAIL_TYPE_PREF "PREF"
+#define STR_CONTACT_EMAIL_TYPE_HOME "HOME"
+
+#define STR_CONTACT_PHONE_NUMBER_TYPE_WORK "WORK"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_PREF "PREF"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_HOME "HOME"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_VOICE "VOICE"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_FAX "FAX"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_MSG "MSG"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_CELL "CELL"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_PAGER "PAGER"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_BBS "BBS"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_MODEM "MODEM"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_CAR "CAR"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_ISDN "ISDN"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_VIDEO "VIDEO"
+#define STR_CONTACT_PHONE_NUMBER_TYPE_PCS "PCS"
+
+#define STR_CONTACT_ADDRESS_TYPE_WORK "WORK"
+#define STR_CONTACT_ADDRESS_TYPE_PREF "PREF"
+#define STR_CONTACT_ADDRESS_TYPE_HOME "HOME"
+
+#define STR_WEBSITE_TYPE_HOMEPAGE "HOMEPAGE"
+#define STR_WEBSITE_TYPE_BLOG "BLOG"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+std::vector<std::string> ContactConverter::m_allowedContactInit;
+std::vector<std::string> ContactConverter::m_allowedContactNameInit;
+std::vector<std::string> ContactConverter::m_allowedContactOrganizationInit;
+std::vector<std::string> ContactConverter::m_allowedContactAddressInit;
+
+ContactConverter::ContactConverter(JSContextRef context) : Converter(context)
+{
+       static bool init = initializeAllowedProperties();
+       (void) init;
+}
+
+ContactConverter::~ContactConverter()
+{
+}
+
+JSValueRef ContactConverter::toJSValueRef(const AddressBookPtr &arg)
+{
+       // It may not used
+       AddressBookController *priv = new AddressBookController(m_context, arg);
+       return JSObjectMake(m_context, JSAddressBook::getClassRef(), priv);
+}
+
+AddressBookPtr ContactConverter::toAddressBook(const JSValueRef &jsValue)
+{
+       if(!JSAddressBook::isObjectOfClass(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+
+       return JSAddressBook::getAddressBook(m_context, jsValue);
+}
+
+JSValueRef ContactConverter::toJSValueRef(const AddressBookArrayPtr &arg)
+{
+       int size = arg->size();
+
+       JSObjectRef resultObject = JSCreateArrayObject(m_context, 0, NULL);
+       if (!resultObject)
+               ThrowMsg(ConversionException, "Can not create array object.");
+
+       for(int i = 0; i < size; i++)
+       {
+               JSValueRef jsvalue = toJSValueRef(arg->at(i));
+               if (!JSSetArrayElement(m_context, resultObject, i, jsvalue))
+                       ThrowMsg(ConversionException, "Can not fill address book array.");
+       }
+
+       return static_cast<JSValueRef>(resultObject);
+}
+
+AddressBookArrayPtr ContactConverter::toAddressBookArray(const JSValueRef &jsValue)
+{
+       if(JSAddressBookArray::isObjectOfClass(m_context, jsValue))
+               return JSAddressBookArray::getAddressBookArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "AddressBookArray is not array.");
+
+       AddressBookArrayPtr result(new AddressBookArray());
+
+       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(toAddressBook(element));
+    }
+    return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContact::getClassRef(), arg);
+}
+
+ContactPtr ContactConverter::toContact(const JSValueRef &jsValue)
+{
+       if(!JSContact::isObjectOfClass(m_context, jsValue))
+       {
+               LogError("Not a Contact object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       return JSContact::getContact(m_context, jsValue);
+}
+
+ContactPtr ContactConverter::toContactFromInit(const JSValueRef &jsValue)
+{
+       // from ContactInit to Contact
+       Validator validator(m_context);
+       if (validator.isNullOrUndefined(jsValue)) {
+               LogError("ContactInit object is null");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       if (!JSValueIsObject(m_context, jsValue) || JSIsArrayValue(m_context, jsValue)) {
+               LogError("ContactInit object is not object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+//     if (!validator.checkArrayKeys(m_allowedContactInit, jsValue)) {
+//             LogError("invalid properties in ContactInit object");
+//             ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+//     }
+
+       const ScopedJSStringRef nameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_NAME));
+       const ScopedJSStringRef addressesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ADDRESSES));
+       const ScopedJSStringRef photoURIStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_PHOTO_URI));
+       const ScopedJSStringRef phoneNumbersStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_PHONE_NUMBERS));
+       const ScopedJSStringRef emailsStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_EMAILS));
+       const ScopedJSStringRef birthdayStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_BIRTHDAY));
+       const ScopedJSStringRef anniversariesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ANNIVERSARIES));
+       const ScopedJSStringRef organizationsStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ORGANIZATIONS));
+       const ScopedJSStringRef notesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_NOTES));
+       const ScopedJSStringRef urlsStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_URLS));
+       const ScopedJSStringRef isFavoriteStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_IS_FAVORITE));
+       const ScopedJSStringRef ringtoneURIStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_RINGTONE_URI));
+       const ScopedJSStringRef groupIdsStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_GROUP_IDS));
+
+       JSObjectRef jsObject = toJSObjectRef(jsValue);
+
+       JSValueRef nameData = JSObjectGetProperty(m_context, jsObject, nameStr.get(), NULL);
+       JSValueRef addressesData = JSObjectGetProperty(m_context, jsObject, addressesStr.get(), NULL);
+       JSValueRef photoURIData = JSObjectGetProperty(m_context, jsObject, photoURIStr.get(), NULL);
+       JSValueRef phoneNumbersData = JSObjectGetProperty(m_context, jsObject, phoneNumbersStr.get(), NULL);
+       JSValueRef emailsData = JSObjectGetProperty(m_context, jsObject, emailsStr.get(), NULL);
+       JSValueRef birthdayData = JSObjectGetProperty(m_context, jsObject, birthdayStr.get(), NULL);
+       JSValueRef anniversariesData = JSObjectGetProperty(m_context, jsObject, anniversariesStr.get(), NULL);
+       JSValueRef organizationsData = JSObjectGetProperty(m_context, jsObject, organizationsStr.get(), NULL);
+       JSValueRef notesData = JSObjectGetProperty(m_context, jsObject, notesStr.get(), NULL);
+       JSValueRef urlsData = JSObjectGetProperty(m_context, jsObject, urlsStr.get(), NULL);
+       JSValueRef ringtoneURIData = JSObjectGetProperty(m_context, jsObject, ringtoneURIStr.get(), NULL);
+       JSValueRef groupIdsData = JSObjectGetProperty(m_context, jsObject, groupIdsStr.get(), NULL);
+
+       ContactNamePtr name;
+       ContactAddressArrayPtr addresses;
+       std::string photoURI;
+       ContactPhoneNumberArrayPtr phoneNumbers;
+       ContactEmailAddressArrayPtr emails;
+       tm birthday;
+       ContactAnniversaryArrayPtr anniversaries;
+       ContactOrganizationArrayPtr organizations;
+       StringArrayPtr notes;
+       ContactWebSiteArrayPtr urls;
+       std::string ringtoneURI;
+       StringArrayPtr groupIds;
+
+       ContactPtr result = ContactFactory::getInstance().createContact();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Cannot create Contact object");
+       }
+
+       if (!validator.isNullOrUndefined(nameData)) {
+               name = toContactName(nameData);
+               result->setName(name);
+       }
+
+       if (!validator.isNullOrUndefined(addressesData)) {
+               addresses = toContactAddressArray(addressesData);
+               result->setAddresses(addresses);
+       }
+
+       if (!validator.isNullOrUndefined(photoURIData)) {
+               if(!JSValueIsString(m_context, photoURIData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "photoURI is not string");
+               photoURI = toString(photoURIData);
+               result->setPhotoURI(photoURI);
+       }
+
+       if (!validator.isNullOrUndefined(phoneNumbersData)) {
+               phoneNumbers = toContactPhoneNumberArray(phoneNumbersData);
+               result->setPhoneNumbers(phoneNumbers);
+       }
+
+       if (!validator.isNullOrUndefined(emailsData)) {
+               emails = toContactEmailAddressArray(emailsData);
+               result->setEmails(emails);
+       }
+
+       if (!validator.isNullOrUndefined(birthdayData)) {
+               if(!validator.isDate(birthdayData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "birthday is not Date");
+               birthday = toDateTm(birthdayData);
+               result->setBirthday(birthday);
+       }
+
+       if (!validator.isNullOrUndefined(anniversariesData)) {
+               anniversaries = toContactAnniversaryArray(anniversariesData);
+               result->setAnniversaries(anniversaries);
+       }
+
+       if (!validator.isNullOrUndefined(organizationsData)) {
+               organizations = toContactOrganizationArray(organizationsData);
+               result->setOrganizations(organizations);
+       }
+
+       if (!validator.isNullOrUndefined(notesData)) {
+               notes = toStringArray(notesData);
+               result->setNotes(notes);
+       }
+
+       if (!validator.isNullOrUndefined(urlsData)) {
+               urls = toContactWebSiteArray(urlsData);
+               result->setUrls(urls);
+       }
+
+       if (!validator.isNullOrUndefined(ringtoneURIData)) {
+               if(!JSValueIsString(m_context, ringtoneURIData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ringtoneURI is not string");
+               ringtoneURI = toString(ringtoneURIData);
+               result->setRingtoneURI(ringtoneURI);
+       }
+
+       if (!validator.isNullOrUndefined(groupIdsData)) {
+               groupIds = toStringArray(groupIdsData);
+               result->setGroupIds(groupIds);
+       }
+
+       return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactArrayPtr &arg)
+{
+       int size = arg->size();
+
+       JSObjectRef resultObject = JSCreateArrayObject(m_context, 0, NULL);
+       if (!resultObject)
+               ThrowMsg(ConversionException, "Can not create array object.");
+
+       for(int i = 0; i < size; i++)
+       {
+               JSValueRef jsvalue = toJSValueRef(arg->at(i));
+               if (!JSSetArrayElement(m_context, resultObject, i, jsvalue))
+                       ThrowMsg(ConversionException, "Can not fill contact array.");
+       }
+
+       return static_cast<JSValueRef>(resultObject);
+}
+
+ContactArrayPtr ContactConverter::toContactArray(const JSValueRef &jsValue)
+{
+//  // toJSValueRef(ContactArrayPtr) creates user object.
+//     if(JSContactArray::isObjectOfClass(m_context, jsValue))
+//             return JSContactArray::getContactArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactArray is not array.");
+
+       ContactArrayPtr result = ContactArrayPtr(new ContactArray());
+
+       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(toContact(element));
+    }
+    return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const PersonPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSPerson::getClassRef(), arg);
+}
+
+PersonPtr ContactConverter::toPerson(const JSValueRef &jsValue)
+{
+       if(!JSPerson::isObjectOfClass(m_context, jsValue))
+       {
+               LogError("Not a Person object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       return JSPerson::getPerson(m_context, jsValue);
+}
+
+JSValueRef ContactConverter::toJSValueRef(const PersonArrayPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSPersonArray::getClassRef(), arg);
+}
+
+PersonArrayPtr ContactConverter::toPersonArray(const JSValueRef &jsValue)
+{
+       if(JSPersonArray::isObjectOfClass(m_context, jsValue))
+               return JSPersonArray::getPersonArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "PersonArray is not array.");
+
+       PersonArrayPtr result(new PersonArray());
+
+       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(toPerson(element));
+    }
+    return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactGroupPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactGroup::getClassRef(), arg);
+}
+
+ContactGroupPtr ContactConverter::toContactGroup(const JSValueRef &jsValue)
+{
+       if(!JSContactGroup::isObjectOfClass(m_context, jsValue))
+       {
+               LogError("Not a ContactGroup object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       return JSContactGroup::getContactGroup(m_context, jsValue);
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactGroupArrayPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactGroupArray::getClassRef(), arg);
+}
+
+ContactGroupArrayPtr ContactConverter::toContactGroupArray(const JSValueRef &jsValue)
+{
+       if(JSContactGroupArray::isObjectOfClass(m_context, jsValue))
+               return JSContactGroupArray::getContactGroupArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactGroupArray is not array.");
+
+       ContactGroupArrayPtr result(new ContactGroupArray());
+
+       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(toContactGroup(element));
+    }
+    return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactRefPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactRef::getClassRef(), arg);
+}
+
+ContactRefPtr ContactConverter::toContactRef(const JSValueRef &jsValue)
+{
+       if(!JSContactRef::isObjectOfClass(m_context, jsValue))
+       {
+               LogError("Not a ContactRef object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       return JSContactRef::getContactRef(m_context, jsValue);
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactNamePtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactName::getClassRef(), arg);
+}
+
+ContactNamePtr ContactConverter::toContactName(const JSValueRef &jsValue)
+{
+       if(!JSContactName::isObjectOfClass(m_context, jsValue))
+       {
+               LogError("Not a ContactName object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       return JSContactName::getContactName(m_context, jsValue);
+}
+
+ContactNamePtr ContactConverter::toContactNameFromInit(const JSValueRef &jsValue)
+{
+       // from ContactNameInit to ContactName
+       Validator validator(m_context);
+       if (validator.isNullOrUndefined(jsValue)) {
+               LogError("ContactNameInit object is null");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       if (!JSValueIsObject(m_context, jsValue) || JSIsArrayValue(m_context, jsValue)) {
+               LogError("ContactNameInit object is not object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+//     if (!validator.checkArrayKeys(m_allowedContactNameInit, jsValue)) {
+//             LogError("invalid properties in ContactNameInit object");
+//             ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+//     }
+
+       const ScopedJSStringRef prefixStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_PREFIX));
+       const ScopedJSStringRef suffixStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_SUFFIX));
+       const ScopedJSStringRef firstNameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_FIRST_NAME));
+       const ScopedJSStringRef middleNameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_MIDDLE_NAME));
+       const ScopedJSStringRef lastNameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_LAST_NAME));
+       const ScopedJSStringRef nicknamesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_NICKNAMES));
+       const ScopedJSStringRef phoneticFirstNameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_PHONETIC_FIRST_NAME));
+       const ScopedJSStringRef phoneticLastNameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_PHONETIC_LAST_NAME));
+
+       JSObjectRef jsObject = toJSObjectRef(jsValue);
+
+       JSValueRef prefixData = JSObjectGetProperty(m_context, jsObject, prefixStr.get(), NULL);
+       JSValueRef suffixData = JSObjectGetProperty(m_context, jsObject, suffixStr.get(), NULL);
+       JSValueRef firstNameData = JSObjectGetProperty(m_context, jsObject, firstNameStr.get(), NULL);
+       JSValueRef middleNameData = JSObjectGetProperty(m_context, jsObject, middleNameStr.get(), NULL);
+       JSValueRef lastNameData = JSObjectGetProperty(m_context, jsObject, lastNameStr.get(), NULL);
+       JSValueRef nicknamesData = JSObjectGetProperty(m_context, jsObject, nicknamesStr.get(), NULL);
+       JSValueRef phoneticFirstNameData = JSObjectGetProperty(m_context, jsObject, phoneticFirstNameStr.get(), NULL);
+       JSValueRef phoneticLastNameData = JSObjectGetProperty(m_context, jsObject, phoneticLastNameStr.get(), NULL);
+
+       std::string prefix;
+       std::string suffix;
+       std::string firstName;
+       std::string middleName;
+       std::string lastName;
+       StringArrayPtr nicknames;
+       std::string phoneticFirstName;
+       std::string phoneticLastName;
+
+       ContactNamePtr result = ContactNamePtr(new ContactName());
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Cannot create ContactName object");
+       }
+
+       if (!validator.isNullOrUndefined(prefixData)) {
+               if(!JSValueIsString(m_context, prefixData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "prefix is not string");
+               prefix = toString(prefixData);
+               result->setPrefix(prefix);
+       }
+
+       if (!validator.isNullOrUndefined(suffixData)) {
+               if(!JSValueIsString(m_context, suffixData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "suffix is not string");
+               suffix = toString(suffixData);
+               result->setSuffix(suffix);
+       }
+
+       if (!validator.isNullOrUndefined(firstNameData)) {
+               if(!JSValueIsString(m_context, firstNameData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "firstName is not string");
+               firstName = toString(firstNameData);
+               result->setFirstName(firstName);
+       }
+
+       if (!validator.isNullOrUndefined(middleNameData)) {
+               if(!JSValueIsString(m_context, middleNameData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "middleName is not string");
+               middleName = toString(middleNameData);
+               result->setMiddleName(middleName);
+       }
+
+       if (!validator.isNullOrUndefined(lastNameData)) {
+               if(!JSValueIsString(m_context, lastNameData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "lastName is not string");
+               lastName = toString(lastNameData);
+               result->setLastName(lastName);
+       }
+
+       if (!validator.isNullOrUndefined(nicknamesData)) {
+               nicknames = toStringArray(nicknamesData);
+               result->setNicknames(nicknames);
+       }
+
+       if (!validator.isNullOrUndefined(phoneticFirstNameData)) {
+               if(!JSValueIsString(m_context, phoneticFirstNameData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "phoneticFirstName is not string");
+               phoneticFirstName = toString(phoneticFirstNameData);
+               result->setPhoneticFirstName(phoneticFirstName);
+       }
+
+       if (!validator.isNullOrUndefined(phoneticLastNameData)) {
+               if(!JSValueIsString(m_context, phoneticLastNameData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "phoneticLastName is not string");
+               phoneticLastName = toString(phoneticLastNameData);
+               result->setPhoneticLastName(phoneticLastName);
+       }
+
+       return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactOrganizationPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactOrganization::getClassRef(), arg);
+}
+
+ContactOrganizationPtr ContactConverter::toContactOrganization(const JSValueRef &jsValue)
+{
+       if(!JSContactOrganization::isObjectOfClass(m_context, jsValue))
+       {
+               LogError("Not a ContactOrganization object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       return JSContactOrganization::getContactOrganization(m_context, jsValue);
+}
+
+ContactOrganizationPtr ContactConverter::toContactOrganizationFromInit(const JSValueRef &jsValue)
+{
+       // from ContactOrganizationInit to ContactOrganization
+       Validator validator(m_context);
+       if (validator.isNullOrUndefined(jsValue)) {
+               LogError("ContactOrganizationInit object is null");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       if (!JSValueIsObject(m_context, jsValue) || JSIsArrayValue(m_context, jsValue)) {
+               LogError("ContactOrganizationInit object is not object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+//     if (!validator.checkArrayKeys(m_allowedContactOrganizationInit, jsValue)) {
+//             LogError("invalid properties in ContactOrganizationInit object");
+//             ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+//     }
+
+       // NOTE: Currently not support office and logoURI fields
+       const ScopedJSStringRef nameStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_NAME));
+       const ScopedJSStringRef departmentStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_DEPARTMENT));
+       const ScopedJSStringRef titleStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_TITLE));
+       const ScopedJSStringRef roleStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ROLE));
+
+       JSObjectRef jsObject = toJSObjectRef(jsValue);
+
+       JSValueRef nameData = JSObjectGetProperty(m_context, jsObject, nameStr.get(), NULL);
+       JSValueRef departmentData = JSObjectGetProperty(m_context, jsObject, departmentStr.get(), NULL);
+       JSValueRef titleData = JSObjectGetProperty(m_context, jsObject, titleStr.get(), NULL);
+       JSValueRef roleData = JSObjectGetProperty(m_context, jsObject, roleStr.get(), NULL);
+
+       std::string name;
+       std::string department;
+       std::string title;
+       std::string role;
+
+       ContactOrganizationPtr result(new ContactOrganization());
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Cannot create ContactOrganization object");
+       }
+
+       if (!validator.isNullOrUndefined(nameData)) {
+               if(!JSValueIsString(m_context, nameData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "name is not string");
+               name = toString(nameData);
+               result->setName(name);
+       }
+
+       if (!validator.isNullOrUndefined(departmentData)) {
+               if(!JSValueIsString(m_context, departmentData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "department is not string");
+               department = toString(departmentData);
+               result->setDepartment(department);
+       }
+
+       if (!validator.isNullOrUndefined(titleData)) {
+               if(!JSValueIsString(m_context, titleData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "title is not string");
+               title = toString(titleData);
+               result->setTitle(title);
+       }
+
+       if (!validator.isNullOrUndefined(roleData)) {
+               if(!JSValueIsString(m_context, roleData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "role is not string");
+               role = toString(roleData);
+               result->setRole(role);
+       }
+
+       return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactOrganizationArrayPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactOrganizationArray::getClassRef(), arg);
+}
+
+ContactOrganizationArrayPtr ContactConverter::toContactOrganizationArray(const JSValueRef &jsValue)
+{
+       if(JSContactOrganizationArray::isObjectOfClass(m_context, jsValue))
+               return JSContactOrganizationArray::getContactOrganizationArray(m_context, jsValue);
+
+       ContactOrganizationArrayPtr result(new ContactOrganizationArray());
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactOrganizationArray is not array.");
+
+       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(toContactOrganization(element));
+    }
+    return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactWebSitePtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactWebSite::getClassRef(), arg);
+}
+
+ContactWebSitePtr ContactConverter::toContactWebSite(const JSValueRef &jsValue)
+{
+       if(!JSContactWebSite::isObjectOfClass(m_context, jsValue))
+       {
+               LogError("Not a ContactWebSite object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       return JSContactWebSite::getContactWebSite(m_context, jsValue);
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactWebSiteArrayPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactWebSiteArray::getClassRef(), arg);
+}
+
+ContactWebSiteArrayPtr ContactConverter::toContactWebSiteArray(const JSValueRef &jsValue)
+{
+       if(JSContactWebSiteArray::isObjectOfClass(m_context, jsValue))
+               return JSContactWebSiteArray::getContactWebSiteArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactWebSiteArray is not array.");
+
+       ContactWebSiteArrayPtr result(new ContactWebSiteArray());
+
+       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(toContactWebSite(element));
+    }
+    return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactAnniversaryPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAnniversary::getClassRef(), arg);
+}
+
+ContactAnniversaryPtr ContactConverter::toContactAnniversary(const JSValueRef &jsValue)
+{
+       if(!JSContactAnniversary::isObjectOfClass(m_context, jsValue))
+       {
+               LogError("Not a ContactAnniversary object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       return JSContactAnniversary::getContactAnniversary(m_context, jsValue);
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactAnniversaryArrayPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAnniversaryArray::getClassRef(), arg);
+}
+
+ContactAnniversaryArrayPtr ContactConverter::toContactAnniversaryArray(const JSValueRef &jsValue)
+{
+       if(JSContactAnniversaryArray::isObjectOfClass(m_context, jsValue))
+               return JSContactAnniversaryArray::getContactAnniversaryArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactAnniversaryArray is not array.");
+
+       ContactAnniversaryArrayPtr result(new ContactAnniversaryArray());
+
+       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(toContactAnniversary(element));
+    }
+    return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactAddressPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAddress::getClassRef(), arg);
+}
+
+ContactAddressPtr ContactConverter::toContactAddress(const JSValueRef &jsValue)
+{
+       if(!JSContactAddress::isObjectOfClass(m_context, jsValue))
+       {
+               LogError("Not a ContactAddress object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       return JSContactAddress::getContactAddress(m_context, jsValue);
+}
+
+ContactAddressPtr ContactConverter::toContactAddressFromInit(const JSValueRef &jsValue)
+{
+       // from ContactAddressInit to ContactAddress
+       Validator validator(m_context);
+       if (validator.isNullOrUndefined(jsValue)) {
+               LogError("ContactAddressInit object is null");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       if (!JSValueIsObject(m_context, jsValue) || JSIsArrayValue(m_context, jsValue)) {
+               LogError("ContactAddressInit object is not object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+//     if (!validator.checkArrayKeys(m_allowedContactAddressInit, jsValue)) {
+//             LogError("invalid properties in ContactAddressInit object");
+//             ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+//     }
+
+       const ScopedJSStringRef countryStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_COUNTRY));
+       const ScopedJSStringRef regionStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_REGION));
+       const ScopedJSStringRef cityStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_CITY));
+       const ScopedJSStringRef streetAddressStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_STREET_ADDRESS));
+       const ScopedJSStringRef additionalInformationStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ADDITIONAL_INFORMATION));
+       const ScopedJSStringRef postalCodeStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_POSTAL_CODE));
+       const ScopedJSStringRef isDefaultStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_IS_DEFAULT));
+       const ScopedJSStringRef typesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_TYPES));
+
+       JSObjectRef jsObject = toJSObjectRef(jsValue);
+
+       JSValueRef countryData = JSObjectGetProperty(m_context, jsObject, countryStr.get(), NULL);
+       JSValueRef regionData = JSObjectGetProperty(m_context, jsObject, regionStr.get(), NULL);
+       JSValueRef cityData = JSObjectGetProperty(m_context, jsObject, cityStr.get(), NULL);
+       JSValueRef streetAddressData = JSObjectGetProperty(m_context, jsObject, streetAddressStr.get(), NULL);
+       JSValueRef additionalInformationData = JSObjectGetProperty(m_context, jsObject, additionalInformationStr.get(), NULL);
+       JSValueRef postalCodeData = JSObjectGetProperty(m_context, jsObject, postalCodeStr.get(), NULL);
+       JSValueRef isDefaultData = JSObjectGetProperty(m_context, jsObject, isDefaultStr.get(), NULL);
+       JSValueRef typesData = JSObjectGetProperty(m_context, jsObject, typesStr.get(), NULL);
+
+       std::string country;
+       std::string region;
+       std::string city;
+       std::string streetAddress;
+       std::string additionalInformation;
+       std::string postalCode;
+       bool isDefault;
+       ContactAddressTypeArrayPtr types;
+
+       ContactAddressPtr result(new ContactAddress());
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Cannot make ContactAddress");
+       }
+
+       if (!validator.isNullOrUndefined(countryData)) {
+               if(!JSValueIsString(m_context, countryData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "country is not string");
+               country = toString(countryData);
+               result->setCountry(country);
+       }
+
+       if (!validator.isNullOrUndefined(regionData)) {
+               if(!JSValueIsString(m_context, regionData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "region is not string");
+               region = toString(regionData);
+               result->setRegion(region);
+       }
+
+       if (!validator.isNullOrUndefined(cityData)) {
+               if(!JSValueIsString(m_context, cityData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "city is not string");
+               city = toString(cityData);
+               result->setCity(city);
+       }
+
+       if (!validator.isNullOrUndefined(streetAddressData)) {
+               if(!JSValueIsString(m_context, streetAddressData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "streetAddress is not string");
+               streetAddress = toString(streetAddressData);
+               result->setStreetAddress(streetAddress);
+       }
+
+       if (!validator.isNullOrUndefined(additionalInformationData)) {
+               if(!JSValueIsString(m_context, additionalInformationData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "additionalInformation is not string");
+               additionalInformation = toString(additionalInformationData);
+               result->setAdditionalInformation(additionalInformation);
+       }
+
+       if (!validator.isNullOrUndefined(postalCodeData)) {
+               if(!JSValueIsString(m_context, postalCodeData))
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "postalCode is not string");
+               postalCode = toString(postalCodeData);
+               result->setPostalCode(postalCode);
+       }
+
+       if (!validator.isNullOrUndefined(isDefaultData)) {
+               isDefault = toBool(isDefaultData);
+               result->setIsDefault(isDefault);
+       }
+
+       if (!validator.isNullOrUndefined(typesData)) {
+               types = toContactAddressTypeArray(typesData);
+               result->setTypes(types);
+       }
+
+       return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactAddressArrayPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAddressArray::getClassRef(), arg);
+}
+
+ContactAddressArrayPtr ContactConverter::toContactAddressArray(const JSValueRef &jsValue)
+{
+       if(JSContactAddressArray::isObjectOfClass(m_context, jsValue))
+               return JSContactAddressArray::getContactAddressArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactAddressArray is not array.");
+
+       ContactAddressArrayPtr result(new ContactAddressArray());
+
+       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(toContactAddress(element));
+    }
+    return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactPhoneNumberPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactPhoneNumber::getClassRef(), arg);
+}
+
+ContactPhoneNumberPtr ContactConverter::toContactPhoneNumber(const JSValueRef &jsValue)
+{
+       if(!JSContactPhoneNumber::isObjectOfClass(m_context, jsValue))
+       {
+               LogError("Not a ContactPhoneNumber object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       return JSContactPhoneNumber::getContactPhoneNumber(m_context, jsValue);
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactPhoneNumberArrayPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactPhoneNumberArray::getClassRef(), arg);
+}
+
+ContactPhoneNumberArrayPtr ContactConverter::toContactPhoneNumberArray(const JSValueRef &jsValue)
+{
+       if(JSContactPhoneNumberArray::isObjectOfClass(m_context, jsValue))
+               return JSContactPhoneNumberArray::getContactPhoneNumberArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactPhoneNumberArray is not array.");
+
+       ContactPhoneNumberArrayPtr result(new ContactPhoneNumberArray());
+
+       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(toContactPhoneNumber(element));
+    }
+    return result;
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactEmailAddress::getClassRef(), arg);
+}
+
+ContactEmailAddressPtr ContactConverter::toContactEmailAddress(const JSValueRef &jsValue)
+{
+       if(!JSContactEmailAddress::isObjectOfClass(m_context, jsValue))
+       {
+               LogError("Not a ContactEmailAddress object");
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       }
+
+       return JSContactEmailAddress::getContactEmailAddress(m_context, jsValue);
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressArrayPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactEmailAddressArray::getClassRef(), arg);
+}
+
+ContactEmailAddressArrayPtr ContactConverter::toContactEmailAddressArray(const JSValueRef &jsValue)
+{
+       if(JSContactEmailAddressArray::isObjectOfClass(m_context, jsValue))
+               return JSContactEmailAddressArray::getContactEmailAddressArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactEmailAddressArray is not array.");
+
+       ContactEmailAddressArrayPtr result(new ContactEmailAddressArray());
+
+       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(toContactEmailAddress(element));
+    }
+    return result;
+}
+
+ContactWebSiteType ContactConverter::toContactWebSiteType(const std::string &arg)
+{
+       std::string argUpper;
+       std::transform(arg.begin(), arg.end(), std::back_inserter(argUpper), ::toupper);
+
+       if (argUpper == STR_WEBSITE_TYPE_HOMEPAGE) {
+               return WEBSITE_TYPE_HOMEPAGE;
+       } else if (argUpper == STR_WEBSITE_TYPE_BLOG) {
+               return WEBSITE_TYPE_BLOG;
+       }
+
+       //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactWebSiteType : " << arg);
+       return WEBSITE_TYPE_NULL;
+}
+
+std::string ContactConverter::toContactWebSiteTypeStr(ContactWebSiteType arg)
+{
+       if (arg == WEBSITE_TYPE_HOMEPAGE) {
+               return STR_WEBSITE_TYPE_HOMEPAGE;
+       } else if (arg == WEBSITE_TYPE_BLOG) {
+               return STR_WEBSITE_TYPE_BLOG;
+       }
+
+       //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactWebSiteType : " << arg);
+       return STR_CONTACT_EMPTY_STRING;
+}
+
+ContactWebSiteType ContactConverter::toContactWebSiteType(const JSValueRef &value)
+{
+       if(!JSValueIsString(m_context, value))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactWebSiteType is not string.");
+
+       return toContactWebSiteType(toString(value));
+}
+
+JSValueRef ContactConverter::toJSValueRef(ContactWebSiteType arg)
+{
+       return toJSValueRef(toContactWebSiteTypeStr(arg));
+}
+
+ContactAddressType ContactConverter::toContactAddressType(const std::string &arg)
+{
+       std::string argUpper;
+       std::transform(arg.begin(), arg.end(), std::back_inserter(argUpper), ::toupper);
+
+       if (argUpper == STR_CONTACT_ADDRESS_TYPE_WORK) {
+               return CONTACT_ADDRESS_TYPE_WORK;
+       } else if (argUpper == STR_CONTACT_ADDRESS_TYPE_PREF) {
+               return CONTACT_ADDRESS_TYPE_PREF;
+       } else if (argUpper == STR_CONTACT_ADDRESS_TYPE_HOME) {
+               return CONTACT_ADDRESS_TYPE_HOME;
+       }
+
+       //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactAddressType : " << arg);
+       return CONTACT_ADDRESS_TYPE_NULL;
+}
+std::string ContactConverter::toContactAddressTypeStr(ContactAddressType arg)
+{
+       if (arg == CONTACT_ADDRESS_TYPE_WORK) {
+               return STR_CONTACT_ADDRESS_TYPE_WORK;
+       } else if (arg == CONTACT_ADDRESS_TYPE_PREF) {
+               return STR_CONTACT_ADDRESS_TYPE_PREF;
+       } else if (arg == CONTACT_ADDRESS_TYPE_HOME) {
+               return STR_CONTACT_ADDRESS_TYPE_HOME;
+       }
+
+       //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactAddressType : " << arg);
+       return STR_CONTACT_EMPTY_STRING;
+}
+
+ContactAddressType ContactConverter::toContactAddressType(const JSValueRef &value)
+{
+       if(!JSValueIsString(m_context, value))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactAddressType is not string.");
+
+       return toContactAddressType(toString(value));
+}
+
+JSValueRef ContactConverter::toJSValueRef(ContactAddressType arg)
+{
+       return toJSValueRef(toContactAddressTypeStr(arg));
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactAddressTypeArrayPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAddressTypeArray::getClassRef(), arg);
+}
+
+ContactAddressTypeArrayPtr ContactConverter::toContactAddressTypeArray(const JSValueRef &jsValue)
+{
+       if(JSContactAddressTypeArray::isObjectOfClass(m_context, jsValue))
+               return JSContactAddressTypeArray::getContactAddressTypeArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactAddressTypeArray is not array.");
+
+       ContactAddressTypeArrayPtr result(new ContactAddressTypeArray());
+
+       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(toContactAddressType(element));
+    }
+    return result;
+}
+
+ContactPhoneNumberType ContactConverter::toContactPhoneNumberType(const std::string &arg)
+{
+       std::string argUpper;
+       std::transform(arg.begin(), arg.end(), std::back_inserter(argUpper), ::toupper);
+
+       if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_WORK) {
+               return CONTACT_PHONE_NUMBER_TYPE_WORK;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_PREF) {
+               return CONTACT_PHONE_NUMBER_TYPE_PREF;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_HOME) {
+               return CONTACT_PHONE_NUMBER_TYPE_HOME;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_VOICE) {
+               return CONTACT_PHONE_NUMBER_TYPE_VOICE;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_FAX) {
+               return CONTACT_PHONE_NUMBER_TYPE_FAX;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_MSG) {
+               return CONTACT_PHONE_NUMBER_TYPE_MSG;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_CELL) {
+               return CONTACT_PHONE_NUMBER_TYPE_CELL;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_PAGER) {
+               return CONTACT_PHONE_NUMBER_TYPE_PAGER;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_BBS) {
+               return CONTACT_PHONE_NUMBER_TYPE_BBS;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_MODEM) {
+               return CONTACT_PHONE_NUMBER_TYPE_MODEM;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_CAR) {
+               return CONTACT_PHONE_NUMBER_TYPE_CAR;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_ISDN) {
+               return CONTACT_PHONE_NUMBER_TYPE_ISDN;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_VIDEO) {
+               return CONTACT_PHONE_NUMBER_TYPE_VIDEO;
+       } else if (argUpper == STR_CONTACT_PHONE_NUMBER_TYPE_PCS) {
+               return CONTACT_PHONE_NUMBER_TYPE_PCS;
+       }
+
+       //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactPhoneNumverType : " << arg);
+       return CONTACT_PHONE_NUMBER_TYPE_NULL;
+}
+
+std::string ContactConverter::toContactPhoneNumberTypeStr(ContactPhoneNumberType arg)
+{
+       if (arg == CONTACT_PHONE_NUMBER_TYPE_WORK) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_WORK;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_PREF) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_PREF;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_HOME) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_HOME;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_VOICE) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_VOICE;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_FAX) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_FAX;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_MSG) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_MSG;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_CELL) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_CELL;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_PAGER) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_PAGER;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_BBS) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_BBS;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_MODEM) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_MODEM;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_CAR) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_CAR;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_ISDN) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_ISDN;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_VIDEO) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_VIDEO;
+       } else if (arg == CONTACT_PHONE_NUMBER_TYPE_PCS) {
+               return STR_CONTACT_PHONE_NUMBER_TYPE_PCS;
+       }
+
+       //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactPhoneNumberType : " << arg);
+       return STR_CONTACT_EMPTY_STRING;
+}
+
+ContactPhoneNumberType ContactConverter::toContactPhoneNumberType(const JSValueRef &value)
+{
+       if(!JSValueIsString(m_context, value))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactPhoneNumberType is not string.");
+
+       return toContactPhoneNumberType(toString(value));
+}
+
+JSValueRef ContactConverter::toJSValueRef(ContactPhoneNumberType arg)
+{
+       return toJSValueRef(toContactPhoneNumberTypeStr(arg));
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactPhoneNumberTypeArrayPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactPhoneNumberTypeArray::getClassRef(), arg);
+}
+
+ContactPhoneNumberTypeArrayPtr ContactConverter::toContactPhoneNumberTypeArray(const JSValueRef &jsValue)
+{
+       if(JSContactPhoneNumberTypeArray::isObjectOfClass(m_context, jsValue))
+               return JSContactPhoneNumberTypeArray::getContactPhoneNumberTypeArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactEmailAddressTypeArray is not array.");
+
+       ContactPhoneNumberTypeArrayPtr result(new ContactPhoneNumberTypeArray());
+
+       JSObjectRef jsObject = toJSObjectRef(jsValue);
+    for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
+        JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
+        Try {
+               result->push_back(toContactPhoneNumberType(element));
+        } Catch (Exception) {
+               // nothing
+        }
+    }
+    return result;
+}
+
+ContactEmailAddressType ContactConverter::toContactEmailAddressType(const std::string &arg)
+{
+       std::string argUpper;
+       std::transform(arg.begin(), arg.end(), std::back_inserter(argUpper), ::toupper);
+
+       if (argUpper == STR_CONTACT_EMAIL_TYPE_WORK) {
+               return CONTACT_EMAIL_TYPE_WORK;
+       } else if (argUpper == STR_CONTACT_EMAIL_TYPE_PREF) {
+               return CONTACT_EMAIL_TYPE_PREF;
+       } else if (argUpper == STR_CONTACT_EMAIL_TYPE_HOME) {
+               return CONTACT_EMAIL_TYPE_HOME;
+       }
+
+       //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactEmailAddressType : " << arg);
+       return CONTACT_EMAIL_TYPE_NULL;
+}
+
+std::string ContactConverter::toContactEmailAddressTypeStr(ContactEmailAddressType arg)
+{
+       if (arg == CONTACT_EMAIL_TYPE_WORK) {
+               return STR_CONTACT_EMAIL_TYPE_WORK;
+       } else if (arg == CONTACT_EMAIL_TYPE_PREF) {
+               return STR_CONTACT_EMAIL_TYPE_PREF;
+       } else if (arg == CONTACT_EMAIL_TYPE_HOME) {
+               return STR_CONTACT_EMAIL_TYPE_HOME;
+       }
+
+       //ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactEmailAddressType : " << arg);
+       return STR_CONTACT_EMPTY_STRING;
+}
+
+ContactEmailAddressType ContactConverter::toContactEmailAddressType(const JSValueRef &value)
+{
+       if(!JSValueIsString(m_context, value))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactEmailAddressType is not string.");
+
+       return toContactEmailAddressType(toString(value));
+}
+
+JSValueRef ContactConverter::toJSValueRef(ContactEmailAddressType arg)
+{
+       return toJSValueRef(toContactEmailAddressTypeStr(arg));
+}
+
+JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressTypeArrayPtr &arg)
+{
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactEmailAddressTypeArray::getClassRef(), arg);
+}
+
+ContactEmailAddressTypeArrayPtr ContactConverter::toContactEmailAddressTypeArray(const JSValueRef &jsValue)
+{
+       if(JSContactEmailAddressTypeArray::isObjectOfClass(m_context, jsValue))
+               return JSContactEmailAddressTypeArray::getContactEmailAddressTypeArray(m_context, jsValue);
+
+       if(!JSIsArrayValue(m_context, jsValue))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactEmailAddressTypeArray is not array.");
+
+       ContactEmailAddressTypeArrayPtr result(new ContactEmailAddressTypeArray());
+
+       JSObjectRef jsObject = toJSObjectRef(jsValue);
+    for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i) {
+        JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
+        Try {
+               result->push_back(toContactEmailAddressType(element));
+        } Catch (Exception) {
+               // nothing
+        }
+    }
+    return result;
+}
+
+StringArrayPtr ContactConverter::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 ContactConverter::toJSValueRef(const StringArrayPtr &arg)
+{
+       return JSStringArray::createArray(m_context, arg);
+}
+
+//std::string ContactConverter::toAttributesOfInterest(const JSValueRef &value)
+//{
+//     // need validator
+//     return toString(value);
+//}
+
+//JSValueRef ContactConverter::toJSValueRefAttributesOfInterestArray(const AttributesOfInterestArrayPtr &arg)
+//{
+//     return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSAttributesOfInterestArray::getClassRef(), arg);
+//}
+
+//AttributesOfInterestArrayPtr ContactConverter::toAttributesOfInterestArray(const JSValueRef &jsValue)
+//{
+//     if(JSAttributesOfInterestArray::isObjectOfClass(m_context, jsValue))
+//             return JSAttributesOfInterestArray::getAttributesOfInterestArray(m_context, jsValue);
+//
+//     if(!JSIsArrayValue(m_context, jsValue))
+//             ThrowMsg(WrtDeviceApis::Commons::ConversionException, "AttributesOfInterestArray is not array.");
+//
+//     AttributesOfInterestArrayPtr result(new AttributesOfInterestArray());
+//
+//     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(toAttributesOfInterest(element));
+//    }
+//    return result;
+//}
+
+bool ContactConverter::initializeAllowedProperties()
+{
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_NAME);
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_ACCOUNT_ID);
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_ADDRESSES);
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_PHOTO_URI );
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_PHONE_NUMBERS);
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_EMAILS);
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_BIRTHDAY);
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_ANNIVERSARIES);
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_ORGANIZATIONS);
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_NOTES);
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_URLS);
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_RINGTONE_URI);
+       m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_GROUP_IDS);
+
+       m_allowedContactNameInit.push_back(CONTACT_ATTRIBUTE_PREFIX);
+       m_allowedContactNameInit.push_back(CONTACT_ATTRIBUTE_FIRST_NAME);
+       m_allowedContactNameInit.push_back(CONTACT_ATTRIBUTE_MIDDLE_NAME);
+       m_allowedContactNameInit.push_back(CONTACT_ATTRIBUTE_LAST_NAME);
+       m_allowedContactNameInit.push_back(CONTACT_ATTRIBUTE_NICKNAMES);
+       m_allowedContactNameInit.push_back(CONTACT_ATTRIBUTE_PHONETIC_FIRST_NAME);
+       m_allowedContactNameInit.push_back(CONTACT_ATTRIBUTE_PHONETIC_LAST_NAME);
+       m_allowedContactNameInit.push_back(CONTACT_ATTRIBUTE_DISPLAY_NAME);
+
+       m_allowedContactOrganizationInit.push_back(CONTACT_ATTRIBUTE_NAME);
+       m_allowedContactOrganizationInit.push_back(CONTACT_ATTRIBUTE_DEPARTMENT);
+       m_allowedContactOrganizationInit.push_back(CONTACT_ATTRIBUTE_OFFICE);
+       m_allowedContactOrganizationInit.push_back(CONTACT_ATTRIBUTE_TITLE);
+       m_allowedContactOrganizationInit.push_back(CONTACT_ATTRIBUTE_ROLE);
+       m_allowedContactOrganizationInit.push_back(CONTACT_ATTRIBUTE_LOGO_URI);
+
+       m_allowedContactAddressInit.push_back(CONTACT_ATTRIBUTE_COUNTRY);
+       m_allowedContactAddressInit.push_back(CONTACT_ATTRIBUTE_REGION);
+       m_allowedContactAddressInit.push_back(CONTACT_ATTRIBUTE_CITY);
+       m_allowedContactAddressInit.push_back(CONTACT_ATTRIBUTE_STREET_ADDRESS);
+       m_allowedContactAddressInit.push_back(CONTACT_ATTRIBUTE_ADDITIONAL_INFORMATION);
+       m_allowedContactAddressInit.push_back(CONTACT_ATTRIBUTE_POSTAL_CODE);
+       m_allowedContactAddressInit.push_back(CONTACT_ATTRIBUTE_TYPES);
+
+       return true;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/ContactConverter.h b/src/standards/Tizen/Contact/ContactConverter.h
new file mode 100755 (executable)
index 0000000..90f18c5
--- /dev/null
@@ -0,0 +1,187 @@
+//
+// 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        ContactConverter.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_JS_CONTACT_CONVERTER_H_
+#define _TIZEN_JS_CONTACT_CONVERTER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/Converter.h>
+#include <API/Contact/ContactTypes.h>
+#include <API/Contact/IAddressBook.h>
+#include <API/Contact/IContact.h>
+#include <API/Contact/IPerson.h>
+#include <API/Contact/ContactGroup.h>
+#include <API/Contact/ContactRef.h>
+#include <API/Contact/ContactName.h>
+#include <API/Contact/ContactOrganization.h>
+#include <API/Contact/ContactWebSite.h>
+#include <API/Contact/ContactAnniversary.h>
+#include <API/Contact/ContactAddress.h>
+#include <API/Contact/ContactPhoneNumber.h>
+#include <API/Contact/ContactEmailAddress.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+class ContactConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+public:
+       using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
+
+       explicit ContactConverter(JSContextRef context);
+       virtual ~ContactConverter();
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::AddressBookPtr &arg);
+       TizenApis::Api::Contact::AddressBookPtr toAddressBook(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::AddressBookArrayPtr &arg);
+       TizenApis::Api::Contact::AddressBookArrayPtr toAddressBookArray(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactPtr &arg);
+       TizenApis::Api::Contact::ContactPtr toContact(const JSValueRef &jsValue);
+       TizenApis::Api::Contact::ContactPtr toContactFromInit(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactArrayPtr &arg);
+       TizenApis::Api::Contact::ContactArrayPtr toContactArray(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactGroupPtr &arg);
+       TizenApis::Api::Contact::ContactGroupPtr toContactGroup(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactGroupArrayPtr &arg);
+       TizenApis::Api::Contact::ContactGroupArrayPtr toContactGroupArray(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::PersonPtr &arg);
+       TizenApis::Api::Contact::PersonPtr toPerson(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::PersonArrayPtr &arg);
+       TizenApis::Api::Contact::PersonArrayPtr toPersonArray(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactRefPtr &arg);
+       TizenApis::Api::Contact::ContactRefPtr toContactRef(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactNamePtr &arg);
+       TizenApis::Api::Contact::ContactNamePtr toContactName(const JSValueRef &jsValue);
+       TizenApis::Api::Contact::ContactNamePtr toContactNameFromInit(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactOrganizationPtr &arg);
+       TizenApis::Api::Contact::ContactOrganizationPtr toContactOrganization(const JSValueRef &jsValue);
+       TizenApis::Api::Contact::ContactOrganizationPtr toContactOrganizationFromInit(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactOrganizationArrayPtr &arg);
+       TizenApis::Api::Contact::ContactOrganizationArrayPtr toContactOrganizationArray(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactWebSitePtr &arg);
+       TizenApis::Api::Contact::ContactWebSitePtr toContactWebSite(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactWebSiteArrayPtr &arg);
+       TizenApis::Api::Contact::ContactWebSiteArrayPtr toContactWebSiteArray(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactAnniversaryPtr &arg);
+       TizenApis::Api::Contact::ContactAnniversaryPtr toContactAnniversary(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactAnniversaryArrayPtr &arg);
+       TizenApis::Api::Contact::ContactAnniversaryArrayPtr toContactAnniversaryArray(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactAddressPtr &arg);
+       TizenApis::Api::Contact::ContactAddressPtr toContactAddress(const JSValueRef &jsValue);
+       TizenApis::Api::Contact::ContactAddressPtr toContactAddressFromInit(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactAddressArrayPtr &arg);
+       TizenApis::Api::Contact::ContactAddressArrayPtr toContactAddressArray(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactPhoneNumberPtr &arg);
+       TizenApis::Api::Contact::ContactPhoneNumberPtr toContactPhoneNumber(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactPhoneNumberArrayPtr &arg);
+       TizenApis::Api::Contact::ContactPhoneNumberArrayPtr toContactPhoneNumberArray(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactEmailAddressPtr &arg);
+       TizenApis::Api::Contact::ContactEmailAddressPtr toContactEmailAddress(const JSValueRef &jsValue);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactEmailAddressArrayPtr &arg);
+       TizenApis::Api::Contact::ContactEmailAddressArrayPtr toContactEmailAddressArray(const JSValueRef &jsValue);
+
+       // ContactWebSiteType
+       TizenApis::Api::Contact::ContactWebSiteType toContactWebSiteType(const std::string &arg);
+       std::string toContactWebSiteTypeStr(TizenApis::Api::Contact::ContactWebSiteType arg);
+       TizenApis::Api::Contact::ContactWebSiteType toContactWebSiteType(const JSValueRef &value);
+       JSValueRef toJSValueRef(TizenApis::Api::Contact::ContactWebSiteType arg);
+
+       // ContactAddressType
+       TizenApis::Api::Contact::ContactAddressType toContactAddressType(const std::string &arg);
+       std::string toContactAddressTypeStr(TizenApis::Api::Contact::ContactAddressType arg);
+       TizenApis::Api::Contact::ContactAddressType toContactAddressType(const JSValueRef &value);
+       JSValueRef toJSValueRef(TizenApis::Api::Contact::ContactAddressType arg);
+
+       // ContactAddressType Array
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactAddressTypeArrayPtr &arg);
+       TizenApis::Api::Contact::ContactAddressTypeArrayPtr toContactAddressTypeArray(const JSValueRef &jsValue);
+
+       // ContactPhoneNumberType
+       TizenApis::Api::Contact::ContactPhoneNumberType toContactPhoneNumberType(const std::string &arg);
+       std::string toContactPhoneNumberTypeStr(TizenApis::Api::Contact::ContactPhoneNumberType arg);
+       TizenApis::Api::Contact::ContactPhoneNumberType toContactPhoneNumberType(const JSValueRef &value);
+       JSValueRef toJSValueRef(TizenApis::Api::Contact::ContactPhoneNumberType arg);
+
+       // ContactPhoneNumberType Array
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactPhoneNumberTypeArrayPtr &arg);
+       TizenApis::Api::Contact::ContactPhoneNumberTypeArrayPtr toContactPhoneNumberTypeArray(const JSValueRef &jsValue);
+
+       // ContactEmailAddressType
+       TizenApis::Api::Contact::ContactEmailAddressType toContactEmailAddressType(const std::string &arg);
+       std::string toContactEmailAddressTypeStr(TizenApis::Api::Contact::ContactEmailAddressType arg);
+       TizenApis::Api::Contact::ContactEmailAddressType toContactEmailAddressType(const JSValueRef &value);
+       JSValueRef toJSValueRef(TizenApis::Api::Contact::ContactEmailAddressType arg);
+
+       // ContactEmailAddressType Array
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactEmailAddressTypeArrayPtr &arg);
+       TizenApis::Api::Contact::ContactEmailAddressTypeArrayPtr toContactEmailAddressTypeArray(const JSValueRef &jsValue);
+
+       // String Array
+       TizenApis::Api::Contact::StringArrayPtr toStringArray(const JSValueRef &value);
+       JSValueRef toJSValueRef(const TizenApis::Api::Contact::StringArrayPtr &arg);
+
+       // AttributesOfInterest Array - No more used
+//     JSValueRef toJSValueRefAttributesOfInterestArray(const TizenApis::Api::Contact::AttributesOfInterestArrayPtr &arg);
+//     TizenApis::Api::Contact::AttributesOfInterestArrayPtr toAttributesOfInterestArray(const JSValueRef &jsValue);
+
+//     JSValueRef toJSValueRef(const std::string &arg);
+//     std::string toAttributesOfInterest(const JSValueRef &value);
+
+private:
+       bool initializeAllowedProperties();
+       static std::vector<std::string> m_allowedContactInit;
+       static std::vector<std::string> m_allowedContactNameInit;
+       static std::vector<std::string> m_allowedContactOrganizationInit;
+       static std::vector<std::string> m_allowedContactAddressInit;
+};
+
+typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<ContactConverter> ContactConverterFactory;
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_JS_CONTACT_CONVERTER_H_
diff --git a/src/standards/Tizen/Contact/ContactListenerManager.cpp b/src/standards/Tizen/Contact/ContactListenerManager.cpp
new file mode 100755 (executable)
index 0000000..5ae037a
--- /dev/null
@@ -0,0 +1,38 @@
+//
+// 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        ContactListnerManager.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "ContactListenerManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::Contact::ContactListenerManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/ContactListenerManager.h b/src/standards/Tizen/Contact/ContactListenerManager.h
new file mode 100755 (executable)
index 0000000..cb4deb7
--- /dev/null
@@ -0,0 +1,138 @@
+//
+// 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        ContactListenerManager.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_LISTENER_MANAGER_H_
+#define _TIZEN_CONTACT_LISTENER_MANAGER_H_
+
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Tizen/Common/IListenerManager.h>
+#include "AddressBookController.h"
+#include "ContactManagerController.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Api::Contact;
+
+class ContactListenerManager : public TizenApis::Commons::IListenerController
+{
+public:
+       ContactListenerManager()
+       {
+       }
+
+       virtual ~ContactListenerManager()
+       {
+       }
+};
+typedef DPL::Singleton<ContactListenerManager> ContactListenerManagerSingleton;
+
+class ContactsChangeListenerCanceller : public TizenApis::Commons::IListenerItem
+{
+public:
+       ContactsChangeListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
+               TizenApis::Commons::IListenerItem(context, object, watchId)
+       {
+       }
+
+       virtual ~ContactsChangeListenerCanceller()
+       {
+       }
+
+       virtual void cancelListener()
+       {
+               AddressBookPtr addressBook;
+               AddressBookController *controller;
+
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(m_object));
+               if (!controller) {
+                       LogWarning("Object has no controller");
+                       return;
+               }
+               addressBook = controller->getObject();
+
+               EventAddressBookRemoveChangeListenerPtr dplEvent(new EventAddressBookRemoveChangeListener());
+
+               dplEvent->setId(m_watchId);
+           dplEvent->setForSynchronousCall();
+
+               Try {
+                       LogDebug("Remove change listener");
+                       addressBook->removeChangeListener(dplEvent);
+               } Catch(WrtDeviceApis::Commons::Exception) {
+                       LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               }
+       }
+};
+typedef DPL::SharedPtr<ContactsChangeListenerCanceller> ContactsChangeListenerCancellerPtr;
+
+class PersonsChangeListenerCanceller : public TizenApis::Commons::IListenerItem
+{
+public:
+       PersonsChangeListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
+               TizenApis::Commons::IListenerItem(context, object, watchId)
+       {
+       }
+
+       virtual ~PersonsChangeListenerCanceller()
+       {
+       }
+
+       virtual void cancelListener()
+       {
+               ContactManagerPtr addressBook;
+               ContactManagerController *controller;
+
+               controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(m_object));
+               if (!controller) {
+                       LogWarning("Object has no controller");
+                       return;
+               }
+               addressBook = controller->getObject();
+
+               EventContactManagerRemoveChangeListenerPtr dplEvent(new EventContactManagerRemoveChangeListener());
+
+               dplEvent->setId(m_watchId);
+           dplEvent->setForSynchronousCall();
+
+               Try {
+                       LogDebug("Remove change listener");
+                       addressBook->removeChangeListener(dplEvent);
+               } Catch(WrtDeviceApis::Commons::Exception) {
+                       LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               }
+       }
+};
+typedef DPL::SharedPtr<PersonsChangeListenerCanceller> PersonsChangeListenerCancellerPtr;
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_LISTENER_MANAGER_H_
diff --git a/src/standards/Tizen/Contact/ContactManagerController.cpp b/src/standards/Tizen/Contact/ContactManagerController.cpp
new file mode 100755 (executable)
index 0000000..065f81e
--- /dev/null
@@ -0,0 +1,462 @@
+//
+// 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        ContactManagerController.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "ContactManagerController.h"
+#include "ContactAsyncCallbackManager.h"
+#include "JSContactManagerChangeCallbackManager.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+ContactManagerController::ContactManagerController(JSContextRef context, ContactManagerPtr contactManager) :
+               EventContactManagerGetAddressBooksAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventContactManagerUpdateBatchAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventContactManagerRemoveBatchAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventContactManagerFindAnswerReceiver(ThreadEnum::NULL_THREAD),
+               EventContactManagerChangeListenerListener(ThreadEnum::NULL_THREAD),
+               ContactManagerPrivObject(context, contactManager)
+{
+       LogDebug("ContactManagerController constructed : " << this);
+}
+
+ContactManagerController::~ContactManagerController()
+{
+       LogDebug("ContactManagerController destructed : " << this);
+}
+
+void ContactManagerAsyncAnswerHandler::getAddressBooks(const EventContactManagerGetAddressBooksPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ContactAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Invalid value error");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       Try {
+               if (!event->getResult())
+                       ThrowMsg(PlatformException, "No result.");
+
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
+               AddressBookArrayPtr addressBooks = event->getAddressBooks();
+
+               JSValueRef result = converter->toJSValueRef(addressBooks);
+
+               callbackManager->callOnSuccess(result);
+               return;
+       } Catch(Exception) {
+               LogError("error during processing answer" << _rethrown_exception.GetMessage());
+               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+
+               callbackManager->callOnError(error);
+               return;
+       }
+}
+
+void ContactManagerAsyncAnswerHandler::updateBatch(const EventContactManagerUpdateBatchPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ContactAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid value error");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       callbackManager->callOnSuccess();
+}
+
+void ContactManagerAsyncAnswerHandler::removeBatch(const EventContactManagerRemoveBatchPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager) {
+               LogError("no callback manager");
+               return;
+       }
+
+       ContactAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid value error");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       callbackManager->callOnSuccess();
+}
+
+void ContactManagerAsyncAnswerHandler::find(const EventContactManagerFindPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager =
+                       DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!callbackManager)
+       {
+               LogError("no callback manager");
+               return;
+       }
+
+       ContactAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if(event->checkCancelled()) {
+               LogDebug("Operation cancelled");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+
+       JSValueRef error = NULL;
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_SUPPORTED_ERROR, "Not support such a filter");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid value error");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+
+       Try {
+               if (!event->getResult())
+                       ThrowMsg(PlatformException, "No result.");
+
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
+               PersonArrayPtr contacts = event->getPersons();
+
+               JSValueRef result = converter->toJSValueRef(contacts);
+
+               callbackManager->callOnSuccess(result);
+               return;
+       } Catch(Exception) {
+               LogError("error during processing answer" << _rethrown_exception.GetMessage());
+               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+
+               callbackManager->callOnError(error);
+               return;
+       }
+}
+
+void ContactManagerAsyncAnswerHandler::changeListenerError(const EventContactManagerChangeListenerPtr &event)
+{
+       LogDebug("entered");
+       JSValueRef errorObject;
+
+       JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+       if (!cbm)
+       {
+               LogError("no callback manager");
+               return;
+       }
+
+       JSContextRef gContext = cbm->getContext();
+
+       if (event->getExceptionCode() == ExceptionCodes::NotFoundException)
+               errorObject = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "Not found error");
+       else
+               errorObject = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+
+       cbm->callOnError(errorObject);
+}
+
+void ContactManagerAsyncAnswerHandler::changeListenerPersonAdded(const EventContactManagerChangeListenerPtr &event)
+{
+       LogDebug("entered");
+       JSContactManagerChangeCallbackManagerPtr cbm =
+               DPL::StaticPointerCast<JSContactManagerChangeCallbackManager>(event->getPrivateData());
+       if (!cbm)
+       {
+               LogError("no callback manager");
+               return;
+       }
+
+       EventInfoContactManagerChangePtr _eventInfo = event->getEventInfo();
+       if(_eventInfo->getCallbackType() != EventInfoContactManagerChange::OnPersonsAdded)
+       {
+               LogError("wrong type");
+               return;
+       }
+
+       EventInfoContactManagerChangeAddedPtr eventInfo = DPL::DynamicPointerCast<EventInfoContactManagerChangeAdded>(_eventInfo);
+
+       if (!eventInfo->getPersonsIsSet())
+       {
+               LogError("no data set");
+               return;
+       }
+
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(cbm->getContext());
+
+       JSValueRef contacts;
+       Try {
+               contacts = converter->toJSValueRef(eventInfo->getPersons());
+       } Catch (Exception) {
+               LogError("Conversion error");
+               return;
+       }
+
+       cbm->callOnPersonsAdded(contacts);
+}
+
+void ContactManagerAsyncAnswerHandler::changeListenerPersonUpdated(const EventContactManagerChangeListenerPtr &event)
+{
+       LogDebug("entered");
+       JSContactManagerChangeCallbackManagerPtr cbm =
+               DPL::StaticPointerCast<JSContactManagerChangeCallbackManager>(event->getPrivateData());
+       if (!cbm)
+       {
+               LogError("no callback manager");
+               return;
+       }
+
+       EventInfoContactManagerChangePtr _eventInfo = event->getEventInfo();
+       if(_eventInfo->getCallbackType() != EventInfoContactManagerChange::OnPersonsUpdated)
+       {
+               LogError("wrong type");
+               return;
+       }
+
+       EventInfoContactManagerChangeUpdatedPtr eventInfo = DPL::DynamicPointerCast<EventInfoContactManagerChangeUpdated>(_eventInfo);
+
+       if (!eventInfo->getPersonsIsSet())
+       {
+               LogError("no data set");
+               return;
+       }
+
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(cbm->getContext());
+
+       JSValueRef contacts;
+       Try {
+               contacts = converter->toJSValueRef(eventInfo->getPersons());
+       } Catch (Exception) {
+               LogError("Conversion error");
+               return;
+       }
+
+       cbm->callOnPersonsUpdated(contacts);
+}
+
+void ContactManagerAsyncAnswerHandler::changeListenerPersonRemoved(const EventContactManagerChangeListenerPtr &event)
+{
+       LogDebug("entered");
+       JSContactManagerChangeCallbackManagerPtr cbm =
+               DPL::StaticPointerCast<JSContactManagerChangeCallbackManager>(event->getPrivateData());
+       if (!cbm)
+       {
+               LogError("no callback manager");
+               return;
+       }
+
+       EventInfoContactManagerChangePtr _eventInfo = event->getEventInfo();
+       if(_eventInfo->getCallbackType() != EventInfoContactManagerChange::OnPersonsRemoved)
+       {
+               LogError("wrong type");
+               return;
+       }
+
+       EventInfoContactManagerChangeRemovedPtr eventInfo = DPL::DynamicPointerCast<EventInfoContactManagerChangeRemoved>(_eventInfo);
+       if (!eventInfo->getPersonIdsIsSet())
+       {
+               LogError("no data set");
+               return;
+       }
+
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(cbm->getContext());
+
+       JSValueRef contactIds;
+       Try {
+               contactIds = converter->toJSValueRef(eventInfo->getPersonIds());
+       } Catch (Exception) {
+               LogError("Conversion error");
+               return;
+       }
+
+       cbm->callOnPersonsDeleted(contactIds);
+}
+
+void ContactManagerController::OnAnswerReceived(const EventContactManagerGetAddressBooksPtr &event)
+{
+       ContactManagerAsyncAnswerHandler::getAddressBooks(event);
+}
+
+void ContactManagerController::OnAnswerReceived(const EventContactManagerUpdateBatchPtr &event)
+{
+       ContactManagerAsyncAnswerHandler::updateBatch(event);
+}
+
+void ContactManagerController::OnAnswerReceived(const EventContactManagerRemoveBatchPtr &event)
+{
+       ContactManagerAsyncAnswerHandler::removeBatch(event);
+}
+
+void ContactManagerController::OnAnswerReceived(const EventContactManagerFindPtr &event)
+{
+       ContactManagerAsyncAnswerHandler::find(event);
+}
+
+void ContactManagerController::onAnswerReceived(const TizenApis::Api::Contact::EventContactManagerChangeListenerPtr &event)
+{
+       EventInfoContactManagerChangePtr eventInfo = event->getEventInfo();
+       if(eventInfo == NULL)
+       {
+               LogError("wrong type");
+               return;
+       }
+
+       EventInfoContactManagerChange::CallbackType type = eventInfo->getCallbackType();
+       if(type == EventInfoContactManagerChange::OnPersonsAdded)
+               ContactManagerAsyncAnswerHandler::changeListenerPersonAdded(event);
+       else if(type == EventInfoContactManagerChange::OnPersonsUpdated)
+               ContactManagerAsyncAnswerHandler::changeListenerPersonUpdated(event);
+       else if(type == EventInfoContactManagerChange::OnPersonsRemoved)
+               ContactManagerAsyncAnswerHandler::changeListenerPersonRemoved(event);
+       else if(type == EventInfoContactManagerChange::OnError)
+               ContactManagerAsyncAnswerHandler::changeListenerError(event);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/ContactManagerController.h b/src/standards/Tizen/Contact/ContactManagerController.h
new file mode 100755 (executable)
index 0000000..6fa48db
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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        ContactManagerController.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_MANAGER_CONTROLLER_H_
+#define _TIZEN_CONTACT_MANAGER_CONTROLLER_H_
+
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSPendingOperationPrivateObject.h>
+#include <API/Contact/IContactManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::ContactManagerPtr,
+                               WrtDeviceApis::CommonsJavaScript::NoOwnership> ContactManagerPrivObject;
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventContactManagerGetAddressBooks> EventContactManagerGetAddressBooksAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventContactManagerUpdateBatch> EventContactManagerUpdateBatchAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventContactManagerRemoveBatch> EventContactManagerRemoveBatchAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Contact::EventContactManagerFind> EventContactManagerFindAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventListener<TizenApis::Api::Contact::EventContactManagerChangeListener> EventContactManagerChangeListenerListener;
+
+class ContactManagerController :
+       public EventContactManagerGetAddressBooksAnswerReceiver,
+       public EventContactManagerUpdateBatchAnswerReceiver,
+       public EventContactManagerRemoveBatchAnswerReceiver,
+       public EventContactManagerFindAnswerReceiver,
+       public EventContactManagerChangeListenerListener,
+    public ContactManagerPrivObject
+{
+private:
+       ContactManagerController();
+
+protected:
+       void    OnAnswerReceived(const TizenApis::Api::Contact::EventContactManagerGetAddressBooksPtr &event);
+       void    OnAnswerReceived(const TizenApis::Api::Contact::EventContactManagerUpdateBatchPtr &event);
+       void    OnAnswerReceived(const TizenApis::Api::Contact::EventContactManagerRemoveBatchPtr &event);
+       void    OnAnswerReceived(const TizenApis::Api::Contact::EventContactManagerFindPtr &event);
+       void    onAnswerReceived(const TizenApis::Api::Contact::EventContactManagerChangeListenerPtr &event);
+
+public:
+       ContactManagerController(JSContextRef context,
+                       TizenApis::Api::Contact::ContactManagerPtr contactManager);
+       virtual ~ContactManagerController();
+};
+
+typedef DPL::SharedPtr<ContactManagerController> ContactManagerControllerPtr;
+
+//common part
+class ContactManagerAsyncAnswerHandler
+{
+public:
+       static void getAddressBooks(const TizenApis::Api::Contact::EventContactManagerGetAddressBooksPtr &event);
+       static void updateBatch(const TizenApis::Api::Contact::EventContactManagerUpdateBatchPtr &event);
+       static void removeBatch(const TizenApis::Api::Contact::EventContactManagerRemoveBatchPtr &event);
+       static void find(const TizenApis::Api::Contact::EventContactManagerFindPtr &event);
+       static void changeListenerError(const TizenApis::Api::Contact::EventContactManagerChangeListenerPtr &event);
+       static void changeListenerPersonAdded(const TizenApis::Api::Contact::EventContactManagerChangeListenerPtr &event);
+       static void changeListenerPersonUpdated(const TizenApis::Api::Contact::EventContactManagerChangeListenerPtr &event);
+       static void changeListenerPersonRemoved(const TizenApis::Api::Contact::EventContactManagerChangeListenerPtr &event);
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_MANAGER_CONTROLLER_H_
diff --git a/src/standards/Tizen/Contact/JSAddressBook.cpp b/src/standards/Tizen/Contact/JSAddressBook.cpp
new file mode 100755 (executable)
index 0000000..a5b5cc0
--- /dev/null
@@ -0,0 +1,1689 @@
+//
+// 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        JSAddressBook.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSAddressBook class
+ */
+
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSPendingOperation.h>
+#include <API/Contact/ContactFactory.h>
+#include <API/Contact/EventAddressBookAddBatch.h>
+#include <API/Contact/EventAddressBookUpdateBatch.h>
+#include <API/Contact/EventAddressBookRemoveBatch.h>
+#include <API/Contact/EventAddressBookFind.h>
+#include <API/Contact/EventAddressBookChangeListener.h>
+#include <API/Contact/EventAddressBookRemoveBatch.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Tizen/Tizen/FilterConverter.h>
+#include "plugin_config.h"
+#include "JSAddressBook.h"
+#include "JSContact.h"
+#include "JSContactGroup.h"
+#include "ContactConverter.h"
+#include "AddressBookController.h"
+#include "JSAddressBookChangeCallbackManager.h"
+#include "ContactAsyncCallbackManager.h"
+#include "ContactListenerManager.h"
+
+using namespace std;
+
+#define TIZEN_ADDRESS_BOOK_ID           "id"
+#define TIZEN_ADDRESS_BOOK_NAME         "name"
+#define TIZEN_ADDRESS_BOOK_READ_ONLY    "readOnly"
+#define TIZEN_ADDRESS_BOOK_ACCOUNT_ID   "accountId"
+
+#define TIZEN_ADDRESS_BOOK              "AddressBook"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace TizenApis::Api::Tizen;
+using namespace TizenApis::Tizen1_0::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassRef JSAddressBook::m_jsClassRef = NULL;
+
+JSClassDefinition JSAddressBook::m_classInfo = {
+       0,
+       kJSClassAttributeNone,
+       TIZEN_ADDRESS_BOOK,
+       0,
+       m_property,
+       m_function,
+       Initialize,
+       Finalize,
+       NULL, //HasProperty,
+       NULL, //GetProperty,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //GetPropertyNames,
+       NULL, //CallAsFunction,
+       NULL, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL, //ConvertToType,
+};
+
+JSStaticValue JSAddressBook::m_property[] = {
+       { TIZEN_ADDRESS_BOOK_ID, getId, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_ADDRESS_BOOK_NAME, getName, NULL, kJSPropertyAttributeReadOnly },
+       { TIZEN_ADDRESS_BOOK_READ_ONLY, getReadOnly, NULL, kJSPropertyAttributeReadOnly },
+//     { TIZEN_ADDRESS_BOOK_ACCOUNT_ID, getAccountId, NULL, kJSPropertyAttributeReadOnly },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSAddressBook::m_function[] = {
+       { "get", get, kJSPropertyAttributeNone },
+       { "add", add, kJSPropertyAttributeNone },
+       { "addBatch", addBatch, kJSPropertyAttributeNone },
+       { "update", update, kJSPropertyAttributeNone },
+       { "updateBatch", updateBatch, kJSPropertyAttributeNone },
+       { "remove", remove, kJSPropertyAttributeNone },
+       { "removeBatch", removeBatch, kJSPropertyAttributeNone },
+       { "find", find, kJSPropertyAttributeNone },
+       { "addChangeListener", addChangeListener, kJSPropertyAttributeNone },
+       { "removeChangeListener", removeChangeListener, kJSPropertyAttributeNone },
+       { "getGroup", getGroup, kJSPropertyAttributeNone },
+       { "addGroup", addGroup, kJSPropertyAttributeNone },
+       { "updateGroup", updateGroup, kJSPropertyAttributeNone },
+       { "removeGroup", removeGroup, kJSPropertyAttributeNone },
+       { "getGroups", getGroups, kJSPropertyAttributeNone },
+       { 0, 0, 0 }
+};
+
+const JSClassDefinition* JSAddressBook::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+const JSClassRef JSAddressBook::getClassRef()
+{
+       LogInfo("entered");
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+void JSAddressBook::Initialize(JSContextRef context,
+               JSObjectRef object)
+{
+//     AddressBookController *priv =
+//             static_cast<AddressBookController*>(JSObjectGetPrivate(object));
+}
+
+void JSAddressBook::Finalize(JSObjectRef object)
+{
+       AddressBookController *priv =
+               static_cast<AddressBookController*>(JSObjectGetPrivate(object));
+
+       delete priv;
+}
+
+bool JSAddressBook::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+AddressBookPtr JSAddressBook::getAddressBook(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(InvalidArgumentException);
+       }
+       AddressBookController *priv = static_cast<AddressBookController*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(NullPointerException);
+       }
+       return priv->getObject();
+}
+
+AddressBookPtr JSAddressBook::getPrivData(JSObjectRef object)
+{
+       AddressBookController *priv =
+               static_cast<AddressBookController*>(JSObjectGetPrivate(object));
+       if (priv) {
+               return priv->getObject();
+       }
+       Throw(NullPointerException);
+}
+
+JSValueRef JSAddressBook::getId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               AddressBookPtr addressBook = getPrivData(object);
+               string id = addressBook->getId();
+               if(id != "")
+                       return converter->toJSValueRef(id);
+               else
+                       return JSValueMakeNull(context);
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::getName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               AddressBookPtr addressBook = getPrivData(object);
+               return converter->toJSValueRef(addressBook->getName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::getReadOnly(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               AddressBookPtr addressBook = getPrivData(object);
+               return converter->toJSValueRef(addressBook->getReadOnly());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::getAccountId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               AddressBookPtr addressBook = getPrivData(object);
+               string accountId = addressBook->getAccountId();
+               if(accountId != "")
+                       return converter->toJSValueRef(accountId);
+               else
+                       return JSValueMakeNull(context);
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::get(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       AddressBookController *controller;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_GET);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+
+       if (argumentCount < 1) {
+               /* 1st Argument must be string. */
+               LogError("1st argument must not be undefined.");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "No Contact id 'undefined'");
+       }
+
+       string id;
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               id = converter->toString(arguments[0]);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+       }
+
+       EventAddressBookGetPtr dplEvent(new EventAddressBookGet());
+
+       dplEvent->setId(id);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->get(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult() || !dplEvent->getContactIsSet())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       LogError("Not Found error : " << id);
+                       oss << "No Contact id '" << id << "'";
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       ContactPtr contact = dplEvent->getContact();
+
+       JSValueRef result;
+       Try {
+               result = converter->toJSValueRef(contact);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       return result;
+}
+
+JSValueRef JSAddressBook::add(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       AddressBookController *controller;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument is an 'undefined'.");
+
+               if (!JSContact::isObjectOfClass(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument is not a 'Contact object'.");
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'Contact object'");
+       }
+
+       ContactPtr contact(NULL);
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               contact = converter->toContact(arguments[0]);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'Contact object'");
+       }
+
+       EventAddressBookAddPtr dplEvent(new EventAddressBookAdd());
+
+       dplEvent->setContact(contact);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->add(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult())
+       {
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+                       case ExceptionCodes::InvalidArgumentException:
+                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "There is Invalid input value");
+                               break;
+               default:
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               }
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::addBatch(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       JSContextRef gContext;
+       AddressBookController *controller;
+
+       bool js2ndParamIsFunction = false;
+       bool js3rdParamIsFunction = false;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       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");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_BATCH);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               // check 1st argument
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument must be an array of 'Contact object'");
+
+               if (!JSValueIsObject(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be an array of 'Contact object'");
+
+               // check 2nd argument
+               if(argumentCount >= 2)
+               {
+                       if(validator->isCallback(arguments[1]))
+                               js2ndParamIsFunction = true;
+
+                       if (!js2ndParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[1]) &&
+                                       !JSValueIsUndefined(context, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "2nd argument must be a 'function' or a 'null'");
+               }
+
+               // check 3rd argument
+               if(argumentCount >= 3)
+               {
+                       if(validator->isCallback(arguments[2]))
+                               js3rdParamIsFunction = true;
+
+                       if (!js3rdParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[2]) &&
+                                       !JSValueIsUndefined(context, arguments[2]))
+                               ThrowMsg(InvalidArgumentException, "3rd argument must be a 'function' or a 'null'");
+               }
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
+
+       if(js2ndParamIsFunction)
+               callbackManager->setOnSuccess(arguments[1]);
+
+       if(js3rdParamIsFunction)
+               callbackManager->setOnError(arguments[2]);
+
+       callbackManager->setObject(thisObject);
+
+       EventAddressBookAddBatchPtr dplEvent(new EventAddressBookAddBatch());
+       Try {
+               dplEvent->setContacts(converter->toContactArray(arguments[0]));
+       } Catch(ConversionException) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be an array of 'Contact object'");
+       }
+
+       // set event handler's data
+       dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+       dplEvent->setForAsynchronousCall(controller);
+
+//     DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
+//     IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
+
+       Try {
+               addressBook->addBatch(dplEvent);
+               ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+//     return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::update(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       AddressBookController *controller;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument is an 'undefined'.");
+
+               if (!JSContact::isObjectOfClass(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument is not a 'Contact object'.");
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'Contact object'");
+       }
+
+       ContactPtr contact(NULL);
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               contact = converter->toContact(arguments[0]);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument is not a 'Contact object'");
+       }
+
+       EventAddressBookUpdatePtr dplEvent(new EventAddressBookUpdate());
+
+       dplEvent->setContact(contact);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->update(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       oss << "No Contact id '" << contact->getId() << "'";
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::updateBatch(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       JSContextRef gContext;
+       AddressBookController *controller;
+
+       bool js2ndParamIsFunction = false;
+       bool js3rdParamIsFunction = false;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       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");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_BATCH);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               // check 1st argument
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument must be an array of 'Contact object'");
+
+               if (!JSValueIsObject(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be an array of 'Contact object'");
+
+               // check 2nd argument
+               if(argumentCount >= 2)
+               {
+                       if(validator->isCallback(arguments[1]))
+                               js2ndParamIsFunction = true;
+
+                       if (!js2ndParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[1]) &&
+                                       !JSValueIsUndefined(context, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "2nd argument must be a 'function' or a 'null'");
+               }
+
+               // check 3rd argument
+               if(argumentCount >= 3)
+               {
+                       if(validator->isCallback(arguments[2]))
+                               js3rdParamIsFunction = true;
+
+                       if (!js3rdParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[2]) &&
+                                       !JSValueIsUndefined(context, arguments[2]))
+                               ThrowMsg(InvalidArgumentException, "3rd argument must be a 'function' or a 'null'");
+               }
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
+
+       if(js2ndParamIsFunction)
+               callbackManager->setOnSuccess(arguments[1]);
+
+       if(js3rdParamIsFunction)
+               callbackManager->setOnError(arguments[2]);
+
+       callbackManager->setObject(thisObject);
+
+       EventAddressBookUpdateBatchPtr dplEvent(new EventAddressBookUpdateBatch());
+       Try {
+               dplEvent->setContacts(converter->toContactArray(arguments[0]));
+       } Catch(ConversionException) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "3rd argument must be an array of 'Contact object'");
+       }
+
+       // set event handler's data
+       dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+       dplEvent->setForAsynchronousCall(controller);
+
+//     DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
+//     IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
+
+       Try {
+               addressBook->updateBatch(dplEvent);
+               ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+//     return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::remove(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       AddressBookController *controller;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       if (argumentCount < 1) {
+               /* 1st Argument must be string. */
+               LogError("1st argument must not be undefined.");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "No Contact id 'undefined'");
+       }
+
+       string contactId;
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               contactId = converter->toString(arguments[0]);
+       }
+       Catch(Exception) {
+               LogError("Error on conversion " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments.");
+       }
+
+       EventAddressBookRemovePtr dplEvent(new EventAddressBookRemove());
+
+       dplEvent->setContactId(contactId);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->remove(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       LogError("Not Found error : " << contactId);
+                       oss << "No Contact id '" << contactId << "'";
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::removeBatch(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       JSContextRef gContext;
+       AddressBookController *controller;
+
+       bool js2ndParamIsFunction = false;
+       bool js3rdParamIsFunction = false;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       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");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_BATCH);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               // check 1st argument
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument must be an array of 'Contact id'");
+
+               if (!JSValueIsObject(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be an array of 'Contact id'");
+
+               // check 2nd argument
+               if(argumentCount >= 2)
+               {
+                       if(validator->isCallback(arguments[1]))
+                               js2ndParamIsFunction = true;
+
+                       if (!js2ndParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[1]) &&
+                                       !JSValueIsUndefined(context, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "2nd argument must be a 'function' or a 'null'");
+               }
+
+               // check 3rd argument
+               if(argumentCount >= 3)
+               {
+                       if(validator->isCallback(arguments[2]))
+                               js3rdParamIsFunction = true;
+
+                       if (!js3rdParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[2]) &&
+                                       !JSValueIsUndefined(context, arguments[2]))
+                               ThrowMsg(InvalidArgumentException, "3rd argument must be a 'function' or a 'null'");
+               }
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
+
+       if(js2ndParamIsFunction)
+               callbackManager->setOnSuccess(arguments[1]);
+
+       if(js3rdParamIsFunction)
+               callbackManager->setOnError(arguments[2]);
+
+       callbackManager->setObject(thisObject);
+
+       EventAddressBookRemoveBatchPtr dplEvent(new EventAddressBookRemoveBatch());
+       Try {
+               dplEvent->setContactIds(converter->toStringArray(arguments[0]));
+       } Catch(ConversionException) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "3rd argument must be an array of 'Contact id'");
+       }
+
+       // set event handler's data
+       dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+       dplEvent->setForAsynchronousCall(controller);
+
+//     DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
+//     IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
+
+       Try {
+               addressBook->removeBatch(dplEvent);
+               ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+//     return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::find(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       JSContextRef gContext;
+       AddressBookController *controller;
+
+       bool js2ndParamIsFunction = false;
+       bool js3rdParamIsObject = false;
+       bool js4thParamIsObject = false;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       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");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_FIND);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'function'");
+
+               if (!validator->isCallback(arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'function'");
+
+               if (argumentCount >= 2)
+               {
+                       if(validator->isCallback(arguments[1]))
+                               js2ndParamIsFunction = true;
+
+                       if (!js2ndParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[1]) &&
+                                       !JSValueIsUndefined(context, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "1st argument must be a 'function' or a 'null'");
+               }
+
+               if (argumentCount >= 3)
+               {
+                       if(JSValueIsObject(context, arguments[2]))
+                               js3rdParamIsObject = true;
+
+                       if (!js3rdParamIsObject &&
+                                       !JSValueIsNull(context, arguments[2]) &&
+                                       !JSValueIsUndefined(context, arguments[2]))
+                               ThrowMsg(InvalidArgumentException, "3rd argument must be an 'Filter object' or 'null'");
+               }
+
+               if (argumentCount >= 4)
+               {
+                       if(JSValueIsObject(context, arguments[3]))
+                               js4thParamIsObject = true;
+
+                       if (!js4thParamIsObject &&
+                                       !JSValueIsNull(context, arguments[3]) &&
+                                       !JSValueIsUndefined(context, arguments[3]))
+                               ThrowMsg(InvalidArgumentException, "4th argument must be an 'SortMode object' or 'null'");
+               }
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
+
+       callbackManager->setOnSuccess(arguments[0]);
+
+       if (js2ndParamIsFunction)
+               callbackManager->setOnError(arguments[1]);
+
+       callbackManager->setObject(thisObject);
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+       EventAddressBookFindPtr dplEvent(new EventAddressBookFind());
+       Try {
+               if (js3rdParamIsObject)
+                       dplEvent->setFilter(filterConverter->toFilter(arguments[2]));
+       } Catch(Exception) {
+               LogError("Error on 3rd parameter conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "3rd argument must be an 'Filter object' or 'null'");
+       }
+
+       Try {
+               if (js4thParamIsObject)
+                       dplEvent->setSortMode(filterConverter->toSortMode(arguments[3]));
+       } Catch(Exception) {
+               LogError("Error on 4th parameter conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "4th argument must be an 'SortMode object' or 'null'");
+       }
+
+       // set event handler's data
+       dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+       dplEvent->setForAsynchronousCall(controller);
+
+//     DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
+//     IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
+
+       Try {
+               addressBook->find(dplEvent);
+               ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+//     return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::addChangeListener(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       JSContextRef gContext;
+       AddressBookController *controller;
+
+       bool js2ndParamIsFunction = false;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       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");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_CHANGE_LISTENER);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'AddressBookChangeCallback object'");
+
+               if (!JSValueIsObject(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'AddressBookChangeCallback object'");
+
+               if (argumentCount >= 2)
+               {
+                       if(validator->isCallback(arguments[1]))
+                               js2ndParamIsFunction = true;
+
+                       if (!js2ndParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[1]) &&
+                                       !JSValueIsUndefined(context, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "2nd argument must be a 'function' or a 'null'");
+               }
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+
+       JSValueRef oncontactsadded;
+       JSValueRef oncontactsupdated;
+       JSValueRef oncontactsdeleted;
+       Try {
+               JSObjectRef callbackObject = converter->toJSObjectRef(arguments[0]);
+
+               oncontactsadded = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsadded");
+               if (validator->isNullOrUndefined(oncontactsadded))
+                       oncontactsadded = NULL;
+               else if (!validator->isCallback(oncontactsadded)) {
+                       ThrowMsg(ConversionException, "2nd argument's oncontactsadded attribute is not a 'function'");
+               }
+
+               oncontactsupdated = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsupdated");
+               if (validator->isNullOrUndefined(oncontactsupdated))
+                       oncontactsupdated = NULL;
+               else if (!validator->isCallback(oncontactsupdated)) {
+                       ThrowMsg(ConversionException, "2nd argument's oncontactsupdated attribute is not a 'function'");
+               }
+
+               oncontactsdeleted = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "oncontactsremoved");
+               if (validator->isNullOrUndefined(oncontactsdeleted))
+                       oncontactsdeleted = NULL;
+               else if (!validator->isCallback(oncontactsdeleted)) {
+                       ThrowMsg(ConversionException, "2nd argument's oncontactsremoved attribute is not a 'function'");
+               }
+
+               if (oncontactsadded == NULL && oncontactsupdated == NULL && oncontactsdeleted == NULL)
+                       ThrowMsg(ConversionException, "2nd argument must have at least one function");
+
+       } Catch(ConversionException) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       JSAddressBookChangeCallbackManagerPtr callbackManager = JSAddressBookChangeCallbackManager::createObject(gContext);
+
+       callbackManager->setOnContactsAdded(oncontactsadded);
+       callbackManager->setOnContactsUpdated(oncontactsupdated);
+       callbackManager->setOnContactsDeleted(oncontactsdeleted);
+       if(js2ndParamIsFunction)
+               callbackManager->setOnError(arguments[1]);
+
+       EventAddressBookChangeListenerEmitterPtr emitter(new EventAddressBookChangeListenerEmitter());
+
+       emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+       emitter->setListener(controller);
+
+       EventAddressBookAddChangeListenerPtr dplEvent(new EventAddressBookAddChangeListener());
+
+       dplEvent->setEmitter(emitter);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->addChangeListener(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult() || !dplEvent->getIdIsSet())
+       {
+               switch (dplEvent->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;
+               }
+       }
+
+       long watchId = dplEvent->getId();
+
+       ContactsChangeListenerCancellerPtr canceller = ContactsChangeListenerCancellerPtr(new ContactsChangeListenerCanceller(gContext, thisObject, watchId));
+       TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+       ContactListenerManagerSingleton::Instance().registerListener(listenerItem, gContext);
+
+       JSValueRef result;
+       Try {
+               result = converter->toJSValueRefLong(watchId);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       return result;
+}
+
+JSValueRef JSAddressBook::removeChangeListener(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       JSContextRef gContext;
+       AddressBookController *controller;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       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");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_CHANGE_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'");
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+
+       long watchId = 0;
+       Try {
+               watchId = static_cast<long>(converter->toLong(arguments[0]));
+
+               if (watchId < 0)
+                       ThrowMsg(PlatformException, "watchId is wrong (" << watchId << ")");
+       } Catch(Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       EventAddressBookRemoveChangeListenerPtr dplEvent(new EventAddressBookRemoveChangeListener());
+
+       dplEvent->setId(watchId);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->removeChangeListener(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       ContactsChangeListenerCancellerPtr canceller = ContactsChangeListenerCancellerPtr(new ContactsChangeListenerCanceller(gContext, thisObject, watchId));
+       TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+       ContactListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+
+       if (!dplEvent->getResult())
+       {
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::InvalidArgumentException:
+               case ExceptionCodes::NotFoundException:
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "Watch id not found");
+                       break;
+               default:
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               }
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::getGroup(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       AddressBookController *controller;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUP);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       if (argumentCount < 1) {
+               /* 1st Argument must be string. */
+               LogError("1st argument must not be undefined.");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::NOT_FOUND_ERROR, "No Group id 'undefined'");
+       }
+
+       string id;
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               id = converter->toString(arguments[0]);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+       }
+
+       EventAddressBookGetGroupPtr dplEvent(new EventAddressBookGetGroup());
+
+       dplEvent->setId(id);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->getGroup(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult() || !dplEvent->getContactGroupIsSet())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       LogError("Not Found error : " << id);
+                       oss << "No Contact id '" << id << "'";
+                       return JSTizenExceptionFactory::postException(context, exception,
+                                       JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       ContactGroupPtr group = dplEvent->getContactGroup();
+
+       JSValueRef result;
+       Try {
+               result = converter->toJSValueRef(group);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       return result;
+}
+
+JSValueRef JSAddressBook::addGroup(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       AddressBookController *controller;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_GROUP);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument is an 'undefined'.");
+
+               if (!JSContactGroup::isObjectOfClass(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument is not a 'ContactGroup object'.");
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactGroup object'");
+       }
+
+       ContactGroupPtr group(NULL);
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               group = converter->toContactGroup(arguments[0]);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactGroup object'");
+       }
+
+       EventAddressBookAddGroupPtr dplEvent(new EventAddressBookAddGroup());
+
+       dplEvent->setContactGroup(group);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->addGroup(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult())
+       {
+               switch (dplEvent->getExceptionCode())
+               {
+               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;
+               }
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::updateGroup(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       AddressBookController *controller;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_GROUP);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument is an 'undefined'.");
+
+               if (!JSContactGroup::isObjectOfClass(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument is not a 'ContactGroup object'.");
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactGroup object'");
+       }
+
+       ContactGroupPtr contact(NULL);
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               contact = converter->toContactGroup(arguments[0]);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument is not a 'ContactGroup object'");
+       }
+
+       EventAddressBookUpdateGroupPtr dplEvent(new EventAddressBookUpdateGroup());
+
+       dplEvent->setContactGroup(contact);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->updateGroup(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       oss << "No Contact id '" << contact->getId() << "'";
+                       return JSTizenExceptionFactory::postException(context, exception,
+                                       JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::removeGroup(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       AddressBookController *controller;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_GROUP);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       if (argumentCount < 1) {
+               /* 1st Argument must be string. */
+               LogError("1st argument must not be undefined.");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::NOT_FOUND_ERROR, "No ContactGroup id 'undefined'");
+       }
+
+       string groupId;
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               groupId = converter->toString(arguments[0]);
+       }
+       Catch(Exception) {
+               LogError("Error on conversion " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments.");
+       }
+
+       EventAddressBookRemoveGroupPtr dplEvent(new EventAddressBookRemoveGroup());
+
+       dplEvent->setContactGroupId(groupId);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->removeGroup(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       LogError("Not Found error : " << groupId);
+                       oss << "No Contact id '" << groupId << "'";
+                       return JSTizenExceptionFactory::postException(context, exception,
+                                       JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBook::getGroups(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       AddressBookPtr addressBook;
+       AddressBookController *controller;
+
+       Try     {
+               controller = static_cast<AddressBookController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUPS);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       string id;
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+
+       EventAddressBookGetGroupsPtr dplEvent(new EventAddressBookGetGroups());
+
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->getGroups(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult() || !dplEvent->getContactGroupsIsSet())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       LogError("Not Found error : " << id);
+                       oss << "No Contact id '" << id << "'";
+                       return JSTizenExceptionFactory::postException(context, exception,
+                                       JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       ContactGroupArrayPtr groups = dplEvent->getContactGroups();
+
+       JSValueRef result;
+       Try {
+               result = converter->toJSValueRef(groups);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       return result;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSAddressBook.h b/src/standards/Tizen/Contact/JSAddressBook.h
new file mode 100755 (executable)
index 0000000..0a7ad6a
--- /dev/null
@@ -0,0 +1,202 @@
+//
+// 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        JSAddressBook.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSAddressBook class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_ADDRESS_BOOK_H_
+#define _TIZEN_CONTACT_JS_ADDRESS_BOOK_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/JSPendingOperationPrivateObject.h>
+#include <API/Contact/IAddressBook.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject
+               <TizenApis::Api::Contact::AddressBookPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSAddressBookPriv;
+
+class JSAddressBook
+{
+public:
+
+       static const JSClassRef getClassRef();
+
+       static const JSClassDefinition* getClassInfo();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::AddressBookPtr getAddressBook(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 JSClassDefinition m_classInfo;
+
+       static JSStaticFunction m_function[];
+
+       static JSStaticValue m_property[];
+
+       static JSClassRef m_jsClassRef;
+
+       static TizenApis::Api::Contact::AddressBookPtr getPrivData(JSObjectRef object);
+
+       static JSValueRef getId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getReadOnly(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getAccountId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef get(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef add(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef addBatch(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 updateBatch(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 removeBatch(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef find(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef addChangeListener(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef removeChangeListener(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef getGroup(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef addGroup(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef updateGroup(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef removeGroup(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef getGroups(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_ADDRESS_BOOK_H_
diff --git a/src/standards/Tizen/Contact/JSAddressBookArray.cpp b/src/standards/Tizen/Contact/JSAddressBookArray.cpp
new file mode 100755 (executable)
index 0000000..f817d82
--- /dev/null
@@ -0,0 +1,633 @@
+//
+// 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        JSAddressBookArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSAddressBookArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSAddressBookArray::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 JSAddressBookArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSAddressBookArray::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 JSAddressBookArray::m_jsClassRef = JSClassCreate(
+               JSAddressBookArray::getClassInfo());
+
+JSValueRef JSAddressBookArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               AddressBookArrayPtr addressBooks = priv->getObject();
+               if (addressBooks) {
+                       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(addressBooks->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSAddressBookArray::createArray(JSContextRef context,
+               const AddressBookArrayPtr &addressBooks)
+{
+       JSAddressBookArrayPriv *priv = new JSAddressBookArrayPriv(context, addressBooks);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSAddressBookArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+bool JSAddressBookArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+AddressBookArrayPtr JSAddressBookArray::getAddressBookArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSAddressBookArrayPriv *priv = static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+JSClassRef JSAddressBookArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+void JSAddressBookArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSAddressBookArray::finalize(JSObjectRef object)
+{
+       JSAddressBookArrayPriv* priv =
+               static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSAddressBookArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               AddressBookArrayPtr addressBooks = priv->getObject();
+               if (index < addressBooks->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSAddressBookArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               AddressBookArrayPtr addressBooks = priv->getObject();
+               if (index < addressBooks->size()) {
+                       AddressBookPtr result = addressBooks->at(index);
+                       if (result) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSAddressBookArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               AddressBookPtr addressBook(NULL);
+               if (!JSValueIsUndefined(context, value)) {
+                       addressBook = converter->toAddressBook(value);
+               }
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               AddressBookArrayPtr addressBooks = priv->getObject();
+               if (!addressBooks) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (addressBooks->size() <= index) {
+                       addressBooks->resize(index + 1);
+               }
+               (*addressBooks)[index] = addressBook;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSAddressBookArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               AddressBookPtr addressBook(NULL);
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               AddressBookArrayPtr addressBooks = priv->getObject();
+               if (!addressBooks) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (addressBooks->size() > index) {
+                       (*addressBooks)[index] = addressBook;
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSAddressBookArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               AddressBookArrayPtr addressBooks = priv->getObject();
+
+               int count = addressBooks->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 JSAddressBookArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               AddressBookArrayPtr addressBooks = AddressBookArrayPtr(new AddressBookArray());
+               JSAddressBookArrayPriv *newPrivateObject = new JSAddressBookArrayPriv(context, addressBooks);
+               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
+
+               //copy current addressBooks
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
+               AddressBookArrayPtr currentAddressBooks = priv->getObject();
+               for (size_t i = 0; i < currentAddressBooks->size(); ++i) {
+                       addressBooks->push_back(currentAddressBooks->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::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);
+                               addressBooks->push_back(converter->toAddressBook(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSAddressBookArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
+               AddressBookArrayPtr currentAddressBooks = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentAddressBooks->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       //FIXME : to be changed to support join
+                       //result += currentAddressBooks->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 JSAddressBookArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
+               AddressBookArrayPtr currentAddressBooks = priv->getObject();
+               if (currentAddressBooks->size() > 0) {
+                       AddressBookPtr result = currentAddressBooks->at(
+                                       currentAddressBooks->size() - 1);
+                       currentAddressBooks->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBookArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
+               AddressBookArrayPtr currentAddressBooks = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentAddressBooks->push_back(converter->toAddressBook(arguments[i]));
+               }
+               return converter->toJSValueRef(currentAddressBooks->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSAddressBookArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
+               AddressBookArrayPtr currentAddressBooks = priv->getObject();
+               std::reverse(currentAddressBooks->begin(), currentAddressBooks->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBookArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
+               AddressBookArrayPtr currentAddressBooks = priv->getObject();
+               if (currentAddressBooks->size() > 0) {
+                       AddressBookPtr result = currentAddressBooks->at(0);
+                       currentAddressBooks->erase(currentAddressBooks->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBookArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               AddressBookArrayPtr addressBooks = AddressBookArrayPtr(new AddressBookArray());
+               JSAddressBookArrayPriv *newPrivateObject = new JSAddressBookArrayPriv(
+                               context,
+                               addressBooks);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current addressBooks
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
+               AddressBookArrayPtr currentAddressBooks = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentAddressBooks->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentAddressBooks->size()) {
+                               last = currentAddressBooks->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       addressBooks->push_back(currentAddressBooks->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSAddressBookArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSAddressBookArrayPriv* priv =
+                       static_cast<JSAddressBookArrayPriv*>(JSObjectGetPrivate(thisObject));
+               AddressBookArrayPtr currentAddressBooks = priv->getObject();
+               std::sort(currentAddressBooks->begin(), currentAddressBooks->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBookArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBookArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSAddressBookArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAddressBookArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSAddressBookArray.h b/src/standards/Tizen/Contact/JSAddressBookArray.h
new file mode 100755 (executable)
index 0000000..66cae65
--- /dev/null
@@ -0,0 +1,192 @@
+//
+// 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        JSAddressBookArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_ADDRESS_BOOK_ARRAY_H_
+#define _TIZEN_CONTACT_JS_ADDRESS_BOOK_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/IAddressBook.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::AddressBookArrayPtr>::Type JSAddressBookArrayPriv;
+
+class JSAddressBookArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::AddressBookArrayPtr &anniversaries);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::AddressBookArrayPtr getAddressBookArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_ADDRESS_BOOK_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSAddressBookChangeCallbackManager.cpp b/src/standards/Tizen/Contact/JSAddressBookChangeCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..41c0323
--- /dev/null
@@ -0,0 +1,256 @@
+//
+// 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        JSAddressBookChangeCallbackManager.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "JSAddressBookChangeCallbackManager.h"
+#include <dpl/log/log.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+JSAddressBookChangeCallbackManagerPtr JSAddressBookChangeCallbackManager::createObject(JSContextRef context)
+{
+       return JSAddressBookChangeCallbackManagerPtr( new JSAddressBookChangeCallbackManager(context) );
+}
+
+JSAddressBookChangeCallbackManager::JSAddressBookChangeCallbackManager(JSContextRef context,
+               JSObjectRef onContactsAdded,
+               JSObjectRef onContactsUpdated,
+               JSObjectRef onContactsDeleted,
+               JSObjectRef onError ) :
+               m_onContactsAdded(NULL),
+               m_onContactsUpdated(NULL),
+               m_onContactsDeleted(NULL),
+               m_onError(NULL),
+               m_context(context),
+               m_object(NULL)
+{
+       setOnContactsAdded(onContactsAdded);
+       setOnContactsUpdated(onContactsUpdated);
+       setOnContactsDeleted(onContactsDeleted);
+    setOnError(onError);
+}
+
+JSAddressBookChangeCallbackManager::~JSAddressBookChangeCallbackManager()
+{
+       if(m_onContactsAdded)
+       {
+               JSValueUnprotect(m_context, m_onContactsAdded);
+       }
+
+       if(m_onContactsUpdated)
+       {
+               JSValueUnprotect(m_context, m_onContactsUpdated);
+       }
+
+       if(m_onContactsDeleted)
+       {
+               JSValueUnprotect(m_context, m_onContactsDeleted);
+       }
+
+    if(m_onError)
+    {
+        JSValueUnprotect(m_context, m_onError);
+    }
+}
+
+void JSAddressBookChangeCallbackManager::setOnContactsAdded( JSValueRef onContactsAdded )
+{
+       if (onContactsAdded)
+       {
+               if (m_onContactsAdded != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onContactsAdded);
+               }
+
+               m_onContactsAdded = JSValueToObject( m_context, onContactsAdded, NULL );
+
+               if (m_onContactsAdded != NULL)
+               {
+                       JSValueProtect(m_context, m_onContactsAdded);
+               }
+       }
+}
+
+JSValueRef JSAddressBookChangeCallbackManager::getOnContactsAdded() const
+{
+       return m_onContactsAdded;
+}
+
+void JSAddressBookChangeCallbackManager::setOnContactsUpdated( JSValueRef onContactsUpdated )
+{
+       if (onContactsUpdated)
+       {
+               if (m_onContactsUpdated != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onContactsUpdated);
+               }
+
+               m_onContactsUpdated = JSValueToObject( m_context, onContactsUpdated, NULL );
+
+               if (m_onContactsUpdated != NULL)
+               {
+                       JSValueProtect(m_context, m_onContactsUpdated);
+               }
+       }
+}
+
+JSValueRef JSAddressBookChangeCallbackManager::getOnContactsUpdated() const
+{
+       return m_onContactsUpdated;
+}
+
+void JSAddressBookChangeCallbackManager::setOnContactsDeleted( JSValueRef onContactsDeleted )
+{
+       if (onContactsDeleted)
+       {
+               if (m_onContactsDeleted != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onContactsDeleted);
+               }
+
+               m_onContactsDeleted = JSValueToObject( m_context, onContactsDeleted, NULL );
+
+               if (m_onContactsDeleted != NULL)
+               {
+                       JSValueProtect(m_context, m_onContactsDeleted);
+               }
+       }
+}
+
+JSValueRef JSAddressBookChangeCallbackManager::getOnContactsDeleted() const
+{
+       return m_onContactsDeleted;
+}
+
+void JSAddressBookChangeCallbackManager::setOnError( JSValueRef onError )
+{
+    if (onError)
+    {
+        if (m_onError != NULL)
+        {
+            JSValueUnprotect(m_context, m_onError);
+        }
+
+        m_onError = JSValueToObject( m_context, onError, NULL );
+
+        if (m_onError != NULL)
+        {
+            JSValueProtect(m_context, m_onError);
+        }
+    }
+}
+
+JSValueRef JSAddressBookChangeCallbackManager::getOnError() const
+{
+    return m_onError;
+}
+
+void JSAddressBookChangeCallbackManager::setContext( JSContextRef context )
+{
+    m_context = context;
+}
+
+void JSAddressBookChangeCallbackManager::setObject( JSObjectRef object )
+{
+    m_object = object;
+}
+
+JSObjectRef JSAddressBookChangeCallbackManager::getObject() const
+{
+    return m_object;
+}
+
+void JSAddressBookChangeCallbackManager::callOnContactsAdded( JSValueRef contacts )
+{
+    if ( m_onContactsAdded == NULL )
+    {
+        //LogDebug("oncontactsadded callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { contacts };
+    makeCallback( m_context, NULL, m_onContactsAdded, "oncontactsadded", objParam, 1 );
+}
+
+void JSAddressBookChangeCallbackManager::callOnContactsUpdated( JSValueRef contacts )
+{
+    if ( m_onContactsUpdated == NULL )
+    {
+        //LogDebug("oncontactsupdated callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { contacts };
+    makeCallback( m_context, NULL, m_onContactsUpdated, "oncontactsupdated", objParam, 1 );
+}
+
+void JSAddressBookChangeCallbackManager::callOnContactsDeleted( JSValueRef contactIds )
+{
+    if ( m_onContactsDeleted == NULL )
+    {
+        //LogDebug("oncontactsdeleted callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { contactIds };
+    makeCallback( m_context, NULL, m_onContactsDeleted, "oncontactsdeleted", objParam, 1 );
+}
+
+void JSAddressBookChangeCallbackManager::callOnError( JSValueRef error )
+{
+    if ( m_onError == NULL )
+    {
+        //LogDebug("Error callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { error };
+    makeCallback( m_context, NULL, m_onError, "onError", objParam, 1 );
+}
+
+void JSAddressBookChangeCallbackManager::makeCallback(JSContextRef context, JSObjectRef object, JSObjectRef callback, const char *szName, JSValueRef argv[], unsigned argc)
+{
+
+    if (callback == NULL)
+    {
+        LogError("callback is NULL");
+        return;
+    }
+
+    if (JSObjectIsFunction(context, callback))
+    {
+        if (argc == 0)
+        {
+                //LogDebug("Calling object directly, no arguments");
+                JSObjectCallAsFunction(context, callback, object, 0, NULL, NULL);
+        }
+        else
+        {
+                //LogDebug("Calling object directly, one argument");
+                JSObjectCallAsFunction(context, callback, object, argc, argv, NULL);
+        }
+        return;
+    }
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSAddressBookChangeCallbackManager.h b/src/standards/Tizen/Contact/JSAddressBookChangeCallbackManager.h
new file mode 100755 (executable)
index 0000000..fbd30e3
--- /dev/null
@@ -0,0 +1,93 @@
+//
+// 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        JSAddressBookChangeCallbackManager.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_ADDRESS_BOOK_CHANGE_CALLBACK_MANAGER_H_
+#define _TIZEN_CONTACT_JS_ADDRESS_BOOK_CHANGE_CALLBACK_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <JavaScriptCore/JavaScript.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+class JSAddressBookChangeCallbackManager;
+typedef DPL::SharedPtr<JSAddressBookChangeCallbackManager> JSAddressBookChangeCallbackManagerPtr;
+
+class JSAddressBookChangeCallbackManager : public WrtDeviceApis::Commons::IEventPrivateData
+{
+private:
+       JSAddressBookChangeCallbackManager() {}
+       JSAddressBookChangeCallbackManager( JSContextRef context,
+                       JSObjectRef onContactsAdded = NULL,
+                       JSObjectRef onContactsUpdated = NULL,
+                       JSObjectRef onContactsDeleted = NULL,
+                       JSObjectRef onError = NULL );
+
+public:
+       static JSAddressBookChangeCallbackManagerPtr createObject(JSContextRef context);
+
+       virtual ~JSAddressBookChangeCallbackManager();
+
+       void    setContext( JSContextRef context );
+       JSContextRef getContext() const { return m_context; }
+
+       void    setOnContactsAdded( JSValueRef onContactsAdded );
+       JSValueRef getOnContactsAdded() const;
+       void    setOnContactsUpdated( JSValueRef onContactsUpdated );
+       JSValueRef getOnContactsUpdated() const;
+       void    setOnContactsDeleted( JSValueRef onContactsDeleted );
+       JSValueRef getOnContactsDeleted() const;
+       void    setOnError( JSValueRef onError );
+       JSValueRef getOnError() const;
+       void    setObject( JSObjectRef object );
+       JSObjectRef getObject() const;
+
+       void    callOnContactsAdded( JSValueRef contacts );
+       void    callOnContactsUpdated( JSValueRef contacts );
+       void    callOnContactsDeleted( JSValueRef contactIds );
+       void    callOnError( JSValueRef error );
+
+private:
+       void    makeCallback(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef callback,
+                       const char *szName,
+                       JSValueRef argv[],
+                       unsigned argc);
+
+       JSObjectRef  m_onContactsAdded;
+       JSObjectRef  m_onContactsUpdated;
+       JSObjectRef  m_onContactsDeleted;
+       JSObjectRef  m_onError;
+       JSContextRef m_context;
+       JSObjectRef  m_object;
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_ADDRESS_BOOK_CHANGE_CALLBACK_MANAGER_H_
diff --git a/src/standards/Tizen/Contact/JSAttributesOfInterestArray.cpp b/src/standards/Tizen/Contact/JSAttributesOfInterestArray.cpp
new file mode 100755 (executable)
index 0000000..1e5d170
--- /dev/null
@@ -0,0 +1,621 @@
+//
+// 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        JSAttributesOfInterestArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSAttributesOfInterestArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSAttributesOfInterestArray::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 JSAttributesOfInterestArray::m_property[] = {
+    { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSAttributesOfInterestArray::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 JSAttributesOfInterestArray::m_jsClassRef = JSClassCreate(
+        JSAttributesOfInterestArray::getClassInfo());
+
+JSValueRef JSAttributesOfInterestArray::getLength(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    //LogDebug("enter");
+    Try
+    {
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            Throw(WrtDeviceApis::Commons::NullPointerException);
+        }
+        AttributesOfInterestArrayPtr typeArray = priv->getObject();
+        if (typeArray) {
+                       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+            return converter->toJSValueRef(typeArray->size());
+        }
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("invalid conversion");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSAttributesOfInterestArray::createArray(JSContextRef context,
+        const AttributesOfInterestArrayPtr &typeArray)
+{
+    JSAttributesOfInterestArrayPriv *priv = new JSAttributesOfInterestArrayPriv(context, typeArray);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSAttributesOfInterestArray::getClassInfo()
+{
+    return &(m_classInfo);
+}
+
+JSClassRef JSAttributesOfInterestArray::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+bool JSAttributesOfInterestArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+AttributesOfInterestArrayPtr JSAttributesOfInterestArray::getAttributesOfInterestArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSAttributesOfInterestArrayPriv *priv = static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSAttributesOfInterestArray::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    //LogDebug("enter");
+}
+
+void JSAttributesOfInterestArray::finalize(JSObjectRef object)
+{
+    //LogDebug("enter");
+    JSAttributesOfInterestArrayPriv* priv =
+        static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
+    delete priv;
+    JSObjectSetPrivate(object, NULL);
+}
+
+bool JSAttributesOfInterestArray::hasProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName)
+{
+    //LogDebug("enter");
+       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+    Try
+    {
+        size_t index = converter->toSizeT(propertyName);
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            Throw(WrtDeviceApis::Commons::NullPointerException);
+        }
+        AttributesOfInterestArrayPtr typeArray = priv->getObject();
+        if (index < typeArray->size()) {
+            return true;
+        }
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        //not reporting error is intended
+    }
+    return false;
+}
+
+JSValueRef JSAttributesOfInterestArray::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    //LogDebug("enter");
+       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+    Try
+    {
+        size_t index = converter->toSizeT(propertyName);
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            Throw(WrtDeviceApis::Commons::NullPointerException);
+        }
+        AttributesOfInterestArrayPtr typeArray = priv->getObject();
+        if (index < typeArray->size()) {
+            std::string result = typeArray->at(index);
+            if (!result.empty()) {
+                return converter->toJSValueRef(result);
+            }
+        }
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("invalid property");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSAttributesOfInterestArray::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    //LogDebug("enter");
+       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+    Try
+    {
+        size_t index = converter->toSizeT(propertyName);
+        std::string str;
+        if (!JSValueIsUndefined(context, value)) {
+            str = converter->toString(value);
+        }
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            Throw(WrtDeviceApis::Commons::NullPointerException);
+        }
+        AttributesOfInterestArrayPtr typeArray = priv->getObject();
+        if (!typeArray) {
+            Throw(WrtDeviceApis::Commons::NullPointerException);
+        }
+        if (typeArray->size() <= index) {
+            typeArray->resize(index + 1);
+        }
+        (*typeArray)[index] = str;
+        return true;
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("error occured");
+        JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+    }
+    return false;
+}
+
+void JSAttributesOfInterestArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSAttributesOfInterestArrayPriv* priv =
+                       static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               AttributesOfInterestArrayPtr interests = priv->getObject();
+
+               int count = interests->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 JSAttributesOfInterestArray::concat(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("enter");
+    Try
+    {
+        AttributesOfInterestArrayPtr typeArray =
+                       AttributesOfInterestArrayPtr(new AttributesOfInterestArray());
+        JSAttributesOfInterestArrayPriv *newPrivateObject =
+                       new JSAttributesOfInterestArrayPriv(context, typeArray);
+        JSValueRef result = JSObjectMake(context,
+                                         getClassRef(), newPrivateObject);
+
+        //copy current typeArray
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
+        AttributesOfInterestArrayPtr currentStrings = priv->getObject();
+        for (size_t i = 0; i < currentStrings->size(); ++i) {
+            typeArray->push_back(currentStrings->at(i));
+        }
+
+        //copy submitted arrays
+        ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::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);
+                typeArray->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 JSAttributesOfInterestArray::join(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("entered");
+    Try
+    {
+        std::string result;
+        std::string separator(",");
+               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
+        AttributesOfInterestArrayPtr 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 JSAttributesOfInterestArray::pop(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("entered");
+    Try
+    {
+               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
+        AttributesOfInterestArrayPtr 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 JSAttributesOfInterestArray::push(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("entered");
+    Try
+    {
+        ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
+        AttributesOfInterestArrayPtr 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 JSAttributesOfInterestArray::reverse(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("entered");
+    Try
+    {
+               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
+        AttributesOfInterestArrayPtr currentStrings = priv->getObject();
+        std::reverse(currentStrings->begin(), currentStrings->end());
+        return thisObject;
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("error occured");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAttributesOfInterestArray::shift(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("entered");
+    Try
+    {
+               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
+        AttributesOfInterestArrayPtr 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 JSAttributesOfInterestArray::slice(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("enter");
+    Try
+    {
+        if (argumentCount < 1) {
+            return JSValueMakeUndefined(context);
+        }
+               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+        AttributesOfInterestArrayPtr typeArray = AttributesOfInterestArrayPtr(new StringArray());
+        JSAttributesOfInterestArrayPriv *newPrivateObject = new JSAttributesOfInterestArrayPriv(
+                context,
+                typeArray);
+        JSValueRef result = JSObjectMake(context,
+                                         getClassRef(), newPrivateObject);
+
+        //copy current typeArray
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
+        AttributesOfInterestArrayPtr 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) {
+            typeArray->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 JSAttributesOfInterestArray::sort(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("entered");
+    Try
+    {
+               WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                               WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+        JSAttributesOfInterestArrayPriv* priv =
+            static_cast<JSAttributesOfInterestArrayPriv*>(JSObjectGetPrivate(thisObject));
+        AttributesOfInterestArrayPtr currentStrings = priv->getObject();
+        std::sort(currentStrings->begin(), currentStrings->end());
+        return thisObject;
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("error occured");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAttributesOfInterestArray::splice(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAttributesOfInterestArray::toString(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("entered");
+    return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSAttributesOfInterestArray::unshift(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAttributesOfInterestArray::valueOf(JSContextRef context,
+        JSObjectRef function,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    //LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSAttributesOfInterestArray.h b/src/standards/Tizen/Contact/JSAttributesOfInterestArray.h
new file mode 100755 (executable)
index 0000000..fd90bef
--- /dev/null
@@ -0,0 +1,187 @@
+//
+// 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        JSAttributesOfInterestArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_ATTRIBUTES_OF_INTEREST_ARRAY_H_
+#define _TIZEN_CONTACT_JS_ATTRIBUTES_OF_INTEREST_ARRAY_H_
+
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::AttributesOfInterestArrayPtr>::Type JSAttributesOfInterestArrayPriv;
+
+class JSAttributesOfInterestArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::AttributesOfInterestArrayPtr &Strings);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::AttributesOfInterestArrayPtr getAttributesOfInterestArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_ATTRIBUTES_OF_INTEREST_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSContact.cpp b/src/standards/Tizen/Contact/JSContact.cpp
new file mode 100755 (executable)
index 0000000..54227e1
--- /dev/null
@@ -0,0 +1,1086 @@
+//
+// 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        JSContact.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSContact class
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Validator.h>
+#include <API/Contact/ContactFactory.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include "plugin_config.h"
+#include "ContactConverter.h"
+#include "JSContact.h"
+
+#define FILTER_CLASS_NAME "Contact"
+
+#define CONTACT_ATTR_ID             "id"
+#define CONTACT_ATTR_ADDRESSBOOK_ID "addressBookId"
+#define CONTACT_ATTR_PERSON_ID      "personId"
+#define CONTACT_ATTR_LAST_UPDATED   "lastUpdated"
+#define CONTACT_ATTR_IS_FAVORITE    "isFavorite"
+#define CONTACT_ATTR_NAME           "name"
+#define CONTACT_ATTR_ADDRESSES      "addresses"
+#define CONTACT_ATTR_PHOTO_URI      "photoURI"
+#define CONTACT_ATTR_PHONE_NUMBERS  "phoneNumbers"
+#define CONTACT_ATTR_EMAILS         "emails"
+#define CONTACT_ATTR_BIRTHDAY       "birthday"
+#define CONTACT_ATTR_ANNIVERSARIES  "anniversaries"
+#define CONTACT_ATTR_ORGANIZATIONS  "organizations"
+#define CONTACT_ATTR_NOTES          "notes"
+#define CONTACT_ATTR_URLS           "urls"
+#define CONTACT_ATTR_LAST_UPDATED   "lastUpdated"
+#define CONTACT_ATTR_RINGTONE_URI   "ringtoneURI"
+#define CONTACT_ATTR_GROUP_IDS      "groupIds"
+#define CONTACT_FUNC_CONVERT_TO_STRING         "convertToString"
+#define CONTACT_FUNC_CLONE                                     "clone"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContact::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       FILTER_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 JSContact::m_property[] = {
+       { CONTACT_ATTR_ID, getId, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_ATTR_ADDRESSBOOK_ID, getAddressBookId, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_ATTR_PERSON_ID, getPersonId, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_ATTR_LAST_UPDATED, getLastUpdated, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_ATTR_IS_FAVORITE, getIsFavorite, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_ATTR_NAME, getName, setName, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_ADDRESSES, getAddresses, setAddresses, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_PHOTO_URI, getPhotoURI, setPhotoURI, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_PHONE_NUMBERS, getPhoneNumbers, setPhoneNumbers, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_EMAILS, getEmails, setEmails, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_BIRTHDAY, getBirthday, setBirthday, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_ANNIVERSARIES, getAnniversaries, setAnniversaries, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_ORGANIZATIONS, getOrganizations, setOrganizations, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_NOTES, getNotes, setNotes, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_URLS, getUrls, setUrls, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_RINGTONE_URI, getRingtoneURI, setRingtoneURI, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_GROUP_IDS, getGroupIds, setGroupIds, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContact::m_functions[] =
+{
+       { CONTACT_FUNC_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone },
+       { CONTACT_FUNC_CLONE, clone, kJSPropertyAttributeNone },
+       { 0, 0, 0 }
+};
+
+JSClassRef JSContact::m_classRef = JSClassCreate(&m_classInfo);
+
+JSClassRef JSContact::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSContact::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactPtr JSContact::getContact(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContact::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               ContactPtr contact = ContactFactory::getInstance().createContact();
+               JSContactPriv *priv = new JSContactPriv(context, ContactPtr(contact));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSContact::Finalize(JSObjectRef object)
+{
+       JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+               delete (priv);
+}
+
+JSObjectRef JSContact::createJSObject(JSContextRef context, ContactPtr contact)
+{
+       JSContactPriv *priv = new JSContactPriv(context, contact);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+ContactPtr JSContact::getPrivData(JSObjectRef object)
+{
+       JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ContactPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null.");
+       }
+       return result;
+}
+
+JSObjectRef JSContact::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       bool jsNoParam = false;
+       bool js1stParamIsObject = false;
+       bool js1stParamIsString = false;
+
+       JSContactPriv *priv = static_cast<JSContactPriv*>(JSObjectGetPrivate(constructor));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       JSContextRef gContext = priv->getContext();
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       if (argumentCount == 0)
+       {
+               jsNoParam = true;
+       }
+       else
+       {
+               if (JSValueIsNull(gContext, arguments[0]) || JSValueIsUndefined(gContext, arguments[0]))
+                       jsNoParam = true;
+               else if (JSValueIsObject(gContext, arguments[0]))
+                       js1stParamIsObject = true;
+               else if (JSValueIsString(gContext, arguments[0]))
+                       js1stParamIsString = true;
+               else
+               {
+                       LogError("Argument type mismatch : 1nd argument must be ContactInit object or string");
+                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be 'ContactTextFormat'");
+                       return NULL;
+               }
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
+
+       ContactPtr contact(NULL);
+       if(js1stParamIsObject)
+       {
+               Try {
+                       contact = converter->toContactFromInit(arguments[0]);
+
+               } Catch(ConversionException) {
+                       LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactInit object'");
+                       return NULL;
+               } Catch(Exception) {
+                       LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       return NULL;
+               }
+       }
+       else if(js1stParamIsString)
+       {
+               Try {
+                       std::string stringRepresentation;       // vCard string
+
+                       stringRepresentation = converter->toString(arguments[0]);
+
+                       contact = ContactFactory::getInstance().createContact();
+                       contact->setContactFromString(stringRepresentation);
+
+               } Catch(ConversionException) {
+                       LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "2nd argument must be 'ContactTextFormat'");
+                       return NULL;
+               } Catch(InvalidArgumentException) {
+                       LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "1st argument must be vCard string");
+                       return NULL;
+               } Catch(UnsupportedException) {
+                       LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
+                       return NULL;
+               } Catch(Exception) {
+                       LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       return NULL;
+               }
+       }
+       else
+       {
+               Try {
+                       contact = ContactFactory::getInstance().createContact();
+               } Catch(Exception) {
+                       LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+                       *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       return NULL;
+               }
+       }
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, contact);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+bool JSContact::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSContact::getId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               if(!contact->getIdIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contact->getId());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContact::getAddressBookId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               if(!contact->getAddressBookIdIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contact->getAddressBookId());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContact::getPersonId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               if(!contact->getPersonIdIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contact->getPersonId());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContact::getLastUpdated(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               if(!contact->getLastUpdatedIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contact->getLastUpdated());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContact::getIsFavorite(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               return converter->toJSValueRef(contact->getIsFavorite());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContact::getName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               ContactNamePtr contactName = contact->getName();
+               if(contactName == NULL)
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactName);
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contact->unsetName();
+               else
+                       contact->setName(converter->toContactName(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 JSContact::getAddresses(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               return converter->toJSValueRef(contact->getAddresses());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setAddresses(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contact->setAddresses(converter->toContactAddressArray(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 JSContact::getPhotoURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               if(!contact->getPhotoURIIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contact->getPhotoURI());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setPhotoURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contact->unsetPhotoURI();
+               else
+                       contact->setPhotoURI(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 JSContact::getPhoneNumbers(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               return converter->toJSValueRef(contact->getPhoneNumbers());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setPhoneNumbers(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contact->setPhoneNumbers(
+                               converter->toContactPhoneNumberArray(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 JSContact::getEmails(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               return converter->toJSValueRef(contact->getEmails());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setEmails(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contact->setEmails(converter->toContactEmailAddressArray(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 JSContact::getBirthday(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               if(!contact->getBirthdayIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contact->getBirthday());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setBirthday(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contact->unsetBirthday();
+               else
+                       contact->setBirthday(converter->toDateTm(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 JSContact::getAnniversaries(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               return converter->toJSValueRef(contact->getAnniversaries());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setAnniversaries(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contact->setAnniversaries(
+                               converter->toContactAnniversaryArray(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 JSContact::getOrganizations(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               return converter->toJSValueRef(contact->getOrganizations());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setOrganizations(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contact->setOrganizations(
+                               converter->toContactOrganizationArray(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 JSContact::getNotes(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               return converter->toJSValueRef(contact->getNotes());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setNotes(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contact->setNotes(converter->toStringArray(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 JSContact::getUrls(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               return converter->toJSValueRef(contact->getUrls());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setUrls(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contact->setUrls(converter->toContactWebSiteArray(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 JSContact::getRingtoneURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               if(!contact->getRingtoneURIIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contact->getRingtoneURI());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setRingtoneURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contact->unsetRingtoneURI();
+               else
+                       contact->setRingtoneURI(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 JSContact::getGroupIds(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPtr contact = getPrivData(object);
+               return converter->toJSValueRef(contact->getGroupIds());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContact::setGroupIds(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPtr contact = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contact->setGroupIds(converter->toStringArray(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 JSContact::convertToString(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       ContactPtr contact(NULL);
+
+       Try     {
+               contact = getPrivData(thisObject);
+               if (contact == NULL) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+//     AceSecurityStatus status = CONTACT_CHECK_ACCESS(
+//     CONTACT_FUNCTION_API_CONVERT_TO_STRING);
+//     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               if (argumentCount >= 1 &&
+                               ( !JSValueIsUndefined(context, arguments[0] ) &&
+                               ( !JSValueIsNull(context, arguments[0]) ) &&
+                               ( !JSValueIsString(context, arguments[0] )) ))
+                       ThrowMsg(ConversionException, "1st argument must be 'ContactTextFormat string'");
+       } Catch (Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
+       }
+
+       std::string format;
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               if(argumentCount >= 1)
+                       format = converter->toString(arguments[0]);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
+       }
+
+       std::string vCard;
+       Try {
+               vCard = contact->convertToString(format);
+       } Catch(ConversionException) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactTextFormat string'");
+       } Catch(UnsupportedException) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Only support vCard 3.0");
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       JSValueRef result;
+       Try {
+               result = converter->toJSValueRef(vCard);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       return result;
+}
+
+JSValueRef JSContact::clone(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       ContactPtr contact(NULL);
+
+       Try     {
+               contact = getPrivData(thisObject);
+               if (contact == NULL) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+//     AceSecurityStatus status = CONTACT_CHECK_ACCESS(
+//     CONTACT_FUNCTION_API_CONVERT_TO_STRING);
+//     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       ContactPtr clonedContact(NULL);
+       Try {
+               clonedContact = contact->clone();
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       JSValueRef result;
+       Try {
+               result = createJSObject(context, clonedContact);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       return result;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContact.h b/src/standards/Tizen/Contact/JSContact.h
new file mode 100755 (executable)
index 0000000..95c94a5
--- /dev/null
@@ -0,0 +1,271 @@
+//
+// 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        JSContact.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSContact class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_H_
+#define _TIZEN_CONTACT_JS_CONTACT_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/IContact.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::ContactPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSContactPriv;
+
+class JSContact {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactPtr getContact(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, TizenApis::Api::Contact::ContactPtr contact);
+
+       static TizenApis::Api::Contact::ContactPtr 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 getId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getAddressBookId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getPersonId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getLastUpdated(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getIsFavorite(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getAddresses(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setAddresses(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getPhotoURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setPhotoURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getPhoneNumbers(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setPhoneNumbers(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getEmails(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setEmails(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getBirthday(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setBirthday(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getAnniversaries(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setAnniversaries(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getOrganizations(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setOrganizations(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getNotes(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setNotes(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getUrls(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setUrls(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getRingtoneURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setRingtoneURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getGroupIds(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setGroupIds(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef convertToString(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef clone(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_H_
diff --git a/src/standards/Tizen/Contact/JSContactAddress.cpp b/src/standards/Tizen/Contact/JSContactAddress.cpp
new file mode 100755 (executable)
index 0000000..1815c90
--- /dev/null
@@ -0,0 +1,626 @@
+//
+// 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        JSContactAddress.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSContactAddress class
+ */
+
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Validator.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactAddress.h"
+#include "JSContactAddressTypeArray.h"
+
+#define CONTACT_CLASS_NAME "ContactAddress"
+
+#define CONTACT_ATTR_COUNTRY "country"
+#define CONTACT_ATTR_REGION "region"
+#define CONTACT_ATTR_CITY "city"
+#define CONTACT_ATTR_STREET_ADDRESS "streetAddress"
+#define CONTACT_ATTR_ADDITIONAL_INFORMATION "additionalInformation"
+#define CONTACT_ATTR_POSTAL_CODE "postalCode"
+#define CONTACT_ATTR_IS_DEFAULT "isDefault"
+#define CONTACT_ATTR_TYPES "types"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactAddress::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       CONTACT_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 JSContactAddress::m_property[] = {
+       { CONTACT_ATTR_COUNTRY, getCountry, setCountry, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_REGION, getRegion, setRegion, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_CITY, getCity, setCity, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_STREET_ADDRESS, getStreetAddress, setStreetAddress, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_ADDITIONAL_INFORMATION, getAdditionalInformation, setAdditionalInformation, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_POSTAL_CODE, getPostalCode, setPostalCode, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_IS_DEFAULT, getIsDefault, setIsDefault, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_TYPES, getTypes, setTypes, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactAddress::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSContactAddress::m_classRef = JSClassCreate(&m_classInfo);
+
+JSClassRef JSContactAddress::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSContactAddress::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactAddressPtr JSContactAddress::getContactAddress(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactAddressPriv *priv = static_cast<JSContactAddressPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContactAddress::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               ContactAddressPtr address(new ContactAddress());
+               JSContactAddressPriv *priv = new JSContactAddressPriv(context, ContactAddressPtr(address));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSContactAddress::Finalize(JSObjectRef object)
+{
+       JSContactAddressPriv *priv = static_cast<JSContactAddressPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+               delete (priv);
+}
+
+JSObjectRef JSContactAddress::createJSObject(JSContextRef context, const ContactAddressPtr contactAddress)
+{
+       JSContactAddressPriv *priv = new JSContactAddressPriv(context, contactAddress);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+ContactAddressPtr JSContactAddress::getPrivData(JSObjectRef object)
+{
+       JSContactAddressPriv *priv = static_cast<JSContactAddressPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ContactAddressPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSObjectRef JSContactAddress::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       bool js1stParamIsObject = false;
+
+       JSContactAddressPriv *priv = static_cast<JSContactAddressPriv*>(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)
+               {
+                       if (JSValueIsObject(gContext, arguments[0]))
+                               js1stParamIsObject = true;
+
+                       if (!js1stParamIsObject &&
+                                       !JSValueIsNull(gContext, arguments[0]) &&
+                                       !JSValueIsUndefined(gContext, arguments[0]))
+                               ThrowMsg(InvalidArgumentException, "1st argument must be a 'ContactAddressInit object'");
+               }
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactAddressInit object'");
+               return NULL;
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
+
+       ContactAddressPtr contactEmailAddress(NULL);
+
+       Try {
+               if(js1stParamIsObject)
+                       contactEmailAddress = converter->toContactAddressFromInit(arguments[0]);
+               else
+                       contactEmailAddress = ContactAddressPtr(new ContactAddress());
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'ContactAddressInit object'");
+               return NULL;
+       }
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, contactEmailAddress);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+bool JSContactAddress::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSContactAddress::getCountry(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAddressPtr contactAddress = getPrivData(object);
+               if(!contactAddress->getCountryIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactAddress->getCountry());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAddress::setCountry(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAddressPtr contactAddress = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetCountry();
+               else
+                       contactAddress->setCountry(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 JSContactAddress::getRegion(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAddressPtr contactAddress = getPrivData(object);
+               if(!contactAddress->getRegionIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactAddress->getRegion());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAddress::setRegion(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAddressPtr contactAddress = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetRegion();
+               else
+                       contactAddress->setRegion(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 JSContactAddress::getCity(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAddressPtr contactAddress = getPrivData(object);
+               if(!contactAddress->getCityIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactAddress->getCity());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAddress::setCity(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAddressPtr contactAddress = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetCity();
+               else
+                       contactAddress->setCity(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 JSContactAddress::getStreetAddress(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAddressPtr contactAddress = getPrivData(object);
+               if(!contactAddress->getStreetAddressIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactAddress->getStreetAddress());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAddress::setStreetAddress(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAddressPtr contactAddress = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetStreetAddress();
+               else
+                       contactAddress->setStreetAddress(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 JSContactAddress::getAdditionalInformation(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAddressPtr contactAddress = getPrivData(object);
+               if(!contactAddress->getAdditionalInformationIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactAddress->getAdditionalInformation());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAddress::setAdditionalInformation(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAddressPtr contactAddress = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetAdditionalInformation();
+               else
+                       contactAddress->setAdditionalInformation(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 JSContactAddress::getPostalCode(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAddressPtr contactAddress = getPrivData(object);
+               if(!contactAddress->getPostalCodeIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactAddress->getPostalCode());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAddress::setPostalCode(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAddressPtr contactAddress = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactAddress->unsetPostalCode();
+               else
+                       contactAddress->setPostalCode(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 JSContactAddress::getIsDefault(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAddressPtr contactAddress = getPrivData(object);
+               return converter->toJSValueRef(contactAddress->getIsDefault());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAddress::setIsDefault(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAddressPtr contactAddress = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               contactAddress->setIsDefault(converter->toBool(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 JSContactAddress::getTypes(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAddressPtr contactAddress = getPrivData(object);
+
+               return converter->toJSValueRef(contactAddress->getTypes());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAddress::setTypes(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAddressPtr contactAddress = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+
+               contactAddress->setTypes(converter->toContactAddressTypeArray(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;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactAddress.h b/src/standards/Tizen/Contact/JSContactAddress.h
new file mode 100755 (executable)
index 0000000..867eff7
--- /dev/null
@@ -0,0 +1,189 @@
+//
+// 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        JSContactAddress.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSContactAddress class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_ADDRESS_H_
+#define _TIZEN_CONTACT_JS_CONTACT_ADDRESS_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/ContactAddress.h>
+#include "JSContactEmailAddressTypeArray.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::ContactAddressPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSContactAddressPriv;
+
+class JSContactAddress {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactAddressPtr getContactAddress(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, const TizenApis::Api::Contact::ContactAddressPtr contactAddress);
+
+       static TizenApis::Api::Contact::ContactAddressPtr 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 getCountry(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setCountry(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getRegion(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setRegion(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getCity(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setCity(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getStreetAddress(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setStreetAddress(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getAdditionalInformation(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setAdditionalInformation(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getPostalCode(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setPostalCode(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getIsDefault(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setIsDefault(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getTypes(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setTypes(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_ADDRESS_H_
diff --git a/src/standards/Tizen/Contact/JSContactAddressArray.cpp b/src/standards/Tizen/Contact/JSContactAddressArray.cpp
new file mode 100755 (executable)
index 0000000..223329a
--- /dev/null
@@ -0,0 +1,633 @@
+//
+// 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        JSContactAddressArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactAddressArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactAddressArray::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 JSContactAddressArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactAddressArray::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 JSContactAddressArray::m_jsClassRef = JSClassCreate(
+               JSContactAddressArray::getClassInfo());
+
+JSValueRef JSContactAddressArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressArrayPtr contactAddresses = priv->getObject();
+               if (contactAddresses) {
+                       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(contactAddresses->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSContactAddressArray::createArray(JSContextRef context,
+               const ContactAddressArrayPtr &contactAddresses)
+{
+       JSContactAddressArrayPriv *priv = new JSContactAddressArrayPriv(context, contactAddresses);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSContactAddressArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSContactAddressArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+bool JSContactAddressArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactAddressArrayPtr JSContactAddressArray::getContactAddressArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactAddressArrayPriv *priv = static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContactAddressArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSContactAddressArray::finalize(JSObjectRef object)
+{
+       JSContactAddressArrayPriv* priv =
+               static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSContactAddressArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressArrayPtr contactAddresses = priv->getObject();
+               if (index < contactAddresses->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSContactAddressArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressArrayPtr contactAddresses = priv->getObject();
+               if (index < contactAddresses->size()) {
+                       ContactAddressPtr result = contactAddresses->at(index);
+                       if (result) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAddressArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactAddressPtr contactAddress(NULL);
+               if (!JSValueIsUndefined(context, value)) {
+                       contactAddress = converter->toContactAddress(value);
+               }
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressArrayPtr contactAddresses = priv->getObject();
+               if (!contactAddresses) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (contactAddresses->size() <= index) {
+                       contactAddresses->resize(index + 1);
+               }
+               (*contactAddresses)[index] = contactAddress;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSContactAddressArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactAddressPtr contactAddress(NULL);
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressArrayPtr contactAddresses = priv->getObject();
+               if (!contactAddresses) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (contactAddresses->size() > index) {
+                       (*contactAddresses)[index] = contactAddress;
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSContactAddressArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressArrayPtr addresses = priv->getObject();
+
+               int count = addresses->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 JSContactAddressArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAddressArrayPtr contactAddresses = ContactAddressArrayPtr(new ContactAddressArray());
+               JSContactAddressArrayPriv *newPrivateObject = new JSContactAddressArrayPriv(context, contactAddresses);
+               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
+
+               //copy current contactAddresses
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressArrayPtr currentContactAddresses = priv->getObject();
+               for (size_t i = 0; i < currentContactAddresses->size(); ++i) {
+                       contactAddresses->push_back(currentContactAddresses->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::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);
+                               contactAddresses->push_back(converter->toContactAddress(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactAddressArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressArrayPtr currentContactAddresses = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentContactAddresses->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       //FIXME : to be changed to support join
+                       //result += currentContactAddresses->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 JSContactAddressArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressArrayPtr currentContactAddresses = priv->getObject();
+               if (currentContactAddresses->size() > 0) {
+                       ContactAddressPtr result = currentContactAddresses->at(
+                                       currentContactAddresses->size() - 1);
+                       currentContactAddresses->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressArrayPtr currentContactAddresses = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentContactAddresses->push_back(converter->toContactAddress(arguments[i]));
+               }
+               return converter->toJSValueRef(currentContactAddresses->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactAddressArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressArrayPtr currentContactAddresses = priv->getObject();
+               std::reverse(currentContactAddresses->begin(), currentContactAddresses->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressArrayPtr currentContactAddresses = priv->getObject();
+               if (currentContactAddresses->size() > 0) {
+                       ContactAddressPtr result = currentContactAddresses->at(0);
+                       currentContactAddresses->erase(currentContactAddresses->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAddressArrayPtr contactAddresses = ContactAddressArrayPtr(new ContactAddressArray());
+               JSContactAddressArrayPriv *newPrivateObject = new JSContactAddressArrayPriv(
+                               context,
+                               contactAddresses);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current contactAddresses
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressArrayPtr currentContactAddresses = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentContactAddresses->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentContactAddresses->size()) {
+                               last = currentContactAddresses->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       contactAddresses->push_back(currentContactAddresses->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactAddressArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAddressArrayPriv* priv =
+                       static_cast<JSContactAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressArrayPtr currentContactAddresses = priv->getObject();
+               std::sort(currentContactAddresses->begin(), currentContactAddresses->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSContactAddressArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactAddressArray.h b/src/standards/Tizen/Contact/JSContactAddressArray.h
new file mode 100755 (executable)
index 0000000..30c80e3
--- /dev/null
@@ -0,0 +1,191 @@
+//
+// 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        JSContactAddressArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_ADDRESS_ARRAY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_ADDRESS_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/ContactAddress.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::ContactAddressArrayPtr>::Type JSContactAddressArrayPriv;
+
+class JSContactAddressArray
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static JSClassRef getClassRef();
+
+    static JSObjectRef createArray(JSContextRef context,
+            const TizenApis::Api::Contact::ContactAddressArrayPtr &contactAddresses);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactAddressArrayPtr getContactAddressArray(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[];
+};
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif /* _TIZEN_CONTACT_JS_CONTACT_ADDRESS_ARRAY_H_ */
diff --git a/src/standards/Tizen/Contact/JSContactAddressTypeArray.cpp b/src/standards/Tizen/Contact/JSContactAddressTypeArray.cpp
new file mode 100755 (executable)
index 0000000..0f4e97a
--- /dev/null
@@ -0,0 +1,633 @@
+//
+// 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        JSContactAddressTypeArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactAddressTypeArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactAddressTypeArray::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 JSContactAddressTypeArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactAddressTypeArray::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 JSContactAddressTypeArray::m_jsClassRef = JSClassCreate(
+               JSContactAddressTypeArray::getClassInfo());
+
+JSValueRef JSContactAddressTypeArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressTypeArrayPtr typeArray = priv->getObject();
+               if (typeArray) {
+                       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(typeArray->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSContactAddressTypeArray::createArray(JSContextRef context,
+               const ContactAddressTypeArrayPtr &typeArray)
+{
+       JSContactAddressTypeArrayPriv *priv = new JSContactAddressTypeArrayPriv(context, typeArray);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSContactAddressTypeArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSContactAddressTypeArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+bool JSContactAddressTypeArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactAddressTypeArrayPtr JSContactAddressTypeArray::getContactAddressTypeArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactAddressTypeArrayPriv *priv = static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContactAddressTypeArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSContactAddressTypeArray::finalize(JSObjectRef object)
+{
+       JSContactAddressTypeArrayPriv* priv =
+               static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSContactAddressTypeArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressTypeArrayPtr typeArray = priv->getObject();
+               if (index < typeArray->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSContactAddressTypeArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressTypeArrayPtr typeArray = priv->getObject();
+               if (index < typeArray->size()) {
+                       std::string result = converter->toContactAddressTypeStr(typeArray->at(index));
+                       if (!result.empty()) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAddressTypeArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+   Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               std::string str;
+               if (!JSValueIsUndefined(context, value)) {
+                       str = converter->toString(value);
+               }
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressTypeArrayPtr typeArray = priv->getObject();
+               if (!typeArray) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (typeArray->size() <= index) {
+                       typeArray->resize(index + 1);
+               }
+               (*typeArray)[index] = converter->toContactAddressType(str);
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSContactAddressTypeArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressTypeArrayPtr typeArray = priv->getObject();
+               if (!typeArray) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (typeArray->size() > index) {
+                       (*typeArray)[index] = converter->toContactAddressType("");
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSContactAddressTypeArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAddressTypeArrayPtr addressTypes = priv->getObject();
+
+               int count = addressTypes->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 JSContactAddressTypeArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAddressTypeArrayPtr typeArray = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
+               JSContactAddressTypeArrayPriv *newPrivateObject = new JSContactAddressTypeArrayPriv(
+                               context,
+                               typeArray);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current typeArray
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressTypeArrayPtr currentTypes = priv->getObject();
+               for (size_t i = 0; i < currentTypes->size(); ++i) {
+                       typeArray->push_back(currentTypes->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                                               ContactConverterFactory::getConverter(context);
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       if (!JSIsArrayValue(context, arguments[i])) {
+                               Throw(WrtDeviceApis::Commons::ConversionException);
+                       }
+                       // process array of types
+                       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);
+                               typeArray->push_back(converter->toContactAddressType(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactAddressTypeArray::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);
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressTypeArrayPtr currentTypes = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentTypes->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       result += currentTypes->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 JSContactAddressTypeArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                                               ContactConverterFactory::getConverter(context);
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressTypeArrayPtr currentTypes = priv->getObject();
+               if (currentTypes->size() > 0) {
+                       std::string result = converter->toContactAddressTypeStr(currentTypes->at(currentTypes->size()-1));
+                       currentTypes->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressTypeArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                                               ContactConverterFactory::getConverter(context);
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressTypeArrayPtr currentTypes = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentTypes->push_back(converter->toContactAddressType(arguments[i]));
+               }
+               return converter->toJSValueRef(currentTypes->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactAddressTypeArray::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);
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressTypeArrayPtr currentTypes = priv->getObject();
+               std::reverse(currentTypes->begin(), currentTypes->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressTypeArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                                               ContactConverterFactory::getConverter(context);
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressTypeArrayPtr currentTypes = priv->getObject();
+               if (currentTypes->size() > 0) {
+                       std::string result = converter->toContactAddressTypeStr(currentTypes->at(0));
+                       currentTypes->erase(currentTypes->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressTypeArray::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);
+               ContactAddressTypeArrayPtr typeArray = ContactAddressTypeArrayPtr(new ContactAddressTypeArray());
+               JSContactAddressTypeArrayPriv *newPrivateObject = new JSContactAddressTypeArrayPriv(
+                               context,
+                               typeArray);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current typeArray
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressTypeArrayPtr currentTypes = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentTypes->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentTypes->size()) {
+                               last = currentTypes->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       typeArray->push_back(currentTypes->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactAddressTypeArray::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);
+               JSContactAddressTypeArrayPriv* priv =
+                       static_cast<JSContactAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAddressTypeArrayPtr currentTypes = priv->getObject();
+               std::sort(currentTypes->begin(), currentTypes->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressTypeArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressTypeArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSContactAddressTypeArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAddressTypeArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactAddressTypeArray.h b/src/standards/Tizen/Contact/JSContactAddressTypeArray.h
new file mode 100755 (executable)
index 0000000..ca06c67
--- /dev/null
@@ -0,0 +1,193 @@
+//
+// 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        JSContactAddressTypeArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_ADDRESS_TYPE_ARRAY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_ADDRESS_TYPE_ARRAY_H_
+
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/ContactAddress.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::ContactAddressTypeArrayPtr>::Type JSContactAddressTypeArrayPriv;
+
+class JSContactAddressTypeArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::ContactAddressTypeArrayPtr &Strings);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactAddressTypeArrayPtr getContactAddressTypeArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_ADDRESS_TYPE_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSContactAnniversary.cpp b/src/standards/Tizen/Contact/JSContactAnniversary.cpp
new file mode 100755 (executable)
index 0000000..121ad89
--- /dev/null
@@ -0,0 +1,329 @@
+//
+// 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        JSContactAnniversary.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSContactAnniversary class
+ */
+
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Validator.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactAnniversary.h"
+
+#define FILTER_CLASS_NAME "Anniversary"
+#define CONTACT_ATTR_DATE "date"
+#define CONTACT_ATTR_LABEL "label"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactAnniversary::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       FILTER_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 JSContactAnniversary::m_property[] = {
+       { CONTACT_ATTR_DATE, getDate, setDate, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_LABEL, getLabel, setLabel, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactAnniversary::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSContactAnniversary::m_classRef = JSClassCreate(&m_classInfo);
+
+JSClassRef JSContactAnniversary::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSContactAnniversary::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactAnniversaryPtr JSContactAnniversary::getContactAnniversary(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactAnniversaryPriv *priv = static_cast<JSContactAnniversaryPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContactAnniversary::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               ContactAnniversaryPtr anniversary(new ContactAnniversary());
+               JSContactAnniversaryPriv *priv = new JSContactAnniversaryPriv(context, ContactAnniversaryPtr(anniversary));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSContactAnniversary::Finalize(JSObjectRef object)
+{
+       JSContactAnniversaryPriv *priv = static_cast<JSContactAnniversaryPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+               delete (priv);
+}
+
+JSObjectRef JSContactAnniversary::createJSObject(JSContextRef context, ContactAnniversaryPtr contactAnniversary)
+{
+       JSContactAnniversaryPriv *priv = new JSContactAnniversaryPriv(context, contactAnniversary);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+ContactAnniversaryPtr JSContactAnniversary::getPrivData(JSObjectRef object)
+{
+       JSContactAnniversaryPriv *priv = static_cast<JSContactAnniversaryPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ContactAnniversaryPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSObjectRef JSContactAnniversary::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       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'");
+
+               if (!JSValueIsObject(gContext, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'Date object'");
+
+               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::tm date;
+       std::string label;
+
+       Try {
+               date = converter->toDateTm(arguments[0]);
+       } 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 {
+               jsobject = createJSObject(gContext, contactAnniversary);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+bool JSContactAnniversary::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSContactAnniversary::getDate(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAnniversaryPtr anniversary = getPrivData(object);
+               return converter->toJSValueRef(anniversary->getDate());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAnniversary::setDate(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAnniversaryPtr anniversary = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               anniversary->setDate(converter->toDateTm(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 JSContactAnniversary::getLabel(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAnniversaryPtr anniversary = getPrivData(object);
+               if(!anniversary->getLabelIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(anniversary->getLabel());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAnniversary::setLabel(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAnniversaryPtr anniversary = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       anniversary->unsetLabel();
+               else
+                       anniversary->setLabel(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;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactAnniversary.h b/src/standards/Tizen/Contact/JSContactAnniversary.h
new file mode 100755 (executable)
index 0000000..cfff16a
--- /dev/null
@@ -0,0 +1,122 @@
+//
+// 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        JSContactAnniversary.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSContactAnniversary class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_ANNIVERSARY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_ANNIVERSARY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/ContactAnniversary.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::ContactAnniversaryPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSContactAnniversaryPriv;
+
+class JSContactAnniversary {
+public:
+       /*
+        * This initializes this JS class in the JS Engine.
+        */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactAnniversaryPtr getContactAnniversary(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, TizenApis::Api::Contact::ContactAnniversaryPtr contactAnniversary);
+
+       static TizenApis::Api::Contact::ContactAnniversaryPtr 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 getDate(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setDate(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getLabel(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setLabel(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_ANNIVERSARY_H_
diff --git a/src/standards/Tizen/Contact/JSContactAnniversaryArray.cpp b/src/standards/Tizen/Contact/JSContactAnniversaryArray.cpp
new file mode 100755 (executable)
index 0000000..05eff4d
--- /dev/null
@@ -0,0 +1,633 @@
+//
+// 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        JSContactAnniversaryArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactAnniversaryArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactAnniversaryArray::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 JSContactAnniversaryArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactAnniversaryArray::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 JSContactAnniversaryArray::m_jsClassRef = JSClassCreate(
+               JSContactAnniversaryArray::getClassInfo());
+
+JSValueRef JSContactAnniversaryArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAnniversaryArrayPtr anniversaries = priv->getObject();
+               if (anniversaries) {
+                       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(anniversaries->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSContactAnniversaryArray::createArray(JSContextRef context,
+               const ContactAnniversaryArrayPtr &anniversaries)
+{
+       JSContactAnniversaryArrayPriv *priv = new JSContactAnniversaryArrayPriv(context, anniversaries);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSContactAnniversaryArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+bool JSContactAnniversaryArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactAnniversaryArrayPtr JSContactAnniversaryArray::getContactAnniversaryArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactAnniversaryArrayPriv *priv = static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+JSClassRef JSContactAnniversaryArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+void JSContactAnniversaryArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSContactAnniversaryArray::finalize(JSObjectRef object)
+{
+       JSContactAnniversaryArrayPriv* priv =
+               static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSContactAnniversaryArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAnniversaryArrayPtr anniversaries = priv->getObject();
+               if (index < anniversaries->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSContactAnniversaryArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAnniversaryArrayPtr anniversaries = priv->getObject();
+               if (index < anniversaries->size()) {
+                       ContactAnniversaryPtr result = anniversaries->at(index);
+                       if (result) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactAnniversaryArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactAnniversaryPtr anniversary(NULL);
+               if (!JSValueIsUndefined(context, value)) {
+                       anniversary = converter->toContactAnniversary(value);
+               }
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAnniversaryArrayPtr anniversaries = priv->getObject();
+               if (!anniversaries) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (anniversaries->size() <= index) {
+                       anniversaries->resize(index + 1);
+               }
+               (*anniversaries)[index] = anniversary;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSContactAnniversaryArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactAnniversaryPtr anniversary(NULL);
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAnniversaryArrayPtr anniversaries = priv->getObject();
+               if (!anniversaries) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (anniversaries->size() > index) {
+                       (*anniversaries)[index] = anniversary;
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSContactAnniversaryArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactAnniversaryArrayPtr anniversaries = priv->getObject();
+
+               int count = anniversaries->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 JSContactAnniversaryArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactAnniversaryArrayPtr anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
+               JSContactAnniversaryArrayPriv *newPrivateObject = new JSContactAnniversaryArrayPriv(context, anniversaries);
+               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
+
+               //copy current anniversaries
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
+               for (size_t i = 0; i < currentAnniversaries->size(); ++i) {
+                       anniversaries->push_back(currentAnniversaries->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::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);
+                               anniversaries->push_back(converter->toContactAnniversary(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactAnniversaryArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentAnniversaries->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       //FIXME : to be changed to support join
+                       //result += currentAnniversaries->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 JSContactAnniversaryArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
+               if (currentAnniversaries->size() > 0) {
+                       ContactAnniversaryPtr result = currentAnniversaries->at(
+                                       currentAnniversaries->size() - 1);
+                       currentAnniversaries->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAnniversaryArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentAnniversaries->push_back(converter->toContactAnniversary(arguments[i]));
+               }
+               return converter->toJSValueRef(currentAnniversaries->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactAnniversaryArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
+               std::reverse(currentAnniversaries->begin(), currentAnniversaries->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAnniversaryArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
+               if (currentAnniversaries->size() > 0) {
+                       ContactAnniversaryPtr result = currentAnniversaries->at(0);
+                       currentAnniversaries->erase(currentAnniversaries->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAnniversaryArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactAnniversaryArrayPtr anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray());
+               JSContactAnniversaryArrayPriv *newPrivateObject = new JSContactAnniversaryArrayPriv(
+                               context,
+                               anniversaries);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current anniversaries
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentAnniversaries->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentAnniversaries->size()) {
+                               last = currentAnniversaries->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       anniversaries->push_back(currentAnniversaries->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactAnniversaryArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactAnniversaryArrayPriv* priv =
+                       static_cast<JSContactAnniversaryArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactAnniversaryArrayPtr currentAnniversaries = priv->getObject();
+               std::sort(currentAnniversaries->begin(), currentAnniversaries->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAnniversaryArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAnniversaryArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSContactAnniversaryArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactAnniversaryArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactAnniversaryArray.h b/src/standards/Tizen/Contact/JSContactAnniversaryArray.h
new file mode 100755 (executable)
index 0000000..247193d
--- /dev/null
@@ -0,0 +1,192 @@
+//
+// 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        JSContactAnniversaryArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_ANNIVERSARY_ARRAY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_ANNIVERSARY_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/ContactAnniversary.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::ContactAnniversaryArrayPtr>::Type JSContactAnniversaryArrayPriv;
+
+class JSContactAnniversaryArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::ContactAnniversaryArrayPtr &anniversaries);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactAnniversaryArrayPtr getContactAnniversaryArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_ANNIVERSARY_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSContactArray.cpp b/src/standards/Tizen/Contact/JSContactArray.cpp
new file mode 100755 (executable)
index 0000000..ae342ce
--- /dev/null
@@ -0,0 +1,633 @@
+//
+// 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        JSContactArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactArray::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 JSContactArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactArray::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 JSContactArray::m_jsClassRef = JSClassCreate(
+               JSContactArray::getClassInfo());
+
+JSValueRef JSContactArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactArrayPtr contacts = priv->getObject();
+               if (contacts) {
+                       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(contacts->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSContactArray::createArray(JSContextRef context,
+               const ContactArrayPtr &contacts)
+{
+       JSContactArrayPriv *priv = new JSContactArrayPriv(context, contacts);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSContactArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSContactArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+bool JSContactArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactArrayPtr JSContactArray::getContactArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactArrayPriv *priv = static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContactArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSContactArray::finalize(JSObjectRef object)
+{
+       JSContactArrayPriv* priv =
+               static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSContactArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactArrayPtr contacts = priv->getObject();
+               if (index < contacts->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSContactArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactArrayPtr contacts = priv->getObject();
+               if (index < contacts->size()) {
+                       ContactPtr result = contacts->at(index);
+                       if (result) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactPtr contact(NULL);
+               if (!JSValueIsUndefined(context, value)) {
+                       contact = converter->toContact(value);
+               }
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactArrayPtr contacts = priv->getObject();
+               if (!contacts) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (contacts->size() <= index) {
+                       contacts->resize(index + 1);
+               }
+               (*contacts)[index] = contact;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSContactArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactPtr contact(NULL);
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactArrayPtr contacts = priv->getObject();
+               if (!contacts) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (contacts->size() > index) {
+                       (*contacts)[index] = contact;
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSContactArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactArrayPtr contacts = priv->getObject();
+
+               int count = contacts->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 JSContactArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactArrayPtr contacts = ContactArrayPtr(new ContactArray());
+               JSContactArrayPriv *newPrivateObject = new JSContactArrayPriv(context, contacts);
+               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
+
+               //copy current contacts
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactArrayPtr currentContacts = priv->getObject();
+               for (size_t i = 0; i < currentContacts->size(); ++i) {
+                       contacts->push_back(currentContacts->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::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);
+                               contacts->push_back(converter->toContact(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactArrayPtr currentContacts = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentContacts->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       //FIXME : to be changed to support join
+                       //result += currentContacts->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 JSContactArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactArrayPtr currentContacts = priv->getObject();
+               if (currentContacts->size() > 0) {
+                       ContactPtr result = currentContacts->at(
+                                       currentContacts->size() - 1);
+                       currentContacts->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactArrayPtr currentContacts = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentContacts->push_back(converter->toContact(arguments[i]));
+               }
+               return converter->toJSValueRef(currentContacts->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactArrayPtr currentContacts = priv->getObject();
+               std::reverse(currentContacts->begin(), currentContacts->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactArrayPtr currentContacts = priv->getObject();
+               if (currentContacts->size() > 0) {
+                       ContactPtr result = currentContacts->at(0);
+                       currentContacts->erase(currentContacts->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactArrayPtr contacts = ContactArrayPtr(new ContactArray());
+               JSContactArrayPriv *newPrivateObject = new JSContactArrayPriv(
+                               context,
+                               contacts);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current contacts
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactArrayPtr currentContacts = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentContacts->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentContacts->size()) {
+                               last = currentContacts->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       contacts->push_back(currentContacts->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactArrayPriv* priv =
+                       static_cast<JSContactArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactArrayPtr currentContacts = priv->getObject();
+               std::sort(currentContacts->begin(), currentContacts->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSContactArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactArray.h b/src/standards/Tizen/Contact/JSContactArray.h
new file mode 100755 (executable)
index 0000000..58aa5fd
--- /dev/null
@@ -0,0 +1,192 @@
+//
+// 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        JSContactArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_ARRAY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/IContact.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::ContactArrayPtr>::Type JSContactArrayPriv;
+
+class JSContactArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::ContactArrayPtr &contactAddresses);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactArrayPtr getContactArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSContactEmailAddress.cpp b/src/standards/Tizen/Contact/JSContactEmailAddress.cpp
new file mode 100755 (executable)
index 0000000..a07c0ec
--- /dev/null
@@ -0,0 +1,393 @@
+//
+// 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        JSContactEmailAddress.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSContactEmailAddress class
+ */
+
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Validator.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactEmailAddressTypeArray.h"
+#include "JSContactEmailAddress.h"
+
+#define CONTACT_CLASS_NAME "EmailAddress"
+
+#define CONTACT_ATTR_EMAIL "email"
+#define CONTACT_ATTR_TYPES "types"
+#define CONTACT_ATTR_IS_DEFAULT "isDefault"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactEmailAddress::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       CONTACT_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 JSContactEmailAddress::m_property[] = {
+       { CONTACT_ATTR_EMAIL, getEmail, setEmail, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_TYPES, getTypes, setTypes, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_IS_DEFAULT, getIsDefault, setIsDefault, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactEmailAddress::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSContactEmailAddress::m_classRef = JSClassCreate(&m_classInfo);
+
+JSClassRef JSContactEmailAddress::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSContactEmailAddress::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactEmailAddressPtr JSContactEmailAddress::getContactEmailAddress(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactEmailAddressPriv *priv = static_cast<JSContactEmailAddressPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContactEmailAddress::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               ContactEmailAddressPtr emailAddress(new ContactEmailAddress());
+               JSContactEmailAddressPriv *priv = new JSContactEmailAddressPriv(context, ContactEmailAddressPtr(emailAddress));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSContactEmailAddress::Finalize(JSObjectRef object)
+{
+       JSContactEmailAddressPriv *priv = static_cast<JSContactEmailAddressPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+               delete (priv);
+}
+
+JSObjectRef JSContactEmailAddress::createJSObject(JSContextRef context,
+               const ContactEmailAddressPtr emailAddress)
+{
+       JSContactEmailAddressPriv *priv = new JSContactEmailAddressPriv(context, emailAddress);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+ContactEmailAddressPtr JSContactEmailAddress::getPrivData(JSObjectRef object)
+{
+       JSContactEmailAddressPriv *priv = static_cast<JSContactEmailAddressPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ContactEmailAddressPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSObjectRef JSContactEmailAddress::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       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;
+
+       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 {
+               if(js2ndParamIsArray)
+                       types = converter->toContactEmailAddressTypeArray(arguments[1]);
+               else
+                       types = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
+
+       } 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));
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       ContactEmailAddressPtr contactEmailAddress(new ContactEmailAddress());
+       contactEmailAddress->setEmail(email);
+       contactEmailAddress->setTypes(types);
+       contactEmailAddress->setIsDefault(isDefault);
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, contactEmailAddress);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+bool JSContactEmailAddress::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSContactEmailAddress::getEmail(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactEmailAddressPtr emailAddress = getPrivData(object);
+               return converter->toJSValueRef(emailAddress->getEmail());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactEmailAddress::setEmail(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactEmailAddressPtr emailAddress = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               emailAddress->setEmail(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 JSContactEmailAddress::getIsDefault(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactEmailAddressPtr emailAddress = getPrivData(object);
+               return converter->toJSValueRef(emailAddress->getIsDefault());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactEmailAddress::setIsDefault(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactEmailAddressPtr emailAddress = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               emailAddress->setIsDefault(converter->toBool(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 JSContactEmailAddress::getTypes(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactEmailAddressPtr emailAddress = getPrivData(object);
+               return JSContactEmailAddressTypeArray::createArray(context, emailAddress->getTypes());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactEmailAddress::setTypes(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactEmailAddressPtr emailAddress = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+
+               if(JSContactEmailAddressTypeArray::isObjectOfClass(context, value))
+                       emailAddress->setTypes(JSContactEmailAddressTypeArray::getContactEmailAddressTypeArray(context, value));
+               else
+                       emailAddress->setTypes(converter->toContactEmailAddressTypeArray(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;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactEmailAddress.h b/src/standards/Tizen/Contact/JSContactEmailAddress.h
new file mode 100755 (executable)
index 0000000..180d4d3
--- /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.
+//
+
+/**
+ * @file        JSContactEmailAddress.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSContactEmailAddress class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_H_
+#define _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/ContactEmailAddress.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::ContactEmailAddressPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSContactEmailAddressPriv;
+
+class JSContactEmailAddress {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactEmailAddressPtr getContactEmailAddress(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, const TizenApis::Api::Contact::ContactEmailAddressPtr emailAddress);
+
+       static TizenApis::Api::Contact::ContactEmailAddressPtr 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 getEmail(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setEmail(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getIsDefault(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setIsDefault(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getTypes(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setTypes(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_H_
diff --git a/src/standards/Tizen/Contact/JSContactEmailAddressArray.cpp b/src/standards/Tizen/Contact/JSContactEmailAddressArray.cpp
new file mode 100755 (executable)
index 0000000..f3b5f34
--- /dev/null
@@ -0,0 +1,633 @@
+//
+// 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        JSContactEmailAddressArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactEmailAddressArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactEmailAddressArray::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 JSContactEmailAddressArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactEmailAddressArray::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 JSContactEmailAddressArray::m_jsClassRef = JSClassCreate(
+               JSContactEmailAddressArray::getClassInfo());
+
+JSValueRef JSContactEmailAddressArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
+               if (emailAddresses) {
+                       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(emailAddresses->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSContactEmailAddressArray::createArray(JSContextRef context,
+               const ContactEmailAddressArrayPtr &emailAddresses)
+{
+       JSContactEmailAddressArrayPriv *priv = new JSContactEmailAddressArrayPriv(context, emailAddresses);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+bool JSContactEmailAddressArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactEmailAddressArrayPtr JSContactEmailAddressArray::getContactEmailAddressArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactEmailAddressArrayPriv *priv = static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+const JSClassDefinition* JSContactEmailAddressArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSContactEmailAddressArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+void JSContactEmailAddressArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSContactEmailAddressArray::finalize(JSObjectRef object)
+{
+       JSContactEmailAddressArrayPriv* priv =
+               static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSContactEmailAddressArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
+               if (index < emailAddresses->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSContactEmailAddressArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
+               if (index < emailAddresses->size()) {
+                       ContactEmailAddressPtr result = emailAddresses->at(index);
+                       if (result) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactEmailAddressArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactEmailAddressPtr emailAddress(NULL);
+               if (!JSValueIsUndefined(context, value)) {
+                       emailAddress = converter->toContactEmailAddress(value);
+               }
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
+               if (!emailAddresses) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (emailAddresses->size() <= index) {
+                       emailAddresses->resize(index + 1);
+               }
+               (*emailAddresses)[index] = emailAddress;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSContactEmailAddressArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactEmailAddressPtr emailAddress(NULL);
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
+               if (!emailAddresses) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (emailAddresses->size() > index) {
+                       (*emailAddresses)[index] = emailAddress;
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSContactEmailAddressArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactEmailAddressArrayPtr emailAddresses = priv->getObject();
+
+               int count = emailAddresses->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 JSContactEmailAddressArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactEmailAddressArrayPtr emailAddresses = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
+               JSContactEmailAddressArrayPriv *newPrivateObject = new JSContactEmailAddressArrayPriv(context, emailAddresses);
+               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
+
+               //copy current emailAddresses
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
+               for (size_t i = 0; i < currentEmailAddresses->size(); ++i) {
+                       emailAddresses->push_back(currentEmailAddresses->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::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);
+                               emailAddresses->push_back(converter->toContactEmailAddress(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactEmailAddressArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentEmailAddresses->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       //FIXME : to be changed to support join
+                       //result += currentEmailAddresses->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 JSContactEmailAddressArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
+               if (currentEmailAddresses->size() > 0) {
+                       ContactEmailAddressPtr result = currentEmailAddresses->at(
+                                       currentEmailAddresses->size() - 1);
+                       currentEmailAddresses->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentEmailAddresses->push_back(converter->toContactEmailAddress(arguments[i]));
+               }
+               return converter->toJSValueRef(currentEmailAddresses->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactEmailAddressArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
+               std::reverse(currentEmailAddresses->begin(), currentEmailAddresses->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
+               if (currentEmailAddresses->size() > 0) {
+                       ContactEmailAddressPtr result = currentEmailAddresses->at(0);
+                       currentEmailAddresses->erase(currentEmailAddresses->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactEmailAddressArrayPtr emailAddresses = ContactEmailAddressArrayPtr(new ContactEmailAddressArray());
+               JSContactEmailAddressArrayPriv *newPrivateObject = new JSContactEmailAddressArrayPriv(
+                               context,
+                               emailAddresses);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current emailAddresses
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentEmailAddresses->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentEmailAddresses->size()) {
+                               last = currentEmailAddresses->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       emailAddresses->push_back(currentEmailAddresses->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactEmailAddressArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactEmailAddressArrayPriv* priv =
+                       static_cast<JSContactEmailAddressArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressArrayPtr currentEmailAddresses = priv->getObject();
+               std::sort(currentEmailAddresses->begin(), currentEmailAddresses->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSContactEmailAddressArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactEmailAddressArray.h b/src/standards/Tizen/Contact/JSContactEmailAddressArray.h
new file mode 100755 (executable)
index 0000000..756e82a
--- /dev/null
@@ -0,0 +1,192 @@
+//
+// 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        JSContactEmailAddressArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_ARRAY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/ContactEmailAddress.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::ContactEmailAddressArrayPtr>::Type JSContactEmailAddressArrayPriv;
+
+class JSContactEmailAddressArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::ContactEmailAddressArrayPtr &emailAddresses);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactEmailAddressArrayPtr getContactEmailAddressArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSContactEmailAddressTypeArray.cpp b/src/standards/Tizen/Contact/JSContactEmailAddressTypeArray.cpp
new file mode 100755 (executable)
index 0000000..7bc1243
--- /dev/null
@@ -0,0 +1,628 @@
+//
+// 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        JSContactEmailAddressTypeArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactEmailAddressTypeArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactEmailAddressTypeArray::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 JSContactEmailAddressTypeArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactEmailAddressTypeArray::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 JSContactEmailAddressTypeArray::m_jsClassRef = JSClassCreate(
+               JSContactEmailAddressTypeArray::getClassInfo());
+
+JSValueRef JSContactEmailAddressTypeArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(NullPointerException);
+               }
+               ContactEmailAddressTypeArrayPtr typeArray = priv->getObject();
+               if (typeArray) {
+                       BasicConverter converter = BasicConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(typeArray->size());
+               }
+       }
+       Catch(Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSContactEmailAddressTypeArray::createArray(JSContextRef context,
+               const ContactEmailAddressTypeArrayPtr &typeArray)
+{
+       JSContactEmailAddressTypeArrayPriv *priv = new JSContactEmailAddressTypeArrayPriv(context, typeArray);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+bool JSContactEmailAddressTypeArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactEmailAddressTypeArrayPtr JSContactEmailAddressTypeArray::getContactEmailAddressTypeArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(InvalidArgumentException);
+       }
+       JSContactEmailAddressTypeArrayPriv *priv = static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(NullPointerException);
+       }
+       return priv->getObject();
+}
+
+const JSClassDefinition* JSContactEmailAddressTypeArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSContactEmailAddressTypeArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+void JSContactEmailAddressTypeArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSContactEmailAddressTypeArray::finalize(JSObjectRef object)
+{
+       JSContactEmailAddressTypeArrayPriv* priv =
+               static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSContactEmailAddressTypeArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       BasicConverter converter = BasicConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(NullPointerException);
+               }
+               ContactEmailAddressTypeArrayPtr typeArray = priv->getObject();
+               if (index < typeArray->size()) {
+                       return true;
+               }
+       }
+       Catch(Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSContactEmailAddressTypeArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(NullPointerException);
+               }
+               ContactEmailAddressTypeArrayPtr typeArray = priv->getObject();
+               if (index < typeArray->size()) {
+                       std::string result = converter->toContactEmailAddressTypeStr(typeArray->at(index));
+                       if (!result.empty()) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactEmailAddressTypeArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               std::string str;
+               if (!JSValueIsUndefined(context, value)) {
+                       str = converter->toString(value);
+               }
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(NullPointerException);
+               }
+               ContactEmailAddressTypeArrayPtr typeArray = priv->getObject();
+               if (!typeArray) {
+                       Throw(NullPointerException);
+               }
+               if (typeArray->size() <= index) {
+                       typeArray->resize(index + 1);
+               }
+               (*typeArray)[index] = converter->toContactEmailAddressType(str);
+               return true;
+       }
+       Catch(Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSContactEmailAddressTypeArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactEmailAddressTypeArrayPtr typeArray = priv->getObject();
+               if (!typeArray) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (typeArray->size() > index) {
+                       (*typeArray)[index] = converter->toContactEmailAddressType("");
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSContactEmailAddressTypeArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactEmailAddressTypeArrayPtr types = priv->getObject();
+
+               int count = types->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 JSContactEmailAddressTypeArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactEmailAddressTypeArrayPtr typeArray = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
+               JSContactEmailAddressTypeArrayPriv *newPrivateObject = new JSContactEmailAddressTypeArrayPriv(
+                               context,
+                               typeArray);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current typeArray
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
+               for (size_t i = 0; i < currentStrings->size(); ++i) {
+                       typeArray->push_back(currentStrings->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                                               ContactConverterFactory::getConverter(context);
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       if (!JSIsArrayValue(context, arguments[i])) {
+                               Throw(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);
+                               typeArray->push_back(converter->toContactEmailAddressType(att));
+                       }
+               }
+               return result;
+       }
+       Catch(Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactEmailAddressTypeArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               BasicConverter converter = BasicConverterFactory::getConverter(context);
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressTypeArrayPtr 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(Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactEmailAddressTypeArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                                               ContactConverterFactory::getConverter(context);
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
+               if (currentStrings->size() > 0) {
+                       std::string result = converter->toContactEmailAddressTypeStr(currentStrings->at(currentStrings->size() - 1));
+                       currentStrings->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressTypeArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                                               ContactConverterFactory::getConverter(context);
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentStrings->push_back(converter->toContactEmailAddressType(arguments[i]));
+               }
+               return converter->toJSValueRef(currentStrings->size());
+       }
+       Catch(Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactEmailAddressTypeArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               Converter converter(context);
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
+               std::reverse(currentStrings->begin(), currentStrings->end());
+               return thisObject;
+       }
+       Catch(Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressTypeArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                                               ContactConverterFactory::getConverter(context);
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
+               if (currentStrings->size() > 0) {
+                       std::string result = converter->toContactEmailAddressTypeStr(currentStrings->at(0));
+                       currentStrings->erase(currentStrings->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressTypeArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               BasicConverter converter = BasicConverterFactory::getConverter(context);
+               ContactEmailAddressTypeArrayPtr typeArray = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray());
+               JSContactEmailAddressTypeArrayPriv *newPrivateObject = new JSContactEmailAddressTypeArrayPriv(
+                               context,
+                               typeArray);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current typeArray
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressTypeArrayPtr 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) {
+                       typeArray->push_back(currentStrings->at(i));
+               }
+
+               return result;
+       }
+       Catch(Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactEmailAddressTypeArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               BasicConverter converter = BasicConverterFactory::getConverter(context);
+               JSContactEmailAddressTypeArrayPriv* priv =
+                       static_cast<JSContactEmailAddressTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactEmailAddressTypeArrayPtr currentStrings = priv->getObject();
+               std::sort(currentStrings->begin(), currentStrings->end());
+               return thisObject;
+       }
+       Catch(Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressTypeArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressTypeArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSContactEmailAddressTypeArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactEmailAddressTypeArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactEmailAddressTypeArray.h b/src/standards/Tizen/Contact/JSContactEmailAddressTypeArray.h
new file mode 100755 (executable)
index 0000000..a1e95a5
--- /dev/null
@@ -0,0 +1,193 @@
+//
+// 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        JSContactEmailAddressTypeArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_TYPE_ARRAY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_TYPE_ARRAY_H_
+
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/ContactEmailAddress.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::ContactEmailAddressTypeArrayPtr>::Type JSContactEmailAddressTypeArrayPriv;
+
+class JSContactEmailAddressTypeArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::ContactEmailAddressTypeArrayPtr &Strings);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactEmailAddressTypeArrayPtr getContactEmailAddressTypeArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_EMAIL_ADDRESS_TYPE_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSContactGroup.cpp b/src/standards/Tizen/Contact/JSContactGroup.cpp
new file mode 100755 (executable)
index 0000000..8df3689
--- /dev/null
@@ -0,0 +1,503 @@
+//
+// 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        JSContactGroup.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSContactGroup class
+ */
+
+#include "JSContactGroup.h"
+
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Validator.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+
+#define CONTACT_CLASS_NAME                  "ContactGroup"
+#define CONTACT_PROP_ATTR_ID                "id"
+#define CONTACT_PROP_ATTR_ADDRESSBOOK_ID    "addressBookId"
+#define CONTACT_PROP_ATTR_NAME              "name"
+#define CONTACT_PROP_ATTR_RINGTONE_URI      "ringtoneURI"
+#define CONTACT_PROP_ATTR_PHOTO_URI         "photoURI"
+#define CONTACT_PROP_ATTR_READ_ONLY         "readOnly"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactGroup::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       CONTACT_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 JSContactGroup::m_property[] = {
+       { CONTACT_PROP_ATTR_ID, getId, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_PROP_ATTR_ADDRESSBOOK_ID, getAddressBookId, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_PROP_ATTR_NAME, getName, setName, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_RINGTONE_URI, getRingtoneURI, setRingtoneURI, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_PHOTO_URI, getPhotoURI, setPhotoURI, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_READ_ONLY, getReadOnly, NULL, kJSPropertyAttributeReadOnly },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactGroup::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSContactGroup::m_classRef = JSClassCreate(&m_classInfo);
+
+JSClassRef JSContactGroup::getClassRef()
+{
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSContactGroup::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactGroupPtr JSContactGroup::getContactGroup(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+
+       JSContactGroupPriv *priv = static_cast<JSContactGroupPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+
+       return priv->getObject();
+}
+
+void JSContactGroup::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               ContactGroupPtr name(new ContactGroup());
+               JSContactGroupPriv *priv = new JSContactGroupPriv(context, ContactGroupPtr(name));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSContactGroup::Finalize(JSObjectRef object)
+{
+       JSContactGroupPriv *priv = static_cast<JSContactGroupPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+               delete (priv);
+}
+
+JSObjectRef JSContactGroup::createJSObject(JSContextRef context, ContactGroupPtr contactGroup)
+{
+       JSContactGroupPriv *priv = new JSContactGroupPriv(context, contactGroup);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef)
+       {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+ContactGroupPtr JSContactGroup::getPrivData(JSObjectRef object)
+{
+       JSContactGroupPriv *priv = static_cast<JSContactGroupPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+
+       ContactGroupPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+
+       return result;
+}
+
+JSObjectRef JSContactGroup::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       JSContactGroupPriv *priv = static_cast<JSContactGroupPriv*>(JSObjectGetPrivate(constructor));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       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)));
+
+               if(argumentCount >= 2 && !validator->isNullOrUndefined(arguments[1]))
+                       contactGroup->setRingtoneURI(converter->toString(arguments[1]));
+
+               if(argumentCount >= 3 && !validator->isNullOrUndefined(arguments[2]))
+                       contactGroup->setPhotoURI(converter->toString(arguments[2]));
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return NULL;
+       }
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, contactGroup);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+bool JSContactGroup::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSContactGroup::getId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactGroupPtr contactGroup = getPrivData(object);
+               if(!contactGroup->getIdIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactGroup->getId());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactGroup::setId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactGroupPtr contactGroup = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactGroup->unsetId();
+               else
+                       contactGroup->setId(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 JSContactGroup::getAddressBookId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactGroupPtr contactGroup = getPrivData(object);
+               if(!contactGroup->getAddressBookIdIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactGroup->getAddressBookId());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactGroup::setAddressBookId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactGroupPtr contactGroup = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactGroup->unsetAddressBookId();
+               else
+                       contactGroup->setAddressBookId(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 JSContactGroup::getName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactGroupPtr contactGroup = getPrivData(object);
+               if(!contactGroup->getNameIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactGroup->getName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactGroup::setName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactGroupPtr contactGroup = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactGroup->unsetName();
+               else
+                       contactGroup->setName(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 JSContactGroup::getRingtoneURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactGroupPtr contactGroup = getPrivData(object);
+               if(!contactGroup->getRingtoneURIIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactGroup->getRingtoneURI());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactGroup::setRingtoneURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactGroupPtr contactGroup = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactGroup->unsetRingtoneURI();
+               else
+                       contactGroup->setRingtoneURI(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 JSContactGroup::getPhotoURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactGroupPtr contactGroup = getPrivData(object);
+               if(!contactGroup->getPhotoURIIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactGroup->getPhotoURI());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactGroup::setPhotoURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactGroupPtr contactGroup = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactGroup->unsetRingtoneURI();
+               else
+                       contactGroup->setPhotoURI(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 JSContactGroup::getReadOnly(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactGroupPtr contactGroup = getPrivData(object);
+
+               return converter->toJSValueRef(contactGroup->getReadOnly());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactGroup.h b/src/standards/Tizen/Contact/JSContactGroup.h
new file mode 100755 (executable)
index 0000000..7465d24
--- /dev/null
@@ -0,0 +1,161 @@
+//
+// 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        JSContactGroup.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSContactGroup class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_GROUP_H_
+#define _TIZEN_CONTACT_JS_CONTACT_GROUP_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/ContactGroup.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::ContactGroupPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSContactGroupPriv;
+
+class JSContactGroup {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactGroupPtr getContactGroup(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, TizenApis::Api::Contact::ContactGroupPtr contactName);
+
+       static TizenApis::Api::Contact::ContactGroupPtr 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 getId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getAddressBookId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setAddressBookId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getRingtoneURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setRingtoneURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getPhotoURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setPhotoURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getReadOnly(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_GROUP_H_
diff --git a/src/standards/Tizen/Contact/JSContactGroupArray.cpp b/src/standards/Tizen/Contact/JSContactGroupArray.cpp
new file mode 100755 (executable)
index 0000000..e54f47f
--- /dev/null
@@ -0,0 +1,633 @@
+//
+// 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        JSContactGroupArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactGroupArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactGroupArray::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 JSContactGroupArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactGroupArray::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 JSContactGroupArray::m_jsClassRef = JSClassCreate(
+               JSContactGroupArray::getClassInfo());
+
+JSValueRef JSContactGroupArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactGroupArrayPtr groups = priv->getObject();
+               if (groups) {
+                       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(groups->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSContactGroupArray::createArray(JSContextRef context,
+               const ContactGroupArrayPtr &groups)
+{
+       JSContactGroupArrayPriv *priv = new JSContactGroupArrayPriv(context, groups);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+bool JSContactGroupArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactGroupArrayPtr JSContactGroupArray::getContactGroupArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactGroupArrayPriv *priv = static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+const JSClassDefinition* JSContactGroupArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSContactGroupArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+void JSContactGroupArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSContactGroupArray::finalize(JSObjectRef object)
+{
+       JSContactGroupArrayPriv* priv =
+               static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSContactGroupArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactGroupArrayPtr groups = priv->getObject();
+               if (index < groups->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSContactGroupArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactGroupArrayPtr groups = priv->getObject();
+               if (index < groups->size()) {
+                       ContactGroupPtr result = groups->at(index);
+                       if (result) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactGroupArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactGroupPtr group(NULL);
+               if (!JSValueIsUndefined(context, value)) {
+                       group = converter->toContactGroup(value);
+               }
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactGroupArrayPtr groups = priv->getObject();
+               if (!groups) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (groups->size() <= index) {
+                       groups->resize(index + 1);
+               }
+               (*groups)[index] = group;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSContactGroupArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactGroupPtr group(NULL);
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactGroupArrayPtr groups = priv->getObject();
+               if (!groups) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (groups->size() > index) {
+                       (*groups)[index] = group;
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSContactGroupArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactGroupArrayPtr groups = priv->getObject();
+
+               int count = groups->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 JSContactGroupArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactGroupArrayPtr groups = ContactGroupArrayPtr(new ContactGroupArray());
+               JSContactGroupArrayPriv *newPrivateObject = new JSContactGroupArrayPriv(context, groups);
+               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
+
+               //copy current groups
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactGroupArrayPtr currentGroups = priv->getObject();
+               for (size_t i = 0; i < currentGroups->size(); ++i) {
+                       groups->push_back(currentGroups->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::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);
+                               groups->push_back(converter->toContactGroup(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactGroupArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactGroupArrayPtr currentGroups = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentGroups->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       //FIXME : to be changed to support join
+                       //result += currentGroups->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 JSContactGroupArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactGroupArrayPtr currentGroups = priv->getObject();
+               if (currentGroups->size() > 0) {
+                       ContactGroupPtr result = currentGroups->at(
+                                       currentGroups->size() - 1);
+                       currentGroups->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactGroupArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactGroupArrayPtr currentGroups = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentGroups->push_back(converter->toContactGroup(arguments[i]));
+               }
+               return converter->toJSValueRef(currentGroups->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactGroupArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactGroupArrayPtr currentGroups = priv->getObject();
+               std::reverse(currentGroups->begin(), currentGroups->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactGroupArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactGroupArrayPtr currentGroups = priv->getObject();
+               if (currentGroups->size() > 0) {
+                       ContactGroupPtr result = currentGroups->at(0);
+                       currentGroups->erase(currentGroups->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactGroupArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactGroupArrayPtr groups = ContactGroupArrayPtr(new ContactGroupArray());
+               JSContactGroupArrayPriv *newPrivateObject = new JSContactGroupArrayPriv(
+                               context,
+                               groups);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current groups
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactGroupArrayPtr currentGroups = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentGroups->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentGroups->size()) {
+                               last = currentGroups->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       groups->push_back(currentGroups->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactGroupArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactGroupArrayPriv* priv =
+                       static_cast<JSContactGroupArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactGroupArrayPtr currentGroups = priv->getObject();
+               std::sort(currentGroups->begin(), currentGroups->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactGroupArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactGroupArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSContactGroupArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactGroupArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactGroupArray.h b/src/standards/Tizen/Contact/JSContactGroupArray.h
new file mode 100755 (executable)
index 0000000..49b814f
--- /dev/null
@@ -0,0 +1,192 @@
+//
+// 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        JSContactGroupArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_GROUP_ARRAY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_GROUP_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/ContactGroup.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::ContactGroupArrayPtr>::Type JSContactGroupArrayPriv;
+
+class JSContactGroupArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::ContactGroupArrayPtr &groups);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactGroupArrayPtr getContactGroupArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_GROUP_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSContactManager.cpp b/src/standards/Tizen/Contact/JSContactManager.cpp
new file mode 100755 (executable)
index 0000000..d0b1cf6
--- /dev/null
@@ -0,0 +1,1199 @@
+//
+// 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        JSContactManager.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.3
+ * @brief
+ */
+
+#include "JSContactManager.h"
+
+#include <string>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSPendingOperation.h>
+#include <API/Contact/ContactFactory.h>
+#include <API/Contact/ContactTypes.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Tizen/Tizen/FilterConverter.h>
+#include "plugin_config.h"
+#include "ContactManagerController.h"
+#include "ContactAsyncCallbackManager.h"
+#include "ContactListenerManager.h"
+#include "ContactConverter.h"
+#include "JSPerson.h"
+#include "JSContactManagerChangeCallbackManager.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Commons;
+using namespace TizenApis::Tizen1_0::Tizen;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactManager::m_classInfo = {
+       0,
+       kJSClassAttributeNone,
+       "ContactManager",
+       0,
+       m_property,
+       m_function,
+       Initialize,
+       Finalize,
+       NULL, //HasProperty,
+       NULL, //GetProperty,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //GetPropertyNames,
+       NULL, //CallAsFunction,
+       NULL, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL, //ConvertToType,
+};
+
+const JSClassDefinition* JSContactManager::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+JSStaticValue JSContactManager::m_property[] = {
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactManager::m_function[] = {
+       { "getAddressBooks", getAddressBooks, kJSPropertyAttributeNone },
+       { "getDefaultAddressBook", getDefaultAddressBook, kJSPropertyAttributeNone },
+       { "getAddressBook", getAddressBook, kJSPropertyAttributeNone },
+       { "get", get, kJSPropertyAttributeNone },
+       { "update", update, kJSPropertyAttributeNone },
+       { "updateBatch", updateBatch, kJSPropertyAttributeNone },
+       { "remove", remove, kJSPropertyAttributeNone },
+       { "removeBatch", removeBatch, kJSPropertyAttributeNone },
+       { "find", find, kJSPropertyAttributeNone },
+       { "addChangeListener", addChangeListener, kJSPropertyAttributeNone },
+       { "removeChangeListener", removeChangeListener, kJSPropertyAttributeNone },
+       { 0, 0, 0 }
+};
+
+JSClassRef JSContactManager::getClassRef()
+{
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+JSClassRef JSContactManager::m_classRef = JSClassCreate(JSContactManager::getClassInfo());
+
+void JSContactManager::Initialize(JSContextRef context,
+               JSObjectRef object)
+{
+       LogDebug("Entered");
+       ContactManagerPtr contactManager = ContactFactory::getInstance().createContactManager();
+
+       ContactManagerController *priv = new ContactManagerController(context, contactManager);
+
+       JSObjectSetPrivate(object, static_cast<void*>(priv));
+}
+
+void JSContactManager::Finalize(JSObjectRef object)
+{
+       LogDebug("entered");
+       ContactManagerController *priv = static_cast<ContactManagerController*>(JSObjectGetPrivate(object));
+       LogInfo("Delete address book manager");
+       delete priv;
+}
+
+JSValueRef JSContactManager::getAddressBooks(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("Entered");
+       ContactManagerPtr contactManager;
+       JSContextRef gContext;
+       ContactManagerController *controller;
+
+       bool js2ndParamIsFunction = false;
+
+       Try     {
+               controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               contactManager = controller->getObject();
+               gContext = controller->getContext();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_ADDRESS_BOOKS);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'function'");
+
+               if (!validator->isCallback(arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'function'");
+
+               if (argumentCount >= 2)
+               {
+                       if (validator->isCallback(arguments[1]))
+                               js2ndParamIsFunction = true;
+
+                       if (!js2ndParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[1]) &&
+                                       !JSValueIsUndefined(context, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "2st argument must be a 'function' or a 'null");
+               }
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
+
+       callbackManager->setOnSuccess(arguments[0]);
+
+       if(js2ndParamIsFunction)
+               callbackManager->setOnError(arguments[1]);
+
+       callbackManager->setObject(thisObject);
+
+       EventContactManagerGetAddressBooksPtr dplEvent(new EventContactManagerGetAddressBooks());
+
+       // set event handler's data
+       dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+       dplEvent->setForAsynchronousCall(controller);
+
+//     DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
+//     IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
+
+       Try {
+               contactManager->getAddressBooks(dplEvent);
+               ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+//     return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactManager::getDefaultAddressBook(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("Entered");
+       ContactManagerController *priv =
+               static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
+       if (!priv) {
+               LogError("private object is null");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_DEFAULT_ADDRESS_BOOK);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       ContactManagerPtr contactManager;
+       JSContextRef gContext;
+       Try {
+               contactManager = priv->getObject();
+               gContext = priv->getContext();
+       } Catch(Exception) {
+               LogError("contact manager or context is null");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
+
+       EventContactManagerGetDefaultAddressBookPtr dplEvent(new EventContactManagerGetDefaultAddressBook());
+
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               contactManager->getDefaultAddressBook(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult() || !dplEvent->getDefaultAddressBookIsSet())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       LogError("Not Found error");
+                       oss << "No default address book";
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       AddressBookPtr defaultAddressBook = dplEvent->getDefaultAddressBook();
+
+       JSValueRef resultValue;
+       Try {
+               resultValue = converter->toJSValueRef(defaultAddressBook);
+       } Catch(Exception){
+               LogError("Conversion error.");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       return resultValue;
+}
+
+JSValueRef JSContactManager::getAddressBook(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("Entered");
+       ContactManagerController *priv =
+               static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
+       if (!priv) {
+               LogError("private object is null");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_ADDRESS_BOOK);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       ContactManagerPtr contactManager;
+       JSContextRef gContext;
+       Try {
+               contactManager = priv->getObject();
+               gContext = priv->getContext();
+       } Catch(Exception) {
+               LogError("contact manager or context is null");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       if (argumentCount < 1) {
+               /* 1st Argument must be string. */
+               LogError("1st argument must not be undefined.");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "No AddressBook name 'undefined'");
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
+
+       std::string addressBookId;
+       Try {
+               addressBookId = converter->toString(arguments[0]);
+       }
+       Catch(Exception) {
+               LogError("Error on conversion " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+       }
+
+       EventContactManagerGetAddressBookPtr dplEvent(new EventContactManagerGetAddressBook());
+
+       dplEvent->setAddressBookId(addressBookId);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               contactManager->getAddressBook(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult() || !dplEvent->getAddressBookIsSet())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       LogError("Not Found error : " << addressBookId);
+                       oss << "No Contact id '" << addressBookId << "'";
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       AddressBookPtr addressBook = dplEvent->getAddressBook();
+
+       JSValueRef resultValue;
+       Try {
+               resultValue = converter->toJSValueRef(addressBook);
+       } Catch(Exception){
+               LogError("Conversion error.");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       return resultValue;
+}
+
+JSValueRef JSContactManager::get(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       ContactManagerPtr addressBook;
+       ContactManagerController *controller;
+
+       Try     {
+               controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_GET);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       if (argumentCount < 1) {
+               /* 1st Argument must be string. */
+               LogError("1st argument must not be undefined.");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "No Contact id 'undefined'");
+       }
+
+       std::string id;
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               id = converter->toString(arguments[0]);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+       }
+
+       EventContactManagerGetPtr dplEvent(new EventContactManagerGet());
+
+       dplEvent->setId(id);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->get(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult() || !dplEvent->getPersonIsSet())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       LogError("Not Found error : " << id);
+                       oss << "No Person id '" << id << "'";
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       PersonPtr person = dplEvent->getPerson();
+
+       JSValueRef result;
+       Try {
+               result = converter->toJSValueRef(person);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       return result;
+}
+
+JSValueRef JSContactManager::update(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       ContactManagerPtr addressBook;
+       ContactManagerController *controller;
+
+       Try     {
+               controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_UPDATE);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument is an 'undefined'.");
+
+               if (!JSPerson::isObjectOfClass(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument is not a 'Contact object'.");
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'Contact object'");
+       }
+
+       PersonPtr person(NULL);
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               person = converter->toPerson(arguments[0]);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument is not a 'Contact object'");
+       }
+
+       EventContactManagerUpdatePtr dplEvent(new EventContactManagerUpdate());
+
+       dplEvent->setPerson(person);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->update(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       oss << "No Contact id '" << person->getId() << "'";
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactManager::updateBatch(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       ContactManagerPtr addressBook;
+       JSContextRef gContext;
+       ContactManagerController *controller;
+
+       bool js2ndParamIsFunction = false;
+       bool js3rdParamIsFunction = false;
+
+       Try     {
+               controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       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");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_UPDATE_BATCH);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               // check 1st argument
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument must be an array of 'Contact object'");
+
+               if (!JSValueIsObject(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be an array of 'Contact object'");
+
+               // check 2nd argument
+               if(argumentCount >= 2)
+               {
+                       if(validator->isCallback(arguments[1]))
+                               js2ndParamIsFunction = true;
+
+                       if (!js2ndParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[1]) &&
+                                       !JSValueIsUndefined(context, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "2nd argument must be a 'function' or a 'null'");
+               }
+
+               // check 3rd argument
+               if(argumentCount >= 3)
+               {
+                       if(validator->isCallback(arguments[2]))
+                               js3rdParamIsFunction = true;
+
+                       if (!js3rdParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[2]) &&
+                                       !JSValueIsUndefined(context, arguments[2]))
+                               ThrowMsg(InvalidArgumentException, "3rd argument must be a 'function' or a 'null'");
+               }
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
+
+       if(js2ndParamIsFunction)
+               callbackManager->setOnSuccess(arguments[1]);
+
+       if(js3rdParamIsFunction)
+               callbackManager->setOnError(arguments[2]);
+
+       callbackManager->setObject(thisObject);
+
+       EventContactManagerUpdateBatchPtr dplEvent(new EventContactManagerUpdateBatch());
+       Try {
+               dplEvent->setPersons(converter->toPersonArray(arguments[0]));
+       } Catch(ConversionException) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "3rd argument must be a 'function' or a 'null'");
+       }
+
+       // set event handler's data
+       dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+       dplEvent->setForAsynchronousCall(controller);
+
+//     DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
+//     IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
+
+       Try {
+               addressBook->updateBatch(dplEvent);
+               ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+//     return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactManager::remove(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       ContactManagerPtr addressBook;
+       ContactManagerController *controller;
+
+       Try     {
+               controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+               }
+               addressBook = controller->getObject();
+       } Catch(Exception) {
+               LogError("No private object");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       if (argumentCount < 1) {
+               /* 1st Argument must be string. */
+               LogError("1st argument must not be undefined.");
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::NOT_FOUND_ERROR, "No Contact id 'undefined'");
+       }
+
+       std::string personId;
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try     {
+               personId = converter->toString(arguments[0]);
+       }
+       Catch(Exception) {
+               LogError("Error on conversion " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments.");
+       }
+
+       EventContactManagerRemovePtr dplEvent(new EventContactManagerRemove());
+
+       dplEvent->setPersonId(personId);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->remove(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+               case ExceptionCodes::InvalidArgumentException:
+                       LogError("Not Found error : " << personId);
+                       oss << "No Contact id '" << personId << "'";
+                       return JSTizenExceptionFactory::postException(context, exception,
+                                       JSTizenException::NOT_FOUND_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactManager::removeBatch(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       ContactManagerPtr addressBook;
+       JSContextRef gContext;
+       ContactManagerController *controller;
+
+       bool js2ndParamIsFunction = false;
+       bool js3rdParamIsFunction = false;
+
+       Try     {
+               controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       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");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE_BATCH);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               // check 1st argument
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument must be an array of 'Contact id'");
+
+               if (!JSValueIsObject(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be an array of 'Contact id'");
+
+               // check 2nd argument
+               if(argumentCount >= 2)
+               {
+                       if(validator->isCallback(arguments[1]))
+                               js2ndParamIsFunction = true;
+
+                       if (!js2ndParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[1]) &&
+                                       !JSValueIsUndefined(context, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "2nd argument must be a 'function' or a 'null'");
+               }
+
+               // check 3rd argument
+               if(argumentCount >= 3)
+               {
+                       if(validator->isCallback(arguments[2]))
+                               js3rdParamIsFunction = true;
+
+                       if (!js3rdParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[2]) &&
+                                       !JSValueIsUndefined(context, arguments[2]))
+                               ThrowMsg(InvalidArgumentException, "3rd argument must be a 'function' or a 'null'");
+               }
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
+
+       if(js2ndParamIsFunction)
+               callbackManager->setOnSuccess(arguments[1]);
+
+       if(js3rdParamIsFunction)
+               callbackManager->setOnError(arguments[2]);
+
+       callbackManager->setObject(thisObject);
+
+       EventContactManagerRemoveBatchPtr dplEvent(new EventContactManagerRemoveBatch());
+       Try {
+               dplEvent->setPersonIds(converter->toStringArray(arguments[0]));
+       } Catch(ConversionException) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "3rd argument must be an array of 'Contact id'");
+       }
+
+       // set event handler's data
+       dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+       dplEvent->setForAsynchronousCall(controller);
+
+//     DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
+//     IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
+
+       Try {
+               addressBook->removeBatch(dplEvent);
+               ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+//     return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactManager::find(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       ContactManagerPtr addressBook;
+       JSContextRef gContext;
+       ContactManagerController *controller;
+
+       bool js2ndParamIsFunction = false;
+       bool js3rdParamIsObject = false;
+       bool js4thParamIsObject = false;
+
+       Try     {
+               controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       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");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_FIND);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'function'");
+
+               if (!validator->isCallback(arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'function'");
+
+               if (argumentCount >= 2)
+               {
+                       if(validator->isCallback(arguments[1]))
+                               js2ndParamIsFunction = true;
+
+                       if (!js2ndParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[1]) &&
+                                       !JSValueIsUndefined(context, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "1st argument must be a 'function' or a 'null'");
+               }
+
+               if (argumentCount >= 3)
+               {
+                       if(JSValueIsObject(context, arguments[2]))
+                               js3rdParamIsObject = true;
+
+                       if (!js3rdParamIsObject &&
+                                       !JSValueIsNull(context, arguments[2]) &&
+                                       !JSValueIsUndefined(context, arguments[2]))
+                               ThrowMsg(InvalidArgumentException, "3rd argument must be an 'Filter object' or 'null'");
+               }
+
+               if (argumentCount >= 4)
+               {
+                       if(JSValueIsObject(context, arguments[3]))
+                               js4thParamIsObject = true;
+
+                       if (!js4thParamIsObject &&
+                                       !JSValueIsNull(context, arguments[3]) &&
+                                       !JSValueIsUndefined(context, arguments[3]))
+                               ThrowMsg(InvalidArgumentException, "4th argument must be an 'SortMode object' or 'null'");
+               }
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext);
+
+       callbackManager->setOnSuccess(arguments[0]);
+
+       if (js2ndParamIsFunction)
+               callbackManager->setOnError(arguments[1]);
+
+       callbackManager->setObject(thisObject);
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+       EventContactManagerFindPtr dplEvent(new EventContactManagerFind());
+       Try {
+               if (js3rdParamIsObject)
+                       dplEvent->setFilter(filterConverter->toFilter(arguments[2]));
+       } Catch(Exception) {
+               LogError("Error on 3rd parameter conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "3rd argument must be an 'Filter object' or 'null'");
+       }
+
+       Try {
+               if (js4thParamIsObject)
+                       dplEvent->setSortMode(filterConverter->toSortMode(arguments[3]));
+       } Catch(Exception) {
+               LogError("Error on 4th parameter conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "4th argument must be an 'SortMode object' or 'null'");
+       }
+
+       // set event handler's data
+       dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+       dplEvent->setForAsynchronousCall(controller);
+
+//     DPL::SharedPtr<IEventController> eventContr = DPL::StaticPointerCast< IEventController>(dplEvent);
+//     IJSPendingOperationPrivateObject *gcPendingOperation = new IJSPendingOperationPrivateObject(eventContr);
+
+       Try {
+               addressBook->find(dplEvent);
+               ContactAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, gContext);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+//     return JSObjectMake(gContext, JSPendingOperation::getClassRef(), gcPendingOperation);
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactManager::addChangeListener(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       ContactManagerPtr addressBook;
+       JSContextRef gContext;
+       ContactManagerController *controller;
+
+       bool js2ndParamIsFunction = false;
+
+       Try     {
+               controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       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");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_ADD_CHANGE_LISTENER);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'ContactManagerChangeCallback object'");
+
+               if (!JSValueIsObject(context, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be a 'ContactManagerChangeCallback object'");
+
+               if (argumentCount >= 2)
+               {
+                       if(validator->isCallback(arguments[1]))
+                               js2ndParamIsFunction = true;
+
+                       if (!js2ndParamIsFunction &&
+                                       !JSValueIsNull(context, arguments[1]) &&
+                                       !JSValueIsUndefined(context, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "2nd argument must be a 'function' or a 'null'");
+               }
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+
+       JSValueRef onpersonsadded;
+       JSValueRef onpersonsupdated;
+       JSValueRef onpersonsdeleted;
+       Try {
+               JSObjectRef callbackObject = converter->toJSObjectRef(arguments[0]);
+
+               onpersonsadded = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "onpersonsadded");
+               if (validator->isNullOrUndefined(onpersonsadded))
+                       onpersonsadded = NULL;
+               else if (!validator->isCallback(onpersonsadded)) {
+                       ThrowMsg(ConversionException, "2nd argument's onpersonsadded attribute is not a 'function'");
+               }
+
+               onpersonsupdated = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "onpersonsupdated");
+               if (validator->isNullOrUndefined(onpersonsupdated))
+                       onpersonsupdated = NULL;
+               else if (!validator->isCallback(onpersonsupdated)) {
+                       ThrowMsg(ConversionException, "2nd argument's onpersonsupdated attribute is not a 'function'");
+               }
+
+               onpersonsdeleted = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "onpersonsremoved");
+               if (validator->isNullOrUndefined(onpersonsdeleted))
+                       onpersonsdeleted = NULL;
+               else if (!validator->isCallback(onpersonsdeleted)) {
+                       ThrowMsg(ConversionException, "2nd argument's onpersonsremoved attribute is not a 'function'");
+               }
+
+               if (onpersonsadded == NULL && onpersonsupdated == NULL && onpersonsdeleted == NULL)
+                       ThrowMsg(ConversionException, "2nd argument must have at least one function");
+
+       } Catch(ConversionException) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+
+       JSContactManagerChangeCallbackManagerPtr callbackManager = JSContactManagerChangeCallbackManager::createObject(gContext);
+
+       callbackManager->setOnPersonsAdded(onpersonsadded);
+       callbackManager->setOnPersonsUpdated(onpersonsupdated);
+       callbackManager->setOnPersonsDeleted(onpersonsdeleted);
+       if(js2ndParamIsFunction)
+               callbackManager->setOnError(arguments[1]);
+
+       EventContactManagerChangeListenerEmitterPtr emitter(new EventContactManagerChangeListenerEmitter());
+
+       emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+       emitter->setListener(controller);
+
+       EventContactManagerAddChangeListenerPtr dplEvent(new EventContactManagerAddChangeListener());
+
+       dplEvent->setEmitter(emitter);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->addChangeListener(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult() || !dplEvent->getIdIsSet())
+       {
+               switch (dplEvent->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;
+               }
+       }
+
+       long watchId = dplEvent->getId();
+
+       PersonsChangeListenerCancellerPtr canceller = PersonsChangeListenerCancellerPtr(new PersonsChangeListenerCanceller(gContext, thisObject, watchId));
+       TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+       ContactListenerManagerSingleton::Instance().registerListener(listenerItem, gContext);
+
+       JSValueRef result;
+       Try {
+               result = converter->toJSValueRefLong(watchId);
+       } Catch(Exception) {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       return result;
+}
+
+JSValueRef JSContactManager::removeChangeListener(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       ContactManagerPtr addressBook;
+       JSContextRef gContext;
+       ContactManagerController *controller;
+
+       Try     {
+               controller = static_cast<ContactManagerController*>(JSObjectGetPrivate(thisObject));
+               if (!controller) {
+                       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");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE_CHANGE_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'");
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+
+       long watchId = 0;
+       Try {
+               watchId = static_cast<long>(converter->toLong(arguments[0]));
+
+               if (watchId < 0)
+                       ThrowMsg(PlatformException, "watchId is wrong (" << watchId << ")");
+       } Catch(Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       EventContactManagerRemoveChangeListenerPtr dplEvent(new EventContactManagerRemoveChangeListener());
+
+       dplEvent->setId(watchId);
+    dplEvent->setForSynchronousCall();
+
+       Try {
+               addressBook->removeChangeListener(dplEvent);
+       } Catch(Exception) {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       PersonsChangeListenerCancellerPtr canceller = PersonsChangeListenerCancellerPtr(new PersonsChangeListenerCanceller(gContext, thisObject, watchId));
+       TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+       ContactListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+
+       if (!dplEvent->getResult())
+       {
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::InvalidArgumentException:
+               case ExceptionCodes::NotFoundException:
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "Watch id not found");
+                       break;
+               default:
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               }
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactManager.h b/src/standards/Tizen/Contact/JSContactManager.h
new file mode 100755 (executable)
index 0000000..36ceaaa
--- /dev/null
@@ -0,0 +1,166 @@
+//
+// 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        JSContactManager.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_MANAGER_H_
+#define _TIZEN_CONTACT_JS_CONTACT_MANAGER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/IContactManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+class JSContactManager
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       /**
+        * This method initializes this in the JS Engine.
+        */
+       static JSClassRef getClassRef();
+
+private:
+       /**
+        * The callback invoked when an object is first created.
+        */
+       static void Initialize(JSContextRef context,
+                       JSObjectRef object);
+
+       /**
+        * The callback invoked when an object is finalized.
+        */
+       static void Finalize(JSObjectRef object);
+
+       /**
+        * This structure describes a statically declared value property.
+        */
+       static JSStaticValue m_property[];
+
+       /**
+        * 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;
+
+       static JSClassRef m_classRef;
+
+       /**
+        * Get Address Books.
+        */
+       static JSValueRef getAddressBooks(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       /**
+        * Get Default Address Books.
+        */
+       static JSValueRef getDefaultAddressBook(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       /**
+        * Get Default Address Books.
+        */
+       static JSValueRef getAddressBook(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 update(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef updateBatch(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 removeBatch(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef find(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef addChangeListener(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef removeChangeListener(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif //_TIZEN_CONTACT_JS_CONTACT_MANAGER_H_
diff --git a/src/standards/Tizen/Contact/JSContactManagerChangeCallbackManager.cpp b/src/standards/Tizen/Contact/JSContactManagerChangeCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..74f8413
--- /dev/null
@@ -0,0 +1,256 @@
+//
+// 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        JSContactManagerChangeCallbackManager.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include "JSContactManagerChangeCallbackManager.h"
+#include <dpl/log/log.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+JSContactManagerChangeCallbackManagerPtr JSContactManagerChangeCallbackManager::createObject(JSContextRef context)
+{
+       return JSContactManagerChangeCallbackManagerPtr( new JSContactManagerChangeCallbackManager(context) );
+}
+
+JSContactManagerChangeCallbackManager::JSContactManagerChangeCallbackManager(JSContextRef context,
+               JSObjectRef onPersonsAdded,
+               JSObjectRef onPersonsUpdated,
+               JSObjectRef onPersonsDeleted,
+               JSObjectRef onError ) :
+               m_onPersonsAdded(NULL),
+               m_onPersonsUpdated(NULL),
+               m_onPersonsDeleted(NULL),
+               m_onError(NULL),
+               m_context(context),
+               m_object(NULL)
+{
+       setOnPersonsAdded(onPersonsAdded);
+       setOnPersonsUpdated(onPersonsUpdated);
+       setOnPersonsDeleted(onPersonsDeleted);
+    setOnError(onError);
+}
+
+JSContactManagerChangeCallbackManager::~JSContactManagerChangeCallbackManager()
+{
+       if(m_onPersonsAdded)
+       {
+               JSValueUnprotect(m_context, m_onPersonsAdded);
+       }
+
+       if(m_onPersonsUpdated)
+       {
+               JSValueUnprotect(m_context, m_onPersonsUpdated);
+       }
+
+       if(m_onPersonsDeleted)
+       {
+               JSValueUnprotect(m_context, m_onPersonsDeleted);
+       }
+
+    if(m_onError)
+    {
+        JSValueUnprotect(m_context, m_onError);
+    }
+}
+
+void JSContactManagerChangeCallbackManager::setOnPersonsAdded( JSValueRef onPersonsAdded )
+{
+       if (onPersonsAdded)
+       {
+               if (m_onPersonsAdded != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onPersonsAdded);
+               }
+
+               m_onPersonsAdded = JSValueToObject( m_context, onPersonsAdded, NULL );
+
+               if (m_onPersonsAdded != NULL)
+               {
+                       JSValueProtect(m_context, m_onPersonsAdded);
+               }
+       }
+}
+
+JSValueRef JSContactManagerChangeCallbackManager::getOnPersonsAdded() const
+{
+       return m_onPersonsAdded;
+}
+
+void JSContactManagerChangeCallbackManager::setOnPersonsUpdated( JSValueRef onPersonsUpdated )
+{
+       if (onPersonsUpdated)
+       {
+               if (m_onPersonsUpdated != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onPersonsUpdated);
+               }
+
+               m_onPersonsUpdated = JSValueToObject( m_context, onPersonsUpdated, NULL );
+
+               if (m_onPersonsUpdated != NULL)
+               {
+                       JSValueProtect(m_context, m_onPersonsUpdated);
+               }
+       }
+}
+
+JSValueRef JSContactManagerChangeCallbackManager::getOnPersonsUpdated() const
+{
+       return m_onPersonsUpdated;
+}
+
+void JSContactManagerChangeCallbackManager::setOnPersonsDeleted( JSValueRef onPersonsDeleted )
+{
+       if (onPersonsDeleted)
+       {
+               if (m_onPersonsDeleted != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onPersonsDeleted);
+               }
+
+               m_onPersonsDeleted = JSValueToObject( m_context, onPersonsDeleted, NULL );
+
+               if (m_onPersonsDeleted != NULL)
+               {
+                       JSValueProtect(m_context, m_onPersonsDeleted);
+               }
+       }
+}
+
+JSValueRef JSContactManagerChangeCallbackManager::getOnPersonsDeleted() const
+{
+       return m_onPersonsDeleted;
+}
+
+void JSContactManagerChangeCallbackManager::setOnError( JSValueRef onError )
+{
+    if (onError)
+    {
+        if (m_onError != NULL)
+        {
+            JSValueUnprotect(m_context, m_onError);
+        }
+
+        m_onError = JSValueToObject( m_context, onError, NULL );
+
+        if (m_onError != NULL)
+        {
+            JSValueProtect(m_context, m_onError);
+        }
+    }
+}
+
+JSValueRef JSContactManagerChangeCallbackManager::getOnError() const
+{
+    return m_onError;
+}
+
+void JSContactManagerChangeCallbackManager::setContext( JSContextRef context )
+{
+    m_context = context;
+}
+
+void JSContactManagerChangeCallbackManager::setObject( JSObjectRef object )
+{
+    m_object = object;
+}
+
+JSObjectRef JSContactManagerChangeCallbackManager::getObject() const
+{
+    return m_object;
+}
+
+void JSContactManagerChangeCallbackManager::callOnPersonsAdded( JSValueRef contacts )
+{
+    if ( m_onPersonsAdded == NULL )
+    {
+        //LogDebug("onpersonsadded callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { contacts };
+    makeCallback( m_context, NULL, m_onPersonsAdded, "onpersonsadded", objParam, 1 );
+}
+
+void JSContactManagerChangeCallbackManager::callOnPersonsUpdated( JSValueRef contacts )
+{
+    if ( m_onPersonsUpdated == NULL )
+    {
+        //LogDebug("onpersonsupdated callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { contacts };
+    makeCallback( m_context, NULL, m_onPersonsUpdated, "onpersonsupdated", objParam, 1 );
+}
+
+void JSContactManagerChangeCallbackManager::callOnPersonsDeleted( JSValueRef contactIds )
+{
+    if ( m_onPersonsDeleted == NULL )
+    {
+        //LogDebug("onpersonsdeleted callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { contactIds };
+    makeCallback( m_context, NULL, m_onPersonsDeleted, "onpersonsdeleted", objParam, 1 );
+}
+
+void JSContactManagerChangeCallbackManager::callOnError( JSValueRef error )
+{
+    if ( m_onError == NULL )
+    {
+        //LogDebug("Error callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { error };
+    makeCallback( m_context, NULL, m_onError, "onError", objParam, 1 );
+}
+
+void JSContactManagerChangeCallbackManager::makeCallback(JSContextRef context, JSObjectRef object, JSObjectRef callback, const char *szName, JSValueRef argv[], unsigned argc)
+{
+
+    if (callback == NULL)
+    {
+        LogError("callback is NULL");
+        return;
+    }
+
+    if (JSObjectIsFunction(context, callback))
+    {
+        if (argc == 0)
+        {
+                //LogDebug("Calling object directly, no arguments");
+                JSObjectCallAsFunction(context, callback, object, 0, NULL, NULL);
+        }
+        else
+        {
+                //LogDebug("Calling object directly, one argument");
+                JSObjectCallAsFunction(context, callback, object, argc, argv, NULL);
+        }
+        return;
+    }
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactManagerChangeCallbackManager.h b/src/standards/Tizen/Contact/JSContactManagerChangeCallbackManager.h
new file mode 100755 (executable)
index 0000000..fdd7ee2
--- /dev/null
@@ -0,0 +1,93 @@
+//
+// 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        JSContactManagerChangeCallbackManager.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_MANAGER_CHANGE_CALLBACK_MANAGER_H_
+#define _TIZEN_CONTACT_JS_CONTACT_MANAGER_CHANGE_CALLBACK_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <JavaScriptCore/JavaScript.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+class JSContactManagerChangeCallbackManager;
+typedef DPL::SharedPtr<JSContactManagerChangeCallbackManager> JSContactManagerChangeCallbackManagerPtr;
+
+class JSContactManagerChangeCallbackManager : public WrtDeviceApis::Commons::IEventPrivateData
+{
+private:
+       JSContactManagerChangeCallbackManager() {}
+       JSContactManagerChangeCallbackManager( JSContextRef context,
+                       JSObjectRef onPersonsAdded = NULL,
+                       JSObjectRef onPersonsUpdated = NULL,
+                       JSObjectRef onPersonsDeleted = NULL,
+                       JSObjectRef onError = NULL );
+
+public:
+       static JSContactManagerChangeCallbackManagerPtr createObject(JSContextRef context);
+
+       virtual ~JSContactManagerChangeCallbackManager();
+
+       void    setContext( JSContextRef context );
+       JSContextRef getContext() const { return m_context; }
+
+       void    setOnPersonsAdded( JSValueRef onPersonsAdded );
+       JSValueRef getOnPersonsAdded() const;
+       void    setOnPersonsUpdated( JSValueRef onPersonsUpdated );
+       JSValueRef getOnPersonsUpdated() const;
+       void    setOnPersonsDeleted( JSValueRef onPersonsDeleted );
+       JSValueRef getOnPersonsDeleted() const;
+       void    setOnError( JSValueRef onError );
+       JSValueRef getOnError() const;
+       void    setObject( JSObjectRef object );
+       JSObjectRef getObject() const;
+
+       void    callOnPersonsAdded( JSValueRef persons );
+       void    callOnPersonsUpdated( JSValueRef persons );
+       void    callOnPersonsDeleted( JSValueRef personIds );
+       void    callOnError( JSValueRef error );
+
+private:
+       void    makeCallback(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef callback,
+                       const char *szName,
+                       JSValueRef argv[],
+                       unsigned argc);
+
+       JSObjectRef  m_onPersonsAdded;
+       JSObjectRef  m_onPersonsUpdated;
+       JSObjectRef  m_onPersonsDeleted;
+       JSObjectRef  m_onError;
+       JSContextRef m_context;
+       JSObjectRef  m_object;
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_MANAGER_CHANGE_CALLBACK_MANAGER_H_
diff --git a/src/standards/Tizen/Contact/JSContactName.cpp b/src/standards/Tizen/Contact/JSContactName.cpp
new file mode 100755 (executable)
index 0000000..4801d77
--- /dev/null
@@ -0,0 +1,690 @@
+//
+// 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        JSContactName.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSContactName class
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Validator.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactName.h"
+
+#define CONTACT_CLASS_NAME                                             "ContactName"
+#define CONTACT_PROP_ATTR_PREFIX                               "prefix"
+#define CONTACT_PROP_ATTR_SUFFIX                               "suffix"
+#define CONTACT_PROP_ATTR_FIRST_NAME                   "firstName"
+#define CONTACT_PROP_ATTR_MIDDLE_NAME                  "middleName"
+#define CONTACT_PROP_ATTR_LAST_NAME                            "lastName"
+#define CONTACT_PROP_ATTR_NICKNAMES                            "nicknames"
+#define CONTACT_PROP_ATTR_PHONETIC_NAME                    "phoneticName"
+#define CONTACT_PROP_ATTR_PHONETIC_FIRST_NAME  "phoneticFirstName"
+#define CONTACT_PROP_ATTR_PHONETIC_LAST_NAME   "phoneticLastName"
+#define CONTACT_PROP_ATTR_DISPLAY_NAME                 "displayName"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactName::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       CONTACT_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 JSContactName::m_property[] = {
+       { CONTACT_PROP_ATTR_PREFIX, getPrefix, setPrefix, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_SUFFIX, getSuffix, setSuffix, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_FIRST_NAME, getFirstName, setFirstName, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_MIDDLE_NAME, getMiddleName, setMiddleName, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_LAST_NAME, getLastName, setLastName, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_NICKNAMES, getNicknames, setNicknames, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_PHONETIC_NAME, getPhoneticName, setPhoneticName, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_PHONETIC_FIRST_NAME, getPhoneticFirstName, setPhoneticFirstName, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_PHONETIC_LAST_NAME, getPhoneticLastName, setPhoneticLastName, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_DISPLAY_NAME, getDisplayName, NULL, kJSPropertyAttributeReadOnly },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactName::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSContactName::m_classRef = JSClassCreate(&m_classInfo);
+
+JSClassRef JSContactName::getClassRef()
+{
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSContactName::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactNamePtr JSContactName::getContactName(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+
+       JSContactNamePriv *priv = static_cast<JSContactNamePriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+
+       return priv->getObject();
+}
+
+void JSContactName::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               ContactNamePtr name(new ContactName());
+               JSContactNamePriv *priv = new JSContactNamePriv(context, ContactNamePtr(name));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSContactName::Finalize(JSObjectRef object)
+{
+       JSContactNamePriv *priv = static_cast<JSContactNamePriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+               delete (priv);
+}
+
+JSObjectRef JSContactName::createJSObject(JSContextRef context, ContactNamePtr contactName)
+{
+       JSContactNamePriv *priv = new JSContactNamePriv(context, contactName);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef)
+       {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+ContactNamePtr JSContactName::getPrivData(JSObjectRef object)
+{
+       JSContactNamePriv *priv = static_cast<JSContactNamePriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+
+       ContactNamePtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+
+       return result;
+}
+
+JSObjectRef JSContactName::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       bool js1stParamIsObject = false;
+
+       JSContactNamePriv *priv = static_cast<JSContactNamePriv*>(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)
+               {
+                       if (JSValueIsObject(gContext, arguments[0]))
+                               js1stParamIsObject = true;
+
+                       if (!js1stParamIsObject &&
+                                       !JSValueIsNull(gContext, arguments[0]) &&
+                                       !JSValueIsUndefined(gContext, arguments[0]))
+                               ThrowMsg(InvalidArgumentException, "1st argument must be 'object'");
+               }
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'object'");
+               return NULL;
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
+
+       ContactNamePtr contactName(NULL);
+       Try {
+               if(js1stParamIsObject)
+                       contactName = converter->toContactNameFromInit(arguments[0]);
+               else
+                       contactName = ContactNamePtr(new ContactName());
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return NULL;
+       }
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, contactName);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+bool JSContactName::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSContactName::getPrefix(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactNamePtr contactName = getPrivData(object);
+               if(!contactName->getPrefixIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactName->getPrefix());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactName::setPrefix(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactNamePtr contactName = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetPrefix();
+               else
+                       contactName->setPrefix(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 JSContactName::getSuffix(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactNamePtr contactName = getPrivData(object);
+               if(!contactName->getSuffixIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactName->getSuffix());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactName::setSuffix(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactNamePtr contactName = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetSuffix();
+               else
+                       contactName->setSuffix(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 JSContactName::getFirstName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactNamePtr contactName = getPrivData(object);
+               if(!contactName->getFirstNameIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactName->getFirstName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactName::setFirstName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactNamePtr contactName = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetFirstName();
+               else
+                       contactName->setFirstName(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 JSContactName::getMiddleName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactNamePtr contactName = getPrivData(object);
+               if(!contactName->getMiddleNameIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactName->getMiddleName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactName::setMiddleName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactNamePtr contactName = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetMiddleName();
+               else
+                       contactName->setMiddleName(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 JSContactName::getLastName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactNamePtr contactName = getPrivData(object);
+               if(!contactName->getLastNameIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactName->getLastName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactName::setLastName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactNamePtr contactName = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetLastName();
+               else
+                       contactName->setLastName(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 JSContactName::getNicknames(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactNamePtr contactName = getPrivData(object);
+               return converter->toJSValueRef(contactName->getNicknames());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactName::setNicknames(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactNamePtr contactName = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contactName->setNicknames(converter->toStringArray(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 JSContactName::getPhoneticName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       // NOTE: Deprecated field.
+       return JSValueMakeNull(context);
+}
+
+bool JSContactName::setPhoneticName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       // NOTE: Deprecated field.
+       return true;
+}
+
+JSValueRef JSContactName::getPhoneticFirstName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactNamePtr contactName = getPrivData(object);
+               if(!contactName->getPhoneticFirstNameIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactName->getPhoneticFirstName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactName::setPhoneticFirstName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactNamePtr contactName = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetPhoneticFirstName();
+               else
+                       contactName->setPhoneticFirstName(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 JSContactName::getPhoneticLastName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactNamePtr contactName = getPrivData(object);
+               if(!contactName->getPhoneticLastNameIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactName->getPhoneticLastName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactName::setPhoneticLastName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactNamePtr contactName = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       contactName->unsetPhoneticLastName();
+               else
+                       contactName->setPhoneticLastName(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 JSContactName::getDisplayName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactNamePtr contactName = getPrivData(object);
+               if(!contactName->getDisplayNameIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(contactName->getDisplayName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactName.h b/src/standards/Tizen/Contact/JSContactName.h
new file mode 100755 (executable)
index 0000000..8edc1ea
--- /dev/null
@@ -0,0 +1,205 @@
+//
+// 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        JSContactName.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSContactName class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_NAME_H_
+#define _TIZEN_CONTACT_JS_CONTACT_NAME_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/ContactName.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::ContactNamePtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSContactNamePriv;
+
+class JSContactName {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactNamePtr getContactName(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, TizenApis::Api::Contact::ContactNamePtr contactName);
+
+       static TizenApis::Api::Contact::ContactNamePtr 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 getPrefix(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setPrefix(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getSuffix(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setSuffix(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getFirstName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setFirstName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getMiddleName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setMiddleName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getLastName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setLastName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getNicknames(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setNicknames(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getPhoneticName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setPhoneticName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getPhoneticFirstName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setPhoneticFirstName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getPhoneticLastName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setPhoneticLastName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getDisplayName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_NAME_H_
diff --git a/src/standards/Tizen/Contact/JSContactOrganization.cpp b/src/standards/Tizen/Contact/JSContactOrganization.cpp
new file mode 100755 (executable)
index 0000000..bb9ce72
--- /dev/null
@@ -0,0 +1,499 @@
+//
+// 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        JSContactOrganization.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSContactOrganization class
+ */
+
+#include "JSContactOrganization.h"
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Validator.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+
+#define ORGANIZATION_CLASS_NAME "ContactOrganization"
+
+#define CONTACT_ATTR_NAME "name"
+#define CONTACT_ATTR_DEPARTMENT "department"
+#define CONTACT_ATTR_OFFICE "office"
+#define CONTACT_ATTR_TITLE "title"
+#define CONTACT_ATTR_ROLE "role"
+#define CONTACT_ATTR_LOGO_URI "logoURI"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactOrganization::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       ORGANIZATION_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 JSContactOrganization::m_property[] = {
+       { CONTACT_ATTR_NAME, getName, setName, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_DEPARTMENT, getDepartment, setDepartment, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_OFFICE, getOffice, setOffice, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_TITLE, getTitle, setTitle, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_ROLE, getRole, setRole, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_LOGO_URI, getLogoURI, setLogoURI, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactOrganization::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSContactOrganization::m_classRef = JSClassCreate(&m_classInfo);
+
+JSClassRef JSContactOrganization::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSContactOrganization::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactOrganizationPtr JSContactOrganization::getContactOrganization(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactOrganizationPriv *priv = static_cast<JSContactOrganizationPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContactOrganization::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               ContactOrganizationPtr organization(new ContactOrganization());
+               JSContactOrganizationPriv *priv = new JSContactOrganizationPriv(context, ContactOrganizationPtr(organization));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSContactOrganization::Finalize(JSObjectRef object)
+{
+       JSContactOrganizationPriv *priv = static_cast<JSContactOrganizationPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+               delete (priv);
+}
+
+JSObjectRef JSContactOrganization::createJSObject(JSContextRef context, ContactOrganizationPtr contactOrganization)
+{
+       JSContactOrganizationPriv *priv = new JSContactOrganizationPriv(context, contactOrganization);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+ContactOrganizationPtr JSContactOrganization::getPrivData(JSObjectRef object)
+{
+       JSContactOrganizationPriv *priv = static_cast<JSContactOrganizationPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ContactOrganizationPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSObjectRef JSContactOrganization::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       bool js1stParamIsObject = false;
+
+       JSContactOrganizationPriv *priv = static_cast<JSContactOrganizationPriv*>(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)
+               {
+                       if (JSValueIsObject(gContext, arguments[0]))
+                               js1stParamIsObject = true;
+
+                       if (!js1stParamIsObject &&
+                                       !JSValueIsNull(gContext, arguments[0]) &&
+                                       !JSValueIsUndefined(gContext, arguments[0]))
+                               ThrowMsg(InvalidArgumentException, "1st argument must be a 'object'");
+               }
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be a 'object'");
+               return NULL;
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
+
+       ContactOrganizationPtr contactOrganization(NULL);
+       Try {
+               if(js1stParamIsObject)
+                       contactOrganization = converter->toContactOrganizationFromInit(arguments[0]);
+               else
+                       contactOrganization = ContactOrganizationPtr(new ContactOrganization());
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return NULL;
+       }
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, contactOrganization);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+bool JSContactOrganization::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSContactOrganization::getName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactOrganizationPtr organization = getPrivData(object);
+               if(!organization->getNameIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(organization->getName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactOrganization::setName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactOrganizationPtr organization = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       organization->unsetName();
+               else
+                       organization->setName(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 JSContactOrganization::getDepartment(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactOrganizationPtr organization = getPrivData(object);
+               if(!organization->getDepartmentIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(organization->getDepartment());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactOrganization::setDepartment(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactOrganizationPtr organization = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       organization->unsetDepartment();
+               else
+                       organization->setDepartment(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 JSContactOrganization::getOffice(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       // NOTE: Deprecated field.
+       return JSValueMakeNull(context);
+}
+
+bool JSContactOrganization::setOffice(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       // NOTE: Deprecated field.
+       return true;
+}
+
+JSValueRef JSContactOrganization::getTitle(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactOrganizationPtr organization = getPrivData(object);
+               if(!organization->getTitleIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(organization->getTitle());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactOrganization::setTitle(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactOrganizationPtr organization = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       organization->unsetTitle();
+               else
+                       organization->setTitle(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 JSContactOrganization::getRole(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactOrganizationPtr organization = getPrivData(object);
+               if(!organization->getRoleIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(organization->getRole());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactOrganization::setRole(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactOrganizationPtr organization = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       organization->unsetRole();
+               else
+                       organization->setRole(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 JSContactOrganization::getLogoURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactOrganizationPtr organization = getPrivData(object);
+               if(!organization->getLogoURIIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(organization->getLogoURI());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactOrganization::setLogoURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               // NOTE: Currently not support this field
+//             ContactOrganizationPtr organization = getPrivData(object);
+//             ContactConverterFactory::ConverterType converter =
+//                             ContactConverterFactory::getConverter(context);
+//             BasicValidator validator =
+//                             BasicValidatorFactory::getValidator(context, exception);
+//             if(validator->isNullOrUndefined(value))
+//                     organization->unsetLogoURI();
+//             else
+//                     organization->setLogoURI(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;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactOrganization.h b/src/standards/Tizen/Contact/JSContactOrganization.h
new file mode 100755 (executable)
index 0000000..5a98595
--- /dev/null
@@ -0,0 +1,166 @@
+//
+// 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        JSContactOrganization.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSContactOrganization class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_ORGANIZATION_H_
+#define _TIZEN_CONTACT_JS_CONTACT_ORGANIZATION_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/ContactOrganization.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::ContactOrganizationPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSContactOrganizationPriv;
+
+class JSContactOrganization {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactOrganizationPtr getContactOrganization(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, TizenApis::Api::Contact::ContactOrganizationPtr contactOrganization);
+
+       static TizenApis::Api::Contact::ContactOrganizationPtr 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 getName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getDepartment(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setDepartment(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getOffice(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setOffice(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getTitle(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setTitle(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getRole(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setRole(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getLogoURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setLogoURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_ORGANIZATION_H_
diff --git a/src/standards/Tizen/Contact/JSContactOrganizationArray.cpp b/src/standards/Tizen/Contact/JSContactOrganizationArray.cpp
new file mode 100755 (executable)
index 0000000..2290022
--- /dev/null
@@ -0,0 +1,632 @@
+//
+// 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        JSContactOrganizationArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactOrganizationArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactOrganizationArray::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 JSContactOrganizationArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactOrganizationArray::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 JSContactOrganizationArray::m_jsClassRef = JSClassCreate(
+               JSContactOrganizationArray::getClassInfo());
+
+JSValueRef JSContactOrganizationArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactOrganizationArrayPtr organizations = priv->getObject();
+               if (organizations) {
+                       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(organizations->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSContactOrganizationArray::createArray(JSContextRef context,
+               const ContactOrganizationArrayPtr &organizations)
+{
+       JSContactOrganizationArrayPriv *priv = new JSContactOrganizationArrayPriv(context, organizations);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+bool JSContactOrganizationArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactOrganizationArrayPtr JSContactOrganizationArray::getContactOrganizationArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactOrganizationArrayPriv *priv = static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+const JSClassDefinition* JSContactOrganizationArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSContactOrganizationArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+void JSContactOrganizationArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSContactOrganizationArray::finalize(JSObjectRef object)
+{
+       JSContactOrganizationArrayPriv* priv =
+               static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSContactOrganizationArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactOrganizationArrayPtr organizations = priv->getObject();
+               if (index < organizations->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSContactOrganizationArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactOrganizationArrayPtr organizations = priv->getObject();
+               if (index < organizations->size()) {
+                       ContactOrganizationPtr result = organizations->at(index);
+                       if (result) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactOrganizationArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactOrganizationPtr organization(NULL);
+               if (!JSValueIsUndefined(context, value)) {
+                       organization = converter->toContactOrganization(value);
+               }
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactOrganizationArrayPtr organizations = priv->getObject();
+               if (!organizations) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (organizations->size() <= index) {
+                       organizations->resize(index + 1);
+               }
+               (*organizations)[index] = organization;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSContactOrganizationArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactOrganizationPtr organization(NULL);
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactOrganizationArrayPtr organizations = priv->getObject();
+               if (!organizations) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (organizations->size() > index) {
+                       (*organizations)[index] = organization;
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSContactOrganizationArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactOrganizationArrayPtr organizations = priv->getObject();
+
+               int count = organizations->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 JSContactOrganizationArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactOrganizationArrayPtr organizations = ContactOrganizationArrayPtr(new ContactOrganizationArray());
+               JSContactOrganizationArrayPriv *newPrivateObject = new JSContactOrganizationArrayPriv(context, organizations);
+               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
+
+               //copy current organizations
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
+               for (size_t i = 0; i < currentOrganizations->size(); ++i) {
+                       organizations->push_back(currentOrganizations->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::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);
+                               organizations->push_back(converter->toContactOrganization(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactOrganizationArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentOrganizations->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       //FIXME : to be changed to support join
+                       //result += currentOrganizations->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 JSContactOrganizationArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
+               if (currentOrganizations->size() > 0) {
+                       ContactOrganizationPtr result = currentOrganizations->at(
+                                       currentOrganizations->size() - 1);
+                       currentOrganizations->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactOrganizationArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentOrganizations->push_back(converter->toContactOrganization(arguments[i]));
+               }
+               return converter->toJSValueRef(currentOrganizations->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactOrganizationArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
+               std::reverse(currentOrganizations->begin(), currentOrganizations->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactOrganizationArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
+               if (currentOrganizations->size() > 0) {
+                       ContactOrganizationPtr result = currentOrganizations->at(0);
+                       currentOrganizations->erase(currentOrganizations->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactOrganizationArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactOrganizationArrayPtr organizations = ContactOrganizationArrayPtr(new ContactOrganizationArray());
+               JSContactOrganizationArrayPriv *newPrivateObject = new JSContactOrganizationArrayPriv(
+                               context,
+                               organizations);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current organizations
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentOrganizations->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentOrganizations->size()) {
+                               last = currentOrganizations->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       organizations->push_back(currentOrganizations->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactOrganizationArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactOrganizationArrayPriv* priv =
+                       static_cast<JSContactOrganizationArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactOrganizationArrayPtr currentOrganizations = priv->getObject();
+               std::sort(currentOrganizations->begin(), currentOrganizations->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactOrganizationArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactOrganizationArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSContactOrganizationArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactOrganizationArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactOrganizationArray.h b/src/standards/Tizen/Contact/JSContactOrganizationArray.h
new file mode 100755 (executable)
index 0000000..d062837
--- /dev/null
@@ -0,0 +1,192 @@
+//
+// 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        JSContactOrganizationArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_ORGANIZATION_ARRAY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_ORGANIZATION_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/ContactOrganization.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::ContactOrganizationArrayPtr>::Type JSContactOrganizationArrayPriv;
+
+class JSContactOrganizationArray
+{
+public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static JSClassRef getClassRef();
+
+    static JSObjectRef createArray(JSContextRef context,
+            const TizenApis::Api::Contact::ContactOrganizationArrayPtr &organizations);
+
+    static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+    static TizenApis::Api::Contact::ContactOrganizationArrayPtr getContactOrganizationArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_ORGANIZATION_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSContactPhoneNumber.cpp b/src/standards/Tizen/Contact/JSContactPhoneNumber.cpp
new file mode 100755 (executable)
index 0000000..c4193d6
--- /dev/null
@@ -0,0 +1,394 @@
+//
+// 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        JSContactPhoneNumber.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSContactPhoneNumber class
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Validator.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactPhoneNumberTypeArray.h"
+#include "JSContactPhoneNumber.h"
+
+#define FILTER_CLASS_NAME "ContactPhoneNumber"
+
+#define CONTACT_ATTR_NUMBER "number"
+#define CONTACT_ATTR_TYPES "types"
+#define CONTACT_ATTR_IS_DEFAULT "idDefault"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactPhoneNumber::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       FILTER_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 JSContactPhoneNumber::m_property[] = {
+       { CONTACT_ATTR_NUMBER, getNumber, setNumber, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_TYPES, getTypes, setTypes, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_IS_DEFAULT, getIsDefault, setIsDefault, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactPhoneNumber::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSContactPhoneNumber::m_classRef = JSClassCreate(&m_classInfo);
+
+JSClassRef JSContactPhoneNumber::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSContactPhoneNumber::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactPhoneNumberPtr JSContactPhoneNumber::getContactPhoneNumber(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactPhoneNumberPriv *priv = static_cast<JSContactPhoneNumberPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContactPhoneNumber::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               ContactPhoneNumberPtr phoneNumber(new ContactPhoneNumber());
+               JSContactPhoneNumberPriv *priv = new JSContactPhoneNumberPriv(context, ContactPhoneNumberPtr(phoneNumber));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSContactPhoneNumber::Finalize(JSObjectRef object)
+{
+       JSContactPhoneNumberPriv *priv = static_cast<JSContactPhoneNumberPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+               delete (priv);
+}
+
+JSObjectRef JSContactPhoneNumber::createJSObject(JSContextRef context, ContactPhoneNumberPtr contactPhoneNumber)
+{
+       JSContactPhoneNumberPriv *priv = new JSContactPhoneNumberPriv(context, contactPhoneNumber);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+ContactPhoneNumberPtr JSContactPhoneNumber::getPrivData(JSObjectRef object)
+{
+       JSContactPhoneNumberPriv *priv = static_cast<JSContactPhoneNumberPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ContactPhoneNumberPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSObjectRef JSContactPhoneNumber::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       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));
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Internal error");
+               return NULL;
+       }
+
+       Try {
+               if(js2ndParamIsArray)
+                       types = converter->toContactPhoneNumberTypeArray(arguments[1]);
+               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));
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       ContactPhoneNumberPtr contactPhoneNumber(new ContactPhoneNumber());
+       contactPhoneNumber->setNumber(number);
+       contactPhoneNumber->setTypes(types);
+       contactPhoneNumber->setIsDefault(isDefault);
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, contactPhoneNumber);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+bool JSContactPhoneNumber::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSContactPhoneNumber::getNumber(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPhoneNumberPtr contactPhoneNumber = getPrivData(object);
+               return converter->toJSValueRef(contactPhoneNumber->getNumber());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactPhoneNumber::setNumber(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPhoneNumberPtr contactPhoneNumber = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contactPhoneNumber->setNumber(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 JSContactPhoneNumber::getIsDefault(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPhoneNumberPtr contactPhoneNumber = getPrivData(object);
+               return converter->toJSValueRef(contactPhoneNumber->getIsDefault());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactPhoneNumber::setIsDefault(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPhoneNumberPtr contactPhoneNumber = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               contactPhoneNumber->setIsDefault(converter->toBool(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 JSContactPhoneNumber::getTypes(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPhoneNumberPtr contactPhoneNumber = getPrivData(object);
+
+               return converter->toJSValueRef(contactPhoneNumber->getTypes());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactPhoneNumber::setTypes(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPhoneNumberPtr contactPhoneNumber = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+
+               contactPhoneNumber->setTypes(converter->toContactPhoneNumberTypeArray(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;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactPhoneNumber.h b/src/standards/Tizen/Contact/JSContactPhoneNumber.h
new file mode 100755 (executable)
index 0000000..43e3ab5
--- /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.
+//
+
+/**
+ * @file        JSContactPhoneNumber.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSContactPhoneNumber class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_H_
+#define _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/ContactPhoneNumber.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::ContactPhoneNumberPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSContactPhoneNumberPriv;
+
+class JSContactPhoneNumber {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactPhoneNumberPtr getContactPhoneNumber(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, TizenApis::Api::Contact::ContactPhoneNumberPtr ontactPhoneNumber);
+
+       static TizenApis::Api::Contact::ContactPhoneNumberPtr 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 getNumber(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setNumber(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getIsDefault(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setIsDefault(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getTypes(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setTypes(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_H_
diff --git a/src/standards/Tizen/Contact/JSContactPhoneNumberArray.cpp b/src/standards/Tizen/Contact/JSContactPhoneNumberArray.cpp
new file mode 100755 (executable)
index 0000000..6dcff7c
--- /dev/null
@@ -0,0 +1,633 @@
+//
+// 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        JSContactPhoneNumberArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactPhoneNumberArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactPhoneNumberArray::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 JSContactPhoneNumberArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactPhoneNumberArray::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 JSContactPhoneNumberArray::m_jsClassRef = JSClassCreate(
+               JSContactPhoneNumberArray::getClassInfo());
+
+JSValueRef JSContactPhoneNumberArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberArrayPtr contactPhoneNumbers = priv->getObject();
+               if (contactPhoneNumbers) {
+                       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(contactPhoneNumbers->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSContactPhoneNumberArray::createArray(JSContextRef context,
+               const ContactPhoneNumberArrayPtr &contactPhoneNumbers)
+{
+       JSContactPhoneNumberArrayPriv *priv = new JSContactPhoneNumberArrayPriv(context, contactPhoneNumbers);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSContactPhoneNumberArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSContactPhoneNumberArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+bool JSContactPhoneNumberArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactPhoneNumberArrayPtr JSContactPhoneNumberArray::getContactPhoneNumberArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactPhoneNumberArrayPriv *priv = static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContactPhoneNumberArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSContactPhoneNumberArray::finalize(JSObjectRef object)
+{
+       JSContactPhoneNumberArrayPriv* priv =
+               static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSContactPhoneNumberArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberArrayPtr contactPhoneNumbers = priv->getObject();
+               if (index < contactPhoneNumbers->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSContactPhoneNumberArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberArrayPtr contactPhoneNumbers = priv->getObject();
+               if (index < contactPhoneNumbers->size()) {
+                       ContactPhoneNumberPtr result = contactPhoneNumbers->at(index);
+                       if (result) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactPhoneNumberArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactPhoneNumberPtr contactPhoneNumber(NULL);
+               if (!JSValueIsUndefined(context, value)) {
+                       contactPhoneNumber = converter->toContactPhoneNumber(value);
+               }
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberArrayPtr contactPhoneNumbers = priv->getObject();
+               if (!contactPhoneNumbers) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (contactPhoneNumbers->size() <= index) {
+                       contactPhoneNumbers->resize(index + 1);
+               }
+               (*contactPhoneNumbers)[index] = contactPhoneNumber;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSContactPhoneNumberArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactPhoneNumberPtr contactPhoneNumber(NULL);
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberArrayPtr contactPhoneNumbers = priv->getObject();
+               if (!contactPhoneNumbers) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (contactPhoneNumbers->size() > index) {
+                       (*contactPhoneNumbers)[index] = contactPhoneNumber;
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSContactPhoneNumberArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberArrayPtr phoneNumbers = priv->getObject();
+
+               int count = phoneNumbers->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 JSContactPhoneNumberArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPhoneNumberArrayPtr contactPhoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
+               JSContactPhoneNumberArrayPriv *newPrivateObject = new JSContactPhoneNumberArrayPriv(context, contactPhoneNumbers);
+               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
+
+               //copy current contactPhoneNumbers
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
+               for (size_t i = 0; i < currentContactPhoneNumbers->size(); ++i) {
+                       contactPhoneNumbers->push_back(currentContactPhoneNumbers->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::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);
+                               contactPhoneNumbers->push_back(converter->toContactPhoneNumber(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactPhoneNumberArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentContactPhoneNumbers->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       //FIXME : to be changed to support join
+                       //result += currentContactPhoneNumbers->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 JSContactPhoneNumberArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
+               if (currentContactPhoneNumbers->size() > 0) {
+                       ContactPhoneNumberPtr result = currentContactPhoneNumbers->at(
+                                       currentContactPhoneNumbers->size() - 1);
+                       currentContactPhoneNumbers->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentContactPhoneNumbers->push_back(converter->toContactPhoneNumber(arguments[i]));
+               }
+               return converter->toJSValueRef(currentContactPhoneNumbers->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactPhoneNumberArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
+               std::reverse(currentContactPhoneNumbers->begin(), currentContactPhoneNumbers->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
+               if (currentContactPhoneNumbers->size() > 0) {
+                       ContactPhoneNumberPtr result = currentContactPhoneNumbers->at(0);
+                       currentContactPhoneNumbers->erase(currentContactPhoneNumbers->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactPhoneNumberArrayPtr contactPhoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray());
+               JSContactPhoneNumberArrayPriv *newPrivateObject = new JSContactPhoneNumberArrayPriv(
+                               context,
+                               contactPhoneNumbers);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current contactPhoneNumbers
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentContactPhoneNumbers->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentContactPhoneNumbers->size()) {
+                               last = currentContactPhoneNumbers->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       contactPhoneNumbers->push_back(currentContactPhoneNumbers->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactPhoneNumberArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactPhoneNumberArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberArrayPtr currentContactPhoneNumbers = priv->getObject();
+               std::sort(currentContactPhoneNumbers->begin(), currentContactPhoneNumbers->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSContactPhoneNumberArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactPhoneNumberArray.h b/src/standards/Tizen/Contact/JSContactPhoneNumberArray.h
new file mode 100755 (executable)
index 0000000..b520468
--- /dev/null
@@ -0,0 +1,192 @@
+//
+// 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        JSContactPhoneNumberArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_ARRAY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/ContactPhoneNumber.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::ContactPhoneNumberArrayPtr>::Type JSContactPhoneNumberArrayPriv;
+
+class JSContactPhoneNumberArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::ContactPhoneNumberArrayPtr &contactPhoneNumbers);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactPhoneNumberArrayPtr getContactPhoneNumberArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSContactPhoneNumberTypeArray.cpp b/src/standards/Tizen/Contact/JSContactPhoneNumberTypeArray.cpp
new file mode 100755 (executable)
index 0000000..e97e336
--- /dev/null
@@ -0,0 +1,627 @@
+//
+// 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        JSContactPhoneNumberTypeArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactPhoneNumberTypeArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactPhoneNumberTypeArray::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 JSContactPhoneNumberTypeArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactPhoneNumberTypeArray::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 JSContactPhoneNumberTypeArray::m_jsClassRef = JSClassCreate(
+               JSContactPhoneNumberTypeArray::getClassInfo());
+
+JSValueRef JSContactPhoneNumberTypeArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
+               if (typeArray) {
+                       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(typeArray->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSContactPhoneNumberTypeArray::createArray(JSContextRef context,
+               const ContactPhoneNumberTypeArrayPtr &typeArray)
+{
+       JSContactPhoneNumberTypeArrayPriv *priv = new JSContactPhoneNumberTypeArrayPriv(context, typeArray);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSContactPhoneNumberTypeArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSContactPhoneNumberTypeArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+bool JSContactPhoneNumberTypeArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactPhoneNumberTypeArrayPtr JSContactPhoneNumberTypeArray::getContactPhoneNumberTypeArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactPhoneNumberTypeArrayPriv *priv = static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContactPhoneNumberTypeArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSContactPhoneNumberTypeArray::finalize(JSObjectRef object)
+{
+       JSContactPhoneNumberTypeArrayPriv* priv =
+               static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSContactPhoneNumberTypeArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       WrtDeviceApis::CommonsJavaScript::BasicConverter converter =
+                       WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
+               if (index < typeArray->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSContactPhoneNumberTypeArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
+               if (index < typeArray->size()) {
+                       std::string result = converter->toContactPhoneNumberTypeStr(typeArray->at(index));
+                       if (!result.empty()) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactPhoneNumberTypeArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               std::string str;
+               if (!JSValueIsUndefined(context, value)) {
+                       str = converter->toString(value);
+               }
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
+               if (!typeArray) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (typeArray->size() <= index) {
+                       typeArray->resize(index + 1);
+               }
+               (*typeArray)[index] = converter->toContactPhoneNumberType(str);
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSContactPhoneNumberTypeArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberTypeArrayPtr typeArray = priv->getObject();
+               if (!typeArray) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (typeArray->size() > index) {
+                       (*typeArray)[index] = converter->toContactPhoneNumberType("");
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSContactPhoneNumberTypeArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactPhoneNumberTypeArrayPtr phoneNumbers = priv->getObject();
+
+               int count = phoneNumbers->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 JSContactPhoneNumberTypeArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactPhoneNumberTypeArrayPtr typeArray = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
+               JSContactPhoneNumberTypeArrayPriv *newPrivateObject = new JSContactPhoneNumberTypeArrayPriv(
+                               context,
+                               typeArray);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current typeArray
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
+               for (size_t i = 0; i < currentStrings->size(); ++i) {
+                       typeArray->push_back(currentStrings->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                                               ContactConverterFactory::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);
+                               typeArray->push_back(converter->toContactPhoneNumberType(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactPhoneNumberTypeArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberTypeArrayPtr 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 JSContactPhoneNumberTypeArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                                               ContactConverterFactory::getConverter(context);
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
+               if (currentStrings->size() > 0) {
+                       std::string result =
+                                       converter->toContactPhoneNumberTypeStr(currentStrings->at(currentStrings->size() - 1));
+                       currentStrings->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberTypeArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                                               ContactConverterFactory::getConverter(context);
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentStrings->push_back(converter->toContactPhoneNumberType(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 JSContactPhoneNumberTypeArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
+               std::reverse(currentStrings->begin(), currentStrings->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberTypeArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
+               if (currentStrings->size() > 0) {
+                       std::string result = converter->toContactPhoneNumberTypeStr(currentStrings->at(0));
+                       currentStrings->erase(currentStrings->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberTypeArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+               ContactPhoneNumberTypeArrayPtr typeArray = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray());
+               JSContactPhoneNumberTypeArrayPriv *newPrivateObject = new JSContactPhoneNumberTypeArrayPriv(
+                               context,
+                               typeArray);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current typeArray
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberTypeArrayPtr 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) {
+                       typeArray->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 JSContactPhoneNumberTypeArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+               JSContactPhoneNumberTypeArrayPriv* priv =
+                       static_cast<JSContactPhoneNumberTypeArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactPhoneNumberTypeArrayPtr currentStrings = priv->getObject();
+               std::sort(currentStrings->begin(), currentStrings->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberTypeArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberTypeArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSContactPhoneNumberTypeArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactPhoneNumberTypeArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactPhoneNumberTypeArray.h b/src/standards/Tizen/Contact/JSContactPhoneNumberTypeArray.h
new file mode 100755 (executable)
index 0000000..b3809af
--- /dev/null
@@ -0,0 +1,193 @@
+//
+// 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        JSContactPhoneNumberTypeArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_TYPE_ARRAY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_TYPE_ARRAY_H_
+
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/ContactPhoneNumber.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::ContactPhoneNumberTypeArrayPtr>::Type JSContactPhoneNumberTypeArrayPriv;
+
+class JSContactPhoneNumberTypeArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::ContactPhoneNumberTypeArrayPtr &Strings);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactPhoneNumberTypeArrayPtr getContactPhoneNumberTypeArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_PHONE_NUMBER_TYPE_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSContactRef.cpp b/src/standards/Tizen/Contact/JSContactRef.cpp
new file mode 100755 (executable)
index 0000000..8ce644c
--- /dev/null
@@ -0,0 +1,324 @@
+//
+// 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        JSContactRef.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSContactRef class
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Validator.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactRef.h"
+
+#define CONTACT_CLASS_NAME                                     "ContactRef"
+#define CONTACT_PROP_ATTR_ADDRESS_BOOK_ID                      "addressBookId"
+#define CONTACT_PROP_ATTR_CONTACT_ID           "contactId"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactRef::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       CONTACT_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 JSContactRef::m_property[] = {
+       { CONTACT_PROP_ATTR_ADDRESS_BOOK_ID, getAddressBookId, setAddressBookId, kJSPropertyAttributeNone },
+       { CONTACT_PROP_ATTR_CONTACT_ID, getContactId, setContactId, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactRef::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSContactRef::m_classRef = JSClassCreate(&m_classInfo);
+
+JSClassRef JSContactRef::getClassRef()
+{
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSContactRef::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactRefPtr JSContactRef::getContactRef(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+
+       JSContactRefPriv *priv = static_cast<JSContactRefPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+
+       return priv->getObject();
+}
+
+void JSContactRef::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               ContactRefPtr name(new ContactRef());
+               JSContactRefPriv *priv = new JSContactRefPriv(context, ContactRefPtr(name));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSContactRef::Finalize(JSObjectRef object)
+{
+       JSContactRefPriv *priv = static_cast<JSContactRefPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+               delete (priv);
+}
+
+JSObjectRef JSContactRef::createJSObject(JSContextRef context, ContactRefPtr contactRef)
+{
+       JSContactRefPriv *priv = new JSContactRefPriv(context, contactRef);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef)
+       {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+ContactRefPtr JSContactRef::getPrivData(JSObjectRef object)
+{
+       JSContactRefPriv *priv = static_cast<JSContactRefPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+
+       ContactRefPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+
+       return result;
+}
+
+JSObjectRef JSContactRef::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       JSContactRefPriv *priv = static_cast<JSContactRefPriv*>(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)
+                       ThrowMsg(InvalidArgumentException, "2nd argument must be contact id");
+
+               if (!JSValueIsString(gContext, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument must be address book id");
+
+               if (!JSValueIsString(gContext, arguments[1]))
+                       ThrowMsg(InvalidArgumentException, "2nd argument must be contact id");
+
+       } Catch(Exception ) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext);
+
+       std::string addressBookId;
+       std::string contactId;
+
+       Try {
+               addressBookId = 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;
+       }
+
+       Try {
+               contactId = 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;
+       }
+
+       ContactRefPtr contactRef(new ContactRef());
+       contactRef->setAddressBookId(addressBookId);
+       contactRef->setContactId(contactId);
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, contactRef);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+bool JSContactRef::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSContactRef::getAddressBookId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactRefPtr contactRef = getPrivData(object);
+               return converter->toJSValueRef(contactRef->getAddressBookId());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactRef::setAddressBookId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactRefPtr contactRef = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contactRef->setAddressBookId(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 JSContactRef::getContactId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactRefPtr contactRef = getPrivData(object);
+               return converter->toJSValueRef(contactRef->getContactId());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactRef::setContactId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactRefPtr contactRef = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               contactRef->setContactId(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;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactRef.h b/src/standards/Tizen/Contact/JSContactRef.h
new file mode 100755 (executable)
index 0000000..4a5b579
--- /dev/null
@@ -0,0 +1,123 @@
+//
+// 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        JSContactRef.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSContactRef class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_REF_H_
+#define _TIZEN_CONTACT_JS_CONTACT_REF_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/ContactRef.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::ContactRefPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSContactRefPriv;
+
+class JSContactRef {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactRefPtr getContactRef(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, TizenApis::Api::Contact::ContactRefPtr contactName);
+
+       static TizenApis::Api::Contact::ContactRefPtr 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 getAddressBookId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setAddressBookId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getContactId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setContactId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_NAME_H_
diff --git a/src/standards/Tizen/Contact/JSContactWebSite.cpp b/src/standards/Tizen/Contact/JSContactWebSite.cpp
new file mode 100755 (executable)
index 0000000..ac76a43
--- /dev/null
@@ -0,0 +1,330 @@
+//
+// 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        JSContactWebSite.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSContactWebSite class
+ */
+
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Validator.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactWebSite.h"
+
+#define CONTACT_CLASS_NAME "ContactWebSite"
+
+#define CONTACT_ATTR_URL  "url"
+#define CONTACT_ATTR_TYPE "type"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactWebSite::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       CONTACT_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 JSContactWebSite::m_property[] = {
+       { CONTACT_ATTR_URL, getUrl, setUrl, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_TYPE, getType, setType, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactWebSite::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSContactWebSite::m_classRef = JSClassCreate(&m_classInfo);
+
+JSClassRef JSContactWebSite::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSContactWebSite::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactWebSitePtr JSContactWebSite::getContactWebSite(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactWebSitePriv *priv = static_cast<JSContactWebSitePriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSContactWebSite::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               ContactWebSitePtr webSite(new ContactWebSite());
+               JSContactWebSitePriv *priv = new JSContactWebSitePriv(context, ContactWebSitePtr(webSite));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSContactWebSite::Finalize(JSObjectRef object)
+{
+       JSContactWebSitePriv *priv = static_cast<JSContactWebSitePriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+               delete (priv);
+}
+
+JSObjectRef JSContactWebSite::createJSObject(JSContextRef context, ContactWebSitePtr contactWebSite)
+{
+       JSContactWebSitePriv *priv = new JSContactWebSitePriv(context, contactWebSite);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+ContactWebSitePtr JSContactWebSite::getPrivData(JSObjectRef object)
+{
+       JSContactWebSitePriv *priv = static_cast<JSContactWebSitePriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       ContactWebSitePtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSObjectRef JSContactWebSite::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       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;
+       ContactWebSiteType type = WEBSITE_TYPE_HOMEPAGE;
+
+       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 {
+               if (js2ndParamIsString)
+                       type = converter->toContactWebSiteType(arguments[1]);
+
+       } Catch(Exception) {
+               LogError("2nd argument only support 'HOMEPAGE' or 'BLOG'");
+       }
+
+       ContactWebSitePtr contactWebSite(new ContactWebSite());
+       contactWebSite->setUrl(url);
+       if(js2ndParamIsString)
+               contactWebSite->setType(type);
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, contactWebSite);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+bool JSContactWebSite::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSContactWebSite::getUrl(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactWebSitePtr webSite = getPrivData(object);
+               return converter->toJSValueRef(webSite->getUrl());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactWebSite::setUrl(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactWebSitePtr webSite = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               webSite->setUrl(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 JSContactWebSite::getType(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactWebSitePtr webSite = getPrivData(object);
+               std::string ret = converter->toContactWebSiteTypeStr(webSite->getType());
+               if(!webSite->getTypeIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(ret);
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactWebSite::setType(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactWebSitePtr webSite = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       webSite->unsetType();
+               else
+               {
+                       ContactWebSiteType type = converter->toContactWebSiteType(converter->toString(value));
+                       webSite->setType(type);
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to set incorrect value");
+       }
+       JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       return false;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactWebSite.h b/src/standards/Tizen/Contact/JSContactWebSite.h
new file mode 100755 (executable)
index 0000000..f014365
--- /dev/null
@@ -0,0 +1,123 @@
+//
+// 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        JSContactWebSite.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSContactWebSite class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_WEB_SITE_H_
+#define _TIZEN_CONTACT_JS_CONTACT_WEB_SITE_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/ContactWebSite.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject< TizenApis::Api::Contact::ContactWebSitePtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSContactWebSitePriv;
+
+class JSContactWebSite {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactWebSitePtr getContactWebSite(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, TizenApis::Api::Contact::ContactWebSitePtr contactWebSite);
+
+       static TizenApis::Api::Contact::ContactWebSitePtr 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 getUrl(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setUrl(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getType(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setType(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_WEB_SITE_H_
diff --git a/src/standards/Tizen/Contact/JSContactWebSiteArray.cpp b/src/standards/Tizen/Contact/JSContactWebSiteArray.cpp
new file mode 100755 (executable)
index 0000000..202fbf9
--- /dev/null
@@ -0,0 +1,633 @@
+//
+// 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        JSContactWebSiteArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSContactWebSiteArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSContactWebSiteArray::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 JSContactWebSiteArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSContactWebSiteArray::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 JSContactWebSiteArray::m_jsClassRef = JSClassCreate(
+               JSContactWebSiteArray::getClassInfo());
+
+JSValueRef JSContactWebSiteArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactWebSiteArrayPtr webSites = priv->getObject();
+               if (webSites) {
+                       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(webSites->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactWebSiteArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+ContactWebSiteArrayPtr JSContactWebSiteArray::getContactWebSiteArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSContactWebSiteArrayPriv *priv = static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+JSObjectRef JSContactWebSiteArray::createArray(JSContextRef context,
+               const ContactWebSiteArrayPtr &webSites)
+{
+       JSContactWebSiteArrayPriv *priv = new JSContactWebSiteArrayPriv(context, webSites);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSContactWebSiteArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSContactWebSiteArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+void JSContactWebSiteArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSContactWebSiteArray::finalize(JSObjectRef object)
+{
+       JSContactWebSiteArrayPriv* priv =
+               static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSContactWebSiteArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactWebSiteArrayPtr webSites = priv->getObject();
+               if (index < webSites->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSContactWebSiteArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactWebSiteArrayPtr webSites = priv->getObject();
+               if (index < webSites->size()) {
+                       ContactWebSitePtr result = webSites->at(index);
+                       if (result) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSContactWebSiteArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactWebSitePtr webSite(NULL);
+               if (!JSValueIsUndefined(context, value)) {
+                       webSite = converter->toContactWebSite(value);
+               }
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactWebSiteArrayPtr webSites = priv->getObject();
+               if (!webSites) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (webSites->size() <= index) {
+                       webSites->resize(index + 1);
+               }
+               (*webSites)[index] = webSite;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSContactWebSiteArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               ContactWebSitePtr webSite(NULL);
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactWebSiteArrayPtr webSites = priv->getObject();
+               if (!webSites) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (webSites->size() > index) {
+                       (*webSites)[index] = webSite;
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSContactWebSiteArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               ContactWebSiteArrayPtr webSites = priv->getObject();
+
+               int count = webSites->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 JSContactWebSiteArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactWebSiteArrayPtr webSites = ContactWebSiteArrayPtr(new ContactWebSiteArray());
+               JSContactWebSiteArrayPriv *newPrivateObject = new JSContactWebSiteArrayPriv(context, webSites);
+               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
+
+               //copy current webSites
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactWebSiteArrayPtr currentWebSites = priv->getObject();
+               for (size_t i = 0; i < currentWebSites->size(); ++i) {
+                       webSites->push_back(currentWebSites->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::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);
+                               webSites->push_back(converter->toContactWebSite(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactWebSiteArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactWebSiteArrayPtr currentWebSites = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentWebSites->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       //FIXME : to be changed to support join
+                       //result += currentWebSites->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 JSContactWebSiteArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactWebSiteArrayPtr currentWebSites = priv->getObject();
+               if (currentWebSites->size() > 0) {
+                       ContactWebSitePtr result = currentWebSites->at(
+                                       currentWebSites->size() - 1);
+                       currentWebSites->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactWebSiteArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactWebSiteArrayPtr currentWebSites = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentWebSites->push_back(converter->toContactWebSite(arguments[i]));
+               }
+               return converter->toJSValueRef(currentWebSites->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactWebSiteArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactWebSiteArrayPtr currentWebSites = priv->getObject();
+               std::reverse(currentWebSites->begin(), currentWebSites->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactWebSiteArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactWebSiteArrayPtr currentWebSites = priv->getObject();
+               if (currentWebSites->size() > 0) {
+                       ContactWebSitePtr result = currentWebSites->at(0);
+                       currentWebSites->erase(currentWebSites->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactWebSiteArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               ContactWebSiteArrayPtr webSites = ContactWebSiteArrayPtr(new ContactWebSiteArray());
+               JSContactWebSiteArrayPriv *newPrivateObject = new JSContactWebSiteArrayPriv(
+                               context,
+                               webSites);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current webSites
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactWebSiteArrayPtr currentWebSites = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentWebSites->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentWebSites->size()) {
+                               last = currentWebSites->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       webSites->push_back(currentWebSites->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSContactWebSiteArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSContactWebSiteArrayPriv* priv =
+                       static_cast<JSContactWebSiteArrayPriv*>(JSObjectGetPrivate(thisObject));
+               ContactWebSiteArrayPtr currentWebSites = priv->getObject();
+               std::sort(currentWebSites->begin(), currentWebSites->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactWebSiteArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactWebSiteArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSContactWebSiteArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSContactWebSiteArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSContactWebSiteArray.h b/src/standards/Tizen/Contact/JSContactWebSiteArray.h
new file mode 100755 (executable)
index 0000000..2843b41
--- /dev/null
@@ -0,0 +1,192 @@
+//
+// 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        JSContactWebSiteArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_CONTACT_WEB_SITE_ARRAY_H_
+#define _TIZEN_CONTACT_JS_CONTACT_WEB_SITE_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/ContactWebSite.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT< TizenApis::Api::Contact::ContactWebSiteArrayPtr >::Type JSContactWebSiteArrayPriv;
+
+class JSContactWebSiteArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::ContactWebSiteArrayPtr &webSites);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::ContactWebSiteArrayPtr getContactWebSiteArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_CONTACT_WEB_SITE_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSPerson.cpp b/src/standards/Tizen/Contact/JSPerson.cpp
new file mode 100755 (executable)
index 0000000..8cefc49
--- /dev/null
@@ -0,0 +1,733 @@
+//
+// 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        JSPerson.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSPerson class
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Validator.h>
+#include <API/Contact/ContactFactory.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include "plugin_config.h"
+#include "ContactConverter.h"
+#include "JSPerson.h"
+
+#define FILTER_CLASS_NAME               "Person"
+
+#define CONTACT_ATTR_ID                 "id"
+#define CONTACT_ATTR_DISPLAY_NAME       "displayName"
+#define CONTACT_ATTR_CONTACT_COUNT      "contactCount"
+#define CONTACT_ATTR_HAS_PHONE_NUMBER   "hasPhoneNumber"
+#define CONTACT_ATTR_HAS_EMAIL          "hasEmail"
+#define CONTACT_ATTR_IS_FAVORITE        "isFavorite"
+#define CONTACT_ATTR_PHOTO_URI             "photoURI"
+#define CONTACT_ATTR_RINGTONE_URI       "ringtoneURI"
+#define CONTACT_ATTR_DISPLAY_CONTACT_ID "displayContactId"
+#define CONTACT_FUNC_LINK               "link"
+#define CONTACT_FUNC_UNLINK             "unlink"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSPerson::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       FILTER_CLASS_NAME,
+       NULL,
+       m_property,
+       m_functions,
+       Initialize,
+       Finalize,
+       NULL, //hasProperty,
+       NULL, //GetProperty,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //getPropertyNames,
+       NULL, //CallAsFunction,
+       NULL, //CallAsConstructor,
+       hasInstance, //HasInstance,
+       NULL, //ConvertToType,
+};
+
+JSStaticValue JSPerson::m_property[] = {
+       { CONTACT_ATTR_ID, getId, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_ATTR_DISPLAY_NAME, getDisplayName, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_ATTR_CONTACT_COUNT, getContactCount, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_ATTR_HAS_PHONE_NUMBER, getHasPhoneNumber, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_ATTR_HAS_EMAIL, getHasEmail, NULL, kJSPropertyAttributeReadOnly },
+       { CONTACT_ATTR_IS_FAVORITE, getIsFavorite, setIsFavorite, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_PHOTO_URI, getPhotoURI, setPhotoURI, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_RINGTONE_URI, getRingtoneURI, setRingtoneURI, kJSPropertyAttributeNone },
+       { CONTACT_ATTR_DISPLAY_CONTACT_ID, getDisplayContactId, setDisplayContactId, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSPerson::m_functions[] =
+{
+       { CONTACT_FUNC_LINK, link, kJSPropertyAttributeNone },
+       { CONTACT_FUNC_UNLINK, unlink, kJSPropertyAttributeNone },
+       { 0, 0, 0 }
+};
+
+JSClassRef JSPerson::m_classRef = JSClassCreate(&m_classInfo);
+
+JSClassRef JSPerson::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSPerson::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+PersonPtr JSPerson::getPerson(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSPersonPriv *priv = static_cast<JSPersonPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+void JSPerson::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               PersonPtr person = ContactFactory::getInstance().createPerson();
+               JSPersonPriv *priv = new JSPersonPriv(context, PersonPtr(person));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSPerson::Finalize(JSObjectRef object)
+{
+       JSPersonPriv *priv = static_cast<JSPersonPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+               delete (priv);
+}
+
+JSObjectRef JSPerson::createJSObject(JSContextRef context, PersonPtr person)
+{
+       JSPersonPriv *priv = new JSPersonPriv(context, person);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+PersonPtr JSPerson::getPrivData(JSObjectRef object)
+{
+       JSPersonPriv *priv = static_cast<JSPersonPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       PersonPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null.");
+       }
+       return result;
+}
+
+bool JSPerson::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSPerson::getId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               PersonPtr person = getPrivData(object);
+               if(!person->getIdIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(person->getId());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPerson::getDisplayName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               PersonPtr person = getPrivData(object);
+               if(!person->getIdIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(person->getDisplayName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPerson::getContactCount(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               PersonPtr person = getPrivData(object);
+               if(!person->getIdIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRefLong(person->getContactCount());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPerson::getHasPhoneNumber(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               PersonPtr person = getPrivData(object);
+               if(!person->getIdIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(person->getHasPhoneNumber());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPerson::getHasEmail(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               PersonPtr person = getPrivData(object);
+               if(!person->getIdIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(person->getHasEmail());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPerson::getIsFavorite(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               PersonPtr person = getPrivData(object);
+               return converter->toJSValueRef(person->getIsFavorite());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSPerson::setIsFavorite(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               PersonPtr person = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               person->setIsFavorite(converter->toBool(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 JSPerson::getPhotoURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               PersonPtr person = getPrivData(object);
+               if(!person->getPhotoURIIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(person->getPhotoURI());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSPerson::setPhotoURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               PersonPtr person = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       person->unsetPhotoURI();
+               else
+                       person->setPhotoURI(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 JSPerson::getRingtoneURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               PersonPtr person = getPrivData(object);
+               if(!person->getRingtoneURIIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(person->getRingtoneURI());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSPerson::setRingtoneURI(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               PersonPtr person = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       person->unsetRingtoneURI();
+               else
+                       person->setRingtoneURI(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 JSPerson::getDisplayContactId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               PersonPtr person = getPrivData(object);
+               if(!person->getDisplayContactIdIsSet())
+                       return JSValueMakeNull(context);
+               else
+                       return converter->toJSValueRef(person->getDisplayContactId());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSPerson::setDisplayContactId(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               PersonPtr person = getPrivData(object);
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               BasicValidator validator =
+                               BasicValidatorFactory::getValidator(context, exception);
+               if(validator->isNullOrUndefined(value))
+                       person->unsetDisplayContactId();
+               else
+                       person->setDisplayContactId(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 JSPerson::link(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       PersonPtr person(NULL);
+
+       Try
+       {
+               person = getPrivData(thisObject);
+               if (person == NULL)
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+       }
+       Catch(Exception)
+       {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_PERSON_LINK);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try
+       {
+               if (argumentCount < 1)
+                       ThrowMsg(ConversionException, "1st argument must be 'PersonId'");
+       }
+       Catch (Exception)
+       {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'PersonId'");
+       }
+
+       std::string personId;
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try
+       {
+               personId = converter->toString(arguments[0]);
+
+               if (personId.empty())
+                       ThrowMsg(ConversionException, "1st argument must be 'PersonId'");
+
+       }
+       Catch(Exception)
+       {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'PersonId'");
+       }
+
+       EventPersonLinkPtr dplEvent(new EventPersonLink());
+
+       dplEvent->setPersonId(personId);
+    dplEvent->setForSynchronousCall();
+
+       Try
+       {
+               person->link(dplEvent);
+       }
+       Catch(ConversionException)
+       {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'PersonId'");
+       }
+       Catch(Exception)
+       {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::NotFoundException:
+                       oss << "Person id (" << personId << ") is not exists.";
+                       return JSTizenExceptionFactory::postException(context, exception,
+                                       JSTizenException::INVALID_VALUES_ERROR, oss.str());
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       oss << "Person id (" << personId << ") is wrong.";
+                       return JSTizenExceptionFactory::postException(context, exception,
+                                       JSTizenException::INVALID_VALUES_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPerson::unlink(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       PersonPtr person(NULL);
+
+       Try
+       {
+               person = getPrivData(thisObject);
+               if (person == NULL)
+                       ThrowMsg(InvalidArgumentException, "No private object.");
+       }
+       Catch(Exception)
+       {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+
+       AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_PERSON_UNLINK);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try
+       {
+               if (argumentCount < 1)
+                       ThrowMsg(ConversionException, "1st argument must be 'ContactId'");
+
+               if (!JSValueIsString(context, arguments[0]))
+                       ThrowMsg(ConversionException, "1st argument must be 'ContactId'");
+       }
+       Catch (Exception)
+       {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactId'");
+       }
+
+       std::string contactId;
+
+       ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context);
+       Try
+       {
+               contactId = converter->toString(arguments[0]);
+       }
+       Catch(Exception)
+       {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactId'");
+       }
+
+       EventPersonUnlinkPtr dplEvent(new EventPersonUnlink());
+
+       dplEvent->setContactId(contactId);
+    dplEvent->setForSynchronousCall();
+
+       Try
+       {
+               person->unlink(dplEvent);
+       }
+       Catch(ConversionException)
+       {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "1st argument must be 'ContactId'");
+       }
+       Catch(Exception)
+       {
+               LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       if (!dplEvent->getResult())
+       {
+               std::stringstream oss;
+               switch (dplEvent->getExceptionCode())
+               {
+               case ExceptionCodes::InvalidArgumentException:
+                       oss << "No Contact id is wrong : '" << contactId << "'";
+                       return JSTizenExceptionFactory::postException(context, exception,
+                                       JSTizenException::INVALID_VALUES_ERROR, oss.str());
+                       break;
+               case ExceptionCodes::NotFoundException:
+                       oss << "No Contact id '" << contactId << "'";
+                       return JSTizenExceptionFactory::postException(context, exception,
+                                       JSTizenException::INVALID_VALUES_ERROR, oss.str());
+                       break;
+               case ExceptionCodes::OutOfRangeException:
+                       oss << "Contact (id:'" << contactId << "') is not a member of person";
+                       return JSTizenExceptionFactory::postException(context, exception,
+                                       JSTizenException::INVALID_VALUES_ERROR, oss.str());
+                       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;
+               }
+       }
+
+       PersonPtr unlinkedPerson = dplEvent->getPerson();
+
+       JSValueRef result;
+       Try
+       {
+               result = converter->toJSValueRef(unlinkedPerson);
+       }
+       Catch(Exception)
+       {
+               LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::UNKNOWN_ERROR, "Internal error");
+       }
+
+       return result;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSPerson.h b/src/standards/Tizen/Contact/JSPerson.h
new file mode 100755 (executable)
index 0000000..ebcbb1f
--- /dev/null
@@ -0,0 +1,177 @@
+//
+// 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        JSPerson.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSPerson class
+ */
+
+#ifndef _TIZEN_CONTACT_JS_PERSON_H_
+#define _TIZEN_CONTACT_JS_PERSON_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Contact/IPerson.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Contact::PersonPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSPersonPriv;
+
+class JSPerson {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::PersonPtr getPerson(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, TizenApis::Api::Contact::PersonPtr person);
+
+       static TizenApis::Api::Contact::PersonPtr getPrivData(JSObjectRef object);
+
+       static bool hasInstance(JSContextRef context,
+                       JSObjectRef constructor,
+                       JSValueRef possibleInstance,
+                       JSValueRef* exception);
+
+       static JSValueRef getId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getDisplayName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getContactCount(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getHasPhoneNumber(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getHasEmail(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef getIsFavorite(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setIsFavorite(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getPhotoURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setPhotoURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getRingtoneURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setRingtoneURI(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getDisplayContactId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setDisplayContactId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef link(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef unlink(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_PERSON_H_
diff --git a/src/standards/Tizen/Contact/JSPersonArray.cpp b/src/standards/Tizen/Contact/JSPersonArray.cpp
new file mode 100755 (executable)
index 0000000..4de9497
--- /dev/null
@@ -0,0 +1,639 @@
+//
+// 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        JSPersonArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSPersonArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Contact;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSPersonArray::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 JSPersonArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSPersonArray::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 JSPersonArray::m_jsClassRef = JSClassCreate(
+               JSPersonArray::getClassInfo());
+
+JSValueRef JSPersonArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       Try
+       {
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               PersonArrayPtr groups = priv->getObject();
+               if (groups) {
+                       ContactConverterFactory::ConverterType converter =
+                                       ContactConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(groups->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSObjectRef JSPersonArray::createArray(JSContextRef context,
+               const PersonArrayPtr &groups)
+{
+       JSPersonArrayPriv *priv = new JSPersonArrayPriv(context, groups);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+bool JSPersonArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+PersonArrayPtr JSPersonArray::getPersonArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSPersonArrayPriv *priv = static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+const JSClassDefinition* JSPersonArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSPersonArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+void JSPersonArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSPersonArray::finalize(JSObjectRef object)
+{
+       JSPersonArrayPriv* priv =
+               static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSPersonArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               PersonArrayPtr groups = priv->getObject();
+               if (index < groups->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSPersonArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               PersonArrayPtr groups = priv->getObject();
+               if (index < groups->size()) {
+                       PersonPtr result = groups->at(index);
+                       if (result) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSPersonArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               PersonPtr group(NULL);
+               if (!JSValueIsUndefined(context, value)) {
+                       group = converter->toPerson(value);
+               }
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               PersonArrayPtr groups = priv->getObject();
+               if (!groups) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (groups->size() <= index) {
+                       groups->resize(index + 1);
+               }
+               (*groups)[index] = group;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+bool JSPersonArray::deleteProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               PersonPtr group(NULL);
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               PersonArrayPtr groups = priv->getObject();
+               if (!groups) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (groups->size() > index) {
+                       (*groups)[index] = group;
+               }
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception,
+                               JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSPersonArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::getConverter(context);
+       Try
+       {
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               PersonArrayPtr groups = priv->getObject();
+
+               int count = groups->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 JSPersonArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               PersonArrayPtr groups = PersonArrayPtr(new PersonArray());
+               JSPersonArrayPriv *newPrivateObject = new JSPersonArrayPriv(context, groups);
+               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
+
+               //copy current groups
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
+               PersonArrayPtr currentPersons = priv->getObject();
+               for (size_t i = 0; i < currentPersons->size(); ++i) {
+                       groups->push_back(currentPersons->at(i));
+               }
+
+               //copy submitted arrays
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::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);
+                               groups->push_back(converter->toPerson(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception,
+                       JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSPersonArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
+               PersonArrayPtr currentPersons = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentPersons->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       //FIXME : to be changed to support join
+                       //result += currentPersons->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 JSPersonArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
+               PersonArrayPtr currentPersons = priv->getObject();
+               if (currentPersons->size() > 0) {
+                       PersonPtr result = currentPersons->at(
+                                       currentPersons->size() - 1);
+                       currentPersons->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPersonArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
+               PersonArrayPtr currentPersons = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentPersons->push_back(converter->toPerson(arguments[i]));
+               }
+               return converter->toJSValueRef(currentPersons->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception,
+                       JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSPersonArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
+               PersonArrayPtr currentPersons = priv->getObject();
+               std::reverse(currentPersons->begin(), currentPersons->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPersonArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
+               PersonArrayPtr currentPersons = priv->getObject();
+               if (currentPersons->size() > 0) {
+                       PersonPtr result = currentPersons->at(0);
+                       currentPersons->erase(currentPersons->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPersonArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               PersonArrayPtr groups = PersonArrayPtr(new PersonArray());
+               JSPersonArrayPriv *newPrivateObject = new JSPersonArrayPriv(
+                               context,
+                               groups);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current groups
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
+               PersonArrayPtr currentPersons = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentPersons->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentPersons->size()) {
+                               last = currentPersons->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       groups->push_back(currentPersons->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception,
+                       JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSPersonArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       Try
+       {
+               ContactConverterFactory::ConverterType converter =
+                               ContactConverterFactory::getConverter(context);
+               JSPersonArrayPriv* priv =
+                       static_cast<JSPersonArrayPriv*>(JSObjectGetPrivate(thisObject));
+               PersonArrayPtr currentPersons = priv->getObject();
+               std::sort(currentPersons->begin(), currentPersons->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPersonArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPersonArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSPersonArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSPersonArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       return JSValueMakeUndefined(context);
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSPersonArray.h b/src/standards/Tizen/Contact/JSPersonArray.h
new file mode 100755 (executable)
index 0000000..334921e
--- /dev/null
@@ -0,0 +1,192 @@
+//
+// 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        JSPersonArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_CONTACT_JS_PERSON_ARRAY_H_
+#define _TIZEN_CONTACT_JS_PERSON_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Contact/IPerson.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Contact::PersonArrayPtr>::Type JSPersonArrayPriv;
+
+class JSPersonArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Contact::PersonArrayPtr &groups);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Contact::PersonArrayPtr getPersonArray(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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_PERSON_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/JSStringArray.cpp b/src/standards/Tizen/Contact/JSStringArray.cpp
new file mode 100755 (executable)
index 0000000..7a544ef
--- /dev/null
@@ -0,0 +1,602 @@
+//
+// 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 <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ContactConverter.h"
+#include "JSStringArray.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 TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+using namespace TizenApis::Commons;
+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);
+               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);
+               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)
+{
+       ContactConverterFactory::ConverterType converter =
+                       ContactConverterFactory::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
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Contact/JSStringArray.h b/src/standards/Tizen/Contact/JSStringArray.h
new file mode 100755 (executable)
index 0000000..e933f4f
--- /dev/null
@@ -0,0 +1,189 @@
+//
+// 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_CONTACT_JS_STRING_ARRAY_H_
+#define _TIZEN_CONTACT_JS_STRING_ARRAY_H_
+
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+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[];
+};
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_CONTACT_JS_STRING_ARRAY_H_
diff --git a/src/standards/Tizen/Contact/config.xml b/src/standards/Tizen/Contact/config.xml
new file mode 100755 (executable)
index 0000000..c5d1c44
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+    <library-name>libwrt-plugins-tizen-2.0-contact.so</library-name>
+    <feature-install-uri>contact.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/contact.read</name>
+        <device-capability>contact.read</device-capability>
+    </api-feature>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/contact.write</name>
+        <device-capability>contact.write</device-capability>
+    </api-feature>
+</plugin-properties>
diff --git a/src/standards/Tizen/Contact/plugin_config.cpp b/src/standards/Tizen/Contact/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..145fdb9
--- /dev/null
@@ -0,0 +1,394 @@
+//
+// 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 CONTACT_FEATURE_API_READ  "http://tizen.org/privilege/contact.read"
+#define CONTACT_FEATURE_API_WRITE "http://tizen.org/privilege/contact.write"
+
+#define CONTACT_DEVICE_CAP_READ "contact.read"
+#define CONTACT_DEVICE_CAP_WRITE "contact.write"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+static FunctionMapping createContactFunctions();
+
+static FunctionMapping ContactFunctions =
+    createContactFunctions();
+
+DEFINE_FUNCTION_GETTER(Contact, ContactFunctions);
+
+static FunctionMapping createContactFunctions()
+{
+    /**
+     * Device capabilities
+     */
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_CONTACT_READ, CONTACT_DEVICE_CAP_READ);
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_CONTACT_WRITE, CONTACT_DEVICE_CAP_WRITE);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_CONTACT_READ);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_CONTACT_READ, DEVICE_CAP_CONTACT_READ);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_CONTACT_WRITE);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_CONTACT_WRITE, DEVICE_CAP_CONTACT_WRITE);
+
+    /**
+     * Api Features
+     */
+    ACE_CREATE_FEATURE(FEATURE_CONTACT_READ, CONTACT_FEATURE_API_READ);
+    ACE_CREATE_FEATURE(FEATURE_CONTACT_WRITE, CONTACT_FEATURE_API_WRITE);
+
+    ACE_CREATE_FEATURE_LIST(CONTACT_FEATURES_CONTACT_READ);
+    ACE_ADD_API_FEATURE(CONTACT_FEATURES_CONTACT_READ, FEATURE_CONTACT_READ);
+
+    ACE_CREATE_FEATURE_LIST(CONTACT_FEATURES_CONTACT_WRITE);
+    ACE_ADD_API_FEATURE(CONTACT_FEATURES_CONTACT_WRITE, FEATURE_CONTACT_WRITE);
+
+    /**
+     * Functions
+     */
+
+    FunctionMapping contactMapping;
+
+    //ContactManager.getAddressBooks
+    AceFunction contactManagerGetAddressBooksFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONTACT_MANAGER_GET_ADDRESS_BOOKS,
+            CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_ADDRESS_BOOKS,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_ADDRESS_BOOKS,
+                               contactManagerGetAddressBooksFunc));
+
+    //ContactManager.getDefaultAddressBook
+    AceFunction contactManagerGetDefaultAddressBookFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONTACT_MANAGER_GET_DEFAULT_ADDRESS_BOOK,
+            CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_DEFAULT_ADDRESS_BOOK,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_DEFAULT_ADDRESS_BOOK,
+                               contactManagerGetDefaultAddressBookFunc));
+
+    //ContactManager.getAddressBook
+    AceFunction contactManagerGetAddressBookFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONTACT_MANAGER_GET_ADDRESS_BOOK,
+            CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_ADDRESS_BOOK,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_ADDRESS_BOOK,
+                               contactManagerGetAddressBookFunc));
+
+
+    //ContactManager.get
+    AceFunction contactManagerGetFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONTACT_MANAGER_GET,
+            CONTACT_FUNCTION_API_CONTACT_MANAGER_GET,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_CONTACT_MANAGER_GET,
+                               contactManagerGetFunc));
+
+    //ContactManager.update
+    AceFunction contactManagerUpdateFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONTACT_MANAGER_UPDATE,
+            CONTACT_FUNCTION_API_CONTACT_MANAGER_UPDATE,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_CONTACT_MANAGER_UPDATE,
+                               contactManagerUpdateFunc));
+
+    //ContactManager.updateBatch
+    AceFunction contactManagerUpdateBatchFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONTACT_MANAGER_UPDATE_BATCH,
+            CONTACT_FUNCTION_API_CONTACT_MANAGER_UPDATE_BATCH,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_CONTACT_MANAGER_UPDATE_BATCH,
+                               contactManagerUpdateBatchFunc));
+
+    //ContactManager.remove
+    AceFunction contactManagerRemoveFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONTACT_MANAGER_REMOVE,
+            CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE,
+                               contactManagerRemoveFunc));
+
+    //ContactManager.removeBatch
+    AceFunction contactManagerRemoveBatchFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONTACT_MANAGER_REMOVE_BATCH,
+            CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE_BATCH,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE_BATCH,
+                               contactManagerRemoveBatchFunc));
+
+    //ContactManager.find
+    AceFunction contactManagerFindFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONTACT_MANAGER_FIND,
+            CONTACT_FUNCTION_API_CONTACT_MANAGER_FIND,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_CONTACT_MANAGER_FIND,
+                               contactManagerFindFunc));
+
+    //ContactManager.addChangeListener
+    AceFunction contactManagerAddChangeListenerFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONTACT_MANAGER_ADD_CHANGE_LISTENER,
+            CONTACT_FUNCTION_API_CONTACT_MANAGER_ADD_CHANGE_LISTENER,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_CONTACT_MANAGER_ADD_CHANGE_LISTENER,
+                               contactManagerAddChangeListenerFunc));
+
+    //ContactManager.removeChangeListener
+    AceFunction contactManagerRemoveChangeListenerFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CONTACT_MANAGER_REMOVE_CHANGE_LISTENER,
+            CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE_CHANGE_LISTENER,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE_CHANGE_LISTENER,
+                               contactManagerRemoveChangeListenerFunc));
+
+    //AddressBook.get
+    AceFunction addressBookGetFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_GET,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_GET,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_GET,
+                               addressBookGetFunc));
+
+    //AddressBook.add
+    AceFunction addressBookAddFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_ADD,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD,
+                               addressBookAddFunc));
+
+    //AddressBook.addBatch
+    AceFunction addressBookAddBatchFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_ADD_BATCH,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_BATCH,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_BATCH,
+                               addressBookAddBatchFunc));
+
+    //AddressBook.update
+    AceFunction addressBookUpdateFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_UPDATE,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE,
+                               addressBookUpdateFunc));
+
+    //AddressBook.updateBatch
+    AceFunction addressBookUpdateBatchFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_UPDATE_BATCH,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_BATCH,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_BATCH,
+                               addressBookUpdateBatchFunc));
+
+    //AddressBook.remove
+    AceFunction addressBookRemoveFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_REMOVE,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE,
+                               addressBookRemoveFunc));
+
+    //AddressBook.removeBatch
+    AceFunction addressBookRemoveBatchFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_REMOVE_BATCH,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_BATCH,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_BATCH,
+                               addressBookRemoveBatchFunc));
+
+    //AddressBook.find
+    AceFunction addressBookFindFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_FIND,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_FIND,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_FIND,
+                               addressBookFindFunc));
+
+    //AddressBook.addChangeListener
+    AceFunction addressBookAddChangeListenerFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_ADD_CHANGE_LISTENER,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_CHANGE_LISTENER,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_CHANGE_LISTENER,
+                               addressBookAddChangeListenerFunc));
+
+    //AddressBook.removeChangeListener
+    AceFunction addressBookRemoveChangeListenerFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_REMOVE_CHANGE_LISTENER,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_CHANGE_LISTENER,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_CHANGE_LISTENER,
+                               addressBookRemoveChangeListenerFunc));
+    //AddressBook.getGroup
+    AceFunction addressBookGetGroupFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_GET_GROUP,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUP,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUP,
+                               addressBookGetGroupFunc));
+
+    //AddressBook.addGroup
+    AceFunction addressBookAddGroupFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_ADD_GROUP,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_GROUP,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_GROUP,
+                               addressBookAddGroupFunc));
+
+    //AddressBook.updateGroup
+    AceFunction addressBookUpdateGroupFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_UPDATE_GROUP,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_GROUP,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_GROUP,
+                               addressBookUpdateGroupFunc));
+
+    //AddressBook.removeGroup
+    AceFunction addressBookRemoveGroupFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_REMOVE_GROUP,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_GROUP,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_GROUP,
+                               addressBookRemoveGroupFunc));
+
+    //AddressBook.getGroups
+    AceFunction addressBookGetGroupsFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_ADDRESS_BOOK_GET_GROUPS,
+            CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUPS,
+            CONTACT_FEATURES_CONTACT_READ,
+            DEVICE_LIST_CONTACT_READ);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUPS,
+                               addressBookGetGroupsFunc));
+
+    //Person.link
+    AceFunction personLinkFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_PERSON_LINK,
+            CONTACT_FUNCTION_API_PERSON_LINK,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_PERSON_LINK,
+                               personLinkFunc));
+
+    //Person.unlink
+    AceFunction personUnlinkFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_PERSON_UNLINK,
+            CONTACT_FUNCTION_API_PERSON_UNLINK,
+            CONTACT_FEATURES_CONTACT_WRITE,
+            DEVICE_LIST_CONTACT_WRITE);
+
+    contactMapping.insert(std::make_pair(
+                               CONTACT_FUNCTION_API_PERSON_UNLINK,
+                               personUnlinkFunc));
+
+    return contactMapping;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Contact/plugin_config.h b/src/standards/Tizen/Contact/plugin_config.h
new file mode 100755 (executable)
index 0000000..276f133
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// 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 _CONTACT_PLUGIN_CONFIG_H_
+#define _CONTACT_PLUGIN_CONFIG_H_
+
+#include <string>
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Contact {
+
+#define CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_ADDRESS_BOOKS          "ContactManager.getAddressBooks"
+#define CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_DEFAULT_ADDRESS_BOOK   "ContactManager.getDefaultAddressBook"
+#define CONTACT_FUNCTION_API_CONTACT_MANAGER_GET_ADDRESS_BOOK           "ContactManager.getAddressBook"
+#define CONTACT_FUNCTION_API_CONTACT_MANAGER_GET                        "ContactManager.get"
+#define CONTACT_FUNCTION_API_CONTACT_MANAGER_UPDATE                     "ContactManager.update"
+#define CONTACT_FUNCTION_API_CONTACT_MANAGER_UPDATE_BATCH               "ContactManager.updateBatch"
+#define CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE                     "ContactManager.remove"
+#define CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE_BATCH               "ContactManager.removeBatch"
+#define CONTACT_FUNCTION_API_CONTACT_MANAGER_FIND                       "ContactManager.find"
+#define CONTACT_FUNCTION_API_CONTACT_MANAGER_ADD_CHANGE_LISTENER        "ContactManager.addChangeListener"
+#define CONTACT_FUNCTION_API_CONTACT_MANAGER_REMOVE_CHANGE_LISTENER     "ContactManager.removeChangeListener"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_GET                           "AddressBook.get"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD                           "AddressBook.add"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_BATCH                     "AddressBook.addBatch"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE                        "AddressBook.update"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_BATCH                  "AddressBook.updateBatch"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE                        "AddressBook.remove"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_BATCH                  "AddressBook.removeBatch"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_FIND                          "AddressBook.find"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_CHANGE_LISTENER           "AddressBook.addChangeListener"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_CHANGE_LISTENER        "AddressBook.removeChangeListener"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUP                     "AddressBook.getGroup"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_ADD_GROUP                     "AddressBook.addGroup"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_UPDATE_GROUP                  "AddressBook.updateGroup"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_REMOVE_GROUP                  "AddressBook.removeGroup"
+#define CONTACT_FUNCTION_API_ADDRESS_BOOK_GET_GROUPS                    "AddressBook.getGroups"
+#define CONTACT_FUNCTION_API_PERSON_LINK                                "AddressBook.link"
+#define CONTACT_FUNCTION_API_PERSON_UNLINK                              "AddressBook.unlink"
+
+DECLARE_FUNCTION_GETTER(Contact);
+
+#define CONTACT_CHECK_ACCESS(functionName)                     \
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(                \
+        getContactFunctionData,           \
+        functionName)
+
+} // Contact
+} // Tizen1_0
+} // Tizen
+
+#endif // _CONTACT_PLUGIN_CONFIG_H_
diff --git a/src/standards/Tizen/Contact/plugin_initializer.cpp b/src/standards/Tizen/Contact/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..d9eee3b
--- /dev/null
@@ -0,0 +1,135 @@
+//
+// 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        plugin_initializer.cpp
+ * @author      Karol Majewski (k.majewski@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+
+#include <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include "JSContactManager.h"
+#include "JSContact.h"
+#include "JSContactGroup.h"
+#include "JSContactRef.h"
+#include "JSContactName.h"
+#include "JSContactOrganization.h"
+#include "JSContactWebSite.h"
+#include "JSContactAnniversary.h"
+#include "JSContactAddress.h"
+#include "JSContactPhoneNumber.h"
+#include "JSContactEmailAddress.h"
+#include "ContactAsyncCallbackManager.h"
+#include "ContactListenerManager.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[Tizen\\contact] on_widget_start_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess initialization failed");
+    }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[Tizen\\contact] on_widget_stop_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+void on_frame_load_callback(const void * context)
+{
+    LogDebug("[Tizen\\contact] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LogDebug("[Tizen\\contact] on_frame_unload_callback (" << context << ")");
+
+    TizenApis::Tizen1_0::Contact::ContactAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+    TizenApis::Tizen1_0::Contact::ContactListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+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,
+                               "contact",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Contact::JSContactManager::getClassRef,
+                               NULL)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "Contact",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Contact::JSContact::getClassRef,
+                               NULL)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "ContactGroup",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Contact::JSContactGroup::getClassRef,
+                               NULL)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "ContactRef",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Contact::JSContactRef::getClassRef,
+                               NULL)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "ContactName",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Contact::JSContactName::getClassRef,
+                               NULL)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "ContactOrganization",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Contact::JSContactOrganization::getClassRef,
+                               NULL)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "ContactWebSite",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Contact::JSContactWebSite::getClassRef,
+                               NULL)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "ContactAnniversary",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Contact::JSContactAnniversary::getClassRef,
+                               NULL)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "ContactAddress",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Contact::JSContactAddress::getClassRef,
+                               NULL)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "ContactPhoneNumber",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Contact::JSContactPhoneNumber::getClassRef,
+                               NULL)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "ContactEmailAddress",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Contact::JSContactEmailAddress::getClassRef,
+                               NULL)
+PLUGIN_CLASS_MAP_END
diff --git a/src/standards/Tizen/Content/CMakeLists.txt b/src/standards/Tizen/Content/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..ac44496
--- /dev/null
@@ -0,0 +1,50 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-content") 
+set(DESTINATION_NAME  "tizen-2.0-content")
+set(TARGET_IMPL_NAME "wrt-plugins-tizen-2.0-content-impl")
+include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_CONTENT})
+
+set(CMAKE_INSTALL_RPATH
+  ${CMAKE_INSTALL_RPATH}
+  ${CMAKE_INSTALL_PREFIX}/tizen-2.0-tizen
+  ${CMAKE_INSTALL_PREFIX}/tizen-2.0-time
+  ${CMAKE_INSTALL_PREFIX}/${DESTINATION_NAME}
+)
+
+set(SRCS_IMPL
+  ${SRCS_PLATFORM_API_CONTENT}
+  ${SRCS_PLATFORM_IMPLEMENTATION_CONTENT}
+  ${SRCS_PLATFORM_API_WRT_WRAPPER}
+  JSFolder.cpp
+  JSMedia.cpp
+  JSImage.cpp
+  JSVideo.cpp
+  JSAudio.cpp
+  JSMediaLyrics.cpp
+  JSContentManager.cpp
+  ContentController.cpp
+  ContentConverter.cpp
+  ContentAsyncCallbackManager.cpp
+  MediaLyricsUtil.cpp
+)
+
+add_library(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
+target_link_libraries(${TARGET_IMPL_NAME}
+  ${LIBS_COMMON}
+  ${LIBS_PLATFORM_IMPLEMENTATION_CONTENT}
+)
+
+set(SRCS
+  plugin_config.cpp
+  plugin_initializer.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${TARGET_IMPL_NAME}
+  wrt-plugins-tizen-2.0-tizen-impl
+  wrt-plugins-tizen-2.0-time-impl
+)
+
+INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
+
diff --git a/src/standards/Tizen/Content/ContentAsyncCallbackManager.cpp b/src/standards/Tizen/Content/ContentAsyncCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..62bff3b
--- /dev/null
@@ -0,0 +1,31 @@
+//
+// 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 "ContentAsyncCallbackManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::Content::MediaContentAsyncCallbackManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+} // Mediacontent
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Content/ContentAsyncCallbackManager.h b/src/standards/Tizen/Content/ContentAsyncCallbackManager.h
new file mode 100755 (executable)
index 0000000..d5d8e0b
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// 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_CONTENT_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_CONTENT_ASYNC_CALLBACK_MANAGER_H_
+#include <dpl/singleton.h>
+#include <Tizen/Common/AsyncCallbackManager.h>
+ namespace TizenApis {
+ namespace Tizen1_0 {
+ namespace Content {
+ class MediaContentAsyncCallbackManager : public TizenApis::Commons::AsyncCallbackManager
+ {
+ public:
+        MediaContentAsyncCallbackManager()
+        {
+        }
+        virtual ~MediaContentAsyncCallbackManager()
+        {
+        }
+        friend class DPL::Singleton<MediaContentAsyncCallbackManager>;
+ };
+ typedef DPL::Singleton<MediaContentAsyncCallbackManager> MediaContentAsyncCallbackManagerSingleton;
+ } // Mediacontent
+ } // Tizen1_0
+ } // TizenApis
+#endif // _TIZEN_CONTENT_ASYNC_CALLBACK_MANAGER_H_
+
+
+
diff --git a/src/standards/Tizen/Content/ContentController.cpp b/src/standards/Tizen/Content/ContentController.cpp
new file mode 100755 (executable)
index 0000000..3dc4ad3
--- /dev/null
@@ -0,0 +1,163 @@
+//
+// 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/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include "ContentController.h"
+#include "ContentConverter.h"
+#include "ContentAsyncCallbackManager.h"
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+MediacontentManagerController& MediacontentManagerController::getInstance()
+{
+    static MediacontentManagerController instance;
+    return instance;
+}
+
+MediacontentManagerController::MediacontentManagerController():
+       EventBrowseFolderAnswerReceiver(ThreadEnum::NULL_THREAD),       
+       EventUpdateMediaItemsAnswerReceiver(ThreadEnum::NULL_THREAD),           
+       EventFindFolderAnswerReceiver(ThreadEnum::NULL_THREAD)
+{
+       LogDebug("create a MediacontentManagerController");
+}
+
+MediacontentManagerController::~MediacontentManagerController() 
+{
+       LogDebug("<<<");
+       LogDebug(">>>");
+}
+
+
+void MediacontentManagerController::OnAnswerReceived(const IEventUpdateMediaItemsPtr &event)
+{
+
+       LogDebug("MediacontentManagerController::IEventUpdateMediaItemsPtr:entered");
+
+    JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+    if(!cbm) 
+       {
+        LogError("no callback manager");
+        return;
+    }
+    Try
+    {
+       MediaContentAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+        if (event->getResult()) 
+               {
+                       cbm->callOnSuccess();
+        }
+        else
+        {
+                       JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                                       cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+                       cbm->callOnError(errorObject);
+        }
+        return;
+    }
+    Catch(Exception)
+    {
+        LogError("error during processing answer");
+    }
+}
+
+
+void MediacontentManagerController::OnAnswerReceived(const IEventBrowseFolderPtr &event)
+{
+
+       LogDebug("MediacontentManagerController::OnAnswerReceived:entered");
+
+    JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+    if (!cbm) 
+       {
+        LogError("no callback manager");
+        return;
+    }
+    Try
+    {
+       MediaContentAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+        if (event->getResult()) 
+               {
+            MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(cbm->getContext());
+            const std::vector<MediacontentMediaPtr> &results = event->getMedia();
+            JSValueRef result = converter->toJSValueRef(results);
+            cbm->callOnSuccess(result);
+        }
+        else
+        {
+                       JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                                       cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+                       cbm->callOnError(errorObject);
+        }        
+               return;
+    }
+    Catch(Exception)
+    {
+        LogError("error during processing answer");
+    }
+}
+
+
+
+void MediacontentManagerController::OnAnswerReceived(const IEventFindFolderPtr &event)
+{
+
+       LogDebug("MediacontentManagerController::OnAnswerReceived:entered");
+
+    JSCallbackManagerPtr cbm = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+    if (!cbm) 
+       {
+        LogError("no callback manager");
+        return;
+    }
+    Try
+    {
+       MediaContentAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+        if (event->getResult()) 
+               {
+            MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(cbm->getContext());
+            const std::vector<MediacontentFolderPtr> &results = event->getFolder();
+            JSValueRef result = converter->toJSValueRef(results);
+            cbm->callOnSuccess(result);
+        }
+        else
+        {
+                       JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                                       cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+                       cbm->callOnError(errorObject);
+        }        
+               return;
+    }
+    Catch(Exception)
+    {
+        LogError("error during processing answer");
+    }
+
+}
+
+
+}
+}
+}
+
diff --git a/src/standards/Tizen/Content/ContentController.h b/src/standards/Tizen/Content/ContentController.h
new file mode 100755 (executable)
index 0000000..d622ee6
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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_CONTROLLER_H_
+#define _TIZEN_CONTROLLER_H_
+
+#include <API/Content/IEventFindMedia.h>
+#include <API/Content/IEventFindFolder.h>
+#include <API/Content/IEventBrowseFolder.h>
+#include <API/Content/IEventUpdateMediaItems.h>
+
+using namespace TizenApis::Api::Content;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+typedef EventAnswerReceiver<IEventFindFolder> EventFindFolderAnswerReceiver;
+typedef EventAnswerReceiver<IEventBrowseFolder> EventBrowseFolderAnswerReceiver;
+typedef EventAnswerReceiver<IEventUpdateMediaItems> EventUpdateMediaItemsAnswerReceiver;
+
+class MediacontentManagerController :
+       public EventBrowseFolderAnswerReceiver,
+       public EventUpdateMediaItemsAnswerReceiver,
+       public EventFindFolderAnswerReceiver
+{
+    public:
+    static MediacontentManagerController& getInstance();
+
+    protected:
+       void OnAnswerReceived(const IEventFindFolderPtr &event);
+       void OnAnswerReceived(const IEventBrowseFolderPtr &event);      
+       void OnAnswerReceived(const IEventUpdateMediaItemsPtr &event);          
+
+    private:
+       MediacontentManagerController();
+       virtual ~MediacontentManagerController();       
+
+};
+
+}
+}
+} 
+
+#endif //_TIZEN_CONTROLLER_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/Content/ContentConverter.cpp b/src/standards/Tizen/Content/ContentConverter.cpp
new file mode 100755 (executable)
index 0000000..16bde3c
--- /dev/null
@@ -0,0 +1,135 @@
+//
+// 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/JSUtils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+
+#include "ContentConverter.h"
+#include "JSMedia.h"
+#include "JSImage.h"
+#include "JSVideo.h"
+#include "JSAudio.h"
+#include "JSFolder.h"
+#include "JSMediaLyrics.h"
+
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+MediaConverter::MediaConverter(JSContextRef context) : Converter(context)
+{
+    LogDebug("entered");
+}
+
+JSValueRef MediaConverter::toFunctionOrNull(const JSValueRef& arg)
+{
+    if (Validator(m_context).isCallback(arg)) 
+       {
+        return arg;
+    } else if (!JSValueIsNull(m_context,arg) && !JSValueIsUndefined(m_context, arg)) 
+    {
+        ThrowMsg(ConversionException, "Not a function nor JS null.");
+    }
+    return NULL;
+}
+
+JSValueRef MediaConverter::toFunction(const JSValueRef& arg)
+{
+    if (Validator(m_context).isCallback(arg)) 
+       {
+        return arg;
+    } else if (JSValueIsNull(m_context,arg) || JSValueIsUndefined(m_context, arg))
+    {
+        ThrowMsg(InvalidArgumentException, "JS null passed as function.");
+    }
+    ThrowMsg(ConversionException, "Not a function nor JS null.");
+}
+
+/*
+JSValueRef MediaConverter::toJSValueRefMediacontent(const IMediacontentPtr& arg)
+{
+    MediacontentPrivObject *priv = new MediacontentPrivObject(m_context, arg);
+    return JSObjectMake(m_context, JSMediacontent::getClassRef(), priv);
+}
+*/
+
+JSValueRef MediaConverter::toJSValueRefMedia(const MediacontentMediaPtr& arg)
+{
+       if(arg->getMediaType() == "IMAGE")
+       {
+           return JSUtils::makeObject(m_context, JSImage::getClassRef(), arg);
+       }
+       if(arg->getMediaType() == "VIDEO")
+       {
+           return JSUtils::makeObject(m_context, JSVideo::getClassRef(), arg);
+       }
+       if(arg->getMediaType() == "AUDIO")
+       {
+           return JSUtils::makeObject(m_context, JSAudio::getClassRef(), arg);
+       }
+       return JSUtils::makeObject(m_context, JSMedia::getClassRef(), arg);
+}
+
+JSValueRef MediaConverter::toJSValueRefFolder(const MediacontentFolderPtr& arg)
+{
+    return JSUtils::makeObject(m_context, JSFolder::getClassRef(), arg);
+}
+
+JSValueRef MediaConverter::toJSValueRef(const std::vector<MediacontentMediaPtr> &arg)
+{
+       return toJSValueRef_(arg, &MediaConverter::toJSValueRefMedia, this);
+}
+
+JSValueRef MediaConverter::toJSValueRef(const std::vector<MediacontentFolderPtr> &arg)
+{
+       return toJSValueRef_(arg, &MediaConverter::toJSValueRefFolder, this);
+}
+
+JSValueRef MediaConverter::toJSValueRef(const MediacontentLyricsPtr &arg)
+{
+       return JSUtils::makeObject(m_context, JSMediaLyrics::getClassRef(), arg);
+}
+
+
+
+MediacontentMediaListPtr MediaConverter::toVectorOfMediaItem(JSValueRef events)
+{
+    LogDebug("entered");
+    MediacontentMediaListPtr result(new MediacontentMediaList());
+
+    std::vector<MediacontentMediaPtr> resultVector;
+    JSObjectRef objArg = toJSObjectRef(events);
+    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);
+        JSObjectRef arg = JSValueToObject(m_context, element, NULL);
+        resultVector.push_back(JSMedia::getMediaObject(arg));
+    }
+    *result = resultVector;
+    return result;
+}
+
+
+
+
+}
+}
+}
diff --git a/src/standards/Tizen/Content/ContentConverter.h b/src/standards/Tizen/Content/ContentConverter.h
new file mode 100755 (executable)
index 0000000..4e771c8
--- /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_CONTENT_CONVERTER_H_
+#define _TIZEN_CONTENT_CONVERTER_H_
+
+#include <vector>
+#include <string>
+#include <CommonsJavaScript/Converter.h>
+#include <API/Content/MediacontentMedia.h>
+#include <API/Content/MediacontentFolder.h>
+#include <API/Content/MediacontentLyrics.h>
+
+using namespace TizenApis::Api::Content;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+       
+
+class MediaConverter : public Converter
+{
+       public:
+       using Converter::toJSValueRef;
+
+       public:
+       explicit MediaConverter(JSContextRef context);
+
+       //JSValueRef toJSValueRefMediacontent(const IMediacontentPtr& arg);
+
+       /**
+       * @throw InvalidArgumentException If not a callback nor JS null.
+       */
+       JSValueRef toFunctionOrNull(const JSValueRef& arg);
+
+       /**
+       * @throw ConversionException If JS null.
+       * @throw InvalidArgumentException If not a callback nor JS null.
+       */
+       JSValueRef toFunction(const JSValueRef& arg);
+       JSValueRef toJSValueRefMedia(const MediacontentMediaPtr& arg);
+       JSValueRef toJSValueRefFolder(const MediacontentFolderPtr& arg);
+       JSValueRef toJSValueRef(const std::vector<MediacontentMediaPtr> &arg);
+       JSValueRef toJSValueRef(const std::vector<MediacontentFolderPtr> &arg);
+       JSValueRef toJSValueRef(const MediacontentLyricsPtr &arg);
+
+       MediacontentMediaListPtr toVectorOfMediaItem(JSValueRef events);
+
+    
+};
+
+typedef ConverterFactory<MediaConverter> MediaConverterFactory;
+
+
+}
+}
+}
+
+#endif // _TIZEN_CONTENT_CONVERTER_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/Content/JSAudio.cpp b/src/standards/Tizen/Content/JSAudio.cpp
new file mode 100755 (executable)
index 0000000..f4296b2
--- /dev/null
@@ -0,0 +1,649 @@
+//
+// 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/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+
+#include "JSAudio.h"
+#include "JSMediaLyrics.h"
+#include "ContentConverter.h"
+#include "MediaLyricsUtil.h"
+
+
+#define TIZEN_CONTENT_AUDIO_ATTRIBUTENAME              "AudioContent"
+#define TIZEN_CONTENT_AUDIO_ALBUM                              "album"
+#define TIZEN_CONTENT_AUDIO_GENRE                              "genres"
+#define TIZEN_CONTENT_AUDIO_ARTIST                             "artists"
+#define TIZEN_CONTENT_AUDIO_COMPOSER                   "composers"
+#define TIZEN_CONTENT_AUDIO_LYIRICS                    "lyrics"
+#define TIZEN_CONTENT_AUDIO_COPYRIGHT                  "copyright"
+#define TIZEN_CONTENT_AUDIO_BITRATE                            "bitrate"
+#define TIZEN_CONTENT_AUDIO_TRACKNUM                   "trackNumber"
+#define TIZEN_CONTENT_AUDIO_DURATION                   "duration"
+#define TIZEN_CONTENT_AUDIO_SIZE                               "size"  
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Content;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+JSClassDefinition JSAudio::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       TIZEN_CONTENT_AUDIO_ATTRIBUTENAME,
+       JSMedia::getClassRef(),
+       m_property,
+       NULL, //    m_function,
+       initialize,
+       finalize,
+       NULL, //hasProperty,
+       NULL, //getProperty,
+       NULL, //setProperty,
+       NULL, //DeleteProperty,
+       NULL, //GetPropertyNames,
+       NULL, //CallAsFunction,
+       NULL, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL  //ConvertToType
+};
+
+JSStaticValue JSAudio::m_property[] =
+{
+       { TIZEN_CONTENT_AUDIO_ALBUM, getPropertyAlbum, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_AUDIO_ARTIST, getPropertyArtist, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_AUDIO_GENRE, getPropertyGenre, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_AUDIO_COMPOSER , getPropertyComposer, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_AUDIO_COPYRIGHT, getPropertyCopyright, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_AUDIO_LYIRICS, getPropertyLyrics, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_AUDIO_BITRATE, getPropertyBitrate, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_AUDIO_TRACKNUM, getPropertyTrackNum, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_AUDIO_DURATION, getPropertyDuration, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_AUDIO_SIZE, getPropertySize, NULL, kJSPropertyAttributeReadOnly},
+       { 0, 0, 0, 0 }
+};
+
+JSClassRef JSAudio::m_jsClassRef = JSClassCreate(JSAudio::getClassInfo());
+
+void JSAudio::initialize(JSContextRef context, JSObjectRef object)
+{
+    LogDebug( "entered" );
+    AudioPrivObject *priv = static_cast<AudioPrivObject*>( JSObjectGetPrivate( object ) );
+    if (!priv) 
+    {
+        MediacontentAudioPtr privateData(new MediacontentAudio());
+        priv = new AudioPrivObject(context, privateData);
+        JSObjectSetPrivate(object, static_cast<void*>(priv));
+        LogDebug("new Private Object is created" );
+    }
+    else {
+        LogDebug("private object already exists");
+    }
+}
+
+void JSAudio::finalize(JSObjectRef object)
+{
+    LogDebug( "entered" );
+       AudioPrivObject *priv =  static_cast<AudioPrivObject*>( JSObjectGetPrivate( object ) ) ;
+       if (priv != NULL)
+       {
+               delete (priv);
+               priv = NULL;
+               JSObjectSetPrivate(object, NULL);               
+       }
+}
+
+const JSClassRef JSAudio::getClassRef()
+{
+       LogDebug("JSAudio::getClassRef()");
+
+    if (!m_jsClassRef) 
+    {
+            m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSAudio::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+
+MediacontentAudioPtr JSAudio::getAudioObject(JSObjectRef object)
+{
+    LogDebug("entered");
+    AudioPrivObject *priv = static_cast<AudioPrivObject*>(JSObjectGetPrivate(object));
+    if(!priv) 
+    {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    MediacontentAudioPtr result = priv->getObject();
+    if (!result) 
+    {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    return result;
+}
+                                       
+JSValueRef JSAudio::getPropertyAlbum(
+                               JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+        return converter.toJSValueRef(audio->getAudioAlbum());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAudio::getPropertyArtist(
+                               JSContextRef context,
+                               JSObjectRef object,
+                               JSStringRef propertyName,
+                               JSValueRef* exception)
+{
+    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;  
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+
+JSValueRef JSAudio::getPropertyGenre(
+                               JSContextRef context,
+                       JSObjectRef object, 
+                       JSStringRef propertyName, 
+                       JSValueRef* exception)
+{
+    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;
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSAudio::getPropertyComposer(
+                               JSContextRef context,
+                       JSObjectRef object, 
+                       JSStringRef propertyName, 
+                       JSValueRef* exception)
+{
+    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;
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAudio::getPropertyCopyright(
+                               JSContextRef context,
+                       JSObjectRef object, 
+                       JSStringRef propertyName, 
+                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+        return converter.toJSValueRef(audio->getAudioCopyright());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAudio::getPropertyLyrics(
+                               JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+               MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+
+       AudioPrivObject *priv = static_cast<AudioPrivObject*>(JSObjectGetPrivate(object));
+       if(!priv) 
+       {
+               ThrowMsg(NullPointerException, "Private object is null");
+       }
+       MediacontentAudioPtr audio = priv->getObject();
+       if (!audio) 
+       {
+               ThrowMsg(NullPointerException, "Private object is null");
+       }
+       
+       JSContextRef globalContext = priv->getContext();
+
+       //check lyrics state
+       LogDebug("lyrics state : " << audio->getLyricsState());
+
+       if ( CONTENT_LYRIC_UNKNOWN == audio->getLyricsState()  ||
+               CONTENT_LYRIC_EXISTENT == audio->getLyricsState() )
+       {
+               
+               MediacontentLyricsPtr mediaContent;
+
+               if ( audio->getLyricsState() == CONTENT_LYRIC_UNKNOWN )
+               {
+                       mediaContent = MediaLyricsUtilSingleton::Instance().fetchLyrics(audio->getFilePath());
+                       if ( mediaContent )
+                               audio->setAudioLyrics(mediaContent);
+                       else
+                               audio->setAudioLyricNonExistent();
+               }
+               else
+               {
+                       mediaContent = audio->getAudioLyrics();
+               }
+               
+               if (mediaContent)
+               {
+                       LogDebug(" lyrics success ");
+                       JSObjectRef jsobject;
+                       jsobject = JSMediaLyrics::createJSObject(globalContext, mediaContent);
+                       return jsobject;        
+               }
+               else
+               {
+                       LogDebug(" lyrics success ");
+                       audio->setAudioLyricNonExistent();
+               }
+       }
+       
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAudio::getPropertyBitrate(
+                               JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+        return converter.toJSValueRef(audio->getAudioBitrate());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAudio::getPropertyTrackNum(
+                               JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+        return converter.toJSValueRef(audio->getAudioTrackNum());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAudio::getPropertyDuration(
+                               JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+        return converter.toJSValueRef(audio->getAudioDuration());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAudio::getPropertySize(
+                               JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+        double audioSize = (double)audio->getAudioSize();
+        return converter.toJSValueRef(audioSize);
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSAudio::setPropertyAlbum(
+                  JSContextRef context,
+                  JSObjectRef object,
+                  JSStringRef propertyName,
+                  JSValueRef value,
+                  JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+                       
+        MediacontentAudioPtr audio = getAudioObject(object);
+        string album = converter.toString(value);
+        audio->setAudioAlbum(album, true);
+        return true;
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to set incorrect value");
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+       return false;
+
+}
+
+bool  JSAudio::setPropertyArtist(
+                  JSContextRef context,
+                  JSObjectRef object,
+                  JSStringRef propertyName,
+                  JSValueRef value,
+                  JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+
+       vector<std::string> artists;
+       if (!JSValueIsNull(context, value)) {
+               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));
+               }
+       }
+               else
+               {
+                       TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+                       return false;
+               }
+       }
+       else
+       {
+               artists.push_back(converter.toString(value));
+       }
+       
+        audio->setAudioArtist(artists, true);
+       return true;
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to set incorrect value");
+        return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+       
+       return false;
+}
+
+
+bool JSAudio::setPropertyComposer(
+                  JSContextRef context,
+                  JSObjectRef object,
+                  JSStringRef propertyName,
+                  JSValueRef value,
+                  JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+
+       vector<std::string> composers;
+       if (!JSValueIsNull(context, value) ) 
+       {
+               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);
+                       composers.push_back(converter.toString(element));
+               }
+       }
+       }
+       else
+       {
+               composers.push_back(converter.toString(value));
+       }
+
+        audio->setAudioComposer(composers, true);
+       return true;
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to set incorrect value");
+        return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+       
+       return false;
+}
+
+bool   JSAudio::setPropertyGenre(
+               JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception) 
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentAudioPtr audio = getAudioObject(object);
+
+       vector<std::string> genres;
+       if (!JSValueIsNull(context, value) ) 
+       {
+               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);
+                       genres.push_back(converter.toString(element));
+               }
+
+               }
+       }
+       else
+       {
+               genres.push_back(converter.toString(value));
+       }
+
+       audio->setAudioGenre(genres, true);
+       return true;
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to set incorrect value");
+        return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+       return false;
+}
+
+bool JSAudio::setPropertyTrackNumber(
+       JSContextRef context,
+       JSObjectRef object,
+       JSStringRef propertyName,
+       JSValueRef value,
+       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+                       
+        MediacontentAudioPtr audio = getAudioObject(object);
+        int trackNum = converter.toInt(value);
+        audio->setAudioTrackNum(trackNum, true);
+        return true;
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to set incorrect value");
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+       return false;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Content/JSAudio.h b/src/standards/Tizen/Content/JSAudio.h
new file mode 100755 (executable)
index 0000000..f160eab
--- /dev/null
@@ -0,0 +1,201 @@
+//
+// 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 _JS_TIZEN_AUDIO_H_
+#define _JS_TIZEN_AUDIO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Content/MediacontentMedia.h>
+#include <API/Content/MediacontentAudio.h>
+#include "JSMedia.h"
+
+using namespace TizenApis::Api::Content;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+typedef PrivateObject<MediacontentAudioPtr, NoOwnership> AudioPrivObject;
+
+class JSAudio
+{
+public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+       static Api::Content::MediacontentAudioPtr getAudioObject(JSObjectRef object);
+
+private:
+    /**
+     * 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;
+
+    /**
+     * 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);
+
+
+
+    /**
+     * Getters and setters for properties
+     */
+
+    static JSValueRef  getPropertyAlbum(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static JSValueRef  getPropertyArtist(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static JSValueRef  getPropertyGenre(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static JSValueRef  getPropertyComposer(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+       static JSValueRef       getPropertyLyrics(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+
+    static JSValueRef  getPropertyCopyright(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static JSValueRef  getPropertyBitrate(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static JSValueRef  getPropertyTrackNum(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+    
+    static JSValueRef  getPropertyDuration(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);    
+
+
+    static JSValueRef  getPropertySize(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);         
+
+    static bool                setPropertyPlayedTime(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef value,
+                                       JSValueRef* exception); 
+
+       static bool                     setPropertyPlayCount(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                   JSValueRef value,
+                                               JSValueRef* exception);  
+
+       static bool        setPropertyAlbum(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                  JSValueRef value,
+                                       JSValueRef* exception);    
+
+       static bool        setPropertyArtist(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                   JSValueRef value,
+                                               JSValueRef* exception);  
+
+       static bool        setPropertyComposer(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                  JSValueRef value,
+                                       JSValueRef* exception);    
+
+       static bool setPropertyGenre(
+                               JSContextRef context,
+                               JSObjectRef object,
+                               JSStringRef propertyName,
+                               JSValueRef value,
+                               JSValueRef* exception);  
+
+       static bool setPropertyTrackNumber(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                  JSValueRef value,
+                                       JSValueRef* exception);                 
+
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_AUDIO_H_ */
diff --git a/src/standards/Tizen/Content/JSContentManager.cpp b/src/standards/Tizen/Content/JSContentManager.cpp
new file mode 100755 (executable)
index 0000000..b038e35
--- /dev/null
@@ -0,0 +1,667 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSPendingOperation.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Tizen/Tizen/FilterConverter.h>
+
+#include <API/Content/MediacontentFactory.h>
+#include "ContentController.h"
+#include "JSContentManager.h"
+#include "JSMedia.h"
+#include "JSImage.h"
+#include "JSVideo.h"
+#include "JSAudio.h"
+#include "ContentConverter.h"
+#include "plugin_config.h"
+#include "ContentAsyncCallbackManager.h"
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Tizen;
+using namespace TizenApis::Tizen1_0::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+#define TIZEN_CONTENT_MANAGER_ATTRIBUTENAME                            "content"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+JSStaticValue JSMediacontentManager::m_property[] =
+{
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSMediacontentManager::m_function[] = 
+{
+       { "find", findItems, kJSPropertyAttributeNone },
+       { "getDirectories", getFolders, kJSPropertyAttributeNone },
+       { "update", updateItem, kJSPropertyAttributeNone },        
+       { "updateBatch", updateItemsBatch, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+
+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
+};
+
+JSValueRef JSMediacontentManager::getFolders(
+                                                       JSContextRef context, 
+                                                       JSObjectRef object,
+                                                       JSObjectRef thisObject, 
+                                                       size_t argumentCount,
+                                                       const JSValueRef arguments[], 
+                                                       JSValueRef* exception )
+{
+       LogDebug("JSMediacontentManager::getFolders 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_GET_FOLDERS);
+
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       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);
+       cbm->setObject(thisObject);
+
+    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
+                       {
+                               LogDebug("SuccessCallback type mismatched.");
+                               Throw(ConversionException);
+                       }
+               }
+               else
+               {
+                       LogDebug("There is no successCallback.");
+                       Throw(ConversionException);
+               }               
+               if(argumentCount >= 2)  //optional ErrorCallback? errorCallback
+               {       
+                       if(validator.isCallback(arguments[1]))
+                       {
+                               onErrorForCbm = arguments[1];
+                       }
+                       else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
+                       {
+                               LogDebug("ErrorCallback type mismatched.");
+                               Throw(ConversionException);                             
+                       }
+               }
+               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);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_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);
+
+}
+
+
+
+JSValueRef JSMediacontentManager::findItems(
+                                                       JSContextRef context, 
+                                                       JSObjectRef object,
+                                                       JSObjectRef thisObject, 
+                                                       size_t argumentCount,
+                                                       const JSValueRef arguments[], 
+                                                       JSValueRef* exception )
+{
+
+       LogDebug("JSMediacontentManager::findItems 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_FIND_ITEMS);
+
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+
+       JSContextRef globalContext = privateObject->getContext();
+       Validator validator(context);
+    JSCallbackManagerPtr cbm(NULL);
+    FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+       MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
+       MediaConverter mediaConverter(globalContext);
+
+       cbm = JSCallbackManager::createObject(globalContext);
+       cbm->setObject(thisObject);
+
+
+    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
+                       {
+                               LogDebug("SuccessCallback type mismatched.");
+                               Throw(ConversionException);
+                       }
+               }
+               else
+               {
+                       LogDebug("There is no SuccessCallback.");
+                       Throw(ConversionException);
+               }  
+               if(argumentCount >= 2)  //ErrorCallback? errorCallback
+               {       
+                       if(validator.isCallback(arguments[1]))
+                       {
+                               onErrorForCbm = arguments[1];
+                       }
+                       else if(!validator.isNullOrUndefined(arguments[1]))             //nullable
+                       {
+                               LogDebug("ErrorCallback type mismatched.");
+                               Throw(ConversionException);                             
+                       }
+               }
+               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
+                       {
+                               LogDebug("Filter type mismatched.");
+                               Throw(ConversionException);
+                       }
+               }
+               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
+                       {
+                               LogDebug("SortMode type mismatched.");
+                               Throw(ConversionException);
+                       }
+               }
+               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.");
+                       }
+               }
+        dplEvent->setPrivateData( DPL::StaticPointerCast<IEventPrivateData> (cbm));
+        dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance());
+        contentMgr->browseFolder(dplEvent);
+
+       MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_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);
+}
+
+
+
+JSValueRef JSMediacontentManager::updateItemsBatch(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("JSMediacontentManager::updateItemsBatch entered");
+       MediacontentManagerPrivObject *privateObject;
+       privateObject = static_cast<MediacontentManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong object");
+       }
+       
+
+       JSContextRef globalContext = privateObject->getContext();
+       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
+                       {
+                               LogDebug("successCallback type mismatched.");
+                               Throw(ConversionException);                             
+                       }
+               }
+       
+               if(argumentCount >= 3)  //ErrorCallback? errorCallback, 
+               {       
+                       if(validator.isCallback(arguments[2]))
+                       {
+                               onErrorForCbm = arguments[2];
+                       }
+                       else if(!validator.isNullOrUndefined(arguments[2]))             //nullable
+                       {
+                               LogDebug("ErrorCallback type is mismatched.");
+                               Throw(ConversionException);                             
+                       }
+               }
+
+               if(cbm)
+               {
+                       cbm->setOnSuccess(onSuccessForCbm);
+                       cbm->setOnError(onErrorForCbm);
+               }
+               
+        IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems());
+        dplEvent->setMediaItems(events);
+        dplEvent->setPrivateData(DPL::StaticPointerCast<IEventPrivateData>(cbm));
+        
+        dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance()); 
+        contentMgr->updateMediaItems(dplEvent);
+
+       MediaContentAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_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);
+}
+
+
+
+JSValueRef JSMediacontentManager::updateItem(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSObjectRef thisObject,
+                                               size_t argumentCount,
+                                               const JSValueRef arguments[],
+                                               JSValueRef* exception)
+{
+LogDebug("JSMediacontentManager::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);
+
+       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 = JSMedia::getMediaObject(arg);
+
+               IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia());
+               dplEvent->setMediaItem(event);
+               dplEvent->setForSynchronousCall();
+               contentMgr->updateMedia(dplEvent);
+
+        if (!(dplEvent->getResult())) {
+            ThrowMsg(UnknownException, "updating failed by unknown reason.");
+        }
+       }
+       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(ConversionException)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+       }
+       Catch (NotFoundException)
+       {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_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);
+
+}
+
+
+const JSClassRef JSMediacontentManager::getClassRef() {
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+
+const JSClassDefinition* JSMediacontentManager::getClassInfo() 
+{
+       return &m_classInfo;
+}
+
+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;
+        }
+    }
+
+}
+
+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;
+       }
+
+}
+
+IMediacontentManagerPtr JSMediacontentManager::getContentManagerPrivObject(
+                                               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.");
+}
+
+
+}
+} 
+} 
+
diff --git a/src/standards/Tizen/Content/JSContentManager.h b/src/standards/Tizen/Content/JSContentManager.h
new file mode 100755 (executable)
index 0000000..1e42453
--- /dev/null
@@ -0,0 +1,146 @@
+//
+// 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 _JS_TIZEN_CONTENTMANAGER_H_
+#define _JS_TIZEN_CONTENTMANAGER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <API/Content/IMediacontentManager.h>
+
+using namespace TizenApis::Api::Content;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+typedef PrivateObject<IMediacontentManagerPtr, NoOwnership> MediacontentManagerPrivObject;
+
+class JSMediacontentManager 
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+       static const JSClassRef getClassRef();
+
+private:
+
+/*
+static JSValueRef getMediacontent(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSObjectRef thisObject,
+                                       size_t argumentCount,
+                                       const JSValueRef arguments[],
+                                       JSValueRef* exception);
+*/
+       static IMediacontentManagerPtr getContentManagerPrivObject(
+                       JSContextRef ctx,
+                       const JSObjectRef object,
+                       JSValueRef* exception);
+
+           
+       /**
+        * 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 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);
+
+
+       static JSValueRef getFolders(
+                       JSContextRef context, 
+                       JSObjectRef object,
+                       JSObjectRef thisObject, 
+                       size_t argumentCount,
+                       const JSValueRef arguments[], 
+                       JSValueRef* exception);
+
+       static JSValueRef updateItem(
+                       JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef updateItemsBatch(
+                       JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef thisObject,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+                       
+
+       static JSValueRef findItems(
+                       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;
+       static JSStaticFunction m_function[];
+
+       /**
+        * This structure describes a statically declared value property.
+        */
+       static JSStaticValue m_property[];
+
+       static JSClassRef m_jsClassRef;
+};
+
+} // MediaContent
+} // Tizen1_0
+} // TizenApi 
+
+#endif //_JS_TIZEN_CONTENTMANAGER_H_
+
diff --git a/src/standards/Tizen/Content/JSFolder.cpp b/src/standards/Tizen/Content/JSFolder.cpp
new file mode 100755 (executable)
index 0000000..f8c48a9
--- /dev/null
@@ -0,0 +1,298 @@
+//
+// 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/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <API/Content/MediacontentFactory.h>
+#include "ContentController.h"
+#include "JSFolder.h"
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+#define TIZEN_CONTENT_FOLDER_ATTRIBUTENAME             "ContentDirectory"
+#define TIZEN_CONTENT_FOLDER_UID                               "id"
+#define TIZEN_CONTENT_FOLDER_NAME                              "title"
+#define TIZEN_CONTENT_FOLDER_PATH                              "directoryURI"
+#define TIZEN_CONTENT_FOLDER_STORAGE_TYPE              "storageType"
+#define TIZEN_CONTENT_FOLDER_MODIFIEDDATE              "modifiedDate"
+
+
+JSClassDefinition JSFolder::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    TIZEN_CONTENT_FOLDER_ATTRIBUTENAME,
+    0,
+    m_property,
+    m_function, //    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL  //ConvertToType
+};
+
+JSStaticValue JSFolder::m_property[] =
+{
+    //FolderProperties
+    { TIZEN_CONTENT_FOLDER_UID, getPropertyId, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_FOLDER_NAME, getPropertyName, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_FOLDER_PATH, getPropertyPath, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_FOLDER_STORAGE_TYPE, getPropertyStorageType, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_FOLDER_MODIFIEDDATE, getPropertyModifiedDate, NULL, kJSPropertyAttributeReadOnly}, 
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSFolder::m_function[] =
+{
+    { 0, 0, 0 }
+};
+
+
+JSClassRef JSFolder::m_jsClassRef = JSClassCreate(JSFolder::getClassInfo());
+
+void JSFolder::initialize(JSContextRef context, JSObjectRef object)
+{
+    LogDebug( "entered" );
+    FolderPrivObject *priv = static_cast<FolderPrivObject*>( JSObjectGetPrivate( object ) );
+    if (!priv) 
+       {
+        MediacontentFolderPtr privateData(new MediacontentFolder());
+        priv = new FolderPrivObject(context, privateData);
+        JSObjectSetPrivate(object, static_cast<void*>(priv));
+        LogDebug("new event is created" );
+    }
+    else 
+       {
+        LogDebug("private object already exists");
+    }
+}
+
+
+void JSFolder::finalize(JSObjectRef object)
+{
+    LogDebug( "entered" );
+    FolderPrivObject *priv = static_cast<FolderPrivObject*>( JSObjectGetPrivate( object ) ) ;
+       if (priv != NULL)
+       {
+               delete (priv);
+               priv = NULL;
+               JSObjectSetPrivate(object, NULL);               
+       }
+
+}
+
+
+
+const JSClassRef JSFolder::getClassRef()
+{
+    if (!m_jsClassRef) 
+       {
+            m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSFolder::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+
+MediacontentFolderPtr JSFolder::getFolderObject(JSObjectRef object)
+{
+    LogDebug("entered");
+    FolderPrivObject *priv = static_cast<FolderPrivObject*>(JSObjectGetPrivate(object));
+    if(!priv) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    MediacontentFolderPtr result = priv->getObject();
+    if (!result) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    return result;
+}
+
+
+
+JSValueRef JSFolder::getPropertyId(
+               JSContextRef context, 
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentFolderPtr folder = getFolderObject(object);
+
+        return converter.toJSValueRef(folder->getFolderUUID());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+
+}
+                                       
+JSValueRef JSFolder::getPropertyName(
+               JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentFolderPtr folder = getFolderObject(object);
+        return converter.toJSValueRef(folder->getFolderName());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSFolder::getPropertyPath(
+               JSContextRef context,
+           JSObjectRef object, 
+           JSStringRef propertyName, 
+           JSValueRef* exception)
+{
+    LogDebug("getPropertyPath::entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentFolderPtr folder = getFolderObject(object);
+        return converter.toJSValueRef(folder->getFolderPath());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSFolder::getPropertyStorageType(
+               JSContextRef context,
+           JSObjectRef object,
+           JSStringRef propertyName,
+           JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentFolderPtr folder = getFolderObject(object);
+        return converter.toJSValueRef(folder->getFolderStorageType());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSFolder::getPropertyModifiedDate(
+               JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentFolderPtr folder = getFolderObject(object);
+        return converter.toJSValueRef(folder->getFolderModifiedDate());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef     JSFolder::getPropertyMediaId(
+               JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentFolderPtr folder = getFolderObject(object);
+        //folder->getMediaIdList()
+        //MediaIdListPtr       getMediaIdList() const; 
+               //typedef vector<std::string> MediaIdList;
+               //typedef DPL::SharedPtr<MediaIdList> MediaIdListPtr;
+               MediaIdListPtr mediaIdLstPtr = folder->getMediaIdList();
+               JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+
+               if(mediaIdLstPtr)
+               {
+                       if (NULL == jsResult) 
+                       {
+                ThrowMsg(NullPointerException, "Could not create js array object");
+            }
+            for(unsigned int i=0; i<mediaIdLstPtr->size(); i++) 
+            {
+               JSValueRef val = converter.toJSValueRef(mediaIdLstPtr->at(i));
+                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);
+
+}
+
+
+
+}
+}
+}
diff --git a/src/standards/Tizen/Content/JSFolder.h b/src/standards/Tizen/Content/JSFolder.h
new file mode 100755 (executable)
index 0000000..e85c5fe
--- /dev/null
@@ -0,0 +1,130 @@
+//
+// 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 _JS_TIZEN_FOLDER_H_
+#define _JS_TIZEN_FOLDER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Content/MediacontentFolder.h>
+
+using namespace TizenApis::Api::Content;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+
+typedef PrivateObject<MediacontentFolderPtr, NoOwnership> FolderPrivObject;
+
+class JSFolder
+{
+       public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       static MediacontentFolderPtr getFolderObject(JSObjectRef object);
+
+       private:
+       /**
+       * 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;
+
+       /**
+       * 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);
+
+       /**
+       * Getters and setters for properties
+       */
+       static JSValueRef       getPropertyId(
+                       JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+       
+       static JSValueRef       getPropertyPath(
+                       JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef       getPropertyName(
+                       JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef       getPropertyStorageType(
+                       JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef       getPropertyModifiedDate(
+                       JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static JSValueRef       getPropertyMediaId(
+                       JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+       
+       static JSValueRef       getPropertyEditableAttr(
+                       JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_FOLDER_H_ */
diff --git a/src/standards/Tizen/Content/JSImage.cpp b/src/standards/Tizen/Content/JSImage.cpp
new file mode 100755 (executable)
index 0000000..1833581
--- /dev/null
@@ -0,0 +1,294 @@
+//
+// 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/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <Tizen/Tizen/JSSimpleCoordinates.h>
+
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "JSImage.h"
+
+
+#define TIZEN_CONTENT_IMAGE_ATTRIBUTENAME              "ImageContent"
+#define TIZEN_CONTENT_IMAGE_GEOLOCATION                        "geolocation"
+#define TIZEN_CONTENT_IMAGE_WIDTH                              "width"
+#define TIZEN_CONTENT_IMAGE_HEIGHT                             "height"
+#define TIZEN_CONTENT_IMAGE_ORIENTATION                        "orientation"
+
+using namespace TizenApis::Tizen1_0::Tizen;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Api::Tizen;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+
+JSClassDefinition JSImage::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       TIZEN_CONTENT_IMAGE_ATTRIBUTENAME,
+       JSMedia::getClassRef(),
+       m_property,
+       NULL, //    m_function,
+       initialize,
+       finalize,
+       NULL, //hasProperty,
+       NULL, //getProperty,
+       NULL, //setProperty,
+       NULL, //DeleteProperty,
+       NULL, //GetPropertyNames,
+       NULL, //CallAsFunction,
+       NULL, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL  //ConvertToType
+};
+
+JSStaticValue JSImage::m_property[] =
+{
+//    { TIZEN_CONTENT_IMAGE_UID, getPropertyUid, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_IMAGE_GEOLOCATION, getPropertyGeoLocation, setPropertyGeolocation, kJSPropertyAttributeNone},
+    { TIZEN_CONTENT_IMAGE_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_IMAGE_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly},    
+    { TIZEN_CONTENT_IMAGE_ORIENTATION, getPropertyOrientation, setPropertyOrientation, kJSPropertyAttributeNone},  
+    { 0, 0, 0, 0 }
+};
+
+
+JSClassRef JSImage::m_jsClassRef = JSClassCreate(JSImage::getClassInfo());
+
+void JSImage::initialize(JSContextRef context, JSObjectRef object)
+{
+    LogDebug( "entered" );
+    ImagePrivObject *priv =
+            static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) );
+    if (!priv) {
+        MediacontentImagePtr privateData(new MediacontentImage());
+        priv = new ImagePrivObject(context, privateData);
+        JSObjectSetPrivate(object, static_cast<void*>(priv));
+        LogDebug("new private object is created" );
+    }
+    else {
+        LogDebug("private object already exists");
+    }
+}
+
+void JSImage::finalize(JSObjectRef object)
+{
+    LogDebug( "entered" );
+       ImagePrivObject *priv = static_cast<ImagePrivObject*>( JSObjectGetPrivate( object ) ) ;
+       if (priv != NULL)
+       {
+               delete (priv);
+               priv = NULL;
+               JSObjectSetPrivate(object, NULL);               
+       }
+}
+
+const JSClassRef JSImage::getClassRef()
+{
+       LogDebug("JSImage::getClassRef()");
+
+    if (!m_jsClassRef) {
+            m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSImage::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+MediacontentImagePtr JSImage::getImageObject(JSObjectRef object)
+{
+    LogDebug("entered");
+    ImagePrivObject *priv = static_cast<ImagePrivObject*>(JSObjectGetPrivate(object));
+    if(!priv) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    MediacontentImagePtr result = priv->getObject();
+    if (!result) {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    return result;
+}
+                                       
+JSValueRef JSImage::getPropertyGeoLocation(
+               JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentImagePtr image = getImageObject(object);
+
+               LogDebug("lati :"  << image->getImageLatitude());
+               LogDebug("longi :"  << image->getImageLongitude());             
+               TizenApis::Api::Tizen::SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(image->getImageLatitude(),image->getImageLongitude()));
+               return JSSimpleCoordinates::createJSObject(context,geoPtr);
+
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSImage::getPropertyWidth(
+               JSContextRef context,
+        JSObjectRef object, 
+        JSStringRef propertyName, 
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentImagePtr image = getImageObject(object);
+        return converter.toJSValueRef(image->getImageWidth());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSImage::getPropertyHeight(
+               JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentImagePtr image = getImageObject(object);
+        return converter.toJSValueRef(image->getImageHeight());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSImage::getPropertyOrientation(
+               JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentImagePtr image = getImageObject(object);
+        return converter.toJSValueRef(image->getImageOrientation());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool   JSImage::setPropertyOrientation(
+                               JSContextRef context,
+                               JSObjectRef object,
+                               JSStringRef propertyName,
+                               JSValueRef value,
+                               JSValueRef* exception)
+{
+        LogDebug("entered");
+        Try
+           {
+               Converter converter(context);
+               MediacontentImagePtr objImg = getImageObject(object);
+
+               string orientation = converter.toString(value);
+               LogDebug("Inserted value : " << orientation);
+
+               if ((objImg->getImageOrientation()).compare(orientation) !=0 )
+               {
+                       objImg->setImageOrientation(orientation, true);
+               }
+               
+               return true;                    
+           }
+           Catch(Exception)
+           {
+               LogWarning("trying to get incorrect value");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR);
+           }
+
+          return false;
+}
+
+bool   JSImage::setPropertyGeolocation(
+                               JSContextRef context,
+                               JSObjectRef object,
+                               JSStringRef propertyName,
+                               JSValueRef value,
+                               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       Try
+       {
+               Converter converter(context);
+               MediacontentImagePtr objImg = getImageObject(object);
+
+               TizenApis::Api::Tizen::SimpleCoordinatesPtr geoLocation =
+                       TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
+
+               objImg->setImageLatitude(geoLocation->getLatitude());
+               objImg->setImageLongitude(geoLocation->getLongitude());
+       
+               return true;
+       }
+       Catch(Exception)
+       {
+               LogWarning("trying to get incorrect value");
+               TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+       }
+
+       return false;
+
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Content/JSImage.h b/src/standards/Tizen/Content/JSImage.h
new file mode 100755 (executable)
index 0000000..c231502
--- /dev/null
@@ -0,0 +1,138 @@
+//
+// 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 _JS_TIZEN_IMAGE_H_
+#define _JS_TIZEN_IMAGE_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Content/MediacontentMedia.h>
+#include <API/Content/MediacontentImage.h>
+#include <API/Filter/SimpleCoordinates.h>
+
+#include "JSMedia.h"
+
+
+using namespace TizenApis::Api::Content;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+typedef PrivateObject<MediacontentImagePtr, NoOwnership> ImagePrivObject;
+
+class JSImage
+{
+public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+    static MediacontentImagePtr getImageObject(JSObjectRef object);
+
+
+private:
+    /**
+     * 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;
+
+    /**
+     * 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);
+
+
+
+    /**
+     * Getters and setters for properties
+     */
+       
+    static JSValueRef  getPropertyGeoLocation(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static JSValueRef  getPropertyWidth(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static JSValueRef  getPropertyHeight(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+    
+
+    static JSValueRef  getPropertyOrientation(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);    
+
+      static bool              setPropertyGeolocation(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef value,
+                                       JSValueRef* exception); 
+         
+    static bool                setPropertyOrientation(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef value,
+                                       JSValueRef* exception); 
+
+
+
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_IMAGE_H_ */
diff --git a/src/standards/Tizen/Content/JSMedia.cpp b/src/standards/Tizen/Content/JSMedia.cpp
new file mode 100755 (executable)
index 0000000..acd70c7
--- /dev/null
@@ -0,0 +1,543 @@
+//
+// 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/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+
+
+#include "JSMedia.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+#define TIZEN_CONTENT_MEDIA_ATTRIBUTENAME              "Content"
+#define TIZEN_CONTENT_MEDIA_UID                                        "id"
+#define TIZEN_CONTENT_MEDIA_TYPE                               "type"
+#define TIZEN_CONTENT_MEDIA_MIME_TYPE                  "mimeType"
+#define TIZEN_CONTENT_MEDIA_TITLE                              "title"
+#define TIZEN_CONTENT_MEDIA_FILE_URL                   "contentURI"
+#define TIZEN_CONTENT_MEDIA_THUMBNAILPATH              "thumbnailURIs"
+#define TIZEN_CONTENT_MEDIA_RELEASEDDATE               "releaseDate"   
+#define TIZEN_CONTENT_MEDIA_MODIFIEDDATE               "modifiedDate"  
+#define TIZEN_CONTENT_MEDIA_DESCRIPTION                "description"   
+#define TIZEN_CONTENT_MEDIA_RATING                             "rating"        
+#define TIZEN_CONTENT_MEDIA_SIZE                               "size"  
+#define TIZEN_CONTENT_MEDIA_EDIABLEATTR                        "editableAttributes"    
+
+
+JSClassDefinition JSMedia::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    TIZEN_CONTENT_MEDIA_ATTRIBUTENAME,
+    0,
+    m_property,
+    NULL, //    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL  //ConvertToType
+};
+
+
+JSStaticValue JSMedia::m_property[] =
+{
+    //EventProperties
+    { TIZEN_CONTENT_MEDIA_UID, getPropertyId, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_MEDIA_TYPE, getPropertyType , NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_MEDIA_MIME_TYPE, getPropertyMimeType , NULL, kJSPropertyAttributeReadOnly},    
+    { TIZEN_CONTENT_MEDIA_TITLE, getPropertyDisplayName, setPropertyDisplayName, kJSPropertyAttributeNone},
+    { TIZEN_CONTENT_MEDIA_FILE_URL, getPropertyFilePath, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_MEDIA_THUMBNAILPATH, getPropertyThumbnailPath, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_MEDIA_RELEASEDDATE, getPropertyReleasedDate, NULL, kJSPropertyAttributeReadOnly},    
+    { TIZEN_CONTENT_MEDIA_MODIFIEDDATE, getPropertyModifiedDate, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_MEDIA_DESCRIPTION, getPropertyDescription, setPropertyDescription, kJSPropertyAttributeNone},    
+    { TIZEN_CONTENT_MEDIA_SIZE, getPropertySize, NULL, kJSPropertyAttributeReadOnly},     
+    { TIZEN_CONTENT_MEDIA_EDIABLEATTR, getPropertyEditableAttr, NULL, kJSPropertyAttributeReadOnly},        
+    { TIZEN_CONTENT_MEDIA_RATING, getPropertyRating, setPropertyRating, kJSPropertyAttributeNone},        
+    { 0, 0, 0, 0 }
+};
+
+
+JSClassRef JSMedia::m_jsClassRef = JSClassCreate(JSMedia::getClassInfo());
+
+void JSMedia::initialize(JSContextRef context, JSObjectRef object)
+{
+    LogDebug( "entered" );
+    MediaPrivObject *priv = static_cast<MediaPrivObject*>( JSObjectGetPrivate( object ) );
+    if (!priv) 
+       {
+        MediacontentMediaPtr privateData(new MediacontentMedia());
+        priv = new MediaPrivObject(context, privateData);
+        JSObjectSetPrivate(object, static_cast<void*>(priv));
+        LogDebug("new event is created" );
+    }
+    else 
+       {
+        LogDebug("private object already exists");
+    }
+}
+
+void JSMedia::finalize(JSObjectRef object)
+{
+    LogDebug( "entered" );
+    MediaPrivObject *priv = static_cast<MediaPrivObject*>( JSObjectGetPrivate( object ) ) ;
+       if (priv != NULL)
+       {
+               delete (priv);
+               priv = NULL;
+               JSObjectSetPrivate(object, NULL);
+       }
+    
+}
+
+const JSClassRef JSMedia::getClassRef()
+{
+       LogDebug("JSMedia::getClassRef()");
+    if (!m_jsClassRef) 
+       {
+            m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSMedia::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+MediacontentMediaPtr JSMedia::getMediaObject(JSObjectRef object)
+{
+    LogDebug("entered");
+    MediaPrivObject *priv = static_cast<MediaPrivObject*>(JSObjectGetPrivate(object));
+    if(!priv) 
+       {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    MediacontentMediaPtr result = priv->getObject();
+    if (!result) 
+       {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    return result;
+}
+
+JSValueRef JSMedia::getPropertyId(
+                                       JSContextRef context, 
+                                       JSObjectRef object,
+                                       JSStringRef propertyName, 
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentMediaPtr media = getMediaObject(object);
+
+        return converter.toJSValueRef(media->getMediaUUID());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+
+}
+
+JSValueRef     JSMedia::getPropertyMimeType(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentMediaPtr media = getMediaObject(object);
+        return converter.toJSValueRef(media->getMimeType());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+
+}
+
+                                       
+JSValueRef JSMedia::getPropertyDisplayName(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception)
+{
+    LogDebug("getPropertyDisplayName::entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentMediaPtr media = getMediaObject(object);
+       LogDebug("getDisplayName:"<<media->getDisplayName());    
+        return converter.toJSValueRef(media->getDisplayName());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSMedia::getPropertyFilePath(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentMediaPtr media = getMediaObject(object);
+        return converter.toJSValueRef(media->getFilePath());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSMedia::getPropertyThumbnailPath(
+                                       JSContextRef context,
+                                       JSObjectRef object, 
+                                       JSStringRef propertyName, 
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentMediaPtr media = getMediaObject(object);
+        JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+               if (NULL == jsResult) 
+               {
+                       ThrowMsg(NullPointerException, "Could not create js array object");
+               }
+//             for(unsigned int i=0; i<event->getThumbnailPath()->size(); i++) 
+               {
+                       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);
+}
+
+JSValueRef JSMedia::getPropertyDescription(
+                                       JSContextRef context,
+                                       JSObjectRef object, 
+                                       JSStringRef propertyName, 
+                                       JSValueRef* exception)
+{
+    LogDebug("getPropertyDescription::entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentMediaPtr media = getMediaObject(object);
+        return converter.toJSValueRef(media->getDescription());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSMedia::getPropertyModifiedDate(
+                                       JSContextRef context,
+                                       JSObjectRef object, 
+                                       JSStringRef propertyName, 
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentMediaPtr media = getMediaObject(object);
+        return converter.toJSValueRef(media->getModifiedDate());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMedia::getPropertyReleasedDate(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentMediaPtr media = getMediaObject(object);
+        return converter.toJSValueRef(media->getReleasedDate());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+
+}
+
+
+JSValueRef JSMedia::getPropertyRating(
+                                       JSContextRef context,
+                                       JSObjectRef object, 
+                                       JSStringRef propertyName, 
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentMediaPtr objMedia = getMediaObject(object);
+        return converter.toJSValueRef(objMedia->getRating());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMedia::getPropertyType(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception)
+{
+    LogDebug("getPropertyType::entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentMediaPtr media = getMediaObject(object);
+        return converter.toJSValueRef(media->getMediaType());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSMedia::getPropertySize(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception)
+{
+    LogDebug("getPropertyType::entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentMediaPtr media = getMediaObject(object);
+        LogDebug("size:" << media->getSize());
+       double var = (double)media->getSize(); //casting.
+       return converter.toJSValueRef(var);
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSMedia::getPropertyEditableAttr(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception)
+{
+    Try
+    {
+               Converter converter(context);
+               MediacontentMediaPtr media = getMediaObject(object);
+               vector<std::string> editableAttrList = media->getEditableAttr();
+               JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+
+                       if (NULL == jsResult) 
+                       {
+                           ThrowMsg(NullPointerException, "Could not create js array object");
+                       }
+               for(unsigned int i=0; i<editableAttrList.size(); i++) 
+                       {
+                       JSValueRef val = converter.toJSValueRef(editableAttrList.at(i));
+                           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);
+
+}
+
+
+bool   JSMedia::setPropertyRating(
+                               JSContextRef context,
+                               JSObjectRef object,
+                               JSStringRef propertyName,
+                               JSValueRef value,
+                               JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+       Converter converter(context);
+       MediacontentMediaPtr objMedia = getMediaObject(object);
+       int rating = converter.toInt(value);
+
+       LogDebug("Inserted value : " << rating);
+
+       if(rating < 0)
+       {
+               rating = 0;
+               LogDebug("Rating value set 0 as inserted value is too small");
+       }
+       
+       if ( objMedia->getRating() != rating)
+       {
+               objMedia->setRating(rating, true);
+       }
+               
+        return true;
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to set incorrect value");
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+
+    return false;
+
+}
+
+bool           JSMedia::setPropertyDisplayName(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef value,
+                                       JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               Converter converter(context);
+               MediacontentMediaPtr objMedia = getMediaObject(object);
+               string displayName = converter.toString(value);
+
+               LogDebug("Inserted value : " << displayName);
+               
+               if ((objMedia->getDescription()).compare(displayName) != 0)
+               {
+                       objMedia->setDisplayName(displayName, true);
+               }
+               
+               return true;
+       }
+       Catch(Exception)
+       {
+               LogWarning("trying to set incorrect value");
+               TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+       }
+
+       return false;
+}
+
+bool           JSMedia::setPropertyDescription(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef value,
+                                       JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               Converter converter(context);
+               MediacontentMediaPtr objMedia = getMediaObject(object);
+               string description = converter.toString(value);
+
+               LogDebug("Inserted value : " << description);
+               
+               if ( (objMedia->getDescription()).compare(description) != 0 )
+               {
+                       objMedia->setDescription(description, true);
+               }
+               
+               return true;
+       }
+       Catch(Exception)
+       {
+               LogWarning("trying to set incorrect value");
+               TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+       }
+
+       return false;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Content/JSMedia.h b/src/standards/Tizen/Content/JSMedia.h
new file mode 100755 (executable)
index 0000000..c149acb
--- /dev/null
@@ -0,0 +1,184 @@
+//
+// 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 _JS_TIZEN_MEDIA_H_
+#define _JS_TIZEN_MEDIA_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Content/MediacontentMedia.h>
+
+
+using namespace TizenApis::Api::Content;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+typedef PrivateObject<Api::Content::MediacontentMediaPtr, NoOwnership> MediaPrivObject;
+
+class JSMedia
+{
+       public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       static Api::Content::MediacontentMediaPtr getMediaObject(JSObjectRef object);
+
+       private:
+       /**
+       * 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;
+
+       /**
+       * 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);
+
+
+
+       /**
+       * Getters and setters for properties
+       */
+       static JSValueRef       getPropertyId(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+
+       static JSValueRef       getPropertyType(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+
+       static JSValueRef       getPropertyMimeType(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+       
+       static JSValueRef       getPropertyDisplayName(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+
+       static JSValueRef       getPropertyFilePath(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+
+       static JSValueRef   getPropertyDescription(
+                                               JSContextRef context,
+                                               JSObjectRef object, 
+                                               JSStringRef propertyName, 
+                                               JSValueRef* exception);
+
+       static JSValueRef       getPropertyThumbnailPath(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+
+       static JSValueRef       getPropertyReleasedDate(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+
+       static JSValueRef       getPropertyModifiedDate(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+
+       static JSValueRef       getPropertyRating(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);  
+
+       static JSValueRef getPropertySize(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+
+       
+       static JSValueRef       getPropertyEditableAttr(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+                                       
+       static bool                     setPropertyRating(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                   JSValueRef value,
+                                               JSValueRef* exception);  
+
+       static bool                     setPropertyDisplayName(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                   JSValueRef value,
+                                               JSValueRef* exception); 
+
+       static bool                     setPropertyDescription(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                   JSValueRef value,
+                                               JSValueRef* exception);  
+       
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_MEDIA_H_ */
diff --git a/src/standards/Tizen/Content/JSMediaLyrics.cpp b/src/standards/Tizen/Content/JSMediaLyrics.cpp
new file mode 100755 (executable)
index 0000000..3b13434
--- /dev/null
@@ -0,0 +1,250 @@
+//
+// 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/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+
+#include "JSMediaLyrics.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+#define TIZEN_CONTENT_MEDIA_LYRICS             "AudioContentLyrics"
+#define TIZEN_CONTENT_LYRICS_TYPE              "type"
+#define TIZEN_CONTENT_LYRICS_TIMESTAMP         "timestamps"
+#define TIZEN_CONTENT_LYRICS_TEXT              "texts"
+
+JSClassDefinition JSMediaLyrics::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    TIZEN_CONTENT_MEDIA_LYRICS,
+    0,
+    m_property,
+    NULL, //    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL  //ConvertToType
+};
+
+JSStaticValue JSMediaLyrics::m_property[] =
+{
+    //EventProperties
+    { TIZEN_CONTENT_LYRICS_TYPE, getPropertyLyricsType, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_LYRICS_TIMESTAMP, getPropertyTimeStamps, NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN_CONTENT_LYRICS_TEXT, getPropertyTexts, NULL, kJSPropertyAttributeReadOnly},    
+    { 0, 0, 0, 0 }
+};
+
+
+JSClassRef JSMediaLyrics::m_jsClassRef = JSClassCreate(JSMediaLyrics::getClassInfo());
+
+void JSMediaLyrics::initialize(JSContextRef context, JSObjectRef object)
+{
+    LogDebug( "entered" );
+    LyricsPrivObject *priv = static_cast<LyricsPrivObject*>( JSObjectGetPrivate( object ) );
+    if (!priv) 
+       {
+        MediacontentLyricsPtr privateData(new MediacontentLyrics());
+        priv = new LyricsPrivObject(context, privateData);
+        JSObjectSetPrivate(object, static_cast<void*>(priv));
+        LogDebug("private object is created");
+    }
+    else 
+       {
+        LogDebug("private object already exists");
+    }
+}
+
+void JSMediaLyrics::finalize(JSObjectRef object)
+{
+    LogDebug( "entered" );
+    LyricsPrivObject *priv = static_cast<LyricsPrivObject*>( JSObjectGetPrivate( object ) ) ;
+    delete priv;
+}
+
+const JSClassRef JSMediaLyrics::getClassRef()
+{
+       LogDebug("JSMediaLyrics::getClassRef()");
+    if (!m_jsClassRef) 
+       {
+            m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSMediaLyrics::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+MediacontentLyricsPtr JSMediaLyrics::getLyricsObject(JSObjectRef object)
+{
+    LogDebug("entered");
+    LyricsPrivObject *priv = static_cast<LyricsPrivObject*>(JSObjectGetPrivate(object));
+    if(!priv) 
+       {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    MediacontentLyricsPtr result = priv->getObject();
+    if (!result) 
+       {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    return result;
+}
+
+
+JSValueRef     JSMediaLyrics::getPropertyLyricsType(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+               Converter converter(context);
+
+        MediacontentLyricsPtr lyrics = getLyricsObject(object);
+
+        return converter.toJSValueRef(lyrics->getMediaLyricsType());
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+
+    return JSValueMakeUndefined(context);
+
+}
+
+JSValueRef     JSMediaLyrics::getPropertyTimeStamps(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+       Converter converter(context);
+        MediacontentLyricsPtr lyrics = getLyricsObject(object);
+        
+       if ( 0 == (lyrics->getMediaLyricsType()).compare("SYNCHRONIZED") )
+       {
+        
+           JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+           vector<unsigned long> timeStamps = lyrics->getMediaLyricsTimeStamps();
+            if(timeStamps.size() > 0)
+           {
+               if (NULL == jsResult) 
+               {
+                    ThrowMsg(NullPointerException, "Could not create js array object");
+                }
+                for(unsigned int i=0; i<timeStamps.size(); i++) 
+                {
+                   JSValueRef val = converter.toJSValueRef(timeStamps.at(i));
+                    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);
+
+}
+
+JSValueRef     JSMediaLyrics::getPropertyTexts(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+               Converter converter(context);
+        MediacontentLyricsPtr lyrics = getLyricsObject(object);
+               JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+               vector<string> texts = lyrics->getMediaLyricsTexts();
+               if(texts.size() >0)
+               {
+                       if (NULL == jsResult) 
+                       {
+                ThrowMsg(NullPointerException, "Could not create js array object");
+            }
+            for(unsigned int i=0; i<texts.size(); i++) 
+            {
+               JSValueRef val = converter.toJSValueRef(texts.at(i));
+                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);
+
+}
+
+JSObjectRef JSMediaLyrics::createJSObject(JSContextRef context, 
+               const MediacontentLyricsPtr mediaContent)
+{
+       LyricsPrivObject *priv = new LyricsPrivObject(context, mediaContent);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+
+}
+}
+}
diff --git a/src/standards/Tizen/Content/JSMediaLyrics.h b/src/standards/Tizen/Content/JSMediaLyrics.h
new file mode 100755 (executable)
index 0000000..5192c47
--- /dev/null
@@ -0,0 +1,114 @@
+//
+// 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 _JS_TIZEN_MEDIA_LYRICS_H_
+#define _JS_TIZEN_MEDIA_LYRICS_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Content/MediacontentLyrics.h>
+
+
+using namespace TizenApis::Api::Content;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+typedef PrivateObject<MediacontentLyricsPtr, NoOwnership> LyricsPrivObject;
+
+class JSMediaLyrics
+{
+       public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       static MediacontentLyricsPtr getLyricsObject(JSObjectRef object);
+
+       static JSObjectRef createJSObject(JSContextRef context, 
+               const TizenApis::Api::Content::MediacontentLyricsPtr mediacontentLyrics);
+
+
+       private:
+       /**
+       * 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;
+
+       /**
+       * 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);
+
+
+
+       /**
+       * Getters and setters for properties
+       */
+
+       static JSValueRef       getPropertyLyricsType(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+
+       static JSValueRef       getPropertyTimeStamps(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception);
+
+       static JSValueRef       getPropertyTexts(
+                                               JSContextRef context,
+                                               JSObjectRef object,
+                                               JSStringRef propertyName,
+                                               JSValueRef* exception); 
+
+
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_MEDIA_LYRICS_H_ */
diff --git a/src/standards/Tizen/Content/JSVideo.cpp b/src/standards/Tizen/Content/JSVideo.cpp
new file mode 100755 (executable)
index 0000000..ad7875e
--- /dev/null
@@ -0,0 +1,391 @@
+//
+// 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/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Tizen/JSSimpleCoordinates.h>
+
+#include "ContentConverter.h"
+#include "JSVideo.h"
+
+#define TIZEN_CONTENT_VIDEO_ATTRIBUTENAME              "VideoContent"
+#define TIZEN_CONTENT_VIDEO_GEOLOCATION                        "geolocation"
+#define TIZEN_CONTENT_VIDEO_ALBUM                              "album"
+#define TIZEN_CONTENT_VIDEO_ARTIST                             "artists"
+#define TIZEN_CONTENT_VIDEO_DURATION                   "duration"      
+#define TIZEN_CONTENT_VIDEO_WIDTH                              "width"
+#define TIZEN_CONTENT_VIDEO_HEIGHT                             "height"
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Tizen;
+using namespace TizenApis::Tizen1_0::Tizen;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+
+JSClassDefinition JSVideo::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       TIZEN_CONTENT_VIDEO_ATTRIBUTENAME,
+       JSMedia::getClassRef(),
+       m_property,
+       NULL, //    m_function,
+       initialize,
+       finalize,
+       NULL, //hasProperty,
+       NULL, //getProperty,
+       NULL, //setProperty,
+       NULL, //DeleteProperty,
+       NULL, //GetPropertyNames,
+       NULL, //CallAsFunction,
+       NULL, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL  //ConvertToType
+};
+
+JSStaticValue JSVideo::m_property[] =
+{
+       { TIZEN_CONTENT_VIDEO_GEOLOCATION, getPropertyGeoLocation, setPropertyGeoLocation, kJSPropertyAttributeNone},
+       { TIZEN_CONTENT_VIDEO_ALBUM, getPropertyAlbum, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_VIDEO_ARTIST, getPropertyArtist, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_VIDEO_DURATION, getPropertyDuration, NULL, kJSPropertyAttributeReadOnly},    
+       { TIZEN_CONTENT_VIDEO_WIDTH, getPropertyWidth, NULL, kJSPropertyAttributeReadOnly},
+       { TIZEN_CONTENT_VIDEO_HEIGHT, getPropertyHeight, NULL, kJSPropertyAttributeReadOnly},    
+       { 0, 0, 0, 0 }
+};
+
+
+JSClassRef JSVideo::m_jsClassRef = JSClassCreate(JSVideo::getClassInfo());
+
+void JSVideo::initialize(JSContextRef context, JSObjectRef object)
+{
+    LogDebug( "entered" );
+    VideoPrivObject *priv = static_cast<VideoPrivObject*>( JSObjectGetPrivate( object ) );
+    if (!priv) 
+    {
+        MediacontentVideoPtr privateData(new MediacontentVideo());
+        priv = new VideoPrivObject(context, privateData);
+        JSObjectSetPrivate(object, static_cast<void*>(priv));
+        LogDebug("new event is created" );
+    }
+    else {
+        LogDebug("private object already exists");
+    }
+}
+
+void JSVideo::finalize(JSObjectRef object)
+{
+    LogDebug( "entered" );
+       VideoPrivObject *priv =  static_cast<VideoPrivObject*>( JSObjectGetPrivate( object ) ) ;
+       if (priv != NULL)
+       {
+               delete (priv);
+               priv = NULL;
+               JSObjectSetPrivate(object, NULL);               
+       }
+
+       priv = NULL;
+
+}
+
+const JSClassRef JSVideo::getClassRef()
+{
+       LogDebug("JSVideo::getClassRef()");
+
+    if (!m_jsClassRef) 
+    {
+            m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSVideo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+MediacontentVideoPtr JSVideo::getVideoObject(JSObjectRef object)
+{
+    LogDebug("entered");
+    VideoPrivObject *priv = static_cast<VideoPrivObject*>(JSObjectGetPrivate(object));
+    if(!priv) 
+    {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    MediacontentVideoPtr result = priv->getObject();
+    if (!result) 
+    {
+        ThrowMsg(NullPointerException, "Private object is null");
+    }
+    return result;
+}
+                       
+JSValueRef JSVideo::getPropertyGeoLocation(
+                                                                               JSContextRef context,
+                                                                       JSObjectRef object,
+                                                                       JSStringRef propertyName,
+                                                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentVideoPtr video = getVideoObject(object);
+               SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(video->getVideoLatitude(),video->getVideoLongitude()));
+        return JSSimpleCoordinates::createJSObject(context,geoPtr);
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSVideo::setPropertyGeoLocation(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef value,
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentVideoPtr video = getVideoObject(object);
+       
+               TizenApis::Api::Tizen::SimpleCoordinatesPtr geoLocation =
+               TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::getSimpleCoordinates(context, value);
+
+               if(geoLocation){
+                       video->setVideoLatitude(geoLocation->getLatitude());
+               video->setVideoLongitude(geoLocation->getLongitude());
+                       return true;
+               }
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+       return false;
+}
+
+
+JSValueRef JSVideo::getPropertyAlbum(
+                                                                       JSContextRef context,
+                                                               JSObjectRef object, 
+                                                               JSStringRef propertyName, 
+                                                               JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentVideoPtr video = getVideoObject(object);
+               if(video){
+                       return converter.toJSValueRef(video->getVideoAlbum());
+               }
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSVideo::getPropertyArtist(
+                                                                       JSContextRef context,
+                                                               JSObjectRef object, 
+                                                               JSStringRef propertyName, 
+                                                               JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {  
+               Converter converter(context);
+               MediacontentVideoPtr video = getVideoObject(object);
+               JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+               if (NULL == jsResult) {
+                       ThrowMsg(NullPointerException, "Could not create js array object");
+               }
+
+               for( unsigned int i=0; i < video->getVideoArtist().size(); i++) {
+                       string artist = video->getVideoArtist().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);
+}
+
+
+JSValueRef JSVideo::getPropertyDuration(
+                                                                       JSContextRef context,
+                                                               JSObjectRef object,
+                                                               JSStringRef propertyName,
+                                                               JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentVideoPtr video = getVideoObject(object);
+               if(video){
+               return converter.toJSValueRef(video->getVideoDuration());
+               }
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSVideo::getPropertyWidth(
+                                                                       JSContextRef context,
+                                                               JSObjectRef object,
+                                                               JSStringRef propertyName,
+                                                               JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentVideoPtr video = getVideoObject(object);
+               if(video){
+               return converter.toJSValueRef(video->getVideoWidth());
+               }
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSVideo::getPropertyHeight(
+                                                                       JSContextRef context,
+                                                               JSObjectRef object,
+                                                               JSStringRef propertyName,
+                                                               JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentVideoPtr video = getVideoObject(object);
+               if(video){
+               return converter.toJSValueRef(video->getVideoHeight());
+               }
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to get incorrect value");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSVideo::setPropertyArtists(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef value,
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+        MediacontentVideoPtr video = getVideoObject(object);
+
+               vector<std::string> artists;
+               if (!JSValueIsNull(context, value)) {
+
+                       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));
+                               }
+                       }
+                       else{
+                               TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+                       }
+                       video->setVideoArtist(artists, true);
+                       return true;
+               }
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to set incorrect value");
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+    return false;
+}
+
+bool JSVideo::setPropertyAlbum(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef value,
+                                       JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        Converter converter(context);
+                       
+        MediacontentVideoPtr video = getVideoObject(object);
+        string album = converter.toString(value);
+               if(video){
+               video->setVideoAlbum(album, true);
+               return true;
+               }
+    }
+    Catch(Exception)
+    {
+        LogWarning("trying to set incorrect value");
+        TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR);
+    }
+    return false;
+}
+
+
+}
+}
+}
diff --git a/src/standards/Tizen/Content/JSVideo.h b/src/standards/Tizen/Content/JSVideo.h
new file mode 100755 (executable)
index 0000000..75e6b39
--- /dev/null
@@ -0,0 +1,167 @@
+//
+// 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 _JS_TIZEN_VIDEO_H_
+#define _JS_TIZEN_VIDEO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Content/MediacontentMedia.h>
+#include <API/Content/MediacontentVideo.h>
+#include "JSMedia.h"
+
+using namespace TizenApis::Api::Content;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+typedef PrivateObject<MediacontentVideoPtr, NoOwnership> VideoPrivObject;
+
+class JSVideo
+{
+public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+       static Api::Content::MediacontentVideoPtr getVideoObject(JSObjectRef object);
+
+private:
+    /**
+     * 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;
+
+    /**
+     * 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);
+
+
+
+    /**
+     * Getters and setters for properties
+     */
+
+    static JSValueRef  getPropertyGeoLocation(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static JSValueRef  getPropertyAlbum(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static JSValueRef  getPropertyArtist(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static JSValueRef  getPropertyDuration(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+
+    static JSValueRef  getPropertyWidth(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static JSValueRef  getPropertyHeight(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                       JSValueRef* exception);
+
+    static bool                setPropertyPlayCount(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                   JSValueRef value,
+                                       JSValueRef* exception);
+
+    
+    static bool                setPropertyPlayedTime(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                   JSValueRef value,
+                                       JSValueRef* exception);
+
+    static bool                setPropertyAlbum(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                   JSValueRef value,
+                                       JSValueRef* exception);
+
+    static bool                setPropertyArtists(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                   JSValueRef value,
+                                       JSValueRef* exception); 
+
+    static bool                setPropertyGeoLocation(
+                                       JSContextRef context,
+                                       JSObjectRef object,
+                                       JSStringRef propertyName,
+                                   JSValueRef value,
+                                       JSValueRef* exception);
+
+       //todo-dykim
+       //static JSValueRef     setPropertyPlayedTime
+
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_VIDEO_H_ */
diff --git a/src/standards/Tizen/Content/MediaLyricsUtil.cpp b/src/standards/Tizen/Content/MediaLyricsUtil.cpp
new file mode 100755 (executable)
index 0000000..23ed9e2
--- /dev/null
@@ -0,0 +1,148 @@
+//
+// 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 "MediaLyricsUtil.h"
+#include <dpl/log/log.h>
+#include <dpl/singleton_impl.h>
+#include <metadata_extractor.h>
+
+using namespace DPL;
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::Content::MediaLyricsUtil)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+metadata_extractor_h m_extractor = NULL;
+MediaLyricsUtil::MediaLyricsUtil()
+{
+        LogDebug("entered ");
+       if ( METADATA_EXTRACTOR_ERROR_NONE != metadata_extractor_create(&m_extractor))
+       {
+               LogDebug("MetaData Extractor create Fail...");
+       }
+}
+
+MediaLyricsUtil::~MediaLyricsUtil()
+{
+       LogDebug("entered ");
+       if ( m_extractor && METADATA_EXTRACTOR_ERROR_NONE != metadata_extractor_destroy(m_extractor))
+       {
+               LogDebug("Metadata extractor destory Fail...");
+       }
+}
+
+MediacontentLyricsPtr MediaLyricsUtil::fetchLyrics(string filepath)
+{
+       MediacontentLyricsPtr result;
+       //MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
+       //set path.
+
+       if (m_extractor)
+       {
+               LogDebug("Valide Extractor");
+
+               //setpath
+               LogDebug("set Path : " << filepath);
+
+               if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_set_path(m_extractor, filepath.c_str()) )
+               {                               
+                       char* strSyncTextNum=NULL;
+                       metadata_extractor_attr_e attr = METADATA_SYNCLYRICS_NUM;
+                       if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_get_metadata(m_extractor, attr, &strSyncTextNum) 
+                               && strSyncTextNum )
+                       {
+                               LogDebug("SYNCHRONIZED");                       
+                               int nSyncTextNum = 0;
+                               istringstream(strSyncTextNum) >> nSyncTextNum;
+                               LogDebug("nSyncTextNum : " << nSyncTextNum);
+
+                               free(strSyncTextNum);
+                               strSyncTextNum = NULL;
+                               
+                               if ( nSyncTextNum > 0)
+                               {
+
+                                       MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
+                                       lyricsPtr->setMediaLyricsType("SYNCHRONIZED");
+                                       for(int i=0; i < nSyncTextNum; i++)
+                                       {       
+                                               unsigned long time_info = 0;
+                                               char * lyrics = NULL;
+                                               if ( METADATA_EXTRACTOR_ERROR_NONE == 
+                                                       metadata_extractor_get_synclyrics(m_extractor, i, &time_info, &lyrics))
+                                               {
+                                                       lyricsPtr->addMediaLyricsTimeStamp(time_info);
+                                                       lyricsPtr->addMediaLyricsText(lyrics);
+                                                       LogDebug( "timestamp " << time_info << "lyrics : " << lyrics);
+                                               }
+                                       }
+
+                                       result = lyricsPtr;
+                               }
+                               else
+                               {       
+                                       LogDebug("sync Lyrics Error. text num is 0");
+
+                                       char* unSyncText = NULL;
+                                       attr = METADATA_UNSYNCLYRICS;
+
+                                       if ( METADATA_EXTRACTOR_ERROR_NONE == metadata_extractor_get_metadata(m_extractor, attr, &unSyncText) )
+                                       {
+                                               if (unSyncText)
+                                               {
+                                                       MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
+                                                       LogDebug("UNSYNCHRONIZED: " << unSyncText);
+                                                       lyricsPtr->setMediaLyricsType("UNSYNCHRONIZED");
+                                                       lyricsPtr->addMediaLyricsTimeStamp(0);
+                                                       lyricsPtr->addMediaLyricsText(unSyncText);
+                                                       
+                                                       result = lyricsPtr;
+                                                       
+                                                       free(unSyncText);
+                                                       unSyncText = NULL;
+                                               }
+                                       }
+                                       
+                               }
+                               
+                       }
+                       else
+                       {       
+                               LogDebug("extractor Error!!!");
+                       }
+
+               }
+
+       }
+       else
+       {
+               LogDebug(" extractor is invaild ");
+       }
+       
+       return result;
+}
+
+} // Mediacontent
+} // Tizen1_0
+} // TizenApis
+  
+
+
+
diff --git a/src/standards/Tizen/Content/MediaLyricsUtil.h b/src/standards/Tizen/Content/MediaLyricsUtil.h
new file mode 100755 (executable)
index 0000000..481f758
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// 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_MEDIA_LYRICS_UTIL_H_
+#define _TIZEN_MEDIA_LYRICS_UTIL_H_
+
+#include <dpl/singleton.h>
+#include <API/Content/MediacontentLyrics.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+using namespace TizenApis::Api::Content;
+ class MediaLyricsUtil
+ {
+ public:
+        MediaLyricsUtil();
+        virtual ~MediaLyricsUtil();
+
+       MediacontentLyricsPtr fetchLyrics(string filepath);
+        friend class DPL::Singleton<MediaLyricsUtil>;
+ };
+ typedef DPL::Singleton<MediaLyricsUtil> MediaLyricsUtilSingleton;
+ } // Mediacontent
+ } // Tizen1_0
+ } // TizenApis
+#endif // _TIZEN_MEDIA_LYRICS_UTIL_H_
+
diff --git a/src/standards/Tizen/Content/config.xml b/src/standards/Tizen/Content/config.xml
new file mode 100755 (executable)
index 0000000..257ea94
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+    <library-name>libwrt-plugins-tizen-2.0-content.so</library-name>
+    <feature-install-uri>content.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/content.read</name>
+        <device-capability>content.read</device-capability>
+    </api-feature>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/content.write</name>
+        <device-capability>content.write</device-capability>
+    </api-feature>
+
+</plugin-properties>
diff --git a/src/standards/Tizen/Content/plugin_config.cpp b/src/standards/Tizen/Content/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..eb40eec
--- /dev/null
@@ -0,0 +1,155 @@
+//
+// 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 CONTENT_FEATURE_API_READ  "http://tizen.org/privilege/content.read"
+#define CONTENT_FEATURE_API_WRITE "http://tizen.org/privilege/content.write"
+
+#define CONTENT_DEVICE_CAP_READ "content.read"
+#define CONTENT_DEVICE_CAP_WRITE "content.write"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+static FunctionMapping createContentFunctions();
+
+static FunctionMapping ContentFunctions = createContentFunctions();
+
+DEFINE_FUNCTION_GETTER(Content, ContentFunctions);
+
+static FunctionMapping createContentFunctions()
+{
+    /**
+     * Device capabilities
+     */
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_CONTENT_READ, CONTENT_DEVICE_CAP_READ);
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_CONTENT_WRITE, CONTENT_DEVICE_CAP_WRITE);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_CONTENT_READ);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_CONTENT_READ, DEVICE_CAP_CONTENT_READ);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_CONTENT_WRITE);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_CONTENT_WRITE, DEVICE_CAP_CONTENT_WRITE);
+
+    /**
+     * Api Features
+     */
+    ACE_CREATE_FEATURE(FEATURE_CONTENT_READ, CONTENT_FEATURE_API_READ);
+    ACE_CREATE_FEATURE(FEATURE_CONTENT_WRITE, CONTENT_FEATURE_API_WRITE);
+
+    ACE_CREATE_FEATURE_LIST(CONTENT_FEATURES_CONTENT_READ_WRITE);
+    ACE_ADD_API_FEATURE(CONTENT_FEATURES_CONTENT_READ_WRITE, FEATURE_CONTENT_READ);
+    ACE_ADD_API_FEATURE(CONTENT_FEATURES_CONTENT_READ_WRITE, FEATURE_CONTENT_WRITE);
+
+    ACE_CREATE_FEATURE_LIST(CONTENT_FEATURES_CONTENT_READ);
+    ACE_ADD_API_FEATURE(CONTENT_FEATURES_CONTENT_READ, FEATURE_CONTENT_READ);
+
+    ACE_CREATE_FEATURE_LIST(CONTENT_FEATURES_CONTENT_WRITE);
+    ACE_ADD_API_FEATURE(CONTENT_FEATURES_CONTENT_WRITE, FEATURE_CONTENT_WRITE);
+#if 0
+    ACE_CREATE_FEATURE_LIST(CONTENT_FEATURES_CONTENT);
+    ACE_ADD_API_FEATURE(CONTENT_FEATURES_CONTENT,
+                        FEATURE_CONTENT);
+       
+    ACE_CREATE_FEATURE_LIST(CONTENT_FEATURES_READ);
+    ACE_ADD_API_FEATURE(CONTENT_FEATURES_READ,
+                        FEATURE_CONTENT_READ);
+
+    ACE_CREATE_FEATURE_LIST(CONTENT_FEATURES_WRITE);
+    ACE_ADD_API_FEATURE(CONTENT_FEATURES_WRITE,
+                        FEATURE_CONTENT_WRITE);
+#endif
+    /**
+     * Functions
+     */
+    FunctionMapping contentMapping;
+
+    //"getLocalMediaSource"
+    AceFunction getLocalMediaSourceFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_LOCAL_MEDIA_SOURCE,
+            CONTENT_FUNCTION_API_GET_LOCAL_MEDIASOURCE,
+            CONTENT_FEATURES_CONTENT_READ_WRITE,
+            DEVICE_LIST_CONTENT_READ);
+
+    contentMapping.insert(std::make_pair(
+                               CONTENT_FUNCTION_API_GET_LOCAL_MEDIASOURCE,
+                               getLocalMediaSourceFunc));
+
+
+    //findItems
+    AceFunction findItemsFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_FIND_ITEMS,
+            CONTENT_FUNCTION_API_FIND_ITEMS,
+            CONTENT_FEATURES_CONTENT_READ,
+            DEVICE_LIST_CONTENT_READ);
+
+    contentMapping.insert(std::make_pair(
+                               CONTENT_FUNCTION_API_FIND_ITEMS,
+                               findItemsFunc));
+
+    //getFolders
+    AceFunction getFoldersFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_FOLDERS,
+            CONTENT_FUNCTION_API_GET_FOLDERS,
+            CONTENT_FEATURES_CONTENT_READ,
+            DEVICE_LIST_CONTENT_READ);
+
+    contentMapping.insert(std::make_pair(
+                               CONTENT_FUNCTION_API_GET_FOLDERS,
+                               getFoldersFunc));
+
+    //updateItem
+    AceFunction updateItemFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_UPDATE_ITEM,
+            CONTENT_FUNCTION_API_UPDATE_ITEM,
+            CONTENT_FEATURES_CONTENT_WRITE,
+            DEVICE_LIST_CONTENT_WRITE);
+
+    contentMapping.insert(std::make_pair(
+                               CONTENT_FUNCTION_API_UPDATE_ITEM,
+                               updateItemFunc));
+
+    //updateItemsBatch
+    AceFunction updateItemsBatchFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_UPDATE_ITEMS_BATCH,
+            CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH,
+            CONTENT_FEATURES_CONTENT_WRITE,
+            DEVICE_LIST_CONTENT_WRITE);
+
+    contentMapping.insert(std::make_pair(
+                               CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH,
+                               updateItemsBatchFunc));
+
+    return contentMapping;
+}
+
+}
+} 
+}
diff --git a/src/standards/Tizen/Content/plugin_config.h b/src/standards/Tizen/Content/plugin_config.h
new file mode 100755 (executable)
index 0000000..d07a14c
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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 _CONTENT_PLUGIN_CONFIG_H_
+#define _CONTENT_PLUGIN_CONFIG_H_
+
+#include <string>
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+// Functions from content manager
+#define CONTENT_FUNCTION_API_GET_LOCAL_MEDIASOURCE "getLocalMediaSource"
+
+// Functions from content
+#define CONTENT_FUNCTION_API_FIND_ITEMS "find"
+#define CONTENT_FUNCTION_API_GET_FOLDERS "getDirectories"
+#define CONTENT_FUNCTION_API_UPDATE_ITEM "update"
+#define CONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH "updateBatch"
+
+DECLARE_FUNCTION_GETTER(Content);
+
+#define CONTENT_CHECK_ACCESS(functionName) \
+    WrtDeviceApis::Commons::aceCheckAccess<AceFunctionGetter, \
+    WrtDeviceApis::Commons::DefaultArgsVerifier<> >(                \
+        getContentFunctionData,         \
+        functionName)
+
+
+}
+}
+}
+
+#endif //  _CONTENT_PLUGIN_CONFIG_H_
diff --git a/src/standards/Tizen/Content/plugin_initializer.cpp b/src/standards/Tizen/Content/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..2ca7a92
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <Commons/Exception.h>
+#include "JSContentManager.h"
+#include "ContentAsyncCallbackManager.h"
+
+
+using namespace TizenApis::Api::Content;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Content {
+
+void on_frame_load_callback(const void * context)
+{
+    LogDebug("[Tizen\\contact] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LogDebug("[Tizen\\contact] on_frame_unload_callback (" << context << ")");
+    TizenApis::Tizen1_0::Content::MediaContentAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[Tizen\\content] on_widget_start_callback (" << widgetId << ")");
+
+       Try
+    {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("WrtAccess intialization failed");
+    }
+
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[Tizen\\content] on_widget_stop_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+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,
+        "content",
+        (js_class_template_getter)JSMediacontentManager::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_END
+
+}
+}
+}
diff --git a/src/standards/Tizen/Download/CMakeLists.txt b/src/standards/Tizen/Download/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..4df20d2
--- /dev/null
@@ -0,0 +1,35 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-download")
+set(DESTINATION_NAME  "tizen-2.0-download")
+
+set(CMAKE_INSTALL_RPATH
+    ${CMAKE_INSTALL_RPATH}
+    ${CMAKE_INSTALL_PREFIX}/tizen-2.0-tizen
+    ${CMAKE_INSTALL_PREFIX}/tizen-2.0-filesystem
+)
+
+set(SRCS
+  ${SRCS_PLATFORM_API_DOWNLOAD}
+  ${SRCS_PLATFORM_IMPLEMENTATION_DOWNLOAD}
+  DownloadResponseDispatcher.cpp
+  DownloadConverter.cpp
+  JSDownloadManager.cpp
+  JSDownloadRequest.cpp
+  DownloadListenerManager.cpp
+  plugin_initializer.cpp
+  plugin_config.cpp
+)
+
+include_directories(
+  ${INCLUDES_PLATFORM_IMPLEMENTATION_DOWNLOAD}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${LIBS_COMMON}
+  ${LIBS_PLATFORM_IMPLEMENTATION_DOWNLOAD}
+  wrt-plugins-tizen-2.0-tizen-impl
+  wrt-plugins-tizen-2.0-filesystem-impl
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
diff --git a/src/standards/Tizen/Download/DownloadConverter.cpp b/src/standards/Tizen/Download/DownloadConverter.cpp
new file mode 100755 (executable)
index 0000000..2742dbc
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include "JSDownloadManager.h"
+#include "DownloadConverter.h"
+
+using namespace TizenApis::Api::Download;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+DownloadConverter::DownloadConverter(JSContextRef context) : Converter(context)
+{
+}
+
+DownloadConverter::~DownloadConverter()
+{
+}
+
+JSValueRef DownloadConverter::toFunctionOrNull(const JSValueRef& arg)
+{
+    if (Validator(m_context).isCallback(arg)) {
+        return arg;
+    } else if (!JSValueIsNull(m_context, arg) && !JSValueIsUndefined(m_context, arg)) {
+        ThrowMsg(ConversionException, "Not a function nor JS null.");
+    }
+    return NULL;
+}
+
+JSValueRef DownloadConverter::toFunction(const JSValueRef& arg)
+{
+    if (Validator(m_context).isCallback(arg)) {
+        return arg;
+    }
+    ThrowMsg(ConversionException, "Not a function.");
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Download/DownloadConverter.h b/src/standards/Tizen/Download/DownloadConverter.h
new file mode 100755 (executable)
index 0000000..48ce250
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// 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 _JS_TIZEN_DOWNLOAD_CONVERTER_H_
+#define _JS_TIZEN_DOWNLOAD_CONVERTER_H_
+
+#include <string>
+#include <API/Download/IDownloadManager.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+class DownloadConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+  public:
+    explicit DownloadConverter(JSContextRef context);
+    virtual ~DownloadConverter();
+
+    /**
+     * @throw InvalidArgumentException If not a callback nor JS null.
+     */
+    JSValueRef toFunctionOrNull(const JSValueRef& arg);
+
+    /**
+     * @throw ConversionException If JS null.
+     * @throw InvalidArgumentException If not a callback nor JS null.
+     */
+    JSValueRef toFunction(const JSValueRef& arg);
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_DOWNLOAD_CONVERTER_H_ */
diff --git a/src/standards/Tizen/Download/DownloadListenerManager.cpp b/src/standards/Tizen/Download/DownloadListenerManager.cpp
new file mode 100755 (executable)
index 0000000..7dd8945
--- /dev/null
@@ -0,0 +1,22 @@
+//
+// 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 "DownloadListenerManager.h"
+#include <dpl/singleton_impl.h>
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::Download::DownloadListenerManager)
+
diff --git a/src/standards/Tizen/Download/DownloadListenerManager.h b/src/standards/Tizen/Download/DownloadListenerManager.h
new file mode 100755 (executable)
index 0000000..5bff7fe
--- /dev/null
@@ -0,0 +1,89 @@
+//
+// 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_DOWNLOAD_LISTENER_MANAGER_H_
+#define _TIZEN_DOWNLOAD_LISTENER_MANAGER_H_
+
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Tizen/Common/IListenerManager.h>
+#include "DownloadResponseDispatcher.h"
+#include "JSDownloadManager.h"
+#include <API/Download/IDownloadManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+using namespace TizenApis::Api::Download;
+
+class DownloadListenerManager : public TizenApis::Commons::IListenerController
+{
+public:
+       DownloadListenerManager()
+       {
+       }
+
+       virtual ~DownloadListenerManager()
+       {
+       }
+};
+typedef DPL::Singleton<DownloadListenerManager> DownloadListenerManagerSingleton;
+
+class DownloadListenerCanceller : public TizenApis::Commons::IListenerItem
+{
+public:
+       DownloadListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
+               TizenApis::Commons::IListenerItem(context, object, watchId)
+       {
+       }
+
+       virtual ~DownloadListenerCanceller()
+       {
+       }
+
+       virtual void cancelListener()
+       {
+               DownloadManagerPrivObject *privateObject = static_cast<DownloadManagerPrivObject*>(JSObjectGetPrivate(m_object));
+               if (!privateObject) {
+                       LogWarning("Object is null.");
+                       return;
+               }
+
+               IDownloadManagerPtr downloadManager = privateObject->getObject();
+
+               Try {
+                       LogDebug("Remove change listeners for download operation with id: "<<m_watchId);
+                       IEventCancelDownloadPtr dplEvent(new IEventCancelDownload());
+                       dplEvent->setDownloadId(m_watchId);
+                       dplEvent->setForSynchronousCall();
+                       downloadManager->cancelDownload(dplEvent);
+               } Catch(WrtDeviceApis::Commons::Exception) {
+                       LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               }
+       }
+};
+typedef DPL::SharedPtr<DownloadListenerCanceller> DownloadListenerCancellerPtr;
+
+} // Download
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_DOWNLOAD_LISTENER_MANAGER_H_
diff --git a/src/standards/Tizen/Download/DownloadMultiCallback.h b/src/standards/Tizen/Download/DownloadMultiCallback.h
new file mode 100755 (executable)
index 0000000..db3810c
--- /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.
+//
+
+#ifndef _DOWNLOAD_MULTI_CALLBACK_H_
+#define _DOWNLOAD_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 TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+class DownloadStateChangeCallbackPrivateData : public WrtDeviceApis::Commons::IEventPrivateData
+{
+public:
+    DownloadStateChangeCallbackPrivateData(const JSCallbackManagerPtr& onProgress,
+        const JSCallbackManagerPtr& onPaused,
+        const JSCallbackManagerPtr& onCanceled,
+        const JSCallbackManagerPtr& onCompleted,
+        const JSCallbackManagerPtr& onFailed):
+        m_onProgress(onProgress),
+        m_onPaused(onPaused),
+        m_onCanceled(onCanceled),
+        m_onCompleted(onCompleted),
+        m_onFailed(onFailed)
+    {
+    }
+
+    JSCallbackManagerPtr getOnProgress() const
+    {
+        return m_onProgress;
+    }
+    JSCallbackManagerPtr getOnPaused() const
+    {
+        return m_onPaused;
+    }
+    JSCallbackManagerPtr getOnCanceled() const
+    {
+        return m_onCanceled;
+    }
+    JSCallbackManagerPtr getOnCompleted() const
+    {
+        return m_onCompleted;
+    }
+    JSCallbackManagerPtr getOnFailed() const
+    {
+        return m_onFailed;
+    }
+
+    private:
+    JSCallbackManagerPtr m_onProgress;
+    JSCallbackManagerPtr m_onPaused;
+    JSCallbackManagerPtr m_onCanceled;
+    JSCallbackManagerPtr m_onCompleted;
+    JSCallbackManagerPtr m_onFailed;
+};
+typedef DPL::SharedPtr<DownloadStateChangeCallbackPrivateData> DownloadStateChangeCallbackPrivateDataPtr;
+
+}
+}
+}
+
+#endif /* _DOWNLOAD_MULTI_CALLBACK_H_ */
diff --git a/src/standards/Tizen/Download/DownloadResponseDispatcher.cpp b/src/standards/Tizen/Download/DownloadResponseDispatcher.cpp
new file mode 100755 (executable)
index 0000000..179ba33
--- /dev/null
@@ -0,0 +1,116 @@
+//
+// 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 "DownloadResponseDispatcher.h"
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include "DownloadConverter.h"
+#include "DownloadMultiCallback.h"
+
+#include <Tizen/Filesystem/FilesystemUtils.h>
+
+using namespace TizenApis::Api::Download;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+DownloadResponseDispatcher& DownloadResponseDispatcher::getInstance()
+{
+    static DownloadResponseDispatcher instance;
+    return instance;
+}
+
+DownloadResponseDispatcher::DownloadResponseDispatcher() :
+    OnDownloadStateChangedListener(ThreadEnum::NULL_THREAD)
+{
+}
+
+DownloadResponseDispatcher::~DownloadResponseDispatcher()
+{
+}
+
+void DownloadResponseDispatcher::onAnswerReceived(const OnDownloadStateChangedPtr& event)
+{
+    LogDebug("entered");
+    DownloadStateChangeCallbackPrivateDataPtr multiCallbacks =
+        DPL::StaticPointerCast<DownloadStateChangeCallbackPrivateData>(event->getPrivateData());
+    if (!multiCallbacks) {
+        LogError("No listener callback!");
+        return;
+    }
+
+    Try
+    {   
+        JSContextRef context = multiCallbacks->getOnProgress()->getContext();
+        if (event->getResult()) {
+            DownloadConverter converter(context);
+            JSValueRef downloadId = converter.toJSValueRefLong(event->getDownloadId());
+            if( 0==event->getDownloadState().compare(TIZEN_ENUM_DOWNLOAD_STATE_DOWNLOADING) ) {
+                JSValueRef receivedSize = converter.toJSValueRef((long long int) event->getReceivedSize());
+                JSValueRef totalSize = converter.toJSValueRef((long long int) event->getTotalSize());
+                JSValueRef objParam[3] = {downloadId, receivedSize, totalSize};
+                multiCallbacks->getOnProgress()->callOnSuccess(objParam, 3);
+            } else if( 0==event->getDownloadState().compare(TIZEN_ENUM_DOWNLOAD_STATE_QUEUED) ) {
+                LogInfo("Download started.");
+                JSValueRef receivedSize = converter.toJSValueRef((long long int) 0);
+                JSValueRef totalSize = converter.toJSValueRef((long long int) 0);
+                JSValueRef objParam[3] = {downloadId, receivedSize, totalSize};
+                multiCallbacks->getOnProgress()->callOnSuccess(objParam, 3);
+            } else if ( 0==event->getDownloadState().compare(TIZEN_ENUM_DOWNLOAD_STATE_PAUSED) ) {
+                LogInfo("Download paused.");
+                multiCallbacks->getOnPaused()->callOnSuccess(downloadId);
+            } else if ( 0==event->getDownloadState().compare(TIZEN_ENUM_DOWNLOAD_STATE_CANCELED) ) {
+                LogInfo("Download canceled.");
+                multiCallbacks->getOnCanceled()->callOnSuccess(downloadId);
+            } else if ( 0==event->getDownloadState().compare(TIZEN_ENUM_DOWNLOAD_STATE_COMPLETED) ) {
+                LogInfo("Download completed with full path: "<<event->getFullPath());
+                JSValueRef fullPath = converter.toJSValueRef(Utils::toVirtualPath(context, event->getFullPath()));
+                JSValueRef objParam[2] = {downloadId, fullPath};
+                multiCallbacks->getOnCompleted()->callOnSuccess(objParam, 2);
+            } else if ( 0==event->getDownloadState().compare(TIZEN_ENUM_DOWNLOAD_STATE_FAILED)) {
+                LogInfo("Download failed with: "<<event->getExceptionCode());
+                JSValueRef errorObject;
+                if (ExceptionCodes::PlatformException==event->getExceptionCode()) {
+                    errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                        context, TizenApis::Commons::JSTizenException::NETWORK_ERROR, event->getErrorMessage());
+                } else {
+                    errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(
+                        context, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR);
+                }
+                JSValueRef objParam[2] = {downloadId, errorObject};
+                multiCallbacks->getOnFailed()->callOnSuccess(objParam, 2);
+            } else {
+                LogWarning("Wrong download state.");
+            }
+        } else {
+            LogWarning("Failed result received.");
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Error during processing answer.");
+    }
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Download/DownloadResponseDispatcher.h b/src/standards/Tizen/Download/DownloadResponseDispatcher.h
new file mode 100755 (executable)
index 0000000..79c3953
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// 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 _DOWNLOAD_RESPONSE_DISPATCHER_H_
+#define _DOWNLOAD_RESPONSE_DISPATCHER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <Commons/EventListener.h>
+#include <API/Download/OnDownloadStateChanged.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+typedef WrtDeviceApis::Commons::EventListener<TizenApis::Api::Download::OnDownloadStateChanged>
+    OnDownloadStateChangedListener;
+
+class DownloadResponseDispatcher : public OnDownloadStateChangedListener
+{
+  public:
+    static DownloadResponseDispatcher& getInstance();
+
+  private:
+    DownloadResponseDispatcher();
+    virtual ~DownloadResponseDispatcher();
+
+  protected:
+    void onAnswerReceived(const TizenApis::Api::Download::OnDownloadStateChangedPtr& event);
+};
+
+}
+}
+}
+
+#endif /* _DOWNLOAD_RESPONSE_DISPATCHER_H_ */
diff --git a/src/standards/Tizen/Download/JSDownloadManager.cpp b/src/standards/Tizen/Download/JSDownloadManager.cpp
new file mode 100755 (executable)
index 0000000..001400d
--- /dev/null
@@ -0,0 +1,919 @@
+//
+// 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 <API/Download/OnDownloadStateChanged.h>
+#include <Tizen/Download/DownloadManager.h>
+
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "JSDownloadManager.h"
+#include "DownloadConverter.h"
+#include "JSDownloadRequest.h"
+#include "plugin_config.h"
+#include "DownloadResponseDispatcher.h"
+#include "DownloadMultiCallback.h"
+
+#include "DownloadListenerManager.h"
+
+#include <Tizen/Filesystem/FilesystemUtils.h>
+
+using namespace TizenApis::Api::Download;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 { 
+namespace Download {
+
+JSClassDefinition JSDownloadManager::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_DOWNLOAD_MANAGER_INTERFACE,
+    NULL, //ParentClass
+    NULL, //StaticValues
+    m_function,
+    initialize,
+    finalize,
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
+};
+
+JSStaticFunction JSDownloadManager::m_function[] = {
+    { DOWNLOAD_FUNCTION_API_START, startDownload, kJSPropertyAttributeNone },
+    { DOWNLOAD_FUNCTION_API_CANCEL, cancelDownload, kJSPropertyAttributeNone },
+    { DOWNLOAD_FUNCTION_API_PAUSE, pauseDownload, kJSPropertyAttributeNone },
+    { DOWNLOAD_FUNCTION_API_RESUME, resumeDownload, kJSPropertyAttributeNone },
+    { DOWNLOAD_FUNCTION_API_GET_STATE, getState, kJSPropertyAttributeNone },
+    { DOWNLOAD_FUNCTION_API_GET_DOWNLOAD_REQUEST, getDownloadRequest, kJSPropertyAttributeNone },
+    { DOWNLOAD_FUNCTION_API_GET_MIME_TYPE, getMIMEType, kJSPropertyAttributeNone },
+    { DOWNLOAD_FUNCTION_API_SET_LISTENER, setListener, kJSPropertyAttributeNone },
+
+    { 0, 0, 0 }
+};
+
+JSClassRef JSDownloadManager::m_jsClassRef = JSClassCreate(JSDownloadManager::getClassInfo());
+
+void JSDownloadManager::initialize(JSContextRef context, JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogInfo("Create download manager private object.");
+        IDownloadManagerPtr download(new TizenApis::Platform::Download::DownloadManager());
+        DownloadManagerPrivObject *priv = new DownloadManagerPrivObject(context, download);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    } else {
+        LogInfo("Private object already set.");
+    }
+}
+
+void JSDownloadManager::finalize(JSObjectRef object)
+{
+    DownloadManagerPrivObject *priv = static_cast<DownloadManagerPrivObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        LogInfo("Deleting download manager private object.");
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+const JSClassRef JSDownloadManager::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSDownloadManager::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSValueRef JSDownloadManager::startDownload(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    DownloadManagerPrivObject *privateObject =
+        static_cast<DownloadManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = DOWNLOAD_CHECK_ACCESS(DOWNLOAD_FUNCTION_API_START);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IDownloadManagerPtr downloadManager = privateObject->getObject();
+
+        JSContextRef globalContext = privateObject->getContext();
+
+        DownloadConverter converter(context);
+
+        if (argumentCount<1) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        DownloadRequestPtr downloadRequest;
+        if (!JSValueIsObjectOfClass(context, arguments[0], JSDownloadRequest::getClassRef())) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+        downloadRequest = JSDownloadRequest::getPrivateObject(JSValueToObject(context, arguments[0], NULL));
+        if (!downloadRequest) {
+            ThrowMsg(ConversionException, "Parameter conversion failed.");
+        }
+
+        try {
+            std::string destination = downloadRequest->getDestination();
+            if (!destination.empty()) {
+                Api::Filesystem::IPathPtr path = Utils::fromVirtualPath(context, destination);
+                downloadRequest->setDestinationFullPath(path->getFullPath());
+            }
+        } Catch(Exception) {
+            ThrowMsg(InvalidArgumentException, "Invalid request.destination : " << _rethrown_exception.GetMessage());
+        }
+
+        LogInfo("url: "<<downloadRequest->getUrl()<<", destination: "<<downloadRequest->getDestination()<<", fileName: "<<downloadRequest->getFileName());
+
+        // Process the download callback
+        JSCallbackManagerPtr onProgressCbm(NULL), onPausedCbm(NULL), onCanceledCbm(NULL), onCompletedCbm(NULL), onFailedCbm(NULL);
+        if (argumentCount>=2 && !JSValueIsNull(context, arguments[1]) && !JSValueIsUndefined(context, arguments[1])) {
+            JSObjectRef objectCallbacks = converter.toJSObjectRef(arguments[1]);
+            Validator validator(context);
+
+            JSValueRef onProgress = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onprogress");
+            if (validator.isNullOrUndefined(onProgress)) {
+                onProgress = NULL;
+            } else if(!validator.isCallback(onProgress)) {
+                ThrowMsg(ConversionException, "Wrong second parameter type.");
+            }
+
+            JSValueRef onPaused = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onpaused");
+            if (validator.isNullOrUndefined(onPaused)) {
+                onPaused = NULL;
+            } else if(!validator.isCallback(onPaused)) {
+                ThrowMsg(ConversionException, "Wrong second parameter type.");
+            }
+
+            JSValueRef onCanceled = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "oncanceled");
+            if (validator.isNullOrUndefined(onCanceled)) {
+                onCanceled = NULL;
+            } else if(!validator.isCallback(onCanceled)) {
+                ThrowMsg(ConversionException, "Wrong second parameter type.");
+            }
+
+            JSValueRef onCompleted = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "oncompleted");
+            if (validator.isNullOrUndefined(onCompleted)) {
+                onCompleted = NULL;
+            } else if(!validator.isCallback(onCompleted)) {
+                ThrowMsg(ConversionException, "Wrong second parameter type.");
+            }
+
+            JSValueRef onFailed = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onfailed");
+            if (validator.isNullOrUndefined(onFailed)) {
+                onFailed = NULL;
+            } else if(!validator.isCallback(onFailed)) {
+                ThrowMsg(ConversionException, "Wrong second parameter type.");
+            }
+
+            if (!onProgress && !onPaused && !onCanceled && !onCompleted && !onFailed) {
+                ThrowMsg(ConversionException, "Wrong second parameter type.");
+            }
+
+            onProgressCbm = JSCallbackManager::createObject(globalContext, onProgress, NULL);
+            onPausedCbm = JSCallbackManager::createObject(globalContext, onPaused, NULL);
+            onCanceledCbm = JSCallbackManager::createObject(globalContext, onCanceled, NULL);
+            onCompletedCbm = JSCallbackManager::createObject(globalContext, onCompleted, NULL);
+            onFailedCbm = JSCallbackManager::createObject(globalContext, onFailed, NULL);
+        }
+
+        LogDebug("Proceed the start download event to the platform.");
+
+        IEventStartDownloadPtr dplEvent(new IEventStartDownload());
+
+        if (onProgressCbm.Get() || onPausedCbm.Get() || onCanceledCbm.Get() || onCompletedCbm.Get() || onFailedCbm.Get()) {
+            DownloadStateChangeCallbackPrivateDataPtr privData(new DownloadStateChangeCallbackPrivateData(
+                onProgressCbm, onPausedCbm, onCanceledCbm, onCompletedCbm, onFailedCbm));
+            OnDownloadStateChangedEmitterPtr emitter(new OnDownloadStateChangedEmitter());
+            emitter->setListener(&DownloadResponseDispatcher::getInstance());
+            emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(privData));
+
+            dplEvent->setEmitter(emitter);
+        }
+
+        dplEvent->setDownloadRequest(downloadRequest);
+        dplEvent->setForSynchronousCall();
+        downloadManager->startDownload(dplEvent);
+
+        long downloadId;
+        if (dplEvent->getResult()) {
+            downloadId = dplEvent->getDownloadId();
+
+            DownloadListenerCancellerPtr canceller = DownloadListenerCancellerPtr(new DownloadListenerCanceller(globalContext, thisObject, downloadId));
+            TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+            DownloadListenerManagerSingleton::Instance().registerListener(listenerItem, globalContext);
+
+            LogDebug("Returning the downloadId "<<downloadId);
+            return converter.toJSValueRefLong(downloadId);
+        } else {
+            if (ExceptionCodes::PlatformException==dplEvent->getExceptionCode()) {
+                ThrowMsg(PlatformException, "Starting download failed by network error.");
+            } else {
+                ThrowMsg(UnknownException, "Starting download failed by unknown reason.");
+            }
+        }
+    }
+    Catch(PlatformException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NETWORK_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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSDownloadManager::setListener(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    DownloadManagerPrivObject *privateObject =
+        static_cast<DownloadManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IDownloadManagerPtr downloadManager = privateObject->getObject();
+
+        JSContextRef globalContext = privateObject->getContext();
+
+        if (argumentCount<2) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        DownloadConverter converter(context);
+        long downloadId = converter.toLong(arguments[0]);
+
+        // Process the listener and errorCallback
+        JSCallbackManagerPtr onProgressCbm(NULL), onPausedCbm(NULL), onCanceledCbm(NULL), onCompletedCbm(NULL), onFailedCbm(NULL);
+        JSObjectRef objectCallbacks = converter.toJSObjectRef(arguments[1]);
+        Validator validator(context);
+
+        JSValueRef onProgress = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onprogress");
+        if (validator.isNullOrUndefined(onProgress)) {
+            onProgress = NULL;
+        } else if(!validator.isCallback(onProgress)) {
+            ThrowMsg(ConversionException, "Wrong second parameter type.");
+        }
+
+        JSValueRef onPaused = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onpaused");
+        if (validator.isNullOrUndefined(onPaused)) {
+            onPaused = NULL;
+        } else if(!validator.isCallback(onPaused)) {
+            ThrowMsg(ConversionException, "Wrong second parameter type.");
+        }
+
+        JSValueRef onCanceled = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "oncanceled");
+        if (validator.isNullOrUndefined(onCanceled)) {
+            onCanceled = NULL;
+        } else if(!validator.isCallback(onCanceled)) {
+            ThrowMsg(ConversionException, "Wrong second parameter type.");
+        }
+
+        JSValueRef onCompleted = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "oncompleted");
+        if (validator.isNullOrUndefined(onCompleted)) {
+            onCompleted = NULL;
+        } else if(!validator.isCallback(onCompleted)) {
+            ThrowMsg(ConversionException, "Wrong second parameter type.");
+        }
+
+        JSValueRef onFailed = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onfailed");
+        if (validator.isNullOrUndefined(onFailed)) {
+            onFailed = NULL;
+        } else if(!validator.isCallback(onFailed)) {
+            ThrowMsg(ConversionException, "Wrong second parameter type.");
+        }
+
+        if (!onProgress && !onPaused && !onCanceled && !onCompleted && !onFailed) {
+            ThrowMsg(ConversionException, "Wrong second parameter type.");
+        }
+
+        onProgressCbm = JSCallbackManager::createObject(globalContext, onProgress, NULL);
+        onPausedCbm = JSCallbackManager::createObject(globalContext, onPaused, NULL);
+        onCanceledCbm = JSCallbackManager::createObject(globalContext, onCanceled, NULL);
+        onCompletedCbm = JSCallbackManager::createObject(globalContext, onCompleted, NULL);
+        onFailedCbm = JSCallbackManager::createObject(globalContext, onFailed, NULL);
+
+        DownloadStateChangeCallbackPrivateDataPtr privData(new DownloadStateChangeCallbackPrivateData(
+            onProgressCbm, onPausedCbm, onCanceledCbm, onCompletedCbm, onFailedCbm));
+        OnDownloadStateChangedEmitterPtr emitter(new OnDownloadStateChangedEmitter());
+        emitter->setListener(&DownloadResponseDispatcher::getInstance());
+        emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(privData));
+
+        LogDebug("Proceed the set listener event to the platform.");
+
+        IEventSetListenerPtr dplEvent(new IEventSetListener());
+        dplEvent->setEmitter(emitter);
+        dplEvent->setDownloadId(downloadId);
+        dplEvent->setForSynchronousCall();
+        downloadManager->setListener(dplEvent);
+
+        if (dplEvent->getResult()) {
+            DownloadListenerCancellerPtr canceller = DownloadListenerCancellerPtr(new DownloadListenerCanceller(globalContext, thisObject, downloadId));
+            TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+            DownloadListenerManagerSingleton::Instance().registerListener(listenerItem, globalContext);
+
+            LogDebug("Setting the listener succeeded.");
+        } else {
+            switch (dplEvent->getExceptionCode()) {
+                case ExceptionCodes::NotFoundException:
+                    ThrowMsg(NotFoundException, "Id not found.");
+                    break;
+                case ExceptionCodes::InvalidArgumentException:
+                    ThrowMsg(InvalidArgumentException, "Invalid argument");
+                    break;
+                default:
+                    ThrowMsg(UnknownException, "Setting the listener failed by unknown reason.");
+                    break;
+            }
+        }
+    }
+    Catch(PlatformException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NETWORK_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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_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);
+}
+
+JSValueRef JSDownloadManager::cancelDownload(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    DownloadManagerPrivObject *privateObject =
+        static_cast<DownloadManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IDownloadManagerPtr downloadManager = privateObject->getObject();
+
+        DownloadConverter converter(context);
+
+        long downloadId = 0;
+        if (argumentCount > 0) {
+            downloadId = converter.toLong(arguments[0]);
+        }
+
+        LogDebug("Make sync operation for cancel download: "<<downloadId);
+
+        IEventCancelDownloadPtr dplEvent(new IEventCancelDownload());
+        dplEvent->setDownloadId(downloadId);
+        dplEvent->setForSynchronousCall();
+        downloadManager->cancelDownload(dplEvent);
+
+        if (!dplEvent->getResult()) {
+            switch (dplEvent->getExceptionCode()) {
+                case ExceptionCodes::NotFoundException:
+                    ThrowMsg(NotFoundException, "Id not found.");
+                    break;
+                case ExceptionCodes::InvalidArgumentException:
+                    ThrowMsg(InvalidArgumentException, "Invalid argument");
+                    break;
+                default:
+                    ThrowMsg(UnknownException, "Canceling download failed.");
+                    break;
+            }
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_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);
+}
+
+JSValueRef JSDownloadManager::pauseDownload(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    DownloadManagerPrivObject *privateObject =
+        static_cast<DownloadManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IDownloadManagerPtr downloadManager = privateObject->getObject();
+
+        DownloadConverter converter(context);
+
+        long downloadId = 0;
+        if (argumentCount > 0) {
+            downloadId = converter.toLong(arguments[0]);
+        }
+
+
+        LogDebug("Make sync operation for pause download: "<<downloadId);
+
+        IEventPauseDownloadPtr dplEvent(new IEventPauseDownload());
+        dplEvent->setDownloadId(downloadId);
+        dplEvent->setForSynchronousCall();
+        downloadManager->pauseDownload(dplEvent);
+
+        if (!dplEvent->getResult()) {
+            switch (dplEvent->getExceptionCode()) {
+                case ExceptionCodes::NotFoundException:
+                    ThrowMsg(NotFoundException, "Id not found.");
+                    break;
+                case ExceptionCodes::InvalidArgumentException:
+                    ThrowMsg(InvalidArgumentException, "Invalid argument");
+                    break;
+                default:
+                    ThrowMsg(UnknownException, "Pausing download failed.");
+                    break;
+            }
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_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);
+}
+
+JSValueRef JSDownloadManager::resumeDownload(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    DownloadManagerPrivObject *privateObject =
+        static_cast<DownloadManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IDownloadManagerPtr downloadManager = privateObject->getObject();
+
+        DownloadConverter converter(context);
+
+        long downloadId = 0;
+        if (argumentCount > 0) {
+            downloadId = converter.toLong(arguments[0]);
+        }
+
+        LogDebug("Make sync operation for resume download: "<<downloadId);
+
+        IEventResumeDownloadPtr dplEvent(new IEventResumeDownload());
+        dplEvent->setDownloadId(downloadId);
+        dplEvent->setForSynchronousCall();
+        downloadManager->resumeDownload(dplEvent);
+
+        if (!dplEvent->getResult()) {
+            switch (dplEvent->getExceptionCode()) {
+                case ExceptionCodes::NotFoundException:
+                    ThrowMsg(NotFoundException, "Id not found.");
+                    break;
+                case ExceptionCodes::InvalidArgumentException:
+                    ThrowMsg(InvalidArgumentException, "Invalid argument");
+                    break;
+                default:
+                    ThrowMsg(UnknownException, "Resuming download failed.");
+                    break;
+            }
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_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);
+}
+
+JSValueRef JSDownloadManager::getState(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    DownloadManagerPrivObject *privateObject =
+        static_cast<DownloadManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IDownloadManagerPtr downloadManager = privateObject->getObject();
+
+        DownloadConverter converter(context);
+
+        long downloadId = 0;
+        if (argumentCount > 0) {
+            downloadId = converter.toLong(arguments[0]);
+        }
+
+        LogDebug("Make sync operation for get state download: "<<downloadId);
+
+        IEventGetStatePtr dplEvent(new IEventGetState());
+        dplEvent->setDownloadId(downloadId);
+        dplEvent->setForSynchronousCall();
+        downloadManager->getState(dplEvent);
+
+        if (dplEvent->getResult()) {
+            std::string downloadState = dplEvent->getDownloadState();
+            LogDebug("Returning the downloadState "<<downloadState);
+            return converter.toJSValueRef(downloadState);
+        } else {
+            switch (dplEvent->getExceptionCode()) {
+                case ExceptionCodes::NotFoundException:
+                    ThrowMsg(NotFoundException, "Id not found.");
+                    break;
+                case ExceptionCodes::InvalidArgumentException:
+                    ThrowMsg(InvalidArgumentException, "Invalid argument");
+                    break;
+                default:
+                    ThrowMsg(UnknownException, "Getting download state failed.");
+                    break;
+            }
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSDownloadManager::getDownloadRequest(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    DownloadManagerPrivObject *privateObject =
+        static_cast<DownloadManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IDownloadManagerPtr downloadManager = privateObject->getObject();
+
+        DownloadConverter converter(context);
+
+        long downloadId = 0;
+        if (argumentCount > 0) {
+            downloadId = converter.toLong(arguments[0]);
+        }
+
+        LogDebug("Make sync operation for get DownloadRequest: "<<downloadId);
+
+        IEventGetDownloadRequestPtr dplEvent(new IEventGetDownloadRequest());
+        dplEvent->setDownloadId(downloadId);
+        dplEvent->setForSynchronousCall();
+        downloadManager->getDownloadRequest(dplEvent);
+
+        if (dplEvent->getResult()) {
+            DownloadRequestPtr downloadRequest = dplEvent->getDownloadRequest();
+            std::string destination = "";
+            Try {
+                destination = Utils::toVirtualPath(context, downloadRequest->getDestination());
+            } Catch (ConversionException) {
+                LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+            }
+            downloadRequest->setDestination(destination);
+            return JSDownloadRequest::createJSDownloadRequest(context, downloadRequest);
+        } else {
+            switch (dplEvent->getExceptionCode()) {
+                case ExceptionCodes::NotFoundException:
+                    ThrowMsg(NotFoundException, "Id not found.");
+                    break;
+                case ExceptionCodes::InvalidArgumentException:
+                    ThrowMsg(InvalidArgumentException, "Invalid argument");
+                    break;
+                default:
+                    ThrowMsg(UnknownException, "Getting DownloadRequest failed.");
+                    break;
+            }
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSDownloadManager::getMIMEType(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    DownloadManagerPrivObject *privateObject =
+        static_cast<DownloadManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IDownloadManagerPtr downloadManager = privateObject->getObject();
+
+        DownloadConverter converter(context);
+
+        long downloadId = 0;
+        if (argumentCount > 0) {
+            downloadId = converter.toLong(arguments[0]);
+        }
+
+        LogDebug("Make sync operation for get MIME type: "<<downloadId);
+
+        IEventGetMIMETypePtr dplEvent(new IEventGetMIMEType());
+        dplEvent->setDownloadId(downloadId);
+        dplEvent->setForSynchronousCall();
+        downloadManager->getMIMEType(dplEvent);
+
+        if (dplEvent->getResult()) {
+            return converter.toJSValueRef(dplEvent->getMIMEType());
+        } else {
+            switch (dplEvent->getExceptionCode()) {
+                case ExceptionCodes::NotFoundException:
+                    ThrowMsg(NotFoundException, "Id not found.");
+                    break;
+                case ExceptionCodes::InvalidArgumentException:
+                    ThrowMsg(InvalidArgumentException, "Invalid argument");
+                    break;
+                default:
+                    ThrowMsg(UnknownException, "Getting MIME type failed.");
+                    break;
+            }
+        }
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch (NotFoundException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Download/JSDownloadManager.h b/src/standards/Tizen/Download/JSDownloadManager.h
new file mode 100755 (executable)
index 0000000..83446ba
--- /dev/null
@@ -0,0 +1,163 @@
+//
+// 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 _JS_TIZEN_DOWNLOAD_MANAGER_H_
+#define _JS_TIZEN_DOWNLOAD_MANAGER_H_
+
+#include <string>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Download/IDownloadManager.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+#define TIZEN_DOWNLOAD_MANAGER_INTERFACE "DownloadManager"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Download::IDownloadManagerPtr,
+                               WrtDeviceApis::CommonsJavaScript::NoOwnership> DownloadManagerPrivObject;
+
+class JSDownloadManager
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+  private:
+
+    /**
+     * 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;
+
+    /**
+     * 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);
+
+    /**
+     * Start a download operation.
+     */
+    static JSValueRef startDownload(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Cancel a download operation.
+     */
+    static JSValueRef cancelDownload(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Pause a download operation.
+     */
+    static JSValueRef pauseDownload(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Resume a paused download operation.
+     */
+    static JSValueRef resumeDownload(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Get the current state of a download operation.
+     */
+    static JSValueRef getState(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Get the DownloadRequest of a download operation.
+     */
+    static JSValueRef getDownloadRequest(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Get the MIME type of a downloaded file.
+     */
+    static JSValueRef getMIMEType(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Set the listener to the ongoing download operation.
+     */
+    static JSValueRef setListener(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_DOWNLOAD_MANAGER_H_ */
+
diff --git a/src/standards/Tizen/Download/JSDownloadRequest.cpp b/src/standards/Tizen/Download/JSDownloadRequest.cpp
new file mode 100755 (executable)
index 0000000..07d431a
--- /dev/null
@@ -0,0 +1,275 @@
+//
+// 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 "JSDownloadRequest.h"
+#include <dpl/log/log.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <CommonsJavaScript/Converter.h>
+#include "DownloadConverter.h"
+
+#include <Tizen/Filesystem/FilesystemUtils.h>
+
+using namespace TizenApis::Api::Download;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+JSClassDefinition JSDownloadRequest::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_DOWNLOAD_REQUEST_INTERFACE,
+    NULL, //parentClass
+    m_property,
+    NULL, //staticValues,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL, //callAsFunction,
+    constructor,
+    hasInstance,
+    NULL, //convertToType,
+};
+
+JSStaticValue JSDownloadRequest::m_property[] = {
+    { TIZEN_DOWNLOAD_REQUEST_URL, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_DOWNLOAD_REQUEST_DESTINATION, getProperty, setProperty, kJSPropertyAttributeNone },
+    { TIZEN_DOWNLOAD_REQUEST_FILE_NAME, getProperty, setProperty, kJSPropertyAttributeNone },
+
+    { 0, 0, 0, 0 }
+};
+
+JSClassRef JSDownloadRequest::m_jsClassRef = JSClassCreate(
+        JSDownloadRequest::getClassInfo());
+
+const JSClassDefinition* JSDownloadRequest::getClassInfo()
+{
+    return &(m_classInfo);
+}
+
+JSClassRef JSDownloadRequest::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+JSObjectRef JSDownloadRequest::createJSDownloadRequest(JSContextRef context, DownloadRequestPtr downloadRequest)
+{
+    DownloadRequestPrivateObject *priv = new DownloadRequestPrivateObject(context, downloadRequest);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+void JSDownloadRequest::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogDebug("Create DownloadRequest private object.");
+        DownloadRequestPtr downloadRequest( new DownloadRequest() );
+        DownloadRequestPrivateObject *priv = new DownloadRequestPrivateObject(context, downloadRequest);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    } else {
+        LogDebug("Private object alrerady set.");
+    }
+}
+
+void JSDownloadRequest::finalize(JSObjectRef object)
+{
+    DownloadRequestPrivateObject* priv = static_cast<DownloadRequestPrivateObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        LogDebug("Deleting DownloadRequest private object.");
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+
+bool JSDownloadRequest::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+DownloadRequestPtr JSDownloadRequest::getPrivateObject(JSObjectRef object)
+{
+    DownloadRequestPrivateObject *priv = static_cast<DownloadRequestPrivateObject*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        ThrowMsg(NullPointerException, "Private object is null.");
+    }
+
+    DownloadRequestPtr downloadRequest = priv->getObject();
+    if (!downloadRequest) {
+        ThrowMsg(NullPointerException, "DownloadRequest object is null.");
+    }
+    return downloadRequest;
+}
+
+void JSDownloadRequest::setPrivateObject(const DownloadRequestPtr &downloadRequest,
+        JSContextRef ctx,
+        const JSObjectRef object)
+{
+    Try
+    {
+        DownloadRequestPrivateObject *priv = static_cast<DownloadRequestPrivateObject*>(JSObjectGetPrivate(object));
+        delete priv;
+        priv = new DownloadRequestPrivateObject(ctx, downloadRequest);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Error during setting DownloadRequest object.");
+    }
+}
+
+JSObjectRef JSDownloadRequest::constructor(JSContextRef context,
+    JSObjectRef constructor,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        DownloadConverter converter(context);
+
+        DownloadRequestPtr downloadRequest( new DownloadRequest() );
+
+        if (argumentCount<1) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        } else {
+            downloadRequest->setUrl(converter.toString(arguments[0]));
+        }
+        if (argumentCount>1) {
+            downloadRequest->setDestination(converter.toString(arguments[1]));
+        }
+        if (argumentCount>2) {
+            downloadRequest->setFileName(converter.toString(arguments[2]));
+        }
+        LogInfo("url: "<<downloadRequest->getUrl()<<", destination: "<<downloadRequest->getDestination()<<", fileName: "<<downloadRequest->getFileName());
+
+        return createJSDownloadRequest(context, downloadRequest);
+    }
+    Catch(UnsupportedException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(InvalidArgumentException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(ConversionException)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+        LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+
+    return NULL;
+}
+
+JSValueRef JSDownloadRequest::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("enter");
+
+    Try
+    {
+        DownloadRequestPrivateObject* priv = static_cast<DownloadRequestPrivateObject*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            ThrowMsg(NullPointerException, "Private object is NULL.");
+        }
+        DownloadRequestPtr downloadRequest = priv->getObject();
+
+        DownloadConverter converter(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_URL)) {
+            return converter.toJSValueRef(downloadRequest->getUrl());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_DESTINATION)) {
+            return converter.toJSValueRef(downloadRequest->getDestination());
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_FILE_NAME)) {
+            return converter.toJSValueRef(downloadRequest->getFileName());
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSDownloadRequest::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        DownloadRequestPrivateObject* priv =
+            static_cast<DownloadRequestPrivateObject*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            ThrowMsg(NullPointerException, "DownloadRequest object is NULL.");
+        }
+        DownloadRequestPtr downloadRequest = priv->getObject();
+
+        DownloadConverter converter(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_URL)) {
+            downloadRequest->setUrl(converter.toString(value));
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_DESTINATION)) {
+            downloadRequest->setDestination(converter.toString(value));
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_DOWNLOAD_REQUEST_FILE_NAME)) {
+            downloadRequest->setFileName(converter.toString(value));
+            return true;
+        }
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+    }
+    JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR);
+    return false;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Download/JSDownloadRequest.h b/src/standards/Tizen/Download/JSDownloadRequest.h
new file mode 100755 (executable)
index 0000000..9cce834
--- /dev/null
@@ -0,0 +1,111 @@
+//
+// 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 _JS_DOWNLOAD_REQUEST_H_
+#define _JS_DOWNLOAD_REQUEST_H_
+
+#include <string>
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Download/DownloadRequest.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+#define TIZEN_DOWNLOAD_REQUEST_INTERFACE "DownloadRequest"
+
+#define TIZEN_DOWNLOAD_REQUEST_URL "url"
+#define TIZEN_DOWNLOAD_REQUEST_DESTINATION "destination"
+#define TIZEN_DOWNLOAD_REQUEST_FILE_NAME "fileName"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Download::DownloadRequestPtr,
+       WrtDeviceApis::CommonsJavaScript::NoOwnership> DownloadRequestPrivateObject;
+
+class JSDownloadRequest
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static JSClassRef getClassRef();
+
+    static JSObjectRef createJSDownloadRequest(JSContextRef context, TizenApis::Api::Download::DownloadRequestPtr downloadRequest);
+
+    static TizenApis::Api::Download::DownloadRequestPtr getPrivateObject(JSObjectRef object);
+
+    static void setPrivateObject(const TizenApis::Api::Download::DownloadRequestPtr &downloadRequest,
+            JSContextRef ctx,
+            const JSObjectRef object);
+
+  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);
+
+       /**
+        * Constructor for the DownloadRequest interface.
+        */
+       static JSObjectRef constructor(JSContextRef context,
+                   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 bool hasInstance(JSContextRef context,
+            JSObjectRef constructor,
+            JSValueRef possibleInstance,
+            JSValueRef* exception);
+
+    static JSClassRef m_jsClassRef;
+
+    /**
+     * 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 /* _JS_DOWNLOAD_REQUEST_H_ */
diff --git a/src/standards/Tizen/Download/config.xml b/src/standards/Tizen/Download/config.xml
new file mode 100755 (executable)
index 0000000..19de436
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+    <library-name>libwrt-plugins-tizen-2.0-download.so</library-name>
+    <feature-install-uri>download.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/download</name>
+        <device-capability>download</device-capability>
+    </api-feature>
+
+</plugin-properties>
\ No newline at end of file
diff --git a/src/standards/Tizen/Download/plugin_config.cpp b/src/standards/Tizen/Download/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..072193e
--- /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 <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include <dpl/exception.h>
+#include <map>
+
+#include "plugin_config.h"
+
+#define DOWNLOAD_FEATURE_API "http://tizen.org/privilege/download"
+
+#define DOWNLOAD_DEVICE_CAP "download"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+static FunctionMapping createDownloadFunctions();
+
+static FunctionMapping DownloadFunctions =
+    createDownloadFunctions();
+
+DEFINE_FUNCTION_GETTER(Download, DownloadFunctions);
+
+static FunctionMapping createDownloadFunctions()
+{
+    /**
+     * Device capabilities
+     */
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_DOWNLOAD, DOWNLOAD_DEVICE_CAP);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_DOWNLOAD);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_DOWNLOAD, DEVICE_CAP_DOWNLOAD);
+
+    /**
+     * Api Features
+     */
+    ACE_CREATE_FEATURE(FEATURE_DOWNLOAD, DOWNLOAD_FEATURE_API);
+
+    ACE_CREATE_FEATURE_LIST(DOWNLOAD_FEATURES);
+    ACE_ADD_API_FEATURE(DOWNLOAD_FEATURES, FEATURE_DOWNLOAD);
+
+    /**
+     * Functions
+     */
+    FunctionMapping downloadMapping;
+
+    // start
+    AceFunction startFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_START,
+            DOWNLOAD_FUNCTION_API_START,
+            DOWNLOAD_FEATURES,
+            DEVICE_LIST_DOWNLOAD);
+
+    downloadMapping.insert(std::make_pair(
+                               DOWNLOAD_FUNCTION_API_START,
+                               startFunc));
+
+    return downloadMapping;
+}
+
+}
+} 
+}
diff --git a/src/standards/Tizen/Download/plugin_config.h b/src/standards/Tizen/Download/plugin_config.h
new file mode 100755 (executable)
index 0000000..2f0a239
--- /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 _DOWNLOAD_PLUGIN_CONFIG_H_
+#define _DOWNLOAD_PLUGIN_CONFIG_H_
+
+#include <string>
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+// Functions from download manager
+#define DOWNLOAD_FUNCTION_API_START "start"
+#define DOWNLOAD_FUNCTION_API_CANCEL "cancel"
+#define DOWNLOAD_FUNCTION_API_PAUSE "pause"
+#define DOWNLOAD_FUNCTION_API_RESUME "resume"
+#define DOWNLOAD_FUNCTION_API_GET_STATE "getState"
+#define DOWNLOAD_FUNCTION_API_GET_DOWNLOAD_REQUEST "getDownloadRequest"
+#define DOWNLOAD_FUNCTION_API_GET_MIME_TYPE "getMIMEType"
+#define DOWNLOAD_FUNCTION_API_SET_LISTENER "setListener"
+
+DECLARE_FUNCTION_GETTER(Download);
+
+#define DOWNLOAD_CHECK_ACCESS(functionName) \
+       aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >( \
+       getDownloadFunctionData, \
+       functionName)
+}
+}
+}
+
+#endif // _DOWNLOAD_PLUGIN_CONFIG_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/Download/plugin_initializer.cpp b/src/standards/Tizen/Download/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..f01f2ce
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <Commons/Exception.h>
+#include "JSDownloadManager.h"
+#include "JSDownloadRequest.h"
+
+#include "DownloadListenerManager.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Download {
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Commons;
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[Tizen\\Download] on_widget_start_callback (" << widgetId << ")");
+
+       Try {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+       } Catch (Exception) {
+               LogError("WrtAccess initialization failed");
+       }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[Tizen\\Download] on_widget_stop_callback (" << widgetId << ")");
+
+       Try {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+       } Catch (Exception) {
+               LogError("WrtAccess deinitialization failed");
+       }
+}
+
+void on_frame_load_callback(const void * context)
+{
+    LogDebug("[Tizen\\Download] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LogDebug("[Tizen\\Download] on_frame_unload_callback (" << context << ")");
+
+       TizenApis::Tizen1_0::Download::DownloadListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+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,
+        "download",
+        (js_class_template_getter)JSDownloadManager::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        TIZEN_DOWNLOAD_REQUEST_INTERFACE,
+        (js_class_template_getter)JSDownloadRequest::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_END
+
+}
+}
+}
+
diff --git a/src/standards/Tizen/Filesystem/CMakeLists.txt b/src/standards/Tizen/Filesystem/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..98e69d3
--- /dev/null
@@ -0,0 +1,48 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-filesystem")
+set(DESTINATION_NAME "tizen-2.0-filesystem")
+set(TARGET_IMPL_NAME "wrt-plugins-tizen-2.0-filesystem-impl")
+
+include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_FILESYSTEM})
+
+set(CMAKE_INSTALL_RPATH
+  ${CMAKE_INSTALL_RPATH}
+  ${CMAKE_INSTALL_PREFIX}/${DESTINATION_NAME}
+)
+
+set(SRCS_IMPL
+  ${SRCS_PLATFORM_API_FILESYSTEM}
+  ${SRCS_PLATFORM_IMPLEMENTATION_FILESYSTEM}
+  JSFilesystemManager.cpp
+  JSFile.cpp
+  JSFilestream.cpp
+  JSStorage.cpp
+  Converter.cpp
+  EventGetNodeData.cpp
+  plugin_config.cpp
+  Encodings.cpp
+  StorageStaticController.cpp
+  FilesystemUtils.cpp
+  ResponseDispatcher.cpp
+  FilesystemAsyncCallbackManager.cpp
+  FilesystemListenerManager.cpp
+)
+
+add_library(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
+target_link_libraries(${TARGET_IMPL_NAME}
+  wrt-plugins-tizen-2.0-tizen-impl
+  ${LIBS_COMMON}
+  ${LIBS_WIDGETDB}
+  ${LIBS_PLATFORM_IMPLEMENTATION_FILESYSTEM}
+)
+
+set(SRCS
+  plugin_initializer.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${TARGET_IMPL_NAME}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
diff --git a/src/standards/Tizen/Filesystem/Converter.cpp b/src/standards/Tizen/Filesystem/Converter.cpp
new file mode 100755 (executable)
index 0000000..5a78745
--- /dev/null
@@ -0,0 +1,293 @@
+//
+// 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 "Converter.h"
+#include <dpl/log/log.h>
+
+#include <API/Filesystem/IManager.h>
+#include <API/Filesystem/IPath.h>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include "FilesystemUtils.h"
+#include "JSFile.h"
+#include "Encodings.h"
+#include "JSStorage.h"
+
+namespace {
+const char* PROPERTY_FILEFILTER_NAME = "name";
+const char* PROPERTY_FILEFILTER_START_CREATED = "startCreated";
+const char* PROPERTY_FILEFILTER_END_CREATED = "endCreated";
+const char* PROPERTY_FILEFILTER_START_MODIFIED = "startModified";
+const char* PROPERTY_FILEFILTER_END_MODIFIED = "endModified";
+const char* ACCESS_MODE_READ = "r";
+const char* ACCESS_MODE_APPEND = "a";
+const char* ACCESS_MODE_WRITE = "w";
+const char* ACCESS_MODE_READ_WRITE = "rw";
+const char* STORAGE_TYPE_STATE_MOUNTED = "MOUNTED";
+const char* STORAGE_TYPE_STATE_REMOVED = "REMOVED";
+const char* STORAGE_TYPE_STATE_UNMOUNTABLE = "REMOVED";
+const char* STORAGE_TYPE_INTERNAL = "INTERNAL";
+const char* STORAGE_TYPE_EXTERNAL = "EXTERNAL";
+
+
+const char* ENCODINGS[] = {
+    TizenApis::Tizen1_0::Encodings::UTF8,
+    TizenApis::Tizen1_0::Encodings::ISO88591,
+    NULL
+};
+} // namespace
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Filesystem;
+
+namespace TizenApis {
+namespace Tizen1_0{
+Converter::Converter(JSContextRef context) : WrtDeviceApis::CommonsJavaScript::Converter(context)
+{
+}
+
+JSValueRef Converter::toJSValueRef(
+        const NodeList& arg,
+        const JSFile::PrivateObjectDef::PermissionList &parentPermissions,
+        JSContextRef context)
+{
+    JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+    if (!jsResult) {
+        ThrowMsg(Commons::ConversionException,
+                 "Could not create js array object");
+    }
+
+    for (std::size_t i = 0; i < arg.size(); ++i)
+    {
+        JSFile::PrivateObjectDefPtr privData(
+                new JSFile::PrivateObjectDef(
+                    arg[i],
+                    parentPermissions));
+        JSFile::PrivateObject* privateObject = new JSFile::PrivateObject(
+                context,
+                privData);
+        JSObjectRef jsObject = JSObjectMake(m_context,
+                                            JSFile::getClassRef(),
+                                            privateObject);
+        if (!jsObject) {
+            delete privateObject;
+            ThrowMsg(Commons::ConversionException,
+                     "Could not create JS object.");
+        }
+        if (!JSSetArrayElement(m_context, jsResult, i, jsObject)) {
+            ThrowMsg(Commons::ConversionException,
+                     "Could not insert value into js array");
+        }
+    }
+
+    return jsResult;
+}
+
+
+JSValueRef Converter::toJSValueRef(unsigned char* data, std::size_t num)
+{
+       JSObjectRef result = JSCreateArrayObject(m_context, 0, NULL);
+       if (!result) {
+               ThrowMsg(Commons::ConversionException, "Could not create array object.");
+       }
+
+       for (std::size_t i = 0; i < num; ++i) {
+               JSValueRef value = JSValueMakeNumber(m_context, data[i]);
+               if (!JSSetArrayElement(m_context, result, i, value)) {
+                       ThrowMsg(Commons::ConversionException, "Could not fill array.");
+               }
+       }
+
+       return result;
+}
+
+Api::Filesystem::IPathPtr Converter::toPath(const JSValueRef& arg)
+{
+       Try {
+               std::string path = toString(arg);
+               if (!Utils::isPathValid(path)) {
+                       ThrowMsg(Commons::InvalidArgumentException, "Invalid path component.");
+               }
+               return Api::Filesystem::IPath::create(path);
+       } Catch (Commons::ConversionException) {
+               ReThrowMsg(Commons::ConversionException, "Not a valid path.");
+       }
+}
+
+Api::Filesystem::NodeFilterPtr Converter::toNodeFilter(const JSValueRef& arg)
+{
+       JSObjectRef filter = toJSObjectRef(arg);
+
+       Api::Filesystem::NodeFilterPtr result(new Api::Filesystem::NodeFilter());
+       JSValueRef prop = NULL;
+       prop = JSUtils::getJSProperty(m_context, filter, PROPERTY_FILEFILTER_NAME);
+       if (prop) {
+               result->setName(toString(prop));
+       }
+
+       prop = JSUtils::getJSProperty(m_context, filter, PROPERTY_FILEFILTER_START_CREATED);
+       if (prop) {
+               result->setMinCreated(toDateTimeT(prop));
+       }
+
+       prop = JSUtils::getJSProperty(m_context, filter, PROPERTY_FILEFILTER_END_CREATED);
+       if (prop) {
+               result->setMaxCreated(toDateTimeT(prop));
+       }
+
+       prop = JSUtils::getJSProperty(m_context, filter, PROPERTY_FILEFILTER_START_MODIFIED);
+       if (prop) {
+               result->setMinModified(toDateTimeT(prop));
+       }
+
+       prop = JSUtils::getJSProperty(m_context, filter, PROPERTY_FILEFILTER_END_MODIFIED);
+       if (prop) {
+               result->setMaxModified(toDateTimeT(prop));
+       }
+
+       return result;
+}
+
+Api::Filesystem::AccessMode Converter::toAccessMode(const JSValueRef& arg)
+{
+       std::string mode = toString_(arg);
+       if (ACCESS_MODE_READ == mode) {
+               return Api::Filesystem::AM_READ;
+       } else if (ACCESS_MODE_APPEND == mode) {
+               return Api::Filesystem::AM_APPEND;
+       } else if (ACCESS_MODE_WRITE == mode) {
+               return Api::Filesystem::AM_WRITE;
+       } else if (ACCESS_MODE_READ_WRITE == mode) {
+               return Api::Filesystem::AM_WRITE;
+       }
+       
+       ThrowMsg(Commons::ConversionException, "Invalid mode.");
+}
+
+std::string Converter::toEncoding(const JSValueRef& arg)
+{
+       std::string result = toString_(arg);
+       const char** ptr = ENCODINGS;
+       while (*ptr) {
+               if (result == *ptr) {
+                       return result;
+               }
+               ++ptr;
+       }
+       ThrowMsg(Commons::ConversionException, "Invalid encoding");
+}
+JSValueRef Converter::toStorageState(const short type)
+{
+       switch (type) 
+       {
+               case JSStorage::STATE_MOUNTED:
+                       return toJSValueRef(STORAGE_TYPE_STATE_MOUNTED);
+               case JSStorage::STATE_REMOVED:
+                       return toJSValueRef(STORAGE_TYPE_STATE_REMOVED);
+               case JSStorage::STATE_UNMOUNTABLE:
+                       return toJSValueRef(STORAGE_TYPE_STATE_UNMOUNTABLE);
+       }
+       ThrowMsg(Commons::ConversionException, "Invalid storage type");
+}
+
+JSValueRef Converter::toStorageType(const short state)
+{
+       switch (state) 
+       {
+               case Api::Filesystem::StorageProperties::TYPE_INTERNAL:
+                       return toJSValueRef(STORAGE_TYPE_INTERNAL);
+               case Api::Filesystem::StorageProperties::TYPE_EXTERNAL:
+                       return toJSValueRef(STORAGE_TYPE_EXTERNAL);
+       }
+       ThrowMsg(Commons::ConversionException, "Invalid storage state");
+}
+
+JSValueRef Converter::toJSValueRef(
+        const Api::Filesystem::StoragePropertiesPtr &arg,
+        JSContextRef context)
+{
+       Api::Filesystem::StorageProperties tmpStorage;
+
+       tmpStorage.setLabel(arg->getLabel()); 
+       tmpStorage.setType(arg->getType());
+
+       switch (arg->getState()) {
+       case Api::Filesystem::StorageProperties::STATE_MOUNTED :
+       case Api::Filesystem::StorageProperties::STATE_MOUNTED_READONLY :
+               tmpStorage.setState(JSStorage::STATE_MOUNTED);
+               break;
+       case Api::Filesystem::StorageProperties::STATE_REMOVED:
+               tmpStorage.setState(JSStorage::STATE_REMOVED);
+               break;
+       case Api::Filesystem::StorageProperties::STATE_UNMOUNTABLE:
+               tmpStorage.setState(JSStorage::STATE_UNMOUNTABLE);
+               break;
+       }
+
+       JSObjectRef jsObject = JSStorage::createJSObject(context, tmpStorage);
+       if (!jsObject) {
+               ThrowMsg(Commons::ConversionException, "Could not create JS object.");
+       }
+
+       return toJSValueRef(jsObject);
+}
+
+JSValueRef Converter::toJSValueRef(
+        const std::vector<Api::Filesystem::StoragePropertiesPtr>& arg,
+        JSContextRef context)
+{
+       JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+       if (!jsResult) {
+               ThrowMsg(Commons::ConversionException, "Could not create js array object");
+       }
+
+       Api::Filesystem::StorageProperties tmpStorage;
+
+       for (size_t i = 0; i < arg.size(); i++) {
+               tmpStorage.setLabel(arg[i]->getLabel()); 
+               tmpStorage.setType(arg[i]->getType());
+
+               switch (arg[i]->getState()) {
+               case Api::Filesystem::StorageProperties::STATE_MOUNTED :
+               case Api::Filesystem::StorageProperties::STATE_MOUNTED_READONLY :
+                       tmpStorage.setState(JSStorage::STATE_MOUNTED);
+                       break;
+               case Api::Filesystem::StorageProperties::STATE_REMOVED:
+                       tmpStorage.setState(JSStorage::STATE_REMOVED);
+                       break;
+               case Api::Filesystem::StorageProperties::STATE_UNMOUNTABLE:
+                       tmpStorage.setState(JSStorage::STATE_UNMOUNTABLE);
+                       break;
+               }
+
+               JSObjectRef jsObject = JSStorage::createJSObject(context, tmpStorage);
+               if (!jsObject) {
+                       ThrowMsg(Commons::ConversionException, "Could not create JS object.");
+               }
+
+               if (!JSSetArrayElement(m_context, jsResult, i, jsObject)) {
+                       ThrowMsg(Commons::ConversionException, "Could not insert value into js array");
+               }
+       }
+
+       return jsResult;
+}
+}
+}
diff --git a/src/standards/Tizen/Filesystem/Converter.h b/src/standards/Tizen/Filesystem/Converter.h
new file mode 100755 (executable)
index 0000000..debed4f
--- /dev/null
@@ -0,0 +1,77 @@
+//
+// 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_FILESYSTEM_CONVERTER_H_
+#define TIZENAPIS_TIZEN_FILESYSTEM_CONVERTER_H_
+
+#include <vector>
+#include <string>
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/Converter.h>
+#include <API/Filesystem/Enums.h>
+#include <API/Filesystem/IPath.h>
+#include <API/Filesystem/INodeTypes.h>
+#include <API/Filesystem/NodeFilter.h>
+#include <API/Filesystem/StorageProperties.h>
+#include "JSFile.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class Converter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+public:
+       using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
+
+public:
+       explicit Converter(JSContextRef context);
+
+
+
+    JSValueRef toJSValueRef(
+            const Api::Filesystem::NodeList& arg,
+            const JSFile::PrivateObjectDef::PermissionList &parentPermissions,
+            JSContextRef context);     
+       JSValueRef toJSValueRef(unsigned char* data,
+               std::size_t num);
+
+       Api::Filesystem::IPathPtr toPath(const JSValueRef& arg);
+
+       Api::Filesystem::NodeFilterPtr toNodeFilter(const JSValueRef& arg);
+
+       Api::Filesystem::AccessMode toAccessMode(const JSValueRef& arg);
+
+       std::string toEncoding(const JSValueRef& arg);
+       
+       JSValueRef toStorageType(const short type);
+       JSValueRef toStorageState(const short state);
+       JSValueRef toJSValueRef(
+               const Api::Filesystem::StoragePropertiesPtr &arg,
+               JSContextRef context);
+
+       JSValueRef toJSValueRef(
+               const std::vector<Api::Filesystem::StoragePropertiesPtr>& arg,
+               JSContextRef context);
+};
+
+typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<Converter> ConverterFactory;
+typedef ConverterFactory::ConverterType ConverterPtr;
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/standards/Tizen/Filesystem/Encodings.cpp b/src/standards/Tizen/Filesystem/Encodings.cpp
new file mode 100755 (executable)
index 0000000..0ac455c
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// 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 "Encodings.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Encodings {
+const char* UTF8 = "UTF-8";
+
+const char* ISO88591 = "ISO-8859-1";
+}
+}
+}
diff --git a/src/standards/Tizen/Filesystem/Encodings.h b/src/standards/Tizen/Filesystem/Encodings.h
new file mode 100755 (executable)
index 0000000..ed3f34b
--- /dev/null
@@ -0,0 +1,32 @@
+//
+// 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_FILESYSTEM_ENCODINGS_H_
+#define TIZENAPIS_TIZEN_FILESYSTEM_ENCODINGS_H_
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Encodings {
+extern const char* UTF8;
+
+extern const char* ISO88591;
+}
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/standards/Tizen/Filesystem/EventGetNodeData.cpp b/src/standards/Tizen/Filesystem/EventGetNodeData.cpp
new file mode 100755 (executable)
index 0000000..82904dd
--- /dev/null
@@ -0,0 +1,41 @@
+//
+// 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 "EventGetNodeData.h"
+
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+EventGetNodeData::EventGetNodeData(int perms, JSCallbackManagerPtr callbackManager) :
+               m_perms(perms),
+               m_callbackManager(callbackManager)
+{
+}
+
+int EventGetNodeData::getPerms() const
+{
+       return m_perms;
+}
+
+JSCallbackManagerPtr EventGetNodeData::getCallbackManager() const
+{
+       return m_callbackManager;
+}
+}
+}
diff --git a/src/standards/Tizen/Filesystem/EventGetNodeData.h b/src/standards/Tizen/Filesystem/EventGetNodeData.h
new file mode 100755 (executable)
index 0000000..4520164
--- /dev/null
@@ -0,0 +1,47 @@
+//
+// 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_EVENTGETNODEDATA_H_
+#define TIZENAPIS_TIZEN_EVENTGETNODEDATA_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class EventGetNodeData : public WrtDeviceApis::Commons::IEventPrivateData
+{
+public:
+       EventGetNodeData(int perms,
+               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager);
+
+       int getPerms() const;
+
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getCallbackManager() const;
+
+private:
+       int m_perms;
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_callbackManager;
+};
+
+typedef DPL::SharedPtr<EventGetNodeData> EventGetNodeDataPtr;
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/standards/Tizen/Filesystem/FilesystemAsyncCallbackManager.cpp b/src/standards/Tizen/Filesystem/FilesystemAsyncCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..7fed0b4
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// 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 "FilesystemAsyncCallbackManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::FilesystemAsyncCallbackManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Filesystem/FilesystemAsyncCallbackManager.h b/src/standards/Tizen/Filesystem/FilesystemAsyncCallbackManager.h
new file mode 100755 (executable)
index 0000000..3b116e1
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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_FILESYSTEM_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_FILESYSTEM_ASYNC_CALLBACK_MANAGER_H_
+
+#include <dpl/singleton.h>
+#include <Tizen/Common/AsyncCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+class FilesystemAsyncCallbackManager : public TizenApis::Commons::AsyncCallbackManager
+{
+public:
+       FilesystemAsyncCallbackManager()
+       {
+       }
+
+       virtual ~FilesystemAsyncCallbackManager()
+       {
+       }
+
+       friend class DPL::Singleton<FilesystemAsyncCallbackManager>;
+};
+
+typedef DPL::Singleton<FilesystemAsyncCallbackManager> FilesystemAsyncCallbackManagerSingleton;
+
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_FILESYSTEM_ASYNC_CALLBACK_MANAGER_H_
diff --git a/src/standards/Tizen/Filesystem/FilesystemListenerManager.cpp b/src/standards/Tizen/Filesystem/FilesystemListenerManager.cpp
new file mode 100755 (executable)
index 0000000..2e6bede
--- /dev/null
@@ -0,0 +1,28 @@
+//
+// 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 "FilesystemListenerManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::FilesystemListenerManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Filesystem/FilesystemListenerManager.h b/src/standards/Tizen/Filesystem/FilesystemListenerManager.h
new file mode 100755 (executable)
index 0000000..8ace056
--- /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_FILESYSTEM_LISTENER_MANAGER_H_
+#define _TIZEN_FILESYSTEM_LISTENER_MANAGER_H_
+
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Tizen/Common/IListenerManager.h>
+#include <API/Filesystem/IManager.h>
+#include "StorageStaticController.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace TizenApis::Api::Filesystem;
+
+class FilesystemListenerManager : public TizenApis::Commons::IListenerController
+{
+public:
+       FilesystemListenerManager()
+       {
+       }
+
+       virtual ~FilesystemListenerManager()
+       {
+       }
+};
+
+typedef DPL::Singleton<FilesystemListenerManager> FilesystemListenerManagerSingleton;
+
+class FilesystemListenerCanceller : public TizenApis::Commons::IListenerItem
+{
+public:
+       FilesystemListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
+               TizenApis::Commons::IListenerItem(context, object, watchId)
+       {
+       }
+
+       virtual ~FilesystemListenerCanceller()
+       {
+       }
+
+       virtual void cancelListener()
+       {
+               Try {
+                       LogDebug("Remove change listener");
+                       Api::Filesystem::IManager::getInstance().removeStorageStateChangeListener(m_watchId);
+               } Catch(WrtDeviceApis::Commons::Exception) {
+                       LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               }
+       }
+};
+typedef DPL::SharedPtr<FilesystemListenerCanceller> FilesystemListenerCancellerPtr;
+
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_FILESYSTEM_LISTENER_MANAGER_H_
diff --git a/src/standards/Tizen/Filesystem/FilesystemUtils.cpp b/src/standards/Tizen/Filesystem/FilesystemUtils.cpp
new file mode 100755 (executable)
index 0000000..c208196
--- /dev/null
@@ -0,0 +1,163 @@
+//
+// 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 <map>
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+#include <Commons/Exception.h>
+#include <API/Filesystem/Enums.h>
+#include <API/Filesystem/IManager.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <WidgetDB/WidgetDBMgr.h>
+#include "FilesystemUtils.h"
+
+using namespace TizenApis::Api::Filesystem;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+namespace {
+const std::string PATH_INVALID_COMPONENT_PARENT_DIR("..");
+const std::string PATH_INVALID_COMPONENT_CURRENT_DIR(".");
+
+typedef std::map<std::string, std::string> RootToPathMap;
+typedef RootToPathMap::const_iterator RootToPathMapIterator;
+typedef std::map<std::string, std::string> PathToRootMap;
+typedef PathToRootMap::const_iterator PathToRootMapIterator;
+}
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Utils {
+const RootToPathMap& getRootToPathMap()
+{
+       static RootToPathMap result;
+       if (result.empty()) {
+        IManager& manager = IManager::getInstance();
+               std::map<std::string, Api::Filesystem::IPathPtr> locations = manager.getStorageList();
+
+               std::map<std::string, Api::Filesystem::IPathPtr>::const_iterator it;
+
+               for (it = locations.begin(); it != locations.end(); ++it) {
+                       result[it->first] = it->second->getFullPath();
+               }
+       }
+       return result;
+}
+
+const PathToRootMap& getPathToRootMap()
+{
+       static PathToRootMap result;
+       if (result.empty()) {
+               IManager& manager = IManager::getInstance();
+               std::map<std::string, Api::Filesystem::IPathPtr> locations = manager.getStorageList();
+
+               std::map<std::string, Api::Filesystem::IPathPtr>::const_iterator it;
+
+               for (it = locations.begin(); it != locations.end(); ++it) {
+                       result[it->second->getFullPath()] = it->first;
+               }
+       }
+       return result;
+}
+
+IPathPtr fromVirtualPath(JSContextRef context,
+                         const std::string& arg)
+{
+       LogDebug("arg:[" << arg << "]");
+
+       if (!isPathValid(arg)) {
+               LogDebug("virtual path is invalid:[" << arg << "]");
+               ThrowMsg(Commons::ConversionException, "Not found path component.");
+       }
+
+       std::string root;
+       std::string tail;
+       std::string::size_type separatorPosition = arg.find(IPath::getSeparator());
+       if (separatorPosition != std::string::npos) {
+               root = arg.substr(0, separatorPosition);
+               tail = arg.substr(separatorPosition + 1, arg.size() - 1);
+       } else {
+               root = arg;
+       }
+
+       int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+       WidgetDB::Api::IWidgetDBPtr widgetDB = WidgetDB::Api::getWidgetDB(widgetId);
+
+       RootToPathMap rootToPath = getRootToPathMap();
+       rootToPath["wgt-package"] = widgetDB->getWidgetInstallationPath();
+       rootToPath["wgt-private"] = widgetDB->getWidgetPersistentStoragePath();
+       rootToPath["wgt-private-tmp"] = widgetDB->getWidgetTemporaryStoragePath();
+       RootToPathMapIterator it = rootToPath.find(root);
+       if (it == rootToPath.end()) {
+               ThrowMsg(Commons::NotFoundException, "Location not found.");
+       }
+       IPathPtr result = IPath::create(it->second);
+
+       if (!tail.empty()) {
+               result->append(tail);
+       }
+
+       return result;
+}
+
+std::string toVirtualPath(JSContextRef context, const std::string& arg) {
+
+    int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+    WidgetDB::Api::IWidgetDBPtr widgetDB =
+        WidgetDB::Api::getWidgetDB(widgetId);
+
+       PathToRootMap pathToRoot = getPathToRootMap();
+       pathToRoot[widgetDB->getWidgetInstallationPath()] = "wgt-package";
+       pathToRoot[widgetDB->getWidgetPersistentStoragePath()] = "wgt-private";
+       pathToRoot[widgetDB->getWidgetTemporaryStoragePath()] = "wgt-private-tmp";
+
+       std::string path = arg;
+       std::string::size_type pos = path.size();
+       while (std::string::npos != (pos = path.rfind(IPath::getSeparator(), pos))) {
+               PathToRootMapIterator it = pathToRoot.find(path);
+               if (pathToRoot.end() != it) {
+                       return it->second + arg.substr(path.size());
+               }
+               path.erase(pos, path.size());
+       }
+       ThrowMsg(Commons::ConversionException, "Path doesn't contain a valid location type.");
+}
+
+bool isPathValid(const std::string& path) {
+       static const std::string currentDirBegin(PATH_INVALID_COMPONENT_CURRENT_DIR + Api::Filesystem::IPath::getSeparator());
+       static const std::string parentDirBegin(PATH_INVALID_COMPONENT_PARENT_DIR +
+               Api::Filesystem::IPath::getSeparator());
+       static const std::string currentDirMiddle(Api::Filesystem::IPath::getSeparator() +
+               PATH_INVALID_COMPONENT_CURRENT_DIR +Api::Filesystem::IPath::getSeparator());
+       static const std::string parentDirMiddle(Api::Filesystem::IPath::getSeparator() +
+               PATH_INVALID_COMPONENT_PARENT_DIR +Api::Filesystem::IPath::getSeparator());
+
+       if (path.find(parentDirBegin) == 0 ||
+                       path.find(currentDirBegin) == 0 ||
+               path.find(parentDirMiddle) != std::string::npos ||
+               path.find(currentDirMiddle) != std::string::npos) {
+               return false;
+       }
+
+       return true;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Filesystem/FilesystemUtils.h b/src/standards/Tizen/Filesystem/FilesystemUtils.h
new file mode 100755 (executable)
index 0000000..dc4ba32
--- /dev/null
@@ -0,0 +1,40 @@
+//
+// 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_FILESYSTEM_UTILS_H_
+#define TIZENAPIS_FILESYSTEM_UTILS_H_
+
+#include <string>
+#include <JavaScriptCore/JavaScript.h>
+#include <API/Filesystem/IPath.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Utils {
+
+Api::Filesystem::IPathPtr fromVirtualPath(JSContextRef context,
+                                          const std::string& arg);
+
+std::string toVirtualPath(JSContextRef context, const std::string& arg);
+
+bool isPathValid(const std::string& path);
+
+}
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Filesystem/JSFile.cpp b/src/standards/Tizen/Filesystem/JSFile.cpp
new file mode 100755 (executable)
index 0000000..b3357b2
--- /dev/null
@@ -0,0 +1,1130 @@
+//
+// 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 "JSFile.h"
+
+#include <string>
+#include <ctime>
+#include <dpl/log/log.h>
+
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <API/Filesystem/Enums.h>
+#include <API/Filesystem/IManager.h>
+#include <API/Filesystem/EventCopy.h>
+#include <API/Filesystem/EventMove.h>
+#include <API/Filesystem/EventListNodes.h>
+#include <API/Filesystem/EventOpen.h>
+#include <API/Filesystem/EventReadText.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h> 
+#include <Tizen/Common/SecurityExceptions.h>
+#include "FilesystemUtils.h"
+#include "Converter.h"
+#include "plugin_config.h"
+#include "Encodings.h"
+#include "JSFilestream.h"
+#include "ResponseDispatcher.h"
+#include "FilesystemAsyncCallbackManager.h"
+
+using namespace TizenApis::Api::Filesystem;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace {
+#define PLUGIN_NAME  "File"
+#define PROPERTY_PARENT  "parent"
+#define PROPERTY_READ_ONLY  "readOnly"
+#define PROPERTY_IS_FILE  "isFile"
+#define PROPERTY_IS_DIRECTORY "isDirectory"
+#define PROPERTY_CREATED  "created"
+#define PROPERTY_MODIFIED  "modified"
+#define PROPERTY_PATH  "path"
+#define PROPERTY_NAME  "name"
+#define PROPERTY_FULL_PATH  "fullPath"
+#define PROPERTY_FILE_SIZE  "fileSize"
+#define PROPERTY_LENGTH "length"
+}      //namespace
+
+JSValueRef getFunctionOrNull(JSContextRef ctx, JSValueRef arg)
+{
+       if (Validator(ctx).isCallback(arg)) {
+               return arg;
+       } else if (!JSValueIsNull(ctx, arg) && !JSValueIsUndefined(ctx, arg)) {
+               ThrowMsg(ConversionException, "Not a function nor JS null.");
+       }
+       return NULL;
+}
+
+
+
+JSValueRef getFunction(JSContextRef ctx, JSValueRef arg)
+{
+       if (Validator(ctx).isCallback(arg)) {
+               return arg;
+       } else{
+               ThrowMsg(ConversionException, "Not a function nor JS null.");
+       }
+}
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassRef JSFile::m_classRef = 0;
+
+JSClassDefinition JSFile::m_classInfo = {
+       0,
+       kJSClassAttributeNone,
+       PLUGIN_NAME,
+       0,
+       m_properties,
+       m_functions,
+       initialize,
+       finalize,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       getPropertyNames,
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+JSStaticValue JSFile::m_properties[] = {
+       { PROPERTY_PARENT, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { PROPERTY_READ_ONLY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { PROPERTY_IS_FILE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { PROPERTY_IS_DIRECTORY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { PROPERTY_CREATED, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { PROPERTY_MODIFIED, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { PROPERTY_PATH, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { PROPERTY_NAME, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { PROPERTY_FULL_PATH, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { PROPERTY_FILE_SIZE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { PROPERTY_LENGTH, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSFile::m_functions[] = {
+       { "toURI", toUri, kJSPropertyAttributeNone },
+       { "listFiles", listFiles, kJSPropertyAttributeNone },
+       { "openStream", openStream, kJSPropertyAttributeNone },
+       { "readAsText", readAsText, kJSPropertyAttributeNone },
+       { "copyTo", copyTo, kJSPropertyAttributeNone },
+       { "moveTo", moveTo, kJSPropertyAttributeNone },
+       { "createDirectory", createDirectory, kJSPropertyAttributeNone },
+       { "createFile", createFile, kJSPropertyAttributeNone },
+       { "resolve", resolve, kJSPropertyAttributeNone },
+       { "deleteDirectory", deleteDirectory, kJSPropertyAttributeNone },
+       { "deleteFile", deleteFile, kJSPropertyAttributeNone },
+       { 0, 0, 0 }
+};
+
+void JSFile::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSFile::finalize(JSObjectRef object)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(object));
+       if (privateObject) {
+               JSObjectSetPrivate(object, NULL);
+               delete privateObject;
+       }
+}
+
+const JSClassRef JSFile::getClassRef()
+{
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+const JSClassDefinition* JSFile::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+JSValueRef JSFile::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject =
+       static_cast<PrivateObject*>(JSObjectGetPrivate(object));
+       if (!privateObject) {
+               LogError("Private object is not set.");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       JSContextRef globalContext = privateObject->getContext();
+       Converter converter(globalContext);
+
+       try {
+               if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_PARENT))
+               {
+                       INodePtr parent(privateObject->getObject()->getNode()->getParent());
+                       PrivateObjectDef::PermissionList perms =
+                       privateObject->getObject()->getParentPermissions();
+                       if (parent && !perms.empty())
+                       {
+                               parent->setPermissions(perms.back());
+                               perms.pop_back();
+                               PrivateObjectDefPtr privData(new PrivateObjectDef(parent, perms));
+
+                               return JSUtils::makeObject(privateObject->getContext(), getClassRef(), privData);
+                       }
+                       return JSValueMakeNull(context);
+               } 
+               else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_READ_ONLY))
+               {
+                       bool readOnly = ((privateObject->getObject()->getNode()->getMode() & PM_USER_WRITE) == 0);
+                       return converter.toJSValueRef(readOnly);
+               }
+               else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_IS_FILE))
+               {
+                       bool isFile = (privateObject->getObject()->getNode()->getType() == NT_FILE);
+                       return converter.toJSValueRef(isFile);
+               }
+               else if (JSStringIsEqualToUTF8CString(propertyName,
+                         PROPERTY_IS_DIRECTORY))
+               {
+                       bool isDirectory = (privateObject->getObject()->getNode()->getType() == NT_DIRECTORY);
+                       return converter.toJSValueRef(isDirectory);
+               }
+               else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_CREATED))
+               {
+                       std::time_t created = privateObject->getObject()->getNode()->getCreated();
+                       return converter.toJSValueRef(created);
+               }
+               else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_MODIFIED))
+               {
+                       std::time_t modified = privateObject->getObject()->getNode()->getModified();
+                       return converter.toJSValueRef(modified);
+               }
+               else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_PATH))
+               {
+                       std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
+                       std::string vpath = Utils::toVirtualPath(globalContext, fpath);
+                       std::string::size_type pos = vpath.rfind(IPath::getSeparator());
+                       std::string path = (std::string::npos != pos ? vpath.substr(0, pos + 1) : vpath);
+                       return converter.toJSValueRef(path);
+               }
+               else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NAME))
+               {
+                       std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
+                       std::string vpath = Utils::toVirtualPath(globalContext, fpath);
+                       std::string name;
+                       std::string::size_type pos = vpath.rfind(IPath::getSeparator());
+
+                       if (std::string::npos != pos) {
+                               name = vpath.substr(pos + 1);
+                       }
+                       return converter.toJSValueRef(name);
+               }
+               else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FULL_PATH))
+               {
+                       std::string path = privateObject->getObject()->getNode()->getPath()->getFullPath();
+                       return converter.toJSValueRef(Utils::toVirtualPath(globalContext, path));
+               }
+               else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FILE_SIZE))
+               {
+                       if (privateObject->getObject()->getNode()->getType() == NT_DIRECTORY)
+                       {
+                               return JSValueMakeUndefined(context);
+                       }
+                       return converter.toJSValueRef(privateObject->getObject()->getNode()->getSize());
+               }
+               else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_LENGTH))
+               {
+                       if (privateObject->getObject()->getNode()->getType() == NT_FILE) {
+                               return JSValueMakeUndefined(context);
+                       }
+                       // TODO: think about more efficent solution!
+                       NodeList children = privateObject->getObject()->getNode()->getChildNodes();
+                       return converter.toJSValueRef(children.size());
+               }
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogError("Exception: " << ex.GetMessage());
+       }
+       /*
+       else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_READ_ONLY)) {
+               bool readOnly = ((privateObject->getObject()->getNode() & PERM_WRITE) == 0);
+               return converter.toJSValueRef(readOnly);
+       } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_IS_FILE)) {
+               bool isFile = (privateObject->getObject()->getNode()->getType() == NT_FILE);
+               return converter.toJSValueRef(isFile);
+       } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_IS_DIRECTORY)) {
+               bool isDirectory =(privateObject->getObject()->getNode()->getType() == NT_DIRECTORY);
+               return converter.toJSValueRef(isDirectory);
+       } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_CREATED)) {
+               std::time_t created = privateObject->getObject()->getNode()->getCreated();
+               return converter.toJSValueRef(created);
+       } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_MODIFIED)) {
+               std::time_t modified = privateObject->getObject()->getNode()->getModified();
+               return converter.toJSValueRef(modified);
+       } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_PATH)) {
+               std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
+               std::string vpath = Utils::toVirtualPath(globalContext, fpath);
+               std::string::size_type pos = vpath.rfind(IPath::getSeparator());
+               std::string path = (std::string::npos != pos ? vpath.substr(0, pos + 1) : vpath);
+               return converter.toJSValueRef(path);
+       } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_NAME)) {
+               std::string fpath = privateObject->getObject()->getNode()->getPath()->getFullPath();
+               std::string vpath = Utils::toVirtualPath(globalContext, fpath);
+               std::string name;
+               std::string::size_type pos = vpath.rfind(IPath::getSeparator());
+               if (std::string::npos != pos) {
+                       name = vpath.substr(pos + 1);
+               }
+               return converter.toJSValueRef(name);
+       } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FULL_PATH)) {
+               std::string path = privateObject->getObject()->getNode()->getPath()->getFullPath();
+               return converter.toJSValueRef(Utils::toVirtualPath(globalContext, path));
+       } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_FILE_SIZE)) {
+               if (privateObject->getObject()->getNode()->getType() == NT_DIRECTORY) {
+                       return JSValueMakeUndefined(context);
+               }
+               return converter.toJSValueRef(privateObject->getObject()->getNode()->getSize());
+       } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_LENGTH)) {
+               if (privateObject->getObject()->getNode()->getType() == NT_FILE) {
+                       return JSValueMakeUndefined(context);
+               }
+                       NodeList children = privateObject->getObject()->getNode()->getChildNodes();
+                       return converter.toJSValueRef(children.size());
+       }
+       } catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogWarning("trying to get incorrect value");
+       }*/
+
+       return JSValueMakeUndefined(context);
+}
+
+void JSFile::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+}
+
+bool JSFile::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSFile::toUri(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               LogError("Private object is not set.");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       Converter converter(context);
+       try {
+               int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+               return converter.toJSValueRef(privateObject->getObject()->getNode()->toUri(widgetId));
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       }
+}
+
+JSValueRef JSFile::listFiles(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       LogDebug("OK");
+
+       JSContextRef globalContext = privateObject->getContext();
+       size_t index = 0;
+       JSValueRef reserveArguments[3];
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
+
+       try {
+
+               for (index = 0; index < 3; index++)
+               {
+                       if (index < argc)
+                               reserveArguments[index] = argv[index];
+                       else 
+                               reserveArguments[index] = JSValueMakeUndefined(context);                                                        
+               }
+
+               JSValueRef onSuccess = getFunction(globalContext, reserveArguments[0]);
+               JSValueRef onError = NULL;
+
+
+               if (argc > 1) {
+                       onError = getFunctionOrNull(globalContext, reserveArguments[1]);
+               }
+
+               cbm->setOnSuccess(onSuccess);
+               cbm->setOnError(onError);
+               cbm->setObject(thisObject);
+
+               Converter converter(globalContext);
+
+               EventListNodesPtr event(new EventListNodes(privateObject->getObject()->getNode()));
+               if (argc > 2) {
+                       if (JSValueIsNull(context, reserveArguments[2]) == false &&
+                               JSValueIsUndefined(context, reserveArguments[2]) == false) {
+                                       event->setFilter(converter.toNodeFilter(reserveArguments[2]));
+                               }
+               }
+               PrivateObjectDef::PermissionList perms =
+               privateObject->getObject()->getParentPermissions();
+               perms.push_back(privateObject->getObject()->getNode()->getPermissions());
+
+               ListFilesPrivateDataPtr privData(new ListFilesPrivateData(cbm, perms));
+
+               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privData));
+               event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
+
+               privateObject->getObject()->getNode()->getChildNodes(event);
+               FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFile::openStream(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       JSContextRef globalContext = privateObject->getContext();
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
+
+       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);                                                        
+
+               }
+
+               JSValueRef onSuccess = getFunction(globalContext, reserveArguments[1]);
+               JSValueRef onError = NULL;
+
+               onError = getFunctionOrNull(globalContext, reserveArguments[2]);
+
+               cbm->setOnSuccess(onSuccess);
+               cbm->setOnError(onError);
+               cbm->setObject(thisObject);
+
+
+               Converter converter(globalContext);
+
+               AccessMode mode = converter.toAccessMode(reserveArguments[0]);
+               std::string encoding = Encodings::UTF8;
+               if (argumentCount > 3) {
+                       if(!JSValueIsNull(globalContext, reserveArguments[3]) && !JSValueIsUndefined(globalContext, reserveArguments[3])){
+                               encoding = converter.toEncoding(reserveArguments[3]);
+                       }
+               }
+
+               if ((AM_READ != mode) && (PERM_READ == privateObject->getObject()->getNode()->getPermissions())) {
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               }
+
+               std::string path = privateObject->getObject()->getNode()->getPath()->getFullPath();
+               std::string vpath = Utils::toVirtualPath(globalContext, path);
+
+               AccessModeInfo am = AccessModeInfo(mode, vpath);
+               AceSecurityStatus status = FILESYSTEM_ACCESSMODE_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_OPEN_STREAM, am);
+
+               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               EventOpenPtr event(new EventOpen(mode));
+               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(cbm));
+               event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
+               FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+               privateObject->getObject()->getNode()->open(event);
+
+
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFile::readAsText(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+
+       JSContextRef globalContext = privateObject->getContext();
+       AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_READ_AS_TEXT);
+
+       size_t index = 0;
+       JSValueRef reserveArguments[3];
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
+
+       try {
+
+               for (index = 0; index < 3; index++) {
+                       if (index < argc)
+                               reserveArguments[index] = argv[index];
+                       else 
+                               reserveArguments[index] = JSValueMakeUndefined(context);                                                        
+
+               }
+               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               JSValueRef onSuccess = getFunction(globalContext, reserveArguments[0]);
+               JSValueRef onError = NULL;
+
+               if (argc > 1) {
+                       onError = getFunctionOrNull(globalContext, reserveArguments[1]);
+               }
+
+               cbm->setOnSuccess(onSuccess);
+               cbm->setOnError(onError);
+               cbm->setObject(thisObject);
+
+               Converter converter(context);
+               std::string src = Encodings::UTF8;
+               if (argc > 2) {
+                       if (!JSValueIsNull(context, reserveArguments[2]) && !JSValueIsUndefined(context, reserveArguments[2])) {
+                               src = converter.toEncoding(reserveArguments[2]);
+                       }
+               }
+
+               if (NT_FILE != privateObject->getObject()->getNode()->getType()) {
+                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
+                       return JSValueMakeUndefined(context);
+               }
+
+               EventReadTextPtr event(new EventReadText());
+               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData,JSCallbackManager>(cbm));
+               event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
+               FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+               privateObject->getObject()->getNode()->read(event);
+
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFile::copyTo(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       JSContextRef globalContext = privateObject->getContext();
+       size_t index = 0;
+       JSValueRef reserveArguments[5];
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
+
+       try {
+
+               for (index = 0; index < 5; index++)
+               {
+                       if (index < argc)
+                               reserveArguments[index] = argv[index];
+                       else 
+                               reserveArguments[index] = JSValueMakeUndefined(context);                                                        
+               }
+
+               Converter converter(globalContext);
+               JSValueRef onSuccess = NULL;
+               JSValueRef onError = NULL;
+
+               onSuccess = getFunctionOrNull(globalContext, reserveArguments[3]);
+               onError = getFunctionOrNull(globalContext, reserveArguments[4]);
+
+               cbm->setOnSuccess(onSuccess);
+               cbm->setOnError(onError);               
+               cbm->setObject(thisObject);
+
+
+               //TODO add check validation for src, dest string.
+               IPathPtr src = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
+               IPathPtr dest = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[1]));
+               bool overwrite = converter.toBool(reserveArguments[2]);;
+                                       
+               if (NT_DIRECTORY != privateObject->getObject()->getNode()->getType()) {
+                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
+                       return JSValueMakeUndefined(context);
+               }
+
+               std::string virtualDestPath = Utils::toVirtualPath(globalContext, dest->getFullPath());
+               AccessModeInfo amode = AccessModeInfo(Api::Filesystem::AM_WRITE, virtualDestPath);
+               AceSecurityStatus status = FILESYSTEM_ACCESSMODE_CHECK_ACCESS(
+                       FILESYSTEM_FUNCTION_API_COPY_TO,
+               amode);
+
+               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               EventCopyPtr event(new EventCopy(src, dest));
+
+               if (overwrite) {
+                       event->setOptions(OPT_OVERWRITE);
+               }
+
+               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::
+                       IEventPrivateData,
+                       JSCallbackManager>(
+                       cbm));
+               event->setForAsynchronousCall(&ResponseDispatcher::getInstance());
+               FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+                                       
+               IManager::getInstance().copy(event);
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::NotFoundException &ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFile::moveTo(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       JSContextRef globalContext = privateObject->getContext();
+
+       LogDebug("OK");
+
+       size_t index = 0;
+       JSValueRef reserveArguments[5];
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
+
+       try {
+
+               for (index = 0; index < 5; index++) {
+                       if (index < argc)
+                               reserveArguments[index] = argv[index];
+                       else 
+                               reserveArguments[index] = JSValueMakeUndefined(context);                                                        
+               }
+
+               if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               }
+
+               Converter converter(context);
+               JSValueRef onSuccess = NULL;
+               JSValueRef onError = NULL;
+
+               onSuccess = getFunctionOrNull(globalContext, reserveArguments[3]);
+               onError = getFunctionOrNull(globalContext, reserveArguments[4]);
+               cbm->setOnSuccess(onSuccess);
+               cbm->setOnError(onError);
+               cbm->setObject(thisObject);
+
+               if (NT_DIRECTORY != privateObject->getObject()->getNode()->getType()) {
+                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "io error"));
+                       return JSValueMakeUndefined(context);
+               }
+
+               IPathPtr src = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
+               IPathPtr dest = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[1]));
+               bool overwrite = converter.toBool(reserveArguments[2]);
+
+               std::string virtualDestPath = Utils::toVirtualPath(globalContext, dest->getFullPath());
+
+               AccessModeInfo amode = AccessModeInfo(Api::Filesystem::AM_WRITE, virtualDestPath);
+               AceSecurityStatus status = FILESYSTEM_ACCESSMODE_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_MOVE_TO, amode);
+
+               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               EventMovePtr event(new EventMove(src, dest));
+               if (overwrite) {
+                       event->setOptions(OPT_OVERWRITE);
+               }
+
+               event->setForAsynchronousCall(&ResponseDispatcher::getInstance()); 
+               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+               FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+               IManager::getInstance().move(event);
+
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       }       catch(const WrtDeviceApis::Commons::NotFoundException &ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
+       }
+       catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFile::createDirectory(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_CREATE_DIR);
+
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+
+       Converter converter(context);
+       try {
+
+               if (argc < 1) {
+                       ThrowMsg(InvalidArgumentException, "Invalid path name");
+               }
+
+               IPathPtr path = converter.toPath(argv[0]);
+               INodePtr node(privateObject->getObject()->getNode()->createChild(path, NT_DIRECTORY, OPT_RECURSIVE));
+               node->setPermissions(privateObject->getObject()->getNode()->getPermissions());
+
+               PrivateObjectDefPtr privData(new PrivateObjectDef(node, privateObject->getObject()->getParentPermissions()));
+               privData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
+
+               return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(privateObject->getContext(), getClassRef(), privData);
+       } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       }
+}
+
+JSValueRef JSFile::createFile(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_CREATE_FILE);
+
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+
+       Converter converter(context);
+       try {
+
+               if (argc < 1) {
+                       ThrowMsg(InvalidArgumentException, "Invalid path name");
+               }
+
+               IPathPtr path = converter.toPath(argv[0]);
+               INodePtr node = privateObject->getObject()->getNode()->createChild(path, NT_FILE);
+
+               PrivateObjectDefPtr privData(new PrivateObjectDef(node, privateObject->getObject()->getParentPermissions()));
+               privData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
+
+               return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(privateObject->getContext(), getClassRef(), privData);
+               /*
+               IPathPtr path = converter.toPath(argv[0]);
+               INodePtr node = privateObject->getObject()->getNode()->createChild(path, NT_FILE);
+               return JSUtils::makeObject(privateObject->getContext(), getClassRef(), node);*/
+       } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       }
+
+}
+
+JSValueRef JSFile::resolve(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+
+       if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, "IO error");
+       }
+
+       Converter converter(context);
+       try {
+
+               if (argc < 1) {
+                       ThrowMsg(InvalidArgumentException, "Invalid path name");
+               }
+
+               IPathPtr path = converter.toPath(argv[0]);
+               INodePtr node = privateObject->getObject()->getNode()->getChild(path);
+               node->setPermissions(privateObject->getObject()->getNode()->getPermissions());
+               PrivateObjectDefPtr privData(new PrivateObjectDef(node,         privateObject->getObject()->getParentPermissions()));
+               privData->pushParentPermissions(privateObject->getObject()->getNode()->getPermissions());
+               return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(privateObject->getContext(), getClassRef(), privData);
+               /*
+               IPathPtr path = converter.toPath(argv[0]);
+               INodePtr node = privateObject->getObject()->getNode()->getChild(path);
+               node->setPermissions(privateObject->getObject()->getNode()->getPermissions());
+               return JSUtils::makeObject(privateObject->getContext(), getClassRef(), node);
+               */
+       } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       }
+}
+
+JSValueRef JSFile::deleteDirectory(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       if (argc < 2) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       JSContextRef globalContext = privateObject->getContext();
+
+       LogDebug("OK");
+
+       size_t index = 0;
+       JSValueRef reserveArguments[4];
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);      
+
+       try {
+               for (index = 0; index < 4; index++) {
+               if (index < argc)
+                       reserveArguments[index] = argv[index];
+               else 
+                       reserveArguments[index] = JSValueMakeUndefined(context);                                                        
+               }
+
+               AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_DELETE_DIR);
+
+               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               JSValueRef onSuccess = NULL;
+               JSValueRef onError = NULL;
+
+               onSuccess = getFunctionOrNull(globalContext, reserveArguments[2]);
+               onError = getFunctionOrNull(globalContext, reserveArguments[3]);
+
+               cbm->setOnSuccess(onSuccess);
+               cbm->setOnError(onError);
+               cbm->setObject(thisObject);
+
+               if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               }
+
+               if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
+                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
+                       return JSValueMakeUndefined(context);
+               }
+
+               Converter converter(context);
+               IPathPtr path = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
+               bool recursive = converter.toBool(reserveArguments[1]);
+
+               if (*privateObject->getObject()->getNode()->getPath() != path->getPath()) {
+                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
+                       return JSValueMakeUndefined(context);
+               }
+
+
+               EventResolvePtr eventResolve(new EventResolve(path));
+               if (eventResolve->setForSynchronousCall()) { 
+                       IManager::getInstance().getNode(eventResolve);
+                       if (!eventResolve->getResult() || (eventResolve->getExceptionCode() != WrtDeviceApis::Commons::ExceptionCodes::None)) {
+                               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
+                               return JSValueMakeUndefined(context);
+                       }
+
+                       if (eventResolve->getResult()->getType() != NT_DIRECTORY) {
+                               ThrowMsg(InvalidArgumentException, "Invalid directory");
+                       }
+
+                       EventRemovePtr eventRemove(new EventRemove(path));
+
+                       if (recursive) {
+                               eventRemove->setOptions(OPT_RECURSIVE);
+                       }
+
+                       eventRemove->setForAsynchronousCall(&ResponseDispatcher::getInstance()); 
+                       eventRemove->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+                       FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+                       IManager::getInstance().remove(eventRemove);
+               }
+       } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
+       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, ex.GetMessage()));
+
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFile::deleteFile(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       LogDebug("<<<");
+
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       JSContextRef globalContext = privateObject->getContext();
+
+       size_t index = 0;
+       JSValueRef reserveArguments[3];
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);      
+
+       try {
+               for (index = 0; index < 3; index++) {
+                       if (index < argc)
+                               reserveArguments[index] = argv[index];
+                       else 
+                               reserveArguments[index] = JSValueMakeUndefined(context);                                                        
+               }
+
+               AceSecurityStatus status = FILESYSTEM_CHECK_ACCESS(FILESYSTEM_FUNCTION_API_DELETE_FILE);
+
+               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               if ((privateObject->getObject()->getNode()->getPermissions() & PERM_WRITE) == 0) {
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               }
+
+               JSValueRef onSuccess = NULL;
+               JSValueRef onError = NULL;
+
+               onSuccess = getFunctionOrNull(globalContext, reserveArguments[1]);
+               onError = getFunctionOrNull(globalContext, reserveArguments[2]);
+
+               cbm->setOnSuccess(onSuccess);
+               cbm->setOnError(onError);
+               cbm->setObject(thisObject);
+
+               if (privateObject->getObject()->getNode()->getType() != NT_DIRECTORY) {
+                       cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
+                       return JSValueMakeUndefined(context);
+               }
+
+
+               Converter converter(context);
+               IPathPtr path = Utils::fromVirtualPath(globalContext, converter.toString(reserveArguments[0]));
+
+               EventResolvePtr eventResolve(new EventResolve(path));
+               if (eventResolve->setForSynchronousCall()) { 
+                       IManager::getInstance().getNode(eventResolve);
+
+                       if (!eventResolve->getResult() ||(eventResolve->getExceptionCode() != WrtDeviceApis::Commons::ExceptionCodes::None)) {
+                               if(eventResolve->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException){
+                                       LogDebug("POST IO NOT_FOUND_ERROR");
+                                       ThrowMsg(NotFoundException, "Not found error");
+                               }
+
+                               LogDebug("POST IO ERROR");
+                               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, "IO error"));
+                               return JSValueMakeUndefined(context);
+                       }
+
+                       if (eventResolve->getResult()->getType() != NT_FILE) {                          
+                               ThrowMsg(InvalidArgumentException, "Invalid directory");
+                       }
+
+                       LogDebug("try to call async event");
+                       EventRemovePtr eventRemove(new EventRemove(path));
+                       eventRemove->setForAsynchronousCall(&ResponseDispatcher::getInstance()); 
+                       eventRemove->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+                       FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+                       IManager::getInstance().remove(eventRemove);
+
+               }
+       } catch (const WrtDeviceApis::Commons::PlatformException& ex) {
+               LogDebug("Platform Exception !!!!!!!! post io error");
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::IO_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+
+       LogDebug(">>>");
+       return JSValueMakeUndefined(context);
+}
+}
+}
+
diff --git a/src/standards/Tizen/Filesystem/JSFile.h b/src/standards/Tizen/Filesystem/JSFile.h
new file mode 100755 (executable)
index 0000000..d097c9b
--- /dev/null
@@ -0,0 +1,286 @@
+//
+// 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_JSFILE_H_
+#define TIZENAPIS_TIZEN_JSFILE_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <API/Filesystem/INode.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class JSFile
+{
+public:
+
+    class PrivateObjectDef
+    {
+    public:
+
+        typedef std::vector<int> PermissionList;
+
+        PrivateObjectDef(const Api::Filesystem::INodePtr &node,
+                         const PermissionList &parentPermissions) :
+            m_node(node),
+            m_parentPerms(parentPermissions)
+        {
+        }
+
+        virtual ~PrivateObjectDef()
+        {
+        }
+
+        Api::Filesystem::INodePtr getNode() const
+        {
+            return m_node;
+        }
+
+        PermissionList getParentPermissions() const
+        {
+            return m_parentPerms;
+        }
+
+        void setParentPermissions(const PermissionList &permissions)
+        {
+            m_parentPerms = permissions;
+        }
+
+        void pushParentPermissions(int permissions)
+        {
+            m_parentPerms.push_back(permissions);
+        }
+
+    private:
+        Api::Filesystem::INodePtr m_node;
+        PermissionList m_parentPerms;
+    };
+
+    class ListFilesPrivateData : public WrtDeviceApis::Commons::IEventPrivateData
+    {
+    public:
+        ListFilesPrivateData(
+                const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr &callbackManager,
+                const PrivateObjectDef::PermissionList parentPermissions) :
+            m_callbackManager(callbackManager),
+            m_parentPermissions(parentPermissions)
+        {
+        }
+
+        virtual ~ListFilesPrivateData()
+        {
+        }
+
+        WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getCallbackManager() const
+        {
+            return m_callbackManager;
+        }
+
+        PrivateObjectDef::PermissionList getParentPermissions() const
+        {
+            return m_parentPermissions;
+        }
+
+    private:
+        WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_callbackManager;
+        PrivateObjectDef::PermissionList m_parentPermissions;
+    };
+
+    typedef DPL::SharedPtr<ListFilesPrivateData> ListFilesPrivateDataPtr;
+    typedef DPL::SharedPtr<PrivateObjectDef> PrivateObjectDefPtr;
+    typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<PrivateObjectDefPtr>::Type PrivateObject;
+
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+private:
+
+       /**
+       * The callback invoked when an object is first created.
+       */
+       static void initialize(JSContextRef context,
+               JSObjectRef object);
+
+       /**
+       * The callback invoked when an object is finalized.
+       */
+       static void finalize(JSObjectRef object);
+
+       /**
+       * The callback invoked when getting a property's value.
+       */
+       static JSValueRef getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception);
+
+       /**
+       * The callback invoked when collecting the names of an object's properties.
+       */
+       static void getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames);
+
+       /**
+       * 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);
+
+       /**
+       * Returns a URI for the file.
+       */
+       static JSValueRef toUri(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * Returns list of all files of this directory.
+       */
+       static JSValueRef listFiles(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * WRT_GeneralError exception
+       */
+       static JSValueRef openStream(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * WRT_GeneralError exception
+       */
+       static JSValueRef readAsText(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * The operation is only for file except for directory.
+       * Make sure the dest directory already exists.
+       */
+       static JSValueRef copyTo(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * This operation is only for file not directory
+       * The dest directory should exists in local file system, or the operation fails.
+       */
+       static JSValueRef moveTo(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * create directory even through the parent directories do not  exist in local file system.
+       */
+       static JSValueRef createDirectory(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * Creates a new empty file in a specified location.
+       */
+       static JSValueRef createFile(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * Resolves an existing file or directory relative to
+       * the current directory this operation is performed on; and
+       * returns a file handle for it.
+       */
+       static JSValueRef resolve(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+        * Removes all files from specified directory if recursive is true, 
+        * or just remove the directory itself when there is no files or directories underneath it
+        */
+       static JSValueRef deleteDirectory(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * Deletes a specified file.
+       */
+       static JSValueRef deleteFile(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * This structure describes a statically declared function property.
+       */
+       static JSStaticFunction m_functions[];
+
+       /**
+       * This structure describes a statically declared value property.
+       */
+       static JSStaticValue m_properties[];
+
+       /**
+       * This structure contains properties and callbacks that define a type of object.
+       */
+       static JSClassDefinition m_classInfo;
+
+       static JSClassRef m_classRef;
+};
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/standards/Tizen/Filesystem/JSFilestream.cpp b/src/standards/Tizen/Filesystem/JSFilestream.cpp
new file mode 100755 (executable)
index 0000000..2add198
--- /dev/null
@@ -0,0 +1,433 @@
+//
+// 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 "JSFilestream.h"
+
+#include <dpl/scoped_array.h>
+#include <dpl/log/log.h>
+
+#include <Commons/Base64.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "Converter.h"
+#include "plugin_config.h"
+
+namespace {
+const char* PLUGIN_NAME = "FileStream";
+const char* PROPERTY_EOF = "eof";
+const char* PROPERTY_POSITION = "position";
+const char* PROPERTY_BYTES_AVAILABLE = "bytesAvailable";
+}
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+JSClassRef JSFilestream::m_classRef = 0;
+
+JSClassDefinition JSFilestream::m_classInfo = {
+       0,
+       kJSClassAttributeNone,
+       PLUGIN_NAME,
+       0,
+       m_properties,
+       m_functions,
+       initialize,
+       finalize,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       getPropertyNames,
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+JSStaticValue JSFilestream::m_properties[] = {
+       { PROPERTY_EOF, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { PROPERTY_POSITION, getProperty, setProperty, kJSPropertyAttributeNone },
+       { PROPERTY_BYTES_AVAILABLE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSFilestream::m_functions[] = {
+       { "close", close, kJSPropertyAttributeNone },
+       { "read", read, kJSPropertyAttributeNone },
+       { "readBytes", readBytes, kJSPropertyAttributeNone },
+       { "readBase64", readBase64, kJSPropertyAttributeNone },
+       { "write", write, kJSPropertyAttributeNone },
+       { "writeBytes", writeBytes, kJSPropertyAttributeNone },
+       { "writeBase64", writeBase64, kJSPropertyAttributeNone },
+       { 0, 0, 0 }
+};
+
+void JSFilestream::initialize(JSContextRef context,
+       JSObjectRef object)
+{
+}
+
+void JSFilestream::finalize(JSObjectRef object)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(object));
+       delete privateObject;
+}
+
+const JSClassRef JSFilestream::getClassRef()
+{
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+const JSClassDefinition* JSFilestream::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+JSValueRef JSFilestream::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(object));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+               
+       }
+
+       PrivateObject::ObjectType stream = privateObject->getObject();
+       Converter converter(context);
+       try {
+               if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_EOF)) {
+                       return converter.toJSValueRef(stream->isEof());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_POSITION)) {
+                       long pos = stream->getPosition();
+                       if (pos < 0) {
+                               return JSValueMakeUndefined(context);
+                       }
+                       return converter.toJSValueRef(static_cast<unsigned long>(pos));
+               } else if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_BYTES_AVAILABLE)) {
+                       long bytes = stream->getSize() - stream->getPosition();
+                       return converter.toJSValueRef(static_cast<unsigned long>(bytes));
+               }
+       } catch (const WrtDeviceApis::Commons::ConversionException& ex) {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSFilestream::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject =  static_cast<PrivateObject*>(JSObjectGetPrivate(object));
+       if (!privateObject) {
+               return false;
+       }
+
+       Converter converter(context);
+       try {
+               if (JSStringIsEqualToUTF8CString(propertyName, PROPERTY_POSITION)) {
+                       privateObject->getObject()->setPosition(converter.toLong(value));
+                       return true;
+               }
+       } catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogWarning("trying to set incorrect value");
+       }
+
+       return false;
+}
+
+void JSFilestream::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+}
+
+bool JSFilestream::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef instance,
+               JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, instance, JSFilestream::getClassRef());
+}
+
+JSValueRef JSFilestream::close(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject =  static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+               
+       }
+
+       Try {
+               privateObject->getObject()->close();
+       } Catch (WrtDeviceApis::Commons::PlatformException) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFilestream::read(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       Converter converter(context);
+       try {
+               JSValueRef undefinedValue = JSValueMakeUndefined(context);
+               unsigned long count = 0;
+
+               if (argc > 0) 
+                       count = converter.toULong(argv[0]);
+               else 
+                       count = converter.toULong(undefinedValue);
+
+               if (count <= 0) {
+                       ThrowMsg(InvalidArgumentException, "Invalid argument");
+               }
+               
+               DPL::ScopedArray<char> text(privateObject->getObject()->getChars(count));
+               return converter.toJSValueRef(std::string(text.Get()));
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+       }
+       
+}
+
+JSValueRef JSFilestream::readBytes(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       Converter converter(context);
+       Try {
+               JSValueRef undefinedValue = JSValueMakeUndefined(context);
+               unsigned long count = 0;
+
+               if (argc > 0) 
+                       count = converter.toULong(argv[0]);
+               else 
+                       count = converter.toULong(undefinedValue);
+
+               if (count <= 0) {
+                       ThrowMsg(InvalidArgumentException, "Invalid argument");
+               }               
+
+
+               DPL::ScopedArray<unsigned char> data(privateObject->getObject()->getBytes(count));
+               return converter.toJSValueRef(data.Get(), privateObject->getObject()->getCount());
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+       }
+
+}
+
+JSValueRef JSFilestream::readBase64(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       Converter converter(context);
+       try {
+               JSValueRef undefinedValue = JSValueMakeUndefined(context);
+               unsigned long count = 0;
+
+               if (argc > 0) 
+                       count = converter.toULong(argv[0]);
+               else 
+                       count = converter.toULong(undefinedValue);
+
+               if (count <= 0) {
+                       ThrowMsg(InvalidArgumentException, "Invalid argument");
+               }
+
+               DPL::ScopedArray<unsigned char> data(privateObject->getObject()->getBytes(count));
+               std::string base64 = WrtDeviceApis::Commons::Base64::encode(data.Get(), privateObject->getObject()->getCount());
+               return converter.toJSValueRef(base64);
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+       }
+
+}
+
+JSValueRef JSFilestream::write(JSContextRef context,
+       JSObjectRef object,
+       JSObjectRef thisObject,
+       size_t argc,
+       const JSValueRef argv[],
+       JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       Converter converter(context);
+       try {
+               JSValueRef undefinedValue = JSValueMakeUndefined(context);
+
+               if (argc > 0) 
+                       privateObject->getObject()->write(converter.toString(argv[0]));
+               else 
+                       privateObject->getObject()->write(converter.toString(undefinedValue));
+
+
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFilestream::writeBytes(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+
+       Converter converter(context);
+       Try {
+               if (argc < 1 || !JSIsArrayValue(context, argv[0]))
+                       ThrowMsg(ConversionException,  "Type mismatch error");
+
+               PrivateObject::ObjectType stream = privateObject->getObject();
+               std::vector<unsigned char> data = converter.toVectorOfUChars(argv[0]);
+               std::vector<unsigned char>::const_iterator it = data.begin();
+               for (; it != data.end(); ++it) {
+                       stream->write(*it);
+               }
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFilestream::writeBase64(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch error");
+       }
+
+       Converter converter(context);
+       try {
+               LogDebug("OK");
+               
+               JSValueRef undefinedValue = JSValueMakeUndefined(context);
+               std::string base64;
+               if (argc > 0) 
+                       base64 = WrtDeviceApis::Commons::Base64::decode(converter.toString(argv[0]));
+               else 
+                       base64 = WrtDeviceApis::Commons::Base64::decode(converter.toString(undefinedValue));
+
+               privateObject->getObject()->write(base64);
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::PlatformException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, ex.GetMessage());
+       }
+
+       return JSValueMakeUndefined(context);
+}
+} // Tizen1_0
+} // TizenApis
+
diff --git a/src/standards/Tizen/Filesystem/JSFilestream.h b/src/standards/Tizen/Filesystem/JSFilestream.h
new file mode 100755 (executable)
index 0000000..1a202a7
--- /dev/null
@@ -0,0 +1,172 @@
+//
+// 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_JSFILESTREAM_H_
+#define TIZENAPIS_TIZEN_JSFILESTREAM_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Filesystem/IStream.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class JSFilestream
+{
+public:
+       typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Filesystem::IStreamPtr>::Type PrivateObject;
+
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+private:
+       /**
+       * The callback invoked when an object is first created.
+       */
+       static void initialize(JSContextRef context,
+               JSObjectRef object);
+
+       /**
+       * The callback invoked when an object is finalized.
+       */
+       static void finalize(JSObjectRef object);
+
+       /**
+       * 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);
+
+       /**
+       * 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);
+
+       /**
+       * Closes this FileStream.
+       */
+       static JSValueRef close(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * Reads the specified number of characters from this FileStream.
+       */
+       static JSValueRef read(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * Reads the specified number of bytes from this FileStream.
+       */
+       static JSValueRef readBytes(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * Reads the specified number of bytes from this FileStream, encoding the result in base64.
+       */
+       static JSValueRef readBase64(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * Writes the specified DOMString to this FileStream.
+       */
+       static JSValueRef write(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * Writes the specified bytes to this FileStream.
+       */
+       static JSValueRef writeBytes(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * Converts the specified base64 DOMString to bytes and writes the result to this FileStream.
+       */
+       static JSValueRef writeBase64(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       /**
+       * This structure describes a statically declared function property.
+       */
+       static JSStaticFunction m_functions[];
+
+       /**
+       * This structure describes a statically declared value property.
+       */
+       static JSStaticValue m_properties[];
+
+       /**
+       * This structure contains properties and callbacks that define a type of object.
+       */
+       static JSClassDefinition m_classInfo;
+
+       static JSClassRef m_classRef;
+};
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/standards/Tizen/Filesystem/JSFilesystemManager.cpp b/src/standards/Tizen/Filesystem/JSFilesystemManager.cpp
new file mode 100755 (executable)
index 0000000..4756b43
--- /dev/null
@@ -0,0 +1,487 @@
+//
+// 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 "JSFilesystemManager.h"
+
+#include <dpl/log/log.h>
+
+#include <Commons/Exception.h>
+#include <API/Filesystem/EventResolve.h>
+#include <API/Filesystem/IManager.h>
+#include <API/Filesystem/IPath.h>
+#include <API/Filesystem/EventGetStorage.h>
+#include <API/Filesystem/EventListStorages.h>
+#include <API/Filesystem/EventStorageStateChanged.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h> 
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <WidgetDB/WidgetDBMgr.h>
+#include <WidgetDB/IWidgetDB.h>
+
+#include "JSFile.h"
+#include "FilesystemUtils.h"
+#include "Converter.h"
+#include "EventGetNodeData.h"
+#include "plugin_config.h"
+#include "StorageStaticController.h"
+#include "ResponseDispatcher.h"
+#include "FilesystemAsyncCallbackManager.h"
+#include "FilesystemListenerManager.h"
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis;
+using namespace TizenApis::Api::Filesystem;
+
+
+namespace {
+const char* PLUGIN_NAME = "filesystem";
+const char* PROPERTY_MAXPATHLENGTH = "maxPathLength";
+
+JSValueRef getFunctionOrNull(JSContextRef ctx, JSValueRef arg)
+{
+       if (Validator(ctx).isCallback(arg)) {
+               return arg;
+       } else if (!JSValueIsNull(ctx, arg) && !JSValueIsUndefined(ctx, arg)) {
+               ThrowMsg(ConversionException, "Not a function nor JS null.");
+       }
+       return NULL;
+}
+
+
+JSValueRef getFunction(JSContextRef ctx, JSValueRef arg)
+{
+       if (Validator(ctx).isCallback(arg)) {
+               return arg;
+       }else{
+               ThrowMsg(ConversionException, "JS null passed as function.");
+       }
+}
+
+}
+
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassRef JSFilesystemManager::m_classRef = 0;
+
+JSClassDefinition JSFilesystemManager::m_classInfo = {
+       0,
+       kJSClassAttributeNone,
+       PLUGIN_NAME,
+       0,
+       m_properties,
+       m_functions,
+       initialize,
+       finalize,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL
+};
+
+JSStaticValue JSFilesystemManager::m_properties[] = {
+       { PROPERTY_MAXPATHLENGTH, getMaxPathLength, NULL, kJSPropertyAttributeReadOnly },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSFilesystemManager::m_functions[] = {
+       { "resolve", JSFilesystemManager::resolve, kJSPropertyAttributeNone },
+       { "getStorage", JSFilesystemManager::getStorage, kJSPropertyAttributeNone },
+       { "listStorages", JSFilesystemManager::getStorageList, kJSPropertyAttributeNone },
+       { "addStorageStateChangeListener", JSFilesystemManager::addStorageStateListener, kJSPropertyAttributeNone },
+       { "removeStorageStateChangeListener", JSFilesystemManager::removeStorageStateListener, kJSPropertyAttributeNone },
+       { 0, 0, 0 }
+};
+
+const JSClassRef JSFilesystemManager::getClassRef()
+{
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+const JSClassDefinition* JSFilesystemManager::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+void JSFilesystemManager::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+       PrivateObject* privateObject = new PrivateObject(context);
+       if (!JSObjectSetPrivate(object, privateObject)) {
+               delete privateObject;
+       }
+       else {
+        int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+               WidgetDB::Api::IWidgetDBPtr widgetDB = WidgetDB::Api::getWidgetDB(widgetId);
+
+               LogDebug(widgetDB->getWidgetInstallationPath());
+               std::string wgtpackage = "wgt-package";
+               std::string wgtprivate = "wgt-private";
+               std::string wgtprivatetemp = "wgt-private-tmp";
+               
+               Api::Filesystem::IManager::getInstance().addWidgetStorage(wgtpackage, widgetDB->getWidgetInstallationPath());
+               Api::Filesystem::IManager::getInstance().addWidgetStorage(wgtprivate, widgetDB->getWidgetPersistentStoragePath());
+               Api::Filesystem::IManager::getInstance().addWidgetStorage(wgtprivatetemp, widgetDB->getWidgetTemporaryStoragePath());
+       
+       }
+}
+
+void JSFilesystemManager::finalize(JSObjectRef object)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(object));
+       if (privateObject) {
+               JSObjectSetPrivate(object, NULL);
+               delete privateObject;
+       }
+}
+
+JSValueRef JSFilesystemManager::getMaxPathLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       ConverterPtr converter = ConverterFactory::getConverter(context);
+       try {
+               return converter->toJSValueRef(Api::Filesystem::IManager::getInstance().getMaxPathLength());
+       } catch (const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, "IO error");
+       }
+}
+
+JSValueRef JSFilesystemManager::getStorage(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSValueMakeUndefined(context);
+       }
+
+       if (argc < 2) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       JSContextRef globalContext = privateObject->getContext();
+       ConverterPtr converter = ConverterFactory::getConverter(globalContext);
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
+
+       try {
+
+               JSValueRef onSuccess = getFunction(globalContext, argv[1]);
+               JSValueRef onError = NULL;
+                       
+               if (argc>2) {
+                       onError = getFunctionOrNull(globalContext, argv[2]);
+               }
+
+               cbm->setOnSuccess(onSuccess);
+               cbm->setOnError(onError);
+
+               Api::Filesystem::EventGetStoragePtr event(new Api::Filesystem::EventGetStorage());
+               event->setLabel(converter->toString(argv[0]));
+               event->setForAsynchronousCall(&ResponseDispatcher::getInstance()); 
+               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+               FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+               Api::Filesystem::IManager::getInstance().getStorage(event);
+
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+       
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFilesystemManager::getStorageList(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSValueMakeUndefined(context);
+       }
+
+       if (argc < 1) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+               
+
+       JSContextRef globalContext = privateObject->getContext();
+       ConverterPtr converter = ConverterFactory::getConverter(globalContext);
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
+       
+       try {
+
+               JSValueRef onSuccess = getFunction(globalContext, argv[0]);
+               JSValueRef onError = NULL;
+                       
+               if (argc > 1) {
+                       onError = getFunctionOrNull(globalContext, argv[1]);
+               }
+
+               cbm->setOnSuccess(onSuccess);
+               cbm->setOnError(onError);
+               cbm->setObject(thisObject);
+
+               Api::Filesystem::EventListStoragesPtr event(new Api::Filesystem::EventListStorages());
+               event->setForAsynchronousCall(&ResponseDispatcher::getInstance()); 
+               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (cbm));
+               FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+
+               Api::Filesystem::IManager::getInstance().listStorages(event);
+
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+       
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFilesystemManager::addStorageStateListener(JSContextRef context, 
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSValueMakeUndefined(context);
+       }
+
+       if (argc < 1) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "TYPE_MISMATCH_ERROR");
+       }
+
+       JSContextRef globalContext = privateObject->getContext();
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);
+       ConverterPtr converter = ConverterFactory::getConverter(globalContext);
+
+       try {
+               JSValueRef onSuccess = getFunction(globalContext, argv[0]);
+               JSValueRef onError = NULL;
+               if (argc > 1) {
+                       onError = getFunctionOrNull(globalContext, argv[1]);
+               }
+
+               cbm->setOnSuccess(onSuccess);
+               cbm->setOnError(onError);
+
+               Api::Filesystem::EventStorageStateChangedEmitterPtr emitter(new Api::Filesystem::EventStorageStateChangedEmitter);
+               emitter->setListener(&StorageStaticController::getInstance());
+               emitter->setEventPrivateData(DPL::StaticPointerCast<Api::Filesystem::EventStorageStateChanged::PrivateDataType>(cbm));
+               long id = Api::Filesystem::IManager::getInstance().addStorageStateChangeListener(emitter);
+               
+               FilesystemListenerCancellerPtr canceller = FilesystemListenerCancellerPtr(new FilesystemListenerCanceller(globalContext, thisObject, id));
+               IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
+               FilesystemListenerManagerSingleton::Instance().registerListener(listenerItem, globalContext);
+
+               return converter->toJSValueRefLong(id);
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+       
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFilesystemManager::removeStorageStateListener(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSValueMakeUndefined(context);
+       }
+
+       if (argc < 1) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       JSContextRef globalContext = privateObject->getContext();
+       ConverterPtr converter = ConverterFactory::getConverter(globalContext);
+       
+       try {
+               long id = static_cast<long>(converter->toLong(argv[0]));
+               LogDebug("id:" << id);
+
+               if (id >= 0) {
+                       
+                       FilesystemListenerCancellerPtr canceller = FilesystemListenerCancellerPtr(new FilesystemListenerCanceller(globalContext, thisObject, id));
+                       IListenerItemPtr listenerItem = DPL::StaticPointerCast<IListenerItem>(canceller);
+                       FilesystemListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+
+                       Api::Filesystem::IManager::getInstance().removeStorageStateChangeListener(id);
+
+
+               }
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch (const WrtDeviceApis::Commons::NotFoundException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, ex.GetMessage());
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSFilesystemManager::resolve(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argc,
+               const JSValueRef argv[],
+               JSValueRef* exception)
+{
+
+       LogDebug("<<<");
+
+       PrivateObject* privateObject = static_cast<PrivateObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               return JSValueMakeUndefined(context);
+       }
+
+       if (argc < 2) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       JSContextRef globalContext = privateObject->getContext();
+       ConverterPtr converter = ConverterFactory::getConverter(globalContext);
+
+       size_t index = 0;
+       JSValueRef reserveArguments[4];
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext);      
+       
+
+       try {
+               for (index = 0; index < 4; index++) {
+                       if (index < argc)
+                               reserveArguments[index] = argv[index];
+                       else 
+                               reserveArguments[index] = JSValueMakeUndefined(context);
+               }
+               JSValueRef onSuccess = getFunction(globalContext, reserveArguments[1]);
+               JSValueRef onError = NULL;
+
+               onError = getFunctionOrNull(globalContext, reserveArguments[2]);
+
+               cbm->setOnSuccess(onSuccess);
+               cbm->setOnError(onError);
+               cbm->setObject(thisObject);
+
+               Api::Filesystem::IPathPtr path;
+               std::string virtualPath;
+               path = Utils::fromVirtualPath(globalContext, converter->toString(reserveArguments[0]));
+               virtualPath = converter->toString(reserveArguments[0]);
+               LogDebug("virtualPath:[" << virtualPath << "]");
+               int permissions = Api::Filesystem::PERM_READ | Api::Filesystem::PERM_WRITE;
+
+
+               
+               if (argc > 3) {
+                       std::string perms = converter->toString(reserveArguments[3]);
+                       LogDebug("perms:[" << perms << "]");
+                       if (("r" != perms) && ("rw" != perms) && ("w" != perms) && ("a" != perms)) {
+                               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Invalid permission");
+                       } else if ("r" == perms) {
+                               permissions = Api::Filesystem::PERM_READ;
+                       }
+               }
+
+               if (permissions & Api::Filesystem::PERM_WRITE && virtualPath == "wgt-package") {
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::PERMISSION_DENIED_ERROR, "permission denied");
+               }
+
+               PermissionsAccessInfo perms(permissions, virtualPath);
+               AceSecurityStatus status = FILESYSTEM_PERMISSION_CHECK_ACCESS(
+                               FILESYSTEM_FUNCTION_API_MGR_RESOLVE_ID,
+                               perms);
+
+               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               EventGetNodeDataPtr data(new EventGetNodeData(permissions, cbm));
+               Api::Filesystem::EventResolvePtr event(new Api::Filesystem::EventResolve(path));
+               event->setForAsynchronousCall(&ResponseDispatcher::getInstance()); 
+               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData > (data));
+               FilesystemAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, globalContext);
+
+               Api::Filesystem::IManager::getInstance().getNode(event);
+               
+       } catch(const WrtDeviceApis::Commons::ConversionException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::NotFoundException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::NOT_FOUND_ERROR, ex.GetMessage()));
+       } catch (const WrtDeviceApis::Commons::UnsupportedException& ex) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, ex.GetMessage());
+       } catch(const WrtDeviceApis::Commons::InvalidArgumentException& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, ex.GetMessage()));
+       } catch(const WrtDeviceApis::Commons::Exception& ex) {
+               cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, ex.GetMessage()));
+       }
+
+       return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Filesystem/JSFilesystemManager.h b/src/standards/Tizen/Filesystem/JSFilesystemManager.h
new file mode 100755 (executable)
index 0000000..66c35d1
--- /dev/null
@@ -0,0 +1,124 @@
+//
+// 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_JSFILESYSTEMMANAGER_H_
+#define TIZENAPIS_TIZEN_JSFILESYSTEMMANAGER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class JSFilesystemManager
+{
+  public:
+    typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<void>::Type PrivateObject;
+
+  public:
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+  private:
+
+    /**
+     * The callback invoked when an object is first created.
+     */
+    static void initialize(JSContextRef context,
+            JSObjectRef object);
+
+    /**
+     * The callback invoked when an object is finalized.
+     */
+    static void finalize(JSObjectRef object);
+
+    /**
+     * The callback invoked when getting a property's value.
+     */
+    static JSValueRef getMaxPathLength(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    /**
+     * Resolves a location to a File handle.
+     */
+    static JSValueRef resolve(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argc,
+            const JSValueRef argv[],
+            JSValueRef* exception);
+
+    /**
+     * Get information about a storage based on it's label.
+     */
+    static JSValueRef getStorage(JSContextRef context,
+       JSObjectRef object,
+       JSObjectRef thisObject,
+       size_t argc,
+       const JSValueRef argv[],
+       JSValueRef* exception);
+
+    /**
+     * List the available storages on the device.
+     * Get the list of available internal and external storage devices.
+     */
+    static JSValueRef getStorageList(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argc,
+            const JSValueRef argv[],
+            JSValueRef* exception);
+
+    static JSValueRef addStorageStateListener(JSContextRef context, 
+       JSObjectRef object,
+       JSObjectRef thisObject,
+       size_t argc,
+       const JSValueRef argv[],
+       JSValueRef* exception) ;
+
+    static JSValueRef removeStorageStateListener(JSContextRef context, 
+       JSObjectRef object,
+       JSObjectRef thisObject,
+       size_t argc, 
+       const JSValueRef argv[],
+       JSValueRef* exception);
+
+  private:
+    /**
+     * This structure describes a statically declared function property.
+     */
+    static JSStaticFunction m_functions[];
+
+    /**
+     * This structure describes a statically declared value property.
+     */
+    static JSStaticValue m_properties[];
+
+    /**
+     * This structure contains properties and callbacks that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+    static JSClassRef m_classRef;
+};
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/standards/Tizen/Filesystem/JSStorage.cpp b/src/standards/Tizen/Filesystem/JSStorage.cpp
new file mode 100755 (executable)
index 0000000..d2e78e2
--- /dev/null
@@ -0,0 +1,170 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSUtils.h>
+//#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <API/Filesystem/StorageProperties.h>
+#include "JSStorage.h"
+#include "Converter.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace Api::Filesystem;
+
+namespace {
+const char* STR_STORAGE_LABEL = "label";
+const char* STR_STORAGE_TYPE = "type";
+const char* STR_STORAGE_STATE = "state";
+/*const char* STR_TYPE_INTERNAL = "INTERNAL";
+const char* STR_TYPE_EXTERNAL = "EXTERNAL";
+const char* STR_STATE_MOUNTED = "MOUNTED";
+const char* STR_STATE_REMOVED = "REMOVED";
+const char* STR_STATE_UNMOUNTABLE = "UNMOUNTABLE";*/
+} //private namespace
+
+JSClassDefinition JSStorage::m_classInfo = {
+       0,
+       kJSClassAttributeNone,
+       "FileSystemStorage",
+       0,
+       m_property,
+       0,
+       initialize,
+       finalize,
+       NULL,     //HasProperty,
+       getProperty,
+       NULL,     //SetProperty,
+       NULL,     //DeleteProperty,
+       NULL,     //GetPropertyNames,
+       NULL,     //CallAsFunction,
+       NULL,     //CallAsConstructor,
+       hasInstance,
+       NULL,     //ConvertToType
+};
+
+JSStaticValue JSStorage::m_property[] = {
+       { STR_STORAGE_LABEL, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_STORAGE_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_STORAGE_STATE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+/*     { STR_TYPE_INTERNAL, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_TYPE_EXTERNAL, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_STATE_MOUNTED, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_STATE_REMOVED, getProperty, NULL, kJSPropertyAttributeReadOnly },
+       { STR_STATE_UNMOUNTABLE, getProperty, NULL, kJSPropertyAttributeReadOnly },*/
+       { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSStorage::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSStorage::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+JSClassRef JSStorage::m_jsClassRef = JSClassCreate(
+               JSStorage::getClassInfo());
+
+JSObjectRef JSStorage::createJSObject(JSContextRef context,
+               const StorageProperties &storages)
+{
+       std::auto_ptr<StorageProperties> storageProps(new StorageProperties());
+
+       storageProps->setLabel(storages.getLabel());
+       storageProps->setType(storages.getType());
+       storageProps->setState(storages.getState());
+
+       JSStoragePriv *priv = new JSStoragePriv(context, storageProps.get());
+       storageProps.release();
+       if (!priv) {
+               ThrowMsg(Commons::NullPointerException, "Can not new an object");
+       }
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+void JSStorage::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+}
+
+void JSStorage::finalize(JSObjectRef object)
+{
+       JSStoragePriv* priv = static_cast<JSStoragePriv*>(JSObjectGetPrivate(object));
+       JSObjectSetPrivate(object, NULL);
+       delete priv;
+}
+
+JSValueRef JSStorage::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       JSStoragePriv *priv = static_cast<JSStoragePriv*>(JSObjectGetPrivate(object));
+       assert(priv && "Private object not set.");
+
+       Try {
+               StorageProperties *storages = priv->getObject();
+               Converter convert(context);
+
+               if (JSStringIsEqualToUTF8CString(propertyName, STR_STORAGE_LABEL)) {
+                       return convert.toJSValueRef(storages->getLabel());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STORAGE_TYPE)) {
+                       return convert.toStorageType(storages->getType());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STORAGE_STATE)) {
+                       return convert.toStorageState(storages->getState());
+               } 
+               /*else if (JSStringIsEqualToUTF8CString(propertyName, STR_TYPE_INTERNAL)) {
+                       return convert.toJSValueRef(TYPE_INTERNAL);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_TYPE_EXTERNAL)) {
+                       return convert.toJSValueRef(TYPE_EXTERNAL);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STATE_MOUNTED)) {
+                       return convert.toJSValueRef(STATE_MOUNTED);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STATE_REMOVED)) {
+                       return convert.toJSValueRef(STATE_REMOVED);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, STR_STATE_UNMOUNTABLE)) {
+                       return convert.toJSValueRef(STATE_UNMOUNTABLE);
+               }*/
+       } Catch(Commons::Exception) {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSStorage::hasInstance(JSContextRef context,
+               JSObjectRef constructor,
+               JSValueRef possibleInstance,
+               JSValueRef* exception)
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+}
+}
+
diff --git a/src/standards/Tizen/Filesystem/JSStorage.h b/src/standards/Tizen/Filesystem/JSStorage.h
new file mode 100755 (executable)
index 0000000..0b7ad85
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// 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_JS_STORAGE_H_
+#define TIZENAPIS_TIZEN_JS_STORAGE_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Filesystem/StorageProperties.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Filesystem::StorageProperties*>::Type JSStoragePriv;
+
+class JSStorage
+{
+public:
+       enum StorageType
+       {
+               TYPE_INTERNAL = 0,
+               TYPE_EXTERNAL,
+       };
+
+       enum StorageState
+       {
+               STATE_MOUNTED = 0,
+               STATE_REMOVED,
+               STATE_UNMOUNTABLE,
+       };
+               
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       /**
+       * create an JSObject for callback function(onAnswerReceived).
+       */
+       static JSObjectRef createJSObject(JSContextRef context,
+               const Api::Filesystem::StorageProperties &storages);
+
+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 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.
+       */
+       static JSClassDefinition m_classInfo;
+
+       /**
+       * This structure describes a statically declared value property.
+       */
+       static JSStaticValue m_property[];
+
+       static JSClassRef m_jsClassRef;
+};
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Filesystem/ResponseDispatcher.cpp b/src/standards/Tizen/Filesystem/ResponseDispatcher.cpp
new file mode 100755 (executable)
index 0000000..b3bef1c
--- /dev/null
@@ -0,0 +1,295 @@
+//
+// 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 "ResponseDispatcher.h"
+
+#include <dpl/log/log.h>
+#include <dpl/assert.h>
+
+#include <Commons/Exception.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h> 
+#include "JSFile.h"
+#include "JSFilestream.h"
+#include "EventGetNodeData.h"
+#include "Converter.h"
+#include "FilesystemAsyncCallbackManager.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+ResponseDispatcher& ResponseDispatcher::getInstance()
+{
+       static ResponseDispatcher dispatcher;
+       return dispatcher;
+}
+
+ResponseDispatcher::ResponseDispatcher() :
+       EventAnswerReceiver<Api::Filesystem::EventResolve>(ThreadEnum::NULL_THREAD),
+       EventAnswerReceiver<Api::Filesystem::EventGetStorage>(ThreadEnum::NULL_THREAD),
+       EventAnswerReceiver<Api::Filesystem::EventListStorages>(ThreadEnum::NULL_THREAD),
+       EventAnswerReceiver<Api::Filesystem::EventListNodes>(ThreadEnum::NULL_THREAD),
+       EventAnswerReceiver<Api::Filesystem::EventOpen>(ThreadEnum::NULL_THREAD),
+       EventAnswerReceiver<Api::Filesystem::EventCopy>(ThreadEnum::NULL_THREAD),
+       EventAnswerReceiver<Api::Filesystem::EventMove>(ThreadEnum::NULL_THREAD),
+       EventAnswerReceiver<Api::Filesystem::EventRemove>(ThreadEnum::NULL_THREAD),
+       EventAnswerReceiver<Api::Filesystem::EventReadText>(ThreadEnum::NULL_THREAD)
+{
+}
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Filesystem::EventResolvePtr& event)
+{
+       LogDebug("ENTER");
+       EventGetNodeDataPtr data =
+       DPL::DynamicPointerCast<EventGetNodeData>(event->getPrivateData());
+       Assert(NULL != data);
+
+       FilesystemAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data->getCallbackManager());
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               event->getResult()->setPermissions(data->getPerms());
+               JSFile::PrivateObjectDefPtr privData(new JSFile::PrivateObjectDef(event->getResult(), JSFile::PrivateObjectDef::PermissionList()));
+
+               JSObjectRef object = JSUtils::makeObject(data->getCallbackManager()->getContext(), JSFile::getClassRef(), privData);
+               data->getCallbackManager()->callOnSuccess(object);
+       }  else {
+               JSObjectRef jsException =       JSTizenExceptionFactory::makeErrorObject(data->getCallbackManager()->getContext(), JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+               data->getCallbackManager()->callOnError(jsException);
+       }
+}
+
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Filesystem::EventListNodesPtr& event)
+{
+       LogDebug("ENTER");
+       JSFile::ListFilesPrivateDataPtr privData =
+       DPL::DynamicPointerCast<JSFile::ListFilesPrivateData>(event->getPrivateData());
+
+       JSCallbackManagerPtr data = privData->getCallbackManager();
+       Assert(NULL != data);
+
+       FilesystemAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data);
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               Converter converter(data->getContext());
+               Try {
+                       JSValueRef result = converter.toJSValueRef(event->getResult(), privData->getParentPermissions(), data->getContext());
+                       data->callOnSuccess(result);
+               }
+               Catch(WrtDeviceApis::Commons::ConversionException) {
+                       data->callOnError(JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error"));
+               }
+       } else {
+               JSObjectRef jsException = NULL;
+               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               } else {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error");
+               }
+               data->callOnError(jsException);
+       }
+}
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Filesystem::EventOpenPtr& event)
+{
+       LogDebug("ENTER");
+       DPL::SharedPtr<JSCallbackManager> data =
+       DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+       Assert(NULL != data);
+
+       FilesystemAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data);
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               JSObjectRef object = JSUtils::makeObject(data->getContext(), JSFilestream::getClassRef(), event->getResult());
+               data->callOnSuccess(object);
+       } else {
+               JSObjectRef jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error");
+               data->callOnError(jsException);
+       }
+}
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Filesystem::EventCopyPtr& event)
+{
+       LogDebug("ENTER");
+       DPL::SharedPtr<JSCallbackManager> data =
+       DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+       Assert(NULL != data);
+
+       FilesystemAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data);
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               JSFile::PrivateObjectDefPtr privData(new JSFile::PrivateObjectDef(
+               event->getResult(),
+               JSFile::PrivateObjectDef::PermissionList()));
+
+               JSObjectRef object = JSUtils::makeObject(data->getContext(), JSFile::getClassRef(), privData);
+               data->callOnSuccess(object);
+       } else {
+               JSObjectRef jsException = NULL;
+               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               } else {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error");
+               }
+               data->callOnError(jsException);
+       }
+}
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Filesystem::EventMovePtr& event)
+{
+       LogDebug("ENTER");
+       DPL::SharedPtr<JSCallbackManager> data =
+       DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+       Assert(NULL != data);
+
+       FilesystemAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data);
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               JSFile::PrivateObjectDefPtr privData(new JSFile::PrivateObjectDef(
+               event->getResult(),
+               JSFile::PrivateObjectDef::PermissionList()));
+               JSObjectRef object = JSUtils::makeObject(data->getContext(),
+                                JSFile::getClassRef(),
+                                privData);
+               data->callOnSuccess(object);
+       } else {
+               JSObjectRef jsException = NULL;
+               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               } else {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error");
+               }
+               data->callOnError(jsException);
+       }
+}
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Filesystem::EventRemovePtr& event)
+{
+       LogDebug("--| ENTER");
+       DPL::SharedPtr<JSCallbackManager> data =
+       DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+       Assert(NULL != data);
+
+       FilesystemAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data);
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               data->callOnSuccess();
+       } else {
+               JSObjectRef jsException = NULL;
+               if (event->getExceptionCode() ==WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               } else {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error");
+               }
+               data->callOnError(jsException);
+       }
+}
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Filesystem::EventReadTextPtr& event)
+{
+       LogDebug("--| ENTER");
+       DPL::SharedPtr<JSCallbackManager> data =
+       DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+       Assert(NULL != data);
+
+       FilesystemAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data);    
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               Converter converter(data->getContext());
+               Try {
+                       JSValueRef result = converter.toJSValueRef(event->getResult());
+                       data->callOnSuccess(result);
+               }
+               Catch(WrtDeviceApis::Commons::ConversionException) {
+                       data->callOnError(JSTizenExceptionFactory::makeErrorObject(
+                       data->getContext(), JSTizenException::IO_ERROR, "IO error"));
+               }
+       }  else {
+               JSObjectRef jsException = NULL;
+               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               } else {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error");
+               }
+               data->callOnError(jsException);
+       }
+}
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Filesystem::EventGetStoragePtr& event)
+{
+       DPL::SharedPtr<JSCallbackManager> data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+       Assert(NULL != data);
+
+       FilesystemAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data);
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               Converter converter(data->getContext());
+               Try {
+                       JSValueRef result = converter.toJSValueRef(event->getResult(), data->getContext());
+                       data->callOnSuccess(result);
+               } Catch (WrtDeviceApis::Commons::ConversionException) {
+                       data->callOnError(JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error"));
+               }
+       } else {
+               JSObjectRef jsException = NULL;
+               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               } 
+               else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException) {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::NOT_FOUND_ERROR, "Not found error");                       
+               }
+               else {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error");
+               }
+               data->callOnError(jsException);
+       }
+}
+
+void ResponseDispatcher::OnAnswerReceived(const Api::Filesystem::EventListStoragesPtr& event)
+{
+       DPL::SharedPtr<JSCallbackManager> data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+       Assert(NULL != data);
+
+       FilesystemAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(data);
+
+       if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) {
+               Converter converter(data->getContext());
+               Try {
+                       JSValueRef result = converter.toJSValueRef(event->getResult(), data->getContext());
+                       data->callOnSuccess(result);
+               } Catch (WrtDeviceApis::Commons::ConversionException) {
+                       data->callOnError(JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error"));
+               }
+       } else {
+               JSObjectRef jsException = NULL;
+               if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::SecurityException) {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::PERMISSION_DENIED_ERROR, "Permission denied error");
+               } else {
+                       jsException = JSTizenExceptionFactory::makeErrorObject(data->getContext(), JSTizenException::IO_ERROR, "IO error");
+               }
+               data->callOnError(jsException);
+       }
+}
+
+}
+}
diff --git a/src/standards/Tizen/Filesystem/ResponseDispatcher.h b/src/standards/Tizen/Filesystem/ResponseDispatcher.h
new file mode 100755 (executable)
index 0000000..e1097f6
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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_RESPONSEDISPATCHER_H_
+#define TIZENAPIS_TIZEN_RESPONSEDISPATCHER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <Commons/EventReceiver.h>
+#include <API/Filesystem/EventResolve.h>
+#include <API/Filesystem/EventGetStorage.h>
+#include <API/Filesystem/EventListStorages.h>
+#include <API/Filesystem/EventListNodes.h>
+#include <API/Filesystem/EventOpen.h>
+#include <API/Filesystem/EventCopy.h>
+#include <API/Filesystem/EventMove.h>
+#include <API/Filesystem/EventRemove.h>
+#include <API/Filesystem/EventReadText.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class ResponseDispatcher : 
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Filesystem::EventResolve>,
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Filesystem::EventGetStorage>,
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Filesystem::EventListStorages>,
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Filesystem::EventListNodes>,
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Filesystem::EventOpen>,
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Filesystem::EventCopy>,
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Filesystem::EventMove>,
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Filesystem::EventRemove>,
+       public WrtDeviceApis::Commons::EventAnswerReceiver<Api::Filesystem::EventReadText>
+{
+public:
+       static ResponseDispatcher& getInstance();
+
+       void OnAnswerReceived(const Api::Filesystem::EventResolvePtr& event);
+       void OnAnswerReceived(const Api::Filesystem::EventGetStoragePtr& event);
+       void OnAnswerReceived(const Api::Filesystem::EventListStoragesPtr& event);
+       void OnAnswerReceived(const Api::Filesystem::EventListNodesPtr& event);
+       void OnAnswerReceived(const Api::Filesystem::EventOpenPtr& event);
+       void OnAnswerReceived(const Api::Filesystem::EventCopyPtr& event);
+       void OnAnswerReceived(const Api::Filesystem::EventMovePtr& event);
+       void OnAnswerReceived(const Api::Filesystem::EventRemovePtr& event);
+       void OnAnswerReceived(const Api::Filesystem::EventReadTextPtr& event);
+
+protected:
+       ResponseDispatcher();
+};
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Filesystem/StorageStaticController.cpp b/src/standards/Tizen/Filesystem/StorageStaticController.cpp
new file mode 100755 (executable)
index 0000000..f03ebff
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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/JSDOMExceptionFactory.h>
+#include <API/Filesystem/EventStorageStateChanged.h>
+#include "StorageStaticController.h"
+#include "JSStorage.h"
+#include "Converter.h"
+
+using namespace TizenApis::Api::Filesystem;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+StorageStaticController& StorageStaticController::getInstance()
+{
+       static StorageStaticController controller;
+       return controller;
+}
+
+StorageStaticController::StorageStaticController() :
+       EventListener<EventStorageStateChanged>(ThreadEnum::NULL_THREAD)
+{
+}
+
+void StorageStaticController::onAnswerReceived(
+       const EventStorageStateChangedPtr& event)
+{
+       JSCallbackManagerPtr callbackManager =
+               DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
+
+       JSContextRef context = callbackManager->getContext();
+       Converter converter(context);
+       try {
+               JSValueRef result = converter.toJSValueRef(event->getResult(), context);
+               callbackManager->callOnSuccess(result);
+       } catch(Commons::ConversionException) {
+               LogError("Conversion exception while processing EventStorageStateChanged");
+       }
+}
+}
+}
\ No newline at end of file
diff --git a/src/standards/Tizen/Filesystem/StorageStaticController.h b/src/standards/Tizen/Filesystem/StorageStaticController.h
new file mode 100755 (executable)
index 0000000..323662c
--- /dev/null
@@ -0,0 +1,44 @@
+//
+// 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_FILESYSTEM_STORAGE_STATIC_CONTROLLER_H_
+#define TIZENAPIS_TIZEN_FILESYSTEM_STORAGE_STATIC_CONTROLLER_H_
+
+#include <Commons/EventReceiver.h>
+#include <Commons/EventListener.h>
+#include <API/Filesystem/EventStorageStateChanged.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class StorageStaticController :
+    public WrtDeviceApis::Commons::EventListener<Api::Filesystem::EventStorageStateChanged>
+{
+public:
+       static StorageStaticController& getInstance();
+
+       void onAnswerReceived(
+       const Api::Filesystem::EventStorageStateChangedPtr& event);
+
+protected:
+       StorageStaticController();
+};
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Filesystem/config.xml b/src/standards/Tizen/Filesystem/config.xml
new file mode 100755 (executable)
index 0000000..d83eae9
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+  <library-name>libwrt-plugins-tizen-2.0-filesystem.so</library-name>
+  <feature-install-uri>filesystem.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/filesystem.read</name>
+      <device-capability>filesystem.read</device-capability>
+  </api-feature>
+
+  <api-feature>
+      <name>http://tizen.org/privilege/filesystem.write</name>
+      <device-capability>filesystem.read</device-capability>
+      <device-capability>filesystem.write</device-capability>
+  </api-feature>
+
+</plugin-properties>
diff --git a/src/standards/Tizen/Filesystem/plugin_config.cpp b/src/standards/Tizen/Filesystem/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..87cb80b
--- /dev/null
@@ -0,0 +1,391 @@
+//
+// 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 <map>
+#include <utility>
+
+#include <dpl/assert.h>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include <API/Filesystem/Enums.h>
+
+#define FILESYSTEM_FEATURE_API_READ "http://tizen.org/privilege/filesystem.read"
+#define FILESYSTEM_FEATURE_API_WRITE "http://tizen.org/privilege/filesystem.write"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+const char* FILESYSTEM_PARAM_LOCATION = "param:location";
+const char* FILESYSTEM_DEVICE_CAP_READ = "filesystem.read";
+const char* FILESYSTEM_DEVICE_CAP_WRITE = "filesystem.write";
+
+const char* FILESYSTEM_FUNCTION_API_MGR_RESOLVE_ID = "manager_resolve";
+const char* FILESYSTEM_FUNCTION_API_MGR_RESOLVE = "resolve";
+
+const char* FILESYSTEM_FUNCTION_API_RESOLVE = "resolve";
+const char* FILESYSTEM_FUNCTION_API_TO_URI = "toURI";
+const char* FILESYSTEM_FUNCTION_API_LIST_FILES = "listFiles";
+const char* FILESYSTEM_FUNCTION_API_OPEN_STREAM = "openStream";
+const char* FILESYSTEM_FUNCTION_API_READ_AS_TEXT = "readAsText";
+const char* FILESYSTEM_FUNCTION_API_COPY_TO = "copyTo";
+const char* FILESYSTEM_FUNCTION_API_MOVE_TO = "moveTo";
+const char* FILESYSTEM_FUNCTION_API_CREATE_DIR = "createDirectory";
+const char* FILESYSTEM_FUNCTION_API_CREATE_FILE = "createFile";
+const char* FILESYSTEM_FUNCTION_API_DELETE_DIR = "deleteDirectory";
+const char* FILESYSTEM_FUNCTION_API_DELETE_FILE = "deleteFile";
+
+const char* FILESYSTEM_FUNCTION_API_CLOSE = "close";
+const char* FILESYSTEM_FUNCTION_API_READ = "read";
+const char* FILESYSTEM_FUNCTION_API_READ_BYTES = "readBytes";
+const char* FILESYSTEM_FUNCTION_API_READ_BASE64 = "readBase64";
+const char* FILESYSTEM_FUNCTION_API_WRITE = "write";
+const char* FILESYSTEM_FUNCTION_API_WRITE_BYTES = "writeBytes";
+const char* FILESYSTEM_FUNCTION_API_WRITE_BASE64 = "writeBase64";
+
+static WrtDeviceApis::Commons::FunctionMapping createFilesystemFunctions();
+
+static WrtDeviceApis::Commons::FunctionMapping FilesystemFunctions =
+    createFilesystemFunctions();
+
+DEFINE_FUNCTION_GETTER(Filesystem, FilesystemFunctions);
+
+static WrtDeviceApis::Commons::FunctionMapping createFilesystemFunctions()
+{
+       using namespace WrtDeviceApis::Commons;
+
+    /**
+     * Device capabilities
+     */
+
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_FILESYSTEM_READ,
+                          FILESYSTEM_DEVICE_CAP_READ);
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_FILESYSTEM_WRITE,
+                          FILESYSTEM_DEVICE_CAP_WRITE);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_FILESYSTEM_READ);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_FILESYSTEM_READ, DEVICE_CAP_FILESYSTEM_READ);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_FILESYSTEM_WRITE);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_FILESYSTEM_WRITE,
+                       DEVICE_CAP_FILESYSTEM_WRITE);
+
+    /**
+     * Api Features
+     */
+    ACE_CREATE_FEATURE(FEATURE_READ, FILESYSTEM_FEATURE_API_READ);
+    ACE_CREATE_FEATURE(FEATURE_WRITE, FILESYSTEM_FEATURE_API_WRITE);
+
+    ACE_CREATE_FEATURE_LIST(FILESYSTEM_FEATURES_FILESYSTEM_READ);
+
+    ACE_ADD_API_FEATURE(FILESYSTEM_FEATURES_FILESYSTEM_READ,
+                        FEATURE_READ);
+
+    ACE_CREATE_FEATURE_LIST(FILESYSTEM_FEATURES_FILESYSTEM_WRITE);
+
+    ACE_ADD_API_FEATURE(FILESYSTEM_FEATURES_FILESYSTEM_WRITE,
+                        FEATURE_WRITE);
+
+    /**
+     * Functions
+     */
+
+    FunctionMapping FilesystemMapping;
+
+    AceFunction mgrResolveFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_MGR_RESOLVE,
+            FILESYSTEM_FUNCTION_API_MGR_RESOLVE,
+            FILESYSTEM_FEATURES_FILESYSTEM_READ,
+            EMPTY_DEVICE_LIST); // check of device-cap will be done inside resolve()
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_MGR_RESOLVE_ID,
+                                 mgrResolveFunc));
+
+    AceFunction resolveFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_RESOLVE,
+            FILESYSTEM_FUNCTION_API_RESOLVE,
+            FILESYSTEM_FEATURES_FILESYSTEM_READ,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_RESOLVE,
+                                 resolveFunc));
+
+    AceFunction toUriFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_TO_URI,
+            FILESYSTEM_FUNCTION_API_TO_URI,
+            FILESYSTEM_FEATURES_FILESYSTEM_READ,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_TO_URI,
+                                 toUriFunc));
+
+    AceFunction listFilesFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_LIST_FILES,
+            FILESYSTEM_FUNCTION_API_LIST_FILES,
+            FILESYSTEM_FEATURES_FILESYSTEM_READ,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_LIST_FILES,
+                                 listFilesFunc));
+
+    AceFunction openStreamFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_OPEN_STREAM,
+            FILESYSTEM_FUNCTION_API_OPEN_STREAM,
+            FILESYSTEM_FEATURES_FILESYSTEM_READ,
+            EMPTY_DEVICE_LIST); 
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_OPEN_STREAM,
+                                 openStreamFunc));
+
+    AceFunction readAsTextFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_READ_AS_TEXT,
+            FILESYSTEM_FUNCTION_API_READ_AS_TEXT,
+            FILESYSTEM_FEATURES_FILESYSTEM_READ,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_READ_AS_TEXT,
+                                 readAsTextFunc));
+
+    AceFunction copyToFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_COPY_TO,
+            FILESYSTEM_FUNCTION_API_COPY_TO,
+            FILESYSTEM_FEATURES_FILESYSTEM_WRITE,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_COPY_TO,
+                                 copyToFunc));
+
+    AceFunction moveToFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_MOVE_TO,
+            FILESYSTEM_FUNCTION_API_MOVE_TO,
+            FILESYSTEM_FEATURES_FILESYSTEM_WRITE,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_MOVE_TO,
+                                 moveToFunc));
+
+    AceFunction createDirFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CREATE_DIR,
+            FILESYSTEM_FUNCTION_API_CREATE_DIR,
+            FILESYSTEM_FEATURES_FILESYSTEM_WRITE,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_CREATE_DIR,
+                                 createDirFunc));
+
+    AceFunction createFileFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CREATE_FILE,
+            FILESYSTEM_FUNCTION_API_CREATE_FILE,
+            FILESYSTEM_FEATURES_FILESYSTEM_WRITE,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_CREATE_FILE,
+                                 createFileFunc));
+
+    AceFunction deleteDirFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_DELETE_DIR,
+            FILESYSTEM_FUNCTION_API_DELETE_DIR,
+            FILESYSTEM_FEATURES_FILESYSTEM_WRITE,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_DELETE_DIR,
+                                 deleteDirFunc));
+
+    AceFunction deleteFileFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_DELETE_FILE,
+            FILESYSTEM_FUNCTION_API_DELETE_FILE,
+            FILESYSTEM_FEATURES_FILESYSTEM_WRITE,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_DELETE_FILE,
+                                 deleteFileFunc));
+
+    AceFunction closeFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_CLOSE,
+            FILESYSTEM_FUNCTION_API_CLOSE,
+            FILESYSTEM_FEATURES_FILESYSTEM_READ,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_CLOSE,
+                                 closeFunc));
+
+    AceFunction readFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_READ,
+            FILESYSTEM_FUNCTION_API_READ,
+            FILESYSTEM_FEATURES_FILESYSTEM_READ,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_READ,
+                                 readFunc));
+
+    AceFunction readBytesFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_READ_BYTES,
+            FILESYSTEM_FUNCTION_API_READ_BYTES,
+            FILESYSTEM_FEATURES_FILESYSTEM_READ,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_READ_BYTES,
+                                 readBytesFunc));
+
+    AceFunction readBase64Func = ACE_CREATE_FUNCTION(
+            FUNCTION_READ_BASE64,
+            FILESYSTEM_FUNCTION_API_READ_BASE64,
+            FILESYSTEM_FEATURES_FILESYSTEM_READ,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_READ_BASE64,
+                                 readBase64Func));
+
+    AceFunction writeFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_WRITE,
+            FILESYSTEM_FUNCTION_API_WRITE,
+            FILESYSTEM_FEATURES_FILESYSTEM_WRITE,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_WRITE,
+                                 writeFunc));
+
+    AceFunction writeBytesFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_WRITE_BYTES,
+            FILESYSTEM_FUNCTION_API_WRITE_BYTES,
+            FILESYSTEM_FEATURES_FILESYSTEM_WRITE,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_WRITE_BYTES,
+                                 writeBytesFunc));
+
+    AceFunction writeBase64Func = ACE_CREATE_FUNCTION(
+            FUNCTION_WRITE_BASE64,
+            FILESYSTEM_FUNCTION_API_WRITE_BASE64,
+            FILESYSTEM_FEATURES_FILESYSTEM_WRITE,
+            EMPTY_DEVICE_LIST);
+
+    FilesystemMapping.insert(std::make_pair(
+                                 FILESYSTEM_FUNCTION_API_WRITE_BASE64,
+                                 writeBase64Func));
+
+    return FilesystemMapping;
+}
+
+void setFilesystemPermDevCaps(int permissions,
+        const std::string& path,
+        WrtDeviceApis::Commons::AceFunction* outFunction)
+{
+    using namespace TizenApis::Api;
+    using namespace WrtDeviceApis::Commons;
+
+    Assert(outFunction && (permissions != Filesystem::PERM_NONE));
+
+    AceDeviceCapParam paramLocation = AceDeviceCapParam(
+            FILESYSTEM_PARAM_LOCATION, path);
+
+    AceDeviceCaps devCaps;
+
+    if (permissions & Filesystem::PERM_READ) {
+        AceDeviceCapability devCapRead = AceDeviceCapability(
+                FILESYSTEM_DEVICE_CAP_READ,
+                AceDeviceCapParams());
+        devCaps.push_back(devCapRead);
+
+        ACE_ADD_DEV_CAP_PARAM(
+            devCaps,
+            FILESYSTEM_DEVICE_CAP_READ,
+            paramLocation);
+    }
+
+    if (permissions & Filesystem::PERM_WRITE) {
+        AceDeviceCapability devCapWrite = AceDeviceCapability(
+                FILESYSTEM_DEVICE_CAP_WRITE,
+                AceDeviceCapParams());
+
+        devCaps.push_back(devCapWrite);
+
+        ACE_ADD_DEV_CAP_PARAM(
+            devCaps,
+            FILESYSTEM_DEVICE_CAP_WRITE,
+            paramLocation);
+    }
+
+    outFunction->deviceCapabilities = devCaps;
+}
+
+void setFilesystemAccessModeDevCaps(int accessMode,
+        const std::string& path,
+        WrtDeviceApis::Commons::AceFunction
+        *outFunction)
+{
+    using namespace TizenApis::Api;
+    using namespace WrtDeviceApis::Commons;
+
+    Assert(outFunction);
+
+    AceDeviceCapParam paramLocation = AceDeviceCapParam(
+            FILESYSTEM_PARAM_LOCATION,
+            path);
+    AceDeviceCaps devCaps;
+
+    if (accessMode & Filesystem::AM_READ) {
+        AceDeviceCapability devCapRead = AceDeviceCapability(
+                FILESYSTEM_DEVICE_CAP_READ,
+                AceDeviceCapParams());
+
+        devCaps.push_back(devCapRead);
+
+        ACE_ADD_DEV_CAP_PARAM(
+            devCaps,
+            FILESYSTEM_DEVICE_CAP_READ,
+            paramLocation);
+    }
+
+    if ((accessMode & Filesystem::AM_WRITE) ||
+        (accessMode & Filesystem::AM_APPEND)) {
+        AceDeviceCapability devCapWrite = AceDeviceCapability(
+                FILESYSTEM_DEVICE_CAP_WRITE,
+                AceDeviceCapParams());
+
+        devCaps.push_back(devCapWrite);
+
+        ACE_ADD_DEV_CAP_PARAM(
+            devCaps,
+            FILESYSTEM_DEVICE_CAP_WRITE,
+            paramLocation);
+    }
+    outFunction->deviceCapabilities = devCaps;
+}
+}
+}
diff --git a/src/standards/Tizen/Filesystem/plugin_config.h b/src/standards/Tizen/Filesystem/plugin_config.h
new file mode 100755 (executable)
index 0000000..56bd1fd
--- /dev/null
@@ -0,0 +1,146 @@
+//
+// 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 _FILESYSTEM_PLUGIN_CONFIG_H_
+#define _FILESYSTEM_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+extern const char* FILESYSTEM_FUNCTION_API_MGR_RESOLVE_ID;
+
+extern const char* FILESYSTEM_FUNCTION_API_RESOLVE;
+extern const char* FILESYSTEM_FUNCTION_API_TO_URI;
+extern const char* FILESYSTEM_FUNCTION_API_LIST_FILES;
+extern const char* FILESYSTEM_FUNCTION_API_OPEN_STREAM;
+extern const char* FILESYSTEM_FUNCTION_API_READ_AS_TEXT;
+extern const char* FILESYSTEM_FUNCTION_API_COPY_TO;
+extern const char* FILESYSTEM_FUNCTION_API_MOVE_TO;
+extern const char* FILESYSTEM_FUNCTION_API_CREATE_DIR;
+extern const char* FILESYSTEM_FUNCTION_API_CREATE_FILE;
+extern const char* FILESYSTEM_FUNCTION_API_DELETE_DIR;
+extern const char* FILESYSTEM_FUNCTION_API_DELETE_FILE;
+
+extern const char* FILESYSTEM_FUNCTION_API_CLOSE;
+extern const char* FILESYSTEM_FUNCTION_API_READ;
+extern const char* FILESYSTEM_FUNCTION_API_READ_BYTES;
+extern const char* FILESYSTEM_FUNCTION_API_READ_BASE64;
+extern const char* FILESYSTEM_FUNCTION_API_WRITE;
+extern const char* FILESYSTEM_FUNCTION_API_WRITE_BYTES;
+extern const char* FILESYSTEM_FUNCTION_API_WRITE_BASE64;
+
+DECLARE_FUNCTION_GETTER(Filesystem);
+
+void setFilesystemPermDevCaps(int permissions,
+        const std::string& path,
+        WrtDeviceApis::Commons::AceFunction* outFunction);
+
+void setFilesystemAccessModeDevCaps(int accessMode,
+        const std::string& path,
+        WrtDeviceApis::Commons::AceFunction*
+        outFunction);
+
+struct PermissionsAccessInfo
+{
+    PermissionsAccessInfo(int perms,
+            const std::string& fpath) :
+        permissions(perms),
+        path(fpath)
+    {
+    }
+
+    int permissions;
+    const std::string path;
+};
+
+struct AccessModeInfo
+{
+    AccessModeInfo(int amode,
+            const std::string& fpath) :
+        accessMode(amode),
+        path(fpath)
+    {
+    }
+
+    int accessMode;
+    const std::string path;
+};
+
+}
+}
+
+namespace WrtDeviceApis {
+namespace Commons {
+
+/**
+ * template specialization for security access basing on permissions
+ */
+template <>
+class DefaultArgsVerifier <TizenApis::Tizen1_0::PermissionsAccessInfo>
+{
+  public:
+    void operator()(AceFunction& aceFunction,
+            const TizenApis::Tizen1_0::PermissionsAccessInfo& permInfo) const
+    {
+        TizenApis::Tizen1_0::setFilesystemPermDevCaps(permInfo.permissions,
+                                 permInfo.path,
+                                 &aceFunction);
+    }
+};
+
+/**
+ * template specialization for security access basing on access mode
+ */
+template <>
+class DefaultArgsVerifier <TizenApis::Tizen1_0::AccessModeInfo>
+{
+  public:
+    void operator()(AceFunction& aceFunction,
+            const TizenApis::Tizen1_0::AccessModeInfo& accessInfo) const
+    {
+        TizenApis::Tizen1_0::setFilesystemAccessModeDevCaps(accessInfo.accessMode,
+                                       accessInfo.path,
+                                       &aceFunction);
+    }
+};
+
+#define FILESYSTEM_CHECK_ACCESS(functionName) \
+    WrtDeviceApis::Commons::aceCheckAccess<AceFunctionGetter, \
+    WrtDeviceApis::Commons::DefaultArgsVerifier<> >(                \
+        getFilesystemFunctionData,         \
+        functionName)
+
+#define FILESYSTEM_PERMISSION_CHECK_ACCESS(functionName, perm)  \
+    WrtDeviceApis::Commons::aceCheckAccess<AceFunctionGetter,                  \
+    WrtDeviceApis::Commons::DefaultArgsVerifier <TizenApis::Tizen1_0::PermissionsAccessInfo> >(             \
+        getFilesystemFunctionData,         \
+        functionName,                      \
+        perm)
+
+#define FILESYSTEM_ACCESSMODE_CHECK_ACCESS(functionName, amode) \
+    WrtDeviceApis::Commons::aceCheckAccess<AceFunctionGetter,                  \
+    WrtDeviceApis::Commons::DefaultArgsVerifier <TizenApis::Tizen1_0::AccessModeInfo> >(                    \
+        getFilesystemFunctionData,         \
+        functionName,                      \
+        amode)
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Filesystem/plugin_initializer.cpp b/src/standards/Tizen/Filesystem/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..a6f06d6
--- /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.
+//
+
+
+#include <dpl/log/log.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <Commons/plugin_initializer_def.h>
+#include "JSFilesystemManager.h"
+#include "JSFile.h"
+#include "JSFilestream.h"
+#include "FilesystemAsyncCallbackManager.h"
+#include "FilesystemListenerManager.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+void on_widget_start_callback(int widgetId)
+{
+       Try {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+       } Catch (Commons::Exception) {
+               LogError("WrtAccess initialization failed");
+       }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+       Try {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+       } Catch (Commons::Exception) {
+               LogError("WrtAccess deinitialization failed");
+       }
+}
+
+void on_frame_unload_callback(const void * context)
+{
+       LogDebug("[Tizen\\filesystem] on_frame_unload_callback (" << context << ")");
+       TizenApis::Tizen1_0::FilesystemAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+       TizenApis::Tizen1_0::FilesystemListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+void on_frame_load_callback(const void * context)
+{
+       LogDebug("[Tizen\\filesystem] on_frame_load_callback (" << context << ")");
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+PLUGIN_ON_FRAME_LOAD(on_frame_load_callback)
+PLUGIN_ON_FRAME_UNLOAD(on_frame_unload_callback)
+
+#define FILESYSTEM ".filesystem"
+
+PLUGIN_CLASS_MAP_BEGIN
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+        "filesystem",
+        (js_class_template_getter)TizenApis::Tizen1_0::JSFilesystemManager::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_END
+
+#undef FILESYSTEM
+
diff --git a/src/standards/Tizen/Messaging/CMakeLists.txt b/src/standards/Tizen/Messaging/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..9153744
--- /dev/null
@@ -0,0 +1,70 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-messaging")
+set(DESTINATION_NAME  "tizen-2.0-messaging")
+include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_MESSAGING})
+
+
+set(SRCS_MESSAGING
+  #${SRCS_PLATFORM_API_FILESYSTEM}
+  #${SRCS_PLATFORM_IMPLEMENTATION_FILESYSTEM}
+  JSMessagingServiceManager.cpp
+  JSMessagingService.cpp
+  JSMessagingStorage.cpp
+  MessagingListener.cpp
+  MessagingController.cpp
+  MessagingStorageMultiCallback.cpp
+  ConverterMessage.cpp
+  EventSendMessagePrivateData.cpp
+  EventMessagingServicePrivateData.cpp
+  JSMessage.cpp
+  JSRecipientArray.cpp
+  JSConversation.cpp  
+  JSMessageFolder.cpp  
+  JSMessageBody.cpp
+  JSMessageAttachment.cpp
+  MessageAsyncCallbackManager.cpp
+  MessageListenerManager.cpp
+  
+  #../Filesystem/Converter.cpp
+  #../Filesystem/EventGetNodeData.cpp
+  #../Filesystem/JSFile.cpp
+  #../Filesystem/JSFilestream.cpp
+  #../Filesystem/plugin_config.cpp
+  #../Filesystem/JSStorage.cpp
+  #../Filesystem/Encodings.cpp
+  #../Filesystem/FilesystemUtils.cpp
+
+  plugin_config.cpp
+  plugin_initializer.cpp
+)
+
+set(CMAKE_INSTALL_RPATH
+    ${CMAKE_INSTALL_RPATH}
+    ${wrt-deviceapis-filesystem_LIBRARY_DIRS}
+    ${CMAKE_INSTALL_PREFIX}/tizen-2.0-tizen
+    ${CMAKE_INSTALL_PREFIX}/tizen-2.0-filesystem
+)
+
+set(SRCS
+    ${SRCS_MESSAGING}
+    ${SRCS_PLATFORM_IMPLEMENTATION_MESSAGING}
+    ${SRCS_PLATFORM_API_MESSAGING}
+)
+
+include_directories(
+    ${INCLUDES_PLATFORM_IMPLEMENTATION_MESSAGING}
+    ${wrt-deviceapis-filesystem}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${LIBS_PLATFORM_IMPLEMENTATION_MESSAGING}
+  ${LIBS_PLATFORM_IMPLEMENTATION_FILESYSTEM}
+  wrt-plugins-tizen-2.0-tizen-impl
+  wrt-plugins-tizen-2.0-filesystem-impl
+  ${wrt-deviceapis-filesystem_LDFLAGS}
+  ${LIBS_COMMON}
+  ${LIBS_WIDGETDB}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
diff --git a/src/standards/Tizen/Messaging/ConverterMessage.cpp b/src/standards/Tizen/Messaging/ConverterMessage.cpp
new file mode 100755 (executable)
index 0000000..e0ca5a9
--- /dev/null
@@ -0,0 +1,610 @@
+//
+// 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/JSDOMExceptionFactory.h>
+#include "ConverterMessage.h"
+#include "JSMessage.h"
+#include "JSMessagePrivateObject.h"
+#include "JSRecipientArray.h"
+#include "MessagingListener.h"
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include "JSMessageAttachment.h"
+#include "JSConversation.h"
+#include "JSMessageFolder.h"
+
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+#include <Tizen/Filesystem/JSFile.h>
+#endif
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace {
+const char* SEND_PROPERTY_ONSUCCESS = "onsuccess";
+const char* SEND_PROPERTY_ONMESSAGESENDSUCCESS = "onmessagesendsuccess";
+const char* SEND_PROPERTY_ONMESSAGESENDERROR = "onmessagesenderror";
+}
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+MessageFunctions ConverterMessage::m_callbackNames[MESSAGING_MULTI_FUNTION_MAX]
+{
+       {"messagesadded", "messagesupdated", "messagesremoved"},
+       {"conversationsadded", "conversationsupdated", "conversationsremoved"},
+       {"foldersadded", "foldersupdated", "foldersremoved"}
+};
+
+ConverterMessage::ConverterMessage(JSContextRef context) :
+    Converter(context)
+{
+}
+
+ConverterMessage::~ConverterMessage()
+{
+}
+
+JSContextRef ConverterMessage::toJSGlobalContext(JSObjectRef arg)
+{
+    // get private object
+    WrtDeviceApis::CommonsJavaScript::PrivateObjectT<void>::Type* priv =
+        static_cast<WrtDeviceApis::CommonsJavaScript::PrivateObjectT<void>::Type*>(JSObjectGetPrivate(
+                                                              arg));
+    if (!priv) {
+        LogError("Private object not initialized");
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
+                 "Private object not initialized");
+    }
+    return priv->getContext();
+}
+
+JSValueRef ConverterMessage::toJSValueRef(Api::Messaging::FolderType arg)
+{
+    switch (arg) {
+    case Api::Messaging::INBOX:
+        return toJSValueRef(messageFolderInbox);
+    case Api::Messaging::OUTBOX:
+        return toJSValueRef(messageFolderOutbox);
+    case Api::Messaging::DRAFTBOX:
+        return toJSValueRef(messageFolderDrafts);
+    case Api::Messaging::SENTBOX:
+        return toJSValueRef(messageFolderSentbox);
+    default:
+        ThrowMsg(WrtDeviceApis::Commons::ConversionException, "folder not supported");
+    }
+}
+
+JSValueRef ConverterMessage::toJSValueRef(Api::Messaging::MessageType arg)
+{
+    switch (arg) {
+    case Api::Messaging::SMS:
+        return toJSValueRef(messageTypeSms);
+    case Api::Messaging::MMS:
+        return toJSValueRef(messageTypeMms);
+    case Api::Messaging::EMAIL:
+        return toJSValueRef(messageTypeEmail);
+    default:
+        ThrowMsg(WrtDeviceApis::Commons::ConversionException, "message type not supported");
+    }
+}
+
+JSValueRef ConverterMessage::toJSValueRef(const Api::Messaging::IMessagePtr& arg)
+{
+    switch (arg->getMessageType()) {
+    case Api::Messaging::SMS:
+    case Api::Messaging::MMS:
+    case Api::Messaging::EMAIL:
+    case Api::Messaging::EMPTY_MESSAGE: 
+        return JSMessage::createJSObject(m_context, arg);
+
+    default:
+        LogError("unknown type");
+        Throw(WrtDeviceApis::Commons::ConversionException);
+    }
+}
+
+JSValueRef ConverterMessage::toJSValueRef(const Api::Messaging::IMessagePtr& arg,
+        Api::Messaging::EventUpdateMessageAnswerReceiver* listener)
+{
+    switch (arg->getMessageType()) {
+    case Api::Messaging::SMS:
+    case Api::Messaging::MMS:
+    case Api::Messaging::EMAIL:
+    case Api::Messaging::EMPTY_MESSAGE: 
+        return JSMessage::createJSObject(m_context, arg, listener);
+
+    default:
+        LogError("unknown type");
+        Throw(WrtDeviceApis::Commons::ConversionException);
+    }
+}
+
+JSValueRef ConverterMessage::toJSValueRef(
+        const std::vector<Api::Messaging::IMessagePtr>& arg,
+        Api::Messaging::EventUpdateMessageAnswerReceiver* listener)
+{
+    vector<JSValueRef> msgsJS;
+    for (size_t i = 0; i < arg.size(); i++) {
+        msgsJS.push_back(toJSValueRef(arg[i], listener));
+    }
+    return toJSValueRef(msgsJS);
+}
+
+JSValueRef ConverterMessage::toJSValueRef(const std::vector<Api::Messaging::IConversationPtr>& conversations)
+{
+    vector<JSValueRef> conversationJS;
+
+       for (size_t i = 0; i < conversations.size(); i++)
+       {
+               JSValueRef value = JSConversation::createJSObject(m_context, conversations[i]);
+        conversationJS.push_back(value);
+    }
+
+    return toJSValueRef(conversationJS);
+}
+
+JSValueRef ConverterMessage::toJSValueRef(const std::vector<Api::Messaging::IMessageFolderPtr>& messagefolders)
+{
+    vector<JSValueRef> messagefolderJS;
+
+       for (size_t i = 0; i < messagefolders.size(); i++)
+       {
+               JSValueRef value = JSMessageFolder::createJSObject(m_context, messagefolders[i]);
+        messagefolderJS.push_back(value);
+    }
+
+    return toJSValueRef(messagefolderJS);
+}
+
+JSValueRef ConverterMessage::toJSValueRef(const Api::Messaging::MessagePriority& arg)
+{
+    switch (arg.getPriority()) {
+    case Api::Messaging::MessagePriority::LOW:
+        return toJSValueRef(false);
+        break;
+    case Api::Messaging::MessagePriority::NORMAL:
+        return toJSValueRef(false);
+        break;
+    case Api::Messaging::MessagePriority::HIGH:
+        return toJSValueRef(true);
+        break;
+    default:
+        ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Unknown priority");
+        break;
+    }
+}
+
+JSValueRef ConverterMessage::keyToJSValue(JSValueRef value,
+        const string& key)
+{
+    JSValueRef retVal = NULL;
+
+    if (NULL == value) {
+        LogError("jsValue null");
+        Throw(WrtDeviceApis::Commons::ConversionException);
+    }
+    JSObjectRef argObj = JSValueToObject(m_context, value, NULL);
+    if (NULL == argObj) {
+        LogError("conversion to jsobject fail");
+        Throw(WrtDeviceApis::Commons::ConversionException);
+    }
+    const JSStringRef keyJSStr = JSStringCreateWithUTF8CString(key.c_str());
+    retVal = JSObjectGetProperty(m_context, argObj, keyJSStr, NULL);
+    JSStringRelease(keyJSStr);
+    if (NULL == retVal) {
+        LogWarning("key \"" << key << "\" not found in JSValue map");
+    }
+    // return NULL if no key in map
+    return retVal;
+}
+
+Api::Messaging::IMessagePtr ConverterMessage::toIMessage(JSValueRef arg)
+{
+    return toIMessage(toJSObjectRef(arg));
+}
+
+Api::Messaging::IMessagePtr ConverterMessage::toIMessage(JSObjectRef arg)
+{
+    LogDebug("message object=" << arg);
+    if (!arg) {
+        LogError("Object is null");
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
+                 "Private object not initialized");
+    }
+    Api::Messaging::IMessagePtr retVal;
+    // get private object
+    JSMessagePrivateObject* priv =
+        static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(arg));
+    if (!priv) {
+        LogError("Private object not initialized");
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
+                 "Private object not initialized");
+    }
+    retVal = priv->getObject();
+    if (!retVal) {
+        LogError("Message private object not initialized");
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
+                 "Private object not initialized");
+    }
+    return retVal;
+}
+
+Api::Messaging::IAttachmentPtr ConverterMessage::toIAttachment(JSValueRef arg)
+{
+       return toIAttachment(toJSObjectRef(arg));
+}
+
+Api::Messaging::IAttachmentPtr ConverterMessage::toIAttachment(JSObjectRef arg)
+{
+       if (!arg)
+       {
+               LogError("Object is Null");
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object not initialized");
+       }
+
+       Api::Messaging::IAttachmentPtr retVal;
+       JSMessageAttachmentPrivate* priv =
+        static_cast<JSMessageAttachmentPrivate*>(JSObjectGetPrivate(arg));
+
+       if (!priv) {
+        LogError("Private object not initialized");
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
+                 "Private object not initialized");
+       }
+
+       retVal = priv->getObject();
+       if (!retVal) {
+        LogError("Message private object not initialized");
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
+                 "Private object not initialized");
+       }
+       return retVal;
+}
+
+Api::Messaging::IMessageFolderPtr ConverterMessage::toIMessageFolder(JSValueRef arg)
+{
+       return toIMessageFolder(toJSObjectRef(arg));
+}
+
+Api::Messaging::IMessageFolderPtr ConverterMessage::toIMessageFolder(JSObjectRef arg)
+{
+       if (!arg)
+       {
+               LogError("Object is Null");
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object not initialized");
+       }
+
+       Api::Messaging::IMessageFolderPtr retVal;
+       JSMessageFolderPriv* priv =
+        static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(arg));
+
+       if (!priv) {
+        LogError("Private object not initialized");
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
+                 "Private object not initialized");
+       }
+
+       retVal = priv->getObject();
+       if (!retVal) {
+        LogError("Message private object not initialized");
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
+                 "Private object not initialized");
+       }
+       return retVal;
+}
+
+Api::Messaging::Recipients ConverterMessage::toRecipients(JSValueRef arg)
+{
+    if (JSValueIsObjectOfClass(m_context, arg,
+                               JSRecipientArray::getClassRef())) {
+        Api::Messaging::RecipientsPtr recipients =
+            JSRecipientArray::getRecipients(m_context, toJSObjectRef(arg));
+        if (!recipients) {
+            Throw(WrtDeviceApis::Commons::ConversionException);
+        }
+        return *recipients;
+    }
+    Api::Messaging::Recipients retVal;
+    // convert JS value to vector of recipient addresses
+    vector<string> recip = toVectorOfStrings(arg);
+    retVal.setRecipients(recip);
+    return retVal;
+}
+
+OnMessagesChanged ConverterMessage::toMessageMultifunctions(JSValueRef argument)
+{
+       OnMessagesChanged result;
+       Validator validator(m_context);
+       JSObjectRef objectCallbacks = toJSObjectRef(argument);
+       std::string callbackName = toString(argument);
+       int index = 0;
+
+       LogDebug("Enter\n");
+
+       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);
+
+                       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);
+       }
+
+       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);
+       }
+
+       return result;
+}
+
+
+std::vector<Api::Messaging::FolderType> ConverterMessage::toVectorOfFolderTypes(
+        JSValueRef arg)
+{
+    return toVectorOfT_(arg, &ConverterMessage::toFolderType, this);
+}
+
+Api::Messaging::FolderType ConverterMessage::toFolderType(const JSValueRef& arg)
+{
+    // convert JS value to folder type
+    messageFolders folder = static_cast<messageFolders>(toInt(arg));
+    switch (folder) {
+    case messageFolderInbox:
+        return Api::Messaging::INBOX;
+    case messageFolderOutbox:
+        return Api::Messaging::OUTBOX;
+    case messageFolderDrafts:
+        return Api::Messaging::DRAFTBOX;
+    case messageFolderSentbox:
+        return Api::Messaging::SENTBOX;
+    default:
+        ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "folder not supported");
+    }
+}
+
+Api::Messaging::MessageType ConverterMessage::toMessageType(JSValueRef arg)
+{
+        return toMessageType(toJSObjectRef(arg));
+}
+
+Api::Messaging::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 Api::Messaging::SMS;
+       }
+       else if ( strMsgType.compare("messaging.mms") == 0 ) 
+       {
+               return Api::Messaging::MMS;
+       }
+       else if ( strMsgType.compare("messaging.email") == 0 )
+       {
+               return Api::Messaging::EMAIL;
+       }
+       else
+       {
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "message type not supported");
+       }
+
+}
+
+std::string ConverterMessage::toMessageType( long msgtype )
+{
+       LogDebug("Messasge Type : " << msgtype);
+
+       switch (msgtype)
+       {
+               case Api::Messaging::SMS:
+                       return "messaging.sms";
+               case Api::Messaging::MMS:
+                       return "messaging.mms";
+               case Api::Messaging::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 Api::Messaging::MESSAGE_STATUS_SENT:
+                       return "SENT";
+               case Api::Messaging::MESSAGE_STATUS_SENDING:
+                       return "SENDING";
+               case Api::Messaging::MESSAGE_STATUS_FAILED:
+                       return "FAILED";
+               case Api::Messaging::MESSAGE_STATUS_DRAFT:
+                       return "DRAFT";
+               case Api::Messaging::MESSAGE_STATUS_CREATED:
+               case Api::Messaging::MESSAGE_STATUS_LOADED:
+                       return "";
+               default :
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "message status not supported");
+       }
+}
+
+Api::Messaging::IConversationPtr ConverterMessage::toConversation(const JSValueRef& arg)
+{
+       return JSConversation::getConversation(m_context, arg);
+}
+
+std::vector<Api::Messaging::IConversationPtr> ConverterMessage::toVectorOfConversation(const JSValueRef& arg)
+{
+       std::vector<Api::Messaging::IConversationPtr> result;
+
+       JSObjectRef jsObject = toJSObjectRef(arg);
+
+       if(     JSGetArrayLength(m_context, jsObject) == 0)
+       {
+        LogError("this is empty conversation");
+        Throw(WrtDeviceApis::Commons::ConversionException);    
+       }
+
+       for (std::size_t i = 0; i < JSGetArrayLength(m_context, jsObject); ++i)
+       {
+        JSValueRef element = JSGetArrayElement(m_context, jsObject, i);
+        result.push_back(toConversation(element));
+    }
+
+    return result;
+
+}
+Api::Messaging::AddressType ConverterMessage::toAddressType(JSValueRef arg)
+{
+    // convert JSvalue to address type enum
+    string addressType = toString(arg);
+    if ("destination" == addressType) {
+        return Api::Messaging::TO_ADDRESS;
+    } else if ("cc" == addressType) {
+        return Api::Messaging::CC_ADDRESS;
+    } else if ("bcc" == addressType) {
+        return Api::Messaging::BCC_ADDRESS;
+    } else {
+        LogError("unknown address type");
+        Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+    }
+}
+
+Api::Messaging::MessagePriority::Priority ConverterMessage::toMessagePriority(
+        JSValueRef arg)
+{
+    if (toBool(arg)) {
+        return Api::Messaging::MessagePriority::HIGH;
+    } else {
+        return Api::Messaging::MessagePriority::NORMAL;
+    }
+}
+
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+Api::Filesystem::INodePtr ConverterMessage::toFilesystemNode(JSValueRef arg)
+{
+    // TODO It doesn't work even when object IS a JS File, not sure what to do?
+    //    if (!JSValueIsObjectOfClass(m_context, arg, JSFile::getClassRef())) {
+    //        ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Not a JSFile object.");
+    //    }
+
+    JSObjectRef attObj = toJSObjectRef(arg);
+    JSFile::PrivateObject* privateObject =
+        static_cast<JSFile::PrivateObject*>(JSObjectGetPrivate(attObj));
+    if (!privateObject) {
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is NULL.");
+    }
+
+    Api::Filesystem::INodePtr result = privateObject->getObject();
+    if (!result) {
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Node object is NULL.");
+    }
+
+    return result;
+}
+#endif
+
+JSValueRef ConverterMessage::toFunctionOrNull(const JSValueRef& arg)
+{
+    Assert(arg && "Argument is NULL.");
+
+    if (Validator(m_context).isCallback(arg)) {
+        return arg;
+    } else if (!JSValueIsNull(m_context, arg) ) {
+        ThrowMsg(ConversionException, "Not a function nor JS null.");
+    }
+    return NULL;
+}
+
+JSValueRef ConverterMessage::toFunction(const JSValueRef& arg)
+{
+    Assert(arg && "Argument is NULL.");
+
+    if (Validator(m_context).isCallback(arg)) {
+        return arg;
+    } else if (JSValueIsNull(m_context, 
+               arg) || JSValueIsUndefined(m_context, arg)) {
+        ThrowMsg(InvalidArgumentException, "JS null passed as function.");
+    }
+    ThrowMsg(ConversionException, "Not a function nor JS null.");
+}
+
+MessageSendCallback
+ConverterMessage::toMessageSendCallback(const JSValueRef& arg)
+{
+    JSObjectRef object = toJSObjectRef(arg);
+
+    MessageSendCallback result;
+    Validator validator(m_context);
+
+    result.onSuccess = JSUtils::getJSPropertyOrUndefined(
+            m_context, object, SEND_PROPERTY_ONSUCCESS
+            );
+    if (!validator.isNullOrUndefined(result.onSuccess) &&
+        !validator.isCallback(result.onSuccess)) {
+        ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Not a valid callback.");
+    }
+
+    result.onMessageSendSuccess = JSUtils::getJSPropertyOrUndefined(
+            m_context, object, SEND_PROPERTY_ONMESSAGESENDSUCCESS
+            );
+    if (!validator.isNullOrUndefined(result.onMessageSendSuccess) &&
+        !validator.isCallback(result.onMessageSendSuccess)) {
+        ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Not a valid callback.");
+    }
+
+    result.onMessageSendError = JSUtils::getJSPropertyOrUndefined(
+            m_context, object, SEND_PROPERTY_ONMESSAGESENDERROR
+            );
+    if (!validator.isNullOrUndefined(result.onMessageSendError) &&
+        !validator.isCallback(result.onMessageSendError)) {
+        ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Not a valid callback.");
+    }
+
+    return result;
+}
+}
+}
diff --git a/src/standards/Tizen/Messaging/ConverterMessage.h b/src/standards/Tizen/Messaging/ConverterMessage.h
new file mode 100755 (executable)
index 0000000..3763a20
--- /dev/null
@@ -0,0 +1,148 @@
+//
+// 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 <API/Messaging/IMessagingTypes.h>
+#include <API/Messaging/MessageFactory.h>
+#include <API/Messaging/Recipient.h>
+#include <API/Messaging/IMessage.h>
+#include <API/Messaging/EventUpdateMessage.h>
+#include <API/Messaging/IConversation.h>
+
+#include "MessageSendCallback.h"
+#include "MessagingStorageMultiCallback.h"
+
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+#include <API/Messaging/IMessageFolder.h>
+#include <API/Filesystem/INodeTypes.h>
+#endif
+
+#ifndef CONVERTEDMESSAGE_H
+#define CONVERTEDMESSAGE_H
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class ConverterMessage : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+  private:
+    enum messageTypes
+    {
+        messageTypeSms = 1,
+        messageTypeMms = 2,
+        messageTypeEmail = 3
+    };
+
+    enum messageFolders
+    {
+        messageFolderInbox = 1,
+        messageFolderOutbox = 2,
+        messageFolderDrafts = 3,
+        messageFolderSentbox = 4
+    };
+    static MessageFunctions m_callbackNames[MESSAGING_MULTI_FUNTION_MAX];
+
+
+  public:
+    using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
+
+    explicit ConverterMessage(JSContextRef context);
+
+    virtual ~ConverterMessage();
+
+    OnMessagesChanged toMessageMultifunctions(JSValueRef argument);
+
+    JSContextRef toJSGlobalContext(JSObjectRef arg);
+
+    JSValueRef toJSValueRef(Api::Messaging::FolderType arg);
+
+    JSValueRef toJSValueRef(const std::vector<Api::Messaging::IMmsSlidePtr>& slides);
+
+    JSValueRef toJSValueRef(Api::Messaging::MessageType arg);
+
+    JSValueRef toJSValueRef(const Api::Messaging::IMessagePtr& arg);
+
+    JSValueRef toJSValueRef(const Api::Messaging::IMessagePtr& arg,
+            Api::Messaging::EventUpdateMessageAnswerReceiver* listener);
+
+    JSValueRef toJSValueRef(const std::vector<Api::Messaging::IMessagePtr>& arg,
+            Api::Messaging::EventUpdateMessageAnswerReceiver* listener);
+    JSValueRef toJSValueRef(const std::vector<Api::Messaging::IConversationPtr>& conversations);
+    JSValueRef toJSValueRef(const std::vector<Api::Messaging::IMessageFolderPtr>& messagefolders);
+       
+    Api::Messaging::IConversationPtr toConversation(const JSValueRef& arg);
+    std::vector<Api::Messaging::IConversationPtr> toVectorOfConversation(const JSValueRef& arg);
+
+    JSValueRef toJSValueRef(const Api::Messaging::MessagePriority& arg);
+
+    JSValueRef keyToJSValue(JSValueRef value,
+            const std::string& key);
+
+    Api::Messaging::IMessagePtr toIMessage(JSValueRef arg);
+
+    Api::Messaging::IMessagePtr toIMessage(JSObjectRef arg);
+
+    Api::Messaging::IAttachmentPtr toIAttachment(JSValueRef arg);
+
+    Api::Messaging::IAttachmentPtr toIAttachment(JSObjectRef arg);
+       
+    Api::Messaging::Recipients toRecipients(JSValueRef arg);
+
+    std::vector<Api::Messaging::FolderType> toVectorOfFolderTypes(JSValueRef arg);
+
+    Api::Messaging::FolderType toFolderType(const JSValueRef& arg);
+
+    Api::Messaging::IMessageFolderPtr toIMessageFolder(JSValueRef arg);
+
+    Api::Messaging::IMessageFolderPtr toIMessageFolder(JSObjectRef arg);
+
+    Api::Messaging::MessageType toMessageType(JSValueRef arg);
+
+    Api::Messaging::MessageType toMessageType(JSObjectRef arg);
+
+    std::string toMessageType( long msgtype );
+
+    std::string toMessageStatusType( long msgstatus );
+
+    Api::Messaging::AddressType toAddressType(JSValueRef arg);
+
+    Api::Messaging::MessagePriority::Priority toMessagePriority(JSValueRef arg);
+
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+    Api::Filesystem::INodePtr toFilesystemNode(JSValueRef arg);
+#endif
+
+    /**
+     * @throw InvalidArgumentException If not a callback nor JS null.
+     */
+    JSValueRef toFunctionOrNull(const JSValueRef& arg);
+
+    /**
+     * @throw ConversionException If JS null.
+     * @throw InvalidArgumentException If not a callback nor JS null.
+     */
+    JSValueRef toFunction(const JSValueRef& arg);
+
+    MessageSendCallback toMessageSendCallback(const JSValueRef& arg);
+};
+
+typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<ConverterMessage> ConverterMessageFactory;
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Messaging/EventMessagingServicePrivateData.cpp b/src/standards/Tizen/Messaging/EventMessagingServicePrivateData.cpp
new file mode 100755 (executable)
index 0000000..9b852a5
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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.
+//\r
+\r
+#include "EventMessagingServicePrivateData.h"\r
+\r
+using namespace WrtDeviceApis::CommonsJavaScript;\r
+\r
+namespace TizenApis {\r
+namespace Tizen1_0 {\r
+\r
+EventMessagingServicePrivateData::EventMessagingServicePrivateData(const JSCallbackManagerPtr& callbackManager) :\r
+       m_callbackManager(callbackManager)\r
+{\r
+}\r
+\r
+EventMessagingServicePrivateData::EventMessagingServicePrivateData(const JSCallbackManagerPtr& callbackManager,\r
+       const JSCallbackManagerPtr& recipientCallbackManager) :\r
+       m_callbackManager(callbackManager),\r
+       m_recipientCallbackManager(recipientCallbackManager)\r
+{\r
+}\r
+\r
+JSCallbackManagerPtr EventMessagingServicePrivateData::getCallbackManager() const\r
+{\r
+    return m_callbackManager;\r
+}\r
+\r
+JSCallbackManagerPtr EventMessagingServicePrivateData::getRecipientCallbackManager() const\r
+{\r
+               return m_recipientCallbackManager;\r
+}\r
+\r
+\r
+}\r
+}\r
+\r
diff --git a/src/standards/Tizen/Messaging/EventMessagingServicePrivateData.h b/src/standards/Tizen/Messaging/EventMessagingServicePrivateData.h
new file mode 100755 (executable)
index 0000000..43b7e02
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// 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_MESSAGING_EVENT_MESSAGING_SERVICE_PRIVATE_H_
+#define TIZEN_MESSAGING_EVENT_MESSAGING_SERVICE_PRIVATE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+       
+class EventMessagingServicePrivateData : public WrtDeviceApis::Commons::IEventPrivateData
+{
+
+public:
+    EventMessagingServicePrivateData(const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& callbackManager);
+    EventMessagingServicePrivateData(const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& callbackManager, 
+               const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& recipientCallbackManager );
+       
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getCallbackManager() const;
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getRecipientCallbackManager() const;
+
+    void setMessageJSValueRef(const JSValueRef& msgJSValueRef)
+    {
+               m_messageJSValueRef = msgJSValueRef;
+    }
+
+    JSValueRef getMessageJSValueRef()
+    {
+               return m_messageJSValueRef;
+    }
+  
+    void setSyncHandle(int handle)
+    {
+               m_sync_handle = handle;
+    }
+
+    int getSyncHandle()
+    {
+               return m_sync_handle;
+    }
+       
+private:
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_callbackManager;
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_recipientCallbackManager;
+    JSValueRef m_messageJSValueRef;
+
+    int m_sync_handle; 
+
+};
+
+typedef DPL::SharedPtr<EventMessagingServicePrivateData> EventMessagingServicePrivateDataPtr;
+
+}
+}
+#endif //TIZEN_MESSAGING_EVENT_MESSAGING_SERVICE_PRIVATE_H_
+
diff --git a/src/standards/Tizen/Messaging/EventSendMessagePrivateData.cpp b/src/standards/Tizen/Messaging/EventSendMessagePrivateData.cpp
new file mode 100755 (executable)
index 0000000..5ff8ef8
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// 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 "EventSendMessagePrivateData.h"
+
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+EventSendMessagePrivateData::EventSendMessagePrivateData(
+        const JSCallbackManagerPtr& callbackManager,
+        const JSCallbackManagerPtr& recipientCallbackManager) :
+    m_callbackManager(callbackManager),
+    m_recipientCallbackManager(recipientCallbackManager)
+{
+}
+
+JSCallbackManagerPtr EventSendMessagePrivateData::getCallbackManager() const
+{
+    return m_callbackManager;
+}
+
+JSCallbackManagerPtr EventSendMessagePrivateData::getRecipientCallbackManager()
+const
+{
+    return m_recipientCallbackManager;
+}
+}
+}
diff --git a/src/standards/Tizen/Messaging/EventSendMessagePrivateData.h b/src/standards/Tizen/Messaging/EventSendMessagePrivateData.h
new file mode 100755 (executable)
index 0000000..da2d94d
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// 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_MESSAGING_EVENTSENDMESSAGEPRIVATE_H_
+#define TIZEN_MESSAGING_EVENTSENDMESSAGEPRIVATE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class EventSendMessagePrivateData : public WrtDeviceApis::Commons::IEventPrivateData
+{
+  public:
+    EventSendMessagePrivateData(const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& callbackManager,
+            const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& recipientCallbackManager);
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getCallbackManager() const;
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getRecipientCallbackManager() const;
+
+  private:
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_callbackManager;
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_recipientCallbackManager;
+};
+
+typedef DPL::SharedPtr<EventSendMessagePrivateData> EventSendMessagePrivateDataPtr;
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Messaging/JSConversation.cpp b/src/standards/Tizen/Messaging/JSConversation.cpp
new file mode 100755 (executable)
index 0000000..ec90c9f
--- /dev/null
@@ -0,0 +1,270 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <API/Messaging/IConversation.h>
+#include "JSConversation.h"
+
+
+
+using namespace std;
+using namespace DPL;
+using namespace TizenApis::Api::Messaging;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassDefinition JSConversation::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "MessageConversation",
+       NULL,
+       m_properties,
+       NULL,
+       initialize,
+       finalize,
+       NULL, //hasProperty,
+       NULL, //getProperty,
+       NULL, //setProperty,
+       NULL, //deleteProperty,
+       NULL, //getPropertyNames,
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+const char* JSConversation::CONVID = "id";
+const char* JSConversation::TYPE = "type";
+const char* JSConversation::TIMESTAMP = "timestamp";
+const char* JSConversation::MESSAGECOUNT = "messageCount";
+const char* JSConversation::UNREADMESSAGES = "unreadMessages";
+const char* JSConversation::PREVIEW = "preview";
+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 std::string JSConversation::TYPE_SMS              = "messaging.sms";
+const std::string JSConversation::TYPE_MMS              = "messaging.mms";
+const std::string JSConversation::TYPE_EMAIL    = "messaging.email";
+
+JSStaticValue JSConversation::m_properties[] = {
+       {"id", 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 },
+       {"subject", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
+       {"isRead", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
+       {"from", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
+       {"to", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
+       {"cc", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
+       {"bcc", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
+       {"lastMessageId", JSConversation::getProperty, NULL, kJSPropertyAttributeReadOnly },
+       {0, 0, 0, 0}
+};
+
+const JSClassRef JSConversation::getClassRef() {
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSConversation::getClassInfo() {
+       return &m_classInfo;
+}
+
+JSClassRef JSConversation::m_jsClassRef = JSClassCreate(JSConversation::getClassInfo());
+
+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 ");              
+       }
+       else
+       {
+               LogDebug("JSConversation::already exist ");             
+       }
+}
+
+
+
+JSObjectRef JSConversation::createJSObject(JSContextRef context, IConversationPtr object)
+{
+       JSConversationPriv* priv = new JSConversationPriv( context, object);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+
+void JSConversation::finalize(JSObjectRef object) {
+       JSConversationPriv* priv = static_cast<JSConversationPriv*>(JSObjectGetPrivate(object));
+
+       LogDebug("JSConversation::Finalrize");
+
+       if (priv != NULL) 
+       {
+               JSObjectSetPrivate(object, NULL);
+               delete priv;
+       }
+}
+
+bool JSConversation::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) {
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSConversation::getProperty(JSContextRef context,
+                                                                               JSObjectRef object,
+                                                                               JSStringRef propertyName,
+                                                                               JSValueRef* exception)
+{
+       LogDebug("OK"); 
+
+       WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+       JSConversationPriv* priv = static_cast<JSConversationPriv*>(JSObjectGetPrivate(object));        
+       try 
+       {
+               if (priv == NULL)
+               {
+                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+               }
+               
+               IConversationPtr conversation(priv->getObject());
+
+               if (conversation->getResult() == false)
+               {
+                       Throw(WrtDeviceApis::Commons::PlatformException);
+               }
+               if(JSStringIsEqualToUTF8CString(propertyName, "id")) 
+               {
+                       return converter.toJSValueRef(conversation->getId());
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, TYPE)) 
+               {
+                       return converter.toJSValueRef(convertMessageType(conversation->getType()));
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, TIMESTAMP)) 
+               {
+                       return converter.toJSValueRef(conversation->getTime());                 
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, MESSAGECOUNT)) 
+               {
+                       return converter.toJSValueRef(conversation->getMessageCount()); 
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, UNREADMESSAGES)) 
+               {
+                       return converter.toJSValueRef(conversation->getUnreadMessages());       
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, PREVIEW)) 
+               {
+                       return converter.toJSValueRef(conversation->getPreview());      
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, SUBJECT)) 
+               {
+                       return converter.toJSValueRef(conversation->getSubject());      
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, ISREAD)) 
+               {
+                       return converter.toJSValueRef(conversation->getRead());                         
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, FROM)) 
+               {
+                       return converter.toJSValueRef(conversation->getFrom());         
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, TO)) 
+               {
+                       return converter.toJSValueRef(conversation->getTo());                                   
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, CC)) 
+               {
+                       return converter.toJSValueRef(conversation->getCC());                   
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, BCC)) 
+               {
+                       return converter.toJSValueRef(conversation->getBCC());                  
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, LASTMESSAGEID)) 
+               {
+                       return converter.toJSValueRef(conversation->getLastMessageId());                        
+               }
+
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogError("Exception: " << ex.GetMessage());
+       }       
+       return JSValueMakeNull(context);
+}
+
+bool JSConversation::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+IConversationPtr JSConversation::getConversation(JSContextRef context, JSValueRef value)
+{
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) 
+       {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSConversationPriv *priv = static_cast<JSConversationPriv*>(JSObjectGetPrivate(object));
+       
+       if (!priv) 
+       {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+std::string JSConversation::convertMessageType(int msgType){
+
+       if(msgType == Api::Messaging::SMS){
+               return JSConversation::TYPE_SMS;                
+       }else if(msgType == Api::Messaging::MMS){
+               return JSConversation::TYPE_MMS;
+       }else if(msgType == Api::Messaging::EMAIL){
+               return JSConversation::TYPE_EMAIL;
+       }else{
+               return NULL;
+       }
+ }
+
+} 
+}// WrtPlugins
+
+
diff --git a/src/standards/Tizen/Messaging/JSConversation.h b/src/standards/Tizen/Messaging/JSConversation.h
new file mode 100755 (executable)
index 0000000..448a126
--- /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 WRTPLUGINS_TIZEN_JS_CONVERSATION_H_
+#define WRTPLUGINS_TIZEN_JS_CONVERSATION_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Messaging/IConversation.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Messaging::IConversationPtr>::Type JSConversationPriv;
+
+class JSConversation {
+public:
+//@struct JSClassDefinition
+//     @abstract This structure contains properties and callbacks that define a type of object. All fields other than the version field are optional. Any pointer may be NULL.
+       static const JSClassDefinition* getClassInfo();
+       static const JSClassRef getClassRef();
+       static JSObjectRef createJSObject(JSContextRef context, Api::Messaging::IConversationPtr object);
+       static Api::Messaging::IConversationPtr getConversation(JSContextRef context, JSValueRef value);
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+       static std::string convertMessageType(int msgType);
+
+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);
+
+
+       /**
+        * 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 JSStaticValue m_properties[];
+       static JSClassRef m_jsClassRef;
+
+
+       
+       static const char* CONVID;
+       static const char* TYPE;
+       static const char* TIMESTAMP;
+       static const char* MESSAGECOUNT;
+       static const char* UNREADMESSAGES;
+       static const char* PREVIEW;
+       static const char* SUBJECT;
+       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 std::string TYPE_SMS;
+       static const std::string TYPE_MMS;
+       static const std::string TYPE_EMAIL;
+
+};
+
+}
+} //WrtPlugins
+
+#endif //WRTPLUGINS_TIZEN_JS_MESSAGING_SERVICE_MANAGER_H_
+
+
diff --git a/src/standards/Tizen/Messaging/JSMessage.cpp b/src/standards/Tizen/Messaging/JSMessage.cpp
new file mode 100755 (executable)
index 0000000..3a25bee
--- /dev/null
@@ -0,0 +1,1942 @@
+//
+// 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 <API/Messaging/MessageFactory.h>
+#include <API/Messaging/MessagePriority.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Utils.h>
+#include "ConverterMessage.h"
+#include "JSMessage.h"
+#include "JSRecipientArray.h"
+#include "JSMessagePrivateObject.h"
+#include "MessagingListener.h"
+#include <API/Messaging/ReqReceiverMessage.h>
+
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+
+#include "MessagingErrorMsg.h"
+#include "JSMessageAttachment.h"
+#include "plugin_config.h"
+
+#include <Messaging/Sms.h>
+
+
+using namespace std;
+using namespace TizenApis::Api::Messaging;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Platform::Messaging;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+JSClassRef JSMessage::m_jsClassRef = NULL;
+
+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,
+};
+
+// JSMessage properties
+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 }
+};
+
+JSValueRef JSMessage::createJSObject(JSContextRef context,
+               Api::Messaging::EmailAccountInfo& account,
+               Api::Messaging::MessageType msgType,
+               const std::string& msgId)
+{
+       Api::Messaging::IMessagePtr msg;
+       LogDebug("createJSObject with account ");
+
+       Try
+       {
+               if (msgType == Api::Messaging::EMAIL) {
+                   LogDebug("Account Address:" << &account);
+                   LogDebug("Account Data ,ID" << account.getId() << "name:" << account.getName() << " Account:" << account.getAddress());
+
+                   msg = Api::Messaging::MessageFactory::createMessage(msgType, account, msgId);
+                   if (!msg)
+                               return JSValueMakeUndefined(context);
+               } else {
+                   Throw(WrtDeviceApis::Commons::UnknownException);   // unsupported type
+               }
+       }
+       Catch(WrtDeviceApis::Commons::UnknownException) {
+           LogError("wrong message type, object not created");
+           return JSValueMakeUndefined(context);
+       }
+       
+       return createJSObject(context, msg);
+}
+
+JSValueRef JSMessage::createJSObject(JSContextRef context,
+        Api::Messaging::EventUpdateMessageAnswerReceiver* listener,
+        Api::Messaging::MessageType msgType,
+        const string& msgId)
+{
+    Api::Messaging::IMessagePtr msg;
+    Try
+    {
+        // create message depending on type
+        if (msgType == Api::Messaging::SMS || msgType == Api::Messaging::MMS || msgType == Api::Messaging::EMAIL) {
+            msg = Api::Messaging::MessageFactory::createMessage(msgType, msgId);
+           if (!msg)
+               return JSValueMakeUndefined(context);
+        } else {
+            Throw(WrtDeviceApis::Commons::UnknownException);   // unsupported type
+        }
+    }
+    Catch(WrtDeviceApis::Commons::UnknownException) {
+        LogError("wrong message type, object not created");
+        return JSValueMakeUndefined(context);
+    }
+    return createJSObject(context, msg, listener);
+}
+
+JSValueRef JSMessage::createJSObject(JSContextRef context,
+        const Api::Messaging::IMessagePtr& msg,
+        Api::Messaging::EventUpdateMessageAnswerReceiver* listener)
+{
+    JSClassRef jsClassRef = JSClassCreate(getClassInfo());
+    JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
+    priv->setUpdateMsgReceiver(listener);
+    JSObjectRef jsValueRef =
+        JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
+    JSClassRelease(jsClassRef);
+    if (NULL == jsValueRef) {
+        LogError("object creation error");
+        return JSValueMakeUndefined(context);
+    }
+    return jsValueRef;
+}
+
+JSValueRef JSMessage::createJSObject(JSContextRef context,
+        const Api::Messaging::IMessagePtr& msg)
+{
+       LogDebug("createJSObject");
+       JSClassRef jsClassRef = JSClassCreate(getClassInfo());
+       LogDebug("jsClassRef success");
+       JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
+       LogDebug("priv success");
+
+       JSObjectRef jsValueRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
+       LogDebug("JSObjectMake success");
+       JSClassRelease(jsClassRef);
+       if (NULL == jsValueRef) {
+           LogError("object creation error");
+           return JSValueMakeUndefined(context);
+       }
+       return jsValueRef;
+}
+
+JSValueRef JSMessage::createJSObject(JSContextRef context,
+        Api::Messaging::MessageType msgType,
+        const string& msgId)
+{
+    Api::Messaging::IMessagePtr msg;
+    Try
+    {
+        // create message depending on type
+        if (msgType == Api::Messaging::SMS || msgType == Api::Messaging::MMS || msgType == Api::Messaging::EMAIL) {
+            msg = Api::Messaging::MessageFactory::createMessage(msgType, msgId);
+        } else {
+            Throw(WrtDeviceApis::Commons::UnknownException);   // unsupported type
+        }
+    }
+    Catch(WrtDeviceApis::Commons::UnknownException) {
+        LogError("wrong message type, object not created");
+        return JSValueMakeUndefined(context);
+    }
+    return createJSObject(context, msg, NULL);
+}
+
+JSValueRef JSMessage::createDummyMessageJSObject(JSContextRef context,
+       Api::Messaging::MessageType msgType)
+{
+       Api::Messaging::IMessagePtr msg;
+
+       if (msgType == Api::Messaging::EMAIL )
+       {
+               msg = Api::Messaging::MessageFactory::createEmailMessage();
+       }
+       else
+       {
+               LogError("message type is invalid");
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException); 
+       }
+
+       return createJSObject(context, msg);
+}
+
+void JSMessage::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+
+    LogInfo("enter");
+
+    if (!JSObjectGetPrivate(object)) {
+               IMessagePtr msg(new Sms());
+               JSMessagePrivateObject *priv = new JSMessagePrivateObject(context, msg);
+               if (!JSObjectSetPrivate(object, priv)) {
+                       LogInfo("set Private Failed...");
+                       delete priv;
+               }
+    }
+       
+}
+
+void JSMessage::finalize(JSObjectRef object)
+{
+    JSMessagePrivateObject* priv =
+        static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        LogDebug("deleting private object");
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+bool JSMessage::hasProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName)
+{
+    return false;
+}
+
+JSValueRef JSMessage::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogError("should not enter");
+    return JSValueMakeUndefined(context);
+}
+
+bool JSMessage::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    LogError("should not enter");
+    return false;
+}
+
+bool JSMessage::deleteProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogInfo("enter");
+    return true;
+}
+
+void JSMessage::getPropertyNames(JSContextRef context,
+        JSObjectRef object,
+        JSPropertyNameAccumulatorRef propertyNames)
+{
+    LogInfo("enter");
+}
+
+JSValueRef JSMessage::callAsFunction(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogInfo("enter");
+    return JSValueMakeUndefined(context);
+}
+
+bool JSMessage::hasInstance(JSContextRef context,
+        JSObjectRef constructor,
+        JSValueRef possibleInstance,
+        JSValueRef* exception)
+{
+    LogInfo("enter");
+    return true;
+}
+
+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)
+       {
+               try 
+               {
+                       if ( argumentCount < 1 || argumentCount > 2) {
+                               LogError("Wrong argument count");
+                               ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Wrong Message argumentCount");
+                       }
+                       else
+                       {       
+                               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+                               Api::Messaging::MessageType msgType = converter->toMessageType(arguments[0]);
+                               //objMsg = JSMessage::createDummyMessageJSObject(globalContext, msgType);               //make message JSValueRef.
+
+                               Api::Messaging::IMessagePtr msg;
+                               if ( msgType == Api::Messaging::EMAIL )
+                               {
+                                       msg = Api::Messaging::MessageFactory::createEmailMessage();
+                               }
+                               else if (msgType == Api::Messaging::MMS || msgType == Api::Messaging::SMS)
+                               {
+                                       msg = Api::Messaging::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 Api::Messaging::MMS:
+                                                       {
+                                                           Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
+                                                           mms->setSubject(subject);
+                                                           break;
+                                                       }
+                                                       case Api::Messaging::EMAIL:
+                                                       {
+                                                           Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                                                           email->setSubject(subject);
+                                                           break;
+                                                       }
+                                                         default:
+                                                         {
+                                                           LogError("message not supported");
+                                                           //Throw(WrtDeviceApis::Commons::UnsupportedException);
+                                                           //break;
+                                                         }
+                                                       }
+                                                }
+                                               //to
+                                               if (!JSValueIsUndefined(globalContext, toData) )
+                                               {
+                                                       Api::Messaging::Recipients to = converter->toRecipients(toData);
+                                                       LogDebug("setting to field, size=" << to.getRecipientSize());
+                                                       msg->setToRecipients(to);
+                                               }
+                                               //cc
+                                               if (msgType == Api::Messaging::EMAIL )
+                                               {
+                                                       Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                                                       if (!JSValueIsUndefined(globalContext, ccData))
+                                                       {
+                                                               Api::Messaging::Recipients cc = converter->toRecipients(ccData);
+                                                               email->setCcRecipients(cc);
+                                                       }
+
+                                                       if (!JSValueIsUndefined(globalContext, bccData))
+                                                       {
+                                                               Api::Messaging::Recipients bcc = converter->toRecipients(bccData);
+                                                               email->setBccRecipients(bcc);
+                                                       }
+
+                                                       if (!JSValueIsUndefined(globalContext, htmlBodyData))
+                                                       {
+                                                               std::string body = converter->toString(htmlBodyData);
+                                                               LogDebug("html body : " << body);
+                                                               email->setHtmlBody(body);
+                                                       }
+
+                                                       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);
+                                               }
+                                       
+                                       }
+
+                                       //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;
+
+                               }       
+                               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;
+               }
+               
+       }
+       else
+       {
+               LogDebug(" globalContext is NULL ");
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);     
+               return NULL;
+       }
+       
+       return NULL;
+}
+
+JSValueRef JSMessage::convertToType(JSContextRef context,
+        JSObjectRef object,
+        JSType type,
+        JSValueRef* exception)
+{
+    LogInfo("enter");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getAttachments(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogInfo("enter");
+    Try
+    {
+         JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
+        if (!priv)
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);        
+               
+         JSContextRef globalContext = priv->getContext();
+               
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::MessageType msgType = msg->getMessageType();
+         LogInfo("msgType=" << msgType);
+        // prepare common values
+        JSCallbackManagerPtr emptyCallbackMgr = JSCallbackManager::createObject(
+                converter->toJSGlobalContext(object),
+                NULL,
+                NULL);
+
+        switch (msgType) {
+               case Api::Messaging::MMS:
+               case Api::Messaging::EMAIL:
+               {
+                               
+                       std::vector<IAttachmentPtr> attachments;
+                       std::vector<IAttachmentPtr>::iterator it;
+                       
+                       if ( msgType == Api::Messaging::MMS )
+                       {
+                               Api::Messaging::AttachmentsPtr mmsAttachments =
+                                       DPL::StaticPointerCast<Api::Messaging::Attachments>(Api::Messaging::MessageFactory::convertToMms(msg));
+                               attachments = mmsAttachments->getAttachments();
+                       }
+                       else
+                       {
+                               Api::Messaging::AttachmentsPtr emailAttachments =
+                                       DPL::StaticPointerCast<Api::Messaging::Attachments>(Api::Messaging::MessageFactory::convertToEmail(msg));
+                               attachments = emailAttachments->getAttachments();
+                       }
+
+                       int count = attachments.size();
+                       LogDebug( "count : " << count);
+
+                       JSObjectRef jsMessageAttachmentObject[count];   //make
+                       
+                       for (unsigned int index = 0 ; index < attachments.size(); index++ )
+                       {
+                               LogDebug( "Attachment ID : " << attachments[index]->getAttachmentID());
+                               jsMessageAttachmentObject[index] = JSMessageAttachment::createJS(globalContext, attachments[index] );
+                       }                       
+                       JSObjectRef result = JSObjectMakeArray(globalContext, count, jsMessageAttachmentObject, NULL);
+                       
+                       return result;
+                                                       
+               }
+               case Api::Messaging::SMS:
+                   return JSValueMakeUndefined(context);   // ignore
+
+               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 JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSMessage::getBccAddress(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::MessageType msgType = msg->getMessageType();
+
+        switch (msgType) {
+        case Api::Messaging::EMAIL:
+        {
+            Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+            Api::Messaging::RecipientsPtr recipient = email->getBccRecipientsPtr();
+            return JSRecipientArray::createArray(converter->toJSGlobalContext(
+                                                     object), recipient);
+        }
+        case Api::Messaging::SMS:
+        case Api::Messaging::MMS:
+            return JSValueMakeUndefined(context);   // ignore
+
+        default:
+            LogError("not supported message type");
+                return JSTizenExceptionFactory::postException(context, exception, 
+                       JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);        // unsupported 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);
+    }
+
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getBody(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::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);
+    }
+
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getCcAddress(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::MessageType msgType = msg->getMessageType();
+
+        switch (msgType) {
+        case Api::Messaging::EMAIL:
+        {
+            Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+            Api::Messaging::RecipientsPtr recipient = email->getCcRecipientsPtr();
+            return JSRecipientArray::createArray(converter->toJSGlobalContext(
+                                                     object), recipient);
+        }
+        case Api::Messaging::MMS:
+        case Api::Messaging::SMS:
+            return JSValueMakeUndefined(context);   // ignore
+
+        default:
+            LogError("not supported message type");
+                return JSTizenExceptionFactory::postException(context, exception, 
+                          JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);    // unsupported 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);
+    }
+
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getDestinationAddress(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogInfo("enter");
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::RecipientsPtr recipient = msg->getToRecipientsPtr();
+        return JSRecipientArray::createArray(converter->toJSGlobalContext(
+                                                 object), recipient);
+    }
+    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);
+}
+
+JSValueRef JSMessage::getIsRead(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::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);
+    }
+
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getMessageId(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        const string& id = msg->getIdRef();
+        LogDebug("msgId=" << id);
+        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);
+    }
+
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getMessagePriority(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::MessageType msgType = msg->getMessageType();
+
+        switch (msgType) {
+        case Api::Messaging::SMS:
+        case Api::Messaging::MMS:
+            return JSValueMakeUndefined(context);
+
+        case Api::Messaging::EMAIL:
+        {
+            Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+            return converter->toJSValueRef(static_cast<Api::Messaging::MessagePriority>(*
+                                                                             email));
+        }
+
+        default:
+            LogError("unsupported message type");
+               return JSTizenExceptionFactory::postException(context, exception, 
+                                 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);        // unsupported 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);
+    }
+
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getMessageType(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::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);
+    }
+
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getSourceAddress(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+
+        //This property is set up by the device or the web runtime environment.
+        //This property should only be taken into account for Email.
+        // TODO Verify with Tizen.
+        //        if (msg->getMessageType() != Api::Messaging::EMAIL && msg->getMessageType() != Api::VIRTUAL_MESSAGE) {
+        //            return JSValueMakeUndefined(context);
+        //        }
+        return converter->toJSValueRef(msg->getSourceAddress());
+    }
+    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);
+}
+
+JSValueRef JSMessage::getSubject(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::MessageType msgType = msg->getMessageType();
+
+        switch (msgType) {
+        case Api::Messaging::MMS:
+        {
+            Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
+            return converter->toJSValueRef(mms->getSubject());
+        }
+        case Api::Messaging::EMAIL:
+        {
+            Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+            return converter->toJSValueRef(email->getSubject());
+        }
+        case Api::Messaging::SMS:
+            return JSValueMakeUndefined(context);   // ignore
+        default:
+            LogError("message not support subject");
+               return JSTizenExceptionFactory::postException(context, exception, 
+                                 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);        // unsupported 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);
+    }
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getTime(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        struct tm dateTime = msg->getDateTime();
+        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);
+    }
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getFolder(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::FolderType folder = msg->getCurrentFolder();
+        return converter->toJSValueRef(folder);
+    }
+    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);
+}
+
+JSValueRef JSMessage::getMessageBody(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    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();
+
+         ConverterMessageFactory::ConverterType converter =
+         ConverterMessageFactory::getConverter(globalContext);
+         Api::Messaging::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);
+    }
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getAccountID(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogInfo("getAccountID");
+
+    Try
+    {
+         JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
+         Assert(priv && "Private object is NULL.");
+
+         JSContextRef globalContext = priv->getContext();
+
+         ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(globalContext);
+
+         Api::Messaging::IMessagePtr msg = converter->toIMessage(object);      //get message point
+
+         LogInfo("create JS");
+         //getAccountID
+         if (msg->getMessageType() == Api::Messaging::EMAIL)
+         {
+               Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+               
+               std::stringstream stream;
+               stream << email->getAccountID();
+               if (stream.fail()) {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+                                        "Couldn't convert e-mail account id");
+               }
+               
+               return converter->toJSValueRef(stream.str());
+         }
+               else if (msg->getMessageType() == Api::Messaging::SMS)
+               {
+                       std::stringstream stream;
+                       stream << Api::Messaging::SMS_ACCOUNT_ID;
+                       if (stream.fail()) {
+                               ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+                                               "Couldn't convert sms account id");
+                       }
+
+                       return converter->toJSValueRef(stream.str());
+               }
+               else if (msg->getMessageType() == Api::Messaging::MMS)
+               {
+                       Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+
+                       std::stringstream stream;
+                       stream << Api::Messaging::MMS_ACCOUNT_ID;
+                       if (stream.fail()) {
+                               ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+                                               "Couldn't convert mms account id");
+               }
+
+                       return converter->toJSValueRef(stream.str());
+               }
+         else
+         {
+                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);
+    }
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getUID(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception)
+       {
+               LogInfo("getUID");
+
+               Try
+               {
+                 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
+                 Assert(priv && "Private object is NULL.");
+
+                 JSContextRef globalContext = priv->getContext();
+
+                 ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(globalContext);
+
+                 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
+
+                 LogInfo("create JS");
+                 //getAccountID
+                 if (msg->getMessageType() == Api::Messaging::EMAIL)
+                 {
+                       Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                       return converter->toJSValueRef(email->getUID());
+                 }
+                 else
+                 {
+                        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);
+               }
+//             return JSValueMakeUndefined(context);
+       }
+
+bool JSMessage::setAttachments(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+       LogInfo("enter");
+
+       Try
+    {
+        JSMessagePrivateObject* priv =
+            static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
+               if (priv) {
+
+                       JSContextRef globalContext = priv->getContext();
+                       if (!globalContext)
+                       {
+                               LogDebug("globalContext is NULL");
+                               globalContext = context;
+                       }
+                       ConverterMessageFactory::ConverterType converter =
+                       ConverterMessageFactory::getConverter(context);
+                       
+                       vector<IAttachmentPtr> attachments;
+                       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;
+                                       }
+                                       Api::Messaging::IAttachmentPtr attachment = converter->toIAttachment(att);
+
+                                       if(attachment->getIsValidAttachment() == false)
+                                       {
+                                               LogDebug("invalid attachment : " << i);
+                                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                                       }
+
+                                       LogDebug("Adding attachment , shotname: " << attachment->getShortName());
+                                       attachments.push_back(attachment);
+                               }                               
+                       }
+                       else
+                       {       
+                               Api::Messaging::IAttachmentPtr attachment = converter->toIAttachment(value);
+                               LogDebug("Adding attachment , shotname: " << attachment->getShortName());
+                               if(attachment->getIsValidAttachment() == false)
+                               {
+                                       LogDebug("invalid attachment");
+                                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                               }                               
+                               attachments.push_back(attachment);
+                       }
+                       
+                       LogDebug("Attachment Size =" << attachments.size());
+                       if ( attachments.size() > 0)                            
+                       {
+                               Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+                               if (msg)
+                               {
+                                       Api::Messaging::MessageType msgType = msg->getMessageType();
+                                       switch (msgType) {
+                                               case Api::Messaging::MMS:
+                                               {
+                                                       Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
+                                                       mms->setAttachments(attachments);
+                                               break;
+                                               }
+                                               case Api::Messaging::EMAIL:
+                                               {
+                                                       Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                                                       email->setAttachments(attachments);
+                                               break;
+                                               }
+                                               default:
+                                                       LogError("not supported message type");
+                                                       Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                                       }
+                               
+                                       return true;
+                               }
+                               else
+                               {
+                                       LogError("Message converter failed...");
+                                       Throw(WrtDeviceApis::Commons::NullPointerException);
+                               }
+                       }
+                                                       
+               }
+         
+    }
+       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;   
+}
+
+
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+bool JSMessage::setAttachments(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    LogInfo("enter");
+
+    Try
+    {
+        JSMessagePrivateObject* priv =
+            static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
+
+        if (!priv) {
+            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);
+    }
+
+    vector<string> attachments;
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        if (JSIsArrayValue(context, value)) {
+            JSObjectRef valueObj = converter->toJSObjectRef(value);
+
+            // extract path from each JSFile object
+            unsigned int len = JSGetArrayLength(context, valueObj);
+            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;
+                }
+                Api::Filesystem::INodePtr node = converter->toFilesystemNode(
+                        att);
+
+                LogDebug("Adding attachment: " << node->getPath()->getFullPath());
+                attachments.push_back(node->getPath()->getFullPath());
+            }
+        } else {
+            LogWarning("Invalid or null element passed as attachment array." <<
+                       "Setting empty vector.");
+        }
+
+        // set up new attachments list
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::MessageType msgType = msg->getMessageType();
+        switch (msgType) {
+        case Api::Messaging::MMS:
+        {
+            Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
+            mms->setAttachments(attachments, true);
+            break;
+        }
+        case Api::Messaging::EMAIL:
+        {
+            Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+            email->setAttachments(attachments, true);
+            break;
+        }
+        case Api::Messaging::SMS:
+
+            return false; // ignore
+
+        default:
+            LogError("not supported message type");
+            Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+        }
+        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::InvalidArgumentException) {
+        LogError("Invalid argument");
+          return JSTizenExceptionFactory::postException(context, exception, 
+                          JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+    }
+    return false;
+}
+#endif
+
+bool JSMessage::setBccAddress(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::Recipients bcc = converter->toRecipients(value);
+        LogDebug("setting bcc field, size=" << bcc.getRecipientSize());
+
+        Api::Messaging::MessageType msgType = msg->getMessageType();
+        switch (msgType) {
+        case Api::Messaging::SMS:
+        case Api::Messaging::MMS:
+            return false;   // ignore
+
+        case Api::Messaging::EMAIL:
+        {
+            Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+            email->setBccRecipients(bcc);
+            break;
+        }
+        default:
+            LogError("unsupported message type");
+            return JSTizenExceptionFactory::postException(context, exception, 
+                                         JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);        // unsupported type
+        }
+        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;
+}
+
+bool JSMessage::setBody(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::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;
+}
+
+bool JSMessage::setCcAddress(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::Recipients cc = converter->toRecipients(value);
+        LogDebug("setting cc field, size=" << cc.getRecipientSize());
+
+        Api::Messaging::MessageType msgType = msg->getMessageType();
+        switch (msgType) {
+        case Api::Messaging::SMS:
+        case Api::Messaging::MMS:
+            return false;   // ignore
+
+        case Api::Messaging::EMAIL:
+        {
+            Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+            email->setCcRecipients(cc);
+            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);
+       }
+
+    return false;
+}
+
+bool JSMessage::setDestinationAddress(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef * exception)
+{
+    LogInfo("enter");
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::Recipients to = converter->toRecipients(value);
+        LogDebug("setting to field, size=" << to.getRecipientSize());
+        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;
+}
+
+bool JSMessage::setIsRead(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef * exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::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;
+}
+
+bool JSMessage::setMessagePriority(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef * exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::MessageType msgType = msg->getMessageType();
+        switch (msgType) {
+        case Api::Messaging::MMS:
+        case Api::Messaging::SMS:
+            return false;   // ignore
+
+        case Api::Messaging::EMAIL:
+            msg->setPriority(converter->toMessagePriority(value));
+            break;
+
+        default:
+            LogError("unsuported message type");
+            Throw(WrtDeviceApis::Commons::ConversionException);
+            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;
+}
+
+bool JSMessage::setSubject(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef * exception)
+{
+    Try
+    {
+        ConverterMessageFactory::ConverterType converter =
+            ConverterMessageFactory::getConverter(context);
+        Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+        Api::Messaging::MessageType msgType = msg->getMessageType();
+        string subject = converter->toString(value);
+        switch (msgType) {
+        case Api::Messaging::MMS:
+        {
+            Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
+            mms->setSubject(subject);
+            break;
+        }
+        case Api::Messaging::EMAIL:
+        {
+            Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+            email->setSubject(subject);
+            break;
+        }
+        case Api::Messaging::SMS:
+            return false;   // ignore
+
+        default:
+            LogError("message not supported");
+            Throw(WrtDeviceApis::Commons::UnsupportedException);
+            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;
+}
+
+bool JSMessage::setMessageBody(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        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;
+}
+
+JSValueRef JSMessage::getConversationId(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+       LogDebug("getConversationId");
+
+    Try
+    {
+               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+               int convId = 0;
+               Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+               Api::Messaging::EventGetConversationIdPtr event(new Api::Messaging::EventGetConversationId());
+               event->setConversationMsgPtr(msg);
+               event->setForSynchronousCall();
+               Api::Messaging::ReqReceiverMessageSingleton::Instance().getConversationId(event);
+
+               convId = event->getConversationId();
+
+        return converter->toJSValueRef(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);
+       }
+
+//    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getInResponseTo(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("getInResponseTo");
+
+       Try
+       {
+               ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);              
+               int convId = -1;
+               int msgId = 0;
+               Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+               
+               if (msg->getMessageType() != EMAIL)
+               {
+                       LogDebug("not EMAIL type");
+                       return JSValueMakeNull(context);                
+               }
+
+               Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+               msgId = email->getUID();
+
+               Api::Messaging::EventGetConversationIdPtr event(new Api::Messaging::EventGetConversationId());
+               event->setConversationMsgPtr(msg);
+               event->setForSynchronousCall();
+               Api::Messaging::ReqReceiverMessageSingleton::Instance().getConversationId(event);
+               convId = event->getConversationId();
+
+               if (convId == msgId)
+               {
+                       LogDebug("Not forwared and replied, return NULL");
+                       return JSValueMakeNull(context);
+               }
+
+               return converter->toJSValueRef(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);
+       }
+
+//     return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessage::getMessageStatus(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception)
+{
+       LogInfo("getMessageStatus");
+
+       Try
+       {
+         JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
+         Assert(priv && "Private object is NULL.");
+
+         JSContextRef globalContext = priv->getContext();
+
+         ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(globalContext);
+
+         Api::Messaging::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);
+}
+
+
+JSValueRef JSMessage::hasAttachment(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception)
+{
+       LogInfo("hasAttachment");
+
+       Try
+       {
+               JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
+               Assert(priv && "Private object is NULL.");
+
+               JSContextRef globalContext = priv->getContext();
+
+               ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(globalContext);
+
+               Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
+
+               bool hasAttachmentFlag = false;
+
+                if ( msg->getMessageType() == EMAIL)
+                       {
+                       Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+
+                       if (email->hasAttachment())
+                               hasAttachmentFlag = true;
+                       }
+               else if  ( msg->getMessageType() == MMS)
+               {
+                       Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
+
+                       if (mms->hasAttachment())
+                               hasAttachmentFlag = true;
+               }
+               else
+               {
+                        return JSTizenExceptionFactory::postException(context, exception, 
+                               JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
+               }
+                        
+               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);
+       }
+       
+//     return JSValueMakeUndefined(context);
+}
+
+#if 0
+JSValueRef JSMessage::getAttachmentExistence(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception)
+{
+       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);
+
+         Api::Messaging::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);
+}
+#endif
+
+}
+}
diff --git a/src/standards/Tizen/Messaging/JSMessage.h b/src/standards/Tizen/Messaging/JSMessage.h
new file mode 100755 (executable)
index 0000000..9d200f3
--- /dev/null
@@ -0,0 +1,333 @@
+//
+// 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 JSMESSAGE_H
+#define JSMESSAGE_H
+
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Messaging/IMessagingTypes.h>
+#include <API/Messaging/IMessage.h>
+#include <API/Messaging/EventUpdateMessage.h>
+#include "JSMessageBody.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class JSMessage
+{
+    static JSClassRef m_jsClassRef;
+
+  public:
+
+    /*
+     * This method initializes object in the JS Engine.
+     */
+    static JSClassRef jsInit(JSContextRef context)
+    {
+        LogInfo("enter");
+        return JSClassCreate(&m_classInfo);
+    }
+
+    static const JSClassDefinition* getClassInfo()
+    {
+        LogInfo("enter");
+        return &(m_classInfo);
+    }
+
+    static JSClassRef getClassRef()
+    {
+        LogInfo("enter");
+        if (!m_jsClassRef) {
+            m_jsClassRef = JSClassCreate(&m_classInfo);
+        }
+        return m_jsClassRef;
+    }
+
+    static JSValueRef createJSObject(JSContextRef context,
+            Api::Messaging::EmailAccountInfo& account, 
+            Api::Messaging::MessageType msgType,
+            const std::string& msgId = "");
+       
+    static JSValueRef createJSObject(JSContextRef context,
+            Api::Messaging::EventUpdateMessageAnswerReceiver* listener,
+            Api::Messaging::MessageType msgType = Api::Messaging::MESSAGETYPE_COUNT,
+            const std::string& msgId = "");
+
+    static JSValueRef createJSObject(JSContextRef context,
+               Api::Messaging::MessageType msgType = Api::Messaging::MESSAGETYPE_COUNT,
+               const std::string& msgId = "");
+
+       static JSValueRef createJSObject(JSContextRef context,
+            const Api::Messaging::IMessagePtr& msg,
+            Api::Messaging::EventUpdateMessageAnswerReceiver* listener);
+
+    static JSValueRef createJSObject(JSContextRef context,
+                 const Api::Messaging::IMessagePtr& msg);
+
+       static JSValueRef createDummyMessageJSObject(JSContextRef context,
+               Api::Messaging::MessageType msgType);
+
+  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 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 deleting a property.
+     */
+    static bool deleteProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    /**
+     * The callback invoked when collecting the names of an object's properties.
+     */
+    static void getPropertyNames(JSContextRef context,
+            JSObjectRef object,
+            JSPropertyNameAccumulatorRef propertyNames);
+
+    /**
+     * The callback invoked when an object is called as a function.
+     */
+    static JSValueRef callAsFunction(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            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 JSObjectRef constructor(JSContextRef ctx, 
+                       JSObjectRef constructor, 
+                       size_t argumentCount, 
+                       const JSValueRef arguments[], 
+                       JSValueRef* exception);
+
+    /**
+     * The callback invoked when converting an object to a particular JavaScript type.
+     */
+    static JSValueRef convertToType(JSContextRef context,
+            JSObjectRef object,
+            JSType type,
+            JSValueRef* exception);
+    static JSValueRef getAttachments(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getBccAddress(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getBody(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getCallbackNumber(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getCcAddress(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getDestinationAddress(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getIsRead(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getMessageId(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getMessagePriority(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getMessageType(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getSourceAddress(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getSubject(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getTime(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getFolder(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getMessageBody(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getAccountID(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+    static JSValueRef getUID(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+    static bool setAttachments(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+#endif
+    static bool setAttachments(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+
+    static bool setBccAddress(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static bool setBody(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static bool setCcAddress(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static bool setDestinationAddress(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static bool setIsRead(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static bool setMessagePriority(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+    static bool setSubject(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+       static bool setMessageBody(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef value,
+            JSValueRef* exception);
+
+    static JSValueRef update(JSContextRef context,
+            JSObjectRef function,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef getConversationId(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+    static JSValueRef getInResponseTo(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+    static JSValueRef getMessageStatus(JSContextRef context,
+                               JSObjectRef object,
+                               JSStringRef propertyName,
+                               JSValueRef* exception);
+
+    static JSValueRef hasAttachment(JSContextRef context,
+                               JSObjectRef object,
+                               JSStringRef propertyName,
+                               JSValueRef* exception);
+
+    /**
+     * 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
diff --git a/src/standards/Tizen/Messaging/JSMessageAttachment.cpp b/src/standards/Tizen/Messaging/JSMessageAttachment.cpp
new file mode 100755 (executable)
index 0000000..0998d2d
--- /dev/null
@@ -0,0 +1,578 @@
+//
+// 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 <CommonsJavaScript/JSUtils.h>
+#include "ConverterMessage.h"
+#include "JSMessageAttachment.h"
+#include <Tizen/Filesystem/JSFile.h>
+#include <Tizen/Filesystem/EventGetNodeData.h>
+#include <Tizen/Filesystem/FilesystemUtils.h>
+#include <API/Filesystem/IManager.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <API/Messaging/AttachmentFactory.h>
+#include "MessagingErrorMsg.h"
+#include <Messaging/Attachment.h>
+
+#if 0
+namespace {
+const char* MSG_ATTACHMENT_MIMETYPE            = "MIMEType";
+const char* MSG_ATTACHMENT_MESSAGEID           = "messageId";
+const char* MSG_ATTACHMENT_CONTENTLOCATION     = "contentLocation";
+const char* MSG_ATTACHMENT_CONTENTID   = "contentId";
+const char* MSG_ATTACHMENT_LOADED              = "loaded";
+}
+#endif
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Messaging;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Platform::Messaging;
+
+JSClassRef JSMessageAttachment::m_jsClassRef = NULL;
+
+JSClassDefinition JSMessageAttachment::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "MessageAttachment",
+    /*NULL,*/
+    /*JSFile::getClassRef(), parent*/
+    NULL,
+    m_property,
+    NULL,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL,   //getproperty
+    NULL,  //setProperty
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL, //callAsFunction,
+    constructor, //callAsConstructor,
+    NULL, //hasInstance,
+    NULL, //convertToType,
+};
+
+JSStaticValue JSMessageAttachment::m_property[] = {
+    //{ "MIMEType", JSMessageAttachment::getMIMEType, NULL, kJSPropertyAttributeReadOnly },
+    { "id", JSMessageAttachment::getContentID, NULL, kJSPropertyAttributeNone },
+    { "messageId", JSMessageAttachment::getMessageID, NULL, kJSPropertyAttributeReadOnly },
+    //{ "contentLocation", JSMessageAttachment::getContentLocation, NULL, kJSPropertyAttributeNone },
+    { "mimeType", JSMessageAttachment::getMIMEType, NULL, kJSPropertyAttributeReadOnly },
+    { "loaded", JSMessageAttachment::getLoaded, NULL, kJSPropertyAttributeReadOnly },
+    { "filePath", JSMessageAttachment::getFilePath, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+const JSClassDefinition* JSMessageAttachment::getClassInfo()
+{
+    return &(m_classInfo);
+}
+
+JSClassRef JSMessageAttachment::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+void JSMessageAttachment::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+       LogDebug("enter");
+       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;
+               }
+       }
+}
+
+void JSMessageAttachment::finalize(JSObjectRef object)
+{
+    LogDebug("enter");
+    JSMessageAttachmentPrivate* priv = static_cast<JSMessageAttachmentPrivate*>(JSObjectGetPrivate(object));
+    JSContextRef gContext = priv->getContext();
+       
+    Api::Messaging::IAttachmentPtr attachment = getAttachment(gContext, object);
+       
+    if ( attachment )
+   {
+       if (attachment->hasDummyFile())
+       {
+               AttachmentFactory::removeDummyFile(attachment->getDummyFilePath());
+       }
+   }
+
+    JSObjectSetPrivate(object, NULL);
+    delete priv;
+}
+
+JSObjectRef JSMessageAttachment::createJS( JSContextRef context, const Api::Messaging::IAttachmentPtr& attachment)
+{
+
+    JSMessageAttachmentPrivate *priv = new JSMessageAttachmentPrivate(context, attachment);
+    return JSObjectMake(context, getClassRef(), priv); //make JSObjectRef.
+}
+
+JSValueRef JSMessageAttachment::getMIMEType(JSContextRef context,
+          JSObjectRef object,
+          JSStringRef propertyName,
+          JSValueRef* exception)
+{
+       LogDebug("enter");
+       Try
+       {
+               Api::Messaging::IAttachmentPtr attachment = getAttachment(context, object);
+
+               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+               LogDebug("mine type :" << attachment->getMimeType());
+               if (attachment->getMimeType().size() == 0)
+               {
+                       LogDebug("return NULL");
+                       return JSValueMakeNull(context);
+               }
+               return converter.toJSValueRef(attachment->getMimeType());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessageAttachment::getMessageID(JSContextRef context,
+          JSObjectRef object,
+          JSStringRef propertyName,
+          JSValueRef* exception)
+{
+       LogDebug("enter");
+       Try
+       {
+               Api::Messaging::IAttachmentPtr attachment = getAttachment(context, object);
+
+               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+               LogDebug("Message ID :" << (attachment->getMessage()));
+               if ( (attachment->getAttachmentID() < 0) && (attachment->getMessage() == 0))
+               {
+                       LogDebug("return NULL");
+                       return JSValueMakeNull(context);
+               }
+               return converter.toJSValueRef(attachment->getMessage()->getId());
+       }
+       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+       {
+               LogError("invalid value conversion");
+               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, 
+               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+       }
+}
+
+
+JSValueRef JSMessageAttachment::getContentLocation(JSContextRef context,
+          JSObjectRef object,
+          JSStringRef propertyName,
+          JSValueRef* exception)
+{
+       return JSValueMakeNull(context);
+}
+
+JSValueRef JSMessageAttachment::getContentID(JSContextRef context,
+          JSObjectRef object,
+          JSStringRef propertyName,
+          JSValueRef* exception)
+{
+       LogDebug("enter");
+       Try
+       {
+               Api::Messaging::IAttachmentPtr attachment = getAttachment(context, object);
+
+               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+               LogDebug("Attachment Loaded :" << (attachment->getDownloaded() ));
+
+               if ( attachment->getAttachmentID() < 0)
+               {
+                       LogDebug("return NULL");
+                       return JSValueMakeNull(context);                        
+               }
+
+               return converter.toJSValueRef(attachment->getAttachmentID());
+       }
+       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+       {
+               LogError("invalid value conversion");
+               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, 
+               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+       }
+}
+
+JSValueRef JSMessageAttachment::getLoaded(JSContextRef context,
+          JSObjectRef object,
+          JSStringRef propertyName,
+          JSValueRef* exception)
+{
+       
+         LogDebug("enter");
+           Try
+           {
+                 Api::Messaging::IAttachmentPtr attachment = getAttachment(context, object);
+                 
+       WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+                 LogDebug("Attachment Loaded :" << (attachment->getDownloaded() ));
+                 return converter.toJSValueRef(attachment->getDownloaded());
+           }
+           Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+           {
+                  LogError("invalid value conversion");
+                  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, 
+                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+           }
+//         return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessageAttachment::getFilePath(JSContextRef context,
+          JSObjectRef object,
+          JSStringRef propertyName,
+          JSValueRef* exception)
+{
+       LogDebug("enter");
+
+       JSMessageAttachmentPrivate* priv = static_cast<JSMessageAttachmentPrivate*>(JSObjectGetPrivate(object));
+       if (priv)
+               LogDebug("priv is vaild");
+
+       JSContextRef globalContext = priv ? priv->getContext() : context;
+       
+       Api::Messaging::IAttachmentPtr attachment = getAttachment(context, object);
+       
+       if ( attachment )
+       {
+               Try
+               {       
+                       WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+                       
+                       std::string fullPath = attachment->getFullPath();
+                       LogDebug("fullPath=" << fullPath);              
+
+                       if (fullPath.empty()) {
+                               return JSValueMakeNull(context);
+                       }
+                       else
+                       {
+                               std::string filePath;
+                               Try {
+                                       filePath = Utils::toVirtualPath(globalContext, fullPath);
+                                       return converter.toJSValueRef(filePath);
+                               }
+                               catch (WrtDeviceApis::Commons::ConversionException)
+                               {
+                                       LogDebug("It is not in the the list of root locations ");
+                                       if (attachment->hasDummyFile())
+                                       {
+                                               LogDebug("Get Dummy File Path " << attachment->getDummyFilePath());
+                                               filePath =      attachment->getDummyFilePath();
+                                       }
+                                       else
+                                       {
+                                               LogDebug("Create DummyFile");
+                                               std::string tmpPath = AttachmentFactory::getDummyFileFromRealPath(globalContext, fullPath);
+                                               LogDebug("tmp Path : " << tmpPath);
+                                               if (tmpPath.length())
+                                               {
+                                                       attachment->setDummyFilePath(tmpPath);
+                                                       if ( !attachment->hasDummyFile())
+                                                       {
+                                                               LogDebug("dummy File Path is invalided But Can't access this file.");
+                                                               return JSValueMakeNull(context);
+                                                       }
+                                                       else
+                                                       {
+                                                               filePath = tmpPath;
+                                                       }
+                                               }
+                                               else
+                                               {
+                                                       return JSValueMakeNull(context); 
+                                               }
+                                       }
+                                       
+                               
+                               }
+
+                               return converter.toJSValueRef(Utils::toVirtualPath(globalContext, filePath));
+
+                       }       
+
+               }
+               Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+               {
+                  LogError("invalid value conversion");
+                  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, 
+                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+               }
+//             return JSValueMakeUndefined(context);
+               
+       }
+       else
+       {
+               return JSTizenExceptionFactory::postException(context, exception, 
+                       JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+       }
+       
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+               LogDebug("enter");
+               Try
+               {
+                 Api::Messaging::IAttachmentPtr attachment = getAttachment(context, object);
+                  if (!attachment) {
+                       return JSValueMakeUndefined(context);
+                   }
+
+                   std::string fullPath = attachment->getFullPath();
+                   LogDebug("full Path = " << fullPath );      
+                   if (fullPath.empty()) {
+                       return JSValueMakeUndefined(context);
+                   }
+
+                   int permissions = Api::Filesystem::PERM_READ | Api::Filesystem::PERM_WRITE;
+                   EventGetNodeDataPtr data(
+                       new EventGetNodeData(permissions, WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr())
+                       );
+                   Api::Filesystem::EventResolvePtr event(new Api::Filesystem::EventResolve(
+                                                         Api::Filesystem::IPath::create(fullPath))
+                                                     );
+                   event->setPrivateData(
+                       DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(data)
+                       );
+                   event->setForSynchronousCall();
+                   Api::Filesystem::IManager::getInstance().getNode(event);
+
+                   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, 
+                                        JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+
+                   }
+
+                   Api::Filesystem::INodePtr node = event->getResult();
+                   if (!node) {
+                       LogError("Resolved attachment location is empty.");
+                          return JSTizenExceptionFactory::postException(context, exception, 
+                                        JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+
+                   }
+
+                       Api::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, 
+                          JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+
+               }
+               Catch(WrtDeviceApis::Commons::Exception)
+               {
+                   LogError("Unkown Exception");
+                   return JSTizenExceptionFactory::postException(context, exception, 
+                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+               }
+               return JSValueMakeUndefined(context);
+#endif
+//return JSValueMakeUndefined(context);
+
+}
+
+Api::Messaging::IAttachmentPtr JSMessageAttachment::getAttachment(JSContextRef context,
+        JSValueRef value)
+{
+    WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+    return getAttachment(context, converter.toJSObjectRef(value));
+}
+
+Api::Messaging::IAttachmentPtr JSMessageAttachment::getAttachment(JSContextRef context,
+        JSObjectRef object)
+{
+    // private object of thisObject
+    return getPrivate(object)->getObject();
+}
+
+JSMessageAttachmentPrivate* JSMessageAttachment::getPrivate(JSObjectRef thisObject)
+{
+    JSMessageAttachmentPrivate* thisPrivate =
+        static_cast<JSMessageAttachmentPrivate*>(JSObjectGetPrivate(thisObject));
+    if (!thisPrivate) {
+        LogError("no private");
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+    }
+    return thisPrivate;
+}
+
+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
+               {
+                       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;
+                       }
+                       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)
+                               {
+                                       Api::Filesystem::IPathPtr src = 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);
+                               Api::Messaging::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..."); 
+                               }
+                       }
+
+               }       
+               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;
+               }
+       }
+       else
+       {
+               LogDebug(" globalContext is NULL ");
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);     
+               return NULL;
+       }
+
+       return NULL;
+}
+
+
+}
+}
+
diff --git a/src/standards/Tizen/Messaging/JSMessageAttachment.h b/src/standards/Tizen/Messaging/JSMessageAttachment.h
new file mode 100755 (executable)
index 0000000..443b4ca
--- /dev/null
@@ -0,0 +1,140 @@
+//
+// 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 WRT_PLUGINS_TIZEN_JS_MESSAGE_ATTACHMENT_H_
+#define WRT_PLUGINS_TIZEN_JS_MESSAGE_ATTACHMENT_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Messaging/IMessagingService.h>
+#include <API/Messaging/IMessage.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Messaging::IAttachmentPtr>::Type JSMessageAttachmentPrivate;     //IAttachmentPtr
+       
+class JSMessageAttachment
+{
+       static JSClassRef m_jsClassRef;
+       
+public:
+       static const JSClassDefinition* getClassInfo();
+       static JSClassRef getClassRef();
+       static JSObjectRef createJS( JSContextRef context, const Api::Messaging::IAttachmentPtr &msg);
+
+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 bool hasProperty(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName);
+
+    static JSObjectRef constructor(JSContextRef ctx, 
+                       JSObjectRef constructor, 
+                       size_t argumentCount, 
+                       const JSValueRef arguments[], 
+                       JSValueRef* exception);
+
+    /**
+     * Get MIME Type of Attachment File.  readonly
+     */
+    static JSValueRef getMIMEType(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception);
+
+    
+    static JSValueRef getMessageID(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception);
+
+    static JSValueRef getContentLocation(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception);
+
+    static JSValueRef getContentID(JSContextRef context,
+               JSObjectRef object,
+               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);
+       
+    /*
+     * returns private object or throws WrtDeviceApis::Commons::NullPointerException
+     */
+    static JSMessageAttachmentPrivate* 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 Api::Messaging::IAttachmentPtr getAttachment(JSContextRef context,
+                       JSValueRef value);
+
+       /*
+        * extracts Api Message representation
+        * throws WrtDeviceApis::Commons::NullPointerException if there's no private object
+        */
+       static Api::Messaging::IAttachmentPtr getAttachment(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[];
+  
+};
+       
+}
+}
+
+#endif //WRT_PLUGINS_TIZEN_JS_MESSAGE_ATTACHMENT_H_
+
diff --git a/src/standards/Tizen/Messaging/JSMessageBody.cpp b/src/standards/Tizen/Messaging/JSMessageBody.cpp
new file mode 100755 (executable)
index 0000000..37d603e
--- /dev/null
@@ -0,0 +1,532 @@
+//
+// 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 <CommonsJavaScript/JSUtils.h>
+#include "ConverterMessage.h"
+#include "JSMessageBody.h"
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+#include "JSAttachmentArray.h"
+#endif
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "MessagingErrorMsg.h"
+
+#include "JSMessageAttachment.h"
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+       using namespace TizenApis::Commons;
+       using namespace TizenApis::Api::Messaging;
+       using namespace WrtDeviceApis::Commons; 
+       using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+JSClassRef JSMessageBody::m_jsClassRef = NULL;
+
+JSClassDefinition JSMessageBody::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "MessageBody",
+    0,
+    m_property,
+    NULL,
+    initialize,
+    finalize,
+    hasProperty,
+    NULL,   //getproperty
+    NULL,  //setProperty
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL, //callAsFunction,
+    NULL, //callAsConstructor,
+    NULL, //hasInstance,
+    NULL, //convertToType,
+};
+
+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 },
+#if 0 // MESSAGING ATTACHMENT IS BLOCKED
+    { "inlineAttachments", NULL, NULL, kJSPropertyAttributeReadOnly },
+#endif
+    { "inlineAttachments", JSMessageBody::getAttachments, JSMessageBody::setAttachments, kJSPropertyAttributeNone },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassDefinition* JSMessageBody::getClassInfo()
+{
+    return &(m_classInfo);
+}
+
+JSClassRef JSMessageBody::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+bool JSMessageBody::hasProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName)
+{
+    LogDebug("enter");
+    WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+    Try
+    {
+        Api::Messaging::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)
+{
+    LogDebug("enter");
+}
+
+void JSMessageBody::finalize(JSObjectRef object)
+{
+    LogDebug("enter");
+    JSMessageBodyPrivate* priv = static_cast<JSMessageBodyPrivate*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    delete priv;
+}
+
+JSObjectRef JSMessageBody::createJS( JSContextRef context, const Api::Messaging::IMessagePtr &msg)
+{
+    JSMessageBodyPrivate *priv = new JSMessageBodyPrivate(context, msg);
+    return JSObjectMake(context, getClassRef(), priv); //make JSObjectRef.
+}
+
+JSValueRef JSMessageBody::getMessageID(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("enter");
+    Try
+    {
+         Api::Messaging::IMessagePtr msg = getMessage(context, object);
+         
+        WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+        return converter.toJSValueRef(msg->getId());
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("invalid conversion");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSMessageBody::getLoadedStatus(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("enter");
+    Try
+    {
+         WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+         Api::Messaging::IMessagePtr msg = getMessage(context, object);
+         
+         if (msg->getMessageType() == Api::Messaging::EMAIL)
+         {
+               //Api::Messaging::IEmailPtr email = DPL::StaticPointerCast<Api::IEmailPtr>(Api::Messaging::MessageFactory::convertToEmail(msg));
+               Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+               return converter.toJSValueRef(email->isBodyDownloaded() > 0 ? true : false);
+         }
+         else
+         {
+               return converter.toJSValueRef(true);
+         }
+         
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("invalid conversion");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+
+JSValueRef JSMessageBody::getPlainBody(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{      
+    LogDebug("getPlainBody");
+
+    Try
+    {          
+               WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+               Api::Messaging::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);
+
+    }
+//    return JSValueMakeUndefined(context);
+}
+
+bool JSMessageBody::setPlainBody(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+
+    LogDebug("setPlainBody");
+
+    Try
+    {
+          WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+        Api::Messaging::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);
+               Api::Messaging::IMessagePtr msg = getMessage(context, object);
+
+             LogDebug("message Type : " << msg->getMessageType() );
+               if (msg->getMessageType() == Api::Messaging::EMAIL)
+                 {
+                       Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+
+                LogDebug("Html Body : " << email->getHtmlBody() );
+                       return converter.toJSValueRef(email->getHtmlBody());
+                 }
+                 else
+                 {
+                        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(WrtDeviceApis::Commons::PlatformException) {
+        LogError("Platform execution");
+        return JSTizenExceptionFactory::postException(context, exception, 
+                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+    }
+
+       
+//    return JSValueMakeUndefined(context);
+}
+
+bool JSMessageBody::setHtmlBody(JSContextRef context,
+       JSObjectRef object,
+       JSStringRef propertyName,
+       JSValueRef value,
+       JSValueRef* exception)
+{
+
+       LogDebug("setHtmlBody");
+
+       Try
+          {
+                 WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+                 Api::Messaging::IMessagePtr msg = getMessage(context, object);
+                 
+                 if (msg->getMessageType() == Api::Messaging::EMAIL)
+                 {
+                       Api::Messaging::IEmailPtr email = Api::Messaging::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 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;
+}
+
+
+JSValueRef JSMessageBody::getAttachments(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogInfo("enter");
+    Try
+    {
+
+               ConverterMessageFactory::ConverterType converter =
+               ConverterMessageFactory::getConverter(context);
+               Api::Messaging::IMessagePtr msg = getMessage(context, object);
+               Api::Messaging::MessageType msgType = msg->getMessageType();
+               int count = 0;
+
+               LogInfo("msgType=" << msgType);
+
+               switch (msgType) {
+                       case Api::Messaging::EMAIL:
+                       {
+
+                               std::vector<IAttachmentPtr> inlineAttachments;
+                               std::vector<IAttachmentPtr>::iterator it;
+
+                               Api::Messaging::AttachmentsPtr emailAttachments =
+                               DPL::StaticPointerCast<Api::Messaging::Attachments>(Api::Messaging::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 Api::Messaging::SMS:
+                       case Api::Messaging::MMS:
+                               return JSValueMakeUndefined(context);   // ignore
+
+                       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);
+       }
+}
+
+bool JSMessageBody::setAttachments(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;
+                               }
+                               Api::Messaging::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
+               {
+                       Api::Messaging::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)
+               {
+                       Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
+                       if (msg)
+                       {
+                               Api::Messaging::MessageType msgType = msg->getMessageType();
+                               switch (msgType) {
+                                       case Api::Messaging::EMAIL:
+                                       {
+                                               Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                                               email->setInlineAttachments(inlineAttachments);
+                                       break;
+                                       }
+                                       default:
+                                               LogError("not supported message type");
+                                               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+                               }
+                               return true;
+                       }
+                       else
+                       {
+                               LogError("Message converter failed...");
+                               Throw(WrtDeviceApis::Commons::NullPointerException);
+                       }
+               }
+    }
+       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;
+}
+
+Api::Messaging::IMessagePtr JSMessageBody::getMessage(JSContextRef context,
+        JSValueRef value)
+{
+    WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+    return getMessage(context, converter.toJSObjectRef(value));
+}
+
+Api::Messaging::IMessagePtr JSMessageBody::getMessage(JSContextRef context,
+        JSObjectRef object)
+{
+    // private object of thisObject
+    return getPrivate(object)->getObject();
+}
+
+JSMessageBodyPrivate* JSMessageBody::getPrivate(JSObjectRef thisObject)
+{
+    JSMessageBodyPrivate* thisPrivate =
+        static_cast<JSMessageBodyPrivate*>(JSObjectGetPrivate(thisObject));
+    if (!thisPrivate) {
+        LogError("no private");
+        Throw(WrtDeviceApis::Commons::NullPointerException);
+    }
+    return thisPrivate;
+}
+
+}
+}
+
+
diff --git a/src/standards/Tizen/Messaging/JSMessageBody.h b/src/standards/Tizen/Messaging/JSMessageBody.h
new file mode 100755 (executable)
index 0000000..617b100
--- /dev/null
@@ -0,0 +1,151 @@
+//
+// 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 WRT_PLUGINS_TIZEN_JS_MESSAGE_BODY_H_
+#define WRT_PLUGINS_TIZEN_JS_MESSAGE_BODY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Messaging/IMessagingService.h>
+#include <API/Messaging/IMessage.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Messaging::IMessagePtr>::Type JSMessageBodyPrivate;      //IMessagePtr
+       
+
+class JSMessageBody
+{
+       static JSClassRef m_jsClassRef;
+       
+public:        
+       static const JSClassDefinition* getClassInfo();
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createJS( JSContextRef context, const Api::Messaging::IMessagePtr &msg);
+
+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 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,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static JSValueRef getLoadedStatus(JSContextRef context,
+            JSObjectRef object,
+            JSStringRef propertyName,
+            JSValueRef* exception);
+
+    static JSValueRef getPlainBody(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);
+
+
+    /*
+     * 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 Api::Messaging::IMessagePtr getMessage(JSContextRef context,
+                       JSValueRef value);
+
+       /*
+        * extracts Api Message representation
+        * throws WrtDeviceApis::Commons::NullPointerException if there's no private object
+        */
+       static Api::Messaging::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[];
+  
+};
+       
+}
+}
+
+#endif //WRT_PLUGINS_TIZEN_JS_MESSAGE_BODY_H_
+
diff --git a/src/standards/Tizen/Messaging/JSMessageFolder.cpp b/src/standards/Tizen/Messaging/JSMessageFolder.cpp
new file mode 100755 (executable)
index 0000000..e9a48bf
--- /dev/null
@@ -0,0 +1,307 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <API/Messaging/IMessageFolder.h>
+#include <API/Messaging/IMessagingTypes.h>
+
+
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "MessagingErrorMsg.h"
+#include "JSMessageFolder.h"
+
+using namespace std;
+using namespace DPL;
+using namespace TizenApis::Api::Messaging;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassDefinition JSMessageFolder::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "MessageFolder",
+       NULL,
+       m_properties,
+       NULL,
+       initialize,
+       finalize,
+       NULL, //hasProperty,
+       NULL, //getProperty,
+       NULL, //setProperty,
+       NULL, //deleteProperty,
+       NULL, //getPropertyNames,
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+const char* JSMessageFolder::FOLDERID = "id";
+const char* JSMessageFolder::PARENTID = "parentId";
+const char* JSMessageFolder::ACCOUNTID = "serviceId";
+const char* JSMessageFolder::CONTENTTYPE = "contentType";
+const char* JSMessageFolder::NAME = "name";
+const char* JSMessageFolder::PATH = "path";
+const char* JSMessageFolder::TYPE = "type";
+const char* JSMessageFolder::SYNCHRONIZABLE = "synchronizable";
+
+const std::string JSMessageFolder::TYPE_SMS             = "messaging.sms";
+const std::string JSMessageFolder::TYPE_MMS             = "messaging.mms";
+const std::string JSMessageFolder::TYPE_EMAIL   = "messaging.email";
+
+const std::string JSMessageFolder::FOLDER_INBOX                 = "INBOX";
+const std::string JSMessageFolder::FOLDER_OUTBOX        = "OUTBOX";
+const std::string JSMessageFolder::FOLDER_DRAFTBOX      = "DRAFTS";
+const std::string JSMessageFolder::FOLDER_SENTBOX       = "SENTBOX";
+const std::string JSMessageFolder::FOLDER_NOTSTANDARD   = "";
+
+
+
+JSStaticValue JSMessageFolder::m_properties[] = {
+       {"id", 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 },
+       {"type", JSMessageFolder::getProperty, NULL, kJSPropertyAttributeReadOnly },
+       {"synchronizable", JSMessageFolder::getProperty, JSMessageFolder::setProperty, kJSPropertyAttributeNone },
+       {0, 0, 0, 0}
+};
+
+const JSClassRef JSMessageFolder::getClassRef() {
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSMessageFolder::getClassInfo() {
+       return &m_classInfo;
+}
+
+JSClassRef JSMessageFolder::m_jsClassRef = JSClassCreate(JSMessageFolder::getClassInfo());
+
+void JSMessageFolder::initialize(JSContextRef context, JSObjectRef object) 
+{
+       LogDebug("JSMessageFolder::initialize ");
+       JSMessageFolderPriv* priv = static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(object));
+
+       if (priv == NULL)
+       {
+
+       }
+       else
+       {
+               LogDebug("JSMessageFolder::already exist ");            
+       }
+}
+
+
+
+JSObjectRef JSMessageFolder::createJSObject(JSContextRef context, IMessageFolderPtr object)
+{
+       JSMessageFolderPriv* priv = new JSMessageFolderPriv(context, object);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+
+void JSMessageFolder::finalize(JSObjectRef object) {
+       JSMessageFolderPriv* priv = static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(object));
+
+       LogDebug("JSMessageFolder::Finalrize");
+
+       if (priv != NULL) 
+       {
+               JSObjectSetPrivate(object, NULL);
+               delete priv;
+       }
+}
+
+bool JSMessageFolder::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) {
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSMessageFolder::getProperty(JSContextRef context,
+                                                                               JSObjectRef object,
+                                                                               JSStringRef propertyName,
+                                                                               JSValueRef* exception)
+{
+       LogDebug("<<<");        
+
+       WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+       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);
+               }
+               
+               IMessageFolderPtr MessageFolder(priv->getObject());
+               if(JSStringIsEqualToUTF8CString(propertyName, FOLDERID)) 
+               {
+                       return converter.toJSValueRef(MessageFolder->getId());
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, PARENTID)) 
+               {
+                       return converter.toJSValueRef(MessageFolder->getParentId());
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, ACCOUNTID)) 
+               {
+                       return converter.toJSValueRef(MessageFolder->getAccountId());                   
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, CONTENTTYPE)) 
+               {
+                       return converter.toJSValueRef(convertMessageType(MessageFolder->getContentType()));     
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, NAME)) 
+               {
+                       return converter.toJSValueRef(MessageFolder->getName());        
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, PATH)) 
+               {
+                       return converter.toJSValueRef(MessageFolder->getPath());        
+               }
+               else if(JSStringIsEqualToUTF8CString(propertyName, TYPE)) 
+               {
+                       return converter.toJSValueRef(convertFolderType(MessageFolder->getType()));     
+               }       
+               else if(JSStringIsEqualToUTF8CString(propertyName, SYNCHRONIZABLE)) 
+               {
+                       return converter.toJSValueRef(MessageFolder->getSynchronizable());                              
+               }
+
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) {
+               LogError("Exception: " << ex.GetMessage());
+       }       
+       return JSValueMakeNull(context);
+}
+
+
+bool JSMessageFolder::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+       WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+       
+    Try
+    {
+               JSMessageFolderPriv* priv = static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(object));      
+        if (!priv) {
+            Throw(WrtDeviceApis::Commons::NullPointerException);
+        }
+               Api::Messaging::IMessageFolderPtr MessageFolder(priv->getObject());
+
+        if (JSStringIsEqualToUTF8CString(propertyName, NAME)) {
+            std::string name = converter.toString(value);
+            MessageFolder->setName(name);
+            return true;
+        } else if (JSStringIsEqualToUTF8CString(propertyName, SYNCHRONIZABLE)) {
+            bool synchronizable = converter.toBool(value);
+            MessageFolder->setSynchronizable(synchronizable);
+            return true;
+    }
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogWarning("trying to set incorrect value");
+          return JSTizenExceptionFactory::postException(context, exception, 
+                        JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+    }
+
+    return false;
+}
+
+bool JSMessageFolder::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+IMessageFolderPtr JSMessageFolder::getMessageFolder(JSContextRef context, JSValueRef value)
+{
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) 
+       {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSMessageFolderPriv *priv = static_cast<JSMessageFolderPriv*>(JSObjectGetPrivate(object));
+       
+       if (!priv) 
+       {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+std::string JSMessageFolder::convertMessageType(int msgType){
+
+       if(msgType == Api::Messaging::SMS){
+               return JSMessageFolder::TYPE_SMS;               
+       }else if(msgType == Api::Messaging::MMS){
+               return JSMessageFolder::TYPE_MMS;
+       }else if(msgType == Api::Messaging::EMAIL){
+               return JSMessageFolder::TYPE_EMAIL;
+       }else{
+               return NULL;
+       }
+ }
+
+std::string JSMessageFolder::convertFolderType(int msgType){
+
+       if(msgType == Api::Messaging::INBOX){
+               return JSMessageFolder::FOLDER_INBOX;           
+       }else if(msgType == Api::Messaging::OUTBOX){
+               return JSMessageFolder::FOLDER_OUTBOX;
+       }else if(msgType == Api::Messaging::DRAFTBOX){
+               return JSMessageFolder::FOLDER_DRAFTBOX;
+       }else if(msgType == Api::Messaging::SENTBOX){
+               return JSMessageFolder::FOLDER_SENTBOX;
+       }else if(msgType == Api::Messaging::USERDEFINED_FOLDER){
+               return JSMessageFolder::FOLDER_NOTSTANDARD;
+       }else{
+               return NULL;
+       }
+ }
+
+
+} 
+}// WrtPlugins
+
+
diff --git a/src/standards/Tizen/Messaging/JSMessageFolder.h b/src/standards/Tizen/Messaging/JSMessageFolder.h
new file mode 100755 (executable)
index 0000000..6b0f60d
--- /dev/null
@@ -0,0 +1,125 @@
+//
+// 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_MESSAGEFOLDER_H_
+#define WRTPLUGINS_TIZEN_JS_MESSAGEFOLDER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Messaging/IMessageFolder.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Messaging::IMessageFolderPtr>::Type JSMessageFolderPriv;
+
+class JSMessageFolder {
+public:
+//@struct JSClassDefinition
+//     @abstract This structure contains properties and callbacks that define a type of object. All fields other than the version field are optional. Any pointer may be NULL.
+       static const JSClassDefinition* getClassInfo();
+       static const JSClassRef getClassRef();
+       static JSObjectRef createJSObject(JSContextRef context, Api::Messaging::IMessageFolderPtr object);
+       static Api::Messaging::IMessageFolderPtr getMessageFolder(JSContextRef context, JSValueRef value);
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+       static std::string convertMessageType(int msgType);
+       static std::string convertFolderType(int msgType);
+
+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);
+
+       static bool setProperty(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       /**
+        * 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 JSStaticValue m_properties[];
+       static JSClassRef m_jsClassRef;
+
+
+       
+       static const char* FOLDERID;
+       static const char* PARENTID;
+       static const char* ACCOUNTID;
+       static const char* CONTENTTYPE;
+       static const char* NAME;
+       static const char* PATH;
+       static const char* TYPE;
+       static const char* SYNCHRONIZABLE;
+
+       static const std::string TYPE_SMS;
+       static const std::string TYPE_MMS;
+       static const std::string TYPE_EMAIL;
+
+       static const std::string FOLDER_INBOX;
+       static const std::string FOLDER_OUTBOX;
+       static const std::string FOLDER_DRAFTBOX;
+       static const std::string FOLDER_SENTBOX;
+       static const std::string FOLDER_NOTSTANDARD;    
+
+
+};
+
+} 
+} //WrtPlugins
+
+#endif //WRTPLUGINS_TIZEN_JS_MESSAGING_SERVICE_MANAGER_H_
+
+
diff --git a/src/standards/Tizen/Messaging/JSMessagePrivateObject.h b/src/standards/Tizen/Messaging/JSMessagePrivateObject.h
new file mode 100755 (executable)
index 0000000..72b3c6d
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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 JSMESSAGEPRIVATEOBJECT_H_
+#define JSMESSAGEPRIVATEOBJECT_H_
+
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Messaging/IMessage.h>
+#include <API/Messaging/EventUpdateMessage.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+/*
+ *
+ */
+class JSMessagePrivateObject : public WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Messaging::IMessagePtr>
+        ::Type
+{
+  public:
+    JSMessagePrivateObject(JSContextRef context,
+            const Api::Messaging::IMessagePtr& object) :
+        WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Messaging::IMessagePtr>::Type(context, object),
+        m_UpdateMessageReceiver(NULL)
+    {
+    }
+
+    void setUpdateMsgReceiver(Api::Messaging::EventUpdateMessageAnswerReceiver* receiver)
+    {
+        m_UpdateMessageReceiver = receiver;
+    }
+
+    Api::Messaging::EventUpdateMessageAnswerReceiver* getUpdateMsgReceiver() const
+    {
+        return m_UpdateMessageReceiver;
+    }
+
+  private:
+    Api::Messaging::EventUpdateMessageAnswerReceiver* m_UpdateMessageReceiver;  // not owned
+};
+}
+}
+
+#endif /* JSMESSAGEPRIVATEOBJECT_H_ */
diff --git a/src/standards/Tizen/Messaging/JSMessagingService.cpp b/src/standards/Tizen/Messaging/JSMessagingService.cpp
new file mode 100644 (file)
index 0000000..eb834c1
--- /dev/null
@@ -0,0 +1,1293 @@
+//
+// 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 "JSMessagingService.h"
+#include "MessagingController.h"
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>                                   
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <CommonsJavaScript/JSPendingOperation.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <Commons/StringUtils.h>
+
+#include <API/Messaging/ReqReceiverMessage.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "MessagingErrorMsg.h"
+#include "ConverterMessage.h"
+#include "MessagingListener.h"
+#include "JSMessagingStorage.h"
+#include "JSMessage.h"
+#include "EventSendMessagePrivateData.h"       //for send message
+#include "EventMessagingServicePrivateData.h"
+#include "MessageAsyncCallbackManager.h"
+#include "plugin_config.h"
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Messaging;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+       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 Api::Messaging::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;
+                               
+                               Api::Messaging::MessageType msgType = (Api::Messaging::MessageType)imessagingService->getType();
+                               LogInfo("msgType :" << msgType);
+       
+                               if (msgType == Api::Messaging::EMAIL)
+                               {
+                                       Api::Messaging::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 Api::Messaging::MMS:
+                                               {
+                                                   Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
+                                                   mms->setSubject(subject);
+                                                   break;
+                                               }
+                                               case Api::Messaging::EMAIL:
+                                               {
+                                                   Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                                                   email->setSubject(subject);
+                                                   break;
+                                               }
+                                                 default:
+                                                 {
+                                                   LogError("message not supported");
+                                                   //Throw(WrtDeviceApis::Commons::UnsupportedException);
+                                                   //break;
+                                                 }
+                                               }
+                                        }
+                                       //to
+                                       if (!JSValueIsUndefined(l_globalContext, toData) )
+                                       {
+                                               Api::Messaging::Recipients to = converter->toRecipients(toData);
+                                               LogDebug("setting to field, size=" << to.getRecipientSize());
+                                               msg->setToRecipients(to);
+                                       }
+                                       //cc
+                                       if (msgType == Api::Messaging::EMAIL )
+                                       {
+                                               Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                                               if (!JSValueIsUndefined(l_globalContext, ccData))
+                                               {
+                                                       Api::Messaging::Recipients cc = converter->toRecipients(ccData);
+                                               email->setCcRecipients(cc);
+                                               }
+
+                                               if (!JSValueIsUndefined(l_globalContext, bccData))
+                                               {
+                                                       Api::Messaging::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);
+               }
+
+       }
+
+JSValueRef JSMessagingService::sendMessage(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_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);         
+    }
+
+    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
+        EventMessagingServicePrivateDataPtr privateData( new EventMessagingServicePrivateData(callbackManager, recipientCallbackManager) );
+
+        //Api::Messaging::EventSendMessagePtr event(new Api::Messaging::EventSendMessage());
+         Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::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->m_messagingService = imessagingService;
+        event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
+        event->setForAsynchronousCall(&MessagingController::getInstance());
+     
+        Api::Messaging::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);
+    }
+    Catch(WrtDeviceApis::Commons::ConversionException) {
+               return JSTizenExceptionFactory::postException(context, exception, 
+                       JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);        
+    }
+    Catch(WrtDeviceApis::Commons::NullPointerException) {
+               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);        
+    }
+
+//    return JSValueMakeNull(context);
+}
+
+JSValueRef JSMessagingService::loadMessageBody(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_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);
+    }
+
+    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) );
+                       Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::EventMessagingService());     
+                       event->m_message = msg;
+
+                       if ( event->m_message )
+                       {       
+                               int msgType = event->m_message->getMessageType();
+                               
+                               if (msgType == Api::Messaging::EMAIL)
+                               {
+                                       Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(event->m_message);
+                                       if (email && email->isBodyDownloaded() > 0)
+                                       {
+                                               callbackManager->callOnSuccess(converter->toJSValueRef(msg));
+                                               return JSValueMakeNull(context);
+                                       }
+                               }
+                               else
+                               {
+                                       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
+                                                       JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT));
+                                       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);
+                       event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY);
+                       event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
+                       event->setForAsynchronousCall(&MessagingController::getInstance());
+
+                       Api::Messaging::ReqReceiverMessageSingleton::Instance().loadMessageBody(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);
+                       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);
+
+}
+
+JSValueRef JSMessagingService::loadMessageAttachment(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_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 {
+               Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::EventMessagingService());     //create event
+               event->setEventType(MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT);
+               event->setPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privateData));
+               event->setForAsynchronousCall(&MessagingController::getInstance());
+
+                       Api::Messaging::IAttachmentPtr iAttchmentPtr = converter->toIAttachment(arguments[0]);
+                               
+                       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);
+                               
+                               //JSValueRef pendingOperation = WrtDeviceApis::CommonsJavaScript::makePendingOperation(globalContext, event);   //create pendingOperation.
+                               Api::Messaging::ReqReceiverMessageSingleton::Instance().loadMessageAttachment(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);
+                               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);
+}
+
+JSValueRef JSMessagingService::sync(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_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.
+
+               Api::Messaging::MessageType msgType = (Api::Messaging::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) );
+                       Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::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());
+
+                               Api::Messaging::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);
+
+}
+
+
+JSValueRef JSMessagingService::syncFolder(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_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.
+
+               Api::Messaging::MessageType msgType = (Api::Messaging::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]);
+                               }
+                       }
+                       
+                       Api::Messaging::EventMessagingServicePtr event(new Api::Messaging::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());
+
+                               Api::Messaging::ReqReceiverMessageSingleton::Instance().syncFolder(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::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);
+
+
+}
+
+JSValueRef JSMessagingService::cancelOperation(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
+                       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);
+                               Api::Messaging::MessageType msgType = (Api::Messaging::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 == Api::Messaging::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 == Api::Messaging::EMAIL)
+                                       {       
+                                               IMessagePtr msg = imessagingService->getMessageFromOpId(opId);
+                                               Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
+                                                       
+                                               if ( opType == Api::Messaging::MESSAGING_SERVICE_OP_DOWNLOAD_BODY )
+                                               {       
+                                                       LogDebug("Cancel Download Body , handle = " << handle);
+                                                       email->downloadBodyCancel(handle);
+                                               }
+                                               else if ( opType == Api::Messaging::MESSAGING_SERVICE_OP_DOWNLOAD_ATTACHMENT)
+                                               {
+                                                       LogDebug("Cancel Download Attachment , handle = " << handle);
+                                                       email->downloadAttachmentCancel(handle);
+                                               }
+                                               else if (  opType == Api::Messaging::MESSAGING_SERVICE_OP_SYNC )
+                                               {       
+                                                       LogDebug("Cancel Sync , handle = " << handle);
+                                                       imessagingService->syncCancel(handle);
+                                               }
+                                               else if ( opType == Api::Messaging::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);
+}
+
+JSValueRef JSMessagingService::stopSync(JSContextRef context, JSObjectRef function, JSObjectRef thisObject,
+                       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);
+                       Api::Messaging::MessageType msgType = (Api::Messaging::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 == Api::Messaging::EMAIL)
+                       {                       
+                               if (  opType == Api::Messaging::MESSAGING_SERVICE_OP_SYNC )
+                               {       
+                                       LogDebug("Cancel Sync , handle = " << handle);
+                                       imessagingService->syncCancel(handle);
+                               }
+                               else if ( opType == Api::Messaging::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);
+}
+
+
+}
+}
+
diff --git a/src/standards/Tizen/Messaging/JSMessagingService.h b/src/standards/Tizen/Messaging/JSMessagingService.h
new file mode 100755 (executable)
index 0000000..2d11897
--- /dev/null
@@ -0,0 +1,113 @@
+//
+// 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 WRT_PLUGINS_TIZEN_JS_MESSAGING_SERVICE_H_
+#define WRT_PLUGINS_TIZEN_JS_MESSAGING_SERVICE_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Messaging/IMessagingService.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Messaging::IMessagingServicePtr>::Type JSMessagingServicePriv;
+
+class JSMessagingService {
+
+public :       
+       static const JSClassDefinition* getClassInfo();
+       static const JSClassRef getClassRef();
+       
+       static JSObjectRef createJSObject(JSContextRef context, const Api::Messaging::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,
+            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;
+               
+}; //JSMessagingService
+
+}
+} //WrtPlugins
+
+
+#endif //WRT_PLUGINS_TIZEN_JS_MESSAGING_SERVICE_H_
diff --git a/src/standards/Tizen/Messaging/JSMessagingServiceManager.cpp b/src/standards/Tizen/Messaging/JSMessagingServiceManager.cpp
new file mode 100644 (file)
index 0000000..a9a7e76
--- /dev/null
@@ -0,0 +1,260 @@
+//
+// 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 <API/Messaging/MessagingFactory.h>
+#include <API/Messaging/IMessagingServiceManager.h>
+#include <Commons/FunctionDeclaration.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>                                   
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "JSMessagingServiceManager.h"
+#include "MessagingController.h"
+#include "MessagingListener.h"
+#include "ConverterMessage.h"
+#include "plugin_config.h"
+#include "MessageAsyncCallbackManager.h"
+#include "MessagingErrorMsg.h"
+
+using namespace std;
+using namespace DPL;
+using namespace TizenApis::Api::Messaging;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+       
+       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) 
+{
+               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);
+}
+
+
+}
+}
+
diff --git a/src/standards/Tizen/Messaging/JSMessagingServiceManager.h b/src/standards/Tizen/Messaging/JSMessagingServiceManager.h
new file mode 100755 (executable)
index 0000000..31d2904
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// 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_MESSAGING_SERVICE_MANAGER_H_
+#define WRTPLUGINS_TIZEN_JS_MESSAGING_SERVICE_MANAGER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Messaging/IMessagingServiceManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Messaging::IMessagingServiceManagerPtr>::Type JSMessagingServiceManagerPriv;
+
+class JSMessagingServiceManager {
+public:
+//@struct JSClassDefinition
+//     @abstract This structure contains properties and callbacks that define a type of object. All fields other than the version field are optional. Any pointer may be NULL.
+       static const JSClassDefinition* getClassInfo();
+       static const JSClassRef getClassRef();
+
+private:
+       /**
+        * The callback invoked when an object is first created.
+        */
+       static void initialize(JSContextRef context, JSObjectRef object);
+
+       /**
+        * The callback invoked when an object is finalized.
+        */
+       static void finalize(JSObjectRef object);
+
+       /**
+        * 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);
+
+       static JSValueRef getMessagingServices(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);
+
+       static JSValueRef getMessagingService(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 function property.
+        */
+       static JSStaticFunction m_function[];
+       static JSStaticValue m_property[];
+       static JSClassRef m_jsClassRef;
+
+private:
+       enum{
+               GET_MESSAGING_SERVICE_ALL = 1,
+               GET_MESSAGING_SERVICE_ACOUNT = 2
+       };
+
+};
+
+} 
+} //WrtPlugins
+
+#endif //WRTPLUGINS_TIZEN_JS_MESSAGING_SERVICE_MANAGER_H_
+
diff --git a/src/standards/Tizen/Messaging/JSMessagingStorage.cpp b/src/standards/Tizen/Messaging/JSMessagingStorage.cpp
new file mode 100755 (executable)
index 0000000..454c880
--- /dev/null
@@ -0,0 +1,1833 @@
+//
+// 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 "JSMessagingStorage.h"
+#include "JSMessagingService.h"
+#include "MessagingListener.h"
+#include "ConverterMessage.h"
+#include "MessagingStorageMultiCallback.h"
+#include "MessageListenerManager.h"
+#include <API/Messaging/ReqReceiverMessage.h>
+#include <API/Filter/SortMode.h>
+
+#include <Tizen/Tizen/FilterConverter.h>
+
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>                                   
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>           
+#include <CommonsJavaScript/SecurityExceptions.h>
+
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "MessagingErrorMsg.h"
+#include "MessageAsyncCallbackManager.h"
+#include "plugin_config.h"
+
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Tizen1_0::Tizen;
+using namespace TizenApis::Commons;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+       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(Api::Messaging::INBOX);
+                       }
+                       else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_OUTBOX")) 
+                       {
+                               LogDebug("FOLDER_OUTBOX" << ":" << "2");
+                               retVal = convert.toJSValueRef(Api::Messaging::OUTBOX);
+                       }
+                       else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_DRAFTS")) 
+                       {
+                               LogDebug("FOLDER_DRAFTS" << ":" << "3");
+                               retVal = convert.toJSValueRef(Api::Messaging::DRAFTBOX);
+                       }
+                       else if (JSStringIsEqualToUTF8CString(propertyName, "FOLDER_SENTBOX")) 
+                       {
+                               LogDebug("FOLDER_SENTBOX" << ":" << "4");
+                               retVal = convert.toJSValueRef(Api::Messaging::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
+               {
+                       Api::Messaging::EventAddDraftMessagePtr event(new Api::Messaging::EventAddDraftMessage());
+
+                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+
+                       if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+                       {
+                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+                       }
+                       else
+                       {
+                               if(objectPriv->getType() == Api::Messaging::EMAIL)
+                               {
+                                       if(objectPriv->getIndex()  < 1)
+                                       {
+                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+                                       }
+                               }
+                       }
+
+                       if(argumentCount < 1)
+                       {
+                               LogDebug("argumentCount is too few");
+                               Throw(InvalidArgumentException);
+                       }
+                       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());
+
+                       Api::Messaging::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
+               {
+                       Api::Messaging::EventQueryMessagesPtr event(new Api::Messaging::EventQueryMessages());
+                       
+                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+
+                       if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+                       {
+                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+                       }
+                       else
+                       {
+                               if(objectPriv->getType() == Api::Messaging::EMAIL)
+                               {
+                                       if(objectPriv->getIndex()  < 1)
+                                       {
+                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+                                       }
+                               }
+                       }
+
+                       if(argumentCount < 2)
+                       {
+                               LogDebug("argumentCount is too few");
+                               Throw(InvalidArgumentException);
+                       }
+                       if(argumentCount >= 1)  //optional AbstractFilter? filter
+                       {
+                               if(JSValueIsObject(context, arguments[0]))
+                               {
+                                       Api::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]))
+                               {
+                                       Api::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());
+
+                       Api::Messaging::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 
+               {
+
+                       Api::Messaging::EventDeleteMessagesPtr event(new Api::Messaging::EventDeleteMessages());
+                       
+                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+
+                       JSObjectRef objArg = NULL;
+
+                       if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+                       {
+                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+                       }
+                       else
+                       {
+                               if(objectPriv->getType() == Api::Messaging::EMAIL)
+                               {
+                                       if(objectPriv->getIndex()  < 1)
+                                       {
+                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+                                       }
+                               }
+                       }
+
+                       if(argumentCount < 1)
+                       {
+                               LogDebug("argumentCount is too few");
+                               Throw(InvalidArgumentException);
+                       }
+                       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<Api::Messaging::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);
+                               Api::Messaging::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());
+
+                       Api::Messaging::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 
+               {
+
+                       Api::Messaging::EventUpdateMessagesPtr event(new Api::Messaging::EventUpdateMessages());
+
+                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+
+                       JSObjectRef objArg = NULL;
+
+                       if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+                       {
+                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+                       }
+                       else
+                       {
+                               if(objectPriv->getType() == Api::Messaging::EMAIL)
+                               {
+                                       if(objectPriv->getIndex()  < 1)
+                                       {
+                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+                                       }
+                               }
+                       }
+
+                       if(argumentCount < 1)
+                       {
+                               LogDebug("argumentCount is too few");
+                               Throw(InvalidArgumentException);
+                       }
+                       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<Api::Messaging::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);
+                               Api::Messaging::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());
+
+                       Api::Messaging::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 
+               {
+                       Api::Messaging::EventQueryConversationsPtr event(new Api::Messaging::EventQueryConversations());
+                       
+                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+
+                       if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+                       {
+                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+                       }
+                       else
+                       {
+                               if(objectPriv->getType() == Api::Messaging::EMAIL)
+                               {
+                                       if(objectPriv->getIndex()  < 1)
+                                       {
+                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+                                       }
+                               }
+                       }
+
+                       if(argumentCount < 2)
+                       {
+                               LogDebug("argumentCount is too few");
+                               Throw(InvalidArgumentException);
+                       }
+                       if(argumentCount >= 1)  //optional AbstractFilter? filter
+                       {
+                               if(JSValueIsObject(context, arguments[0]))
+                               {
+                                       Api::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]))
+                               {
+                                       Api::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());
+
+                       Api::Messaging::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 
+               {
+
+                       Api::Messaging::EventDeleteConversationsPtr event(new Api::Messaging::EventDeleteConversations());
+                       
+                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+
+                       std::vector<Api::Messaging::IConversationPtr> deleteConversationArray;
+
+                       if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+                       {
+                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+                       }
+                       else
+                       {
+                               if(objectPriv->getType() == Api::Messaging::EMAIL)
+                               {
+                                       if(objectPriv->getIndex()  < 1)
+                                       {
+                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+                                       }
+                               }
+                       }
+
+                       if(argumentCount < 1)
+                       {
+                               LogDebug("argumentCount is too few");
+                               Throw(InvalidArgumentException);
+                       }
+                       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());
+
+                       Api::Messaging::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
+               {
+                       Api::Messaging::EventQueryFoldersPtr event(new Api::Messaging::EventQueryFolders());
+                       
+                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+                       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+
+                       if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+                       {
+                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+                       }
+                       else
+                       {
+                               if(objectPriv->getType() == Api::Messaging::EMAIL)
+                               {
+                                       if(objectPriv->getIndex()  < 1)
+                                       {
+                                               ThrowMsg(InvalidArgumentException, "serviceId is not defined.");
+                                       }
+                               }
+                       }
+       
+                       if(argumentCount < 2)
+                       {
+                               LogDebug("argumentCount is too few");
+                               Throw(InvalidArgumentException);
+                       }
+                       if(argumentCount >= 1)  //optional AbstractFilter? filter
+                       {
+                               if(JSValueIsObject(context, arguments[0]))
+                               {
+                                       Api::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());
+
+                       Api::Messaging::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
+               {
+                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+                       JSValueRef onSuccessForCbm = NULL;
+
+                       OnMessagesChanged functionResult;
+                       int funtionIndex = -1;
+                       
+                       if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+                       {
+                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+                       }
+                       else
+                       {
+                               if(objectPriv->getType() == Api::Messaging::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]))
+                               {
+                                       Api::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
+               {
+                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+                       JSValueRef onSuccessForCbm = NULL;
+
+                       OnMessagesChanged functionResult;
+                       int funtionIndex = -1;
+                       
+                       if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+                       {
+                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+                       }
+                       else
+                       {
+                               if(objectPriv->getType() == Api::Messaging::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]))
+                               {
+                                       Api::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
+               {
+
+                       FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context);
+
+                       JSValueRef onSuccessForCbm = NULL;
+
+                       OnMessagesChanged functionResult;
+                       int funtionIndex = -1;
+                       
+                       if((objectPriv->getType() < Api::Messaging::SMS) || (objectPriv->getType() > Api::Messaging::EMAIL))
+                       {
+                               ThrowMsg(InvalidArgumentException, "Message type is not SMS or MMS or EMAIL.");
+                       }
+                       else
+                       {
+                               if(objectPriv->getType() == Api::Messaging::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]))
+                               {
+                                       Api::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(InvalidArgumentException);
+                       }
+                       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);
+       }
+
+}
+}
diff --git a/src/standards/Tizen/Messaging/JSMessagingStorage.h b/src/standards/Tizen/Messaging/JSMessagingStorage.h
new file mode 100755 (executable)
index 0000000..c2f1a4c
--- /dev/null
@@ -0,0 +1,144 @@
+//
+// 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_MESSAGING_STORAGE_H_
+#define WRTPLUGINS_TIZEN_JS_MESSAGING_STORAGE_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include "MessagingListener.h"
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+class MessagingStoragePrivObj
+{
+public:
+       long m_index;
+       int m_type;
+//     MessagingListener instance;
+
+long getIndex() const
+{
+       return m_index;
+}
+
+int getType() const
+{
+       return m_type;
+}
+       
+};
+
+typedef DPL::SharedPtr<MessagingStoragePrivObj> MessagingStoragePrivObjPtr;
+       
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<MessagingStoragePrivObjPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> MessagingStoragePriv;
+
+class JSMessagingStorage {
+public:
+//@struct JSClassDefinition
+//     @abstract This structure contains properties and callbacks that define a type of object. All fields other than the version field are optional. Any pointer may be NULL.
+       static const JSClassDefinition* getClassInfo();
+       static const JSClassRef getClassRef();
+
+private:
+       /**
+        * The callback invoked when an object is first created.
+        */
+       static void initialize(JSContextRef context, JSObjectRef object);
+
+       /**
+        * The callback invoked when an object is finalized.
+        */
+       static void finalize(JSObjectRef object);
+
+       /**
+        * 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);
+
+       static JSValueRef addDraftMessage(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);
+
+       static JSValueRef findMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);
+
+       static JSValueRef findConversations(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);
+
+       static JSValueRef removeConversations(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);
+
+       static JSValueRef findFolders(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);
+
+       static JSValueRef removeMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);
+
+       static JSValueRef updateMessages(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);
+
+       static JSValueRef addMessagesChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);   
+
+       static JSValueRef addConversationsChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);   
+
+       static JSValueRef addFoldersChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);   
+
+       static JSValueRef removeChangeListener(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 function property.
+        */
+       static JSStaticFunction m_function[];
+       static JSStaticValue m_property[];
+       static JSClassRef m_jsClassRef;
+
+};
+
+}
+} //WrtPlugins
+
+#endif //WRTPLUGINS_TIZEN_JS_MESSAGING_SERVICE_MANAGER_H_
+
diff --git a/src/standards/Tizen/Messaging/JSRecipientArray.cpp b/src/standards/Tizen/Messaging/JSRecipientArray.cpp
new file mode 100755 (executable)
index 0000000..8c0abef
--- /dev/null
@@ -0,0 +1,384 @@
+//
+// 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 "JSRecipientArray.h"
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.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 TizenApis {
+namespace Tizen1_0 {
+JSClassRef JSRecipientArray::m_jsClassRef = NULL;
+
+JSClassDefinition JSRecipientArray::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    ARRAY,
+    0,
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    hasProperty,
+    getProperty,
+    setProperty,
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL, //callAsFunction,
+    NULL, //callAsConstructor,
+    NULL, //hasInstance,
+    NULL, //convertToType,
+};
+
+JSStaticValue JSRecipientArray::m_property[] = {
+    { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSRecipientArray::m_function[] = {
+    { FUNCTION_CONCAT, concat, kJSPropertyAttributeNone },
+    { FUNCTION_JOIN, join, kJSPropertyAttributeNone },
+    { FUNCTION_POP, pop, kJSPropertyAttributeNone },
+    { FUNCTION_PUSH, push, kJSPropertyAttributeNone },
+    { FUNCTION_REVERSE, reverse, kJSPropertyAttributeNone },
+    { FUNCTION_SHIFT, shift, kJSPropertyAttributeNone },
+    { FUNCTION_SLICE, slice, kJSPropertyAttributeNone },
+    { FUNCTION_SORT, sort, kJSPropertyAttributeNone },
+    { FUNCTION_SPLICE, splice, kJSPropertyAttributeNone },
+    { FUNCTION_TOSTRING, toString, kJSPropertyAttributeNone },
+    { FUNCTION_UNSHIFT, unshift, kJSPropertyAttributeNone },
+    { FUNCTION_VALUEOF, valueOf, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+JSValueRef JSRecipientArray::getLength(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("enter");
+    Try
+    {
+        JSRecipientArrayPrivate* priv =
+            static_cast<JSRecipientArrayPrivate*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            Throw(WrtDeviceApis::Commons::NullPointerException);
+        }
+        Api::Messaging::RecipientsPtr recipients = priv->getObject();
+        WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+        return converter.toJSValueRef(recipients->getRecipientSize());
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("invalid conversion");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+Api::Messaging::RecipientsPtr JSRecipientArray::getRecipients(JSContextRef context,
+        JSObjectRef object)
+{
+    JSRecipientArrayPrivate* priv =
+        static_cast<JSRecipientArrayPrivate*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        ThrowMsg(WrtDeviceApis::Commons::NullPointerException,
+                 "Array contains no private object");
+    }
+    return priv->getObject();
+}
+
+JSObjectRef JSRecipientArray::createArray(JSContextRef context,
+        const Api::Messaging::RecipientsPtr &recipients)
+{
+    
+    JSRecipientArrayPrivate *priv = new JSRecipientArrayPrivate(context, recipients);
+    return JSObjectMake(context, getClassRef(), priv);
+    
+}
+
+const JSClassDefinition* JSRecipientArray::getClassInfo()
+{
+    return &(m_classInfo);
+}
+
+JSClassRef JSRecipientArray::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+void JSRecipientArray::initialize(JSContextRef context,
+        JSObjectRef object)
+{
+    LogDebug("enter");
+}
+
+void JSRecipientArray::finalize(JSObjectRef object)
+{
+    LogDebug("enter");
+    JSRecipientArrayPrivate* priv =
+        static_cast<JSRecipientArrayPrivate*>(JSObjectGetPrivate(object));
+    delete priv;
+    JSObjectSetPrivate(object, NULL);
+}
+
+bool JSRecipientArray::checkValue(const std::string &value)
+{
+    return true;
+}
+
+bool JSRecipientArray::hasProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName)
+{
+    LogDebug("enter");
+    WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+    Try
+    {
+        size_t index = converter.toSizeT(propertyName);
+        JSRecipientArrayPrivate* priv =
+            static_cast<JSRecipientArrayPrivate*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            Throw(WrtDeviceApis::Commons::NullPointerException);
+        }
+        Api::Messaging::RecipientsPtr recipients = priv->getObject();
+        if (index < recipients->getRecipientSize()) {
+            return true;
+        }
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        //not reporting error is intended
+    }
+    return false;
+}
+
+JSValueRef JSRecipientArray::getProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef* exception)
+{
+    LogDebug("enter");
+    WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+    Try
+    {
+        size_t index = converter.toSizeT(propertyName);
+        JSRecipientArrayPrivate* priv =
+            static_cast<JSRecipientArrayPrivate*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            Throw(WrtDeviceApis::Commons::NullPointerException);
+        }
+        Api::Messaging::RecipientsPtr recipients = priv->getObject();
+        if (index < recipients->getRecipientSize()) {
+            std::string result = recipients->getRecipient(index);
+            if (!result.empty()) {
+                return converter.toJSValueRef(result);
+            }
+        }
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("invalid property");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+bool JSRecipientArray::setProperty(JSContextRef context,
+        JSObjectRef object,
+        JSStringRef propertyName,
+        JSValueRef value,
+        JSValueRef* exception)
+{
+    LogDebug("enter");
+    WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+    Try
+    {
+        size_t index = converter.toSizeT(propertyName);
+        std::string address;
+        if (!JSValueIsUndefined(context, value)) {
+            address = converter.toString(value);
+        }
+        if (!checkValue(address)) {
+            LogError("trying to assing invalid value");
+            Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+        }
+        JSRecipientArrayPrivate* priv =
+            static_cast<JSRecipientArrayPrivate*>(JSObjectGetPrivate(object));
+        if (!priv) {
+            Throw(WrtDeviceApis::Commons::NullPointerException);
+        }
+        Api::Messaging::RecipientsPtr recipients = priv->getObject();
+        recipients->setRecipientWithExpand(index, address);
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("error occured");
+    }
+    return false;
+}
+
+JSValueRef JSRecipientArray::concat(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSRecipientArray::join(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSRecipientArray::pop(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSRecipientArray::push(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSRecipientArray::reverse(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSRecipientArray::shift(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSRecipientArray::slice(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSRecipientArray::sort(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSRecipientArray::splice(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSRecipientArray::toString(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSRecipientArray::unshift(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSRecipientArray::valueOf(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Messaging/JSRecipientArray.h b/src/standards/Tizen/Messaging/JSRecipientArray.h
new file mode 100755 (executable)
index 0000000..f8a7983
--- /dev/null
@@ -0,0 +1,172 @@
+//
+// 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 _JS_RECIPIENT_ARRAY_H_
+#define _JS_RECIPIENT_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <API/Messaging/Recipient.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Messaging::RecipientsPtr>::Type
+JSRecipientArrayPrivate;
+
+class JSRecipientArray
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static JSClassRef getClassRef();
+
+    static JSObjectRef createArray(JSContextRef context,
+            const Api::Messaging::RecipientsPtr &recipients);
+
+    static Api::Messaging::RecipientsPtr getRecipients(JSContextRef context,
+            JSObjectRef object);
+
+  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 JSValueRef concat(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef join(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef pop(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef push(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef reverse(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef shift(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef slice(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef sort(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef splice(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef toString(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef unshift(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+    static JSValueRef valueOf(JSContextRef context,
+            JSObjectRef object,
+            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 /* _JS_ARRAY_H_ */
\ No newline at end of file
diff --git a/src/standards/Tizen/Messaging/MessageAsyncCallbackManager.cpp b/src/standards/Tizen/Messaging/MessageAsyncCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..164a0f1
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// 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 "MessageAsyncCallbackManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::MessageAsyncCallbackManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Messaging/MessageAsyncCallbackManager.h b/src/standards/Tizen/Messaging/MessageAsyncCallbackManager.h
new file mode 100755 (executable)
index 0000000..dd7b278
--- /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_MESSAGING_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_MESSAGING_ASYNC_CALLBACK_MANAGER_H_
+
+#include <dpl/singleton.h>
+#include <Tizen/Common/AsyncCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+class MessageAsyncCallbackManager : public TizenApis::Commons::AsyncCallbackManager
+{
+public:
+       MessageAsyncCallbackManager()
+       {
+       }
+
+       virtual ~MessageAsyncCallbackManager()
+       {
+       }
+
+       friend class DPL::Singleton<MessageAsyncCallbackManager>;
+};
+
+typedef DPL::Singleton<MessageAsyncCallbackManager> MessageAsyncCallbackManagerSingleton;
+
+
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_MESSAGING_ASYNC_CALLBACK_MANAGER_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/Messaging/MessageListenerManager.cpp b/src/standards/Tizen/Messaging/MessageListenerManager.cpp
new file mode 100755 (executable)
index 0000000..1ce75db
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// 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 "MessageListenerManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::MessageListenerManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Messaging/MessageListenerManager.h b/src/standards/Tizen/Messaging/MessageListenerManager.h
new file mode 100755 (executable)
index 0000000..68124d1
--- /dev/null
@@ -0,0 +1,95 @@
+//
+// 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_MESSAGING_LISTENER_MANAGER_H_
+#define _TIZEN_MESSAGING_LISTENER_MANAGER_H_
+
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Tizen/Common/IListenerManager.h>
+#include "JSMessagingStorage.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace TizenApis::Api::Messaging;
+
+class MessageListenerManager : public TizenApis::Commons::IListenerController
+{
+public:
+       MessageListenerManager()
+       {
+       }
+
+       virtual ~MessageListenerManager()
+       {
+       }
+};
+typedef DPL::Singleton<MessageListenerManager> MessageListenerManagerSingleton;
+
+class MessageListenerCanceller : public TizenApis::Commons::IListenerItem
+{
+public:
+       MessageListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
+               TizenApis::Commons::IListenerItem(context, object, watchId)
+       {
+       }
+
+       virtual ~MessageListenerCanceller()
+       {
+       }
+
+       virtual void cancelListener()
+       {
+               MessagingStoragePriv* priv = static_cast<MessagingStoragePriv*>(JSObjectGetPrivate(m_object));
+
+//             long handler = -1;
+               
+               if (!priv)
+               {
+                       LogDebug("priv is NULL.");
+                       return;
+               }
+
+               MessagingStoragePrivObjPtr objectPriv = priv->getObject();
+
+               if (!objectPriv)
+               {
+                       LogDebug("objectPriv is NULL.");                
+                       return;
+               }
+
+               Try 
+               {
+                       LogDebug("objectPriv type : " << objectPriv->getType() << " Id : " << objectPriv->getIndex());
+                       MessagingListener::getInstance().removeIncomingMsgCallback(m_watchId, objectPriv->getType(), objectPriv->getIndex());
+               }Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+                       LogError("Try to deregister by unmatched service");
+                       return;
+               }
+       }
+
+};
+typedef DPL::SharedPtr<MessageListenerCanceller> MessageListenerCancellerPtr;
+
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_MESSAGING_LISTENER_MANAGER_H_
diff --git a/src/standards/Tizen/Messaging/MessageSendCallback.h b/src/standards/Tizen/Messaging/MessageSendCallback.h
new file mode 100755 (executable)
index 0000000..3263a57
--- /dev/null
@@ -0,0 +1,41 @@
+//
+// 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_MESSAGING_MESSAGESENDCALLBACK_H_
+#define TIZEN_MESSAGING_MESSAGESENDCALLBACK_H_
+
+#include <JavaScriptCore/JavaScript.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+struct MessageSendCallback
+{
+    JSValueRef onSuccess;
+    JSValueRef onMessageSendSuccess;
+    JSValueRef onMessageSendError;
+
+    MessageSendCallback() :
+        onSuccess(NULL),
+        onMessageSendSuccess(NULL),
+        onMessageSendError(NULL)
+    {
+    }
+};
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Messaging/MessagingController.cpp b/src/standards/Tizen/Messaging/MessagingController.cpp
new file mode 100644 (file)
index 0000000..d5a5dc1
--- /dev/null
@@ -0,0 +1,368 @@
+//
+// 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/Exception.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "MessagingErrorMsg.h"
+#include "MessagingController.h"
+#include "JSMessagingService.h"
+#include "ConverterMessage.h"
+#include "EventSendMessagePrivateData.h"
+#include "EventMessagingServicePrivateData.h"
+#include <API/Messaging/EventMessagingService.h>
+#include "JSMessage.h"
+#include "JSMessageAttachment.h"
+#include "MessageAsyncCallbackManager.h"
+
+#include <dpl/singleton_safe_impl.h>
+
+IMPLEMENT_SAFE_SINGLETON(TizenApis::Tizen1_0::MessagingController)
+
+using namespace std;
+using namespace TizenApis::Api::Messaging;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+MessagingController::MessagingController() :
+       SendMessageAnswerReceiver(ThreadEnum::NULL_THREAD),
+       GetMessagingServiceReceiver (ThreadEnum::NULL_THREAD), 
+       MessagingServiceReceiver (ThreadEnum::NULL_THREAD)
+{
+       LogDebug("<<< ");
+       LogDebug(">>>");
+}
+
+MessagingController::~MessagingController() {
+       LogDebug("<<<");
+       LogDebug(">>>");
+}
+
+MessagingController& MessagingController::getInstance()
+{
+       static MessagingController instance;
+       return instance;
+}
+
+void MessagingController::OnAnswerReceived(const Api::Messaging::EventGetMessagingServicePtr &event) {
+       LogDebug("<<<");
+
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager > (event->getPrivateData());
+       MessageAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+       
+       if (event->getExceptionCode() == ExceptionCodes::None)
+       {
+               std::vector<IMessagingServicePtr> messagingServices = event->getMessagingServices();
+               int count = messagingServices.size();
+               int index = 0;
+
+               JSObjectRef jsMessagingServiceObject[count];    //make
+
+               LogDebug(" Service Count :" << count);
+               
+               for (index = 0; index < count; index++)
+               {
+                       jsMessagingServiceObject[index] = JSMessagingService::createJSObject(callbackManager->getContext(), messagingServices[index] );
+               }
+               JSObjectRef result = JSObjectMakeArray(callbackManager->getContext(), count, jsMessagingServiceObject, NULL);
+
+               callbackManager->callOnSuccess(result);
+       }
+       else
+       {
+               LogDebug("Operation failed. Exception code: " << event->getExceptionCode());
+               JSContextRef context = callbackManager->getContext();
+               JSValueRef errorObject = NULL;
+
+               WrtDeviceApis::Commons::ExceptionCodes::Enumeration exception = event->getExceptionCode();
+               switch(exception) {
+                       case WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException:
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+                               break;
+                       case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::IO_ERROR, JSMESSAGING_EXCEPTION_MSG_IO);
+                       break;
+                       case WrtDeviceApis::Commons::ExceptionCodes::PlatformWrongStateException:
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
+                       break;
+                       default:
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+                               break;
+               }
+               callbackManager->callOnError(errorObject);
+       }
+
+       LogDebug(">>>");
+}
+
+void MessagingController::OnAnswerReceived(const Api::Messaging::EventMessagingServicePtr &event)
+{
+       LogDebug(" <<< EventMessagingServicePtr >>> ");
+
+       EventMessagingServicePrivateDataPtr privateData = 
+               DPL::StaticPointerCast<EventMessagingServicePrivateData>(event->getPrivateData());
+       
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = privateData->getCallbackManager();             //get callback manager
+       MessageAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+       
+       JSContextRef globalContext = callbackManager->getContext();
+
+       int MessagingServiceEventType = event->getEventType();
+       LogDebug(" MessagingServiceEvent Type :" << MessagingServiceEventType); 
+
+       ConverterMessageFactory::ConverterType converter =
+                ConverterMessageFactory::getConverter(globalContext);
+
+       if (MessagingServiceEventType == MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_BODY)
+       {
+               LogDebug(" Message Load Body");
+               LogDebug("Operation ID : " << event->opId);
+               if ( event->m_messagingService)
+                       event->m_messagingService->deleteOpId(event->opId);
+
+               if (event->getExceptionCode() == ExceptionCodes::None && event->m_message)
+               {
+                       LogDebug(" Message Type :" << event->m_message->getMessageType());
+                       JSValueRef msg = JSMessage::createJSObject(globalContext, event->m_message);
+                       if(msg)
+                               callbackManager->callOnSuccess(msg);
+                       else
+                               callbackManager->callOnError( JSTizenExceptionFactory::makeErrorObject(globalContext,
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+               }
+               else
+               {
+                       JSValueRef msg = privateData->getMessageJSValueRef();
+                       callbackManager->callOnError(msg);
+               }
+       }
+       else if (MessagingServiceEventType == MESSAGING_SERVICE_EVENT_TYPE_LOAD_MESSAGE_ATTACHMENT)
+       {
+               LogDebug(" Message load attachment");
+               LogDebug("Operation ID : " << event->opId);
+               if ( event->m_messagingService)
+                       event->m_messagingService->deleteOpId(event->opId);
+
+               if (event->getExceptionCode() == ExceptionCodes::None && event->m_attachment)
+               {
+                       LogDebug(" Message Type :" << event->m_message->getMessageType());
+
+                       JSValueRef attachment  =  JSMessageAttachment::createJS(globalContext, event->m_attachment );
+                       if ( attachment)
+                               callbackManager->callOnSuccess(attachment);
+                       else
+                               callbackManager->callOnError( JSTizenExceptionFactory::makeErrorObject(globalContext,
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+               }
+               else
+               {
+                       callbackManager->callOnError();
+               }
+       }
+       else if (MessagingServiceEventType == MESSAGING_SERVICE_EVENT_TYPE_SYNC)
+       {       
+               LogDebug(" Message Sync :");
+               LogDebug("Operation ID : " << event->opId);
+               if ( event->m_messagingService)
+                       event->m_messagingService->deleteOpId(event->opId);
+       
+               if (event->getExceptionCode() == ExceptionCodes::None)
+               {
+                       callbackManager->callOnSuccess();
+               }
+               else
+               {
+                       callbackManager->callOnError();
+               }
+       }
+       else if (MessagingServiceEventType == MESSAGING_SERVICE_EVENT_TYPE_SYNC_FOLDER)
+       {       
+               LogDebug(" Message Sync Folder");
+               LogDebug("Operation ID : " << event->opId);
+               if ( event->m_messagingService)
+                       event->m_messagingService->deleteOpId(event->opId);
+               if (event->getExceptionCode() == ExceptionCodes::None)
+               {
+                       callbackManager->callOnSuccess();
+               }
+               else
+               {
+                       callbackManager->callOnError();
+               }
+       }
+       else if (MessagingServiceEventType == MESSAGING_SERVICE_EVENT_TYPE_SEND_MESSAGE)
+       {
+               JSValueRef error = NULL;
+               WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr recipientCallbackManager = privateData->getRecipientCallbackManager();
+
+               if (WrtDeviceApis::Commons::ExceptionCodes::None != event->getExceptionCode()) {
+                       switch (event->getExceptionCode()) {
+                               case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+                               case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                                       error = JSTizenExceptionFactory::makeErrorObject(globalContext,           
+                                                 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+                                       break;
+                               default:
+                                       error = JSTizenExceptionFactory::makeErrorObject(globalContext,           
+                                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+                                       break;
+                       }
+                 }
+                 
+                 ConverterMessage converter(globalContext);
+                
+                 //remove operation handle
+                 if (event->m_messagingService)
+                 {
+                         LogDebug("Operation ID : " << event->opId);
+                         event->m_messagingService->deleteOpId(event->opId); 
+                 }
+                 if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) 
+                 {
+                         LogDebug(" success size : " << event->m_successRecipients.size());
+                         std::vector<JSValueRef> successRecipentList;
+                         
+                         int cnt = event->m_successRecipients.size();
+                         LogDebug( "success count : " << cnt);
+               
+                         for(int index = 0; index < cnt; index++)
+                         {
+                                 LogDebug( "success recipent : " << event->m_successRecipients[index]);
+                                 successRecipentList.push_back(converter.toJSValueRef(event->m_successRecipients[index]));
+                         }
+                                         
+                         JSObjectRef result = JSObjectMakeArray(globalContext, cnt, successRecipentList.data(), NULL);
+                         callbackManager->callOnSuccess(result);
+                          
+                 } 
+                 else {
+                         //JSValueRef params[] = { error, recipient };
+                         //callbackManager->callOnError( params, sizeof(params) / sizeof(params[0]));
+                         callbackManager->callOnError(error);
+                 }
+               
+       }
+       else 
+       {
+               callbackManager->callOnError(JSValueMakeUndefined(globalContext));
+       }
+       
+}
+void MessagingController::OnAnswerReceived(const Api::Messaging::EventSendMessagePtr& event)
+{
+       LogDebug("ENTER");
+
+       JSValueRef error = NULL;
+       EventSendMessagePrivateDataPtr privateData = 
+               DPL::StaticPointerCast<EventSendMessagePrivateData>(event->getPrivateData());
+       Assert(NULL != privateData);
+
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = privateData->getCallbackManager();
+       MessageAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+       
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr recipientCallbackManager = privateData->getRecipientCallbackManager();
+
+       JSContextRef context = callbackManager->getContext();
+       Assert(NULL != context);
+          
+    if (WrtDeviceApis::Commons::ExceptionCodes::None != event->getExceptionCode()) {
+        switch (event->getExceptionCode()) {
+        case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+        case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+               error = JSTizenExceptionFactory::makeErrorObject(context,               
+                                               JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
+                       break;
+        default:
+            error = JSTizenExceptionFactory::makeErrorObject(context,          
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
+                       break;
+        }
+    }
+               
+       ConverterMessage converter(context);
+       //JSValueRef recipient = converter.toJSValueRef(event->getRecipient());
+
+       //remove operation handle
+       if (event->m_messagingService)
+       {
+               LogDebug("Operation ID : " << event->opId);
+               event->m_messagingService->deleteOpId(event->opId);     
+       }
+       if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) {
+               LogDebug(" success size : " << event->m_successRecipients.size());
+
+            //JSObjectRef result = JSObjectMakeArray(context, event->m_successRecipients.size(), jsMessagingServiceObject, NULL);
+               std::vector<JSValueRef> successRecipentList;
+               
+               int cnt = event->m_successRecipients.size();
+               LogDebug( "success count : " << cnt);
+
+
+               for(int index = 0; index < cnt; index++)
+               {
+                       LogDebug( "success recipent : " << event->m_successRecipients[index]);
+                       successRecipentList.push_back(converter.toJSValueRef(event->m_successRecipients[index]));
+               }
+                               
+               JSObjectRef result = JSObjectMakeArray(context, cnt, successRecipentList.data(), NULL);
+               callbackManager->callOnSuccess(result);
+                
+       } 
+       else {
+               //JSValueRef params[] = { error, recipient };
+               //callbackManager->callOnError( params, sizeof(params) / sizeof(params[0]));
+               callbackManager->callOnError(error);
+       }
+               
+#if 0 //old style code
+    if (!event->getSendCallbackPerRecipient()) {
+        //this is callback for whole operation, not single recipient
+        if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) {
+            callbackManager->callOnSuccess();
+        } else {
+            callbackManager->callOnError(error);
+        }
+    } else if (recipientCallbackManager) {
+        //this is callback for single recipient
+        ConverterMessage converter(context);
+        JSValueRef recipient = converter.toJSValueRef(event->getRecipient());
+        if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) {
+            recipientCallbackManager->callOnSuccess(recipient);
+        } else {
+            JSValueRef params[] = { error, recipient };
+            recipientCallbackManager->callOnError( params, sizeof(params) / sizeof(params[0]));
+        }
+    }
+#endif
+       
+}
+}
+}
+
diff --git a/src/standards/Tizen/Messaging/MessagingController.h b/src/standards/Tizen/Messaging/MessagingController.h
new file mode 100755 (executable)
index 0000000..fbd2c08
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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_MESSAGING_CONTROLLER_H_
+#define WRTPLUGINS_TIZEN_MESSAGING_CONTROLLER_H_
+
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <API/Messaging/IMessagingServiceManager.h>
+#include <API/Messaging/IMessagingService.h>
+#include <API/Messaging/EventSendMessage.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<Api::Messaging::EventGetMessagingService> GetMessagingServiceReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<Api::Messaging::EventMessagingService> MessagingServiceReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<Api::Messaging::EventSendMessage> SendMessageAnswerReceiver;
+
+
+class MessagingController :
+               public SendMessageAnswerReceiver,
+               public GetMessagingServiceReceiver,
+               public MessagingServiceReceiver
+{
+
+public:
+       explicit MessagingController();
+       virtual ~MessagingController();
+
+       static MessagingController& getInstance();
+
+protected:
+       void OnAnswerReceived(const Api::Messaging::EventGetMessagingServicePtr &event);
+
+       void OnAnswerReceived(const Api::Messaging::EventMessagingServicePtr &event);
+
+       void OnAnswerReceived(const Api::Messaging::EventSendMessagePtr &event);
+
+};
+
+typedef DPL::Singleton<MessagingController> MessagingControllerSingleton;      //for singleton
+
+}
+} // WrtPlugins
+
+#endif //WRTPLUGINS_TIZEN_MESSAGING_CONTROLLER_H_
diff --git a/src/standards/Tizen/Messaging/MessagingErrorMsg.h b/src/standards/Tizen/Messaging/MessagingErrorMsg.h
new file mode 100755 (executable)
index 0000000..e54758b
--- /dev/null
@@ -0,0 +1,33 @@
+//
+// 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.
+//\r
+\r
+#ifndef _MESSAGING_ERROR_MESSAGE_H_\r
+#define _MESSAGING_ERROR_MESSAGE_H_\r
+\r
+//exception message\r
+\r
+#define JSMESSAGING_EXCEPTION_MSG_UNKNOWN                              "UnknownError"\r
+#define JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH                "Type Mismatch"\r
+#define JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT             "Argument is invalid"\r
+#define JSMESSAGING_EXCEPTION_MSG_IO                                           "IO Error"\r
+#define JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED                "Not Supported"\r
+#define JSMESSAGING_EXCEPTION_MSG_PERMISSION_DENIED            "Permission Denied"\r
+#define JSMESSAGING_EXCEPTION_MSG_NOT_FOUND                    "Not Found"\r
+#define JSMESSAGING_EXCEPTION_MSG_ABORT_ERROR                  "Abort Error"\r
+\r
+#endif //_MESSAGING_ERROR_MESSAGE_H_\r
+\r
diff --git a/src/standards/Tizen/Messaging/MessagingListener.cpp b/src/standards/Tizen/Messaging/MessagingListener.cpp
new file mode 100755 (executable)
index 0000000..98c8e4e
--- /dev/null
@@ -0,0 +1,914 @@
+//
+// 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 <vector>
+#include <dpl/assert.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+#include <API/Filter/IFilter.h>
+#include <API/Messaging/StorageChangesMessageGenerator.h>
+#include <API/Messaging/StorageChangesConversationGenerator.h>
+#include <API/Messaging/StorageChangesFolderGenerator.h>
+
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "MessagingErrorMsg.h"
+#include "JSMessagingStorage.h"
+#include "ConverterMessage.h"
+#include "EventSendMessagePrivateData.h"
+#include "MessagingListener.h"
+#include "MessageAsyncCallbackManager.h"
+#include <dpl/singleton_safe_impl.h>
+
+IMPLEMENT_SAFE_SINGLETON(TizenApis::Tizen1_0::MessagingListener)
+
+using namespace std;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Api::Messaging;
+using namespace TizenApis::Commons;
+
+
+MessagingListener::MessagingListener() :
+    EventAddDraftMessageAnswerReceiver(ThreadEnum::NULL_THREAD),
+    EventQueryMessagesAnswerReceiver(ThreadEnum::NULL_THREAD),
+    EventDeleteMessagesAnswerReceiver(ThreadEnum::NULL_THREAD),
+    EventUpdateMessagesAnswerReceiver(ThreadEnum::NULL_THREAD),        
+    Api::Messaging::EventUpdateMessageAnswerReceiver(ThreadEnum::NULL_THREAD),
+    EventMessageReceivedListener(ThreadEnum::NULL_THREAD),
+    EventQueryConversationsAnswerReceiver(ThreadEnum::NULL_THREAD),
+    EventDeleteConversationsAnswerReceiver(ThreadEnum::NULL_THREAD),
+    EventQueryFoldersAnswerReceiver(ThreadEnum::NULL_THREAD),    
+    m_nextHandle(1)
+//    m_emiterMsgId(Api::Messaging::EmitterMessageReceived::emptyId),
+//    m_emiterConvId(Api::Messaging::EmitterConversationReceived::emptyId),
+//    m_emiterFolderId(Api::Messaging::EmitterFolderReceived::emptyId)
+{
+}
+
+MessagingListener::~MessagingListener() {
+}
+
+void MessagingListener::OnAnswerReceived(
+        const Api::Messaging::EventAddDraftMessagePtr& event)
+{
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager =
+        DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+    Assert(NULL != callbackManager);
+    LogDebug("thread=" << DPL::Thread::GetCurrentThread());
+
+    JSContextRef context = callbackManager->getContext();
+    Assert(NULL != context);
+
+    MessageAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+    Try
+    {
+        if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) {
+            callbackManager->callOnSuccess();
+
+        } else {
+            switch (event->getExceptionCode()) {
+            case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+                Throw(WrtDeviceApis::Commons::PlatformException);
+            case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                Throw(WrtDeviceApis::Commons::ConversionException);
+            default:
+                Throw(WrtDeviceApis::Commons::UnknownException);
+            }
+        }
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("platform error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+    Catch(WrtDeviceApis::Commons::ConversionException) {
+        LogError("conversion error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+    Catch(WrtDeviceApis::Commons::UnknownException) {
+        LogError("unknown error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+
+}
+
+
+
+void MessagingListener::OnAnswerReceived(
+        const Api::Messaging::EventQueryMessagesPtr& event)
+{
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager =
+        DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+    Assert(NULL != callbackManager);
+    LogDebug("thread=" << DPL::Thread::GetCurrentThread());
+
+    JSContextRef context = callbackManager->getContext();
+    Assert(NULL != context);
+
+    MessageAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+    Try
+    {
+        if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) {
+            std::vector<Api::Messaging::IMessagePtr> msgs = event->msgs;
+
+            ConverterMessageFactory::ConverterType converter =
+                ConverterMessageFactory::getConverter(context);
+
+            callbackManager->callOnSuccess(converter->toJSValueRef(msgs, this));
+
+        } else {
+            switch (event->getExceptionCode()) {
+            case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+                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);
+            }
+        }
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("platform error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+
+    Catch(WrtDeviceApis::Commons::ConversionException) {
+        LogError("conversion error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+
+    Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
+    {
+        LogError("conversion 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,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+}
+
+void MessagingListener::OnAnswerReceived(
+        const Api::Messaging::EventDeleteMessagesPtr& event)
+{
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager =
+        DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+    Assert(NULL != callbackManager);
+    LogDebug("thread=" << DPL::Thread::GetCurrentThread());
+
+    JSContextRef context = callbackManager->getContext();
+    Assert(NULL != context);
+
+    MessageAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+    Try
+    {
+        if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) {
+            callbackManager->callOnSuccess();
+
+        } else {
+            switch (event->getExceptionCode()) {
+            case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+                Throw(WrtDeviceApis::Commons::PlatformException);
+            case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                Throw(WrtDeviceApis::Commons::ConversionException);
+            default:
+                Throw(WrtDeviceApis::Commons::UnknownException);
+            }
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("platform error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+
+    Catch(WrtDeviceApis::Commons::ConversionException) {
+        LogError("conversion error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+
+    Catch(WrtDeviceApis::Commons::UnknownException) {
+        LogError("unknown error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+
+}
+
+void MessagingListener::OnAnswerReceived(
+        const Api::Messaging::EventUpdateMessagesPtr& event)
+{
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager =
+        DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+    Assert(NULL != callbackManager);
+    LogDebug("thread=" << DPL::Thread::GetCurrentThread());
+
+    JSContextRef context = callbackManager->getContext();
+    Assert(NULL != context);
+
+    MessageAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+    Try
+    {
+        if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) {
+            callbackManager->callOnSuccess();
+
+        } else {
+            switch (event->getExceptionCode()) {
+            case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+                Throw(WrtDeviceApis::Commons::PlatformException);
+            case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                Throw(WrtDeviceApis::Commons::ConversionException);
+            default:
+                Throw(WrtDeviceApis::Commons::UnknownException);
+            }
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("platform error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+
+    Catch(WrtDeviceApis::Commons::ConversionException) {
+        LogError("conversion error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+
+    Catch(WrtDeviceApis::Commons::UnknownException) {
+        LogError("unknown error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+
+}
+
+void MessagingListener::OnAnswerReceived(
+        const DPL::SharedPtr<Api::Messaging::EventUpdateMessage> &event)
+{
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager =
+        DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+    Assert(NULL != callbackManager);
+    LogDebug("thread=" << DPL::Thread::GetCurrentThread());
+
+    JSContextRef context = callbackManager->getContext();
+    Assert(NULL != context);
+
+    Try
+    {
+        if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) {
+            ConverterMessageFactory::ConverterType converter =
+                ConverterMessageFactory::getConverter(context);
+            callbackManager->callOnSuccess(converter->toJSValueRef(event->msg,
+                                                                   this));
+        } else {
+            switch (event->getExceptionCode()) {
+            case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+                Throw(WrtDeviceApis::Commons::PlatformException);
+            case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                Throw(WrtDeviceApis::Commons::ConversionException);
+            default:
+                Throw(WrtDeviceApis::Commons::UnknownException);
+            }
+        }
+    }
+
+    Catch(WrtDeviceApis::Commons::PlatformException) {
+        LogError("platform error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+
+    Catch(WrtDeviceApis::Commons::ConversionException) {
+        LogError("conversion error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+
+    Catch(WrtDeviceApis::Commons::UnknownException) {
+        LogError("conversion error");
+        callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,         
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+    }
+}
+
+void MessagingListener::OnAnswerReceived(const Api::Messaging::EventQueryConversationsPtr& event)
+{
+       LogDebug("enter");
+
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+
+       JSContextRef context = callbackManager->getContext();
+       Assert(NULL != context);
+
+       MessageAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       Try
+       {
+               if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) 
+               {
+                       vector<IConversationPtr> convPtr = event->getConversatioins();
+                       ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+                       callbackManager->callOnSuccess(converter->toJSValueRef(convPtr));
+
+               } 
+               else 
+               {
+                       switch (event->getExceptionCode()) 
+                       {
+                               case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+                                       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);
+                       }
+               }
+       }
+
+       Catch(WrtDeviceApis::Commons::PlatformException) 
+       {
+               LogError("platform error");
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+       }
+       Catch(WrtDeviceApis::Commons::ConversionException) 
+       {
+               LogError("conversion error");
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+       }
+       Catch(WrtDeviceApis::Commons::InvalidArgumentException)
+       {
+               LogError("conversion 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,          
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+       }
+
+}
+
+void MessagingListener::OnAnswerReceived(const Api::Messaging::EventDeleteConversationsPtr& event)
+{
+       LogDebug("enter");
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+
+       JSContextRef context = callbackManager->getContext();
+       Assert(NULL != context);
+
+       MessageAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+       
+       try 
+       {
+               if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) 
+               {
+                       callbackManager->callOnSuccess();
+       
+}
+               else 
+               {
+                       switch (event->getExceptionCode()) 
+                       {
+                               case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+                                       Throw(WrtDeviceApis::Commons::PlatformException);
+                               case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                                       Throw(WrtDeviceApis::Commons::ConversionException);
+                               default:
+                                       Throw(WrtDeviceApis::Commons::UnknownException);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::PlatformException) 
+       {
+               LogError("platform error");
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+       }
+       Catch(WrtDeviceApis::Commons::ConversionException) 
+       {
+               LogError("conversion error");
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+       }
+       Catch(WrtDeviceApis::Commons::UnknownException) 
+       {
+               LogError("unknown error");
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+       }
+}
+
+void MessagingListener::OnAnswerReceived(const Api::Messaging::EventQueryFoldersPtr& event)
+{
+       LogDebug("enter");
+
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+
+       JSContextRef context = callbackManager->getContext();
+       Assert(NULL != context);
+
+       MessageAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       Try
+       {
+               if (WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) 
+               {
+                       vector<IMessageFolderPtr> folderPtr = event->getFolders();
+                       int size = folderPtr.size();
+                       LogDebug(size);
+                       
+                       ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+                       callbackManager->callOnSuccess(converter->toJSValueRef(folderPtr));
+               } 
+               else 
+               {
+                       switch (event->getExceptionCode()) 
+                       {
+                               case WrtDeviceApis::Commons::ExceptionCodes::PlatformException:
+                                       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);
+                       }
+               }
+       }
+
+       Catch(WrtDeviceApis::Commons::PlatformException) 
+       {
+               LogError("platform error");
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+       }
+       Catch(WrtDeviceApis::Commons::ConversionException) 
+       {
+               LogError("conversion error");
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,          
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+       }
+       Catch(WrtDeviceApis::Commons::InvalidArgumentException) 
+       {
+               LogError("conversion 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,          
+                                               JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN));
+       }
+
+}
+
+
+void MessagingListener::onAnswerReceived(
+        const Api::Messaging::EventMessageReceivedPtr& event)
+{
+       LogDebug("<<<");
+
+       if (WrtDeviceApis::Commons::ExceptionCodes::None != event->getExceptionCode()) 
+       {
+               LogError("exception occured: " << event->getExceptionCode());
+               return;
+       }
+
+       JSValueRef jsMsg = NULL;
+
+       EventOnMessagingStorageChangesPrivateDataPtr multiCallbacks = 
+               DPL::DynamicPointerCast<EventOnMessagingStorageChangesPrivateData>(event->getPrivateData());
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr defaultCbm = multiCallbacks->getMessagesAdded();
+
+    JSContextRef context = defaultCbm->getContext();
+       ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
+
+
+
+       switch(multiCallbacks->getFunctionIndex())
+       {
+               case MESSAGES_MULTI_FUNCTION:
+               {
+
+                       Api::Tizen::FilterPtr filter = multiCallbacks->getFilter();
+                       Api::Messaging::IMessagePtr msg = event->getMessage();
+
+                       if(filter != NULL && msg->getMessageType() != Api::Messaging::EMPTY_MESSAGE)
+                       {
+                               LogDebug("Filter exist");                       
+                               Platform::Messaging::StorageChangesMessageGeneratorPtr queryGenerator(new Platform::Messaging::StorageChangesMessageGenerator(event->getMessage(), event->getConversation()));
+                       
+                               Api::Tizen::IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<Api::Tizen::IFilterVisitor>(queryGenerator);
+                               filter->travel(filterVisitor, 0);
+                               std::vector<Api::Messaging::IMessagePtr> msgs; // for msg
+//                             Api::Messaging::IMessagePtr msg = event->getMessage();
+                               if(queryGenerator->getCompareResult())
+                               {
+                                       LogDebug("Message call back");
+                                       msgs.push_back(msg);
+                                       jsMsg = converter->toJSValueRef(msgs, this);
+                               }
+                               else
+                               {
+                                       LogDebug("skip");
+                                       return;                                 
+                               }
+                       }
+                       else 
+                       {
+                               LogDebug("Filter not exist or empty message");                                          
+                               std::vector<Api::Messaging::IMessagePtr> msgs; // for msg
+                               Api::Messaging::IMessagePtr msg = event->getMessage();
+                               msgs.push_back(msg);
+                               jsMsg = converter->toJSValueRef(msgs, this);                    
+                       }
+               }
+               break;
+               case CONVERSATIONS_MULTI_FUNCTION:
+               {
+                       Api::Tizen::FilterPtr filter = multiCallbacks->getFilter();
+                       Api::Messaging::IMessagePtr msg = event->getMessage();
+
+                       if(filter != NULL && msg->getMessageType() != Api::Messaging::EMPTY_MESSAGE)
+                       {
+                               LogDebug("Filter exist");                       
+                               Platform::Messaging::StorageChangesConversationGeneratorPtr queryGenerator(new Platform::Messaging::StorageChangesConversationGenerator(event->getConversation()));
+                       
+                               Api::Tizen::IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<Api::Tizen::IFilterVisitor>(queryGenerator);
+                               filter->travel(filterVisitor, 0);
+                               std::vector<Api::Messaging::IConversationPtr> convPtrs; // for conversation
+                               Api::Messaging::IConversationPtr conversation = event->getConversation();
+                               if(queryGenerator->getCompareResult())
+                               {
+                                       LogDebug("Message call back");
+                                       convPtrs.push_back(conversation);
+                                       jsMsg = converter->toJSValueRef(convPtrs);
+                               }
+                               else
+                               {
+                                       LogDebug("skip");
+                                       return;                                 
+                               }
+                       }
+                       else 
+                       {
+                               LogDebug("Filter not exist or empty conversation");                                             
+                               std::vector<Api::Messaging::IConversationPtr> convPtrs; // for conversation
+                               Api::Messaging::IConversationPtr conversation = event->getConversation();
+
+                               LogDebug("Conversation call back");
+
+                               convPtrs.push_back(conversation);
+                               jsMsg = converter->toJSValueRef(convPtrs);
+                       }
+               }
+               break;
+               case FOLDERS_MULTI_FUNCTION:
+               {
+                       Api::Tizen::FilterPtr filter = multiCallbacks->getFilter();
+                       if(filter != NULL)
+                       {
+                               LogDebug("Filter exist");                       
+                               Platform::Messaging::StorageChangesFolderGeneratorPtr queryGenerator(new Platform::Messaging::StorageChangesFolderGenerator(event->getMessageFolder()));
+                       
+                               Api::Tizen::IFilterVisitorPtr filterVisitor = DPL::StaticPointerCast<Api::Tizen::IFilterVisitor>(queryGenerator);
+                               filter->travel(filterVisitor, 0);
+                               std::vector<Api::Messaging::IMessageFolderPtr> folderPtrs; // for messagefoldeer
+                               Api::Messaging::IMessageFolderPtr messagefolder = event->getMessageFolder();
+                               if(queryGenerator->getCompareResult())
+                               {
+                                       LogDebug("Message call back");
+                                       folderPtrs.push_back(messagefolder);
+                                       jsMsg = converter->toJSValueRef(folderPtrs);
+                               }
+                               else
+                               {
+                                       LogDebug("skip");
+                                       return;                                 
+                               }
+                       }
+                       else 
+                       {
+                               LogDebug("Filter not exist");                                           
+                               std::vector<Api::Messaging::IMessageFolderPtr> folderPtrs; // for messagefoldeer
+                               Api::Messaging::IMessageFolderPtr messagefolder = event->getMessageFolder();
+               
+                               LogDebug("MessageFolder call back");
+               
+                               folderPtrs.push_back(messagefolder);
+                               jsMsg = converter->toJSValueRef(folderPtrs);
+                       }
+               }
+               break;
+       }
+
+       switch(event->getMsg_Event_Type())
+       {
+               case Api::Messaging::EventMessageReceived::MSG_ADDED:
+               {
+                       multiCallbacks->getMessagesAdded()->callOnSuccess(jsMsg);
+               }
+               break;
+               case Api::Messaging::EventMessageReceived::MSG_UPDATED:
+               {
+                       defaultCbm = multiCallbacks->getMessagesUpdated();
+                       defaultCbm->callOnSuccess(jsMsg);
+               }
+               break;
+               case Api::Messaging::EventMessageReceived::MSG_DELETED:
+               {
+                       defaultCbm = multiCallbacks->getMessagesRemoved();
+                       defaultCbm->callOnSuccess(jsMsg);
+               }
+               break;
+               default:
+               {
+                       break;
+               }
+                       
+       }
+}
+
+long MessagingListener::addIncomingMsgCallback(const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& cbManager, int funtionIndex)
+{
+       IncomingMsgCB* callbacks = NULL;
+       long handle = 0;
+       
+       switch(funtionIndex)
+       {
+               case MESSAGES_MULTI_FUNCTION:
+               {
+                       callbacks = &m_MessageCallbacks;                        
+                       handle = static_cast<long>(m_emiterMsgId.back());
+                       LogWarning("Message Emitter handle : " << handle);                      
+               }
+               break;
+               case CONVERSATIONS_MULTI_FUNCTION:
+               {
+                       callbacks = &m_ConversationCallbacks;                                           
+                       handle = static_cast<long>(m_emiterConvId.back());
+                       LogWarning("Conversation Emitter handle : " << handle);                 
+               }
+               break;
+               case FOLDERS_MULTI_FUNCTION:
+               {
+                       callbacks = &m_FolderCallbacks;                                         
+                       handle = static_cast<long>(m_emiterFolderId.back());
+                       LogWarning("Folder Emitter handle : " << handle);                       
+               }
+               break;
+               default:
+               {
+                       LogWarning("Unexpected state");
+               }
+               break;
+       }
+
+       if (NULL == callbacks) {
+           Throw(WrtDeviceApis::Commons::UnsupportedException);
+       }
+
+    // try to insert new callback
+    if (!callbacks->insert(std::make_pair(handle, cbManager)).second) {
+        // callback with this handle already exists!
+        Throw(WrtDeviceApis::Commons::AlreadyInUseException);
+    }
+
+    return handle;
+}
+
+void MessagingListener::removeIncomingMsgCallback(long handle, int type, long index)
+{
+    size_t msgRemoved = 0;
+    size_t convRemoved = 0;
+    size_t folderRemoved = 0;  
+
+    if(!checkMessagingEmitter(handle, type, index))
+    {
+        LogWarning("Try to deregister by unmatched service");
+        Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+    }
+               
+    msgRemoved += m_MessageCallbacks.erase(handle);
+    convRemoved += m_ConversationCallbacks.erase(handle);      
+    folderRemoved += m_FolderCallbacks.erase(handle);
+
+    // there are duplicate handles
+    if (msgRemoved+msgRemoved+folderRemoved > 1) {
+        LogError("Duplicate callback handles!");
+    }
+    Api::Messaging::EmitterMessageReceived::IdType temp_handle;
+    temp_handle = static_cast<Api::Messaging::EmitterMessageReceived::IdType>(handle);
+
+    if (msgRemoved) {
+        LogWarning("EmitterMessageReceived registered");
+        Api::Messaging::IMessaging::getInstance().removeOnMessageMsgReceived(temp_handle);
+        removeMessagingEmitter(temp_handle);   
+        for(unsigned int i=0; i<m_emiterMsgId.size(); i++)
+        {
+            if(temp_handle == static_cast<long>(m_emiterMsgId[i]))
+            {
+                LogWarning("handle : handle " << temp_handle<< " " << static_cast<long>(m_emiterMsgId[i]) );
+                m_emiterMsgId.erase(m_emiterMsgId.begin()+i);
+            }
+        }
+    }
+    else if (convRemoved) {
+        LogWarning("EmitterConversationReceived registered");
+        Api::Messaging::IMessaging::getInstance().removeOnMessageConvReceived(temp_handle);
+        removeMessagingEmitter(temp_handle);
+        for(unsigned int i=0; i<m_emiterConvId.size(); i++)
+        {
+            if(temp_handle == static_cast<long>(m_emiterConvId[i]))
+            {
+                LogWarning("handle : handle " << temp_handle<< " " << static_cast<long>(m_emiterConvId[i]) );
+                m_emiterConvId.erase(m_emiterConvId.begin()+i);
+            }
+        }
+    }
+    else if (folderRemoved) {
+        LogWarning("EmitterFolderReceived registered");
+        Api::Messaging::IMessaging::getInstance().removeOnMessageFolderReceived(temp_handle);
+        removeMessagingEmitter(temp_handle);
+        for(unsigned int i=0; i<m_emiterFolderId.size(); i++)
+        {
+            if(temp_handle == static_cast<long>(m_emiterFolderId[i]))
+            {
+                LogWarning("handle : handle " << temp_handle<< " " << static_cast<long>(m_emiterFolderId[i]) );
+                m_emiterFolderId.erase(m_emiterFolderId.begin()+i);
+            }
+        }
+    }
+       
+}
+
+void MessagingListener::registerMessageReceivedEmitter(EventOnMessagingStorageChangesPrivateDataPtr privData)
+{
+
+    Try
+    {
+        if(privData->getFunctionIndex() == MESSAGES_MULTI_FUNCTION)
+        {
+
+            Api::Messaging::EmitterMessageReceivedPtr emitter(new Api::Messaging::EmitterMessageReceived());
+            emitter->setListener(this);
+            emitter->setEventPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privData));// <-registerMessageReceivedEmitter()
+            m_emiterMsgId.push_back(emitter->getId());
+            Api::Messaging::IMessaging::getInstance().addOnMessageReceived(emitter, privData->getFilter(), privData->getFunctionIndex());              
+            addMessagingEmitter(static_cast<long>(emitter->getId()), privData->getType(), privData->getIndex());               
+        }
+        else if(privData->getFunctionIndex() == CONVERSATIONS_MULTI_FUNCTION)
+        {
+            Api::Messaging::EmitterConversationReceivedPtr emitter(new Api::Messaging::EmitterConversationReceived());
+            emitter->setListener(this);
+            emitter->setEventPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privData));// <-registerMessageReceivedEmitter()
+            m_emiterConvId.push_back(emitter->getId());
+            Api::Messaging::IMessaging::getInstance().addOnMessageReceived(emitter, privData->getFilter(), privData->getFunctionIndex());              
+            addMessagingEmitter(static_cast<long>(emitter->getId()), privData->getType(), privData->getIndex());               
+        }
+        else// if(privData->getFunctionIndex() == FOLDERS_MULTI_FUNCTION)
+        {
+            Api::Messaging::EmitterFolderReceivedPtr emitter(new Api::Messaging::EmitterFolderReceived());
+            emitter->setListener(this);
+            emitter->setEventPrivateData(DPL::StaticPointerCast<WrtDeviceApis::Commons::IEventPrivateData>(privData));// <-registerMessageReceivedEmitter()
+            m_emiterFolderId.push_back(emitter->getId());
+            Api::Messaging::IMessaging::getInstance().addOnMessageReceived(emitter, privData->getFilter(), privData->getFunctionIndex());              
+            addMessagingEmitter(static_cast<long>(emitter->getId()), privData->getType(), privData->getIndex());
+        }
+    }
+    Catch(WrtDeviceApis::Commons::PlatformException){
+        LogDebug("registerMessageReceivedEmitter failed");                             
+        Throw(WrtDeviceApis::Commons::PlatformException);
+    }
+       
+}
+
+void MessagingListener::deregisterMessageReceivedEmitter()
+{
+    LogDebug("enter");
+    if (m_emiterMsgId.size() > 0) {
+        LogWarning("EmitterMessageReceived registered");
+               Api::Messaging::EmitterMessageReceived::IdType  tempId;
+               while(m_emiterMsgId.size() > 0)
+               {
+                       tempId = m_emiterMsgId.back();
+                       Api::Messaging::IMessaging::getInstance().removeOnMessageMsgReceived(tempId);
+                       m_emiterMsgId.pop_back();
+               }
+    }
+
+       if (m_emiterConvId.size() > 0) {
+               LogWarning("EmitterConversationReceived registered");
+               Api::Messaging::EmitterConversationReceived::IdType     tempId;
+               while(m_emiterConvId.size() > 0)
+               {
+                       tempId = m_emiterConvId.back();
+                       Api::Messaging::IMessaging::getInstance().removeOnMessageMsgReceived(tempId);
+                       m_emiterConvId.pop_back();
+               }
+       }
+
+       if (m_emiterFolderId.size() > 0) {
+               LogWarning("EmitterFolderReceived registered");
+               Api::Messaging::EmitterFolderReceived::IdType   tempId;
+               while(m_emiterFolderId.size() > 0)
+               {
+                       tempId = m_emiterFolderId.back();
+                       Api::Messaging::IMessaging::getInstance().removeOnMessageMsgReceived(tempId);
+                       m_emiterFolderId.pop_back();
+               }
+       }
+
+       MessagingEmitterRegistersIterator it = m_requests.begin();
+
+       for (; it != m_requests.end(); it++)
+       {
+               removeMessagingEmitter(it->first);
+       }
+        LogDebug("finish");
+       return;
+}
+
+bool MessagingListener::checkMessagingEmitter(long handle, int type, long index)
+{
+       int ret = FALSE;
+    MessagingEmitterRegistersIterator it = m_requests.find(handle);
+
+    LogDebug("handle, type, index"<< handle << " " << type << " " << index);
+    LogDebug("it->second.type, it->second.accountId"<< it->second.type << " " << it->second.accountId);
+       
+       if((it->second.type == type) && (it->second.accountId == index))
+       {
+               ret = TRUE;
+       }
+       return ret;     
+}
+
+void MessagingListener::addMessagingEmitter(long handle, int type, long index)
+{
+    LogDebug("handle, type, index"<< handle << " " << type << " " << index);
+       m_requests.insert(std::make_pair(handle, MessagingEmitterData(type, index)));
+}
+
+void MessagingListener::removeMessagingEmitter(long handle)
+{
+    LogDebug("handle"<< handle );
+       m_requests.erase(handle);
+}
+
+
+MessagingListener& MessagingListener::getInstance()
+{
+       static MessagingListener instance;
+       return instance;
+}
+
+}
+}
diff --git a/src/standards/Tizen/Messaging/MessagingListener.h b/src/standards/Tizen/Messaging/MessagingListener.h
new file mode 100755 (executable)
index 0000000..9dc6845
--- /dev/null
@@ -0,0 +1,119 @@
+//
+// 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 MESSAGINGLISTENER_H
+#define MESSAGINGLISTENER_H
+
+#include <map>
+#include <CommonsJavaScript/JSPendingOperation.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Messaging/ReqReceiverMessage.h>
+#include <API/Messaging/EventMessageReceived.h>
+#include <API/Messaging/IMessaging.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+#include "MessagingStorageMultiCallback.h"
+
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<Api::Messaging::EventAddDraftMessage> EventAddDraftMessageAnswerReceiver;  
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<Api::Messaging::EventQueryMessages> EventQueryMessagesAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<Api::Messaging::EventDeleteMessages> EventDeleteMessagesAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<Api::Messaging::EventUpdateMessages> EventUpdateMessagesAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<Api::Messaging::EventQueryConversations> EventQueryConversationsAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<Api::Messaging::EventDeleteConversations> EventDeleteConversationsAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<Api::Messaging::EventQueryFolders> EventQueryFoldersAnswerReceiver;
+
+typedef WrtDeviceApis::Commons::EventListener<Api::Messaging::EventMessageReceived> EventMessageReceivedListener;
+
+class MessagingListener;
+typedef DPL::SharedPtr<MessagingListener> MessagingListenerPtr;
+
+class MessagingListener : 
+    public EventAddDraftMessageAnswerReceiver,
+    public EventQueryMessagesAnswerReceiver,
+    public EventDeleteMessagesAnswerReceiver,
+    public EventUpdateMessagesAnswerReceiver,
+    public Api::Messaging::EventUpdateMessageAnswerReceiver,
+    public EventMessageReceivedListener,
+    public EventQueryConversationsAnswerReceiver,
+    public EventDeleteConversationsAnswerReceiver,
+    public EventQueryFoldersAnswerReceiver
+{
+  public:
+    explicit MessagingListener();
+    virtual ~MessagingListener();      
+
+    long addIncomingMsgCallback(const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& cbManager, int funtionIndex);
+    void removeIncomingMsgCallback(long handle, int type, long index);
+    void registerMessageReceivedEmitter(EventOnMessagingStorageChangesPrivateDataPtr privData);
+    void deregisterMessageReceivedEmitter();
+
+  protected:
+    virtual void OnAnswerReceived(const DPL::SharedPtr<Api::Messaging::EventAddDraftMessage> &event);
+    virtual void OnAnswerReceived(const DPL::SharedPtr<Api::Messaging::EventQueryMessages> &event);
+    virtual void OnAnswerReceived(const DPL::SharedPtr<Api::Messaging::EventDeleteMessages> &event);
+    virtual void OnAnswerReceived(const DPL::SharedPtr<Api::Messaging::EventUpdateMessages> &event);
+    virtual void OnAnswerReceived(const DPL::SharedPtr<Api::Messaging::EventUpdateMessage> &event);
+    virtual void OnAnswerReceived(const Api::Messaging::EventQueryConversationsPtr& event);
+    virtual void OnAnswerReceived(const Api::Messaging::EventDeleteConversationsPtr& event);
+    virtual void OnAnswerReceived(const Api::Messaging::EventQueryFoldersPtr& event);
+    virtual void onAnswerReceived(const Api::Messaging::EventMessageReceivedPtr& event);
+
+  private:
+    typedef std::map<long, WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr> IncomingMsgCB;
+    IncomingMsgCB m_MessageCallbacks;
+    IncomingMsgCB m_ConversationCallbacks;
+    IncomingMsgCB m_FolderCallbacks;
+    long m_nextHandle;
+    std::vector<Api::Messaging::EmitterMessageReceived::IdType> m_emiterMsgId;
+    std::vector<Api::Messaging::EmitterConversationReceived::IdType> m_emiterConvId;
+    std::vector<Api::Messaging::EmitterFolderReceived::IdType> m_emiterFolderId;
+
+    struct MessagingEmitterData//SendRequestData
+    {
+        int type;
+        long accountId;
+        explicit MessagingEmitterData(const int type, const long index) :
+        type(type),
+        accountId(index)
+        {
+        }
+};
+
+    typedef std::map<long, MessagingEmitterData> MessagingEmitterRegisters;
+    typedef MessagingEmitterRegisters::iterator MessagingEmitterRegistersIterator;//SendRequestsIterator;
+       
+    MessagingEmitterRegisters m_requests;      
+
+  public:
+    static MessagingListener& getInstance();
+       
+    bool checkMessagingEmitter(long handle, int type, long index);
+    void addMessagingEmitter(long handle, int type, long index);
+    void removeMessagingEmitter(long handle);  
+//     static MessagingListenerPtr getInstance(JSContextRef context);
+};
+
+typedef DPL::Singleton<MessagingListener> MessagingListenerSingleton;  //for singleton
+
+}
+}
+
+#endif // MessagingListener_H
diff --git a/src/standards/Tizen/Messaging/MessagingStorageMultiCallback.cpp b/src/standards/Tizen/Messaging/MessagingStorageMultiCallback.cpp
new file mode 100755 (executable)
index 0000000..4c3363e
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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 "MessagingStorageMultiCallback.h"
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+EventOnMessagingStorageChangesPrivateData::EventOnMessagingStorageChangesPrivateData(
+                       const JSCallbackManagerPtr& messagesAdded,      
+                       const JSCallbackManagerPtr& messagesUpdated,
+                       const JSCallbackManagerPtr& messagesRemoved,
+                       const int functionIndex) :
+                       m_messagesAdded(messagesAdded), 
+                       m_messagesUpdated(messagesUpdated), 
+                       m_messagesRemoved(messagesRemoved),
+                       m_functionIndex(functionIndex),
+                       m_type(-1),
+                       m_index(-1),
+                       m_filter(NULL)
+{
+}
+
+int EventOnMessagingStorageChangesPrivateData::getFunctionIndex() const
+{
+       return m_functionIndex;
+}
+
+JSCallbackManagerPtr EventOnMessagingStorageChangesPrivateData::getMessagesAdded() const
+{
+       return m_messagesAdded;
+}
+
+JSCallbackManagerPtr EventOnMessagingStorageChangesPrivateData::getMessagesUpdated() const
+{
+       return m_messagesUpdated;
+}
+
+JSCallbackManagerPtr EventOnMessagingStorageChangesPrivateData::getMessagesRemoved() const
+{
+       return m_messagesRemoved;
+}
+
+}
+}
+
+
+
+
diff --git a/src/standards/Tizen/Messaging/MessagingStorageMultiCallback.h b/src/standards/Tizen/Messaging/MessagingStorageMultiCallback.h
new file mode 100755 (executable)
index 0000000..3fe83f8
--- /dev/null
@@ -0,0 +1,109 @@
+//
+// 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_MESSAGING_STORAGE_MULTI_CALLBACK_H_
+#define TIZEN_MESSAGING_STORAGE_MULTI_CALLBACK_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <API/Filter/IFilter.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+struct OnMessagesChanged {
+       int functionIndex;
+       JSValueRef messagesAdded;
+       JSValueRef messagesUpdated;
+       JSValueRef messagesRemoved;
+
+       OnMessagesChanged()
+               : 
+               functionIndex(-1),
+               messagesAdded(NULL),
+               messagesUpdated(NULL),
+               messagesRemoved(NULL)
+       { }
+};
+
+enum MessageFunctionNum{
+       MESSAGES_MULTI_FUNCTION = 0,
+       CONVERSATIONS_MULTI_FUNCTION,   
+       FOLDERS_MULTI_FUNCTION, 
+       MESSAGING_MULTI_FUNTION_MAX
+};
+
+struct MessageFunctions {
+       const char *addedFunction;
+       const char *updatedFunction;
+       const char *removedFunction;
+};
+
+class EventOnMessagingStorageChangesPrivateData : public WrtDeviceApis::Commons::IEventPrivateData 
+{
+       public:
+               EventOnMessagingStorageChangesPrivateData(const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& messagesAdded,
+                       const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& messagesUpdated,
+                       const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& messagesRemoved, const int functionIndex);
+
+       int getFunctionIndex() const;
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getMessagesAdded() const;
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getMessagesUpdated() const;
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getMessagesRemoved() const;
+
+       void setFilter(const Api::Tizen::FilterPtr& filter) {
+               m_filter = filter;
+       }
+
+       Api::Tizen::FilterPtr getFilter() {
+               return m_filter;
+       }
+
+       void setIndex(long index){
+               m_index = index;
+       }
+       
+       long getIndex(){
+               return m_index;
+       }
+       
+       void setType(int type){
+               m_type = type;
+       }
+       
+       int getType(){
+               return m_type;
+       }       
+
+private:
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_messagesAdded;
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_messagesUpdated;
+       WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_messagesRemoved;       
+       int m_functionIndex;
+       int m_type;
+       long m_index;
+       Api::Tizen::FilterPtr m_filter;
+};
+
+typedef DPL::SharedPtr<EventOnMessagingStorageChangesPrivateData> EventOnMessagingStorageChangesPrivateDataPtr;
+
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Messaging/config.xml b/src/standards/Tizen/Messaging/config.xml
new file mode 100755 (executable)
index 0000000..789388f
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+    <library-name>libwrt-plugins-tizen-2.0-messaging.so</library-name>
+    <feature-install-uri>messaging.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/messaging.read</name>
+        <device-capability>messaging.read</device-capability>
+    </api-feature>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/messaging.send</name>
+        <device-capability>messaging.send</device-capability>
+    </api-feature>
+
+     <api-feature>
+        <name>http://tizen.org/privilege/messaging.write</name>
+        <device-capability>messaging.write</device-capability>
+    </api-feature>
+       
+</plugin-properties>
diff --git a/src/standards/Tizen/Messaging/plugin_config.cpp b/src/standards/Tizen/Messaging/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..6ecb41c
--- /dev/null
@@ -0,0 +1,340 @@
+//
+// 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 <map>
+#include <utility>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include "plugin_config.h"
+
+#define MESSAGING_FEATURE_API_READ "http://tizen.org/privilege/messaging.read"
+#define MESSAGING_FEATURE_API_SEND "http://tizen.org/privilege/messaging.send"
+#define MESSAGING_FEATURE_API_WRITE "http://tizen.org/privilege/messaging.write"
+
+#define MESSAGING_DEVICE_CAP_READ "messaging.read"
+#define MESSAGING_DEVICE_CAP_SEND "messaging.send"
+#define MESSAGING_DEVICE_CAP_WRITE "messaging.write"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace WrtDeviceApis::Commons;
+
+const char* MessagingExportedNames[] = 
+{
+       "getMessageServices",
+       "createMessage",
+       "sendMessage",
+       "loadMessageBody",
+       "loadMessageAttachment",
+       "sync",
+       "syncFolder",
+       "cancelOperation",
+       "addDraftMessage",
+       "findMessages",
+       "removeMessages",
+       "updateMessages",
+       "findConversations",
+       "removeConversations",
+       "findFolders",
+       "addMessagesChangeListener",
+       "addConversationsChangeListener",
+       "addFoldersChangeListener",
+       "removeChangeListener"
+};
+
+static WrtDeviceApis::Commons::FunctionMapping createMessagingFunctions();
+static WrtDeviceApis::Commons::FunctionMapping MessagingFunctions = createMessagingFunctions();
+
+DEFINE_FUNCTION_GETTER(Messaging, MessagingFunctions);
+
+static WrtDeviceApis::Commons::FunctionMapping createMessagingFunctions()
+{
+     /**
+     * Device capabilities
+     */
+
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_MESSAGING_READ, MESSAGING_DEVICE_CAP_READ);
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_MESSAGING_SEND, MESSAGING_DEVICE_CAP_SEND);
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_MESSAGING_WRITE, MESSAGING_DEVICE_CAP_WRITE);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_MESSAGING_READ);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_MESSAGING_READ, DEVICE_CAP_MESSAGING_READ);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_MESSAGING_SEND);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_MESSAGING_SEND, DEVICE_CAP_MESSAGING_SEND);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_MESSAGING_WRITE);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_MESSAGING_WRITE, DEVICE_CAP_MESSAGING_WRITE);
+
+    /**
+    * API features
+    */
+    ACE_CREATE_FEATURE(FEATURE_MESSAGING_READ, MESSAGING_FEATURE_API_READ);
+    ACE_CREATE_FEATURE(FEATURE_MESSAGING_SEND, MESSAGING_FEATURE_API_SEND);
+    ACE_CREATE_FEATURE(FEATURE_MESSAGING_WRITE, MESSAGING_FEATURE_API_WRITE);
+
+    ACE_CREATE_FEATURE_LIST(MESSAGING_FEATURES_MESSAGING_READ_SEND_WRITE);
+
+    ACE_ADD_API_FEATURE(MESSAGING_FEATURES_MESSAGING_READ_SEND_WRITE, FEATURE_MESSAGING_READ);
+    ACE_ADD_API_FEATURE(MESSAGING_FEATURES_MESSAGING_READ_SEND_WRITE, FEATURE_MESSAGING_SEND);
+    ACE_ADD_API_FEATURE(MESSAGING_FEATURES_MESSAGING_READ_SEND_WRITE, FEATURE_MESSAGING_WRITE);
+
+    ACE_CREATE_FEATURE_LIST(MESSAGING_FEATURES_MESSAGING_READ);
+    ACE_ADD_API_FEATURE(MESSAGING_FEATURES_MESSAGING_READ, FEATURE_MESSAGING_READ);
+
+    ACE_CREATE_FEATURE_LIST(MESSAGING_FEATURES_MESSAGING_SEND);
+    ACE_ADD_API_FEATURE(MESSAGING_FEATURES_MESSAGING_SEND, FEATURE_MESSAGING_SEND);
+
+    ACE_CREATE_FEATURE_LIST(MESSAGING_FEATURES_MESSAGING_WRITE);
+    ACE_ADD_API_FEATURE(MESSAGING_FEATURES_MESSAGING_WRITE, FEATURE_MESSAGING_WRITE);
+#if 0   
+    ACE_CREATE_FEATURE_LIST(MESSAGING_FEATURES_MESSAGING);
+    ACE_ADD_API_FEATURE(MESSAGING_FEATURES_MESSAGING, FEATURE_MESSAGING);
+
+    ACE_CREATE_FEATURE_LIST(MESSAGING_FEATURES_READ);
+    ACE_ADD_API_FEATURE(MESSAGING_FEATURES_READ, FEATURE_MESSAGING_READ);
+
+    ACE_CREATE_FEATURE_LIST(MESSAGING_FEATURES_SEND);
+    ACE_ADD_API_FEATURE(MESSAGING_FEATURES_SEND, FEATURE_MESSAGING_SEND);
+       
+    ACE_CREATE_FEATURE_LIST(MESSAGING_FEATURES_WRITE);
+    ACE_ADD_API_FEATURE(MESSAGING_FEATURES_WRITE, FEATURE_MESSAGING_WRITE);
+#endif
+    /**
+     * Functions
+     */
+
+     FunctionMapping MessagingFunctions;
+
+       //get Message Service
+       AceFunction getMessagingServiceFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_GET_MESSAGING_SERVICE],
+                       MESSAGING_FEATURES_MESSAGING_READ_SEND_WRITE,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert(std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_GET_MESSAGING_SERVICE],
+                       getMessagingServiceFunc));
+
+      /**  Read  **/
+    
+
+       AceFunction cancelOpFolderFunc = ACE_CREATE_FUNCTION(
+                         FUNCTION_GET_MGR_SERVICE,
+                         MessagingExportedNames[MESSAGING_FUNCTION_API_CANCEL_OPERATION],
+                         MESSAGING_FEATURES_MESSAGING_READ,
+                         EMPTY_DEVICE_LIST);
+         
+       MessagingFunctions.insert( std::make_pair(
+                         MessagingExportedNames[MESSAGING_FUNCTION_API_CANCEL_OPERATION],
+                         cancelOpFolderFunc));
+         
+      AceFunction findMessagesFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_MESSAGES],
+                       MESSAGING_FEATURES_MESSAGING_READ,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_MESSAGES],
+                       findMessagesFunc));
+
+      AceFunction findConversationsFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_CONVERSATIONS],
+                       MESSAGING_FEATURES_MESSAGING_READ,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_CONVERSATIONS],
+                       findConversationsFunc));
+
+      AceFunction findFoldersFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_FOLDERS],
+                       MESSAGING_FEATURES_MESSAGING_READ,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_FIND_FOLDERS],
+                       findFoldersFunc));
+
+      AceFunction addMessagesChangeListenerFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_MESSAGES_CHANGE_LISTNER],
+                       MESSAGING_FEATURES_MESSAGING_READ,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_MESSAGES_CHANGE_LISTNER],
+                       addMessagesChangeListenerFunc));
+
+      AceFunction addConversationsChangeListenerFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_CONVERSATIONS_CHANGE_LISTNER],
+                       MESSAGING_FEATURES_MESSAGING_READ,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_CONVERSATIONS_CHANGE_LISTNER],
+                       addConversationsChangeListenerFunc));
+
+      AceFunction addFoldersChangeListenerFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_FOLDERS_CHANGE_LISTNER],
+                       MESSAGING_FEATURES_MESSAGING_READ,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_FOLDERS_CHANGE_LISTNER],
+                       addFoldersChangeListenerFunc));
+
+      AceFunction removeChangeListenerFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CHANGE_LISTENER],
+                       MESSAGING_FEATURES_MESSAGING_READ,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CHANGE_LISTENER],
+                       removeChangeListenerFunc));
+
+
+       /**  Send  **/
+     //create Message
+     AceFunction createMessageFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_CREATE_MESSAGE],
+                       MESSAGING_FEATURES_MESSAGING_SEND,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_CREATE_MESSAGE],
+                       createMessageFunc));
+
+     AceFunction sendMessageFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_SEND_MESSAGE],
+                       MESSAGING_FEATURES_MESSAGING_SEND,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_SEND_MESSAGE],
+                       sendMessageFunc));
+       
+      /**  Write  **/
+          AceFunction loadMessageBodyFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_BODY],
+                       MESSAGING_FEATURES_MESSAGING_WRITE,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_BODY],
+                       loadMessageBodyFunc));      
+
+      AceFunction loadMessageAttachmentFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_ATTACHMENT],
+                       MESSAGING_FEATURES_MESSAGING_WRITE,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_LOAD_MESSAGE_ATTACHMENT],
+                       loadMessageAttachmentFunc));
+
+      AceFunction syncFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC],
+                       MESSAGING_FEATURES_MESSAGING_WRITE,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC],
+                       syncFunc));
+
+      AceFunction syncFolderFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC_FOLDER],
+                       MESSAGING_FEATURES_MESSAGING_WRITE,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_SYNC_FOLDER],
+                       syncFolderFunc));
+       
+     AceFunction addDraftMessageFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_DRAFT_MESSAGE],
+                       MESSAGING_FEATURES_MESSAGING_WRITE,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_ADD_DRAFT_MESSAGE],
+                       addDraftMessageFunc));
+       
+     AceFunction removeMessagesFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_MESSAGES],
+                       MESSAGING_FEATURES_MESSAGING_WRITE,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_MESSAGES],
+                       removeMessagesFunc));
+
+     AceFunction removeConversationsFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CONVERSATIONS],
+                       MESSAGING_FEATURES_MESSAGING_WRITE,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_REMOVE_CONVERSATIONS],
+                       removeConversationsFunc));
+
+     AceFunction updateMessagesFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_MGR_SERVICE,
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_UPDATE_MESSAGES],
+                       MESSAGING_FEATURES_MESSAGING_WRITE,
+                       EMPTY_DEVICE_LIST);
+       
+       MessagingFunctions.insert( std::make_pair(
+                       MessagingExportedNames[MESSAGING_FUNCTION_API_UPDATE_MESSAGES],
+                       updateMessagesFunc));   
+      
+    return MessagingFunctions;
+}
+
+
+}
+}
+
+#undef MESSAGING_FEATURE_API 
+#undef MESSAGING_FEATURE_API_READ 
+#undef MESSAGING_FEATURE_API_SEND 
+#undef MESSAGING_FEATURE_API_WRITE 
+#undef MESSAGING_DEVICE_CAP_READ 
+#undef MESSAGING_DEVICE_CAP_SEND 
+#undef MESSAGING_DEVICE_CAP_WRITE 
+
diff --git a/src/standards/Tizen/Messaging/plugin_config.h b/src/standards/Tizen/Messaging/plugin_config.h
new file mode 100755 (executable)
index 0000000..b312722
--- /dev/null
@@ -0,0 +1,62 @@
+//
+// 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 _MESSAGING_PLUGIN_CONFIG_H_
+#define _MESSAGING_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef enum 
+{
+MESSAGING_FUNCTION_API_GET_MESSAGING_SERVICE = 0,
+MESSAGING_FUNCTION_API_CREATE_MESSAGE,
+MESSAGING_FUNCTION_API_SEND_MESSAGE,
+MESSAGING_FUNCTION_API_LOAD_MESSAGE_BODY,
+MESSAGING_FUNCTION_API_LOAD_MESSAGE_ATTACHMENT,
+MESSAGING_FUNCTION_API_SYNC,
+MESSAGING_FUNCTION_API_SYNC_FOLDER,
+MESSAGING_FUNCTION_API_CANCEL_OPERATION,
+MESSAGING_FUNCTION_API_ADD_DRAFT_MESSAGE,
+MESSAGING_FUNCTION_API_FIND_MESSAGES,
+MESSAGING_FUNCTION_API_REMOVE_MESSAGES,
+MESSAGING_FUNCTION_API_UPDATE_MESSAGES,
+MESSAGING_FUNCTION_API_FIND_CONVERSATIONS,
+MESSAGING_FUNCTION_API_REMOVE_CONVERSATIONS,
+MESSAGING_FUNCTION_API_FIND_FOLDERS,
+MESSAGING_FUNCTION_API_ADD_MESSAGES_CHANGE_LISTNER,
+MESSAGING_FUNCTION_API_ADD_CONVERSATIONS_CHANGE_LISTNER,
+MESSAGING_FUNCTION_API_ADD_FOLDERS_CHANGE_LISTNER,
+MESSAGING_FUNCTION_API_REMOVE_CHANGE_LISTENER
+} MessagingFuncNames;
+
+extern const char* MessagingExportedNames[];
+
+DECLARE_FUNCTION_GETTER(Messaging);
+
+#define MESSAGING_CHECK_ACCESS(functionName)   \
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(        \
+    getMessagingFunctionData,                                              \
+    functionName)
+
+}
+}
+
+#endif //MESSAGING_PLUGIN_CONFIG_H_
+
diff --git a/src/standards/Tizen/Messaging/plugin_initializer.cpp b/src/standards/Tizen/Messaging/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..8802712
--- /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 <dpl/log/log.h>
+#include <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include "JSMessagingServiceManager.h"
+#include "JSMessagingStorage.h"
+#include "JSMessage.h"
+#include "JSMessageAttachment.h"
+#include "MessageAsyncCallbackManager.h"
+#include "MessageListenerManager.h"
+
+
+
+#define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
+#define OBJECT_MESSAGING ".messaging"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+void on_widget_start_callback(int widgetId) {
+       LogDebug("[Tizen\\MessagingServiceManager] on_widget_start_callback ("<<widgetId<<")");
+    Try {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    } Catch(Commons::Exception) {
+        LogError("WrtAccess initialization failed");
+    }
+}
+
+void on_widget_stop_callback(int widgetId) {
+       LogDebug("[Tizen\\MessagingServiceManager] on_widget_stop_callback ("<<widgetId<<")");
+    Try {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+    } Catch(Commons::Exception) {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+void on_frame_load_callback(const void * context)
+{
+    LogDebug("[Tizen\\contact] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LogDebug("[Tizen\\contact] on_frame_unload_callback (" << context << ")");
+
+    TizenApis::Tizen1_0::MessageAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+    TizenApis::Tizen1_0::MessageListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+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,
+               "messaging",
+               (js_class_template_getter)TizenApis::Tizen1_0::JSMessagingServiceManager::getClassRef,
+               NULL)
+       PLUGIN_CLASS_MAP_ADD_CLASS(
+               WRT_JS_EXTENSION_OBJECT_TIZEN,
+               "Message",
+               (js_class_template_getter)TizenApis::Tizen1_0::JSMessage::getClassRef,
+               NULL)
+
+       PLUGIN_CLASS_MAP_ADD_CLASS(
+               WRT_JS_EXTENSION_OBJECT_TIZEN,
+               "MessageAttachment",
+               (js_class_template_getter)TizenApis::Tizen1_0::JSMessageAttachment::getClassRef,
+               NULL)
+
+PLUGIN_CLASS_MAP_END
diff --git a/src/standards/Tizen/NFC/CMakeLists.txt b/src/standards/Tizen/NFC/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..3dc9460
--- /dev/null
@@ -0,0 +1,36 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-nfc")
+set(DESTINATION_NAME "tizen-2.0-nfc")
+
+include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_NFC})
+
+set(SRCS
+  ${SRCS_PLATFORM_API_NFC}
+  ${SRCS_PLATFORM_IMPLEMENTATION_NFC}
+  JSNFCManager.cpp
+  JSNFCAdapter.cpp
+  JSNFCTag.cpp
+       JSNdefMessage.cpp
+       JSNdefRecord.cpp
+       JSNdefRecordText.cpp
+       JSNdefRecordURI.cpp
+       JSNdefRecordMedia.cpp
+       JSNdefRecordArray.cpp
+       JSNFCTarget.cpp
+       NFCConverter.cpp
+       EventNFCChangedPrivateData.cpp
+  NFCStaticController.cpp
+  NFCAsyncCallbackManager.cpp
+  NFCListenerManager.cpp
+  ResponseDispatcher.cpp
+       plugin_initializer.cpp
+  plugin_config.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${LIBS_COMMON}
+  ${LIBS_PLATFORM_IMPLEMENTATION_NFC}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
diff --git a/src/standards/Tizen/NFC/EventNFCChangedPrivateData.cpp b/src/standards/Tizen/NFC/EventNFCChangedPrivateData.cpp
new file mode 100755 (executable)
index 0000000..cf3607d
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// 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 "EventNFCChangedPrivateData.h"
+
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+EventNFCChangedPrivateData::EventNFCChangedPrivateData(
+        const JSCallbackManagerPtr& callbackManager,
+        const JSCallbackManagerPtr& detachedCallbackManager) :
+    m_callbackManager(callbackManager),
+    m_detachedCallbackManager(detachedCallbackManager)
+{
+}
+
+JSCallbackManagerPtr EventNFCChangedPrivateData::getCallbackManager() const
+{
+    return m_callbackManager;
+}
+
+JSCallbackManagerPtr EventNFCChangedPrivateData::getDetachedCallbackManager()
+const
+{
+    return m_detachedCallbackManager;
+}
+}
+}
diff --git a/src/standards/Tizen/NFC/EventNFCChangedPrivateData.h b/src/standards/Tizen/NFC/EventNFCChangedPrivateData.h
new file mode 100755 (executable)
index 0000000..94a1d6c
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// 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_NFC_EVENTNFCCHANGEDPRIVATE_H_
+#define TIZEN_NFC_EVENTNFCCHANGEDPRIVATE_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class EventNFCChangedPrivateData : public WrtDeviceApis::Commons::IEventPrivateData
+{
+  public:
+    EventNFCChangedPrivateData(const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& callbackManager,
+            const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& detachedCallbackManager);
+
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getCallbackManager() const;
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr getDetachedCallbackManager() const;
+
+  private:
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_callbackManager;
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr m_detachedCallbackManager;
+};
+
+typedef DPL::SharedPtr<EventNFCChangedPrivateData> EventNFCChangedPrivateDataPtr;
+}
+}
+
+#endif //TIZEN_NFC_EVENTNFCCHANGEDPRIVATE_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/NFC/JSNFCAdapter.cpp b/src/standards/Tizen/NFC/JSNFCAdapter.cpp
new file mode 100755 (executable)
index 0000000..90863df
--- /dev/null
@@ -0,0 +1,699 @@
+//
+// 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 "JSNFCManager.h"
+#include "JSNFCAdapter.h"
+#include "JSNdefMessage.h"
+#include "JSNdefRecord.h"
+#include "NFCConverter.h"
+#include "NFCStaticController.h"
+#include "EventNFCChangedPrivateData.h"
+#include "NFCAsyncCallbackManager.h"
+#include "NFCListenerManager.h"
+
+#include <dpl/log/log.h>
+
+#include <string>
+#include <CommonsJavaScript/Validator.h>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <API/NFC/NFCFactory.h>
+#include <API/NFC/EventNFCChanged.h>
+#include "plugin_config.h"
+
+using namespace std;
+using namespace DPL;
+using namespace TizenApis::Api::NFC;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+#define TIZEN10_NFCADAPTER_ATTRIBUTENAME "NFCAdapter"
+#define TIZEN10_NFCADAPTER_POWERED "powered"
+#define TIZEN20_NFCADAPTER_SETYPE "seType"
+namespace TizenApis {
+namespace Tizen1_0 {
+
+ JSClassDefinition JSNFCAdapter::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       TIZEN10_NFCADAPTER_ATTRIBUTENAME,
+       0,
+       m_property,
+       m_function,
+       initialize,
+       finalize,
+       NULL, //hasProperty,
+       NULL,
+       NULL, //setProperty,
+       NULL, //DeleteProperty,
+       NULL, //GetPropertyNames,
+       NULL, //CallAsFunction,
+       NULL, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL  //ConvertToType
+};
+
+JSStaticValue JSNFCAdapter::m_property[] =
+{
+    //NFCAdapterProperties
+       {TIZEN10_NFCADAPTER_POWERED,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN20_NFCADAPTER_SETYPE,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSNFCAdapter::m_function[] = {
+       {"setTagListener",      JSNFCAdapter::setTagListener, kJSPropertyAttributeNone },
+       {"unsetTagListener",       JSNFCAdapter::unsetTagListener, kJSPropertyAttributeNone},
+       {"setPeerListener",      JSNFCAdapter::setPeerListener, kJSPropertyAttributeNone },
+       {"unsetPeerListener",       JSNFCAdapter::unsetPeerListener, kJSPropertyAttributeNone},
+       {"getCachedMessage", JSNFCAdapter::getCachedMessage, kJSPropertyAttributeNone},
+       {"setPowered",      JSNFCAdapter::setPowered, kJSPropertyAttributeNone },
+       {"setCardEmulation",      JSNFCAdapter::setCardEmulation, kJSPropertyAttributeNone },
+       {"setCardEmulationChangeListener",      JSNFCAdapter::setCardEmulationChangeListener, kJSPropertyAttributeNone },
+       {"unsetCardEmulationChangeListener",      JSNFCAdapter::unsetCardEmulationChangeListener, kJSPropertyAttributeNone },
+       { 0, 0, 0}
+};
+
+JSClassRef JSNFCAdapter::m_jsClassRef = JSClassCreate(JSNFCAdapter::getClassInfo());
+
+void JSNFCAdapter::initialize(JSContextRef context, JSObjectRef object)
+{
+       LogDebug("entered. Nothing to do");
+}
+
+void JSNFCAdapter::finalize(JSObjectRef object)
+{
+       NFCAdapterPrivObject* priv =
+               static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+JSObjectRef JSNFCAdapter::createJSObject(JSContextRef context) {
+       LogDebug("entered");
+
+       INFCAdapterPtr nfcAdapter(NFCFactory::getInstance().createNFCAdapterObject());
+       NFCAdapterPrivObject *priv = new NFCAdapterPrivObject(context, nfcAdapter);
+
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new a NFCTag object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassRef JSNFCAdapter::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNFCAdapter::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+JSValueRef JSNFCAdapter::getProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception)
+{
+       LogDebug("Enter");
+
+       Try     {
+               NFCConverter convert(context);
+
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCADAPTER_POWERED)) {
+                       NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(object));
+                       if (!privateObject) {
+                               LogError("private object is null");
+                               ThrowMsg(NullPointerException, "Private object not initialized");
+                       }
+                       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
+                       return convert.toJSValueRef(nfcAdapter->getPowerState());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN20_NFCADAPTER_SETYPE)) {
+                       AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_CARDEMULATION_FUNCS);
+                       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+                       NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(object));
+                       if (!privateObject) {
+                               LogError("private object is null");
+                               ThrowMsg(NullPointerException, "Private object not initialized");
+                       }
+                       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
+                       return convert.toJSValueRefSEType(nfcAdapter->getSEType());
+               }
+       } Catch (NullPointerException) {
+               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+       } Catch (UnsupportedException) {
+               LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (PlatformException) {
+               LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNFCAdapter::setTagListener (JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception) {
+       LogDebug("JSNFCAdapter::setTagListener Enter");
+
+       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);
+    
+       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);
+               }
+               else
+               {
+                       TagFilterPtr _filter (new TagFilter());
+                       tagFilter = _filter;
+               }
+
+               EventNFCChangedPrivateDataPtr privateData(
+                   new EventNFCChangedPrivateData(callbackManager,
+                                                   detachedCallbackManager)
+                   );
+               EventNFCChangedEmitterPtr emitter(new EventNFCChangedEmitter);
+               emitter->setListener(&NFCStaticController::getInstance());
+               emitter->setEventPrivateData(StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
+
+               if (nfcAdapter->setTagListener(emitter, tagFilter) != 0)
+                       Throw(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 (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) {
+               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 JSNFCAdapter::setPeerListener (JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception) {
+       LogDebug("JSNFCAdapter::setPeerListener Enter");
+
+       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");
+       }
+
+       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);
+
+       Try {
+               INFCAdapterPtr nfcAdapter(privateObject->getObject());
+
+               EventNFCChangedPrivateDataPtr privateData(
+                   new EventNFCChangedPrivateData(callbackManager,
+                                                   detachedCallbackManager)
+                   );
+
+               EventNFCChangedEmitterPtr emitter(new EventNFCChangedEmitter);
+               emitter->setListener(&NFCStaticController::getInstance());
+               emitter->setEventPrivateData(StaticPointerCast<EventNFCChanged::PrivateDataType>(privateData));
+
+               if (nfcAdapter->setPeerListener(emitter) != 0)
+                       Throw(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 (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) {
+               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 JSNFCAdapter::unsetTagListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
+       LogDebug("JSNFCAdapter::unsetNFCTagListener Enter");
+
+       AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_TAG_FUNCS);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       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() );
+
+               nfcAdapter->unsetTagListener();
+
+               NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(privateObject->getContext(), thisObject,  static_cast<long>(ID_NFCADAPTER_TAG_LISTENER)));
+               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
+               NFCListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+
+               return JSValueMakeUndefined(context);
+       } Catch (NullPointerException) {
+               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 (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSNFCAdapter::unsetPeerListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
+       LogDebug("JSNFCAdapter::unsetPeerListener Enter");
+
+       AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_P2P_FUNCS);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       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() );
+
+               nfcAdapter->unsetPeerListener();
+
+               NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(privateObject->getContext(), thisObject,  static_cast<long>(ID_NFCADAPTER_PEER_LISTENER)));
+               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
+               NFCListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+
+               return JSValueMakeUndefined(context);
+       } Catch (NullPointerException) {
+               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 (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSNFCAdapter::getCachedMessage (JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception) {
+       LogDebug("JSNFCAdapter::getCachedMessage Enter");
+
+       AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_COMMON_FUNCS);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       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());
+               void *cachedMessage = nfcAdapter->getCachedMessage();
+               if (cachedMessage != NULL)
+                       return JSNdefMessage::createJSObject(context, nfcAdapter->getCachedMessage());
+               return JSValueMakeNull(context);
+       } 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");
+}
+
+JSValueRef JSNFCAdapter::setPowered (JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception) {
+       LogDebug("Enter");
+
+       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];
+       }
+
+       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();
+
+       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, onErrorForCbm, true, true);
+
+       Try {
+               NFCConverter nfcConverter(context);
+               bool state = false;
+               state = nfcConverter.toBool(arguments[0]);
+
+               EventNFCChangedSetPoweredPtr event(new EventNFCChangedSetPowered(state));
+               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
+               event->setForAsynchronousCall(&NFCStaticController::getInstance());
+               nfcAdapter->setPowered(event);
+               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, global_context);
+               return JSValueMakeUndefined(context);
+       } Catch (ConversionException) {
+               LogError("ConversionException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
+               return JSValueMakeUndefined(context);
+       } Catch (UnknownException) {
+               LogError("UnknownException: " << _rethrown_exception.GetMessage());
+       } 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());
+       }
+       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNFCAdapter::setCardEmulation (JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception) {
+       LogDebug("Enter");
+
+       AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_CARDEMULATION_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])) {
+               /* And 2st 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])) {
+               /* 3nd 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];
+       }
+
+       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();
+
+       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, onErrorForCbm, true, true);
+
+       Try {
+               NFCConverter nfcConverter(context);
+               EventNFCSEType seType = NFC_SE_INVALID;
+               seType = nfcConverter.toSEType(arguments[0]);
+
+               EventNFCSetCardEmulationPtr event(new EventNFCSetCardEmulation(seType));
+               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
+               event->setForAsynchronousCall(&NFCStaticController::getInstance());
+               nfcAdapter->setCardEmulation(event);
+               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, global_context);
+               return JSValueMakeUndefined(context);
+       } Catch (ConversionException) {
+               LogError("ConversionException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
+               return JSValueMakeUndefined(context);
+       } Catch (UnknownException) {
+               LogError("UnknownException: " << _rethrown_exception.GetMessage());
+       } 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());
+       }
+       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNFCAdapter::setCardEmulationChangeListener (JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception) {
+       LogDebug("Entered ");
+
+       AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_CARDEMULATION_FUNCS);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       Validator validator(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");
+       }
+
+       JSValueRef onSuccessForCbm = NULL;
+       if (validator.isCallback(arguments[0])) {
+               onSuccessForCbm = arguments[0];
+       }
+
+       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();
+
+       INFCAdapterPtr nfcAdapter(privateObject->getObject() );
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(global_context, onSuccessForCbm, NULL, true, true);
+
+       Try {
+               EventNFCChangedCardEmulationEmitterPtr emitter(new EventNFCChangedCardEmulationEmitter);
+               emitter->setListener(&NFCStaticController::getInstance());
+               emitter->setEventPrivateData(StaticPointerCast<EventNFCChangedCardEmulation::PrivateDataType>(callbackManager));
+               nfcAdapter->setCardEmulationChangeListener(emitter);
+
+               NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(global_context, thisObject, static_cast<long>(ID_NFCADAPTER_CARDEMULATION_LISTENER)));
+               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
+               NFCListenerManagerSingleton::Instance().registerListener(listenerItem, global_context);
+
+               return JSValueMakeUndefined(context);
+       } Catch (ConversionException) {
+               LogError("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) {
+               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 JSNFCAdapter::unsetCardEmulationChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
+       LogDebug("JSNFCAdapter::unsetPeerListener Enter");
+
+       AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_CARDEMULATION_FUNCS);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       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());
+               nfcAdapter->unsetCardEmulationChangeListener();
+
+               NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(privateObject->getContext(), thisObject,  ID_NFCADAPTER_CARDEMULATION_LISTENER));
+               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
+               NFCListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+
+               return JSValueMakeUndefined(context);
+       } Catch (ConversionException) {
+               LogError("ConversionException");
+               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 (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+
+}
+}
diff --git a/src/standards/Tizen/NFC/JSNFCAdapter.h b/src/standards/Tizen/NFC/JSNFCAdapter.h
new file mode 100755 (executable)
index 0000000..499da35
--- /dev/null
@@ -0,0 +1,129 @@
+//
+// 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 _JS_TIZEN_NFCADAPTER_H_
+#define _JS_TIZEN_NFCADAPTER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <API/NFC/INFCAdapter.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::NFC::INFCAdapterPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> NFCAdapterPrivObject;
+class JSNFCAdapter
+{
+public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+    static JSObjectRef createJSObject(JSContextRef context);
+private:
+    /**
+     * 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;
+
+    /**
+     * 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);
+
+    /**
+     * Getters  for properties
+     */
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object,
+            JSStringRef propertyName, JSValueRef* exception);
+
+       static JSValueRef setTagListener(JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       static JSValueRef unsetTagListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+                       size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+       static JSValueRef setPeerListener(JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception);
+
+       static JSValueRef unsetPeerListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+                       size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+    static JSValueRef getCachedMessage(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 setCardEmulation(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+    static JSValueRef setCardEmulationChangeListener(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+    static JSValueRef unsetCardEmulationChangeListener(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+};
+
+}
+}
+
+#endif /* _JS_TIZEN_NFCADAPTER_H_ */
diff --git a/src/standards/Tizen/NFC/JSNFCManager.cpp b/src/standards/Tizen/NFC/JSNFCManager.cpp
new file mode 100755 (executable)
index 0000000..c97a275
--- /dev/null
@@ -0,0 +1,219 @@
+//
+// 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 "JSNFCManager.h"
+#include "JSNFCAdapter.h"
+#include "NFCConverter.h"
+
+#include <dpl/log/log.h>
+
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <API/NFC/NFCFactory.h>
+#include "plugin_config.h"
+
+using namespace std;
+using namespace DPL;
+using namespace TizenApis::Api::NFC;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+#define TIZEN10_NFCMANAGER_ATTRIBUTENAME "NFCManager"
+
+#define TIZEN10_NFCMANAGER_TNF_EMPTY "NFC_RECORD_TNF_EMPTY"
+#define TIZEN10_NFCMANAGER_TNF_WELL_KNOWN "NFC_RECORD_TNF_WELL_KNOWN"
+#define TIZEN10_NFCMANAGER_TNF_MIME_MEDIA "NFC_RECORD_TNF_MIME_MEDIA"
+#define TIZEN10_NFCMANAGER_TNF_URI "NFC_RECORD_TNF_URI"
+#define TIZEN10_NFCMANAGER_TNF_EXTERNAL_RTD  "NFC_RECORD_TNF_EXTERNAL_RTD"
+#define TIZEN10_NFCMANAGER_TNF_UNKNOWN  "NFC_RECORD_TNF_UNKNOWN"
+#define TIZEN10_NFCMANAGER_TNF_UNCHANGED "NFC_RECORD_TNF_UNCHANGED"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+ JSClassDefinition JSNFCManager::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       TIZEN10_NFCMANAGER_ATTRIBUTENAME,
+       0,
+       m_property,
+       m_function,
+       initialize,
+       finalize,
+       NULL, //hasProperty,
+       NULL,
+       NULL, //setProperty,
+       NULL, //DeleteProperty,
+       NULL, //GetPropertyNames,
+       NULL, //CallAsFunction,
+       NULL, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL  //ConvertToType
+};
+
+JSStaticValue JSNFCManager::m_property[] =
+{
+    //NFCManagerProperties
+       {TIZEN10_NFCMANAGER_TNF_EMPTY,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN10_NFCMANAGER_TNF_WELL_KNOWN,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN10_NFCMANAGER_TNF_MIME_MEDIA,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN10_NFCMANAGER_TNF_URI,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN10_NFCMANAGER_TNF_EXTERNAL_RTD,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN10_NFCMANAGER_TNF_UNKNOWN,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN10_NFCMANAGER_TNF_UNCHANGED,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSNFCManager::m_function[] = {
+       {"getDefaultAdapter",      JSNFCManager::getDefaultAdapter, kJSPropertyAttributeNone },
+       { 0, 0, 0}
+};
+
+JSClassRef JSNFCManager::m_jsClassRef = JSClassCreate(JSNFCManager::getClassInfo());
+
+void JSNFCManager::initialize(JSContextRef context, JSObjectRef object)
+{
+       LogDebug("entered");
+       NFCManagerPrivObject* priv = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Try {
+                       priv = new NFCManagerPrivObject(context);
+                       if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+                               LogError("Object can't store private data.");
+                               delete priv;
+                       }
+               } Catch (UnsupportedException) {
+                       LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
+               } Catch (UnknownException) {
+                       LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+               } Catch (PlatformException) {
+                       LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
+               } Catch (WrtDeviceApis::Commons::Exception) {
+                       LogError("Exception: " << _rethrown_exception.GetMessage());
+               }
+       }
+}
+
+void JSNFCManager::finalize(JSObjectRef object)
+{
+       LogDebug( "entered" );
+       NFCManagerPrivObject *priv = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(object));
+       if (priv) {
+               JSObjectSetPrivate(object, NULL);
+               LogDebug("Deleting NFC Manager object");
+               delete priv;
+       }
+}
+
+
+const JSClassRef JSNFCManager::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNFCManager::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+JSValueRef JSNFCManager::getProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception)
+{
+       LogDebug("Enter");
+
+       Try     {
+               Converter convert(context);
+
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_EMPTY)) {
+                       return convert.toJSValueRef(NFC_TNF_EMPTY);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_WELL_KNOWN)) {
+                       return convert.toJSValueRef(NFC_TNF_WELL_KNOWN);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_MIME_MEDIA)) {
+                       return convert.toJSValueRef(NFC_TNF_MIME_MEDIA);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_URI)) {
+                       return convert.toJSValueRef(NFC_TNF_URI);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_EXTERNAL_RTD)) {
+                       return convert.toJSValueRef(NFC_TNF_EXTERNAL_RTD);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_UNKNOWN)) {
+                       return convert.toJSValueRef(NFC_TNF_UNKNOWN);
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCMANAGER_TNF_UNCHANGED)) {
+                       return convert.toJSValueRef(NFC_TNF_UNCHANGED);
+               }
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+       } Catch (UnsupportedException) {
+               LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (PlatformException) {
+               LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNFCManager::getDefaultAdapter (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);
+
+               NFCManagerPrivObject* privateObject = static_cast<NFCManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("private object is null");
+                       ThrowMsg(UnsupportedException, "private object is null");
+               }
+               return JSNFCAdapter::createJSObject(privateObject->getContext());
+       } Catch (UnsupportedException) {
+               LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Not Supported");
+       } 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 (InvalidArgumentException) {
+               LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+       } Catch (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");
+}
+
+}
+}
diff --git a/src/standards/Tizen/NFC/JSNFCManager.h b/src/standards/Tizen/NFC/JSNFCManager.h
new file mode 100755 (executable)
index 0000000..27b8d38
--- /dev/null
@@ -0,0 +1,86 @@
+//
+// 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 _JS_TIZEN_NFCMANAGER_H_
+#define _JS_TIZEN_NFCMANAGER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <API/NFC/INFCAdapter.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<void, WrtDeviceApis::CommonsJavaScript::NoOwnership> NFCManagerPrivObject;
+class JSNFCManager
+{
+public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+private:
+    /**
+     * 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;
+
+    /**
+     * 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);
+
+    /**
+     * Getters  for properties
+     */
+    static JSValueRef getProperty(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);
+
+};
+
+}
+}
+
+#endif /* _JS_TIZEN_NFCMANAGER_H_ */
diff --git a/src/standards/Tizen/NFC/JSNFCTag.cpp b/src/standards/Tizen/NFC/JSNFCTag.cpp
new file mode 100755 (executable)
index 0000000..386cc7b
--- /dev/null
@@ -0,0 +1,436 @@
+//
+// 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 "JSNFCTag.h"
+#include "JSNdefMessage.h"
+#include "JSNFCManager.h"
+#include "NFCConverter.h"
+#include "ResponseDispatcher.h"
+#include <dpl/log/log.h>
+
+#include <CommonsJavaScript/Validator.h>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <API/NFC/NFCFactory.h>
+#include <API/NFC/EventTagAction.h>
+#include "NFCAsyncCallbackManager.h"
+#include "plugin_config.h"
+
+
+using namespace TizenApis::Api::NFC;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace DPL;
+
+#define TIZEN10_NFCTAG_ATTRIBUTENAME "NFCTag"
+
+#define TIZEN10_NFCTAG_TYPE "type"
+#define TIZEN10_NFCTAG_ISSUPPORTEDNDEF "isSupportedNDEF"
+#define TIZEN10_NFCTAG_NDEFSIZE "ndefSize"
+#define TIZEN10_NFCTAG_PROPERTIES "properties"
+#define TIZEN10_NFCTAG_ISCONNECTED "isConnected"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+ JSClassDefinition JSNFCTag::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    TIZEN10_NFCTAG_ATTRIBUTENAME,
+    0,
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL,
+    NULL, //setProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    hasInstance, //HasInstance,
+    NULL  //ConvertToType
+};
+
+JSStaticValue JSNFCTag::m_property[] =
+{
+    //NFCTagProperties
+    { TIZEN10_NFCTAG_TYPE, getProperty, 
+            NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN10_NFCTAG_ISSUPPORTEDNDEF, getProperty, 
+            NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN10_NFCTAG_NDEFSIZE, getProperty, 
+            NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN10_NFCTAG_PROPERTIES, getProperty, 
+            NULL, kJSPropertyAttributeReadOnly},
+    { TIZEN10_NFCTAG_ISCONNECTED, getProperty, 
+            NULL, kJSPropertyAttributeReadOnly},
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSNFCTag::m_function[] = {
+    {"readNDEF", JSNFCTag::readNDEF, kJSPropertyAttributeNone},
+    {"writeNDEF", JSNFCTag::writeNDEF, kJSPropertyAttributeNone},
+    {"transceive", JSNFCTag::transceive, kJSPropertyAttributeNone},
+    { 0, 0, 0}
+};
+
+JSClassRef JSNFCTag::m_jsClassRef = JSClassCreate(JSNFCTag::getClassInfo());
+
+JSObjectRef JSNFCTag::createJSObject(JSContextRef context, void *tagHandle) {
+       LogDebug("entered");
+
+       INFCTagPtr nfcTag = NFCFactory::getInstance().createNFCTagObject(tagHandle);
+       
+       NFCTagPrivObject *priv = new NFCTagPrivObject(context, nfcTag);
+
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new a NFCTag object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+void JSNFCTag::initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSNFCTag::finalize(JSObjectRef object)
+{
+       LogDebug( "entered" );
+       NFCTagPrivObject *priv = static_cast<NFCTagPrivObject*>( JSObjectGetPrivate( object ) ) ;
+       JSObjectSetPrivate(object, NULL);
+       LogDebug("Deleting NFCTag object");
+       delete priv;
+}
+
+
+const JSClassRef JSNFCTag::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNFCTag::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+JSValueRef JSNFCTag::getProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception)
+{
+       LogDebug("Enter");
+
+       Try     {
+               NFCTagPrivObject* privateObject = static_cast<NFCTagPrivObject*>(JSObjectGetPrivate(object));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               INFCTagPtr nfcTag(privateObject->getObject());
+               NFCConverter convert(context);
+
+               LogDebug("propertyName : " << convert.toString(propertyName));
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCTAG_TYPE)) {
+                       return convert.toJSValueRef(convert.toNfcTagTypeString(nfcTag->getTagType()));
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCTAG_ISSUPPORTEDNDEF)) {
+                       return convert.toJSValueRef(nfcTag->isNDEFSupport());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCTAG_NDEFSIZE)) {
+                       return convert.toJSValueRefLong(nfcTag->getNdefSize());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCTAG_PROPERTIES)) {
+                       LogDebug("get Properties");
+                       return convert.toJSValueRef(nfcTag->getProperties());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCTAG_ISCONNECTED)) {
+                       return convert.toJSValueRef(nfcTag->isConnected());
+               }
+       } Catch (NullPointerException) {
+               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (PlatformException) {
+               LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSNFCTag::hasInstance(JSContextRef context,
+        JSObjectRef constructor,
+        JSValueRef possibleInstance,
+        JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSNFCTag::readNDEF(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("Entered ");
+
+       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];
+               }
+       }
+
+       NFCTagPrivObject* privateObject = static_cast<NFCTagPrivObject*>(JSObjectGetPrivate(thisObject));
+       if (NULL == privateObject) {
+               LogError("private object is null");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       }
+
+       INFCTagPtr nfcTag(privateObject->getObject());
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
+    
+       Try {
+               EventTagActionReadPtr event(new EventTagActionRead());
+               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
+               event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
+
+               nfcTag->readNdef(event);
+               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, privateObject->getContext());
+               return JSValueMakeUndefined(context);
+       } Catch (ConversionException) {
+               LogError("readNDEF : ConversionException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (UnsupportedException) {
+               LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Not Support NDEF");
+       } Catch (InvalidArgumentException) {
+               LogError("readNDEF InvalidArgumentException");
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values"));
+               return JSValueMakeUndefined(context);
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
+               return JSValueMakeUndefined(context);
+       } Catch (UnknownException) {
+               LogError("UnknownException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNFCTag::writeNDEF(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("Entered ");
+
+       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];
+       }
+
+       NFCTagPrivObject* privateObject = static_cast<NFCTagPrivObject*>(JSObjectGetPrivate(thisObject));
+       if (NULL == privateObject) {
+               LogError("private object is null");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       }
+
+       INFCTagPtr nfcTag(privateObject->getObject());
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
+       Try {
+               EventTagActionWritePtr event(new EventTagActionWrite());
+               void *messageHandle = convert.getMessageHandle(arguments[0]);
+               event->writeNdef(messageHandle);
+               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
+               event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
+               nfcTag->writeNdef(event);
+               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, privateObject->getContext());
+               return JSValueMakeUndefined(context);
+       } Catch (ConversionException) {
+               LogError("writeNDEF : ConversionException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (UnsupportedException) {
+               LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Not Support NDEF");
+       } Catch (InvalidArgumentException) {
+               LogError("writeNDEF InvalidArgumentException");
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values"));
+               return JSValueMakeUndefined(context);
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
+               return JSValueMakeUndefined(context);
+       } Catch (UnknownException) {
+               LogError("UnknownException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNFCTag::transceive(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("Entered ");
+
+       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];
+       }
+
+       NFCTagPrivObject* privateObject = static_cast<NFCTagPrivObject*>(JSObjectGetPrivate(thisObject));
+       if (NULL == privateObject) {
+               LogError("private object is null");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       }
+
+       INFCTagPtr nfcTag(privateObject->getObject());
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
+       Try {
+               EventTagActionTransceivePtr event(new EventTagActionTransceive());
+               std::vector<unsigned char> 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());
+               return JSValueMakeUndefined(context);
+       } Catch (ConversionException) {
+               LogError("transceive : ConversionException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (InvalidArgumentException) {
+               LogError("transceive InvalidArgumentException");
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values"));
+               return JSValueMakeUndefined(context);
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
+               return JSValueMakeUndefined(context);
+       } Catch (UnknownException) {
+               LogError("UnknownException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
+       return JSValueMakeUndefined(context);
+}
+
+
+}
+}
diff --git a/src/standards/Tizen/NFC/JSNFCTag.h b/src/standards/Tizen/NFC/JSNFCTag.h
new file mode 100755 (executable)
index 0000000..a252294
--- /dev/null
@@ -0,0 +1,113 @@
+//
+// 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 _JS_TIZEN_NFCTAG_H_
+#define _JS_TIZEN_NFCTAG_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <API/NFC/INFCTag.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::NFC::INFCTagPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> NFCTagPrivObject;
+
+class JSNFCTag
+{
+public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+    static JSObjectRef createJSObject(JSContextRef context, void *tagHandle);
+
+private:
+    /**
+     * 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;
+
+    /**
+     * 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);
+
+    /**
+     * Getters for properties
+     */
+    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);
+
+    static JSValueRef readNDEF(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+       
+    static JSValueRef writeNDEF(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+       
+    static JSValueRef transceive(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+};
+
+}
+}
+
+#endif /* _JS_TIZEN_NFCTAG_H_ */
diff --git a/src/standards/Tizen/NFC/JSNFCTarget.cpp b/src/standards/Tizen/NFC/JSNFCTarget.cpp
new file mode 100755 (executable)
index 0000000..a320c73
--- /dev/null
@@ -0,0 +1,354 @@
+//
+// 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 "JSNFCTarget.h"
+#include "JSNFCManager.h"
+#include "JSNdefMessage.h"
+#include "NFCConverter.h"
+#include "ResponseDispatcher.h"
+#include "NFCAsyncCallbackManager.h"
+#include "NFCListenerManager.h"
+#include <dpl/log/log.h>
+
+#include <CommonsJavaScript/Validator.h>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <API/NFC/NFCFactory.h>
+#include <API/NFC/EventTargetAction.h>
+
+#include "plugin_config.h"
+
+
+using namespace TizenApis::Api::NFC;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace DPL;
+
+#define TIZEN10_NFCTARGET_ATTRIBUTENAME "NFCTarget"
+
+#define TIZEN10_NFCTARGET_ISCONNECTED "isConnected"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+ JSClassDefinition JSNFCTarget::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    TIZEN10_NFCTARGET_ATTRIBUTENAME,
+    0,
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL,
+    NULL, //setProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    hasInstance, //HasInstance,
+    NULL  //ConvertToType
+};
+
+JSStaticValue JSNFCTarget::m_property[] =
+{
+    //NFCTargetProperties
+    { TIZEN10_NFCTARGET_ISCONNECTED, getProperty,
+            NULL, kJSPropertyAttributeReadOnly},
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSNFCTarget::m_function[] = {
+    {"setReceiveNDEFListener", JSNFCTarget::setReceiveNDEFListener, kJSPropertyAttributeNone},
+    {"unsetReceiveNDEFListener", JSNFCTarget::unsetReceiveNDEFListener, kJSPropertyAttributeNone},
+    {"sendNDEF", JSNFCTarget::sendNDEF, kJSPropertyAttributeNone},
+    { 0, 0, 0}
+};
+
+JSClassRef JSNFCTarget::m_jsClassRef = JSClassCreate(JSNFCTarget::getClassInfo());
+
+JSObjectRef JSNFCTarget::createJSObject(JSContextRef context, void *tagHandle) {
+       LogDebug("entered");
+
+       INFCTargetPtr nfcTarget = NFCFactory::getInstance().createNFCTargetObject(tagHandle);
+
+       NFCTargetPrivObject *priv = new NFCTargetPrivObject(context, nfcTarget);
+
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new a NFCTarget object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+void JSNFCTarget::initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSNFCTarget::finalize(JSObjectRef object)
+{
+       LogDebug( "entered" );
+       NFCTargetPrivObject *priv = static_cast<NFCTargetPrivObject*>( JSObjectGetPrivate( object ) ) ;
+       JSObjectSetPrivate(object, NULL);
+       LogDebug("Deleting timezone object");
+       delete priv;
+}
+
+
+const JSClassRef JSNFCTarget::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNFCTarget::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+JSValueRef JSNFCTarget::getProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception)
+{
+       LogDebug("Enter");
+
+       Try     {
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NFCTARGET_ISCONNECTED)) {
+                       NFCTargetPrivObject* privateObject = static_cast<NFCTargetPrivObject*>(JSObjectGetPrivate(object));
+                       if (!privateObject) {
+                               LogError("Private object is not set.");
+                               ThrowMsg(NullPointerException, "Private object not initialized");
+                       }
+
+                       INFCTargetPtr nfcTarget(privateObject->getObject());
+                       NFCConverter convert(context);
+                       return convert.toJSValueRef(nfcTarget->isConnected());
+               }
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+       } Catch (NullPointerException) {
+               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (PlatformException) {
+               LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSNFCTarget::hasInstance(JSContextRef context,
+        JSObjectRef constructor,
+        JSValueRef possibleInstance,
+        JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSNFCTarget::setReceiveNDEFListener(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("Entered ");
+
+       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];
+       }
+
+       NFCTargetPrivObject* privateObject = static_cast<NFCTargetPrivObject*>(JSObjectGetPrivate(thisObject));
+       if (NULL == privateObject) {
+               LogError("private object is null");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       }
+       
+       INFCTargetPtr nfcTarget(privateObject->getObject());
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, NULL, true, true);
+       Try {
+
+               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)));
+               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
+               NFCListenerManagerSingleton::Instance().registerListener(listenerItem, privateObject->getContext());
+
+               return JSValueMakeUndefined(context);
+       } 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) {
+               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 JSNFCTarget::unsetReceiveNDEFListener(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("Entered ");
+       Try {
+               AceSecurityStatus status = NFC_CHECK_ACCESS(NFC_FUNCTION_API_P2P_FUNCS);
+               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               NFCTargetPrivObject* privateObject = static_cast<NFCTargetPrivObject*>(JSObjectGetPrivate(thisObject));
+               if (NULL == privateObject) {
+                       LogError("private object is null");
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               }
+
+               INFCTargetPtr nfcTarget(privateObject->getObject());
+               nfcTarget->unsetReceiveNDEFListener();
+
+               NFCListenerCancellerPtr canceller = NFCListenerCancellerPtr(new NFCListenerCanceller(privateObject->getContext(), thisObject,  static_cast<long>(ID_NFCPEER_RECEIVENDEF_LISTENER)));
+               IListenerItemPtr listenerItem = StaticPointerCast<IListenerItem>(canceller);
+               NFCListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+
+               return JSValueMakeUndefined(context);
+       } Catch (UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               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 (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSNFCTarget::sendNDEF(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("Entered ");
+
+       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) {
+        /* 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) {
+               LogError("private object is null");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       }
+
+       INFCTargetPtr nfcTarget(privateObject->getObject());
+       JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(privateObject->getContext(), onSuccessForCbm, onErrorForCbm, true, true);
+       Try {
+               void *messageHandle = convert.getMessageHandle(arguments[0]);
+               EventTargetActionSendPtr event(new EventTargetActionSend(messageHandle));
+               event->setPrivateData( StaticPointerCast<IEventPrivateData>(callbackManager) );
+               event->setForAsynchronousCall(&NFCResponseDispatcher::getInstance());
+               nfcTarget->sendNDEF(event);
+               NFCAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, privateObject->getContext());
+               return JSValueMakeUndefined(context);
+       } Catch (ConversionException) {
+               LogError("sendNDEF : ConversionException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (InvalidArgumentException) {
+               LogError("sendNDEF InvalidArgumentException");
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values"));
+               return JSValueMakeUndefined(context);
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available"));
+               return JSValueMakeUndefined(context);
+       } Catch (UnknownException) {
+               LogError("UnknownException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR,"Unknown Error"));
+       return JSValueMakeUndefined(context);
+}
+
+}
+}
diff --git a/src/standards/Tizen/NFC/JSNFCTarget.h b/src/standards/Tizen/NFC/JSNFCTarget.h
new file mode 100755 (executable)
index 0000000..40e46e0
--- /dev/null
@@ -0,0 +1,112 @@
+//
+// 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 _JS_TIZEN_NFCTARGET_H_
+#define _JS_TIZEN_NFCTARGET_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <API/NFC/INFCTarget.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::NFC::INFCTargetPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> NFCTargetPrivObject;
+
+class JSNFCTarget
+{
+public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+    static JSObjectRef createJSObject(JSContextRef context, void *tagHandle);
+
+private:
+    /**
+     * 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;
+
+    /**
+     * 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);
+
+    /**
+     * Getters and setters for properties
+     */
+    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);
+
+    static JSValueRef setReceiveNDEFListener(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+    static JSValueRef unsetReceiveNDEFListener(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+    static JSValueRef sendNDEF(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+};
+
+}
+}
+
+#endif /* _JS_TIZEN_NFCTARGET_H_ */
diff --git a/src/standards/Tizen/NFC/JSNdefMessage.cpp b/src/standards/Tizen/NFC/JSNdefMessage.cpp
new file mode 100755 (executable)
index 0000000..6826709
--- /dev/null
@@ -0,0 +1,387 @@
+//
+// 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 "JSNdefMessage.h"
+#include "JSNdefRecord.h"
+#include "JSNdefRecordText.h"
+#include "JSNdefRecordURI.h"
+#include "JSNdefRecordMedia.h"
+#include "JSNdefRecordArray.h"
+#include "NFCConverter.h"
+
+#include <dpl/log/log.h>
+
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <API/NFC/NFCFactory.h>
+#include "plugin_config.h"
+
+using namespace TizenApis::Api::NFC;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+#define TIZEN10_NDEFMESSAGE_ATTRIBUTENAME "NDEFMessage"
+#define TIZEN10_NDEFMESSAGE_RECORDCOUNT "recordCount"
+#define TIZEN10_NDEFMESSAGE_RECORDS "records"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+ JSClassDefinition JSNdefMessage::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    TIZEN10_NDEFMESSAGE_ATTRIBUTENAME,
+    0,
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL,
+    setProperty, //setProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    constructor, //CallAsConstructor,
+    hasInstance, //HasInstance,
+    NULL  //ConvertToType
+};
+
+JSStaticValue JSNdefMessage::m_property[] =
+{
+    //NdefMessageProperties
+    { TIZEN10_NDEFMESSAGE_RECORDCOUNT, getProperty,
+            NULL, kJSPropertyAttributeReadOnly},
+     { TIZEN10_NDEFMESSAGE_RECORDS, getProperty,
+            setProperty, kJSPropertyAttributeNone},
+    { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSNdefMessage::m_function[] = {
+    {"toByte", JSNdefMessage::toByte, kJSPropertyAttributeNone},
+    { 0, 0, 0}
+};
+
+JSClassRef JSNdefMessage::m_jsClassRef = JSClassCreate(JSNdefMessage::getClassInfo());
+
+JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, void *messageHandle) {
+       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);
+}
+
+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);
+}
+
+JSObjectRef JSNdefMessage::createJSObject(JSContextRef context, INdefMessagePtr message) {
+       LogDebug("entered");
+
+       NdefMessagePrivObject *priv = new NdefMessagePrivObject(context, message);
+
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new a NdefMessage object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+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);
+}
+
+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);
+}
+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;
+}
+
+
+const JSClassRef JSNdefMessage::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNdefMessage::getClassInfo()
+{
+       return &m_classInfo;
+}
+
+JSObjectRef JSNdefMessage::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+       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");
+
+                       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))
+                                               isRecordArray = true;
+                                       else
+                                               isByteArray = true;
+                                       if (isRecordArray && isByteArray)
+                                               break;
+                               }
+                               if (isRecordArray && isByteArray)
+                                       ThrowMsg(ConversionException, "Parameter's type is not matched");
+                               else if (isRecordArray)
+                                       return createJSObject(ctx, convert.toVectorOfRecordHandles(arguments[0]));
+                               else
+                                       return createJSObject(ctx, convert.toVectorOfUChars(arguments[0]));
+                       } else
+                               return createJSObject(ctx);
+               }
+       } Catch(ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return NULL;
+       } Catch (InvalidArgumentException) {
+               LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               return NULL;
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               return NULL;
+       } Catch (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;
+}
+
+JSValueRef JSNdefMessage::getProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception)
+{
+       LogDebug("Enter");
+
+       Try     {
+               NdefMessagePrivObject* privateObject = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               INdefMessagePtr ndefMessage(privateObject->getObject());
+               NFCConverter convert(context);
+
+               LogDebug("propertyName : " << convert.toString(propertyName));
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFMESSAGE_RECORDCOUNT)) {
+                       return convert.toJSValueRefLong(ndefMessage->getRecordCount());
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFMESSAGE_RECORDS)) {
+                       return JSNdefRecordArray::createArray(context, ndefMessage);
+               }
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+       } Catch (NullPointerException) {
+               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (PlatformException) {
+               LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSNdefMessage::setProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef value,  JSValueRef* exception)
+{
+       LogDebug("Enter");
+
+       Try     {
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFMESSAGE_RECORDS)) {
+                       NdefMessagePrivObject* privateObject = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(object));
+                       if (!privateObject) {
+                               LogError("Private object is not set.");
+                               ThrowMsg(NullPointerException, "Private object not initialized");
+                       }
+
+                       NFCConverter convert(context);
+
+                       if (JSValueIsNull(context, value) || JSValueIsUndefined(context, value) || !(JSIsArrayValue(context, value) || JSNdefRecordArray::isObjectOfClass(context, value))) {
+                               LogError("value is invald.");
+                               ThrowMsg(ConversionException, "value is invald.");
+                       }
+
+                       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) {
+               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,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("Entered ");
+       Try {
+               NdefMessagePrivObject* privateObject = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (NULL == privateObject) {
+                       LogError("private object is null");
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               }
+
+               INdefMessagePtr ndefMessage(privateObject->getObject());
+               NFCConverter convert(context);
+
+               return convert.toJSValueRef(ndefMessage->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");
+}
+
+}
+}
diff --git a/src/standards/Tizen/NFC/JSNdefMessage.h b/src/standards/Tizen/NFC/JSNdefMessage.h
new file mode 100755 (executable)
index 0000000..4bc5765
--- /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 _JS_TIZEN_NDEFMESSAGE_H_
+#define _JS_TIZEN_NDEFMESSAGE_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <API/NFC/INdefMessage.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::NFC::INdefMessagePtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> NdefMessagePrivObject;
+
+class JSNdefMessage
+{
+public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+    static JSObjectRef createJSObject(JSContextRef context);
+    static JSObjectRef createJSObject(JSContextRef context, void *messageHandle);
+    static JSObjectRef createJSObject(JSContextRef context, Api::NFC::INdefMessagePtr message);
+    static JSObjectRef createJSObject(JSContextRef context, std::vector<void *> ndefRcords);
+    static JSObjectRef createJSObject(JSContextRef context, std::vector<unsigned char> rawdata);
+
+private:
+    /**
+     * 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;
+
+    /**
+     * 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 JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+    /**
+     * Getters and setters for properties
+     */
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object,
+            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,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+};
+
+}
+}
+
+#endif /* _JS_TIZEN_NDEFMESSAGE_H_ */
diff --git a/src/standards/Tizen/NFC/JSNdefRecord.cpp b/src/standards/Tizen/NFC/JSNdefRecord.cpp
new file mode 100755 (executable)
index 0000000..d9fb295
--- /dev/null
@@ -0,0 +1,274 @@
+//
+// 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 <memory>
+#include <string>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSUtils.h>
+
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include <API/NFC/NFCFactory.h>
+
+#include "JSNdefRecord.h"
+#include "plugin_config.h"
+#include "NFCConverter.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace Api::NFC;
+
+#define TIZEN10_NDEFRECORD_TNF "tnf"
+#define TIZEN10_NDEFRECORD_TYPE "type"
+#define TIZEN10_NDEFRECORD_ID "id"
+#define TIZEN10_NDEFRECORD_PAYLOAD "payload"
+
+JSClassDefinition JSNdefRecord::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "NDEFRecord",
+       0,
+       m_property,
+       NULL,
+       initialize,
+       finalize,
+       NULL, //HasProperty,
+       NULL,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //GetPropertyNames,
+       NULL, //CallAsFunction,
+       constructor, //CallAsConstructor,
+       hasInstance,
+       NULL, //ConvertToType
+};
+
+JSStaticValue JSNdefRecord::m_property[] =
+{
+       {TIZEN10_NDEFRECORD_TNF,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN10_NDEFRECORD_TYPE,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN10_NDEFRECORD_ID,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN10_NDEFRECORD_PAYLOAD,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSNdefRecord::getClassRef() {
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNdefRecord::getClassInfo() {
+       return &m_classInfo;
+}
+
+JSClassRef JSNdefRecord::m_jsClassRef = JSClassCreate(JSNdefRecord::getClassInfo());
+
+JSObjectRef JSNdefRecord::createJSObject(JSContextRef context, const NdefRecordData &ndefRecordData) {
+       LogDebug("Entered");
+       return createJSObject(context, ndefRecordData.properties, ndefRecordData.payload);
+}
+
+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);
+}
+
+JSObjectRef JSNdefRecord::createJSObject(JSContextRef context, std::vector<unsigned char> rawdata) {
+       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(rawdata);
+
+       NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
+
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+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;
+}
+
+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");
+               }
+
+               NFCConverter convert(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]);
+               }
+
+               return createJSObject(ctx, prop, convert.toVectorOfUChars(arguments[2]));
+
+       } Catch(ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return NULL;
+       } Catch (InvalidArgumentException) {
+               LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               return NULL;
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               return NULL;
+       } Catch (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;
+}
+
+JSValueRef JSNdefRecord::getProperty(JSContextRef context, JSObjectRef object,
+       JSStringRef propertyName, JSValueRef* exception) {
+       LogDebug("Enter");
+
+       Try     {
+               NFCConverter convert(context);
+               NdefRecordPrivObject *priv = static_cast<NdefRecordPrivObject*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       ThrowMsg(NullPointerException, "Private object not set.");
+               }
+               INdefRecordPtr ndefRecord = priv->getObject();
+
+               LogDebug("propertyName : " << convert.toString(propertyName));
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFRECORD_TNF))
+                       return convert.toJSValueRef(ndefRecord->getTNF());
+               else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFRECORD_TYPE))
+                       return convert.toJSValueRef(ndefRecord->getTypeName());
+               else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFRECORD_ID))
+                       return convert.toJSValueRef(ndefRecord->getID());
+               else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFRECORD_PAYLOAD))
+                       return convert.toJSValueRef(ndefRecord->getPayload());
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (PlatformException) {
+               LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (NullPointerException) {
+               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       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");
+}
+
+} //Tizen1_0
+} //TizenApis
+
diff --git a/src/standards/Tizen/NFC/JSNdefRecord.h b/src/standards/Tizen/NFC/JSNdefRecord.h
new file mode 100755 (executable)
index 0000000..ab60a38
--- /dev/null
@@ -0,0 +1,96 @@
+//
+// 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_H_
+#define WRTPLUGINS_TIZEN_JS_NDEFRECORD_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/NFC/INdefRecord.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<Api::NFC::INdefRecordPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> NdefRecordPrivObject;
+
+class JSNdefRecord
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       static JSObjectRef createJSObject(JSContextRef context, 
+               const Api::NFC::NdefRecordData &ndefRecordData);
+       static JSObjectRef createJSObject(JSContextRef context, 
+               const Api::NFC::NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+       static JSObjectRef createJSObject(JSContextRef context, 
+               std::vector<unsigned char> rawdata);
+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 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.
+     */
+       static JSClassDefinition m_classInfo;
+       
+       /**
+     * This structure describes a statically declared value property.
+     */
+       static JSStaticValue m_property[];
+
+       static JSClassRef m_jsClassRef;
+
+    static JSValueRef toByte(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+};
+
+} //Tizen1_0
+} //TizenApis
+
+#endif
+
diff --git a/src/standards/Tizen/NFC/JSNdefRecordArray.cpp b/src/standards/Tizen/NFC/JSNdefRecordArray.cpp
new file mode 100755 (executable)
index 0000000..ba46f60
--- /dev/null
@@ -0,0 +1,768 @@
+//
+// 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 <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "JSNdefRecordArray.h"
+#include "JSNdefMessage.h"
+#include "NFCConverter.h"
+#include <API/NFC/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 TizenApis {
+namespace Tizen1_0 {
+using namespace TizenApis::Commons;
+using namespace Api::NFC;
+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/standards/Tizen/NFC/JSNdefRecordArray.h b/src/standards/Tizen/NFC/JSNdefRecordArray.h
new file mode 100755 (executable)
index 0000000..fe88133
--- /dev/null
@@ -0,0 +1,176 @@
+//
+// 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 <API/NFC/INdefMessage.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+class JSNdefRecordArray
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static JSClassRef getClassRef();
+
+    static JSObjectRef createArray(JSContextRef context,
+            const Api::NFC::INdefMessagePtr &recordArray);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static Api::NFC::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
diff --git a/src/standards/Tizen/NFC/JSNdefRecordMedia.cpp b/src/standards/Tizen/NFC/JSNdefRecordMedia.cpp
new file mode 100755 (executable)
index 0000000..a5f5367
--- /dev/null
@@ -0,0 +1,207 @@
+//
+// 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 <memory>
+#include <string>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSUtils.h>
+
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include <API/NFC/NFCFactory.h>
+
+#include "JSNdefRecordMedia.h"
+#include "NFCConverter.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace Api::NFC;
+
+#define TIZEN10_NDEFRECORD_MEDIA_MIMETYPE "mimeType"
+
+JSClassDefinition JSNdefRecordMedia::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "NDEFRecordMedia",
+       JSNdefRecord::getClassRef(),
+       m_property,
+       NULL,
+       initialize,
+       finalize,
+       NULL, //HasProperty,
+       NULL,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //GetPropertyNames,
+       NULL, //CallAsFunction,
+       constructor, //CallAsConstructor,
+       hasInstance,
+       NULL, //ConvertToType
+};
+
+JSStaticValue JSNdefRecordMedia::m_property[] =
+{
+       {TIZEN10_NDEFRECORD_MEDIA_MIMETYPE,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSNdefRecordMedia::getClassRef() {
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNdefRecordMedia::getClassInfo() {
+       return &m_classInfo;
+}
+
+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);
+}
+
+JSObjectRef JSNdefRecordMedia::createJSObject(JSContextRef context, const std::string &mimeType, std::vector<unsigned char> data) {
+       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(mimeType, data);
+
+       NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
+
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+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;
+               }
+       }
+}
+
+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)
+{
+       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");
+               }
+
+               Converter convert(ctx);
+               return createJSObject(ctx, convert.toString(arguments[0]), convert.toVectorOfUChars(arguments[1]));
+       } Catch(ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return NULL;
+       } Catch (InvalidArgumentException) {
+               LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               return NULL;
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               return NULL;
+       } Catch (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;
+
+}
+
+JSValueRef JSNdefRecordMedia::getProperty(JSContextRef context, JSObjectRef object,
+       JSStringRef propertyName, JSValueRef* exception) {
+       LogDebug("Enter");
+
+       Try     {
+               NFCConverter convert(context);
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFRECORD_MEDIA_MIMETYPE)) {
+                       NdefRecordPrivObject *priv = static_cast<NdefRecordPrivObject*>(JSObjectGetPrivate(object));
+                       if (!priv) {
+                               ThrowMsg(NullPointerException, "Private object not set.");
+                       }
+                       INdefRecordPtr ndefRecord = priv->getObject();
+                       char * mimeType = NULL;
+                       if (ndefRecord->getMimeType(&mimeType)) {
+                               std::string result(mimeType);
+                               free(mimeType);
+                               LogDebug("mimeType : " << result);
+                               return convert.toJSValueRef(result);
+                       }
+                       LogDebug("This record is not MEDIA Type");
+               }
+
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (PlatformException) {
+               LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (NullPointerException) {
+               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSNdefRecordMedia::hasInstance(JSContextRef context,
+        JSObjectRef constructor,
+        JSValueRef possibleInstance,
+        JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+} //Tizen1_0
+} //TizenApis
+
diff --git a/src/standards/Tizen/NFC/JSNdefRecordMedia.h b/src/standards/Tizen/NFC/JSNdefRecordMedia.h
new file mode 100755 (executable)
index 0000000..a114a60
--- /dev/null
@@ -0,0 +1,84 @@
+//
+// 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_MEDIA_H_
+#define WRTPLUGINS_TIZEN_JS_NDEFRECORD_MEDIA_H_
+
+#include "JSNdefRecord.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+class JSNdefRecordMedia
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       static JSObjectRef createJSObject(JSContextRef context, 
+               const Api::NFC::NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+
+       static JSObjectRef createJSObject(JSContextRef context, 
+               const std::string &mimeType, std::vector<unsigned char> data);
+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 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.
+     */
+       static JSClassDefinition m_classInfo;
+
+       /**
+     * This structure describes a statically declared value property.
+     */
+       static JSStaticValue m_property[];
+
+       static JSClassRef m_jsClassRef;
+
+};
+
+} //Tizen1_0
+} //TizenApis
+
+#endif
+
diff --git a/src/standards/Tizen/NFC/JSNdefRecordText.cpp b/src/standards/Tizen/NFC/JSNdefRecordText.cpp
new file mode 100755 (executable)
index 0000000..1df4ef2
--- /dev/null
@@ -0,0 +1,238 @@
+//
+// 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 <memory>
+#include <string>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSUtils.h>
+
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include <API/NFC/NFCFactory.h>
+
+#include "JSNdefRecordText.h"
+#include "NFCConverter.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace Api::NFC;
+
+#define TIZEN10_NDEFRECORD_TEXT_TEXT "text"
+#define TIZEN10_NDEFRECORD_TEXT_LANGCODE "languageCode"
+#define TIZEN10_NDEFRECORD_TEXT_ENCODING "encoding"
+
+JSClassDefinition JSNdefRecordText::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "NDEFRecordText",
+       JSNdefRecord::getClassRef(),
+       m_property,
+       NULL,
+       initialize,
+       finalize,
+       NULL, //HasProperty,
+       NULL,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //GetPropertyNames,
+       NULL, //CallAsFunction,
+       constructor, //CallAsConstructor,
+       hasInstance,
+       NULL, //ConvertToType
+};
+
+JSStaticValue JSNdefRecordText::m_property[] =
+{
+       {TIZEN10_NDEFRECORD_TEXT_TEXT,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN10_NDEFRECORD_TEXT_LANGCODE,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       {TIZEN10_NDEFRECORD_TEXT_ENCODING,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSNdefRecordText::getClassRef() {
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNdefRecordText::getClassInfo() {
+       return &m_classInfo;
+}
+
+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);
+}
+
+JSObjectRef JSNdefRecordText::createJSObject(JSContextRef context, const std::string &text, const std::string &langCode, const short encodeType) {
+       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(text, langCode, encodeType);
+
+       NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
+
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+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)
+{
+       LogDebug("entered");
+
+       Try {
+               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);
+       } Catch(ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return NULL;
+       } Catch (InvalidArgumentException) {
+               LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               return NULL;
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               return NULL;
+       } Catch (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;
+
+}
+JSValueRef JSNdefRecordText::getProperty(JSContextRef context, JSObjectRef object,
+       JSStringRef propertyName, JSValueRef* exception) {
+       LogDebug("Enter");
+
+       Try     {
+               NFCConverter convert(context);
+               NdefRecordPrivObject *priv = static_cast<NdefRecordPrivObject*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       ThrowMsg(NullPointerException, "Private object not set.");
+               }
+               INdefRecordPtr ndefRecord = priv->getObject();
+
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFRECORD_TEXT_TEXT)) {
+                       char * text = NULL;
+                       if (ndefRecord->getText(&text)) {
+                               std::string result(text);
+                               free(text);
+                               LogDebug("text : " << result);
+                               return convert.toJSValueRef(result);
+                       }
+                       LogDebug("This record is not Text Type");
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFRECORD_TEXT_LANGCODE)) {
+                       char * langCode = NULL;
+                       if (ndefRecord->getLangCode(&langCode)) {
+                               std::string result(langCode);
+                               free(langCode);
+                               LogDebug("langCode : " << result);
+                               return convert.toJSValueRef(result);
+                       }
+                       LogDebug("This record is not Text Type");
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFRECORD_TEXT_ENCODING)) {
+                       nfcTextEncodeUTF encodeType = NFC_TEXT_ENCODE_UTF_16;
+                       if (ndefRecord->getEncodeType(&encodeType)) {
+                               LogDebug("encodeType : " << encodeType);
+                               return convert.toJSValueRef(convert.toNfcTextEncodeUTFString(encodeType));
+                       }
+                       LogDebug("This record is not Text Type");
+               }
+
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (PlatformException) {
+               LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (NullPointerException) {
+               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSNdefRecordText::hasInstance(JSContextRef context,
+        JSObjectRef constructor,
+        JSValueRef possibleInstance,
+        JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+} //Tizen1_0
+} //TizenApis
+
diff --git a/src/standards/Tizen/NFC/JSNdefRecordText.h b/src/standards/Tizen/NFC/JSNdefRecordText.h
new file mode 100755 (executable)
index 0000000..4b7ef55
--- /dev/null
@@ -0,0 +1,84 @@
+//
+// 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_TEXT_H_
+#define WRTPLUGINS_TIZEN_JS_NDEFRECORD_TEXT_H_
+
+#include "JSNdefRecord.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+class JSNdefRecordText
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       static JSObjectRef createJSObject(JSContextRef context, 
+               const Api::NFC::NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+
+       static JSObjectRef createJSObject(JSContextRef context, const std::string &text, 
+               const std::string &langCode, const short encodeType);
+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 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.
+     */
+       static JSClassDefinition m_classInfo;
+
+       /**
+     * This structure describes a statically declared value property.
+     */
+       static JSStaticValue m_property[];
+
+       static JSClassRef m_jsClassRef;
+
+};
+
+} //Tizen1_0
+} //TizenApis
+
+#endif
+
diff --git a/src/standards/Tizen/NFC/JSNdefRecordURI.cpp b/src/standards/Tizen/NFC/JSNdefRecordURI.cpp
new file mode 100755 (executable)
index 0000000..e50bb66
--- /dev/null
@@ -0,0 +1,205 @@
+//
+// 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 <memory>
+#include <string>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSUtils.h>
+
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include <API/NFC/NFCFactory.h>
+
+#include "JSNdefRecordURI.h"
+#include <CommonsJavaScript/Converter.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace Api::NFC;
+
+#define TIZEN10_NDEFRECORD_URI_URI "uri"
+
+JSClassDefinition JSNdefRecordURI::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "NDEFRecordURI",
+       JSNdefRecord::getClassRef(),
+       m_property,
+       NULL,
+       initialize,
+       finalize,
+       NULL, //HasProperty,
+       NULL,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //GetPropertyNames,
+       NULL, //CallAsFunction,
+       constructor, //CallAsConstructor,
+       hasInstance,
+       NULL, //ConvertToType
+};
+
+JSStaticValue JSNdefRecordURI::m_property[] =
+{
+       {TIZEN10_NDEFRECORD_URI_URI,  getProperty, NULL, kJSPropertyAttributeReadOnly},
+       { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSNdefRecordURI::getClassRef() {
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNdefRecordURI::getClassInfo() {
+       return &m_classInfo;
+}
+
+JSClassRef JSNdefRecordURI::m_jsClassRef = JSClassCreate(JSNdefRecordURI::getClassInfo());
+
+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);
+}
+
+JSObjectRef JSNdefRecordURI::createJSObject(JSContextRef context, const std::string &uri) {
+       INdefRecordPtr ndefRecord = NFCFactory::getInstance().createNDEFRecordObject(uri);
+
+       NdefRecordPrivObject *priv = new NdefRecordPrivObject(context, ndefRecord);
+
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new a NdefRecord object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSObjectRef JSNdefRecordURI::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       Try {
+               Converter convert(ctx);
+
+               if (argumentCount > 0)
+                       return createJSObject(ctx, convert.toString(arguments[0]));
+               else
+                       return createJSObject(ctx, convert.toString(JSValueMakeUndefined(ctx)));
+       } Catch(ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return NULL;
+       } Catch (InvalidArgumentException) {
+               LogError("InvalidArgumentException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               return NULL;
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::SERVICE_NOT_AVAILABLE, "Service Not Available");
+               return NULL;
+       } Catch (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;
+
+}
+JSValueRef JSNdefRecordURI::getProperty(JSContextRef context, JSObjectRef object,
+       JSStringRef propertyName, JSValueRef* exception) {
+       LogDebug("Enter");
+
+       Try     {
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_NDEFRECORD_URI_URI)) {
+                       NdefRecordPrivObject *priv = static_cast<NdefRecordPrivObject*>(JSObjectGetPrivate(object));
+                       if (!priv) {
+                               ThrowMsg(NullPointerException, "Private object not set.");
+                       }
+                       INdefRecordPtr ndefRecord = priv->getObject();
+                       char * uri = NULL;
+                       if (ndefRecord->getUri(&uri)) {
+                               Converter convert(context);
+                               std::string result(uri);
+                               free(uri);
+                               LogDebug("uri : " << result);
+                               return convert.toJSValueRef(result);
+                       }
+                       LogDebug("This record is not URI Type");
+               }
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (PlatformException) {
+               LogError("PlatformException: " << _rethrown_exception.GetMessage());
+       } Catch (NullPointerException) {
+               LogError("NullPointerException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSNdefRecordURI::hasInstance(JSContextRef context,
+        JSObjectRef constructor,
+        JSValueRef possibleInstance,
+        JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+} //Tizen1_0
+} //TizenApis
+
diff --git a/src/standards/Tizen/NFC/JSNdefRecordURI.h b/src/standards/Tizen/NFC/JSNdefRecordURI.h
new file mode 100755 (executable)
index 0000000..99201fa
--- /dev/null
@@ -0,0 +1,83 @@
+//
+// 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_URI_H_
+#define WRTPLUGINS_TIZEN_JS_NDEFRECORD_URI_H_
+
+#include "JSNdefRecord.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+class JSNdefRecordURI
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+
+       static const JSClassRef getClassRef();
+
+       static JSObjectRef createJSObject(JSContextRef context, 
+               const Api::NFC::NdefRecordProperties &ndefRecordProperties, std::vector<unsigned char> payload);
+
+       static JSObjectRef createJSObject(JSContextRef context, const std::string &uri);
+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 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.
+     */
+       static JSClassDefinition m_classInfo;
+
+       /**
+     * This structure describes a statically declared value property.
+     */
+       static JSStaticValue m_property[];
+
+       static JSClassRef m_jsClassRef;
+
+};
+
+} //Tizen1_0
+} //TizenApis
+
+#endif
+
diff --git a/src/standards/Tizen/NFC/NFCAsyncCallbackManager.cpp b/src/standards/Tizen/NFC/NFCAsyncCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..41619ef
--- /dev/null
@@ -0,0 +1,30 @@
+//
+// 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 "NFCAsyncCallbackManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::NFCAsyncCallbackManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/NFC/NFCAsyncCallbackManager.h b/src/standards/Tizen/NFC/NFCAsyncCallbackManager.h
new file mode 100755 (executable)
index 0000000..e56631b
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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_NFC_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_NFC_ASYNC_CALLBACK_MANAGER_H_
+
+#include <dpl/singleton.h>
+#include <Tizen/Common/AsyncCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+class NFCAsyncCallbackManager : public TizenApis::Commons::AsyncCallbackManager
+{
+public:
+       NFCAsyncCallbackManager()
+       {
+       }
+
+       virtual ~NFCAsyncCallbackManager()
+       {
+       }
+
+       friend class DPL::Singleton<NFCAsyncCallbackManager>;
+};
+
+typedef DPL::Singleton<NFCAsyncCallbackManager> NFCAsyncCallbackManagerSingleton;
+
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_NFC_ASYNC_CALLBACK_MANAGER_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/NFC/NFCChangedCallback.h b/src/standards/Tizen/NFC/NFCChangedCallback.h
new file mode 100755 (executable)
index 0000000..8c78218
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// 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_NFC_NFCCHANGEDCALLBACK_H_
+#define TIZEN_NFC_NFCCHANGEDCALLBACK_H_
+
+#include <JavaScriptCore/JavaScript.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+struct NFCChangedCallback
+{
+    JSValueRef onattach;
+    JSValueRef ondetach;
+
+    NFCChangedCallback() :
+        onattach(NULL),
+        ondetach(NULL)
+    {
+    }
+};
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/NFC/NFCConverter.cpp b/src/standards/Tizen/NFC/NFCConverter.cpp
new file mode 100755 (executable)
index 0000000..203803f
--- /dev/null
@@ -0,0 +1,418 @@
+//
+// 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/Validator.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <API/NFC/NFCFactory.h>
+#include "NFCConverter.h"
+#include "JSNdefRecord.h"
+#include "JSNdefRecordText.h"
+#include "JSNdefRecordURI.h"
+#include "JSNdefRecordMedia.h"
+#include "JSNdefMessage.h"
+
+using namespace std;
+using namespace TizenApis::Api::NFC;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis;
+
+
+#define NFC_FILTER_ATTRIBUTE_TAG_TYPES "tagTypes"
+
+#define NFC_CHANGED_CALLBACK_ONATTATCH "onattach"
+#define NFC_CHANGED_CALLBACK_ONDETACH "ondetach"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+vector<std::string> NFCConverter::m_allowedTagFilterProperties;
+
+NFCConverter::NFCConverter(JSContextRef context) : Converter(context)
+{
+    LogDebug("entered");
+    static bool init = initializeAllowedProperties();
+    (void) init;
+}
+
+NFCConverter::~NFCConverter()
+{
+    LogDebug("entered");
+}
+
+TagFilterPtr NFCConverter::toNFCTagFilter(JSValueRef jsValue)
+{
+    LogDebug("entered");
+    if (JSValueIsNull(m_context, jsValue) ||
+        JSValueIsUndefined(m_context, jsValue)) {
+        return TagFilterPtr(); //empty filter
+    }
+    TagFilterPtr filter(new TagFilter());
+
+    Validator validator(m_context);
+
+    if (!JSValueIsUndefined(m_context, jsValue)) {
+       vector<std::string> filter_values(toVectorOfStrings(jsValue));
+
+       LogDebug("NFCConverter, start setting filter values, tag_types.size() : " << filter_values.size());
+         for (unsigned int i=0; i<filter_values.size(); i++) {
+               nfcTagType filterValue = toNfcTagType(filter_values.at(i));
+
+               filter->addTagTypeValue(filterValue);
+                 LogDebug("NFCConverter,  tag_types.at(i): " << filter_values.at(i));
+         }
+    }
+    LogDebug("NFCConverter,  filter size == " << filter->getFilterSize());
+
+    return filter;
+}
+
+
+nfcTagType NFCConverter::toNfcTagType(std::string typeString) {
+       if (typeString == "GENERIC_TARGET")
+               return NFC_TAGTYPE_GENERIC_PICC;
+       else if (typeString == "ISO14443_A")
+               return NFC_TAGTYPE_ISO14443_A_PICC;
+       else if (typeString == "ISO14443_4A")
+               return NFC_TAGTYPE_ISO14443_4A_PICC;
+       else if (typeString == "ISO14443_3A")
+               return NFC_TAGTYPE_ISO14443_3A_PICC;
+       else if (typeString == "MIFARE_MINI")
+               return NFC_TAGTYPE_MIFARE_MINI_PICC;
+       else if (typeString == "MIFARE_1K")
+               return NFC_TAGTYPE_MIFARE_1K_PICC;
+       else if (typeString == "MIFARE_4K")
+               return NFC_TAGTYPE_MIFARE_4K_PICC;
+       else if (typeString == "MIFARE_ULTRA")
+               return NFC_TAGTYPE_MIFARE_ULTRA_PICC;
+       else if (typeString == "MIFARE_DESFIRE")
+               return NFC_TAGTYPE_MIFARE_DESFIRE_PICC;
+       else if (typeString == "ISO14443_B")
+               return NFC_TAGTYPE_ISO14443_B_PICC;
+       else if (typeString == "ISO14443_4B")
+               return NFC_TAGTYPE_ISO14443_4B_PICC;
+       else if (typeString == "ISO14443_BPRIME")
+               return NFC_TAGTYPE_ISO14443_BPRIME_PICC;
+       else if (typeString == "FELICA")
+               return NFC_TAGTYPE_FELICA_PICC;
+       else if (typeString == "JEWEL")
+               return NFC_TAGTYPE_JEWEL_PICC;
+       else if (typeString == "ISO15693")
+               return NFC_TAGTYPE_ISO15693_PICC;
+       else if (typeString == "UNKNOWN_TARGET")
+               return NFC_TAGTYPE_UNKNOWN_TARGET;
+       else
+               ThrowMsg(Commons::ConversionException, "No Match Tag Type");
+}
+
+std::string NFCConverter::toNfcTagTypeString(nfcTagType type) {
+       switch (type) {
+               case NFC_TAGTYPE_GENERIC_PICC:
+                       return "GENERIC_TARGET";
+                       break;
+               case NFC_TAGTYPE_ISO14443_A_PICC:
+                       return "ISO14443_A";
+                       break;
+               case NFC_TAGTYPE_ISO14443_4A_PICC:
+                       return "ISO14443_4A";
+                       break;
+               case NFC_TAGTYPE_ISO14443_3A_PICC:
+                       return "ISO14443_3A";
+                       break;
+               case NFC_TAGTYPE_MIFARE_MINI_PICC:
+                       return "MIFARE_MINI";
+                       break;
+               case NFC_TAGTYPE_MIFARE_1K_PICC:
+                       return "MIFARE_1K";
+                       break;
+               case NFC_TAGTYPE_MIFARE_4K_PICC:
+                       return "MIFARE_4K";
+                       break;
+               case NFC_TAGTYPE_MIFARE_ULTRA_PICC:
+                       return "MIFARE_ULTRA";
+                       break;
+               case NFC_TAGTYPE_MIFARE_DESFIRE_PICC:
+                       return "MIFARE_DESFIRE";
+                       break;
+               case NFC_TAGTYPE_ISO14443_B_PICC:
+                       return "ISO14443_B";
+                       break;
+               case NFC_TAGTYPE_ISO14443_4B_PICC:
+                       return "ISO14443_4B";
+                       break;
+               case NFC_TAGTYPE_ISO14443_BPRIME_PICC:
+                       return "ISO14443_BPRIME";
+                       break;
+               case NFC_TAGTYPE_FELICA_PICC:
+                       return "FELICA";
+                       break;
+               case NFC_TAGTYPE_JEWEL_PICC:
+                       return "JEWEL";
+                       break;
+               case NFC_TAGTYPE_ISO15693_PICC:
+                       return "ISO15693";
+                       break;
+               case NFC_TAGTYPE_UNKNOWN_TARGET:
+               default:
+                       return "UNKNOWN_TARGET";
+                       break;
+       }
+}
+
+nfcTextEncodeUTF NFCConverter::toNfcTextEncodeUTF(std::string encodeString) {
+       if (encodeString == "UTF8")
+               return NFC_TEXT_ENCODE_UTF_8;
+       else if (encodeString == "UTF16")
+               return NFC_TEXT_ENCODE_UTF_16;
+       else
+               Throw(ConversionException);
+}
+
+std::string NFCConverter::toNfcTextEncodeUTFString(nfcTextEncodeUTF encode) {
+       switch(encode) {
+               case NFC_TEXT_ENCODE_UTF_8:
+                       return "UTF8";
+                       break;
+               case NFC_TEXT_ENCODE_UTF_16:
+                       return "UTF16";
+                       break;
+               default:
+                       Throw(ConversionException);
+       }
+}
+
+nfcTNF NFCConverter::toNfcTNF(const JSValueRef& arg) {
+       long value = toLong(arg);
+       LogDebug("toNfcTNF,  value == " << value);
+
+       if ((value < NFC_TNF_EMPTY) || (value > NFC_TNF_UNCHANGED)) {
+               ThrowMsg(InvalidArgumentException, "It is not a correct tnf value");
+       }
+
+       return static_cast<nfcTNF>(value);
+}
+
+bool NFCConverter::initializeAllowedProperties()
+{
+    LogDebug("entered");
+    //NFC Filter properties
+    m_allowedTagFilterProperties.push_back(NFC_FILTER_ATTRIBUTE_TAG_TYPES);
+     return true;
+}
+
+JSValueRef NFCConverter::toJSValueRef(const std::vector<unsigned char>& arg) {
+    JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+
+    if (NULL == jsResult) {
+        ThrowMsg(Commons::UnknownException, "Could not create js array object");
+    }
+
+    for (std::size_t i = 0; i < arg.size(); ++i) {
+        JSValueRef tmpVal = JSValueMakeNumber(m_context, arg[i]);
+        if (!JSSetArrayElement(m_context, jsResult, i, tmpVal)) {
+            ThrowMsg(Commons::UnknownException, "Could not insert value into js array");
+        }
+    }
+
+    return jsResult;
+}
+
+JSValueRef NFCConverter::toJSValueRef(NdefRecordData arg) {
+       if (arg.properties.tnf == NFC_TNF_MIME_MEDIA)
+               return JSNdefRecordMedia::createJSObject(m_context, arg.properties, arg.payload);
+       if (arg.properties.tnf == NFC_TNF_WELL_KNOWN) {
+               if (arg.properties.typeName.size() > 0) {
+                       if (arg.properties.typeName[0] == 0x54)
+                               return JSNdefRecordText::createJSObject(m_context, arg.properties, arg.payload);
+                       if (arg.properties.typeName[0] == 0x55)
+                               return JSNdefRecordURI::createJSObject(m_context, arg.properties, arg.payload);
+               }
+       }
+       return JSNdefRecord::createJSObject(m_context, arg.properties, arg.payload);
+}
+
+JSValueRef NFCConverter::toJSValueRef(std::vector<NFCTagProperties> props) {
+       JSObjectRef jsResult = JSCreateArrayObject(m_context, 0, NULL);
+       if (NULL == jsResult) {
+               ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+                        "Could not create js array object");
+       }
+
+       for (std::size_t i = 0; i < props.size(); ++i) {
+               JSValueRef tmpVal = toJSValueRef(props[i].value);
+               if (!JSSetArrayElementInArrayList(m_context, jsResult, props[i].key.c_str(), tmpVal)) {
+                       ThrowMsg(WrtDeviceApis::Commons::UnknownException,
+                                "Could not insert value into js array");
+               }
+       }
+       return jsResult;
+}
+
+bool NFCConverter::isNdefRecord(const JSValueRef& arg) {
+       LogDebug("Entered");
+       if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg)) {
+               LogDebug("Object is Null or Undefied");
+               return false;
+       }
+       if (JSValueIsObjectOfClass(m_context, arg, JSNdefRecord::getClassRef())
+               || JSValueIsObjectOfClass(m_context, arg, JSNdefRecordText::getClassRef())
+               || JSValueIsObjectOfClass(m_context, arg, JSNdefRecordURI::getClassRef())
+               || JSValueIsObjectOfClass(m_context, arg, JSNdefRecordMedia::getClassRef()))
+               return true;
+
+       return false;
+}
+
+std::vector<void *> NFCConverter::toVectorOfRecordHandles(const JSValueRef& arg) {
+    if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg)) {
+               ThrowMsg(Commons::ConversionException,
+                        "NdefRecordArray is JS null or JS undefined.");
+    }
+
+    if (!JSIsArrayValue(m_context, arg)) {
+        ThrowMsg(Commons::ConversionException, "Argument is not an JS array.");
+    }
+
+    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);
+       if (isNdefRecord(element))
+               result.push_back(getRecordHandle(element));
+       else
+               ThrowMsg(Commons::ConversionException, "JS array has no record.");
+    }
+    return result;
+}
+
+std::string NFCConverter::toRecordClassName(NdefRecordData arg) {
+       if (arg.properties.tnf == NFC_TNF_MIME_MEDIA)
+               return JSNdefRecordMedia::getClassInfo()->className;
+       if (arg.properties.tnf == NFC_TNF_WELL_KNOWN) {
+               if (arg.properties.typeName.size() > 0) {
+                       if (arg.properties.typeName[0] == 0x54)
+                               return JSNdefRecordText::getClassInfo()->className;
+                       if (arg.properties.typeName[0] == 0x55)
+                               return JSNdefRecordURI::getClassInfo()->className;
+               }
+       }
+       return JSNdefRecord::getClassInfo()->className;
+}
+
+void *NFCConverter::getRecordHandle(const JSValueRef& arg) {
+       LogDebug("Entered");
+       if (!isNdefRecord(arg)) {
+               ThrowMsg(Commons::ConversionException,
+                        "Message is JS null or JS undefined.");
+       }
+       JSObjectRef obj = toJSObjectRef(arg);
+       
+       if (!obj) {
+               LogError("Object is null");
+               ThrowMsg(Commons::ConversionException, "Object is null");
+       }
+       NdefRecordPrivObject* privateObject = static_cast<NdefRecordPrivObject*>(JSObjectGetPrivate(obj));
+       if (!privateObject) {
+               LogError("Private object is not set.");
+               ThrowMsg(Commons::ConversionException, "Private object not set");
+       }
+
+       INdefRecordPtr record = privateObject->getObject();
+
+       return record->getHandle();
+}
+
+void *NFCConverter::getMessageHandle(const JSValueRef& arg) {
+       if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg) ||
+               (!JSValueIsObjectOfClass(m_context, arg, JSNdefMessage::getClassRef()))) {
+               ThrowMsg(Commons::ConversionException,
+                        "Message is JS null or JS undefined.");
+       }
+       JSObjectRef obj = toJSObjectRef(arg);
+       
+       if (!obj) {
+               LogError("Object is null");
+               ThrowMsg(Commons::ConversionException, "Object is null");
+       }
+       NdefMessagePrivObject* privateObject = static_cast<NdefMessagePrivObject*>(JSObjectGetPrivate(obj));
+       if (!privateObject) {
+               LogError("Private object is not set.");
+               ThrowMsg(Commons::ConversionException, "Private object is not set");
+       }
+
+       INdefMessagePtr message = privateObject->getObject();
+
+       return message->getHandle();
+}
+
+NFCChangedCallback NFCConverter::toNFCChangedCallback(const JSValueRef& arg) {
+       LogDebug("Entered");
+    JSObjectRef object = toJSObjectRef(arg);
+
+    NFCChangedCallback result;
+    Validator validator(m_context);
+
+    result.onattach= JSUtils::getJSPropertyOrUndefined(
+            m_context, object, NFC_CHANGED_CALLBACK_ONATTATCH
+            );
+    if (!validator.isNullOrUndefined(result.onattach) &&
+        !validator.isCallback(result.onattach)) {
+        ThrowMsg(Commons::ConversionException, "Not a valid callback.");
+    }
+
+    result.ondetach= JSUtils::getJSPropertyOrUndefined(
+            m_context, object, NFC_CHANGED_CALLBACK_ONDETACH
+            );
+    if (!validator.isNullOrUndefined(result.ondetach) &&
+        !validator.isCallback(result.ondetach)) {
+        ThrowMsg(Commons::ConversionException, "Not a valid callback.");
+    }
+
+    if (validator.isNullOrUndefined(result.onattach) && validator.isNullOrUndefined(result.ondetach))
+        ThrowMsg(Commons::ConversionException, "Not a valid callback.");
+
+    return result;
+}
+
+EventNFCSEType NFCConverter::toSEType(JSValueRef arg) {
+       std::string seType = toString(arg);
+       if (seType == "NONE")
+               return NFC_SE_NONE;
+       else if (seType == "ESE")
+               return NFC_SE_ESE;
+       else if (seType == "UICC")
+               return NFC_SE_UICC;
+       else
+               ThrowMsg(Commons::ConversionException, "No Match SE Type");
+}
+
+JSValueRef NFCConverter::toJSValueRefSEType(EventNFCSEType type) {
+       if (type == NFC_SE_NONE)
+               return toJSValueRef("NONE");
+       else if (type == NFC_SE_ESE)
+               return toJSValueRef("ESE");
+       else if (type == NFC_SE_UICC)
+               return toJSValueRef("UICC");
+       else
+               ThrowMsg(Commons::ConversionException, "No Match SE Type");
+}
+
+}
+}
diff --git a/src/standards/Tizen/NFC/NFCConverter.h b/src/standards/Tizen/NFC/NFCConverter.h
new file mode 100755 (executable)
index 0000000..3ab6938
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// 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 _JS_TIZEN10_NFC_CONVERTER_H_
+#define _JS_TIZEN10_NFC_CONVERTER_H_
+
+#include <vector>
+#include <string>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/Converter.h>
+#include <API/NFC/TagFilter.h>
+#include <API/NFC/NdefRecordProperties.h>
+#include <API/NFC/NFCTagProperties.h>
+#include <API/NFC/INdefRecord.h>
+#include <API/NFC/EventNFCChanged.h>
+#include "NFCChangedCallback.h"
+
+using namespace TizenApis::Api::NFC;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+class NFCConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+    public:
+       using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
+    public:
+       explicit NFCConverter(JSContextRef context);
+       virtual  ~NFCConverter();
+        TagFilterPtr toNFCTagFilter(JSValueRef jsValue);
+       nfcTagType toNfcTagType(std::string typeString);
+       std::string toNfcTagTypeString(nfcTagType type);
+       nfcTextEncodeUTF toNfcTextEncodeUTF(std::string encodeString);
+       std::string toNfcTextEncodeUTFString(nfcTextEncodeUTF encode);
+       nfcTNF toNfcTNF(const JSValueRef& arg);
+       JSValueRef toJSValueRef(const std::vector<unsigned char>& arg);
+       JSValueRef toJSValueRef(std::vector<NFCTagProperties> props);
+       JSValueRef toJSValueRef(NdefRecordData arg);
+       bool isNdefRecord(const JSValueRef& arg);
+       std::vector<void *> toVectorOfRecordHandles(const JSValueRef& arg);
+       std::string toRecordClassName(NdefRecordData arg);
+       void *getRecordHandle(const JSValueRef& arg);
+       void *getMessageHandle(const JSValueRef& arg);
+       NFCChangedCallback toNFCChangedCallback(const JSValueRef& arg);
+       EventNFCSEType toSEType(JSValueRef arg);
+       JSValueRef toJSValueRefSEType(EventNFCSEType type);
+  private:
+    bool initializeAllowedProperties();
+    static std::vector<std::string> m_allowedTagFilterProperties;
+};
+
+typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<NFCConverter> NFCConverterFactory;
+
+}
+}
+
+#endif /* _JS_TIZEN10_NFC_CONVERTER_H_ */
diff --git a/src/standards/Tizen/NFC/NFCListenerManager.cpp b/src/standards/Tizen/NFC/NFCListenerManager.cpp
new file mode 100755 (executable)
index 0000000..55b46bd
--- /dev/null
@@ -0,0 +1,30 @@
+//
+// 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 "NFCListenerManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::NFCListenerManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/NFC/NFCListenerManager.h b/src/standards/Tizen/NFC/NFCListenerManager.h
new file mode 100755 (executable)
index 0000000..33e2bf1
--- /dev/null
@@ -0,0 +1,130 @@
+//
+// 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_NFC_LISTENER_MANAGER_H_
+#define _TIZEN_NFC_LISTENER_MANAGER_H_
+
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Tizen/Common/IListenerManager.h>
+#include "JSNFCAdapter.h"
+#include "JSNFCTarget.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace TizenApis::Api::NFC;
+
+enum NFCListenerWatchID {
+       ID_NFCADAPTER_TAG_LISTENER = 1,
+       ID_NFCADAPTER_PEER_LISTENER,
+       ID_NFCPEER_RECEIVENDEF_LISTENER,
+       ID_NFCADAPTER_CARDEMULATION_LISTENER
+};
+
+class NFCListenerManager : public TizenApis::Commons::IListenerController
+{
+public:
+       NFCListenerManager()
+       {
+       }
+
+       virtual ~NFCListenerManager()
+       {
+       }
+
+};
+typedef DPL::Singleton<NFCListenerManager> NFCListenerManagerSingleton;
+
+class NFCListenerCanceller : public TizenApis::Commons::IListenerItem
+{
+public:
+       NFCListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
+               TizenApis::Commons::IListenerItem(context, object, watchId)
+       {
+       }
+
+       virtual ~NFCListenerCanceller()
+       {
+       }
+
+       virtual void cancelListener()
+       {
+               LogDebug("context : " << m_context);
+               LogDebug("object : " << m_object);
+               switch(m_watchId) {
+                       case ID_NFCPEER_RECEIVENDEF_LISTENER:
+                       {
+                               NFCTargetPrivObject* privateObject = static_cast<NFCTargetPrivObject*>(JSObjectGetPrivate(m_object));
+                               if (NULL == privateObject) {
+                                       LogWarning("Object has no privateObject");
+                                       return;
+                               }
+
+                               INFCTargetPtr nfcTarget(privateObject->getObject());
+                               nfcTarget->unsetReceiveNDEFListener();
+                               break;
+                       }
+                       case ID_NFCADAPTER_TAG_LISTENER:
+                       case ID_NFCADAPTER_PEER_LISTENER:
+                       {
+                               NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(m_object));
+                               if (NULL == privateObject) {
+                                       LogError("Object has no privateObject");
+                                       return;
+                               }
+                               Try {
+                                       INFCAdapterPtr nfcAdapter( privateObject->getObject());
+                                       if (ID_NFCADAPTER_TAG_LISTENER == m_watchId)
+                                               nfcAdapter->unsetTagListener();
+                                       else
+                                               nfcAdapter->unsetPeerListener();
+                               } Catch(WrtDeviceApis::Commons::Exception) {
+                                       LogError("Error on platform : " << _rethrown_exception.GetMessage());
+                               }
+                               break;
+                       }
+                       case ID_NFCADAPTER_CARDEMULATION_LISTENER:
+                       {
+                               NFCAdapterPrivObject* privateObject = static_cast<NFCAdapterPrivObject*>(JSObjectGetPrivate(m_object));
+                               if (NULL == privateObject) {
+                                       LogError("Object has no privateObject");
+                                       return;
+                               }
+                               Try {
+                                       INFCAdapterPtr nfcAdapter( privateObject->getObject());
+                                       nfcAdapter->unsetCardEmulationChangeListener();
+                               } Catch(WrtDeviceApis::Commons::Exception) {
+                                       LogError("Error on platform : " << _rethrown_exception.GetMessage());
+                               }
+                               break;                          
+                       }
+                       default:
+                               LogError("Wrong ID");
+               }
+       }
+};
+typedef DPL::SharedPtr<NFCListenerCanceller> NFCListenerCancellerPtr;
+
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_NFC_LISTENER_MANAGER_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/NFC/NFCStaticController.cpp b/src/standards/Tizen/NFC/NFCStaticController.cpp
new file mode 100755 (executable)
index 0000000..225566e
--- /dev/null
@@ -0,0 +1,211 @@
+//
+// 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 <dpl/shared_ptr.h>
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Commons/IEvent.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+
+#include "NFCStaticController.h"
+#include "EventNFCChangedPrivateData.h"
+#include "JSNFCTag.h"
+#include "JSNFCTarget.h"
+#include "JSNdefMessage.h"
+#include "NFCConverter.h"
+#include "NFCAsyncCallbackManager.h"
+
+using namespace TizenApis::Api::NFC;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+NFCStaticController& NFCStaticController::getInstance() {
+       static NFCStaticController controller;
+       return controller;
+}
+
+NFCStaticController::NFCStaticController() :
+       EventNFCChangedListener(ThreadEnum::NULL_THREAD), 
+       setPoweredAnswerReceiver(ThreadEnum::NULL_THREAD),
+       setCardEmulationAnswerReceiver(ThreadEnum::NULL_THREAD),
+       EventNFCChangedCardEmulationListener(ThreadEnum::NULL_THREAD) {
+}
+
+void NFCStaticController::onAnswerReceived(const EventNFCChangedPtr& event) {
+       LogDebug("onAnswerReceived Enter");
+
+       EventNFCChangedPrivateDataPtr privateData =
+       DPL::DynamicPointerCast<EventNFCChangedPrivateData>(event->getPrivateData());
+
+       void *nfcProp = event->getNFCProperties();
+
+       Try {
+               /**
+               *When received answer from platform, create an NFCTag JSObject and then call success function.
+               */
+               if (nfcProp != NULL) {
+                       JSObjectRef nfcObj;
+                       JSCallbackManagerPtr callbackManager = privateData->getCallbackManager();
+                       JSContextRef context = callbackManager->getContext();
+                       
+                       if (event->getNFCType() == NFC_TAG_TYPE)
+                               nfcObj = JSNFCTag::createJSObject(context, nfcProp);
+                       else
+                               nfcObj = JSNFCTarget::createJSObject(context, nfcProp);
+                       LogDebug("callOnSuccess");
+                       callbackManager->callOnSuccess(static_cast<JSValueRef>(nfcObj));
+               } else {
+                       JSCallbackManagerPtr detachedCallbackManager = privateData->getDetachedCallbackManager();
+
+                       detachedCallbackManager->callOnSuccess();
+               }
+       } Catch (ConversionException) {
+               LogError("Conversion exception while processing EventNFCChanged");
+       } Catch (PlatformException) {
+               LogError("PlatformException:Platform can't create NFCTag"  << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownException:Platform can't create NFCTag"  << _rethrown_exception.GetMessage());
+       } Catch (NullPointerException) {
+               LogError("NullPointer exception while processing EventNFCChanged");
+       }
+
+}
+
+void NFCStaticController::OnAnswerReceived(const EventNFCChangedSetPoweredPtr &event)
+{
+       JSCallbackManagerPtr cbm =
+           DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+
+       Try {
+               if (!cbm) {
+                       LogDebug("no callback manager");
+                       return;
+               }
+               NFCAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+               if (event->getResult()) {
+                       LogDebug("result success");
+                       cbm->callOnSuccess();
+                       return;
+               }
+               LogDebug("result fail");
+               std::string error = event->getError();
+               std::string errorMessage = event->getErrorMessage();
+               JSValueRef errorObject;
+               if (error != "") {
+                       if (errorMessage != "")
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, errorMessage);
+                       else
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, error);
+               } else
+                       errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+               cbm->callOnError(errorObject);
+       } Catch (PlatformException) {
+               LogError("PlatformException"  << _rethrown_exception.GetMessage());
+               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::SERVICE_NOT_AVAILABLE,"Service Not Available");
+               cbm->callOnError(errorObject);
+       } Catch (UnknownException) {
+               LogError("UnknownException"  << _rethrown_exception.GetMessage());
+               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+               cbm->callOnError(errorObject);          
+       } Catch (Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+               cbm->callOnError(errorObject);  
+       }
+}
+
+void NFCStaticController::OnAnswerReceived(const EventNFCSetCardEmulationPtr &event)
+{
+       JSCallbackManagerPtr cbm =
+           DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+
+       Try {
+               if (!cbm) {
+                       LogDebug("no callback manager");
+                       return;
+               }
+               NFCAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+               if (event->getResult()) {
+                       LogDebug("result success");
+                       cbm->callOnSuccess();
+                       return;
+               }
+               LogDebug("result fail");
+               std::string error = event->getError();
+               std::string errorMessage = event->getErrorMessage();
+               JSValueRef errorObject;
+               if (error != "") {
+                       if (errorMessage != "")
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, errorMessage);
+                       else
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, error);
+               } else
+                       errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+               cbm->callOnError(errorObject);
+       } Catch (PlatformException) {
+               LogError("PlatformException"  << _rethrown_exception.GetMessage());
+               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::SERVICE_NOT_AVAILABLE,"Service Not Available");
+               cbm->callOnError(errorObject);
+       } Catch (UnknownException) {
+               LogError("UnknownException"  << _rethrown_exception.GetMessage());
+               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+               cbm->callOnError(errorObject);          
+       } Catch (Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+               cbm->callOnError(errorObject);  
+       }
+}
+
+void NFCStaticController::onAnswerReceived(const EventNFCChangedCardEmulationPtr& event) {
+       LogDebug("Enter");
+
+       Try {
+               JSCallbackManagerPtr cbm =
+                   DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+               EventNFCSEType seType = event->getSEType();
+
+               if (seType != NFC_SE_INVALID) {
+                       JSContextRef context = cbm->getContext();
+                       LogDebug("callOnSuccess");
+                       NFCConverter converter(context);
+                       cbm->callOnSuccess(converter.toJSValueRefSEType(seType));
+               }
+       } Catch (ConversionException) {
+               LogError("Conversion exception while processing EventNFCChanged");
+       } Catch (PlatformException) {
+               LogError("PlatformException:Platform can't create NFCTag"  << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownException:Platform can't create NFCTag"  << _rethrown_exception.GetMessage());
+       } Catch (NullPointerException) {
+               LogError("NullPointer exception while processing EventNFCChanged");
+       }
+
+}
+
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/NFC/NFCStaticController.h b/src/standards/Tizen/NFC/NFCStaticController.h
new file mode 100755 (executable)
index 0000000..9cb2c2f
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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_NFC_STATIC_CONTROLLER_H_
+#define WRTPLUGINS_TIZEN_NFC_STATIC_CONTROLLER_H_
+
+#include <Commons/EventListener.h>
+#include <Commons/EventReceiver.h>
+#include <API/NFC/EventNFCChanged.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::Commons;
+using namespace Api::NFC;
+typedef EventListener<EventNFCChanged> EventNFCChangedListener;
+typedef EventAnswerReceiver<EventNFCChangedSetPowered> setPoweredAnswerReceiver;
+typedef EventAnswerReceiver<EventNFCSetCardEmulation> setCardEmulationAnswerReceiver;
+typedef EventListener<EventNFCChangedCardEmulation> EventNFCChangedCardEmulationListener;
+class NFCStaticController :
+       public EventNFCChangedListener,
+       public setPoweredAnswerReceiver,
+       public setCardEmulationAnswerReceiver,
+       public EventNFCChangedCardEmulationListener
+{
+public:
+       static NFCStaticController& getInstance();
+
+       void onAnswerReceived(const EventNFCChangedPtr& event);
+       void OnAnswerReceived(const EventNFCChangedSetPoweredPtr &event);
+       void OnAnswerReceived(const EventNFCSetCardEmulationPtr &event);
+       void onAnswerReceived(const EventNFCChangedCardEmulationPtr& event);
+protected:
+       NFCStaticController();
+};
+
+
+} // Tizen1_0
+} // TizenApis
+
+#endif /* WRTPLUGINS_TIZEN_NFC_STATIC_CONTROLLER_H_ */
+
diff --git a/src/standards/Tizen/NFC/ResponseDispatcher.cpp b/src/standards/Tizen/NFC/ResponseDispatcher.cpp
new file mode 100755 (executable)
index 0000000..3225313
--- /dev/null
@@ -0,0 +1,264 @@
+//
+// 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 <vector>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "ResponseDispatcher.h"
+#include "NFCConverter.h"
+#include "JSNdefMessage.h"
+#include "NFCAsyncCallbackManager.h"
+
+using namespace TizenApis::Api::NFC;
+using namespace TizenApis::Commons;
+using namespace  WrtDeviceApis::Commons;
+using namespace  WrtDeviceApis::CommonsJavaScript;
+namespace TizenApis {
+namespace Tizen1_0 {
+
+NFCResponseDispatcher& NFCResponseDispatcher::getInstance()
+{
+    static NFCResponseDispatcher instance;
+    return instance;
+}
+
+NFCResponseDispatcher::NFCResponseDispatcher() :
+    readNDEFAnswerReceiver(ThreadEnum::NULL_THREAD),
+     writeNDEFAnswerReceiver(ThreadEnum::NULL_THREAD),
+     transceiveAnswerReceiver(ThreadEnum::NULL_THREAD),
+     formatAnswerReceiver(ThreadEnum::NULL_THREAD),
+     TargetSendNdefAnswerReceiver(ThreadEnum::NULL_THREAD),
+     TargetReceiveNdefListener(ThreadEnum::NULL_THREAD)
+{
+    LogDebug("entered");
+}
+
+NFCResponseDispatcher::~NFCResponseDispatcher()
+{
+    LogDebug("entered");
+}
+
+void NFCResponseDispatcher::OnAnswerReceived(const EventTagActionReadPtr &event)
+{
+       JSCallbackManagerPtr cbm =
+           DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+
+       Try {
+               if (!cbm) {
+                       LogDebug("no callback manager");
+                       return;
+               }
+               NFCAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+
+               if (event->getResult()) {
+                       LogDebug("result success");
+                       cbm->callOnSuccess(JSNdefMessage::createJSObject(cbm->getContext(), event->getReadNdefResult()));
+                       return;
+               }
+               LogDebug("result fail");
+
+               std::string error = event->getError();
+               std::string errorMessage = event->getErrorMessage();
+               JSValueRef errorObject;
+               if (error != "") {
+                       if (errorMessage != "")
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, errorMessage);
+                       else
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, error);
+               } else
+                       errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+
+               cbm->callOnError(errorObject);
+       } Catch (PlatformException) {
+               LogError("Platform can't create NdefMessage"  << _rethrown_exception.GetMessage());
+               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+               cbm->callOnError(errorObject);          
+       } Catch (Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+               cbm->callOnError(errorObject);  
+       }
+}
+
+void NFCResponseDispatcher::OnAnswerReceived(const EventTagActionWritePtr &event)
+{
+       JSCallbackManagerPtr cbm =
+           DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+
+       if (!cbm) {
+               LogDebug("no callback manager");
+               return;
+       }
+       NFCAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+
+       if (event->getResult()) {
+               LogDebug("result success");
+               cbm->callOnSuccess();
+               return;
+       }
+       LogDebug("result fail");
+
+       std::string error = event->getError();
+       std::string errorMessage = event->getErrorMessage();
+       JSValueRef errorObject;
+       if (error != "") {
+               if (errorMessage != "")
+                       errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, errorMessage);
+               else
+                       errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, error);
+       } else
+               errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+
+       cbm->callOnError(errorObject);
+}
+
+void NFCResponseDispatcher::OnAnswerReceived(const EventTagActionTransceivePtr &event)
+{
+       JSCallbackManagerPtr cbm =
+               DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+
+       Try {
+               if (!cbm) {
+                       LogDebug("no callback manager");
+                       return;
+               }
+               NFCAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+
+               JSContextRef context = cbm->getContext();
+
+               if (event->getResult()) {
+                       NFCConverter convert(context);
+                       LogDebug("result success");
+                       cbm->callOnSuccess(convert.toJSValueRef(event->getTransceiveBuffer()));
+                       return;
+               }
+               LogDebug("result fail");
+
+               std::string error = event->getError();
+               std::string errorMessage = event->getErrorMessage();
+               JSValueRef errorObject;
+               if (error != "") {
+                       if (errorMessage != "")
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, errorMessage);
+                       else
+                               errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, error);
+               } else
+                       errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+
+               cbm->callOnError(errorObject);
+       } Catch (ConversionException) {
+               LogError("Conversion exception while processing EventTagActionTransceive");
+               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+               cbm->callOnError(errorObject);          
+       } Catch (Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+               cbm->callOnError(errorObject);  
+       }
+}
+
+void NFCResponseDispatcher::OnAnswerReceived(const EventTagActionFormatPtr &event)
+{
+       JSCallbackManagerPtr cbm =
+               DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+
+       if (!cbm) {
+               LogDebug("no callback manager");
+               return;
+       }
+       NFCAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+
+       if (event->getResult()) {
+               LogDebug("result success");
+               cbm->callOnSuccess();
+               return;
+       }
+       LogDebug("result fail");
+
+       std::string error = event->getError();
+       std::string errorMessage = event->getErrorMessage();
+       JSValueRef errorObject;
+       if (error != "") {
+               if (errorMessage != "")
+                       errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, errorMessage);
+               else
+                       errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, error);
+       } else
+               errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+
+       cbm->callOnError(errorObject);
+}
+
+void NFCResponseDispatcher::OnAnswerReceived(const EventTargetActionSendPtr &event)
+{
+       JSCallbackManagerPtr cbm =
+               DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+
+       if (!cbm) {
+               LogDebug("no callback manager");
+               return;
+       }
+       NFCAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(cbm);
+
+       if (event->getResult()) {
+               LogDebug("result success");
+               cbm->callOnSuccess();
+               return;
+       }
+       LogDebug("result fail");
+
+       std::string error = event->getError();
+       std::string errorMessage = event->getErrorMessage();
+       JSValueRef errorObject;
+       if (error != "") {
+               if (errorMessage != "")
+                       errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, errorMessage);
+               else
+                       errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), error, error);
+       } else
+               errorObject = JSTizenExceptionFactory::makeErrorObject(cbm->getContext(), JSTizenException::UNKNOWN_ERROR,"Unknown Error");
+
+       cbm->callOnError(errorObject);
+}
+
+void NFCResponseDispatcher::onAnswerReceived(const EventTargetActionReceivePtr &event)
+{
+       LogDebug("onAnswerReceived Enter");
+       JSCallbackManagerPtr cbm =
+               DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+
+       Try {
+               if (!cbm) {
+                       LogDebug("no callback manager");
+                       return;
+               }
+
+               JSContextRef context = cbm->getContext();
+
+               LogDebug("result success");
+               cbm->callOnSuccess(JSNdefMessage::createJSObject(context, event->getReadNdefResult()));
+       } Catch (PlatformException) {
+               LogError("Platform can't create NdefMessage"  << _rethrown_exception.GetMessage());     
+       } Catch (Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());    
+       }
+}
+
+}
+}
diff --git a/src/standards/Tizen/NFC/ResponseDispatcher.h b/src/standards/Tizen/NFC/ResponseDispatcher.h
new file mode 100755 (executable)
index 0000000..ff1c983
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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_TIZEN10_NFC_RESPONSEDISPATCHER_H_
+#define WRTPLUGINS_TIZEN10_NFC_RESPONSEDISPATCHER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <Commons/EventReceiver.h>
+#include <Commons/EventListener.h>
+#include <API/NFC/EventTagAction.h>
+#include <API/NFC/EventTargetAction.h>
+
+using namespace TizenApis::Api::NFC;
+using namespace WrtDeviceApis::Commons;
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef EventAnswerReceiver< EventTagActionRead > readNDEFAnswerReceiver;
+typedef EventAnswerReceiver< EventTagActionWrite > writeNDEFAnswerReceiver;
+typedef EventAnswerReceiver< EventTagActionTransceive > transceiveAnswerReceiver;
+typedef EventAnswerReceiver< EventTagActionFormat > formatAnswerReceiver;
+typedef EventAnswerReceiver< EventTargetActionSend > TargetSendNdefAnswerReceiver;
+typedef EventListener< EventTargetActionReceive > TargetReceiveNdefListener;
+
+class NFCResponseDispatcher :
+    public readNDEFAnswerReceiver,
+    public writeNDEFAnswerReceiver,
+    public transceiveAnswerReceiver,
+    public formatAnswerReceiver,
+    public TargetSendNdefAnswerReceiver,
+    public TargetReceiveNdefListener
+    
+{
+public:
+    static NFCResponseDispatcher& getInstance();
+private:
+    NFCResponseDispatcher();
+    virtual ~NFCResponseDispatcher();
+protected:
+    void OnAnswerReceived(const EventTagActionReadPtr &event);
+    void OnAnswerReceived(const EventTagActionWritePtr &event);
+    void OnAnswerReceived(const EventTagActionTransceivePtr &event);
+    void OnAnswerReceived(const EventTagActionFormatPtr &event);
+    void OnAnswerReceived(const EventTargetActionSendPtr &event);
+    void onAnswerReceived(const EventTargetActionReceivePtr &event);
+};
+
+}
+}
+
+#endif
\ No newline at end of file
diff --git a/src/standards/Tizen/NFC/config.xml b/src/standards/Tizen/NFC/config.xml
new file mode 100755 (executable)
index 0000000..f073ec5
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+    <library-name>libwrt-plugins-tizen-2.0-nfc.so</library-name>
+    <feature-install-uri>nfc.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/nfc.common</name>
+        <device-capability>nfc.common</device-capability>
+    </api-feature>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/nfc.tag</name>
+        <device-capability>nfc.tag</device-capability>
+    </api-feature>
+
+     <api-feature>
+        <name>http://tizen.org/privilege/nfc.p2p</name>
+        <device-capability>nfc.p2p</device-capability>
+    </api-feature>
+
+     <api-feature>
+        <name>http://tizen.org/privilege/nfc.admin</name>
+        <device-capability>nfc.admin</device-capability>
+    </api-feature>
+
+     <api-feature>
+        <name>http://tizen.org/privilege/nfc.cardemulation</name>
+        <device-capability>nfc.cardemulation</device-capability>
+    </api-feature>
+</plugin-properties>
+
diff --git a/src/standards/Tizen/NFC/plugin_config.cpp b/src/standards/Tizen/NFC/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..a14a95c
--- /dev/null
@@ -0,0 +1,179 @@
+//
+// 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 <map>
+#include <utility>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include "plugin_config.h"
+
+#define NFC_FEATURE_API_COMMON "http://tizen.org/privilege/nfc.common"
+#define NFC_FEATURE_API_ADMIN "http://tizen.org/privilege/nfc.admin"
+#define NFC_FEATURE_API_TAG "http://tizen.org/privilege/nfc.tag"
+#define NFC_FEATURE_API_P2P "http://tizen.org/privilege/nfc.p2p"
+#define NFC_FEATURE_API_CARDEMULATION "http://tizen.org/privilege/nfc.cardemulation"
+
+#define NFC_DEVICE_CAP_COMMON "nfc.common"
+#define NFC_DEVICE_CAP_ADMIN "nfc.admin"
+#define NFC_DEVICE_CAP_TAG "nfc.tag"
+#define NFC_DEVICE_CAP_P2P "nfc.p2p"
+#define NFC_DEVICE_CAP_CARDEMULATION "nfc.cardemulation"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+const char* NFC_FUNCTION_API_COMMON_FUNCS = "NFCCommonFunctions";
+const char* NFC_FUNCTION_API_ADMIN_FUNCS = "NFCAdminFunctions";
+const char* NFC_FUNCTION_API_TAG_FUNCS = "NFCTagFunctions";
+const char* NFC_FUNCTION_API_P2P_FUNCS = "NFCP2PFunctions";
+const char* NFC_FUNCTION_API_CARDEMULATION_FUNCS = "NFCCardEmulationFunctions";
+
+static WrtDeviceApis::Commons::FunctionMapping createNFCFunctions();
+
+static WrtDeviceApis::Commons::FunctionMapping NFCFunctions =
+    createNFCFunctions();
+
+DEFINE_FUNCTION_GETTER(NFC, NFCFunctions);
+
+static WrtDeviceApis::Commons::FunctionMapping createNFCFunctions()
+{
+    using namespace WrtDeviceApis::Commons;
+
+    /**
+     * Device capabilities
+     */
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_NFC_COMMON, NFC_DEVICE_CAP_COMMON);
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_NFC_ADMIN, NFC_DEVICE_CAP_ADMIN);
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_NFC_TAG, NFC_DEVICE_CAP_TAG);
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_NFC_P2P, NFC_DEVICE_CAP_P2P);
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_NFC_CARDEMULATION, NFC_DEVICE_CAP_CARDEMULATION);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_NFC_COMMON);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_NFC_COMMON, DEVICE_CAP_NFC_COMMON);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_NFC_ADMIN);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_NFC_ADMIN, DEVICE_CAP_NFC_ADMIN);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_NFC_TAG);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_NFC_TAG, DEVICE_CAP_NFC_TAG);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_NFC_P2P);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_NFC_P2P, DEVICE_CAP_NFC_P2P);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_NFC_CARDEMULATION);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_NFC_CARDEMULATION, DEVICE_CAP_NFC_CARDEMULATION);
+
+    /**
+     * API features
+     */
+    ACE_CREATE_FEATURE(FEATURE_COMMON, NFC_FEATURE_API_COMMON);
+    ACE_CREATE_FEATURE(FEATURE_ADMIN, NFC_FEATURE_API_ADMIN);
+    ACE_CREATE_FEATURE(FEATURE_TAG, NFC_FEATURE_API_TAG);
+    ACE_CREATE_FEATURE(FEATURE_P2P, NFC_FEATURE_API_P2P);
+    ACE_CREATE_FEATURE(FEATURE_CARDEMULATION, NFC_FEATURE_API_CARDEMULATION);
+
+    ACE_CREATE_FEATURE_LIST(NFC_FEATURES_NFC_COMMON);
+    ACE_ADD_API_FEATURE(NFC_FEATURES_NFC_COMMON, FEATURE_COMMON);
+
+    ACE_CREATE_FEATURE_LIST(NFC_FEATURES_NFC_ADMIN);
+    ACE_ADD_API_FEATURE(NFC_FEATURES_NFC_ADMIN, FEATURE_ADMIN);
+
+    ACE_CREATE_FEATURE_LIST(NFC_FEATURES_NFC_TAG);
+    ACE_ADD_API_FEATURE(NFC_FEATURES_NFC_TAG, FEATURE_TAG);
+
+    ACE_CREATE_FEATURE_LIST(NFC_FEATURES_NFC_P2P);
+    ACE_ADD_API_FEATURE(NFC_FEATURES_NFC_P2P, FEATURE_P2P);
+
+    ACE_CREATE_FEATURE_LIST(NFC_FEATURES_NFC_CARDEMULATION);
+    ACE_ADD_API_FEATURE(NFC_FEATURES_NFC_CARDEMULATION, FEATURE_CARDEMULATION);
+
+   /**
+     * Functions
+     */
+    FunctionMapping NFCFunctions;
+
+       AceFunction nfcCommonFuncs = ACE_CREATE_FUNCTION(
+            FUNCTION_NFC_COMMON_FUNCTIONS,
+            NFC_FUNCTION_API_COMMON_FUNCS,
+            NFC_FEATURES_NFC_COMMON,
+            DEVICE_LIST_NFC_COMMON);
+
+    NFCFunctions.insert(std::make_pair(
+                               NFC_FUNCTION_API_COMMON_FUNCS,
+                               nfcCommonFuncs));
+
+       AceFunction nfcAdminFuncs = ACE_CREATE_FUNCTION(
+            FUNCTION_NFC_ADMIN_FUNCTIONS,
+            NFC_FUNCTION_API_ADMIN_FUNCS,
+            NFC_FEATURES_NFC_ADMIN,
+            DEVICE_LIST_NFC_ADMIN);
+
+    NFCFunctions.insert(std::make_pair(
+                               NFC_FUNCTION_API_ADMIN_FUNCS,
+                               nfcAdminFuncs));
+
+       AceFunction nfcTagFuncs = ACE_CREATE_FUNCTION(
+            FUNCTION_NFC_TAG_FUNCTIONS,
+            NFC_FUNCTION_API_TAG_FUNCS,
+            NFC_FEATURES_NFC_TAG,
+            DEVICE_LIST_NFC_TAG);
+
+    NFCFunctions.insert(std::make_pair(
+                               NFC_FUNCTION_API_TAG_FUNCS,
+                               nfcTagFuncs));
+
+       AceFunction nfcP2PFuncs = ACE_CREATE_FUNCTION(
+            FUNCTION_NFC_P2P_FUNCTIONS,
+            NFC_FUNCTION_API_P2P_FUNCS,
+            NFC_FEATURES_NFC_P2P,
+            DEVICE_LIST_NFC_P2P);
+
+    NFCFunctions.insert(std::make_pair(
+                               NFC_FUNCTION_API_P2P_FUNCS,
+                               nfcP2PFuncs));
+
+       AceFunction nfcCardEmulationFuncs = ACE_CREATE_FUNCTION(
+            FUNCTION_NFC_CARDEMULATION_FUNCTIONS,
+            NFC_FUNCTION_API_CARDEMULATION_FUNCS,
+            NFC_FEATURES_NFC_CARDEMULATION,
+            DEVICE_LIST_NFC_CARDEMULATION);
+
+    NFCFunctions.insert(std::make_pair(
+                               NFC_FUNCTION_API_CARDEMULATION_FUNCS,
+                               nfcCardEmulationFuncs));
+
+
+    return NFCFunctions;
+}
+} // namespace Tizen1_0
+} // namespace TizenApis
+
+#undef NFC_FEATURE_API_COMMON
+#undef NFC_FEATURE_API_ADMIN
+#undef NFC_FEATURE_API_TAG
+#undef NFC_FEATURE_API_P2P
+#undef NFC_FEATURE_API_CARDEMULATION
+#undef NFC_DEVICE_CAP_COMMON
+#undef NFC_DEVICE_CAP_ADMIN
+#undef NFC_DEVICE_CAP_TAG
+#undef NFC_DEVICE_CAP_P2P
+#undef NFC_DEVICE_CAP_CARDEMULATION
diff --git a/src/standards/Tizen/NFC/plugin_config.h b/src/standards/Tizen/NFC/plugin_config.h
new file mode 100755 (executable)
index 0000000..107ca30
--- /dev/null
@@ -0,0 +1,42 @@
+//
+// 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 _NFC_PLUGIN_CONFIG_H_
+#define _NFC_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+extern const char* NFC_FUNCTION_API_COMMON_FUNCS;
+extern const char* NFC_FUNCTION_API_ADMIN_FUNCS;
+extern const char* NFC_FUNCTION_API_TAG_FUNCS;
+extern const char* NFC_FUNCTION_API_P2P_FUNCS;
+extern const char* NFC_FUNCTION_API_CARDEMULATION_FUNCS;
+
+DECLARE_FUNCTION_GETTER(NFC);
+
+#define NFC_CHECK_ACCESS(functionName)                       \
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(                \
+        getNFCFunctionData,             \
+        functionName)
+}
+}
+
+#endif //  _NFC_PLUGIN_CONFIG_H_
diff --git a/src/standards/Tizen/NFC/plugin_initializer.cpp b/src/standards/Tizen/NFC/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..d33c3ed
--- /dev/null
@@ -0,0 +1,85 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include "JSNFCManager.h"
+#include "JSNdefMessage.h"
+#include "JSNdefRecord.h"
+#include "JSNdefRecordText.h"
+#include "JSNdefRecordURI.h"
+#include "JSNdefRecordMedia.h"
+#include "NFCAsyncCallbackManager.h"
+#include "NFCListenerManager.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[TIZEN\\NFC ] on_widget_start_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess initialization failed");
+    }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[TIZEN\\NFC ] on_widget_stop_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+void on_frame_load_callback(const void * context)
+{
+       LogDebug("[Tizen\\NFC] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+       LogDebug("[Tizen\\NFC] on_frame_unload_callback (" << context << ")");
+
+       TizenApis::Tizen1_0::NFCAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+       TizenApis::Tizen1_0::NFCListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+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)TizenApis::Tizen1_0::JSNFCManager::getClassRef, NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "NDEFMessage", (js_class_template_getter)TizenApis::Tizen1_0::JSNdefMessage::getClassRef, NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "NDEFRecord", (js_class_template_getter)TizenApis::Tizen1_0::JSNdefRecord::getClassRef, NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "NDEFRecordText", (js_class_template_getter)TizenApis::Tizen1_0::JSNdefRecordText::getClassRef, NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "NDEFRecordURI", (js_class_template_getter)TizenApis::Tizen1_0::JSNdefRecordURI::getClassRef, NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "NDEFRecordMedia", (js_class_template_getter)TizenApis::Tizen1_0::JSNdefRecordMedia::getClassRef, NULL)
+PLUGIN_CLASS_MAP_END
+
diff --git a/src/standards/Tizen/NetworkBearerSelection/CMakeLists.txt b/src/standards/Tizen/NetworkBearerSelection/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..79246db
--- /dev/null
@@ -0,0 +1,22 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-networkbearerselection")
+
+include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_NETWORKBEARERSELECTION})
+
+set(SRCS 
+  ${SRCS_PLATFORM_IMPLEMENTATION_NETWORKBEARERSELECTION}
+  ${SRCS_PLATFORM_API_NETWORKBEARERSELECTION}
+  plugin_initializer.cpp
+  plugin_config.cpp
+  JSNetworkBearerSelection.cpp
+  JSNetworkBearerSelectionCallbackManager.cpp
+  NetworkBearerSelectionResponseDispatcher.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${LIBS_COMMON}
+  ${LIBS_PLATFORM_IMPLEMENTATION_NETWORKBEARERSELECTION}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION tizen-2.0-networkbearerselection)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION tizen-2.0-networkbearerselection)
diff --git a/src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelection.cpp b/src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelection.cpp
new file mode 100755 (executable)
index 0000000..1951523
--- /dev/null
@@ -0,0 +1,278 @@
+//
+// 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 <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <API/NetworkBearerSelection/NetworkBearerSelectionFactory.h>
+#include <API/NetworkBearerSelection/INetworkBearerSelection.h>
+#include <API/NetworkBearerSelection/EventNetworkBearerSelection.h>
+#include <API/NetworkBearerSelection/EventNetworkBearerRelease.h>
+#include <API/NetworkBearerSelection/OnNetworkBearerSelectionStateChanged.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include "JSNetworkBearerSelection.h"
+#include "JSNetworkBearerSelectionCallbackManager.h"
+#include "NetworkBearerSelectionResponseDispatcher.h"
+#include "plugin_config.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "TIZEN_N_NETWORKBEARER"
+#endif
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace NetworkBearerSelection {
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::NetworkBearerSelection;
+using namespace TizenApis::Commons;
+
+JSClassDefinition JSNetworkBearerSelection::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "NetworkBearerSelection",
+    NULL,
+    NULL,
+    m_function,
+    initialize,
+    finalize,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticFunction JSNetworkBearerSelection::m_function[] = {
+    { "requestRouteToHost", JSNetworkBearerSelection::requestRouteToHost, kJSPropertyAttributeNone },
+    { "releaseRouteToHost", JSNetworkBearerSelection::releaseRouteToHost, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+const JSClassRef JSNetworkBearerSelection::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNetworkBearerSelection::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSNetworkBearerSelection::m_jsClassRef = JSClassCreate(JSNetworkBearerSelection::getClassInfo());
+
+void JSNetworkBearerSelection::initialize(JSContextRef context, JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        INetworkBearerSelectionPtr NetworkBearers(NetworkBearerSelectionFactory::getInstance().getNetworkBearerSelections());
+        JSNetworkBearerSelectionPriv* priv = new JSNetworkBearerSelectionPriv(context, NetworkBearers);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            LogError("Object can't store private data.");
+            delete priv;
+        }
+        LogDebug("JSNetworkBearerSelection::initialize ");
+    } else {
+        LogDebug("Private object already set.");
+    }
+}
+
+void JSNetworkBearerSelection::finalize(JSObjectRef object)
+{
+    JSNetworkBearerSelectionPriv* priv = static_cast<JSNetworkBearerSelectionPriv*>(JSObjectGetPrivate(object));
+    
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting gallery");
+    delete priv;
+}
+
+JSValueRef JSNetworkBearerSelection::requestRouteToHost(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+        size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("enter");
+    JSNetworkBearerSelectionPriv *priv = static_cast<JSNetworkBearerSelectionPriv*>(JSObjectGetPrivate(thisObject));
+
+    Converter converter(context);
+    Validator check(context, exception);
+
+    if (!priv) {
+        LogError("private object is null");
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Wrong Object");
+    }
+    if (argumentCount < 3) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+    }
+    if (argumentCount == 4) {
+        if (check.isCallback(arguments[3])) {
+            LogDebug("arguments 3 is callback");
+        } else if (!JSValueIsNull(context, arguments[3]) && !JSValueIsUndefined(context, arguments[3])) {
+            return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+        }
+    }
+
+       JSValueRef onsuccess;
+       JSValueRef onpaused;
+       JSValueRef onresumed;
+       JSValueRef ondisconnected;
+
+    Try {
+       JSObjectRef callbackObject = converter.toJSObjectRef(arguments[2]);
+
+       onsuccess = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "onsuccess");
+       if (check.isNullOrUndefined(onsuccess))
+           onsuccess = NULL;
+       else if (!check.isCallback(onsuccess)) {
+           ThrowMsg(ConversionException, "2nd argument's onsuccess attribute is not a 'function'");
+       }
+
+       onpaused = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "onpaused");
+       if (check.isNullOrUndefined(onpaused))
+           onpaused = NULL;
+       else if (!check.isCallback(onpaused)) {
+           ThrowMsg(ConversionException, "2nd argument's onsuccess attribute is not a 'function'");
+       }
+
+       onresumed = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "onresumed");
+       if (check.isNullOrUndefined(onresumed))
+           onresumed = NULL;
+       else if (!check.isCallback(onresumed)) {
+           ThrowMsg(ConversionException, "2nd argument's onsuccess attribute is not a 'function'");
+       }
+
+       ondisconnected = JSUtils::getJSPropertyOrUndefined(context, callbackObject, "ondisconnected");
+       if (check.isNullOrUndefined(ondisconnected))
+           ondisconnected = NULL;
+       else if (!check.isCallback(ondisconnected)) {
+           ThrowMsg(ConversionException, "2nd argument's onsuccess attribute is not a 'function'");
+       }
+
+    } Catch(ConversionException) {
+        LogError("Error on conversion : " << _rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+
+       JSNetworkBearerSelectionCallbackManagerPtr callbackManager = JSNetworkBearerSelectionCallbackManager::createObject(context);
+
+    std::string networkType = converter.toString(arguments[0]);
+    std::string domainName = converter.toString(arguments[1]);
+    if (strcmp(networkType.c_str(), "CELLULAR") != 0) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");        
+    }
+
+       callbackManager->setOnSuccess(onsuccess);
+       callbackManager->setOnPaused(onpaused);
+       callbackManager->setOnResumed(onresumed);
+       callbackManager->setOnDisconneced(ondisconnected);
+       if(argumentCount > 3)
+               callbackManager->setOnError(arguments[3]);
+
+    Try {
+        INetworkBearerSelectionPtr NetworkBearerSelections(priv->getObject());
+       
+        EventNetworkBearerSelectionPtr dplEvent(new EventNetworkBearerSelection());
+        OnNetworkBearerSelectionStateChangedEmitterPtr emitter(new OnNetworkBearerSelectionStateChangedEmitter());
+
+        emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(callbackManager));
+        emitter->setListener(&NetworkBearerSelectionResponseDispatcher::getInstance());
+
+        dplEvent->setNetworkType(networkType);
+        dplEvent->setDomainName(domainName);
+        dplEvent->setEmitter(emitter);
+        dplEvent->setForAsynchronousCall(&NetworkBearerSelectionResponseDispatcher::getInstance());
+
+        NetworkBearerSelections->requestRouteToHost(dplEvent);
+    }
+    
+    Catch(WrtDeviceApis::Commons::Exception) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");        
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSNetworkBearerSelection::releaseRouteToHost(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+        size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("enter");
+    JSNetworkBearerSelectionPriv *priv = static_cast<JSNetworkBearerSelectionPriv*>(JSObjectGetPrivate(thisObject));
+    Converter converter(context);
+    Validator check(context, exception);
+    
+    if (!priv) {
+        LogError("private object is null");
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Wrong Object");
+    }
+    if (argumentCount < 3) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+    }
+    if (!check.isCallback(arguments[2])) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+    }
+
+    std::string networkType = converter.toString(arguments[0]);
+    std::string domainName = converter.toString(arguments[1]);
+    if (strcmp(networkType.c_str(), "CELLULAR") != 0) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");        
+    }
+
+    JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+    onSuccessForCbm = arguments[2];
+    if (argumentCount > 3) {
+        if (check.isCallback(arguments[3])) {
+            onErrorForCbm = arguments[3];
+        } else if (!JSValueIsNull(context, arguments[3]) && !JSValueIsUndefined(context, arguments[3])) {
+            return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+        }
+    }
+    JSCallbackManagerPtr callbackManager(JSCallbackManager::createObject(priv->getContext(), onSuccessForCbm, onErrorForCbm, true, true));
+    callbackManager->setObject(thisObject);    
+
+    Try {
+        INetworkBearerSelectionPtr NetworkBearerSelections(priv->getObject());
+        EventNetworkBearerReleasePtr dplEvent(new EventNetworkBearerRelease());
+        dplEvent->setNetworkType(networkType);
+        dplEvent->setDomainName(domainName);
+        dplEvent->setPrivateData(StaticPointerCast<IEventPrivateData>(callbackManager));
+        dplEvent->setForAsynchronousCall(&NetworkBearerSelectionResponseDispatcher::getInstance());
+       
+        NetworkBearerSelections->releaseRouteToHost(dplEvent);
+    }
+    
+    Catch(WrtDeviceApis::Commons::Exception) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");        
+    }
+
+    return JSValueMakeUndefined(context);
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelection.h b/src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelection.h
new file mode 100755 (executable)
index 0000000..400e005
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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_TIZEN1_0_JS_NETWORK_BEARER_SELECTION_H_
+#define WRTPLUGINS_TIZEN1_0_JS_NETWORK_BEARER_SELECTION_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/NetworkBearerSelection/INetworkBearerSelection.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace NetworkBearerSelection {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::NetworkBearerSelection::INetworkBearerSelectionPtr>::Type        JSNetworkBearerSelectionPriv;
+
+class JSNetworkBearerSelection
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+
+  private:
+    static void initialize(JSContextRef context, JSObjectRef object);
+    static void finalize(JSObjectRef object);
+
+    static JSValueRef requestRouteToHost(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+    static JSValueRef releaseRouteToHost(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;
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelectionCallbackManager.cpp b/src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelectionCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..986f77d
--- /dev/null
@@ -0,0 +1,291 @@
+//
+// 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 "JSNetworkBearerSelectionCallbackManager.h"
+#include <dpl/log/log.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace NetworkBearerSelection {
+
+
+JSNetworkBearerSelectionCallbackManagerPtr JSNetworkBearerSelectionCallbackManager::createObject(JSContextRef context)
+{
+       return JSNetworkBearerSelectionCallbackManagerPtr(new JSNetworkBearerSelectionCallbackManager(context));
+}
+
+JSNetworkBearerSelectionCallbackManager::JSNetworkBearerSelectionCallbackManager(JSContextRef context,
+               JSObjectRef onSuccess,
+               JSObjectRef onPaused,
+               JSObjectRef onResumed,
+               JSObjectRef onDisconnected,             
+               JSObjectRef onError ) :
+               m_onSuccess(NULL),
+               m_onPaused(NULL),
+               m_onResumed(NULL),
+               m_onDisconnected(NULL),
+               m_onError(NULL),
+               m_context(context),
+               m_object(NULL)
+{
+       setOnSuccess(onSuccess);
+       setOnPaused(onPaused);
+       setOnResumed(onResumed);
+       setOnDisconneced(onDisconnected);
+    setOnError(onError);
+}
+
+JSNetworkBearerSelectionCallbackManager::~JSNetworkBearerSelectionCallbackManager()
+{
+       if(m_onSuccess)
+       {
+               JSValueUnprotect(m_context, m_onSuccess);
+       }
+
+       if(m_onPaused)
+       {
+               JSValueUnprotect(m_context, m_onPaused);
+       }
+
+       if(m_onResumed)
+       {
+               JSValueUnprotect(m_context, m_onResumed);
+       }
+
+       if(m_onDisconnected)
+       {
+               JSValueUnprotect(m_context, m_onDisconnected);
+       }
+
+    if(m_onError)
+    {
+        JSValueUnprotect(m_context, m_onError);
+    }
+}
+
+void JSNetworkBearerSelectionCallbackManager::setOnSuccess(JSValueRef onSuccess)
+{
+       if (onSuccess)
+       {
+               if (m_onSuccess != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onSuccess);
+               }
+
+               m_onSuccess = JSValueToObject( m_context, onSuccess, NULL );
+
+               if (m_onSuccess != NULL)
+               {
+                       JSValueProtect(m_context, m_onSuccess);
+               }
+       }
+}
+
+JSValueRef JSNetworkBearerSelectionCallbackManager::getOnSuccess() const
+{
+       return m_onSuccess;
+}
+
+void JSNetworkBearerSelectionCallbackManager::setOnPaused(JSValueRef onPaused)
+{
+       if (onPaused)
+       {
+               if (m_onPaused != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onPaused);
+               }
+
+               m_onPaused = JSValueToObject( m_context, onPaused, NULL );
+
+               if (m_onPaused != NULL)
+               {
+                       JSValueProtect(m_context, m_onPaused);
+               }
+       }
+}
+
+JSValueRef JSNetworkBearerSelectionCallbackManager::getOnPaused() const
+{
+       return m_onPaused;
+}
+
+void JSNetworkBearerSelectionCallbackManager::setOnResumed(JSValueRef onResumed)
+{
+       if (onResumed)
+       {
+               if (m_onResumed != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onResumed);
+               }
+
+               m_onResumed = JSValueToObject( m_context, onResumed, NULL );
+
+               if (m_onResumed != NULL)
+               {
+                       JSValueProtect(m_context, m_onResumed);
+               }
+       }
+}
+
+JSValueRef JSNetworkBearerSelectionCallbackManager::getOnResumed() const
+{
+       return m_onResumed;
+}
+
+void JSNetworkBearerSelectionCallbackManager::setOnDisconneced(JSValueRef onDisconnected)
+{
+       if (onDisconnected)
+       {
+               if (m_onDisconnected != NULL)
+               {
+                       JSValueUnprotect(m_context, m_onDisconnected);
+               }
+
+               m_onDisconnected = JSValueToObject( m_context, onDisconnected, NULL );
+
+               if (m_onDisconnected != NULL)
+               {
+                       JSValueProtect(m_context, m_onDisconnected);
+               }
+       }
+}
+
+JSValueRef JSNetworkBearerSelectionCallbackManager::getOnDisconneced() const
+{
+       return m_onDisconnected;
+}
+
+void JSNetworkBearerSelectionCallbackManager::setOnError(JSValueRef onError)
+{
+    if (onError)
+    {
+        if (m_onError != NULL)
+        {
+            JSValueUnprotect(m_context, m_onError);
+        }
+
+        m_onError = JSValueToObject(m_context, onError, NULL);
+
+        if (m_onError != NULL)
+        {
+            JSValueProtect(m_context, m_onError);
+        }
+    }
+}
+
+JSValueRef JSNetworkBearerSelectionCallbackManager::getOnError() const
+{
+    return m_onError;
+}
+
+void JSNetworkBearerSelectionCallbackManager::setContext(JSContextRef context)
+{
+    m_context = context;
+}
+
+void JSNetworkBearerSelectionCallbackManager::setObject(JSObjectRef object)
+{
+    m_object = object;
+}
+
+JSObjectRef JSNetworkBearerSelectionCallbackManager::getObject() const
+{
+    return m_object;
+}
+
+void JSNetworkBearerSelectionCallbackManager::callOnSuccess()
+{
+    if (m_onSuccess == NULL)
+    {
+        //LogDebug("oncontactsadded callback is not set");
+        return;
+    }
+
+    makeCallback(m_context, NULL, m_onSuccess, "onsuccess", NULL, 0);
+}
+
+void JSNetworkBearerSelectionCallbackManager::callOnPaused()
+{
+    if (m_onPaused == NULL)
+    {
+        //LogDebug("oncontactsadded callback is not set");
+        return;
+    }
+
+    makeCallback(m_context, NULL, m_onPaused, "onpaused", NULL, 0);
+}
+
+void JSNetworkBearerSelectionCallbackManager::callOnResumed()
+{
+    if (m_onResumed == NULL)
+    {
+        //LogDebug("oncontactsadded callback is not set");
+        return;
+    }
+
+    makeCallback(m_context, NULL, m_onResumed, "onresumed", NULL, 0);
+}
+
+void JSNetworkBearerSelectionCallbackManager::callOnDisconnected()
+{
+    if (m_onDisconnected == NULL)
+    {
+        //LogDebug("oncontactsadded callback is not set");
+        return;
+    }
+
+    makeCallback(m_context, NULL, m_onDisconnected, "ondisconnected", NULL, 0);
+}
+
+void JSNetworkBearerSelectionCallbackManager::callOnError(JSValueRef error)
+{
+    if (m_onError == NULL)
+    {
+        //LogDebug("Error callback is not set");
+        return;
+    }
+    JSValueRef objParam[1] = { error };
+    makeCallback(m_context, NULL, m_onError, "onError", objParam, 1);
+}
+
+void JSNetworkBearerSelectionCallbackManager::makeCallback(JSContextRef context, JSObjectRef object, JSObjectRef callback, const char *szName, JSValueRef argv[], unsigned argc)
+{
+    if (callback == NULL)
+    {
+        LogError("callback is NULL");
+        return;
+    }
+
+    if (JSObjectIsFunction(context, callback))
+    {
+        if (argc == 0)
+        {
+                //LogDebug("Calling object directly, no arguments");
+                JSObjectCallAsFunction(context, callback, object, 0, NULL, NULL);
+        }
+        else
+        {
+                //LogDebug("Calling object directly, one argument");
+                JSObjectCallAsFunction(context, callback, object, argc, argv, NULL);
+        }
+        return;
+    }
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelectionCallbackManager.h b/src/standards/Tizen/NetworkBearerSelection/JSNetworkBearerSelectionCallbackManager.h
new file mode 100755 (executable)
index 0000000..4049023
--- /dev/null
@@ -0,0 +1,90 @@
+//
+// 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_CONTACT_JS_NETWORK_BEARER_SELECTION_CALLBACK_MANAGER_H_
+#define _TIZEN_CONTACT_JS_NETWORK_BEARER_SELECTION_CALLBACK_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <Commons/IEvent.h>
+#include <JavaScriptCore/JavaScript.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace NetworkBearerSelection {
+
+class JSNetworkBearerSelectionCallbackManager;
+typedef DPL::SharedPtr<JSNetworkBearerSelectionCallbackManager> JSNetworkBearerSelectionCallbackManagerPtr;
+
+class JSNetworkBearerSelectionCallbackManager : public WrtDeviceApis::Commons::IEventPrivateData
+{
+private:
+       JSNetworkBearerSelectionCallbackManager() {}
+       JSNetworkBearerSelectionCallbackManager( JSContextRef context,
+                       JSObjectRef onSuccess = NULL,
+                       JSObjectRef onPaused = NULL,
+                       JSObjectRef onResumed = NULL,
+                       JSObjectRef onDisconnected = NULL,
+                       JSObjectRef onError = NULL );
+
+public:
+       static JSNetworkBearerSelectionCallbackManagerPtr createObject(JSContextRef context);
+
+       virtual ~JSNetworkBearerSelectionCallbackManager();
+
+       void    setContext(JSContextRef context);
+       JSContextRef getContext() const { return m_context; }
+
+       void    setOnSuccess(JSValueRef onSuccess);
+       JSValueRef getOnSuccess() const;
+       void    setOnPaused(JSValueRef onPaused);
+       JSValueRef getOnPaused() const;
+       void    setOnResumed(JSValueRef onResumed);
+       JSValueRef getOnResumed() const;
+       void    setOnDisconneced(JSValueRef onDisconnected);
+       JSValueRef getOnDisconneced() const;
+       void    setOnError(JSValueRef onError);
+       JSValueRef getOnError() const;
+       void    setObject( JSObjectRef object );
+       JSObjectRef getObject() const;
+
+       void    callOnSuccess();
+       void    callOnPaused();
+       void    callOnResumed();
+       void    callOnDisconnected();
+       void    callOnError(JSValueRef error);
+
+private:
+       void    makeCallback(JSContextRef context,
+                       JSObjectRef object,
+                       JSObjectRef callback,
+                       const char *szName,
+                       JSValueRef argv[],
+                       unsigned argc);
+
+       JSObjectRef  m_onSuccess;
+       JSObjectRef  m_onPaused;
+       JSObjectRef  m_onResumed;
+       JSObjectRef  m_onDisconnected;
+       JSObjectRef  m_onError;    
+       JSContextRef m_context;
+       JSObjectRef  m_object;
+};
+
+}
+} // Tizen1_0
+} // TizenApis
+#endif
diff --git a/src/standards/Tizen/NetworkBearerSelection/NetworkBearerSelectionResponseDispatcher.cpp b/src/standards/Tizen/NetworkBearerSelection/NetworkBearerSelectionResponseDispatcher.cpp
new file mode 100755 (executable)
index 0000000..2a74d7c
--- /dev/null
@@ -0,0 +1,154 @@
+//
+// 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 "NetworkBearerSelectionResponseDispatcher.h"
+#include "JSNetworkBearerSelectionCallbackManager.h"
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::NetworkBearerSelection;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace NetworkBearerSelection {
+
+NetworkBearerSelectionResponseDispatcher& NetworkBearerSelectionResponseDispatcher::getInstance()
+{
+    static NetworkBearerSelectionResponseDispatcher instance;
+    return instance;
+}
+
+NetworkBearerSelectionResponseDispatcher::NetworkBearerSelectionResponseDispatcher() :
+    NetworkBearerSelectionEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD),
+    NetworkBearerReleaseEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD),        
+    OnNetworkBearerSelectionStateChangedListener(ThreadEnum::NULL_THREAD)    
+{
+}
+
+NetworkBearerSelectionResponseDispatcher::~NetworkBearerSelectionResponseDispatcher()
+{
+}
+
+void NetworkBearerSelectionResponseDispatcher::OnAnswerReceived(const EventNetworkBearerSelectionPtr &event)
+{
+    LogDebug("entered");
+}
+
+void NetworkBearerSelectionResponseDispatcher::OnAnswerReceived(const EventNetworkBearerReleasePtr &event)
+{
+    LogDebug("entered");
+    JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+
+    if (!callbackManager) {
+        LogError("No listener callback!");
+        return;
+    }
+
+       JSContextRef gContext = callbackManager->getContext();        
+    JSValueRef error = NULL;
+    
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::INVALID_VALUES_ERROR, "DomainName is not setted");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }        
+    callbackManager->callOnSuccess();
+}
+
+
+void NetworkBearerSelectionResponseDispatcher::onAnswerReceived(const OnNetworkBearerSelectionStateChangedPtr& event)
+{
+    LogDebug("entered");
+    JSNetworkBearerSelectionCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSNetworkBearerSelectionCallbackManager>(event->getPrivateData());
+
+    if (!callbackManager) {
+        LogError("No listener callback!");
+        return;
+    }
+
+    Try
+    {
+        if (event->getConnectionStateType() == CONNECTION_STATE_CONNECTED) {
+            LogDebug("success callback");
+            callbackManager->callOnSuccess();
+        } else if (event->getConnectionStateType() == CONNECTION_STATE_DISCONNECTED) {
+            LogDebug("disconnect callback");  
+            callbackManager->callOnDisconnected();
+        } else if (event->getConnectionStateType() == CONNECTION_STATE_ERROR) {
+               JSContextRef gContext = callbackManager->getContext();        
+            JSValueRef error = NULL;
+            
+               if (ExceptionCodes::None != event->getExceptionCode())
+               {
+                       switch (event->getExceptionCode())
+                       {
+                       case ExceptionCodes::PlatformException:
+                               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                               break;
+                       case ExceptionCodes::NotFoundException:
+                               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
+                               break;
+                       case ExceptionCodes::InvalidArgumentException:
+                               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");
+                               break;
+                       case ExceptionCodes::ConversionException:
+                               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                               break;
+                       default:
+                               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                               break;
+                       }
+
+                       callbackManager->callOnError(error);
+                       return;
+               }               
+            LogDebug("error callback");
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Error during processing answer.");
+    }
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/NetworkBearerSelection/NetworkBearerSelectionResponseDispatcher.h b/src/standards/Tizen/NetworkBearerSelection/NetworkBearerSelectionResponseDispatcher.h
new file mode 100755 (executable)
index 0000000..22f993b
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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 _NETWORK_BEARER_SELECTION_RESPONSE_DISPATCHER_H_
+#define _NETWORK_BEARER_SELECTION_RESPONSE_DISPATCHER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <Commons/EventReceiver.h>
+#include <Commons/EventListener.h>
+#include <API/NetworkBearerSelection/EventNetworkBearerSelection.h>
+#include <API/NetworkBearerSelection/EventNetworkBearerRelease.h>
+#include <API/NetworkBearerSelection/OnNetworkBearerSelectionStateChanged.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace NetworkBearerSelection {
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::NetworkBearerSelection::EventNetworkBearerSelection>
+NetworkBearerSelectionEventAnswerReceiverRequest;
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::NetworkBearerSelection::EventNetworkBearerRelease>
+NetworkBearerReleaseEventAnswerReceiverRequest;
+
+typedef WrtDeviceApis::Commons::EventListener<TizenApis::Api::NetworkBearerSelection::OnNetworkBearerSelectionStateChanged>
+OnNetworkBearerSelectionStateChangedListener;
+
+class NetworkBearerSelectionResponseDispatcher :
+       public NetworkBearerSelectionEventAnswerReceiverRequest,
+       public NetworkBearerReleaseEventAnswerReceiverRequest,     
+    public OnNetworkBearerSelectionStateChangedListener
+{
+  public:
+    static NetworkBearerSelectionResponseDispatcher& getInstance();
+
+  private:
+    NetworkBearerSelectionResponseDispatcher();
+    virtual ~NetworkBearerSelectionResponseDispatcher();
+
+  protected:
+    void OnAnswerReceived(const TizenApis::Api::NetworkBearerSelection::EventNetworkBearerSelectionPtr &event);
+    void OnAnswerReceived(const TizenApis::Api::NetworkBearerSelection::EventNetworkBearerReleasePtr &event);    
+    void onAnswerReceived(const TizenApis::Api::NetworkBearerSelection::OnNetworkBearerSelectionStateChangedPtr& event);
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/NetworkBearerSelection/config.xml b/src/standards/Tizen/NetworkBearerSelection/config.xml
new file mode 100755 (executable)
index 0000000..74c656b
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+       <library-name>libwrt-plugins-tizen-2.0-networkbearerselection.so</library-name>
+       <feature-install-uri>networkbearerselection.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/networkbearerselection</name>
+        <device-capability>networkbearerselection</device-capability>
+        <Object name="networkbearerselection">
+            <Function name="requestRouteToHost"/>
+            <Function name="releaseRouteToHost"/>            
+        </Object>
+    </api-feature>
+</plugin-properties>
+
diff --git a/src/standards/Tizen/NetworkBearerSelection/plugin_config.cpp b/src/standards/Tizen/NetworkBearerSelection/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..26bde21
--- /dev/null
@@ -0,0 +1,84 @@
+//
+// 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 <map>
+#include <utility>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include "plugin_config.h"
+
+#define NETWORKBEARERSELECTION_FEATURE_API "http://tizen.org/privilege/networkbearerselection"
+
+#define NETWORKBEARERSELECTION_DEVICE_CAP "networkbearerselection"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+const char* NETWORKBEARERSELECTION_FUNCTION_API_REQUEST_ROUTE_TO_HOST = "requestRouteToHost";
+const char* NETWORKBEARERSELECTION_FUNCTION_API_RELEASE_ROUTE_TO_HOST = "releaseRouteToHost";
+
+static WrtDeviceApis::Commons::FunctionMapping createNetworkBearerSelectionFunctions();
+
+static WrtDeviceApis::Commons::FunctionMapping NetworkBearerSelectionFunctions =
+    createNetworkBearerSelectionFunctions();
+
+DEFINE_FUNCTION_GETTER(NetworkBearerSelection, NetworkBearerSelectionFunctions);
+
+static WrtDeviceApis::Commons::FunctionMapping createNetworkBearerSelectionFunctions()
+{
+    using namespace WrtDeviceApis::Commons;
+
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_NETWORKBEARERSELECTION, NETWORKBEARERSELECTION_DEVICE_CAP);
+    ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_NETWORKBEARERSELECTION);
+
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_NETWORKBEARERSELECTION, DEVICE_CAP_NETWORKBEARERSELECTION);
+
+    ACE_CREATE_FEATURE(FEATURE_NETWORKBEARERSELECTION, NETWORKBEARERSELECTION_FEATURE_API);
+    ACE_CREATE_FEATURE_LIST(NETWORKBEARERSELECTION_FEATURES);
+
+    ACE_ADD_API_FEATURE(NETWORKBEARERSELECTION_FEATURES, FEATURE_NETWORKBEARERSELECTION);
+
+    FunctionMapping NetworkBearerSelectionFunctions;
+
+    AceFunction requestRouteToHostFunc = ACE_CREATE_FUNCTION(
+        FUNCTION_REQUEST_ROUTE_TO_HOST,
+        NETWORKBEARERSELECTION_FUNCTION_API_REQUEST_ROUTE_TO_HOST,
+        NETWORKBEARERSELECTION_FEATURES,
+        DEVICE_LIST_NETWORKBEARERSELECTION);
+
+    NetworkBearerSelectionFunctions.insert(std::make_pair(
+        NETWORKBEARERSELECTION_FUNCTION_API_REQUEST_ROUTE_TO_HOST,
+        requestRouteToHostFunc));
+
+    AceFunction releaseRouteToHostFunc = ACE_CREATE_FUNCTION(
+        FUNCTION_RELEASE_ROUTE_TO_HOST,
+        NETWORKBEARERSELECTION_FUNCTION_API_RELEASE_ROUTE_TO_HOST,
+        NETWORKBEARERSELECTION_FEATURES,
+        DEVICE_LIST_NETWORKBEARERSELECTION);
+
+    NetworkBearerSelectionFunctions.insert(std::make_pair(
+        NETWORKBEARERSELECTION_FUNCTION_API_RELEASE_ROUTE_TO_HOST,
+        releaseRouteToHostFunc));    
+
+    return NetworkBearerSelectionFunctions;
+}
+}
+}
+
+#undef NETWORKBEARERSELECTION_FEATURE_API
\ No newline at end of file
diff --git a/src/standards/Tizen/NetworkBearerSelection/plugin_config.h b/src/standards/Tizen/NetworkBearerSelection/plugin_config.h
new file mode 100755 (executable)
index 0000000..1ec3ae0
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// 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 _NETWORKBEARERSELECTION_PLUGIN_CONFIG_H_
+#define _NETWORKBEARERSELECTION_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+extern const char* NETWORKBEARERSELECTION_FUNCTION_API_REQUEST_ROUTE_TO_HOST;
+extern const char* NETWORKBEARERSELECTION_FUNCTION_API_RELEASE_ROUTE_TO_HOST;
+
+
+DECLARE_FUNCTION_GETTER(NetworkBearerSelection);
+
+#define NETWORKBEARERSELECTION_CHECK_ACCESS(functionName)               \
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(             \
+                                            getNetworkBearerSelectionFunctionData,     \
+                                            functionName)
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/NetworkBearerSelection/plugin_initializer.cpp b/src/standards/Tizen/NetworkBearerSelection/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..7cf5534
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include "JSNetworkBearerSelection.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+#define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[Tizen\\NetworkBearerSelection ] on_widget_start_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess initialization failed");
+    }    
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[Tizen\\NetworkBearerSelection ] on_widget_stop_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+PLUGIN_CLASS_MAP_BEGIN
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, "networkbearerselection", (js_class_template_getter)TizenApis::Tizen1_0::NetworkBearerSelection::JSNetworkBearerSelection::getClassRef, NULL)
+PLUGIN_CLASS_MAP_END
+
diff --git a/src/standards/Tizen/Notification/CMakeLists.txt b/src/standards/Tizen/Notification/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0813282
--- /dev/null
@@ -0,0 +1,34 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-notification")
+
+include_directories(
+  ${INCLUDES_PLATFORM_IMPLEMENTATION_NOTIFICATION}
+)
+
+set(CMAKE_INSTALL_RPATH
+  ${CMAKE_INSTALL_RPATH}
+  ${CMAKE_INSTALL_PREFIX}/tizen-2.0-tizen
+  ${CMAKE_INSTALL_PREFIX}/tizen-2.0-application
+  ${CMAKE_INSTALL_PREFIX}/tizen-2.0-filesystem
+)
+
+set(SRCS 
+       ${SRCS_PLATFORM_IMPLEMENTATION_NOTIFICATION}    
+       ${SRCS_PLATFORM_API_NOTIFICATION}
+       plugin_config.cpp
+       plugin_initializer.cpp
+       JSStatusNotification.cpp
+       JSNotificationManager.cpp
+       NotificationConverter.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+       wrt-plugins-tizen-2.0-tizen-impl
+       wrt-plugins-tizen-2.0-application-impl
+       wrt-plugins-tizen-2.0-filesystem-impl
+       ${LIBS_COMMON}
+       ${LIBS_PLATFORM_IMPLEMENTATION_NOTIFICATION}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION tizen-2.0-notification)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION tizen-2.0-notification)
diff --git a/src/standards/Tizen/Notification/JSNotificationManager.cpp b/src/standards/Tizen/Notification/JSNotificationManager.cpp
new file mode 100644 (file)
index 0000000..ec77e3e
--- /dev/null
@@ -0,0 +1,522 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Commons/Exception.h>
+#include <API/Notification/NotificationFactory.h>
+#include "JSNotificationManager.h"
+#include "NotificationConverter.h"
+#include "plugin_config.h"
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassDefinition JSNotificationManager::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "NotificationManager",
+       NULL,
+       NULL,
+       m_function,
+       initialize,
+       finalize,
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+       
+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 }
+};
+
+
+const JSClassRef JSNotificationManager::getClassRef() 
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSNotificationManager::getClassInfo() 
+{
+       return &m_classInfo;
+}
+
+JSClassRef JSNotificationManager::m_jsClassRef = JSClassCreate(JSNotificationManager::getClassInfo());
+
+void JSNotificationManager::initialize(JSContextRef context, JSObjectRef object) 
+{
+       LogDebug("JSNotificationManager::initialize ");
+
+       JSNotificationManagerPriv* priv = static_cast<JSNotificationManagerPriv*>(JSObjectGetPrivate(object));
+
+       if (priv == NULL)
+       {
+               LogDebug("JSNotificationManager::initialize create");           
+
+               TizenApis::Api::Notification::INotificationManagerPtr  notificationManager(
+                       TizenApis::Api::Notification::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 ");              
+       }
+}
+
+void JSNotificationManager::finalize(JSObjectRef object) 
+{
+       JSNotificationManagerPriv* priv = static_cast<JSNotificationManagerPriv*>(JSObjectGetPrivate(object));
+
+       LogDebug("JSNotificationManager::Finalrize");
+
+       if (priv != NULL) 
+       {
+               JSObjectSetPrivate(object, NULL);
+               delete priv;
+       }
+}
+
+bool JSNotificationManager::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) 
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+
+JSValueRef JSNotificationManager::cancel(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_WRITE);
+               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());
+               std::string id = converter.toString(reserveArguments);
+               
+               TizenApis::Api::Notification::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());
+       }       
+       
+       return JSValueMakeUndefined(context);
+
+}
+
+JSValueRef JSNotificationManager::cancelAll(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_WRITE);
+               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+               
+               if (priv == NULL)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Private object is null");        
+               }
+
+               TizenApis::Api::Notification::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);
+
+}
+
+
+JSValueRef JSNotificationManager::update(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_WRITE);
+               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());
+               TizenApis::Api::Notification::INotificationManagerPtr notificationManager(priv->getObject());
+               TizenApis::Api::Notification::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);
+}
+
+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 
+       {
+
+               AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC_READ);
+               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());
+               std::string id = converter.toString(reserveArguments);
+               
+               TizenApis::Api::Notification::INotificationManagerPtr notificationManager(priv->getObject());
+               TizenApis::Api::Notification::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());
+       }       
+
+}
+
+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;
+
+       try 
+       {
+
+               AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC_WRITE);
+               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());
+               TizenApis::Api::Notification::INotificationManagerPtr notificationManager(priv->getObject());
+               TizenApis::Api::Notification::INotificationPtr notification =  converter.toINotificationPtr(reserveArguments);
+               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);
+
+}
+
+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 
+       {
+
+               AceSecurityStatus status = NOTIFICATION_CHECK_ACCESS(NOTIFICATION_FUNC_READ);
+               TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+               
+               if (priv == NULL)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Private object is null");
+               }
+
+               NotificationConverter converter(priv->getContext());
+               TizenApis::Api::Notification::INotificationManagerPtr notificationManager(priv->getObject());
+               std::vector<TizenApis::Api::Notification::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());
+       }       
+
+}
+
+}
+}
+
diff --git a/src/standards/Tizen/Notification/JSNotificationManager.h b/src/standards/Tizen/Notification/JSNotificationManager.h
new file mode 100644 (file)
index 0000000..165f6dd
--- /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 TIZENAPIS_TIZEN_JS_NOTIFICATION_MANAGER_H_
+#define TIZENAPIS_TIZEN_JS_NOTIFICATION_MANAGER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Notification/INotificationManager.h>
+       
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Notification::INotificationManagerPtr>::Type JSNotificationManagerPriv;
+
+class JSNotificationManager {
+public:
+       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;
+};
+
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Notification/JSStatusNotification.cpp b/src/standards/Tizen/Notification/JSStatusNotification.cpp
new file mode 100644 (file)
index 0000000..0526807
--- /dev/null
@@ -0,0 +1,502 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <API/Notification/NotificationFactory.h>
+#include "JSStatusNotification.h"
+#include "NotificationConverter.h"
+
+//#include "plugin_config.h"
+
+using namespace TizenApis::Commons;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+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 },     
+       {0, 0, 0, 0}
+};
+
+
+       
+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) 
+{
+       LogDebug("JSStatusNotification::initialize, nothing ");
+}
+
+void JSStatusNotification::finalize(JSObjectRef object) 
+{
+       JSStatusNotificationPriv* priv = static_cast<JSStatusNotificationPriv*>(JSObjectGetPrivate(object));
+
+       LogDebug("JSStatusNotification::Finalrize");
+
+       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);
+       std::string property = converter.toString(propertyName);
+
+       try {
+               
+               if (priv == NULL)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException,"Private Object is null");
+               }
+
+
+               TizenApis::Api::Notification::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);
+                       Api::Filesystem::IPathPtr path = 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);
+                       Api::Filesystem::IPathPtr path = Utils::fromVirtualPath(context, soundPath);
+                       soundPath = path->getFullPath();
+                       
+                       notification->setSoundPath(soundPath);
+                       return true;
+               }
+               else if (property == NOTIFICATION_VIBRATION)
+               {
+                       bool virbration = converter.toBool(value);
+                       notification->setVibration(virbration);
+                       return true;
+               }
+               else if (property == NOTIFICATION_APP_CONTROL
+#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
+                               || property == NOTIFICATION_SEVICE
+#endif
+                               )
+               {
+                       TizenApis::Api::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);
+                       LogDebug("progressValue = " << progressValue);
+                       notification->setProgressValue(progressValue);
+                       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;
+}
+
+JSValueRef JSStatusNotification::getProperty(JSContextRef context,
+                                                                               JSObjectRef object,
+                                                                               JSStringRef propertyName,
+                                                                               JSValueRef* exception)
+{
+       LogDebug("OK"); 
+
+       JSStatusNotificationPriv* priv = static_cast<JSStatusNotificationPriv*>(JSObjectGetPrivate(object));
+       NotificationConverter converter(context);
+       std::string property = converter.toString(propertyName);
+       
+
+       try {
+               
+               if (priv == NULL)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException,"Private Object is null");
+               }
+               
+               TizenApis::Api::Notification::INotificationPtr notification(priv->getObject());
+
+               if (notification == NULL)
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException,"Private Object is null");
+               }
+
+               if (property == NOTIFICATION_ID)
+               {
+                       return converter.toJSValueRef(notification->getId());
+               }
+               else if (property == NOTIFICATION_TYPE)
+               {
+                       return converter.toJSValueRef(notification->getType());
+               }
+               else if (property == NOTIFICATION_POSTED_TIME)
+               {
+                       time_t postedTime = notification->getPostedTime();
+                       return converter.toJSValueRef(postedTime);
+               }
+               else if (property == NOTIFICATION_TITLE)
+               {
+                       std::string title = notification->getTitle();
+                       return converter.toJSValueRef(title);
+               }
+               else if (property == NOTIFICATION_CONTENT)
+               {
+                       std::string content = notification->getContent();
+
+                       if (content.size() == 0)
+                               return JSValueMakeNull(context);
+
+                       return converter.toJSValueRef(content);
+               }
+               else if (property == NOTIFICATION_STATUS_TYPE)
+               {
+                       std::string statusType = notification->getStatusType();
+                       return converter.toJSValueRef(statusType);
+               }
+               else if (property == NOTIFICATION_ICON_PATH)
+               {
+                       std::string iconPath = notification->getIconPath();
+                       
+                       if (iconPath.size() == 0)
+                               return JSValueMakeNull(context);
+                       
+                       iconPath = Utils::toVirtualPath(context, iconPath);
+                       
+                       return converter.toJSValueRef(iconPath);
+               }
+               else if (property == NOTIFICATION_SOUND_PATH)
+               {
+                       std::string soundPath = notification->getSoundPath();
+
+                       if (soundPath.size() == 0)
+                               return JSValueMakeNull(context);
+                                               
+                       soundPath = Utils::toVirtualPath(context, soundPath);
+                                               
+                       return converter.toJSValueRef(soundPath);
+               }
+               else if (property == NOTIFICATION_VIBRATION)
+               {
+                       bool virbration = notification->getVibration();
+
+                       return converter.toJSValueRef(virbration);
+               }
+               else if (property == NOTIFICATION_APP_ID)
+               {
+                       std::string appid = notification->getApplicationId();
+                       return converter.toJSValueRef(appid);
+               }
+               else if (property == NOTIFICATION_APP_CONTROL
+#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
+                               || property == NOTIFICATION_SEVICE
+#endif
+                               )
+               {
+                       TizenApis::Api::Application::ApplicationControlPtr appControl = notification->getApplicationControl();
+                       return converter.toJSValueRef(appControl);
+               }
+               else if (property == NOTIFICATION_PROGRESS_VALUE)
+               {
+                       double progress = notification->getProgressValue();
+                       int progressValue = int (progress*100+0.1);
+                       return converter.toJSValueRef(progressValue);
+               }
+               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());
+       }       
+
+}
+
+
+JSObjectRef JSStatusNotification::createJSObject(JSContextRef context, TizenApis::Api::Notification::INotificationPtr notification)
+{
+       JSStatusNotificationPriv* priv = new JSStatusNotificationPriv( context, notification);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+
+JSObjectRef JSStatusNotification::constructor(JSContextRef context,
+    JSObjectRef constructor,
+    size_t argumentCount,
+    const JSValueRef arguments[],
+    JSValueRef* exception)
+{
+       LogDebug("OK"); 
+       TizenApis::Api::Notification::INotificationPtr notification(
+               TizenApis::Api::Notification::NotificationFactory::getInstance().getNotification(FALSE));
+       NotificationConverter converter(context);
+       JSStatusNotificationPriv* priv = new JSStatusNotificationPriv(context, notification);
+
+       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);                                
+               }
+
+               std::string statusType = converter.toString(reserveArguments[0]);
+
+               if (statusType == "ONGOING" || statusType == "PROGRESS") 
+               {
+                       notification.Reset();
+                       TizenApis::Api::Notification::INotificationPtr newNotification(
+                       TizenApis::Api::Notification::NotificationFactory::getInstance().getNotification(TRUE));
+                       notification = newNotification;
+
+                       if (priv)
+                       {
+                               delete priv;
+                               priv = new JSStatusNotificationPriv(context, notification);
+                       }
+               }
+               
+               notification->setStatusType(converter.toString(reserveArguments[0]));
+               notification->setTitle(converter.toString(reserveArguments[1]));
+
+               if (!JSValueIsUndefined(context, reserveArguments[2]))
+               {       
+                       converter.toNotificationFromDict(notification, reserveArguments[2]);
+               }
+               
+           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());
+       }       
+       return NULL;
+}
+
+TizenApis::Api::Notification::INotificationPtr JSStatusNotification::getNotification(JSContextRef context, JSValueRef value)
+{
+       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();
+}
+
+
+}
+}
+
diff --git a/src/standards/Tizen/Notification/JSStatusNotification.h b/src/standards/Tizen/Notification/JSStatusNotification.h
new file mode 100644 (file)
index 0000000..2693c72
--- /dev/null
@@ -0,0 +1,85 @@
+//
+// 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_JS_STATUS_NOTIFICATION_H_
+#define TIZENAPIS_TIZEN_JS_STATUS_NOTIFICATION_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Notification/INotification.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<TizenApis::Api::Notification::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_VALUE "progressValue"
+
+
+class JSStatusNotification {
+public:
+       static const JSClassDefinition* getClassInfo();
+       static const JSClassRef getClassRef();
+       static TizenApis::Api::Notification::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, 
+               TizenApis::Api::Notification::INotificationPtr notification);
+       
+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;
+};
+
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Notification/NotificationConverter.cpp b/src/standards/Tizen/Notification/NotificationConverter.cpp
new file mode 100644 (file)
index 0000000..125a5a3
--- /dev/null
@@ -0,0 +1,202 @@
+//
+// 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 "JSStatusNotification.h"
+#include "NotificationConverter.h"
+
+
+#include <pcrecpp.h>
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+NotificationConverter::NotificationConverter(JSContextRef context) :
+    Converter(context)
+{
+}
+
+NotificationConverter::~NotificationConverter()
+{
+}
+
+TizenApis::Api::Notification::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); 
+}
+
+TizenApis::Api::Application::ApplicationControlPtr NotificationConverter::toIApplicationPtr(const JSValueRef arg)
+{
+       Application::ApplicationConverter applicationConverter(m_context);
+       return applicationConverter.toApplicationControl(arg);
+}
+
+void NotificationConverter::NotificationConverter::toNotificationFromDict(
+       TizenApis::Api::Notification::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)); 
+               
+       Api::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);
+
+    if (!JSValueIsUndefined(m_context, contentValue)) 
+       {
+               std::string content = toString(contentValue);
+               notification->setContent(content);
+       }
+    if (!JSValueIsUndefined(m_context, iconValue)) 
+       {
+               std::string icon = toString(iconValue);
+               path = Utils::fromVirtualPath(m_context, icon);
+               icon = path->getFullPath();
+               LogDebug(icon);
+               
+               notification->setIconPath(icon);
+       }
+    if (!JSValueIsUndefined(m_context, soundValue)) 
+       {
+               std::string sound = toString(soundValue);
+               path = Utils::fromVirtualPath(m_context, sound);
+               sound = path->getFullPath();
+               LogDebug(sound);
+
+               notification->setSoundPath(sound);
+       }
+    if (!JSValueIsUndefined(m_context, vibrationValue)) 
+       {
+               bool vibration = toBool(vibrationValue);
+               notification->setVibration(vibration);
+       }
+
+    if (!JSValueIsUndefined(m_context, appControlValue))
+       {
+               TizenApis::Api::Application::ApplicationControlPtr appControl = toIApplicationPtr(appControlValue);
+               notification->setApplicationControl(appControl);
+       }
+#ifdef APPLICATION_API_BACKWARD_COMPATIBILITY
+    else if (!JSValueIsUndefined(m_context, serviceValue))
+       {
+               TizenApis::Api::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, progressValue)) 
+       {
+               unsigned short value = toULong(progressValue);
+               notification->setProgressValue(value);
+       }
+}
+
+JSValueRef NotificationConverter::toJSValueRef(const TizenApis::Api::Application::ApplicationControlPtr &arg)
+{
+       Application::ApplicationConverter applicationConverter(m_context);
+       return applicationConverter.toJSValueRef(arg);
+}
+
+JSValueRef NotificationConverter::toJSValueRef(const TizenApis::Api::Notification::INotificationPtr arg)
+{
+       if (arg->getType() == "STATUS")
+       {
+               return JSStatusNotification::createJSObject(m_context, arg);
+       }
+       else 
+       {
+               ThrowMsg(ConversionException, "type missmatch");
+       }
+}
+
+JSValueRef NotificationConverter::toJSValueRef(const std::vector<TizenApis::Api::Notification::INotificationPtr> &arg)
+{
+       int count = arg.size();
+       int index = 0;
+       JSObjectRef notificaitions[count];
+
+       LogDebug(count);
+       
+       for (index = 0; index < count; index++)
+       {
+               if (arg[index]->getType() == "STATUS")
+               {
+                       notificaitions[index] = JSStatusNotification::createJSObject(m_context, arg[index]);
+               }
+               else 
+               {
+                       ThrowMsg(ConversionException, "type missmatch");
+               }
+       }
+       JSObjectRef result = JSObjectMakeArray(m_context, count, notificaitions, NULL);
+       return result;  
+}
+}
+}
+
diff --git a/src/standards/Tizen/Notification/NotificationConverter.h b/src/standards/Tizen/Notification/NotificationConverter.h
new file mode 100644 (file)
index 0000000..f161587
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include <API/Notification/INotification.h>
+#include <Tizen/Application/ApplicationConverter.h>
+#include <Tizen/Filesystem/FilesystemUtils.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+       
+class NotificationConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+public:
+       using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
+
+       explicit NotificationConverter(JSContextRef context);
+       virtual ~NotificationConverter();
+       TizenApis::Api::Notification::INotificationPtr toINotificationPtr(const JSValueRef arg);
+       TizenApis::Api::Application::ApplicationControlPtr toIApplicationPtr(const JSValueRef arg);     
+       void toNotificationFromDict(TizenApis::Api::Notification::INotificationPtr& notification, const JSValueRef arg);
+       JSValueRef toJSValueRef(const TizenApis::Api::Application::ApplicationControlPtr &arg);
+       JSValueRef toJSValueRef(const TizenApis::Api::Notification::INotificationPtr arg);
+       JSValueRef toJSValueRef(const std::vector<TizenApis::Api::Notification::INotificationPtr> &arg);
+       
+};
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/Notification/NotificationCoverter.cpp b/src/standards/Tizen/Notification/NotificationCoverter.cpp
new file mode 100644 (file)
index 0000000..ef4e888
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// 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 <Tizen/Application/ApplicationConverter.h>
+#include "JSStatusNotification.h"
+#include "NotificationConverter.h"
+
+#include <pcrecpp.h>
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+NotificationCoverter::NotificationCoverter(JSContextRef context) :
+    Converter(context)
+{
+}
+
+NotificationCoverter::~NotificationCoverter()
+{
+}
+
+TizenApis::Api::Notification::INotificationPtr NotificationCoverter::toINotificationPtr(const JSValueRef arg)
+{
+       if (!JSValueIsObjectOfClass(m_context, arg, JSNotification::getClassRef())) 
+       {
+               ThrowMsg(ConversionException, "type missmatch");
+       }
+       
+       return JSNotification::getNotification(m_context, arg);
+}
+
+}
+}
+
diff --git a/src/standards/Tizen/Notification/config.xml b/src/standards/Tizen/Notification/config.xml
new file mode 100644 (file)
index 0000000..a1a8991
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+       <library-name>libwrt-plugins-tizen-2.0-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>
+               <device-capability>notification.read</device-capability>
+       </api-feature>
+       <api-feature>
+               <name>http://tizen.org/privilege/notification.write</name>
+               <device-capability>notification.read</device-capability>
+               <device-capability>notification.write</device-capability>
+       </api-feature>
+</plugin-properties>
+
diff --git a/src/standards/Tizen/Notification/plugin_config.cpp b/src/standards/Tizen/Notification/plugin_config.cpp
new file mode 100644 (file)
index 0000000..b43af7d
--- /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 <map>
+#include <utility>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include "plugin_config.h"
+
+#define NOTIFICATION_FEATURE_API_READ "http://tizen.org/privilege/notification.read"
+#define NOTIFICATION_FEATURE_API_WRITE "http://tizen.org/privilege/notification.write"
+
+#define NOTIFICATION_DEVICE_CAP_READ "notification.read"
+#define NOTIFICATION_DEVICE_CAP_WRITE "notification.write"
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+static WrtDeviceApis::Commons::FunctionMapping createNotificationFunctions();
+
+static WrtDeviceApis::Commons::FunctionMapping NotificationFunctions = createNotificationFunctions();
+
+const char *NOTIFICATION_FUNC_READ_WRITE = "NotificationReadWrite";
+const char *NOTIFICATION_FUNC_WRITE = "NotificationWrite";
+const char *NOTIFICATION_FUNC_READ = "NotificationRead";;
+
+
+DEFINE_FUNCTION_GETTER(Notification, NotificationFunctions);
+
+static WrtDeviceApis::Commons::FunctionMapping createNotificationFunctions()
+{
+       using namespace WrtDeviceApis::Commons;
+
+       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_NOTIFICATION_READ,  NOTIFICATION_DEVICE_CAP_READ);
+       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_NOTIFICATION_WRITE, NOTIFICATION_DEVICE_CAP_WRITE);
+
+       ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+
+       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_NOTIFICATION_READ);
+       ACE_ADD_DEVICE_CAP(DEVICE_LIST_NOTIFICATION_READ, DEVICE_CAP_NOTIFICATION_READ);
+
+       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_NOTIFICATION_WRITE);
+       ACE_ADD_DEVICE_CAP(DEVICE_LIST_NOTIFICATION_WRITE, DEVICE_CAP_NOTIFICATION_WRITE);
+
+
+       ACE_CREATE_FEATURE(FEATURE_READ, NOTIFICATION_FEATURE_API_READ);
+       ACE_CREATE_FEATURE(FEATURE_WRITE, NOTIFICATION_FEATURE_API_WRITE);
+
+
+       ACE_CREATE_FEATURE_LIST(FEATURES_WRITE);
+       ACE_ADD_API_FEATURE(FEATURES_WRITE, FEATURE_WRITE);
+
+       ACE_CREATE_FEATURE_LIST(FEATURES_READ);
+       ACE_ADD_API_FEATURE(FEATURES_READ, FEATURE_READ);
+
+       FunctionMapping NotificationFunctions;
+
+       AceFunction NotificationWrite = ACE_CREATE_FUNCTION(FUNCTION_NOTIFICATION_WRITE, NOTIFICATION_FUNC_WRITE, 
+               FEATURES_WRITE, DEVICE_LIST_NOTIFICATION_WRITE);
+       NotificationFunctions.insert(std::make_pair(NOTIFICATION_FUNC_WRITE, NotificationWrite));
+
+       AceFunction NotificationRead = ACE_CREATE_FUNCTION(FUNCTION_NOTIFICATION_READ, NOTIFICATION_FUNC_READ, 
+               FEATURES_READ, DEVICE_LIST_NOTIFICATION_READ);
+       NotificationFunctions.insert(std::make_pair(NOTIFICATION_FUNC_READ, NotificationRead));
+
+       return NotificationFunctions;
+}
+} 
+}
+
+#undef NOTIFICATION_FEATURE_API 
+#undef NOTIFICATION_FEATURE_API_READ 
+#undef NOTIFICATION_FEATURE_API_WRITE 
+#undef NOTIFICATION_DEVICE_CAP_READ 
+#undef NOTIFICATION_DEVICE_CAP_WRITE 
diff --git a/src/standards/Tizen/Notification/plugin_config.h b/src/standards/Tizen/Notification/plugin_config.h
new file mode 100644 (file)
index 0000000..1e79368
--- /dev/null
@@ -0,0 +1,41 @@
+//
+// 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_JS_NOTIFICATION_PLUGIN_CONFIG_H_
+#define TIZENAPIS_TIZEN_JS_NOTIFICATION_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+extern const char *NOTIFICATION_FUNC_READ_WRITE;
+extern const char *NOTIFICATION_FUNC_WRITE ;
+extern const char *NOTIFICATION_FUNC_READ;
+
+
+DECLARE_FUNCTION_GETTER(Notification);
+
+#define NOTIFICATION_CHECK_ACCESS(functionName)                       \
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(                \
+        getNotificationFunctionData,             \
+        functionName)
+}
+}
+
+#endif 
diff --git a/src/standards/Tizen/Notification/plugin_initializer.cpp b/src/standards/Tizen/Notification/plugin_initializer.cpp
new file mode 100644 (file)
index 0000000..e4c7938
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+
+#include "JSNotificationManager.h"
+#include "JSStatusNotification.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+void on_widget_start_callback(int widgetId)
+{
+       LogDebug("[Tizen\\Notification ] on_widget_start_callback ("<<widgetId<<")");
+       Try
+       {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+       }
+       Catch(Commons::Exception)
+       {
+               LogError("WrtAccess initialization failed");
+       }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+       LogDebug("[Tizen\\Notification] on_widget_stop_callback ("<<widgetId<<")");
+       Try
+       {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+       }
+       Catch(Commons::Exception)
+       {
+               LogError("WrtAccess deinitialization failed");
+       }
+}
+
+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"
+
+PLUGIN_CLASS_MAP_BEGIN
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, UI_NOTIFICATION,
+      (js_class_template_getter)TizenApis::Tizen1_0::JSNotificationManager::getClassRef,NULL)
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, UI_NOTIFICATION_SIMPLE,
+                 (js_class_template_getter)TizenApis::Tizen1_0::JSStatusNotification::getClassRef,NULL)
+PLUGIN_CLASS_MAP_END
+
diff --git a/src/standards/Tizen/Power/CMakeLists.txt b/src/standards/Tizen/Power/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..1903fbf
--- /dev/null
@@ -0,0 +1,32 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-power")
+set(DESTINATION_NAME  "tizen-2.0-power")
+
+set(CMAKE_INSTALL_RPATH
+    ${CMAKE_INSTALL_RPATH}
+    ${CMAKE_INSTALL_PREFIX}/tizen-2.0-tizen
+)
+
+set(SRCS
+  ${SRCS_PLATFORM_API_POWER}
+  ${SRCS_PLATFORM_IMPLEMENTATION_POWER}
+  PowerResponseDispatcher.cpp
+  PowerConverter.cpp
+  JSPowerManager.cpp
+  PowerListenerManager.cpp
+  plugin_initializer.cpp
+  plugin_config.cpp
+)
+
+include_directories(
+  ${INCLUDES_PLATFORM_IMPLEMENTATION_POWER}
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${LIBS_COMMON}
+  ${LIBS_PLATFORM_IMPLEMENTATION_POWER}
+  wrt-plugins-tizen-2.0-tizen-impl
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
diff --git a/src/standards/Tizen/Power/JSPowerManager.cpp b/src/standards/Tizen/Power/JSPowerManager.cpp
new file mode 100755 (executable)
index 0000000..5f2781d
--- /dev/null
@@ -0,0 +1,703 @@
+//
+// 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 <API/Power/OnPowerStateChanged.h>
+#include <Tizen/Power/PowerManager.h>
+
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/SecurityExceptions.h>
+
+#include "JSPowerManager.h"
+#include "PowerConverter.h"
+#include "plugin_config.h"
+#include "PowerResponseDispatcher.h"
+
+#include "PowerListenerManager.h"
+
+using namespace TizenApis::Api::Power;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 { 
+namespace Power {
+
+JSClassDefinition JSPowerManager::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    TIZEN_POWER_INTERFACE,
+    NULL, //ParentClass
+    NULL, //StaticValues
+    m_function,
+    initialize,
+    finalize,
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    NULL, //HasInstance,
+    NULL //ConvertToType
+};
+
+JSStaticFunction JSPowerManager::m_function[] = {
+    { POWER_FUNCTION_API_REQUEST, request, kJSPropertyAttributeNone },
+    { POWER_FUNCTION_API_RELEASE, release, kJSPropertyAttributeNone },
+    { POWER_FUNCTION_API_SET_SCREEN_STATE_CHANGE_LISTENER, setScreenStateChangeListener, kJSPropertyAttributeNone },
+    { POWER_FUNCTION_API_UNSET_SCREEN_STATE_CHANGE_LISTENER, unsetScreenStateChangeListener, kJSPropertyAttributeNone },
+    { POWER_FUNCTION_API_GET_SCREEN_BRIGHTNESS, getScreenBrightness, kJSPropertyAttributeNone },
+    { POWER_FUNCTION_API_SET_SCREEN_BRIGHTNESS, setScreenBrightness, kJSPropertyAttributeNone },
+    { POWER_FUNCTION_API_IS_SCREEN_ON, isScreenOn, kJSPropertyAttributeNone },
+    { POWER_FUNCTION_API_RESTORE_SCREEN_BRIGHTNESS, restoreScreenBrightness, kJSPropertyAttributeNone },
+    { POWER_FUNCTION_API_TURN_SCREEN_ON, turnScreenOn, kJSPropertyAttributeNone },
+    { POWER_FUNCTION_API_TURN_SCREEN_OFF, turnScreenOff, kJSPropertyAttributeNone },
+
+    { 0, 0, 0 }
+};
+
+JSClassRef JSPowerManager::m_jsClassRef = JSClassCreate(JSPowerManager::getClassInfo());
+
+void JSPowerManager::initialize(JSContextRef context, JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        LogInfo("Create power manager private object.");
+        IPowerManagerPtr power(new TizenApis::Platform::Power::PowerManager());
+        PowerManagerPrivObject *priv = new PowerManagerPrivObject(context, power);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            delete priv;
+        }
+    } else {
+        LogInfo("Private object already set.");
+    }
+}
+
+void JSPowerManager::finalize(JSObjectRef object)
+{
+    PowerManagerPrivObject *priv = static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(object));
+    if (priv) {
+        LogInfo("Deleting power manager private object.");
+        delete priv;
+        JSObjectSetPrivate(object, NULL);
+    }
+}
+
+const JSClassRef JSPowerManager::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSPowerManager::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSValueRef JSPowerManager::request(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    PowerManagerPrivObject *privateObject =
+        static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = POWER_CHECK_ACCESS(POWER_FUNCTION_API_REQUEST);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IPowerManagerPtr powerManager = privateObject->getObject();
+
+        if (argumentCount<2) {
+            ThrowMsg(ConversionException, "Wrong number of parameters.");
+        }
+
+        PowerConverter converter(context);
+
+        PowerResource resource = converter.toPowerResource(arguments[0]);
+        PowerState state = converter.toPowerState(arguments[1]);
+        LogDebug("resource: "<<resource<<", state: "<<state);
+
+        IEventRequestPtr dplEvent(new IEventRequest());
+        dplEvent->setResource(resource);
+        dplEvent->setState(state);
+        dplEvent->setForSynchronousCall();
+        powerManager->request(dplEvent);
+
+               return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSPowerManager::release(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    PowerManagerPrivObject *privateObject =
+        static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IPowerManagerPtr powerManager = privateObject->getObject();
+
+        if (argumentCount<1) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        PowerConverter converter(context);
+        PowerResource resource = converter.toPowerResource(arguments[0]);
+
+        LogDebug("Make sync operation for release: "<<resource);
+
+        IEventReleasePtr dplEvent(new IEventRelease());
+        dplEvent->setResource(resource);
+        dplEvent->setForSynchronousCall();
+        powerManager->release(dplEvent);
+
+        return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSPowerManager::setScreenStateChangeListener(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    PowerManagerPrivObject *privateObject =
+        static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IPowerManagerPtr powerManager = privateObject->getObject();
+
+        JSContextRef globalContext = privateObject->getContext();
+
+        PowerConverter converter(context);
+
+        if (argumentCount<1) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        IEventSetScreenStateChangeListenerPtr dplEvent(new IEventSetScreenStateChangeListener());
+        dplEvent->setForSynchronousCall();
+
+        // Process the listener
+        JSValueRef onChanged = converter.toFunction(arguments[0]);
+        if(onChanged) {
+            LogDebug("Setting an emitter.");
+            JSCallbackManagerPtr listener = JSCallbackManager::createObject(globalContext, onChanged, NULL);
+
+            OnPowerStateChangedEmitterPtr emitter(new OnPowerStateChangedEmitter());
+            emitter->setListener(&PowerResponseDispatcher::getInstance());
+            emitter->setEventPrivateData(DPL::StaticPointerCast<IEventPrivateData>(listener));
+            dplEvent->setEmitter(emitter);
+        }  else {
+            LogDebug("Listener argument is not a function for listener.");
+        }
+
+        powerManager->setScreenStateChangeListener(dplEvent);
+
+               PowerListenerCancellerPtr canceller = PowerListenerCancellerPtr(new PowerListenerCanceller(globalContext, thisObject, 0));
+               TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+               PowerListenerManagerSingleton::Instance().registerListener(listenerItem, globalContext);
+
+               return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSPowerManager::unsetScreenStateChangeListener(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    PowerManagerPrivObject *privateObject =
+        static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IPowerManagerPtr powerManager = privateObject->getObject();
+
+        JSContextRef globalContext = privateObject->getContext();
+
+        IEventUnsetScreenStateChangeListenerPtr dplEvent(new IEventUnsetScreenStateChangeListener());
+        dplEvent->setForSynchronousCall();
+        powerManager->unsetScreenStateChangeListener(dplEvent);
+
+               PowerListenerCancellerPtr canceller = PowerListenerCancellerPtr(new PowerListenerCanceller(globalContext, thisObject, 0));
+               TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+               PowerListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+
+        return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSPowerManager::getScreenBrightness(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    PowerManagerPrivObject *privateObject =
+        static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IPowerManagerPtr powerManager = privateObject->getObject();
+
+        IEventGetScreenBrightnessPtr dplEvent(new IEventGetScreenBrightness());
+        dplEvent->setForSynchronousCall();
+        powerManager->getScreenBrightness(dplEvent);
+
+        PowerConverter converter(context);
+
+        if(dplEvent->getResult()) {
+            return converter.toJSValueRef(dplEvent->getBrightenss());
+        } else {
+            LogDebug("Failed to get brightness.");
+        }
+
+               return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSPowerManager::setScreenBrightness(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    PowerManagerPrivObject *privateObject =
+        static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = POWER_CHECK_ACCESS(POWER_FUNCTION_API_SET_SCREEN_BRIGHTNESS);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        if (argumentCount<1) {
+            ThrowMsg(ConversionException, "Wrong number of parameters.");
+        }
+
+        PowerConverter converter(context);
+
+        IPowerManagerPtr powerManager = privateObject->getObject();
+        double brightness = converter.toDouble(arguments[0]);
+        if( std::isnan(brightness) ) {
+            ThrowMsg(ConversionException, "Wrong parameter type.");
+        }
+
+        IEventSetScreenBrightnessPtr dplEvent(new IEventSetScreenBrightness());
+        dplEvent->setBrightness(brightness);
+        dplEvent->setForSynchronousCall();
+        powerManager->setScreenBrightness(dplEvent);
+
+               return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSPowerManager::isScreenOn(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    PowerManagerPrivObject *privateObject =
+        static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        PowerConverter converter(context);
+
+        IPowerManagerPtr powerManager = privateObject->getObject();
+
+        IEventIsScreenOnPtr dplEvent(new IEventIsScreenOn());
+        dplEvent->setForSynchronousCall();
+        powerManager->isScreenOn(dplEvent);
+
+        if(dplEvent->getResult()) {
+            return converter.toJSValueRef(dplEvent->getIsScreenOn());
+        } else {
+            LogDebug("Failed to get screen on flag.");
+        }
+
+               return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSPowerManager::restoreScreenBrightness(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    PowerManagerPrivObject *privateObject =
+        static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IPowerManagerPtr powerManager = privateObject->getObject();
+
+        IEventRestoreScreenBrightnessPtr dplEvent(new IEventRestoreScreenBrightness());
+        dplEvent->setForSynchronousCall();
+        powerManager->restoreScreenBrightness(dplEvent);
+
+               return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSPowerManager::turnScreenOn(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    PowerManagerPrivObject *privateObject =
+        static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = POWER_CHECK_ACCESS(POWER_FUNCTION_API_TURN_SCREEN_ON);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IPowerManagerPtr powerManager = privateObject->getObject();
+
+        IEventTurnScreenOnPtr dplEvent(new IEventTurnScreenOn());
+        dplEvent->setForSynchronousCall();
+        powerManager->turnScreenOn(dplEvent);
+
+               return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+JSValueRef JSPowerManager::turnScreenOff(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    PowerManagerPrivObject *privateObject =
+        static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = POWER_CHECK_ACCESS(POWER_FUNCTION_API_TURN_SCREEN_OFF);
+
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Try
+    {
+        if (!privateObject) {
+            ThrowMsg(ConversionException, "Object is null.");
+        }
+
+        IPowerManagerPtr powerManager = privateObject->getObject();
+
+        IEventTurnScreenOffPtr dplEvent(new IEventTurnScreenOff());
+        dplEvent->setForSynchronousCall();
+        powerManager->turnScreenOff(dplEvent);
+
+               return JSValueMakeUndefined(context);
+    }
+    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(ConversionException)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
+    }
+    Catch(Exception)
+    {
+               LogWarning("Exception: "<<_rethrown_exception.GetMessage());
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
+    }
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Power/JSPowerManager.h b/src/standards/Tizen/Power/JSPowerManager.h
new file mode 100755 (executable)
index 0000000..01666a3
--- /dev/null
@@ -0,0 +1,193 @@
+//
+// 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 _JS_TIZEN_POWER_MANAGER_H_
+#define _JS_TIZEN_POWER_MANAGER_H_
+
+#include <string>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Power/IPowerManager.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Power {
+
+#define TIZEN_POWER_INTERFACE "PowerManager"
+
+#define TIZEN_POWER_ENUM_RESOURCE_SCREEN       "SCREEN"
+#define TIZEN_POWER_ENUM_RESOURCE_CPU          "CPU"
+
+#define TIZEN_POWER_ENUM_SCREEN_OFF            "SCREEN_OFF"
+#define TIZEN_POWER_ENUM_SCREEN_DIM            "SCREEN_DIM"
+#define TIZEN_POWER_ENUM_SCREEN_NORMAL "SCREEN_NORMAL"
+#define TIZEN_POWER_ENUM_SCREEN_BRIGHT "SCREEN_BRIGHT"
+
+#define TIZEN_POWER_ENUM_CPU_AWAKE     "CPU_AWAKE"
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Power::IPowerManagerPtr,
+                               WrtDeviceApis::CommonsJavaScript::NoOwnership> PowerManagerPrivObject;
+
+class JSPowerManager
+{
+  public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+
+  private:
+
+    /**
+     * 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;
+
+    /**
+     * 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);
+
+    /**
+     * Requests a power resource.
+     */
+    static JSValueRef request(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Releases a previous power request.
+     */
+    static JSValueRef release(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Sets the screen state change listener.
+     */
+    static JSValueRef setScreenStateChangeListener(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Unsets the screen state change listener.
+     */
+    static JSValueRef unsetScreenStateChangeListener(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Gets the screen brightness.
+     */
+    static JSValueRef getScreenBrightness(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Sets the screen brightness.
+     */
+    static JSValueRef setScreenBrightness(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Returns true if screen is on.
+     */
+    static JSValueRef isScreenOn(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Restore the screen brightensss to the default setting value.
+     */
+    static JSValueRef restoreScreenBrightness(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Turns the screen on.
+     */
+    static JSValueRef turnScreenOn(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+
+    /**
+     * Turns the screen off.
+     */
+    static JSValueRef turnScreenOff(JSContextRef context,
+            JSObjectRef object,
+            JSObjectRef thisObject,
+            size_t argumentCount,
+            const JSValueRef arguments[],
+            JSValueRef* exception);
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_POWER_MANAGER_H_ */
+
diff --git a/src/standards/Tizen/Power/PowerConverter.cpp b/src/standards/Tizen/Power/PowerConverter.cpp
new file mode 100755 (executable)
index 0000000..276cb0b
--- /dev/null
@@ -0,0 +1,126 @@
+//
+// 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/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include "JSPowerManager.h"
+#include "PowerConverter.h"
+
+using namespace TizenApis::Api::Power;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Power {
+
+PowerConverter::PowerConverter(JSContextRef context) : Converter(context)
+{
+}
+
+PowerConverter::~PowerConverter()
+{
+}
+
+JSValueRef PowerConverter::toFunctionOrNull(const JSValueRef& arg)
+{
+    if (Validator(m_context).isCallback(arg)) {
+        return arg;
+    } else if (!JSValueIsNull(m_context,
+                              arg) && !JSValueIsUndefined(m_context, arg)) {
+        ThrowMsg(ConversionException, "Not a function nor JS null.");
+    }
+    return NULL;
+}
+
+JSValueRef PowerConverter::toFunction(const JSValueRef& arg)
+{
+    if (Validator(m_context).isCallback(arg)) {
+        return arg;
+    }
+    ThrowMsg(ConversionException, "Not a function.");
+}
+
+std::string PowerConverter::toTizenValue(PowerResource abstractValue) const
+{
+    switch (abstractValue) {
+    case SCREEN_RESOURCE:
+        return TIZEN_POWER_ENUM_RESOURCE_SCREEN;
+    case CPU_RESOURCE:
+        return TIZEN_POWER_ENUM_RESOURCE_CPU;
+    default:
+        break;
+    }
+
+    ThrowMsg(ConversionException, "Invalid resource value.");
+}
+
+PowerResource PowerConverter::toPowerResource(JSValueRef tizenValue)
+{
+    std::string stringValue = toString(tizenValue);
+    if(!stringValue.compare(TIZEN_POWER_ENUM_RESOURCE_SCREEN))
+        return SCREEN_RESOURCE;
+    else if (!stringValue.compare(TIZEN_POWER_ENUM_RESOURCE_CPU))
+        return CPU_RESOURCE;
+    else
+        ThrowMsg(ConversionException, "Invalid resource value.");
+
+    return UNDEFINED_RESOURCE;
+}
+
+std::string PowerConverter::toTizenValue(PowerState abstractValue) const
+{
+    switch (abstractValue) {
+    case SCREEN_OFF_STATE:
+        return TIZEN_POWER_ENUM_SCREEN_OFF;
+    case SCREEN_DIM_STATE:
+        return TIZEN_POWER_ENUM_SCREEN_DIM;
+    case SCREEN_NORMAL_STATE:
+        return TIZEN_POWER_ENUM_SCREEN_NORMAL;
+    case SCREEN_BRIGHT_STATE:
+        return TIZEN_POWER_ENUM_SCREEN_BRIGHT;
+    case CPU_AWAKE_STATE:
+        return TIZEN_POWER_ENUM_CPU_AWAKE;
+    default:
+        break;
+    }
+
+    ThrowMsg(ConversionException, "Invalid power state value.");
+}
+
+PowerState PowerConverter::toPowerState(JSValueRef tizenValue)
+{
+    std::string stringValue = toString(tizenValue);
+    if(!stringValue.compare(TIZEN_POWER_ENUM_SCREEN_DIM))
+        return SCREEN_DIM_STATE;
+    else if (!stringValue.compare(TIZEN_POWER_ENUM_SCREEN_NORMAL))
+        return SCREEN_NORMAL_STATE;
+    else if (!stringValue.compare(TIZEN_POWER_ENUM_SCREEN_BRIGHT))
+        return SCREEN_BRIGHT_STATE;
+    else if (!stringValue.compare(TIZEN_POWER_ENUM_CPU_AWAKE))
+        return CPU_AWAKE_STATE;
+    else
+        ThrowMsg(ConversionException, "Invalid power state value.");
+
+    return UNDEFINED_STATE;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Power/PowerConverter.h b/src/standards/Tizen/Power/PowerConverter.h
new file mode 100755 (executable)
index 0000000..e1bf1ff
--- /dev/null
@@ -0,0 +1,58 @@
+//
+// 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 _JS_TIZEN_POWER_CONVERTER_H_
+#define _JS_TIZEN_POWER_CONVERTER_H_
+
+#include <string>
+#include <API/Power/IPowerManager.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Power {
+
+class PowerConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+  public:
+    explicit PowerConverter(JSContextRef context);
+    virtual ~PowerConverter();
+
+    TizenApis::Api::Power::PowerResource toPowerResource(JSValueRef tizenValue);
+    TizenApis::Api::Power::PowerState toPowerState(JSValueRef tizenValue);
+
+    std::string toTizenValue(TizenApis::Api::Power::PowerResource abstractValue) const;
+    std::string toTizenValue(TizenApis::Api::Power::PowerState abstractValue) const;
+
+    /**
+     * @throw InvalidArgumentException If not a callback nor JS null.
+     */
+    JSValueRef toFunctionOrNull(const JSValueRef& arg);
+
+    /**
+     * @throw ConversionException If JS null.
+     * @throw InvalidArgumentException If not a callback nor JS null.
+     */
+    JSValueRef toFunction(const JSValueRef& arg);
+};
+
+}
+}
+}
+
+#endif /* _JS_TIZEN_POWER_CONVERTER_H_ */
diff --git a/src/standards/Tizen/Power/PowerListenerManager.cpp b/src/standards/Tizen/Power/PowerListenerManager.cpp
new file mode 100755 (executable)
index 0000000..0fff6e0
--- /dev/null
@@ -0,0 +1,23 @@
+//
+// 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 "PowerListenerManager.h"
+#include <dpl/singleton_impl.h>
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::Power::PowerListenerManager)
+
diff --git a/src/standards/Tizen/Power/PowerListenerManager.h b/src/standards/Tizen/Power/PowerListenerManager.h
new file mode 100755 (executable)
index 0000000..29a342e
--- /dev/null
@@ -0,0 +1,88 @@
+//
+// 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_POWER_LISTENER_MANAGER_H_
+#define _TIZEN_POWER_LISTENER_MANAGER_H_
+
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Tizen/Common/IListenerManager.h>
+#include "JSPowerManager.h"
+#include <API/Power/IPowerManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Power {
+
+using namespace TizenApis::Api::Power;
+
+class PowerListenerManager : public TizenApis::Commons::IListenerController
+{
+public:
+       PowerListenerManager()
+       {
+       }
+
+       virtual ~PowerListenerManager()
+       {
+       }
+};
+typedef DPL::Singleton<PowerListenerManager> PowerListenerManagerSingleton;
+
+class PowerListenerCanceller : public TizenApis::Commons::IListenerItem
+{
+public:
+       PowerListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
+               TizenApis::Commons::IListenerItem(context, object, watchId)
+       {
+       }
+
+       virtual ~PowerListenerCanceller()
+       {
+       }
+
+       virtual void cancelListener()
+       {
+               PowerManagerPrivObject *privateObject = static_cast<PowerManagerPrivObject*>(JSObjectGetPrivate(m_object));
+               if (!privateObject) {
+                       LogWarning("Object is null.");
+                       return;
+               }
+
+               IPowerManagerPtr powerManager = privateObject->getObject();
+
+               Try {
+                       LogDebug("Remove change listener for power resources.");
+                       IEventUnsetScreenStateChangeListenerPtr dplEvent(new IEventUnsetScreenStateChangeListener());
+                       dplEvent->setForSynchronousCall();
+                       powerManager->unsetScreenStateChangeListener(dplEvent);
+               } Catch(WrtDeviceApis::Commons::Exception) {
+                       LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               }
+       }
+};
+typedef DPL::SharedPtr<PowerListenerCanceller> PowerListenerCancellerPtr;
+
+} // Power
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_POWER_LISTENER_MANAGER_H_
diff --git a/src/standards/Tizen/Power/PowerResponseDispatcher.cpp b/src/standards/Tizen/Power/PowerResponseDispatcher.cpp
new file mode 100755 (executable)
index 0000000..a36cd4c
--- /dev/null
@@ -0,0 +1,80 @@
+//
+// 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 "PowerResponseDispatcher.h"
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include "PowerConverter.h"
+#include <API/Power/IPowerManager.h>
+
+using namespace TizenApis::Api::Power;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Power {
+
+PowerResponseDispatcher& PowerResponseDispatcher::getInstance()
+{
+    static PowerResponseDispatcher instance;
+    return instance;
+}
+
+PowerResponseDispatcher::PowerResponseDispatcher() :
+    OnPowerStateChangedListener(ThreadEnum::NULL_THREAD)
+{
+}
+
+PowerResponseDispatcher::~PowerResponseDispatcher()
+{
+}
+
+void PowerResponseDispatcher::onAnswerReceived(const OnPowerStateChangedPtr& event)
+{
+    LogDebug("entered");
+    JSCallbackManagerPtr listener = DPL::StaticPointerCast<JSCallbackManager>(event->getPrivateData());
+    if (!listener) {
+        LogError("No listener callback!");
+        return;
+    }
+
+    Try
+    {
+        if (event->getResult()) {
+            PowerConverter converter(listener->getContext());
+            JSValueRef previousState = converter.toJSValueRef(converter.toTizenValue(event->getPreviousState()));
+            JSValueRef changedState = converter.toJSValueRef(converter.toTizenValue(event->getChangedState()));
+            JSValueRef objParam[2] = {previousState, changedState};
+            listener->callOnSuccess(objParam, 2);
+            return;
+        } else {
+            LogWarning("State change CB failed!");
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Error during processing answer.");
+    }
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Power/PowerResponseDispatcher.h b/src/standards/Tizen/Power/PowerResponseDispatcher.h
new file mode 100755 (executable)
index 0000000..60e8dae
--- /dev/null
@@ -0,0 +1,50 @@
+//
+// 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 _POWER_RESPONSE_DISPATCHER_H_
+#define _POWER_RESPONSE_DISPATCHER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <Commons/EventListener.h>
+#include <API/Power/OnPowerStateChanged.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Power {
+
+typedef WrtDeviceApis::Commons::EventListener<TizenApis::Api::Power::OnPowerStateChanged>
+OnPowerStateChangedListener;
+
+class PowerResponseDispatcher :
+    public OnPowerStateChangedListener
+{
+  public:
+    static PowerResponseDispatcher& getInstance();
+
+  private:
+    PowerResponseDispatcher();
+    virtual ~PowerResponseDispatcher();
+
+  protected:
+    void onAnswerReceived(const TizenApis::Api::Power::OnPowerStateChangedPtr& event);
+};
+
+}
+}
+}
+
+#endif /* _POWER_RESPONSE_DISPATCHER_H_ */
diff --git a/src/standards/Tizen/Power/config.xml b/src/standards/Tizen/Power/config.xml
new file mode 100755 (executable)
index 0000000..4344c3b
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+    <library-name>libwrt-plugins-tizen-2.0-power.so</library-name>
+    <feature-install-uri>power.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/power</name>
+        <device-capability>power</device-capability>
+    </api-feature>
+
+</plugin-properties>
\ No newline at end of file
diff --git a/src/standards/Tizen/Power/plugin_config.cpp b/src/standards/Tizen/Power/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..9cb0fb2
--- /dev/null
@@ -0,0 +1,184 @@
+//
+// 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 <Commons/Exception.h>
+#include <dpl/exception.h>
+#include <map>
+
+#include "plugin_config.h"
+
+#define POWER_FEATURE_API "http://tizen.org/privilege/power"
+
+#define POWER_DEVICE_CAP "power"
+
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Power {
+
+static FunctionMapping createPowerFunctions();
+
+static FunctionMapping PowerFunctions =
+    createPowerFunctions();
+
+DEFINE_FUNCTION_GETTER(Power, PowerFunctions);
+
+static FunctionMapping createPowerFunctions()
+{
+    /**
+     * Device capabilities
+     */
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_POWER, POWER_DEVICE_CAP);
+
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_POWER);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_POWER, DEVICE_CAP_POWER);
+
+    /**
+     * Api Features
+     */
+    ACE_CREATE_FEATURE(FEATURE_POWER, POWER_FEATURE_API);
+
+    ACE_CREATE_FEATURE_LIST(POWER_FEATURES);
+    ACE_ADD_API_FEATURE(POWER_FEATURES, FEATURE_POWER);
+
+    ACE_CREATE_FEATURE_LIST(POWER_NP_FEATURES);
+
+    /**
+     * Functions
+     */
+    FunctionMapping powerMapping;
+
+    // request
+    AceFunction requestFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_REQUEST,
+            POWER_FUNCTION_API_REQUEST,
+            POWER_FEATURES,
+            DEVICE_LIST_POWER);
+
+    powerMapping.insert(std::make_pair(
+                               POWER_FUNCTION_API_REQUEST,
+                               requestFunc));
+
+    // release
+    AceFunction releaseFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_RELEASE,
+            POWER_FUNCTION_API_RELEASE,
+            POWER_NP_FEATURES,
+            DEVICE_LIST_POWER);
+
+    powerMapping.insert(std::make_pair(
+                               POWER_FUNCTION_API_RELEASE,
+                               releaseFunc));
+
+    // setScreenStateChangeListener
+    AceFunction setScreenStateChangeListenerFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_SET_SCREEN_STATE_CHANGE_LISTENER,
+            POWER_FUNCTION_API_SET_SCREEN_STATE_CHANGE_LISTENER,
+            POWER_NP_FEATURES,
+            DEVICE_LIST_POWER);
+
+    powerMapping.insert(std::make_pair(
+                               POWER_FUNCTION_API_SET_SCREEN_STATE_CHANGE_LISTENER,
+                               setScreenStateChangeListenerFunc));
+
+    // unsetScreenStateChangeListenerFunc
+    AceFunction setScreenStateChangeListenerFuncFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_UNSET_SCREEN_STATE_CHANGE_LISTENER,
+            POWER_FUNCTION_API_UNSET_SCREEN_STATE_CHANGE_LISTENER,
+            POWER_NP_FEATURES,
+            DEVICE_LIST_POWER);
+
+    powerMapping.insert(std::make_pair(
+                               POWER_FUNCTION_API_UNSET_SCREEN_STATE_CHANGE_LISTENER,
+                               setScreenStateChangeListenerFuncFunc));
+
+    // getScreenBrightness
+    AceFunction getScreenBrightnessFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_GET_SCREEN_BRIGHTNESS,
+            POWER_FUNCTION_API_GET_SCREEN_BRIGHTNESS,
+            POWER_NP_FEATURES,
+            DEVICE_LIST_POWER);
+
+    powerMapping.insert(std::make_pair(
+                               POWER_FUNCTION_API_GET_SCREEN_BRIGHTNESS,
+                               getScreenBrightnessFunc));
+
+    // setScreenBrightness
+    AceFunction setScreenBrightnessFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_SET_SCREEN_BRIGHTNESS,
+            POWER_FUNCTION_API_SET_SCREEN_BRIGHTNESS,
+            POWER_FEATURES,
+            DEVICE_LIST_POWER);
+
+    powerMapping.insert(std::make_pair(
+                               POWER_FUNCTION_API_SET_SCREEN_BRIGHTNESS,
+                               setScreenBrightnessFunc));
+
+    // isScreenOn
+    AceFunction isScreenOnFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_IS_SCREEN_ON,
+            POWER_FUNCTION_API_IS_SCREEN_ON,
+            POWER_NP_FEATURES,
+            DEVICE_LIST_POWER);
+
+    powerMapping.insert(std::make_pair(
+                               POWER_FUNCTION_API_IS_SCREEN_ON,
+                               isScreenOnFunc));
+
+    // restoreScreenBrightness
+    AceFunction restoreScreenBrightnessFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_RESTORE_SCREEN_BRIGHTNESS,
+            POWER_FUNCTION_API_RESTORE_SCREEN_BRIGHTNESS,
+            POWER_NP_FEATURES,
+            DEVICE_LIST_POWER);
+
+    powerMapping.insert(std::make_pair(
+                               POWER_FUNCTION_API_RESTORE_SCREEN_BRIGHTNESS,
+                               restoreScreenBrightnessFunc));
+
+    // turnScreenOn
+    AceFunction turnScreenOnFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_TURN_SCREEN_ON,
+            POWER_FUNCTION_API_TURN_SCREEN_ON,
+            POWER_FEATURES,
+            DEVICE_LIST_POWER);
+
+    powerMapping.insert(std::make_pair(
+                               POWER_FUNCTION_API_TURN_SCREEN_ON,
+                               turnScreenOnFunc));
+
+    // turnScreenOff
+    AceFunction turnScreenOffFunc = ACE_CREATE_FUNCTION(
+            FUNCTION_TURN_SCREEN_OFF,
+            POWER_FUNCTION_API_TURN_SCREEN_OFF,
+            POWER_FEATURES,
+            DEVICE_LIST_POWER);
+
+    powerMapping.insert(std::make_pair(
+                               POWER_FUNCTION_API_TURN_SCREEN_OFF,
+                               turnScreenOffFunc));
+
+    return powerMapping;
+}
+
+}
+} 
+}
+//
diff --git a/src/standards/Tizen/Power/plugin_config.h b/src/standards/Tizen/Power/plugin_config.h
new file mode 100755 (executable)
index 0000000..29be9f4
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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 _POWER_PLUGIN_CONFIG_H_
+#define _POWER_PLUGIN_CONFIG_H_
+
+#include <string>
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Power {
+
+// Functions from power manager
+#define POWER_FUNCTION_API_REQUEST "request"
+#define POWER_FUNCTION_API_RELEASE "release"
+#define POWER_FUNCTION_API_SET_SCREEN_STATE_CHANGE_LISTENER "setScreenStateChangeListener"
+#define POWER_FUNCTION_API_UNSET_SCREEN_STATE_CHANGE_LISTENER "unsetScreenStateChangeListener"
+#define POWER_FUNCTION_API_GET_SCREEN_BRIGHTNESS "getScreenBrightness"
+#define POWER_FUNCTION_API_SET_SCREEN_BRIGHTNESS "setScreenBrightness"
+#define POWER_FUNCTION_API_IS_SCREEN_ON "isScreenOn"
+#define POWER_FUNCTION_API_RESTORE_SCREEN_BRIGHTNESS "restoreScreenBrightness"
+#define POWER_FUNCTION_API_TURN_SCREEN_ON "turnScreenOn"
+#define POWER_FUNCTION_API_TURN_SCREEN_OFF "turnScreenOff"
+
+DECLARE_FUNCTION_GETTER(Power);
+
+#define POWER_CHECK_ACCESS(functionName) \
+       aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >( \
+       getPowerFunctionData, \
+       functionName)
+}
+}
+}
+
+#endif // _POWER_PLUGIN_CONFIG_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/Power/plugin_initializer.cpp b/src/standards/Tizen/Power/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..a91011c
--- /dev/null
@@ -0,0 +1,86 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <Commons/Exception.h>
+#include "JSPowerManager.h"
+
+#include "PowerListenerManager.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Power {
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Commons;
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[Tizen\\Power] on_widget_start_callback (" << widgetId << ")");
+
+       Try {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+       } Catch (Exception) {
+               LogError("WrtAccess initialization failed");
+       }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[Tizen\\Power] on_widget_stop_callback (" << widgetId << ")");
+
+       Try {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+       } Catch (Exception) {
+               LogError("WrtAccess deinitialization failed");
+       }
+}
+
+void on_frame_load_callback(const void * context)
+{
+    LogDebug("[Tizen\\Power] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LogDebug("[Tizen\\Power] on_frame_unload_callback (" << context << ")");
+
+       TizenApis::Tizen1_0::Power::PowerListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+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,
+        "power",
+        (js_class_template_getter)JSPowerManager::getClassRef,
+        NULL)
+PLUGIN_CLASS_MAP_END
+
+}
+}
+}
+
diff --git a/src/standards/Tizen/SecureStorage/CMakeLists.txt b/src/standards/Tizen/SecureStorage/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ee12dd5
--- /dev/null
@@ -0,0 +1,23 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-securestorage")
+
+pkg_search_module(secure-storage REQUIRED secure-storage)
+
+include_directories(
+  ${secure-storage_INCLUDE_DIRS}
+)
+
+set(SRCS 
+       plugin_initializer.cpp
+       plugin_config.cpp
+       SecureStorageManager.cpp
+       JSSecureStorageManager.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+       ${LIBS_COMMON}
+       ${secure-storage_LIBRARIES}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION tizen-2.0-securestorage)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION tizen-2.0-securestorage)
diff --git a/src/standards/Tizen/SecureStorage/JSSecureStorageManager.cpp b/src/standards/Tizen/SecureStorage/JSSecureStorageManager.cpp
new file mode 100644 (file)
index 0000000..6e49801
--- /dev/null
@@ -0,0 +1,408 @@
+//
+// 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 <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "JSSecureStorageManager.h"
+#include "plugin_config.h"
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace TizenApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassDefinition JSSecureStorageManager::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       "SecureStorageManager",
+       NULL,
+       NULL,
+       m_function,
+       initialize,
+       finalize,
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL, 
+       NULL,
+       NULL,
+       hasInstance,
+       NULL
+};
+
+       
+JSStaticFunction JSSecureStorageManager::m_function[] =
+{
+       { "remove", JSSecureStorageManager::remove, kJSPropertyAttributeNone },
+       { "set", JSSecureStorageManager::set, kJSPropertyAttributeNone },
+       { "get", JSSecureStorageManager::get, kJSPropertyAttributeNone },       
+       { "listKeys", JSSecureStorageManager::listKeys, kJSPropertyAttributeNone },     
+       { "removeAll", JSSecureStorageManager::removeAll, kJSPropertyAttributeNone },           
+       { 0, 0, 0 }
+};
+
+
+const JSClassRef JSSecureStorageManager::getClassRef() 
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+const JSClassDefinition* JSSecureStorageManager::getClassInfo() 
+{
+       return &m_classInfo;
+}
+
+JSClassRef JSSecureStorageManager::m_jsClassRef = JSClassCreate(JSSecureStorageManager::getClassInfo());
+
+void JSSecureStorageManager::initialize(JSContextRef context, JSObjectRef object) 
+{
+       LogDebug("JSSecureStorageManager::initialize ");
+       JSSecureStorageManagerPriv* priv = static_cast<JSSecureStorageManagerPriv*>(JSObjectGetPrivate(object));
+
+       if (priv == NULL)
+       {
+               SecureStorageManagerPtr secureStorage(new SecureStorageManager());
+               priv = new JSSecureStorageManagerPriv( context, secureStorage);
+               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) 
+               {
+                       LogError("Object can't store private data.");
+                       delete priv;
+               }
+       }
+       else
+       {
+               LogDebug("JSSecureStorageManager::already exist ");             
+       }
+}
+
+void JSSecureStorageManager::finalize(JSObjectRef object) 
+{
+       JSSecureStorageManagerPriv* priv = static_cast<JSSecureStorageManagerPriv*>(JSObjectGetPrivate(object));
+
+       LogDebug("JSSecureStorageManager::Finalrize");
+
+       if (priv != NULL) 
+       {
+               JSObjectSetPrivate(object, NULL);
+               delete priv;
+       }
+}
+
+bool JSSecureStorageManager::hasInstance(JSContextRef context, JSObjectRef constructor,
+               JSValueRef possibleInstance, JSValueRef* exception) 
+{
+       return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+
+JSValueRef JSSecureStorageManager::listKeys(JSContextRef context, JSObjectRef object,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+       JSValueRef* exception)
+{
+       JSSecureStorageManagerPriv* priv = static_cast<JSSecureStorageManagerPriv*>(JSObjectGetPrivate(thisObject));    
+
+       try 
+       {
+               if (priv == NULL)
+               {
+                       LogError("priv null");
+                       Throw(WrtDeviceApis::Commons::ConversionException);
+               }
+
+
+               // to do : need to update TizenPolicy.xml
+               // AceSecurityStatus status = SECURE_STORAGE_CHECK_ACCESS(SECURE_STORAGE_FUNC_READ);
+               // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+               
+               SecureStorageManagerPtr secureStorage(priv->getObject());
+               Converter converter(priv->getContext());
+               std::vector<std::string> keys = secureStorage->listKeys();
+               return converter.toJSValueRef(keys);    
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               LogDebug("Error message" << ex.GetMessage());
+               switch(ex.getCode())
+               {
+                       case WrtDeviceApis::Commons::ExceptionCodes::NotFoundException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::NOT_FOUND_ERROR, "not found error"); 
+                       case WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error"); 
+                       case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");  
+                       case WrtDeviceApis::Commons::ExceptionCodes::SecurityException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");  
+                       case WrtDeviceApis::Commons::ExceptionCodes::Exception:
+                       default:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::UNKNOWN_ERROR, "Unkown error");
+               }
+       }
+       return JSValueMakeUndefined(context);
+
+}
+
+
+JSValueRef JSSecureStorageManager::set(JSContextRef context, JSObjectRef object,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+       JSValueRef* exception)
+{
+       JSSecureStorageManagerPriv* priv = static_cast<JSSecureStorageManagerPriv*>(JSObjectGetPrivate(thisObject));    
+       JSValueRef reserveArguments[2];
+       size_t index = 0;
+
+
+       try 
+       {
+               if (priv == NULL)
+               {
+                       LogError("priv null");
+
+                       Throw(WrtDeviceApis::Commons::ConversionException);
+               }
+
+               // to do : need to update TizenPolicy.xml
+               // AceSecurityStatus status = SECURE_STORAGE_CHECK_ACCESS(SECURE_STORAGE_FUNC_WRITE);
+               // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+               
+
+               for (index = 0; index < 2; index++)
+               {
+                       if (index < argumentCount)
+                               reserveArguments[index] = arguments[index];
+                       else 
+                               reserveArguments[index] = JSValueMakeUndefined(context);
+               }
+
+               SecureStorageManagerPtr secureStorage(priv->getObject());
+               Converter converter(priv->getContext());
+               std::string key = converter.toString(reserveArguments[0]);
+               std::string value = converter.toString(reserveArguments[1]);
+               secureStorage->set(key, value);
+               
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               LogDebug("Error message" << ex.GetMessage());
+               switch(ex.getCode())
+               {
+                       case WrtDeviceApis::Commons::ExceptionCodes::NotFoundException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::NOT_FOUND_ERROR, "not found error"); 
+                       case WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error"); 
+                       case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");  
+                       case WrtDeviceApis::Commons::ExceptionCodes::SecurityException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");  
+                       case WrtDeviceApis::Commons::ExceptionCodes::Exception:
+                       default:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::UNKNOWN_ERROR, "Unkown error");
+               }
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSecureStorageManager::get(JSContextRef context, JSObjectRef object,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+       JSValueRef* exception)
+{
+       JSSecureStorageManagerPriv* priv = static_cast<JSSecureStorageManagerPriv*>(JSObjectGetPrivate(thisObject));    
+       JSValueRef reserveArguments;
+
+       try 
+       {
+               if (priv == NULL)
+               {
+                       LogError("priv null");
+                       Throw(WrtDeviceApis::Commons::ConversionException);
+               }
+
+               // to do : need to update TizenPolicy.xml
+               // AceSecurityStatus status = SECURE_STORAGE_CHECK_ACCESS(SECURE_STORAGE_FUNC_READ);
+               // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               if (argumentCount > 0) 
+                       reserveArguments = arguments[0];
+               else 
+                       reserveArguments = JSValueMakeUndefined(context);
+               
+               SecureStorageManagerPtr secureStorage(priv->getObject());
+               Converter converter(priv->getContext());
+               std::string key = converter.toString(reserveArguments);
+               std::string value = secureStorage->get(key);
+               return converter.toJSValueRef(value);
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               LogDebug("Error message" << ex.GetMessage());
+               switch(ex.getCode())
+               {
+                       case WrtDeviceApis::Commons::ExceptionCodes::NotFoundException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::NOT_FOUND_ERROR, "not found error"); 
+                       case WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error"); 
+                       case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");  
+                       case WrtDeviceApis::Commons::ExceptionCodes::SecurityException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");  
+                       case WrtDeviceApis::Commons::ExceptionCodes::Exception:
+                       default:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::UNKNOWN_ERROR, "Unkown error");
+               }
+       }
+       return JSValueMakeUndefined(context);
+
+}
+
+JSValueRef JSSecureStorageManager::remove(JSContextRef context, JSObjectRef object,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+       JSValueRef* exception)
+{
+       JSSecureStorageManagerPriv* priv = static_cast<JSSecureStorageManagerPriv*>(JSObjectGetPrivate(thisObject));    
+       JSValueRef reserveArguments;
+
+       try 
+       {
+               if (priv == NULL)
+               {
+                       LogError("priv null");
+                       Throw(WrtDeviceApis::Commons::ConversionException);
+               }
+
+               // to do : need to update TizenPolicy.xml
+               // AceSecurityStatus status = SECURE_STORAGE_CHECK_ACCESS(SECURE_STORAGE_FUNC_WRITE);
+               // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               if (argumentCount > 0) 
+                       reserveArguments = arguments[0];
+               else 
+                       reserveArguments = JSValueMakeUndefined(context);
+               
+               SecureStorageManagerPtr secureStorage(priv->getObject());
+               Converter converter(priv->getContext());
+               std::string key = converter.toString(reserveArguments);
+               secureStorage->remove(key);
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               LogDebug("Error message" << ex.GetMessage());
+               switch(ex.getCode())
+               {
+                       case WrtDeviceApis::Commons::ExceptionCodes::NotFoundException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::NOT_FOUND_ERROR, "not found error"); 
+                       case WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error"); 
+                       case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");  
+                       case WrtDeviceApis::Commons::ExceptionCodes::SecurityException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");  
+                       case WrtDeviceApis::Commons::ExceptionCodes::Exception:
+                       default:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::UNKNOWN_ERROR, "Unkown error");
+               }
+       }       
+       return JSValueMakeUndefined(context);
+
+}
+
+JSValueRef JSSecureStorageManager::removeAll(JSContextRef context, JSObjectRef object,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+       JSValueRef* exception)
+{
+       JSSecureStorageManagerPriv* priv = static_cast<JSSecureStorageManagerPriv*>(JSObjectGetPrivate(thisObject));    
+
+       try 
+       {
+               if (priv == NULL)
+               {
+                       LogError("priv null");
+                       Throw(WrtDeviceApis::Commons::ConversionException);
+               }
+
+               // to do : need to update TizenPolicy.xml
+               // AceSecurityStatus status = SECURE_STORAGE_CHECK_ACCESS(SECURE_STORAGE_FUNC_WRITE);
+               // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+               SecureStorageManagerPtr secureStorage(priv->getObject());
+               Converter converter(priv->getContext());
+               secureStorage->removeAll();
+
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               LogDebug("Error message" << ex.GetMessage());
+               switch(ex.getCode())
+               {
+                       case WrtDeviceApis::Commons::ExceptionCodes::NotFoundException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::NOT_FOUND_ERROR, "not found error"); 
+                       case WrtDeviceApis::Commons::ExceptionCodes::InvalidArgumentException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error"); 
+                       case WrtDeviceApis::Commons::ExceptionCodes::ConversionException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");  
+                       case WrtDeviceApis::Commons::ExceptionCodes::SecurityException:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error");  
+                       case WrtDeviceApis::Commons::ExceptionCodes::Exception:
+                       default:
+                               return JSTizenExceptionFactory::postException(context, exception, 
+                                       JSTizenException::UNKNOWN_ERROR, "Unkown error");
+               }
+       }
+       return JSValueMakeUndefined(context);
+
+}
+
+}
+}
+
diff --git a/src/standards/Tizen/SecureStorage/JSSecureStorageManager.h b/src/standards/Tizen/SecureStorage/JSSecureStorageManager.h
new file mode 100644 (file)
index 0000000..21d5759
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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_JS_SECURE_STORAGE_MANAGER_H_
+#define TIZENAPIS_TIZEN_JS_SECURE_STORAGE_MANAGER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "SecureStorageManager.h"
+#include <CommonsJavaScript/PrivateObject.h>
+
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+       
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+typedef PrivateObjectT<SecureStorageManagerPtr>::Type JSSecureStorageManagerPriv;
+
+class JSSecureStorageManager {
+public:
+       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 listKeys(JSContextRef context, JSObjectRef object,
+               JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef* exception);
+       static JSValueRef set(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 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 JSClassDefinition m_classInfo;
+       static JSStaticFunction m_function[];
+       static JSClassRef m_jsClassRef;
+};
+
+}
+}
+
+#endif
+
diff --git a/src/standards/Tizen/SecureStorage/SecureStorageManager.cpp b/src/standards/Tizen/SecureStorage/SecureStorageManager.cpp
new file mode 100644 (file)
index 0000000..cfc1e29
--- /dev/null
@@ -0,0 +1,266 @@
+//
+// 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 "SecureStorageManager.h"
+#include <ss_manager.h>
+#include <cassert>
+#include <exception>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <dpl/scoped_array.h>
+
+using namespace DPL;
+using namespace WrtDeviceApis::Commons;
+
+namespace TizenApis {
+namespace Tizen1_0{
+       
+std::string SecureStorageManager::m_filePath = "securedata.txt";
+int SecureStorageManager::m_maxLength = 256;
+
+SecureStorageManager::SecureStorageManager()
+{
+       LogDebug("OK");
+
+       try 
+       {
+               loadSecurePairData();
+       }
+       catch (const WrtDeviceApis::Commons::Exception& ex) 
+       {
+               LogError("Exception: " << ex.GetMessage());
+               LogDebug("there is no file");
+       }
+
+       LogDebug("initial map size : " << m_securePairData.size());
+}
+
+SecureStorageManager::~SecureStorageManager()
+{
+       LogDebug("OK");
+}
+
+std::string SecureStorageManager::get(std::string key)
+{
+       LogDebug("OK");
+
+       std::map<std::string,std::string>::iterator it = m_securePairData.find(key);    
+
+       if (it == m_securePairData.end())
+       {
+               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "not found key");
+       }
+       
+       return m_securePairData[key];
+}
+
+std::vector<std::string> SecureStorageManager::listKeys()
+{
+       std::vector<std::string> vector;
+       std::map<std::string,std::string>::iterator it; 
+
+       LogDebug("OK");
+
+       for (it = m_securePairData.begin(); it != m_securePairData.end(); ++it)
+       {
+               vector.push_back((*it).first);
+       }
+       
+       return vector;
+}
+void SecureStorageManager::set(std::string key, std::string value)
+{
+       m_securePairData[key] = value;
+
+       LogDebug("Save current data");
+       saveSecurePairData();
+}
+
+void SecureStorageManager::remove(std::string key)
+{
+       LogDebug("OK");
+
+       std::map<std::string,std::string>::iterator it = m_securePairData.find(key);    
+
+       if (it == m_securePairData.end())
+       {
+               ThrowMsg(WrtDeviceApis::Commons::NotFoundException, "not found key");
+       }
+       m_securePairData.erase(it);
+       LogDebug("Save current data");
+       saveSecurePairData();
+}
+
+void SecureStorageManager::removeAll()
+{
+       LogDebug("OK");
+
+       ssm_flag flag = SSM_FLAG_SECRET_OPERATION;
+               
+       m_securePairData.clear();
+       ssm_delete_file(m_filePath.c_str(), flag, NULL);
+}
+
+void SecureStorageManager::saveSecurePairData()
+{
+       LogDebug("OK");
+
+       std::map<std::string,std::string>::iterator it; 
+       size_t dataSize = 0;
+       size_t index = 0;
+       size_t num = 0;
+       size_t mapSize = m_securePairData.size();
+       int ret = -1;   
+
+       for (it = m_securePairData.begin(); it != m_securePairData.end(); ++it)
+       {
+               dataSize += (*it).first.size();
+               dataSize += (*it).second.size();
+       }
+       
+       dataSize += sizeof(size_t) * 2 * m_securePairData.size();
+       dataSize += sizeof(size_t) * 2;
+
+       DPL::ScopedArray<char> saveBuf(new char[dataSize]);
+
+       memcpy(&saveBuf[index], (char*)&mapSize, sizeof(size_t));
+       index += sizeof(size_t);
+
+       memcpy(&saveBuf[index], (char*)&dataSize, sizeof(size_t));
+       index += sizeof(size_t);
+       
+       for (it = m_securePairData.begin(); it != m_securePairData.end(); ++it)
+       {
+               num = (*it).first.size();
+               memcpy(&saveBuf[index], (char*)&num, sizeof(size_t));
+               index += sizeof(size_t);
+
+               memcpy(&saveBuf[index], (char*)(*it).first.c_str(), (*it).first.size());
+               index += (*it).first.size();                    
+
+               num = (*it).second.size();              
+               memcpy(&saveBuf[index], (char*)&num, sizeof(size_t));
+               index += sizeof(size_t);
+               memcpy(&saveBuf[index], (char*)(*it).second.c_str(), (*it).second.size());
+               index += (*it).second.size();                   
+       }       
+
+       ssm_flag flag = SSM_FLAG_SECRET_OPERATION;
+
+       ret = ssm_write_buffer(saveBuf.Get(), dataSize, m_filePath.c_str(), flag, NULL);
+
+       if (ret < 0) 
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "ssm write buf error");
+       }
+       LogDebug("save result : " << ret);
+}
+
+std::string SecureStorageManager::readStringFromMemory(const char *saveBuf, size_t &current, size_t dataSize) 
+{
+       std::string value = "";
+       size_t num = 0;
+       char tempbuf[m_maxLength];
+
+       if (current + sizeof(size_t) > dataSize)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get size error ");
+       }
+       
+       memcpy(&num, &saveBuf[current], sizeof(size_t));
+       memset(tempbuf, 0, sizeof(tempbuf));
+       current += sizeof(size_t);      
+
+       if (current + num > dataSize)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get size error ");
+       }               
+       
+       memcpy(tempbuf, &saveBuf[current], num);
+       current += num; 
+       value = tempbuf;        
+       
+       return value;
+}
+
+
+void SecureStorageManager::loadSecurePairData()
+{
+       LogDebug("OK");
+       
+       int ret = -1;   
+       size_t num = 0;
+       size_t dataSize = 0;
+       size_t i = 0;   
+       size_t readlen = 0;     
+       char* retbuf = NULL;    
+       ssm_file_info_t sfi;
+       ssm_flag flag = SSM_FLAG_SECRET_OPERATION;
+       size_t index = 0;
+
+       m_securePairData.clear();
+       ret = ssm_getinfo(m_filePath.c_str(), &sfi, flag, NULL);
+
+       if (ret < 0)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "get info error");
+       }
+
+       if (sfi.originSize == 0) 
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "originSize error");
+       }
+       
+       DPL::ScopedArray<char> saveBuf(new char[sfi.originSize]);
+       retbuf = saveBuf.Get();
+
+       memset(retbuf, 0x00, sizeof(char) * sfi.originSize);
+       ret = ssm_read(m_filePath.c_str(), retbuf, sfi.originSize, &readlen, flag, NULL);
+
+       if (ret < 0)
+       {
+               ThrowMsg(WrtDeviceApis::Commons::PlatformException, "read buf error");
+       }
+
+       LogDebug("read result : " << ret << ", length:" << readlen);
+
+       memcpy(&num, &saveBuf[index], sizeof(size_t));
+       index += sizeof(size_t);
+
+       memcpy(&dataSize, &saveBuf[index], sizeof(size_t));
+       index += sizeof(size_t);
+       
+       LogDebug("dataSize" <<  dataSize << "-" << num);
+
+       for (i = 0; i < num; i++) 
+       {
+               std::string key = readStringFromMemory(retbuf, index, dataSize);
+               std::string value = readStringFromMemory(retbuf, index, dataSize);
+
+               if (key.size() == 0 || value.size() == 0) 
+               {
+                       ThrowMsg(WrtDeviceApis::Commons::PlatformException, "read buf error");
+               }
+               m_securePairData[key] = value;
+               LogDebug("contents:" << key << "-" << m_securePairData[key]);
+       }       
+}
+
+
+}
+}
+
diff --git a/src/standards/Tizen/SecureStorage/SecureStorageManager.h b/src/standards/Tizen/SecureStorage/SecureStorageManager.h
new file mode 100644 (file)
index 0000000..12e26e9
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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_SECURE_STORAGE_MANAGER_H_
+#define TIZENAPIS_TIZEN_SECURE_STORAGE_MANAGER_H_
+
+#include <dpl/shared_ptr.h>
+#include <map>
+#include <string>
+#include <vector>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+class SecureStorageManager;
+typedef DPL::SharedPtr<SecureStorageManager> SecureStorageManagerPtr;
+
+
+class SecureStorageManager
+{
+public:        
+       std::string get(std::string key);
+       std::vector<std::string> listKeys();
+       void set(std::string key, std::string value);
+       void remove(std::string key);
+       void removeAll();
+       SecureStorageManager();
+       ~SecureStorageManager();
+private:       
+       static std::string m_filePath;
+       static int m_maxLength;
+       std::map<std::string, std::string> m_securePairData;
+       void saveSecurePairData();
+       void loadSecurePairData();
+       std::string readStringFromMemory(const char *saveBuf, size_t &current, size_t dataSize);
+};
+}
+}
+#endif
diff --git a/src/standards/Tizen/SecureStorage/config.xml b/src/standards/Tizen/SecureStorage/config.xml
new file mode 100644 (file)
index 0000000..b908ba9
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+       <library-name>libwrt-plugins-tizen-2.0-securestorage.so</library-name>
+       <feature-install-uri>securestorage.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/securestorage.read</name>
+               <device-capability>securestorage.read</device-capability>
+       </api-feature>
+       <api-feature>
+               <name>http://tizen.org/privilege/securestorage.write</name>
+               <device-capability>securestorage.write</device-capability> 
+       </api-feature>
+</plugin-properties>
+
diff --git a/src/standards/Tizen/SecureStorage/plugin_config.cpp b/src/standards/Tizen/SecureStorage/plugin_config.cpp
new file mode 100644 (file)
index 0000000..baa47fc
--- /dev/null
@@ -0,0 +1,128 @@
+//
+// 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 <map>
+#include <utility>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include "plugin_config.h"
+
+#define SECURE_STORAGE_FEATURE_API_READ "http://tizen.org/privilege/securestorage.read"
+#define SECURE_STORAGE_FEATURE_API_WRITE "http://tizen.org/privilege/securestorage.write"
+
+#define SECURE_STORAGE_DEVICE_CAP_READ "securestorage.read"
+#define SECURE_STORAGE_DEVICE_CAP_WRITE "securestorage.write"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+const char* SECURE_STORAGE_FUNC_READ = "SecureStroageReadFunc";
+const char* SECURE_STORAGE_FUNC_WRITE = "SecureStroageWriteFunc";
+const char* SECURE_STORAGE_FUNC_READWRITE = "SecureStroageReadWriteFunc";
+
+static WrtDeviceApis::Commons::FunctionMapping createSecureStorageFunctions();
+
+static WrtDeviceApis::Commons::FunctionMapping SecureStorageFunctions =
+    createSecureStorageFunctions();
+
+DEFINE_FUNCTION_GETTER(SecureStorage, SecureStorageFunctions);
+
+static WrtDeviceApis::Commons::FunctionMapping createSecureStorageFunctions()
+{
+       using namespace WrtDeviceApis::Commons;
+
+       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_SECURE_STORAGE_READ, SECURE_STORAGE_DEVICE_CAP_READ);
+       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_SECURE_STORAGE_WRITE, SECURE_STORAGE_DEVICE_CAP_WRITE);
+
+
+       ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+
+       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_SECURE_STORAGE_READ);
+       ACE_ADD_DEVICE_CAP(DEVICE_LIST_SECURE_STORAGE_READ, DEVICE_CAP_SECURE_STORAGE_READ);
+
+       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_SECURE_STORAGE_WRITE);
+       ACE_ADD_DEVICE_CAP(DEVICE_LIST_SECURE_STORAGE_WRITE, DEVICE_CAP_SECURE_STORAGE_WRITE);
+
+
+       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_SECURE_STORAGE_READWRITE);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_SECURE_STORAGE_READWRITE, DEVICE_CAP_SECURE_STORAGE_READ);
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_SECURE_STORAGE_READWRITE, DEVICE_CAP_SECURE_STORAGE_WRITE);
+       
+
+       ACE_CREATE_FEATURE(FEATURE_SECURE_STORAGE, SECURE_STORAGE_FEATURE_API);
+       ACE_CREATE_FEATURE(FEATURE_READ, SECURE_STORAGE_FEATURE_API_READ);
+       ACE_CREATE_FEATURE(FEATURE_WRITE, SECURE_STORAGE_FEATURE_API_WRITE);
+
+       ACE_CREATE_FEATURE_LIST(SECURE_STORAGE_FEATURES_SECURE_READWRITE);
+       ACE_ADD_API_FEATURE(SECURE_STORAGE_FEATURES_SECURE_READWRITE, FEATURE_SECURE_STORAGE);
+       ACE_ADD_API_FEATURE(SECURE_STORAGE_FEATURES_SECURE_READWRITE, FEATURE_READ);
+       ACE_ADD_API_FEATURE(SECURE_STORAGE_FEATURES_SECURE_READWRITE, FEATURE_WRITE);
+       
+       ACE_CREATE_FEATURE_LIST(SECURE_STORAGE_FEATURES_READ);
+       ACE_ADD_API_FEATURE(SECURE_STORAGE_FEATURES_READ, FEATURE_SECURE_STORAGE);
+       ACE_ADD_API_FEATURE(SECURE_STORAGE_FEATURES_READ, FEATURE_READ);
+
+       ACE_CREATE_FEATURE_LIST(SECURE_STORAGE_FEATURES_WRITE);
+       ACE_ADD_API_FEATURE(SECURE_STORAGE_FEATURES_WRITE, FEATURE_SECURE_STORAGE);
+       ACE_ADD_API_FEATURE(SECURE_STORAGE_FEATURES_WRITE, FEATURE_WRITE);
+
+
+   FunctionMapping SecureStorageFunctions;
+
+       AceFunction secureStorageRead = ACE_CREATE_FUNCTION(
+            FUNCTION_SECURE_STORAGE_READ_FUNCTIONS,
+            SECURE_STORAGE_FUNC_READ,
+            SECURE_STORAGE_FEATURES_READ,
+            DEVICE_LIST_SECURE_STORAGE_READ);
+
+    SecureStorageFunctions.insert(std::make_pair(
+                               SECURE_STORAGE_FUNC_READ,
+                               secureStorageRead));
+
+       AceFunction secureStorageWrite = ACE_CREATE_FUNCTION(
+            FUNCTION_SECURE_STORAGE_WRITE_FUNCTIONS,
+            SECURE_STORAGE_FUNC_WRITE,
+            SECURE_STORAGE_FEATURES_WRITE,
+            DEVICE_LIST_SECURE_STORAGE_WRITE);
+
+    SecureStorageFunctions.insert(std::make_pair(
+                               SECURE_STORAGE_FUNC_WRITE,
+                               secureStorageWrite));
+       
+       AceFunction secureStorageReadWrite = ACE_CREATE_FUNCTION(
+            FUNCTION_SECURE_STORAGE_READWRITE_FUNCTIONS,
+            SECURE_STORAGE_FUNC_READWRITE,
+            SECURE_STORAGE_FEATURES_SECURE_READWRITE,
+            DEVICE_LIST_SECURE_STORAGE_READWRITE);
+
+    SecureStorageFunctions.insert(std::make_pair(
+                               SECURE_STORAGE_FUNC_READWRITE,
+                               secureStorageReadWrite));
+       
+       return SecureStorageFunctions;
+}
+} 
+}
+
+#undef SECURE_STORAGE_FEATURE_API 
+#undef SECURE_STORAGE_FEATURE_API_WRITE 
+#undef SECURE_STORAGE_FEATURE_API_READ
+#undef SECURE_STORAGE_DEVICE_CAP_WRITE 
+#undef SECURE_STORAGE_DEVICE_CAP_READ
+
diff --git a/src/standards/Tizen/SecureStorage/plugin_config.h b/src/standards/Tizen/SecureStorage/plugin_config.h
new file mode 100644 (file)
index 0000000..08ad977
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// 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_JS_SECURE_STORAGE_PLUGIN_CONFIG_H_
+#define TIZENAPIS_TIZEN_JS_SECURE_STORAGE_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+extern const char* SECURE_STORAGE_FUNC_READ;
+extern const char* SECURE_STORAGE_FUNC_WRITE;
+
+
+WrtDeviceApis::Commons::AceFunction getSecureStorageFunctionData(const std::string & functionId);
+
+#define SECURE_STORAGE_CHECK_ACCESS(functionName)                       \
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(                \
+        getSecureStorageFunctionData,    \
+        functionName)
+}
+}
+
+#endif 
diff --git a/src/standards/Tizen/SecureStorage/plugin_initializer.cpp b/src/standards/Tizen/SecureStorage/plugin_initializer.cpp
new file mode 100644 (file)
index 0000000..7666d15
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+
+
+#include "JSSecureStorageManager.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+void on_widget_start_callback(int widgetId)
+{
+       LogDebug("[Tizen\\Bluetooth ] on_widget_start_callback ("<<widgetId<<")");
+       Try
+       {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+       }
+       Catch(Commons::Exception)
+       {
+               LogError("WrtAccess initialization failed");
+       }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+       LogDebug("[Tizen\\Bluetooth] on_widget_stop_callback ("<<widgetId<<")");
+       Try
+       {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+       }
+       Catch(Commons::Exception)
+       {
+               LogError("WrtAccess deinitialization failed");
+       }
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+#define SECURE_STORAGE "securestorage"
+
+PLUGIN_CLASS_MAP_BEGIN
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, SECURE_STORAGE,
+      (js_class_template_getter)TizenApis::Tizen1_0::JSSecureStorageManager::getClassRef,NULL)
+PLUGIN_CLASS_MAP_END
+
diff --git a/src/standards/Tizen/SystemSetting/CMakeLists.txt b/src/standards/Tizen/SystemSetting/CMakeLists.txt
new file mode 100644 (file)
index 0000000..f499f4d
--- /dev/null
@@ -0,0 +1,29 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-systemsetting")
+
+include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_SYSTEMSETTING})
+
+set(SRCS
+  ${SRCS_PLATFORM_IMPLEMENTATION_SYSTEMSETTING}
+  ${SRCS_PLATFORM_API_SYSTEMSETTING}
+  plugin_initializer.cpp
+  plugin_config.cpp
+  JSSystemSetting.cpp
+  SystemSettingResponseDispatcher.cpp
+  ConverterSystemSetting.cpp
+  SystemSettingAsyncCallbackManager.cpp
+)
+
+set(CMAKE_INSTALL_RPATH
+    ${CMAKE_INSTALL_RPATH}
+    ${CMAKE_INSTALL_PREFIX}/tizen-2.0-filesystem
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${LIBS_COMMON}
+  ${LIBS_PLATFORM_IMPLEMENTATION_SYSTEMSETTING}
+  wrt-plugins-tizen-2.0-filesystem-impl
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION tizen-2.0-systemsetting)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION tizen-2.0-systemsetting)
diff --git a/src/standards/Tizen/SystemSetting/ConverterSystemSetting.cpp b/src/standards/Tizen/SystemSetting/ConverterSystemSetting.cpp
new file mode 100755 (executable)
index 0000000..6d5583e
--- /dev/null
@@ -0,0 +1,123 @@
+//
+// 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/JSDOMExceptionFactory.h>
+#include "ConverterSystemSetting.h"
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+//#include "JSMessageAttachment.h"
+//#include "JSConversation.h"
+//#include "JSMessageFolder.h"
+
+using namespace std;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+ConverterSystemSetting::ConverterSystemSetting(JSContextRef context) :
+    Converter(context)
+{
+}
+
+ConverterSystemSetting::~ConverterSystemSetting()
+{
+}
+
+Api::SystemSetting::SettingType ConverterSystemSetting::toSettingType(JSValueRef arg)
+{
+       LogDebug("Enter");
+        return toSettingType(toJSObjectRef(arg));
+}
+
+Api::SystemSetting::SettingType ConverterSystemSetting::toSettingType(JSObjectRef arg)
+{
+    // convert JSvalue to message type enum
+       std::string strSettingType = toString(arg);
+       LogDebug("Setting Type : " << strSettingType);
+
+       if ( strSettingType.compare("HOME_SCREEN") == 0 )
+       {
+               return Api::SystemSetting::HOME_SCREEN;
+       }
+       else if ( strSettingType.compare("LOCK_SCREEN") == 0 )
+       {
+               return Api::SystemSetting::LOCK_SCREEN;
+       }
+       else if ( strSettingType.compare("INCOMING_CALL") == 0 )
+       {
+               return Api::SystemSetting::INCOMMING_CALL;
+       }
+       else if ( strSettingType.compare("NOTIFICATION_EMAIL") == 0 )
+       {
+               return Api::SystemSetting::NOTIFICATION_EMAIL;
+       }
+       else
+       {
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Setting type not supported");
+       }
+
+}
+
+/*
+std::string ConverterMessage::toMessageType( long msgtype )
+{
+       LogDebug("Messasge Type : " << msgtype);
+
+       switch (msgtype)
+       {
+               case Api::Messaging::SMS:
+                       return "messaging.sms";
+               case Api::Messaging::MMS:
+                       return "messaging.mms";
+               case Api::Messaging::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 Api::Messaging::MESSAGE_STATUS_SENT:
+                       return "SENT";
+               case Api::Messaging::MESSAGE_STATUS_SENDING:
+                       return "SENDING";
+               case Api::Messaging::MESSAGE_STATUS_FAILED:
+                       return "FAILED";
+               case Api::Messaging::MESSAGE_STATUS_DRAFT:
+                       return "DRAFT";
+               case Api::Messaging::MESSAGE_STATUS_CREATED:
+               case Api::Messaging::MESSAGE_STATUS_LOADED:
+                       return "";
+               default :
+                       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "message status not supported");
+       }
+}
+*/
+
+}
+}
diff --git a/src/standards/Tizen/SystemSetting/ConverterSystemSetting.h b/src/standards/Tizen/SystemSetting/ConverterSystemSetting.h
new file mode 100755 (executable)
index 0000000..8435fff
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// 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 <API/SystemSetting/ISystemSettingType.h>
+
+#ifndef CONVERTEDSYSTEMSETTING_H
+#define CONVERTEDSYSTEMSETTING_H
+
+namespace TizenApis {
+namespace Tizen1_0 {
+class ConverterSystemSetting : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+  private:
+
+  public:
+    using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
+
+    explicit ConverterSystemSetting(JSContextRef context);
+
+    virtual ~ConverterSystemSetting();
+
+    Api::SystemSetting::SettingType toSettingType(JSValueRef arg);
+
+    Api::SystemSetting::SettingType toSettingType(JSObjectRef arg);
+
+//    std::string toMessageStatusType( long msgstatus );
+};
+
+typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<ConverterSystemSetting> ConverterSystemSettingFactory;
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/SystemSetting/JSSystemSetting.cpp b/src/standards/Tizen/SystemSetting/JSSystemSetting.cpp
new file mode 100755 (executable)
index 0000000..787057e
--- /dev/null
@@ -0,0 +1,324 @@
+//
+// 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 <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <API/SystemSetting/SystemSettingFactory.h>
+#include <API/SystemSetting/ISystemSetting.h>
+#include <API/SystemSetting/EventSetWallpaper.h>
+#include <API/SystemSetting/EventSetRingtone.h>
+#include <API/SystemSetting/EventSetSetting.h>
+#include <API/SystemSetting/EventGetSetting.h>
+#include <API/SystemSetting/SystemSettingFactory.h>
+
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include "JSSystemSetting.h"
+#include "SystemSettingResponseDispatcher.h"
+
+#include "ConverterSystemSetting.h"
+#include "SystemSettingAsyncCallbackManager.h"
+
+//#include <Tizen/Filesystem/JSFile.h>
+//#include <Tizen/Filesystem/EventGetNodeData.h>
+#include <Tizen/Filesystem/FilesystemUtils.h>
+
+#include "plugin_config.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "TIZEN_N_SYSTEMSETTING"
+#endif
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace SystemSetting {
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::SystemSetting;
+using namespace TizenApis::Commons;
+
+JSClassDefinition JSSystemSetting::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "systemsetting",
+    NULL,
+    NULL,
+    m_function,
+    initialize,
+    finalize,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticFunction JSSystemSetting::m_function[] = {
+//    { "setWallpaper", JSSystemSetting::setWallpaper, kJSPropertyAttributeNone },
+//    { "setRingtone", JSSystemSetting::setRingtone, kJSPropertyAttributeNone },
+    { "setProperty", JSSystemSetting::setProperty, kJSPropertyAttributeNone },
+    { "getProperty", JSSystemSetting::getProperty, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+const JSClassRef JSSystemSetting::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSSystemSetting::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSSystemSetting::m_jsClassRef = JSClassCreate(JSSystemSetting::getClassInfo());
+
+void JSSystemSetting::initialize(JSContextRef context, JSObjectRef object)
+{
+    JSSystemSettingPriv* priv = static_cast<JSSystemSettingPriv*>(JSObjectGetPrivate(object));
+    ISystemSettingPtr SystemSettings(SystemSettingFactory::getInstance().getSystemSetting());
+
+       if (priv != NULL)
+       {
+           LogDebug("JSSystemSetting::initialize already");
+               return;
+       }
+
+       Try {
+               priv = new JSSystemSettingPriv(context, SystemSettings);
+               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+                       LogError("Object can't store private data.");
+                       delete priv;
+               }
+       } Catch (UnsupportedException) {
+               LogError("UnsupportedException: " << _rethrown_exception.GetMessage());
+       } Catch (UnknownException) {
+               LogError("UnknownExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (PlatformException) {
+               LogError("PlatformExceptionException: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+    LogDebug("JSSystemSetting::initialize ");
+       
+}
+
+void JSSystemSetting::finalize(JSObjectRef object)
+{
+    JSSystemSettingPriv* priv = static_cast<JSSystemSettingPriv*>(JSObjectGetPrivate(object));
+    
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting gallery");
+    delete priv;
+}
+
+JSValueRef JSSystemSetting::setProperty(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+        size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+       LogDebug("enter");
+
+       Api::SystemSetting::SettingType settingType;
+       std::string settingValue;
+       
+       JSSystemSettingPriv *priv = static_cast<JSSystemSettingPriv*>(JSObjectGetPrivate(thisObject));
+       ConverterSystemSettingFactory::ConverterType converter = ConverterSystemSettingFactory::getConverter(context);
+       Validator check(context, exception);
+       
+       if (!priv) {
+               LogError("private object is null");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Wrong Object");
+       }
+       if (argumentCount < 3) {
+               LogDebug("Argument is too few");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
+       }
+       if (!check.isCallback(arguments[2])) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       AceSecurityStatus status = SYSTEMSETTING_CHECK_ACCESS(SYSTEMSETTING_FUNCTION_API_SET_PROPERTY);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+       onSuccessForCbm = arguments[2];
+       if (argumentCount > 3) {
+               if (check.isCallback(arguments[3])) {
+                       onErrorForCbm = arguments[3];
+               } else if (!JSValueIsNull(context, arguments[3]) && !JSValueIsUndefined(context, arguments[3])) {
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+               }
+       }
+
+       JSCallbackManagerPtr callbackManager(JSCallbackManager::createObject(priv->getContext(), onSuccessForCbm, onErrorForCbm, true, true));
+       callbackManager->setObject(thisObject);
+
+       Try {
+
+               settingType = converter->toSettingType(arguments[0]);
+               settingValue = converter->toString(arguments[1]);
+
+               Try{
+                       Api::Filesystem::IPathPtr src = Utils::fromVirtualPath(priv->getContext(), settingValue);
+                       if (src)
+                               settingValue = src->getFullPath();
+                       else
+                               settingValue = "";      //set empty string.
+
+                       LogDebug("real path = " << settingValue);
+               }
+               Catch(WrtDeviceApis::Commons::Exception) {
+                       LogDebug("settingValue is not Virtual Path");
+               }
+               
+               LogDebug("settingValue = " << settingValue);
+               
+               ISystemSettingPtr SystemSettings(priv->getObject());
+               EventSetSettingPtr dplEvent(new EventSetSetting());
+               dplEvent->setSettingType(settingType);
+               dplEvent->setSettingValue(settingValue);
+               dplEvent->setPrivateData(StaticPointerCast<IEventPrivateData>(callbackManager));
+               dplEvent->setForAsynchronousCall(&SystemSettingResponseDispatcher::getInstance());
+          
+               SystemSettings->setProperty(dplEvent);
+               SystemSettingAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
+       }
+
+       Catch(WrtDeviceApis::Commons::ConversionException) {
+               LogDebug("Exception");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+               LogDebug("Exception");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
+       }
+
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               LogDebug("Exception");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "platform error");
+       }
+
+       Catch(WrtDeviceApis::Commons::Exception) {
+               LogDebug("Exception");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+       }
+
+       LogDebug("end");
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSystemSetting::getProperty(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+        size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+       LogDebug("enter");
+       JSSystemSettingPriv *priv = static_cast<JSSystemSettingPriv*>(JSObjectGetPrivate(thisObject));
+
+       ConverterSystemSettingFactory::ConverterType converter = ConverterSystemSettingFactory::getConverter(context);
+
+       Validator check(context, exception);
+       
+       if (!priv) {
+               LogError("private object is null");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Wrong Object");
+       }
+
+       if (argumentCount < 2) {
+               LogDebug("Argument is too few");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
+       }
+       if (!check.isCallback(arguments[1])) {
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+/*
+       AceSecurityStatus status = SYSTEMSETTING_CHECK_ACCESS(SYSTEMSETTING_FUNCTION_API_GET_PROPERTY);
+       TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+*/
+
+       JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+       onSuccessForCbm = arguments[1];
+       if (argumentCount > 2) {
+               if (check.isCallback(arguments[2])) {
+                       onErrorForCbm = arguments[2];
+               } else if (!JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2])) {
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+               }
+       }
+
+       JSCallbackManagerPtr callbackManager(JSCallbackManager::createObject(priv->getContext(), onSuccessForCbm, onErrorForCbm, true, true));
+       callbackManager->setObject(thisObject);
+
+       Try {
+
+               Api::SystemSetting::SettingType settingType = converter->toSettingType(arguments[0]);
+
+               ISystemSettingPtr SystemSettings(priv->getObject());
+               EventGetSettingPtr dplEvent(new EventGetSetting());
+               dplEvent->setSettingType(settingType);
+               dplEvent->setPrivateData(StaticPointerCast<IEventPrivateData>(callbackManager));
+               dplEvent->setForAsynchronousCall(&SystemSettingResponseDispatcher::getInstance());
+          
+               SystemSettings->getProperty(dplEvent);
+               SystemSettingAsyncCallbackManagerSingleton::Instance().registerCallbackManager(callbackManager, priv->getContext());
+
+       }
+
+       Catch(WrtDeviceApis::Commons::ConversionException) {
+               LogDebug("Exception");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+       }
+
+       Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+               LogDebug("Exception");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
+       }
+
+       Catch(WrtDeviceApis::Commons::PlatformException) {
+               LogDebug("Exception");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "platform error");
+       }
+
+       Catch(WrtDeviceApis::Commons::Exception) {
+               LogDebug("Exception");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+       }
+
+       LogDebug("end");
+       return JSValueMakeUndefined(context);
+}
+
+
+}
+}
+}
diff --git a/src/standards/Tizen/SystemSetting/JSSystemSetting.h b/src/standards/Tizen/SystemSetting/JSSystemSetting.h
new file mode 100755 (executable)
index 0000000..ea2b8f0
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// 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_TIZEN1_0_JS_SYSTEMSETTING_H_
+#define WRTPLUGINS_TIZEN1_0_JS_SYSTEMSETTING_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/SystemSetting/ISystemSetting.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace SystemSetting {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::SystemSetting::ISystemSettingPtr>::Type  JSSystemSettingPriv;
+
+class JSSystemSetting
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+
+  private:
+    static void initialize(JSContextRef context, JSObjectRef object);
+    static void finalize(JSObjectRef object);
+
+    static JSValueRef setProperty(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+    static JSValueRef getProperty(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;
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/SystemSetting/SystemSettingAsyncCallbackManager.cpp b/src/standards/Tizen/SystemSetting/SystemSettingAsyncCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..e37e4c4
--- /dev/null
@@ -0,0 +1,35 @@
+//
+// 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        SystemSettingAsyncCallbackManager.cpp
+ * @version     0.1
+ * @brief
+ */
+
+#include "SystemSettingAsyncCallbackManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::SystemSettingAsyncCallbackManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/SystemSetting/SystemSettingAsyncCallbackManager.h b/src/standards/Tizen/SystemSetting/SystemSettingAsyncCallbackManager.h
new file mode 100755 (executable)
index 0000000..14ea73b
--- /dev/null
@@ -0,0 +1,54 @@
+//
+// 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        SystemSettingAsyncCallbackManager.h
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_SYSTEMSETTING_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_SYSTEMSETTING_ASYNC_CALLBACK_MANAGER_H_
+
+#include <dpl/singleton.h>
+#include <Tizen/Common/AsyncCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+class SystemSettingAsyncCallbackManager : public TizenApis::Commons::AsyncCallbackManager
+{
+public:
+       SystemSettingAsyncCallbackManager()
+       {
+       }
+
+       virtual ~SystemSettingAsyncCallbackManager()
+       {
+       }
+
+       friend class DPL::Singleton<SystemSettingAsyncCallbackManager>;
+};
+
+typedef DPL::Singleton<SystemSettingAsyncCallbackManager> SystemSettingAsyncCallbackManagerSingleton;
+
+
+} // Tizen1_0
+} // TizenApis
+
+#endif
diff --git a/src/standards/Tizen/SystemSetting/SystemSettingResponseDispatcher.cpp b/src/standards/Tizen/SystemSetting/SystemSettingResponseDispatcher.cpp
new file mode 100755 (executable)
index 0000000..e48910a
--- /dev/null
@@ -0,0 +1,249 @@
+//
+// 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 "SystemSettingResponseDispatcher.h"
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+
+#include <Tizen/Filesystem/FilesystemUtils.h>
+
+#include "SystemSettingAsyncCallbackManager.h"
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::SystemSetting;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace SystemSetting {
+
+SystemSettingResponseDispatcher& SystemSettingResponseDispatcher::getInstance()
+{
+    static SystemSettingResponseDispatcher instance;
+    return instance;
+}
+
+SystemSettingResponseDispatcher::SystemSettingResponseDispatcher() :
+    SystemSettingSetWallpaperEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD),
+    SystemSettingSetRingtoneEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD),
+    SystemSettingSetSettingEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD),
+    SystemSettingGetSettingEventAnswerReceiverRequest(ThreadEnum::NULL_THREAD)
+{
+}
+
+SystemSettingResponseDispatcher::~SystemSettingResponseDispatcher()
+{
+}
+
+void SystemSettingResponseDispatcher::OnAnswerReceived(const EventSetWallpaperPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+
+       if (!callbackManager) {
+               LogError("No listener callback!");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+       JSValueRef error = NULL;
+       
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::INVALID_VALUES_ERROR, "DomainName is not setted");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+               LogDebug("callOnError");
+               callbackManager->callOnError(error);
+               return;
+       }
+       LogDebug("callOnSuccess");
+       callbackManager->callOnSuccess();
+}
+
+
+void SystemSettingResponseDispatcher::OnAnswerReceived(const EventSetRingtonePtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+
+       if (!callbackManager) {
+               LogError("No listener callback!");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+       JSValueRef error = NULL;
+
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::INVALID_VALUES_ERROR, "DomainName is not setted");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+       callbackManager->callOnSuccess();
+}
+
+void SystemSettingResponseDispatcher::OnAnswerReceived(const EventSetSettingPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+
+       if (!callbackManager) {
+               LogError("No listener callback!");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+       JSValueRef error = NULL;
+    
+       SystemSettingAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::INVALID_VALUES_ERROR, "DomainName is not setted");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+       callbackManager->callOnSuccess();
+}
+
+void SystemSettingResponseDispatcher::OnAnswerReceived(const EventGetSettingPtr &event)
+{
+       LogDebug("entered");
+       JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<JSCallbackManager >(event->getPrivateData());
+
+       if (!callbackManager) {
+               LogError("No listener callback!");
+               return;
+       }
+
+       JSContextRef gContext = callbackManager->getContext();
+       JSValueRef error = NULL;
+    
+       SystemSettingAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager);
+    
+       Converter converter(gContext);
+       
+       if (ExceptionCodes::None != event->getExceptionCode())
+       {
+               switch (event->getExceptionCode())
+               {
+               case ExceptionCodes::PlatformException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Internal error");
+                       break;
+               case ExceptionCodes::NotFoundException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::NOT_FOUND_ERROR, "record not found");
+                       break;
+               case ExceptionCodes::InvalidArgumentException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::INVALID_VALUES_ERROR, "DomainName is not setted");
+                       break;
+               case ExceptionCodes::ConversionException:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong argument");
+                       break;
+               default:
+                       error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+                       break;
+               }
+
+               callbackManager->callOnError(error);
+               return;
+       }
+       LogDebug("gettingValue : " << event->getSettingValue());
+
+       std::string settingPath = event->getSettingValue();
+       LogDebug("RealSettingPath : " << settingPath);
+
+       Try
+       {
+               settingPath = Utils::toVirtualPath(gContext, settingPath);
+               LogDebug("VirtualSettingPath : " << settingPath);
+       }
+       Catch(WrtDeviceApis::Commons::ConversionException) {
+               LogDebug("not the virtual path");
+               LogDebug("RealSettingSettingPath : " << settingPath);
+       }
+
+       if (settingPath.size() == 0)
+       {
+               error = JSTizenExceptionFactory::makeErrorObject(gContext, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+               callbackManager->callOnError(error);
+               return;
+       }
+//     return converter.toJSValueRef(iconPath);
+       callbackManager->callOnSuccess(converter.toJSValueRef(settingPath));
+}
+
+
+
+}
+}
+}
diff --git a/src/standards/Tizen/SystemSetting/SystemSettingResponseDispatcher.h b/src/standards/Tizen/SystemSetting/SystemSettingResponseDispatcher.h
new file mode 100755 (executable)
index 0000000..4ecccae
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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 _SYSTEMSETTING_RESPONSE_DISPATCHER_H_
+#define _SYSTEMSETTING_RESPONSE_DISPATCHER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <Commons/EventReceiver.h>
+#include <Commons/EventListener.h>
+#include <API/SystemSetting/EventSetWallpaper.h>
+#include <API/SystemSetting/EventSetRingtone.h>
+#include <API/SystemSetting/EventSetSetting.h>
+#include <API/SystemSetting/EventGetSetting.h>
+
+#include <CommonsJavaScript/Converter.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace SystemSetting {
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::SystemSetting::EventSetWallpaper>
+SystemSettingSetWallpaperEventAnswerReceiverRequest;
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::SystemSetting::EventSetRingtone>
+SystemSettingSetRingtoneEventAnswerReceiverRequest;
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::SystemSetting::EventSetSetting>
+SystemSettingSetSettingEventAnswerReceiverRequest;
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::SystemSetting::EventGetSetting>
+SystemSettingGetSettingEventAnswerReceiverRequest;
+
+class SystemSettingResponseDispatcher :
+       public SystemSettingSetWallpaperEventAnswerReceiverRequest,
+       public SystemSettingSetRingtoneEventAnswerReceiverRequest,
+       public SystemSettingSetSettingEventAnswerReceiverRequest,
+       public SystemSettingGetSettingEventAnswerReceiverRequest
+{
+  public:
+    static SystemSettingResponseDispatcher& getInstance();
+
+  private:
+    SystemSettingResponseDispatcher();
+    virtual ~SystemSettingResponseDispatcher();
+
+  protected:
+    void OnAnswerReceived(const TizenApis::Api::SystemSetting::EventSetWallpaperPtr &event);
+    void OnAnswerReceived(const TizenApis::Api::SystemSetting::EventSetRingtonePtr &event);
+    void OnAnswerReceived(const TizenApis::Api::SystemSetting::EventSetSettingPtr &event);
+    void OnAnswerReceived(const TizenApis::Api::SystemSetting::EventGetSettingPtr &event);
+
+};
+
+}
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/SystemSetting/config.xml b/src/standards/Tizen/SystemSetting/config.xml
new file mode 100644 (file)
index 0000000..1c356bc
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+       <library-name>libwrt-plugins-tizen-2.0-systemsetting.so</library-name>
+       <feature-install-uri>systemsetting.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/setting</name>
+        <device-capability>setting</device-capability>
+        <Object name="setting">
+            <Function name="setProperty"/>
+            <Function name="getProperty"/>
+        </Object>
+    </api-feature>
+</plugin-properties>
+
diff --git a/src/standards/Tizen/SystemSetting/plugin_config.cpp b/src/standards/Tizen/SystemSetting/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..1fba1b7
--- /dev/null
@@ -0,0 +1,108 @@
+//
+// 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 <map>
+#include <utility>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include "plugin_config.h"
+
+#define SYSTEMSETTING_FEATURE_API "http://tizen.org/privilege/setting"
+//#define SYSTEMSETTING_FEATURE_API_READ "http://tizen.org/privilege/setting.read"
+//#define SYSTEMSETTING_FEATURE_API_WRITE "http://tizen.org/privilege/setting.write"
+
+#define SYSTEMSETTING_DEVICE_CAP "setting"
+//#define SYSTEMSETTING_DEVICE_CAP_READ "setting"
+//#define SYSTEMSETTING_DEVICE_CAP_WRITE "setting"
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+const char* SYSTEMSETTING_FUNCTION_API_SET_PROPERTY = "setProperty";
+const char* SYSTEMSETTING_FUNCTION_API_GET_PROPERTY = "getProperty";
+
+static WrtDeviceApis::Commons::FunctionMapping createSystemSettingFunctions();
+
+static WrtDeviceApis::Commons::FunctionMapping SystemSettingFunctions =
+    createSystemSettingFunctions();
+
+DEFINE_FUNCTION_GETTER(SystemSetting, SystemSettingFunctions);
+
+static WrtDeviceApis::Commons::FunctionMapping createSystemSettingFunctions()
+{
+    using namespace WrtDeviceApis::Commons;
+
+       /**
+        * Device capabilities
+        */
+
+       ACE_CREATE_DEVICE_CAP(DEVICE_CAP_SYSTEMSETTING, SYSTEMSETTING_DEVICE_CAP);
+
+       ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+
+       ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_SYSTEMSETTING);
+       ACE_ADD_DEVICE_CAP(DEVICE_LIST_SYSTEMSETTING, DEVICE_CAP_SYSTEMSETTING);
+
+       /**
+        * Api Features
+        */
+
+       ACE_CREATE_FEATURE(FEATURE_SYSTEMSETTING, SYSTEMSETTING_FEATURE_API);
+
+       ACE_CREATE_FEATURE_LIST(SYSTEMSETTING_FEATURES_SYSTEMSETTING);
+       ACE_ADD_API_FEATURE(SYSTEMSETTING_FEATURES_SYSTEMSETTING, FEATURE_SYSTEMSETTING);
+
+
+       /**
+       * Functions
+       */
+
+       FunctionMapping SystemSettingFunctions;
+
+       /**  Read  **/
+       AceFunction getPropertyFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_GET_PROPERTY,
+                       SYSTEMSETTING_FUNCTION_API_GET_PROPERTY,
+                       SYSTEMSETTING_FEATURES_SYSTEMSETTING,
+                       EMPTY_DEVICE_LIST);
+
+       SystemSettingFunctions.insert( std::make_pair(
+                       SYSTEMSETTING_FUNCTION_API_GET_PROPERTY,
+                       getPropertyFunc));
+
+
+       /**  Write  **/
+       AceFunction setPropertyFunc = ACE_CREATE_FUNCTION(
+                       FUNCTION_SET_PROPERTY,
+                       SYSTEMSETTING_FUNCTION_API_SET_PROPERTY,
+                       SYSTEMSETTING_FEATURES_SYSTEMSETTING,
+                       EMPTY_DEVICE_LIST);
+
+       SystemSettingFunctions.insert( std::make_pair(
+                       SYSTEMSETTING_FUNCTION_API_SET_PROPERTY,
+                       setPropertyFunc));
+
+       return SystemSettingFunctions;
+}
+}
+}
+
+#undef SYSTEMSETTING_FEATURE_API
+#undef SYSTEMSETTING_DEVICE_CAP
+
diff --git a/src/standards/Tizen/SystemSetting/plugin_config.h b/src/standards/Tizen/SystemSetting/plugin_config.h
new file mode 100755 (executable)
index 0000000..0287e2f
--- /dev/null
@@ -0,0 +1,39 @@
+//
+// 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 _SYSTEMSETTING_PLUGIN_CONFIG_H_
+#define _SYSTEMSETTING_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+extern const char* SYSTEMSETTING_FUNCTION_API_SET_PROPERTY;
+extern const char* SYSTEMSETTING_FUNCTION_API_GET_PROPERTY;
+
+
+DECLARE_FUNCTION_GETTER(SystemSetting);
+
+#define SYSTEMSETTING_CHECK_ACCESS(functionName)               \
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(             \
+                                            getSystemSettingFunctionData,     \
+                                            functionName)
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/SystemSetting/plugin_initializer.cpp b/src/standards/Tizen/SystemSetting/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..ca11112
--- /dev/null
@@ -0,0 +1,79 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include "JSSystemSetting.h"
+#include "SystemSettingAsyncCallbackManager.h"
+//#include "MessageListenerManager.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+#define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[Tizen\\SystemSetting ] on_widget_start_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess initialization failed");
+    }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[Tizen\\SystemSetting ] on_widget_stop_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+void on_frame_load_callback(const void * context)
+{
+    LogDebug("[Tizen\\contact] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LogDebug("[Tizen\\contact] on_frame_unload_callback (" << context << ")");
+
+    TizenApis::Tizen1_0::SystemSettingAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+//    TizenApis::Tizen1_0::MessageListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+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, "systemsetting", (js_class_template_getter)TizenApis::Tizen1_0::SystemSetting::JSSystemSetting::getClassRef, NULL)
+PLUGIN_CLASS_MAP_END
+
diff --git a/src/standards/Tizen/Systeminfo/CMakeLists.txt b/src/standards/Tizen/Systeminfo/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..b4beb0a
--- /dev/null
@@ -0,0 +1,34 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-systeminfo")
+
+include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_SYSTEMINFO})
+
+set(SRCS 
+  ${SRCS_PLATFORM_IMPLEMENTATION_SYSTEMINFO}
+  ${SRCS_PLATFORM_API_SYSTEMINFO}
+  JSDisplayInfo.cpp  
+  JSStorageInfo.cpp
+  JSCpuInfo.cpp
+  JSWifiNetworkInfo.cpp
+  JSCellularNetworkInfo.cpp
+  JSBatteryInfo.cpp
+  JSNetworkInfo.cpp
+  JSSIMInfo.cpp  
+  JSDeviceOrientationInfo.cpp
+  JSBuildInfo.cpp
+  JSDeviceCapabilitiesInfo.cpp  
+  JSSysteminfo.cpp
+  SysteminfoAsyncCallbackManager.cpp
+  SysteminfoListener.cpp
+  SysteminfoListenerManager.cpp
+  plugin_initializer.cpp
+  plugin_config.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${LIBS_COMMON}
+  ${LIBS_PLATFORM_IMPLEMENTATION_SYSTEMINFO}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION tizen-2.0-systeminfo)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION tizen-2.0-systeminfo)
diff --git a/src/standards/Tizen/Systeminfo/JSBatteryInfo.cpp b/src/standards/Tizen/Systeminfo/JSBatteryInfo.cpp
new file mode 100755 (executable)
index 0000000..370f4a3
--- /dev/null
@@ -0,0 +1,126 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include "JSBatteryInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+
+namespace {
+const char* BATTERY_LEVEL_PROPERTY = "level";
+const char* BATTERY_ISCHARGING_PROPERTY = "isCharging";
+} 
+
+JSClassRef JSBatteryInfo::m_classRef = NULL;
+
+JSClassDefinition JSBatteryInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "batteryinfo",
+    0,
+    m_properties,
+    NULL,
+    Initialize,
+    Finalize,
+    hasProperty,
+    getProperty,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticValue JSBatteryInfo::m_properties[] = {
+    { BATTERY_LEVEL_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { BATTERY_ISCHARGING_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSBatteryInfo::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+const JSClassDefinition* JSBatteryInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSBatteryInfo::Initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSBatteryInfo::Finalize(JSObjectRef object)
+{
+    LogDebug("Entered");
+    JSBatteryPriv* priv = static_cast<JSBatteryPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting batteryInfo object");
+    delete priv;
+}
+
+bool JSBatteryInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    return JSUtils::hasProperty(m_properties, propertyName);
+}
+
+JSObjectRef JSBatteryInfo::createJSObject(JSContextRef context, const Api::Systeminfo::BatteryPropertiesPtr batteryInfo)
+{
+       LogDebug("test");
+    JSBatteryPriv *priv = new JSBatteryPriv(context, batteryInfo);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSBatteryInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("Enter");
+    JSBatteryPriv *priv = static_cast<JSBatteryPriv*>(JSObjectGetPrivate(object));
+    if (NULL == priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    Try
+    {
+        Api::Systeminfo::BatteryPropertiesPtr batteryInfo = priv->getObject();
+        Converter convert(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, BATTERY_LEVEL_PROPERTY)) {
+            return convert.toJSValueRef(batteryInfo->level);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, BATTERY_ISCHARGING_PROPERTY)) {
+            return convert.toJSValueRef(batteryInfo->isCharging);
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSBatteryInfo.h b/src/standards/Tizen/Systeminfo/JSBatteryInfo.h
new file mode 100755 (executable)
index 0000000..8bb4e46
--- /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 WRTPLUGINS_TIZEN1_0_BATTERY_INFO_H_
+#define WRTPLUGINS_TIZEN1_0_BATTERY_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Systeminfo/SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::BatteryPropertiesPtr>::Type  JSBatteryPriv;
+
+class JSBatteryInfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::Systeminfo::BatteryPropertiesPtr batteryInfo);
+
+  private:
+    static void Initialize(JSContextRef context, JSObjectRef object);
+    static void Finalize(JSObjectRef object);
+    static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSStaticValue m_properties[];
+    static JSClassRef m_classRef;
+    static JSClassDefinition m_classInfo;
+};
+
+}
+}
+#endif
diff --git a/src/standards/Tizen/Systeminfo/JSBuildInfo.cpp b/src/standards/Tizen/Systeminfo/JSBuildInfo.cpp
new file mode 100755 (executable)
index 0000000..b026e62
--- /dev/null
@@ -0,0 +1,121 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include "JSBuildInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+
+namespace {
+const char* BUILD_MODEL_PROPERTY = "model";
+}
+
+JSClassRef JSBuildInfo::m_classRef = NULL;
+
+JSClassDefinition JSBuildInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "buildinfo",
+    0,
+    m_properties,
+    NULL,
+    Initialize,
+    Finalize,
+    hasProperty,
+    getProperty,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticValue JSBuildInfo::m_properties[] = {
+    { BUILD_MODEL_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSBuildInfo::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+const JSClassDefinition* JSBuildInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSBuildInfo::Initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSBuildInfo::Finalize(JSObjectRef object)
+{
+    LogDebug("Entered");
+    JSBuildPriv* priv = static_cast<JSBuildPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting buildInfo object");
+    delete priv;
+}
+
+bool JSBuildInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    return JSUtils::hasProperty(m_properties, propertyName);
+}
+
+JSObjectRef JSBuildInfo::createJSObject(JSContextRef context, const Api::Systeminfo::BuildPropertiesPtr buildInfo)
+{
+    JSBuildPriv *priv = new JSBuildPriv(context, buildInfo);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSBuildInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("Enter");
+    JSBuildPriv *priv = static_cast<JSBuildPriv*>(JSObjectGetPrivate(object));
+    if (NULL == priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    Try
+    {
+        Api::Systeminfo::BuildPropertiesPtr buildInfo = priv->getObject();
+        Converter convert(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, BUILD_MODEL_PROPERTY)) {
+            return convert.toJSValueRef(buildInfo->model);
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSBuildInfo.h b/src/standards/Tizen/Systeminfo/JSBuildInfo.h
new file mode 100755 (executable)
index 0000000..1929da8
--- /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 WRTPLUGINS_TIZEN1_0_BUILD_INFO_H_
+#define WRTPLUGINS_TIZEN1_0_BUILD_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Systeminfo/SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::BuildPropertiesPtr>::Type    JSBuildPriv;
+
+class JSBuildInfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::Systeminfo::BuildPropertiesPtr buildInfo);
+
+  private:
+    static void Initialize(JSContextRef context, JSObjectRef object);
+    static void Finalize(JSObjectRef object);
+    static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSStaticValue m_properties[];
+    static JSClassRef m_classRef;
+    static JSClassDefinition m_classInfo;
+};
+
+}
+}
+#endif
diff --git a/src/standards/Tizen/Systeminfo/JSCellularNetworkInfo.cpp b/src/standards/Tizen/Systeminfo/JSCellularNetworkInfo.cpp
new file mode 100755 (executable)
index 0000000..8930790
--- /dev/null
@@ -0,0 +1,154 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include "JSCellularNetworkInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+
+namespace {
+const char* CELLULARNETWORK_STATUS_PROPERTY = "status";
+const char* CELLULARNETWORK_APN_PROPERTY = "apn";
+const char* CELLULARNETWORK_IPADDRESS_PROPERTY = "ipAddress";
+const char* CELLULARNETWORK_IPV6ADDRESS_PROPERTY = "ipv6Address";
+const char* CELLULARNETWORK_MCC_PROPERTY = "mcc";
+const char* CELLULARNETWORK_MNC_PROPERTY = "mnc";
+const char* CELLULARNETWORK_CELLID_PROPERTY = "cellId";
+const char* CELLULARNETWORK_LAC_PROPERTY = "lac";
+const char* CELLULARNETWORK_ROAMING_PROPERTY = "isRoaming";
+} 
+
+JSClassRef JSCellularNetworkInfo::m_classRef = NULL;
+
+JSClassDefinition JSCellularNetworkInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "cellularnetworkinfo",
+    0,
+    m_properties,
+    NULL,
+    Initialize,
+    Finalize,
+    hasProperty,
+    getProperty,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticValue JSCellularNetworkInfo::m_properties[] = {
+    { CELLULARNETWORK_STATUS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { CELLULARNETWORK_APN_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { CELLULARNETWORK_IPADDRESS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
+    { CELLULARNETWORK_IPV6ADDRESS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },            
+    { CELLULARNETWORK_MCC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
+    { CELLULARNETWORK_MNC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },                
+    { CELLULARNETWORK_CELLID_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { CELLULARNETWORK_LAC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
+    { CELLULARNETWORK_ROAMING_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },                
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSCellularNetworkInfo::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+const JSClassDefinition* JSCellularNetworkInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSCellularNetworkInfo::Initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSCellularNetworkInfo::Finalize(JSObjectRef object)
+{
+    LogDebug("Entered");
+    JSCellularNetworkPriv* priv = static_cast<JSCellularNetworkPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting CellularNetworkInfo object");
+    delete priv;
+}
+
+bool JSCellularNetworkInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    return JSUtils::hasProperty(m_properties, propertyName);
+}
+
+JSObjectRef JSCellularNetworkInfo::createJSObject(JSContextRef context, const Api::Systeminfo::CellularNetworkPropertiesPtr cellularNetworkInfo)
+{
+    LogDebug("Enter");
+    JSCellularNetworkPriv *priv = new JSCellularNetworkPriv(context, cellularNetworkInfo);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSCellularNetworkInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("Enter");
+    JSCellularNetworkPriv *priv = static_cast<JSCellularNetworkPriv*>(JSObjectGetPrivate(object));
+    if (NULL == priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    Try
+    {
+        Api::Systeminfo::CellularNetworkPropertiesPtr cellularNetworkInfo = priv->getObject();
+        Converter convert(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_STATUS_PROPERTY)) {
+            return convert.toJSValueRef(cellularNetworkInfo->status);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_APN_PROPERTY)) {
+            return convert.toJSValueRef(cellularNetworkInfo->apn);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_IPADDRESS_PROPERTY)) {
+            return convert.toJSValueRef(cellularNetworkInfo->ipAddress);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_IPV6ADDRESS_PROPERTY)) {
+            return convert.toJSValueRef(cellularNetworkInfo->ipv6Address);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_MCC_PROPERTY)) {
+            return convert.toJSValueRef(cellularNetworkInfo->mcc);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_MNC_PROPERTY)) {
+            return convert.toJSValueRef(cellularNetworkInfo->mnc);            
+        } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_CELLID_PROPERTY)) {
+            return convert.toJSValueRef(cellularNetworkInfo->cellId);            
+        } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_LAC_PROPERTY)) {
+            return convert.toJSValueRef(cellularNetworkInfo->lac);            
+        } else if (JSStringIsEqualToUTF8CString(propertyName, CELLULARNETWORK_ROAMING_PROPERTY)) {
+            return convert.toJSValueRef(cellularNetworkInfo->isRoaming);            
+        }            
+    }
+    Catch(Exception)
+    {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSCellularNetworkInfo.h b/src/standards/Tizen/Systeminfo/JSCellularNetworkInfo.h
new file mode 100755 (executable)
index 0000000..c6cce47
--- /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 WRTPLUGINS_TIZEN1_0_CELLULARNETWORK_INFO_H_
+#define WRTPLUGINS_TIZEN1_0_CELLULARNETWORK_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Systeminfo/SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::CellularNetworkPropertiesPtr>::Type  JSCellularNetworkPriv;
+
+class JSCellularNetworkInfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::Systeminfo::CellularNetworkPropertiesPtr cellularNetworkInfo);
+
+  private:
+    static void Initialize(JSContextRef context, JSObjectRef object);
+    static void Finalize(JSObjectRef object);
+    static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSStaticValue m_properties[];
+    static JSClassRef m_classRef;
+    static JSClassDefinition m_classInfo;
+};
+
+}
+}
+#endif
diff --git a/src/standards/Tizen/Systeminfo/JSCpuInfo.cpp b/src/standards/Tizen/Systeminfo/JSCpuInfo.cpp
new file mode 100755 (executable)
index 0000000..dd06908
--- /dev/null
@@ -0,0 +1,122 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include "JSCpuInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+
+namespace {
+const char* CPU_LOAD_PROPERTY = "load";
+} 
+
+JSClassRef JSCpuInfo::m_classRef = NULL;
+
+JSClassDefinition JSCpuInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "cpuinfo",
+    0,
+    m_properties,
+    NULL,
+    Initialize,
+    Finalize,
+    hasProperty,
+    getProperty,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticValue JSCpuInfo::m_properties[] = {
+    { CPU_LOAD_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSCpuInfo::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+const JSClassDefinition* JSCpuInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSCpuInfo::Initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSCpuInfo::Finalize(JSObjectRef object)
+{
+    LogDebug("Entered");
+    JSCpuPriv* priv = static_cast<JSCpuPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting CpuInfo object");
+    delete priv;
+}
+
+bool JSCpuInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    return JSUtils::hasProperty(m_properties, propertyName);
+}
+
+JSObjectRef JSCpuInfo::createJSObject(JSContextRef context, const Api::Systeminfo::CpuPropertiesPtr cpuInfo)
+{
+    LogDebug("Enter");
+    JSCpuPriv *priv = new JSCpuPriv(context, cpuInfo);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSCpuInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("Enter");
+    JSCpuPriv *priv = static_cast<JSCpuPriv*>(JSObjectGetPrivate(object));
+    if (NULL == priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    Try
+    {
+        Api::Systeminfo::CpuPropertiesPtr cpuInfo = priv->getObject();
+        Converter convert(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, CPU_LOAD_PROPERTY)) {
+            return convert.toJSValueRef(cpuInfo->load);
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSCpuInfo.h b/src/standards/Tizen/Systeminfo/JSCpuInfo.h
new file mode 100755 (executable)
index 0000000..cd1f0d5
--- /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 WRTPLUGINS_TIZEN1_0_CPU_INFO_H_
+#define WRTPLUGINS_TIZEN1_0_CPU_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Systeminfo/SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::CpuPropertiesPtr>::Type      JSCpuPriv;
+
+class JSCpuInfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::Systeminfo::CpuPropertiesPtr cpuInfo);
+
+  private:
+    static void Initialize(JSContextRef context, JSObjectRef object);
+    static void Finalize(JSObjectRef object);
+    static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSStaticValue m_properties[];
+    static JSClassRef m_classRef;
+    static JSClassDefinition m_classInfo;
+};
+
+}
+}
+#endif
diff --git a/src/standards/Tizen/Systeminfo/JSDeviceCapabilitiesInfo.cpp b/src/standards/Tizen/Systeminfo/JSDeviceCapabilitiesInfo.cpp
new file mode 100755 (executable)
index 0000000..457d48c
--- /dev/null
@@ -0,0 +1,250 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include "JSDeviceCapabilitiesInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+
+namespace {
+const char* DEVICE_CAPABILITIES_BLUETOOTH = "bluetooth";
+const char* DEVICE_CAPABILITIES_NFC = "nfc";
+const char* DEVICE_CAPABILITIES_MULTITOUCHCOUNT = "multiTouchCount";
+const char* DEVICE_CAPABILITIES_INPUTKEYBOARD = "inputKeyboard";
+const char* DEVICE_CAPABILITIES_WIFI = "wifi";
+const char* DEVICE_CAPABILITIES_WIFIDIRECT = "wifiDirect";
+const char* DEVICE_CAPABILITIES_OPENGLESVERSION1_1 = "openglesVersion1_1";
+const char* DEVICE_CAPABILITIES_OPENGLESVERSION2_0 = "openglesVersion2_0";
+const char* DEVICE_CAPABILITIES_FMRADIO = "fmRadio";
+const char* DEVICE_CAPABILITIES_PLATFORMVERSION = "platformVersion";
+const char* DEVICE_CAPABILITIES_PLATFORMNAME = "platformName";
+const char* DEVICE_CAPABILITIES_CAMERAFRONT = "cameraFront";
+const char* DEVICE_CAPABILITIES_CAMERAFRONTFLASH = "cameraFrontFlash";
+const char* DEVICE_CAPABILITIES_CAMERABACK = "cameraBack";
+const char* DEVICE_CAPABILITIES_CAMERABACKFLASH = "cameraBackFlash";
+const char* DEVICE_CAPABILITIES_LOCATION = "location";
+const char* DEVICE_CAPABILITIES_LOCATIONGPS = "locationGps";
+const char* DEVICE_CAPABILITIES_LOCATIONWPS = "locationWps";
+const char* DEVICE_CAPABILITIES_MICROPHONE = "microphone";
+const char* DEVICE_CAPABILITIES_USBHOST = "usbHost";
+const char* DEVICE_CAPABILITIES_USBACCESSORY = "usbAccessory";
+const char* DEVICE_CAPABILITIES_SCREENOUTPUTRCA = "screenOutputRca";
+const char* DEVICE_CAPABILITIES_SCREENOUTPUTHDMI = "screenOutputHdmi";
+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_ACCELEROMETER = "accelerometer";
+const char* DEVICE_CAPABILITIES_BAROMETER = "barometer";
+const char* DEVICE_CAPABILITIES_GYROSCOPE = "gyroscope";
+const char* DEVICE_CAPABILITIES_MAGNETOMETER = "magnetometer";
+const char* DEVICE_CAPABILITIES_PROXIMITY = "proximity";
+} 
+
+JSClassRef JSDeviceCapabilitiesInfo::m_classRef = NULL;
+
+JSClassDefinition JSDeviceCapabilitiesInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "devicecapabilitiesinfo",
+    0,
+    m_properties,
+    NULL,
+    Initialize,
+    Finalize,
+    hasProperty,
+    getProperty,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticValue JSDeviceCapabilitiesInfo::m_properties[] = {
+    { DEVICE_CAPABILITIES_BLUETOOTH, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_NFC, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_MULTITOUCHCOUNT, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_INPUTKEYBOARD, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_WIFI, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_WIFIDIRECT, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_OPENGLESVERSION1_1, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_OPENGLESVERSION2_0, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_FMRADIO, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_PLATFORMVERSION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_PLATFORMNAME, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_CAMERAFRONT, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_CAMERAFRONTFLASH, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_CAMERABACK, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_CAMERABACKFLASH, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_LOCATION, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_LOCATIONGPS, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_LOCATIONWPS, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_MICROPHONE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_USBHOST, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_USBACCESSORY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_SCREENOUTPUTRCA, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_SCREENOUTPUTHDMI, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_PLATFORMCORECPUARCH, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 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_ACCELEROMETER, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_BAROMETER, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_GYROSCOPE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_MAGNETOMETER, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DEVICE_CAPABILITIES_PROXIMITY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSDeviceCapabilitiesInfo::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+const JSClassDefinition* JSDeviceCapabilitiesInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSDeviceCapabilitiesInfo::Initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSDeviceCapabilitiesInfo::Finalize(JSObjectRef object)
+{
+    LogDebug("Entered");
+    JSDeviceCapabilitiesPriv* priv = static_cast<JSDeviceCapabilitiesPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting DeviceCapabilitiesInfo object");
+    delete priv;
+}
+
+bool JSDeviceCapabilitiesInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    return JSUtils::hasProperty(m_properties, propertyName);
+}
+
+JSObjectRef JSDeviceCapabilitiesInfo::createJSObject(JSContextRef context, const Api::Systeminfo::DeviceCapabilitiesPropertiesPtr deviceCapabilitiesInfo)
+{
+    LogDebug("Enter");
+    JSDeviceCapabilitiesPriv *priv = new JSDeviceCapabilitiesPriv(context, deviceCapabilitiesInfo);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSDeviceCapabilitiesInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("Enter");
+    JSDeviceCapabilitiesPriv *priv = static_cast<JSDeviceCapabilitiesPriv*>(JSObjectGetPrivate(object));
+    if (NULL == priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    Try
+    {
+        Api::Systeminfo::DeviceCapabilitiesPropertiesPtr deviceCapabilitiesInfo = priv->getObject();
+        Converter convert(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_BLUETOOTH)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->bluetooth);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_NFC)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->nfc);
+        } 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_WIFI)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->wifi);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_WIFIDIRECT)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->wifiDirect);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_OPENGLESVERSION1_1)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->openglesVersion1_1);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_OPENGLESVERSION2_0)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->openglesVersion2_0);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_FMRADIO)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->fmRadio);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_PLATFORMVERSION)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->platformVersion);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_PLATFORMNAME)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->platformName);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_CAMERAFRONT)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->cameraFront);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_CAMERAFRONTFLASH)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->cameraFrontFlash);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_CAMERABACK)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->cameraBack);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_CAMERABACKFLASH)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->cameraBackFlash);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_LOCATION)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->location);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_LOCATIONGPS)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->locationGps);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_LOCATIONWPS)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->locationWps);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_MICROPHONE)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->microphone);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_USBHOST)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->usbHost);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_USBACCESSORY)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->usbAccessory);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SCREENOUTPUTRCA)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->screenOutputRca);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SCREENOUTPUTHDMI)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->screenOutputHdmi);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_PLATFORMCORECPUARCH)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->platformCoreCpuArch);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_PLATFORMCOREFPUARCH)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->platformCoreFpuArch);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SIPVOIP)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->sipVoip);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_DUID)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->duid);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_SPEECHROCOGNITION)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->speechRecognition);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_ACCELEROMETER)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->accelerometer);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_BAROMETER)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->barometer);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_GYROSCOPE)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->gyroscope);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_MAGNETOMETER)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->magnetometer);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DEVICE_CAPABILITIES_PROXIMITY)) {
+            return convert.toJSValueRef(deviceCapabilitiesInfo->proximity);
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSDeviceCapabilitiesInfo.h b/src/standards/Tizen/Systeminfo/JSDeviceCapabilitiesInfo.h
new file mode 100755 (executable)
index 0000000..af47748
--- /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 WRTPLUGINS_TIZEN1_0_DEVICE_CAPABILITIES_INFO_H_
+#define WRTPLUGINS_TIZEN1_0_DEVICE_CAPABILITIES_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Systeminfo/SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::DeviceCapabilitiesPropertiesPtr>::Type       JSDeviceCapabilitiesPriv;
+
+class JSDeviceCapabilitiesInfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::Systeminfo::DeviceCapabilitiesPropertiesPtr deviceCapabilitiesInfo);
+
+  private:
+    static void Initialize(JSContextRef context, JSObjectRef object);
+    static void Finalize(JSObjectRef object);
+    static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSStaticValue m_properties[];
+    static JSClassRef m_classRef;
+    static JSClassDefinition m_classInfo;
+};
+
+}
+}
+#endif
diff --git a/src/standards/Tizen/Systeminfo/JSDeviceOrientationInfo.cpp b/src/standards/Tizen/Systeminfo/JSDeviceOrientationInfo.cpp
new file mode 100755 (executable)
index 0000000..e445a34
--- /dev/null
@@ -0,0 +1,121 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include "JSDeviceOrientationInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+
+namespace {
+const char* DEVICEORIENTATION_STATUS_PROPERTY = "status";
+}
+
+JSClassRef JSDeviceOrientationInfo::m_classRef = NULL;
+
+JSClassDefinition JSDeviceOrientationInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "deviceorientationinfo",
+    0,
+    m_properties,
+    NULL,
+    Initialize,
+    Finalize,
+    hasProperty,
+    getProperty,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticValue JSDeviceOrientationInfo::m_properties[] = {
+    { DEVICEORIENTATION_STATUS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSDeviceOrientationInfo::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+const JSClassDefinition* JSDeviceOrientationInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSDeviceOrientationInfo::Initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSDeviceOrientationInfo::Finalize(JSObjectRef object)
+{
+    LogDebug("Entered");
+    JSDeviceOrientationPriv* priv = static_cast<JSDeviceOrientationPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting deviceOrientationInfo object");
+    delete priv;
+}
+
+bool JSDeviceOrientationInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    return JSUtils::hasProperty(m_properties, propertyName);
+}
+
+JSObjectRef JSDeviceOrientationInfo::createJSObject(JSContextRef context, const Api::Systeminfo::DeviceOrientationPropertiesPtr deviceOrientationInfo)
+{
+    JSDeviceOrientationPriv *priv = new JSDeviceOrientationPriv(context, deviceOrientationInfo);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSDeviceOrientationInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("Enter");
+    JSDeviceOrientationPriv *priv = static_cast<JSDeviceOrientationPriv*>(JSObjectGetPrivate(object));
+    if (NULL == priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    Try
+    {
+        Api::Systeminfo::DeviceOrientationPropertiesPtr deviceOrientationInfo = priv->getObject();
+        Converter convert(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, DEVICEORIENTATION_STATUS_PROPERTY)) {
+            return convert.toJSValueRef(deviceOrientationInfo->status);
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSDeviceOrientationInfo.h b/src/standards/Tizen/Systeminfo/JSDeviceOrientationInfo.h
new file mode 100755 (executable)
index 0000000..9b7dfa4
--- /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 WRTPLUGINS_TIZEN1_0_DEVICEORIENTATION_INFO_H_
+#define WRTPLUGINS_TIZEN1_0_DEVICEORIENTATION_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Systeminfo/SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::DeviceOrientationPropertiesPtr>::Type        JSDeviceOrientationPriv;
+
+class JSDeviceOrientationInfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::Systeminfo::DeviceOrientationPropertiesPtr deviceOrientationInfo);
+
+  private:
+    static void Initialize(JSContextRef context, JSObjectRef object);
+    static void Finalize(JSObjectRef object);
+    static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSStaticValue m_properties[];
+    static JSClassRef m_classRef;
+    static JSClassDefinition m_classInfo;
+};
+
+}
+}
+#endif
diff --git a/src/standards/Tizen/Systeminfo/JSDisplayInfo.cpp b/src/standards/Tizen/Systeminfo/JSDisplayInfo.cpp
new file mode 100755 (executable)
index 0000000..812a6f0
--- /dev/null
@@ -0,0 +1,144 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include "JSDisplayInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+
+namespace {
+const char* DISPLAY_RESOLUTIONW_PROPERTY = "resolutionWidth";
+const char* DISPLAY_RESOLUTIONH_PROPERTY = "resolutionHeight";
+const char* DISPLAY_INCHW_PROPERTY = "dotsPerInchWidth";
+const char* DISPLAY_INCHH_PROPERTY = "dotsPerInchHeight";
+const char* DISPLAY_PHYSICALW_PROPERTY = "physicalWidth";
+const char* DISPLAY_PHYSICALH_PROPERTY = "physicalHeight";
+const char* DISPLAY_BRIGHTNESS_PROPERTY = "brightness";
+} 
+
+JSClassRef JSDisplayInfo::m_classRef = NULL;
+
+JSClassDefinition JSDisplayInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "displayinfo",
+    0,
+    m_properties,
+    NULL,
+    Initialize,
+    Finalize,
+    hasProperty,
+    getProperty,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticValue JSDisplayInfo::m_properties[] = {
+    { DISPLAY_RESOLUTIONW_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DISPLAY_RESOLUTIONH_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DISPLAY_INCHW_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DISPLAY_INCHH_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DISPLAY_PHYSICALW_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { DISPLAY_PHYSICALH_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
+    { DISPLAY_BRIGHTNESS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSDisplayInfo::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+const JSClassDefinition* JSDisplayInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSDisplayInfo::Initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSDisplayInfo::Finalize(JSObjectRef object)
+{
+    LogDebug("Entered");
+    JSDisplayPriv* priv = static_cast<JSDisplayPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting DisplayInfo object");
+    delete priv;
+}
+
+bool JSDisplayInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    return JSUtils::hasProperty(m_properties, propertyName);
+}
+
+JSObjectRef JSDisplayInfo::createJSObject(JSContextRef context, const Api::Systeminfo::DisplayPropertiesPtr displayInfo)
+{
+    JSDisplayPriv *priv = new JSDisplayPriv(context, displayInfo);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSDisplayInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("Enter");
+    JSDisplayPriv *priv = static_cast<JSDisplayPriv*>(JSObjectGetPrivate(object));
+    if (NULL == priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    Try
+    {
+        Api::Systeminfo::DisplayPropertiesPtr displayInfo = priv->getObject();
+        Converter convert(context);
+        if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_RESOLUTIONW_PROPERTY)) {
+            return convert.toJSValueRef(displayInfo->resolutionWidth);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_RESOLUTIONH_PROPERTY)) {
+            return convert.toJSValueRef(displayInfo->resolutionHeight);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_INCHW_PROPERTY)) {
+            return convert.toJSValueRef(displayInfo->dotsPerInchWidth);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_INCHH_PROPERTY)) {
+            return convert.toJSValueRef(displayInfo->dotsPerInchHeight);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_PHYSICALW_PROPERTY)) {
+            return convert.toJSValueRef(displayInfo->physicalWidth);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_PHYSICALH_PROPERTY)) {
+            return convert.toJSValueRef(displayInfo->physicalHeight);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, DISPLAY_BRIGHTNESS_PROPERTY)) {
+            return convert.toJSValueRef(displayInfo->brightness);
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSDisplayInfo.h b/src/standards/Tizen/Systeminfo/JSDisplayInfo.h
new file mode 100755 (executable)
index 0000000..261e387
--- /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 WRTPLUGINS_TIZEN1_0_DISPLAY_INFO_H_
+#define WRTPLUGINS_TIZEN1_0_DISPLAY_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Systeminfo/SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::DisplayPropertiesPtr>::Type  JSDisplayPriv;
+
+class JSDisplayInfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::Systeminfo::DisplayPropertiesPtr displayInfo);
+
+  private:
+    static void Initialize(JSContextRef context, JSObjectRef object);
+    static void Finalize(JSObjectRef object);
+    static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSStaticValue m_properties[];
+    static JSClassRef m_classRef;
+    static JSClassDefinition m_classInfo;
+};
+
+}
+}
+#endif
diff --git a/src/standards/Tizen/Systeminfo/JSNetworkInfo.cpp b/src/standards/Tizen/Systeminfo/JSNetworkInfo.cpp
new file mode 100755 (executable)
index 0000000..0a72259
--- /dev/null
@@ -0,0 +1,121 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include "JSNetworkInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+
+namespace {
+const char* NETWORK_TYPE_PROPERTY = "networkType";
+} 
+
+JSClassRef JSNetworkInfo::m_classRef = NULL;
+
+JSClassDefinition JSNetworkInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "networkinfo",
+    0,
+    m_properties,
+    NULL,
+    Initialize,
+    Finalize,
+    hasProperty,
+    getProperty,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticValue JSNetworkInfo::m_properties[] = {
+    { NETWORK_TYPE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSNetworkInfo::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+const JSClassDefinition* JSNetworkInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSNetworkInfo::Initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSNetworkInfo::Finalize(JSObjectRef object)
+{
+    LogDebug("Entered");
+    JSNetworkPriv* priv = static_cast<JSNetworkPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting networkInfo object");
+    delete priv;
+}
+
+bool JSNetworkInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    return JSUtils::hasProperty(m_properties, propertyName);
+}
+
+JSObjectRef JSNetworkInfo::createJSObject(JSContextRef context, const Api::Systeminfo::NetworkPropertiesPtr networkInfo)
+{
+    JSNetworkPriv *priv = new JSNetworkPriv(context, networkInfo);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSNetworkInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("Enter");
+    JSNetworkPriv *priv = static_cast<JSNetworkPriv*>(JSObjectGetPrivate(object));
+    if (NULL == priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    Try
+    {
+        Api::Systeminfo::NetworkPropertiesPtr networkInfo = priv->getObject();
+        Converter convert(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, NETWORK_TYPE_PROPERTY)) {
+            return convert.toJSValueRef(networkInfo->networkType);
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSNetworkInfo.h b/src/standards/Tizen/Systeminfo/JSNetworkInfo.h
new file mode 100755 (executable)
index 0000000..5af17bd
--- /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 WRTPLUGINS_TIZEN1_0_NETWORK_INFO_H_
+#define WRTPLUGINS_TIZEN1_0_NETWORK_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Systeminfo/SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::NetworkPropertiesPtr>::Type  JSNetworkPriv;
+
+class JSNetworkInfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::Systeminfo::NetworkPropertiesPtr networkInfo);
+
+  private:
+    static void Initialize(JSContextRef context, JSObjectRef object);
+    static void Finalize(JSObjectRef object);
+    static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSStaticValue m_properties[];
+    static JSClassRef m_classRef;
+    static JSClassDefinition m_classInfo;
+};
+
+}
+}
+#endif
diff --git a/src/standards/Tizen/Systeminfo/JSSIMInfo.cpp b/src/standards/Tizen/Systeminfo/JSSIMInfo.cpp
new file mode 100755 (executable)
index 0000000..1539708
--- /dev/null
@@ -0,0 +1,146 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include "JSSIMInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+
+namespace {
+const char* SIM_OPERATORNAME_PROPERTY = "operatorName";
+const char* SIM_MSISDN_PROPERTY = "msisdn";
+const char* SIM_ICCID_PROPERTY = "iccid";
+const char* SIM_MCC_PROPERTY = "mcc";
+const char* SIM_MNC_PROPERTY = "mnc";
+const char* SIM_MSIN_PROPERTY = "msin";
+const char* SIM_SPN_PROPERTY = "spn";
+} 
+
+JSClassRef JSSIMInfo::m_classRef = NULL;
+
+JSClassDefinition JSSIMInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "siminfo",
+    0,
+    m_properties,
+    NULL,
+    Initialize,
+    Finalize,
+    hasProperty,
+    getProperty,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticValue JSSIMInfo::m_properties[] = {
+    { SIM_OPERATORNAME_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { SIM_MSISDN_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { SIM_ICCID_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
+    { SIM_MCC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
+    { SIM_MNC_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },                
+    { SIM_MSIN_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { SIM_SPN_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSSIMInfo::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+const JSClassDefinition* JSSIMInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSSIMInfo::Initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSSIMInfo::Finalize(JSObjectRef object)
+{
+    LogDebug("Entered");
+    JSSIMPriv* priv = static_cast<JSSIMPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting SIM Info object");
+    delete priv;
+}
+
+bool JSSIMInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    return JSUtils::hasProperty(m_properties, propertyName);
+}
+
+JSObjectRef JSSIMInfo::createJSObject(JSContextRef context, const Api::Systeminfo::SIMPropertiesPtr SIMInfo)
+{
+    LogDebug("Enter");
+    JSSIMPriv *priv = new JSSIMPriv(context, SIMInfo);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSSIMInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("Enter");
+    JSSIMPriv *priv = static_cast<JSSIMPriv*>(JSObjectGetPrivate(object));
+    if (NULL == priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    Try
+    {
+        Api::Systeminfo::SIMPropertiesPtr SIMInfo = priv->getObject();
+        Converter convert(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, SIM_OPERATORNAME_PROPERTY)) {
+            return convert.toJSValueRef(SIMInfo->operatorName);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MSISDN_PROPERTY)) {
+            return convert.toJSValueRef(SIMInfo->msisdn);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_ICCID_PROPERTY)) {
+            return convert.toJSValueRef(SIMInfo->iccid);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MCC_PROPERTY)) {
+            return convert.toJSValueRef(SIMInfo->mcc);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MNC_PROPERTY)) {
+            return convert.toJSValueRef(SIMInfo->mnc);            
+        } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_MSIN_PROPERTY)) {
+            return convert.toJSValueRef(SIMInfo->msin);            
+        } else if (JSStringIsEqualToUTF8CString(propertyName, SIM_SPN_PROPERTY)) {
+            return convert.toJSValueRef(SIMInfo->spn);            
+        }            
+    }
+    Catch(Exception)
+    {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSSIMInfo.h b/src/standards/Tizen/Systeminfo/JSSIMInfo.h
new file mode 100755 (executable)
index 0000000..663a7b3
--- /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 WRTPLUGINS_TIZEN1_0_SIM_INFO_H_
+#define WRTPLUGINS_TIZEN1_0_SIM_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Systeminfo/SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::SIMPropertiesPtr>::Type      JSSIMPriv;
+
+class JSSIMInfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::Systeminfo::SIMPropertiesPtr SIMInfo);
+
+  private:
+    static void Initialize(JSContextRef context, JSObjectRef object);
+    static void Finalize(JSObjectRef object);
+    static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSStaticValue m_properties[];
+    static JSClassRef m_classRef;
+    static JSClassDefinition m_classInfo;
+};
+
+}
+}
+#endif
diff --git a/src/standards/Tizen/Systeminfo/JSStorageInfo.cpp b/src/standards/Tizen/Systeminfo/JSStorageInfo.cpp
new file mode 100755 (executable)
index 0000000..daa3475
--- /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 <memory>
+#include <dpl/log/log.h>
+#include "JSStorageInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+
+namespace {
+const char* STORAGE_TYPE_PROPERTY = "type";
+const char* STORAGE_CAPACITY_PROPERTY = "capacity";
+const char* STORAGE_AVAILCAPA_PROPERTY = "availableCapacity";
+const char* STORAGE_REMOVEABLE_PROPERTY = "isRemoveable";
+} 
+
+JSClassRef JSStorageInfo::m_classRef = NULL;
+
+JSClassDefinition JSStorageInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "storageinfo",
+    0,
+    m_properties,
+    NULL,
+    Initialize,
+    Finalize,
+    hasProperty,
+    getProperty,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticValue JSStorageInfo::m_properties[] = {
+    { STORAGE_TYPE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { STORAGE_CAPACITY_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { STORAGE_AVAILCAPA_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { STORAGE_REMOVEABLE_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSStorageInfo::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+const JSClassDefinition* JSStorageInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSStorageInfo::Initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSStorageInfo::Finalize(JSObjectRef object)
+{
+    LogDebug("Entered");
+    JSStoragePriv* priv = static_cast<JSStoragePriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting StorageInfo object");
+    delete priv;
+}
+
+bool JSStorageInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    return JSUtils::hasProperty(m_properties, propertyName);
+}
+
+JSObjectRef JSStorageInfo::createJSObject(JSContextRef context, const Api::Systeminfo::StoragePropertiesPtr storageInfo)
+{
+    JSStoragePriv *priv = new JSStoragePriv(context, storageInfo);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSStorageInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("Enter");
+    JSStoragePriv *priv = static_cast<JSStoragePriv*>(JSObjectGetPrivate(object));
+    if (NULL == priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    Try
+    {
+        Api::Systeminfo::StoragePropertiesPtr storageInfo = priv->getObject();
+        Converter convert(context);
+        if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_TYPE_PROPERTY)) {
+            return convert.toJSValueRef(storageInfo->type);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_CAPACITY_PROPERTY)) {
+            return JSValueMakeNumber(context, storageInfo->capacity);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_AVAILCAPA_PROPERTY)) {
+            return JSValueMakeNumber(context, storageInfo->availableCapacity);            
+        } else if (JSStringIsEqualToUTF8CString(propertyName, STORAGE_REMOVEABLE_PROPERTY)) {
+            return convert.toJSValueRef(storageInfo->isRemoveable);
+        }
+    }
+    Catch(Exception)
+    {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSStorageInfo.h b/src/standards/Tizen/Systeminfo/JSStorageInfo.h
new file mode 100755 (executable)
index 0000000..e96f4ed
--- /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 WRTPLUGINS_TIZEN1_0_STORAGE_INFO_H_
+#define WRTPLUGINS_TIZEN1_0_STORAGE_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Systeminfo/SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::StoragePropertiesPtr>::Type  JSStoragePriv;
+
+class JSStorageInfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::Systeminfo::StoragePropertiesPtr storageInfo);
+
+  private:
+    static void Initialize(JSContextRef context, JSObjectRef object);
+    static void Finalize(JSObjectRef object);
+    static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSStaticValue m_properties[];
+    static JSClassRef m_classRef;
+    static JSClassDefinition m_classInfo;
+};
+
+}
+}
+#endif
diff --git a/src/standards/Tizen/Systeminfo/JSSysteminfo.cpp b/src/standards/Tizen/Systeminfo/JSSysteminfo.cpp
new file mode 100755 (executable)
index 0000000..f993b6f
--- /dev/null
@@ -0,0 +1,332 @@
+//
+// 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 <CommonsJavaScript/JSUtils.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/Converter.h>
+#include <API/Systeminfo/SysteminfoFactory.h>
+#include <API/Systeminfo/EventGetSysteminfo.h>
+#include <API/Systeminfo/EventWatchSysteminfo.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include <Tizen/Common/SecurityExceptions.h>
+#include "SysteminfoListener.h"
+#include "SysteminfoAsyncCallbackManager.h"
+#include "SysteminfoListenerManager.h"
+#include "JSSysteminfo.h"
+#include "plugin_config.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace std;
+using namespace DPL;
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+using namespace TizenApis::Commons;
+
+JSClassDefinition JSSysteminfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "systeminfo",
+    NULL,
+    NULL,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticFunction JSSysteminfo::m_function[] = {
+    { "getCapabilities", JSSysteminfo::getCapabilities, kJSPropertyAttributeNone },    
+    { "getPropertyValue", JSSysteminfo::getPropertyValue, kJSPropertyAttributeNone },
+    { "addPropertyValueChangeListener", JSSysteminfo::addPropertyValueChangeListener, kJSPropertyAttributeNone },
+    { "removePropertyValueChangeListener", JSSysteminfo::removePropertyValueChangeListener, kJSPropertyAttributeNone },
+    { 0, 0, 0 }
+};
+
+const JSClassRef JSSysteminfo::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSSysteminfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSSysteminfo::m_jsClassRef = JSClassCreate(JSSysteminfo::getClassInfo());
+
+void JSSysteminfo::initialize(JSContextRef context, JSObjectRef object)
+{
+    if (!JSObjectGetPrivate(object)) {
+        ISysteminfoPtr Systeminfos(SysteminfoFactory::getInstance().getSysteminfos());
+        JSSysteminfoPriv* priv = new JSSysteminfoPriv(context, Systeminfos);
+        if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+            LogError("Object can't store private data.");
+            delete priv;
+        }
+
+        LogDebug("JSSysteminfo::initialize ");
+    } else {
+        LogDebug("Private object already set.");
+    }
+}
+
+void JSSysteminfo::finalize(JSObjectRef object)
+{
+    JSSysteminfoPriv* priv = static_cast<JSSysteminfoPriv*>(JSObjectGetPrivate(object));
+    
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting gallery");
+    delete priv;
+}
+
+JSValueRef JSSysteminfo::getCapabilities(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+        size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    JSSysteminfoPriv *priv = static_cast<JSSysteminfoPriv*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(SYSTEMINFO_FUNCTION_API_GET_CAPABILITIES);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Converter converter(context);
+    Validator check(context, exception);
+
+    if (!priv) {
+        LogError("private object is null");
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+    }
+    Try
+    {
+        ISysteminfoPtr Systeminfos(priv->getObject());
+
+        DeviceCapabilitiesPropertiesPtr result(new DeviceCapabilitiesProperties());
+
+        result = Systeminfos->getCapabilities();
+
+        return (static_cast<JSValueRef>(JSDeviceCapabilitiesInfo::createJSObject(context, result)));
+    }
+    Catch(WrtDeviceApis::Commons::ConversionException) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");
+    }
+    Catch(WrtDeviceApis::Commons::InvalidArgumentException){
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");
+    }
+    Catch(WrtDeviceApis::Commons::Exception) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+    }    
+}
+
+JSValueRef JSSysteminfo::getPropertyValue(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+        size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    JSSysteminfoPriv *priv = static_cast<JSSysteminfoPriv*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(
+        SYSTEMINFO_FUNCTION_API_GET_PROPERTY_VALUE);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Converter converter(context);
+    Validator check(context, exception);
+    std::string property;
+
+    if (!priv) {
+        LogError("private object is null");
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Wrong Object");
+    }
+    if (argumentCount < 2) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+    }
+    if (!check.isCallback(arguments[1])) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+    }
+
+    JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL;
+    onSuccessForCbm = arguments[1];
+    if (argumentCount == 3) {
+        if (check.isCallback(arguments[2])) {
+            onErrorForCbm = arguments[2];
+        } else if (!JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2])) {
+            return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+        }
+    }
+    
+    JSCallbackManagerPtr cbm(JSCallbackManager::createObject(priv->getContext(), onSuccessForCbm, onErrorForCbm, true, true));
+    cbm->setObject(thisObject);        
+
+    Try {
+        ISysteminfoPtr Systeminfos(priv->getObject());
+        
+        EventGetSysteminfoPtr event(new EventGetSysteminfo());
+        event->setBasePropertyPtr(Systeminfos->getBasePropertyPtr(priv->getContext(), arguments[0]));
+        event->setPrivateData(StaticPointerCast<IEventPrivateData>(cbm));
+
+        SysteminfoListener& listener = SysteminfoListener::getInstance();
+        event->setForAsynchronousCall(&listener);
+
+        Systeminfos->get(event);
+        SysteminfoAsyncCallbackManagerSingleton::Instance().registerCallbackManager(cbm, priv->getContext());
+
+        return JSValueMakeUndefined(context);
+    }
+    
+    Catch(WrtDeviceApis::Commons::PendingOperationException) {
+        cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Unknown error"));
+    }
+    Catch(WrtDeviceApis::Commons::ConversionException) {
+        cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error"));
+    }
+    Catch(WrtDeviceApis::Commons::InvalidArgumentException){
+        cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error"));
+    }
+    Catch(WrtDeviceApis::Commons::Exception) {
+        cbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Unknown error"));
+    }
+    return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSysteminfo::addPropertyValueChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+        size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    WatchOption option;
+    JSSysteminfoPriv *priv = static_cast<JSSysteminfoPriv*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(
+        SYSTEMINFO_FUNCTION_API_ADD_PROPERTY_VALUE_CHANGE_LISTENER);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Converter converter(context);
+    Validator check(context, exception);
+
+    if (!priv) {
+        LogError("private object is null");
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Wrong Object");
+    }
+    if (argumentCount < 2) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+    }
+    if (!check.isCallback(arguments[1])) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+    }
+    
+    JSValueRef onSuccessForCbm = NULL;
+    onSuccessForCbm = arguments[1];
+
+    JSCallbackManagerPtr cbm(JSCallbackManager::createObject(priv->getContext(), onSuccessForCbm, NULL, true, true));
+
+    Try {
+        if (argumentCount > 2) {
+            if (JSValueIsObject(context, arguments[2])) {
+                option.timeout = converter.toULong(JSUtils::getJSProperty(context, arguments[2], "timeout", exception));
+                option.highThreshold = converter.toDouble(JSUtils::getJSProperty(context, arguments[2], "highThreshold", exception));
+                option.lowThreshold = converter.toDouble(JSUtils::getJSProperty(context, arguments[2], "lowThreshold", exception));
+            } else if (!JSValueIsNull(context, arguments[2]) && !JSValueIsUndefined(context, arguments[2])) {
+                return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");        
+            }
+        }
+        ISysteminfoPtr Systeminfos(priv->getObject());
+
+        EventWatchSysteminfoPtr event(new EventWatchSysteminfo);
+        event->setWatchOption(option);
+        event->setBasePropertyPtr(Systeminfos->getBasePropertyPtr(priv->getContext(), arguments[0]));
+        event->setPrivateData(StaticPointerCast<IEventPrivateData>(cbm));
+
+        SysteminfoListener& listener = SysteminfoListener::getInstance();
+        event->setForAsynchronousCall(&listener);        
+            
+        Systeminfos->watch(event);
+        LogDebug("event->getId()" << event->getId());
+
+        SysteminfoListenerCancellerPtr canceller = SysteminfoListenerCancellerPtr(new SysteminfoListenerCanceller(priv->getContext(), thisObject, event->getId()));
+        TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+        SysteminfoListenerManagerSingleton::Instance().registerListener(listenerItem, priv->getContext());             
+       
+        return converter.toJSValueRef(event->getId());
+    }
+
+    Catch(WrtDeviceApis::Commons::ConversionException) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");
+    }
+    Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");
+    }
+    Catch(WrtDeviceApis::Commons::Exception) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");
+    }
+}
+
+JSValueRef JSSysteminfo::removePropertyValueChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+        size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    long id = 0;
+    JSSysteminfoPriv *priv = static_cast<JSSysteminfoPriv*>(JSObjectGetPrivate(thisObject));
+
+    AceSecurityStatus status = SYSTEMINFO_CHECK_ACCESS(
+        SYSTEMINFO_FUNCTION_API_REMOVE_PROPERTY_VALUE_CHANGE_LISTENER);
+    TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+    Converter converter(context);
+    if (!priv) {
+        LogError("private object is null");
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Wrong Object");
+    }
+    if (argumentCount < 1) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+    }
+
+    Try {
+        ISysteminfoPtr Systeminfos(priv->getObject());
+        id = static_cast<long>(converter.toLong(arguments[0]));
+
+               LogDebug("clearWatch id = " << id );
+               Systeminfos->clearWatch(id);
+
+               SysteminfoListenerCancellerPtr canceller = SysteminfoListenerCancellerPtr(new SysteminfoListenerCanceller(priv->getContext(), thisObject, id));
+               TizenApis::Commons::IListenerItemPtr listenerItem = DPL::StaticPointerCast<TizenApis::Commons::IListenerItem>(canceller);
+               SysteminfoListenerManagerSingleton::Instance().unregisterListener(listenerItem);
+               
+               return JSValueMakeUndefined(context);
+       }
+    Catch(WrtDeviceApis::Commons::ConversionException) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type missmatch error");
+    }    
+    Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid values error");
+    }
+    Catch(WrtDeviceApis::Commons::Exception) {
+        return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error");        
+    }
+}
+
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSSysteminfo.h b/src/standards/Tizen/Systeminfo/JSSysteminfo.h
new file mode 100755 (executable)
index 0000000..d2eb8ab
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// 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_TIZEN1_0_JS_SYSTEMINFO_H_
+#define WRTPLUGINS_TIZEN1_0_JS_SYSTEMINFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Systeminfo/ISysteminfo.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::ISysteminfoPtr>::Type        JSSysteminfoPriv;
+
+class JSSysteminfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+
+  private:
+    static void initialize(JSContextRef context, JSObjectRef object);
+    static void finalize(JSObjectRef object);
+
+    static JSValueRef getCapabilities(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+    static JSValueRef getPropertyValue(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+    static JSValueRef addPropertyValueChangeListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject,
+            size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+    static JSValueRef removePropertyValueChangeListener(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;
+};
+
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Systeminfo/JSWifiNetworkInfo.cpp b/src/standards/Tizen/Systeminfo/JSWifiNetworkInfo.cpp
new file mode 100755 (executable)
index 0000000..45c5628
--- /dev/null
@@ -0,0 +1,138 @@
+//
+// 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 <memory>
+#include <dpl/log/log.h>
+#include "JSWifiNetworkInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+using namespace WrtDeviceApis::CommonsJavaScript;
+using namespace WrtDeviceApis::Commons;
+using namespace Api::Systeminfo;
+
+namespace {
+const char* WIFINETWORK_STATUS_PROPERTY = "status";
+const char* WIFINETWORK_SSID_PROPERTY = "ssid";
+const char* WIFINETWORK_IPADDRESS_PROPERTY = "ipAddress";
+const char* WIFINETWORK_IPV6ADDRESS_PROPERTY = "ipv6Address";
+const char* WIFINETWORK_SIGNALSTRENGTH_PROPERTY = "signalStrength";
+} 
+
+JSClassRef JSWifiNetworkInfo::m_classRef = NULL;
+
+JSClassDefinition JSWifiNetworkInfo::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "wifinetworkinfo",
+    0,
+    m_properties,
+    NULL,
+    Initialize,
+    Finalize,
+    hasProperty,
+    getProperty,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+JSStaticValue JSWifiNetworkInfo::m_properties[] = {
+    { WIFINETWORK_STATUS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { WIFINETWORK_SSID_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { WIFINETWORK_IPADDRESS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
+    { WIFINETWORK_IPV6ADDRESS_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { WIFINETWORK_SIGNALSTRENGTH_PROPERTY, getProperty, NULL, kJSPropertyAttributeReadOnly },        
+    { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSWifiNetworkInfo::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+const JSClassDefinition* JSWifiNetworkInfo::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+void JSWifiNetworkInfo::Initialize(JSContextRef context, JSObjectRef object)
+{
+}
+
+void JSWifiNetworkInfo::Finalize(JSObjectRef object)
+{
+    LogDebug("Entered");
+    JSWifiNetworkPriv* priv = static_cast<JSWifiNetworkPriv*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    LogDebug("Deleting WifiNetworkInfo object");
+    delete priv;
+}
+
+bool JSWifiNetworkInfo::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+    return JSUtils::hasProperty(m_properties, propertyName);
+}
+
+JSObjectRef JSWifiNetworkInfo::createJSObject(JSContextRef context, const Api::Systeminfo::WifiNetworkPropertiesPtr wifiNetworkInfo)
+{
+    LogDebug("Enter");
+    JSWifiNetworkPriv *priv = new JSWifiNetworkPriv(context, wifiNetworkInfo);
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSValueRef JSWifiNetworkInfo::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("Enter");
+    JSWifiNetworkPriv *priv = static_cast<JSWifiNetworkPriv*>(JSObjectGetPrivate(object));
+    if (NULL == priv) {
+        LogError("Private object not set.");
+        return JSValueMakeUndefined(context);
+    }
+
+    Try
+    {
+        Api::Systeminfo::WifiNetworkPropertiesPtr wifiNetworkInfo = priv->getObject();
+        Converter convert(context);
+
+        if (JSStringIsEqualToUTF8CString(propertyName, WIFINETWORK_STATUS_PROPERTY)) {
+            return convert.toJSValueRef(wifiNetworkInfo->status);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, WIFINETWORK_SSID_PROPERTY)) {
+            return convert.toJSValueRef(wifiNetworkInfo->ssid);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, WIFINETWORK_IPADDRESS_PROPERTY)) {
+            return convert.toJSValueRef(wifiNetworkInfo->ipAddress);
+        } else if (JSStringIsEqualToUTF8CString(propertyName, WIFINETWORK_IPV6ADDRESS_PROPERTY)) {
+            return convert.toJSValueRef(wifiNetworkInfo->ipv6Address);                 
+        } else if (JSStringIsEqualToUTF8CString(propertyName, WIFINETWORK_SIGNALSTRENGTH_PROPERTY)) {
+            return convert.toJSValueRef(wifiNetworkInfo->signalStrength);
+        }            
+    }
+    Catch(Exception)
+    {
+        LogError("Exception: " << _rethrown_exception.GetMessage());
+    }
+    return JSValueMakeUndefined(context);
+}
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/JSWifiNetworkInfo.h b/src/standards/Tizen/Systeminfo/JSWifiNetworkInfo.h
new file mode 100755 (executable)
index 0000000..5580505
--- /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 WRTPLUGINS_TIZEN1_0_WIFINETWORK_INFO_H_
+#define WRTPLUGINS_TIZEN1_0_WIFINETWORK_INFO_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include "API/Systeminfo/SysteminfoPropertyInfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<Api::Systeminfo::WifiNetworkPropertiesPtr>::Type      JSWifiNetworkPriv;
+
+class JSWifiNetworkInfo
+{
+  public:
+    static const JSClassDefinition* getClassInfo();
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::Systeminfo::WifiNetworkPropertiesPtr wifiNetworkInfo);
+
+  private:
+    static void Initialize(JSContextRef context, JSObjectRef object);
+    static void Finalize(JSObjectRef object);
+    static bool hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName);
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+    static JSStaticValue m_properties[];
+    static JSClassRef m_classRef;
+    static JSClassDefinition m_classInfo;
+};
+
+}
+}
+#endif
diff --git a/src/standards/Tizen/Systeminfo/SysteminfoAsyncCallbackManager.cpp b/src/standards/Tizen/Systeminfo/SysteminfoAsyncCallbackManager.cpp
new file mode 100755 (executable)
index 0000000..c4e4495
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// 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 "SysteminfoAsyncCallbackManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::SysteminfoAsyncCallbackManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/SysteminfoAsyncCallbackManager.h b/src/standards/Tizen/Systeminfo/SysteminfoAsyncCallbackManager.h
new file mode 100755 (executable)
index 0000000..354b832
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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_SYSTEMINFO_ASYNC_CALLBACK_MANAGER_H_
+#define _TIZEN_SYSTEMINFO_ASYNC_CALLBACK_MANAGER_H_
+
+#include <dpl/singleton.h>
+#include <Tizen/Common/AsyncCallbackManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+       
+class SysteminfoAsyncCallbackManager : public TizenApis::Commons::AsyncCallbackManager
+{
+public:
+       SysteminfoAsyncCallbackManager()
+       {
+       }
+
+       virtual ~SysteminfoAsyncCallbackManager()
+       {
+       }
+
+       friend class DPL::Singleton<SysteminfoAsyncCallbackManager>;
+};
+
+typedef DPL::Singleton<SysteminfoAsyncCallbackManager> SysteminfoAsyncCallbackManagerSingleton;
+
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Systeminfo/SysteminfoListener.cpp b/src/standards/Tizen/Systeminfo/SysteminfoListener.cpp
new file mode 100755 (executable)
index 0000000..e73dcf1
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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/JSCallbackManager.h>
+#include "SysteminfoListener.h"
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include "SysteminfoAsyncCallbackManager.h"
+
+using namespace std;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+SysteminfoListener& SysteminfoListener::getInstance()
+{
+    static SysteminfoListener instance;
+    return instance;
+}
+
+SysteminfoListener::SysteminfoListener() : 
+    EventGetSysteminfoAnswerReceiver(WrtDeviceApis::Commons::ThreadEnum::NULL_THREAD), 
+    EventWatchSysteminfoAnswerReceiver(WrtDeviceApis::Commons::ThreadEnum::NULL_THREAD)
+{
+}
+
+SysteminfoListener::~SysteminfoListener()
+{
+}
+
+void SysteminfoListener::OnAnswerReceived(const TizenApis::Api::Systeminfo::EventGetSysteminfoPtr& event)
+{
+    LogDebug("Enter");
+    WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast<WrtDeviceApis::CommonsJavaScript::JSCallbackManager >(event->getPrivateData());
+    LogDebug("thread=" << DPL::Thread::GetCurrentThread());
+
+    SysteminfoAsyncCallbackManagerSingleton::Instance().unregisterCallbackManager(callbackManager); 
+
+    if (!event->checkCancelled()) {
+        JSValueRef tmpValue = event->getValue();
+        if ((WrtDeviceApis::Commons::ExceptionCodes::None == event->getExceptionCode()) && (NULL != tmpValue)) {
+            callbackManager->callOnSuccess(tmpValue);
+        }
+    }
+}    
+
+void SysteminfoListener::OnAnswerReceived(const TizenApis::Api::Systeminfo::EventWatchSysteminfoPtr& event)
+{
+}
+
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/SysteminfoListener.h b/src/standards/Tizen/Systeminfo/SysteminfoListener.h
new file mode 100755 (executable)
index 0000000..22800fa
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// 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_API_SYSTEMINFO_LISTENER_H_
+#define WRTPLUGINS_API_SYSTEMINFO_LISTENER_H_
+
+#include <CommonsJavaScript/JSPendingOperation.h>
+#include <API/Systeminfo/ISysteminfo.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Systeminfo::EventGetSysteminfo> EventGetSysteminfoAnswerReceiver;
+typedef WrtDeviceApis::Commons::EventAnswerReceiver<TizenApis::Api::Systeminfo::EventWatchSysteminfo> EventWatchSysteminfoAnswerReceiver;
+
+class SysteminfoListener : public EventGetSysteminfoAnswerReceiver, public EventWatchSysteminfoAnswerReceiver
+{
+  private:
+    explicit SysteminfoListener();
+
+  public:
+    static SysteminfoListener& getInstance();
+
+    virtual ~SysteminfoListener();
+
+  protected:
+    virtual void OnAnswerReceived(const TizenApis::Api::Systeminfo::EventGetSysteminfoPtr& event);
+
+    virtual void OnAnswerReceived(const TizenApis::Api::Systeminfo::EventWatchSysteminfoPtr& event);
+};
+
+typedef DPL::SharedPtr<SysteminfoListener> SysteminfoListenerPtr;
+
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Systeminfo/SysteminfoListenerManager.cpp b/src/standards/Tizen/Systeminfo/SysteminfoListenerManager.cpp
new file mode 100755 (executable)
index 0000000..421ee0c
--- /dev/null
@@ -0,0 +1,29 @@
+//
+// 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 "SysteminfoListenerManager.h"
+#include <dpl/singleton_impl.h>
+
+using namespace DPL;
+
+IMPLEMENT_SINGLETON(TizenApis::Tizen1_0::SysteminfoListenerManager)
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+}
+}
diff --git a/src/standards/Tizen/Systeminfo/SysteminfoListenerManager.h b/src/standards/Tizen/Systeminfo/SysteminfoListenerManager.h
new file mode 100755 (executable)
index 0000000..4d9ef68
--- /dev/null
@@ -0,0 +1,81 @@
+//
+// 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_SYSTEMINFO_LISTENER_MANAGER_H_
+#define _TIZEN_SYSTEMINFO_LISTENER_MANAGER_H_
+
+#include <map>
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <dpl/singleton.h>
+#include <Tizen/Common/IListenerManager.h>
+#include "JSSysteminfo.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+       
+using namespace TizenApis::Api::Systeminfo;
+
+class SysteminfoListenerManager : public TizenApis::Commons::IListenerController
+{
+public:
+       SysteminfoListenerManager()
+       {
+       }
+
+       virtual ~SysteminfoListenerManager()
+       {
+       }
+};
+typedef DPL::Singleton<SysteminfoListenerManager> SysteminfoListenerManagerSingleton;
+
+class SysteminfoListenerCanceller : public TizenApis::Commons::IListenerItem
+{
+public:
+       SysteminfoListenerCanceller(JSContextRef context, JSObjectRef object, long watchId) :
+               TizenApis::Commons::IListenerItem(context, object, watchId)
+       {
+       }
+
+       virtual ~SysteminfoListenerCanceller()
+       {
+       }
+
+       virtual void cancelListener()
+       {
+               JSSysteminfoPriv *priv = static_cast<JSSysteminfoPriv*>(JSObjectGetPrivate(m_object));  
+
+               if (!priv) {
+                       LogWarning("Object has no private object");
+                       return;
+               }
+
+               try {
+                       ISysteminfoPtr Systeminfos(priv->getObject());
+                       Systeminfos->clearWatch(m_watchId);
+               } Catch(WrtDeviceApis::Commons::Exception) {
+                       LogError("Error on platform : " << _rethrown_exception.GetMessage());
+               }
+       }
+};
+typedef DPL::SharedPtr<SysteminfoListenerCanceller> SysteminfoListenerCancellerPtr;
+
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Systeminfo/config.xml b/src/standards/Tizen/Systeminfo/config.xml
new file mode 100755 (executable)
index 0000000..2fbcaba
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+       <library-name>libwrt-plugins-tizen-2.0-systeminfo.so</library-name>
+       <feature-install-uri>systeminfo.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/systeminfo</name>
+        <device-capability>systeminfo</device-capability>
+    </api-feature>
+</plugin-properties>
+
diff --git a/src/standards/Tizen/Systeminfo/plugin_config.cpp b/src/standards/Tizen/Systeminfo/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..ce7464f
--- /dev/null
@@ -0,0 +1,109 @@
+//
+// 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 <map>
+#include <utility>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+#include "plugin_config.h"
+
+#define SYSTEMINFO_FEATURE_API "http://tizen.org/privilege/systeminfo"
+
+#define SYSTEMINFO_DEVICE_CAP "systeminfo"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+const char* SYSTEMINFO_FUNCTION_API_GET_CAPABILITIES = "getCapabilities";
+const char* SYSTEMINFO_FUNCTION_API_GET_PROPERTY_VALUE = "getPropertyValue";
+const char* SYSTEMINFO_FUNCTION_API_ADD_PROPERTY_VALUE_CHANGE_LISTENER = "addPropertyValueChangeListener";
+const char* SYSTEMINFO_FUNCTION_API_REMOVE_PROPERTY_VALUE_CHANGE_LISTENER = "removePropertyValueChangeListener";
+
+static WrtDeviceApis::Commons::FunctionMapping createSysteminfoFunctions();
+
+static WrtDeviceApis::Commons::FunctionMapping SysteminfoFunctions =
+    createSysteminfoFunctions();
+
+DEFINE_FUNCTION_GETTER(Systeminfo, SysteminfoFunctions);
+
+static WrtDeviceApis::Commons::FunctionMapping createSysteminfoFunctions()
+{
+    using namespace WrtDeviceApis::Commons;
+
+    ACE_CREATE_DEVICE_CAP(DEVICE_CAP_SYSTEMINFO, SYSTEMINFO_DEVICE_CAP);
+    ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+    ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_SYSTEMINFO);
+
+    ACE_ADD_DEVICE_CAP(DEVICE_LIST_SYSTEMINFO, DEVICE_CAP_SYSTEMINFO);
+
+    ACE_CREATE_FEATURE(FEATURE_SYSTEMINFO, SYSTEMINFO_FEATURE_API);
+    ACE_CREATE_FEATURE_LIST(SYSTEMINFO_FEATURES);
+
+    ACE_ADD_API_FEATURE(SYSTEMINFO_FEATURES, FEATURE_SYSTEMINFO);
+
+    FunctionMapping SysteminfoFunctions;
+
+    AceFunction isSupportedFunc = ACE_CREATE_FUNCTION(
+        FUNCTION_GET_CAPABILITIES,
+        SYSTEMINFO_FUNCTION_API_GET_CAPABILITIES,
+        SYSTEMINFO_FEATURES,
+        DEVICE_LIST_SYSTEMINFO);
+
+    SysteminfoFunctions.insert(std::make_pair(
+        SYSTEMINFO_FUNCTION_API_GET_CAPABILITIES,
+        isSupportedFunc));
+
+
+    AceFunction getPropertyValueFunc = ACE_CREATE_FUNCTION(
+        FUNCTION_GET_PROPERTY_VALUE,
+        SYSTEMINFO_FUNCTION_API_GET_PROPERTY_VALUE,
+        SYSTEMINFO_FEATURES,
+        DEVICE_LIST_SYSTEMINFO);
+
+    SysteminfoFunctions.insert(std::make_pair(
+        SYSTEMINFO_FUNCTION_API_GET_PROPERTY_VALUE,
+        getPropertyValueFunc));
+
+
+    AceFunction addPropertyValueChangedListenerFunc = ACE_CREATE_FUNCTION(
+        FUNCTION_ADD_PROPERTY_VALUE_CHANGED_LISTENER,
+        SYSTEMINFO_FUNCTION_API_ADD_PROPERTY_VALUE_CHANGE_LISTENER,
+        SYSTEMINFO_FEATURES,
+        DEVICE_LIST_SYSTEMINFO);
+
+    SysteminfoFunctions.insert(std::make_pair(
+        SYSTEMINFO_FUNCTION_API_ADD_PROPERTY_VALUE_CHANGE_LISTENER,
+        addPropertyValueChangedListenerFunc));
+
+
+    AceFunction removePropertyChangedListenerFunc = ACE_CREATE_FUNCTION(
+        FUNCTION_REMOVE_PROPERTY_CHANGED_LISTENER,
+        SYSTEMINFO_FUNCTION_API_REMOVE_PROPERTY_VALUE_CHANGE_LISTENER,
+        SYSTEMINFO_FEATURES,
+        DEVICE_LIST_SYSTEMINFO);
+
+    SysteminfoFunctions.insert(std::make_pair(
+        SYSTEMINFO_FUNCTION_API_REMOVE_PROPERTY_VALUE_CHANGE_LISTENER,
+        removePropertyChangedListenerFunc));
+
+    return SysteminfoFunctions;
+}
+}
+}
+
+#undef SYSTEMINFO_FEATURE_API
diff --git a/src/standards/Tizen/Systeminfo/plugin_config.h b/src/standards/Tizen/Systeminfo/plugin_config.h
new file mode 100755 (executable)
index 0000000..50c9f4e
--- /dev/null
@@ -0,0 +1,40 @@
+//
+// 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 _SYSTEMINFO_PLUGIN_CONFIG_H_
+#define _SYSTEMINFO_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+extern const char* SYSTEMINFO_FUNCTION_API_GET_CAPABILITIES;
+extern const char* SYSTEMINFO_FUNCTION_API_GET_PROPERTY_VALUE;
+extern const char* SYSTEMINFO_FUNCTION_API_ADD_PROPERTY_VALUE_CHANGE_LISTENER;
+extern const char* SYSTEMINFO_FUNCTION_API_REMOVE_PROPERTY_VALUE_CHANGE_LISTENER;
+
+DECLARE_FUNCTION_GETTER(Systeminfo);
+
+#define SYSTEMINFO_CHECK_ACCESS(functionName)               \
+    aceCheckAccess<AceFunctionGetter, DefaultArgsVerifier<> >(             \
+                                            getSysteminfoFunctionData,     \
+                                            functionName)
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Systeminfo/plugin_initializer.cpp b/src/standards/Tizen/Systeminfo/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..1297c69
--- /dev/null
@@ -0,0 +1,78 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+
+#include "SysteminfoAsyncCallbackManager.h"
+#include "SysteminfoListenerManager.h"
+#include "JSSysteminfo.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+#define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[Tizen\\Systeminfo ] on_widget_start_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess initialization failed");
+    }    
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[Tizen\\Systeminfo ] on_widget_stop_callback (" << widgetId << ")");
+    Try
+    {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+void on_frame_load_callback(const void * context)
+{
+    LogDebug("[Tizen\\systeminfo] on_frame_load_callback (" << context << ")");
+}
+
+void on_frame_unload_callback(const void * context)
+{
+    LogDebug("[Tizen\\systeminfo] on_frame_unload_callback (" << context << ")");
+
+    TizenApis::Tizen1_0::SysteminfoAsyncCallbackManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+    TizenApis::Tizen1_0::SysteminfoListenerManagerSingleton::Instance().unregisterContext(static_cast<JSContextRef>(context));
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+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, "systeminfo", (js_class_template_getter)TizenApis::Tizen1_0::JSSysteminfo::getClassRef, NULL)
+PLUGIN_CLASS_MAP_END
+
diff --git a/src/standards/Tizen/TimeUtil/CMakeLists.txt b/src/standards/Tizen/TimeUtil/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..ffa17a8
--- /dev/null
@@ -0,0 +1,38 @@
+set(TARGET_NAME "wrt-plugins-tizen-2.0-time")
+set(DESTINATION_NAME  "tizen-2.0-time")
+set(TARGET_IMPL_NAME "wrt-plugins-tizen-2.0-time-impl")
+
+include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_TIMEUTIL})
+
+set(CMAKE_INSTALL_RPATH
+  ${CMAKE_INSTALL_RPATH}
+  ${CMAKE_INSTALL_PREFIX}/${DESTINATION_NAME}
+)
+
+set(SRCS_IMPL
+  ${SRCS_PLATFORM_API_TIMEUTIL}
+  ${SRCS_PLATFORM_IMPLEMENTATION_TIMEUTIL}
+  JSTimeUtil.cpp
+  JSTZDate.cpp
+  JSTimeDuration.cpp
+  TimeUtilConverter.cpp
+)
+
+add_library(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
+
+target_link_libraries(${TARGET_IMPL_NAME}
+  ${LIBS_COMMON}
+  ${LIBS_PLATFORM_IMPLEMENTATION_TIMEUTIL}
+)
+
+set(SRCS
+  plugin_initializer.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+target_link_libraries(${TARGET_NAME}
+  ${TARGET_IMPL_NAME}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
diff --git a/src/standards/Tizen/TimeUtil/JSTZDate.cpp b/src/standards/Tizen/TimeUtil/JSTZDate.cpp
new file mode 100755 (executable)
index 0000000..173844c
--- /dev/null
@@ -0,0 +1,1470 @@
+//
+// 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 <ctime>
+#include <string>
+#include <dpl/log/log.h>
+
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Commons/Exception.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+
+#include <API/TimeUtil/DurationProperties.h>
+#include <API/TimeUtil/TimeUtilFactory.h>
+
+#include "JSTZDate.h"
+#include "TimeUtilConverter.h"
+
+using namespace TizenApis::Api::TimeUtil;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+#define min(a,b) (((a) < (b)) ? (a) : (b))
+
+#define TIZEN10_TZDATE_ATTRIBUTENAME   "TZDate"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+JSClassDefinition JSTZDate::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    TIZEN10_TZDATE_ATTRIBUTENAME,
+    0,
+    NULL,//property,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    constructor, //CallAsConstructor,
+    hasInstance, //HasInstance,
+    NULL  //ConvertToType
+};
+
+JSStaticFunction JSTZDate::m_function[] = {
+    {"getDate",           JSTZDate::getDate,            kJSPropertyAttributeNone},
+    {"getDay",            JSTZDate::getDay,             kJSPropertyAttributeNone},
+    {"getFullYear",       JSTZDate::getFullYear,        kJSPropertyAttributeNone},
+    {"getHours",          JSTZDate::getHours,           kJSPropertyAttributeNone},
+    {"getMilliseconds",   JSTZDate::getMilliseconds,    kJSPropertyAttributeNone},
+    {"getMinutes",        JSTZDate::getMinutes,         kJSPropertyAttributeNone},
+    {"getMonth",          JSTZDate::getMonth,           kJSPropertyAttributeNone},
+    {"getSeconds",        JSTZDate::getSeconds,         kJSPropertyAttributeNone},
+
+    {"setDate",           JSTZDate::setDate,           kJSPropertyAttributeNone},
+    {"setFullYear",       JSTZDate::setFullYear,       kJSPropertyAttributeNone},
+    {"setHours",          JSTZDate::setHours,          kJSPropertyAttributeNone},
+    {"setMilliseconds",   JSTZDate::setMilliseconds,   kJSPropertyAttributeNone},
+    {"setMinutes",        JSTZDate::setMinutes,        kJSPropertyAttributeNone},
+    {"setMonth",          JSTZDate::setMonth,          kJSPropertyAttributeNone},
+    {"setSeconds",        JSTZDate::setSeconds,        kJSPropertyAttributeNone},
+
+    {"getUTCDate", JSTZDate::getUTCDate, kJSPropertyAttributeNone},
+    {"getUTCDay", JSTZDate::getUTCDay, kJSPropertyAttributeNone},
+    {"getUTCFullYear", JSTZDate::getUTCFullYear, kJSPropertyAttributeNone},
+    {"getUTCHours", JSTZDate::getUTCHours, kJSPropertyAttributeNone},
+    {"getUTCMilliseconds", JSTZDate::getUTCMilliseconds, kJSPropertyAttributeNone},
+    {"getUTCMinutes", JSTZDate::getUTCMinutes, kJSPropertyAttributeNone},
+    {"getUTCMonth", JSTZDate::getUTCMonth, kJSPropertyAttributeNone},
+    {"getUTCSeconds", JSTZDate::getUTCSeconds, kJSPropertyAttributeNone},
+
+    {"setUTCDate", JSTZDate::setUTCDate, kJSPropertyAttributeNone},
+    {"setUTCFullYear", JSTZDate::setUTCFullYear, kJSPropertyAttributeNone},
+    {"setUTCHours", JSTZDate::setUTCHours, kJSPropertyAttributeNone},
+    {"setUTCMilliseconds", JSTZDate::setUTCMilliseconds, kJSPropertyAttributeNone},
+    {"setUTCMinutes", JSTZDate::setUTCMinutes, kJSPropertyAttributeNone},
+    {"setUTCMonth", JSTZDate::setUTCMonth, kJSPropertyAttributeNone},
+    {"setUTCSeconds", JSTZDate::setUTCSeconds, kJSPropertyAttributeNone},
+
+    {"getTimezone",          JSTZDate::getTimezone,          kJSPropertyAttributeNone},
+    {"toTimezone",        JSTZDate::toTimezone,        kJSPropertyAttributeNone},
+    {"toLocalTimezone", JSTZDate::toLocalTimezone, kJSPropertyAttributeNone},
+    {"toUTC",           JSTZDate::toUTC,           kJSPropertyAttributeNone},
+
+    {"difference",         JSTZDate::difference,         kJSPropertyAttributeNone},
+    {"equalsTo",        JSTZDate::equalsTo,        kJSPropertyAttributeNone},
+    {"earlierThan",     JSTZDate::earlierThan,     kJSPropertyAttributeNone},
+    {"laterThan",       JSTZDate::laterThan,       kJSPropertyAttributeNone},
+    {"addDuration",     JSTZDate::addDuration,     kJSPropertyAttributeNone},
+
+    {"toLocaleDateString", JSTZDate::toLocaleDateString, kJSPropertyAttributeNone},
+    {"toLocaleTimeString", JSTZDate::toLocaleTimeString, kJSPropertyAttributeNone},
+    {"toLocaleString", JSTZDate::toLocaleString, kJSPropertyAttributeNone},
+    {"toDateString", JSTZDate::toDateString, kJSPropertyAttributeNone},
+    {"toTimeString", JSTZDate::toTimeString, kJSPropertyAttributeNone},
+    {"toString", JSTZDate::toString, kJSPropertyAttributeNone},
+
+    {"getTimezoneAbbreviation", JSTZDate::getTimezoneAbbreviation, kJSPropertyAttributeNone},
+    {"secondsFromUTC", JSTZDate::secondsFromUTC, kJSPropertyAttributeNone},
+    {"isDST", JSTZDate::isDST, kJSPropertyAttributeNone},
+    {"getPreviousDSTTransition", JSTZDate::getPreviousDSTTransition, kJSPropertyAttributeNone},
+    {"getNextDSTTransition", JSTZDate::getNextDSTTransition, kJSPropertyAttributeNone},
+    { 0, 0, 0}
+};
+
+JSClassRef JSTZDate::m_jsClassRef = JSClassCreate(JSTZDate::getClassInfo());
+
+JSObjectRef JSTZDate::createJSObject(JSContextRef context) {
+       LogDebug("entered");
+       ITZDatePtr tzDate = TimeUtilFactory::getInstance().createTZDateObject();
+       TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new an object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSObjectRef JSTZDate::createJSObject(JSContextRef context, const std::string &timezone) {
+       LogDebug("entered");
+       if (timezone == "")
+               return createJSObject(context);
+
+       ITZDatePtr tzDate = TimeUtilFactory::getInstance().createTZDateObject(timezone);
+       TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new an object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSObjectRef JSTZDate::createJSObject(JSContextRef context, const double milliseconds, const std::string &timezone) {
+       LogDebug("entered");
+       ITZDatePtr tzDate;
+       if (timezone == "")
+               tzDate = TimeUtilFactory::getInstance().createTZDateObject();
+       else
+               tzDate = TimeUtilFactory::getInstance().createTZDateObject(timezone);
+
+       if (!tzDate->setTime(milliseconds))
+               ThrowMsg(UnknownException, "Can not set UTC Time");
+
+       TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new an object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSObjectRef JSTZDate::createJSObject(JSContextRef context, const TZDateProperties &properties) {
+       LogDebug("entered");
+       ITZDatePtr tzDate = TimeUtilFactory::getInstance().createTZDateObject(properties);
+
+       TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
+       if (!priv) {
+               ThrowMsg(NullPointerException, "Can not new an object");
+       }
+
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSObjectRef JSTZDate::createJSObject(JSContextRef context, const long year, const long month,  const long day, const long hours, const long minutes, const long seconds, const long milliseconds, const std::string &timezone) {
+       LogDebug("entered");
+
+       TZDateProperties props;
+       props.year = year;
+       props.month = month;
+       props.day = day;
+       props.hours = hours;
+       props.minutes = minutes;
+       props.seconds = seconds;
+       props.milliseconds = milliseconds;
+       props.timezone = timezone;
+
+       return createJSObject(context, props);
+
+}
+
+void JSTZDate::initialize(JSContextRef context, JSObjectRef object)
+{
+       LogDebug("entered Nothing to do.");
+
+       if (!JSObjectGetPrivate(object)) {
+               LogDebug("Private object not set... setting it.");
+               ITZDatePtr tzDate = TimeUtilFactory::getInstance().createTZDateObject(FALSE);
+               TZDatePrivObject *priv = new TZDatePrivObject(context, tzDate);
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSTZDate::finalize(JSObjectRef object)
+{
+    LogDebug( "entered" );
+    TZDatePrivObject *priv =
+        static_cast<TZDatePrivObject*>( JSObjectGetPrivate( object ) ) ;
+    delete priv;
+}
+
+JSObjectRef JSTZDate::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+       LogDebug("entered");
+       TZDateProperties prop;
+       TimeUtilConverter converter(ctx);
+
+       Try {
+               if (argumentCount == 0) {
+                       return createJSObject(ctx);
+               } else if (argumentCount <= 2) {
+                       std::string timezone = "";
+                       if ((argumentCount == 2) && !JSValueIsNull(ctx, arguments[1]) && !JSValueIsUndefined(ctx, arguments[1])) {
+                               timezone = converter.toString(arguments[1]);
+                       }
+
+                       if (JSValueIsNull(ctx, arguments[0]) || JSValueIsUndefined(ctx, arguments[0]))
+                               return createJSObject(ctx, timezone);
+
+                       struct tm date = converter.toDateTm(arguments[0]);
+                       LogDebug("date = " << date.tm_year << "." << date.tm_mon << "." << date.tm_mday);
+                       LogDebug(date.tm_hour << ":" << date.tm_min << ":" << date.tm_sec);
+                       LogDebug("isdst?" << date.tm_isdst);
+
+                       prop.timezone = timezone;
+                       prop.year = date.tm_year + 1900;
+                       prop.month = date.tm_mon;
+                       prop.day = date.tm_mday;
+                       prop.hours = date.tm_hour;
+                       prop.minutes = date.tm_min;
+                       prop.seconds = date.tm_sec;
+
+                      JSStringRef getMillisecondsName = JSStringCreateWithUTF8CString("getMilliseconds");
+                       JSValueRef getMiliSecFuction = JSObjectGetProperty(ctx, converter.toJSObjectRef(arguments[0]), getMillisecondsName, exception);
+                       JSStringRelease(getMillisecondsName);
+                       if (getMiliSecFuction) {
+                               JSObjectRef function = JSValueToObject(ctx, getMiliSecFuction, exception);
+                               JSValueRef result = JSObjectCallAsFunction(ctx, function, converter.toJSObjectRef(arguments[0]), 0, NULL, exception);
+                               prop.milliseconds = converter.toLong(result);
+                               LogDebug("getMilliseconds = " << prop.milliseconds);
+                       }
+                       return createJSObject(ctx, prop);
+               } else {
+                       prop.year = converter.toLong(arguments[0]);
+                       if ((prop.year >= 0) && (prop.year <= 99))
+                               prop.year += 1900;
+                       prop.month = converter.toLong(arguments[1]);
+                       prop.day = converter.toLong(arguments[2]);
+                       if (argumentCount > 3) {
+                               if (!JSValueIsUndefined(ctx, arguments[3]) && !JSValueIsNull(ctx, arguments[3]))
+                                       prop.hours = converter.toLong(arguments[3]);
+                               if (argumentCount > 4) {
+                                       if (!JSValueIsUndefined(ctx, arguments[4]) && !JSValueIsNull(ctx, arguments[4]))
+                                               prop.minutes = converter.toLong(arguments[4]);
+                                       if (argumentCount > 5) {
+                                               if (!JSValueIsUndefined(ctx, arguments[5]) && !JSValueIsNull(ctx, arguments[5]))
+                                                       prop.seconds = converter.toLong(arguments[5]);
+                                               if (argumentCount > 6) {
+                                                       if (!JSValueIsUndefined(ctx, arguments[6]) && !JSValueIsNull(ctx, arguments[6]))
+                                                               prop.milliseconds= converter.toLong(arguments[6]);
+                                                       if (argumentCount > 7) {
+                                                               if (!JSValueIsUndefined(ctx, arguments[7]) && !JSValueIsNull(ctx, arguments[7]))
+                                                                       prop.timezone = converter.toString(arguments[7]);
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+                       return createJSObject(ctx, prop);
+               }
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return NULL;
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               return NULL;
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       return NULL;
+}
+const JSClassRef JSTZDate::getClassRef()
+{
+    if (!m_jsClassRef) {
+            m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSTZDate::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+bool JSTZDate::hasInstance(JSContextRef context,
+        JSObjectRef constructor,
+        JSValueRef possibleInstance,
+        JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSTZDate::getTimezone(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("entered");
+
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               std::string timezone = tzDate->getTimezone();
+               TimeUtilConverter converter(context);
+
+               return converter.toJSValueRef(timezone);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+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]);
+
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               return createJSObject(context, tzDate->toTimezone(timezone));
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+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");
+       }
+
+       TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               LogError("Private object is not set.");
+               ThrowMsg(NullPointerException, "Private object not initialized");
+       }
+       TimeUtilConverter converter(context);
+       ITZDatePtr tzDate(privateObject->getObject());
+       long long cmpResult = tzDate->difference(converter.getPropertiesInTZDate(arguments[0]));
+
+       switch (type) {
+               case EQUALSTO:
+               {
+                       if (cmpResult == 0)
+                               return converter.toJSValueRef(true);
+                       else
+                               return converter.toJSValueRef(false);
+               }
+               case EARLIERTHAN:
+               {
+                       if (cmpResult < 0)
+                               return converter.toJSValueRef(true);
+                       else
+                               return converter.toJSValueRef(false);
+               }
+               case LATERTHAN:
+               {
+                       if (cmpResult > 0)
+                               return converter.toJSValueRef(true);
+                       else
+                               return converter.toJSValueRef(false);
+               }
+               case DIFFERENCE:
+               default:
+                       return converter.makeMillisecondDurationObject(cmpResult);
+       }
+}
+
+JSValueRef JSTZDate::difference(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("entered");
+
+       Try {
+               return diffTZDate(context, thisObject, argumentCount,  arguments, exception, DIFFERENCE);
+       } 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) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::equalsTo(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("entered");
+
+       Try {
+               return diffTZDate(context, thisObject, argumentCount,  arguments, exception, EQUALSTO);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::earlierThan(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("earlierThan entered");
+
+       Try {
+               return diffTZDate(context, thisObject, argumentCount,  arguments, exception, EARLIERTHAN);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+
+}
+
+JSValueRef JSTZDate::laterThan(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+
+       LogDebug("laterThan entered");
+
+       Try {
+               return diffTZDate(context, thisObject, argumentCount,  arguments, exception, LATERTHAN);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+
+}
+
+JSValueRef JSTZDate::addDuration(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+
+       LogDebug("addDuration entered");
+       Try {
+               TimeUtilConverter converter(context);
+
+               DurationProperties duration;
+               if (argumentCount == 0)
+                       duration= converter.getDurationPropertis(JSValueMakeUndefined(context));
+               else
+                       duration= converter.getDurationPropertis(arguments[0]);
+
+               LogDebug("unit : " << duration.unit << " Length:" << duration.length);
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               TZDateProperties result = tzDate->addDuration(duration);
+
+               return (static_cast<JSValueRef>(createJSObject(context, result)));
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (OutOfRangeException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "The result is beyond the scope that TZDate can handle.");
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::toUTC(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+
+       LogDebug("toUTC entered");
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               TZDateProperties result = tzDate->toUTC();
+               return (static_cast<JSValueRef>(createJSObject(context, result)));
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+
+JSValueRef JSTZDate::toLocalTimezone(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+
+       LogDebug("toLocalTimezone entered");
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               TZDateProperties result = tzDate->toLocalTimezone();
+               return (static_cast<JSValueRef>(createJSObject(context, result)));
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::toLocaleDateString(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               std::string result = tzDate->toDateString(true);
+               return converter.toJSValueRef(result);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::toLocaleTimeString(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               std::string result = tzDate->toTimeString(true);
+               return converter.toJSValueRef(result);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::toLocaleString(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               std::string result = tzDate->toString(true);
+               return converter.toJSValueRef(result);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::toDateString(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               std::string result = tzDate->toDateString();
+               return converter.toJSValueRef(result);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::toTimeString(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               std::string result = tzDate->toTimeString();
+               return converter.toJSValueRef(result);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+
+JSValueRef JSTZDate::toString(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               std::string result = tzDate->toString();
+               return converter.toJSValueRef(result);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::getDate(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_DATE;
+       return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+} //getDate()
+
+JSValueRef JSTZDate::getDay(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_DAY_OF_WEEK;
+       return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+} //getDay()
+
+JSValueRef JSTZDate::getFullYear(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_YEAR;
+       return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+} //getFullYear()
+
+JSValueRef JSTZDate::getHours(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_HOUR_OF_DAY;
+       return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+} //getHours()
+
+JSValueRef JSTZDate::getMilliseconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_MILLISECOND;
+       return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+} //getMilliseconds()
+
+JSValueRef JSTZDate::getMinutes(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_MINUTE;
+       return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+} //getMinutes()
+
+JSValueRef JSTZDate::getMonth(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_MONTH;
+       return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+} //getMonth()
+
+JSValueRef JSTZDate::getSeconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_SECOND;
+       return getTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+} //getSeconds()
+
+JSValueRef JSTZDate::getTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception,
+        ITZDate::TZDateFields dateFields) {
+       try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*> (JSObjectGetPrivate(thisObject));
+
+               if (privateObject == NULL) {
+                       LogError(">>> NULL Exception");
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               }
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               long retVal = tzDate->get(dateFields);
+
+               TimeUtilConverter converter(context);
+               LogDebug(">>> retVal:" << retVal);
+               return converter.toJSValueRef(static_cast<int> (retVal));
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::setDate(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_DATE;
+
+       try{
+               setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       }
+
+       return JSValueMakeNull(context);
+} //setDate()
+
+JSValueRef JSTZDate::setFullYear(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_YEAR;
+
+       try{
+               setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       }
+
+       return JSValueMakeNull(context);
+} //setFullYear()
+
+JSValueRef JSTZDate::setHours(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_HOUR_OF_DAY;
+
+       Try {
+               setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       }
+
+       return JSValueMakeNull(context);
+} //setHours()
+
+JSValueRef JSTZDate::setMilliseconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_MILLISECOND;
+       
+       Try{
+               setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       }
+
+       return JSValueMakeNull(context);
+} //setMilliseconds()
+
+JSValueRef JSTZDate::setMinutes(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_MINUTE;
+
+       Try {
+               setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       }
+
+       return JSValueMakeNull(context);
+} //setMinutes()
+
+JSValueRef JSTZDate::setMonth(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_MONTH;
+
+       Try {
+               setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       }
+
+       return JSValueMakeNull(context);
+} //setMonth()
+
+JSValueRef JSTZDate::setSeconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception) {
+       LogDebug("<<<");
+
+       ITZDate::TZDateFields dateFields = ITZDate::TZDATE_SECOND;
+
+       Try {
+               setTZDateValue(context, thisObject, argumentCount, arguments, exception, dateFields);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       }
+
+       return JSValueMakeNull(context);
+} //setSeconds()
+
+
+JSValueRef JSTZDate::setTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+        JSValueRef * exception, ITZDate::TZDateFields dateFields) {
+
+       TimeUtilConverter converter(context);
+
+       int data =0;
+       if (argumentCount == 0)
+               data = converter.toInt(JSValueMakeUndefined(context));
+       else
+               data = converter.toInt(arguments[0]);
+
+       if ((dateFields == ITZDate::TZDATE_YEAR) && (data < 0))
+               ThrowMsg(InvalidArgumentException, "Invalid Argument:Year can't be set to negative");
+
+       TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*> (JSObjectGetPrivate(thisObject));
+
+       if (privateObject == NULL) {
+               LogError(">>> NULL Exception");
+               ThrowMsg(NullPointerException, "privateObject is NULL");
+       }
+
+       ITZDatePtr tzDate(privateObject->getObject());
+       tzDate->set(dateFields, static_cast<long> (data));
+
+       return JSValueMakeNull(context);
+}      //setTZDateValue
+
+JSValueRef JSTZDate::getUTCDate(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       return getUTCTZDateValue(context, thisObject, argumentCount, ITZDate::TZDATE_DATE, exception);
+}
+
+JSValueRef JSTZDate::getUTCDay(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       return getUTCTZDateValue(context, thisObject, argumentCount, ITZDate::TZDATE_DAY_OF_WEEK, exception);
+}
+
+JSValueRef JSTZDate::getUTCFullYear(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       return getUTCTZDateValue(context, thisObject, argumentCount, ITZDate::TZDATE_YEAR, exception);
+}
+
+JSValueRef JSTZDate::getUTCHours(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       return getUTCTZDateValue(context, thisObject, argumentCount, ITZDate::TZDATE_HOUR_OF_DAY, exception);
+}
+
+JSValueRef JSTZDate::getUTCMilliseconds(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       return getUTCTZDateValue(context, thisObject, argumentCount, ITZDate::TZDATE_MILLISECOND, exception);
+}
+
+JSValueRef JSTZDate::getUTCMinutes(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       return getUTCTZDateValue(context, thisObject, argumentCount, ITZDate::TZDATE_MINUTE, exception);
+}
+
+JSValueRef JSTZDate::getUTCMonth(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       return getUTCTZDateValue(context, thisObject, argumentCount, ITZDate::TZDATE_MONTH, exception);
+}
+
+JSValueRef JSTZDate::getUTCSeconds(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       return getUTCTZDateValue(context, thisObject, argumentCount, ITZDate::TZDATE_SECOND, exception);
+}
+
+JSValueRef JSTZDate::getUTCTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, ITZDate::TZDateFields DateFields, JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               long result = tzDate->getUTC(DateFields);
+
+               return converter.toJSValueRefLong(result);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::setUTCDate(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+
+       return setUTCTZDateValue(context, thisObject, argumentCount, arguments, ITZDate::TZDATE_DATE, exception);
+}
+
+JSValueRef JSTZDate::setUTCFullYear(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+
+       return setUTCTZDateValue(context, thisObject, argumentCount, arguments, ITZDate::TZDATE_YEAR, exception);
+}
+
+JSValueRef JSTZDate::setUTCHours(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+
+       return setUTCTZDateValue(context, thisObject, argumentCount, arguments, ITZDate::TZDATE_HOUR_OF_DAY, exception);
+}
+
+JSValueRef JSTZDate::setUTCMilliseconds(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+
+       return setUTCTZDateValue(context, thisObject, argumentCount, arguments, ITZDate::TZDATE_MILLISECOND, exception);
+}
+
+JSValueRef JSTZDate::setUTCMinutes(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+
+       return setUTCTZDateValue(context, thisObject, argumentCount, arguments, ITZDate::TZDATE_MINUTE, exception);
+}
+
+JSValueRef JSTZDate::setUTCMonth(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+
+       return setUTCTZDateValue(context, thisObject, argumentCount, arguments, ITZDate::TZDATE_MONTH, exception);
+}
+
+JSValueRef JSTZDate::setUTCSeconds(JSContextRef context, JSObjectRef function,
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+
+       return setUTCTZDateValue(context, thisObject, argumentCount, arguments, ITZDate::TZDATE_SECOND, exception);
+}
+
+JSValueRef JSTZDate::setUTCTZDateValue(JSContextRef context, JSObjectRef thisObject,
+       size_t argumentCount, const JSValueRef arguments[], ITZDate::TZDateFields dateFields, JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               TimeUtilConverter converter(context);
+               
+               long data = 0;
+               if (argumentCount == 0)
+                       data = converter.toLong(JSValueMakeUndefined(context));
+               else
+                       data = converter.toLong(arguments[0]);
+
+               if ((dateFields == ITZDate::TZDATE_YEAR) && (data < 0))
+                       ThrowMsg(InvalidArgumentException, "Invalid Argument:Year can't be set to negative");
+
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               ITZDatePtr tzDate(privateObject->getObject());
+               tzDate->setUTC(dateFields, data);
+
+               return JSValueMakeNull(context);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::getTimezoneAbbreviation(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("entered");
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+
+               std::string result;
+
+               return converter.toJSValueRef(tzDate->getTimezoneAbbreviation());
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::secondsFromUTC(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("entered");
+
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+
+               return converter.toJSValueRefLong(tzDate->secondsFromUTC());
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+JSValueRef JSTZDate::isDST(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("entered");
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+
+               return converter.toJSValueRef(tzDate->isDST());
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::getPreviousDSTTransition(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("entered");
+
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+       
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+
+               TZDateProperties resultDate =  tzDate->getDSTTransition(ITZDate::PREV_TRANSITION);
+               if (resultDate.timezone == "")
+                       return JSValueMakeNull(context);
+       
+               return createJSObject(context, resultDate);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTZDate::getNextDSTTransition(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("entered");
+
+       Try {
+               TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(thisObject));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+       
+               TimeUtilConverter converter(context);
+
+               ITZDatePtr tzDate(privateObject->getObject());
+
+               TZDateProperties resultDate =  tzDate->getDSTTransition(ITZDate::NEXT_TRANSITION);
+               if (resultDate.timezone == "")
+                       return JSValueMakeNull(context);
+       
+               return createJSObject(context, resultDate);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+}              //Tizen1_0
+}              //TizenApis
+#undef min
diff --git a/src/standards/Tizen/TimeUtil/JSTZDate.h b/src/standards/Tizen/TimeUtil/JSTZDate.h
new file mode 100755 (executable)
index 0000000..20af025
--- /dev/null
@@ -0,0 +1,228 @@
+//
+// 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 _JS_TIZEN_TZDATE_H_
+#define _JS_TIZEN_TZDATE_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <API/TimeUtil/ITZDate.h>
+#include <CommonsJavaScript/PrivateObject.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::TimeUtil::ITZDatePtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> TZDatePrivObject;
+
+class JSTZDate
+{
+public:
+
+    static const JSClassDefinition* getClassInfo();
+
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context);
+    static JSObjectRef createJSObject(JSContextRef context, const std::string &timezone);
+    static JSObjectRef createJSObject(JSContextRef context, const double milliseconds, const std::string &timezone);
+    static JSObjectRef createJSObject(JSContextRef context, const Api::TimeUtil::TZDateProperties &properties);
+    static JSObjectRef createJSObject(JSContextRef context, const long year, const long month,  const long day, const long hours, const long minutes, const long seconds, const long milliseconds, const std::string &timezone);       
+private:
+       enum CompareType {
+               DIFFERENCE,
+               EQUALSTO,
+               EARLIERTHAN,
+               LATERTHAN
+               };
+    /**
+     * 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 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 JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], 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 getTimezone(JSContextRef context, JSObjectRef function, 
+            JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef toTimezone(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+       
+    static JSValueRef diffTZDate(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception, CompareType type);
+       
+    static JSValueRef difference(JSContextRef context, JSObjectRef function, 
+            JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef equalsTo(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef earlierThan(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef laterThan(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef addDuration(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef toUTC(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef toLocalTimezone(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+
+    static JSValueRef toLocaleDateString(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef toLocaleTimeString(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef toLocaleString(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef toDateString(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef toTimeString(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 getDate(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef getDay(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef getFullYear(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef getHours(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef getMilliseconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef getMinutes(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef getMonth(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef getSeconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef setTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception,
+                       TizenApis::Api::TimeUtil::ITZDate::TZDateFields dateFields);
+
+       static JSValueRef getTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception,
+                       TizenApis::Api::TimeUtil::ITZDate::TZDateFields dateFields);
+
+       static JSValueRef setDate(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+                       JSValueRef * exception);
+
+       static JSValueRef setFullYear(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+                       JSValueRef * exception);
+
+       static JSValueRef setHours(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef setMilliseconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef setMinutes(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef setMonth(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+       static JSValueRef setSeconds(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[],
+               JSValueRef * exception);
+
+    static JSValueRef getUTCTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, 
+               TizenApis::Api::TimeUtil::ITZDate::TZDateFields DateFields, JSValueRef * exception);    
+    static JSValueRef getUTCDate(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef getUTCDay(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef getUTCFullYear(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef getUTCHours(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef getUTCMilliseconds(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef getUTCMinutes(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef getUTCMonth(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef getUTCSeconds(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+
+    static JSValueRef setUTCTZDateValue(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, 
+               const JSValueRef arguments[], TizenApis::Api::TimeUtil::ITZDate::TZDateFields dateFields, JSValueRef * exception);
+    static JSValueRef setUTCDate(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef setUTCFullYear(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef setUTCHours(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef setUTCMilliseconds(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef setUTCMinutes(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef setUTCMonth(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef setUTCSeconds(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+
+    static JSValueRef getTimezoneAbbreviation(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, 
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);    
+    static JSValueRef secondsFromUTC(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, 
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef isDST(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, 
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef getPreviousDSTTransition(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, 
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef getNextDSTTransition(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, 
+               size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+};
+
+}
+}
+
+#endif /* _JS_TIZEN_DATETIME_H_ */
diff --git a/src/standards/Tizen/TimeUtil/JSTimeDuration.cpp b/src/standards/Tizen/TimeUtil/JSTimeDuration.cpp
new file mode 100755 (executable)
index 0000000..34c37af
--- /dev/null
@@ -0,0 +1,403 @@
+//
+// 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 <string>
+#include <memory>
+#include <dpl/log/log.h>
+#include <cmath>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+
+#include <API/TimeUtil/TimeUtilFactory.h>
+
+#include "JSTimeDuration.h"
+#include "TimeUtilConverter.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace DPL;
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::TimeUtil;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+#define TIZEN10_TIMEDURATION_LENGTH "length"
+#define TIZEN10_TIMEDURATION_UNIT "unit"
+
+JSClassDefinition JSTimeDuration::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "TimeDuration",
+    0,
+    m_property,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    setProperty, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    constructor, //CallAsConstructor,
+    hasInstance,
+    NULL, //ConvertToType
+};
+
+
+JSStaticFunction JSTimeDuration::m_function[] = {
+    {"difference",           JSTimeDuration::difference,            kJSPropertyAttributeNone},
+    {"equalsTo",           JSTimeDuration::equalsTo,            kJSPropertyAttributeNone},
+    {"lessThan",           JSTimeDuration::lessThan,            kJSPropertyAttributeNone},
+    {"greaterThan",           JSTimeDuration::greaterThan,            kJSPropertyAttributeNone},
+};
+
+JSStaticValue JSTimeDuration::m_property[] =
+{
+    //TimdDurationProperties
+       {TIZEN10_TIMEDURATION_LENGTH,  getProperty, setProperty, kJSPropertyAttributeNone},
+       {TIZEN10_TIMEDURATION_UNIT,  getProperty, setProperty, kJSPropertyAttributeNone},
+       { 0, 0, 0, 0 }
+};
+
+const JSClassRef JSTimeDuration::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSTimeDuration::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSTimeDuration::m_jsClassRef = JSClassCreate(JSTimeDuration::getClassInfo());
+
+void JSTimeDuration::initialize(JSContextRef context, JSObjectRef object)
+{
+       LogDebug("entered Nothing to do.");
+
+       if (!JSObjectGetPrivate(object)) {
+               LogDebug("Private object not set... setting it.");
+               DurationProperties durations;
+               DurationPropertiesPtr durationProps(new DurationProperties(durations));
+               TimeDurationPrivObject *priv = new TimeDurationPrivObject(context, durationProps);
+
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSTimeDuration::finalize(JSObjectRef object)
+{
+       TimeDurationPrivObject* priv = static_cast<TimeDurationPrivObject*>(JSObjectGetPrivate(object));
+       JSObjectSetPrivate(object, NULL);
+       LogDebug("Deleting TimeDuration");
+       delete priv;
+}
+
+JSValueRef JSTimeDuration::getProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception)
+{
+       LogDebug("Enter");
+
+       Try     {
+               TimeUtilConverter convert(context);
+
+               LogDebug("propertyName : " << convert.toString(propertyName));
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_TIMEDURATION_LENGTH)) {
+                       return convert.toJSValueRef(static_cast<double>(convert.getDurationLength(object)));
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_TIMEDURATION_UNIT)) {
+                       std::string strUnit = convert.toDurationUnitString(convert.getDurationUnit(object));
+                       if (strUnit == "")
+                               ThrowMsg(InvalidArgumentException, "unit string is invald.");
+                       return convert.toJSValueRef(strUnit);
+               }
+       } Catch (ConversionException) {
+               LogError("ConversionException: " << _rethrown_exception.GetMessage());
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSTimeDuration::setProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef value,  JSValueRef* exception)
+{
+       LogDebug("Enter");
+
+       Try     {
+               TimeDurationPrivObject* privateObject = static_cast<TimeDurationPrivObject*>(JSObjectGetPrivate(object));
+               if (!privateObject) {
+                       LogError("Private object is not set.");
+                       ThrowMsg(NullPointerException, "Private object not initialized");
+               }
+
+               DurationPropertiesPtr duration = privateObject->getObject();
+               TimeUtilConverter convert(context);
+
+               if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_TIMEDURATION_LENGTH)) {
+                       duration->length = static_cast<long long>(convert.toDouble(value));
+                       if (std::isnan(duration->length)  || std::isinf(duration->length))
+                               duration->length = 0;
+               } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN10_TIMEDURATION_UNIT)) {
+                       short unit = convert.toDurationUnit(convert.toString(value));
+                       if (unit == 0xff)
+                               ThrowMsg(ConversionException, "property doesn't exist.");
+                       duration->unit = unit;
+               } else
+                       return false;
+
+               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 (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       }
+       return false;
+}
+
+JSObjectRef JSTimeDuration::createJSObject(JSContextRef context,
+        const DurationProperties &durations)
+{
+    DurationPropertiesPtr durationProps(new DurationProperties(durations));
+    TimeDurationPrivObject *priv = new TimeDurationPrivObject(context, durationProps);
+
+    if (!priv) {
+        ThrowMsg(NullPointerException, "Can not new an object");
+    }
+    return JSObjectMake(context, getClassRef(), priv);
+}
+
+JSObjectRef JSTimeDuration::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
+       LogDebug("entered");
+       TimeUtilConverter convert(ctx);
+       Try {
+               DurationProperties duration;
+               if (argumentCount == 0)
+                       duration.length = convert.toDouble(JSValueMakeUndefined(ctx));
+               else
+                       duration.length = convert.toDouble(arguments[0]);
+
+               if (std::isnan(duration.length) || std::isinf(duration.length))
+                       duration.length = 0;
+
+               if (argumentCount > 1) {
+                       if (!JSValueIsUndefined(ctx, arguments[1]) && !JSValueIsNull(ctx, arguments[1])) {
+                               std::string unit = convert.toString(arguments[1]);
+                               duration.unit = convert.toDurationUnit(unit);
+                               if (duration.unit == 0xff)
+                                       ThrowMsg(ConversionException, "Argument(unit) is invalid(wrong type unit)");
+                       }
+               }
+               return createJSObject(ctx, duration);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return NULL;
+       } Catch(UnknownException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+               return NULL;
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               return NULL;
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+               return NULL;
+       } Catch (WrtDeviceApis::Commons::Exception) {
+           LogWarning("Trying to get incorrect value");
+       }
+       *exception = JSTizenExceptionFactory::makeErrorObject(ctx, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+       return NULL;
+}
+
+bool JSTimeDuration::hasInstance(JSContextRef context,
+        JSObjectRef constructor,
+        JSValueRef possibleInstance,
+        JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSTimeDuration::diffTimeDuration(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception, CompareType type) {
+       LogDebug("entered");
+
+       TimeDurationPrivObject* privateObject = static_cast<TimeDurationPrivObject*>(JSObjectGetPrivate(thisObject));
+       if (!privateObject) {
+               LogError("Private object is not set.");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       }
+
+       TimeUtilConverter converter(context);
+
+       DurationProperties first = converter.getDurationPropertis(thisObject);
+       DurationProperties second;
+       if (argumentCount == 0)
+               second= converter.getDurationPropertis(JSValueMakeUndefined(context));
+       else
+               second= converter.getDurationPropertis(arguments[0]);
+
+       DurationProperties diff;
+       if (first.unit > second.unit) {
+               long long firstLength = converter.convertDurationLength(first, second.unit);
+               diff.unit = second.unit;
+               diff.length = firstLength - second.length;
+       } else {
+               long long secondLength = converter.convertDurationLength(second, first.unit);
+               diff.unit = first.unit;
+               diff.length = first.length - secondLength;
+       }
+
+       switch (type) {
+               case EQUALSTO:
+               {
+                       if (diff.length == 0)
+                               return converter.toJSValueRef(true);
+                       else
+                               return converter.toJSValueRef(false);
+               }
+               case LESSTHAN:
+               {
+                       if (diff.length < 0)
+                               return converter.toJSValueRef(true);
+                       else
+                               return converter.toJSValueRef(false);
+               }
+               case GREATERTHAN:
+               {
+                       if (diff.length > 0)
+                               return converter.toJSValueRef(true);
+                       else
+                               return converter.toJSValueRef(false);
+               }
+               case DIFFERENCE:
+               default:
+                       return converter.makeDurationObject(diff);
+       }
+}
+
+JSValueRef JSTimeDuration::difference(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               return diffTimeDuration(context, thisObject, argumentCount, arguments, exception, DIFFERENCE);
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (UnsupportedException) {
+               LogError("JSTimeUtil::hasInstance NotSupportedException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR , "Not Support");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());            
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTimeDuration::equalsTo(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               return diffTimeDuration(context, thisObject, argumentCount, arguments, exception, EQUALSTO);
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (UnsupportedException) {
+               LogError("JSTimeUtil::hasInstance NotSupportedException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR , "Not Support");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());                    
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTimeDuration::lessThan(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               return diffTimeDuration(context, thisObject, argumentCount, arguments, exception, LESSTHAN);
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (UnsupportedException) {
+               LogError("JSTimeUtil::hasInstance NotSupportedException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR , "Not Support");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());            
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTimeDuration::greaterThan(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               return diffTimeDuration(context, thisObject, argumentCount, arguments, exception, GREATERTHAN);
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (UnsupportedException) {
+               LogError("JSTimeUtil::hasInstance NotSupportedException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR , "Not Support");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+} //Tizen1_0
+} //TizenApis
diff --git a/src/standards/Tizen/TimeUtil/JSTimeDuration.h b/src/standards/Tizen/TimeUtil/JSTimeDuration.h
new file mode 100755 (executable)
index 0000000..b7d04c9
--- /dev/null
@@ -0,0 +1,124 @@
+//
+// 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 WRT_PLUGINS_TIZEN_1_0_JS_TIMEDURATION_H_
+#define WRT_PLUGINS_TIZEN_1_0_JS_TIMEDURATION_H_
+
+#include <dpl/shared_ptr.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/TimeUtil/DurationProperties.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<
+             TizenApis::Api::TimeUtil::DurationPropertiesPtr>::
+    Type TimeDurationPrivObject;
+
+/**
+ * @class JSTimeDuration
+ * @brief This class is javascript extension
+ *
+ */
+class JSTimeDuration
+{
+  public:
+    /**
+     * Gets object's class description.
+     */
+    static const JSClassDefinition* getClassInfo();
+
+    /**
+     * Gets class definition reference.
+     * @remarks New instance of JSClassRef is created (only once) if none was
+     * @remarks set before.
+     * @return Class reference.
+     */
+    static const JSClassRef getClassRef();
+    static JSObjectRef createJSObject(JSContextRef context, const Api::TimeUtil::DurationProperties &durations);
+  private:
+       enum CompareType {
+               DIFFERENCE,
+               EQUALSTO,
+               LESSTHAN,
+               GREATERTHAN
+               };
+    /**
+     * 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);
+
+    /**
+     * Getters for properties
+     */
+    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 constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], 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 diffTimeDuration(JSContextRef context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception, CompareType type);
+    static JSValueRef difference(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef equalsTo(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef lessThan(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception);
+    static JSValueRef greaterThan(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 JSClassRef m_jsClassRef;
+
+    /**
+     * 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[];
+};
+}
+}
+
+#endif //WRT_PLUGINS_TIZEN_1_0_JS_TIMEDURATION_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/TimeUtil/JSTimeUtil.cpp b/src/standards/Tizen/TimeUtil/JSTimeUtil.cpp
new file mode 100755 (executable)
index 0000000..bc0aa0b
--- /dev/null
@@ -0,0 +1,351 @@
+//
+// 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 <string>
+#include <ctime>
+#include <dpl/log/log.h>
+
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+
+#include <API/TimeUtil/TimeUtilFactory.h>
+
+#include "JSTimeUtil.h"
+#include "JSTZDate.h"
+#include "TimeUtilConverter.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+using namespace DPL;
+using namespace TizenApis::Api::TimeUtil;
+using namespace TizenApis::Commons;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+JSClassDefinition JSTimeUtil::m_classInfo = {
+    0,
+    kJSClassAttributeNone,
+    "TimeUtil",
+    0,
+    NULL,
+    m_function,
+    initialize,
+    finalize,
+    NULL, //HasProperty,
+    NULL, //GetProperty,
+    NULL, //SetProperty,
+    NULL, //DeleteProperty,
+    NULL, //GetPropertyNames,
+    NULL, //CallAsFunction,
+    NULL, //CallAsConstructor,
+    hasInstance,
+    NULL, //ConvertToType
+};
+
+JSStaticFunction JSTimeUtil::m_function[] = {
+    { "getCurrentDateTime", JSTimeUtil::getCurrentDateTime, kJSPropertyAttributeNone },
+    { "getLocalTimezone", JSTimeUtil::getLocalTimezone, kJSPropertyAttributeNone },
+    { "getAvailableTimezones", JSTimeUtil::getAvailableTimezones, kJSPropertyAttributeNone },
+    { "getDateFormat", JSTimeUtil::getDateFormat, kJSPropertyAttributeNone },
+    { "getTimeFormat", JSTimeUtil::getTimeFormat, kJSPropertyAttributeNone },
+    { "isLeapYear",      JSTimeUtil::isLeapYear,      kJSPropertyAttributeNone},
+    { 0, 0, 0 }
+};
+
+const JSClassRef JSTimeUtil::getClassRef()
+{
+    if (!m_jsClassRef) {
+        m_jsClassRef = JSClassCreate(&m_classInfo);
+    }
+    return m_jsClassRef;
+}
+
+const JSClassDefinition* JSTimeUtil::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSTimeUtil::m_jsClassRef = JSClassCreate(JSTimeUtil::getClassInfo());
+
+void JSTimeUtil::initialize(JSContextRef context, JSObjectRef object)
+{
+       TimeUtilPrivObject* priv = static_cast<TimeUtilPrivObject*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ITimeUtilPtr timeutil( TimeUtilFactory::getInstance().createTimeUtilObject() );
+               priv = new TimeUtilPrivObject( context, timeutil);
+               if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+                       LogError("Object can't store private data.");
+                       delete priv;
+               }       
+       }
+
+       LogDebug("JSTimeUtil::initialize ");
+}
+
+void JSTimeUtil::finalize(JSObjectRef object)
+{
+       TimeUtilPrivObject* priv = static_cast<TimeUtilPrivObject*>(JSObjectGetPrivate(object));
+       JSObjectSetPrivate(object, NULL);
+       LogDebug("Deleting timeutil");
+       delete priv;
+}
+
+bool JSTimeUtil::hasInstance(JSContextRef context,
+        JSObjectRef constructor,
+        JSValueRef possibleInstance,
+        JSValueRef* exception)
+{
+    return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSTimeUtil::getCurrentDateTime(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("Entered ");
+       Try {
+               TimeUtilPrivObject* privateObject = static_cast<TimeUtilPrivObject*>(JSObjectGetPrivate(thisObject));
+               if (NULL == privateObject) {
+                       LogError("private object is null");
+                       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+               }
+       
+               return JSTZDate::createJSObject(context);
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } 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");
+}
+
+JSValueRef JSTimeUtil::getLocalTimezone(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("Entered ");
+       Try {
+               TimeUtilPrivObject* privateObject = 
+                       static_cast<TimeUtilPrivObject*>(JSObjectGetPrivate(
+                                                              thisObject));
+               if (NULL == privateObject) {
+                       ThrowMsg(NullPointerException, "Can not new an object");
+               }
+               
+               ITimeUtilPtr timeutil(privateObject->getObject());
+               std::string localTimezone = timeutil->getLocalTimezone();
+
+               TimeUtilConverter converter(context);
+               
+               return converter.toJSValueRef(localTimezone);
+       } Catch(NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTimeUtil::getAvailableTimezones(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try {
+               TimeUtilPrivObject* privateObject = 
+                       static_cast<TimeUtilPrivObject*>(JSObjectGetPrivate(
+                                                              thisObject));
+               if (NULL == privateObject) {
+                       ThrowMsg(NullPointerException, "Can not new an object");
+               }
+
+               TimeUtilConverter converter(context);   
+       
+               ITimeUtilPtr timeutil(privateObject->getObject());
+
+               std::vector<std::string> timezones = timeutil->getAvailableTimezones();
+               std::vector<JSValueRef> timezonesArray;
+               unsigned short timezonesCount = timezones.size();
+               for (int i = 0; i < timezonesCount; ++i) {
+                       timezonesArray.push_back(converter.toJSValueRef(timezones[i]));
+               }
+               
+               return converter.toJSValueRef(timezonesArray);
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");;
+       } Catch (UnsupportedException) {
+               LogError("JSTimeUtil::hasInstance NotSupportedException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR , "Not Support");
+       } Catch (NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");    
+}
+
+JSValueRef JSTimeUtil::getDateFormat(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try {
+               bool b_shortFormat = true;
+               
+               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));
+               if (NULL == privateObject) {
+                       ThrowMsg(NullPointerException, "Can not new an object");
+               }
+
+               ITimeUtilPtr timeutil(privateObject->getObject());
+               std::string dateformat = timeutil->getDateFormat(b_shortFormat);
+               
+               return converter.toJSValueRef(dateformat);
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");;
+       } Catch (UnsupportedException) {
+               LogError("JSTimeUtil::hasInstance NotSupportedException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR , "Not Support");
+       } Catch (NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");    
+}
+
+JSValueRef JSTimeUtil::getTimeFormat(JSContextRef context,
+        JSObjectRef object,
+        JSObjectRef thisObject,
+        size_t argumentCount,
+        const JSValueRef arguments[],
+        JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try {
+               TimeUtilPrivObject* privateObject = 
+                       static_cast<TimeUtilPrivObject*>(JSObjectGetPrivate(
+                                                              thisObject));
+               
+               if (NULL == privateObject) {
+                       ThrowMsg(NullPointerException, "Can not new an object");
+               }       
+               
+               ITimeUtilPtr timeutil(privateObject->getObject());
+               std::string timeFormat = timeutil->getTimeFormat();
+               TimeUtilConverter converter(context);
+               
+               return converter.toJSValueRef(timeFormat);
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (UnsupportedException) {
+               LogError("JSTimeUtil::hasInstance NotSupportedException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR , "Not Support");
+       } Catch (NullPointerException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());            
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+JSValueRef JSTimeUtil::isLeapYear(JSContextRef context, JSObjectRef function, 
+       JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) {
+       LogDebug("Entered");
+       Try {
+               TimeUtilConverter converter(context);
+
+               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)
+                       return converter.toJSValueRef(true);
+               if (year % 100 == 0)
+                       return converter.toJSValueRef(false);
+
+               return converter.toJSValueRef(true);    
+       } Catch(ConversionException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch");
+       } Catch (InvalidArgumentException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid Values");
+       } Catch (UnsupportedException) {
+               LogError("JSTimeUtil::hasInstance NotSupportedException");
+               return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR , "Not Support");
+       } Catch (PlatformException) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());
+       } Catch (WrtDeviceApis::Commons::Exception) {
+               LogError("Exception: " << _rethrown_exception.GetMessage());            
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown Error");
+}
+
+} //Tizen1_0
+} //TizenApis
diff --git a/src/standards/Tizen/TimeUtil/JSTimeUtil.h b/src/standards/Tizen/TimeUtil/JSTimeUtil.h
new file mode 100755 (executable)
index 0000000..38e7586
--- /dev/null
@@ -0,0 +1,138 @@
+//
+// 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 WRT_PLUGINS_TIZEN_1_0_JS_TIMEUTIL_H_
+#define WRT_PLUGINS_TIZEN_1_0_JS_TIMEUTIL_H_
+
+#include <dpl/shared_ptr.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/JSPendingOperationPrivateObject.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/TimeUtil/ITimeUtil.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::TimeUtil::ITimeUtilPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> TimeUtilPrivObject;
+
+/**
+ * @class JSTimeUtil
+ * @brief This class is javascript extension
+ *
+ */
+class JSTimeUtil
+{
+  public:
+    /**
+     * Gets object's class description.
+     */
+    static const JSClassDefinition* getClassInfo();
+
+    /**
+     * Gets class definition reference.
+     * @remarks New instance of JSClassRef is created (only once) if none was
+     * @remarks set before.
+     * @return Class reference.
+     */
+    static const JSClassRef getClassRef();
+
+  private:
+    /**
+     * The callback invoked when an object is first created.
+     */
+    static void initialize(JSContextRef context,
+            JSObjectRef object);
+
+    /**
+     * The callback invoked when an object is finalized.
+     */
+    static void finalize(JSObjectRef object);
+
+    /**
+     * The callback invoked when an object is used as the target of an 'instanceof' expression.
+     */
+    static bool hasInstance(JSContextRef ctx,
+            JSObjectRef constructor,
+            JSValueRef possibleInstance,
+            JSValueRef* exception);
+
+    /**
+     * Get current date/time.
+     */
+    static JSValueRef getCurrentDateTime(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+
+    /**
+     * Get local system timezone.
+     */
+    static JSValueRef getLocalTimezone(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+    /**
+     * Get asynchronously the timezones supported by the system.
+     */
+    static JSValueRef getAvailableTimezones(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+    static JSValueRef getDateFormat(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+
+    static JSValueRef getTimeFormat(JSContextRef context,
+               JSObjectRef object,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception);
+       
+    static JSValueRef isLeapYear(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;
+
+    /**
+     * This structure describes a statically declared function.
+     */
+    static JSStaticFunction m_function[];
+
+    static JSClassRef m_jsClassRef;
+};
+}
+}
+
+#endif //WRT_PLUGINS_TIZEN_1_0_JS_TIMEUTIL_H_
\ No newline at end of file
diff --git a/src/standards/Tizen/TimeUtil/TimeUtilConverter.cpp b/src/standards/Tizen/TimeUtil/TimeUtilConverter.cpp
new file mode 100755 (executable)
index 0000000..38dc014
--- /dev/null
@@ -0,0 +1,295 @@
+//
+// 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 <Commons/Exception.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <Commons/RegexUtils.h>
+
+#include <API/TimeUtil/TimeUtilFactory.h>
+#include "TimeUtilConverter.h"
+
+#include "JSTZDate.h"
+#include "JSTimeDuration.h"
+
+using namespace TizenApis::Api::TimeUtil;
+using namespace WrtDeviceApis;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+TimeUtilConverter::TimeUtilConverter(JSContextRef context)
+: WrtDeviceApis::CommonsJavaScript::Converter(context) {
+}
+
+TimeUtilConverter::~TimeUtilConverter() {
+}
+
+short TimeUtilConverter::toShort(const JSValueRef& arg)
+{
+    double tmp = toNumber_(arg);
+    return (isNan(tmp) ? 0 : static_cast<short>(tmp));
+}
+
+TZDateProperties TimeUtilConverter::getPropertiesInTZDate(JSValueRef arg) {
+       if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg) || !JSValueIsObjectOfClass(m_context, arg, JSTZDate::getClassRef())) {
+               ThrowMsg(Commons::ConversionException,
+                        "Message is JS null or JS undefined.");
+       }
+       JSObjectRef obj = toJSObjectRef(arg);
+       return getPropertiesInTZDate(obj);
+}
+
+
+TZDateProperties TimeUtilConverter::getPropertiesInTZDate(JSObjectRef arg) {
+       LogDebug("TZDate object=" << arg);
+       if (!arg) {
+               LogError("Object is null");
+               ThrowMsg(Commons::ConversionException, "Private object not initialized");
+       }
+       TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(arg));
+       if (!privateObject) {
+               LogError("Private object is not set.");
+               ThrowMsg(Commons::ConversionException, "Private object not initialized");
+       }
+       
+       ITZDatePtr tzDate = privateObject->getObject();
+       TZDateProperties result;
+
+       result.timezone = tzDate->getTimezone();
+       result.year = tzDate->get(ITZDate::TZDATE_YEAR);
+       result.month = tzDate->get(ITZDate::TZDATE_MONTH);
+       result.day= tzDate->get(ITZDate::TZDATE_DATE);
+       result.hours= tzDate->get(ITZDate::TZDATE_HOUR_OF_DAY);
+       result.minutes= tzDate->get(ITZDate::TZDATE_MINUTE);
+       result.seconds= tzDate->get(ITZDate::TZDATE_SECOND);
+       result.milliseconds = tzDate->get(ITZDate::TZDATE_MILLISECOND);
+       return result;
+}
+
+JSObjectRef TimeUtilConverter::makeDurationObject(const DurationProperties &duration) {
+       return JSTimeDuration::createJSObject(m_context, duration);
+}
+
+JSObjectRef TimeUtilConverter::makeMillisecondDurationObject(const long long length) {
+       DurationProperties duration;
+       duration.length = length;
+       duration.unit = MSECS_UNIT;
+       const long long dayToMsecs = 1000 * 60 * 60 * 24;
+       if ((length % dayToMsecs) == 0) {
+               duration.length = length / dayToMsecs;
+               duration.unit = DAYS_UNIT;
+       }
+
+       return makeDurationObject(duration);
+}
+
+DurationProperties TimeUtilConverter::getDurationPropertis(JSValueRef value) {
+       DurationProperties duration;
+       duration.length = getDurationLength(value);
+       duration.unit = getDurationUnit(value);
+       return duration;
+}
+
+long long TimeUtilConverter::getDurationLength(JSValueRef value) {
+       if (JSValueIsNull(m_context, value) || JSValueIsUndefined(m_context, value) || !JSValueIsObjectOfClass(m_context, value, JSTimeDuration::getClassRef())) {
+               ThrowMsg(Commons::ConversionException,
+                        "Duration is JS null or JS undefined.");
+       }
+       JSObjectRef obj = toJSObjectRef(value);
+       return getDurationLength(obj);
+}
+
+long long TimeUtilConverter::getDurationLength(JSObjectRef object) {
+       TimeDurationPrivObject* privateObject = static_cast<TimeDurationPrivObject*>(JSObjectGetPrivate(object));
+       if (!privateObject) {
+               LogError("Private object is not set.");
+               ThrowMsg(Commons::ConversionException, "Private object not initialized");
+       }
+
+       DurationPropertiesPtr duration = privateObject->getObject();
+
+       return duration->length;
+}
+
+short TimeUtilConverter::getDurationUnit(JSValueRef value) {
+       if (JSValueIsNull(m_context, value) || JSValueIsUndefined(m_context, value) || !JSValueIsObjectOfClass(m_context, value, JSTimeDuration::getClassRef())) {
+               ThrowMsg(Commons::ConversionException,
+                        "Duration is JS null or JS undefined.");
+       }
+       JSObjectRef obj = toJSObjectRef(value);
+       return getDurationUnit(obj);
+}
+
+short TimeUtilConverter::getDurationUnit(JSObjectRef object) {
+       TimeDurationPrivObject* privateObject = static_cast<TimeDurationPrivObject*>(JSObjectGetPrivate(object));
+       if (!privateObject) {
+               LogError("Private object is not set.");
+               ThrowMsg(Commons::ConversionException, "Private object not initialized");
+       }
+
+       DurationPropertiesPtr duration = privateObject->getObject();
+
+       return duration->unit;
+
+}
+
+short TimeUtilConverter::toDurationUnit(std::string strUnit) {
+       if (!strUnit.compare("DAYS"))
+               return DAYS_UNIT;
+       else if (!strUnit.compare("SECS"))
+               return SECONDS_UNIT;
+       else if (!strUnit.compare("MINS"))
+               return MINUTES_UNIT;
+       else if (!strUnit.compare("HOURS"))
+               return HOURS_UNIT;
+       else if (!strUnit.compare("MSECS"))
+               return  MSECS_UNIT;
+       else
+               return 0xff;
+}
+
+std::string TimeUtilConverter::toDurationUnitString(short unit) {
+       switch (unit) {
+               case DAYS_UNIT:
+                       return "DAYS";
+               case SECONDS_UNIT:
+                       return "SECS";
+               case MINUTES_UNIT:
+                       return "MINS";
+               case HOURS_UNIT:
+                       return "HOURS";
+               case MSECS_UNIT:
+                       return "MSECS";
+               default:
+                       return "";
+       }
+}
+
+long long TimeUtilConverter::convertDurationLength(DurationProperties duration, short unit) {
+       if (duration.unit < unit)
+               ThrowMsg(Commons::ConversionException, "Unit is larger thatn duration's unit");
+
+       if (duration.unit == unit)
+               return duration.length;
+
+       long long result = duration.length;
+
+       switch(unit) {
+               case MSECS_UNIT:
+                       result = result * 1000;
+                       if (duration.unit == SECONDS_UNIT)
+                               return result;
+                       // intentional fall-through
+
+               case SECONDS_UNIT:
+                       result = result * 60;
+                       if (duration.unit == MINUTES_UNIT)
+                               return result;
+                       // intentional fall-through
+
+               case MINUTES_UNIT:
+                       result = result * 60;
+                       if (duration.unit == HOURS_UNIT)
+                               return result;
+                       // intentional fall-through
+
+               case HOURS_UNIT:
+                       result = result * 24;
+                       return result;
+                       // intentional fall-through
+       }
+    return result;
+}
+
+double TimeUtilConverter::getTimeInMilliseconds(JSValueRef arg) {
+       if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg) || !JSValueIsObjectOfClass(m_context, arg, JSTZDate::getClassRef())) {
+               ThrowMsg(Commons::ConversionException,
+                        "JSValueRef is JS null or JS undefined.");
+       }
+       JSObjectRef obj = toJSObjectRef(arg);
+
+       return getTimeInMilliseconds(obj);
+}
+
+double TimeUtilConverter::getTimeInMilliseconds(JSObjectRef arg) {
+       if (!arg) {
+               LogError("Object is null");
+               ThrowMsg(Commons::ConversionException, "Private object not initialized");
+       }
+
+       TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(arg));
+       if (!privateObject) {
+               LogError("Private object is not set.");
+               ThrowMsg(Commons::ConversionException, "Private object not initialized");
+       }
+
+       ITZDatePtr tzDate = privateObject->getObject();
+
+       return tzDate->getTime();
+}
+
+tm TimeUtilConverter::toTZDateTime(JSValueRef arg) {
+       if (JSValueIsNull(m_context, arg) || JSValueIsUndefined(m_context, arg) || !JSValueIsObjectOfClass(m_context, arg, JSTZDate::getClassRef())) {
+               ThrowMsg(Commons::ConversionException,
+                        "JSValueRef is JS null or JS undefined.");
+       }
+       JSObjectRef obj = toJSObjectRef(arg);
+
+       return toTZDateTime(obj);
+}
+
+tm TimeUtilConverter::toTZDateTime(JSObjectRef arg) {
+       if (!arg) {
+               LogError("Object is null");
+               ThrowMsg(Commons::ConversionException, "Private object not initialized");
+       }
+
+       TZDatePrivObject* privateObject = static_cast<TZDatePrivObject*>(JSObjectGetPrivate(arg));
+       if (!privateObject) {
+               LogError("Private object is not set.");
+               ThrowMsg(Commons::ConversionException, "Private object not initialized");
+       }
+
+       ITZDatePtr tzDate = privateObject->getObject();
+
+       TZDateProperties utcProperties = tzDate->toUTC();
+       struct tm  utcTm;
+       memset(&utcTm, 0, sizeof(utcTm));
+
+       utcTm.tm_year = utcProperties.year - 1900;
+       utcTm.tm_mon = utcProperties.month;
+       utcTm.tm_mday= utcProperties.day;
+       utcTm.tm_hour= utcProperties.hours;
+       utcTm.tm_min=utcProperties.minutes;
+       utcTm.tm_sec= utcProperties.seconds;
+       utcTm.tm_isdst = 0;
+       return utcTm;
+}
+
+JSObjectRef TimeUtilConverter::toJSValueRefTZDate(const double milliseconds, const std::string &timezone) {
+       return JSTZDate::createJSObject(m_context, milliseconds, timezone);
+}
+
+}
+}
diff --git a/src/standards/Tizen/TimeUtil/TimeUtilConverter.h b/src/standards/Tizen/TimeUtil/TimeUtilConverter.h
new file mode 100755 (executable)
index 0000000..0413ac4
--- /dev/null
@@ -0,0 +1,74 @@
+//
+// 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 _JS_TIZEN10_TIMEUTIL_CONVERTER_H_
+#define _JS_TIZEN10_TIMEUTIL_CONVERTER_H_
+
+#include <vector>
+#include <string>
+
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+
+#include <API/TimeUtil/ITZDate.h>
+#include <API/TimeUtil/DurationProperties.h>
+
+using namespace TizenApis::Api::TimeUtil;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+namespace TizenApis {
+namespace Tizen1_0 {
+
+
+class TimeUtilConverter : public Converter
+{
+    public:
+       using Converter::toJSValueRef;
+    public:
+       explicit TimeUtilConverter(JSContextRef context);
+       virtual  ~TimeUtilConverter();
+       short toShort(const JSValueRef& arg);
+
+       TZDateProperties getPropertiesInTZDate(JSValueRef arg);
+       TZDateProperties getPropertiesInTZDate(JSObjectRef arg);
+       JSObjectRef makeDurationObject(const DurationProperties &duration);
+       JSObjectRef makeMillisecondDurationObject(const long long length);
+       DurationProperties getDurationPropertis(JSValueRef value);
+       long long getDurationLength(JSValueRef value);
+       long long getDurationLength(JSObjectRef object);
+       short getDurationUnit(JSValueRef value);
+       short getDurationUnit(JSObjectRef object);
+       short toDurationUnit(std::string strUnit);
+       std::string toDurationUnitString(short unit);
+       long long convertDurationLength(DurationProperties duration, short unit);
+       double getTimeInMilliseconds(JSValueRef arg);
+       double getTimeInMilliseconds(JSObjectRef arg);
+       tm toTZDateTime(JSValueRef arg);
+       tm toTZDateTime(JSObjectRef arg);
+       JSObjectRef toJSValueRefTZDate(const double milliseconds, const std::string &timezone);
+
+};
+
+typedef ConverterFactory<TimeUtilConverter> TimeUtilConverterFactory;
+
+}
+}
+
+#endif /* _JS_TIZEN10_TIMEUTIL_CONVERTER_H_ */
diff --git a/src/standards/Tizen/TimeUtil/config.xml b/src/standards/Tizen/TimeUtil/config.xml
new file mode 100755 (executable)
index 0000000..6eecac8
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+    <library-name>libwrt-plugins-tizen-2.0-time.so</library-name>
+    <feature-install-uri>time.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/time</name>
+        <device-capability>time</device-capability>
+    </api-feature>
+
+                            
+</plugin-properties>
diff --git a/src/standards/Tizen/TimeUtil/plugin_initializer.cpp b/src/standards/Tizen/TimeUtil/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..3ba873f
--- /dev/null
@@ -0,0 +1,72 @@
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include "JSTimeUtil.h"
+#include "JSTZDate.h"
+#include "JSTimeDuration.h"
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+void on_widget_start_callback(int widgetId) {
+       LogDebug("[TIZEN\\TimeUtil] on_widget_start_callback ("<<widgetId<<")");
+    Try
+    {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess initialization failed");
+    }
+}
+
+void on_widget_stop_callback(int widgetId) {
+       LogDebug("[TIZEN\\TimeUtil] on_widget_stop_callback ("<<widgetId<<")");
+    Try
+    {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+PLUGIN_CLASS_MAP_BEGIN
+       PLUGIN_CLASS_MAP_ADD_CLASS(
+               WRT_JS_EXTENSION_OBJECT_TIZEN,
+               "time",
+               (js_class_template_getter)TizenApis::Tizen1_0::JSTimeUtil::getClassRef,
+               NULL)
+       PLUGIN_CLASS_MAP_ADD_CLASS(
+               WRT_JS_EXTENSION_OBJECT_TIZEN,
+               "TZDate",
+               (js_class_template_getter)TizenApis::Tizen1_0::JSTZDate::getClassRef,
+               NULL)
+       PLUGIN_CLASS_MAP_ADD_CLASS(
+               WRT_JS_EXTENSION_OBJECT_TIZEN,
+               "TimeDuration",
+               (js_class_template_getter)TizenApis::Tizen1_0::JSTimeDuration::getClassRef,
+               NULL)
+PLUGIN_CLASS_MAP_END
diff --git a/src/standards/Tizen/Tizen/CMakeLists.txt b/src/standards/Tizen/Tizen/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..8a168f7
--- /dev/null
@@ -0,0 +1,53 @@
+set(TARGET_NAME       "wrt-plugins-tizen-2.0-tizen")
+set(DESTINATION_NAME  "tizen-2.0-tizen")
+set(TARGET_IMPL_NAME  "wrt-plugins-tizen-2.0-tizen-impl")
+
+pkg_search_module(wrt-plugins-plugin-manager REQUIRED wrt-plugins-plugin-manager)
+
+include_directories(
+    ${wrt-plugins-plugin-manager_INCLUDE_DIRS}
+)
+
+set(CMAKE_INSTALL_RPATH
+  ${CMAKE_INSTALL_RPATH}
+  ${CMAKE_INSTALL_PREFIX}/${DESTINATION_NAME}
+  ${CMAKE_INSTALL_PREFIX}/tizen-2.0-time
+)
+
+set(SRCS_IMPL
+  ${SRCS_PLATFORM_API_FILTER}
+  JSTizen.cpp
+  JSAttributeFilter.cpp
+  JSAttributeRangeFilter.cpp
+  JSCompositeFilter.cpp
+  JSAbstractFilterArray.cpp
+  JSSortMode.cpp
+  FilterConverter.cpp
+  JSSimpleCoordinates.cpp
+  JSFeature.cpp
+  JSFeatureParam.cpp
+  plugin_config.cpp
+  PluginOnDemandPriv.cpp
+)
+
+add_library(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
+
+target_link_libraries(${TARGET_IMPL_NAME}
+    wrt-plugins-tizen-2.0-time-impl
+    ${LIBS_WIDGETDB}
+    ${LIBS_COMMON}
+    ${wrt-plugins-plugin-manager_LIBRARIES}
+)
+
+set(SRCS
+  plugin_initializer.cpp
+)
+
+add_library(${TARGET_NAME} SHARED ${SRCS})
+
+target_link_libraries(${TARGET_NAME}
+    ${TARGET_IMPL_NAME}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_NAME})
diff --git a/src/standards/Tizen/Tizen/FilterConverter.cpp b/src/standards/Tizen/Tizen/FilterConverter.cpp
new file mode 100755 (executable)
index 0000000..42acd5c
--- /dev/null
@@ -0,0 +1,506 @@
+//
+// 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        FilterConverter.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @description        Reference from CalendarConverter.cpp
+ */
+
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <CommonsJavaScript/Validator.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include "JSAttributeFilter.h"
+#include "JSAttributeRangeFilter.h"
+#include "JSCompositeFilter.h"
+#include "JSAbstractFilterArray.h"
+#include "JSSortMode.h"
+#include "FilterConverter.h"
+
+#define TIZEN_FILTER_CONVERTER_ATTRIBUTE_TYPE                          "type"
+#define TIZEN_FILTER_CONVERTER_ATTRIBUTE_ORDER                         "order"
+#define TIZEN_FILTER_CONVERTER_ATTRIBUTE_FILTERS                       "filters"
+#define TIZEN_FILTER_CONVERTER_ATTRIBUTE_IDS                           "ids"
+#define TIZEN_FILTER_CONVERTER_ATTRIBUTE_ATTRIBUTE_NAME                "attributeName"
+#define TIZEN_FILTER_CONVERTER_ATTRIBUTE_MATCH_FLAG                    "matchFlag"
+#define TIZEN_FILTER_CONVERTER_ATTRIBUTE_MATCH_VALUES          "matchValues"
+#define TIZEN_FILTER_CONVERTER_ATTRIBUTE_INITIAL_VALUE         "initialValue"
+#define TIZEN_FILTER_CONVERTER_ATTRIBUTE_END_VALUE                     "endValue"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+using namespace std;
+
+FilterConverter::FilterConverter(JSContextRef context) : Converter(context)
+{
+       initFilterAttrs();
+}
+
+FilterConverter::~FilterConverter()
+{
+       LogDebug("entered");
+}
+
+JSValueRef FilterConverter::toJSValueRef(FilterPtr arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "Filter is NULL.");
+
+       JSValueRef result = NULL;
+
+       if(arg->getFilterType() == UNION_FILTER || arg->getFilterType() == INTERSECTION_FILTER)
+       {
+               CompositeFilterPtr filter = DPL::DynamicPointerCast<CompositeFilter>(arg);
+
+               result = toJSValueRef(filter);
+       }
+       else if(arg->getFilterType() == ATTRIBUTE_FILTER)
+       {
+               AttributeFilterPtr filter = DPL::DynamicPointerCast<AttributeFilter>(arg);
+
+               result = toJSValueRef(filter);
+       }
+       else if(arg->getFilterType() == ATTRIBUTE_RANGE_FILTER)
+       {
+               AttributeRangeFilterPtr filter = DPL::DynamicPointerCast<AttributeRangeFilter>(arg);
+
+               result = toJSValueRef(filter);
+       }
+
+       return result;
+}
+
+FilterPtr FilterConverter::toFilter(const JSValueRef& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       if(!JSValueIsObject(m_context, arg))
+               ThrowMsg(InvalidArgumentException, "Filter is not object.");
+
+       if(JSCompositeFilter::isObjectOfClass(m_context, arg))
+               return DPL::StaticPointerCast<IFilter>(JSCompositeFilter::getCompositeFilter(m_context, arg));
+
+       if(JSAttributeFilter::isObjectOfClass(m_context, arg))
+               return DPL::StaticPointerCast<IFilter>(JSAttributeFilter::getAttributeFilter(m_context, arg));
+
+       if(JSAttributeRangeFilter::isObjectOfClass(m_context, arg))
+               return DPL::StaticPointerCast<IFilter>(JSAttributeRangeFilter::getAttributeRangeFilter(m_context, arg));
+
+       ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+       return FilterPtr(NULL);
+}
+
+JSValueRef FilterConverter::toJSValueRef(const FilterArrayPtr& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "FilterArray is NULL.");
+
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSAbstractFilterArray::getClassRef(), arg);
+}
+
+FilterArrayPtr FilterConverter::toFilterArray(const JSValueRef& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       if(JSAbstractFilterArray::isObjectOfClass(m_context, arg))
+               return JSAbstractFilterArray::getAbstractFilterArray(m_context, arg);
+
+       if(!JSIsArrayValue(m_context, arg))
+               ThrowMsg(InvalidArgumentException, "JSValueRef is not Array.");
+
+       FilterArrayPtr retVal;
+
+       JSObjectRef obj = toJSObjectRef(arg);
+       retVal = FilterArrayPtr(new FilterArray());
+
+       unsigned int length = JSGetArrayLength(m_context, obj);
+       for(unsigned int i=0; i<length; i++)
+       {
+               JSValueRef value = JSGetArrayElement(m_context, obj, i);
+
+               if(JSValueIsNull(m_context, value) ||  JSValueIsUndefined(m_context, value)) {
+                       ThrowMsg(InvalidArgumentException, "CompositeFilter.filters has null elements.");
+               }
+
+               FilterPtr filter;
+               Try {
+                       filter = toFilter(value);
+               } Catch (Exception) {
+                       ThrowMsg(InvalidArgumentException, "Element is not an AbstractFilter (" << i << ")");
+               }
+
+               retVal->push_back(filter);
+       }
+
+       return retVal;
+}
+
+JSValueRef FilterConverter::toJSValueRef(const CompositeFilterPtr& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "CompositeFilter is NULL.");
+
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSCompositeFilter::getClassRef(), arg);
+}
+
+CompositeFilterPtr FilterConverter::toCompositeFilter(const JSValueRef& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       if(!JSCompositeFilter::isObjectOfClass(m_context, arg))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+
+       return JSCompositeFilter::getCompositeFilter(m_context, arg);
+}
+
+JSValueRef FilterConverter::toJSValueRef(const AttributeFilterPtr& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "AttributeFilter is NULL.");
+
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSAttributeFilter::getClassRef(), arg);
+}
+
+AttributeFilterPtr FilterConverter::toAttributeFilter(const JSValueRef& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       if(!JSAttributeFilter::isObjectOfClass(m_context, arg))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+
+       return JSAttributeFilter::getAttributeFilter(m_context, arg);
+}
+
+JSValueRef FilterConverter::toJSValueRef(const AttributeRangeFilterPtr& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "AttributeRangeFilter is NULL.");
+
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSAttributeRangeFilter::getClassRef(), arg);
+}
+
+AttributeRangeFilterPtr FilterConverter::toAttributeRangeFilter(const JSValueRef& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       if(!JSAttributeRangeFilter::isObjectOfClass(m_context, arg))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+
+       return JSAttributeRangeFilter::getAttributeRangeFilter(m_context, arg);
+}
+
+JSValueRef FilterConverter::toJSValueRef(const SortModePtr& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "SortMode is NULL.");
+
+       return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSSortMode::getClassRef(), arg);
+}
+
+SortModePtr FilterConverter::toSortMode(const JSValueRef& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       if(!JSSortMode::isObjectOfClass(m_context, arg))
+               ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute");
+
+       return JSSortMode::getSortMode(m_context, arg);
+}
+
+JSValueRef FilterConverter::toJSValueRef(const SortModeArrayPtr& arg)
+{
+       // Not used any more.
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "SortModeArray is NULL.");
+
+       int size = arg->size();
+
+       JSObjectRef resultObject = JSCreateArrayObject(m_context, 0, NULL);
+       if (!resultObject)
+               ThrowMsg(ConversionException, "Can not create array object.");
+
+       for(int i = 0; i < size; i++)
+       {
+               JSValueRef jsvalue = toJSValueRef(arg->at(i));
+               if (!JSSetArrayElement(m_context, resultObject, i, jsvalue))
+                       ThrowMsg(ConversionException, "Can not fill SortMode array.");
+       }
+
+       return static_cast<JSValueRef>(resultObject);
+}
+
+SortModeArrayPtr FilterConverter::toSortModeArray(const JSValueRef& arg)
+{
+       // Not used any more.
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       if(!JSIsArrayValue(m_context, arg))
+               ThrowMsg(InvalidArgumentException, "Not an array type.");
+
+       SortModeArrayPtr sortModeArray = SortModeArrayPtr(new SortModeArray());
+       JSObjectRef object = toJSObjectRef(arg);
+
+       unsigned int length = JSGetArrayLength(m_context, object);
+       for(unsigned int i=0; i<length; i++)
+       {
+               JSValueRef value = JSGetArrayElement(m_context, object, i);
+
+               if(JSValueIsNull(m_context, value) ||  JSValueIsUndefined(m_context, value)) {
+                       ThrowMsg(InvalidArgumentException, "CompositeFilter.filters has null elements.");
+               }
+
+               SortModePtr sortMode = toSortMode(value);
+
+               sortModeArray->push_back(sortMode);
+       }
+
+       return sortModeArray;
+}
+
+JSValueRef FilterConverter::toJSValueRef(const AnyPtr& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "Any is NULL.");
+
+       AnyTypeConverterFactory::ConverterType converter =
+                       AnyTypeConverterFactory::getConverter(m_context);
+
+       return converter->toJSValueRef(arg);
+}
+
+AnyPtr FilterConverter::toAny(const JSValueRef& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       AnyArrayPtr retVal;
+
+       AnyTypeConverterFactory::ConverterType converter =
+                       AnyTypeConverterFactory::getConverter(m_context);
+
+       return converter->toAny(arg);
+}
+
+JSValueRef FilterConverter::toJSValueRef(const AnyArrayPtr& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "AnyArray is NULL.");
+
+       AnyTypeConverterFactory::ConverterType converter =
+                       AnyTypeConverterFactory::getConverter(m_context);
+
+       int size = arg->size();
+
+       JSObjectRef resultObject = JSCreateArrayObject(m_context, 0, NULL);
+       if (!resultObject)
+               ThrowMsg(ConversionException, "Can not create array object.");
+
+       for(int i = 0; i < size; i++)
+       {
+               JSValueRef jsvalue = converter->toJSValueRef(arg->at(i));
+               if (!JSSetArrayElement(m_context, resultObject, i, jsvalue))
+                       ThrowMsg(ConversionException, "Can not fill any array.");
+       }
+
+       return static_cast<JSValueRef>(resultObject);
+}
+
+AnyArrayPtr FilterConverter::toAnyArray(const JSValueRef& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       AnyArrayPtr retVal;
+
+       retVal = AnyArrayPtr(new AnyArray());
+
+       JSObjectRef obj = toJSObjectRef(arg);
+       AnyTypeConverterFactory::ConverterType converter =
+                       AnyTypeConverterFactory::getConverter(m_context);
+
+       unsigned int length = JSGetArrayLength(m_context, obj);
+       for(unsigned int i=0; i<length; i++)
+       {
+               JSValueRef value = JSGetArrayElement(m_context, obj, i);
+
+               if(JSValueIsNull(m_context, value) ||  JSValueIsUndefined(m_context, value)) {
+                       ThrowMsg(InvalidArgumentException, "IDFilter.ids has null elements.");
+               }
+               AnyPtr any = converter->toAny(value);
+
+               retVal->push_back(any);
+       }
+
+       return retVal;
+}
+
+JSValueRef FilterConverter::toJSValueRef(const FilterType& arg)
+{
+       string compositeFilterTypeStr;
+
+       if(arg == UNION_FILTER)
+               compositeFilterTypeStr = "UNION";
+       else if(arg == INTERSECTION_FILTER)
+               compositeFilterTypeStr = "INTERSECTION";
+       else
+               ThrowMsg(ConversionException, "Can not create CompositeFilterType.");
+
+       return toJSValueRef(compositeFilterTypeStr);
+}
+
+FilterType FilterConverter::toCompositeFilterType(const JSValueRef& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       if(!JSValueIsString(m_context, arg))
+               ThrowMsg(InvalidArgumentException, "Value is not an string.");
+
+       string compositeFilterTypeStr = toString(arg);
+       FilterType compositeFilterType;
+
+       if(compositeFilterTypeStr == "UNION")
+               compositeFilterType = UNION_FILTER;
+       else if(compositeFilterTypeStr == "INTERSECTION")
+               compositeFilterType = INTERSECTION_FILTER;
+       else
+               ThrowMsg(InvalidArgumentException, "CompositeFilterType cannot have " << compositeFilterTypeStr);
+
+       return compositeFilterType;
+}
+
+JSValueRef FilterConverter::toJSValueRef(const MatchFlag& arg)
+{
+       string matchFlagStr;
+
+       if(arg == MATCH_EXACTLY)
+               matchFlagStr = "EXACTLY";
+       else if(arg == MATCH_FULLSTRING)
+               matchFlagStr = "FULLSTRING";
+       else if(arg == MATCH_CONTAINS)
+               matchFlagStr = "CONTAINS";
+       else if(arg == MATCH_STARTSWITH)
+               matchFlagStr = "STARTSWITH";
+       else if(arg == MATCH_ENDSWITH)
+               matchFlagStr = "ENDSWITH";
+       else if(arg == MATCH_EXISTS)
+               matchFlagStr = "EXISTS";
+       else
+               ThrowMsg(ConversionException, "Can not create MatchFlag.");
+
+       return toJSValueRef(matchFlagStr);
+}
+
+MatchFlag FilterConverter::toMatchFlag(const JSValueRef& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       if(!JSValueIsString(m_context, arg))
+               ThrowMsg(InvalidArgumentException, "Value is not an string.");
+
+       string matchFlagStr = toString(arg);
+       MatchFlag matchFlag;
+
+       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
+               ThrowMsg(InvalidArgumentException, "FilterMatchFlag cannot have " << matchFlagStr);
+
+       return matchFlag;
+}
+
+JSValueRef FilterConverter::toJSValueRef(const SortOrder& arg)
+{
+       string sortOrderStr;
+
+       if(arg == ASCENDING_SORT_ORDER)
+               sortOrderStr = "ASC";
+       else if(arg == DESCENDING_SORT_ORDER)
+               sortOrderStr = "DESC";
+       else
+               ThrowMsg(ConversionException, "Can not create SortModeOrder.");
+
+       return toJSValueRef(sortOrderStr);
+}
+
+SortOrder FilterConverter::toSortOrder(const JSValueRef& arg)
+{
+       if(arg == NULL)
+               ThrowMsg(NullPointerException, "JSValueRef is NULL.");
+
+       if(!JSValueIsString(m_context, arg))
+               ThrowMsg(InvalidArgumentException, "Value is not an string.");
+
+       string sortOrderStr = toString(arg);
+       SortOrder sortOrder;
+
+       if(sortOrderStr == "ASC")
+               sortOrder = ASCENDING_SORT_ORDER;
+       else if(sortOrderStr == "DESC")
+               sortOrder = DESCENDING_SORT_ORDER;
+       else
+               ThrowMsg(InvalidArgumentException, "SortModeOrder cannot have " << sortOrderStr);
+
+       return sortOrder;
+}
+
+void FilterConverter::initFilterAttrs()
+{
+       m_compositeFilterAttrs.push_back(TIZEN_FILTER_CONVERTER_ATTRIBUTE_TYPE);
+       m_compositeFilterAttrs.push_back(TIZEN_FILTER_CONVERTER_ATTRIBUTE_FILTERS);
+
+       m_attributeFilterAttrs.push_back(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ATTRIBUTE_NAME);
+       m_attributeFilterAttrs.push_back(TIZEN_FILTER_CONVERTER_ATTRIBUTE_MATCH_FLAG);
+       m_attributeFilterAttrs.push_back(TIZEN_FILTER_CONVERTER_ATTRIBUTE_MATCH_VALUES);
+
+       m_attributeRangeFilterAttrs.push_back(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ATTRIBUTE_NAME);
+       m_attributeRangeFilterAttrs.push_back(TIZEN_FILTER_CONVERTER_ATTRIBUTE_INITIAL_VALUE);
+       m_attributeRangeFilterAttrs.push_back(TIZEN_FILTER_CONVERTER_ATTRIBUTE_END_VALUE);
+
+       m_sortModeAttrs.push_back(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ORDER);
+       m_sortModeAttrs.push_back(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ATTRIBUTE_NAME);
+}
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Tizen/FilterConverter.h b/src/standards/Tizen/Tizen/FilterConverter.h
new file mode 100755 (executable)
index 0000000..b61cc32
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// 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        FilterConverter.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @description        Reference from CalendarConverter.h
+ */
+
+#ifndef _TIZEN_FILTER_CONVERTER_H_
+#define _TIZEN_FILTER_CONVERTER_H_
+
+#include <vector>
+#include <string>
+#include <CommonsJavaScript/Converter.h>
+#include <API/Filter/IFilter.h>
+#include <API/Filter/CompositeFilter.h>
+#include <API/Filter/AttributeFilter.h>
+#include <API/Filter/AttributeRangeFilter.h>
+#include <API/Filter/SortMode.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+class FilterConverter : public WrtDeviceApis::CommonsJavaScript::Converter
+{
+public:
+       using WrtDeviceApis::CommonsJavaScript::Converter::toJSValueRef;
+public:
+       explicit FilterConverter(JSContextRef context);
+       virtual ~FilterConverter();
+
+       JSValueRef toJSValueRef(TizenApis::Api::Tizen::FilterPtr arg);
+       TizenApis::Api::Tizen::FilterPtr toFilter(const JSValueRef& arg);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Tizen::FilterArrayPtr& arg);
+       TizenApis::Api::Tizen::FilterArrayPtr toFilterArray(const JSValueRef& arg);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Tizen::CompositeFilterPtr& arg);
+       TizenApis::Api::Tizen::CompositeFilterPtr toCompositeFilter(const JSValueRef& arg);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Tizen::AttributeFilterPtr& arg);
+       TizenApis::Api::Tizen::AttributeFilterPtr toAttributeFilter(const JSValueRef& arg);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Tizen::AttributeRangeFilterPtr& arg);
+       TizenApis::Api::Tizen::AttributeRangeFilterPtr toAttributeRangeFilter(const JSValueRef& arg);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Tizen::SortModePtr& arg);
+       TizenApis::Api::Tizen::SortModePtr toSortMode(const JSValueRef& arg);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Tizen::SortModeArrayPtr& arg);
+       TizenApis::Api::Tizen::SortModeArrayPtr toSortModeArray(const JSValueRef& arg);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Tizen::AnyPtr& arg);
+       TizenApis::Api::Tizen::AnyPtr toAny(const JSValueRef& arg);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Tizen::AnyArrayPtr& arg);
+       TizenApis::Api::Tizen::AnyArrayPtr toAnyArray(const JSValueRef& arg);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Tizen::FilterType& arg);
+       TizenApis::Api::Tizen::FilterType toCompositeFilterType(const JSValueRef& arg);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Tizen::MatchFlag& arg);
+       TizenApis::Api::Tizen::MatchFlag toMatchFlag(const JSValueRef& arg);
+
+       JSValueRef toJSValueRef(const TizenApis::Api::Tizen::SortOrder& arg);
+       TizenApis::Api::Tizen::SortOrder toSortOrder(const JSValueRef& arg);
+
+private:
+       std::vector<std::string> m_compositeFilterAttrs;
+       std::vector<std::string> m_attributeFilterAttrs;
+       std::vector<std::string> m_attributeRangeFilterAttrs;
+       std::vector<std::string> m_sortModeAttrs;
+
+       void initFilterAttrs();
+};
+
+typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory<FilterConverter> FilterConverterFactory;
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_FILTER_CONVERTER_H_
diff --git a/src/standards/Tizen/Tizen/JSAbstractFilterArray.cpp b/src/standards/Tizen/Tizen/JSAbstractFilterArray.cpp
new file mode 100755 (executable)
index 0000000..4c14e7a
--- /dev/null
@@ -0,0 +1,636 @@
+//
+// 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        JSAbstractFilterArray.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <algorithm>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/ScopedJSStringRef.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "FilterConverter.h"
+#include "JSAbstractFilterArray.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"
+#define FUNCTION_CONSTRUCTOR "constructor"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSAbstractFilterArray::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 JSAbstractFilterArray::m_property[] = {
+       { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSAbstractFilterArray::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 },
+       { FUNCTION_CONSTRUCTOR, constructor, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete },
+       { 0, 0, 0 }
+};
+
+JSClassRef JSAbstractFilterArray::m_jsClassRef = JSClassCreate(
+               JSAbstractFilterArray::getClassInfo());
+
+JSValueRef JSAbstractFilterArray::getLength(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       //LogDebug("enter");
+       Try
+       {
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               FilterArrayPtr filters = priv->getObject();
+               if (filters) {
+                       FilterConverterFactory::ConverterType converter =
+                                       FilterConverterFactory::getConverter(context);
+                       return converter->toJSValueRef(filters->size());
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid conversion");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSAbstractFilterArray::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+FilterArrayPtr JSAbstractFilterArray::getAbstractFilterArray(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSAbstractFilterArrayPriv *priv = static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+JSObjectRef JSAbstractFilterArray::createArray(JSContextRef context,
+               const FilterArrayPtr &filters)
+{
+       JSAbstractFilterArrayPriv *priv = new JSAbstractFilterArrayPriv(context, filters);
+       return JSObjectMake(context, getClassRef(), priv);
+}
+
+const JSClassDefinition* JSAbstractFilterArray::getClassInfo()
+{
+       return &(m_classInfo);
+}
+
+JSClassRef JSAbstractFilterArray::getClassRef()
+{
+       if (!m_jsClassRef) {
+               m_jsClassRef = JSClassCreate(&m_classInfo);
+       }
+       return m_jsClassRef;
+}
+
+void JSAbstractFilterArray::initialize(JSContextRef context,
+               JSObjectRef object)
+{
+       //LogDebug("enter");
+}
+
+void JSAbstractFilterArray::finalize(JSObjectRef object)
+{
+       //LogDebug("enter");
+       JSAbstractFilterArrayPriv* priv =
+               static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(object));
+       delete priv;
+       JSObjectSetPrivate(object, NULL);
+}
+
+bool JSAbstractFilterArray::hasProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName)
+{
+       //LogDebug("enter");
+       FilterConverterFactory::ConverterType converter =
+                       FilterConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               FilterArrayPtr filters = priv->getObject();
+               if (index < filters->size()) {
+                       return true;
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               //not reporting error is intended
+       }
+       return false;
+}
+
+JSValueRef JSAbstractFilterArray::getProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       //LogDebug("enter");
+       FilterConverterFactory::ConverterType converter =
+                       FilterConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               FilterArrayPtr filters = priv->getObject();
+               if (index < filters->size()) {
+                       FilterPtr result = filters->at(index);
+                       if (result) {
+                               return converter->toJSValueRef(result);
+                       }
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("invalid property");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSAbstractFilterArray::setProperty(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       //LogDebug("enter");
+       FilterConverterFactory::ConverterType converter =
+                       FilterConverterFactory::getConverter(context);
+       Try
+       {
+               size_t index = converter->toSizeT(propertyName);
+               FilterPtr filter;
+               if (!JSValueIsUndefined(context, value)) {
+                       filter = converter->toFilter(value);
+               }
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               FilterArrayPtr filters = priv->getObject();
+               if (!filters) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               if (filters->size() <= index) {
+                       filters->resize(index + 1);
+               }
+               (*filters)[index] = filter;
+               return true;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+               JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+       }
+       return false;
+}
+
+void JSAbstractFilterArray::getPropertyNames(JSContextRef context,
+               JSObjectRef object,
+               JSPropertyNameAccumulatorRef propertyNames)
+{
+       FilterConverterFactory::ConverterType converter =
+                       FilterConverterFactory::getConverter(context);
+       Try
+       {
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(object));
+               if (!priv) {
+                       Throw(WrtDeviceApis::Commons::NullPointerException);
+               }
+               FilterArrayPtr filters = priv->getObject();
+
+               int count = filters->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 JSAbstractFilterArray::concat(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("enter");
+       Try
+       {
+               FilterArrayPtr filters = FilterArrayPtr(new FilterArray());
+               JSAbstractFilterArrayPriv *newPrivateObject = new JSAbstractFilterArrayPriv(context, filters);
+               JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject);
+
+               //copy current filters
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(thisObject));
+               FilterArrayPtr currentWebSites = priv->getObject();
+               for (size_t i = 0; i < currentWebSites->size(); ++i) {
+                       filters->push_back(currentWebSites->at(i));
+               }
+
+               //copy submitted arrays
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::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);
+                               filters->push_back(converter->toFilter(att));
+                       }
+               }
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSAbstractFilterArray::join(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("entered");
+       Try
+       {
+               std::string result;
+               std::string separator(",");
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(thisObject));
+               FilterArrayPtr currentWebSites = priv->getObject();
+               if (argumentCount > 0 && JSValueIsString(context, arguments[0])) {
+                       separator = converter->toString(arguments[0]);
+               }
+               for (size_t i = 0; i < currentWebSites->size(); ++i) {
+                       if (i != 0) {
+                               result += separator;
+                       }
+                       //FIXME : to be changed to support join
+                       //result += currentWebSites->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 JSAbstractFilterArray::pop(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(thisObject));
+               FilterArrayPtr currentWebSites = priv->getObject();
+               if (currentWebSites->size() > 0) {
+                       FilterPtr result = currentWebSites->at(
+                                       currentWebSites->size() - 1);
+                       currentWebSites->pop_back();
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAbstractFilterArray::push(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(thisObject));
+               FilterArrayPtr currentWebSites = priv->getObject();
+               for (size_t i = 0; i < argumentCount; ++i) {
+                       currentWebSites->push_back(converter->toFilter(arguments[i]));
+               }
+               return converter->toJSValueRef(currentWebSites->size());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSAbstractFilterArray::reverse(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(thisObject));
+               FilterArrayPtr currentWebSites = priv->getObject();
+               std::reverse(currentWebSites->begin(), currentWebSites->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAbstractFilterArray::shift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(thisObject));
+               FilterArrayPtr currentWebSites = priv->getObject();
+               if (currentWebSites->size() > 0) {
+                       FilterPtr result = currentWebSites->at(0);
+                       currentWebSites->erase(currentWebSites->begin());
+                       return converter->toJSValueRef(result);
+               }
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAbstractFilterArray::slice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("enter");
+       Try
+       {
+               if (argumentCount < 1) {
+                       return JSValueMakeUndefined(context);
+               }
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               FilterArrayPtr filters = FilterArrayPtr(new FilterArray());
+               JSAbstractFilterArrayPriv *newPrivateObject = new JSAbstractFilterArrayPriv(
+                               context,
+                               filters);
+               JSValueRef result = JSObjectMake(context,
+                                                                                getClassRef(), newPrivateObject);
+
+               //copy current filters
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(thisObject));
+               FilterArrayPtr currentWebSites = priv->getObject();
+               std::size_t first = converter->toSizeT(arguments[0]);
+               std::size_t last = currentWebSites->size() - 1;
+               if (argumentCount > 1) {
+                       last = converter->toSizeT(arguments[1]);
+                       if (last >= currentWebSites->size()) {
+                               last = currentWebSites->size() - 1;
+                       }
+               }
+               for (size_t i = first; i <= last; ++i) {
+                       filters->push_back(currentWebSites->at(i));
+               }
+
+               return result;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mismatch");
+}
+
+JSValueRef JSAbstractFilterArray::sort(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               JSAbstractFilterArrayPriv* priv =
+                       static_cast<JSAbstractFilterArrayPriv*>(JSObjectGetPrivate(thisObject));
+               FilterArrayPtr currentWebSites = priv->getObject();
+               std::sort(currentWebSites->begin(), currentWebSites->end());
+               return thisObject;
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogError("error occured");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAbstractFilterArray::splice(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("entered");
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAbstractFilterArray::toString(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("entered");
+       return join(context, function, thisObject, 0, arguments, exception);
+}
+
+JSValueRef JSAbstractFilterArray::unshift(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("entered");
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAbstractFilterArray::valueOf(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       //LogDebug("entered");
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSAbstractFilterArray::constructor(JSContextRef context,
+               JSObjectRef function,
+               JSObjectRef thisObject,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       // To determine this object as array
+       WrtDeviceApis::CommonsJavaScript::ScopedJSStringRef json(JSStringCreateWithUTF8CString("[]"));
+       JSValueRef array = JSValueMakeFromJSONString(context, json.get());
+       WrtDeviceApis::CommonsJavaScript::ScopedJSStringRef constructorStr(JSStringCreateWithUTF8CString("constructor"));
+       JSObjectRef arrayObject = JSValueToObject(context, array, NULL);
+       JSValueRef constructorValue = JSObjectGetProperty(context, arrayObject, constructorStr.get(), NULL);
+       return constructorValue;
+}
+
+} // Contact
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Tizen/JSAbstractFilterArray.h b/src/standards/Tizen/Tizen/JSAbstractFilterArray.h
new file mode 100755 (executable)
index 0000000..f48a7f6
--- /dev/null
@@ -0,0 +1,193 @@
+//
+// 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        JSAbstractFilterArray.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_TIZEN_JS_ABSTRACT_FILTER_ARRAY_H_
+#define _TIZEN_TIZEN_JS_ABSTRACT_FILTER_ARRAY_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <API/Filter/IFilter.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT< TizenApis::Api::Tizen::FilterArrayPtr >::Type JSAbstractFilterArrayPriv;
+
+class JSAbstractFilterArray
+{
+public:
+
+       static const JSClassDefinition* getClassInfo();
+
+       static JSClassRef getClassRef();
+
+       static JSObjectRef createArray(JSContextRef context,
+                       const TizenApis::Api::Tizen::FilterArrayPtr &filterArray);
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Tizen::FilterArrayPtr getAbstractFilterArray(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 JSValueRef constructor(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[];
+};
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_TIZEN_JS_ABSTRACT_FILTER_ARRAY_H_
diff --git a/src/standards/Tizen/Tizen/JSAttributeFilter.cpp b/src/standards/Tizen/Tizen/JSAttributeFilter.cpp
new file mode 100755 (executable)
index 0000000..95b5a5c
--- /dev/null
@@ -0,0 +1,402 @@
+//
+// 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        JSAttributeFilter.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSAttributeFilter class
+ */
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <API/Filter/AttributeFilter.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "FilterConverter.h"
+#include "JSAttributeFilter.h"
+
+#define ATTRIBUTE_FILTER_CLASS_NAME "AttributeFilter"
+
+#define ATTRIBUTE_FILTER_ATTR_ATTRIBUTE_NAME "attributeName"
+#define ATTRIBUTE_FILTER_ATTR_MATCH_FLAG "matchFlag"
+#define ATTRIBUTE_FILTER_ATTR_MATCH_VALUE "matchValue"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassRef JSAttributeFilter::m_classRef = NULL;
+
+JSClassDefinition JSAttributeFilter::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       ATTRIBUTE_FILTER_CLASS_NAME,
+       NULL,
+       m_property,
+       m_functions,
+       Initialize,
+       Finalize,
+       NULL, //hasProperty,
+       NULL, //GetProperty,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //getPropertyNames,
+       NULL, //CallAsFunction,
+       constructor, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL, //ConvertToType,
+};
+
+JSStaticValue JSAttributeFilter::m_property[] = {
+       { ATTRIBUTE_FILTER_ATTR_ATTRIBUTE_NAME, getAttributeName, setAttributeName, kJSPropertyAttributeNone },
+       { ATTRIBUTE_FILTER_ATTR_MATCH_FLAG, getMatchFlag, setMatchFlag, kJSPropertyAttributeNone },
+       { ATTRIBUTE_FILTER_ATTR_MATCH_VALUE, getMatchValue, setMatchValue, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSAttributeFilter::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSAttributeFilter::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSAttributeFilter::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+AttributeFilterPtr JSAttributeFilter::getAttributeFilter(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSAttributeFilterPriv *priv = static_cast<JSAttributeFilterPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+JSObjectRef JSAttributeFilter::createJSObject(JSContextRef context, AttributeFilterPtr privateData)
+{
+       JSAttributeFilterPriv *priv = new JSAttributeFilterPriv(context, privateData);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+void JSAttributeFilter::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               AttributeFilterPtr filter(new AttributeFilter("", MATCH_NONE, AnyPtr(NULL)));
+               JSAttributeFilterPriv *priv = new JSAttributeFilterPriv(context, AttributeFilterPtr(filter));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSAttributeFilter::Finalize(JSObjectRef object)
+{
+       JSAttributeFilterPriv *priv = static_cast<JSAttributeFilterPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+       {
+               delete (priv);
+       }
+
+       priv = NULL;
+}
+
+AttributeFilterPtr JSAttributeFilter::getPrivData(JSObjectRef object)
+{
+       LogDebug("entered");
+       JSAttributeFilterPriv *priv = static_cast<JSAttributeFilterPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       AttributeFilterPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSObjectRef JSAttributeFilter::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       bool js2ndParamIsString = false;
+       bool js3rdParamIsValue = false;
+
+//     AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADD);
+//     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       JSAttributeFilterPriv *priv = static_cast<JSAttributeFilterPriv*>(JSObjectGetPrivate(constructor));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       JSContextRef gContext = priv->getContext();
+
+//     JSContextRef gContext = JSGlobalContextFactory::getInstance()->get();
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(context, exception);
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
+
+               if (!JSValueIsString(gContext, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument is not string.");
+
+               if (argumentCount >= 2)
+               {
+                       if (JSValueIsString(gContext, arguments[1]))
+                               js2ndParamIsString = true;
+
+                       if (!js2ndParamIsString &&
+                                       !JSValueIsNull(gContext, arguments[1]) &&
+                                       !JSValueIsUndefined(gContext, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "2nd argument is not array.");
+               }
+
+               if (argumentCount >= 3)
+               {
+                       if (!JSValueIsNull(gContext, arguments[2]) && !JSValueIsUndefined(gContext, 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(gContext);
+
+       std::string attributeName;
+       MatchFlag matchFlag;
+       AnyPtr matchValue(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;
+       }
+
+       Try {
+               if(js2ndParamIsString)
+                       matchFlag = converter->toMatchFlag(arguments[1]);
+               else
+                       matchFlag = MATCH_EXACTLY;
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       Try {
+               if(js3rdParamIsValue)
+                       matchValue = converter->toAny(arguments[2]);
+               else
+                       matchValue = AnyPtr(new Any());
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       AttributeFilterPtr attributeFilter(new AttributeFilter(attributeName, matchFlag, matchValue));
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, attributeFilter);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+JSValueRef JSAttributeFilter::getAttributeName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               AttributeFilterPtr attributeFilter = getPrivData(object);
+               return converter->toJSValueRef(attributeFilter->getAttributeName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSAttributeFilter::setAttributeName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               AttributeFilterPtr attributeFilter = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               attributeFilter->setAttributeName(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 JSAttributeFilter::getMatchFlag(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               AttributeFilterPtr attributeFilter = getPrivData(object);
+               return converter->toJSValueRef(attributeFilter->getMatchFlag());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSAttributeFilter::setMatchFlag(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               AttributeFilterPtr attributeFilter = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               attributeFilter->setMatchFlag(converter->toMatchFlag(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 JSAttributeFilter::getMatchValue(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               AttributeFilterPtr attributeFilter = getPrivData(object);
+               return converter->toJSValueRef(attributeFilter->getMatchValue());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+
+       return JSValueMakeUndefined(context);
+}
+
+bool JSAttributeFilter::setMatchValue(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               AttributeFilterPtr attributeFilter = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               attributeFilter->setMatchValue(converter->toAny(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;
+}
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Tizen/JSAttributeFilter.h b/src/standards/Tizen/Tizen/JSAttributeFilter.h
new file mode 100755 (executable)
index 0000000..fc8c321
--- /dev/null
@@ -0,0 +1,128 @@
+//
+// 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        JSAttributeFilter.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSAttributeFilter class
+ */
+
+#ifndef _TIZEN_TIZEN_JS_ATTRIBUTE_FILTER_H_
+#define _TIZEN_TIZEN_JS_ATTRIBUTE_FILTER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Filter/AttributeFilter.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Tizen::AttributeFilterPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSAttributeFilterPriv;
+
+class JSAttributeFilter {
+public:
+       /*
+        * This initializes this JS class in the JS Engine.
+        */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Tizen::AttributeFilterPtr getAttributeFilter(JSContextRef context, JSValueRef value);
+
+       static JSObjectRef createJSObject(JSContextRef context, TizenApis::Api::Tizen::AttributeFilterPtr privateData);
+
+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 TizenApis::Api::Tizen::AttributeFilterPtr getPrivData(JSObjectRef object);
+
+       static JSObjectRef constructor(JSContextRef context,
+                       JSObjectRef constructor,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef getAttributeName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setAttributeName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getMatchFlag(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setMatchFlag(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getMatchValue(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setMatchValue(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+};
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_TIZEN_JS_ATTRIBUTE_FILTER_H_
diff --git a/src/standards/Tizen/Tizen/JSAttributeRangeFilter.cpp b/src/standards/Tizen/Tizen/JSAttributeRangeFilter.cpp
new file mode 100755 (executable)
index 0000000..73f75ac
--- /dev/null
@@ -0,0 +1,395 @@
+//
+// 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        JSAttributeRangeFilter.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSAttributeRangeFilter class
+ */
+
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <API/Filter/AttributeRangeFilter.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "FilterConverter.h"
+#include "JSAttributeRangeFilter.h"
+
+#define ATTRIBUTE_RANGE_FILTER_CLASS_NAME "AttributeRangeFilter"
+
+#define ATTRIBUTE_FILTER_ATTR_ATTRIBUTE_NAME "attributeName"
+#define ATTRIBUTE_FILTER_ATTR_INITIAL_VALUE "initialValue"
+#define ATTRIBUTE_FILTER_ATTR_END_VALUE "endValue"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassRef JSAttributeRangeFilter::m_classRef = NULL;
+
+JSClassDefinition JSAttributeRangeFilter::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       ATTRIBUTE_RANGE_FILTER_CLASS_NAME,
+       NULL,
+       m_property,
+       m_functions,
+       Initialize,
+       Finalize,
+       NULL, //hasProperty,
+       NULL, //GetProperty,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //getPropertyNames,
+       NULL, //CallAsFunction,
+       constructor, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL, //ConvertToType,
+};
+
+JSStaticValue JSAttributeRangeFilter::m_property[] = {
+       { ATTRIBUTE_FILTER_ATTR_ATTRIBUTE_NAME, getAttributeName, setAttributeName, kJSPropertyAttributeNone },
+       { ATTRIBUTE_FILTER_ATTR_INITIAL_VALUE, getInitialValue, setInitialValue, kJSPropertyAttributeNone },
+       { ATTRIBUTE_FILTER_ATTR_END_VALUE, getEndValue, setEndValue, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSAttributeRangeFilter::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSAttributeRangeFilter::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSAttributeRangeFilter::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+AttributeRangeFilterPtr JSAttributeRangeFilter::getAttributeRangeFilter(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSAttributeRangeFilterPriv *priv = static_cast<JSAttributeRangeFilterPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+JSObjectRef JSAttributeRangeFilter::createJSObject(JSContextRef context, AttributeRangeFilterPtr privateData)
+{
+       JSAttributeRangeFilterPriv *priv = new JSAttributeRangeFilterPriv(context, privateData);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+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)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSAttributeRangeFilter::Finalize(JSObjectRef object)
+{
+       JSAttributeRangeFilterPriv *priv = static_cast<JSAttributeRangeFilterPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+       {
+               delete (priv);
+       }
+
+       priv = NULL;
+}
+
+AttributeRangeFilterPtr JSAttributeRangeFilter::getPrivData(JSObjectRef object)
+{
+       LogDebug("entered");
+       JSAttributeRangeFilterPriv *priv = static_cast<JSAttributeRangeFilterPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       AttributeRangeFilterPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSObjectRef JSAttributeRangeFilter::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       bool js2ndParamIsValue = false;
+       bool js3rdParamIsValue = false;
+
+//     AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADD);
+//     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       JSAttributeRangeFilterPriv *priv = static_cast<JSAttributeRangeFilterPriv*>(JSObjectGetPrivate(constructor));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       JSContextRef gContext = priv->getContext();
+
+//     JSContextRef gContext = JSGlobalContextFactory::getInstance()->get();
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(gContext, exception);
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
+
+               if (!JSValueIsString(gContext, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument is not string.");
+
+               // 2nd and 3rd argument can be any type.
+               if (argumentCount >= 2)
+               {
+                       if(!JSValueIsUndefined(gContext, arguments[1]) && !JSValueIsNull(gContext, arguments[1]))
+                               js2ndParamIsValue = true;
+               }
+
+               if (argumentCount >= 3)
+               {
+                       if(!JSValueIsUndefined(gContext, arguments[2]) && !JSValueIsNull(gContext, 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(gContext);
+
+       std::string attributeName;
+       AnyPtr initialValue(NULL);
+       AnyPtr endValue(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;
+       }
+
+       Try {
+               if(js2ndParamIsValue)
+                       initialValue = converter->toAny(arguments[1]);
+               else
+                       initialValue = AnyPtr(new Any());
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       Try {
+               if(js3rdParamIsValue)
+                       endValue = converter->toAny(arguments[2]);
+               else
+                       endValue = AnyPtr(new Any());
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       AttributeRangeFilterPtr attributeRangeFilter(new AttributeRangeFilter(attributeName, initialValue, endValue));
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, attributeRangeFilter);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+JSValueRef JSAttributeRangeFilter::getAttributeName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               AttributeRangeFilterPtr attributeRangeFilter = getPrivData(object);
+               return converter->toJSValueRef(attributeRangeFilter->getAttributeName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSAttributeRangeFilter::setAttributeName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               AttributeRangeFilterPtr attributeRangeFilter = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               attributeRangeFilter->setAttributeName(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 JSAttributeRangeFilter::getInitialValue(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               AttributeRangeFilterPtr attributeRangeFilter = getPrivData(object);
+               return converter->toJSValueRef(attributeRangeFilter->getInitialValue());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSAttributeRangeFilter::setInitialValue(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               AttributeRangeFilterPtr attributeRangeFilter = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               attributeRangeFilter->setInitialValue(converter->toAny(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 JSAttributeRangeFilter::getEndValue(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               AttributeRangeFilterPtr attributeRangeFilter = getPrivData(object);
+               return converter->toJSValueRef(attributeRangeFilter->getEndValue());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSAttributeRangeFilter::setEndValue(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               AttributeRangeFilterPtr attributeRangeFilter = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               attributeRangeFilter->setEndValue(converter->toAny(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;
+}
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Tizen/JSAttributeRangeFilter.h b/src/standards/Tizen/Tizen/JSAttributeRangeFilter.h
new file mode 100755 (executable)
index 0000000..58bcac4
--- /dev/null
@@ -0,0 +1,129 @@
+//
+// 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        JSAttributeRangeFilter.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSAttributeRangeFilter class
+ */
+
+#ifndef _TIZEN_TIZEN_JS_ATTRIBUTE_RANGE_FILTER_H_
+#define _TIZEN_TIZEN_JS_ATTRIBUTE_RANGE_FILTER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Filter/AttributeRangeFilter.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Tizen::AttributeRangeFilterPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSAttributeRangeFilterPriv;
+
+class JSAttributeRangeFilter {
+public:
+       /*
+       * This initializes this JS class in the JS Engine.
+       */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Tizen::AttributeRangeFilterPtr getAttributeRangeFilter(JSContextRef context, JSValueRef value);
+
+       static JSObjectRef createJSObject(JSContextRef context,
+                       TizenApis::Api::Tizen::AttributeRangeFilterPtr privateData);
+
+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 TizenApis::Api::Tizen::AttributeRangeFilterPtr getPrivData(JSObjectRef object);
+
+       static JSObjectRef constructor(JSContextRef context,
+                       JSObjectRef constructor,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef getAttributeName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setAttributeName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getInitialValue(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setInitialValue(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getEndValue(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setEndValue(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+};
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_TIZEN_JS_ATTRIBUTE_RANGE_FILTER_H_
diff --git a/src/standards/Tizen/Tizen/JSCompositeFilter.cpp b/src/standards/Tizen/Tizen/JSCompositeFilter.cpp
new file mode 100755 (executable)
index 0000000..29fcfc3
--- /dev/null
@@ -0,0 +1,336 @@
+//
+// 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        JSCompositeFilter.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSCompositeFilter class
+ */
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <API/Filter/CompositeFilter.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "FilterConverter.h"
+#include "JSAbstractFilterArray.h"
+#include "JSCompositeFilter.h"
+
+#define ATTRIBUTE_FILTER_CLASS_NAME "CompositeFilter"
+
+#define ATTRIBUTE_FILTER_ATTR_TYPE "type"
+#define ATTRIBUTE_FILTER_ATTR_FILTERS "filters"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassRef JSCompositeFilter::m_classRef = NULL;
+
+JSClassDefinition JSCompositeFilter::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       ATTRIBUTE_FILTER_CLASS_NAME,
+       NULL,
+       m_property,
+       m_functions,
+       Initialize,
+       Finalize,
+       NULL, //hasProperty,
+       NULL, //GetProperty,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //getPropertyNames,
+       NULL, //CallAsFunction,
+       constructor, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL, //ConvertToType,
+};
+
+JSStaticValue JSCompositeFilter::m_property[] = {
+       { ATTRIBUTE_FILTER_ATTR_TYPE, getType, setType, kJSPropertyAttributeNone },
+       { ATTRIBUTE_FILTER_ATTR_FILTERS, getFilters, setFilters, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSCompositeFilter::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSCompositeFilter::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSCompositeFilter::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+CompositeFilterPtr JSCompositeFilter::getCompositeFilter(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSCompositeFilterPriv *priv = static_cast<JSCompositeFilterPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+JSObjectRef JSCompositeFilter::createJSObject(JSContextRef context, CompositeFilterPtr privateData)
+{
+       JSCompositeFilterPriv *priv = new JSCompositeFilterPriv(context, privateData);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+void JSCompositeFilter::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               CompositeFilterPtr filter(new CompositeFilter(UNION_FILTER, FilterArrayPtr(NULL)));
+               JSCompositeFilterPriv *priv = new JSCompositeFilterPriv(context, CompositeFilterPtr(filter));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSCompositeFilter::Finalize(JSObjectRef object)
+{
+       JSCompositeFilterPriv *priv = static_cast<JSCompositeFilterPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+       {
+               delete (priv);
+       }
+
+       priv = NULL;
+}
+
+CompositeFilterPtr JSCompositeFilter::getPrivData(JSObjectRef object)
+{
+       LogDebug("entered");
+       JSCompositeFilterPriv *priv = static_cast<JSCompositeFilterPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       CompositeFilterPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSObjectRef JSCompositeFilter::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       bool js2ndParamIsObject = false;
+
+//     AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADD);
+//     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       JSCompositeFilterPriv *priv = static_cast<JSCompositeFilterPriv*>(JSObjectGetPrivate(constructor));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       JSContextRef gContext = priv->getContext();
+
+//     JSContextRef gContext = JSGlobalContextFactory::getInstance()->get();
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(gContext, exception);
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
+
+               if (!JSValueIsString(gContext, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument is not string.");
+
+               if (argumentCount >= 2)
+               {
+                       if (JSValueIsObject(gContext, arguments[1]))
+                               js2ndParamIsObject = true;
+
+                       if (!js2ndParamIsObject &&
+                                       !JSValueIsNull(gContext, arguments[1]) &&
+                                       !JSValueIsUndefined(gContext, arguments[1]))
+                               ThrowMsg(InvalidArgumentException, "2nd argument is not array.");
+               }
+
+       } 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(gContext);
+
+       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;
+       }
+
+       Try {
+               if(js2ndParamIsObject)
+                       filters = converter->toFilterArray(arguments[1]);
+               else
+                       filters = FilterArrayPtr(new FilterArray());
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       CompositeFilterPtr compositeFilter(new CompositeFilter(type, filters));
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, compositeFilter);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+JSValueRef JSCompositeFilter::getType(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               CompositeFilterPtr compositeFilter = getPrivData(object);
+               return converter->toJSValueRef(compositeFilter->getFilterType());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSCompositeFilter::setType(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               CompositeFilterPtr compositeFilter = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               compositeFilter->setFilterType(converter->toCompositeFilterType(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 JSCompositeFilter::getFilters(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               CompositeFilterPtr compositeFilter = getPrivData(object);
+               return converter->toJSValueRef(compositeFilter->getFilters());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSCompositeFilter::setFilters(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               CompositeFilterPtr compositeFilter = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               compositeFilter->setFilters(converter->toFilterArray(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;
+}
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Tizen/JSCompositeFilter.h b/src/standards/Tizen/Tizen/JSCompositeFilter.h
new file mode 100755 (executable)
index 0000000..fee0705
--- /dev/null
@@ -0,0 +1,117 @@
+//
+// 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        JSCompositeFilter.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSCompositeFilter class
+ */
+
+#ifndef _TIZEN_TIZEN_JS_COMPOSITE_FILTER_H_
+#define _TIZEN_TIZEN_JS_COMPOSITE_FILTER_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Filter/CompositeFilter.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Tizen::CompositeFilterPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSCompositeFilterPriv;
+
+class JSCompositeFilter {
+public:
+       /*
+        * This initializes this JS class in the JS Engine.
+        */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Tizen::CompositeFilterPtr getCompositeFilter(JSContextRef context, JSValueRef value);
+
+       static JSObjectRef createJSObject(JSContextRef context, TizenApis::Api::Tizen::CompositeFilterPtr privateData);
+
+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 TizenApis::Api::Tizen::CompositeFilterPtr getPrivData(JSObjectRef object);
+
+       static JSObjectRef constructor(JSContextRef context,
+                       JSObjectRef constructor,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef getType(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setType(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getFilters(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setFilters(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+};
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_TIZEN_JS_COMPOSITE_FILTER_H_
diff --git a/src/standards/Tizen/Tizen/JSFeature.cpp b/src/standards/Tizen/Tizen/JSFeature.cpp
new file mode 100755 (executable)
index 0000000..555c7d6
--- /dev/null
@@ -0,0 +1,155 @@
+//
+// 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        JSFeature.cpp
+ * @author
+ * @version     0.1
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include "JSFeature.h"
+#include "JSFeatureParam.h"
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+namespace {
+    const char* PLUGIN_NAME = "Feature";
+    const char* ATTRIBUTE_URI = "uri";
+    const char* ATTRIBUTE_REQUIRED = "required";
+    const char* ATTRIBUTE_PARAMS = "params";
+}
+
+JSClassDefinition JSFeature::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    PLUGIN_NAME,
+    0,
+    m_properties,
+    NULL, //m_functions,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL,
+    NULL,
+    NULL, //hasInstance,
+    NULL  //convertToType
+};
+
+JSStaticValue JSFeature::m_properties[] = {
+    { ATTRIBUTE_URI, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { ATTRIBUTE_REQUIRED, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { ATTRIBUTE_PARAMS, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassDefinition* JSFeature::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSFeature::m_classRef = JSClassCreate(JSFeature::getClassInfo());
+
+void JSFeature::initialize(JSContextRef context, JSObjectRef object)
+{
+    //LogDebug("entered");
+    //private object should be passed to JSObjectMake function.
+    //Nothing to do here.
+}
+
+void JSFeature::finalize(JSObjectRef object)
+{
+    LogDebug("entered");
+    JSFeaturePrivateObject* priv =
+            static_cast<JSFeaturePrivateObject*>(JSObjectGetPrivate(object));
+    delete priv;
+}
+
+JSClassRef JSFeature::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+JSValueRef JSFeature::getProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("entered");
+    JSFeaturePrivateObject* priv =
+        static_cast<JSFeaturePrivateObject*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        LogError("no private object");
+        return JSValueMakeUndefined(context);
+    }
+    Try
+    {
+        WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+        if (JSStringIsEqualToUTF8CString(propertyName, ATTRIBUTE_URI)) {
+            return converter.toJSValueRef(priv->getObject()->getName() );
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, ATTRIBUTE_REQUIRED)) {
+            if (priv->getObject()->isRequestedByWidget()) {
+                return converter.toJSValueRef(priv->getObject()->isRequired() );
+            }
+            return JSValueMakeNull(context);
+        }
+        else if (JSStringIsEqualToUTF8CString(propertyName, ATTRIBUTE_PARAMS)) {
+            if (priv->getObject()->isRequestedByWidget()) {
+                JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL);
+                if (jsResult) {
+                    WrtDeviceApis::WidgetDB::Api::IWidgetFeature::Params params =
+                        priv->getObject()->getParams();
+                    WrtDeviceApis::WidgetDB::Api::IWidgetFeature::ParamsIterator it =
+                        params.begin();
+                    size_t i = 0;
+                    for (; it != params.end(); ++it, ++i) {
+                        std::pair<std::string, std::string> param = make_pair(it->first, it->second);
+                        JSFeatureParamPrivObject *priv = new JSFeatureParamPrivObject(context, param);
+                        JSObjectRef tempVal = JSObjectMake(context, JSFeatureParam::getClassRef(), priv);
+                        bool result = JSSetArrayElement(context, jsResult, i, tempVal);
+                        if(result == false)
+                               continue;
+                    }
+                    return jsResult;
+                }
+            }
+            return JSValueMakeNull(context);
+        }
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("error during conversion");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Tizen/JSFeature.h b/src/standards/Tizen/Tizen/JSFeature.h
new file mode 100755 (executable)
index 0000000..9e3b282
--- /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.
+//
+
+/**
+ * @file        JSFeature.h
+ * @author
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGIN_JS_FEATURE_H_
+#define _WRT_PLUGIN_JS_FEATURE_H_
+
+#include <string>
+#include <vector>
+#include <JavaScriptCore/JavaScript.h>
+#include <WidgetDB/IWidgetFeature.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<WrtDeviceApis::WidgetDB::Api::IWidgetFeaturePtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSFeaturePrivateObject;
+
+/**
+ * @class JSFeature
+ * @brief This class is javascript extenstion
+ *
+ */
+class JSFeature
+{
+public:
+    /**
+     * This method initializes this in the JS Engine.
+     */
+    static JSClassRef getClassRef();
+
+    /**
+     * Gets object's class description.
+     */
+    static const JSClassDefinition* getClassInfo();
+
+private:
+    /**
+     * The callback invoked when an object is first created.
+     */
+    static void initialize(JSContextRef context, JSObjectRef object);
+
+    /**
+     * The callback invoked when an object is finalized.
+     */
+    static void finalize(JSObjectRef object);
+
+    /**
+     * The callback invoked when getting a property's value.
+     */
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception);
+
+    /**
+     * This structure describes a statically declared value property.
+     */
+    static JSStaticValue m_properties[];
+
+    /**
+     * This structure contains properties and callbacks that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+    static JSClassRef m_classRef;
+
+};
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
+
+#endif //  _WRT_PLUGIN_JS_FEATURE_H_
diff --git a/src/standards/Tizen/Tizen/JSFeatureParam.cpp b/src/standards/Tizen/Tizen/JSFeatureParam.cpp
new file mode 100755 (executable)
index 0000000..2c3341e
--- /dev/null
@@ -0,0 +1,128 @@
+//
+// 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        JSFeatureParam.cpp
+ * @author
+ * @version     0.1
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/Converter.h>
+#include "JSFeatureParam.h"
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+namespace {
+    const char* PLUGIN_NAME = "Param";
+    const char* ATTRIBUTE_NAME = "name";
+    const char* ATTRIBUTE_VALUE = "value";
+}
+
+JSClassDefinition JSFeatureParam::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    PLUGIN_NAME,
+    0,
+    m_properties,
+    NULL, //m_functions,
+    initialize,
+    finalize,
+    NULL, //hasProperty,
+    NULL, //getProperty,
+    NULL, //setProperty,
+    NULL, //deleteProperty,
+    NULL, //getPropertyNames,
+    NULL,
+    NULL,
+    NULL, //hasInstance,
+    NULL  //convertToType
+};
+
+JSStaticValue JSFeatureParam::m_properties[] = {
+    { ATTRIBUTE_NAME, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { ATTRIBUTE_VALUE, getProperty, NULL, kJSPropertyAttributeReadOnly },
+    { 0, 0, 0, 0 }
+};
+
+const JSClassDefinition* JSFeatureParam::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSFeatureParam::m_classRef = JSClassCreate(JSFeatureParam::getClassInfo());
+
+
+void JSFeatureParam::initialize(JSContextRef context, JSObjectRef object)
+{
+    LogDebug("entered");
+    //private object should be passed to JSObjectMake function.
+    //Nothing to do here.
+}
+
+void JSFeatureParam::finalize(JSObjectRef object)
+{
+    LogDebug("entered");
+    JSFeatureParamPrivObject* priv =
+            static_cast<JSFeatureParamPrivObject*>(JSObjectGetPrivate(object));
+    delete priv;
+}
+
+JSClassRef JSFeatureParam::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+JSValueRef JSFeatureParam::getProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("entered");
+    JSFeatureParamPrivObject* priv =
+        static_cast<JSFeatureParamPrivObject*>(JSObjectGetPrivate(object));
+    if (!priv) {
+        LogError("no private object");
+        return JSValueMakeUndefined(context);
+    }
+    Try
+    {
+        WrtDeviceApis::CommonsJavaScript::Converter converter(context);
+        std::string propertyNameStr = converter.toString(propertyName);
+        if (propertyNameStr == ATTRIBUTE_NAME) {
+            return converter.toJSValueRef(priv->getObject().first);
+        }
+        else if (propertyNameStr == ATTRIBUTE_VALUE) {
+            return converter.toJSValueRef(priv->getObject().second);
+        }
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("error during conversion");
+    }
+    return JSValueMakeUndefined(context);
+}
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Tizen/JSFeatureParam.h b/src/standards/Tizen/Tizen/JSFeatureParam.h
new file mode 100755 (executable)
index 0000000..5ccea6f
--- /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.
+//
+
+/**
+ * @file        JSFeatureParam.h
+ * @author
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGIN_JS_FEATURE_PARAM_H_
+#define _WRT_PLUGIN_JS_FEATURE_PARAM_H_
+
+#include <string>
+#include <utility>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <JavaScriptCore/JavaScript.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<std::pair<std::string, std::string>, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSFeatureParamPrivObject;
+
+/**
+ * @class JSFeatureParam
+ * @brief This class is javascript extenstion
+ *
+ */
+class JSFeatureParam
+{
+public:
+    /**
+     * This method initializes this in the JS Engine.
+     */
+    static JSClassRef getClassRef();
+
+    /**
+     * Gets object's class description.
+     */
+    static const JSClassDefinition* getClassInfo();
+
+private:
+    /**
+     * The callback invoked when an object is first created.
+     */
+    static void initialize(JSContextRef context, JSObjectRef object);
+
+    /**
+     * The callback invoked when an object is finalized.
+     */
+    static void finalize(JSObjectRef object);
+
+    /**
+     * The callback invoked when getting a property's value.
+     */
+    static JSValueRef getProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception);
+
+    /**
+     * This structure describes a statically declared value property.
+     */
+    static JSStaticValue m_properties[];
+
+    /**
+     * This structure contains properties and callbacks that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+    static JSClassRef m_classRef;
+
+};
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
+
+#endif //  _WRT_PLUGIN_JS_FEATURE_PARAM_H_
diff --git a/src/standards/Tizen/Tizen/JSSimpleCoordinates.cpp b/src/standards/Tizen/Tizen/JSSimpleCoordinates.cpp
new file mode 100755 (executable)
index 0000000..0fed224
--- /dev/null
@@ -0,0 +1,321 @@
+//
+// 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        JSSimpleCoordinates.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSSimpleCoordinates class
+ */
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <API/Filter/SimpleCoordinates.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "FilterConverter.h"
+#include "JSSimpleCoordinates.h"
+
+#define ATTRIBUTE_FILTER_CLASS_NAME "SimpleCoordinates"
+
+#define ATTRIBUTE_FILTER_ATTR_LATITUDE "latitude"
+#define ATTRIBUTE_FILTER_ATTR_LONGITUDE "longitude"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassRef JSSimpleCoordinates::m_classRef = NULL;
+
+JSClassDefinition JSSimpleCoordinates::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       ATTRIBUTE_FILTER_CLASS_NAME,
+       NULL,
+       m_property,
+       m_functions,
+       Initialize,
+       Finalize,
+       NULL, //hasProperty,
+       NULL, //GetProperty,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //getPropertyNames,
+       NULL, //CallAsFunction,
+       constructor, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL, //ConvertToType,
+};
+
+JSStaticValue JSSimpleCoordinates::m_property[] = {
+       { ATTRIBUTE_FILTER_ATTR_LATITUDE, getLatitude, setLatitude, kJSPropertyAttributeNone },
+       { ATTRIBUTE_FILTER_ATTR_LONGITUDE, getLongitude, setLongitude, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSSimpleCoordinates::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSSimpleCoordinates::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSSimpleCoordinates::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+SimpleCoordinatesPtr JSSimpleCoordinates::getSimpleCoordinates(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSSimpleCoordinatesPriv *priv = static_cast<JSSimpleCoordinatesPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+JSObjectRef JSSimpleCoordinates::createJSObject(JSContextRef context, SimpleCoordinatesPtr privateData)
+{
+       JSSimpleCoordinatesPriv *priv = new JSSimpleCoordinatesPriv(context, privateData);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+void JSSimpleCoordinates::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               SimpleCoordinatesPtr coord(new SimpleCoordinates(0.0, 0.0));
+               JSSimpleCoordinatesPriv *priv = new JSSimpleCoordinatesPriv(context, SimpleCoordinatesPtr(coord));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSSimpleCoordinates::Finalize(JSObjectRef object)
+{
+       JSSimpleCoordinatesPriv *priv = static_cast<JSSimpleCoordinatesPriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+       {
+               delete (priv);
+       }
+
+       priv = NULL;
+}
+
+SimpleCoordinatesPtr JSSimpleCoordinates::getPrivData(JSObjectRef object)
+{
+       LogDebug("entered");
+       JSSimpleCoordinatesPriv *priv = static_cast<JSSimpleCoordinatesPriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       SimpleCoordinatesPtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSObjectRef JSSimpleCoordinates::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+//     AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADD);
+//     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       JSSimpleCoordinatesPriv *priv = static_cast<JSSimpleCoordinatesPriv*>(JSObjectGetPrivate(constructor));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       JSContextRef gContext = priv->getContext();
+
+//     JSGlobalContextRef gContext = JSGlobalContextFactory::getInstance()->get();
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(gContext, exception);
+       Try {
+               if (argumentCount < 2)
+                       ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
+
+               if (!JSValueIsNumber(gContext, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument is not string.");
+
+               if (!JSValueIsNumber(gContext, 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(gContext);
+
+       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 {
+               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;
+       }
+
+       SimpleCoordinatesPtr simpleCoordinates(new SimpleCoordinates(latitude, longitude));
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, simpleCoordinates);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+JSValueRef JSSimpleCoordinates::getLatitude(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               SimpleCoordinatesPtr simpleCoordinates = getPrivData(object);
+               return converter->toJSValueRef(simpleCoordinates->getLatitude());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSSimpleCoordinates::setLatitude(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               SimpleCoordinatesPtr simpleCoordinates = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               simpleCoordinates->setLatitude(converter->toDouble(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 JSSimpleCoordinates::getLongitude(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               SimpleCoordinatesPtr simpleCoordinates = getPrivData(object);
+               return converter->toJSValueRef(simpleCoordinates->getLongitude());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSSimpleCoordinates::setLongitude(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               SimpleCoordinatesPtr simpleCoordinates = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               simpleCoordinates->setLongitude(converter->toDouble(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;
+}
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Tizen/JSSimpleCoordinates.h b/src/standards/Tizen/Tizen/JSSimpleCoordinates.h
new file mode 100755 (executable)
index 0000000..5ea7729
--- /dev/null
@@ -0,0 +1,117 @@
+//
+// 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        JSSimpleCoordinates.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSSimpleCoordinates class
+ */
+
+#ifndef _TIZEN_TIZEN_JS_SIMPLE_COORDINATES_H_
+#define _TIZEN_TIZEN_JS_SIMPLE_COORDINATES_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Filter/SimpleCoordinates.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Tizen::SimpleCoordinatesPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSSimpleCoordinatesPriv;
+
+class JSSimpleCoordinates {
+public:
+       /*
+        * This initializes this JS class in the JS Engine.
+        */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Tizen::SimpleCoordinatesPtr getSimpleCoordinates(JSContextRef context, JSValueRef value);
+
+       static JSObjectRef createJSObject(JSContextRef context, TizenApis::Api::Tizen::SimpleCoordinatesPtr privateData);
+
+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 TizenApis::Api::Tizen::SimpleCoordinatesPtr getPrivData(JSObjectRef object);
+
+       static JSObjectRef constructor(JSContextRef context,
+                       JSObjectRef constructor,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef getLatitude(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setLatitude(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getLongitude(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setLongitude(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+};
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_TIZEN_JS_SIMPLE_COORDINATES_H_
diff --git a/src/standards/Tizen/Tizen/JSSortMode.cpp b/src/standards/Tizen/Tizen/JSSortMode.cpp
new file mode 100755 (executable)
index 0000000..ff6995e
--- /dev/null
@@ -0,0 +1,335 @@
+//
+// 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        JSSortMode.cpp
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Implementation of the JSSortMode class
+ */
+
+#include <string>
+#include <dpl/log/log.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/Converter.h>
+#include <CommonsJavaScript/Validator.h>
+#include <API/Filter/SortMode.h>
+#include <Tizen/Common/JSTizenExceptionFactory.h>
+#include <Tizen/Common/JSTizenException.h>
+#include "FilterConverter.h"
+#include "JSSortMode.h"
+
+#define ATTRIBUTE_FILTER_CLASS_NAME "SortMode"
+
+#define ATTRIBUTE_FILTER_ATTR_ATTRIBUTE_NAME "attributeName"
+#define ATTRIBUTE_FILTER_ATTR_ORDER "order"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+using namespace TizenApis::Commons;
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassRef JSSortMode::m_classRef = NULL;
+
+JSClassDefinition JSSortMode::m_classInfo =
+{
+       0,
+       kJSClassAttributeNone,
+       ATTRIBUTE_FILTER_CLASS_NAME,
+       NULL,
+       m_property,
+       m_functions,
+       Initialize,
+       Finalize,
+       NULL, //hasProperty,
+       NULL, //GetProperty,
+       NULL, //SetProperty,
+       NULL, //DeleteProperty,
+       NULL, //getPropertyNames,
+       NULL, //CallAsFunction,
+       constructor, //CallAsConstructor,
+       NULL, //HasInstance,
+       NULL, //ConvertToType,
+};
+
+JSStaticValue JSSortMode::m_property[] = {
+       { ATTRIBUTE_FILTER_ATTR_ATTRIBUTE_NAME, getAttributeName, setAttributeName, kJSPropertyAttributeNone },
+       { ATTRIBUTE_FILTER_ATTR_ORDER, getOrder, setOrder, kJSPropertyAttributeNone },
+       { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSSortMode::m_functions[] =
+{
+       { 0, 0, 0 }
+};
+
+JSClassRef JSSortMode::getClassRef() {
+       if (!m_classRef) {
+               m_classRef = JSClassCreate(&m_classInfo);
+       }
+       return m_classRef;
+}
+
+bool JSSortMode::isObjectOfClass(JSContextRef context, JSValueRef value)
+{
+       return JSValueIsObjectOfClass(context, value, getClassRef());
+}
+
+SortModePtr JSSortMode::getSortMode(JSContextRef context, JSValueRef value)
+{
+       if (!isObjectOfClass(context, value)) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSObjectRef object = JSValueToObject(context, value, NULL);
+       if (!object) {
+               Throw(WrtDeviceApis::Commons::InvalidArgumentException);
+       }
+       JSSortModePriv *priv = static_cast<JSSortModePriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               Throw(WrtDeviceApis::Commons::NullPointerException);
+       }
+       return priv->getObject();
+}
+
+JSObjectRef JSSortMode::createJSObject(JSContextRef context, SortModePtr privateData)
+{
+       JSSortModePriv *priv = new JSSortModePriv(context, privateData);
+       JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
+       if (NULL == jsObjectRef) {
+               LogError("object creation error");
+               return NULL;
+       }
+       return jsObjectRef;
+}
+
+void JSSortMode::Initialize(JSContextRef context, JSObjectRef object)
+{
+       if (!JSObjectGetPrivate(object))
+       {
+               SortModePtr sortMode(new SortMode(""));
+               JSSortModePriv *priv = new JSSortModePriv(context, SortModePtr(sortMode));
+               if (!JSObjectSetPrivate(object, priv)) {
+                       delete priv;
+               }
+       }
+}
+
+void JSSortMode::Finalize(JSObjectRef object)
+{
+       JSSortModePriv *priv = static_cast<JSSortModePriv*>(JSObjectGetPrivate(object));
+
+       if (priv != NULL)
+       {
+               delete (priv);
+       }
+
+       priv = NULL;
+}
+
+SortModePtr JSSortMode::getPrivData(JSObjectRef object)
+{
+       LogDebug("entered");
+       JSSortModePriv *priv = static_cast<JSSortModePriv*>(JSObjectGetPrivate(object));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       SortModePtr result = priv->getObject();
+       if (!result) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       return result;
+}
+
+JSObjectRef JSSortMode::constructor(JSContextRef context,
+               JSObjectRef constructor,
+               size_t argumentCount,
+               const JSValueRef arguments[],
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+
+       bool js2ndParamIsString = false;
+
+//     AceSecurityStatus status = CONTACT_CHECK_ACCESS(CONTACT_FUNCTION_API_ADD);
+//     TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
+
+       JSSortModePriv *priv = static_cast<JSSortModePriv*>(JSObjectGetPrivate(constructor));
+       if (!priv) {
+               ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null");
+       }
+       JSContextRef gContext = priv->getContext();
+
+//     JSContextRef gContext = JSGlobalContextFactory::getInstance()->get();
+
+       BasicValidator validator = BasicValidatorFactory::getValidator(gContext, exception);
+       Try {
+               if (argumentCount < 1)
+                       ThrowMsg(InvalidArgumentException, "Wrong arguments count.");
+
+               if (!JSValueIsString(gContext, arguments[0]))
+                       ThrowMsg(InvalidArgumentException, "1st argument is not string.");
+
+               if (argumentCount >= 2)
+               {
+                       if (JSValueIsString(gContext, arguments[1]))
+                               js2ndParamIsString = true;
+
+                       if (!js2ndParamIsString &&
+                                       !JSValueIsNull(gContext, arguments[1]) &&
+                                       !JSValueIsUndefined(gContext, 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(gContext);
+
+       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;
+       }
+
+       Try {
+               if(js2ndParamIsString)
+                       sortOrder = converter->toSortOrder(arguments[1]);
+               else
+                       sortOrder = ASCENDING_SORT_ORDER;
+
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       SortModePtr sortMode(new SortMode(attributeName, sortOrder));
+
+       JSObjectRef jsobject;
+
+       Try {
+               jsobject = createJSObject(gContext, sortMode);
+       } Catch(Exception) {
+               LogError("Argument type mismatch : " << _rethrown_exception.GetMessage());
+               *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments");
+               return NULL;
+       }
+
+       return jsobject;
+}
+
+JSValueRef JSSortMode::getAttributeName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               SortModePtr sortMode = getPrivData(object);
+               return converter->toJSValueRef(sortMode->getAttributeName());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSSortMode::setAttributeName(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               SortModePtr sortMode = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               sortMode->setAttributeName(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 JSSortMode::getOrder(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef* exception)
+{
+       LogDebug("entered");
+       Try
+       {
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               SortModePtr sortMode = getPrivData(object);
+               return converter->toJSValueRef(sortMode->getOrder());
+       }
+       Catch(WrtDeviceApis::Commons::Exception)
+       {
+               LogWarning("trying to get incorrect value");
+       }
+       return JSValueMakeUndefined(context);
+}
+
+bool JSSortMode::setOrder(JSContextRef context,
+               JSObjectRef object,
+               JSStringRef propertyName,
+               JSValueRef value,
+               JSValueRef* exception)
+{
+       Try
+       {
+               SortModePtr sortMode = getPrivData(object);
+               FilterConverterFactory::ConverterType converter =
+                               FilterConverterFactory::getConverter(context);
+               sortMode->setOrder(converter->toSortOrder(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;
+}
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Tizen/JSSortMode.h b/src/standards/Tizen/Tizen/JSSortMode.h
new file mode 100755 (executable)
index 0000000..fb83921
--- /dev/null
@@ -0,0 +1,117 @@
+//
+// 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        JSSortMode.h
+ * @author      Kisub Song (kisubs.song@samsung.com)
+ * @version     0.1
+ * @brief       Declaration of the JSSortMode class
+ */
+
+#ifndef _TIZEN_TIZEN_JS_SORT_MODE_H_
+#define _TIZEN_TIZEN_JS_SORT_MODE_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <dpl/shared_ptr.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Commons/IEvent.h>
+#include <API/Filter/SortMode.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<TizenApis::Api::Tizen::SortModePtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> JSSortModePriv;
+
+class JSSortMode {
+public:
+       /*
+        * This initializes this JS class in the JS Engine.
+        */
+       static JSClassRef getClassRef();
+
+       static bool isObjectOfClass(JSContextRef context, JSValueRef value);
+
+       static TizenApis::Api::Tizen::SortModePtr getSortMode(JSContextRef context, JSValueRef value);
+
+       static JSObjectRef createJSObject(JSContextRef context, TizenApis::Api::Tizen::SortModePtr privateData);
+
+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 TizenApis::Api::Tizen::SortModePtr getPrivData(JSObjectRef object);
+
+       static JSObjectRef constructor(JSContextRef context,
+                       JSObjectRef constructor,
+                       size_t argumentCount,
+                       const JSValueRef arguments[],
+                       JSValueRef* exception);
+
+       static JSValueRef getAttributeName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setAttributeName(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+
+       static JSValueRef getOrder(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef* exception);
+
+       static bool setOrder(JSContextRef context,
+                       JSObjectRef object,
+                       JSStringRef propertyName,
+                       JSValueRef value,
+                       JSValueRef* exception);
+};
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
+
+#endif // _TIZEN_TIZEN_JS_SORT_MODE_H_
diff --git a/src/standards/Tizen/Tizen/JSTizen.cpp b/src/standards/Tizen/Tizen/JSTizen.cpp
new file mode 100755 (executable)
index 0000000..2d6683a
--- /dev/null
@@ -0,0 +1,354 @@
+//
+// 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        JSTizen.cpp
+ * @author
+ * @version     0.1
+ * @brief
+ */
+
+#include <cassert>
+#include <vector>
+#include <dpl/log/log.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <CommonsJavaScript/Converter.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <API/Filter/FilterTypes.h>
+#include <API/Filter/AnyType.h>
+#include <CommonsJavaScript/JSDOMExceptionFactory.h>
+#include "JSTizen.h"
+#include "JSFeature.h"
+#include "plugin_config.h"
+#include <WidgetDB/WidgetDBMgr.h>
+#include <WidgetDB/IWidgetDB.h>
+#include <PluginManager/PluginManagerFactory.h>
+
+#include <iostream>
+
+#define PLUGIN_NAME "tizen"
+#define FUNCTION_LIST_AVAILABLE_FEATURES "listAvailableFeatures"
+#define FUNCTION_LIST_ACTIVATED_FEATURES "listActivatedFeatures"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+using namespace TizenApis::Api::Tizen;
+using namespace WrtDeviceApis::PluginManager::Api;
+
+JSClassDefinition JSTizen::m_classInfo =
+{
+    0,
+    kJSClassAttributeNone,
+    PLUGIN_NAME,
+    0,
+    m_properties,
+    m_functions,
+    initialize,
+    finalize,
+    hasProperty,
+    getProperty,
+    setProperty,
+    NULL, //deleteProperty,
+    getPropertyNames,
+    NULL,
+    NULL,
+    hasInstance,
+    convertToType
+};
+
+JSStaticValue JSTizen::m_properties[] = {
+    { 0, 0, 0 }
+};
+
+JSStaticFunction JSTizen::m_functions[] = {
+    { FUNCTION_LIST_AVAILABLE_FEATURES, listAvailableFeatures, kJSPropertyAttributeNone},
+    { FUNCTION_LIST_ACTIVATED_FEATURES, listActivatedFeatures, kJSPropertyAttributeNone},
+    { 0, 0, 0 }
+};
+
+const JSClassDefinition* JSTizen::getClassInfo()
+{
+    return &m_classInfo;
+}
+
+JSClassRef JSTizen::m_classRef = JSClassCreate(JSTizen::getClassInfo());
+
+void JSTizen::initialize(JSContextRef context, JSObjectRef object)
+{
+    LogDebug("entered");
+    TizenPrivate* priv = static_cast<TizenPrivate*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    if (priv) {
+        delete priv;
+    }
+
+    int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+    PluginOnDemandPrivPtr privObject(
+        new PluginOnDemandPriv(
+                       PluginManagerFactory::getInstance().getPluginManager(
+                           widgetId,
+                           PLUGIN_NAME,
+                           object,
+                           context)));
+
+    priv = new TizenPrivate(context, privObject);
+    if (!JSObjectSetPrivate(object, static_cast<void*>(priv))) {
+        JSObjectSetPrivate(object, NULL);
+        delete priv;
+    }
+}
+
+void JSTizen::finalize(JSObjectRef object)
+{
+    LogDebug("entered");
+    TizenPrivate* priv = static_cast<TizenPrivate*>(JSObjectGetPrivate(object));
+    JSObjectSetPrivate(object, NULL);
+    delete priv;
+}
+
+JSClassRef JSTizen::getClassRef()
+{
+    if (!m_classRef) {
+        m_classRef = JSClassCreate(&m_classInfo);
+    }
+    return m_classRef;
+}
+
+//bool JSTizen::deleteProperty(JSContextRef context, JSObjectRef object,
+//        JSStringRef propertyName, JSValueRef* exception)
+//{
+//    return true;
+//}
+
+void JSTizen::getPropertyNames(JSContextRef context, JSObjectRef object,
+        JSPropertyNameAccumulatorRef propertyNames)
+{
+    Try
+    {
+        TizenPrivate* priv =
+            static_cast<TizenPrivate*>(JSObjectGetPrivate(object));
+        if (!priv || !priv->getObject()) {
+            LogError("No private obejct");
+            return;
+        }
+        PluginOnDemandPrivPtr privObj = priv->getObject();
+        privObj->getPluginManager()->addPropertiesToList(propertyNames);
+
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("Error occured");
+    }
+}
+
+bool JSTizen::hasInstance(JSContextRef context, JSObjectRef constructor,
+        JSValueRef possibleInstance, JSValueRef* exception)
+{
+    return true;
+}
+
+JSValueRef JSTizen::convertToType(JSContextRef context, JSObjectRef object,
+        JSType type, JSValueRef* exception)
+{
+    return JSValueMakeUndefined(context);
+}
+
+bool JSTizen::hasProperty(JSContextRef context,
+        JSObjectRef object, JSStringRef propertyName)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        TizenPrivate* priv = static_cast<TizenPrivate*>(JSObjectGetPrivate(object));
+
+        if (!priv || !priv->getObject()) {
+            LogError("No private obejct");
+            return false;
+        }
+
+        return priv->getObject()->getPluginManager()->hasChild(
+            CommonsJavaScript::Converter(context).toString(propertyName));
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("Error occured");
+    }
+
+    //let JSCore to handle this property
+    return false;
+}
+
+JSValueRef JSTizen::getProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    Try
+    {
+        TizenPrivate* priv =
+                static_cast<TizenPrivate*>(JSObjectGetPrivate(object));
+        if (!priv || !priv->getObject()) {
+            LogError("No private obejct");
+            return false;
+        }
+
+        return priv->getObject()->getPluginManager()->getProperty(
+            CommonsJavaScript::Converter(context).toString(propertyName));
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("Error occured");
+    }
+
+    /* During normal operation flow should not reach here,
+       but wrt may fail with loading plugin. */
+  return JSValueMakeUndefined(context);
+}
+
+bool JSTizen::setProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+{
+    LogDebug("entered");
+    Try
+    {
+        TizenPrivate* priv =
+                static_cast<TizenPrivate*>(JSObjectGetPrivate(object));
+        if (!priv || !priv->getObject()) {
+            LogError("No private obejct");
+            return false;
+        }
+        std::string strPropertyName = CommonsJavaScript::Converter(context).toString(propertyName);
+        if(!priv->getObject()->propertyInited(strPropertyName))
+        {
+            priv->getObject()->getPluginManager()->setProperty(
+                strPropertyName,
+                value);
+        }
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("Error occured");
+    }
+
+    //this code should not be reached. setProperty is not called when
+    //hasProperty returns false. Anyway, if we didn't set value then we
+    //return false.
+    return false;
+}
+
+JSValueRef JSTizen::listAvailableFeatures(JSContextRef context, JSObjectRef object,
+        JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    TizenPrivate* priv = static_cast<TizenPrivate*>(JSObjectGetPrivate(thisObject));
+    assert(priv);
+
+    /*
+     * Current Tizen spec assures that tizen is always available
+    AccessStatus status = DEVICEAPIS_CHECK_ACCESS(
+                                 DEVICEAPIS_FUNCTION_API_LIST_AVAIL_FEATURES);
+
+    SYNC_ACCESS_STATUS_HANDLER(status, context, exception);
+    */
+
+    try
+    {
+        if (!priv) {
+            ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "No private object");
+        }
+           PluginOnDemandPrivPtr privObj = priv->getObject();
+    }
+    catch(const WrtDeviceApis::Commons::Exception &ex)
+    {
+        return WrtDeviceApis::CommonsJavaScript::JSDOMExceptionFactory::UnknownException.make(context, exception);
+    }
+    JSObjectRef result = JSCreateArrayObject(context, 0, NULL);
+    int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+    WidgetDB::Api::IWidgetDBPtr widgetDB =
+        WidgetDB::Api::getWidgetDB(widgetId);
+    WidgetDB::Api::Features features = widgetDB->getRegisteredFeatures();
+    for (size_t i=0; i<features.size(); ++i) {
+        JSFeaturePrivateObject *priv = new JSFeaturePrivateObject(context, features[i]);
+        JSObjectRef tempObj = JSObjectMake(context, JSFeature::getClassRef(), priv);
+        if (tempObj) {
+            if (!JSSetArrayElement(context, result, i, tempObj)) {
+                delete priv;
+            }
+        }
+        else {
+            delete priv;
+        }
+    }
+    return result;
+}
+
+JSValueRef JSTizen::listActivatedFeatures(JSContextRef context, JSObjectRef object,
+        JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception)
+{
+    LogDebug("entered");
+
+    TizenPrivate* priv = static_cast<TizenPrivate*>(JSObjectGetPrivate(thisObject));
+    assert(priv);
+
+    /*
+     * Current Tizen spec assures that tizen is always available
+     AccessStatus status = DEVICEAPIS_CHECK_ACCESS(
+                                 DEVICEAPIS_FUNCTION_API_LIST_ACTIV_FEATURES);
+
+    SYNC_ACCESS_STATUS_HANDLER(status, context, exception);*/
+    try
+    {
+        if (!priv) {
+            ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "No private object");
+        }
+        PluginOnDemandPrivPtr privObj = priv->getObject();
+    }
+    catch(const WrtDeviceApis::Commons::Exception &ex)
+    {
+        return WrtDeviceApis::CommonsJavaScript::JSDOMExceptionFactory::UnknownException.make(context, exception);
+    }
+    JSObjectRef result = JSCreateArrayObject(context, 0, NULL);
+    int widgetId = WrtAccessSingleton::Instance().getWidgetId();
+    WidgetDB::Api::IWidgetDBPtr widgetDB =
+        WidgetDB::Api::getWidgetDB(widgetId);
+    WidgetDB::Api::Features features = widgetDB->getWidgetFeatures();
+    for (size_t i=0; i<features.size(); ++i) {
+        JSFeaturePrivateObject *priv = new JSFeaturePrivateObject(context, features[i]);
+        JSObjectRef tempObj = JSObjectMake(context, JSFeature::getClassRef(), priv);
+        if (tempObj) {
+            if (!JSSetArrayElement(context, result, i, tempObj)) {
+                delete priv;
+            }
+        }
+        else {
+            delete priv;
+        }
+    }
+    return result;
+}
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
diff --git a/src/standards/Tizen/Tizen/JSTizen.h b/src/standards/Tizen/Tizen/JSTizen.h
new file mode 100755 (executable)
index 0000000..d63a020
--- /dev/null
@@ -0,0 +1,141 @@
+//
+// 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        JSTizen.h
+ * @author
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGIN_JS_DEVICE_APIS_H_
+#define _WRT_PLUGIN_JS_DEVICE_APIS_H_
+
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include "PluginOnDemandPriv.h"
+
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+/**
+ * @class JSBondi
+ * @brief This class is javascript extenstion
+ *
+ */
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT<PluginOnDemandPrivPtr>::Type TizenPrivate;
+
+
+class JSTizen {
+public:
+    /**
+     * This method initializes this in the JS Engine.
+     */
+    static JSClassRef getClassRef();
+
+    /**
+     * Gets object's class description.
+     */
+    static const JSClassDefinition* getClassInfo();
+
+private:
+    /**
+     * The callback invoked when an object is first created.
+     */
+    static void initialize(JSContextRef context, JSObjectRef object);
+
+    /**
+     * The callback invoked when an object is finalized.
+     */
+    static void finalize(JSObjectRef object);
+
+    /**
+     * The callback invoked when 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 deleting a property.
+     */
+    static bool deleteProperty(JSContextRef context, JSObjectRef object,
+        JSStringRef propertyName, JSValueRef* exception);
+
+    /**
+     * The callback invoked when collecting the names of an object's properties.
+     */
+    static void getPropertyNames(JSContextRef ctx, JSObjectRef object,
+        JSPropertyNameAccumulatorRef propertyNames);
+
+    /**
+     * The callback invoked when an object is used as the target of an 'instanceof' expression.
+     */
+    static bool hasInstance(JSContextRef ctx, JSObjectRef constructor,
+        JSValueRef possibleInstance, JSValueRef* exception);
+
+    /**
+     * The callback invoked when converting an object to a particular JavaScript type.
+     */
+    static JSValueRef convertToType(JSContextRef ctx, JSObjectRef object,
+        JSType type, JSValueRef* exception);
+
+    /**
+     * This structure describes a statically declared value property.
+     */
+    static JSStaticValue m_properties[];
+
+    /**
+     * This structure contains properties and callbacks that define a type of object.
+     */
+    static JSClassDefinition m_classInfo;
+
+    /**
+     * This structure describes a statically declared function.
+     */
+    static JSStaticFunction m_functions[];
+
+    static JSClassRef m_classRef;
+
+    static JSValueRef listAvailableFeatures(JSContextRef context,
+        JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);
+
+    static JSValueRef listActivatedFeatures(JSContextRef context,
+        JSObjectRef object, JSObjectRef thisObject, size_t argumentCount,
+        const JSValueRef arguments[], JSValueRef* exception);
+};
+
+} // Tizen
+} // Tizen1_0
+} // TizenApis
+
+#endif //  _WRT_PLUGIN_JS_XXX_H_
diff --git a/src/standards/Tizen/Tizen/PluginOnDemandPriv.cpp b/src/standards/Tizen/Tizen/PluginOnDemandPriv.cpp
new file mode 100755 (executable)
index 0000000..03b6525
--- /dev/null
@@ -0,0 +1,60 @@
+//
+// 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        PluginOnDemandPriv.cpp
+ * @author
+ * @version     0.1
+ * @brief
+ */
+
+#include "PluginOnDemandPriv.h"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+using namespace WrtDeviceApis::PluginManager::Api;
+
+PluginOnDemandPriv::PluginOnDemandPriv(const IPluginManagerPtr &pluginManager) :
+    m_pluginManager(pluginManager)
+{
+}
+
+PluginOnDemandPriv::~PluginOnDemandPriv()
+{
+}
+
+IPluginManagerPtr PluginOnDemandPriv::getPluginManager() const
+{
+    return m_pluginManager;
+}
+
+bool PluginOnDemandPriv::propertyInited(std::string &propertyName)
+{
+    if(m_initedProperties.find(propertyName) == m_initedProperties.end())
+    {
+        m_initedProperties.insert(propertyName);
+        return false;
+    }
+
+    return true;
+}
+
+}
+}
+}
diff --git a/src/standards/Tizen/Tizen/PluginOnDemandPriv.h b/src/standards/Tizen/Tizen/PluginOnDemandPriv.h
new file mode 100755 (executable)
index 0000000..55845fc
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// 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        PluginOnDemandPriv.h
+ * @author
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _WRT_PLUGIN_STANDARDS_TIZEN_DEVICEAPIS_PLUGIN_ON_DEMAND_PRIV
+#define _WRT_PLUGIN_STANDARDS_TIZEN_DEVICEAPIS_PLUGIN_ON_DEMAND_PRIV
+
+#include <map>
+#include <set>
+#include <string>
+#include <dpl/shared_ptr.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <PluginManager/IPluginManager.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+class PluginOnDemandPriv
+{
+  public:
+    PluginOnDemandPriv(
+        const WrtDeviceApis::PluginManager::Api::IPluginManagerPtr &pluginManager);
+
+    virtual ~PluginOnDemandPriv();
+
+    WrtDeviceApis::PluginManager::Api::IPluginManagerPtr getPluginManager() const;
+
+    bool propertyInited(std::string &propertyName);
+
+  private:
+    WrtDeviceApis::PluginManager::Api::IPluginManagerPtr m_pluginManager;
+
+    std::set<std::string> m_initedProperties;
+};
+
+typedef DPL::SharedPtr<PluginOnDemandPriv> PluginOnDemandPrivPtr;
+
+}
+}
+}
+
+#endif
diff --git a/src/standards/Tizen/Tizen/config.xml b/src/standards/Tizen/Tizen/config.xml
new file mode 100755 (executable)
index 0000000..089dd05
--- /dev/null
@@ -0,0 +1,25 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+    <library-name>libwrt-plugins-tizen-2.0-tizen.so</library-name>
+    <feature-install-uri>tizen.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/tizen</name>
+        <Object name="tizen">
+        <!--
+            <Function name="listAvailableFeatures"/>
+            <Function name="listActivatedFeatures"/>
+            <Function name="createCompositeFilter"/>
+            <Function name="createAttributeFilter"/>
+            <Function name="createAttributeRangeFilter"/>
+            <Function name="createIDFilter"/>
+            <Function name="createSortMode"/>
+        -->
+        </Object>
+    </api-feature>
+</plugin-properties>
+
diff --git a/src/standards/Tizen/Tizen/plugin_config.cpp b/src/standards/Tizen/Tizen/plugin_config.cpp
new file mode 100755 (executable)
index 0000000..ea526b0
--- /dev/null
@@ -0,0 +1,101 @@
+//
+// 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        plugin_config.cpp
+ * @author
+ * @version     0.1
+ * @brief
+ */
+
+#include <map>
+#include <utility>
+#include <Commons/FunctionDefinition.h>
+#include <Commons/FunctionDeclaration.h>
+#include <Commons/Exception.h>
+
+#define TIZEN_FEATURE_API "http://tizen.org/privilege/tizen"
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+const char* TIZEN_FUNCTION_API_LIST_AVAIL_FEATURES =
+    "listAvailableFeatures";
+const char* TIZEN_FUNCTION_API_LIST_ACTIV_FEATURES =
+    "listActivatedFeatures";
+
+static WrtDeviceApis::Commons::FunctionMapping createDeviceApisFunctions();
+
+static WrtDeviceApis::Commons::FunctionMapping DeviceApisFunctions =
+    createDeviceApisFunctions();
+
+DEFINE_FUNCTION_GETTER(DeviceApis, DeviceApisFunctions);
+
+static WrtDeviceApis::Commons::FunctionMapping createDeviceApisFunctions()
+{
+    ACE_CREATE_DEVICE_CAPS_LIST(EMPTY_DEVICE_LIST);
+
+    //
+    // --- features ----
+    //
+
+    ACE_CREATE_FEATURE(FEATURE_TIZEN,TIZEN_FEATURE_API);
+
+    ACE_CREATE_FEATURE_LIST(FEATURE_LIST_TIZEN);
+    ACE_ADD_API_FEATURE(FEATURE_LIST_TIZEN,FEATURE_TIZEN);
+
+    //
+    // --- functions ---
+    //
+
+    WrtDeviceApis::Commons::FunctionMapping DeviceApisMapping;
+
+    //LIST_AVAIL
+    WrtDeviceApis::Commons::AceFunction listAvailableFeaturesFuncs = ACE_CREATE_FUNCTION(
+        FUNCTION_LIST_AVAILABLE_FEATURES,
+        TIZEN_FUNCTION_API_LIST_AVAIL_FEATURES,
+        FEATURE_LIST_TIZEN,
+        EMPTY_DEVICE_LIST);
+
+    DeviceApisMapping.insert(
+        std::make_pair(
+        TIZEN_FUNCTION_API_LIST_AVAIL_FEATURES,
+        listAvailableFeaturesFuncs));
+
+    //LIST_ACTIV
+    WrtDeviceApis::Commons::AceFunction listActivatedFeaturesFunc = ACE_CREATE_FUNCTION(
+        FUNCTION_LIST_ACTIVATED_FEATURES,
+        TIZEN_FUNCTION_API_LIST_ACTIV_FEATURES,
+        FEATURE_LIST_TIZEN,
+        EMPTY_DEVICE_LIST);
+
+    DeviceApisMapping.insert(
+        std::make_pair(
+        TIZEN_FUNCTION_API_LIST_ACTIV_FEATURES,
+        listActivatedFeaturesFunc));
+
+    return DeviceApisMapping;
+}
+
+}
+} // namespace Tizen1_0
+} // namespace TizenApis
+
+#undef TIZEN_FEATURE_API
+#undef TIZEN_FUNCTION_API_LIST_ACTIV_FEATURES
+#undef TIZEN_FUNCTION_API_LIST_AVAIL_FEATURES
diff --git a/src/standards/Tizen/Tizen/plugin_config.h b/src/standards/Tizen/Tizen/plugin_config.h
new file mode 100755 (executable)
index 0000000..5385963
--- /dev/null
@@ -0,0 +1,46 @@
+//
+// 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        plugin_config.h
+ * @author
+ * @version     0.1
+ * @brief
+ */
+
+#ifndef _TIZEN_PLUGIN_CONFIG_H_
+#define _TIZEN_PLUGIN_CONFIG_H_
+
+#include <Commons/FunctionDeclaration.h>
+
+namespace TizenApis {
+namespace Tizen1_0 {
+namespace Tizen {
+
+extern const char* TIZEN_FUNCTION_API_LIST_AVAIL_FEATURES;
+extern const char* TIZEN_FUNCTION_API_LIST_ACTIV_FEATURES;
+extern const char* TIZEN_FUNCTION_API_CREATE_COMPOSITE_FILTER;
+extern const char* TIZEN_FUNCTION_API_CREATE_ATTRIBUTE_FILTER;
+extern const char* TIZEN_FUNCTION_API_CREATE_ATTRIBUTE_RANGE_FILTER;
+extern const char* TIZEN_FUNCTION_API_CREATE_ID_FILTER;
+extern const char* TIZEN_FUNCTION_API_CREATE_SORT_MODE;
+
+}
+}
+}
+
+#endif //  _TIZEN_PLUGIN_CONFIG_H_
diff --git a/src/standards/Tizen/Tizen/plugin_initializer.cpp b/src/standards/Tizen/Tizen/plugin_initializer.cpp
new file mode 100755 (executable)
index 0000000..907d18d
--- /dev/null
@@ -0,0 +1,113 @@
+//
+// 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        plugin_initializer.cpp
+ * @author      Karol Majewski (k.majewski@samsung.com)
+ * @version     0.1
+ * @brief
+ */
+
+#include <dpl/log/log.h>
+#include <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include <Commons/Exception.h>
+#include "JSTizen.h"
+#include "JSAttributeFilter.h"
+#include "JSAttributeRangeFilter.h"
+#include "JSCompositeFilter.h"
+#include "JSSortMode.h"
+#include "JSSimpleCoordinates.h"
+
+#define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen"
+
+#define OBJECT_TIZEN "tizen"
+
+namespace Options{
+
+class_definition_options_t TizenOptions =
+{
+    JS_CLASS,
+    CREATE_INSTANCE,
+    NONE_NOTICE,
+    USE_OVERLAYED, //ignored
+    NULL,
+    NULL
+};
+
+}
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+void on_widget_start_callback(int widgetId)
+{
+    LogDebug("[Tizen\\xxx] on_widget_start_callback ("<<widgetId<<")");
+    Try
+    {
+        WrtAccessSingleton::Instance().initialize(widgetId);
+    }
+    Catch(Commons::Exception)
+    {
+        LogError("WrtAccess initialization failed");
+    }
+}
+
+void on_widget_stop_callback(int widgetId)
+{
+    LogDebug("[Tizen\\xxx] on_widget_stop_callback ("<<widgetId<<")");
+    Try
+    {
+        WrtAccessSingleton::Instance().deinitialize(widgetId);
+    }
+    Catch(WrtDeviceApis::Commons::Exception)
+    {
+        LogError("WrtAccess deinitialization failed");
+    }
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+PLUGIN_CLASS_MAP_BEGIN
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_GLOBAL,
+                               OBJECT_TIZEN,
+                               (js_class_template_getter)TizenApis::Tizen1_0::Tizen::JSTizen::getClassRef,
+                               &Options::TizenOptions)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "AttributeFilter",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Tizen::JSAttributeFilter::getClassRef,
+                               &Options::TizenOptions)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "AttributeRangeFilter",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Tizen::JSAttributeRangeFilter::getClassRef,
+                               &Options::TizenOptions)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "CompositeFilter",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Tizen::JSCompositeFilter::getClassRef,
+                               &Options::TizenOptions)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "SortMode",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Tizen::JSSortMode::getClassRef,
+                               &Options::TizenOptions)
+    PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+                               "SimpleCoordinates",
+                               (js_class_template_getter)TizenApis::Tizen1_0::Tizen::JSSimpleCoordinates::getClassRef,
+                               &Options::TizenOptions)
+PLUGIN_CLASS_MAP_END
+
+#undef OBJECT_TIZEN
diff --git a/wrt-plugins-tizen.manifest b/wrt-plugins-tizen.manifest
new file mode 100644 (file)
index 0000000..81ace0c
--- /dev/null
@@ -0,0 +1,6 @@
+<manifest>
+       <request>
+               <domain name="_"/>
+       </request>
+</manifest>
+