From a87694c0ced5c390c924a345ab3eb0ad1549718d Mon Sep 17 00:00:00 2001 From: Sangtai Kim Date: Fri, 17 Feb 2012 16:53:46 +0900 Subject: [PATCH] merge wrt-plugins-tizen_0.2.0-2 --- debian/changelog | 17 + .../API/Application/ApplicationInformation.cpp | 15 + .../API/Application/ApplicationInformation.h | 5 +- .../API/Application/ApplicationService.cpp | 62 +- src/platform/API/Application/ApplicationService.h | 8 +- .../Application/ApplicationServiceExtraData.cpp | 53 - .../API/Application/ApplicationServiceExtraData.h | 55 - .../API/Application/ApplicationServiceReply.cpp | 67 - .../API/Application/ApplicationServiceReply.h | 51 - .../API/Application/ApplicationServiceRequest.cpp | 104 -- .../API/Application/ApplicationServiceRequest.h | 72 -- .../Application/EventInstalledApplicationChanged.h | 16 +- .../API/Application/EventManageApplication.h | 3 +- src/platform/API/Application/IApplication.h | 2 +- src/platform/API/Calendar/CalendarEvent.cpp | 3 +- src/platform/API/Calendar/EventAttendee.cpp | 31 +- src/platform/API/Calendar/EventAttendee.h | 18 +- src/platform/API/Contact/Contact.cpp | 129 -- src/platform/API/Contact/Contact.h | 82 -- src/platform/API/Contact/ContactAccount.cpp | 35 +- src/platform/API/Contact/ContactAccount.h | 11 +- src/platform/API/Contact/ContactAddress.cpp | 52 +- src/platform/API/Contact/ContactAddress.h | 1 + src/platform/API/Contact/ContactAnniversary.cpp | 19 +- src/platform/API/Contact/ContactAnniversary.h | 1 + src/platform/API/Contact/ContactEmailAddress.cpp | 20 +- src/platform/API/Contact/ContactEmailAddress.h | 1 + src/platform/API/Contact/ContactFactory.cpp | 22 +- src/platform/API/Contact/ContactFactory.h | 4 + src/platform/API/Contact/ContactName.cpp | 46 +- src/platform/API/Contact/ContactName.h | 5 +- src/platform/API/Contact/ContactOrganization.cpp | 35 +- src/platform/API/Contact/ContactOrganization.h | 1 + src/platform/API/Contact/ContactPhoneNumber.cpp | 33 +- src/platform/API/Contact/ContactPhoneNumber.h | 11 +- src/platform/API/Contact/ContactProperties.cpp | 351 ----- src/platform/API/Contact/ContactRef.cpp | 112 ++ src/platform/API/Contact/ContactRef.h | 74 ++ src/platform/API/Contact/ContactTypes.h | 11 +- src/platform/API/Contact/ContactWebSite.cpp | 20 +- src/platform/API/Contact/ContactWebSite.h | 1 + .../API/Contact/EventAddressBookAddBatch.h | 26 +- .../API/Contact/EventAddressBookChangeListener.h | 3 +- src/platform/API/Contact/EventAddressBookFind.h | 43 +- .../API/Contact/EventAddressBookUpdateBatch.h | 2 +- .../Contact/EventContactManagerGetAddressBooks.h | 6 +- src/platform/API/Contact/IAddressBook.h | 17 +- src/platform/API/Contact/IContact.cpp | 468 +++++++ .../Contact/{ContactProperties.h => IContact.h} | 49 +- .../API/Contact/IContactEventPrivateData.h | 1 + src/platform/API/Contact/IContactManager.cpp | 1 + src/platform/API/Contact/IContactManager.h | 3 +- src/platform/API/Contact/config.cmake | 4 +- src/platform/API/Filesystem/Enums.h | 6 +- src/platform/API/Filesystem/IManager.h | 1 + src/platform/API/Filesystem/StorageProperties.h | 1 + src/platform/API/Filter/AnyType.cpp | 5 + src/platform/API/Filter/AnyType.h | 1 + src/platform/API/Filter/AttributeFilter.cpp | 16 +- src/platform/API/Filter/AttributeFilter.h | 8 +- src/platform/API/Filter/FilterFactory.cpp | 4 +- src/platform/API/Filter/FilterFactory.h | 2 +- src/platform/API/Filter/FilterValidator.cpp | 31 +- src/platform/API/Filter/FilterValidator.h | 2 +- src/platform/API/Filter/IFilterVisitor.h | 2 +- .../API/Mediacontent/IEventAddAudioToPlaylist.h | 83 -- src/platform/API/Mediacontent/IEventBrowseFolder.h | 175 +++ .../API/Mediacontent/IEventDeleteAudioToPlaylist.h | 83 -- src/platform/API/Mediacontent/IEventFindMedia.h | 1 + src/platform/API/Mediacontent/IEventFindPlaylist.h | 57 - .../API/Mediacontent/IEventFolderFindMedia.h | 57 - src/platform/API/Mediacontent/IEventUpdateMedia.h | 1 - ...ntDeletePlaylist.h => IEventUpdateMediaItems.h} | 43 +- src/platform/API/Mediacontent/IMediacontent.cpp | 20 +- src/platform/API/Mediacontent/IMediacontent.h | 11 +- .../API/Mediacontent/MediacontentAudio.cpp | 23 + src/platform/API/Mediacontent/MediacontentAudio.h | 7 +- .../API/Mediacontent/MediacontentFolder.cpp | 6 - src/platform/API/Mediacontent/MediacontentFolder.h | 6 +- .../API/Mediacontent/MediacontentImage.cpp | 10 + src/platform/API/Mediacontent/MediacontentImage.h | 3 + .../API/Mediacontent/MediacontentMedia.cpp | 26 +- src/platform/API/Mediacontent/MediacontentMedia.h | 10 +- .../API/Mediacontent/MediacontentVideo.cpp | 23 + src/platform/API/Mediacontent/MediacontentVideo.h | 6 + src/platform/API/Mediacontent/config.cmake | 16 + .../API/Messaging/ConversationFilterValidator.cpp | 21 +- .../API/Messaging/ConversationFilterValidator.h | 2 +- .../API/Messaging/FolderFilterValidator.cpp | 17 +- src/platform/API/Messaging/FolderFilterValidator.h | 2 +- .../API/Messaging/FolderFilterValidatorFactory.cpp | 0 .../API/Messaging/MessageFilterValidator.cpp | 20 +- .../API/Messaging/MessageFilterValidator.h | 2 +- .../StorageChangesConversationFilterValidator.cpp | 11 +- .../StorageChangesConversationFilterValidator.h | 2 +- .../StorageChangesConversationGenerator.cpp | 35 +- .../StorageChangesConversationGenerator.h | 2 +- .../StorageChangesFolderFilterValidator.cpp | 7 +- .../StorageChangesFolderFilterValidator.h | 2 +- .../Messaging/StorageChangesFolderGenerator.cpp | 36 +- .../API/Messaging/StorageChangesFolderGenerator.h | 4 +- .../StorageChangesMessageFilterValidator.cpp | 7 +- .../StorageChangesMessageFilterValidator.h | 2 +- .../Messaging/StorageChangesMessageGenerator.cpp | 37 +- .../API/Messaging/StorageChangesMessageGenerator.h | 2 +- src/platform/Tizen/Account/AccountService.cpp | 225 ---- src/platform/Tizen/Account/AccountService.h | 56 - src/platform/Tizen/Application/Application.cpp | 973 ++++++++------ src/platform/Tizen/Application/Application.h | 7 +- .../Tizen/Bluetooth/BluetoothAdapterManager.cpp | 18 +- .../Tizen/Bluetooth/BluetoothDeviceManager.cpp | 7 +- src/platform/Tizen/Calendar/Calendar.cpp | 21 +- src/platform/Tizen/Calendar/CalendarFilter.cpp | 92 +- src/platform/Tizen/Calendar/CalendarFilter.h | 2 +- src/platform/Tizen/Calendar/EventWrapper.cpp | 12 +- src/platform/Tizen/Call/CallHistoryFilter.cpp | 24 +- src/platform/Tizen/Call/CallHistoryFilter.h | 2 +- src/platform/Tizen/Contact/AddressBook.cpp | 235 +--- src/platform/Tizen/Contact/AddressBook.h | 54 +- src/platform/Tizen/Contact/AddressBookStorage.cpp | 101 ++ src/platform/Tizen/Contact/AddressBookStorage.h | 58 + src/platform/Tizen/Contact/Contact.cpp | 114 ++ src/platform/Tizen/Contact/Contact.h | 53 + .../Tizen/Contact/ContactImpl.h} | 35 +- src/platform/Tizen/Contact/ContactManager.cpp | 62 +- src/platform/Tizen/Contact/ContactManager.h | 8 +- src/platform/Tizen/Contact/ContactSearchEngine.cpp | 84 +- src/platform/Tizen/Contact/ContactSearchEngine.h | 5 +- src/platform/Tizen/Contact/ContactWrapper.cpp | 89 +- src/platform/Tizen/Contact/ContactWrapper.h | 2 +- src/platform/Tizen/Contact/DownloadManager.cpp | 185 +++ src/platform/Tizen/Contact/DownloadManager.h | 95 ++ src/platform/Tizen/Contact/config.cmake | 3 + src/platform/Tizen/Filesystem/Manager.cpp | 44 +- src/platform/Tizen/Filesystem/Manager.h | 1 + .../Tizen/Mediacontent/MediaFilterValidator.cpp | 16 +- .../Tizen/Mediacontent/MediaSearchVisitor.cpp | 58 +- .../Tizen/Mediacontent/MediaSearchVisitor.h | 2 +- src/platform/Tizen/Mediacontent/Mediacontent.cpp | 344 ++++- src/platform/Tizen/Mediacontent/Mediacontent.h | 5 + .../Tizen/Messaging/FolderQueryGenerator.cpp | 28 +- .../Tizen/Messaging/FolderQueryGenerator.h | 2 +- .../Tizen/Messaging/MessageQueryGenerator.cpp | 36 +- .../Tizen/Messaging/MessageQueryGenerator.h | 4 +- src/standards/Tizen/Account/CMakeLists.txt | 35 +- src/standards/Tizen/Account/JSAccountService.cpp | 597 --------- src/standards/Tizen/Account/JSAccountService.h | 163 --- src/standards/Tizen/Alarm/AlarmAbsolute.cpp | 73 +- src/standards/Tizen/Alarm/AlarmAbsolute.h | 35 +- src/standards/Tizen/Alarm/AlarmConverter.cpp | 165 ++- src/standards/Tizen/Alarm/AlarmConverter.h | 20 +- src/standards/Tizen/Alarm/AlarmRecurrence.cpp | 72 -- src/standards/Tizen/Alarm/AlarmRecurrence.h | 51 - src/standards/Tizen/Alarm/AlarmRelative.cpp | 65 +- src/standards/Tizen/Alarm/AlarmRelative.h | 22 +- src/standards/Tizen/Alarm/CMakeLists.txt | 12 +- src/standards/Tizen/Alarm/JSAlarmAbsolute.cpp | 281 ++-- src/standards/Tizen/Alarm/JSAlarmAbsolute.h | 19 +- src/standards/Tizen/Alarm/JSAlarmManager.cpp | 575 +++++---- src/standards/Tizen/Alarm/JSAlarmManager.h | 35 +- src/standards/Tizen/Alarm/JSAlarmRecurrence.cpp | 424 ------ src/standards/Tizen/Alarm/JSAlarmRecurrence.h | 95 -- src/standards/Tizen/Alarm/JSAlarmRelative.cpp | 322 +++-- src/standards/Tizen/Alarm/JSAlarmRelative.h | 19 +- src/standards/Tizen/Alarm/alarm_common.h | 46 + src/standards/Tizen/Alarm/config.xml | 21 +- src/standards/Tizen/Alarm/plugin_config.cpp | 172 +++ src/standards/Tizen/Alarm/plugin_config.h | 50 + src/standards/Tizen/Alarm/plugin_initializer.cpp | 1 - .../Application/ApplicationAnswerReceiver.cpp | 101 +- .../Tizen/Application/ApplicationConverter.cpp | 41 +- .../ApplicationInformationEventCallback.h | 46 - .../Tizen/Application/ApplicationListener.cpp | 69 +- .../Tizen/Application/ApplicationUtil.cpp | 107 ++ src/standards/Tizen/Application/ApplicationUtil.h | 51 + src/standards/Tizen/Application/CMakeLists.txt | 10 +- src/standards/Tizen/Application/JSApplication.cpp | 949 ++++++-------- src/standards/Tizen/Application/JSApplication.h | 4 +- .../Tizen/Application/JSApplicationContext.cpp | 135 +- .../Tizen/Application/JSApplicationContext.h | 34 +- .../Tizen/Application/JSApplicationContextArray.h | 11 + .../Tizen/Application/JSApplicationEvent.cpp | 44 +- .../Tizen/Application/JSApplicationInformation.cpp | 145 ++- .../Tizen/Application/JSApplicationInformation.h | 28 +- .../Tizen/Application/JSApplicationService.cpp | 266 ++-- .../Tizen/Application/JSApplicationService.h | 6 + .../Tizen/Application/JSApplicationServiceData.cpp | 170 ++- .../Tizen/Application/JSApplicationServiceData.h | 15 +- .../Application/JSApplicationServiceExtraData.cpp | 223 ---- .../JSApplicationServiceExtraDataArray.cpp | 575 --------- .../JSApplicationServiceExtraDataArray.h | 174 --- .../Application/JSApplicationServiceReply.cpp | 209 --- .../Tizen/Application/JSApplicationServiceReply.h | 103 -- .../Application/JSApplicationServiceRequest.cpp | 213 --- .../Application/JSApplicationServiceRequest.h | 95 -- src/standards/Tizen/Application/config.xml | 19 +- src/standards/Tizen/Application/plugin_config.cpp | 248 ++-- src/standards/Tizen/Application/plugin_config.h | 35 +- .../Tizen/Bluetooth/BluetoothAdapterListener.cpp | 7 +- .../Tizen/Bluetooth/BluetoothConverter.cpp | 7 +- .../Bluetooth/BluetoothDeviceManagerListener.cpp | 9 +- src/standards/Tizen/Bluetooth/CMakeLists.txt | 3 - .../Tizen/Bluetooth/JSBluetoothAdapter.cpp | 189 ++- .../Tizen/Bluetooth/JSBluetoothDevice.cpp | 139 +- .../Tizen/Bluetooth/JSBluetoothManager.cpp | 56 +- src/standards/Tizen/Bluetooth/JSBluetoothManager.h | 4 + .../Tizen/Bluetooth/JSBluetoothSocket.cpp | 70 +- .../Tizen/Bluetooth/plugin_initializer.cpp | 6 +- src/standards/Tizen/CMakeLists.txt | 19 + src/standards/Tizen/Calendar/CMakeLists.txt | 27 +- src/standards/Tizen/Calendar/CalendarConverter.cpp | 2 +- src/standards/Tizen/Calendar/JSAttendee.cpp | 253 ---- src/standards/Tizen/Calendar/JSAttendee.h | 106 -- .../Tizen/Calendar/JSCalendarAttendee.cpp | 4 +- src/standards/Tizen/Calendar/JSEventAlarm.cpp | 217 ---- src/standards/Tizen/Calendar/JSEventAlarm.h | 95 -- src/standards/Tizen/Calendar/JSEventId.cpp | 194 --- src/standards/Tizen/Calendar/JSEventId.h | 91 -- src/standards/Tizen/Calendar/JSRecurrenceRule.cpp | 266 ---- src/standards/Tizen/Calendar/JSRecurrenceRule.h | 106 -- src/standards/Tizen/Call/CMakeLists.txt | 21 +- src/standards/Tizen/Call/JSCallApi.cpp | 131 -- src/standards/Tizen/Call/JSCallApi.h | 59 - src/standards/Tizen/Common/CMakeLists.txt | 16 + .../Tizen/Contact/AddressBookController.cpp | 11 +- .../Tizen/Contact/AddressBookController.h | 4 +- src/standards/Tizen/Contact/CMakeLists.txt | 48 +- src/standards/Tizen/Contact/ContactConverter.cpp | 1365 +++++++++----------- src/standards/Tizen/Contact/ContactConverter.h | 143 +- .../Tizen/Contact/ContactManagerController.cpp | 3 +- src/standards/Tizen/Contact/JSAddressBook.cpp | 324 +++-- src/standards/Tizen/Contact/JSAddressBook.h | 32 +- src/standards/Tizen/Contact/JSAddressBookArray.cpp | 58 +- src/standards/Tizen/Contact/JSAddressBookArray.h | 6 +- .../Contact/JSAddressBookChangeCallbackManager.cpp | 25 - src/standards/Tizen/Contact/JSContact.cpp | 889 ++++++++++++- src/standards/Tizen/Contact/JSContact.h | 179 ++- src/standards/Tizen/Contact/JSContactAccount.cpp | 162 ++- src/standards/Tizen/Contact/JSContactAccount.h | 21 +- src/standards/Tizen/Contact/JSContactAddress.cpp | 186 ++- src/standards/Tizen/Contact/JSContactAddress.h | 23 +- .../Tizen/Contact/JSContactAddressArray.cpp | 18 - .../Tizen/Contact/JSContactAddressTypeArray.cpp | 18 - .../Tizen/Contact/JSContactAnniversary.cpp | 160 ++- src/standards/Tizen/Contact/JSContactAnniversary.h | 17 +- .../Tizen/Contact/JSContactAnniversaryArray.cpp | 18 - src/standards/Tizen/Contact/JSContactArray.cpp | 18 - src/standards/Tizen/Contact/JSContactArray.h | 2 +- .../Tizen/Contact/JSContactEmailAddress.cpp | 154 ++- .../Tizen/Contact/JSContactEmailAddress.h | 17 +- .../Tizen/Contact/JSContactEmailAddressArray.cpp | 18 - .../Contact/JSContactEmailAddressTypeArray.cpp | 18 - src/standards/Tizen/Contact/JSContactManager.cpp | 86 +- src/standards/Tizen/Contact/JSContactManager.h | 10 + src/standards/Tizen/Contact/JSContactName.cpp | 226 +++- src/standards/Tizen/Contact/JSContactName.h | 22 +- .../Tizen/Contact/JSContactOrganization.cpp | 177 ++- .../Tizen/Contact/JSContactOrganization.h | 21 +- .../Tizen/Contact/JSContactOrganizationArray.cpp | 18 - .../Tizen/Contact/JSContactPhoneNumber.cpp | 151 ++- src/standards/Tizen/Contact/JSContactPhoneNumber.h | 17 +- .../Tizen/Contact/JSContactPhoneNumberArray.cpp | 18 - .../Contact/JSContactPhoneNumberTypeArray.cpp | 18 - .../Tizen/Contact/JSContactProperties.cpp | 799 ------------ src/standards/Tizen/Contact/JSContactProperties.h | 242 ---- src/standards/Tizen/Contact/JSContactRef.cpp | 329 +++++ .../JSContactRef.h} | 63 +- src/standards/Tizen/Contact/JSContactWebSite.cpp | 161 ++- src/standards/Tizen/Contact/JSContactWebSite.h | 17 +- .../Tizen/Contact/JSContactWebSiteArray.cpp | 18 - src/standards/Tizen/Contact/JSStringArray.cpp | 18 - src/standards/Tizen/Contact/plugin_config.cpp | 45 +- src/standards/Tizen/Contact/plugin_config.h | 3 +- src/standards/Tizen/Contact/plugin_initializer.cpp | 50 + src/standards/Tizen/Filesystem/CMakeLists.txt | 29 +- src/standards/Tizen/Filesystem/Converter.cpp | 12 +- src/standards/Tizen/Filesystem/FilesystemUtils.cpp | 12 +- src/standards/Tizen/Filesystem/JSFile.cpp | 2 +- .../Tizen/Filesystem/JSFilesystemManager.cpp | 21 + src/standards/Tizen/Filesystem/JSStorage.cpp | 4 +- src/standards/Tizen/Geocoder/CMakeLists.txt | 3 - src/standards/Tizen/Mediacontent/CMakeLists.txt | 18 +- src/standards/Tizen/Mediacontent/JSAudio.cpp | 1 - src/standards/Tizen/Mediacontent/JSFolder.cpp | 71 +- src/standards/Tizen/Mediacontent/JSImage.cpp | 12 +- src/standards/Tizen/Mediacontent/JSImage.h | 2 + src/standards/Tizen/Mediacontent/JSMedia.cpp | 41 + src/standards/Tizen/Mediacontent/JSMedia.h | 8 +- .../Tizen/Mediacontent/JSMediacontent.cpp | 534 ++++---- src/standards/Tizen/Mediacontent/JSMediacontent.h | 41 +- src/standards/Tizen/Mediacontent/JSVideo.cpp | 12 +- .../Tizen/Mediacontent/MediaConverter.cpp | 21 + src/standards/Tizen/Mediacontent/MediaConverter.h | 6 +- .../Tizen/Mediacontent/MediacontentController.cpp | 65 +- .../Tizen/Mediacontent/MediacontentController.h | 9 +- src/standards/Tizen/Mediacontent/config.xml | 19 +- src/standards/Tizen/Mediacontent/plugin_config.cpp | 157 +++ src/standards/Tizen/Mediacontent/plugin_config.h | 50 + src/standards/Tizen/Messaging/CMakeLists.txt | 18 +- src/standards/Tizen/Messaging/ConverterMessage.cpp | 2 +- src/standards/Tizen/Messaging/JSMessage.cpp | 2 +- .../Tizen/Messaging/JSMessagingService.cpp | 2 +- .../Tizen/Messaging/JSMessagingStorage.cpp | 46 +- ...MessagingListener.cpp => MessagingListener.cpp} | 34 +- .../{JSMessagingListener.h => MessagingListener.h} | 14 +- .../Tizen/Messaging/plugin_initializer.cpp | 7 + src/standards/Tizen/NFC/CMakeLists.txt | 3 - src/standards/Tizen/Systeminfo/CMakeLists.txt | 3 - src/standards/Tizen/TimeUtil/CMakeLists.txt | 40 +- src/standards/Tizen/Tizen/CMakeLists.txt | 32 +- src/standards/Tizen/Tizen/FilterConverter.cpp | 322 ----- src/standards/Tizen/Tizen/JSAttributeFilter.cpp | 78 +- src/standards/Tizen/Tizen/JSAttributeFilter.h | 8 +- .../Tizen/Tizen/JSAttributeRangeFilter.cpp | 51 +- src/standards/Tizen/Tizen/JSAttributeRangeFilter.h | 6 +- src/standards/Tizen/Tizen/JSCompositeFilter.cpp | 51 +- src/standards/Tizen/Tizen/JSCompositeFilter.h | 4 +- src/standards/Tizen/Tizen/JSSimpleCoordinates.cpp | 30 +- src/standards/Tizen/Tizen/JSSimpleCoordinates.h | 4 +- src/standards/Tizen/Tizen/JSSortMode.cpp | 51 +- src/standards/Tizen/Tizen/JSSortMode.h | 4 +- 321 files changed, 11004 insertions(+), 13398 deletions(-) delete mode 100755 src/platform/API/Application/ApplicationServiceExtraData.cpp delete mode 100755 src/platform/API/Application/ApplicationServiceExtraData.h delete mode 100755 src/platform/API/Application/ApplicationServiceReply.cpp delete mode 100755 src/platform/API/Application/ApplicationServiceReply.h delete mode 100755 src/platform/API/Application/ApplicationServiceRequest.cpp delete mode 100755 src/platform/API/Application/ApplicationServiceRequest.h delete mode 100755 src/platform/API/Contact/Contact.cpp delete mode 100755 src/platform/API/Contact/Contact.h delete mode 100755 src/platform/API/Contact/ContactProperties.cpp create mode 100755 src/platform/API/Contact/ContactRef.cpp create mode 100755 src/platform/API/Contact/ContactRef.h create mode 100755 src/platform/API/Contact/IContact.cpp rename src/platform/API/Contact/{ContactProperties.h => IContact.h} (79%) delete mode 100644 src/platform/API/Mediacontent/IEventAddAudioToPlaylist.h create mode 100644 src/platform/API/Mediacontent/IEventBrowseFolder.h delete mode 100644 src/platform/API/Mediacontent/IEventDeleteAudioToPlaylist.h delete mode 100644 src/platform/API/Mediacontent/IEventFindPlaylist.h delete mode 100644 src/platform/API/Mediacontent/IEventFolderFindMedia.h rename src/platform/API/Mediacontent/{IEventDeletePlaylist.h => IEventUpdateMediaItems.h} (61%) mode change 100644 => 100755 src/platform/API/Messaging/FolderFilterValidatorFactory.cpp delete mode 100755 src/platform/Tizen/Account/AccountService.cpp delete mode 100755 src/platform/Tizen/Account/AccountService.h create mode 100755 src/platform/Tizen/Contact/AddressBookStorage.cpp create mode 100755 src/platform/Tizen/Contact/AddressBookStorage.h create mode 100755 src/platform/Tizen/Contact/Contact.cpp create mode 100755 src/platform/Tizen/Contact/Contact.h rename src/{standards/Tizen/Application/ApplicationServiceReplyCallback.h => platform/Tizen/Contact/ContactImpl.h} (56%) create mode 100755 src/platform/Tizen/Contact/DownloadManager.cpp create mode 100755 src/platform/Tizen/Contact/DownloadManager.h delete mode 100755 src/standards/Tizen/Account/JSAccountService.cpp delete mode 100755 src/standards/Tizen/Account/JSAccountService.h delete mode 100755 src/standards/Tizen/Alarm/AlarmRecurrence.cpp delete mode 100755 src/standards/Tizen/Alarm/AlarmRecurrence.h delete mode 100755 src/standards/Tizen/Alarm/JSAlarmRecurrence.cpp delete mode 100755 src/standards/Tizen/Alarm/JSAlarmRecurrence.h create mode 100755 src/standards/Tizen/Alarm/alarm_common.h create mode 100755 src/standards/Tizen/Alarm/plugin_config.cpp create mode 100755 src/standards/Tizen/Alarm/plugin_config.h delete mode 100755 src/standards/Tizen/Application/ApplicationInformationEventCallback.h create mode 100755 src/standards/Tizen/Application/ApplicationUtil.cpp create mode 100755 src/standards/Tizen/Application/ApplicationUtil.h delete mode 100755 src/standards/Tizen/Application/JSApplicationServiceExtraData.cpp delete mode 100755 src/standards/Tizen/Application/JSApplicationServiceExtraDataArray.cpp delete mode 100755 src/standards/Tizen/Application/JSApplicationServiceExtraDataArray.h delete mode 100755 src/standards/Tizen/Application/JSApplicationServiceReply.cpp delete mode 100755 src/standards/Tizen/Application/JSApplicationServiceReply.h delete mode 100755 src/standards/Tizen/Application/JSApplicationServiceRequest.cpp delete mode 100755 src/standards/Tizen/Application/JSApplicationServiceRequest.h delete mode 100755 src/standards/Tizen/Calendar/JSAttendee.cpp delete mode 100755 src/standards/Tizen/Calendar/JSAttendee.h delete mode 100755 src/standards/Tizen/Calendar/JSEventAlarm.cpp delete mode 100755 src/standards/Tizen/Calendar/JSEventAlarm.h delete mode 100755 src/standards/Tizen/Calendar/JSEventId.cpp delete mode 100755 src/standards/Tizen/Calendar/JSEventId.h delete mode 100755 src/standards/Tizen/Calendar/JSRecurrenceRule.cpp delete mode 100755 src/standards/Tizen/Calendar/JSRecurrenceRule.h delete mode 100755 src/standards/Tizen/Call/JSCallApi.cpp delete mode 100755 src/standards/Tizen/Call/JSCallApi.h create mode 100755 src/standards/Tizen/Common/CMakeLists.txt delete mode 100755 src/standards/Tizen/Contact/JSContactProperties.cpp delete mode 100755 src/standards/Tizen/Contact/JSContactProperties.h create mode 100755 src/standards/Tizen/Contact/JSContactRef.cpp rename src/standards/Tizen/{Application/JSApplicationServiceExtraData.h => Contact/JSContactRef.h} (56%) create mode 100755 src/standards/Tizen/Mediacontent/plugin_config.cpp create mode 100755 src/standards/Tizen/Mediacontent/plugin_config.h rename src/standards/Tizen/Messaging/{JSMessagingListener.cpp => MessagingListener.cpp} (96%) rename src/standards/Tizen/Messaging/{JSMessagingListener.h => MessagingListener.h} (92%) diff --git a/debian/changelog b/debian/changelog index b33beac..fe43c01 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,20 @@ +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 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 Thu, 16 Feb 2012 12:19:32 +0900 + wrt-plugins-tizen (0.2.0-0) unstable; urgency=low * beta merge diff --git a/src/platform/API/Application/ApplicationInformation.cpp b/src/platform/API/Application/ApplicationInformation.cpp index edfc672..7079159 100755 --- a/src/platform/API/Application/ApplicationInformation.cpp +++ b/src/platform/API/Application/ApplicationInformation.cpp @@ -31,6 +31,7 @@ std::string ApplicationInformation::getName() const { return m_name; } + void ApplicationInformation::setName(const std::string &name) { m_name = name; @@ -40,6 +41,7 @@ std::string ApplicationInformation::getAppId() const { return m_appId; } + void ApplicationInformation::setAppId(const std::string &appId) { m_appId = appId; @@ -49,6 +51,7 @@ std::string ApplicationInformation::getIconPath() const { return m_iconPath; } + void ApplicationInformation::setIconPath(const std::string &iconPath) { m_iconPath = iconPath; @@ -58,11 +61,23 @@ 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; +} + + } } } diff --git a/src/platform/API/Application/ApplicationInformation.h b/src/platform/API/Application/ApplicationInformation.h index 25792a0..0d1b447 100755 --- a/src/platform/API/Application/ApplicationInformation.h +++ b/src/platform/API/Application/ApplicationInformation.h @@ -46,12 +46,15 @@ class ApplicationInformation void setIconPath(const std::string &iconPath); std::string getVersion() const; void setVersion(const std::string &version); + bool getShow() const; + void setShow(const bool &show); private: std::string m_name; std::string m_appId; std::string m_iconPath; - std::string m_version; + std::string m_version; + bool m_show; }; } } diff --git a/src/platform/API/Application/ApplicationService.cpp b/src/platform/API/Application/ApplicationService.cpp index b3998ea..eb5d4a2 100755 --- a/src/platform/API/Application/ApplicationService.cpp +++ b/src/platform/API/Application/ApplicationService.cpp @@ -35,13 +35,14 @@ ApplicationService::ApplicationService() : //m_serviceDataArray = ApplicationServiceDataPtr(new ApplicationServiceData); } -ApplicationService::ApplicationService(const std::string &op, const std::string &uri, const std::string &mime, std::vector &dataArray) : +ApplicationService::ApplicationService(const std::string &op, const std::string &uri, const std::string &mime, const std::string &appId, std::vector &dataArray) : m_service(NULL) { LogDebug("entered"); m_operation = op; m_uri = uri; m_mime = mime; + m_appId = appId; m_serviceDataArray = dataArray; } @@ -81,6 +82,17 @@ void ApplicationService::setMime(const std::string &mime) m_mime = mime; } +std::string ApplicationService::getAppId() const +{ + return m_appId; +} + +void ApplicationService::setAppId(const std::string &appId) +{ + m_appId = appId; +} + + std::vector ApplicationService::getServiceDataArray() const { return m_serviceDataArray; @@ -101,11 +113,59 @@ service_h ApplicationService::getService_h() const { return m_service; } + void ApplicationService::setService_h(const service_h service) { m_service = service; } +void ApplicationService::replyResult(std::vector &appServiceDataArray) +{ + service_h reply; + service_create(&reply); + + const char* key = NULL; + const char** arr = NULL; + + if (!appServiceDataArray.empty()) + { + LogDebug("appServiceDataArray.size() : "<getKey().c_str(); + std::vector valueArray = appServiceDataArray.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("==[WS] appServiceDataArray is empty"); + } + + service_reply_to_launch_request(reply, m_service, SERVICE_RESULT_SUCCEEDED); + + service_destroy(reply); + + if (arr) { + free (arr); + } + +} + +void ApplicationService::replyFailure() +{ + service_h reply; + service_create(&reply); + + LogError("==[WS] enter ApplicationService::replyFailure"); + service_reply_to_launch_request(reply, m_service, SERVICE_RESULT_FAILED); + + service_destroy(reply); +} + } } } diff --git a/src/platform/API/Application/ApplicationService.h b/src/platform/API/Application/ApplicationService.h index 88ade61..e0035ad 100755 --- a/src/platform/API/Application/ApplicationService.h +++ b/src/platform/API/Application/ApplicationService.h @@ -36,7 +36,7 @@ class ApplicationService { public: ApplicationService(); - ApplicationService(const std::string &op, const std::string &uri, const std::string &mime, std::vector &dataArray) ; + ApplicationService(const std::string &op, const std::string &uri, const std::string &mime, const std::string &appId, std::vector &dataArray) ; ~ApplicationService(); std::string getOperation() const; @@ -48,6 +48,9 @@ class ApplicationService std::string getMime() const; void setMime(const std::string &uri); + std::string getAppId() const; + void setAppId(const std::string &appId); + std::vector getServiceDataArray() const; void setServiceDataArray(std::vector &dataArray); void addServiceData(const ApplicationServiceDataPtr &data); @@ -55,11 +58,14 @@ class ApplicationService service_h getService_h() const; void setService_h(const service_h service); + void replyResult(std::vector &appServiceDataArray); + void replyFailure(); private: std::string m_operation; std::string m_uri; std::string m_mime; + std::string m_appId; std::vector m_serviceDataArray; service_h m_service; }; diff --git a/src/platform/API/Application/ApplicationServiceExtraData.cpp b/src/platform/API/Application/ApplicationServiceExtraData.cpp deleted file mode 100755 index 36879c5..0000000 --- a/src/platform/API/Application/ApplicationServiceExtraData.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ApplicationServiceExtraData.h" - -namespace TizenApis { -namespace Api { -namespace Application { -ApplicationServiceExtraData::ApplicationServiceExtraData() -{ - LogDebug("entered"); -} - -ApplicationServiceExtraData::~ApplicationServiceExtraData() -{ - //nothing to do in destructor - LogDebug("entered"); -} - -std::string ApplicationServiceExtraData::getKey() const -{ - return m_key; -} -void ApplicationServiceExtraData::setKey(const std::string &key) -{ - m_key = key; -} - -std::string ApplicationServiceExtraData::getValue() const -{ - return m_value; -} -void ApplicationServiceExtraData::setValue(const std::string &value) -{ - m_value = value; -} - -} -} -} diff --git a/src/platform/API/Application/ApplicationServiceExtraData.h b/src/platform/API/Application/ApplicationServiceExtraData.h deleted file mode 100755 index 673ed85..0000000 --- a/src/platform/API/Application/ApplicationServiceExtraData.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_SERVICE_EXTRA_DATA_H_ -#define TIZENAPIS_API_APPLICATION_SERVICE_EXTRA_DATA_H_ - -#include -#include -#include -#include - -namespace TizenApis { -namespace Api { -namespace Application { - -class ApplicationServiceExtraData; -typedef DPL::SharedPtr ApplicationServiceExtraDataPtr; - -typedef std::vector ApplicationServiceExtraDataArray; -typedef DPL::SharedPtr ApplicationServiceExtraDataArrayPtr; - -/* This object represents a single extra data for service request and reply */ -class ApplicationServiceExtraData -{ - public: - ApplicationServiceExtraData(); - ~ApplicationServiceExtraData(); - - std::string getKey() const; - void setKey(const std::string &key); - - std::string getValue() const; - void setValue(const std::string &value); - - private: - std::string m_key; - std::string m_value; -}; -} -} -} -#endif diff --git a/src/platform/API/Application/ApplicationServiceReply.cpp b/src/platform/API/Application/ApplicationServiceReply.cpp deleted file mode 100755 index fbac74a..0000000 --- a/src/platform/API/Application/ApplicationServiceReply.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file ApplicationServiceReply.cpp - * @author Youngkyeong Yun (yk.yun@samsung.com) - * @version 0.1 - */ - - -#include "ApplicationServiceReply.h" - -namespace TizenApis { -namespace Api { -namespace Application { -ApplicationServiceReply::ApplicationServiceReply() -{ - LogDebug("entered"); - m_extraDataArray = ApplicationServiceExtraDataArrayPtr(new ApplicationServiceExtraDataArray); -} - -ApplicationServiceReply::~ApplicationServiceReply() -{ - //nothing to do in destructor - LogDebug("entered"); -} - -bool ApplicationServiceReply::getIsSucceed() const -{ - return m_issucceed; -} -void ApplicationServiceReply::setIsSucceed(const bool success) -{ - m_issucceed = success; -} - -ApplicationServiceExtraDataArrayPtr ApplicationServiceReply::getExtraDataArray() const -{ - return m_extraDataArray; -} -void ApplicationServiceReply::setExtraDataArray(const ApplicationServiceExtraDataArrayPtr &extraDataArray) -{ - m_extraDataArray = extraDataArray; -} - -void ApplicationServiceReply::addExtraData(const ApplicationServiceExtraDataPtr &extraData) -{ - m_extraDataArray->push_back(extraData); -} - -} -} -} diff --git a/src/platform/API/Application/ApplicationServiceReply.h b/src/platform/API/Application/ApplicationServiceReply.h deleted file mode 100755 index 9a4c047..0000000 --- a/src/platform/API/Application/ApplicationServiceReply.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_SERVICE_REPLY_H_ -#define TIZENAPIS_API_APPLICATION_SERVICE_REPLY_H_ - -#include -#include -#include "ApplicationServiceExtraData.h" - -namespace TizenApis { -namespace Api { -namespace Application { - -class ApplicationServiceReply; -typedef DPL::SharedPtr ApplicationServiceReplyPtr; - -/* This object represents a single extra data for service request and reply */ -class ApplicationServiceReply -{ -public: - ApplicationServiceReply(); - ~ApplicationServiceReply(); - - bool getIsSucceed() const; - void setIsSucceed(const bool success); - ApplicationServiceExtraDataArrayPtr getExtraDataArray() const; - void setExtraDataArray(const ApplicationServiceExtraDataArrayPtr &extraDataArray); - void addExtraData(const ApplicationServiceExtraDataPtr &extraData); - -private: - ApplicationServiceExtraDataArrayPtr m_extraDataArray; - bool m_issucceed; -}; -} -} -} -#endif diff --git a/src/platform/API/Application/ApplicationServiceRequest.cpp b/src/platform/API/Application/ApplicationServiceRequest.cpp deleted file mode 100755 index d9038f4..0000000 --- a/src/platform/API/Application/ApplicationServiceRequest.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file ApplicationServiceRequest.cpp - * @author Youngkyeong Yun (yk.yun@samsung.com) - * @version 0.1 - */ - - -#include "ApplicationServiceRequest.h" - -namespace TizenApis { -namespace Api { -namespace Application { -ApplicationServiceRequest::ApplicationServiceRequest() : - m_service(NULL) -{ - LogDebug("entered"); - m_extraDataArray = ApplicationServiceExtraDataArrayPtr(new ApplicationServiceExtraDataArray); -} - -ApplicationServiceRequest::~ApplicationServiceRequest() -{ - //nothing to do in destructor - LogDebug("entered"); -} - -std::string ApplicationServiceRequest::getOperation() const -{ - return m_operation; -} -void ApplicationServiceRequest::setOperation(const std::string &operation) -{ - m_operation = operation; -} - -std::string ApplicationServiceRequest::getUri() const -{ - return m_uri; -} -void ApplicationServiceRequest::setUri(const std::string &uri) -{ - m_uri = uri; -} - -std::string ApplicationServiceRequest::getMime() const -{ - return m_mime; -} -void ApplicationServiceRequest::setMime(const std::string &mime) -{ - m_mime = mime; -} - -std::string ApplicationServiceRequest::getPackage() const -{ - return m_package; -} -void ApplicationServiceRequest::setPackage(const std::string &package) -{ - m_package = package; -} - -ApplicationServiceExtraDataArrayPtr ApplicationServiceRequest::getExtraDataArray() const -{ - return m_extraDataArray; -} -void ApplicationServiceRequest::setExtraDataArray(const ApplicationServiceExtraDataArrayPtr &extraDataArray) -{ - m_extraDataArray = extraDataArray; -} - -void ApplicationServiceRequest::addExtraData(const ApplicationServiceExtraDataPtr &extraData) -{ - m_extraDataArray->push_back(extraData); -} - -service_h ApplicationServiceRequest::getService_h() const -{ - return m_service; -} -void ApplicationServiceRequest::setService_h(const service_h service) -{ - m_service = service; -} - -} -} -} diff --git a/src/platform/API/Application/ApplicationServiceRequest.h b/src/platform/API/Application/ApplicationServiceRequest.h deleted file mode 100755 index 730839c..0000000 --- a/src/platform/API/Application/ApplicationServiceRequest.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_SERVICE_H_ -#define TIZENAPIS_API_APPLICATION_SERVICE_H_ - -#include -#include -#include -#include -#include -#include "ApplicationServiceExtraData.h" - -namespace TizenApis { -namespace Api { -namespace Application { - -class ApplicationServiceRequest; -typedef DPL::SharedPtr ApplicationServiceRequestPtr; - -/* This object represents a single extra data for service request and reply */ -class ApplicationServiceRequest -{ - public: - ApplicationServiceRequest(); - ~ApplicationServiceRequest(); - - 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 getPackage() const; - void setPackage(const std::string &uri); - - ApplicationServiceExtraDataArrayPtr getExtraDataArray() const; - void setExtraDataArray(const ApplicationServiceExtraDataArrayPtr &extraDataArray); - void addExtraData(const ApplicationServiceExtraDataPtr &extraData); - - service_h getService_h() const; - void setService_h(const service_h service); - - - private: - std::string m_operation; - std::string m_uri; - std::string m_mime; - std::string m_package; - ApplicationServiceExtraDataArrayPtr m_extraDataArray; - service_h m_service; -}; -} -} -} -#endif diff --git a/src/platform/API/Application/EventInstalledApplicationChanged.h b/src/platform/API/Application/EventInstalledApplicationChanged.h index 8f90fbc..13771d5 100755 --- a/src/platform/API/Application/EventInstalledApplicationChanged.h +++ b/src/platform/API/Application/EventInstalledApplicationChanged.h @@ -24,10 +24,6 @@ #include "ApplicationInformation.h" #include "ApplicationEvent.h" -#define APPLICATON_EVENT_CODE_INSTALLED "INSTALLED" -#define APPLICATON_EVENT_CODE_UNINSTALLED "UNINSTALLED" -#define APPLICATON_EVENT_CODE_UPDATED "UPDATED" - namespace TizenApis { namespace Api { namespace Application { @@ -36,7 +32,13 @@ class EventInstalledApplicationChanged: public WrtDeviceApis::Commons::ListenerE { private: ApplicationInformationPtr m_appinfo; - std::string m_eventCode; + int m_eventCode; + +public: + static const int APPLICATON_CHANGED_EVENT_CODE_INSTALLED = 0; + static const int APPLICATON_CHANGED_EVENT_CODE_UNINSTALLED = 1; + static const int APPLICATON_CHANGED_EVENT_CODE_UPDATED = 2; + public: void setApplicationInformation(const ApplicationInformationPtr &appinfo) @@ -49,12 +51,12 @@ public: return m_appinfo; } - void setEventCode(std::string code) + void setEventCode(int code) { m_eventCode = code; } - std::string getEventCode() const + int getEventCode() const { return m_eventCode; } diff --git a/src/platform/API/Application/EventManageApplication.h b/src/platform/API/Application/EventManageApplication.h index c3bb0bc..ce2cc3d 100755 --- a/src/platform/API/Application/EventManageApplication.h +++ b/src/platform/API/Application/EventManageApplication.h @@ -38,8 +38,7 @@ private: public: static const int APP_MANAGER_UNKNOWN = 0; static const int APP_MANAGER_KILL_APPLICATION = 1; - static const int APP_MANAGER_HIDE_APPLICATION = 2; - static const int APP_MANAGER_LAUNCH_APPLICATION = 3; + static const int APP_MANAGER_LAUNCH_APPLICATION = 2; public: void setApplicationInformation(const ApplicationInformationPtr appinfo) diff --git a/src/platform/API/Application/IApplication.h b/src/platform/API/Application/IApplication.h index 496a195..f8106b5 100755 --- a/src/platform/API/Application/IApplication.h +++ b/src/platform/API/Application/IApplication.h @@ -44,7 +44,7 @@ public: virtual void launch(const EventManageApplicationPtr& event) = 0; virtual void kill(const EventManageApplicationPtr& event) = 0; virtual void exit() = 0; - virtual void hide(const EventManageApplicationPtr& event) = 0; + virtual void hide() = 0; virtual void listApplications(const EventListInstalledApplicationsPtr& event) = 0; virtual void getApplication(const EventGetApplicationPtr& event) = 0; virtual long addApplicationInformationEventListener(const EventInstalledApplicationChangedEmitterPtr& emitter) = 0; diff --git a/src/platform/API/Calendar/CalendarEvent.cpp b/src/platform/API/Calendar/CalendarEvent.cpp index 76b7e52..7bdfa8a 100755 --- a/src/platform/API/Calendar/CalendarEvent.cpp +++ b/src/platform/API/Calendar/CalendarEvent.cpp @@ -95,7 +95,8 @@ CalendarEvent::CalendarEvent(const CalendarEvent &original) attendeePtr->setGroup(original.getAttendees()->at(i)->getGroup()); attendeePtr->setDelegatorURI(original.getAttendees()->at(i)->getDelegatorURI()); attendeePtr->setDelegateURI(original.getAttendees()->at(i)->getDelegateURI()); - attendeePtr->setPersonId(original.getAttendees()->at(i)->getPersonId()); + attendeePtr->setAddressBookId(original.getAttendees()->at(i)->getAddressBookId()); + attendeePtr->setContactId(original.getAttendees()->at(i)->getContactId()); m_attendees->push_back(attendeePtr); } diff --git a/src/platform/API/Calendar/EventAttendee.cpp b/src/platform/API/Calendar/EventAttendee.cpp index 8f129c7..9345180 100755 --- a/src/platform/API/Calendar/EventAttendee.cpp +++ b/src/platform/API/Calendar/EventAttendee.cpp @@ -18,18 +18,16 @@ #include "EventAttendee.h" #include -/** - * @file EventAttendee.cpp - * - * @version 0.1 - */ - 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() @@ -116,7 +114,6 @@ void EventAttendee::setDelegatorURI(const std::string &value) m_delegatorURI = value; } - std::string EventAttendee::getDelegateURI() const { return m_delegateURI; @@ -127,14 +124,24 @@ void EventAttendee::setDelegateURI(const std::string &value) m_delegateURI = value; } -std::string EventAttendee::getPersonId() const +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_uid; + return m_contactId; } -void EventAttendee::setPersonId(const std::string &value) +void EventAttendee::setContactId(const std::string &value) { - m_uid = value; + m_contactId = value; } } diff --git a/src/platform/API/Calendar/EventAttendee.h b/src/platform/API/Calendar/EventAttendee.h index 3ec16be..f4dc01a 100755 --- a/src/platform/API/Calendar/EventAttendee.h +++ b/src/platform/API/Calendar/EventAttendee.h @@ -94,20 +94,24 @@ class EventAttendee std::string getDelegateURI() const; void setDelegateURI(const std::string &value); - std::string getPersonId() const; - void setPersonId(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; + 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_uid; // needs PersonId class! + std::string m_addressBookId; + std::string m_contactId; }; typedef DPL::SharedPtr EventAttendeePtr; diff --git a/src/platform/API/Contact/Contact.cpp b/src/platform/API/Contact/Contact.cpp deleted file mode 100755 index 3e913ad..0000000 --- a/src/platform/API/Contact/Contact.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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" - -namespace TizenApis { -namespace Api { -namespace Contact { - -Contact::Contact() : - m_readOnly(false), - m_idIsSet(false), - m_readOnlyIsSet(false), - m_lastUpdatedIsSet(false) -{ -} - -Contact::Contact(const ContactProperties &contactProperties) : - ContactProperties(contactProperties), - m_readOnly(false), - m_idIsSet(false), - m_readOnlyIsSet(false), - m_lastUpdatedIsSet(false) -{ -} - -Contact::~Contact() -{ -} - -std::string Contact::getId() const -{ - return m_id; -} - -void Contact::setId(const std::string value) -{ - m_id = value; - m_idIsSet = true; -} - -bool Contact::getIdIsSet() const -{ - return m_idIsSet; -} - -void Contact::setId(const int value) -{ - std::stringstream oss; - oss << value; - m_id = oss.str(); - m_idIsSet = true; -} - -bool Contact::getReadOnly() const -{ - return m_readOnly; -} - -void Contact::setReadOnly(const bool &value) -{ - m_readOnly = value; - m_readOnlyIsSet = true; -} - -bool Contact::getReadOnlyIsSet() const -{ - return m_readOnlyIsSet; -} - -std::tm Contact::getLastUpdated() const -{ - return m_lastUpdated; -} - -void Contact::setLastUpdated(const std::tm &value) -{ - m_lastUpdated = value; - m_lastUpdatedIsSet = true; -} - -bool Contact::getLastUpdatedIsSet() const -{ - return m_lastUpdatedIsSet; -} - -void Contact::clear() -{ - LogDebug("entered"); - //clear all fields - ContactProperties::clear(); - m_id.clear(); - m_readOnly = false; - m_idIsSet = false; - m_readOnlyIsSet = false; -} - -ContactPtr Contact::clone() -{ - // TODO - //clone object - //use defaul copy constructor - ContactPtr result(new Contact(*this)); - return result; -} - -} // Contact -} // Api -} // TizenApis diff --git a/src/platform/API/Contact/Contact.h b/src/platform/API/Contact/Contact.h deleted file mode 100755 index ff1f6eb..0000000 --- a/src/platform/API/Contact/Contact.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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 _API_CONTACT_CONTACT_H_ -#define _API_CONTACT_CONTACT_H_ - -#include -#include -#include -#include -#include -#include "ContactProperties.h" - -namespace TizenApis { -namespace Api { -namespace Contact { - -class Contact; -typedef DPL::SharedPtr ContactPtr; - -typedef std::vector ContactArray; -typedef DPL::SharedPtr ContactArrayPtr; - -class Contact : public ContactProperties -{ -public: - Contact(); - // CAUTION: The copy constructor of ContactProperties was not implemented implicitly. So use this function carefully. - Contact(const ContactProperties &contactProperties); - virtual ~Contact(); - - std::string getId() const; - void setId(const std::string value); - void setId(const int value); - bool getIdIsSet() const; - - bool getReadOnly() const; - void setReadOnly(const bool &value); - bool getReadOnlyIsSet() const; - - std::tm getLastUpdated() const; - void setLastUpdated(const std::tm &value); - bool getLastUpdatedIsSet() const; - - void clear(); - ContactPtr clone(); - -private: - std::string m_id; - bool m_readOnly; - std::tm m_lastUpdated; - - bool m_idIsSet; - bool m_readOnlyIsSet; - bool m_lastUpdatedIsSet; -}; - -} // Contact -} // Api -} // TizenApis - -#endif // _API_CONTACT_CONTACT_H_ diff --git a/src/platform/API/Contact/ContactAccount.cpp b/src/platform/API/Contact/ContactAccount.cpp index 09aace2..de8af86 100755 --- a/src/platform/API/Contact/ContactAccount.cpp +++ b/src/platform/API/Contact/ContactAccount.cpp @@ -28,7 +28,7 @@ namespace Api { namespace Contact { ContactAccount::ContactAccount() : - m_accountIdIsSet(false), + m_accountServiceIdIsSet(false), m_contactURIIsSet(false) { } @@ -37,20 +37,20 @@ ContactAccount::~ContactAccount() { } -std::string ContactAccount::getAccountId() const +std::string ContactAccount::getAccountServiceId() const { - return m_accountId; + return m_accountServiceId; } -void ContactAccount::setAccountId(const std::string &value) +void ContactAccount::setAccountServiceId(const std::string &value) { - m_accountIdIsSet = true; - m_accountId = value; + m_accountServiceIdIsSet = true; + m_accountServiceId = value; } -bool ContactAccount::getAccountIdIsSet() const +bool ContactAccount::getAccountServiceIdIsSet() const { - return m_accountIdIsSet; + return m_accountServiceIdIsSet; } @@ -70,9 +70,26 @@ bool ContactAccount::getContactURIIsSet() const return m_contactURIIsSet; } +void ContactAccount::clear() +{ + m_accountServiceId = ""; + m_contactURI = ""; + + m_accountServiceIdIsSet = false; + m_contactURIIsSet = false; +} + ContactAccountPtr ContactAccount::clone() const { - return ContactAccountPtr(new ContactAccount(*this)); + ContactAccountPtr result(new ContactAccount()); + + result->m_accountServiceId = m_accountServiceId; + result->m_contactURI = m_contactURI; + + result->m_accountServiceIdIsSet = m_accountServiceIdIsSet; + result->m_contactURIIsSet = m_contactURIIsSet; + + return result; } } // Contact diff --git a/src/platform/API/Contact/ContactAccount.h b/src/platform/API/Contact/ContactAccount.h index 7cbad95..372c2fd 100755 --- a/src/platform/API/Contact/ContactAccount.h +++ b/src/platform/API/Contact/ContactAccount.h @@ -44,21 +44,22 @@ public: ContactAccount(); ~ContactAccount(); - std::string getAccountId() const; - void setAccountId(const std::string &value); - bool getAccountIdIsSet() const; + std::string getAccountServiceId() const; + void setAccountServiceId(const std::string &value); + bool getAccountServiceIdIsSet() const; std::string getContactURI() const; void setContactURI(const std::string &value); bool getContactURIIsSet() const; + void clear(); ContactAccountPtr clone() const; private: - std::string m_accountId; + std::string m_accountServiceId; std::string m_contactURI; - bool m_accountIdIsSet; + bool m_accountServiceIdIsSet; bool m_contactURIIsSet; }; diff --git a/src/platform/API/Contact/ContactAddress.cpp b/src/platform/API/Contact/ContactAddress.cpp index 0d5f9e7..b5c13af 100755 --- a/src/platform/API/Contact/ContactAddress.cpp +++ b/src/platform/API/Contact/ContactAddress.cpp @@ -196,12 +196,6 @@ bool ContactAddress::compareTo(const ContactAddressPtr &address, return false; } -ContactAddressPtr ContactAddress::clone() const -{ - //clone object by using copy constructors - return ContactAddressPtr(new ContactAddress(*this)); -} - std::string ContactAddress::getAsSingleString() const { std::string fullAddress; @@ -235,6 +229,52 @@ std::string ContactAddress::getAsSingleString() const return ""; } +void ContactAddress::clear() +{ + m_country = ""; + m_region = ""; + m_city = ""; + m_streetAddress = ""; + m_additionalInformation = ""; + m_postalCode = ""; + m_types = ContactAddressTypeArrayPtr(new ContactAddressTypeArray()); + + m_countryIsSet = false; + m_regionIsSet = false; + m_cityIsSet = false; + m_streetAddressIsSet = false; + m_additionalInformationIsSet = false; + m_postalCodeIsSet = false; +} + +ContactAddressPtr ContactAddress::clone() const +{ + ContactAddressPtr result(new ContactAddress()); + + result->m_country = m_country; + result->m_region = m_region; + result->m_city = m_city; + result->m_streetAddress = m_streetAddress; + result->m_additionalInformation = m_additionalInformation; + result->m_postalCode = m_postalCode; + 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); + } + + result->m_countryIsSet = m_countryIsSet; + result->m_regionIsSet = m_regionIsSet; + result->m_cityIsSet = m_cityIsSet; + result->m_streetAddressIsSet = m_streetAddressIsSet; + result->m_additionalInformationIsSet = m_additionalInformationIsSet; + result->m_postalCodeIsSet = m_postalCodeIsSet; + + return result; +} + } // Contact } // Api } // TizenApis diff --git a/src/platform/API/Contact/ContactAddress.h b/src/platform/API/Contact/ContactAddress.h index 8d683d6..f1f99b5 100755 --- a/src/platform/API/Contact/ContactAddress.h +++ b/src/platform/API/Contact/ContactAddress.h @@ -86,6 +86,7 @@ public: bool compareTo(const ContactAddressPtr &address, bool includeId = false, bool includeTypes = false) const; + void clear(); ContactAddressPtr clone() const; private: diff --git a/src/platform/API/Contact/ContactAnniversary.cpp b/src/platform/API/Contact/ContactAnniversary.cpp index 7d9f2f4..24b4920 100755 --- a/src/platform/API/Contact/ContactAnniversary.cpp +++ b/src/platform/API/Contact/ContactAnniversary.cpp @@ -69,9 +69,26 @@ bool ContactAnniversary::getLabelIsSet() const return m_labelIsSet; } +void ContactAnniversary::clear() +{ + m_date = {0, }; + m_label = ""; + + m_dateIsSet = false; + m_labelIsSet = false; +} + ContactAnniversaryPtr ContactAnniversary::clone() const { - return ContactAnniversaryPtr(new ContactAnniversary(*this)); + ContactAnniversaryPtr result(new ContactAnniversary()); + + result->m_date = m_date; + result->m_label = m_label; + + result->m_dateIsSet = m_dateIsSet; + result->m_labelIsSet = m_labelIsSet; + + return result; } } // Contact diff --git a/src/platform/API/Contact/ContactAnniversary.h b/src/platform/API/Contact/ContactAnniversary.h index 72b1109..c3c4524 100755 --- a/src/platform/API/Contact/ContactAnniversary.h +++ b/src/platform/API/Contact/ContactAnniversary.h @@ -54,6 +54,7 @@ public: void setLabel(const std::string &value); bool getLabelIsSet() const; + void clear(); ContactAnniversaryPtr clone() const; private: diff --git a/src/platform/API/Contact/ContactEmailAddress.cpp b/src/platform/API/Contact/ContactEmailAddress.cpp index 60945d6..03ff7fa 100755 --- a/src/platform/API/Contact/ContactEmailAddress.cpp +++ b/src/platform/API/Contact/ContactEmailAddress.cpp @@ -78,9 +78,27 @@ int ContactEmailAddress::getTypesNum() const return m_types->size(); } +void ContactEmailAddress::clear() +{ + m_email = ""; + m_types = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray()); + + m_emailIsSet = false; +} + ContactEmailAddressPtr ContactEmailAddress::clone() const { - return ContactEmailAddressPtr(new ContactEmailAddress(*this)); + ContactEmailAddressPtr result(new ContactEmailAddress()); + + result->m_email = m_email; + 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); + + result->m_emailIsSet = m_emailIsSet; + + return result; } } // Contact diff --git a/src/platform/API/Contact/ContactEmailAddress.h b/src/platform/API/Contact/ContactEmailAddress.h index 79e6f6f..9ee3b9e 100755 --- a/src/platform/API/Contact/ContactEmailAddress.h +++ b/src/platform/API/Contact/ContactEmailAddress.h @@ -59,6 +59,7 @@ public: bool isTypeOf(ContactEmailAddressType value) const; int getTypesNum() const; + void clear(); ContactEmailAddressPtr clone() const; private: diff --git a/src/platform/API/Contact/ContactFactory.cpp b/src/platform/API/Contact/ContactFactory.cpp index 2933be9..6cb171b 100755 --- a/src/platform/API/Contact/ContactFactory.cpp +++ b/src/platform/API/Contact/ContactFactory.cpp @@ -19,15 +19,23 @@ * @author Kisub Song (kisubs.song@samsung.com) * @version 0.1 * @brief + * ## */ +#include #include "ContactFactory.h" -#include +#include namespace TizenApis { namespace Api { namespace Contact { +ContactFactory& ContactFactory::getInstance() // static +{ + static ContactFactory theInstance; + return theInstance; +} + IContactManagerPtr ContactFactory::createContactManager() { static IContactManagerPtr result(new TizenApis::Platform::Contact::ContactManager()); @@ -35,10 +43,16 @@ IContactManagerPtr ContactFactory::createContactManager() return result; } -ContactFactory& ContactFactory::getInstance() +ContactPtr ContactFactory::createContact() { - static ContactFactory theInstance; - return theInstance; + ContactPtr result(new TizenApis::Platform::Contact::Contact()); + return result; +} + +ContactPtr ContactFactory::createContact(const std::string &vObjectStr, const std::string &format) +{ + ContactPtr result(new TizenApis::Platform::Contact::Contact(vObjectStr, format)); + return result; } } // Contact diff --git a/src/platform/API/Contact/ContactFactory.h b/src/platform/API/Contact/ContactFactory.h index ddd2496..d1ecd00 100755 --- a/src/platform/API/Contact/ContactFactory.h +++ b/src/platform/API/Contact/ContactFactory.h @@ -19,6 +19,7 @@ * @author Kisub Song (kisubs.song@samsung.com) * @version 0.1 * @brief + * ## */ #ifndef _API_CONTACT_CONTACT_FACTORY_H_ @@ -26,6 +27,7 @@ #include #include "IContactManager.h" +#include "IContact.h" namespace TizenApis { namespace Api { @@ -40,6 +42,8 @@ private: public: static ContactFactory& getInstance(); IContactManagerPtr createContactManager(); + ContactPtr createContact(); + ContactPtr createContact(const std::string &vObjectStr, const std::string &format); }; } // Contact diff --git a/src/platform/API/Contact/ContactName.cpp b/src/platform/API/Contact/ContactName.cpp index 1b8c09e..44a91c3 100755 --- a/src/platform/API/Contact/ContactName.cpp +++ b/src/platform/API/Contact/ContactName.cpp @@ -137,7 +137,7 @@ void ContactName::setPhoneticName(const std::string &value) m_phoneticNameIsSet = true; } -bool ContactName::getPhoneticIsSet() const +bool ContactName::getPhoneticNameIsSet() const { return m_phoneticNameIsSet; } @@ -158,9 +158,51 @@ bool ContactName::getDisplayNameIsSet() const return m_displayNameIsSet; } +void ContactName::clear() +{ + m_prefix = ""; + m_firstName = ""; + m_middleName = ""; + m_lastName = ""; + m_nicknames = StringArrayPtr(new StringArray()); + m_phoneticName = ""; + m_displayName = ""; + + m_prefixIsSet = false; + m_firstNameIsSet = false; + m_middleNameIsSet = false; + m_lastNameIsSet = false; + m_phoneticNameIsSet = false; + m_displayNameIsSet = false; +} + ContactNamePtr ContactName::clone() const { - return ContactNamePtr(new ContactName(*this)); + ContactNamePtr result(new ContactName()); + + result->m_prefix = m_prefix; + result->m_firstName = m_firstName; + result->m_middleName = m_middleName; + result->m_lastName = m_lastName; + 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_phoneticName = m_phoneticName; + result->m_displayName = m_displayName; + + result->m_prefixIsSet = m_prefixIsSet; + result->m_firstNameIsSet = m_firstNameIsSet; + result->m_middleNameIsSet = m_middleNameIsSet; + result->m_lastNameIsSet = m_lastNameIsSet; + result->m_phoneticNameIsSet = m_phoneticNameIsSet; + result->m_displayNameIsSet = m_displayNameIsSet; + + return result; } } // Contact diff --git a/src/platform/API/Contact/ContactName.h b/src/platform/API/Contact/ContactName.h index b989c80..fdae7e9 100755 --- a/src/platform/API/Contact/ContactName.h +++ b/src/platform/API/Contact/ContactName.h @@ -43,7 +43,7 @@ class ContactName { public: ContactName(); - ~ContactName(); + virtual ~ContactName(); std::string getPrefix() const; void setPrefix(const std::string &value); @@ -68,12 +68,13 @@ public: std::string getPhoneticName() const; void setPhoneticName(const std::string &value); - bool getPhoneticIsSet() const; + bool getPhoneticNameIsSet() const; std::string getDisplayName() const; void setDisplayName(const std::string &value); bool getDisplayNameIsSet() const; + void clear(); ContactNamePtr clone() const; private: diff --git a/src/platform/API/Contact/ContactOrganization.cpp b/src/platform/API/Contact/ContactOrganization.cpp index b628afa..715494f 100755 --- a/src/platform/API/Contact/ContactOrganization.cpp +++ b/src/platform/API/Contact/ContactOrganization.cpp @@ -137,9 +137,42 @@ bool ContactOrganization::getLogoURIIsSet() const return m_logoURIIsSet; } +void ContactOrganization::clear() +{ + m_name = ""; + m_department = ""; + m_office = ""; + m_title = ""; + m_role = ""; + m_logoURI = ""; + + m_nameIsSet = false; + m_departmentIsSet = false; + m_officeIsSet = false; + m_titleIsSet = false; + m_roleIsSet = false; + m_logoURIIsSet = false; +} + ContactOrganizationPtr ContactOrganization::clone() const { - return ContactOrganizationPtr(new ContactOrganization(*this)); + ContactOrganizationPtr result(new ContactOrganization()); + + result->m_name = m_name; + result->m_department = m_department; + result->m_office = m_office; + result->m_title = m_title; + result->m_role = m_role; + result->m_logoURI = m_logoURI; + + result->m_nameIsSet = m_nameIsSet; + result->m_departmentIsSet = m_departmentIsSet; + result->m_officeIsSet = m_officeIsSet; + result->m_titleIsSet = m_titleIsSet; + result->m_roleIsSet = m_roleIsSet; + result->m_logoURIIsSet = m_logoURIIsSet; + + return result; } } // Contact diff --git a/src/platform/API/Contact/ContactOrganization.h b/src/platform/API/Contact/ContactOrganization.h index b8ee672..05e2f42 100755 --- a/src/platform/API/Contact/ContactOrganization.h +++ b/src/platform/API/Contact/ContactOrganization.h @@ -68,6 +68,7 @@ public: void setLogoURI(const std::string &value); bool getLogoURIIsSet() const; + void clear(); ContactOrganizationPtr clone() const; private: diff --git a/src/platform/API/Contact/ContactPhoneNumber.cpp b/src/platform/API/Contact/ContactPhoneNumber.cpp index 5e73386..658eebd 100755 --- a/src/platform/API/Contact/ContactPhoneNumber.cpp +++ b/src/platform/API/Contact/ContactPhoneNumber.cpp @@ -32,7 +32,7 @@ using namespace std; ContactPhoneNumber::ContactPhoneNumber() : m_numberIsSet(false) { - m_types = StringArrayPtr(new StringArray()); + m_types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray()); } ContactPhoneNumber::~ContactPhoneNumber() @@ -55,22 +55,22 @@ bool ContactPhoneNumber::getNumberIsSet() const return m_numberIsSet; } -StringArrayPtr ContactPhoneNumber::getTypes() const +ContactPhoneNumberTypeArrayPtr ContactPhoneNumber::getTypes() const { return m_types; } -void ContactPhoneNumber::setTypes(const StringArrayPtr &value) +void ContactPhoneNumber::setTypes(const ContactPhoneNumberTypeArrayPtr &value) { m_types = value; } -void ContactPhoneNumber::addType(const string value) +void ContactPhoneNumber::addType(const ContactPhoneNumberType value) { m_types->push_back(value); } -bool ContactPhoneNumber::isTypeOf(string value) const +bool ContactPhoneNumber::isTypeOf(const ContactPhoneNumberType value) const { return std::find(m_types->begin(), m_types->end(), value) != m_types->end(); } @@ -80,9 +80,30 @@ int ContactPhoneNumber::getTypesNum() const return m_types->size(); } +void ContactPhoneNumber::clear() +{ + m_number = ""; + m_types = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray()); + + m_numberIsSet = false; +} + ContactPhoneNumberPtr ContactPhoneNumber::clone() const { - return ContactPhoneNumberPtr(new ContactPhoneNumber(*this)); + ContactPhoneNumberPtr result(new ContactPhoneNumber()); + + result->m_number = m_number; + 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); + } + + result->m_numberIsSet = m_numberIsSet; + + return result; } } // Contact diff --git a/src/platform/API/Contact/ContactPhoneNumber.h b/src/platform/API/Contact/ContactPhoneNumber.h index cb94748..4f36254 100755 --- a/src/platform/API/Contact/ContactPhoneNumber.h +++ b/src/platform/API/Contact/ContactPhoneNumber.h @@ -54,17 +54,18 @@ public: void setNumber(const std::string &value); bool getNumberIsSet() const; - StringArrayPtr getTypes() const; - void setTypes(const StringArrayPtr &value); - void addType(const std::string value); - bool isTypeOf(std::string value) const; + 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; - StringArrayPtr m_types; + ContactPhoneNumberTypeArrayPtr m_types; bool m_numberIsSet; }; diff --git a/src/platform/API/Contact/ContactProperties.cpp b/src/platform/API/Contact/ContactProperties.cpp deleted file mode 100755 index 2e177f1..0000000 --- a/src/platform/API/Contact/ContactProperties.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file ContactProperties.cpp - * @author Kisub Song (kisubs.song@samsung.com) - * @version 0.1 - * @brief - */ - -#include "ContactProperties.h" - -namespace TizenApis { -namespace Api { -namespace Contact { - -ContactProperties::ContactProperties() : - //initialize fields - m_isFavorite(false), - m_nameIsSet(false), - m_accountIsSet(false), - m_photoURIIsSet(false), - m_birthdayIsSet(false), - m_organizationIsSet(false), - m_ringtoneURIIsSet(false) -{ - LogDebug("entered"); - m_name = ContactNamePtr(new ContactName()); - m_account = ContactAccountPtr(new ContactAccount()); - m_addresses = ContactAddressArrayPtr(new ContactAddressArray()); - m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray()); - m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray()); - m_birthday = {0, }; - m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray()); - m_organization = ContactOrganizationPtr(new ContactOrganization()); - m_notes = StringArrayPtr(new StringArray()); - m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray()); - m_categories = StringArrayPtr(new StringArray()); -} - -ContactProperties::~ContactProperties() -{ - //nothing to do in destructor -// LogDebug("entered"); -} - -ContactNamePtr ContactProperties::getName() const -{ - return m_name; -} - -void ContactProperties::setName(const ContactNamePtr &value) -{ - m_name = value; - m_nameIsSet = true; -} - -bool ContactProperties::getNameIsSet() const -{ - return m_nameIsSet; -} - -ContactAccountPtr ContactProperties::getAccount() const -{ - return m_account; -} - -void ContactProperties::setAccount(const ContactAccountPtr &value) -{ - m_account = value; - m_accountIsSet = true; -} - -bool ContactProperties::getAccountIsSet() const -{ - return m_accountIsSet; -} - -ContactAddressArrayPtr ContactProperties::getAddresses() const -{ - return m_addresses; -} - -void ContactProperties::setAddresses(const ContactAddressArrayPtr &value) -{ - m_addresses = value; -} - -void ContactProperties::addAddress(const ContactAddressPtr &value) -{ - m_addresses->push_back(value); -} - -int ContactProperties::getAddressesNum() const -{ - return m_addresses->size(); -} - -std::string ContactProperties::getPhotoURI() const -{ - return m_photoURI; -} - -void ContactProperties::setPhotoURI(const std::string &value) -{ - m_photoURI = value; - m_photoURIIsSet = true; -} - -bool ContactProperties::getPhotoURIIsSet() const -{ - return m_photoURIIsSet; -} - -ContactPhoneNumberArrayPtr ContactProperties::getPhoneNumbers() const -{ - return m_phoneNumbers; -} - -void ContactProperties::setPhoneNumbers(const ContactPhoneNumberArrayPtr &value) -{ - m_phoneNumbers = value; -} - -void ContactProperties::addPhoneNumber(const ContactPhoneNumberPtr &value) -{ - m_phoneNumbers->push_back(value); -} - -int ContactProperties::getPhoneNumbersNum() const -{ - return m_phoneNumbers->size(); -} - -ContactEmailAddressArrayPtr ContactProperties::getEmails() const -{ - return m_emails; -} - -void ContactProperties::addEmail(const ContactEmailAddressPtr& value) -{ - m_emails->push_back(value); -} - -void ContactProperties::setEmails(const ContactEmailAddressArrayPtr &value) -{ - m_emails = value; -} - -int ContactProperties::getEmailsNum() const -{ - return m_emails->size(); -} - -std::tm ContactProperties::getBirthday() const -{ - return m_birthday; -} - -void ContactProperties::setBirthday(const std::tm &value) -{ - m_birthday = value; - m_birthdayIsSet = true; -} - -bool ContactProperties::getBirthdayIsSet() const -{ - return m_birthdayIsSet; -} - -ContactAnniversaryArrayPtr ContactProperties::getAnniversaries() const -{ - return m_anniversaries; -} - -void ContactProperties::setAnniversaries(const ContactAnniversaryArrayPtr &value) -{ - m_anniversaries = value; -} - -void ContactProperties::addAnniversary(const ContactAnniversaryPtr &value) -{ - m_anniversaries->push_back(value); -} - -int ContactProperties::getAnniversariesNum() const -{ - return m_anniversaries->size(); -} - -ContactOrganizationPtr ContactProperties::getOrganization() const -{ - return m_organization; -} - -void ContactProperties::setOrganization(const ContactOrganizationPtr &value) -{ - m_organization = value; - m_organizationIsSet = true; -} - -bool ContactProperties::getOrganizationIsSet() const -{ - return m_organizationIsSet; -} - -StringArrayPtr ContactProperties::getNotes() const -{ - return m_notes; -} - -void ContactProperties::setNotes(const StringArrayPtr &value) -{ - m_notes = value; -} - -void ContactProperties::addNote(const std::string &value) -{ - m_notes->push_back(value); -} - -int ContactProperties::getNotesNum() const -{ - return m_notes->size(); -} - -ContactWebSiteArrayPtr ContactProperties::getUrls() const -{ - return m_urls; -} - -void ContactProperties::setUrls(const ContactWebSiteArrayPtr &value) -{ - m_urls = value; -} - -void ContactProperties::addUrl(const ContactWebSitePtr &value) -{ - m_urls->push_back(value); -} - -int ContactProperties::getUrlsNum() const -{ - return m_urls->size(); -} - -bool ContactProperties::getIsFavorite() const -{ - return m_isFavorite; -} - -void ContactProperties::setIsFavorite(const bool &value) -{ - m_isFavorite = value; -} - -std::string ContactProperties::getRingtoneURI() const -{ - return m_ringtoneURI; -} - -bool ContactProperties::getRingtoneURIIsSet() const -{ - return m_ringtoneURIIsSet; -} - -void ContactProperties::setRingtoneURI(const std::string &value) -{ - m_ringtoneURI = value; - m_ringtoneURIIsSet = true; -} - -StringArrayPtr ContactProperties::getCategories() const -{ - return m_categories; -} - -void ContactProperties::setCategories(const StringArrayPtr &value) -{ - m_categories = value; -} - -void ContactProperties::addCategory(const std::string &value) -{ - m_categories->push_back(value); -} - -int ContactProperties::getCategoriesNum() const -{ - return m_categories->size(); -} - -void ContactProperties::clear() -{ - LogDebug("entered"); - //clear all fields - m_addresses->clear(); - m_photoURI.clear(); - m_phoneNumbers->clear(); - m_emails->clear(); - m_birthday = {0,}; - m_anniversaries->clear(); - m_urls->clear(); - m_isFavorite = false; - m_ringtoneURI.clear(); - m_categories->clear(); -} - -ContactPropertiesPtr ContactProperties::clone() -{ - // TODO - //clone object - //use default copy constructor - ContactPropertiesPtr result(new ContactProperties(*this)); - ContactAddressArrayPtr addresses; - ContactPhoneNumberArrayPtr phoneNumbers; - ContactEmailAddressArrayPtr emails; - //clone internal representation of addresses - for (std::size_t i = 0; i < m_addresses->size(); ++i) { - addresses->push_back(m_addresses->at(i)->clone()); - } - result->setAddresses(addresses); - //clone internal representation of phone numbers - for (std::size_t i = 0; i < m_phoneNumbers->size(); ++i) { - phoneNumbers->push_back(m_phoneNumbers->at(i)->clone()); - } - result->setPhoneNumbers(phoneNumbers); - //clone internal representation of emails - for (std::size_t i = 0; i < m_emails->size(); ++i) { - emails->push_back(m_emails->at(i)->clone()); - } - result->setEmails(emails); - return result; -} - -} // Contact -} // Api -} // TizenApis diff --git a/src/platform/API/Contact/ContactRef.cpp b/src/platform/API/Contact/ContactRef.cpp new file mode 100755 index 0000000..81342b6 --- /dev/null +++ b/src/platform/API/Contact/ContactRef.cpp @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES 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_contactId = ""; + + m_addressBookIdIsSet = false; + m_contactIdIsSet = false; +} + +ContactRefPtr ContactRef::clone() +{ + ContactRefPtr result(new ContactRef()); + + result->m_addressBookId = m_addressBookId; + result->m_contactId = m_contactId; + + result->m_addressBookIdIsSet = m_addressBookIdIsSet; + 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 index 0000000..73bcbcc --- /dev/null +++ b/src/platform/API/Contact/ContactRef.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES 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 +#include +#include +#include +#include + +namespace TizenApis { +namespace Api { +namespace Contact { + +class ContactRef; +typedef DPL::SharedPtr ContactRefPtr; + +typedef std::vector ContactRefArray; +typedef DPL::SharedPtr 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; + std::string m_contactId; + + bool m_addressBookIdIsSet; + 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 index d0fe85f..79c3de6 100755 --- a/src/platform/API/Contact/ContactTypes.h +++ b/src/platform/API/Contact/ContactTypes.h @@ -34,8 +34,8 @@ namespace Contact { typedef std::vector StringArray; typedef DPL::SharedPtr StringArrayPtr; -typedef std::vector AttributesOfInterestArray; -typedef DPL::SharedPtr AttributesOfInterestArrayPtr; +//typedef std::vector AttributesOfInterestArray; +//typedef DPL::SharedPtr AttributesOfInterestArrayPtr; enum ContactEmailAddressType { @@ -88,13 +88,6 @@ enum ContactVCardFormat VCARD_30_FORMAT }; -enum ContactCapabilityType -{ - HAS_VIDEO_CAPABILITY, - HAS_VOICE_CAPABILITY, - HAS_CAMERA_CAPABILITY -}; - } // Contact } // Api } // TizenApis diff --git a/src/platform/API/Contact/ContactWebSite.cpp b/src/platform/API/Contact/ContactWebSite.cpp index 46013c5..30670db 100755 --- a/src/platform/API/Contact/ContactWebSite.cpp +++ b/src/platform/API/Contact/ContactWebSite.cpp @@ -61,6 +61,7 @@ ContactWebSiteType ContactWebSite::getType() const void ContactWebSite::setType(const ContactWebSiteType value) { m_type = value; + m_typeIsSet = true; } bool ContactWebSite::getTypeIsSet() const @@ -68,9 +69,26 @@ bool ContactWebSite::getTypeIsSet() const return m_typeIsSet; } +void ContactWebSite::clear() +{ + m_url = ""; + m_type = WEBSITE_TYPE_HOMEPAGE; + + m_urlIsSet = false; + m_typeIsSet = false; +} + ContactWebSitePtr ContactWebSite::clone() const { - return ContactWebSitePtr(new ContactWebSite(*this)); + ContactWebSitePtr result(new ContactWebSite()); + + result->m_url = m_url; + result->m_type = m_type; + + result->m_urlIsSet = m_urlIsSet; + result->m_typeIsSet = m_typeIsSet; + + return result; } } // Contact diff --git a/src/platform/API/Contact/ContactWebSite.h b/src/platform/API/Contact/ContactWebSite.h index 33c6ad6..4b81cea 100755 --- a/src/platform/API/Contact/ContactWebSite.h +++ b/src/platform/API/Contact/ContactWebSite.h @@ -53,6 +53,7 @@ public: void setType(const ContactWebSiteType value); bool getTypeIsSet() const; + void clear(); ContactWebSitePtr clone() const; private: diff --git a/src/platform/API/Contact/EventAddressBookAddBatch.h b/src/platform/API/Contact/EventAddressBookAddBatch.h index b6aad1e..aba037e 100755 --- a/src/platform/API/Contact/EventAddressBookAddBatch.h +++ b/src/platform/API/Contact/EventAddressBookAddBatch.h @@ -27,8 +27,7 @@ #include #include #include -#include "Contact.h" -#include "ContactProperties.h" +#include "IContact.h" namespace TizenApis { namespace Api { @@ -40,11 +39,6 @@ private: bool m_result; /* parameters */ - ContactPropertiesArrayPtr m_contactProperties; - - bool m_contactPropertiesIsSet; - - /* results */ ContactArrayPtr m_contacts; bool m_contactsIsSet; @@ -52,7 +46,7 @@ private: public: EventAddressBookAddBatch() : m_result(false), - m_contactPropertiesIsSet(false) + m_contactsIsSet(false) { } @@ -74,22 +68,6 @@ public: return m_result; } - ContactPropertiesArrayPtr getContactProperties() const - { - return m_contactProperties; - } - - void setContactProperties(const ContactPropertiesArrayPtr &value) - { - m_contactProperties = value; - m_contactPropertiesIsSet = true; - } - - bool getContactPropertiesIsSet() const - { - return m_contactPropertiesIsSet; - } - ContactArrayPtr getContacts() const { return m_contacts; diff --git a/src/platform/API/Contact/EventAddressBookChangeListener.h b/src/platform/API/Contact/EventAddressBookChangeListener.h index e270729..6e1e133 100755 --- a/src/platform/API/Contact/EventAddressBookChangeListener.h +++ b/src/platform/API/Contact/EventAddressBookChangeListener.h @@ -19,6 +19,7 @@ * @author Kisub Song (kisubs.song@samsung.com) * @version 0.1 * @brief + * ## */ #ifndef _API_CONTACT_EVENT_ADDRESS_BOOK_CHANGE_LISTENER_H_ @@ -29,7 +30,7 @@ #include #include #include -#include "Contact.h" +#include "IContact.h" namespace TizenApis { namespace Api { diff --git a/src/platform/API/Contact/EventAddressBookFind.h b/src/platform/API/Contact/EventAddressBookFind.h index 08e0074..69b9cd2 100755 --- a/src/platform/API/Contact/EventAddressBookFind.h +++ b/src/platform/API/Contact/EventAddressBookFind.h @@ -29,7 +29,7 @@ #include #include #include "ContactTypes.h" -#include "Contact.h" +#include "IContact.h" namespace TizenApis { namespace Api { @@ -42,13 +42,11 @@ private: bool m_result; /* parameters */ - Tizen::FilterPtr m_filter; - Tizen::SortModeArrayPtr m_sortModes; -// StringArrayPtr m_attributesOfInterest; + Tizen::FilterPtr m_filter; + Tizen::SortModePtr m_sortMode; bool m_filterIsSet; - bool m_sortModesIsSet; -// bool m_attributesOfInterestIsSet; + bool m_sortModeIsSet; /* results */ ContactArrayPtr m_contacts; @@ -59,8 +57,7 @@ public: EventAddressBookFind() : m_result(false), m_filterIsSet(false), - m_sortModesIsSet(false), -// m_attributesOfInterestIsSet(false), + m_sortModeIsSet(false), m_contactsIsSet(false) { } @@ -99,38 +96,22 @@ public: return m_filterIsSet; } - Tizen::SortModeArrayPtr getSortModes() const + Tizen::SortModePtr getSortMode() const { - return m_sortModes; + return m_sortMode; } - void setSortModes(const Tizen::SortModeArrayPtr &value) + void setSortMode(const Tizen::SortModePtr &value) { - m_sortModes = value; - m_sortModesIsSet = true; + m_sortMode = value; + m_sortModeIsSet = true; } - bool getSortModesIsSet() const + bool getSortModeIsSet() const { - return m_sortModesIsSet; + return m_sortModeIsSet; } -// StringArrayPtr getAttributesOfInterest() const -// { -// return m_attributesOfInterest; -// } -// -// void setAttributesOfInterest(const StringArrayPtr &value) -// { -// m_attributesOfInterest = value; -// m_attributesOfInterestIsSet = true; -// } -// -// bool getAttributesOfInterestIsSet() const -// { -// return m_attributesOfInterestIsSet; -// } - ContactArrayPtr getContacts() const { return m_contacts; diff --git a/src/platform/API/Contact/EventAddressBookUpdateBatch.h b/src/platform/API/Contact/EventAddressBookUpdateBatch.h index c3be9e0..be2d5b6 100755 --- a/src/platform/API/Contact/EventAddressBookUpdateBatch.h +++ b/src/platform/API/Contact/EventAddressBookUpdateBatch.h @@ -27,7 +27,7 @@ #include #include #include -#include "Contact.h" +#include "IContact.h" namespace TizenApis { namespace Api { diff --git a/src/platform/API/Contact/EventContactManagerGetAddressBooks.h b/src/platform/API/Contact/EventContactManagerGetAddressBooks.h index 6f18240..e20528d 100755 --- a/src/platform/API/Contact/EventContactManagerGetAddressBooks.h +++ b/src/platform/API/Contact/EventContactManagerGetAddressBooks.h @@ -39,7 +39,7 @@ private: bool m_result; /* parameters */ - IAddressBookArrayPtr m_addressBooks; + AddressBookArrayPtr m_addressBooks; bool m_addressBooksIsSet; @@ -68,12 +68,12 @@ public: return m_result; } - IAddressBookArrayPtr getAddressBooks() const + AddressBookArrayPtr getAddressBooks() const { return m_addressBooks; } - void setAddressBooks(const IAddressBookArrayPtr &value) + void setAddressBooks(const AddressBookArrayPtr &value) { m_addressBooks = value; m_addressBooksIsSet = true; diff --git a/src/platform/API/Contact/IAddressBook.h b/src/platform/API/Contact/IAddressBook.h index 42c823a..4340ddc 100755 --- a/src/platform/API/Contact/IAddressBook.h +++ b/src/platform/API/Contact/IAddressBook.h @@ -41,10 +41,10 @@ namespace Api { namespace Contact { class IAddressBook; -typedef DPL::SharedPtr IAddressBookPtr; +typedef DPL::SharedPtr AddressBookPtr; -typedef std::vector IAddressBookArray; -typedef DPL::SharedPtr IAddressBookArrayPtr; +typedef std::vector AddressBookArray; +typedef DPL::SharedPtr AddressBookArrayPtr; class IAddressBook : public WrtDeviceApis::Commons::EventRequestReceiver< EventAddressBookAddBatch >, @@ -60,12 +60,11 @@ public: PhoneBook } AddressBookType; - virtual ~IAddressBook(); explicit IAddressBook(AddressBookType type); + virtual ~IAddressBook(); - virtual ContactPropertiesPtr convertFromString(const std::string &vCardStr, const std::string &format) = 0; - virtual std::string convertToString(const ContactPtr &contact, const std::string &format) = 0; - virtual ContactPtr add(const ContactPropertiesPtr &contactProperty) = 0; + virtual ContactPtr get(const std::string &contactId) = 0; + virtual void add(const ContactPtr &contact) = 0; virtual void addBatch(const EventAddressBookAddBatchPtr &event); virtual void update(const ContactPtr &contact) = 0; virtual void updateBatch(const EventAddressBookUpdateBatchPtr &event); @@ -77,8 +76,12 @@ public: virtual void removeChangeListener(const long watchId) = 0; virtual AddressBookType getType() const; + 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 bool getReadOnly() const = 0; + virtual void setReadOnly(const bool &value) = 0; protected: AddressBookType m_bookType; diff --git a/src/platform/API/Contact/IContact.cpp b/src/platform/API/Contact/IContact.cpp new file mode 100755 index 0000000..6e38f35 --- /dev/null +++ b/src/platform/API/Contact/IContact.cpp @@ -0,0 +1,468 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES 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 + * ## - Change name to IContact + */ + +#include "ContactFactory.h" +#include "IContact.h" + +namespace TizenApis { +namespace Api { +namespace Contact { + +IContact::IContact() : + m_isFavorite(false), + m_idIsSet(false), + m_lastUpdatedIsSet(false), + m_nameIsSet(false), + m_accountIsSet(false), + m_photoURIIsSet(false), + m_birthdayIsSet(false), + m_organizationIsSet(false), + m_ringtoneURIIsSet(false) +{ + m_name = ContactNamePtr(new ContactName()); + m_account = ContactAccountPtr(new ContactAccount()); + m_addresses = ContactAddressArrayPtr(new ContactAddressArray()); + m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray()); + m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray()); + m_birthday = {0, }; + m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray()); + m_organization = ContactOrganizationPtr(new ContactOrganization()); + m_notes = StringArrayPtr(new StringArray()); + m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray()); + m_categories = StringArrayPtr(new StringArray()); +} + +IContact::IContact(const std::string &vObjectStr, const std::string &format) : + m_isFavorite(false), + m_idIsSet(false), + m_lastUpdatedIsSet(false), + m_nameIsSet(false), + m_accountIsSet(false), + m_photoURIIsSet(false), + m_birthdayIsSet(false), + m_organizationIsSet(false), + m_ringtoneURIIsSet(false) +{ + m_name = ContactNamePtr(new ContactName()); + m_account = ContactAccountPtr(new ContactAccount()); + m_addresses = ContactAddressArrayPtr(new ContactAddressArray()); + m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray()); + m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray()); + m_birthday = {0, }; + m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray()); + m_organization = ContactOrganizationPtr(new ContactOrganization()); + m_notes = StringArrayPtr(new StringArray()); + m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray()); + m_categories = 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; +} + +bool IContact::getIdIsSet() const +{ + return m_idIsSet; +} + +void IContact::setId(const int value) +{ + std::stringstream oss; + oss << value; + m_id = oss.str(); + m_idIsSet = true; +} + +std::tm IContact::getLastUpdated() const +{ + return m_lastUpdated; +} + +void IContact::setLastUpdated(const std::tm &value) +{ + m_lastUpdated = value; + m_lastUpdatedIsSet = true; +} + +bool IContact::getLastUpdatedIsSet() const +{ + return m_lastUpdatedIsSet; +} + +ContactNamePtr IContact::getName() const +{ + return m_name; +} + +void IContact::setName(const ContactNamePtr &value) +{ + m_name = value; + m_nameIsSet = true; +} + +bool IContact::getNameIsSet() const +{ + return m_nameIsSet; +} + +ContactAccountPtr IContact::getAccount() const +{ + return m_account; +} + +void IContact::setAccount(const ContactAccountPtr &value) +{ + m_account = value; + m_accountIsSet = true; +} + +bool IContact::getAccountIsSet() const +{ + return m_accountIsSet; +} + +ContactAddressArrayPtr IContact::getAddresses() const +{ + return m_addresses; +} + +void IContact::setAddresses(const ContactAddressArrayPtr &value) +{ + m_addresses = value; +} + +void IContact::addAddress(const ContactAddressPtr &value) +{ + m_addresses->push_back(value); +} + +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; +} + +bool IContact::getPhotoURIIsSet() const +{ + return m_photoURIIsSet; +} + +ContactPhoneNumberArrayPtr IContact::getPhoneNumbers() const +{ + return m_phoneNumbers; +} + +void IContact::setPhoneNumbers(const ContactPhoneNumberArrayPtr &value) +{ + m_phoneNumbers = value; +} + +void IContact::addPhoneNumber(const ContactPhoneNumberPtr &value) +{ + m_phoneNumbers->push_back(value); +} + +int IContact::getPhoneNumbersNum() const +{ + return m_phoneNumbers->size(); +} + +ContactEmailAddressArrayPtr IContact::getEmails() const +{ + return m_emails; +} + +void IContact::addEmail(const ContactEmailAddressPtr& value) +{ + m_emails->push_back(value); +} + +void IContact::setEmails(const ContactEmailAddressArrayPtr &value) +{ + m_emails = value; +} + +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; +} + +bool IContact::getBirthdayIsSet() const +{ + return m_birthdayIsSet; +} + +ContactAnniversaryArrayPtr IContact::getAnniversaries() const +{ + return m_anniversaries; +} + +void IContact::setAnniversaries(const ContactAnniversaryArrayPtr &value) +{ + m_anniversaries = value; +} + +void IContact::addAnniversary(const ContactAnniversaryPtr &value) +{ + m_anniversaries->push_back(value); +} + +int IContact::getAnniversariesNum() const +{ + return m_anniversaries->size(); +} + +ContactOrganizationPtr IContact::getOrganization() const +{ + return m_organization; +} + +void IContact::setOrganization(const ContactOrganizationPtr &value) +{ + m_organization = value; + m_organizationIsSet = true; +} + +bool IContact::getOrganizationIsSet() const +{ + return m_organizationIsSet; +} + +StringArrayPtr IContact::getNotes() const +{ + return m_notes; +} + +void IContact::setNotes(const StringArrayPtr &value) +{ + m_notes = value; +} + +void IContact::addNote(const std::string &value) +{ + m_notes->push_back(value); +} + +int IContact::getNotesNum() const +{ + return m_notes->size(); +} + +ContactWebSiteArrayPtr IContact::getUrls() const +{ + return m_urls; +} + +void IContact::setUrls(const ContactWebSiteArrayPtr &value) +{ + m_urls = value; +} + +void IContact::addUrl(const ContactWebSitePtr &value) +{ + m_urls->push_back(value); +} + +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; +} + +bool IContact::getRingtoneURIIsSet() const +{ + return m_ringtoneURIIsSet; +} + +void IContact::setRingtoneURI(const std::string &value) +{ + m_ringtoneURI = value; + m_ringtoneURIIsSet = true; +} + +StringArrayPtr IContact::getCategories() const +{ + return m_categories; +} + +void IContact::setCategories(const StringArrayPtr &value) +{ + m_categories = value; +} + +void IContact::addCategory(const std::string &value) +{ + m_categories->push_back(value); +} + +int IContact::getCategoriesNum() const +{ + return m_categories->size(); +} + +void IContact::clear() +{ + m_id = ""; + m_lastUpdated = {0, }; + m_name = ContactNamePtr(new ContactName()); + m_account = ContactAccountPtr(new ContactAccount()); + m_addresses = ContactAddressArrayPtr(new ContactAddressArray()); + m_photoURI = ""; + m_phoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray()); + m_emails = ContactEmailAddressArrayPtr(new ContactEmailAddressArray()); + m_birthday = {0, }; + m_anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray()); + m_organization = ContactOrganizationPtr(new ContactOrganization()); + m_notes = StringArrayPtr(new StringArray()); + m_urls = ContactWebSiteArrayPtr(new ContactWebSiteArray()); + m_isFavorite = false; + m_ringtoneURI = ""; + m_categories = StringArrayPtr(new StringArray()); + + m_idIsSet = false; + m_lastUpdatedIsSet = false; + m_nameIsSet = false; + m_accountIsSet = false; + m_photoURIIsSet = false; + m_birthdayIsSet = false; + m_organizationIsSet = false; + m_ringtoneURIIsSet = false; +} + +ContactPtr IContact::clone() const +{ + ContactPtr result = ContactFactory::getInstance().createContact(); + + result->m_id = ""; + result->m_lastUpdated = {0, }; + + result->m_name = m_name->clone(); + result->m_account = m_account->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_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_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_organization = m_organization->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_categories = StringArrayPtr(new StringArray()); + StringArray::iterator categoryIter; + for(categoryIter = m_categories->begin(); categoryIter != m_categories->end(); categoryIter++) + { + std::string category = *categoryIter; + result->m_categories->push_back(category); + } + + result->m_idIsSet = false; + result->m_lastUpdatedIsSet = false; + result->m_nameIsSet = m_nameIsSet; + result->m_accountIsSet = m_accountIsSet; + result->m_photoURIIsSet = m_photoURIIsSet; + result->m_birthdayIsSet = m_birthdayIsSet; + result->m_organizationIsSet = m_organizationIsSet; + result->m_ringtoneURIIsSet = m_ringtoneURIIsSet; + + return result; +} + +} // Contact +} // Api +} // TizenApis diff --git a/src/platform/API/Contact/ContactProperties.h b/src/platform/API/Contact/IContact.h similarity index 79% rename from src/platform/API/Contact/ContactProperties.h rename to src/platform/API/Contact/IContact.h index a0ca03c..a7ce7ad 100755 --- a/src/platform/API/Contact/ContactProperties.h +++ b/src/platform/API/Contact/IContact.h @@ -15,14 +15,15 @@ */ /** - * @file ContactProperties.h + * @file IContact.h * @author Kisub Song (kisubs.song@samsung.com) * @version 0.1 * @brief + * ## */ -#ifndef _API_CONTACT_CONTACT_PROPERTIES_H_ -#define _API_CONTACT_CONTACT_PROPERTIES_H_ +#ifndef _API_CONTACT_ICONTACT_H_ +#define _API_CONTACT_ICONTACT_H_ #include #include @@ -43,17 +44,29 @@ namespace TizenApis { namespace Api { namespace Contact { -class ContactProperties; -typedef DPL::SharedPtr ContactPropertiesPtr; +class IContact; +typedef DPL::SharedPtr ContactPtr; -typedef std::vector ContactPropertiesArray; -typedef DPL::SharedPtr ContactPropertiesArrayPtr; +typedef std::vector ContactArray; +typedef DPL::SharedPtr ContactArrayPtr; -class ContactProperties +class IContact { public: - ContactProperties(); - virtual ~ContactProperties(); + IContact(); + IContact(const std::string &vObjectStr, const std::string &format); + virtual ~IContact(); + + virtual std::string convertToString(const std::string &format) = 0; + + std::string getId() const; + void setId(const std::string value); + void setId(const int value); + bool getIdIsSet() const; + + std::tm getLastUpdated() const; + void setLastUpdated(const std::tm &value); + bool getLastUpdatedIsSet() const; ContactNamePtr getName() const; void setName(const ContactNamePtr &value); @@ -117,12 +130,14 @@ public: void addCategory(const std::string &value); int getCategoriesNum() const; - void clear(); - ContactPropertiesPtr clone(); + virtual void clear(); + virtual ContactPtr clone() const; -private: - ContactNamePtr m_name; - ContactAccountPtr m_account; +protected: + std::string m_id; + std::tm m_lastUpdated; + ContactNamePtr m_name; + ContactAccountPtr m_account; ContactAddressArrayPtr m_addresses; std::string m_photoURI; ContactPhoneNumberArrayPtr m_phoneNumbers; @@ -136,6 +151,8 @@ private: std::string m_ringtoneURI; StringArrayPtr m_categories; + bool m_idIsSet; + bool m_lastUpdatedIsSet; bool m_nameIsSet; bool m_accountIsSet; bool m_photoURIIsSet; @@ -148,4 +165,4 @@ private: } // Api } // TizenApis -#endif // _API_CONTACT_CONTACT_PROPERTIES_H_ +#endif // _API_CONTACT_CONTACT_H_ diff --git a/src/platform/API/Contact/IContactEventPrivateData.h b/src/platform/API/Contact/IContactEventPrivateData.h index d426058..7c2b0a1 100755 --- a/src/platform/API/Contact/IContactEventPrivateData.h +++ b/src/platform/API/Contact/IContactEventPrivateData.h @@ -19,6 +19,7 @@ * @author Lukasz Marek (l.marek@samsung.com) * @version 0.1 * @brief + * ## */ #ifndef _API_CONTACT_ICONTACT_EVENT_PRIVATE_DATA_H_ diff --git a/src/platform/API/Contact/IContactManager.cpp b/src/platform/API/Contact/IContactManager.cpp index 6c228ee..8c50174 100755 --- a/src/platform/API/Contact/IContactManager.cpp +++ b/src/platform/API/Contact/IContactManager.cpp @@ -19,6 +19,7 @@ * @author Kisub Song (kisubs.song@samsung.com) * @version 0.1 * @brief + * ## */ #include diff --git a/src/platform/API/Contact/IContactManager.h b/src/platform/API/Contact/IContactManager.h index fe68102..ecbb7ba 100755 --- a/src/platform/API/Contact/IContactManager.h +++ b/src/platform/API/Contact/IContactManager.h @@ -40,7 +40,8 @@ public: IContactManager(); virtual ~IContactManager(); virtual void getAddressBooks(const EventContactManagerGetAddressBooksPtr &event); - virtual IAddressBookPtr getDefaultAddressBook() = 0; + virtual AddressBookPtr getDefaultAddressBook() = 0; + virtual AddressBookPtr getAddressBook(const std::string &addressBookId) = 0; protected: virtual void OnRequestReceived(const EventContactManagerGetAddressBooksPtr &event) = 0; diff --git a/src/platform/API/Contact/config.cmake b/src/platform/API/Contact/config.cmake index 73204e2..be4fd13 100755 --- a/src/platform/API/Contact/config.cmake +++ b/src/platform/API/Contact/config.cmake @@ -2,8 +2,8 @@ get_current_path() set(SRCS_PLATFORM_API_CONTACT ${CURRENT_PATH}/IAddressBook.cpp ${CURRENT_PATH}/IContactManager.cpp - ${CURRENT_PATH}/Contact.cpp - ${CURRENT_PATH}/ContactProperties.cpp + ${CURRENT_PATH}/IContact.cpp + ${CURRENT_PATH}/ContactRef.cpp ${CURRENT_PATH}/ContactName.cpp ${CURRENT_PATH}/ContactAccount.cpp ${CURRENT_PATH}/ContactAnniversary.cpp diff --git a/src/platform/API/Filesystem/Enums.h b/src/platform/API/Filesystem/Enums.h index 95003dc..94e7686 100755 --- a/src/platform/API/Filesystem/Enums.h +++ b/src/platform/API/Filesystem/Enums.h @@ -34,9 +34,13 @@ enum LocationType LT_OTHERS, LT_ROOT, LT_SDCARD, + LT_USBHOST, LT_SOUNDS, LT_TEMP, - LT_VIDEOS + LT_VIDEOS, + LT_WGTPKG, + LT_WGTPRV, + LT_WGTPRVTMP }; enum NodeType diff --git a/src/platform/API/Filesystem/IManager.h b/src/platform/API/Filesystem/IManager.h index 526028f..5f6aa5e 100755 --- a/src/platform/API/Filesystem/IManager.h +++ b/src/platform/API/Filesystem/IManager.h @@ -154,6 +154,7 @@ class IManager : public WrtDeviceApis::Commons::EventRequestReceivervalidateAttribute(m_attributeName, m_matchFlag, m_matchValues, 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_matchValues, depth); + visitor->visitAttribute(m_attributeName, m_matchFlag, m_matchValue, depth); } -AnyArrayPtr AttributeFilter::getMatchValues() const +AnyPtr AttributeFilter::getMatchValue() const { - return m_matchValues; + return m_matchValue; } -void AttributeFilter::setMatchValues(const AnyArrayPtr &value) +void AttributeFilter::setMatchValue(const AnyPtr &value) { - m_matchValues = value; + m_matchValue = value; } MatchFlag AttributeFilter::getMatchFlag() const diff --git a/src/platform/API/Filter/AttributeFilter.h b/src/platform/API/Filter/AttributeFilter.h index caa3beb..b378d1e 100644 --- a/src/platform/API/Filter/AttributeFilter.h +++ b/src/platform/API/Filter/AttributeFilter.h @@ -51,7 +51,7 @@ private: // fields /** * match value object. */ - AnyArrayPtr m_matchValues; + AnyPtr m_matchValue; protected: @@ -62,7 +62,7 @@ public: // methods */ explicit AttributeFilter(const std::string attributeName, const MatchFlag& matchFlag, - const AnyArrayPtr& matchValues); + const AnyPtr& matchValue); virtual ~AttributeFilter(); @@ -83,8 +83,8 @@ public: // methods std::string getAttributeName() const; void setAttributeName(const std::string &value); - AnyArrayPtr getMatchValues() const; - void setMatchValues(const AnyArrayPtr &value); + AnyPtr getMatchValue() const; + void setMatchValue(const AnyPtr &value); MatchFlag getMatchFlag() const; void setMatchFlag(const MatchFlag& value); diff --git a/src/platform/API/Filter/FilterFactory.cpp b/src/platform/API/Filter/FilterFactory.cpp index 5d2aa8f..38f2652 100644 --- a/src/platform/API/Filter/FilterFactory.cpp +++ b/src/platform/API/Filter/FilterFactory.cpp @@ -38,9 +38,9 @@ CompositeFilterPtr FilterFactory::createCompositeFilterObject(const FilterType& AttributeFilterPtr FilterFactory::createAttributeFilterObject(const string& attributeName, const MatchFlag& matchFlag, - const AnyArrayPtr& matchValues) + const AnyPtr& matchValue) { - AttributeFilterPtr result(new AttributeFilter(attributeName, matchFlag, matchValues)); + AttributeFilterPtr result(new AttributeFilter(attributeName, matchFlag, matchValue)); return result; } diff --git a/src/platform/API/Filter/FilterFactory.h b/src/platform/API/Filter/FilterFactory.h index d7ee360..831e3ed 100644 --- a/src/platform/API/Filter/FilterFactory.h +++ b/src/platform/API/Filter/FilterFactory.h @@ -50,7 +50,7 @@ public: AttributeFilterPtr createAttributeFilterObject(const std::string& attributeName, const MatchFlag& matchFlag, - const AnyArrayPtr& matchValues); + const AnyPtr& matchValue); AttributeRangeFilterPtr createAttributeRangeFilterObject(const std::string& attributeName, const AnyPtr& initialValue, diff --git a/src/platform/API/Filter/FilterValidator.cpp b/src/platform/API/Filter/FilterValidator.cpp index a0a65be..51ff86e 100644 --- a/src/platform/API/Filter/FilterValidator.cpp +++ b/src/platform/API/Filter/FilterValidator.cpp @@ -43,20 +43,18 @@ FilterValidator::~FilterValidator() } bool FilterValidator::validateAttribute(std::string& attrName, - MatchFlag& matchFlag, AnyArrayPtr& values, int depth) + MatchFlag& matchFlag, AnyPtr& matchValue, int depth) { - if(m_properties[attrName] == NULL) + if(m_properties.find(attrName) == m_properties.end()) + return false; + + if(matchValue == NULL) return false; PropertyPtr prop = m_properties[attrName]; - if(values != NULL) - { - AnyArray::iterator arrayIter; - for(arrayIter = values->begin(); arrayIter != values->end(); arrayIter++) - if(!(prop->type & (*arrayIter)->getType())) - return false; - } + if(!matchValue->isType(prop->type)) + return false; return true; } @@ -64,18 +62,25 @@ bool FilterValidator::validateAttribute(std::string& attrName, bool FilterValidator::validateAttributeRange(std::string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth) { - if(m_properties[attrName] == NULL) + if(initialValue == NULL || endValue == NULL) + return false; + + if(m_properties.find(attrName) == m_properties.end()) return false; PropertyPtr prop = m_properties[attrName]; - if(initialValue == NULL && endValue == NULL) + bool initialValueIsNull = initialValue->isNullOrUndefined(); + bool endValueIsNull = endValue->isNullOrUndefined(); + + // Invalid if both values are null + if(initialValueIsNull && endValueIsNull) return false; - if(prop->type != initialValue->getType()) + if(!initialValueIsNull && !initialValue->isType(prop->type)) return false; - if(prop->type != endValue->getType()) + if(!endValueIsNull && !endValue->isType(prop->type)) return false; return true; diff --git a/src/platform/API/Filter/FilterValidator.h b/src/platform/API/Filter/FilterValidator.h index c5459a4..d4222ae 100644 --- a/src/platform/API/Filter/FilterValidator.h +++ b/src/platform/API/Filter/FilterValidator.h @@ -70,7 +70,7 @@ public: // validate AttributeFilter virtual bool validateAttribute(std::string& attrName, - MatchFlag& matchFlag, AnyArrayPtr& values, int depth=0); + MatchFlag& matchFlag, AnyPtr& matchValue, int depth=0); // validate AttributeRangeFilter virtual bool validateAttributeRange(std::string& attrName, diff --git a/src/platform/API/Filter/IFilterVisitor.h b/src/platform/API/Filter/IFilterVisitor.h index cefd2a0..985b485 100644 --- a/src/platform/API/Filter/IFilterVisitor.h +++ b/src/platform/API/Filter/IFilterVisitor.h @@ -50,7 +50,7 @@ public: virtual void visitInComposite(FilterType& type, int depth) = 0; virtual void visitPostComposite(FilterType& type, int depth) = 0; virtual void visitAttribute(std::string& attrName, - MatchFlag& matchFlag, AnyArrayPtr& values, int depth) = 0; + MatchFlag& matchFlag, AnyPtr& matchValue, int depth) = 0; virtual void visitAttributeRange(std::string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth) = 0; }; diff --git a/src/platform/API/Mediacontent/IEventAddAudioToPlaylist.h b/src/platform/API/Mediacontent/IEventAddAudioToPlaylist.h deleted file mode 100644 index ba33b20..0000000 --- a/src/platform/API/Mediacontent/IEventAddAudioToPlaylist.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES 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_AUDIO_TO_PLAYLIST_H_ -#define _ABSTRACT_LAYER_IEVENT_ADD_AUDIO_TO_PLAYLIST_H_ - -#include -#include -#include -#include "MediacontentPlaylist.h" - -namespace TizenApis { -namespace Api { -namespace Mediacontent { - -class IEventAddAudioToPlaylist : public WrtDeviceApis::Commons::IEvent -{ - - public: - IEventAddAudioToPlaylist():m_result(false), m_playlistId(NULL), m_mediaUID(NULL) - { - LogDebug("entered"); - } - ~IEventAddAudioToPlaylist(){} - - - void setPlaylistId(string& value) - { - m_playlistId = value; - } - - string getPlaylistId() - { - return m_playlistId; - } - - void setMediaUID(string& value) - { - m_mediaUID = value; - } - - string getMediaUID() - { - return m_mediaUID; - } - - - void setResult(bool value) - { - m_result = value; - } - bool getResult() const - { - return m_result; - } - - - private: - bool m_result; - string m_playlistId; //OUTPUT: result list - string m_mediaUID; -}; - -typedef DPL::SharedPtr IEventAddAudioToPlaylistPtr; - -} -} -} -#endif /* _ABSTRACT_LAYER_IEVENT_ADD_AUDIO_TO_PLAYLIST_H_ */ diff --git a/src/platform/API/Mediacontent/IEventBrowseFolder.h b/src/platform/API/Mediacontent/IEventBrowseFolder.h new file mode 100644 index 0000000..60e1e62 --- /dev/null +++ b/src/platform/API/Mediacontent/IEventBrowseFolder.h @@ -0,0 +1,175 @@ +/* +* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES 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 +#include +#include +#include + +#include +#include "MediacontentMedia.h" + +using namespace TizenApis::Api::Tizen; + +namespace TizenApis { +namespace Api { +namespace Mediacontent { + +class IEventBrowseFolder : public WrtDeviceApis::Commons::IEvent +{ + + public: + + IEventBrowseFolder() + { + m_result = false; + m_filterIsSet = false; + m_sortModesIsSet = false; + m_limitIsSet = false; + m_offsetIsSet = false; + + } + + + virtual ~IEventBrowseFolder(){} + + void addMedia(MediacontentMedia *value) + { + MediacontentMediaPtr mediaItem(value); + m_media.push_back(mediaItem); + } + + vector 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 setFolderID(const string &value) + { + m_folderId = value; + } + + 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 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; + + string m_folderId; + + vector m_media; + +}; + +typedef DPL::SharedPtr IEventBrowseFolderPtr; + +} +} +} +#endif /* _ABSTRACT_LAYER_IEVENT_BROWSE_FOLDER_H_ */ diff --git a/src/platform/API/Mediacontent/IEventDeleteAudioToPlaylist.h b/src/platform/API/Mediacontent/IEventDeleteAudioToPlaylist.h deleted file mode 100644 index 40bf99d..0000000 --- a/src/platform/API/Mediacontent/IEventDeleteAudioToPlaylist.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES 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_AUDIO_TO_PLAYLIST_H_ -#define _ABSTRACT_LAYER_IEVENT_DELETE_AUDIO_TO_PLAYLIST_H_ - -#include -#include -#include -#include "MediacontentPlaylist.h" - -namespace TizenApis { -namespace Api { -namespace Mediacontent { - -class IEventDeleteAudioToPlaylist : public WrtDeviceApis::Commons::IEvent -{ - - public: - IEventDeleteAudioToPlaylist():m_result(false), m_playlistId(NULL), m_mediaUID(NULL) - { - LogDebug("entered"); - } - ~IEventDeleteAudioToPlaylist(){} - - - void setPlaylistId(string& value) - { - m_playlistId = value; - } - - string getPlaylistId() - { - return m_playlistId; - } - - void setMediaUID(string& value) - { - m_mediaUID = value; - } - - string getMediaUID() - { - return m_mediaUID; - } - - - void setResult(bool value) - { - m_result = value; - } - bool getResult() const - { - return m_result; - } - - - private: - bool m_result; - string m_playlistId; //OUTPUT: result list - string m_mediaUID; -}; - -typedef DPL::SharedPtr IEventDeleteAudioToPlaylistPtr; - -} -} -} -#endif /* _ABSTRACT_LAYER_IEVENT_DELETE_AUDIO_TO_PLAYLIST_H_ */ diff --git a/src/platform/API/Mediacontent/IEventFindMedia.h b/src/platform/API/Mediacontent/IEventFindMedia.h index d410186..ffaf5ef 100644 --- a/src/platform/API/Mediacontent/IEventFindMedia.h +++ b/src/platform/API/Mediacontent/IEventFindMedia.h @@ -44,6 +44,7 @@ class IEventFindMedia : public WrtDeviceApis::Commons::IEvent m_sortModesIsSet = false; m_limitIsSet = false; m_offsetIsSet = false; + } diff --git a/src/platform/API/Mediacontent/IEventFindPlaylist.h b/src/platform/API/Mediacontent/IEventFindPlaylist.h deleted file mode 100644 index b5b9d0d..0000000 --- a/src/platform/API/Mediacontent/IEventFindPlaylist.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES 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_PLAYLIST_H_ -#define _ABSTRACT_LAYER_IEVENT_FIND_PLAYLIST_H_ - -#include -#include -#include -#include "MediacontentPlaylist.h" - - -using namespace std; - -namespace TizenApis { -namespace Api { -namespace Mediacontent { - -class IEventFindPlaylist : public WrtDeviceApis::Commons::IEvent -{ - public: - IEventFindPlaylist():m_result(false){} - ~IEventFindPlaylist(){ } - void addPlaylist(MediacontentPlaylistPtr value){ m_playlist.push_back(value);} - void setResult(bool value){m_result = value;} - bool getResult()const {return m_result; } - vector getPlaylist(){return m_playlist; } - - virtual void clearOnCancel(){;} - - - private: - vector m_playlist; //OUTPUT: result list - bool m_result; //OUTPUT: operation result -}; - -typedef DPL::SharedPtr IEventFindPlaylistPtr; - -} -} -} -#endif /* _ABSTRACT_LAYER_IEVENT_FIND_PLAYLIST_H_ */ diff --git a/src/platform/API/Mediacontent/IEventFolderFindMedia.h b/src/platform/API/Mediacontent/IEventFolderFindMedia.h deleted file mode 100644 index 5d27e46..0000000 --- a/src/platform/API/Mediacontent/IEventFolderFindMedia.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES 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_FOLDER_FIND_MEDIA_H_ -#define _ABSTRACT_LAYER_IEVENT_FOLDER_FIND_MEDIA_H_ - -#include -#include -#include "MediacontentMedia.h" -#include "MediacontentFolder.h" -#include - -namespace WrtPlugins { -namespace Api { - -class IEventFolderFindMedia : public WrtDeviceApis::Commons::IEvent -{ - public: - IEventFolderFindMedia():m_result(false){} - ~IEventFolderFindMedia(){ } - - MediacontentFolderPtr getFolder(){ return m_folder;} - std::vector getMedia(){ return m_media; } - - void addMedia(MediacontentMediaPtr value){ m_media.push_back(value); } - void setResult(bool value) { m_result = value; } - bool getResult()const { return m_result; } - void setFolder(MediacontentFolderPtr folder){ m_folder = folder;} - - virtual void clearOnCancel(){;} - - - private: - MediacontentFolderPtr m_folder; - std::vector m_media; - bool m_result; -}; - -typedef DPL::SharedPtr IEventFolderFindMediaPtr; - -} -} -#endif /* _ABSTRACT_LAYER_IEVENT_FOLDER_FIND_MEDIA_H_ */ diff --git a/src/platform/API/Mediacontent/IEventUpdateMedia.h b/src/platform/API/Mediacontent/IEventUpdateMedia.h index df951a1..bb18f5f 100644 --- a/src/platform/API/Mediacontent/IEventUpdateMedia.h +++ b/src/platform/API/Mediacontent/IEventUpdateMedia.h @@ -59,7 +59,6 @@ class IEventUpdateMedia : public WrtDeviceApis::Commons::IEvent -#include #include #include -#include "MediacontentPlaylist.h" - -using namespace std; +#include "MediacontentMedia.h" namespace TizenApis { namespace Api { namespace Mediacontent { -class IEventDeletePlaylist : public WrtDeviceApis::Commons::IEvent +class IEventUpdateMediaItems : public WrtDeviceApis::Commons::IEvent { public: - IEventDeletePlaylist()//:m_result(false), m_playlistID(NULL) + IEventUpdateMediaItems():m_result(false) { LogDebug("entered"); } - ~IEventDeletePlaylist(){} + virtual ~IEventUpdateMediaItems(){} - - void setPlaylistId(const string& value) - { - m_playlistID = value; - } - - string getPlaylistId() - { - return m_playlistID; - } - - void setResult(bool value) { m_result = value; @@ -61,15 +46,25 @@ class IEventDeletePlaylist : public WrtDeviceApis::Commons::IEvent IEventDeletePlaylistPtr; +typedef DPL::SharedPtr IEventUpdateMediaItemsPtr; } } } -#endif /* _ABSTRACT_LAYER_IEVENT_DELETE_PLAYLIST_H_ */ +#endif /* _ABSTRACT_LAYER_IEVENT_UPDATE_ITEMS_H_ */ diff --git a/src/platform/API/Mediacontent/IMediacontent.cpp b/src/platform/API/Mediacontent/IMediacontent.cpp index 4b5f4a5..b1508db 100644 --- a/src/platform/API/Mediacontent/IMediacontent.cpp +++ b/src/platform/API/Mediacontent/IMediacontent.cpp @@ -24,10 +24,11 @@ namespace Mediacontent { IMediacontent::IMediacontent(): - WrtDeviceApis::Commons::EventRequestReceiver(WrtDeviceApis::Commons::ThreadEnum::GALLERY_THREAD), - WrtDeviceApis::Commons::EventRequestReceiver(WrtDeviceApis::Commons::ThreadEnum::GALLERY_THREAD), - WrtDeviceApis::Commons::EventRequestReceiver(WrtDeviceApis::Commons::ThreadEnum::GALLERY_THREAD) - // TODO TO be changed to MEDIACONTENT_THREAD + WrtDeviceApis::Commons::EventRequestReceiver(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD), + WrtDeviceApis::Commons::EventRequestReceiver(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD), + WrtDeviceApis::Commons::EventRequestReceiver(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD), + WrtDeviceApis::Commons::EventRequestReceiver(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD), + WrtDeviceApis::Commons::EventRequestReceiver(WrtDeviceApis::Commons::ThreadEnum::MEDIACONTENT_THREAD) { LogDebug("IMediacontent::Constructure entered"); } @@ -54,6 +55,17 @@ void IMediacontent::updateMedia(IEventUpdateMediaPtr &ptr) WrtDeviceApis::Commons::EventRequestReceiver::PostRequest(ptr); } +void IMediacontent::browseFolder(IEventBrowseFolderPtr &ptr) +{ + LogDebug("IMediacontent::called IEventBrowseFolder"); + WrtDeviceApis::Commons::EventRequestReceiver::PostRequest(ptr); +} + +void IMediacontent::updateMediaItems(IEventUpdateMediaItemsPtr &ptr) +{ + LogDebug("IMediacontent::called IEventBrowseFolder"); + WrtDeviceApis::Commons::EventRequestReceiver::PostRequest(ptr); +} } diff --git a/src/platform/API/Mediacontent/IMediacontent.h b/src/platform/API/Mediacontent/IMediacontent.h index 7bb9414..c832687 100644 --- a/src/platform/API/Mediacontent/IMediacontent.h +++ b/src/platform/API/Mediacontent/IMediacontent.h @@ -24,6 +24,9 @@ #include "IEventFindMedia.h" #include "IEventFindFolder.h" #include "IEventUpdateMedia.h" +#include "IEventUpdateMediaItems.h" +#include "IEventBrowseFolder.h" + namespace TizenApis { @@ -33,7 +36,9 @@ namespace Mediacontent { class IMediacontent : public WrtDeviceApis::Commons::EventRequestReceiver, public WrtDeviceApis::Commons::EventRequestReceiver, - public WrtDeviceApis::Commons::EventRequestReceiver + public WrtDeviceApis::Commons::EventRequestReceiver, + public WrtDeviceApis::Commons::EventRequestReceiver, + public WrtDeviceApis::Commons::EventRequestReceiver { public: @@ -50,10 +55,14 @@ class IMediacontent : virtual void findMedia(IEventFindMediaPtr &ptr); virtual void findFolder(IEventFindFolderPtr &ptr); virtual void updateMedia(IEventUpdateMediaPtr &ptr); + virtual void browseFolder(IEventBrowseFolderPtr &ptr); + virtual void updateMediaItems(IEventUpdateMediaItemsPtr &ptr); virtual void OnRequestReceived(const IEventFindMediaPtr &value) = 0; 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; }; diff --git a/src/platform/API/Mediacontent/MediacontentAudio.cpp b/src/platform/API/Mediacontent/MediacontentAudio.cpp index 8defb18..8c4169e 100644 --- a/src/platform/API/Mediacontent/MediacontentAudio.cpp +++ b/src/platform/API/Mediacontent/MediacontentAudio.cpp @@ -29,6 +29,14 @@ MediacontentAudio::MediacontentAudio() m_isChangedPlayCount = false; m_isChangedPlayedTime = false; + EditableAttributeListPtr listPtr(new EditableAttributeList()); + + listPtr->push_back("rating"); + listPtr->push_back("playedTime"); + listPtr->push_back("playCount"); + + m_editableAttrPtr = listPtr; + } MediacontentAudio::~MediacontentAudio() @@ -160,6 +168,21 @@ void MediacontentAudio::setAudioLyrics(MediacontentLyricsPtr value) } +bool MediacontentAudio::isChangedPlayCount() +{ + return m_isChangedPlayCount; +} +bool MediacontentAudio::isChangedPlayedTime() +{ + return m_isChangedPlayedTime; +} + +EditableAttributeListPtr MediacontentAudio::getEditableAttr() const +{ + return m_editableAttrPtr; +} + + void MediacontentAudio::display() const { diff --git a/src/platform/API/Mediacontent/MediacontentAudio.h b/src/platform/API/Mediacontent/MediacontentAudio.h index 340afc5..b9775ab 100644 --- a/src/platform/API/Mediacontent/MediacontentAudio.h +++ b/src/platform/API/Mediacontent/MediacontentAudio.h @@ -70,8 +70,13 @@ class MediacontentAudio : public MediacontentMedia void setAudioSize(const int &value); void setAudioLyrics(MediacontentLyricsPtr value); - + bool isChangedPlayCount(); + bool isChangedPlayedTime(); + + + virtual EditableAttributeListPtr getEditableAttr() const; + void display() const; diff --git a/src/platform/API/Mediacontent/MediacontentFolder.cpp b/src/platform/API/Mediacontent/MediacontentFolder.cpp index a3d758a..783e5de 100644 --- a/src/platform/API/Mediacontent/MediacontentFolder.cpp +++ b/src/platform/API/Mediacontent/MediacontentFolder.cpp @@ -34,12 +34,6 @@ MediacontentFolder::~MediacontentFolder() } -EditableAttributeListPtr MediacontentFolder::getEditableAttr() const -{ - return m_editableAttrPtr; -} - - string MediacontentFolder::getFolderUUID() const { return m_folderUUID; diff --git a/src/platform/API/Mediacontent/MediacontentFolder.h b/src/platform/API/Mediacontent/MediacontentFolder.h index 17e3240..97cad2f 100644 --- a/src/platform/API/Mediacontent/MediacontentFolder.h +++ b/src/platform/API/Mediacontent/MediacontentFolder.h @@ -32,8 +32,6 @@ namespace TizenApis { namespace Api { namespace Mediacontent { -typedef vector EditableAttributeList; -typedef DPL::SharedPtr EditableAttributeListPtr; typedef vector MediaIdList; typedef DPL::SharedPtr MediaIdListPtr; @@ -45,7 +43,7 @@ class MediacontentFolder MediacontentFolder(); virtual ~MediacontentFolder(); - EditableAttributeListPtr getEditableAttr() const; + string getFolderUUID() const; string getFolderPath() const; string getFolderName() const; @@ -73,7 +71,7 @@ class MediacontentFolder string m_storageType; tm m_modifiedDate; MediaIdListPtr m_mediaIdArrayPtr; - EditableAttributeListPtr m_editableAttrPtr; + map m_folderValue; }; diff --git a/src/platform/API/Mediacontent/MediacontentImage.cpp b/src/platform/API/Mediacontent/MediacontentImage.cpp index 7309b0b..d8a2272 100644 --- a/src/platform/API/Mediacontent/MediacontentImage.cpp +++ b/src/platform/API/Mediacontent/MediacontentImage.cpp @@ -26,6 +26,10 @@ namespace Mediacontent { MediacontentImage::MediacontentImage() { + + EditableAttributeListPtr listPtr(new EditableAttributeList()); + listPtr->push_back("rating"); + m_editableAttrPtr = listPtr; } MediacontentImage::~MediacontentImage() @@ -86,6 +90,12 @@ void MediacontentImage::setImageOrientation(const string &value) } +EditableAttributeListPtr MediacontentImage::getEditableAttr() const +{ + return m_editableAttrPtr; +} + + void MediacontentImage::display() { diff --git a/src/platform/API/Mediacontent/MediacontentImage.h b/src/platform/API/Mediacontent/MediacontentImage.h index fc9d412..0bc8a96 100644 --- a/src/platform/API/Mediacontent/MediacontentImage.h +++ b/src/platform/API/Mediacontent/MediacontentImage.h @@ -53,6 +53,9 @@ class MediacontentImage : public MediacontentMedia void setImageLongitude(const double &value); void display(); + + virtual EditableAttributeListPtr getEditableAttr() const; + protected: int m_imageWidth; diff --git a/src/platform/API/Mediacontent/MediacontentMedia.cpp b/src/platform/API/Mediacontent/MediacontentMedia.cpp index 9635944..6457d5e 100644 --- a/src/platform/API/Mediacontent/MediacontentMedia.cpp +++ b/src/platform/API/Mediacontent/MediacontentMedia.cpp @@ -17,6 +17,8 @@ #include #include #include "MediacontentMedia.h" +#include + namespace TizenApis { namespace Api { @@ -25,6 +27,7 @@ namespace Mediacontent { MediacontentMedia::MediacontentMedia() { m_isChangedFavorite = false; + m_isGetMimetype = false; } MediacontentMedia::~MediacontentMedia() @@ -41,8 +44,21 @@ void MediacontentMedia::setMediaUUID(const string &value) m_mediaUUID = value; } -string MediacontentMedia::getMimeType() const -{ +string MediacontentMedia::getMimeType() +{ + LogDebug("MediacontentMedia::getMimeType"); + if(!m_isGetMimetype) + { + int res; + char type[256]; + res = aul_get_mime_from_file(m_filePath.c_str(), type, sizeof(type)); + LogDebug("file:"<< m_filePath <<" type:" << type); + if(res == 0) + { + m_mimeType = type; + m_isGetMimetype = true; + } + } return m_mimeType; } @@ -171,6 +187,12 @@ bool MediacontentMedia::getIsChangedFavorite() const +EditableAttributeListPtr MediacontentMedia::getEditableAttr() const +{ + return m_editableAttrPtr; +} + + } } } diff --git a/src/platform/API/Mediacontent/MediacontentMedia.h b/src/platform/API/Mediacontent/MediacontentMedia.h index ab502a5..d606340 100644 --- a/src/platform/API/Mediacontent/MediacontentMedia.h +++ b/src/platform/API/Mediacontent/MediacontentMedia.h @@ -39,6 +39,9 @@ typedef enum }media_type; +typedef vector EditableAttributeList; +typedef DPL::SharedPtr EditableAttributeListPtr; + class MediacontentMedia { public: @@ -48,7 +51,7 @@ class MediacontentMedia string getMediaUUID() const; string getMediaType() const; - string getMimeType() const; + string getMimeType(); string getDisplayName() const; string getFilePath() const; string getThumbnailPath() const; @@ -73,6 +76,7 @@ class MediacontentMedia void setDescription(const string &value); void display() const; + virtual EditableAttributeListPtr getEditableAttr() const; private: string m_mediaUUID; @@ -87,6 +91,10 @@ class MediacontentMedia tm m_modifiedDate; int m_favorite; bool m_isChangedFavorite; + bool m_isGetMimetype; + + protected: + EditableAttributeListPtr m_editableAttrPtr; }; diff --git a/src/platform/API/Mediacontent/MediacontentVideo.cpp b/src/platform/API/Mediacontent/MediacontentVideo.cpp index d352d96..58ba798 100644 --- a/src/platform/API/Mediacontent/MediacontentVideo.cpp +++ b/src/platform/API/Mediacontent/MediacontentVideo.cpp @@ -28,6 +28,14 @@ MediacontentVideo::MediacontentVideo() { m_isChangedPlayCount = false; m_isChangedPlayedTime = false; + + EditableAttributeListPtr listPtr(new EditableAttributeList()); + + listPtr->push_back("rating"); + listPtr->push_back("playedTime"); +// m_editableAttrPtr->push_back("playCount"); + m_editableAttrPtr = listPtr; + } MediacontentVideo::~MediacontentVideo() @@ -138,6 +146,21 @@ void MediacontentVideo::setVideoArtist(const string &value) } +bool MediacontentVideo::isChangedPlayCount() +{ + return m_isChangedPlayCount; +} +bool MediacontentVideo::isChangedPlayedTime() +{ + return m_isChangedPlayedTime; +} + +EditableAttributeListPtr MediacontentVideo::getEditableAttr() const +{ + return m_editableAttrPtr; +} + + void MediacontentVideo::display() const { diff --git a/src/platform/API/Mediacontent/MediacontentVideo.h b/src/platform/API/Mediacontent/MediacontentVideo.h index c1f46db..63f43bf 100644 --- a/src/platform/API/Mediacontent/MediacontentVideo.h +++ b/src/platform/API/Mediacontent/MediacontentVideo.h @@ -59,6 +59,11 @@ class MediacontentVideo : public MediacontentMedia void setVideoAlbum(const string &value); void setVideoArtist(const string &value); + bool isChangedPlayCount(); + bool isChangedPlayedTime(); + + virtual EditableAttributeListPtr getEditableAttr() const; + void display() const; private: @@ -73,6 +78,7 @@ class MediacontentVideo : public MediacontentMedia int m_videoHeight; bool m_isChangedPlayCount; bool m_isChangedPlayedTime; + vector editableAttr; }; typedef DPL::SharedPtr MediacontentVideoPtr; diff --git a/src/platform/API/Mediacontent/config.cmake b/src/platform/API/Mediacontent/config.cmake index 0eaa91d..0fa13e6 100644 --- a/src/platform/API/Mediacontent/config.cmake +++ b/src/platform/API/Mediacontent/config.cmake @@ -1,4 +1,20 @@ get_current_path() + +pkg_search_module(mm-fileinfo REQUIRED mm-fileinfo) +pkg_search_module(aul REQUIRED aul) + +set(INCLUDES_PLATFORM_IMPLEMENTATION_MEDIACONTENT + ${mm-fileinfo_INCLUDE_DIRS} + ${aul_INCLUDE_DIRS} + PARENT_SCOPE +) + +set(LIBS_PLATFORM_IMPLEMENTATION_MEDIACONTENT + ${mm-fileinfo_LIBRARIES} + ${aul_LIBRARIES} + PARENT_SCOPE +) + set(SRCS_PLATFORM_API_MEDIACONTENT ${CURRENT_PATH}/MediacontentFactory.cpp ${CURRENT_PATH}/MediacontentMedia.cpp diff --git a/src/platform/API/Messaging/ConversationFilterValidator.cpp b/src/platform/API/Messaging/ConversationFilterValidator.cpp index 2c8ca88..50c0a0a 100755 --- a/src/platform/API/Messaging/ConversationFilterValidator.cpp +++ b/src/platform/API/Messaging/ConversationFilterValidator.cpp @@ -43,6 +43,9 @@ namespace TizenApis { 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){ @@ -55,19 +58,19 @@ namespace TizenApis { } bool ConversationFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth){ + Api::Tizen::AnyPtr& matchValue, int depth){ + + if(matchValue == NULL) + return false; + bool retBool = false; - AnyArray::iterator iter; - for(iter=values->begin(); iter!=values->end(); iter++){ - AnyPtr value = *iter; - if(validateAttributeEach(attrName, matchFlag, value, depth) == false){ - MsgLogWanning(">>>[Warning] attrName:[" << attrName << "] is invalid value:[" << value->toString() << "]"); - 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, values,depth); + retBool = FilterValidator::validateAttribute(attrName, matchFlag, matchValue,depth); LogDebug(">>> retBool:" << retBool); return retBool; } diff --git a/src/platform/API/Messaging/ConversationFilterValidator.h b/src/platform/API/Messaging/ConversationFilterValidator.h index 8e84b3b..e47e810 100755 --- a/src/platform/API/Messaging/ConversationFilterValidator.h +++ b/src/platform/API/Messaging/ConversationFilterValidator.h @@ -43,7 +43,7 @@ namespace TizenApis { Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0); virtual bool validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth=0); + Api::Tizen::AnyPtr& matchValue, int depth=0); protected: bool validateAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth); diff --git a/src/platform/API/Messaging/FolderFilterValidator.cpp b/src/platform/API/Messaging/FolderFilterValidator.cpp index d1e1aab..1ebe276 100644 --- a/src/platform/API/Messaging/FolderFilterValidator.cpp +++ b/src/platform/API/Messaging/FolderFilterValidator.cpp @@ -97,19 +97,18 @@ namespace TizenApis { } bool FolderFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth){ + Api::Tizen::AnyPtr& matchValue, int depth){ bool retBool = false; - AnyArray::iterator iter; - for(iter=values->begin(); iter!=values->end(); iter++){ - AnyPtr value = *iter; - if(validateAttributeEach(attrName, matchFlag, value, depth) == false){ - MsgLogWanning(">>>[Warning] attrName:[" << attrName << "] is invalid value:[" << value->toString() << "]"); - return 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, values, depth); + retBool = FilterValidator::validateAttribute(attrName, matchFlag, matchValue, depth); LogDebug("## 002 ##"); LogDebug(">>> retBool:" << retBool); return retBool; diff --git a/src/platform/API/Messaging/FolderFilterValidator.h b/src/platform/API/Messaging/FolderFilterValidator.h index 47eba0d..0e42d47 100644 --- a/src/platform/API/Messaging/FolderFilterValidator.h +++ b/src/platform/API/Messaging/FolderFilterValidator.h @@ -51,7 +51,7 @@ namespace TizenApis { Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0); virtual bool validateAttribute(std::string& attrName, - Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyArrayPtr& values, int depth=0); + 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); diff --git a/src/platform/API/Messaging/FolderFilterValidatorFactory.cpp b/src/platform/API/Messaging/FolderFilterValidatorFactory.cpp old mode 100644 new mode 100755 diff --git a/src/platform/API/Messaging/MessageFilterValidator.cpp b/src/platform/API/Messaging/MessageFilterValidator.cpp index 0d45373..694d5dc 100755 --- a/src/platform/API/Messaging/MessageFilterValidator.cpp +++ b/src/platform/API/Messaging/MessageFilterValidator.cpp @@ -100,6 +100,9 @@ namespace TizenApis { } 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){ @@ -150,19 +153,18 @@ namespace TizenApis { } bool MessageFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth){ + Api::Tizen::AnyPtr& matchValue, int depth){ bool retBool = false; - AnyArray::iterator iter; - for(iter=values->begin(); iter!=values->end(); iter++){ - AnyPtr value = *iter; - if(validateAttributeEach(attrName, matchFlag, value, depth) == false){ - MsgLogWanning(">>>[Warning] attrName:[" << attrName << "] is invalid value:[" << value->toString() << "]"); - return 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, values, depth); + retBool = FilterValidator::validateAttribute(attrName, matchFlag, matchValue, depth); LogDebug(">>> retBool:" << retBool); return retBool; } diff --git a/src/platform/API/Messaging/MessageFilterValidator.h b/src/platform/API/Messaging/MessageFilterValidator.h index 7222500..4b27b00 100755 --- a/src/platform/API/Messaging/MessageFilterValidator.h +++ b/src/platform/API/Messaging/MessageFilterValidator.h @@ -61,7 +61,7 @@ namespace TizenApis { Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0); virtual bool validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth=0); + Api::Tizen::AnyPtr& matchValue, int depth=0); protected: bool validateAttributeEach(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& value, int depth); diff --git a/src/platform/API/Messaging/StorageChangesConversationFilterValidator.cpp b/src/platform/API/Messaging/StorageChangesConversationFilterValidator.cpp index ed0f18f..c32ec5c 100755 --- a/src/platform/API/Messaging/StorageChangesConversationFilterValidator.cpp +++ b/src/platform/API/Messaging/StorageChangesConversationFilterValidator.cpp @@ -43,6 +43,10 @@ namespace TizenApis { 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 << "]"); @@ -54,11 +58,14 @@ namespace TizenApis { } bool StorageChangesConversationFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth){ + Api::Tizen::AnyPtr& matchValue, int depth){ + + if(matchValue == NULL) + return false; bool retBool = false; - retBool = FilterValidator::validateAttribute(attrName, matchFlag, values, depth); + 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 index 846e70b..d43c0b3 100755 --- a/src/platform/API/Messaging/StorageChangesConversationFilterValidator.h +++ b/src/platform/API/Messaging/StorageChangesConversationFilterValidator.h @@ -46,7 +46,7 @@ namespace TizenApis { Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0); virtual bool validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth=0); + Api::Tizen::AnyPtr& matchValue, int depth=0); diff --git a/src/platform/API/Messaging/StorageChangesConversationGenerator.cpp b/src/platform/API/Messaging/StorageChangesConversationGenerator.cpp index c30f8e7..cf4c110 100755 --- a/src/platform/API/Messaging/StorageChangesConversationGenerator.cpp +++ b/src/platform/API/Messaging/StorageChangesConversationGenerator.cpp @@ -249,34 +249,14 @@ namespace TizenApis { } void StorageChangesConversationGenerator::visitAttribute(std::string& attrName, - MatchFlag& matchFlag, AnyArrayPtr& values, int depth){ + MatchFlag& matchFlag, AnyPtr& matchValue, int depth){ LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]"); - LogDebug("values->size():" << values->size()); + if(matchValue == NULL) + return; - Api::Tizen::FilterType filterType = UNION_FILTER; + LogDebug("matchValue:" << matchValue->toString()); - if(matchFlag==Api::Tizen::MATCH_EXISTS){ - //TODO implement for EXIST - }else if(values->size() == 1){ - AnyPtr matchValue = values->at(0); - visitAttributeEach(attrName, matchFlag, matchValue, depth); - }else{ - visitPreComposite(filterType, depth); - - AnyArray::iterator iter; - for(iter=values->begin(); iter!= values->end(); iter++){ - - if(iter != values->begin()){ - - visitInComposite(filterType, depth); - } - - AnyPtr matchValue = *iter; - visitAttributeEach(attrName, matchFlag, matchValue, depth); - } - - visitPostComposite(filterType, depth); - } + visitAttributeEach(attrName, matchFlag, matchValue, depth); LogDebug(">>>"); } @@ -506,6 +486,9 @@ namespace TizenApis { time_t init_time, mid_time, end_time; struct tm retValue; + if(initialValue == NULL || endValue == NULL) + return; + if(attrName.compare("timestamp")==0){ retValue = convertToTimeFormat(initialValue->toString()); init_time = mktime(&retValue); @@ -539,7 +522,7 @@ namespace TizenApis { std::vector::iterator iter; bool result = FALSE; if(matchFlag == Api::Tizen::MATCH_EXACTLY){ - LogDebug("STRING_MATCH_EXCACTLY"); + LogDebug("STRING_MATCH_EXACTLY"); result = result || getMatchExactlyClause(valueString, value); }else if(matchFlag == Api::Tizen::MATCH_CONTAINS){ LogDebug("STRING_MATCH_CONTAINS"); diff --git a/src/platform/API/Messaging/StorageChangesConversationGenerator.h b/src/platform/API/Messaging/StorageChangesConversationGenerator.h index aa88075..cfc0d7c 100755 --- a/src/platform/API/Messaging/StorageChangesConversationGenerator.h +++ b/src/platform/API/Messaging/StorageChangesConversationGenerator.h @@ -54,7 +54,7 @@ namespace TizenApis { 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::AnyArrayPtr& values, int depth); + 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); diff --git a/src/platform/API/Messaging/StorageChangesFolderFilterValidator.cpp b/src/platform/API/Messaging/StorageChangesFolderFilterValidator.cpp index f1b4adf..60fe664 100755 --- a/src/platform/API/Messaging/StorageChangesFolderFilterValidator.cpp +++ b/src/platform/API/Messaging/StorageChangesFolderFilterValidator.cpp @@ -47,11 +47,14 @@ namespace TizenApis { } bool StorageChangesFolderFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth){ + Api::Tizen::AnyPtr& matchValue, int depth){ bool retBool = false; - retBool = FilterValidator::validateAttribute(attrName, matchFlag, values, depth); + 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 index bfb2b00..9acc6d3 100755 --- a/src/platform/API/Messaging/StorageChangesFolderFilterValidator.h +++ b/src/platform/API/Messaging/StorageChangesFolderFilterValidator.h @@ -46,7 +46,7 @@ namespace TizenApis { Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0); virtual bool validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth=0); + Api::Tizen::AnyPtr& matchValue, int depth=0); diff --git a/src/platform/API/Messaging/StorageChangesFolderGenerator.cpp b/src/platform/API/Messaging/StorageChangesFolderGenerator.cpp index d3e5c57..799c68a 100755 --- a/src/platform/API/Messaging/StorageChangesFolderGenerator.cpp +++ b/src/platform/API/Messaging/StorageChangesFolderGenerator.cpp @@ -37,7 +37,7 @@ namespace TizenApis { namespace Messaging { - const std::string StorageChangesFolderGenerator::STRING_MATCH_EXCACTLY = "EXACTLY"; + const std::string StorageChangesFolderGenerator::STRING_MATCH_EXACTLY = "EXACTLY"; const std::string StorageChangesFolderGenerator::STRING_MATCH_CONTAINS = "CONTAINS"; const std::string StorageChangesFolderGenerator::STRING_MATCH_STARTSWITH = "STARTSWITH"; const std::string StorageChangesFolderGenerator::STRING_MATCH_ENDSWITH = "ENDSWITH"; @@ -210,35 +210,15 @@ namespace TizenApis { } void StorageChangesFolderGenerator::visitAttribute(std::string& attrName, - Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyArrayPtr& values, int depth){ + Api::Tizen::MatchFlag& matchFlag, Api::Tizen::AnyPtr& matchValue, int depth){ LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]"); - LogDebug("values->size():" << values->size()); - Api::Tizen::FilterType filterType = UNION_FILTER; + if(matchValue == NULL) + return; - if(matchFlag == Api::Tizen::MATCH_EXISTS){ - //TODO implement for EXIST - }else if(values->size() == 1){ - AnyPtr matchValue = values->at(0); - visitAttributeEach(attrName, matchFlag, matchValue, depth); - }else{ - visitPreComposite(filterType, depth); - - AnyArray::iterator iter; - for(iter=values->begin(); iter!= values->end(); iter++){ - - if(iter != values->begin()){ - - visitInComposite(filterType, depth); - } - - AnyPtr matchValue = *iter; - visitAttributeEach(attrName, matchFlag, matchValue, depth); - } - - visitPostComposite(filterType, depth); - } - LogDebug(">>>"); + 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){ @@ -404,7 +384,7 @@ namespace TizenApis { std::vector::iterator iter; bool result = FALSE; if(matchFlag == Api::Tizen::MATCH_EXACTLY){ - LogDebug("STRING_MATCH_EXCACTLY"); + LogDebug("STRING_MATCH_EXACTLY"); result = result || getMatchExactlyClause(valueString, value); }else if(matchFlag == Api::Tizen::MATCH_CONTAINS){ LogDebug("STRING_MATCH_CONTAINS"); diff --git a/src/platform/API/Messaging/StorageChangesFolderGenerator.h b/src/platform/API/Messaging/StorageChangesFolderGenerator.h index cc2595c..c396cda 100755 --- a/src/platform/API/Messaging/StorageChangesFolderGenerator.h +++ b/src/platform/API/Messaging/StorageChangesFolderGenerator.h @@ -55,7 +55,7 @@ namespace TizenApis { 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::AnyArrayPtr& values, int depth); + 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(); @@ -91,7 +91,7 @@ namespace TizenApis { unsigned short m_type; bool m_synchronizable; - static const std::string STRING_MATCH_EXCACTLY; + 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; diff --git a/src/platform/API/Messaging/StorageChangesMessageFilterValidator.cpp b/src/platform/API/Messaging/StorageChangesMessageFilterValidator.cpp index 574e3b7..af63feb 100755 --- a/src/platform/API/Messaging/StorageChangesMessageFilterValidator.cpp +++ b/src/platform/API/Messaging/StorageChangesMessageFilterValidator.cpp @@ -53,10 +53,13 @@ namespace TizenApis { //TODO Implement bool StorageChangesMessageFilterValidator::validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth){ + Api::Tizen::AnyPtr& matchValue, int depth){ + if(matchValue == NULL) + return false; + bool retBool = false; - retBool = FilterValidator::validateAttribute(attrName, matchFlag, values, depth); + 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 index fb41d23..b150192 100755 --- a/src/platform/API/Messaging/StorageChangesMessageFilterValidator.h +++ b/src/platform/API/Messaging/StorageChangesMessageFilterValidator.h @@ -46,7 +46,7 @@ namespace TizenApis { Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth=0); virtual bool validateAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth=0); + Api::Tizen::AnyPtr& matchValue, int depth=0); diff --git a/src/platform/API/Messaging/StorageChangesMessageGenerator.cpp b/src/platform/API/Messaging/StorageChangesMessageGenerator.cpp index 37bd722..de8123d 100755 --- a/src/platform/API/Messaging/StorageChangesMessageGenerator.cpp +++ b/src/platform/API/Messaging/StorageChangesMessageGenerator.cpp @@ -344,34 +344,16 @@ namespace TizenApis { } void StorageChangesMessageGenerator::visitAttribute(std::string& attrName, - MatchFlag& matchFlag, Api::Tizen::AnyArrayPtr& values, int depth){ + MatchFlag& matchFlag, Api::Tizen::AnyPtr& matchValue, int depth){ LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]"); - LogDebug("values->size():" << values->size()); - Api::Tizen::FilterType filterType = UNION_FILTER; + if(matchValue == NULL) + return; + + LogDebug("matchValue:" << matchValue->toString()); + + visitAttributeEach(attrName, matchFlag, matchValue, depth); - if(matchFlag == Api::Tizen::MATCH_EXISTS){ - //TODO implement for EXIST - }else if(values->size() == 1){ - AnyPtr matchValue = values->at(0); - visitAttributeEach(attrName, matchFlag, matchValue, depth); - }else{ - visitPreComposite(filterType, depth); - - AnyArray::iterator iter; - for(iter=values->begin(); iter!= values->end(); iter++){ - - if(iter != values->begin()){ - - visitInComposite(filterType, depth); - } - - AnyPtr matchValue = *iter; - visitAttributeEach(attrName, matchFlag, matchValue, depth); - } - - visitPostComposite(filterType, depth); - } LogDebug(">>>"); } @@ -612,6 +594,9 @@ namespace TizenApis { struct tm endTime; bool result = FALSE; + if(initialValue == NULL || endValue == NULL) + return; + if(attrName.compare("timestamp")==0){ startTime = convertToTimeFormat(initialValue->toString()); endTime = convertToTimeFormat(endValue->toString()); @@ -632,7 +617,7 @@ namespace TizenApis { std::vector::iterator iter; bool result = FALSE; if(matchFlag == Api::Tizen::MATCH_EXACTLY){ - LogDebug("STRING_MATCH_EXCACTLY"); + LogDebug("STRING_MATCH_EXACTLY"); result = result || getMatchExactlyClause(valueString, value); }else if(matchFlag == Api::Tizen::MATCH_CONTAINS){ LogDebug("STRING_MATCH_CONTAINS"); diff --git a/src/platform/API/Messaging/StorageChangesMessageGenerator.h b/src/platform/API/Messaging/StorageChangesMessageGenerator.h index 78987d0..1ea3a5a 100755 --- a/src/platform/API/Messaging/StorageChangesMessageGenerator.h +++ b/src/platform/API/Messaging/StorageChangesMessageGenerator.h @@ -54,7 +54,7 @@ namespace TizenApis { 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::AnyArrayPtr& values, int depth); + 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(); diff --git a/src/platform/Tizen/Account/AccountService.cpp b/src/platform/Tizen/Account/AccountService.cpp deleted file mode 100755 index e596f63..0000000 --- a/src/platform/Tizen/Account/AccountService.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file Account.cpp - * @author Jihwa Park (jh7979.park@samsung.com) - * @author Sangtai Kim - * @version 0.1 - */ - -#include -#include - -#include "AccountManager.h" -#include "API/Account/OnAddEventsChanged.h" -#include "API/Account/OnUpdateEventsChanged.h" -#include "API/Account/OnDeleteEventsChanged.h" -#include "account-svc-db.h" -#include "AccountService.h" -using namespace TizenApis::Api::Account; -using namespace WrtDeviceApis::Commons; -//using namespace WrtDeviceApis::CommonsJavaScript; - -namespace TizenApis { -namespace Platform { -namespace Account{ - -AccountService::AccountService() -{ - LogDebug("entered"); -} - -AccountService::~AccountService() -{ - LogDebug("entered"); -} - -//TODO: implmeting Eventwrapper - - -void AccountService::OnRequestReceived(const IEventDeleteAccountPtr &account) -{ - LogDebug("entered"); -#if 1 - - Try - { - if (!account->getEvent()) { - ThrowMsg(NullPointerException, "event parameter is NULL"); - } - - //TODO: check if ID is valid - /* - if (!account->getEvent()->getIdIsSet()) { - ThrowMsg(Commons::InvalidArgumentException, - "Cannot delete non-existing event."); - } - */ - DPL::ScopedPtr accountWrapper(new AccountWrapper( - account->getEvent())); - accountWrapper->convertAbstractAccountToPlatformAccount(); - if (account->checkCancelled()) { - account->setCancelAllowed(true); - account->setResult(true); - return; - } - accountWrapper->deleteAccount(); - account->setResult(true); - } - catch (const NotFoundException &ex) - { - LogError("event doesn't exist"); - account->setResult(false); - account->setExceptionCode(ExceptionCodes::NotFoundException); - } - catch (const Exception &ex) - { - LogError("Error during deleting event " << ex.DumpToString()); - account->setResult(false); - } - account->setCancelAllowed(false); -#endif -} - -void AccountService::OnRequestReceived(const IEventUpdateAccountPtr &account) -{ - LogDebug("entered"); -#if 1 - - Try - { - if (!account->getEvent()) { - ThrowMsg(NullPointerException, "event parameter is NULL"); - } - /* if (!account->getEvent()->getIdIsSet()) { - ThrowMsg( - Commons::InvalidArgumentException, - "Cannot update non-existing event. Event needs adding or ID is wrong"); - }*/ - DPL::ScopedPtr accountWrapper(new AccountWrapper( - account->getEvent())); - accountWrapper->convertAbstractAccountToPlatformAccount(); - if (account->checkCancelled()) { - account->setCancelAllowed(true); - account->setResult(true); - return; - } - accountWrapper->saveAccount(); - account->setResult(true); - } - catch (const Exception &ex) - { - LogError("Error during updating event " << ex.DumpToString()); - account->setResult(false); - } - account->setCancelAllowed(false); -#endif -} - -void AccountService::OnRequestReceived(const IEventFindAccountsPtr &event) -{ - LogDebug("entered"); - - const AccountFilterPtr &filter = event->getFilter(); - char* handle = NULL; - int error_code = ACCOUNT_OPERATION_SUCCESS; - - try { - - if (NULL != filter) - { - if(filter->getIdIsSet()) { - std::istringstream istream(filter->getIdFilter()); - int id; - istream>>id; - LogDebug("id : " << id); - } - } - - if (ACCOUNT_OPERATION_SUCCESS != account_svc_new(ACCOUNT_CATEGORY, &handle)) { - ThrowMsg(PlatformException, "Can't create handle"); - } - if (ACCOUNT_OPERATION_SUCCESS != account_svc_get_account_list(handle, 0)) { - ThrowMsg(PlatformException, "Can't get all records"); - } - - while(error_code== ACCOUNT_OPERATION_SUCCESS) - { - event->tryCancelled(); - int accountId = account_svc_get_value_int(handle, ACCOUNT_ID, &error_code); - - if(error_code!=ACCOUNT_OPERATION_SUCCESS) { - ThrowMsg(PlatformException, "Can't get handle"); - } - - DPL::ScopedPtr accountWrapper(new AccountWrapper()); - accountWrapper->loadAccount(accountId); - event->addEvent(accountWrapper->getAbstractAccount()); - error_code = account_svc_get_next_val(handle); - } - event->setResult(true); - account_svc_get_finish(handle); - } - catch (const Exception &ex) - { - LogError("Exception: " << ex.DumpToString()); - event->setResult(false); - } - - event->setCancelAllowed(true); -} - -void AccountService::OnRequestReceived(const IEventCreateAccountPtr &event) -{ - LogDebug("entered"); -} - -void AccountService::OnRequestReceived(const IEventAddAccountPtr &account) -{ - LogDebug("entered"); - Try - { - if (!account->getEvent()) { - ThrowMsg(NullPointerException, "event parameter is NULL"); - } - /* if (account->getEvent()->getIdIsSet()) { - LogWarning("adding event that is already added"); - account->getEvent()->resetId(); - }*/ - DPL::ScopedPtr accountWrapper(new AccountWrapper( - account->getEvent())); - accountWrapper->convertAbstractAccountToPlatformAccount(); - if (account->checkCancelled()) { - account->setCancelAllowed(true); - account->setResult(true); - return; - } - accountWrapper->saveAccount(); - account->setResult(true); - } - catch (const Exception &ex) - { - LogError("Error during adding event" << ex.DumpToString()); - account->setResult(false); - } - account->setCancelAllowed(false); -} - -} -} -} diff --git a/src/platform/Tizen/Account/AccountService.h b/src/platform/Tizen/Account/AccountService.h deleted file mode 100755 index 0b63ff8..0000000 --- a/src/platform/Tizen/Account/AccountService.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file AccountService.h - * @author Jihwa Park (jh7979.park@samsung.com) - * @author Sangtai Kim - * @version 0.1 - */ - -#ifndef _TIZEN_ACCOUNT_H_ -#define _TIZEN_ACCOUNT_H_ - -#include -#include "API/Account/IAccountService.h" -#include "AccountWrapper.h" - -using namespace TizenApis::Api::Account; -//using namespace WrtDeviceApis::Commons; -//using namespace WrtDeviceApis::CommonsJavaScript; - -namespace TizenApis { -namespace Platform { -namespace Account{ -class AccountService : public IAccountService -{ - public: - AccountService(); - virtual ~AccountService(); - protected: - virtual void OnRequestReceived(const IEventDeleteAccountPtr &account); - virtual void OnRequestReceived(const IEventUpdateAccountPtr &account); - virtual void OnRequestReceived(const IEventFindAccountsPtr &account); - virtual void OnRequestReceived(const IEventCreateAccountPtr &account); - virtual void OnRequestReceived(const IEventAddAccountPtr &account); - -}; - -} -} -} -#endif diff --git a/src/platform/Tizen/Application/Application.cpp b/src/platform/Tizen/Application/Application.cpp index bcfe943..a9e5b50 100755 --- a/src/platform/Tizen/Application/Application.cpp +++ b/src/platform/Tizen/Application/Application.cpp @@ -41,104 +41,142 @@ using namespace WrtDeviceApis; using namespace WrtDeviceApis::Commons; using namespace Platform; +namespace { -namespace -{ - typedef struct { - char **result_str; - ail_prop_str_e type; - } convert_cb_context; + extern "C" int service_create_event(bundle *data, struct service_s **service); - ail_cb_ret_e convert_cb(const ail_appinfo_h appinfo, void *user_data) + // callback function to get package name. this callback is called from getPackageById() + static ail_cb_ret_e appinfoCallback(const ail_appinfo_h appinfo, void *user_data) { - convert_cb_context *foreach_cb_context = NULL; if (appinfo == NULL || user_data == NULL) { return AIL_CB_RET_CANCEL; } - - foreach_cb_context = (convert_cb_context *)user_data; - char* tmp_str = NULL; - if (ail_appinfo_get_str(appinfo, foreach_cb_context->type, &tmp_str) == AIL_ERROR_OK) { - *(foreach_cb_context->result_str) = strdup(tmp_str); - return AIL_CB_RET_CANCEL; - } else { + + 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; } - static char* id_to_pkg(const char* appId) + // get package name by id + static char* getPackageById(const char* appId) { ail_filter_h filter; ail_error_e ret; - char* result = NULL; + char* pkg = NULL; + + if (appId == NULL) { + return NULL; + } - LogDebug("[id_to_pkg] appId : "<setName(name); appinfo->setAppId(appid); appinfo->setIconPath(iconPath); - appinfo->setVersion(version); + appinfo->setVersion(version); + appinfo->setShow(show); event->addApplicationInformation(appinfo); if (name) @@ -163,74 +202,83 @@ namespace return true; } - static int app_manager_app_context_cb(const aul_app_info *ainfo, void *user_data) + static int runningAppListCallback(const aul_app_info *ainfo, void *user_data) { - //TBD : get package from appid. below code is temporal code. should be replaced. - //char *appid; - //appid = app_manager_get_appid(package, &appid); - char *appid = pkg_to_id(ainfo->pkg_name); - //char *appid = strdup(ainfo->pkg_name); - char contextid[PATH_MAX]; - snprintf(contextid, PATH_MAX, "%d", ainfo->pid); + char *appId; + char contextId[PATH_MAX]; + + if (user_data == NULL) { + return 0; + } - if(user_data != NULL){ - EventListInstalledApplications* event = (EventListInstalledApplications*)user_data; + appId = getIdFromPackage(ainfo->pkg_name); + snprintf(contextId, PATH_MAX, "%d", ainfo->pid); + + EventListInstalledApplications* event = (EventListInstalledApplications*)user_data; - ApplicationContextPtr appcontext(new ApplicationContext()); - appcontext->setAppId(appid); - appcontext->setContextId(contextid); + ApplicationContextPtr appContext(new ApplicationContext()); + appContext->setAppId(appId); + appContext->setContextId(contextId); - event->addApplicationContext(appcontext); - if (appid) - free(appid); - } + event->addApplicationContext(appContext); + + if (appId) + free(appId); + + return 0; } - static void app_manager_app_list_changed_cb(app_manger_event_type_e event_type,const char *package, void *user_data) + static void installedAppListChangedCallback(app_manger_event_type_e event_type,const char *package, void *user_data) { - LogDebug(">>> app_manager_app_list_changed_cb"); - if(user_data != NULL){ ((Application*)user_data)->InstalledApplicationChanged(event_type, package); } } - static void service_result_cb(service_h request, service_h reply, service_result_e result, void *user_data) + static void serviceResultCallback(service_h request, service_h reply, service_result_e result, void *user_data) { - if(user_data != NULL){ + if(user_data != NULL) { ((Application*)user_data)->launchServiceManualAnswer(request, reply, result); } } - static bool service_extra_data_cb(service_h service, const char *key, void* user_data) + static bool serviceExtraDataCallback(service_h service, const char *key, void* user_data) { EventLaunchService* event = (EventLaunchService*)user_data; - LogDebug(">>>service_extra_data_cb, key = "<>>serviceExtraDataCallback, key = "< *list = (std::map*)user_data; + if (package == NULL) { + return true; + } + + char *appid = getIdFromPackage(package); + list->insert(std::pair(package, appid)); + + if (appid) + free(appid); + + return true; + } } Application::Application() : m_initialized(false) { + } Application::~Application() { + } void Application::launch(const EventManageApplicationPtr& event) @@ -308,16 +373,13 @@ void Application::kill(const EventManageApplicationPtr& event) void Application::exit() { + // should be changed to event raise app_efl_exit(); } -void Application::hide(const EventManageApplicationPtr& event) +void Application::hide() { - if (m_initialized == false) { - initialize(); - } - - EventRequestReceiver::PostRequest(event); + // hide application call } void Application::listApplications(const EventListInstalledApplicationsPtr& event) @@ -340,68 +402,64 @@ void Application::getApplication(const EventGetApplicationPtr& event) long Application::addApplicationInformationEventListener(const EventInstalledApplicationChangedEmitterPtr& emitter) { - if(m_installedApplicationsEmitterPtr != NULL) - { + if(m_installedApplicationsEmitterPtr != NULL) { LogWarning("listener is already added"); return 0; } + m_installedApplicationsEmitterPtr = emitter; - int result = app_manager_set_app_list_changed_cb(app_manager_app_list_changed_cb, this ); - if ( result == APP_MANAGER_ERROR_NONE) - { - LogWarning("application list listener is set successfully."); - } - else if( result == APP_MANAGER_ERROR_INVALID_PARAMETER ) - { + int result = app_manager_set_app_list_changed_cb(installedAppListChangedCallback, this ); + if ( result == APP_MANAGER_ERROR_NONE) { + // TODO: below code is tempral. if FW can return appid, then use that. + if (m_installedApplicationList.empty()) { + app_manager_foreach_app_installed(getIdCallback, &m_installedApplicationList); + } + + } else if( result == APP_MANAGER_ERROR_INVALID_PARAMETER ) { LogWarning("app_manager_set_app_list_changed_cb() returns APP_MANAGER_ERROR_INVALID_PARAMETER"); EventInstalledApplicationChangedPtr event(new EventInstalledApplicationChanged()); event->setExceptionCode(ExceptionCodes::InvalidArgumentException); m_installedApplicationsEmitterPtr->emit(event); } + return m_installedApplicationsEmitterPtr->getId(); - } void Application::removeApplicationInformationEventListener(const EventInstalledApplicationChangedEmitter::IdType id) { - if(m_installedApplicationsEmitterPtr) - { - if(m_installedApplicationsEmitterPtr->getId() == id) - { + if(m_installedApplicationsEmitterPtr) { + if(m_installedApplicationsEmitterPtr->getId() == id) { LogWarning("id matched"); m_installedApplicationsEmitterPtr = EventInstalledApplicationChangedEmitterPtr(NULL); + // TODO: below code is tempral. if FW can return appid, then remove this + if (!m_installedApplicationList.empty()) { + m_installedApplicationList.clear(); + } app_manager_unset_app_list_changed_cb(); - } - else + } else { LogInfo("id does not match with listener"); + Throw(WrtDeviceApis::Commons::NotFoundException); + } } } void Application::launchService(const EventLaunchServicePtr& event) { - LogDebug("<<<"); - if (m_initialized == false) { initialize(); } EventRequestReceiver::PostRequest(event); - - LogDebug(">>>"); } void Application::getApplicationService(const EventLaunchServicePtr& event) { - LogDebug("<<<"); - if (m_initialized == false) { initialize(); } EventRequestReceiver::PostRequest(event); - - LogDebug(">>>"); } @@ -410,20 +468,27 @@ void Application::InstalledApplicationChanged(app_manger_event_type_e event_type char *name = NULL; char *iconPath = NULL; char *version = NULL; - LogDebug(">>> InstalledApplicationChanged : package : " << package); - char *appid = pkg_to_id(package); - LogDebug(">>> InstalledApplicationChanged : appid : " << appid); + char *appid = getIdFromPackage(package); + bool show = getShowFromPackage(package); if (appid == NULL) { - appid = strdup(package); + // get appid from installed application list. if cannot found, duplicate package to appid + const char* id = m_installedApplicationList[package].c_str(); + if (id != NULL) { + appid = strdup(id); + LogDebug(">>> InstalledApplicationChanged : (from List)appid : " << appid); + } else { + // set package if cannot found appid from DB and installed application list + appid = strdup(package); + LogDebug(">>> InstalledApplicationChanged : (copy package)appid : " << appid); + } } EventInstalledApplicationChangedPtr event(new EventInstalledApplicationChanged()); ApplicationInformationPtr appinfo(new ApplicationInformation()); appinfo->setAppId(appid); - if(event_type != APP_MANAGER_EVENT_UNINSTALLED) - { + if(event_type != APP_MANAGER_EVENT_UNINSTALLED) { app_manager_get_app_name(package, &name); app_manager_get_app_icon_path(package, &iconPath); app_manager_get_app_version(package, &version); @@ -431,377 +496,423 @@ void Application::InstalledApplicationChanged(app_manger_event_type_e event_type appinfo->setName(name); appinfo->setIconPath(iconPath); appinfo->setVersion(version); + appinfo->setShow(show); + } + + switch (event_type) { + case APP_MANAGER_EVENT_INSTALLED: + m_installedApplicationList[package] = appid; + event->setEventCode(EventInstalledApplicationChanged::APPLICATON_CHANGED_EVENT_CODE_INSTALLED); + LogDebug("APP_MANAGER_EVENT_INSTALLED, package name : "<setEventCode(EventInstalledApplicationChanged::APPLICATON_CHANGED_EVENT_CODE_UNINSTALLED); + LogDebug("APP_MANAGER_EVENT_UNINSTALLED, package name : "<setEventCode(EventInstalledApplicationChanged::APPLICATON_CHANGED_EVENT_CODE_UPDATED); + LogDebug("APP_MANAGER_EVENT_UPDATED, package name : "<setExceptionCode(ExceptionCodes::InvalidArgumentException); + break; } - if(event_type == APP_MANAGER_EVENT_INSTALLED) - { - event->setEventCode(APPLICATON_EVENT_CODE_INSTALLED); - LogDebug("event : APP_MANAGER_EVENT_INSTALLED, package name : "<setEventCode(APPLICATON_EVENT_CODE_UNINSTALLED); - LogDebug("event : APP_MANAGER_EVENT_UNINSTALLED, package name : "<setEventCode(APPLICATON_EVENT_CODE_UPDATED); - LogDebug("event : APP_MANAGER_EVENT_UPDATED, package name : "<setApplicationInformation(appinfo); m_installedApplicationsEmitterPtr->emit(event); - if(name != NULL ) + if(name != NULL) free(name); - if(iconPath != NULL ) + if(iconPath != NULL) free(iconPath); - if(version != NULL ) + if(version != NULL) free(version); - if(appid != NULL ) + if(appid != NULL) free(appid); - - LogDebug("<<>>launchServiceManualAnswer"); + if (m_eventLaunchServicePtr == NULL) { + return; + } - //EventLaunchServicePtr event(new EventLaunchService()); - - if(result == SERVICE_RESULT_SUCCEEDED) - { - // onsuccess - LogDebug("SERVICE_RESULT_SUCCEEDED in service_result_cb"); + if(result == SERVICE_RESULT_SUCCEEDED) { + LogDebug("SERVICE_RESULT_SUCCEEDED in serviceResultCallback"); - int result = service_foreach_extra_data(reply, service_extra_data_cb, m_eventLaunchServicePtr.Get()); - if( result == SERVICE_ERROR_NONE) - { + int result = service_foreach_extra_data(reply, serviceExtraDataCallback, m_eventLaunchServicePtr.Get()); + if( result == SERVICE_ERROR_NONE) { LogDebug("service_foreach_extra_data() success"); - } - else - { + m_eventLaunchServicePtr->setCallbackType(EventLaunchService::APPLICATION_SERVICE_REPLY_SUCCESS_CALLBACK); + } else { LogDebug("service_foreach_extra_data() failed"); + m_eventLaunchServicePtr->setCallbackType(EventLaunchService::APPLICATION_SERVICE_REPLY_FAIL_CALLBACK); } - - // FIXME : if reply service is failed, then we need call replyError callback - m_eventLaunchServicePtr->setCallbackType(EventLaunchService::APPLICATION_SERVICE_REPLY_SUCCESS_CALLBACK); - - } - else if(result == SERVICE_RESULT_FAILED || result == SERVICE_RESULT_CANCELED) - { - // onfail - LogDebug("SERVICE_RESULT_FAILED in service_result_cb"); + } else if(result == SERVICE_RESULT_FAILED || result == SERVICE_RESULT_CANCELED) { + LogDebug("SERVICE_RESULT_FAILED in serviceResultCallback : " <setCallbackType(EventLaunchService::APPLICATION_SERVICE_REPLY_FAIL_CALLBACK); } - // FIXME : if there is no callback , then we don't need to call ManualAnswer. - - WrtDeviceApis::Commons::EventRequestReceiver::ManualAnswer(m_eventLaunchServicePtr); - service_destroy(request); - -// EventRequestReceiver::ManualAnswer(event); - LogDebug("<<::ManualAnswer(m_eventLaunchServicePtr); } -void Application::OnRequestReceived(const Api::Application::EventListInstalledApplicationsPtr& event) -{ - if(event->getEventType() == EventListInstalledApplications::APPMANAGER_LIST_INSTALLED_APPLICATIONS) { - int result = app_manager_foreach_app_installed(app_manager_app_list_cb, event.Get()); - if( result != 0) - event->setExceptionCode(Commons::ExceptionCodes::PlatformException); - - } else if(event->getEventType() == EventListInstalledApplications::APPMANAGER_LIST_RUNNING_APPLICATIONS) { - int result = aul_app_get_running_app_info(app_manager_app_context_cb, event.Get()); - if( result != 0) - event->setExceptionCode(Commons::ExceptionCodes::PlatformException); - } else { - LogError("[ERROR] UNKNOWN EVENT TYPE"); - event->setExceptionCode(Commons::ExceptionCodes::UnknownException); - } -} -void Application::OnRequestReceived(const Api::Application::EventManageApplicationPtr& event) +void Application::OnRequestReceived(const EventManageApplicationPtr& event) { - if (event->getEventType() == EventManageApplication::APP_MANAGER_LAUNCH_APPLICATION) { - service_h service; - service_create(&service); + switch (event->getEventType()) { + case EventManageApplication::APP_MANAGER_LAUNCH_APPLICATION: { + service_h service; + service_create(&service); - std::string arg = event->getArgument(); - - if (!arg.empty()) { - service_set_operation(service, "slp.appsvc.operation.PAGE"); - service_set_uri(service, arg.c_str()); - } else { + /* caution. if default operation is changed, wrt should have to be modified too. */ service_set_operation(service, SERVICE_OPERATION_DEFAULT); - } + + std::string arg = event->getArgument(); + if (!arg.empty()) { + service_set_uri(service, arg.c_str()); + } - const char *appId = event->getAppId().c_str(); - if (appId == NULL) { - LogError("[ERROR] Can not get context id from context"); - event->setExceptionCode(Commons::ExceptionCodes::UnknownException); - } - char *package = id_to_pkg(appId); - service_set_package(service, package); - service_send_launch_request(service, NULL, this); + const char *appId = event->getAppId().c_str(); + if (appId == NULL) { + LogError("[ERROR] Can not get context id from context"); + event->setExceptionCode(Commons::ExceptionCodes::NotFoundException); + break; + } + char *package = getPackageById(appId); - service_destroy(service); - - if (package) - free(package); - - } else if (event->getEventType() == EventManageApplication::APP_MANAGER_KILL_APPLICATION) { - const char *contextId = event->getApplicationContext()->getContextId().c_str(); - if (contextId == NULL) { - LogError("[ERROR] Can not get context id from context"); - event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + if (package == NULL) { + event->setExceptionCode(Commons::ExceptionCodes::NotFoundException); + break; + } + + service_set_package(service, package); + if (service_send_launch_request(service, NULL, this) != SERVICE_ERROR_NONE) + { + // TODO: change launch fail exception --> and we have to call error callback. + event->setExceptionCode(Commons::ExceptionCodes::PlatformException); + } + + service_destroy(service); + + if (package) + free(package); + + break; } - - int pid = atoi(contextId); - int result = aul_terminate_pid(pid); - if (result < 0) { - LogError("[ERROR] Fail to terminate application with context"); - event->setExceptionCode(Commons::ExceptionCodes::UnknownException); - } - } else if (event->getEventType() == EventManageApplication::APP_MANAGER_HIDE_APPLICATION) { - LogError("[ERROR] Hide is not supported yet"); - event->setExceptionCode(Commons::ExceptionCodes::UnknownException); - } else { - LogError("[ERROR] UNKNOWN EVENT TYPE"); - event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + case EventManageApplication::APP_MANAGER_KILL_APPLICATION: { + const char *contextId = event->getApplicationContext()->getContextId().c_str(); + if (contextId == NULL) { + LogError("[ERROR] Can not get context id from context"); + event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException); + } + + int pid = atoi(contextId); + int result = aul_terminate_pid(pid); + if (result < 0) { + LogError("[ERROR] Fail to terminate application with context"); + if (result == AUL_R_EINVAL) { + event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException); + } else { + event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + } + } + break; + } + default: + LogError("[ERROR] UNKNOWN EVENT TYPE"); + event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + break; } } - -void Application::OnRequestReceived(const Api::Application::EventGetApplicationPtr& event) +void Application::OnRequestReceived(const EventGetApplicationPtr& event) { - if(event->getEventType() == EventGetApplication::APP_MANAGER_GET_INFORMATION) { - char *name = NULL; - char *iconPath = NULL; - char *version = NULL; - char *appId = NULL; - char *package = NULL; - - std::string strId = event->getAppId(); - if (strId.empty()) { - //char *tmpStr; - if (app_get_package(&package) != APP_ERROR_NONE) { - LogError("[ERROR] Can not get package name from current pid"); - event->setExceptionCode(Commons::ExceptionCodes::NotFoundException); + switch (event->getEventType()) { + case EventGetApplication::APP_MANAGER_GET_INFORMATION: { + char *name = NULL; + char *iconPath = NULL; + char *version = NULL; + char *appId = NULL; + char *package = NULL; + + std::string strId = event->getAppId(); + // in case of no argument, get application information of current. + if (strId.empty()) { + if (app_get_package(&package) == APP_ERROR_NONE) { + appId = getIdFromPackage(package); + } else { + LogError("[ERROR] Can not get package name from current pid"); + event->setExceptionCode(Commons::ExceptionCodes::NotFoundException); + } } else { - appId = pkg_to_id(package); - } - } else { - //TBD : get package from appid. below code is temporal code. should be replaced. - //package = strId.c_str(); - appId = strdup(strId.c_str()); - package = id_to_pkg(appId); - } - - ApplicationInformationPtr appinfo(new ApplicationInformation()); - LogInfo("AppID to get information : "<setExceptionCode(Commons::ExceptionCodes::NotFoundException); - } - else - { - if( app_manager_get_app_version(package, &version) <0) - { - LogWarning("can not get the version information of "<setName(name); - appinfo->setAppId(appId); - appinfo->setIconPath(iconPath); - appinfo->setVersion(version); - event->setApplicationInformation(appinfo); - } - LogError("Recheck!!! AppId : "<getAppId()); - - if(name) - free(name); - if(iconPath) - free(iconPath); - if(version) - free(version); - if(package) - free(package); - if (appId) - free(appId); - - } else if (event->getEventType() == EventGetApplication::APP_MANAGER_GET_CONTEXT) { - char *package; - char contextId[PATH_MAX]; - snprintf(contextId, PATH_MAX, "%d", getpid()); - - if (app_get_package(&package) != 0) { - LogError("[ERROR] Can not get package name from current pid"); - event->setExceptionCode(Commons::ExceptionCodes::NotFoundException); - } else { - char *appId = pkg_to_id(package); - ApplicationContextPtr appContext(new ApplicationContext()); - appContext->setAppId(appId); - appContext->setContextId(contextId); + ApplicationInformationPtr appinfo(new ApplicationInformation()); + if( app_manager_get_app_name(package, &name) < 0 || + app_manager_get_app_icon_path(package, &iconPath) < 0) { + LogError("can not get the information of "<setExceptionCode(Commons::ExceptionCodes::NotFoundException); + } else { + if(app_manager_get_app_version(package, &version) < 0) { + LogWarning("can not get the version information of "<setName(name); + appinfo->setAppId(appId); + appinfo->setIconPath(iconPath); + appinfo->setVersion(version); + appinfo->setShow(getShowFromPackage(package)); + event->setApplicationInformation(appinfo); + } - event->setApplicationContext(appContext); - - if (package) + if (name) + free(name); + if (iconPath) + free(iconPath); + if (version) + free(version); + if (package) free(package); if (appId) free(appId); + + break; } - } else { - LogError("[ERROR] UNKNOWN EVENT TYPE"); - event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + case EventGetApplication::APP_MANAGER_GET_CONTEXT: { + char *package; + char contextId[PATH_MAX]; + snprintf(contextId, PATH_MAX, "%d", getpid()); + + if (app_get_package(&package) != 0) { + LogError("[ERROR] Can not get package name from current pid"); + event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + } else { + char *appId = getIdFromPackage(package); + if (appId == NULL) { + LogError("[ERROR] Can not get package name from current pid"); + event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + break; + } + + ApplicationContextPtr appContext(new ApplicationContext()); + appContext->setAppId(appId); + appContext->setContextId(contextId); + + event->setApplicationContext(appContext); + + if (package) + free(package); + if (appId) + free(appId); + } + break; + } + default: + LogError("[ERROR] UNKNOWN EVENT TYPE"); + event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + break; } } -extern "C" int service_create_event(bundle *data, struct service_s **service); -void Application::OnRequestReceived(const Api::Application::EventLaunchServicePtr& event) +void Application::OnRequestReceived(const EventListInstalledApplicationsPtr& event) { - LogError("[enter] OnRequestReceived >>>"); - if (event->getEventType() == EventLaunchService::APPLICATION_SERVICE_GET_REQUEST) - { - // TODO: get bundle_str from wrt engine to get real request from caller. below bundle str is test code. - std::string bundle_str = "NQAAAAEEAAAUAAAAX19BUFBfU1ZDX09QX1RZUEVfXwARAAAAVEhJU19JU19PRVJBVElPTgAsAAAAAQQAABAAAABfX0FQUF9TVkNfVVJJX18ADAAAAFRISVNfSVNfVVJJADMAAAABBAAAFgAAAF9fQVBQX1NWQ19NSU1FX1RZUEVfXwANAAAAVEhJU19JU19NSU1FADUAAAABBAAAFQAAAF9fQVBQX1NWQ19QS0dfTkFNRV9fABAAAABUSElTX0lTX1BBQ0tBR0UAMgAAAAEEAAAQAAAARVhUUkFfREFUQV9LRVkxABIAAABFWFRSQV9EQVRBX1ZBTFVFMQAyAAAAAQQAABAAAABFWFRSQV9EQVRBX0tFWTIAEgAAAEVYVFJBX0RBVEFfVkFMVUUyAHoAAAABBQAAFgAAAEVYVFJBX0RBVEFfQVJSQVlfS0VZMQADAAAAGAAAABgAAAAYAAAARVhUUkFfREFUQV9BUlJBWV9WQUxVRTEARVhUUkFfREFUQV9BUlJBWV9WQUxVRTIARVhUUkFfREFUQV9BUlJBWV9WQUxVRTMA"; - service_h service; - - bundle *request_bundle = bundle_decode((bundle_raw*)bundle_str.c_str(), bundle_str.length()); - if (service_create_event(request_bundle, &service) != SERVICE_ERROR_NONE) - { - // throw exception. + switch (event->getEventType()) { + case EventListInstalledApplications::APPMANAGER_LIST_INSTALLED_APPLICATIONS: { + int result = app_manager_foreach_app_installed(installedAppListCallback, event.Get()); + if( result != 0) { + event->setExceptionCode(Commons::ExceptionCodes::PlatformException); + } + break; } + case EventListInstalledApplications::APPMANAGER_LIST_RUNNING_APPLICATIONS: { + int result = aul_app_get_running_app_info(runningAppListCallback, event.Get()); + if( result != 0) { + event->setExceptionCode(Commons::ExceptionCodes::PlatformException); + } + break; + } + default: + LogError("[ERROR] UNKNOWN EVENT TYPE"); + event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + break; + } +} - ApplicationServicePtr appService(new ApplicationService()); - char* str; - appService->setService_h(service); - - if (service_get_operation(service, &str) == SERVICE_ERROR_NONE) { - LogError("operation : "<setOperation(str); - free(str); +void Application::OnRequestReceived(const EventLaunchServicePtr& event) +{ + switch(event->getEventType()) { + case EventLaunchService::APPLICATION_SERVICE_GET_REQUEST: { + // TODO: get bundle_str from wrt engine to get real request from caller. below bundle str is test code. + std::string bundle_str = "NQAAAAEEAAAUAAAAX19BUFBfU1ZDX09QX1RZUEVfXwARAAAAVEhJU19JU19PRVJBVElPTgAsAAAAAQQAABAAAABfX0FQUF9TVkNfVVJJX18ADAAAAFRISVNfSVNfVVJJADMAAAABBAAAFgAAAF9fQVBQX1NWQ19NSU1FX1RZUEVfXwANAAAAVEhJU19JU19NSU1FADUAAAABBAAAFQAAAF9fQVBQX1NWQ19QS0dfTkFNRV9fABAAAABUSElTX0lTX1BBQ0tBR0UAMgAAAAEEAAAQAAAARVhUUkFfREFUQV9LRVkxABIAAABFWFRSQV9EQVRBX1ZBTFVFMQAyAAAAAQQAABAAAABFWFRSQV9EQVRBX0tFWTIAEgAAAEVYVFJBX0RBVEFfVkFMVUUyAHoAAAABBQAAFgAAAEVYVFJBX0RBVEFfQVJSQVlfS0VZMQADAAAAGAAAABgAAAAYAAAARVhUUkFfREFUQV9BUlJBWV9WQUxVRTEARVhUUkFfREFUQV9BUlJBWV9WQUxVRTIARVhUUkFfREFUQV9BUlJBWV9WQUxVRTMA"; + service_h service; + char* tmpStr = NULL; + + bundle *request_bundle = bundle_decode((bundle_raw*)bundle_str.c_str(), bundle_str.length()); + if (service_create_event(request_bundle, &service) != SERVICE_ERROR_NONE) + { + // TODO: find proper exception. + event->setExceptionCode(Commons::ExceptionCodes::UnknownException); } - } else { - LogError("fail to get operation"); - } - if (service_get_uri(service, &str) == SERVICE_ERROR_NONE) { - LogError("uri : "<setUri(str); - free(str); - } - } else { - LogError("fail to get uri"); - } - if (service_get_mime(service, &str) == SERVICE_ERROR_NONE) { - LogError("mime : "<setMime(str); - free(str); - } - } else { - LogError("fail to get mime"); - } - event->setService(appService); - if (service_foreach_extra_data(service, service_extra_data_cb, event.Get()) != SERVICE_ERROR_NONE) - { - LogError("service_foreach_extra_data fail"); - } - else - { - LogError("service_foreach_extra_data success"); + ApplicationServicePtr appService(new ApplicationService()); + appService->setService_h(service); + + if (service_get_operation(service, &tmpStr) == SERVICE_ERROR_NONE) { + LogInfo("operation : "<setOperation(tmpStr); + free(tmpStr); + tmpStr = NULL; + } + } + if (service_get_uri(service, &tmpStr) == SERVICE_ERROR_NONE) { + LogInfo("uri : "<setUri(tmpStr); + free(tmpStr); + tmpStr = NULL; + } + } + if (service_get_mime(service, &tmpStr) == SERVICE_ERROR_NONE) { + LogInfo("mime : "<setMime(tmpStr); + free(tmpStr); + tmpStr = NULL; + } + } + if (service_get_package(service, &tmpStr) == SERVICE_ERROR_NONE) { + LogInfo("package : "<setAppId(appId); + free(appId); + } + free(tmpStr); + } + } + + event->setService(appService); + if (service_foreach_extra_data(service, serviceExtraDataCallback, event.Get()) != SERVICE_ERROR_NONE) { + LogError("service_foreach_extra_data fail"); + event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + } else { + LogError("service_foreach_extra_data success"); + } + + break; } - } - else if (event->getEventType() == EventLaunchService::APPLICATION_SERVICE_LAUNCH) - { - LogDebug("<<<"); - m_eventLaunchServicePtr = event; - ApplicationServicePtr appservice= event->getService(); + case EventLaunchService::APPLICATION_SERVICE_LAUNCH: { + m_eventLaunchServicePtr = event; + ApplicationServicePtr appservice= event->getService(); - // from now on we will have to call answer manually - event->switchToManualAnswer(); + event->switchToManualAnswer(); - service_h service; - service_create(&service); - service_set_operation(service, appservice->getOperation().c_str() ); + service_h service; + service_create(&service); + if (appservice->getOperation().compare("") != 0) { + LogDebug("operation is "<getOperation()); + service_set_operation(service, appservice->getOperation().c_str() ); + } else { + LogDebug("Error. operation is madatory field. cannot be null"); + event->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException); + break; + } - if (appservice->getUri().compare("") != 0) - { - LogDebug("appservice.uri is not null"); - service_set_uri(service, appservice->getUri().c_str() ); - } + 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 "<getMime()); - service_set_mime(service, appservice->getMime().c_str() ); - } + if (appservice->getMime().compare("") != 0) { + LogDebug("mime is "<getMime()); + service_set_mime(service, appservice->getMime().c_str() ); + } - LogDebug(">>> appservice->getServiceDataArray"); - std::vector serviceDataArray = appservice->getServiceDataArray(); - - const char** arr = NULL; - const char* key = NULL; - if (!serviceDataArray.empty()) - { - LogDebug("serviceDataArray.size() : "<getKey().c_str(); - std::vector valueArray = serviceDataArray.at(i)->getValue(); - - arr = (const char**) calloc (sizeof(char*), valueArray.size()); + if (appservice->getAppId().compare("") != 0) { + LogDebug("appId is "<getAppId()); + char* pkg = getPackageById(appservice->getAppId().c_str()); + if (pkg != NULL) { + service_set_package(service, pkg); + free(pkg); + } + } + + LogDebug(">>> appservice->getServiceDataArray"); + std::vector serviceDataArray = appservice->getServiceDataArray(); + + if (!serviceDataArray.empty()) { + const char* key = NULL; + const char** arr = NULL; + LogDebug("serviceDataArray.size() : "<getKey().c_str(); + if (key == NULL) { + m_eventLaunchServicePtr->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException); + break; + } + std::vector valueArray = serviceDataArray.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, arr, size); - for (size_t j = 0; j < valueArray.size(); j++) { - arr[j] = valueArray.at(j).c_str(); + if (arr) + free(arr); } - service_add_extra_data_array(service, key, arr, valueArray.size()); } - } - int result = service_send_launch_request (service, service_result_cb , this); - - //TODO: free each items of arr - if (arr) - free(arr); - - switch (result){ - case SERVICE_ERROR_NONE : - LogDebug("service_send_launch_request successful"); - m_eventLaunchServicePtr->setCallbackType(EventLaunchService::APPLICATION_SERVICE_CALLBACK); - break; - case SERVICE_ERROR_INVALID_PARAMETER: - LogDebug("service_send_launch_request returns SERVICE_ERROR_INVALID_PARAMETER"); - m_eventLaunchServicePtr->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException); - break; - case SERVICE_ERROR_OUT_OF_MEMORY: - LogDebug("service_send_launch_request returns SERVICE_ERROR_OUT_OF_MEMORY"); - m_eventLaunchServicePtr->setExceptionCode(Commons::ExceptionCodes::PlatformException); - break; - case SERVICE_ERROR_APP_NOT_FOUND: - LogDebug("service_send_launch_request returns SERVICE_ERROR_APP_NOT_FOUND"); - m_eventLaunchServicePtr->setExceptionCode(Commons::ExceptionCodes::NotFoundException); - break; - default: - LogDebug("service_send_launch_request returns UNKNOWN ERROR!!!"); - m_eventLaunchServicePtr->setExceptionCode(Commons::ExceptionCodes::UnknownException); - break; + int result = service_send_launch_request (service, serviceResultCallback , this); + + service_destroy(service); + + switch (result) { + case SERVICE_ERROR_NONE: + LogDebug("service_send_launch_request successful"); + m_eventLaunchServicePtr->setCallbackType(EventLaunchService::APPLICATION_SERVICE_CALLBACK); + break; + case SERVICE_ERROR_INVALID_PARAMETER: + LogDebug("service_send_launch_request returns SERVICE_ERROR_INVALID_PARAMETER"); + // TODO: it can be return to error callback + m_eventLaunchServicePtr->setExceptionCode(Commons::ExceptionCodes::InvalidArgumentException); + break; + case SERVICE_ERROR_OUT_OF_MEMORY: + LogDebug("service_send_launch_request returns SERVICE_ERROR_OUT_OF_MEMORY"); + // TODO: it can be return to error callback + m_eventLaunchServicePtr->setExceptionCode(Commons::ExceptionCodes::PlatformException); + break; + case SERVICE_ERROR_APP_NOT_FOUND: + LogDebug("service_send_launch_request returns SERVICE_ERROR_APP_NOT_FOUND"); + // TODO: it can be return to error callback + m_eventLaunchServicePtr->setExceptionCode(Commons::ExceptionCodes::NotFoundException); + break; + default: + LogDebug("service_send_launch_request returns UNKNOWN ERROR!!!"); + m_eventLaunchServicePtr->setExceptionCode(Commons::ExceptionCodes::UnknownException); + break; + } + EventRequestReceiver::ManualAnswer(m_eventLaunchServicePtr); + + break; } - EventRequestReceiver::ManualAnswer(m_eventLaunchServicePtr); - LogDebug(">>>"); - } else { - LogError("[ERROR] UNKNOWN EVENT TYPE"); - event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + default: + LogError("[ERROR] UNKNOWN EVENT TYPE"); + event->setExceptionCode(Commons::ExceptionCodes::UnknownException); + break; } } diff --git a/src/platform/Tizen/Application/Application.h b/src/platform/Tizen/Application/Application.h index 1a175c1..230d2fa 100755 --- a/src/platform/Tizen/Application/Application.h +++ b/src/platform/Tizen/Application/Application.h @@ -28,7 +28,8 @@ #include #include -#include +#include + using namespace TizenApis::Api::Application; namespace TizenApis { @@ -44,7 +45,7 @@ public: virtual void launch(const EventManageApplicationPtr& event); virtual void kill(const EventManageApplicationPtr& event); virtual void exit(); - virtual void hide(const EventManageApplicationPtr& event); + virtual void hide(); virtual void listApplications(const EventListInstalledApplicationsPtr& event); virtual void getApplication(const EventGetApplicationPtr& event); virtual long addApplicationInformationEventListener(const EventInstalledApplicationChangedEmitterPtr& emitter); @@ -67,6 +68,8 @@ private: bool m_initialized; Api::Application::EventLaunchServicePtr m_eventLaunchServicePtr; EventInstalledApplicationChangedEmitterPtr m_installedApplicationsEmitterPtr; + std::map m_installedApplicationList; + }; } diff --git a/src/platform/Tizen/Bluetooth/BluetoothAdapterManager.cpp b/src/platform/Tizen/Bluetooth/BluetoothAdapterManager.cpp index d03c1a1..ca9542a 100644 --- a/src/platform/Tizen/Bluetooth/BluetoothAdapterManager.cpp +++ b/src/platform/Tizen/Bluetooth/BluetoothAdapterManager.cpp @@ -464,9 +464,15 @@ void BluetoothAdapterManager::serviceSearchManualAnswer(unsigned short error) { 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::UnknownException, "bt_adapter_foreach_bonded_device" << ret); + ThrowMsg(Commons::NotFoundException, "bt_adapter_foreach_bonded_device" << ret); } m_btGetDeviceEvent = false; @@ -583,7 +589,11 @@ void BluetoothAdapterManager::createBondingManualAnswer(unsigned short error, bt m_EventBTCreateDestroyBondingPtr->setExceptionCode(Commons::ExceptionCodes::None); m_EventBTCreateDestroyBondingPtr->setDevice(device); } - else + else if (error == BT_ERROR_REMOTE_DEVICE_NOT_FOUND) + { + m_EventBTCreateDestroyBondingPtr->setExceptionCode(Commons::ExceptionCodes::NotFoundException); + } + else { m_EventBTCreateDestroyBondingPtr->setExceptionCode(Commons::ExceptionCodes::UnknownException); } @@ -605,6 +615,10 @@ void BluetoothAdapterManager::destroyBondingManualAnswer(unsigned short error) { 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); diff --git a/src/platform/Tizen/Bluetooth/BluetoothDeviceManager.cpp b/src/platform/Tizen/Bluetooth/BluetoothDeviceManager.cpp index d9df686..8ec6e21 100644 --- a/src/platform/Tizen/Bluetooth/BluetoothDeviceManager.cpp +++ b/src/platform/Tizen/Bluetooth/BluetoothDeviceManager.cpp @@ -201,17 +201,20 @@ void BluetoothDeviceManager::serviceSearchManualAnswer(unsigned short error) try { + if (error != BT_ERROR_NONE) + { + ThrowMsg(Commons::NotFoundException, "service search error"); + } + if (bt_socket_set_connection_state_changed_cb( capi_callback_bt_socket_connection_state_changed, this) != BT_ERROR_NONE) { - error = Commons::ExceptionCodes::UnknownException; ThrowMsg(Commons::UnknownException, "service call back set error"); } if (bt_socket_connect_rfcomm(socketData.peerDevice.address.data(), socketData.uuid.data()) != BT_ERROR_NONE) { - error = Commons::ExceptionCodes::UnknownException; ThrowMsg(Commons::UnknownException, "connect error"); } LogDebug("Service search OK, try to connect"); diff --git a/src/platform/Tizen/Calendar/Calendar.cpp b/src/platform/Tizen/Calendar/Calendar.cpp index 3cda9a6..3d23af0 100755 --- a/src/platform/Tizen/Calendar/Calendar.cpp +++ b/src/platform/Tizen/Calendar/Calendar.cpp @@ -473,6 +473,9 @@ void Calendar::OnRequestReceived(const IEventFindEventsPtr &event) TizenApis::Api::Tizen::IFilterVisitorPtr filterTraversal = DPL::StaticPointerCast(calendarFilter); + std::stringstream ssType; + std::stringstream ssAccount; + ssAccount<getGenericFilterIsSet()) { TizenApis::Api::Tizen::FilterPtr genericFilter = event->getGenericFilter(); @@ -487,9 +490,23 @@ void Calendar::OnRequestReceived(const IEventFindEventsPtr &event) genericFilter->travel(filterTraversal, 0); LogDebug("Traverse string [" << calendarFilter->getResult() << "]"); query.append(calendarFilter->getResult()); - query.append(" AND is_deleted = 0;"); + query.append(std::string(" AND ") + CAL_VALUE_INT_ACCOUNT_ID + " = " + ssAccount.str()); + if (getType()==CalendarEvent::TASK_TYPE) { + ssType<getSortModesIsSet()) { diff --git a/src/platform/Tizen/Calendar/CalendarFilter.cpp b/src/platform/Tizen/Calendar/CalendarFilter.cpp index cc49827..3123eee 100755 --- a/src/platform/Tizen/Calendar/CalendarFilter.cpp +++ b/src/platform/Tizen/Calendar/CalendarFilter.cpp @@ -91,57 +91,52 @@ void CalendarFilter::visitPostComposite(TizenApis::Api::Tizen::FilterType& type, m_query.append(" )"); } -void CalendarFilter::visitAttribute(std::string& attrName, TizenApis::Api::Tizen::MatchFlag& matchFlag, TizenApis::Api::Tizen::AnyArrayPtr& matchValues, int depth) +void CalendarFilter::visitAttribute(std::string& attrName, TizenApis::Api::Tizen::MatchFlag& matchFlag, TizenApis::Api::Tizen::AnyPtr& matchValue, int depth) { - LogDebug("attrName: "<size()<<", matchFlag: "<toString()<<", matchFlag: "<begin(); iter != matchValues->end(); iter++) - { - TizenApis::Api::Tizen::AnyPtr matchValue = *iter; - if(iter != matchValues->begin()) - conditionQuery.append("OR"); - - if(matchValue->getType() == TizenApis::Api::Tizen::PrimitiveType_Time) - { - tm date = matchValue->getDateTm(); - std::stringstream time; - time << mktime(&date); - valueString = time.str(); - } - else - { - valueString = matchValue->toString(); - } + if(matchValue->isType(TizenApis::Api::Tizen::PrimitiveType_Time)) + { + tm date = matchValue->getDateTm(); + std::stringstream time; + time << mktime(&date); + valueString = time.str(); + } + else + { + valueString = matchValue->toString(); + } - if(attrName=="visibility" || attrName=="status" || attrName=="priority" || attrName=="availability") { - valueString = convertStringToValue(attrName, valueString); - } + if(attrName=="visibility" || attrName=="status" || attrName=="priority" || attrName=="availability") { + valueString = convertStringToValue(attrName, valueString); + } - if( matchFlag==TizenApis::Api::Tizen::MATCH_EXACTLY ) { - matchString = " like \'" + valueString + "\'"; - } else if( matchFlag==TizenApis::Api::Tizen::MATCH_CONTAINS) { - matchString = " like \'%" + valueString + "%\'"; - } else if( matchFlag==TizenApis::Api::Tizen::MATCH_STARTSWITH) { - matchString = " like \'%" + valueString + "\'"; - } else if( matchFlag==TizenApis::Api::Tizen::MATCH_ENDSWITH) { - matchString = " like \'" + valueString + "%\'"; - }else if( matchFlag==TizenApis::Api::Tizen::MATCH_EXISTS) { - matchString = " is not null"; - } else { - LogError("Invalid matchFlag!"); - matchString = " is not null"; - } + if( matchFlag==TizenApis::Api::Tizen::MATCH_EXACTLY ) { + matchString = " = \'" + valueString + "\'"; // case-sensitive + } else if( matchFlag==TizenApis::Api::Tizen::MATCH_FULLSTRING ) { + matchString = " like \'" + valueString + "\'"; // case-insensitive + } else if( matchFlag==TizenApis::Api::Tizen::MATCH_CONTAINS) { + matchString = " like \'%" + valueString + "%\'"; + } else if( matchFlag==TizenApis::Api::Tizen::MATCH_STARTSWITH) { + matchString = " like \'%" + valueString + "\'"; + } else if( matchFlag==TizenApis::Api::Tizen::MATCH_ENDSWITH) { + matchString = " like \'" + valueString + "%\'"; + }else if( matchFlag==TizenApis::Api::Tizen::MATCH_EXISTS) { + matchString = " is not null"; + } else { + LogError("Invalid matchFlag!"); + matchString = " is not null"; + } - // If the attrName is not directly mapped, branch here. - conditionQuery.append(" (" + m_attributeMap[attrName] + matchString + ") "); - } - conditionQuery.append(")"); + // If the attrName is not directly mapped, branch here. + conditionQuery.append(" (" + m_attributeMap[attrName] + matchString + ") "); LogInfo("Generated condition query: [" << conditionQuery << "]"); @@ -150,12 +145,15 @@ void CalendarFilter::visitAttribute(std::string& attrName, TizenApis::Api::Tizen void CalendarFilter::visitAttributeRange(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& initialValue, TizenApis::Api::Tizen::AnyPtr& endValue, int depth) { + if(initialValue == NULL || endValue == NULL) + return; + LogDebug("attrName: " <toString()<<", endValue: " <toString()<<", depth: "<isNullOrUndefined()) { if( TizenApis::Api::Tizen::PrimitiveType_Time==initialValue->getType() ) { tm date = initialValue->getDateTm(); std::stringstream time; @@ -166,7 +164,7 @@ void CalendarFilter::visitAttributeRange(std::string& attrName, TizenApis::Api:: } } - if (endValue != NULL) { + if (!endValue->isNullOrUndefined()) { if( TizenApis::Api::Tizen::PrimitiveType_Time==endValue->getType() ) { tm date = endValue->getDateTm(); std::stringstream time; @@ -177,11 +175,11 @@ void CalendarFilter::visitAttributeRange(std::string& attrName, TizenApis::Api:: } } - if (initialValue!=NULL && endValue==NULL ) { + if (!initialValue->isNullOrUndefined() && endValue->isNullOrUndefined() ) { conditionQuery = " " + m_attributeMap[attrName] + ">" + initialValueStr + " "; - } else if (initialValue==NULL && endValue!=NULL ) { + } else if (initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined() ) { conditionQuery = " " + m_attributeMap[attrName] + "<" + endValueStr + " "; - } else if (initialValue!=NULL && endValue!=NULL ) { + } else if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined() ) { conditionQuery = " " + m_attributeMap[attrName] + ">" + initialValueStr + " AND " + m_attributeMap[attrName] + "<" + endValueStr + " "; } diff --git a/src/platform/Tizen/Calendar/CalendarFilter.h b/src/platform/Tizen/Calendar/CalendarFilter.h index 29fa483..346bf7b 100755 --- a/src/platform/Tizen/Calendar/CalendarFilter.h +++ b/src/platform/Tizen/Calendar/CalendarFilter.h @@ -76,7 +76,7 @@ public: virtual void visitAttribute(std::string& attrName, TizenApis::Api::Tizen::MatchFlag& matchFlag, - TizenApis::Api::Tizen::AnyArrayPtr& matchValues, + TizenApis::Api::Tizen::AnyPtr& matchValue, int depth); virtual void visitAttributeRange(std::string& attrName, diff --git a/src/platform/Tizen/Calendar/EventWrapper.cpp b/src/platform/Tizen/Calendar/EventWrapper.cpp index 2651a45..4295af9 100755 --- a/src/platform/Tizen/Calendar/EventWrapper.cpp +++ b/src/platform/Tizen/Calendar/EventWrapper.cpp @@ -1188,10 +1188,10 @@ void EventWrapper::setAttendeesToPlatformEvent() ThrowMsg(PlatformException, "Cannot set attendee delegate uri"); } - // save uid + // save contactId only if (CAL_SUCCESS != calendar_svc_value_set_str(attendee, CAL_VALUE_TXT_ATTENDEE_UID, - attendeeList->at(i)->getPersonId().c_str())) { + attendeeList->at(i)->getContactId().c_str())) { LogError("error during setting attendee uid"); calendar_svc_value_free(&attendee); ThrowMsg(PlatformException, "Cannot set attendee uid"); @@ -1951,13 +1951,13 @@ void EventWrapper::setAttendeesFromPlatformEvent() } attendeePtr->setDelegateURI(attendeeDelegateURI); - // load uid - char* attendeeUId = calendar_svc_value_get_str(attendee, CAL_VALUE_TXT_ATTENDEE_UID); - if (NULL == attendeeUId) { + // load contactId + char* attendeeContactId = calendar_svc_value_get_str(attendee, CAL_VALUE_TXT_ATTENDEE_UID); + if (NULL == attendeeContactId) { LogError("cannot read attendee UId"); return; } - attendeePtr->setPersonId(attendeeUId); + attendeePtr->setContactId(attendeeContactId); m_abstractEvent->getAttendees()->push_back(attendeePtr); } diff --git a/src/platform/Tizen/Call/CallHistoryFilter.cpp b/src/platform/Tizen/Call/CallHistoryFilter.cpp index 46ea04a..a15a5db 100755 --- a/src/platform/Tizen/Call/CallHistoryFilter.cpp +++ b/src/platform/Tizen/Call/CallHistoryFilter.cpp @@ -83,26 +83,24 @@ void CallHistoryFilter::visitPostComposite(FilterType& type, int depth) m_query = m_query + STR_RIGHT_BRACKET; } -void CallHistoryFilter::visitAttribute(std::string& attrName, MatchFlag& matchFlag, Api::Tizen::AnyArrayPtr& values, int depth) +void CallHistoryFilter::visitAttribute(std::string& attrName, MatchFlag& matchFlag, Api::Tizen::AnyPtr& matchValue, int depth) { std::string str (""); - if (values == NULL) { + if (matchValue == NULL) { return; } - if (values->size() == 1) { - AnyPtr value = values->at(0); - str.append(convertAttribute(attrName, value)); - } else if (values->size() > 1) { - str.append(convertAttributeArray(attrName, values)); - } + str.append(convertAttribute(attrName, matchValue)); m_query = m_query + str; } void CallHistoryFilter::visitAttributeRange(std::string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth) { + if(initialValue == NULL || endValue == NULL) + return; + string str (""); string name (""); string initialValueStr (""); @@ -120,7 +118,7 @@ void CallHistoryFilter::visitAttributeRange(std::string& attrName, AnyPtr& initi name = attrName; } - if (initialValue != NULL) { + if (!initialValue->isNullOrUndefined()) { if(initialValue->getType() == PrimitiveType_Time) { tm date = initialValue->getDateTm(); std::stringstream time; @@ -131,7 +129,7 @@ void CallHistoryFilter::visitAttributeRange(std::string& attrName, AnyPtr& initi } } - if (endValue != NULL) { + if (!endValue->isNullOrUndefined()) { if(endValue->getType() == PrimitiveType_Time) { tm date = endValue->getDateTm(); std::stringstream time; @@ -143,11 +141,11 @@ void CallHistoryFilter::visitAttributeRange(std::string& attrName, AnyPtr& initi } } - if (initialValue != NULL && endValue == NULL) { + if (!initialValue->isNullOrUndefined() && endValue->isNullOrUndefined()) { str = STR_LEFT_BRACKET + name + STR_GREATER_THAN + STR_EQUAL + STR_S_QUOTATION + initialValueStr + STR_S_QUOTATION + STR_RIGHT_BRACKET; - } else if (initialValue == NULL && endValue != NULL) { + } else if (initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) { str = STR_LEFT_BRACKET + name + STR_LESS_THAN + STR_S_QUOTATION + endValueStr + STR_S_QUOTATION + STR_RIGHT_BRACKET; - } else if (initialValue != NULL && endValue != NULL) { + } else if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) { str = STR_LEFT_BRACKET + name + STR_GREATER_THAN + STR_EQUAL + STR_S_QUOTATION + initialValueStr + STR_S_QUOTATION + STR_AND + name + STR_LESS_THAN + STR_S_QUOTATION + endValueStr + STR_S_QUOTATION + STR_RIGHT_BRACKET; } diff --git a/src/platform/Tizen/Call/CallHistoryFilter.h b/src/platform/Tizen/Call/CallHistoryFilter.h index d05c83a..0dd2e8a 100755 --- a/src/platform/Tizen/Call/CallHistoryFilter.h +++ b/src/platform/Tizen/Call/CallHistoryFilter.h @@ -63,7 +63,7 @@ public: void visitAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, + Api::Tizen::AnyPtr& matchValue, int depth); void visitAttributeRange(std::string& attrName, diff --git a/src/platform/Tizen/Contact/AddressBook.cpp b/src/platform/Tizen/Contact/AddressBook.cpp index d34db95..95f6685 100755 --- a/src/platform/Tizen/Contact/AddressBook.cpp +++ b/src/platform/Tizen/Contact/AddressBook.cpp @@ -32,11 +32,12 @@ #include #include #include -#include +#include #include "AddressBook.h" #include "ContactWrapper.h" #include "ContactSearchEngine.h" #include "ContactFilterValidator.h" +#include "DownloadManager.h" namespace TizenApis { namespace Platform { @@ -47,81 +48,50 @@ using namespace TizenApis::Api::Tizen; using namespace WrtDeviceApis::Commons; using namespace std; -using TizenApis::Api::Contact::Contact; - AddressBook::AddressBook(IAddressBook::AddressBookType changeType) : IAddressBook(changeType), m_name("TEST_ADDRESS_BOOK") { LogDebug("entered"); - setDaClientIdByDaInit(); } AddressBook::~AddressBook() { } -ContactPropertiesPtr AddressBook::convertFromString(const string &vObjectStr, const string &format) +ContactPtr AddressBook::get(const std::string &contactId) { - const void *vcard_stream = vObjectStr.c_str(); - CTSstruct* cts; - - if(format != "VCARD_30") - ThrowMsg(UnsupportedException, "Only support vCard 3.0."); - - int ret = contacts_svc_get_contact_from_vcard(vcard_stream, &cts); - if(CTS_SUCCESS != ret) - ThrowMsg(PlatformException, "Fail to convert contact from vCard."); - - ContactWrapperPtr contactWrapper(new ContactWrapper(m_bookType)); - Try { - contactWrapper->setPlatformContact(cts); - } Catch (PlatformException) { - ThrowMsg(PlatformException, "Fail to extract contact from platform object."); - } - - return DPL::StaticPointerCast(contactWrapper->getAbstractContact()); -} - -string AddressBook::convertToString(const ContactPtr &contact, const string &format) -{ - char *vcard_stream = NULL; + LogDebug("entered"); + if(contactId == "") + ThrowMsg(InvalidArgumentException, "contactId argument is wrong"); - if(format != "VCARD_30") - ThrowMsg(UnsupportedException, "Only support vCard 3.0."); + ContactSearchEnginePtr searchEngine(new ContactSearchEngine(ContactSearchEngine::CONTACT_QUERY)); - ContactWrapperPtr contactWrapper(new ContactWrapper(m_bookType)); - Try { - contactWrapper->setAbstractContact(contact, true); - } Catch (PlatformException) { - ThrowMsg(PlatformException, "Fail to extract contact to platform object."); - } - int ret = contacts_svc_get_vcard_from_contact(contactWrapper->getPlatformContact(), &vcard_stream); - if(ret != CTS_SUCCESS) - ThrowMsg(PlatformException, "Fail to convert to vCard."); + searchEngine->setCondition(contactId); + searchEngine->setAttributeOfInterest(); + searchEngine->setSortMode(); - string result((char *)vcard_stream); + ContactArrayPtr contacts = searchEngine->getContactSearchResult(); - free(vcard_stream); + if(contacts->size() == 0) + ThrowMsg(NotFoundException, "No contact with ID:" << contactId); - return result; + return contacts->at(0); } -ContactPtr AddressBook::add(const ContactPropertiesPtr &contactProperties) +void AddressBook::add(const ContactPtr &contact) { - ContactPtr contact(new Contact(*contactProperties)); - + LogDebug("entered"); if(!contact) - ThrowMsg(InvalidArgumentException, "ContactProperties argument is wrong"); + ThrowMsg(InvalidArgumentException, "Contact argument is wrong"); internalAddContact(contact); m_latestVersion = get_contact_version(); - - return contact; } void AddressBook::update(const ContactPtr &contact) { + LogDebug("entered"); if(!contact) ThrowMsg(InvalidArgumentException, "Contact argument is wrong"); @@ -131,6 +101,7 @@ void AddressBook::update(const ContactPtr &contact) void AddressBook::remove(const string &id) { + LogDebug("entered"); int contactId; try { @@ -188,14 +159,14 @@ void AddressBook::removeChangeListener(const long watchId) void AddressBook::OnRequestReceived(const EventAddressBookAddBatchPtr &event) { LogDebug("entered"); + ContactArrayPtr contacts(NULL); - ContactPropertiesArrayPtr contactProperties(NULL); Try { - if(!event->getContactPropertiesIsSet()) + if(!event->getContactsIsSet()) ThrowMsg(InvalidArgumentException, "Contacts were not set."); - contactProperties = event->getContactProperties(); - if(!contactProperties) + contacts = event->getContacts(); + if(!contacts) ThrowMsg(InvalidArgumentException, "No contacts."); } Catch(InvalidArgumentException) { @@ -207,27 +178,23 @@ void AddressBook::OnRequestReceived(const EventAddressBookAddBatchPtr &event) Try { - ContactArrayPtr contacts(new ContactArray()); int ret = contacts_svc_begin_trans(); if (ret < 0) { LogError("error code " << ret); ThrowMsg(PlatformException, "Error during executing contacts_svc_begin_trans()"); } - for(ContactPropertiesArray::iterator i = contactProperties->begin(); i != contactProperties->end(); i++) + for(ContactArray::iterator i = contacts->begin(); i != contacts->end(); i++) { - ContactPtr contact(new Contact(*(*i))); + ContactPtr contact = *i; internalAddContact(contact); - - contacts->push_back(contact); } contacts_svc_end_trans(true); if (ret < 0) { LogError("error code " << ret); ThrowMsg(PlatformException, "Error during executing contacts_svc_end_trans()"); } - event->setContacts(contacts); } Catch (NotFoundException) { @@ -253,7 +220,6 @@ void AddressBook::OnRequestReceived(const EventAddressBookAddBatchPtr &event) void AddressBook::OnRequestReceived(const EventAddressBookUpdateBatchPtr &event) { LogDebug("entered"); - ContactArrayPtr contacts(NULL); Try { @@ -316,7 +282,6 @@ void AddressBook::OnRequestReceived(const EventAddressBookUpdateBatchPtr &event) void AddressBook::OnRequestReceived(const EventAddressBookRemoveBatchPtr &event) { LogDebug("entered"); - StringArrayPtr contactIds(NULL); Try { @@ -393,6 +358,7 @@ void AddressBook::OnRequestReceived(const EventAddressBookRemoveBatchPtr &event) void AddressBook::OnRequestReceived(const EventAddressBookFindPtr &event) { + LogDebug("entered"); Try { ContactSearchEnginePtr searchEngine(new ContactSearchEngine(ContactSearchEngine::CONTACT_QUERY)); @@ -418,12 +384,9 @@ void AddressBook::OnRequestReceived(const EventAddressBookFindPtr &event) searchEngine->setAttributeOfInterest(); - if (event->getSortModesIsSet()) + if (event->getSortModeIsSet()) { - if(event->getSortModes()->size() > 0) - searchEngine->setSortMode(event->getSortModes()->at(0)); - else - searchEngine->setSortMode(); + searchEngine->setSortMode(event->getSortMode()); } else searchEngine->setSortMode(); @@ -448,143 +411,6 @@ void AddressBook::OnRequestReceived(const EventAddressBookFindPtr &event) } } -void AddressBook::daNotifyCallback(user_notify_info_t *notify_info, void *user_data) -{ - if (notify_info == NULL) - { - LogDebug("notify_info is NULL!!"); - return; - } - - if (notify_info->state == DA_STATE_FAILED || - notify_info->state == DA_STATE_CANCELED) - { - if (user_data != NULL) - { - DownImageInfo *downImageInfo; - downImageInfo = static_cast(user_data); - (downImageInfo->getWaitableEvent())->Signal(); - } - } -} - -void AddressBook::daGetDdInfoCallback(user_dd_info_t *dd_info, void *user_data) -{ - /* Empty CB */ -} - -void AddressBook::daUpdateDownloadInfoCallback(user_download_info_t *download_info, void *user_data) -{ - if(download_info == NULL) - { - LogDebug("download_info is NULL!!"); - return; - } - - if (user_data == NULL) - { - LogDebug("user_data is NULL!!"); - return; - } - - if (download_info->saved_path) - { - LogDebug("download_info->saved_path : " << download_info->saved_path); - - DownImageInfo *downImageInfo = static_cast(user_data); - string savedPath = download_info->saved_path; - downImageInfo->setDownloadedImagePath(savedPath); - (downImageInfo->getWaitableEvent())->Signal(); - } -} - -void AddressBook::setDaClientIdByDaInit(void) -{ - int da_ret = DA_INVALID_ID; - - da_client_cb_t da_cb = { 0 }; - - da_cb.user_noti_cb = &daNotifyCallback; - da_cb.send_dd_info_cb = &daGetDdInfoCallback; - da_cb.update_dl_info_cb = &daUpdateDownloadInfoCallback; - - da_ret = da_init(&da_cb, DA_NETWORK_MANAGING_METHOD_AUTO, &m_daClientId); - - if (da_ret != DA_RESULT_OK) - { - LogDebug("Error during da_init() da_ret: " << da_ret); - } -} - -void AddressBook::unsetDaClientIdByDaDeinit(void) -{ - da_deinit(m_daClientId); - - m_daClientId = DA_INVALID_ID; -} - -string AddressBook::downloadImage(const string &imgUrl) const -{ - LogDebug("URL : " << imgUrl); - - string result; - Try { - DownImageInfo downImageInfo; - int da_ret = DA_INVALID_ID; - int download_id = -1; - - DPL::WaitableEvent waitableEvent; - downImageInfo.setWaitableEvent(&waitableEvent); - da_ret = da_start_download_with_extension(m_daClientId, imgUrl.c_str(), - &download_id, DA_FEATURE_USER_DATA, - static_cast(&downImageInfo), NULL); - if (da_ret != DA_RESULT_OK) { - ThrowMsg(PlatformException, - "Error during da_start_download_with_extension() da_ret: " - << da_ret << ", m_daClientId: " << m_daClientId); - } - - DPL::WaitForSingleHandle(waitableEvent.GetHandle()); - waitableEvent.Reset(); - if ((downImageInfo.getDownloadedImagePath()).empty()) { - ThrowMsg(PlatformException, "Download failed"); - } - - result = downImageInfo.getDownloadedImagePath(); - - } Catch (Exception) { - LogError("Probably invalid URL(" << imgUrl << ") " << _rethrown_exception.GetMessage()); - } - - return result; -} - -string AddressBook::getRealPath(const string &path) const -{ - LogDebug("Path : " << path); - - string result; - Try - { - if ( validate("^(http(s)?://)?\\w+.*$", path, VALIDATE_MATCH_CASELESS) ) - { - // if path is URL then Image will be downloaded. - result = downloadImage(path); - } - else - { - result = path; - } - } - Catch(Exception) - { - //probably path doesn't exist - LogError("invalid path(" << path << ")"); - } - - return result; -} - void AddressBook::internalAddContact(const ContactPtr &newContact) { LogDebug("entered"); @@ -594,7 +420,7 @@ void AddressBook::internalAddContact(const ContactPtr &newContact) //translate provided path to real filesystem path if (newContact->getPhotoURIIsSet()) { - string realpath = getRealPath(newContact->getPhotoURI()); + string realpath = DownloadManager::getInstance()->getRealPath(newContact->getPhotoURI()); newContact->setPhotoURI(realpath); } @@ -623,7 +449,7 @@ void AddressBook::internalAddContact(const ContactPtr &newContact) int addressBookId = 0; int accountId = 0; - string accountIdStr = newContact->getAccount()->getAccountId(); + string accountIdStr = newContact->getAccount()->getAccountServiceId(); try { istringstream iss(accountIdStr); iss >> accountId; @@ -669,6 +495,7 @@ void AddressBook::contactsSvcContactChangedCallback(void *data) void AddressBook::contactsSvcContactChangedCallback() { + LogDebug("entered"); if(m_addressBookEmitters.size() == 0) return; diff --git a/src/platform/Tizen/Contact/AddressBook.h b/src/platform/Tizen/Contact/AddressBook.h index 8f7b059..5d3c92a 100755 --- a/src/platform/Tizen/Contact/AddressBook.h +++ b/src/platform/Tizen/Contact/AddressBook.h @@ -25,13 +25,12 @@ #define _PLATFORM_CONTACT_ADDRESS_BOOK_H_ #include -#include #include #include #include #include -#include +#include namespace TizenApis { namespace Platform { @@ -40,20 +39,23 @@ namespace Contact { class AddressBook : public TizenApis::Api::Contact::IAddressBook { private: + std::string m_id; std::string m_name; + bool m_readOnly; public: explicit AddressBook(TizenApis::Api::Contact::IAddressBook::AddressBookType type); virtual ~AddressBook(); + virtual std::string getId() const { return m_id; } + virtual void setId(const std::string &value) { m_id = value; } virtual std::string getName() const { return m_name; } - virtual void setName(const std::string &value) { m_name = value; }; + 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 TizenApis::Api::Contact::ContactPropertiesPtr convertFromString(const std::string &vCardStr, - const std::string &format); - virtual std::string convertToString(const TizenApis::Api::Contact::ContactPtr &contact, - const std::string &format); - virtual TizenApis::Api::Contact::ContactPtr add(const TizenApis::Api::Contact::ContactPropertiesPtr &contactProperties); + virtual TizenApis::Api::Contact::ContactPtr get(const std::string &contactId); + virtual void add(const TizenApis::Api::Contact::ContactPtr &contact); virtual void update(const TizenApis::Api::Contact::ContactPtr &contact); virtual void remove(const std::string &id); @@ -67,44 +69,8 @@ protected: virtual void OnRequestReceived(const TizenApis::Api::Contact::EventAddressBookFindPtr &event); private: - class DownImageInfo - { - private: - DPL::WaitableEvent* m_waitableEvent; - std::string m_downloadedImagePath; - - public: - DownImageInfo() : m_waitableEvent(NULL) - { - } - void setWaitableEvent (DPL::WaitableEvent* waitableEvent) - { - m_waitableEvent = waitableEvent; - } - DPL::WaitableEvent* getWaitableEvent (void) const - { - return m_waitableEvent; - } - void setDownloadedImagePath (const std::string &downloadedImagePath) - { - m_downloadedImagePath = downloadedImagePath; - } - std::string getDownloadedImagePath (void) const - { - return m_downloadedImagePath; - } - }; - static void daNotifyCallback(user_notify_info_t *notify_info, void *user_data); - static void daGetDdInfoCallback(user_dd_info_t *dd_info, void *user_data); - static void daUpdateDownloadInfoCallback(user_download_info_t *download_info, void *user_data); - void setDaClientIdByDaInit(void); - void unsetDaClientIdByDaDeinit(void); - int m_daClientId; int m_latestVersion; - std::string downloadImage(const std::string &imgUrl) const; - std::string getRealPath(const std::string &path) const; - void internalAddContact(const TizenApis::Api::Contact::ContactPtr &newContact); void internalDeleteContactById(int id); DPL::Mutex m_contactEditingMutex; diff --git a/src/platform/Tizen/Contact/AddressBookStorage.cpp b/src/platform/Tizen/Contact/AddressBookStorage.cpp new file mode 100755 index 0000000..263bc1b --- /dev/null +++ b/src/platform/Tizen/Contact/AddressBookStorage.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file AddressBookStorage.cpp + * @author Kisub Song (kisubs.song@samsung.com) + * @version 0.1 + * @brief + */ + +#include +#include +#include "AddressBookStorage.h" + +namespace TizenApis { +namespace Platform { +namespace Contact { + +using namespace WrtDeviceApis::Commons; +using namespace TizenApis::Api::Contact; +//using namespace TizenApis::Api::Tizen; + +AddressBookStorage::AddressBookStorage() : + m_addressBooks(new AddressBookArray()), + m_defaultAddressBookIndex(-1) +{ +} + +AddressBookStorage::~AddressBookStorage() +{ +} + +void AddressBookStorage::insert(AddressBookPtr addressBook, bool setAsDefault) +{ + int index; + std::string id; + + std::stringstream ss; + + index = m_addressBooks->size(); + + // just use index as id (very simple) + ss << index; + id = ss.str(); + m_idMap[id] = index; + + addressBook->setId(id); + + m_addressBooks->push_back(addressBook); + + if(m_defaultAddressBookIndex == -1 || setAsDefault) + m_defaultAddressBookIndex = index; +} + +AddressBookPtr AddressBookStorage::getAddressBook(const std::string &id) +{ + if(m_idMap.find(id) == m_idMap.end()) + ThrowMsg(NotFoundException, "No AddressBook id:" << id); + + int index = m_idMap[id]; + + if(static_cast(m_addressBooks->size()) <= index) + ThrowMsg(NotFoundException, "No AddressBook id:" << id); + + return m_addressBooks->at(index); +} + +AddressBookPtr AddressBookStorage::getDefaultAddressBook() const +{ + if(m_defaultAddressBookIndex == -1 || m_addressBooks->size() == 0) + ThrowMsg(PlatformException, "Invalid request"); + + return m_addressBooks->at(m_defaultAddressBookIndex); +} + +AddressBookArrayPtr AddressBookStorage::getAddressBooks() const +{ + AddressBookArrayPtr newArray(new AddressBookArray()); + + for(AddressBookArray::iterator i = m_addressBooks->begin(); i != m_addressBooks->end(); i++) + newArray->push_back(*i); + + return newArray; +} + +} // Contact +} // Platform +} // TizenApis diff --git a/src/platform/Tizen/Contact/AddressBookStorage.h b/src/platform/Tizen/Contact/AddressBookStorage.h new file mode 100755 index 0000000..4e7c91b --- /dev/null +++ b/src/platform/Tizen/Contact/AddressBookStorage.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file AddressBookStorage.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 +#include +#include +#include + +namespace TizenApis { +namespace Platform { +namespace Contact { + +class AddressBookStorage +{ +public: + AddressBookStorage(); + virtual ~AddressBookStorage(); + + void insert(TizenApis::Api::Contact::AddressBookPtr addressBook, bool setAsDefault = false); + TizenApis::Api::Contact::AddressBookPtr getAddressBook(const std::string &id); + TizenApis::Api::Contact::AddressBookPtr getDefaultAddressBook() const; + TizenApis::Api::Contact::AddressBookArrayPtr getAddressBooks() const; + +private: + TizenApis::Api::Contact::AddressBookArrayPtr m_addressBooks; + std::map m_idMap; + int m_defaultAddressBookIndex; +}; +typedef DPL::SharedPtr AddressBookStoragePtr; + +} // Contact +} // Platform +} // TizenApis + +#endif // _PLATFORM_CONTACT_ADDRESS_BOOK_STORAGE_H_ diff --git a/src/platform/Tizen/Contact/Contact.cpp b/src/platform/Tizen/Contact/Contact.cpp new file mode 100755 index 0000000..31cc1d7 --- /dev/null +++ b/src/platform/Tizen/Contact/Contact.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES 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 +#include +#include +#include +#include +#include "ContactWrapper.h" +#include "Contact.h" + +namespace TizenApis { +namespace Platform { +namespace Contact { + +using namespace TizenApis::Api::Contact; +using namespace WrtDeviceApis::Commons; +using namespace std; + +Contact::Contact() : IContact() +{ + LogDebug("entered"); +} + +Contact::Contact(const string &vObjectStr, const string &format) + : IContact(vObjectStr, format) +{ + LogDebug("entered"); + ContactPtr iContact = convertFromString(vObjectStr, format); + DPL::SharedPtr contact = DPL::DynamicPointerCast(iContact); + + *this = *contact; +} + +Contact::~Contact() +{ +} + +string Contact::convertToString(const string &format) +{ + LogDebug("entered"); + char *vcard_stream = NULL; + + if(format != "VCARD_30") + ThrowMsg(UnsupportedException, "Only support vCard 3.0."); + + Contact *pContact = new Contact(); + *pContact = *this; + ContactPtr contact(pContact); + + ContactWrapperPtr contactWrapper(new ContactWrapper(TizenApis::Api::Contact::IAddressBook::PhoneBook)); + Try { +// contactWrapper->setAbstractContact(DPL::StaticPointerCast(SharedFromThis()), true); + contactWrapper->setAbstractContact(contact, true); + } Catch (PlatformException) { + ThrowMsg(PlatformException, "Fail to extract contact to platform object."); + } + int ret = contacts_svc_get_vcard_from_contact(contactWrapper->getPlatformContact(), &vcard_stream); + if(ret != CTS_SUCCESS) + ThrowMsg(PlatformException, "Fail to convert to vCard."); + + string result((char *)vcard_stream); + + free(vcard_stream); + + return result; +} + +ContactPtr Contact::convertFromString(const std::string &vObjectStr, const std::string &format) +{ + LogDebug("entered"); + const void *vcard_stream = vObjectStr.c_str(); + CTSstruct* cts; + + if(format != "VCARD_30") + ThrowMsg(UnsupportedException, "Only support vCard 3.0."); + + int ret = contacts_svc_get_contact_from_vcard(vcard_stream, &cts); + if(CTS_SUCCESS != ret) + ThrowMsg(PlatformException, "Fail to convert contact from vCard."); + + ContactWrapperPtr contactWrapper(new ContactWrapper(TizenApis::Api::Contact::IAddressBook::PhoneBook)); + Try { + contactWrapper->setPlatformContact(cts); + } Catch (PlatformException) { + ThrowMsg(PlatformException, "Fail to extract contact from platform object."); + } + + return contactWrapper->getAbstractContact(); +} + +} // Contact +} // Platform +} // TizenApis diff --git a/src/platform/Tizen/Contact/Contact.h b/src/platform/Tizen/Contact/Contact.h new file mode 100755 index 0000000..efbe7b9 --- /dev/null +++ b/src/platform/Tizen/Contact/Contact.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES 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 +#include +#include + +namespace TizenApis { +namespace Platform { +namespace Contact { + +class Contact : + public TizenApis::Api::Contact::IContact +// public DPL::EnableSharedFromThis +{ +public: + Contact(); + Contact(const std::string &vObjectStr, const std::string &format); + virtual ~Contact(); + + virtual std::string convertToString(const std::string &format); + + static TizenApis::Api::Contact::ContactPtr convertFromString(const std::string &vObjectStr, const std::string &format); +}; + +} // Contact +} // Platform +} // TizenApis + +#endif // _PLATFORM_CONTACT_CONTACT_H_ diff --git a/src/standards/Tizen/Application/ApplicationServiceReplyCallback.h b/src/platform/Tizen/Contact/ContactImpl.h similarity index 56% rename from src/standards/Tizen/Application/ApplicationServiceReplyCallback.h rename to src/platform/Tizen/Contact/ContactImpl.h index e5a6ee0..54837d6 100755 --- a/src/standards/Tizen/Application/ApplicationServiceReplyCallback.h +++ b/src/platform/Tizen/Contact/ContactImpl.h @@ -14,29 +14,18 @@ * limitations under the License. */ +/** + * @file ContactImpl.h + * @author Kisub Song (kisubs.song@samsung.com) + * @version 0.1 + * @brief + */ -#ifndef TIZENAPIS_TIZEN_APPLICATION_SERVICE_REPLY_CALLBACK_H_ -#define TIZENAPIS_TIZEN_APPLICATION_SERVICE_REPLY_CALLBACK_H_ - -#include +#ifndef _PLATFORM_CONTACT_CONTACT_IMPL_H_ +#define _PLATFORM_CONTACT_CONTACT_IMPL_H_ -namespace TizenApis { -namespace Tizen1_0 { -namespace Application { -struct ApplicationServiceReplyCallback -{ - JSValueRef onsuccess; - JSValueRef onfail; - JSValueRef oncancel; +#include "ContactManager.h" +#include "AddressBook.h" +#include "Contact.h" - ApplicationServiceReplyCallback() : - onsuccess(NULL), - onfail(NULL), - oncancel(NULL) - { - } -}; -} -} -} -#endif +#endif // _PLATFORM_CONTACT_CONTACT_IMPL_H_ diff --git a/src/platform/Tizen/Contact/ContactManager.cpp b/src/platform/Tizen/Contact/ContactManager.cpp index b67d96a..1167a3b 100755 --- a/src/platform/Tizen/Contact/ContactManager.cpp +++ b/src/platform/Tizen/Contact/ContactManager.cpp @@ -25,9 +25,10 @@ #include #include #include -#include +#include #include "ContactManager.h" #include "AddressBook.h" +#include "DownloadManager.h" #define DEVICE_ADDRESSBOOK "DEVICE AddressBook" #define SIM_ADDRESSBOOK "SIM AddressBook" @@ -44,13 +45,15 @@ using namespace TizenApis::Api::Tizen; int ContactManager::m_instanceCount = 0; bool ContactManager::m_opened = false; -ContactManager::ContactManager() : - m_deviceBook(new AddressBook(IAddressBook::AddressBookType::PhoneBook)), - m_simBook(new AddressBook(IAddressBook::AddressBookType::SIMBook)) +ContactManager::ContactManager() + : m_addressBookStorage(new AddressBookStorage()) { - //set address book names - m_deviceBook->setName(DEVICE_ADDRESSBOOK); - m_simBook->setName(SIM_ADDRESSBOOK); + // Currently only supports PhoneBook + AddressBookPtr addressBook(new AddressBook(IAddressBook::PhoneBook)); + addressBook->setName(DEVICE_ADDRESSBOOK); + addressBook->setReadOnly(false); + + m_addressBookStorage->insert(addressBook, true); //protect for pararel execution DPL::Mutex::ScopedLock mx(&m_constructorMutex); @@ -72,6 +75,9 @@ ContactManager::ContactManager() : //increase counter of instances m_instanceCount++; + + //initialize download manager + DownloadManagerPtr downloadManager = DownloadManager::getInstance(); } ContactManager::~ContactManager() @@ -93,7 +99,7 @@ ContactManager::~ContactManager() } } -IAddressBookPtr ContactManager::getDefaultAddressBook() +AddressBookPtr ContactManager::getDefaultAddressBook() { if(!m_opened) { @@ -102,7 +108,37 @@ IAddressBookPtr ContactManager::getDefaultAddressBook() ThrowMsg(PlatformException, "Contact DB is not opened."); } - return m_deviceBook; + return m_addressBookStorage->getDefaultAddressBook(); +} + +AddressBookPtr ContactManager::getAddressBook(const std::string &addressBookId) +{ + if(!m_opened) + { + //when database is not opened then set result as failed + LogError("Contact DB is not opened."); + ThrowMsg(PlatformException, "Contact DB is not opened."); + } + + if(addressBookId == "") + { + //when database is not opened then set result as failed + LogError("Wrong address book id"); + ThrowMsg(InvalidArgumentException, "Wrong address book id."); + } + + AddressBookPtr addressBook; + + Try { + addressBook = m_addressBookStorage->getAddressBook(addressBookId); + + } Catch(Exception) { + //when database is not opened then set result as failed + LogError("Not found : " << _rethrown_exception.GetMessage()); + ThrowMsg(NotFoundException, "No address book"); + } + + return addressBook; } void ContactManager::OnRequestReceived(const EventContactManagerGetAddressBooksPtr &event) @@ -118,12 +154,10 @@ void ContactManager::OnRequestReceived(const EventContactManagerGetAddressBooksP Try { - IAddressBookArrayPtr addressBookArray = IAddressBookArrayPtr(new IAddressBookArray()); + AddressBookArrayPtr addressBookArray = m_addressBookStorage->getAddressBooks(); - if (m_deviceBook != NULL) - addressBookArray->push_back(m_deviceBook); - if (m_simBook != NULL) - addressBookArray->push_back(m_simBook); + if(addressBookArray->size() == 0) + ThrowMsg(NotFoundException, "No address book"); event->setAddressBooks(addressBookArray); event->setResult(true); diff --git a/src/platform/Tizen/Contact/ContactManager.h b/src/platform/Tizen/Contact/ContactManager.h index f6717b6..e0eb9b0 100755 --- a/src/platform/Tizen/Contact/ContactManager.h +++ b/src/platform/Tizen/Contact/ContactManager.h @@ -27,6 +27,7 @@ #include #include #include "AddressBook.h" +#include "AddressBookStorage.h" namespace TizenApis { namespace Platform { @@ -38,18 +39,17 @@ public: ContactManager(); virtual ~ContactManager(); - virtual TizenApis::Api::Contact::IAddressBookPtr getDefaultAddressBook(); + virtual TizenApis::Api::Contact::AddressBookPtr getDefaultAddressBook(); + virtual TizenApis::Api::Contact::AddressBookPtr getAddressBook(const std::string &addressBookId); protected: virtual void OnRequestReceived(const TizenApis::Api::Contact::EventContactManagerGetAddressBooksPtr &event); private: - TizenApis::Api::Contact::IAddressBookPtr m_deviceBook; - TizenApis::Api::Contact::IAddressBookPtr m_simBook; - static int m_instanceCount; static bool m_opened; DPL::Mutex m_constructorMutex; + AddressBookStoragePtr m_addressBookStorage; }; } // Contact diff --git a/src/platform/Tizen/Contact/ContactSearchEngine.cpp b/src/platform/Tizen/Contact/ContactSearchEngine.cpp index a6e8b9e..6fb68d2 100755 --- a/src/platform/Tizen/Contact/ContactSearchEngine.cpp +++ b/src/platform/Tizen/Contact/ContactSearchEngine.cpp @@ -26,6 +26,7 @@ #include #include +#include "Contact.h" #include "ContactSearchEngine.h" namespace TizenApis { @@ -37,8 +38,6 @@ using namespace TizenApis::Api::Tizen; using namespace WrtDeviceApis::Commons; using namespace std; -using TizenApis::Api::Contact::Contact; - map ContactSearchEngine::attrEnumMap = { {"id", contact_attribute_e::CONTACT_ID}, {"readOnly", contact_attribute_e::ATTRIBUTE_MAX}, @@ -106,6 +105,14 @@ void ContactSearchEngine::setCondition(FilterPtr filter) filter->travel(filterQuery); } +void ContactSearchEngine::setCondition(string contactId) +{ + if(contactId == "") + ThrowMsg(InvalidArgumentException, "contactId id empty."); + + query_set_condition(m_contact_query_service, getPlatformAttr("id"), EQUAL, contactId.c_str()); +} + void ContactSearchEngine::setSortMode(SortModePtr attr) { if(attr) @@ -187,7 +194,7 @@ ContactArrayPtr ContactSearchEngine::getContactSearchResult() str = query_get_attribute(m_contact_query_service, ACCOUNT_ID, &err); if( str ) - contact->getAccount()->setAccountId(str); + contact->getAccount()->setAccountServiceId(str); str = query_get_attribute(m_contact_query_service, CONTACT_IS_FAVORITE, &err); if( str ) @@ -398,8 +405,11 @@ void ContactSearchEngine::visitPostComposite(FilterType& type, int depth) query_set_condition_append(m_contact_query_service, RIGHT_BRACKET); } -void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag, AnyArrayPtr& matchValues, int depth) +void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag, AnyPtr& matchValue, int depth) { + if(matchValue == NULL) + return; + contact_attribute_e attr; attr = getPlatformAttr(attrName); @@ -409,11 +419,7 @@ void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag, { query_set_condition(m_contact_query_service, attr, EXISTS, NULL); } - else if(attrName == "id" && matchFlag == MATCH_EXACTLY) - { - visitAttributeID(matchValues); - } - else if(matchValues->size() == 1) + else { condition_e cond; if(matchFlag == MATCH_EXACTLY) @@ -423,38 +429,15 @@ void ContactSearchEngine::visitAttribute(string& attrName, MatchFlag& matchFlag, else cond = EQUAL; - AnyPtr matchValue = matchValues->at(0); - visitAttributeEach(attr, matchValue, cond); } - else if(matchValues->size() > 1) - { - condition_e cond; - if(matchFlag == MATCH_EXACTLY) - cond = EQUAL; - else if (matchFlag == MATCH_STARTSWITH || matchFlag == MATCH_ENDSWITH) - cond = LIKE; - else - cond = EQUAL; - - query_set_condition_append(m_contact_query_service, LEFT_BRACKET); - - AnyArray::iterator iter; - for(iter = matchValues->begin(); iter != matchValues->end(); iter++) - { - AnyPtr matchValue = *iter; - if(iter != matchValues->begin()) - query_set_condition_append(m_contact_query_service, OR); - - visitAttributeEach(attr, matchValue, cond); - } - - query_set_condition_append(m_contact_query_service, RIGHT_BRACKET); - } } void ContactSearchEngine::visitAttributeRange(string& attrName, AnyPtr& initialValue, AnyPtr& endValue, int depth) { + if(initialValue == NULL || endValue == NULL) + return; + contact_attribute_e attr; string initialValueStr; string endValueStr; @@ -649,7 +632,36 @@ void ContactSearchEngine::setPhoneNumber(ContactPtr& contact, char *number, char tokenize(type,tokens, ","); for (unsigned int i=0; iaddType(tokens[i]); + { + if (tokens[i].compare("WORK") == 0) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_WORK); + else if (tokens[i].compare("PREF")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_PREF); + else if (tokens[i].compare("HOME")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_HOME); + else if (tokens[i].compare("VOICE")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_VOICE); + else if (tokens[i].compare("FAX")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_FAX); + else if (tokens[i].compare("MSG")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_MSG); + else if (tokens[i].compare("CELL")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_CELL); + else if (tokens[i].compare("PAGER")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_PAGER); + else if (tokens[i].compare("BBS")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_BBS); + else if (tokens[i].compare("MODEM")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_MODEM); + else if (tokens[i].compare("CAR")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_CAR); + else if (tokens[i].compare("IDSN")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_ISDN); + else if (tokens[i].compare("VIDEO")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_VIDEO); + else if (tokens[i].compare("PCS")) + numberType->addType(CONTACT_PHONE_NUMBER_TYPE_PCS); + } } contact->addPhoneNumber(numberType); diff --git a/src/platform/Tizen/Contact/ContactSearchEngine.h b/src/platform/Tizen/Contact/ContactSearchEngine.h index ff8fc42..33808e8 100755 --- a/src/platform/Tizen/Contact/ContactSearchEngine.h +++ b/src/platform/Tizen/Contact/ContactSearchEngine.h @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include "query-svc/query-service.h" @@ -54,6 +54,7 @@ public: // setting search options. void setCondition(TizenApis::Api::Tizen::FilterPtr filter); + void setCondition(std::string contactId); void setAttributeOfInterest(TizenApis::Api::Contact::StringArrayPtr attr = TizenApis::Api::Contact::StringArrayPtr(NULL)); void setSortMode(TizenApis::Api::Tizen::SortModePtr attr = TizenApis::Api::Tizen::SortModePtr(NULL)); @@ -66,7 +67,7 @@ public: virtual void visitPostComposite(TizenApis::Api::Tizen::FilterType& type, int depth); virtual void visitAttribute(std::string& attrName, TizenApis::Api::Tizen::MatchFlag& matchFlag, - TizenApis::Api::Tizen::AnyArrayPtr& matchValues, + TizenApis::Api::Tizen::AnyPtr& matchValue, int depth); virtual void visitAttributeRange(std::string& attrName, TizenApis::Api::Tizen::AnyPtr& initialValue, diff --git a/src/platform/Tizen/Contact/ContactWrapper.cpp b/src/platform/Tizen/Contact/ContactWrapper.cpp index b9dfd65..afd7115 100755 --- a/src/platform/Tizen/Contact/ContactWrapper.cpp +++ b/src/platform/Tizen/Contact/ContactWrapper.cpp @@ -28,6 +28,7 @@ #include #include "ContactWrapper.h" #include "AddressBook.h" +#include "Contact.h" #include "query-svc/query-service.h" #define CONTACT_ATTRIBUTE_PHONETIC_NAME "phoneticName" @@ -43,8 +44,6 @@ using namespace TizenApis::Api::Contact; using namespace WrtDeviceApis::Commons; using namespace std; -using TizenApis::Api::Contact::Contact; - ContactWrapper::ContactWrapper(IAddressBook::AddressBookType type) : m_abstractContact(NULL), m_platformContact(NULL) @@ -701,50 +700,50 @@ bool ContactWrapper::convertToAbstractPhoneObject() switch (type) { case CTS_NUM_TYPE_WORK: - phoneNumber->addType("WORK"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_WORK); break; case CTS_NUM_TYPE_NONE: - phoneNumber->addType("PREF"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PREF); break; case CTS_NUM_TYPE_HOME: - phoneNumber->addType("HOME"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_HOME); break; case CTS_NUM_TYPE_FAX: - phoneNumber->addType("FAX"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_FAX); break; case CTS_NUM_TYPE_CELL: - phoneNumber->addType("CELL"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CELL); break; case CTS_NUM_TYPE_PAGER: - phoneNumber->addType("PAGER"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PAGER); break; case CTS_NUM_TYPE_CAR: - phoneNumber->addType("CAR"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_CAR); break; case CTS_NUM_TYPE_VOICE: - phoneNumber->addType("VOICE"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VOICE); break; case CTS_NUM_TYPE_MSG: - phoneNumber->addType("MSG"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_MSG); break; case CTS_NUM_TYPE_BBS: - phoneNumber->addType("BBS"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_BBS); break; case CTS_NUM_TYPE_MODEM: - phoneNumber->addType("MODEM"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_MODEM); break; case CTS_NUM_TYPE_ISDN: - phoneNumber->addType("ISDN"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_ISDN); break; case CTS_NUM_TYPE_VIDEO: - phoneNumber->addType("VIDEO"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_VIDEO); break; case CTS_NUM_TYPE_PCS: - phoneNumber->addType("PCS"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PCS); break; default: LogError("invalid phone type"); - phoneNumber->addType("PREF"); + phoneNumber->addType(CONTACT_PHONE_NUMBER_TYPE_PREF); break; } @@ -1046,7 +1045,7 @@ bool ContactWrapper::convertToPlatformGroupObject() int accountId; try { - string accountIdStr = m_abstractContact->getAccount()->getAccountId(); + string accountIdStr = m_abstractContact->getAccount()->getAccountServiceId(); stringstream ss(accountIdStr); ss >> accountId; } catch (...) { @@ -1518,65 +1517,39 @@ bool ContactWrapper::convertToPlatformPhoneObject() //add new items for (size_t i = 0; i < phoneNumbers->size(); ++i) { - StringArrayPtr types = phoneNumbers->at(i)->getTypes(); + ContactPhoneNumberTypeArrayPtr types = phoneNumbers->at(i)->getTypes(); number = contacts_svc_value_new(CTS_VALUE_NUMBER); type = 0; if (number) { for (size_t j = 0; j < types->size(); ++j) { - if (types->at(j) == "WORK") - { + if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_WORK) type = type | CTS_NUM_TYPE_WORK; - } - else if (types->at(j) == "PREF") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_PREF) type = type | CTS_NUM_TYPE_NONE; - } - else if (types->at(j) == "HOME") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_HOME) type = type | CTS_NUM_TYPE_HOME; - } - else if (types->at(j) == "FAX") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_FAX) type = type | CTS_NUM_TYPE_FAX; - } - else if (types->at(j) == "CELL") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_CELL) type = type | CTS_NUM_TYPE_CELL; - } - else if (types->at(j) == "PAGER") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_PAGER) type = type | CTS_NUM_TYPE_PAGER; - } - else if (types->at(j) == "CAR") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_CAR) type = type | CTS_NUM_TYPE_CAR; - } - else if (types->at(j) == "BBS") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_BBS) type = type | CTS_NUM_TYPE_BBS; - } - else if (types->at(j) == "MODEM") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_MODEM) type = type | CTS_NUM_TYPE_MODEM; - } - else if (types->at(j) == "ISDN") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_ISDN) type = type | CTS_NUM_TYPE_ISDN; - } - else if (types->at(j) == "VIDEO") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_VIDEO) type = type | CTS_NUM_TYPE_VIDEO; - } - else if (types->at(j) == "VOICE") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_VOICE) type = type | CTS_NUM_TYPE_VOICE; - } - else if (types->at(j) == "MSG") - { + else if (types->at(j) == CONTACT_PHONE_NUMBER_TYPE_MSG) type = type | CTS_NUM_TYPE_MSG; - } else { LogError("invalid phone type"); diff --git a/src/platform/Tizen/Contact/ContactWrapper.h b/src/platform/Tizen/Contact/ContactWrapper.h index b12caad..321dfa9 100755 --- a/src/platform/Tizen/Contact/ContactWrapper.h +++ b/src/platform/Tizen/Contact/ContactWrapper.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include namespace TizenApis { diff --git a/src/platform/Tizen/Contact/DownloadManager.cpp b/src/platform/Tizen/Contact/DownloadManager.cpp new file mode 100755 index 0000000..50736e0 --- /dev/null +++ b/src/platform/Tizen/Contact/DownloadManager.cpp @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file DownloadManager.cpp + * @author Kisub Song (kisubs.song@samsung.com) + * @version 0.1 + * @brief + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "DownloadManager.h" + +namespace TizenApis { +namespace Platform { +namespace Contact { + +using namespace WrtDeviceApis::Commons; + +DownloadManager::DownloadManager() +{ + int da_ret = DA_INVALID_ID; + + da_client_cb_t da_cb = { 0 }; + + da_cb.user_noti_cb = &daNotifyCallback; + da_cb.send_dd_info_cb = &daGetDdInfoCallback; + da_cb.update_dl_info_cb = &daUpdateDownloadInfoCallback; + + da_ret = da_init(&da_cb, DA_DOWNLOAD_MANAGING_METHOD_AUTO); + + if (da_ret != DA_RESULT_OK) + { + LogDebug("Error during da_init() da_ret: " << da_ret); + } +} + +DownloadManager::~DownloadManager() +{ + da_deinit(); +} + +string DownloadManager::downloadImage(const string &imgUrl) const +{ + LogDebug("URL : " << imgUrl); + + string result; + Try { + DownImageInfo downImageInfo; + int da_ret = DA_INVALID_ID; + int download_id = -1; + + DPL::WaitableEvent waitableEvent; + downImageInfo.setWaitableEvent(&waitableEvent); + da_ret = da_start_download_with_extension(imgUrl.c_str(), + &download_id, DA_FEATURE_USER_DATA, + static_cast(&downImageInfo), NULL); + if (da_ret != DA_RESULT_OK) { + ThrowMsg(PlatformException, + "Error during da_start_download_with_extension() da_ret: " + << da_ret); + } + + DPL::WaitForSingleHandle(waitableEvent.GetHandle()); + waitableEvent.Reset(); + if ((downImageInfo.getDownloadedImagePath()).empty()) { + ThrowMsg(PlatformException, "Download failed"); + } + + result = downImageInfo.getDownloadedImagePath(); + + } Catch (Exception) { + LogError("Probably invalid URL(" << imgUrl << ") " << _rethrown_exception.GetMessage()); + } + + return result; +} + +string DownloadManager::getRealPath(const string &path) const +{ + LogDebug("Path : " << path); + + string result; + Try + { + if ( validate("^(http(s)?://)?\\w+.*$", path, VALIDATE_MATCH_CASELESS) ) + { + // if path is URL then Image will be downloaded. + result = downloadImage(path); + } + else + { + result = path; + } + } + Catch(Exception) + { + //probably path doesn't exist + LogError("invalid path(" << path << ")"); + } + + return result; +} + +void DownloadManager::daNotifyCallback(user_notify_info_t *notify_info, void *user_data) +{ + if (notify_info == NULL) + { + LogDebug("notify_info is NULL!!"); + } + + if (notify_info->state == DA_STATE_FAILED || + notify_info->state == DA_STATE_CANCELED) + { + if (user_data != NULL) + { + DownImageInfo *downImageInfo; + downImageInfo = static_cast(user_data); + (downImageInfo->getWaitableEvent())->Signal(); + } + } +} + +void DownloadManager::daGetDdInfoCallback(user_dd_info_t *dd_info, void *user_data) +{ + /* Empty CB */ +} + +void DownloadManager::daUpdateDownloadInfoCallback(user_download_info_t *download_info, void *user_data) +{ + if(download_info == NULL) + { + LogDebug("download_info is NULL!!"); + return; + } + + if (user_data == NULL) + { + LogDebug("user_data is NULL!!"); + return; + } + + if (download_info->saved_path) + { + LogDebug("download_info->saved_path : " << download_info->saved_path); + + DownImageInfo *downImageInfo = static_cast(user_data); + string savedPath = download_info->saved_path; + downImageInfo->setDownloadedImagePath(savedPath); + (downImageInfo->getWaitableEvent())->Signal(); + } +} + +DownloadManagerPtr DownloadManager::getInstance() +{ + static DownloadManagerPtr downloadManager(new DownloadManager()); + + return downloadManager; +} + +} // Contact +} // Platform +} // TizenApis diff --git a/src/platform/Tizen/Contact/DownloadManager.h b/src/platform/Tizen/Contact/DownloadManager.h new file mode 100755 index 0000000..a045628 --- /dev/null +++ b/src/platform/Tizen/Contact/DownloadManager.h @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file DownloadManager.h + * @author Kisub Song (kisubs.song@samsung.com) + * @version 0.1 + * @brief + */ + +#ifndef _PLATFORM_CONTACT_DOWNLOAD_MANAGER_H_ +#define _PLATFORM_CONTACT_DOWNLOAD_MANAGER_H_ + +#include +#include +#include +#include + +namespace TizenApis { +namespace Platform { +namespace Contact { + +class DownloadManager; +typedef DPL::SharedPtr DownloadManagerPtr; + +class DownloadManager +{ +private: + class DownImageInfo + { + private: + DPL::WaitableEvent* m_waitableEvent; + std::string m_downloadedImagePath; + + public: + DownImageInfo() : m_waitableEvent(NULL) + { + } + + void setWaitableEvent (DPL::WaitableEvent* waitableEvent) + { + m_waitableEvent = waitableEvent; + } + + DPL::WaitableEvent* getWaitableEvent (void) const + { + return m_waitableEvent; + } + + void setDownloadedImagePath (const std::string &downloadedImagePath) + { + m_downloadedImagePath = downloadedImagePath; + } + + std::string getDownloadedImagePath (void) const + { + return m_downloadedImagePath; + } + }; + +private: + DownloadManager(); + +public: + virtual ~DownloadManager(); + +public: + static void daNotifyCallback(user_notify_info_t *notify_info, void *user_data); + static void daGetDdInfoCallback(user_dd_info_t *dd_info, void *user_data); + static void daUpdateDownloadInfoCallback(user_download_info_t *download_info, void *user_data); + + std::string downloadImage(const std::string &imgUrl) const; + std::string getRealPath(const std::string &path) const; + + static DownloadManagerPtr getInstance(); +}; + +} // Contact +} // Platform +} // TizenApis + +#endif // _PLATFORM_CONTACT_DOWNLOAD_MANAGER_H_ diff --git a/src/platform/Tizen/Contact/config.cmake b/src/platform/Tizen/Contact/config.cmake index 4f6b195..3ef7a1c 100755 --- a/src/platform/Tizen/Contact/config.cmake +++ b/src/platform/Tizen/Contact/config.cmake @@ -21,9 +21,12 @@ set(LIBS_PLATFORM_IMPLEMENTATION_CONTACT set(SRCS_PLATFORM_IMPLEMENTATION_CONTACT ${CURRENT_PATH}/ContactManager.cpp ${CURRENT_PATH}/AddressBook.cpp + ${CURRENT_PATH}/Contact.cpp ${CURRENT_PATH}/ContactWrapper.cpp ${CURRENT_PATH}/ContactSearchEngine.cpp ${CURRENT_PATH}/ContactFilterValidator.cpp + ${CURRENT_PATH}/AddressBookStorage.cpp + ${CURRENT_PATH}/DownloadManager.cpp ${CURRENT_PATH}/query-svc/query-svc.c ${CURRENT_PATH}/query-svc/query-utility.c # ${CURRENT_PATH}/../../API/Filesystem/IManager.cpp diff --git a/src/platform/Tizen/Filesystem/Manager.cpp b/src/platform/Tizen/Filesystem/Manager.cpp index 7103806..c830e02 100755 --- a/src/platform/Tizen/Filesystem/Manager.cpp +++ b/src/platform/Tizen/Filesystem/Manager.cpp @@ -37,6 +37,7 @@ #include "MoveCommand.h" #include "RemoveCommand.h" #include "Utils.h" +#include using namespace TizenApis::Api::Filesystem; @@ -44,8 +45,8 @@ namespace { const char* PATH_DOWNLOADS = "/opt/media/Downloads"; const char* PATH_DOCUMENTS = "/opt/media/Documents"; const char* PATH_SOUNDS = "/opt/media/Music"; -const char* PATH_IMAGES = "/opt/media/Videos"; -const char* PATH_VIDEOS = "/opt/media/Images and videos"; +const char* PATH_IMAGES = "/opt/media/Images"; +const char* PATH_VIDEOS = "/opt/media/Videos"; } using namespace WrtDeviceApis; @@ -421,12 +422,22 @@ void Manager::OnRequestReceived(const EventListStoragesPtr& event) { try { std::vector storageList; + storage_foreach_device_supported(Manager::getSupportedDeviceCB, &storageList); - addLocalStorage("downloads", storageList); - addLocalStorage("documents", storageList); - addLocalStorage("music", storageList); - addLocalStorage("images", storageList); - addLocalStorage("videos", 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::PlatformException& ex) { event->setExceptionCode(Commons::ExceptionCodes::PlatformException); @@ -623,6 +634,24 @@ void Manager::addLocalStorage(std::string label, std::vector storageList; @@ -642,6 +671,7 @@ bool Manager::init() 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"; diff --git a/src/platform/Tizen/Filesystem/Manager.h b/src/platform/Tizen/Filesystem/Manager.h index c83d646..dc670a6 100755 --- a/src/platform/Tizen/Filesystem/Manager.h +++ b/src/platform/Tizen/Filesystem/Manager.h @@ -151,6 +151,7 @@ public : void OnRequestReceived(const Api::Filesystem::EventFindPtr& event); void addLocalStorage(std::string label, std::vector &storageList); + void addWidgetStorage(const std::string &key, const std::string &value); private: typedef std::map Locations; diff --git a/src/platform/Tizen/Mediacontent/MediaFilterValidator.cpp b/src/platform/Tizen/Mediacontent/MediaFilterValidator.cpp index 2132e58..db09b11 100755 --- a/src/platform/Tizen/Mediacontent/MediaFilterValidator.cpp +++ b/src/platform/Tizen/Mediacontent/MediaFilterValidator.cpp @@ -34,10 +34,6 @@ static PropertyStructArray folderProperties = static PropertyStructArray mediaProperties = { - {"folder.id", PrimitiveType_String}, - {"folder.title", PrimitiveType_String}, - {"folder.folderURL", PrimitiveType_String}, - {"folder.storageType", PrimitiveType_String}, {"id", PrimitiveType_String}, {"type", PrimitiveType_String}, {"mimeType", PrimitiveType_String}, @@ -60,22 +56,26 @@ static PropertyStructArray mediaProperties = {"playCount", PrimitiveType_Long}, {"genre", PrimitiveType_String}, {"artist", PrimitiveType_String}, - {0, PrimitiveType_NoType} + {0, PrimitiveType_NoType} + }; + FilterValidatorPtr MediaFilterValidatorFactory::getMediaFilterValidator(QueryType value) { static FilterValidatorPtr theFolderInstance; static FilterValidatorPtr theMediaInstance; if(value == QUERY_FOLDER) - { - theFolderInstance = FilterValidatorPtr(new FilterValidator(folderProperties)); + { + LogDebug("create validator of folder"); + theFolderInstance = FilterValidatorPtr(new FilterValidator(folderProperties)); return theFolderInstance; } else if(value == QUERY_MEDIA) { - theMediaInstance = FilterValidatorPtr(new FilterValidator(mediaProperties)); + LogDebug("create validator of media item"); + theMediaInstance = FilterValidatorPtr(new FilterValidator(folderProperties)); return theMediaInstance; } diff --git a/src/platform/Tizen/Mediacontent/MediaSearchVisitor.cpp b/src/platform/Tizen/Mediacontent/MediaSearchVisitor.cpp index 078f524..81d76a6 100755 --- a/src/platform/Tizen/Mediacontent/MediaSearchVisitor.cpp +++ b/src/platform/Tizen/Mediacontent/MediaSearchVisitor.cpp @@ -115,20 +115,20 @@ MediaSearchVisitor::~MediaSearchVisitor() void MediaSearchVisitor::visitPreComposite(FilterType& type, int depth) { - m_query = m_query + STR_LEFT_BRACKET; + m_query.append(STR_LEFT_BRACKET); } void MediaSearchVisitor::visitInComposite(FilterType& type, int depth) { if(type == UNION_FILTER) - m_query = m_query + STR_OR; + m_query.append(STR_OR); else if(type == INTERSECTION_FILTER) - m_query = m_query + STR_AND; + m_query.append(STR_AND); } void MediaSearchVisitor::visitPostComposite(FilterType& type, int depth) { - m_query = m_query + STR_RIGHT_BRACKET; + m_query.append(STR_RIGHT_BRACKET); } @@ -168,35 +168,15 @@ string MediaSearchVisitor::getPlatformAttr(string attrName) } -void MediaSearchVisitor::visitAttribute(string& attrName, MatchFlag& matchFlag, AnyArrayPtr& matchValues, int depth) +void MediaSearchVisitor::visitAttribute(string& attrName, MatchFlag& matchFlag, AnyPtr& matchValue, int depth) { string attrPlatform = getPlatformAttr(attrName); - if(matchValues == NULL) + if(matchValue == NULL) { return ; } - if(matchValues->size() == 1) - { - AnyPtr matchValue = matchValues->at(0); - - m_query = convertAttribute(attrPlatform, matchValue, matchFlag); - } - else if(matchValues->size() > 1) - { - AnyArray::iterator iter; - m_query.append(STR_LEFT_BRACKET); - for(iter = matchValues->begin(); iter != matchValues->end(); iter++) - { - AnyPtr matchValue = *iter; - if(iter != matchValues->begin()) - { - m_query.append(STR_OR); - } - m_query.append(convertAttribute(attrPlatform, matchValue, matchFlag)); - } - m_query.append(STR_RIGHT_BRACKET); - } + m_query.append(convertAttribute(attrPlatform, matchValue, matchFlag)); } string MediaSearchVisitor::toDateDbStr(const tm &date) const @@ -281,20 +261,21 @@ string MediaSearchVisitor::convertAttribute(string &attrName, AnyPtr& matchValue void MediaSearchVisitor::visitAttributeRange(string& attrName,AnyPtr& initialValue,AnyPtr& endValue,int depth) { + if(initialValue == NULL || endValue == NULL) + return; string str; string initialValueStr; string endValueStr; - if(initialValue != NULL) + if(!initialValue->isNullOrUndefined()) { if(initialValue->getType() == PrimitiveType_Time) { tm date = initialValue->getDateTm(); - std::stringstream time; - time << mktime(&date); - initialValueStr = time.str(); + initialValueStr = toDateDbStr(date); + } else { @@ -302,15 +283,12 @@ void MediaSearchVisitor::visitAttributeRange(string& attrName,AnyPtr& initialVal } } - if (endValue != NULL) + if (!endValue->isNullOrUndefined()) { if(endValue->getType() == PrimitiveType_Time) { tm date = endValue->getDateTm(); - std::stringstream time; - time << mktime(&date); - endValueStr = time.str(); - + endValueStr = toDateDbStr(date); } else { @@ -318,20 +296,20 @@ void MediaSearchVisitor::visitAttributeRange(string& attrName,AnyPtr& initialVal } } - if (initialValue != NULL && endValue == NULL) + if (!initialValue->isNullOrUndefined() && endValue->isNullOrUndefined()) { str = STR_LEFT_BRACKET + attrName + STR_GREATER_THAN + STR_EQUAL + STR_S_QUOTATION + initialValueStr + STR_S_QUOTATION + STR_RIGHT_BRACKET; } - else if(initialValue == NULL && endValue != NULL) + else if(initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) { str = STR_LEFT_BRACKET + attrName + STR_LESS_THAN + STR_S_QUOTATION + endValueStr + STR_S_QUOTATION + STR_RIGHT_BRACKET; } - else if (initialValue != NULL && endValue != NULL) + else if (!initialValue->isNullOrUndefined() && !endValue->isNullOrUndefined()) { str = STR_LEFT_BRACKET + attrName + STR_GREATER_THAN + STR_EQUAL + STR_S_QUOTATION + initialValueStr + STR_S_QUOTATION + STR_AND + attrName + STR_LESS_THAN + STR_S_QUOTATION + endValueStr + STR_S_QUOTATION + STR_RIGHT_BRACKET; } - m_query = str; + m_query.append(str); } diff --git a/src/platform/Tizen/Mediacontent/MediaSearchVisitor.h b/src/platform/Tizen/Mediacontent/MediaSearchVisitor.h index fcb0046..1ac5656 100755 --- a/src/platform/Tizen/Mediacontent/MediaSearchVisitor.h +++ b/src/platform/Tizen/Mediacontent/MediaSearchVisitor.h @@ -73,7 +73,7 @@ public: 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, AnyArrayPtr& matchValues, 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); diff --git a/src/platform/Tizen/Mediacontent/Mediacontent.cpp b/src/platform/Tizen/Mediacontent/Mediacontent.cpp index 06a7ceb..75fc431 100644 --- a/src/platform/Tizen/Mediacontent/Mediacontent.cpp +++ b/src/platform/Tizen/Mediacontent/Mediacontent.cpp @@ -33,27 +33,23 @@ using namespace WrtDeviceApis::Commons; #define MEDIA_DEBUG 0 const string SELECT_FOLDER_QUERY = - "select uuid, path, title, storage_type,modified_date from (select uuid, path, folder_name as title, storage_type,modified_date from visual_folder where valid=1 union select _id, path, folder_name as title, storage_type,modified_date from audio_folder) where 1 "; + "select folder_uuid, path, title, storage_type,modified_date from (select folder_uuid, path, folder_name as title, storage_type,modified_date from visual_folder where valid=1 union select folder_uuid, path, folder_name as title, storage_type,modified_date from audio_folder) where 1 "; const string VIEW_MEDIA_QUERY_WITH_FOLDER = - "select media_uuid, folder_uuid, content_type, display_name, path, thumbnail_path,created_date, released_date, modified_date, description,rating, album, artist, last_played_time, played_count,longitude, latitude, width, height, orientation, genre, author, duration, folder_name, folder_path from \ -(select media_uuid,folder_uuid, content_type, display_name, path, thumbnail_path,null as created_date, released_date, modified_date, description,rating, album, artist, last_played_time, null as played_count,longitude, latitude, width, height, orientation,null as genre, null as author, duration from visual_media join \ + "select visual_uuid, folder_uuid, content_type, display_name, path, thumbnail_path,created_date, released_date, modified_date, description,rating, album, artist, last_played_time, played_count,longitude, latitude, width, height, orientation, genre, author, duration from \ +(select visual_uuid,folder_uuid, content_type, display_name, path, thumbnail_path,null as created_date, released_date, modified_date, description,rating, album, artist, last_played_time, null as played_count,longitude, latitude, width, height, orientation,null as genre, null as author, duration from visual_media join \ (select * from \ - (select media_uuid, longitude, latitude, description, width, height, datetaken as released_date, orientation,null as album, null as artist, null as last_played_time,null as duration from image_meta \ + (select visual_uuid as meta_uuid, longitude, latitude, description, width, height, datetaken as released_date, orientation,null as album, null as artist, null as last_played_time,null as duration from image_meta \ union all \ - select media_uuid, longitude, latitude, description, width, height, datetaken as released_date, null as orientation, album, artist, last_played_time,duration from video_meta)) \ -on uuid=media_uuid \ + select visual_uuid as meta_uuid, longitude, latitude, description, width, height, datetaken as released_date, null as orientation, album, artist, last_played_time,duration from video_meta)) \ +on visual_uuid=meta_uuid \ union all \ - select audio_id, folder_id as folder_uuid, content_type, title as display_name, path, thumbnail_path, added_time, year, modified_date, description, favourite, album, artist, last_played_time, played_count, null as longitude, null as latitude, null as width, null as height, null as orientation, genre, author, duration from audio_media) \ -join ( select uuid as folder_id, path as folder_path, folder_name, modified_date as folder_modified_date, storage_type from visual_folder \ -union all \ - select _id as folder_id, path, folder_name, modified_date, storage_type from audio_folder) \ -on folder_uuid=folder_id where 1 "; + select audio_uuid, folder_uuid as folder_uuid, content_type, title as display_name, path, thumbnail_path, added_time, year, modified_date, description, favourite, album, artist, last_played_time, played_count, null as longitude, null as latitude, null as width, null as height, null as orientation, genre, author, duration from audio_media) where 1 "; const string SELECT_MEDIA_ID_WITH_FOLDER = "select item_id from item_view where folder_uuid="; const string SELECT_EXTRA_AUDIO = - "select copyright,bitrate,track_num,size from audio_media where audio_id="; + "select copyright,bitrate,track_num,size from audio_media where audio_uuid="; namespace TizenApis { @@ -192,13 +188,13 @@ void Mediacontent::OnRequestReceived(const IEventFindFolderPtr &eFolder) if(eFolder->getFilterIsSet()) { FilterPtr filter = eFolder->getFilter(); - +/* FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_FOLDER); bool success = filter->validate(validator); if(!success) ThrowMsg(InvalidArgumentException, "Invalid filter arguments."); - +*/ IFilterVisitorPtr IVisitor = DPL::StaticPointerCast(visitor); visitor->setQueryType(MediaSearchVisitor::QUERY_FOLDER); @@ -255,26 +251,6 @@ void Mediacontent::OnRequestReceived(const IEventFindFolderPtr &eFolder) MediacontentFolderPtr newFolder(new MediacontentFolder()); convertToPlatformFolder(media_folder, newFolder); - string queryMediaId(SELECT_MEDIA_ID_WITH_FOLDER); - queryMediaId.append("'"); - queryMediaId.append(media_folder.folder_uuid); - queryMediaId.append("'"); - sqlite3_stmt* pStmt1 = NULL; - if(sqlite3_prepare_v2(hDBCt, (char *)(queryMediaId.c_str()), strlen((char *)(queryMediaId.c_str())), &pStmt1, NULL) == SQLITE_OK) - { - MediaIdListPtr newMediaIdList(new MediaIdList()); - //sqlite3_bind_text(pStmt1, 1, media_folder.folder_uuid,strlen(media_folder.folder_uuid), SQLITE_TRANSIENT); - LogDebug("execute 111111 [" << queryMediaId << "]"); - while( sqlite3_step(pStmt1) == SQLITE_ROW) - { - string mediaId = (char *)sqlite3_column_text(pStmt1, 0); - LogDebug("execute mediaId [" << mediaId << "]"); - newMediaIdList->push_back(mediaId); - } - newFolder->setMediaIdList(newMediaIdList); - sqlite3_finalize(pStmt1); - } - eFolder->addFolder(newFolder); } sqlite3_finalize(pStmt); @@ -308,12 +284,12 @@ void Mediacontent::OnRequestReceived(const IEventFindMediaPtr &eMedia) FilterPtr filter = eMedia->getFilter(); // FIXME validator have to be placed at JS binding. - FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA); +/* FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA); bool success = filter->validate(validator); if(!success) ThrowMsg(InvalidArgumentException, "Invalid filter arguments."); - +*/ IFilterVisitorPtr IVisitor = DPL::StaticPointerCast(visitor); visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA); @@ -397,62 +373,298 @@ void Mediacontent::OnRequestReceived(const IEventFindMediaPtr &eMedia) LogError("Exception: " << ex.DumpToString()); eMedia->setResult(false); } - eMedia->setCancelAllowed(true); - } - -void Mediacontent::OnRequestReceived(const IEventUpdateMediaPtr &eMedia) +void Mediacontent::OnRequestReceived(const IEventBrowseFolderPtr &eBrowse) { - LogDebug("OnRequestReceived::IEventUpdateMediaPtr entered"); + LogDebug("OnRequestReceived::IEventFindMediaPtr entered"); - try + string projection; + string sortMode; + string limitOffset; + string condition; + + string query(VIEW_MEDIA_QUERY_WITH_FOLDER); + std::stringstream folderStream; + folderStream <<" and folder_uuid='" << eBrowse->getFolderID() <<"' "; + query.append(folderStream.str()); + + MediaSearchVisitorPtr visitor(new MediaSearchVisitor()); + + if(eBrowse->getFilterIsSet()) { - MediacontentMediaPtr mediaPtr = eMedia->getMediaItem(); - string type = mediaPtr->getMediaType(); - - if(type.compare("IMAGE")==0) + FilterPtr filter = eBrowse->getFilter(); + + // FIXME validator have to be placed at JS binding. + FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA); + bool success = filter->validate(validator); + + if(!success) + ThrowMsg(InvalidArgumentException, "Invalid filter arguments."); + + IFilterVisitorPtr IVisitor = DPL::StaticPointerCast(visitor); + + visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA); + filter->travel(IVisitor); + condition = visitor->getResult(); + query.append(" and "); + query.append(condition); + } + + if(eBrowse->getSortModesIsSet()) + { + sortMode = makeQuerySortMode(eBrowse->getSortModes()); + + query.append(sortMode); + } + if (eBrowse->getLimitIsSet()) + { + limitOffset.append(" LIMIT "); + std::stringstream limitStream; + limitStream << eBrowse->getLimit(); + limitOffset.append(limitStream.str()); + if(eBrowse->getOffsetIsSet()) + { + limitOffset.append(" OFFSET "); + std::stringstream offsetStream; + offsetStream << eBrowse->getOffset(); + limitOffset.append(offsetStream.str()); + } + + query.append(limitOffset); + } + + LogDebug("execute condition [" << condition << "]"); + LogDebug("execute projection [" << projection << "]"); + LogDebug("execute sortMode [" << sortMode << "]"); + LogDebug("execute limitOffset [" << limitOffset << "]"); + LogDebug("execute query [" << query << "]"); + + int ret; + try + { + sqlite3_stmt* pStmt = NULL; + int content_type; + ret = sqlite3_prepare_v2(hDBCt, (char *)(query.c_str()), query.length(), &pStmt, NULL); + + while( sqlite3_step(pStmt) == SQLITE_ROW) { - LogDebug("Image11"); - MediacontentImagePtr imagePtr = DPL::DynamicPointerCast(mediaPtr); - if(imagePtr != NULL) + + content_type = sqlite3_column_int(pStmt, 2); + + if(content_type == MEDIA_TYPE_IMAGE) + { + + MediacontentImage *newImage(new MediacontentImage()); + readImageFromDB(pStmt,newImage); + eBrowse->addMedia(newImage); + } + else if(content_type == MEDIA_TYPE_VIDEO) + { + MediacontentVideo *newVideo(new MediacontentVideo()); + readVideoFromDB(pStmt,newVideo); + eBrowse->addMedia(newVideo); + } + else if(content_type == MEDIA_TYPE_AUDIO) { - LogDebug("Image22"); + MediacontentAudio *newVAudio(new MediacontentAudio()); + readAudioFromDB(pStmt,newVAudio); + eBrowse->addMedia(newVAudio); + } + } - if(type.compare("VIDEO")==0) + sqlite3_finalize(pStmt); + eBrowse->setResult(true); + + } + catch (const Exception &ex) + { + LogError("Exception: " << ex.DumpToString()); + eBrowse->setResult(false); + } + + eBrowse->setCancelAllowed(true); + +} + +bool Mediacontent::updateMediaToDB(MediacontentMediaPtr mediaPtr) +{ + int err; + char *errMsg = NULL; + + bool ret = false; + string type = mediaPtr->getMediaType(); + + if(type.compare("IMAGE")==0) + { + LogDebug("Image11"); + MediacontentImagePtr imagePtr = DPL::DynamicPointerCast(mediaPtr); + if(imagePtr != NULL) { - LogDebug("Video11"); - MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast(mediaPtr); - if(videoPtr != NULL) + string query; + LogDebug("Image22"); + if(imagePtr->getIsChangedFavorite()) { - LogDebug("video22"); - } + query.append("update visual_media set rating="); + std::stringstream offsetStream; + offsetStream << imagePtr->getFavorite(); + query.append(offsetStream.str()); + query.append(" where visual_uuid='"); + query.append(imagePtr->getMediaUUID()); + query.append("'"); + LogDebug("QUERY : " << query); + + err = sqlite3_exec(hDBCt, query.c_str(), NULL, NULL, &errMsg); + if (SQLITE_OK != err) + { + if(errMsg) + { + sqlite3_free(errMsg); + } + } + } } - if(type.compare("AUDIO")==0) + ret = true; + } + if(type.compare("VIDEO")==0) + { + LogDebug("Video11"); + MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast(mediaPtr); + if(videoPtr != NULL) { - LogDebug("Audio11"); - MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast(mediaPtr); - if(audioPtr != NULL) + string query; + if(videoPtr->getIsChangedFavorite()) { - LogDebug("audio22"); - } - } + std::stringstream offsetStream; + offsetStream << "update visual_media set rating=" << videoPtr->getFavorite() << " where visual_uuid=" << "'" << videoPtr->getMediaUUID() << "'"; + query = offsetStream.str(); + err = sqlite3_exec(hDBCt, query.c_str(), NULL, NULL, &errMsg); + if (SQLITE_OK != err) + { + if(errMsg) + { + sqlite3_free(errMsg); + } + } + } + if(videoPtr->isChangedPlayedTime() || videoPtr->isChangedPlayCount()) + { + std::stringstream offsetStream; + offsetStream << "update video_meta set last_played_time=" << videoPtr->getVideoPlayedTime() << " where visual_uuid=" << "'" << videoPtr->getMediaUUID() << "'"; + query = offsetStream.str(); + err = sqlite3_exec(hDBCt, query.c_str(), NULL, NULL, &errMsg); + if (SQLITE_OK != err) + { + if(errMsg) + { + sqlite3_free(errMsg); + } + } + } + } + ret = true; + } + if(type.compare("AUDIO")==0) + { + LogDebug("Audio11"); + MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast(mediaPtr); + if(audioPtr != NULL) + { + string query; + if(audioPtr->getIsChangedFavorite()) + { + std::stringstream offsetStream; + offsetStream << "update audio_media set rating=" << audioPtr->getFavorite() << " where audio_uuid=" << "'" << audioPtr->getMediaUUID() << "'"; + query = offsetStream.str(); + err = sqlite3_exec(hDBCt, query.c_str(), NULL, NULL, &errMsg); + if (SQLITE_OK != err) + { + if(errMsg) + { + sqlite3_free(errMsg); + //throw error + } + + } + } + if(audioPtr->isChangedPlayedTime() || audioPtr->isChangedPlayCount()) + { + std::stringstream offsetStream; + offsetStream << "update audio_media set last_played_time=" <getAudioPlayedTime()<< ",played_count="<getAudioPlayCount()<<" where audio_uuid=" << "'" << audioPtr->getMediaUUID() << "'"; + query = offsetStream.str(); + err = sqlite3_exec(hDBCt, query.c_str(), NULL, NULL, &errMsg); + if (SQLITE_OK != err) + { + if(errMsg) + { + sqlite3_free(errMsg); + //throw error + } + } + } + } + ret = true; + } + return ret; +} - eMedia->setResult(true); +void Mediacontent::OnRequestReceived(const IEventUpdateMediaPtr &eMedia) +{ + LogDebug("OnRequestReceived::IEventUpdateMediaPtr entered"); + try + { + MediacontentMediaPtr mediaPtr = eMedia->getMediaItem(); + + if(updateMediaToDB(mediaPtr)) + { + eMedia->setResult(true); + } + else + { + eMedia->setResult(false); + } } catch (const Exception &ex) { LogError("Exception: " << ex.DumpToString()); eMedia->setResult(false); } - eMedia->setCancelAllowed(true); - } +void Mediacontent::OnRequestReceived(const IEventUpdateMediaItemsPtr &eItems) +{ + LogDebug("OnRequestReceived::IEventUpdateMediaItemsPtr entered"); + + try + { + MediacontentMediaListPtr mediaListPtr = eItems->getMediaItems(); + if (mediaListPtr->empty()) + { + ThrowMsg(NullPointerException, "Item vector parameter is empty"); + } + + for(unsigned int i=0; isize(); i++) + { + MediacontentMediaPtr mediaPtr = mediaListPtr->at(i); + if(!updateMediaToDB(mediaPtr)) + { + ThrowMsg(NullPointerException, "DB operation is failed"); + } + } + eItems->setResult(true); + } + catch (const Exception &ex) + { + LogError("Exception: " << ex.DumpToString()); + eItems->setResult(false); + } + eItems->setCancelAllowed(true); + +} void Mediacontent::readImageFromDB(sqlite3_stmt* pStmt, MediacontentImage* newImage) { diff --git a/src/platform/Tizen/Mediacontent/Mediacontent.h b/src/platform/Tizen/Mediacontent/Mediacontent.h index ba2025a..5ba3006 100644 --- a/src/platform/Tizen/Mediacontent/Mediacontent.h +++ b/src/platform/Tizen/Mediacontent/Mediacontent.h @@ -25,6 +25,8 @@ #include "API/Mediacontent/IEventFindFolder.h" #include "API/Mediacontent/IEventFindMedia.h" #include "API/Mediacontent/IEventUpdateMedia.h" +#include "API/Mediacontent/IEventUpdateMediaItems.h" + #include #include @@ -63,12 +65,15 @@ class Mediacontent : public Api::Mediacontent::IMediacontent virtual void OnRequestReceived(const IEventFindMediaPtr &ptr); 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: void convertToPlatformFolder(folder_s &media_folder, MediacontentFolderPtr& newFolder); void readImageFromDB(sqlite3_stmt* pStmt, MediacontentImage* newImage); void readVideoFromDB(sqlite3_stmt* pStmt, MediacontentVideo* newVideo); void readAudioFromDB(sqlite3_stmt* pStmt, MediacontentAudio* newAudio); + bool updateMediaToDB(MediacontentMediaPtr mediaPtr); tm toDateTm(time_t date); string makeQuerySortMode(SortModeArrayPtr attr); diff --git a/src/platform/Tizen/Messaging/FolderQueryGenerator.cpp b/src/platform/Tizen/Messaging/FolderQueryGenerator.cpp index 3f757ba..2a75634 100644 --- a/src/platform/Tizen/Messaging/FolderQueryGenerator.cpp +++ b/src/platform/Tizen/Messaging/FolderQueryGenerator.cpp @@ -111,34 +111,16 @@ namespace TizenApis { } void FolderQueryGenerator::visitAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth){ + Api::Tizen::AnyPtr& matchValue, int depth){ LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]"); - LogDebug("values->size():" << values->size()); - Api::Tizen::FilterType filterType = UNION_FILTER; - - if(matchFlag == MATCH_EXISTS){ - //TODO implement for EXIST - }else if(values->size() == 1){ - AnyPtr matchValue = values->at(0); - visitAttributeEach(attrName, matchFlag, matchValue, depth); - }else{ - visitPreComposite(filterType, depth); - - AnyArray::iterator iter; - for(iter=values->begin(); iter!= values->end(); iter++){ - - if(iter != values->begin()){ + if(matchValue == NULL) + return; - visitInComposite(filterType, depth); - } + LogDebug("matchValue:" << matchValue->toString()); - AnyPtr matchValue = *iter; - visitAttributeEach(attrName, matchFlag, matchValue, depth); - } + visitAttributeEach(attrName, matchFlag, matchValue, depth); - visitPostComposite(filterType, depth); - } LogDebug(">>>"); } diff --git a/src/platform/Tizen/Messaging/FolderQueryGenerator.h b/src/platform/Tizen/Messaging/FolderQueryGenerator.h index 7c4bfea..a3d01e8 100644 --- a/src/platform/Tizen/Messaging/FolderQueryGenerator.h +++ b/src/platform/Tizen/Messaging/FolderQueryGenerator.h @@ -74,7 +74,7 @@ public: 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::AnyArrayPtr& values, int depth); + Api::Tizen::AnyPtr& matchValue, int depth); void visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth); diff --git a/src/platform/Tizen/Messaging/MessageQueryGenerator.cpp b/src/platform/Tizen/Messaging/MessageQueryGenerator.cpp index 7bbbb7d..0277ffc 100755 --- a/src/platform/Tizen/Messaging/MessageQueryGenerator.cpp +++ b/src/platform/Tizen/Messaging/MessageQueryGenerator.cpp @@ -40,7 +40,7 @@ namespace TizenApis { namespace Platform { namespace Messaging { - const std::string MessageQueryGenerator::STRING_MATCH_EXCACTLY = "EXACTLY"; + 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"; @@ -545,34 +545,16 @@ namespace TizenApis { } void MessageQueryGenerator::visitAttribute(std::string& attrName, Api::Tizen::MatchFlag& matchFlag, - Api::Tizen::AnyArrayPtr& values, int depth){ + Api::Tizen::AnyPtr& matchValue, int depth){ LogDebug("<<< attrName:[" << attrName << "], matchFlag:[" << matchFlag << "]"); - LogDebug("values->size():" << values->size()); - Api::Tizen::FilterType filterType = UNION_FILTER; - - if(matchFlag == MATCH_EXISTS){ - //TODO implement for EXIST - }else if(values->size() == 1){ - AnyPtr matchValue = values->at(0); - visitAttributeEach(attrName, matchFlag, matchValue, depth); - }else{ - visitPreComposite(filterType, depth); - - AnyArray::iterator iter; - for(iter=values->begin(); iter!= values->end(); iter++){ + if(matchValue == NULL) + return; - if(iter != values->begin()){ + LogDebug("matchValue:" << matchValue->toString()); - visitInComposite(filterType, depth); - } + visitAttributeEach(attrName, matchFlag, matchValue, depth); - AnyPtr matchValue = *iter; - visitAttributeEach(attrName, matchFlag, matchValue, depth); - } - - visitPostComposite(filterType, depth); - } LogDebug(">>>"); } @@ -619,7 +601,7 @@ namespace TizenApis { std::string tmpStringBuffer; if(matchFlag == Api::Tizen::MATCH_EXACTLY){ - LogDebug("STRING_MATCH_EXCACTLY"); + LogDebug("STRING_MATCH_EXACTLY"); tmpStringBuffer.append(getMatchExactlyClause(attrName, value)); }else if(matchFlag == Api::Tizen::MATCH_CONTAINS){ LogDebug("STRING_MATCH_CONTAINS"); @@ -642,6 +624,10 @@ namespace TizenApis { void MessageQueryGenerator::visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth) { LogDebug("<<< sttrName:[" << attrName <<"]"); + + if(initialValue == NULL || endValue == NULL) + return; + LogDebug("initialVAlue:[" << initialValue->toString() << "]"); LogDebug("endValue:[" << endValue->toString() << "]"); diff --git a/src/platform/Tizen/Messaging/MessageQueryGenerator.h b/src/platform/Tizen/Messaging/MessageQueryGenerator.h index cb9e7e4..c1541d4 100755 --- a/src/platform/Tizen/Messaging/MessageQueryGenerator.h +++ b/src/platform/Tizen/Messaging/MessageQueryGenerator.h @@ -59,7 +59,7 @@ namespace TizenApis { int m_typeProcessing; std::string m_currentType; - static const std::string STRING_MATCH_EXCACTLY; + 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; @@ -79,7 +79,7 @@ namespace TizenApis { 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::AnyArrayPtr& values, int depth); + Api::Tizen::AnyPtr& matchValue, int depth); void visitAttributeRange(std::string& attrName, Api::Tizen::AnyPtr& initialValue, Api::Tizen::AnyPtr& endValue, int depth); std::string getQuery(); diff --git a/src/standards/Tizen/Account/CMakeLists.txt b/src/standards/Tizen/Account/CMakeLists.txt index 64f509e..2fbef2c 100755 --- a/src/standards/Tizen/Account/CMakeLists.txt +++ b/src/standards/Tizen/Account/CMakeLists.txt @@ -1,8 +1,18 @@ set(TARGET_NAME "wrt-plugins-tizen-1.0-account") set(DESTINATION_NAME "tizen-1.0-account") -set(SRCS +set(TARGET_IMPL_NAME "wrt-plugins-tizen-1.0-account-impl") + +include_directories( + ${INCLUDES_PLATFORM_IMPLEMENTATION_ACCOUNT} +) + +set(CMAKE_INSTALL_RPATH + ${CMAKE_INSTALL_RPATH} + ${CMAKE_INSTALL_PREFIX}/${DESTINATION_NAME} +) + +set(SRCS_IMPL ${SRCS_PLATFORM_API_ACCOUNT} - ${SRCS_PLATFORM_API_FILTER} ${SRCS_PLATFORM_IMPLEMENTATION_ACCOUNT} ResponseDispatcher.cpp AccountConverter.cpp @@ -13,24 +23,23 @@ set(SRCS JSAccountServices.cpp JSAccountServiceType.cpp JSAccountServiceProvider.cpp - plugin_initializer.cpp plugin_config.cpp - ../Tizen/FilterConverter.cpp - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp ) -include_directories( - ${INCLUDES_PLATFORM_IMPLEMENTATION_ACCOUNT} +add_library(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL}) +target_link_libraries(${TARGET_IMPL_NAME} + ${LIBS_PLATFORM_IMPLEMENTATION_ACCOUNT} + ${LIBS_COMMON} +) + +set(SRCS + plugin_initializer.cpp ) add_library(${TARGET_NAME} SHARED ${SRCS}) target_link_libraries(${TARGET_NAME} - wrt-plugins-tizen-1.0-tizen - ${LIBS_PLATFORM_IMPLEMENTATION_ACCOUNT} - ${LIBS_COMMON} + ${TARGET_IMPL_NAME} ) -INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_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/Account/JSAccountService.cpp b/src/standards/Tizen/Account/JSAccountService.cpp deleted file mode 100755 index d4fc69d..0000000 --- a/src/standards/Tizen/Account/JSAccountService.cpp +++ /dev/null @@ -1,597 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file JSAccountService.cpp -* @author Jihwa Park (jh7979.park@samsung.com) - * @author Sangtai Kim - * @version 0.1 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include -#include -#include -#include -#include - - -#include "JSAccountManager.h" -#include "AccountConverter.h" -#include "JSAccountService.h" -#include "JSAccount.h" -#include "plugin_config.h" -#include "ResponseDispatcher.h" - -using namespace TizenApis::Api::Account; -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; - -namespace { - -#define TIZEN_ACCOUNT_SERVICE_ATTRIBUTENAME "AccountService" -#define TIZEN_ACCOUNT_SERVICE_PROPERTY_TYPE "type" -#define TIZEN_ACCOUNT_SERVICE_PROPERTY_NAME "name" - - -/** - * @throw InvalidArgumentException If not a callback nor JS null nor JS undefined. - */ -JSValueRef getFunctionOrNull(JSContextRef ctx, - JSValueRef arg) -{ - if (Validator(ctx).isCallback(arg)) { - LogDebug("isCallback"); - return arg; - } else if (!JSValueIsNull(ctx, arg) && !JSValueIsUndefined(ctx, arg)) { - - LogDebug("not Callback"); - ThrowMsg(InvalidArgumentException, "Not a function nor JS null."); - } - return NULL; -} -} - -namespace TizenApis { -namespace Tizen1_0 { -namespace Account{ -JSClassDefinition JSAccountService::m_classInfo = { - 0, - kJSClassAttributeNone, - TIZEN_ACCOUNT_SERVICE_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 JSAccountService::m_property[] = { - { TIZEN_ACCOUNT_SERVICE_PROPERTY_TYPE, JSAccountService::getPropertyType, - NULL, kJSPropertyAttributeReadOnly }, - { TIZEN_ACCOUNT_SERVICE_PROPERTY_NAME, JSAccountService::getPropertyName, - NULL, kJSPropertyAttributeReadOnly }, - { 0, 0, 0, 0 } -}; - -JSStaticFunction JSAccountService::m_function[] = { - { "createAccount", createAccount, kJSPropertyAttributeNone }, - { "addAccount", addAccount, kJSPropertyAttributeNone }, - { "updateAccount", updateAccount, kJSPropertyAttributeNone }, - { "deleteAccount", deleteAccount, kJSPropertyAttributeNone }, - { "getAccounts", findAccounts, kJSPropertyAttributeNone }, - - { 0, 0, 0 } -}; - -JSClassRef JSAccountService::m_jsClassRef = JSClassCreate(JSAccountService::getClassInfo()); - -void JSAccountService::initialize(JSContextRef context, - JSObjectRef object) -{ - LogDebug("entered"); - AccountServicePrivObject *priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - //create default instance - LogWarning("create default instance"); - IAccountServicePtr account = - AccountFactory::getInstance().createAccountObject(); - priv = new AccountServicePrivObject(context, account); - if (!JSObjectSetPrivate(object, static_cast(priv))) { - delete priv; - } - } else { - //can be set by JSMakeObject inside getCalendars method - LogDebug("private object alrerady exists"); - } -} - -void JSAccountService::finalize(JSObjectRef object) -{ - LogDebug("entered"); - AccountServicePrivObject *priv = - static_cast(JSObjectGetPrivate(object)); - delete priv; -} - -const JSClassRef JSAccountService::getClassRef() -{ - if (!m_jsClassRef) { - m_jsClassRef = JSClassCreate(&m_classInfo); - } - return m_jsClassRef; -} - -const JSClassDefinition* JSAccountService::getClassInfo() -{ - return &m_classInfo; -} - -JSValueRef JSAccountService::updateAccount(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - - AccountServicePrivObject *privateObject = - static_cast(JSObjectGetPrivate(thisObject)); - assert(privateObject); - -// AceSecurityStatus status = ACCOUNT_CHECK_ACCESS(privateObject->getContext(),ACCOUNT_FUNCTION_API_UPDATE_ACCOUNT); - - Try - { - IAccountServicePtr accountservice = getAccountService(context, thisObject, exception); - - - if (argumentCount != 1) { - LogError("Wrong number of parameters."); - return JSDOMExceptionFactory::TypeMismatchException.make(context, exception); - } - - - - if (JSValueIsUndefined(context, arguments[0]) ||JSValueIsNull(context, arguments[0])) { - return JSDOMExceptionFactory::InvalidValuesException.make(privateObject->getContext());} - - - JSObjectRef arg = JSValueToObject(context, arguments[0], exception); - - EventAccountPtr account = JSAccount::getIEvent(arg); - if (!JSAccount::validate(context, arg, exception)) { - LogError("account parameter contains errors"); - - return JSValueMakeNull(context); - } - - AccountConverterFactory::ConverterType converter =AccountConverterFactory::getConverter(context); - //EventAccountPtr account = converter->toAccount(arguments[0]); - - if (!account) { - LogError("updateAccount: Failed to update account"); - - return JSDOMExceptionFactory::NotFoundException.make(privateObject->getContext()); - } - - IEventUpdateAccountPtr dplEvent(new IEventUpdateAccount()); - dplEvent->setEvent(account); - dplEvent->setForSynchronousCall(); - accountservice->updateAccount(dplEvent); - - if (dplEvent->getResult()) { - return JSValueMakeNull(context); - } else { - LogError("Unknow error occured."); - return JSDOMExceptionFactory::UnknownException.make(context, exception); - } - } - Catch(InvalidArgumentException) - { - LogError("Invalid argument"); - return JSDOMExceptionFactory::TypeMismatchException.make(context, - exception); - } - Catch(Exception) - { - LogError("unknow error occured"); - } - return JSValueMakeNull(context); -} - -JSValueRef JSAccountService::deleteAccount(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - AccountServicePrivObject *privateObject = - static_cast(JSObjectGetPrivate(thisObject)); - assert(privateObject); - JSCallbackManagerPtr cbm(NULL); - -// AceSecurityStatus status = ACCOUNT_CHECK_ACCESS(privateObject->getContext(),ACCOUNT_FUNCTION_API_DELETE_ACCOUNT); - Try - { - IAccountServicePtr accountservice = getAccountService(context, thisObject, exception); - if (argumentCount!=1) { - LogError("Wrong number of parameters."); - return JSDOMExceptionFactory::TypeMismatchException.make(context, exception); - } - - - - //if not able to convert to int then it won't be found - //TODO: Calendar has EventID function. I need to check this later - int id = 0; - Try - { - - AccountConverterFactory::ConverterType converter = AccountConverterFactory::getConverter(context); - id = converter->toInt(converter->toString(arguments[0])); - } - Catch(Exception) - { - LogError("invalid value of id parameter, account will not be found"); - return JSDOMExceptionFactory::NotFoundException.make(privateObject->getContext()); - } - //abstract API use event object as a filter, but only id - //attribute is revelant during delete operation. - EventAccountPtr account(new EventAccount()); - account->setID(id); - IEventDeleteAccountPtr dplEvent(new IEventDeleteAccount()); - dplEvent->setEvent(account); - - dplEvent->setForSynchronousCall(); - accountservice->deleteAccount(dplEvent); - - if (dplEvent->getResult()) { - return JSValueMakeNull(context); - } else { - if (dplEvent->getExceptionCode() == ExceptionCodes::NotFoundException) { - return JSDOMExceptionFactory::NotFoundException.make(context); - } else { - return JSDOMExceptionFactory::UnknownException.make(context); - } - } - } - Catch(InvalidArgumentException) - { - LogError("Invalid argument"); - return JSDOMExceptionFactory::TypeMismatchException.make(context, - exception); - } - Catch(Exception) - { - LogError("unknow error occured"); - } - - return JSValueMakeNull(context); -} - -JSValueRef JSAccountService::createAccount(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - - AccountServicePrivObject *privateObject = - static_cast(JSObjectGetPrivate(thisObject)); - assert(privateObject); - - Try - { - // We need to use the global context for the event creation to invoke TZDate functions. - JSObjectRef jsObject = JSObjectMake(privateObject->getContext(), - JSAccount::getClassRef(), NULL); - if (jsObject == NULL) { - LogError("CreateEvent: failed to create object reference"); - return JSDOMExceptionFactory::UnknownException.make(context, exception); - } - if (argumentCount >= 1 && - !JSValueIsUndefined(context, arguments[0]) && - !JSValueIsNull(context, arguments[0])) { - //set properties if declared - LogDebug("setting properties"); - AccountConverterFactory::ConverterType converter = - AccountConverterFactory::getConverter(context); - EventAccountPtr event = converter->toAccount(arguments[0]); - - - JSAccount::setIEvent(event, privateObject->getContext(), jsObject); - } else { - - //TODO: check if No default value for Account - //set default values - /* - EventAccountPtr account = JSAccount::getIEvent(jsObject); - event->setStartTime(std::time(NULL)); - event->setEndTime(event->getStartTime()); - event->setStatus(CalendarEvent::CONFIRMED_STATUS); - */ - } - return static_cast(jsObject); - } - Catch(ConversionException) - { - LogError("conversion error"); - return JSDOMExceptionFactory::InvalidValuesException.make(context, - exception); - } - Catch(Exception) - { - LogError("error during execution"); - } - return JSDOMExceptionFactory::UnknownException.make(context, exception); -} - - -JSValueRef JSAccountService::addAccount(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - - AccountServicePrivObject *privateObject = - static_cast(JSObjectGetPrivate(thisObject)); - LogDebug("jcpark 1"); - assert(privateObject); - //JSCallbackManagerPtr cbm(NULL); - LogDebug("jcpark 2"); - //TODO: down here!! why? - //ACCOUNT_CHECK_ACCESS( privateObject->getContext(),ACCOUNT_FUNCTION_API_ADD_ACCOUNT); - Try - { - LogDebug("1"); - IAccountServicePtr accountservice = getAccountService(context, thisObject, NULL); - LogDebug("2"); - if (argumentCount != 1) { - LogError("Wrong number of parameters."); - return JSDOMExceptionFactory::TypeMismatchException.make(context, exception); - } - LogDebug("3"); - - if (JSValueIsUndefined(context, arguments[0]) || - JSValueIsNull(context, arguments[0])) { - return JSDOMExceptionFactory::InvalidValuesException.make( - privateObject->getContext()); - return JSValueMakeNull(context);} - LogDebug("4"); - LogDebug("setting properties"); - AccountConverterFactory::ConverterType converter = - AccountConverterFactory::getConverter(context); - EventAccountPtr account = converter->toAccount(arguments[0]); - - if (!account) { - LogError("Failed to get an event."); - return JSDOMExceptionFactory::UnknownException.make(privateObject->getContext());} - - IEventAddAccountPtr dplEvent(new IEventAddAccount()); - dplEvent->setEvent(account); - dplEvent->setForSynchronousCall(); - accountservice->addAccount(dplEvent); - - if (dplEvent->getResult()) { - return converter->toJSValueRef(dplEvent->getEvent()->getID()); - } else { - return JSDOMExceptionFactory::UnknownException.make(context, exception);} - - } - Catch(InvalidArgumentException) - { - LogError("Invalid argument"); - return JSDOMExceptionFactory::TypeMismatchException.make(context, - exception); - } - Catch(Exception) - { - LogError("Unexpected error during adding account"); - return JSDOMExceptionFactory::UnknownException.make(privateObject->getContext()); - } - return JSValueMakeNull(context); -} -JSValueRef JSAccountService::findAccounts(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - AccountServicePrivObject *privateObject = - static_cast(JSObjectGetPrivate(thisObject)); - assert(privateObject); -// AceSecurityStatus status = ACCOUNT_CHECK_ACCESS(privateObject->getContext(),ACCOUNT_FUNCTION_API_FIND_ACCOUNTS); - JSCallbackManagerPtr cbm(NULL); - Try - { - LogDebug("2"); - IAccountServicePtr account = getAccountService(context, thisObject, exception); - if (argumentCount < 1) { - LogError("No callback parameters"); - return JSDOMExceptionFactory::TypeMismatchException.make(context, - exception); - } - LogDebug("3"); - JSValueRef onError = - (argumentCount > - 1 ? getFunctionOrNull(context, arguments[1]) : NULL); - JSContextRef globalContext = privateObject->getContext(); - LogDebug("4"); - - cbm = JSCallbackManager::createObject(globalContext, NULL, onError); -// ASYNC_CBM_ACCESS_STATUS_HANDLER(status, context, cbm); - - Validator validator(context); - if (validator.isCallback(arguments[0])) { - cbm->setOnSuccess(arguments[0]); - } else if (JSValueIsNull(context, - arguments[0]) || - JSValueIsUndefined(context, arguments[0])) { - cbm->callOnError(JSDOMExceptionFactory::InvalidValuesException.make( - context)); - return JSValueMakeNull(context); - } else { - return JSDOMExceptionFactory::TypeMismatchException.make(context, - exception); - } - //setup filters - /* EventFilterPtr filter(NULL); - if (argumentCount >= 3) { - LogDebug("setting some filters"); - AccountConverterFactory::ConverterType converter = - AccountConverterFactory::getConverter(context); - Try - { - if (!JSValueIsUndefined(context, - arguments[2]) && - !JSValueIsNull(context, arguments[2])) { - filter = converter->toEventFilter(arguments[2]); - } - } - Catch(InvalidArgumentException) - { - LogError("Invalid argument"); - filter.Reset(); - } - }*/ - LogDebug("6"); - IEventFindAccountsPtr dplEvent(new IEventFindAccounts()); - dplEvent->setPrivateData( - DPL::StaticPointerCast(cbm)); - dplEvent->setForAsynchronousCall( - &AccountResponseDispatcher::getInstance()); - // dplEvent->setFilter(filter); - account->findAccounts(dplEvent); - - return makePendingOperation(cbm->getContext(), dplEvent); - } - Catch(InvalidArgumentException) - { - return JSDOMExceptionFactory::TypeMismatchException.make( - context, exception); - } - Catch(ConversionException) - { - LogError("Invalid argument"); - return JSDOMExceptionFactory::TypeMismatchException.make( - context, exception); - } - Catch(Exception) - { - LogError("unknow error occured"); - } - if (NULL != cbm) { - cbm->callOnError(JSDOMExceptionFactory::UnknownException.make( - privateObject->getContext())); - } - return JSValueMakeNull(context); -} - -IAccountServicePtr JSAccountService::getAccountService(JSContextRef ctx, - const JSObjectRef object, - JSValueRef* exception) -{ - AccountServicePrivObject *priv = - static_cast(JSObjectGetPrivate(object)); - if (priv) { - return priv->getObject(); - } - ThrowMsg(NullPointerException, "Private object is NULL."); -} - -JSValueRef JSAccountService::getPropertyName(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - Try - { - IAccountServicePtr accountservice = getAccountService(context, object, exception); - Converter converter(context); - return converter.toJSValueRef(accountservice->getName()); - } - Catch(Exception) - { - LogError("error during executing a function"); - } - return JSValueMakeUndefined(context); -} - -JSValueRef JSAccountService::getPropertyType(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - Try - { - IAccountServicePtr accountservice = getAccountService(context, object, exception); - int accountserviceType = accountservice->getType(); - Converter converter(context); - switch (accountserviceType) { -/* case IAccountService::TYPE_SIM: - return converter.toJSValueRef( - JSAccountManager::TYPE_SIM); - break;*/ - case IAccountService::TYPE_INTERNET: - return converter.toJSValueRef(JSAccountManager::TYPE_INTERNET); - break; - default: - LogWarning("invalid type of accountservice"); - break; - } - } - Catch(Exception) - { - LogError("error during executing a function"); - } - return JSValueMakeUndefined(context); -} - -} -} -} diff --git a/src/standards/Tizen/Account/JSAccountService.h b/src/standards/Tizen/Account/JSAccountService.h deleted file mode 100755 index 523dec3..0000000 --- a/src/standards/Tizen/Account/JSAccountService.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/* - * @file JSAccountService.h - * @author Jihwa Park (jh7979.park@samsung.com) - * @author Sangtai Kim - * @version 0.1 - */ - -#ifndef _JS_TIZEN_ACCOUNTSERVICE_H_ -#define _JS_TIZEN_ACCOUNTSERVICE_H_ - -#include -#include -#include -#include -#include -#include - - -using namespace TizenApis::Api::Account; -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; - -namespace TizenApis { -namespace Tizen1_0 { -namespace Account{ -typedef PrivateObject AccountServicePrivObject; - -class JSAccountService -{ - 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 getPropertyType(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - - - /** - * Update an event. - */ - static JSValueRef updateAccount(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception); - - /** - * Delete a calendar event. - */ - static JSValueRef deleteAccount(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception); - - /** - * Search for calendar events. - */ - static JSValueRef findAccounts(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception); - - /** - * Create Events - */ - static JSValueRef createAccount(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception); - - - /** - * Add Event - */ - static JSValueRef addAccount(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception); - - /** - * Returns calendar stored as private object - */ - static IAccountServicePtr getAccountService(JSContextRef ctx, - const JSObjectRef object, - JSValueRef* exception); - - -}; -} -} -} - -#endif /* _JS_TIZEN_ACCOUNTSERVICE_H_ */ - diff --git a/src/standards/Tizen/Alarm/AlarmAbsolute.cpp b/src/standards/Tizen/Alarm/AlarmAbsolute.cpp index 5e1565b..a5d50fa 100755 --- a/src/standards/Tizen/Alarm/AlarmAbsolute.cpp +++ b/src/standards/Tizen/Alarm/AlarmAbsolute.cpp @@ -15,6 +15,10 @@ */ #include "AlarmAbsolute.h" +#include "alarm_common.h" +#include +#include +#include namespace TizenApis { namespace Api { @@ -22,12 +26,23 @@ namespace Alarm { AlarmAbsolute::AlarmAbsolute() { - m_alarmRecurrence = AlarmRecurrencePtr(new AlarmRecurrence()); 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 @@ -50,56 +65,60 @@ void AlarmAbsolute::setIsRecurrence(bool value) m_isRecurrence = value; } -AlarmRecurrencePtr AlarmAbsolute::getRecurrence() -{ - return m_alarmRecurrence; -} -void AlarmAbsolute::setRecurrence(AlarmRecurrencePtr ptr) -{ - m_alarmRecurrence->setData(ptr); -} - void AlarmAbsolute::setDate(struct tm date) { - LogError("=== Before Assign ==="); - LogError("[ILOVEFILM] 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); + char strDate[19]; m_date = date; - LogError("=== After Assign ==="); - LogError("[ILOVEFILM] Date = " << " Sec : " << m_date.tm_sec << " Min : "<< m_date.tm_min + + 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() { - LogError("[ILOVEFILM] 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); return m_date; } -void AlarmAbsolute::setDelay(int delay) +void AlarmAbsolute::setInterval(int interval) { - m_delay = delay; + 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::getDelay() +int AlarmAbsolute::getInterval() { - return m_delay; + return m_interval; } -void AlarmAbsolute::setAlarmType(alarm_type_e type) +void AlarmAbsolute::setByDayRecurrence(std::vector &daysOfTheWeek) { - m_alarmType = type; + m_recurrenceType = AbsoluteRecurrence::ByDayValue; + m_daysOfTheWeek = daysOfTheWeek; + service_add_extra_data(m_service_handle, ALARM_ALSOLUTE_RECURRENCE_TYPE_KEY, ALARM_ALSOLUTE_RECURRENCE_TYPE_BYDAYVALUE); } -AlarmAbsolute::alarm_type_e AlarmAbsolute::getAlarmType() + +std::vector AlarmAbsolute::getByDayRecurrence() { - return m_alarmType; + 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 index 26c74bc..1c74fca 100755 --- a/src/standards/Tizen/Alarm/AlarmAbsolute.h +++ b/src/standards/Tizen/Alarm/AlarmAbsolute.h @@ -6,12 +6,15 @@ #include #include #include -#include "AlarmRecurrence.h" - +#include +#include "alarm_common.h" + namespace TizenApis { namespace Api { namespace Alarm { +using namespace TizenApis::Tizen1_0::Alarm; + class AlarmAbsolute; typedef DPL::SharedPtr AlarmAbsolutePtr; typedef std::vector AlarmAbsoluteArrayPtr; @@ -19,34 +22,30 @@ typedef std::vector AlarmAbsoluteArrayPtr; class AlarmAbsolute { public: - typedef enum { - ALARM_TYPE_DELAY, - ALARM_TYPE_DATE, - ALARM_TYPE_INVALID, - } alarm_type_e; - AlarmAbsolute(); + AlarmAbsolute(service_h handle); ~AlarmAbsolute(); - AlarmRecurrencePtr getRecurrence(); - void setRecurrence(AlarmRecurrencePtr ptr); - void setIsRecurrence(bool value); int getId() const; void setId(const int id); void setDate(struct tm date); struct tm getDate(); - void setDelay(int delay); - int getDelay(); - void setAlarmType(alarm_type_e type); - alarm_type_e getAlarmType(); + void setInterval(int interval); + int getInterval(); bool isRecurrence(); + void setIsRecurrence(bool value); + void setByDayRecurrence(std::vector &daysOfTheWeek); + std::vector getByDayRecurrence(); + AbsoluteRecurrence::Type getRecurrenceType(); + service_h getService(); private: int m_id; - int m_delay; struct tm m_date; bool m_isRecurrence; - AlarmRecurrencePtr m_alarmRecurrence; - alarm_type_e m_alarmType; + int m_interval; + service_h m_service_handle; + std::vector m_daysOfTheWeek; + AbsoluteRecurrence::Type m_recurrenceType; }; diff --git a/src/standards/Tizen/Alarm/AlarmConverter.cpp b/src/standards/Tizen/Alarm/AlarmConverter.cpp index 59e69e7..23d39d5 100755 --- a/src/standards/Tizen/Alarm/AlarmConverter.cpp +++ b/src/standards/Tizen/Alarm/AlarmConverter.cpp @@ -22,11 +22,11 @@ #include #include #include -#include "AlarmRecurrence.h" -#include "JSAlarmRecurrence.h" #include "AlarmConverter.h" - - +#include "JSAlarmAbsolute.h" +#include "AlarmAbsolute.h" +#include "JSAlarmRelative.h" +#include "AlarmRelative.h" namespace TizenApis { namespace Tizen1_0 { @@ -35,7 +35,6 @@ namespace Alarm { using namespace WrtDeviceApis::Commons; using namespace WrtDeviceApis::CommonsJavaScript; using namespace TizenApis::Tizen1_0::Alarm; -using namespace TizenApis::Api::Alarm; AlarmConverter::AlarmConverter(JSContextRef context) : WrtDeviceApis::CommonsJavaScript::Converter(context) { @@ -47,41 +46,7 @@ AlarmConverter::~AlarmConverter() } -AlarmRecurrence::alarm_frequency_e AlarmConverter::toRecurrenceFrequency( - std::string tizenValue) const -{ - if (!tizenValue.compare(TIZEN_ALARM_PROPERTY_MINUTELY_RECURRENCE)) - return AlarmRecurrence::MINUTELY_RECURRENCE; - else if (!tizenValue.compare(TIZEN_ALARM_PROPERTY_HOURLY_RECURRENCE)) - return AlarmRecurrence::HOURLY_RECURRENCE; - else if (!tizenValue.compare(TIZEN_ALARM_PROPERTY_DAILY_RECURRENCE)) - return AlarmRecurrence::DAILY_RECURRENCE; - else if (!tizenValue.compare(TIZEN_ALARM_PROPERTY_WEEKLY_RECURRENCE)) - return AlarmRecurrence::WEEKLY_RECURRENCE; - - return AlarmRecurrence::NO_RECURRENCE; -} - -std::string AlarmConverter::toTizenValue( - AlarmRecurrence::alarm_frequency_e frequency ) const -{ - switch (frequency) { - case AlarmRecurrence::MINUTELY_RECURRENCE: - return TIZEN_ALARM_PROPERTY_MINUTELY_RECURRENCE; - case AlarmRecurrence::HOURLY_RECURRENCE: - return TIZEN_ALARM_PROPERTY_HOURLY_RECURRENCE; - case AlarmRecurrence::DAILY_RECURRENCE: - return TIZEN_ALARM_PROPERTY_DAILY_RECURRENCE; - case AlarmRecurrence::WEEKLY_RECURRENCE: - return TIZEN_ALARM_PROPERTY_WEEKLY_RECURRENCE; - default: - return ""; - break; - } -} - - -int toNativeValue(std::vector daysOfTheWeek) +int AlarmConverter::toNativeAlarmValue(std::vector daysOfTheWeek) { int nativeValue = 0; @@ -105,6 +70,26 @@ int toNativeValue(std::vector daysOfTheWeek) return nativeValue; } +std::vector AlarmConverter::convertFlagToDaysOfTheWeek(int byDayValue) +{ + std::vector 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"); +} + service_h AlarmConverter::toService(std::string id) { @@ -127,6 +112,106 @@ service_h AlarmConverter::toService(std::string id, std::string page) service_set_package(service, id.c_str()); return service; } + +bool AlarmConverter::toAlarmAbsolutePtr(int id, service_h handle, AlarmAbsolutePtr privateData) +{ + char* dateString; + char* alarmType; + int delay; + struct tm date; + int bydayValue = 0; + 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 NULL; + 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); + privateData->setInterval(interval); + } else if(!strcmp(alarmType, ALARM_ALSOLUTE_RECURRENCE_TYPE_BYDAYVALUE)) { + int byDayValue =0; + error = alarm_get_scheduled_recurrence_week_flag(id, &byDayValue); + if(error == ALARM_ERROR_NONE && bydayValue > 0) { + std::vector result; + result = convertFlagToDaysOfTheWeek(byDayValue); + privateData->setByDayRecurrence(result); + } + } + + 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; + 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; +} + + } } } diff --git a/src/standards/Tizen/Alarm/AlarmConverter.h b/src/standards/Tizen/Alarm/AlarmConverter.h index 985560f..8815ce8 100755 --- a/src/standards/Tizen/Alarm/AlarmConverter.h +++ b/src/standards/Tizen/Alarm/AlarmConverter.h @@ -23,7 +23,11 @@ #include #include #include -#include "AlarmRecurrence.h" +#include "JSAlarmAbsolute.h" +#include "AlarmAbsolute.h" +#include "JSAlarmRelative.h" +#include "AlarmRelative.h" + namespace TizenApis { namespace Tizen1_0 { @@ -31,8 +35,7 @@ namespace Alarm { using namespace WrtDeviceApis::Commons; using namespace WrtDeviceApis::CommonsJavaScript; -using namespace TizenApis::Api::Alarm; - +using namespace TizenApis::Tizen1_0::Alarm; class AlarmConverter : public WrtDeviceApis::CommonsJavaScript::Converter { @@ -41,12 +44,15 @@ public: explicit AlarmConverter(JSContextRef context); virtual ~AlarmConverter(); - AlarmRecurrence::alarm_frequency_e toRecurrenceFrequency(std::string tizenValue) const; - std::string toTizenValue(AlarmRecurrence::alarm_frequency_e frequency ) const; - int toNativeValue(std::vector daysOfTheWeek); - int toNativeValue(int interval); + int toNativeAlarmValue(std::vector daysOfTheWeek); + std::vector convertFlagToDaysOfTheWeek(int byDayValue); + int toNativeValue(int interval); + std::vector 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); }; typedef ConverterFactory AlarmConverterFactory; diff --git a/src/standards/Tizen/Alarm/AlarmRecurrence.cpp b/src/standards/Tizen/Alarm/AlarmRecurrence.cpp deleted file mode 100755 index 238d5c7..0000000 --- a/src/standards/Tizen/Alarm/AlarmRecurrence.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "AlarmRecurrence.h" - -namespace TizenApis { -namespace Api { -namespace Alarm { - -AlarmRecurrence::AlarmRecurrence() -{ - m_frequency = NO_RECURRENCE; - m_interval = 0; -} - -AlarmRecurrence::~AlarmRecurrence() -{ -} - -void AlarmRecurrence::setFrequency(AlarmRecurrence::alarm_frequency_e frequency) -{ - m_frequency = frequency; -} - -AlarmRecurrence::alarm_frequency_e AlarmRecurrence::getFrequency() -{ - return m_frequency; -} -void AlarmRecurrence::setInterval(int interval) -{ - m_interval = interval; -} -int AlarmRecurrence::getInterval() -{ - return m_interval; -} -void AlarmRecurrence::setDaysOfTheWeek(std::vector daysOfTheWeek) -{ - // copy vector - m_daysOfTheWeek.clear(); - m_daysOfTheWeek.assign(daysOfTheWeek.begin(), daysOfTheWeek.end()); - m_frequency = DAYS_OF_THE_WEEK_RECURRENCE; -} -std::vector AlarmRecurrence::getDaysOfTheWeek() -{ - return m_daysOfTheWeek; -} - -void AlarmRecurrence::setData(AlarmRecurrencePtr ptr) -{ - setFrequency(ptr->getFrequency()); - setInterval(ptr->getInterval()); - setDaysOfTheWeek(ptr->getDaysOfTheWeek()); -} - -} -} -} - diff --git a/src/standards/Tizen/Alarm/AlarmRecurrence.h b/src/standards/Tizen/Alarm/AlarmRecurrence.h deleted file mode 100755 index 04b7209..0000000 --- a/src/standards/Tizen/Alarm/AlarmRecurrence.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef TIZENAPIS_API_ALARMRECURRENCE_H_ -#define TIZENAPIS_API_ALARMRECURRENCE_H_ - -#include -#include -#include -#include - -namespace TizenApis { -namespace Api { -namespace Alarm { - -class AlarmRecurrence; -typedef DPL::SharedPtr AlarmRecurrencePtr; - -class AlarmRecurrence -{ - public: - typedef enum - { - NO_RECURRENCE, - MINUTELY_RECURRENCE = 60, // The alarm trigger minutely - HOURLY_RECURRENCE = 3600, // The alarm trigger hourly - DAILY_RECURRENCE = 86400, // The alarm trigger daily - WEEKLY_RECURRENCE = 604800, // The alarm trigger weekly - DAYS_OF_THE_WEEK_RECURRENCE, - INVALID_RECURRENCE = 1000000, - } alarm_frequency_e; - - AlarmRecurrence(); - ~AlarmRecurrence(); - void setFrequency(AlarmRecurrence::alarm_frequency_e frequency); - AlarmRecurrence::alarm_frequency_e getFrequency(); - void setInterval(int interval); - int getInterval(); - void setDaysOfTheWeek(std::vector daysOfTheWeek); - std::vector getDaysOfTheWeek(); - void setData(AlarmRecurrencePtr ptr); - - private: - alarm_frequency_e m_frequency; - int m_interval; - std::vector m_daysOfTheWeek; -}; - - -} -} -} - -#endif diff --git a/src/standards/Tizen/Alarm/AlarmRelative.cpp b/src/standards/Tizen/Alarm/AlarmRelative.cpp index 7d2f647..59ce270 100755 --- a/src/standards/Tizen/Alarm/AlarmRelative.cpp +++ b/src/standards/Tizen/Alarm/AlarmRelative.cpp @@ -15,6 +15,9 @@ */ #include "AlarmRelative.h" +#include "alarm_common.h" +#include +#include namespace TizenApis { namespace Api { @@ -22,12 +25,23 @@ namespace Alarm { AlarmRelative::AlarmRelative() { - m_alarmRecurrence = AlarmRecurrencePtr(new AlarmRecurrence()); 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 @@ -50,38 +64,11 @@ void AlarmRelative::setIsRecurrence(bool value) m_isRecurrence = value; } -AlarmRecurrencePtr AlarmRelative::getRecurrence() -{ - return m_alarmRecurrence; -} -void AlarmRelative::setRecurrence(AlarmRecurrencePtr ptr) -{ - m_alarmRecurrence->setData(ptr); -} - -void AlarmRelative::setDate(struct tm date) -{ - LogError("=== Before Assign ==="); - LogError("[ILOVEFILM] 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); - m_date = date; - LogError("=== After Assign ==="); - LogError("[ILOVEFILM] 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 AlarmRelative::getDate() -{ - LogError("[ILOVEFILM] 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); - return m_date; -} - 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; } @@ -90,15 +77,23 @@ int AlarmRelative::getDelay() return m_delay; } -void AlarmRelative::setAlarmType(alarm_type_e type) +void AlarmRelative::setPeriod(int value) { - m_alarmType = type; + LogInfo("Param Peroid = " << value); + m_Period = value; + LogInfo("Setted Period = " << m_Period); } -AlarmRelative::alarm_type_e AlarmRelative::getAlarmType() + +int AlarmRelative::getPeriod() { - return m_alarmType; + 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 index e971a19..a304ae8 100755 --- a/src/standards/Tizen/Alarm/AlarmRelative.h +++ b/src/standards/Tizen/Alarm/AlarmRelative.h @@ -6,12 +6,15 @@ #include #include #include -#include "AlarmRecurrence.h" - +#include +#include "alarm_common.h" + namespace TizenApis { namespace Api { namespace Alarm { +using namespace TizenApis::Tizen1_0::Alarm; + class AlarmRelative; typedef DPL::SharedPtr AlarmRelativePtr; typedef std::vector AlarmRelativeArrayPtr; @@ -26,27 +29,24 @@ class AlarmRelative } alarm_type_e; AlarmRelative(); + AlarmRelative(service_h handle); ~AlarmRelative(); - AlarmRecurrencePtr getRecurrence(); - void setRecurrence(AlarmRecurrencePtr ptr); void setIsRecurrence(bool value); int getId() const; void setId(const int id); - void setDate(struct tm date); - struct tm getDate(); void setDelay(int delay); int getDelay(); - void setAlarmType(alarm_type_e type); - alarm_type_e getAlarmType(); bool isRecurrence(); + void setPeriod(int value); + int getPeriod(); + service_h getService(); private: int m_id; int m_delay; - struct tm m_date; bool m_isRecurrence; - AlarmRecurrencePtr m_alarmRecurrence; - alarm_type_e m_alarmType; + int m_Period; + service_h m_service_handle; }; diff --git a/src/standards/Tizen/Alarm/CMakeLists.txt b/src/standards/Tizen/Alarm/CMakeLists.txt index 4ba0e7b..f3026c0 100755 --- a/src/standards/Tizen/Alarm/CMakeLists.txt +++ b/src/standards/Tizen/Alarm/CMakeLists.txt @@ -4,20 +4,21 @@ pkg_search_module(alarm REQUIRED capi-appfw-application) include_directories(${alarm_INCLUDE_DIRS}) +set(CMAKE_INSTALL_RPATH + ${CMAKE_INSTALL_RPATH} + ${CMAKE_INSTALL_PREFIX}/tizen-1.0-tizen +) + set(SRCS AlarmAbsolute.cpp AlarmConverter.cpp - AlarmRecurrence.cpp AlarmRelative.cpp JSAbstractAlarm.cpp JSAlarmAbsolute.cpp JSAlarmManager.cpp - JSAlarmRecurrence.cpp JSAlarmRelative.cpp plugin_initializer.cpp - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp + plugin_config.cpp ) set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} @@ -26,6 +27,7 @@ set(CMAKE_INSTALL_RPATH add_library(${TARGET_NAME} SHARED ${SRCS}) target_link_libraries(${TARGET_NAME} + wrt-plugins-tizen-1.0-tizen-impl ${LIBS_COMMON} ${alarm_LIBRARIES} ) diff --git a/src/standards/Tizen/Alarm/JSAlarmAbsolute.cpp b/src/standards/Tizen/Alarm/JSAlarmAbsolute.cpp index a8a8921..1c10efd 100755 --- a/src/standards/Tizen/Alarm/JSAlarmAbsolute.cpp +++ b/src/standards/Tizen/Alarm/JSAlarmAbsolute.cpp @@ -24,14 +24,17 @@ #include #include #include +#include + #include "AlarmAbsolute.h" -#include "AlarmRecurrence.h" #include "AlarmConverter.h" #include #include -#include "JSAlarmRecurrence.h" + +#include "plugin_config.h" #include "JSAbstractAlarm.h" #include "JSAlarmAbsolute.h" +#include "JSAlarmManager.h" namespace TizenApis { @@ -42,6 +45,7 @@ using namespace std; using namespace DPL; using namespace WrtDeviceApis::Commons; using namespace WrtDeviceApis::CommonsJavaScript; +using namespace TizenApis::Commons; using namespace TizenApis::Api::Alarm; JSClassRef JSAlarmAbsolute::m_jsClassRef = NULL; @@ -72,8 +76,10 @@ JSStaticFunction JSAlarmAbsolute::m_function[] = { }; JSStaticValue JSAlarmAbsolute::m_property[] = { - { "id", getId, NULL, kJSPropertyAttributeReadOnly }, - { "recurrenceRule", getRecurrenceRule, NULL, kJSPropertyAttributeReadOnly }, + { "id", getId, NULL, kJSPropertyAttributeReadOnly }, + { "date", getDate, NULL, kJSPropertyAttributeReadOnly }, + { "period", getInterval, NULL, kJSPropertyAttributeReadOnly }, + { "daysOfTheWeek", getDaysOfTheWeek, NULL, kJSPropertyAttributeReadOnly }, { 0, 0, 0, 0 } }; @@ -92,10 +98,14 @@ const JSClassDefinition* JSAlarmAbsolute::getClassInfo() void JSAlarmAbsolute::initialize(JSContextRef context, JSObjectRef object) { - } void JSAlarmAbsolute::finalize(JSObjectRef object) { + JSAlarmAbsolutePriv *priv = static_cast(JSObjectGetPrivate(object)); + if (!priv) { + LogError("Private object is null"); + } + delete priv; } @@ -113,85 +123,97 @@ JSObjectRef JSAlarmAbsolute::constructor(JSContextRef ctx, JSObjectRef construct int interval =0; AlarmConverter converter(ctx); Validator validator(ctx); - bool isRecurrence = false; - - if(argumentCount < 1) - { - LogWarning("Argument is not corrent"); - } - - if( validator.isDate(arguments[0])) - { - // date + + Try { + AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute()); + + if(argumentCount < 1) + { + ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Wrong argumentCount"); + } + + if(!validator.isDate(arguments[0])) + { + ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"Invalid Date"); + } + date = converter.toDateTm(arguments[0]); - LogWarning("Argument is not corrent"); - } - - if(argumentCount == 2) - { - // TODO : check it is TimeDuration object. - #if 0 - if(JSValueIsObjectOfClass(ctx, arguments[1], JSAlarmRecurrence::getClassRef())) + privateData->setDate(date); + + if(argumentCount >= 2) { - // TODO : Get interval from TimeUnit - isRecurrence = true; + if(JSValueIsNumber(ctx, arguments[1])) + { + int interval = JSValueToNumber(ctx, arguments[1], exception); + privateData->setInterval(interval); + } else if(JSIsArrayValue(ctx, arguments[1])) { + std::vector daysOfTheWeek = converter.toVectorOfStrings(arguments[1]); + if(daysOfTheWeek.size() >0) { + privateData->setByDayRecurrence(daysOfTheWeek); + } + } } - #endif + return JSValueToObject(ctx, createJSObject(ctx, privateData), exception); + } Catch (WrtDeviceApis::Commons::ConversionException) { + *exception = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(ctx,TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + return NULL; + } Catch(WrtDeviceApis::Commons::InvalidArgumentException) { + *exception = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(ctx,TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + return NULL; + } Catch(WrtDeviceApis::Commons::NullPointerException) { + *exception = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(ctx,TizenApis::Commons::JSTizenException::UNKNOWN_ERROR, "Unknown error"); + return NULL; + } Catch (WrtDeviceApis::Commons::Exception) { + *exception = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(ctx,TizenApis::Commons::JSTizenException::UNKNOWN_ERROR, "Unknown error"); + return NULL; } - if(isRecurrence == true) { - return JSValueToObject(ctx, createJSObject(ctx, date, interval), exception); - } - else - { - return JSValueToObject(ctx, createJSObject(ctx, date), exception); - } - - } AlarmAbsolutePtr JSAlarmAbsolute::getPrivData(JSObjectRef object) { - JSAlarmAbsolutePriv *priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - AlarmAbsolutePtr result = priv->getObject(); - if (!result) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - return result; + JSAlarmAbsolutePriv *priv = static_cast(JSObjectGetPrivate(object)); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + AlarmAbsolutePtr result = priv->getObject(); + if (!result) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + return result; } JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, const int id) { - AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute()); - + AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute()); privateData->setId(id); + + JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object"); + } + return JSObjectMake(context, getClassRef(), static_cast(priv)); +} +JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, AlarmAbsolutePtr privateData) +{ JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object"); } - return jsValueRef; + return JSObjectMake(context, getClassRef(), static_cast(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); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object"); } - return jsValueRef; - + return JSObjectMake(context, getClassRef(), static_cast(priv)); } JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, struct tm date) @@ -200,41 +222,72 @@ JSValueRef JSAlarmAbsolute::createJSObject(JSContextRef context, struct tm date) privateData->setDate(date); JSAlarmAbsolutePriv *priv = new JSAlarmAbsolutePriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; - + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object"); + } + return JSObjectMake(context, getClassRef(), static_cast(priv)); } -JSValueRef JSAlarmAbsolute::getNextScheduledDate(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ +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); + AceSecurityStatus status = ALARM_CHECK_ACCESS(TizenApis::Tizen1_0::Alarm::JSAlarmManager::gContext, ALARM_FUNCTION_API_GET_NEXT_SCHEDULED_DATE); + TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception); + struct tm date; Converter converter(ctx); int id; Try { - AlarmAbsolutePtr privateData = getPrivData(object); - id = privateData->getId(); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); + 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(WrtDeviceApis::Commons::Exception) { + return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } - - int err = alarm_get_scheduled_date(id, &date); - JSValueRef result = converter.toJSValueRef(date); +} - if(err != ALARM_ERROR_NONE) +JSValueRef JSAlarmAbsolute::getDate(JSContextRef ctx, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + Converter converter(ctx); + int id; + struct tm date; + time_t temp; + Try { - return JSDOMExceptionFactory::UnknownException.make(ctx, exception); + 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(WrtDeviceApis::Commons::Exception) { + return JSValueMakeUndefined(ctx); } - return result; } + JSValueRef JSAlarmAbsolute::getId(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, @@ -246,37 +299,73 @@ JSValueRef JSAlarmAbsolute::getId(JSContextRef ctx, { AlarmAbsolutePtr privateData = getPrivData(object); id = privateData->getId(); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); + if(id >= 0) { + return converter.toJSValueRef(id); + } else { + return JSValueMakeNull(ctx); + } + } Catch(WrtDeviceApis::Commons::Exception) { + return JSValueMakeNull(ctx); } - return converter.toJSValueRef(id); } -JSValueRef JSAlarmAbsolute::getRecurrenceRule(JSContextRef ctx, +JSValueRef JSAlarmAbsolute::getInterval(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { - #if 0 Converter converter(ctx); int interval; - Try - { - AlarmPtr privateData = getPrivData(object); - interval = privateData->getRecurrence(); - } - Catch(WrtDeviceApis::Commons::Exception) + Try { - LogWarning("trying to get incorrect value"); - } + 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(WrtDeviceApis::Commons::Exception) { + return JSValueMakeNull(ctx); + } +} - return converter.toJSValueRef(interval); - #endif +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 daysOfTheWeek = privateData->getByDayRecurrence(); + if(daysOfTheWeek.size() >0) + { + if (jsResult == NULL) + { + ThrowMsg(NullPointerException, "Could not create js array object"); + } + + for(unsigned int i=0; i #include @@ -35,6 +35,7 @@ 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); @@ -48,22 +49,34 @@ protected: 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 getRecurrenceRule(JSContextRef context, + 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 diff --git a/src/standards/Tizen/Alarm/JSAlarmManager.cpp b/src/standards/Tizen/Alarm/JSAlarmManager.cpp index 938947d..266a905 100755 --- a/src/standards/Tizen/Alarm/JSAlarmManager.cpp +++ b/src/standards/Tizen/Alarm/JSAlarmManager.cpp @@ -27,10 +27,13 @@ #include #include -#include "AlarmAbsolute.h" +#include "plugin_config.h" #include "AlarmConverter.h" -#include "JSAlarmManager.h" #include "JSAlarmAbsolute.h" +#include "AlarmAbsolute.h" +#include "JSAlarmRelative.h" +#include "AlarmRelative.h" +#include "JSAlarmManager.h" using namespace std; @@ -41,23 +44,9 @@ namespace Alarm { using namespace WrtDeviceApis::Commons; using namespace WrtDeviceApis::CommonsJavaScript; using namespace TizenApis::Tizen1_0::Alarm; +using namespace TizenApis::Commons; using namespace TizenApis::Api::Alarm; -#if 0 -using TizenApis::Api::Alarm::Alarm; -using TizenApis::Tizen1_0::Alarm::JSAlarm; -class JSAlarm; -#endif - -#if 0 -using namespace std; -using namespace DPL; -using namespace TizenApis::Api::Alarm; -using namespace WrtDeviceApis; -using namespace WrtDeviceApis::CommonsJavaScript; -#endif - - static bool alarm_iterate_callback(int alarm_id, void *user_data) { vector *alarmIds = reinterpret_cast*>(user_data); @@ -74,7 +63,7 @@ JSClassDefinition JSAlarmManager::m_jsClassInfo = { kJSClassAttributeNone, "AlarmManager", NULL, - NULL, + m_property, m_function, initialize, finalize, @@ -92,10 +81,20 @@ JSClassDefinition JSAlarmManager::m_jsClassInfo = { JSStaticFunction JSAlarmManager::m_function[] = { { "add",JSAlarmManager::add,kJSPropertyAttributeNone }, { "remove",JSAlarmManager::remove,kJSPropertyAttributeNone }, - { "getAlarms",JSAlarmManager::getAlarms,kJSPropertyAttributeNone }, + { "removeAll",JSAlarmManager::removeAll,kJSPropertyAttributeNone }, + { "getAll",JSAlarmManager::getAll,kJSPropertyAttributeNone }, + { "get",JSAlarmManager::get,kJSPropertyAttributeNone }, { 0, 0, 0 } }; +JSStaticValue JSAlarmManager::m_property[] = { + { "PERIOD_MINUTE", getMin, NULL, kJSPropertyAttributeReadOnly }, + { "PERIOD_HOUR", getHour, NULL, kJSPropertyAttributeReadOnly }, + { "PERIOD_DAY", getDay, NULL, kJSPropertyAttributeReadOnly }, + { "PERIOD_WEEK", getWeek, NULL, kJSPropertyAttributeReadOnly }, + { 0, 0, 0, 0 } +}; + const JSClassRef JSAlarmManager::getClassRef() { if (!m_jsClassRef) { @@ -109,9 +108,11 @@ 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) { @@ -124,117 +125,123 @@ bool JSAlarmManager::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef JSAlarmManager::add(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - - #if 0 service_h service; - char *package; - Alarm::alarm_type_e type = Alarm::ALARM_TYPE_INVALID; struct tm startDate; - int delay; - AlarmRecurrencePtr recurrencePtr; - int interval = 0; - int id; - - LogError("[ILOVEFILM] Enter add"); - - Validator check(ctx, exception); - AlarmConverter converter(ctx); + int delay = 0; + int alarm_id; + std::string package; + std::string page; - LogError("[ILOVEFILM] Enter add2"); - if(argumentCount < 2) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - LogError("[ILOVEFILM] Enter add3"); - if(!JSValueIsObjectOfClass(ctx, arguments[0], JSAlarmAbsolute::getClassRef())) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - - // need to know - // 1. type(delay, date) - // 2. weekly or time - // 3. convert freqeuncy to second - - // 1. GetAlarmPrivate Data - LogError("[ILOVEFILM] Enter add4"); - JSObjectRef alarmObj = JSValueToObject(ctx, arguments[0], exception); - - LogError("[ILOVEFILM] Enter add5"); - JSAlarmPriv *priv = static_cast(JSObjectGetPrivate(alarmObj)); - if (!priv) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - LogError("[ILOVEFILM] Enter add6"); - AlarmAbsolutePtr alarmPtr = priv->getObject(); - if (!alarmPtr) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } + AceSecurityStatus status = ALARM_CHECK_ACCESS(gContext, ALARM_FUNCTION_API_ADD); + TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception); - LogError("[ILOVEFILM] Enter add7"); + Validator check(ctx, exception); + AlarmConverter converter(ctx); - type = alarmPtr->getAlarmType(); - if(type == Alarm::ALARM_TYPE_DELAY) - { - LogError("[ILOVEFILM] Enter add8 get Date"); - delay = alarmPtr->getDelay(); - } - else if(type == Alarm::ALARM_TYPE_DATE) - { - LogError("[ILOVEFILM] Enter add8 get Delay"); - startDate = alarmPtr->getDate(); + Try { - } + if(argumentCount < 2) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } - if(type == Alarm::ALARM_TYPE_DELAY) - { - service = converter.toService(converter.toString(arguments[1])); - if(alarmPtr->isRecurrence()) - { - recurrencePtr = alarmPtr->getRecurrence(); + if(argumentCount >= 2) { + if(!JSValueIsString(ctx, arguments[1])) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + package = converter.toString(arguments[1]); } - else - { - int err = alarm_schedule_after_delay(service, delay, 0, &id); - alarmPtr->setId(id); - } - - } else if(type == Alarm::ALARM_TYPE_DATE) - { - LogError("[ILOVEFILM] Enter add9"); - service = converter.toService(converter.toString(arguments[1])); - if(alarmPtr->isRecurrence()) - { - LogError("[ILOVEFILM] Enter add10"); - recurrencePtr = alarmPtr->getRecurrence(); - int err = alarm_schedule_at_date(service, &startDate, 0, &id); + + if(argumentCount == 3) { + if(!JSValueIsString(ctx, arguments[2])) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + Throw(WrtDeviceApis::Commons::UnsupportedException); } - else - { - char *package; - service_get_package(service, &package); - struct tm current; - alarm_get_current_time(¤t); - LogError("[ILOVEFILM] Current Date = " << "Sec : " << current.tm_sec << " Min : "<< current.tm_min - << " Hour : " << current.tm_hour << " Day : " << current.tm_mday << " MON : " << current.tm_mon - << " Year : " << current.tm_year); - - LogError("[ILOVEFILM] Enter add11 service package = " << package); - LogError("[ILOVEFILM] Date = " << "Sec : " << startDate.tm_sec << " Min : "<< startDate.tm_min - << " Hour : " << startDate.tm_hour << " Day : " << startDate.tm_mday << " MON : " << startDate.tm_mon - << " Year : " << startDate.tm_year); - int err = alarm_schedule_at_date(service, &startDate, 0, &id); - LogError("[ILOVEFILM] Enter add12 error code " << err ); - - LogError("[ILOVEFILM] Enter add12 error code ALARM_ERROR_INVALID_PARAMETER = " << ALARM_ERROR_INVALID_PARAMETER ); - LogError("[ILOVEFILM] Enter add12 error code ALARM_ERROR_INVALID_DATE = " << ALARM_ERROR_INVALID_DATE ); - LogError("[ILOVEFILM] Enter add12 error code ALARM_ERROR_CONNECTION_FAIL = " << ALARM_ERROR_CONNECTION_FAIL ); + if(JSValueIsObjectOfClass(ctx, arguments[0], JSAlarmAbsolute::getClassRef())) { + // AlarmAbsolute obj + JSObjectRef alarmObj = JSValueToObject(ctx, arguments[0], exception); + JSAlarmAbsolutePriv *priv = static_cast(JSObjectGetPrivate(alarmObj)); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + AlarmAbsolutePtr alarmPtr = priv->getObject(); + if (!alarmPtr) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + + startDate = alarmPtr->getDate(); + // ilovefilm + service = alarmPtr->getService(); + if(!page.empty()) { + JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Page is not support"); + } + else { + service_set_operation(service, SERVICE_OPERATION_DEFAULT); + } + service_set_package(service, package.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); + } - } - - alarmPtr->setId(id); - } - #endif - + } else if(JSValueIsObjectOfClass(ctx, arguments[0], JSAlarmRelative::getClassRef())) { + JSObjectRef alarmObj = JSValueToObject(ctx, arguments[0], exception); + JSAlarmRelativePriv *priv = static_cast(JSObjectGetPrivate(alarmObj)); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + + AlarmRelativePtr alarmPtr = priv->getObject(); + if (!alarmPtr) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + + delay = alarmPtr->getDelay(); + int interval = alarmPtr->getPeriod(); + service = alarmPtr->getService(); + if(!page.empty()) { + JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Page is not support"); + } + else { + service_set_operation(service, SERVICE_OPERATION_DEFAULT); + } + service_set_package(service, package.c_str()); + int err = alarm_schedule_after_delay(service, delay, interval, &alarm_id); + + if(err == ALARM_ERROR_NONE) { + alarmPtr->setId(alarm_id); + } + } else { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + } Catch (WrtDeviceApis::Commons::ConversionException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } Catch (WrtDeviceApis::Commons::UnsupportedException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::NOT_SUPPORTED_ERROR, "Not supported"); + } Catch (WrtDeviceApis::Commons::InvalidArgumentException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } Catch (WrtDeviceApis::Commons::NullPointerException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } Catch (WrtDeviceApis::Commons::Exception) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } + + return JSValueMakeUndefined(ctx); } @@ -242,204 +249,228 @@ JSValueRef JSAlarmManager::remove(JSContextRef ctx, JSObjectRef object, JSObject { int err; - if(argumentCount < 1 || !JSValueIsString(ctx, arguments[0])) - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); - - Converter converter(ctx); - // todo : check exception or error - string stringID = converter.toString(arguments[0]); + AceSecurityStatus status = ALARM_CHECK_ACCESS(gContext, ALARM_FUNCTION_API_REMOVE); + TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception); - int id = atoi(stringID.c_str()); + Try { + if(argumentCount < 1 || !JSValueIsString(ctx, arguments[0])) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } - err = alarm_cancel(id); + Converter converter(ctx); + string stringID = converter.toString(arguments[0]); + + int id = atoi(stringID.c_str()); - if(err != ALARM_ERROR_NONE) - { - return JSDOMExceptionFactory::UnknownException.make(ctx, exception); - } + err = alarm_cancel(id); + + if(err != ALARM_ERROR_NONE) + { + if(err == ALARM_ERROR_INVALID_PARAMETER) { + JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::NOT_FOUND_ERROR, "Not found error"); + } + else { + JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } + } + + } Catch (WrtDeviceApis::Commons::ConversionException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } Catch (WrtDeviceApis::Commons::UnsupportedException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::NOT_SUPPORTED_ERROR, "Not supported"); + } Catch (WrtDeviceApis::Commons::InvalidArgumentException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } Catch (WrtDeviceApis::Commons::NullPointerException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } Catch (WrtDeviceApis::Commons::Exception) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } return JSValueMakeUndefined(ctx); } - -JSValueRef JSAlarmManager::getAlarms(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +JSValueRef JSAlarmManager::removeAll(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - int error; - vector alarmIds; - error = alarm_foreach_registered_alarm(alarm_iterate_callback, &alarmIds); - - if(error != ALARM_ERROR_NONE) - { - return JSDOMExceptionFactory::UnknownException.make(ctx, exception); - } - -#if 0 - AlarmArrayPtr alarmObjectArrary; - for(int i = 0; i < alarmIds.size(); i++) - { - TizenApis::Tizen1_0::Alarm::JSAlarmAbsolute::createJSObject(ctx, alarmIds[i]); - } -#endif - -} + LogError("GContext = " << gContext); + AceSecurityStatus status = ALARM_CHECK_ACCESS(gContext, ALARM_FUNCTION_API_REMOVE_ALL); + TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception); -#if 0 -JSValueRef JSAlarmManager::createAlarm(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - struct tm date; - int id; - service_h service; - char *package; - - Validator check(ctx,exception); - - if(argumentCount < 3) { - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); - } - - if(JSValueIsNumber(ctx, arguments[1])) { - return createAfterDelay(ctx, object, thisObject, argumentCount, arguments, exception); - } - - if(check.isCallback(arguments[0]) | check.isNullOrUndefined(arguments[0])) { - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); - } - - if(!check.isDate(arguments[1])) { - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); - } - - if(!JSValueIsNumber(ctx, arguments[2])) { - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); - } - - AlarmConverter alarmConverter(ctx); - date = alarmConverter.toDateTm(arguments[1]); - int period = (int)JSValueToNumber(ctx, arguments[2], exception); - service = alarmConverter.toService(arguments[0]); - int err = alarm_schedule_at_date(service, &date, period, &id); - - service_destroy(service); - - if(err != ALARM_ERROR_NONE) { - return JSDOMExceptionFactory::UnknownException.make(ctx, exception); - } - - return alarmConverter.toJSValueRef(id); + alarm_cancel_all(); + return JSValueMakeUndefined(ctx); } -JSValueRef JSAlarmManager::createAfterDelay(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +JSValueRef JSAlarmManager::getAll(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - struct tm date; - int id; - service_h service; - char *package; - Validator check(ctx,exception); + AceSecurityStatus status = ALARM_CHECK_ACCESS(gContext, ALARM_FUNCTION_API_GET_ALL); + TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception); - if(argumentCount < 3) { - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); - } - - if(check.isCallback(arguments[0]) | check.isNullOrUndefined(arguments[0])) { - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); - } + int error; + AlarmConverter converter(ctx); + vector alarmIds; + + error = alarm_foreach_registered_alarm(alarm_iterate_callback, &alarmIds); - if( !JSValueIsNumber(ctx, arguments[1])) { - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); - } + Try { + if(error != ALARM_ERROR_NONE) + { + return JSDOMExceptionFactory::UnknownException.make(ctx, exception); + } - if(!JSValueIsNumber(ctx, arguments[2])) { - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); + JSObjectRef jsResult = JSCreateArrayObject(ctx, 0, NULL); + + //JSCreateArrayObject(JSContextRef context, int length, const JSValueRef vector [ ]) + LogInfo("Enter getAll Natvie alarm id size = " << alarmIds.size()); + for(int i = 0; i < alarmIds.size(); i++) + { + service_h handle; + char* alarmType; + alarm_get_service(alarmIds.at(i), &handle); + service_get_extra_data(handle, ALARM_TYPE_KEY, &alarmType); + LogInfo("Enter getAll Natvie 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) { + Throw(WrtDeviceApis::Commons::ConversionException); + } + + JSValueRef obj = JSAlarmAbsolute::createJSObject(ctx, privateData); + if(!JSSetArrayElement(ctx, jsResult, i, obj)) + { + ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Could not insert value into js array"); + } + + } else if( !strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE)) { + AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(handle)); + if(converter.toAlarmRelativePtr(alarmIds.at(i), handle, privateData) == false) { + Throw(WrtDeviceApis::Commons::ConversionException); + } + JSValueRef obj = JSAlarmRelative::createJSObject(ctx, privateData); + if(!JSSetArrayElement(ctx, jsResult, i, obj)) + { + ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Could not insert value into js array"); + } + } + service_destroy(handle); + } + return jsResult; + + } Catch (WrtDeviceApis::Commons::ConversionException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } Catch (WrtDeviceApis::Commons::UnsupportedException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::NOT_SUPPORTED_ERROR, "Not supported"); + } Catch (WrtDeviceApis::Commons::InvalidArgumentException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } Catch (WrtDeviceApis::Commons::NullPointerException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } Catch (WrtDeviceApis::Commons::Exception) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); } - AlarmConverter alarmConverter(ctx); - int delay = (int)JSValueToNumber(ctx, arguments[1], exception); - int period = (int)JSValueToNumber(ctx, arguments[2], exception); - service = alarmConverter.toService(arguments[0]); - - int err = alarm_schedule_after_delay(service, delay, period, &id); - - service_destroy(service); - - if(err != ALARM_ERROR_NONE) { - return JSDOMExceptionFactory::UnknownException.make(ctx, exception); - } - - return alarmConverter.toJSValueRef(id); } -JSValueRef JSAlarmManager::cancelAlarm(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +JSValueRef JSAlarmManager::get(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - int err; - if(argumentCount < 1 || !JSValueIsNumber(ctx, arguments[0])) - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); + AceSecurityStatus status = ALARM_CHECK_ACCESS(gContext, ALARM_FUNCTION_API_GET); + TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception); - int id = (int)JSValueToNumber(ctx, arguments[0], exception); + int error; + int alarmId; + AlarmConverter converter(ctx); + + Try { + if(argumentCount <1) { + // Exception + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } - err = alarm_cancel(id); + if(!JSValueIsNumber(ctx, arguments[0])){ + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } + alarmId = JSValueToNumber(ctx, arguments[0], exception); - if(err != ALARM_ERROR_NONE) - { - return JSDOMExceptionFactory::UnknownException.make(ctx, exception); + service_h handle; + char* alarmType; + alarm_get_service(alarmId, &handle); + service_get_extra_data(handle, ALARM_TYPE_KEY, &alarmType); + if(!strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE)) + { + AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(handle)); + if(converter.toAlarmAbsolutePtr(alarmId, handle, privateData) == false) { + Throw(WrtDeviceApis::Commons::ConversionException); + } + + 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) { + Throw(WrtDeviceApis::Commons::ConversionException); + } + return JSAlarmRelative::createJSObject(ctx, privateData); + } + + } Catch (WrtDeviceApis::Commons::ConversionException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } Catch (WrtDeviceApis::Commons::UnsupportedException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::NOT_SUPPORTED_ERROR, "Not supported"); + } Catch (WrtDeviceApis::Commons::InvalidArgumentException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } Catch (WrtDeviceApis::Commons::NullPointerException) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } Catch (WrtDeviceApis::Commons::Exception) { + return JSTizenExceptionFactory::postException(ctx, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); } return JSValueMakeUndefined(ctx); } - -JSValueRef JSAlarmManager::getAlarmIDs(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +JSValueRef JSAlarmManager::getMin(JSContextRef ctx, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) { - vector alarmIds; - alarm_foreach_registered_alarm(alarm_iterate_callback, &alarmIds); - Converter converter(ctx); - return converter.toJSValueRef(alarmIds); + return converter.toJSValueRef(60); } -JSValueRef JSAlarmManager::getNextScheduledDate(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +JSValueRef JSAlarmManager::getHour(JSContextRef ctx, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) { - if(argumentCount < 1 || !JSValueIsNumber(ctx, arguments[0])) - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); - - struct tm date; Converter converter(ctx); - int id = (int)JSValueToNumber(ctx, arguments[0], exception); - int err = alarm_get_scheduled_date(id, &date); - - JSValueRef result = converter.toJSValueRef(date); - - if(err != ALARM_ERROR_NONE) - { - return JSDOMExceptionFactory::UnknownException.make(ctx, exception); - } - - return result; + return converter.toJSValueRef(3600); } - -JSValueRef JSAlarmManager::getReccurentSecond(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +JSValueRef JSAlarmManager::getDay(JSContextRef ctx, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) { - if(argumentCount < 1 || !JSValueIsNumber(ctx, arguments[0])) - return JSDOMExceptionFactory::TypeMismatchException.make(ctx, exception); + Converter converter(ctx); + return converter.toJSValueRef(86400); +} - int period; +JSValueRef JSAlarmManager::getWeek(JSContextRef ctx, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ Converter converter(ctx); - int id = (int)JSValueToNumber(ctx, arguments[0], exception); - int err = alarm_get_scheduled_period(id, &period); - if(err != ALARM_ERROR_NONE) - { - return JSDOMExceptionFactory::UnknownException.make(ctx, exception); - } - - return converter.toJSValueRef(period); + return converter.toJSValueRef(604800); } -#endif } // Alarm } // Tizen1_0 diff --git a/src/standards/Tizen/Alarm/JSAlarmManager.h b/src/standards/Tizen/Alarm/JSAlarmManager.h index c56c296..bb27c56 100755 --- a/src/standards/Tizen/Alarm/JSAlarmManager.h +++ b/src/standards/Tizen/Alarm/JSAlarmManager.h @@ -18,6 +18,8 @@ #define _JS_TIZEN_ALARM_MANAGER #include +#include + namespace TizenApis { namespace Tizen1_0 { @@ -27,37 +29,28 @@ 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); -#if 0 - static JSValueRef createAlarm(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); - - static JSValueRef createAfterDelay(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); - - static JSValueRef cancelAlarm(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); - - static JSValueRef getAlarmIDs(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); - - static JSValueRef getNextScheduledDate(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); - - static JSValueRef getReccurentSecond(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); -#endif - 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 getAlarms(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 JSClassDefinition m_jsClassInfo; static JSClassRef m_jsClassRef; static JSStaticFunction m_function[]; + static JSStaticValue m_property[]; + }; } diff --git a/src/standards/Tizen/Alarm/JSAlarmRecurrence.cpp b/src/standards/Tizen/Alarm/JSAlarmRecurrence.cpp deleted file mode 100755 index 740b567..0000000 --- a/src/standards/Tizen/Alarm/JSAlarmRecurrence.cpp +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "AlarmRecurrence.h" -#include -#include "JSAlarmRecurrence.h" -#include "AlarmConverter.h" - -namespace TizenApis { -namespace Tizen1_0 { -namespace Alarm { - -using namespace std; -using namespace DPL; -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; -using namespace TizenApis::Commons; - - -JSClassRef JSAlarmRecurrence::m_jsClassRef = NULL; - -JSClassDefinition JSAlarmRecurrence::m_jsClassInfo = { - 0, - kJSClassAttributeNone, - "JSAlarmRecurrence", - NULL, - m_property, - NULL, - initialize, - finalize, - NULL, //hasProperty, - NULL, //getProperty, - NULL, //setProperty, - NULL, //deleteProperty - NULL, //getPropertyNames, - NULL, - constructor, // constructor - hasInstance, - NULL -}; - -JSStaticValue JSAlarmRecurrence::m_property[] = { - { "frequency", getFrequency, setFrequency, kJSPropertyAttributeNone }, - { "interval", getInterval, setInterval, kJSPropertyAttributeNone }, - { "daysOfTheWeek", getDaysOfTheWeek, setDaysOfTheWeek, kJSPropertyAttributeNone }, - { 0, 0, 0, 0 } -}; - -const JSClassRef JSAlarmRecurrence::getClassRef() -{ - if (!m_jsClassRef) { - m_jsClassRef = JSClassCreate(&m_jsClassInfo); - } - return m_jsClassRef; -} - -const JSClassDefinition* JSAlarmRecurrence::getClassInfo() -{ - return &m_jsClassInfo; -} - -void JSAlarmRecurrence::initialize(JSContextRef context, JSObjectRef object) -{ - -} - -void JSAlarmRecurrence::finalize(JSObjectRef object) -{ - -} - -JSObjectRef JSAlarmRecurrence::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - // Parameter can be 1 or 2. - - // 1. Parameter : AlarmFrequency - // 2. Parameter : interval - // 3. Parameter : ByDayValue[] - AlarmConverter converter(ctx); - - // return : Should return AlarmRecurrence object - if(argumentCount < 1) - { - return converter.toJSObjectRef(TizenApis::Commons::JSTizenExceptionFactory::postException(ctx, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR)); - } - - if(argumentCount == 1) - { - // daysOfTheweek - // convert javascript array to string array - // How can i check javascript - if(!JSIsArrayValue(ctx, arguments[0])) - { - // exception. - return converter.toJSObjectRef(TizenApis::Commons::JSTizenExceptionFactory::postException(ctx, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR)); - } - std::vector temp = converter.toVectorOfStrings(arguments[0]); - JSObjectRef obj = createJSObject(ctx, temp); - return obj; - } - else - { - std::string frequencyStr; - int interval; - AlarmRecurrence::alarm_frequency_e frequency; - // Should frequency & interval - if(!JSValueIsString(ctx, arguments[0])) - { - return converter.toJSObjectRef(TizenApis::Commons::JSTizenExceptionFactory::postException(ctx, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR)); - } - frequencyStr = converter.toString(arguments[0]); - - frequency = converter.toRecurrenceFrequency(frequencyStr); - - if(frequency == AlarmRecurrence::NO_RECURRENCE) - { - return converter.toJSObjectRef(TizenApis::Commons::JSTizenExceptionFactory::postException(ctx, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR)); - } - - if(JSValueIsNumber(ctx, arguments[1])) - { - return converter.toJSObjectRef(TizenApis::Commons::JSTizenExceptionFactory::postException(ctx, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR)); - } - - interval = converter.toInt(arguments[1]); - - if(interval <=0) - { - return converter.toJSObjectRef(TizenApis::Commons::JSTizenExceptionFactory::postException(ctx, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR)); - } - - JSObjectRef obj = createJSObject(ctx, frequency, interval); - return obj; - - } - -} - -bool JSAlarmRecurrence::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) -{ - return JSValueIsObjectOfClass(context, possibleInstance, getClassRef()); -} - -AlarmRecurrencePtr JSAlarmRecurrence::getPrivData(JSObjectRef object) -{ - JSAlarmRecurrencePriv*priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - - AlarmRecurrencePtr result = priv->getObject(); - if (!result) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - return result; -} - -JSObjectRef JSAlarmRecurrence::createJSObject(JSContextRef context, std::vector daysOfTheWeek) -{ - AlarmRecurrencePtr privateData = AlarmRecurrencePtr(new AlarmRecurrence()); - privateData->setDaysOfTheWeek(daysOfTheWeek); - JSAlarmRecurrencePriv *priv = new JSAlarmRecurrencePriv(context, privateData); - JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsObjectRef) { - // Exception - LogError("JSAlarmRecurrence object creation error"); - - } - return jsObjectRef; -} - -JSObjectRef JSAlarmRecurrence::createJSObject(JSContextRef context, AlarmRecurrence::alarm_frequency_e frequency, int interval) -{ - AlarmRecurrencePtr privateData = AlarmRecurrencePtr(new AlarmRecurrence()); - privateData->setInterval(interval); - privateData->setFrequency(frequency); - JSAlarmRecurrencePriv *priv = new JSAlarmRecurrencePriv(context, privateData); - JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsObjectRef) { - // Exception - LogError("JSAlarmRecurrence object creation error"); - - } - return jsObjectRef; -} - - -JSValueRef JSAlarmRecurrence::getFrequency(JSContextRef ctx, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - AlarmConverter converter(ctx); - AlarmRecurrence::alarm_frequency_e frequency; - Try - { - AlarmRecurrencePtr privateData = getPrivData(object); - frequency = privateData->getFrequency(); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return converter.toJSValueRef(converter.toTizenValue(frequency)); -} - -bool JSAlarmRecurrence::setFrequency(JSContextRef ctx, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - AlarmConverter converter(ctx); - std::string frequencyStr; - - if(!JSValueIsString(ctx, value)) - { - return false; - } - - Try - { - AlarmRecurrencePtr privateData = getPrivData(object); - frequencyStr = converter.toString(value); - privateData->setFrequency(converter.toRecurrenceFrequency(frequencyStr)); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return true; -} - -JSValueRef JSAlarmRecurrence::getInterval(JSContextRef ctx, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - int interval; - Converter converter(ctx); - Try - { - AlarmRecurrencePtr privateData = getPrivData(object); - interval = privateData->getInterval(); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return converter.toJSValueRef(interval); - -} - -bool JSAlarmRecurrence::setInterval(JSContextRef ctx, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Converter converter(ctx); - - if(!JSValueIsNumber(ctx, value)) - { - return false; - } - - Try - { - AlarmRecurrencePtr privateData = getPrivData(object); - privateData->setInterval(converter.toInt(value)); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - return true; - -} -JSValueRef JSAlarmRecurrence::getDaysOfTheWeek(JSContextRef ctx, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - // todo change to AlarmConverter - std::vector daysOfTheWeek; - Converter converter(ctx); - Try - { - AlarmRecurrencePtr privateData = getPrivData(object); - daysOfTheWeek = privateData->getDaysOfTheWeek(); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return converter.toJSValueRef(daysOfTheWeek); - -} - -bool JSAlarmRecurrence::setDaysOfTheWeek(JSContextRef ctx, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - - AlarmConverter converter(ctx); - std::vector daysOfTheWeek; - - Try - { - AlarmRecurrencePtr privateData = getPrivData(object); - daysOfTheWeek = converter.toVectorOfStrings(value); - privateData->setDaysOfTheWeek(daysOfTheWeek); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return converter.toJSValueRef(daysOfTheWeek); - -} - - -#if 0 -void convertDaysOfTheWeekToFlag(std::vector daysOfTheWeek, char weekFlag[]) -{ - for( unsigned int i=0; igetId(); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return converter.toJSValueRef(id); - -} - - -JSValueRef JSAlarmRecurrence::getInterval(JSContextRef ctx, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - Converter converter(ctx); - int interval; - Try - { - AlarmPtr privateData = getPrivData(object); - interval = privateData->getInterval(); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return converter.toJSValueRef(interval); - -} - -#endif - -} // Alarm -} // Tizen1_0 -} // TizenApis - - diff --git a/src/standards/Tizen/Alarm/JSAlarmRecurrence.h b/src/standards/Tizen/Alarm/JSAlarmRecurrence.h deleted file mode 100755 index 3d681db..0000000 --- a/src/standards/Tizen/Alarm/JSAlarmRecurrence.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_ALARMRECURRENCE -#define _JS_TIZEN_ALARMRECURRENCE - -#include -#include "AlarmRecurrence.h" - -namespace TizenApis { -namespace Tizen1_0 { -namespace Alarm { - -using namespace TizenApis::Api::Alarm; - -typedef WrtDeviceApis::CommonsJavaScript::PrivateObject JSAlarmRecurrencePriv; - - -#define TIZEN_ALARM_PROPERTY_MINUTELY_RECURRENCE "MINUTELY" -#define TIZEN_ALARM_PROPERTY_HOURLY_RECURRENCE "HOURLY" -#define TIZEN_ALARM_PROPERTY_DAILY_RECURRENCE "DAILY" -#define TIZEN_ALARM_PROPERTY_WEEKLY_RECURRENCE "WEEKLY" - -class JSAlarmRecurrence { -public: - static const JSClassDefinition* getClassInfo(); - static const JSClassRef getClassRef(); - static JSObjectRef createJSObject(JSContextRef context, std::vector daysOfTheWeek); - static JSObjectRef createJSObject(JSContextRef context, AlarmRecurrence::alarm_frequency_e frequency, int interval); - - -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 JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); - -private: - static AlarmRecurrencePtr getPrivData(JSObjectRef object); - static JSValueRef getFrequency(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - static bool setFrequency(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception); - - static JSValueRef getInterval(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - static bool setInterval(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception); - - static JSValueRef getDaysOfTheWeek(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - static bool setDaysOfTheWeek(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception); - - static JSClassDefinition m_jsClassInfo; - static JSClassRef m_jsClassRef; - static JSStaticValue m_property[]; -}; - -}// Alarm -} // Tizen1_0 -} // TizenApis - -#endif diff --git a/src/standards/Tizen/Alarm/JSAlarmRelative.cpp b/src/standards/Tizen/Alarm/JSAlarmRelative.cpp index ffc66c4..aebfa3a 100755 --- a/src/standards/Tizen/Alarm/JSAlarmRelative.cpp +++ b/src/standards/Tizen/Alarm/JSAlarmRelative.cpp @@ -24,14 +24,19 @@ #include #include #include +#include + + +#include "plugin_config.h" + #include "AlarmRelative.h" -#include "AlarmRecurrence.h" #include "AlarmConverter.h" -#include -#include -#include "JSAlarmRecurrence.h" #include "JSAbstractAlarm.h" #include "JSAlarmRelative.h" +#include "JSAlarmManager.h" + +#include +#include namespace TizenApis { @@ -42,6 +47,8 @@ using namespace std; using namespace DPL; using namespace WrtDeviceApis::Commons; using namespace WrtDeviceApis::CommonsJavaScript; +using namespace TizenApis::Commons; + using namespace TizenApis::Api::Alarm; JSClassRef JSAlarmRelative::m_jsClassRef = NULL; @@ -67,13 +74,14 @@ JSClassDefinition JSAlarmRelative::m_jsClassInfo = { }; JSStaticFunction JSAlarmRelative::m_function[] = { - { "getNextScheduledDate",JSAlarmRelative::getNextScheduledDate,kJSPropertyAttributeNone }, + { "getRemainingSeconds",JSAlarmRelative::getRemainingSeconds,kJSPropertyAttributeNone }, { 0, 0, 0 } }; JSStaticValue JSAlarmRelative::m_property[] = { { "id", getId, NULL, kJSPropertyAttributeReadOnly }, - { "recurrenceRule", getRecurrenceRule, NULL, kJSPropertyAttributeReadOnly }, + { "delay", getDelay, NULL, kJSPropertyAttributeReadOnly }, + { "period", getPeriod, NULL, kJSPropertyAttributeReadOnly }, { 0, 0, 0, 0 } }; @@ -92,11 +100,14 @@ const JSClassDefinition* JSAlarmRelative::getClassInfo() void JSAlarmRelative::initialize(JSContextRef context, JSObjectRef object) { - } void JSAlarmRelative::finalize(JSObjectRef object) { - + JSAlarmRelativePriv *priv = static_cast(JSObjectGetPrivate(object)); + if (!priv) { + LogError("Private object is null"); + } + delete priv; } bool JSAlarmRelative::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) @@ -107,239 +118,208 @@ bool JSAlarmRelative::hasInstance(JSContextRef context, JSObjectRef constructor, JSObjectRef JSAlarmRelative::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - #if 0 - LogError("[ILOVEFILM] Enter constructor"); - // 2 Param - // 1. Date, Recurrence - // 2. Delay, Recurrence - struct tm date; AlarmConverter converter(ctx); Validator validator(ctx); - AlarmRelative::alarm_type_e alarm_type; + int delay = 0; + int interval = 0; + bool isRecurrence = false; - bool isRecurrence = false; - - - if(argumentCount < 1) - { - // excpetion - LogWarning("Argument is not corrent"); - } - - int delay; - if(JSValueIsNumber(ctx, arguments[0])); - { - // delay - delay = converter.toInt(arguments[0]); - alarm_type = Alarm::ALARM_TYPE_DELAY; - } - - if( validator.isDate(arguments[0]) == true) - { - // date - date = converter.toDateTm(arguments[0]); - alarm_type = Alarm::ALARM_TYPE_DATE; - } + Try { - AlarmRecurrencePtr result; - - if(argumentCount == 2) - { - if(JSValueIsObjectOfClass(ctx, arguments[1], JSAlarmRecurrence::getClassRef())) + if(argumentCount < 1) { - JSObjectRef recurreceObj = JSValueToObject(ctx, arguments[1], exception); - - JSAlarmRecurrencePriv*priv = static_cast(JSObjectGetPrivate(recurreceObj)); - if (!priv) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - - result = priv->getObject(); - if (!result) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } + ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Wrong argumentCount"); } - isRecurrence = true; - } - - if(alarm_type == Alarm::ALARM_TYPE_DELAY) - { - if(isRecurrence == true) { - return JSValueToObject(ctx, createJSObject(ctx, delay, result), exception); - } - else + + if(!JSValueIsNumber(ctx, arguments[0])) { - return JSValueToObject(ctx, createJSObject(ctx, delay,0), exception); - } - } - else - { - if(isRecurrence == true) { - return JSValueToObject(ctx, createJSObject(ctx, date, result), exception); + ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"Invalid Type"); + } + + delay = JSValueToNumber(ctx, arguments[0], exception); + + if(delay <=0) { + ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"First parameter should be > 0"); } - else + + if(argumentCount == 2) { - return JSValueToObject(ctx, createJSObject(ctx, date), exception); + if(!JSValueIsNumber(ctx, arguments[1])) + { + ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException,"Invalid Type"); + } + + interval = JSValueToNumber(ctx, arguments[1], exception); + LogInfo("Constructor interval = " << interval); } + return JSValueToObject(ctx, createJSObject(ctx, delay, interval), exception); + } Catch (WrtDeviceApis::Commons::ConversionException) { + *exception = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(ctx,TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + return NULL; + } Catch(WrtDeviceApis::Commons::InvalidArgumentException) { + *exception = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(ctx,TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + return NULL; + } Catch(WrtDeviceApis::Commons::NullPointerException) { + *exception = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(ctx,TizenApis::Commons::JSTizenException::UNKNOWN_ERROR, "Unknown error"); + return NULL; + } Catch (WrtDeviceApis::Commons::Exception) { + *exception = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(ctx,TizenApis::Commons::JSTizenException::UNKNOWN_ERROR, "Unknown error"); + return NULL; } -#endif - } AlarmRelativePtr JSAlarmRelative::getPrivData(JSObjectRef object) { - JSAlarmRelativePriv *priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - AlarmRelativePtr result = priv->getObject(); - if (!result) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - return result; + JSAlarmRelativePriv *priv = static_cast(JSObjectGetPrivate(object)); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + AlarmRelativePtr result = priv->getObject(); + if (!result) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + return result; } -JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, const int id) +JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, AlarmRelativePtr privateData) { - AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative()); - - privateData->setId(id); - JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object"); } - return jsValueRef; + return JSObjectMake(context, getClassRef(), static_cast(priv)); } -JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, struct tm date, AlarmRecurrencePtr ptr) -{ - AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative()); - - JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; - -} -JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, int delay, AlarmRecurrencePtr ptr) +JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, int delay, int interval) { AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative()); - privateData->setDelay(delay); - privateData->setRecurrence(ptr); + privateData->setPeriod(interval); JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object"); } - return jsValueRef; + return JSObjectMake(context, getClassRef(), static_cast(priv)); } +JSValueRef JSAlarmRelative::getRemainingSeconds(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef * exception) +{ -JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, struct tm date) -{ - AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative()); - - JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; + AceSecurityStatus status = ALARM_CHECK_ACCESS(TizenApis::Tizen1_0::Alarm::JSAlarmManager::gContext, ALARM_FUNCTION_API_GET_REMAINING_SECONDS); + TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception); -} -JSValueRef JSAlarmRelative::createJSObject(JSContextRef context, int delay, int dummy) -{ - AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative()); - privateData->setDelay(delay); - - JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(context, privateData); + struct tm date; + struct tm current; + time_t currentTime; + time_t nextTime; + Converter converter(ctx); + int id; - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; + 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 { + Throw(WrtDeviceApis::Commons::NullPointerException); + } + } + + alarm_get_current_time(¤t); + + nextTime = mktime(&date); + currentTime = mktime(¤t); + + int result = nextTime - currentTime; + + if(result <0) { + // It is impossible + Throw(WrtDeviceApis::Commons::Exception); + } + + JSValueRef jsResult = converter.toJSValueRef(result); + return jsResult; + } Catch(WrtDeviceApis::Commons::Exception) { + return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } } -JSValueRef JSAlarmRelative::getNextScheduledDate(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - struct tm date; +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) { + return converter.toJSValueRef(id); + } else { + return JSValueMakeNull(ctx); + } + } Catch(WrtDeviceApis::Commons::Exception) { + return JSValueMakeNull(ctx); } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - int err = alarm_get_scheduled_date(id, &date); - - JSValueRef result = converter.toJSValueRef(date); - - if(err != ALARM_ERROR_NONE) - { - return JSDOMExceptionFactory::UnknownException.make(ctx, exception); - } - return result; } -JSValueRef JSAlarmRelative::getId(JSContextRef ctx, +JSValueRef JSAlarmRelative::getDelay(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { Converter converter(ctx); - int id; + int delay; Try { AlarmRelativePtr privateData = getPrivData(object); - id = privateData->getId(); + delay = privateData->getDelay(); + LogInfo("JSAlarmRelative delay = " << delay); + if(delay > 0) { + return converter.toJSValueRef(delay); + } else { + // Impossible + Throw(WrtDeviceApis::Commons::Exception); + } } Catch(WrtDeviceApis::Commons::Exception) { - LogWarning("trying to get incorrect value"); + return JSValueMakeUndefined(ctx); } - - return converter.toJSValueRef(id); + } -JSValueRef JSAlarmRelative::getRecurrenceRule(JSContextRef ctx, +JSValueRef JSAlarmRelative::getPeriod(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { - #if 0 + Converter converter(ctx); - int interval; + int period =0; Try { - AlarmPtr privateData = getPrivData(object); - interval = privateData->getRecurrence(); + AlarmRelativePtr privateData = getPrivData(object); + period = privateData->getPeriod(); + LogInfo("JSAlarmRelative interval = " << period); + if(period <=0) { + return JSValueMakeNull(ctx); + } else { + return converter.toJSValueRef(period); + } } Catch(WrtDeviceApis::Commons::Exception) { - LogWarning("trying to get incorrect value"); + return JSValueMakeNull(ctx); } - - return converter.toJSValueRef(interval); - #endif - } } // Alarm diff --git a/src/standards/Tizen/Alarm/JSAlarmRelative.h b/src/standards/Tizen/Alarm/JSAlarmRelative.h index 049dcda..441effa 100755 --- a/src/standards/Tizen/Alarm/JSAlarmRelative.h +++ b/src/standards/Tizen/Alarm/JSAlarmRelative.h @@ -34,11 +34,8 @@ class JSAlarmRelative { public: static const JSClassDefinition* getClassInfo(); static const JSClassRef getClassRef(); - static JSValueRef createJSObject(JSContextRef context, const int id); - static JSValueRef createJSObject(JSContextRef context, struct tm date, AlarmRecurrencePtr ptr); - static JSValueRef createJSObject(JSContextRef context, int delay, AlarmRecurrencePtr ptr); - static JSValueRef createJSObject(JSContextRef context, struct tm date); - static JSValueRef createJSObject(JSContextRef context, int delay, int dummy); + 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); @@ -46,7 +43,9 @@ 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); + //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); @@ -56,7 +55,12 @@ private: JSStringRef propertyName, JSValueRef* exception); - static JSValueRef getRecurrenceRule(JSContextRef context, + static JSValueRef getDelay(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + + static JSValueRef getPeriod(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); @@ -65,7 +69,6 @@ private: static JSClassRef m_jsClassRef; static JSStaticFunction m_function[]; static JSStaticValue m_property[]; - }; }// Alarm diff --git a/src/standards/Tizen/Alarm/alarm_common.h b/src/standards/Tizen/Alarm/alarm_common.h new file mode 100755 index 0000000..ecdc8bf --- /dev/null +++ b/src/standards/Tizen/Alarm/alarm_common.h @@ -0,0 +1,46 @@ +#ifndef TIZENAPIS_API_ALARM_COMMON_H_ +#define TIZENAPIS_API_ALARM_COMMON_H_ + +namespace TizenApis { +namespace Tizen1_0 { +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 index 95b74a1..53918e2 100755 --- a/src/standards/Tizen/Alarm/config.xml +++ b/src/standards/Tizen/Alarm/config.xml @@ -9,11 +9,18 @@ http://tizen.org/api/alarm - alarm - - - - - + alarm.read + alarm.write - \ No newline at end of file + + + http://tizen.org/api/alarm.read + alarm.read + + + + http://tizen.org/api/alarm.write + alarm.write + + + diff --git a/src/standards/Tizen/Alarm/plugin_config.cpp b/src/standards/Tizen/Alarm/plugin_config.cpp new file mode 100755 index 0000000..0065d19 --- /dev/null +++ b/src/standards/Tizen/Alarm/plugin_config.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include + +#include "plugin_config.h" + +#define ALARM_FEATURE_API "http://tizen.org/api/alarm" +#define ALARM_FEATURE_API_READ "http://tizen.org/api/alarm.read" +#define ALARM_FEATURE_API_WRITE "http://tizen.org/api/alarm.write" + +#define ALARM_DEVICE_CAP_READ "alarm.read" +#define ALARM_DEVICE_CAP_WRITE "alarm.write" + +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_READ, ALARM_DEVICE_CAP_READ); + ACE_CREATE_DEVICE_CAP(DEVICE_CAP_ALARM_WRITE, ALARM_DEVICE_CAP_WRITE); + + ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_ALARM_READ); + ACE_ADD_DEVICE_CAP(DEVICE_LIST_ALARM_READ, DEVICE_CAP_ALARM_READ); + + ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_ALARM_WRITE); + ACE_ADD_DEVICE_CAP(DEVICE_LIST_ALARM_WRITE, DEVICE_CAP_ALARM_WRITE); + + + /** + * Api Features + */ + ACE_CREATE_FEATURE(FEATURE_ALARM, ALARM_FEATURE_API); + ACE_CREATE_FEATURE(FEATURE_ALARM_READ, ALARM_FEATURE_API_READ); + ACE_CREATE_FEATURE(FEATURE_ALARM_WRITE, ALARM_FEATURE_API_WRITE); + + ACE_CREATE_FEATURE_LIST(ALARM_FEATURES_ALARM_READ_WRITE); + ACE_ADD_API_FEATURE(ALARM_FEATURES_ALARM_READ_WRITE, FEATURE_ALARM); + ACE_ADD_API_FEATURE(ALARM_FEATURES_ALARM_READ_WRITE, FEATURE_ALARM_READ); + ACE_ADD_API_FEATURE(ALARM_FEATURES_ALARM_READ_WRITE, FEATURE_ALARM_WRITE); + + ACE_CREATE_FEATURE_LIST(ALARM_FEATURES_ALARM_READ); + ACE_ADD_API_FEATURE(ALARM_FEATURES_ALARM_READ, FEATURE_ALARM); + ACE_ADD_API_FEATURE(ALARM_FEATURES_ALARM_READ, FEATURE_ALARM_READ); + + ACE_CREATE_FEATURE_LIST(ALARM_FEATURES_ALARM_WRITE); + ACE_ADD_API_FEATURE(ALARM_FEATURES_ALARM_WRITE, FEATURE_ALARM); + ACE_ADD_API_FEATURE(ALARM_FEATURES_ALARM_WRITE, FEATURE_ALARM_WRITE); + + + /** + * Functions + */ + FunctionMapping alarmMapping; + + // getAll + AceFunction getAllFunc = ACE_CREATE_FUNCTION( + FUNCTION_GET_ALL, + ALARM_FUNCTION_API_GET_ALL, + ALARM_FEATURES_ALARM_READ, + DEVICE_LIST_ALARM_READ); + + alarmMapping.insert(std::make_pair( + ALARM_FUNCTION_API_GET_ALL, + getAllFunc)); + + // get + AceFunction getFunc = ACE_CREATE_FUNCTION( + FUNCTION_GET, + ALARM_FUNCTION_API_GET, + ALARM_FEATURES_ALARM_READ, + DEVICE_LIST_ALARM_READ); + + alarmMapping.insert(std::make_pair( + ALARM_FUNCTION_API_GET, + getFunc)); + + // add + AceFunction addFunc = ACE_CREATE_FUNCTION( + FUNCTION_ADD, + ALARM_FUNCTION_API_ADD, + ALARM_FEATURES_ALARM_WRITE, + DEVICE_LIST_ALARM_WRITE); + + alarmMapping.insert(std::make_pair( + ALARM_FUNCTION_API_ADD, + addFunc)); + + // remove + AceFunction removeFunc = ACE_CREATE_FUNCTION( + FUNCTION_REMOVE, + ALARM_FUNCTION_API_REMOVE, + ALARM_FEATURES_ALARM_WRITE, + DEVICE_LIST_ALARM_WRITE); + + 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_ALARM_WRITE, + DEVICE_LIST_ALARM_WRITE); + + alarmMapping.insert(std::make_pair( + ALARM_FUNCTION_API_REMOVE_ALL, + removeAllFunc)); + + // getNextSchduledDate + AceFunction getNextScheduledDateFunc = ACE_CREATE_FUNCTION( + FUNCTION_GET_NEXT_SCHEDULED_DATE, + ALARM_FUNCTION_API_GET_NEXT_SCHEDULED_DATE, + ALARM_FEATURES_ALARM_READ, + DEVICE_LIST_ALARM_READ); + + alarmMapping.insert(std::make_pair( + ALARM_FUNCTION_API_GET_NEXT_SCHEDULED_DATE, + getNextScheduledDateFunc)); + + // getReminingSeconds + AceFunction getRemainingSecondsFunc = ACE_CREATE_FUNCTION( + FUNCTION_GET_REMAINING_SECONDS, + ALARM_FUNCTION_API_GET_REMAINING_SECONDS, + ALARM_FEATURES_ALARM_READ, + DEVICE_LIST_ALARM_READ); + + alarmMapping.insert(std::make_pair( + ALARM_FUNCTION_API_GET_REMAINING_SECONDS, + getRemainingSecondsFunc)); + + + return alarmMapping; +} + +} +} +} diff --git a/src/standards/Tizen/Alarm/plugin_config.h b/src/standards/Tizen/Alarm/plugin_config.h new file mode 100755 index 0000000..925c4fa --- /dev/null +++ b/src/standards/Tizen/Alarm/plugin_config.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef _ALARM_PLUGIN_CONFIG_H_ +#define _ALARM_PLUGIN_CONFIG_H_ + +#include +#include + +#define ALARM_FUNCTION_API_GET_ALL "getAll" +#define ALARM_FUNCTION_API_GET "get" +#define ALARM_FUNCTION_API_ADD "add" +#define ALARM_FUNCTION_API_REMOVE "remove" +#define ALARM_FUNCTION_API_REMOVE_ALL "removeAll" + +#define ALARM_FUNCTION_API_GET_NEXT_SCHEDULED_DATE "getNextScheduledDate" + +#define ALARM_FUNCTION_API_GET_REMAINING_SECONDS "getRemainingSeconds" + + +namespace TizenApis { +namespace Tizen1_0 { +namespace Alarm { + +DECLARE_FUNCTION_GETTER(Alarm); + +#define ALARM_CHECK_ACCESS(globalContext, functionName) \ + aceCheckAccess >( \ + globalContext, \ + getAlarmFunctionData, \ + functionName) +} +} +} +#endif + diff --git a/src/standards/Tizen/Alarm/plugin_initializer.cpp b/src/standards/Tizen/Alarm/plugin_initializer.cpp index f4cf46d..f04a5d4 100755 --- a/src/standards/Tizen/Alarm/plugin_initializer.cpp +++ b/src/standards/Tizen/Alarm/plugin_initializer.cpp @@ -19,7 +19,6 @@ #include "JSAlarmManager.h" #include "JSAlarmAbsolute.h" #include "JSAlarmRelative.h" -#include "JSAlarmRecurrence.h" #define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen" diff --git a/src/standards/Tizen/Application/ApplicationAnswerReceiver.cpp b/src/standards/Tizen/Application/ApplicationAnswerReceiver.cpp index 710fa80..63bde9a 100755 --- a/src/standards/Tizen/Application/ApplicationAnswerReceiver.cpp +++ b/src/standards/Tizen/Application/ApplicationAnswerReceiver.cpp @@ -52,62 +52,41 @@ ApplicationAnswerReceiver::~ApplicationAnswerReceiver() { void ApplicationAnswerReceiver::OnAnswerReceived(const EventListInstalledApplicationsPtr &event) { + JSContextRef context = m_callbackManager->getContext(); + if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) { - if (event->getEventType() == EventListInstalledApplications::APPMANAGER_LIST_INSTALLED_APPLICATIONS) { - Try - { + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + + Try { + if (event->getEventType() == EventListInstalledApplications::APPMANAGER_LIST_INSTALLED_APPLICATIONS) { ApplicationInformationArrayPtr appinfoArray = event->getApplicationInformationArray(); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(m_callbackManager->getContext()); JSValueRef result = converter->toJSValueRef(appinfoArray); m_callbackManager->callOnSuccess(result); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogError("error during function executing"); - JSContextRef context = m_callbackManager->getContext(); - JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"unknown error"); - m_callbackManager->callOnError(errorObject); - } - } else if (event->getEventType() == EventListInstalledApplications::APPMANAGER_LIST_RUNNING_APPLICATIONS) { - Try - { + } else if (event->getEventType() == EventListInstalledApplications::APPMANAGER_LIST_RUNNING_APPLICATIONS) { ApplicationContextArrayPtr appcontextArray = event->getApplicationContextArray(); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(m_callbackManager->getContext()); JSValueRef result = converter->toJSValueRef(appcontextArray); - m_callbackManager->callOnSuccess(result); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogError("error during function executing"); - JSContextRef context = m_callbackManager->getContext(); + } else { + LogError("unknow event type"); JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"unknown error"); m_callbackManager->callOnError(errorObject); } - } else { - LogError("unknow event type"); - JSContextRef context = m_callbackManager->getContext(); + } Catch (WrtDeviceApis::Commons::InvalidArgumentException) { + JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"invalid value error"); + m_callbackManager->callOnError(errorObject); + } Catch (WrtDeviceApis::Commons::Exception) { JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"unknown error"); m_callbackManager->callOnError(errorObject); } - } - else { + } else { LogDebug("Operation failed. Exception code: " << event->getExceptionCode()); - JSContextRef context = m_callbackManager->getContext(); JSValueRef errorObject = NULL; - - 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; + if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::PlatformException) { + errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"platform exception"); + } else { + errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"unknown error"); } + m_callbackManager->callOnError(errorObject); } } @@ -116,8 +95,7 @@ void ApplicationAnswerReceiver::OnAnswerReceived(const EventManageApplicationPtr { if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) { if (event->getEventType() == EventManageApplication::APP_MANAGER_KILL_APPLICATION || - event->getEventType() == EventManageApplication::APP_MANAGER_HIDE_APPLICATION || - event->getEventType() == EventManageApplication::APP_MANAGER_LAUNCH_APPLICATION) { + event->getEventType() == EventManageApplication::APP_MANAGER_LAUNCH_APPLICATION) { LogDebug("Event Type: " << event->getEventType()); m_callbackManager->callOnSuccess(); } else { @@ -126,8 +104,7 @@ void ApplicationAnswerReceiver::OnAnswerReceived(const EventManageApplicationPtr JSValueRef errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"unknown error"); m_callbackManager->callOnError(errorObject); } - } - else { + } else { LogDebug("Operation failed. Exception code: " << event->getExceptionCode()); JSContextRef context = m_callbackManager->getContext(); JSValueRef errorObject = NULL; @@ -154,25 +131,19 @@ void ApplicationAnswerReceiver::OnAnswerReceived(const EventLaunchServicePtr &ev LogDebug("<<<"); LaunchServicePrivateDataPtr privateData = DPL::StaticPointerCast(event->getPrivateData()); - if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) - { + if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) { LogDebug("OnAnswerReceived"); - Try - { - if( event->getCallbackType() == EventLaunchService::APPLICATION_SERVICE_CALLBACK) - { + Try { + if ( event->getCallbackType() == EventLaunchService::APPLICATION_SERVICE_CALLBACK) { CommonsJavaScript::JSCallbackManagerPtr callbackManager = privateData->getCallbackManager(); callbackManager->callOnSuccess(); LogDebug("after callOnSuccess"); - } - else if(event->getCallbackType() == EventLaunchService::APPLICATION_SERVICE_REPLY_SUCCESS_CALLBACK) - { + } else if(event->getCallbackType() == EventLaunchService::APPLICATION_SERVICE_REPLY_SUCCESS_CALLBACK) { CommonsJavaScript::JSCallbackManagerPtr replyCallbackManager = privateData->getReplyCallbackManager(); - if(replyCallbackManager) - { + if(replyCallbackManager) { LogDebug("check ApplicationServiceReply"); std::vector reply = event->getService()->getServiceDataArray(); @@ -183,37 +154,29 @@ void ApplicationAnswerReceiver::OnAnswerReceived(const EventLaunchServicePtr &ev replyCallbackManager->callOnSuccess(jsObj); LogDebug("after replyCallbackManager onsuccess"); } - } - else if(event->getCallbackType() == EventLaunchService::APPLICATION_SERVICE_REPLY_FAIL_CALLBACK) - { + } else if(event->getCallbackType() == EventLaunchService::APPLICATION_SERVICE_REPLY_FAIL_CALLBACK) { CommonsJavaScript::JSCallbackManagerPtr replyCallbackManager = privateData->getReplyCallbackManager(); - if(replyCallbackManager) - { + if(replyCallbackManager) { replyCallbackManager->callOnError(); LogDebug("after replyCallbackManager onfail"); } } - } - Catch(WrtDeviceApis::Commons::Exception) - { + } Catch(WrtDeviceApis::Commons::Exception) { LogError("error during function executing"); } - } - else - { + } else { LogDebug("Operation failed. Exception code: " << event->getExceptionCode()); JSValueRef errorObject = NULL; CommonsJavaScript::JSCallbackManagerPtr callbackManager = privateData->getCallbackManager(); - if(callbackManager == NULL ) - { + if(callbackManager == NULL ) { LogWarning("callbackManager is null"); } JSContextRef context = callbackManager->getContext(); WrtDeviceApis::Commons::ExceptionCodes::Enumeration exception = event->getExceptionCode(); - switch(exception){ + switch (exception) { case WrtDeviceApis::Commons::ExceptionCodes::NotFoundException: errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::NOT_FOUND_ERROR,"given package is not found"); break; diff --git a/src/standards/Tizen/Application/ApplicationConverter.cpp b/src/standards/Tizen/Application/ApplicationConverter.cpp index 4554785..a71791a 100755 --- a/src/standards/Tizen/Application/ApplicationConverter.cpp +++ b/src/standards/Tizen/Application/ApplicationConverter.cpp @@ -29,7 +29,6 @@ #include "JSApplicationServiceData.h" #include "JSApplicationServiceData.h" #include "JSApplicationService.h" -//#include "JSApplicationServiceReply.h" namespace { const char* APPLICATOIN_ATTRIBUTE_NAME = "name"; @@ -37,6 +36,7 @@ namespace { const char* APPLICATOIN_ATTRIBUTE_CONTEXT_ID = "contextId"; const char* APPLICATOIN_ATTRIBUTE_ICONF_PATH = "iconPath"; const char* APPLICATOIN_ATTRIBUTE_VERSION = "version"; + const char* APPLICATOIN_ATTRIBUTE_SHOW = "show"; const char* APPLICATOIN_ATTRIBUTE_EXTRA_KEY = "key"; const char* APPLICATOIN_ATTRIBUTE_EXTRA_VALUE = "value"; const char* APPLICATOIN_ATTRIBUTE_OPERATION = "operation"; @@ -70,9 +70,8 @@ ApplicationConverter::~ApplicationConverter() JSValueRef ApplicationConverter::toJSValueRef(const ApplicationInformationPtr &arg) { - if(arg == NULL) - { - Throw(Commons::InvalidArgumentException); + if(arg == NULL) { + Throw(Commons::ConversionException); } return CommonsJavaScript::JSUtils::makeObject(m_context, JSApplicationInformation::getClassRef(), arg); } @@ -91,7 +90,8 @@ ApplicationInformationPtr ApplicationConverter::toApplicationInformation(const J const ScopedJSStringRef nameStr(JSStringCreateWithUTF8CString(APPLICATOIN_ATTRIBUTE_NAME)); const ScopedJSStringRef appIdStr(JSStringCreateWithUTF8CString(APPLICATOIN_ATTRIBUTE_APP_ID)); const ScopedJSStringRef iconPathStr(JSStringCreateWithUTF8CString(APPLICATOIN_ATTRIBUTE_ICONF_PATH)); - const ScopedJSStringRef versionStr(JSStringCreateWithUTF8CString(APPLICATOIN_ATTRIBUTE_VERSION)); + const ScopedJSStringRef versionStr(JSStringCreateWithUTF8CString(APPLICATOIN_ATTRIBUTE_VERSION)); + const ScopedJSStringRef showStr(JSStringCreateWithUTF8CString(APPLICATOIN_ATTRIBUTE_SHOW)); JSObjectRef jsObject = toJSObjectRef(jsValue); @@ -99,11 +99,13 @@ ApplicationInformationPtr ApplicationConverter::toApplicationInformation(const J 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); std::string name; std::string appid; std::string iconPath; - std::string version; + std::string version; + bool show; ApplicationInformationPtr result(new ApplicationInformation()); if (!result) { @@ -126,14 +128,17 @@ ApplicationInformationPtr ApplicationConverter::toApplicationInformation(const J version = toString(versionData); result->setVersion(version); } + if (!JSValueIsUndefined(m_context, showData)) { + show = toBool(showData); + result->setShow(show); + } return result; } JSValueRef ApplicationConverter::toJSValueRef(const ApplicationInformationArrayPtr &arg) { - if(arg == NULL) - { + if(arg == NULL) { Throw(Commons::InvalidArgumentException); } return CommonsJavaScript::JSUtils::makeObject(m_context, JSApplicationInformationArray::getClassRef(), arg); @@ -156,8 +161,7 @@ ApplicationInformationArrayPtr ApplicationConverter::toApplicationInformationArr JSValueRef ApplicationConverter::toJSValueRef(const ApplicationContextPtr &arg) { - if(arg == NULL) - { + if(arg == NULL) { Throw(Commons::InvalidArgumentException); } return CommonsJavaScript::JSUtils::makeObject(m_context, JSApplicationContext::getClassRef(), arg); @@ -206,9 +210,8 @@ ApplicationContextPtr ApplicationConverter::toApplicationContext(const JSValueRe JSValueRef ApplicationConverter::toJSValueRef(const ApplicationContextArrayPtr &arg) { - if(arg == NULL) - { - Throw(Commons::InvalidArgumentException); + if(arg == NULL) { + Throw(Commons::ConversionException); } return CommonsJavaScript::JSUtils::makeObject(m_context, JSApplicationContextArray::getClassRef(), arg); } @@ -335,16 +338,14 @@ JSValueRef ApplicationConverter::toJSValueRef(const std::vector ApplicationConverter::toApplicationServiceDataArray(const JSValueRef &jsValue) { - //return WrtDeviceApis::CommonsJavaScript::Converter::toVectorOfT_(jsValue, &ApplicationConverter::toApplicationServiceData); - if (JSValueIsNull(m_context, - jsValue) || JSValueIsUndefined(m_context, jsValue)) { + if (JSValueIsNull(m_context, jsValue) || JSValueIsUndefined(m_context, jsValue)) { return std::vector(); } diff --git a/src/standards/Tizen/Application/ApplicationInformationEventCallback.h b/src/standards/Tizen/Application/ApplicationInformationEventCallback.h deleted file mode 100755 index 42f02ee..0000000 --- a/src/standards/Tizen/Application/ApplicationInformationEventCallback.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_CALLBACK_H_ -#define TIZENAPIS_TIZEN_APPLICATION_INFORMATION_EVENT_CALLBACK_H_ - -#include - -namespace TizenApis { -namespace Tizen1_0 { -namespace Application { -struct ApplicationInformationEventCallback -{ - JSValueRef onInstalled; - JSValueRef onUpdated; - JSValueRef onUninstalled; - JSValueRef onError; - - ApplicationInformationEventCallback() : - onInstalled(NULL), - onUpdated(NULL), - onUninstalled(NULL), - onError(NULL) - { - } -}; - -typedef DPL::SharedPtr ApplicationInformationEventCallbackPtr; -} -} -} -#endif diff --git a/src/standards/Tizen/Application/ApplicationListener.cpp b/src/standards/Tizen/Application/ApplicationListener.cpp index 35d752f..2b35e6f 100755 --- a/src/standards/Tizen/Application/ApplicationListener.cpp +++ b/src/standards/Tizen/Application/ApplicationListener.cpp @@ -55,48 +55,43 @@ void ApplicationListener::onAnswerReceived(const EventInstalledApplicationChange { LogError(">>> onAnswerReceived for EventInstalledApplicationChanged"); ApplicationInformationEventPrivateDataPtr priveData = DPL::DynamicPointerCast(event->getPrivateData()); + JSContextRef context = priveData->getOnInstalled()->getContext(); + JSValueRef errorObject = NULL; + JSValueRef result = NULL; - if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) - { - Try - { - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(priveData->getOnInstalled()->getContext()); - // TODO: why send event code to string. enum value is enough!! - if (event->getEventCode() == APPLICATON_EVENT_CODE_INSTALLED) - { - LogError(">>> installed event is come"); - JSValueRef result = converter->toJSValueRef(event->getApplicationInformation()); - priveData->getOnInstalled()->callOnSuccess(result); - } - else if (event->getEventCode() == APPLICATON_EVENT_CODE_UPDATED) - { - LogError(">>> updated event is come"); - JSValueRef result = converter->toJSValueRef(event->getApplicationInformation()); - priveData->getOnUpdated()->callOnSuccess(result); + if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::None) { + Try { + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + switch(event->getEventCode()) { + case EventInstalledApplicationChanged::APPLICATON_CHANGED_EVENT_CODE_INSTALLED: + LogError(">>> installed event is come"); + result = converter->toJSValueRef(event->getApplicationInformation()); + priveData->getOnInstalled()->callOnSuccess(result); + break; + case EventInstalledApplicationChanged::APPLICATON_CHANGED_EVENT_CODE_UPDATED: + LogError(">>> updated event is come"); + result = converter->toJSValueRef(event->getApplicationInformation()); + priveData->getOnUpdated()->callOnSuccess(result); + break; + case EventInstalledApplicationChanged::APPLICATON_CHANGED_EVENT_CODE_UNINSTALLED: + LogError(">>> uninstalled event is come"); + result = converter->toJSValueRef(event->getApplicationInformation()->getAppId()); + priveData->getOnUninstalled()->callOnSuccess(result); + break; + default: + LogError(">>> unknown event is come"); + errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"unknown error"); + priveData->getOnInstalled()->callOnError(errorObject); + break; } - else if (event->getEventCode() == APPLICATON_EVENT_CODE_UNINSTALLED) - { - LogError(">>> uninstalled event is come"); - JSValueRef result = converter->toJSValueRef(event->getApplicationInformation()->getAppId()); - priveData->getOnUninstalled()->callOnSuccess(result); - } - } - Catch (WrtDeviceApis::Commons::Exception) - { + } Catch (WrtDeviceApis::Commons::Exception) { LogError("error during function executing"); + errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"unknown error"); + priveData->getOnInstalled()->callOnError(errorObject); } - } - else - { + } else { LogDebug("Operation failed. Exception code: " << event->getExceptionCode()); - JSValueRef errorObject = NULL; - - WrtDeviceApis::Commons::ExceptionCodes::Enumeration exception = event->getExceptionCode(); - switch(exception){ - default: - errorObject = JSTizenExceptionFactory::makeErrorObject(priveData->getOnInstalled()->getContext(),JSTizenException::UNKNOWN_ERROR,"unknown error"); - break; - } + errorObject = JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"unknown error"); priveData->getOnInstalled()->callOnError(errorObject); } } diff --git a/src/standards/Tizen/Application/ApplicationUtil.cpp b/src/standards/Tizen/Application/ApplicationUtil.cpp new file mode 100755 index 0000000..e6a5de4 --- /dev/null +++ b/src/standards/Tizen/Application/ApplicationUtil.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES 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 + +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)); +} + +} +} // +} // diff --git a/src/standards/Tizen/Application/ApplicationUtil.h b/src/standards/Tizen/Application/ApplicationUtil.h new file mode 100755 index 0000000..3fd8048 --- /dev/null +++ b/src/standards/Tizen/Application/ApplicationUtil.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES 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 + +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); + + protected: + JSContextRef m_context; + JSValueRef* m_exception; +}; +} +} // +} // + +#endif + diff --git a/src/standards/Tizen/Application/CMakeLists.txt b/src/standards/Tizen/Application/CMakeLists.txt index 2110c1d..c5285c8 100755 --- a/src/standards/Tizen/Application/CMakeLists.txt +++ b/src/standards/Tizen/Application/CMakeLists.txt @@ -2,6 +2,11 @@ set(TARGET_NAME "wrt-plugins-tizen-1.0-application") set(DESTINATION_NAME "tizen-1.0-application") include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_APPLICATION}) +set(CMAKE_INSTALL_RPATH + ${CMAKE_INSTALL_RPATH} + ${CMAKE_INSTALL_PREFIX}/tizen-1.0-tizen +) + set(SRCS # ${SRCS_PLATFORM_API_WRT_WRAPPER} ${SRCS_PLATFORM_API_APPLICATION} @@ -11,6 +16,7 @@ set(SRCS ApplicationAnswerReceiver.cpp ApplicationListener.cpp ApplicationConverter.cpp + ApplicationUtil.cpp JSApplication.cpp JSApplicationInformation.cpp JSApplicationInformationArray.cpp @@ -20,13 +26,11 @@ set(SRCS JSApplicationService.cpp JSApplicationServiceData.cpp LaunchServicePrivateData.cpp - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp ) add_library(${TARGET_NAME} SHARED ${SRCS}) target_link_libraries(${TARGET_NAME} + wrt-plugins-tizen-1.0-tizen-impl ${LIBS_COMMON} ${LIBS_PLATFORM_IMPLEMENTATION_APPLICATION} ) diff --git a/src/standards/Tizen/Application/JSApplication.cpp b/src/standards/Tizen/Application/JSApplication.cpp index f848129..2d6a2d0 100755 --- a/src/standards/Tizen/Application/JSApplication.cpp +++ b/src/standards/Tizen/Application/JSApplication.cpp @@ -35,8 +35,7 @@ #include "ApplicationListener.h" #include "JSApplication.h" #include "ApplicationConverter.h" -#include "ApplicationServiceReplyCallback.h" -#include "ApplicationInformationEventCallback.h" +#include "ApplicationUtil.h" #include "LaunchServicePrivateData.h" #include "ApplicationInformationEventPrivateData.h" #include "JSApplicationService.h" @@ -81,9 +80,9 @@ JSStaticFunction JSApplication::m_function[] = { { "launch",JSApplication::launch,kJSPropertyAttributeNone }, { "exit",JSApplication::exit,kJSPropertyAttributeNone }, { "kill",JSApplication::kill,kJSPropertyAttributeNone }, - { "hide",JSApplication::hide,kJSPropertyAttributeNone }, - { "getApplicationInformations",JSApplication::getApplicationInformations,kJSPropertyAttributeNone }, - { "getRunningApplicationContexts",JSApplication::getRunningApplicationContexts,kJSPropertyAttributeNone }, + /*{ "hide",JSApplication::hide,kJSPropertyAttributeNone },*/ + { "getApplicationsInformation",JSApplication::getApplicationsInformation,kJSPropertyAttributeNone }, + { "getRunningApplicationsContext",JSApplication::getRunningApplicationsContext,kJSPropertyAttributeNone }, { "getApplicationInformation",JSApplication::getApplicationInformation,kJSPropertyAttributeNone }, { "getCurrentApplicationContext",JSApplication::getCurrentApplicationContext,kJSPropertyAttributeNone }, { "addApplicationInformationEventListener",JSApplication::addApplicationInformationEventListener,kJSPropertyAttributeNone }, @@ -93,29 +92,36 @@ JSStaticFunction JSApplication::m_function[] = { { 0, 0, 0 } }; -const JSClassRef JSApplication::getClassRef() { +const JSClassRef JSApplication::getClassRef() +{ if (!m_jsClassRef) { m_jsClassRef = JSClassCreate(&m_classInfo); } + return m_jsClassRef; } -const JSClassDefinition* JSApplication::getClassInfo() { +const JSClassDefinition* JSApplication::getClassInfo() +{ return &m_classInfo; } -void JSApplication::initialize(JSContextRef context, JSObjectRef object) { +void JSApplication::initialize(JSContextRef context, JSObjectRef object) +{ JSApplicationPriv* priv = static_cast(JSObjectGetPrivate(object)); assert(!priv && "Invalid object creation."); + IApplicationPtr applications(ApplicationFactory::getInstance().createApplication()); priv = new JSApplicationPriv(context, applications); + if (!JSObjectSetPrivate(object, static_cast(priv))) { LogError("Object can't store private data."); delete priv; } } -void JSApplication::finalize(JSObjectRef object) { +void JSApplication::finalize(JSObjectRef object) +{ JSApplicationPriv* priv = static_cast (JSObjectGetPrivate(object)); JSObjectSetPrivate(object, NULL); delete priv; @@ -138,63 +144,58 @@ JSValueRef JSApplication::launch(JSContextRef context, { JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); assert(priv && "Invalid private pointer."); - JSContextRef gContext = priv->getContext(); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - gContext, - APPLICATION_FUNCTION_API_LAUNCH); + JSContextRef gContext = priv->getContext(); + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(gContext, APPLICATION_FUNCTION_API_LAUNCH); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + if ((argumentCount < 2) || (argumentCount > 4)) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } - if ((argumentCount < 2) || - (JSValueIsNull(context, arguments[0]) || - JSValueIsUndefined(context, arguments[0]) || - JSObjectIsFunction(context, converter->toJSObjectRef(arguments[0]))) || - (JSValueIsNull(context, arguments[1]) || - JSValueIsUndefined(context, arguments[1]) || - !JSObjectIsFunction(context, converter->toJSObjectRef(arguments[1]))) || - (argumentCount > 2 && - (JSValueIsUndefined(context, arguments[2]) || - !JSObjectIsFunction(context, converter->toJSObjectRef(arguments[2])))) || - (argumentCount > 3 && - (JSValueIsUndefined(context, arguments[3]) || - JSObjectIsFunction(context, converter->toJSObjectRef(arguments[3]))))) { - LogError("Wrong callbacks parameters"); - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - } + ApplicationUtil util(context, exception); + if (!util.isString(arguments[0]) || + !util.isFunction(arguments[1]) || + (argumentCount > 2 && !util.isNullOrFunction(arguments[2])) || + (argumentCount > 3 && !util.isNullOrString(arguments[3]))) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); callbackManager->setOnSuccess(arguments[1]); - if (argumentCount > 2) + if (argumentCount > 2) { callbackManager->setOnError(arguments[2]); + } + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); EventManageApplicationPtr event(new EventManageApplication()); - Try{ + + Try { IApplicationPtr applications(priv->getObject()); event->setEventType(EventManageApplication::APP_MANAGER_LAUNCH_APPLICATION); - event->setAppId(converter->toString( arguments[0] )); + event->setAppId(converter->toString(arguments[0])); + // TODO: argument passing is not supported yet if (argumentCount > 3) { - event->setArgument(converter->toString(arguments[3])); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Not yet supported"); + //event->setArgument(converter->toString(arguments[3])); } event->setPrivateData(StaticPointerCast(callbackManager)); event->setForAsynchronousCall(new ApplicationAnswerReceiver(callbackManager)); applications->launch(event); - }Catch (WrtDeviceApis::Commons::ConversionException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - }Catch (WrtDeviceApis::Commons::PendingOperationException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Pending operation failed")); - return JSValueMakeUndefined(context); - }Catch (WrtDeviceApis::Commons::InvalidArgumentException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Invalid value error")); - return JSValueMakeUndefined(context); - }Catch (WrtDeviceApis::Commons::NullPointerException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"Unknown error")); - return JSValueMakeUndefined(context); - }Catch(WrtDeviceApis::Commons::Exception){ + + } 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } + return JSValueMakeUndefined(context); } @@ -207,45 +208,31 @@ JSValueRef JSApplication::kill(JSContextRef context, { JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); assert(priv && "Invalid private pointer."); - JSContextRef gContext = priv->getContext(); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - gContext, - APPLICATION_FUNCTION_API_KILL); + JSContextRef gContext = priv->getContext(); + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(gContext, APPLICATION_FUNCTION_API_KILL); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + if ((argumentCount < 1) || (argumentCount > 2)) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } - if ((argumentCount < 2) || - (JSValueIsNull(context, - arguments[0]) || - JSValueIsUndefined(context, - arguments[0]) || - !JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[0]))) || - (JSValueIsNull(context, - arguments[1]) || - JSValueIsUndefined(context, - arguments[1]) || - !JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[1]))) || - (argumentCount > 2 && - !JSValueIsNull(context, - arguments[2]) && - !JSValueIsUndefined(context, - arguments[2]) && - !JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[2])))) { - LogError("Wrong callbacks parameters"); - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - } + ApplicationUtil util(context, exception); + if (!util.isObject(arguments[0]) || + ((argumentCount > 1) && !util.isNullOrFunction(arguments[2]))) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); - callbackManager->setOnSuccess(arguments[1]); - if (argumentCount > 2) - callbackManager->setOnError(arguments[2]); - + if (argumentCount > 1) { + callbackManager->setOnSuccess(arguments[1]); + } + + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); EventManageApplicationPtr event(new EventManageApplication()); + Try{ ApplicationContextPtr appContext = converter->toApplicationContext(arguments[0]); @@ -255,21 +242,18 @@ JSValueRef JSApplication::kill(JSContextRef context, event->setPrivateData(StaticPointerCast(callbackManager)); event->setForAsynchronousCall(new ApplicationAnswerReceiver(callbackManager)); applications->kill(event); - }Catch (WrtDeviceApis::Commons::ConversionException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - }Catch (WrtDeviceApis::Commons::PendingOperationException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Pending operation failed")); - return JSValueMakeUndefined(context); - }Catch (WrtDeviceApis::Commons::InvalidArgumentException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Invalid value error")); - return JSValueMakeUndefined(context); - }Catch (WrtDeviceApis::Commons::NullPointerException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"Unknown error")); - return JSValueMakeUndefined(context); - }Catch(WrtDeviceApis::Commons::Exception){ + + } 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } + return JSValueMakeUndefined(context); } @@ -280,28 +264,28 @@ JSValueRef JSApplication::exit(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - LogError("== [WS] enter JSApplication::exit"); - JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); assert(priv && "Invalid private pointer."); - JSContextRef gContext = priv->getContext(); - LogError("== [WS] call ACE"); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - gContext, - APPLICATION_FUNCTION_API_EXIT); + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(priv->getContext(), APPLICATION_FUNCTION_API_EXIT); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - Try{ - LogError("== [WS] get applications"); + if (argumentCount != 0) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } + + Try { IApplicationPtr applications(priv->getObject()); - LogError("== [WS] applications->exit()"); applications->exit(); - } Catch(WrtDeviceApis::Commons::Exception){ + + } 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } - LogError("exit JSApplication::exit"); + return JSValueMakeUndefined(context); } @@ -313,76 +297,37 @@ JSValueRef JSApplication::hide(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Not yet supported"); + +#if 0 JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); assert(priv && "Invalid private pointer."); - JSContextRef gContext = priv->getContext(); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - gContext, - APPLICATION_FUNCTION_API_HIDE); + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(priv->getContext(), APPLICATION_FUNCTION_API_HIDE); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - - if ((argumentCount < 2) || - (JSValueIsNull(context, - arguments[0]) || - JSValueIsUndefined(context, - arguments[0]) || - !JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[0]))) || - (JSValueIsNull(context, - arguments[1]) || - JSValueIsUndefined(context, - arguments[1]) || - !JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[1]))) || - (argumentCount > 2 && - !JSValueIsNull(context, - arguments[2]) && - !JSValueIsUndefined(context, - arguments[2]) && - !JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[2])))) { - LogError("Wrong callbacks parameters"); - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - } - - JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); - callbackManager->setOnSuccess(arguments[1]); - if (argumentCount > 2) - callbackManager->setOnError(arguments[2]); + if (argumentCount != 0) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } - EventManageApplicationPtr event(new EventManageApplication()); - Try{ - ApplicationContextPtr appContext = converter->toApplicationContext(arguments[0]); - + Try { IApplicationPtr applications(priv->getObject()); - event->setEventType(EventManageApplication::APP_MANAGER_HIDE_APPLICATION); - event->setApplicationContext(appContext); - event->setPrivateData(StaticPointerCast(callbackManager)); - event->setForAsynchronousCall(new ApplicationAnswerReceiver(callbackManager)); - applications->hide(event); - }Catch (WrtDeviceApis::Commons::ConversionException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - }Catch (WrtDeviceApis::Commons::PendingOperationException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Pending operation failed")); - return JSValueMakeUndefined(context); - }Catch (WrtDeviceApis::Commons::InvalidArgumentException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Invalid value error")); - return JSValueMakeUndefined(context); - }Catch (WrtDeviceApis::Commons::NullPointerException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"Unknown error")); - return JSValueMakeUndefined(context); - }Catch(WrtDeviceApis::Commons::Exception){ + applications->hide(); + + } 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } + return JSValueMakeUndefined(context); +#endif } -JSValueRef JSApplication::getApplicationInformations(JSContextRef context, +JSValueRef JSApplication::launchService(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, @@ -391,116 +336,126 @@ JSValueRef JSApplication::getApplicationInformations(JSContextRef context, { JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); assert(priv && "Invalid private pointer."); - JSContextRef gContext = priv->getContext(); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - gContext, - APPLICATION_FUNCTION_API_GET_APPLICATION_INFORMATIONS); - TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + JSContextRef gContext = priv->getContext(); + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(gContext, APPLICATION_FUNCTION_API_LAUNCH_SERVICE); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + if ((argumentCount < 2) || (argumentCount > 4)) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } - if ((argumentCount == 0) || - (JSValueIsNull(context, - arguments[0]) || - JSValueIsUndefined(context, - arguments[0]) || - !JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[0]))) || - (argumentCount > 1 && - !JSValueIsNull(context, - arguments[1]) && - !JSValueIsUndefined(context, - arguments[1]) && - !JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[1])))) { - LogError("Wrong callbacks parameters"); - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - } + ApplicationUtil util(context, exception); + if (!util.isObject(arguments[0]) || + !util.isFunction(arguments[1]) || + ((argumentCount > 2) && !util.isNullOrFunction(arguments[2])) || + ((argumentCount > 3) && !util.isNullOrObject(arguments[3]))) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); - callbackManager->setOnSuccess(arguments[0]); - if (argumentCount > 1) - callbackManager->setOnError(arguments[1]); + callbackManager->setOnSuccess(arguments[1]); + if (argumentCount > 2) + callbackManager->setOnError(arguments[2]); - EventListInstalledApplicationsPtr event(new EventListInstalledApplications()); - Try{ + JSCallbackManagerPtr replyCallbackManager; + if (argumentCount == 4) { + JSObjectRef cbObj = JSValueToObject(context, arguments[3], exception); + JSValueRef onsuccess = JSUtils::getJSProperty(context, cbObj, "onSuccess"); + JSValueRef onfail = JSUtils::getJSProperty(context, cbObj, "onFailed"); + + if (!util.isFunction(onsuccess) || !util.isFunction(onfail)) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } + + replyCallbackManager = JSCallbackManager::createObject(gContext, onsuccess, onfail); + } + + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + EventLaunchServicePtr event(new EventLaunchService()); + + Try { + ApplicationServicePtr appService = converter->toApplicationService(arguments[0]); + LaunchServicePrivateDataPtr privateData(new LaunchServicePrivateData(callbackManager,replyCallbackManager)); IApplicationPtr applications(priv->getObject()); - event->setEventType(EventListInstalledApplications::APPMANAGER_LIST_INSTALLED_APPLICATIONS); - event->setPrivateData(StaticPointerCast(callbackManager)); - event->setForAsynchronousCall(new ApplicationAnswerReceiver(callbackManager)); - applications->listApplications(event); - }Catch (WrtDeviceApis::Commons::ConversionException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - }Catch (WrtDeviceApis::Commons::PendingOperationException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Pending operation failed")); - return JSValueMakeUndefined(context); - }Catch (WrtDeviceApis::Commons::InvalidArgumentException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Invalid value error")); - return JSValueMakeUndefined(context); - }Catch (WrtDeviceApis::Commons::NullPointerException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"Unknown error")); - return JSValueMakeUndefined(context); - }Catch(WrtDeviceApis::Commons::Exception){ + + event->setEventType(EventLaunchService::APPLICATION_SERVICE_LAUNCH); + event->setPrivateData(StaticPointerCast (privateData)); + event->setService(appService); + event->setForAsynchronousCall(new ApplicationAnswerReceiver(privateData)); + + applications->launchService(event); + + } 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } - return JSValueMakeUndefined(context); + + return JSValueMakeUndefined(context); } -JSValueRef JSApplication::getApplicationInformation(JSContextRef context, +JSValueRef JSApplication::getApplicationService(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Not yet supported"); +#if 0 + JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); assert(priv && "Invalid private pointer."); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - priv->getContext(), - APPLICATION_FUNCTION_API_GET_APPLICATION_INFORMATION); - TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(priv->getContext(), APPLICATION_FUNCTION_API_GET_APP_SERVICE); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - std::string appid; - - if ((argumentCount == 0) || ((argumentCount == 1) && JSValueIsNull(context, arguments[0]))) { - // skip. return empty string - } else if ((argumentCount == 1) && JSValueIsString(context, arguments[0])) { - appid = converter->toString( arguments[0] ); - } else if (JSValueIsUndefined(context, arguments[0])) { - LogError("Wrong package " << JSValueIsNull(context, arguments[0]) <<", "<getObject()); - EventGetApplicationPtr event(new EventGetApplication()); - event->setEventType(EventGetApplication::APP_MANAGER_GET_INFORMATION); + event->setEventType(EventLaunchService::APPLICATION_SERVICE_GET_REQUEST); event->setForSynchronousCall(); - event->setAppId(appid); - applications->getApplication(event); + applications->getApplicationService(event); + if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException) { - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::NOT_FOUND_ERROR, "Given package is not found"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "no service request found"); + } else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) { + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } - return converter->toJSValueRef(event->getApplicationInformation()); - }Catch (WrtDeviceApis::Commons::ConversionException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - }Catch (WrtDeviceApis::Commons::InvalidArgumentException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR,"Invalid value error"); - }Catch (WrtDeviceApis::Commons::NullPointerException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); - }Catch(WrtDeviceApis::Commons::Exception){ + + return converter->toJSValueRef(event->getService()); + + } 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } +#endif } -JSValueRef JSApplication::getRunningApplicationContexts(JSContextRef context, + +JSValueRef JSApplication::getRunningApplicationsContext(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, @@ -508,65 +463,53 @@ JSValueRef JSApplication::getRunningApplicationContexts(JSContextRef context, JSValueRef* exception) { JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); - assert(priv && "Invalid private pointer."); - JSContextRef gContext = priv->getContext(); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - gContext, - APPLICATION_FUNCTION_API_GET_RUNNING_APPLICATION_CONTEXTS); + JSContextRef gContext = priv->getContext(); + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(gContext, APPLICATION_FUNCTION_API_GET_RUNNING_APPS_CONTEXT); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + if ((argumentCount < 1) || (argumentCount > 2)) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } - if ((argumentCount == 0) || - (JSValueIsNull(context, - arguments[0]) || - JSValueIsUndefined(context, - arguments[0]) || - !JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[0]))) || - (argumentCount > 1 && - !JSValueIsNull(context, - arguments[1]) && - !JSValueIsUndefined(context, - arguments[1]) && - !JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[1])))) { - LogError("Wrong callbacks parameters"); - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - } + ApplicationUtil util(context, exception); + if (!util.isFunction(arguments[0]) || + !util.isNullOrFunction(arguments[1])) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); callbackManager->setOnSuccess(arguments[0]); - if (argumentCount > 1) + if (argumentCount > 1) { callbackManager->setOnError(arguments[1]); + } EventListInstalledApplicationsPtr event(new EventListInstalledApplications()); - Try{ + Try { IApplicationPtr applications(priv->getObject()); event->setEventType(EventListInstalledApplications::APPMANAGER_LIST_RUNNING_APPLICATIONS); event->setPrivateData(StaticPointerCast(callbackManager)); event->setForAsynchronousCall(new ApplicationAnswerReceiver(callbackManager)); applications->listApplications(event); - }Catch (WrtDeviceApis::Commons::ConversionException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - }Catch (WrtDeviceApis::Commons::PendingOperationException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Pending operation failed")); - return JSValueMakeUndefined(context); - }Catch (WrtDeviceApis::Commons::InvalidArgumentException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Invalid value error")); - return JSValueMakeUndefined(context); - }Catch (WrtDeviceApis::Commons::NullPointerException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"Unknown error")); - return JSValueMakeUndefined(context); - }Catch(WrtDeviceApis::Commons::Exception){ + + } 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } + return JSValueMakeUndefined(context); } + JSValueRef JSApplication::getCurrentApplicationContext(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, @@ -575,49 +518,41 @@ JSValueRef JSApplication::getCurrentApplicationContext(JSContextRef context, JSValueRef* exception) { JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); - assert(priv && "Invalid private pointer."); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - priv->getContext(), - APPLICATION_FUNCTION_API_GET_CURRENT_APPLICATION_CONTEXT); + + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(priv->getContext(), APPLICATION_FUNCTION_API_GET_CURRENT_APP_CONTEXT); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - -#if 0 - if(JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0])){ - LogError("Wrong package " << JSValueIsNull(context, arguments[0]) <<", "<getObject()); event->setEventType(EventGetApplication::APP_MANAGER_GET_CONTEXT); event->setForSynchronousCall(); applications->getApplication(event); - if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException) { - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::NOT_FOUND_ERROR, "Given package is not found"); - } else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) { - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + + if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) { + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } + return converter->toJSValueRef(event->getApplicationContext()); - }Catch (WrtDeviceApis::Commons::ConversionException){ - LogError("== [WS] error on type mismatch"); - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - }Catch (WrtDeviceApis::Commons::InvalidArgumentException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR,"Invalid value error"); - }Catch (WrtDeviceApis::Commons::NullPointerException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); - }Catch(WrtDeviceApis::Commons::Exception){ + + } 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } } -JSValueRef JSApplication::addApplicationInformationEventListener(JSContextRef context, + +JSValueRef JSApplication::getApplicationsInformation(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, @@ -625,278 +560,236 @@ JSValueRef JSApplication::addApplicationInformationEventListener(JSContextRef co JSValueRef* exception) { JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); - assert(priv && "Invalid private pointer."); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - priv->getContext(), - APPLICATION_FUNCTION_API_ADD_APPLICATION_INFORMATION_EVENT_LISTENER); + + JSContextRef gContext = priv->getContext(); + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(gContext, APPLICATION_FUNCTION_API_GET_APPS_INFO); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - if ((argumentCount == 0) || - (JSValueIsNull(context, - arguments[0]) || - JSValueIsUndefined(context, - arguments[0]) || - JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[0]))) || - (argumentCount > 1 && - !JSValueIsNull(context, - arguments[1]) && - !JSValueIsUndefined(context, - arguments[1]) && - !JSObjectIsFunction(context, - converter->toJSObjectRef(arguments[1])))) { - LogError("Wrong callbacks parameters"); - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - } - - JSObjectRef objectCallbacks = converter->toJSObjectRef(arguments[0]); - - ApplicationInformationEventCallback result; - result.onInstalled = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onInstalled"); - result.onUpdated = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onUpdated"); - result.onUninstalled = JSUtils::getJSPropertyOrUndefined(context, objectCallbacks, "onUninstalled"); - - if (argumentCount == 2) { - result.onError = arguments[1]; - } else { - result.onError =JSValueMakeUndefined(context); - } - - Validator validator(context); - if ((!validator.isNullOrUndefined(result.onInstalled) && !validator.isCallback(result.onInstalled)) || - (!validator.isNullOrUndefined(result.onUpdated) && !validator.isCallback(result.onUpdated)) || - (!validator.isNullOrUndefined(result.onUninstalled) && !validator.isCallback(result.onUninstalled))) - { - LogError("Application Information Event Callbakc is not set properly!"); - Throw(InvalidArgumentException); - } - - JSCallbackManagerPtr onInstalledCbm = JSCallbackManager::createObject(priv->getContext(), result.onInstalled, result.onError); - JSCallbackManagerPtr onUpdatedCbm = JSCallbackManager::createObject(priv->getContext(), result.onUpdated, result.onError); - JSCallbackManagerPtr onUninstalledCbm = JSCallbackManager::createObject(priv->getContext(), result.onUninstalled, result.onError); - - ApplicationInformationEventPrivateDataPtr privData(new ApplicationInformationEventPrivateData(onInstalledCbm, onUpdatedCbm, onUninstalledCbm)); - Try { - IApplicationPtr applications(priv->getObject()); - EventInstalledApplicationChangedEmitterPtr emitter(new EventInstalledApplicationChangedEmitter); - emitter->setListener(&ApplicationListener::getInstance()); - emitter->setEventPrivateData(StaticPointerCast(privData)); - unsigned long id = applications->addApplicationInformationEventListener(emitter); - LogInfo("id = "< 2)) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } - 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 or already registered"); - } Catch (WrtDeviceApis::Commons::InvalidArgumentException){ - onUpdatedCbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Invalid value error")); - return JSValueMakeUndefined(context); - } Catch (WrtDeviceApis::Commons::NullPointerException){ - onUpdatedCbm->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"Unknown error")); - return JSValueMakeUndefined(context); - } Catch(WrtDeviceApis::Commons::Exception){ + ApplicationUtil util(context, exception); + if (!util.isFunction(arguments[0]) || + !util.isNullOrFunction(arguments[1])) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } + + JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); + callbackManager->setOnSuccess(arguments[0]); + if (argumentCount > 1) { + callbackManager->setOnError(arguments[1]); + } + + EventListInstalledApplicationsPtr event(new EventListInstalledApplications()); + Try{ + IApplicationPtr applications(priv->getObject()); + event->setEventType(EventListInstalledApplications::APPMANAGER_LIST_INSTALLED_APPLICATIONS); + event->setPrivateData(StaticPointerCast(callbackManager)); + event->setForAsynchronousCall(new ApplicationAnswerReceiver(callbackManager)); + applications->listApplications(event); + + } 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } + + return JSValueMakeUndefined(context); } -JSValueRef JSApplication::removeApplicationInformationEventListener(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) +JSValueRef JSApplication::getApplicationInformation(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) { - JSApplicationPriv *priv = static_cast(JSObjectGetPrivate(thisObject)); - assert(priv && "Invalid private pointer."); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - priv->getContext(), - APPLICATION_FUNCTION_API_REMOVE_APPLICATION_INFORMATION_EVENT_LISTENER); + JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); + assert(priv && "Invalid private pointer."); + + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(priv->getContext(), APPLICATION_FUNCTION_API_GET_APP_INFO); TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - Try - { - IApplicationPtr applications = priv->getObject(); - assert(applications && "Application object not present."); - if (argumentCount < 1) { - Throw(WrtDeviceApis::Commons::InvalidArgumentException); - } + if (argumentCount > 1) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } - long id = converter->toLong(arguments[0]); - applications->removeApplicationInformationEventListener(id); - }Catch (WrtDeviceApis::Commons::InvalidArgumentException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - }Catch (WrtDeviceApis::Commons::ConversionException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - }Catch (WrtDeviceApis::Commons::NullPointerException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); - }Catch(WrtDeviceApis::Commons::Exception){ + ApplicationUtil util(context, exception); + if ((argumentCount == 1) && !util.isNullOrString(arguments[0])) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } + + EventGetApplicationPtr event(new EventGetApplication()); + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + + Try { + IApplicationPtr applications(priv->getObject()); + event->setEventType(EventGetApplication::APP_MANAGER_GET_INFORMATION); + event->setForSynchronousCall(); + if (argumentCount == 1 && util.isString(arguments[0])) { + event->setAppId(converter->toString(arguments[0])); + } + applications->getApplication(event); + + if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException) { + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "Given package is not found"); + } else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) { + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } + + return converter->toJSValueRef(event->getApplicationInformation()); + + } 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } - return JSValueMakeUndefined(context); } -JSValueRef JSApplication::launchService(JSContextRef context, + +JSValueRef JSApplication::addApplicationInformationEventListener(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - LogInfo("launchService <<<"); - LogDebug("argumentConunt:" << argumentCount); JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); assert(priv && "Invalid private pointer."); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - priv->getContext(), - APPLICATION_FUNCTION_API_LAUNCH_SERVICE); - TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - JSContextRef gContext = priv->getContext(); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + JSContextRef gContext = priv->getContext(); + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(gContext, APPLICATION_FUNCTION_API_ADD_APP_INFO_EVENT_LISTENER); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - if ((argumentCount < 1) || - (JSValueIsNull(context, arguments[0]) || - JSValueIsUndefined(context, arguments[0]) || - JSObjectIsFunction(context, converter->toJSObjectRef(arguments[0]))) || - ( (argumentCount > 1) && - !JSObjectIsFunction(context, converter->toJSObjectRef(arguments[1]))) || - ( (argumentCount > 2) && - !JSObjectIsFunction(context, converter->toJSObjectRef(arguments[2]))) || - ( (argumentCount > 3) && - JSObjectIsFunction(context, converter->toJSObjectRef(arguments[3])))) { - LogError("Wrong parameters"); - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + if ((argumentCount < 1) || (argumentCount > 2)) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); } - JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); - callbackManager->setOnSuccess(arguments[1]); - if (argumentCount > 2) - callbackManager->setOnError(arguments[2]); + ApplicationUtil util(context, exception); + if (!util.isObject(arguments[0]) || + !util.isNullOrFunction(arguments[1])) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } + + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - try { - ApplicationServicePtr appService; - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - appService = converter->toApplicationService(arguments[0]); - - JSCallbackManagerPtr replyCallbackManager; - if( argumentCount >3) - { - CommonsJavaScript::Validator validator(gContext); - ApplicationServiceReplyCallback result; - - JSObjectRef obj = JSValueToObject(context, arguments[3], NULL); - - result.onsuccess = JSUtils::getJSProperty(context, obj, "onSuccess"); - - if (!validator.isNullOrUndefined(result.onsuccess) && - !validator.isCallback(result.onsuccess)) { - ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Not a valid callback."); - } - - result.onfail = JSUtils::getJSProperty(context, obj, "onFailed"); - if (!validator.isNullOrUndefined(result.onfail) && - !validator.isCallback(result.onfail)) { - ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Not a valid callback."); - } - - if(result.onsuccess || result.onfail) - { - replyCallbackManager = JSCallbackManager::createObject(priv->getContext(), - result.onsuccess, result.onfail); - } + Try { + 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"); + + if (!util.isFunction(onInstalled) || !util.isFunction(onUpdated) || !util.isFunction(onUninstalled)) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); } - LogDebug("replyCallback"<getObject()); + emitter->setListener(&ApplicationListener::getInstance()); + emitter->setEventPrivateData(StaticPointerCast(privData)); + unsigned long id = applications->addApplicationInformationEventListener(emitter); - event->setEventType(EventLaunchService::APPLICATION_SERVICE_LAUNCH); - event->setPrivateData(StaticPointerCast (privateData)); - event->setService(appService); - event->setForAsynchronousCall(new ApplicationAnswerReceiver(privateData)); + if (id == 0) { + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "only one event listener can be registered."); + } - applications->launchService(event); - }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){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::INVALID_VALUES_ERROR,"Invalid value error")); - return JSValueMakeUndefined(context); - }Catch (WrtDeviceApis::Commons::NullPointerException){ - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(context,JSTizenException::UNKNOWN_ERROR,"Unknown error")); - return JSValueMakeUndefined(context); - }Catch(WrtDeviceApis::Commons::Exception){ + 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } - - return JSValueMakeUndefined(context); } -JSValueRef JSApplication::getApplicationService(JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) +JSValueRef JSApplication::removeApplicationInformationEventListener(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) { - JSApplicationPriv *priv = static_cast (JSObjectGetPrivate(thisObject)); + JSApplicationPriv *priv = static_cast(JSObjectGetPrivate(thisObject)); + assert(priv && "Invalid private pointer."); + + AceSecurityStatus status = APPLICATION_CHECK_ACCESS(priv->getContext(), APPLICATION_FUNCTION_API_REMOVE_APP_INFO_EVENT_LISTENER); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - LogDebug("enter getApplicationService"); + if (argumentCount != 1) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } - assert(priv && "Invalid private pointer."); - AceSecurityStatus status = APPLICATION_CHECK_ACCESS( - priv->getContext(), - APPLICATION_FUNCTION_API_GET_APPLICATION_SERVICE); - TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + if (!JSValueIsNumber(context, arguments[0]) || + JSValueIsNull(context, arguments[0]) || + JSValueIsUndefined(context, arguments[0])) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - - LogDebug("get EventLaunchServicePtr"); - EventLaunchServicePtr event(new EventLaunchService()); + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - Try - { - IApplicationPtr applications(priv->getObject()); - event->setEventType(EventLaunchService::APPLICATION_SERVICE_GET_REQUEST); - event->setForSynchronousCall(); - LogDebug("call getApplicationService"); - applications->getApplicationService(event); - if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::NotFoundException) { - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::NOT_FOUND_ERROR, "Given package is not found"); - } else if (event->getExceptionCode() == WrtDeviceApis::Commons::ExceptionCodes::UnknownException) { - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); - } - LogDebug("return result"); - return converter->toJSValueRef(event->getService()); - }Catch (WrtDeviceApis::Commons::ConversionException){ - LogError("== [WS] error on type mismatch"); - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); - }Catch (WrtDeviceApis::Commons::InvalidArgumentException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR,"Invalid value error"); - }Catch (WrtDeviceApis::Commons::NullPointerException){ - return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); - }Catch(WrtDeviceApis::Commons::Exception){ + Try { + IApplicationPtr applications(priv->getObject()); + long id = converter->toLong(arguments[0]); + + applications->removeApplicationInformationEventListener(id); + + } Catch (WrtDeviceApis::Commons::NotFoundException) { + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "id is not matched"); + } 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"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Unknown error"); } + + return JSValueMakeUndefined(context); } + } } } diff --git a/src/standards/Tizen/Application/JSApplication.h b/src/standards/Tizen/Application/JSApplication.h index cf6a64d..48ccb01 100755 --- a/src/standards/Tizen/Application/JSApplication.h +++ b/src/standards/Tizen/Application/JSApplication.h @@ -76,13 +76,13 @@ private: /** * Gets the list of installed packages. */ - static JSValueRef getApplicationInformations(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, + static JSValueRef getApplicationsInformation(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); /** * Gets the list of running packages. */ - static JSValueRef getRunningApplicationContexts(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, + static JSValueRef getRunningApplicationsContext(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); /** diff --git a/src/standards/Tizen/Application/JSApplicationContext.cpp b/src/standards/Tizen/Application/JSApplicationContext.cpp index 01f102c..1c03942 100755 --- a/src/standards/Tizen/Application/JSApplicationContext.cpp +++ b/src/standards/Tizen/Application/JSApplicationContext.cpp @@ -36,7 +36,7 @@ using namespace TizenApis::Commons; namespace { const char* APPLICATION_CONTEXT_APP_ID = "appId"; -const char* APPLICATION_CONTEXT_CONTEXT_ID = "contextId"; +const char* APPLICATION_CONTEXT_CONTEXT_ID = "id"; } //private namespace @@ -52,8 +52,8 @@ JSClassDefinition JSApplicationContext::m_classInfo = { initialize, finalize, NULL, //HasProperty, - NULL, - NULL, //SetProperty, + getProperty, //GetProperty, + setProperty, //SetProperty, NULL, //DeleteProperty, NULL, //GetPropertyNames, NULL, //CallAsFunction, @@ -63,8 +63,8 @@ JSClassDefinition JSApplicationContext::m_classInfo = { }; JSStaticValue JSApplicationContext::m_property[] = { - { APPLICATION_CONTEXT_APP_ID, getAppId, setAppId, kJSPropertyAttributeReadOnly }, - { APPLICATION_CONTEXT_CONTEXT_ID, getContextId, setContextId, kJSPropertyAttributeReadOnly }, + { APPLICATION_CONTEXT_APP_ID, getProperty, setProperty, kJSPropertyAttributeReadOnly }, + { APPLICATION_CONTEXT_CONTEXT_ID, getProperty, setProperty, kJSPropertyAttributeReadOnly }, { 0, 0, 0, 0 } }; @@ -76,29 +76,36 @@ JSClassRef JSApplicationContext::getClassRef() { } JSValueRef JSApplicationContext::createJSObject(JSContextRef context, - const std::string &appId, - const std::string &contextId) + const std::string &appId, + const std::string &contextId) { ApplicationContextPtr privateData = ApplicationContextPtr(new ApplicationContext()); - privateData->setAppId(appId); - privateData->setContextId(contextId); + privateData->setContextId(contextId); + JSApplicationContextPriv *priv = new JSApplicationContextPriv(context, privateData); + JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); if (NULL == jsValueRef) { LogError("object creation error"); return JSValueMakeUndefined(context); } + return jsValueRef; } void JSApplicationContext::initialize(JSContextRef context, JSObjectRef object) { - assert(NULL != JSObjectGetPrivate(object)); + LogInfo(">> initialize"); } void JSApplicationContext::finalize(JSObjectRef object) { + LogInfo(">> finalize"); + JSApplicationContextPriv* priv = static_cast(JSObjectGetPrivate(object)); + JSObjectSetPrivate(object, NULL); + LogDebug("Deleting JSApplicationContext object"); + delete priv; } bool JSApplicationContext::isObjectOfClass(JSContextRef context, JSValueRef value) @@ -112,10 +119,12 @@ ApplicationContextPtr JSApplicationContext::getPrivData(JSObjectRef 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; } @@ -124,92 +133,68 @@ ApplicationContextPtr JSApplicationContext::getApplicationContext(JSContextRef c if (!isObjectOfClass(context, value)) { Throw(WrtDeviceApis::Commons::InvalidArgumentException); } + JSObjectRef object = JSValueToObject(context, value, NULL); if (!object) { Throw(WrtDeviceApis::Commons::InvalidArgumentException); } + JSApplicationContextPriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { Throw(WrtDeviceApis::Commons::NullPointerException); } + return priv->getObject(); } -JSValueRef JSApplicationContext::getAppId(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) + +JSValueRef JSApplicationContext::getProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) { - Try - { + Try { CommonsJavaScript::Converter converter(context); ApplicationContextPtr privateData = getPrivData(object); - return converter.toJSValueRef(privateData->getAppId()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } + + if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_CONTEXT_APP_ID)) { + return converter.toJSValueRef(privateData->getAppId()); + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_CONTEXT_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); } -bool JSApplicationContext::setAppId(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef appId, - JSValueRef* exception) -{ - Try - { - ApplicationContextPtr privateData = getPrivData(object); - CommonsJavaScript::Converter converter(context); - privateData->setAppId(converter.toString(appId)); - return true; - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to set incorrect value"); - } - JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); - return false; -} -JSValueRef JSApplicationContext::getContextId(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) +bool JSApplicationContext::setProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef value, + JSValueRef* exception) { - Try - { + Try { CommonsJavaScript::Converter converter(context); ApplicationContextPtr privateData = getPrivData(object); - return converter.toJSValueRef(privateData->getContextId()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - return JSValueMakeUndefined(context); -} - -bool JSApplicationContext::setContextId(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef contextId, - JSValueRef* exception) -{ - Try - { - ApplicationContextPtr privateData = getPrivData(object); - CommonsJavaScript::Converter converter(context); - privateData->setContextId(converter.toString(contextId)); - return true; - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to set incorrect value"); - } - JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + + if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_CONTEXT_APP_ID)) { + privateData->setAppId(converter.toString(value)); + return true; + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_CONTEXT_CONTEXT_ID)) { + privateData->setContextId(converter.toString(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/JSApplicationContext.h b/src/standards/Tizen/Application/JSApplicationContext.h index 55d8a8c..b857de8 100755 --- a/src/standards/Tizen/Application/JSApplicationContext.h +++ b/src/standards/Tizen/Application/JSApplicationContext.h @@ -41,8 +41,7 @@ public: static bool isObjectOfClass(JSContextRef context, JSValueRef value); - static Api::Application::ApplicationContextPtr - getApplicationContext(JSContextRef context, JSValueRef value); + static Api::Application::ApplicationContextPtr getApplicationContext(JSContextRef context, JSValueRef value); private: /** @@ -75,27 +74,16 @@ private: static Api::Application::ApplicationContextPtr getPrivData(JSObjectRef object); - static JSValueRef getAppId(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - static bool setAppId(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef appId, - JSValueRef* exception); - - static JSValueRef getContextId(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - static bool setContextId(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef contextId, - 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); }; diff --git a/src/standards/Tizen/Application/JSApplicationContextArray.h b/src/standards/Tizen/Application/JSApplicationContextArray.h index 2ba0f70..ebbce0f 100755 --- a/src/standards/Tizen/Application/JSApplicationContextArray.h +++ b/src/standards/Tizen/Application/JSApplicationContextArray.h @@ -82,66 +82,77 @@ class JSApplicationContextArray 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, diff --git a/src/standards/Tizen/Application/JSApplicationEvent.cpp b/src/standards/Tizen/Application/JSApplicationEvent.cpp index 3e452fc..507c307 100755 --- a/src/standards/Tizen/Application/JSApplicationEvent.cpp +++ b/src/standards/Tizen/Application/JSApplicationEvent.cpp @@ -83,13 +83,14 @@ const JSClassRef JSApplicationEvent::getClassRef() } JSObjectRef JSApplicationEvent::createJSObject(JSContextRef context, - const std::string eventCode, - const ApplicationInformationPtr &appinfo) + const std::string eventCode, + const ApplicationInformationPtr &appinfo) { ApplicationEventPtr privateData = ApplicationEventPtr(new ApplicationEvent()); privateData->setCode(eventCode); privateData->setApplicationInformation(appinfo); JSApplicationEventPriv *priv = new JSApplicationEventPriv(context, privateData); + JSObjectRef jsObjRef = JSObjectMake(context, getClassRef(), static_cast(priv)); if (NULL == jsObjRef) { LogError("object creation error"); @@ -100,60 +101,59 @@ JSObjectRef JSApplicationEvent::createJSObject(JSContextRef context, void JSApplicationEvent::initialize(JSContextRef context,JSObjectRef object) { + } void JSApplicationEvent::finalize(JSObjectRef object) { + } JSValueRef JSApplicationEvent::getProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) { LogDebug("Enter"); - JSApplicationEventPriv *priv = - static_cast(JSObjectGetPrivate(object)); + JSApplicationEventPriv *priv = static_cast(JSObjectGetPrivate(object)); assert(priv && "Private object not set."); - Try { + Try { ApplicationEventPtr appEvent = priv->getObject(); Converter convert(context); if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_EVENT_CODE)) { - LogDebug( - "JSApplicationEvent::getProperty ::code " <getCode()); + LogDebug("JSApplicationEvent::getProperty ::code " <getCode()); return convert.toJSValueRef(appEvent->getCode()); - }else if (JSStringIsEqualToUTF8CString(propertyName, - APPLICATION_EVENT_APPLICATIONINFORMATION)) { - LogDebug( - "JSApplicationEvent::getProperty ::applicationInformation"); + + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_EVENT_APPLICATIONINFORMATION)) { + LogDebug("JSApplicationEvent::getProperty ::applicationInformation"); ApplicationInformationPtr appinfo = appEvent->getApplicationInformation(); ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); JSValueRef result = converter->toJSValueRef(appinfo); return result; - } - else - { + + } else { LogError("wrong property"); } - } - Catch(WrtDeviceApis::Commons::Exception) { + } Catch (WrtDeviceApis::Commons::Exception) { LogError("Exception: " << _rethrown_exception.GetMessage()); return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); } + return JSValueMakeUndefined(context); } bool JSApplicationEvent::hasInstance(JSContextRef context, - JSObjectRef constructor, - JSValueRef possibleInstance, - JSValueRef* exception) + JSObjectRef constructor, + JSValueRef possibleInstance, + JSValueRef* exception) { return JSValueIsObjectOfClass(context, possibleInstance, getClassRef()); } + } } } diff --git a/src/standards/Tizen/Application/JSApplicationInformation.cpp b/src/standards/Tizen/Application/JSApplicationInformation.cpp index e288dd8..f767a6a 100755 --- a/src/standards/Tizen/Application/JSApplicationInformation.cpp +++ b/src/standards/Tizen/Application/JSApplicationInformation.cpp @@ -36,9 +36,10 @@ using namespace TizenApis::Commons; namespace { const char* APPLICATION_INFORMATION_NAME = "name"; -const char* APPLICATION_INFORMATION_APP_ID = "appId"; +const char* APPLICATION_INFORMATION_APP_ID = "id"; const char* APPLICATION_INFORMATION_ICONPATH = "iconPath"; const char* APPLICATION_INFORMATION_VERSION = "version"; +const char* APPLICATION_INFORMATION_SHOW = "show"; } //private namespace @@ -54,8 +55,8 @@ JSClassDefinition JSApplicationInformation::m_classInfo = { initialize, finalize, NULL, //HasProperty, - NULL, - NULL, //SetProperty, + getProperty, //GetProperty, + setProperty, //SetProperty, NULL, //DeleteProperty, NULL, //GetPropertyNames, NULL, //CallAsFunction, @@ -65,10 +66,11 @@ JSClassDefinition JSApplicationInformation::m_classInfo = { }; JSStaticValue JSApplicationInformation::m_property[] = { - { APPLICATION_INFORMATION_NAME, getName, setName, kJSPropertyAttributeReadOnly }, - { APPLICATION_INFORMATION_APP_ID, getAppId, setAppId, kJSPropertyAttributeReadOnly }, - { APPLICATION_INFORMATION_ICONPATH, getIconPath, setIconPath, kJSPropertyAttributeReadOnly }, - { APPLICATION_INFORMATION_VERSION, getVersion, setVersion, kJSPropertyAttributeReadOnly }, + { APPLICATION_INFORMATION_NAME, getProperty, setProperty, kJSPropertyAttributeReadOnly }, + { APPLICATION_INFORMATION_APP_ID, getProperty, setProperty, kJSPropertyAttributeReadOnly }, + { APPLICATION_INFORMATION_ICONPATH, getProperty, setProperty, kJSPropertyAttributeReadOnly }, + { APPLICATION_INFORMATION_VERSION, getProperty, setProperty, kJSPropertyAttributeReadOnly }, + { APPLICATION_INFORMATION_SHOW, getProperty, setProperty, kJSPropertyAttributeReadOnly }, { 0, 0, 0, 0 } }; @@ -83,30 +85,39 @@ JSValueRef JSApplicationInformation::createJSObject(JSContextRef context, const std::string &name, const std::string &appId, const std::string &iconPath, - const std::string &version) + const std::string &version, + const bool &show) { ApplicationInformationPtr privateData = ApplicationInformationPtr(new ApplicationInformation()); - privateData->setName(name); privateData->setAppId(appId); privateData->setIconPath(iconPath); - privateData->setVersion(version); + privateData->setVersion(version); + privateData->setShow(show); + JSApplicationInformationPriv *priv = new JSApplicationInformationPriv(context, privateData); + JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); if (NULL == jsValueRef) { LogError("object creation error"); return JSValueMakeUndefined(context); } + return jsValueRef; } void JSApplicationInformation::initialize(JSContextRef context, JSObjectRef object) { - assert(NULL != JSObjectGetPrivate(object)); + LogInfo(">> initialize"); } void JSApplicationInformation::finalize(JSObjectRef object) { + LogInfo(">> finalize"); + JSApplicationInformationPriv* priv = static_cast(JSObjectGetPrivate(object)); + JSObjectSetPrivate(object, NULL); + LogDebug("Deleting JSApplicationInformation object"); + delete priv; } bool JSApplicationInformation::isObjectOfClass(JSContextRef context, JSValueRef value) @@ -127,23 +138,92 @@ ApplicationInformationPtr JSApplicationInformation::getPrivData(JSObjectRef obje return result; } -ApplicationInformationPtr - JSApplicationInformation::getApplicationInformation(JSContextRef context, JSValueRef value) +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(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, APPLICATION_INFORMATION_NAME)) { + return converter.toJSValueRef(privateData->getName()); + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_INFORMATION_APP_ID)) { + return converter.toJSValueRef(privateData->getAppId()); + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_INFORMATION_ICONPATH)) { + return converter.toJSValueRef(privateData->getIconPath()); + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_INFORMATION_VERSION)) { + return converter.toJSValueRef(privateData->getVersion()); + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_INFORMATION_SHOW)) { + return converter.toJSValueRef(privateData->getShow()); + } + + } Catch(WrtDeviceApis::Commons::Exception) { + LogError("Exception: " << _rethrown_exception.GetMessage()); + JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + } + + return JSValueMakeUndefined(context); +} + + +bool JSApplicationInformation::setProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef value, + JSValueRef* exception) +{ + Try { + CommonsJavaScript::Converter converter(context); + ApplicationInformationPtr privateData = getPrivData(object); + + if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_INFORMATION_NAME)) { + privateData->setName(converter.toString(value)); + return true; + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_INFORMATION_APP_ID)) { + privateData->setAppId(converter.toString(value)); + return true; + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_INFORMATION_ICONPATH)) { + privateData->setIconPath(converter.toString(value)); + return true; + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_INFORMATION_VERSION)) { + privateData->setVersion(converter.toString(value)); + return true; + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_INFORMATION_SHOW)) { + privateData->setShow(converter.toBool(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; +} + +#if 0 + JSValueRef JSApplicationInformation::getName(JSContextRef context, JSObjectRef object, JSStringRef propertyName, @@ -300,6 +380,45 @@ bool JSApplicationInformation::setVersion(JSContextRef context, return false; } +JSValueRef JSApplicationInformation::getShow(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + Try + { + CommonsJavaScript::Converter converter(context); + ApplicationInformationPtr privateData = getPrivData(object); + return converter.toJSValueRef(privateData->getShow()); + } + Catch(WrtDeviceApis::Commons::Exception) + { + LogWarning("trying to get incorrect value"); + } + return JSValueMakeUndefined(context); +} + +bool JSApplicationInformation::setShow(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef show, + JSValueRef* exception) +{ + Try + { + ApplicationInformationPtr privateData = getPrivData(object); + CommonsJavaScript::Converter converter(context); + privateData->setShow(converter.toBool(show)); + return true; + } + Catch(WrtDeviceApis::Commons::Exception) + { + LogWarning("trying to set incorrect value"); + } + JSTizenExceptionFactory::postException(context, exception,JSTizenException::INVALID_VALUES_ERROR, "Invalid value error"); + return false; +} +#endif } } diff --git a/src/standards/Tizen/Application/JSApplicationInformation.h b/src/standards/Tizen/Application/JSApplicationInformation.h index f03276c..f5daa3f 100755 --- a/src/standards/Tizen/Application/JSApplicationInformation.h +++ b/src/standards/Tizen/Application/JSApplicationInformation.h @@ -39,7 +39,8 @@ public: const std::string &name, const std::string &package, const std::string &iconPath, - const std::string &version); + const std::string &version, + const bool &show); static bool isObjectOfClass(JSContextRef context, JSValueRef value); @@ -77,6 +78,19 @@ private: static Api::Application::ApplicationInformationPtr 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); + + +#if 0 static JSValueRef getName(JSContextRef context, JSObjectRef object, JSStringRef propertyName, @@ -121,6 +135,18 @@ static bool setVersion(JSContextRef context, JSValueRef version, JSValueRef* exception); +static JSValueRef getShow(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + +static bool setShow(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef show, + JSValueRef* exception); +#endif + }; } diff --git a/src/standards/Tizen/Application/JSApplicationService.cpp b/src/standards/Tizen/Application/JSApplicationService.cpp index 5d0c04e..0a56094 100755 --- a/src/standards/Tizen/Application/JSApplicationService.cpp +++ b/src/standards/Tizen/Application/JSApplicationService.cpp @@ -21,29 +21,32 @@ #include #include #include +#include #include #include #include +#include "plugin_config.h" + #include "ApplicationConverter.h" +#include "ApplicationUtil.h" #include "JSApplicationService.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 { -using namespace WrtDeviceApis; -using namespace WrtDeviceApis::CommonsJavaScript; - -using namespace Api::Application; namespace { const char* APPLICATION_SERVICE_OPERATION = "operation"; const char* APPLICATION_SERVICE_URI = "uri"; const char* APPLICATION_SERVICE_MIME = "mime"; -const char* APPLICATION_SERVICE_PACKAGE = "package"; +const char* APPLICATION_SERVICE_APPLICATION_ID = "id"; const char* APPLICATION_SERVICE_DATA = "data"; - } //private namespace JSClassRef JSApplicationService::m_jsClassRef = NULL; @@ -54,7 +57,7 @@ JSClassDefinition JSApplicationService::m_classInfo = { "ApplicationService", 0, m_property, - 0, + m_function, initialize, finalize, NULL, //HasProperty, @@ -72,11 +75,17 @@ JSStaticValue JSApplicationService::m_property[] = { { APPLICATION_SERVICE_OPERATION, getProperty, NULL, kJSPropertyAttributeReadOnly }, { APPLICATION_SERVICE_URI, getProperty, NULL, kJSPropertyAttributeReadOnly }, { APPLICATION_SERVICE_MIME, getProperty, NULL, kJSPropertyAttributeReadOnly }, - { APPLICATION_SERVICE_PACKAGE, getProperty, NULL, kJSPropertyAttributeReadOnly }, + { APPLICATION_SERVICE_APPLICATION_ID, getProperty, NULL, kJSPropertyAttributeReadOnly }, { APPLICATION_SERVICE_DATA, getProperty, NULL, kJSPropertyAttributeReadOnly }, { 0, 0, 0, 0 } }; +JSStaticFunction JSApplicationService::m_function[] = { + { "replyResult",JSApplicationService::replyResult,kJSPropertyAttributeNone }, + { "replyFailure",JSApplicationService::replyFailure,kJSPropertyAttributeNone }, + { 0, 0, 0 } +}; + const JSClassDefinition* JSApplicationService::getClassInfo() { return &m_classInfo; @@ -87,20 +96,18 @@ const JSClassRef JSApplicationService::getClassRef() if (!m_jsClassRef) { m_jsClassRef = JSClassCreate(&m_classInfo); } + return m_jsClassRef; } -//JSClassRef JSApplicationService::m_jsClassRef = JSClassCreate( -// JSApplicationService::getClassInfo()); - -JSObjectRef JSApplicationService::createJSObject(JSContextRef context, - const ApplicationServicePtr &appsvc) +JSObjectRef JSApplicationService::createJSObject(JSContextRef context, const ApplicationServicePtr &appsvc) { JSApplicationServicePriv *priv = new JSApplicationServicePriv(context, appsvc); if (!priv) { ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Can not new an object"); } + return JSObjectMake(context, getClassRef(), priv); } @@ -110,10 +117,12 @@ ApplicationServicePtr JSApplicationService::getApplicationService(JSContextRef c if (!isObjectOfClass(context, value)) { Throw(WrtDeviceApis::Commons::InvalidArgumentException); } + JSObjectRef object = JSValueToObject(context, value, NULL); if (!object) { Throw(WrtDeviceApis::Commons::InvalidArgumentException); } + JSApplicationServicePriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { Throw(WrtDeviceApis::Commons::NullPointerException); @@ -127,85 +136,79 @@ ApplicationServicePtr JSApplicationService::getPrivateData(JSObjectRef object) if (!priv) { Throw(WrtDeviceApis::Commons::NullPointerException); } + return priv->getObject(); } void JSApplicationService::initialize(JSContextRef context,JSObjectRef object) { - LogDebug("Entered. Nothing to do."); + LogInfo(">> initialize"); } void JSApplicationService::finalize(JSObjectRef object) { - LogDebug("Entered"); - JSApplicationServicePriv* priv = - static_cast(JSObjectGetPrivate(object)); + LogInfo(">> finalize"); + JSApplicationServicePriv* priv = static_cast(JSObjectGetPrivate(object)); JSObjectSetPrivate(object, NULL); LogDebug("Deleting ApplicationService object"); delete priv; } -JSObjectRef JSApplicationService::constructor(JSContextRef context, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) +JSObjectRef JSApplicationService::constructor(JSContextRef context, + JSObjectRef constructor, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) { - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - - // TODO: exception handling -#if 0 - if ((argumentCount < 1 && argumentCount > 4) || - (JSValueIsNull(context, arguments[0]) || - JSValueIsUndefined(context, arguments[0]) || - JSObjectIsFunction(context, converter->toJSObjectRef(arguments[0]))) || - ((argumentCount >= 2) && - JSValueIsUndefined(context, arguments[1]) || - JSObjectIsFunction(context, converter->toJSObjectRef(arguments[1]))) || - ((argumentCount >= 3) && - JSValueIsUndefined(context, arguments[2]) || - JSObjectIsFunction(context, converter->toJSObjectRef(arguments[2]))) || - ((argumentCount = 4) && !JSValueIsNull(context, arguments[3]) && - JSIsArrayValue(context, arguments[3]))) { - LogError("Wrong callbacks parameters"); - LogError("===[WS] 2"); - *exception = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(context,TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch"); + ApplicationUtil util(context, exception); + if ((argumentCount < 1) || (argumentCount > 5) || + (!util.isString(arguments[0])) || + (argumentCount > 1 && !util.isNullOrString(arguments[1])) || + (argumentCount > 1 && !util.isNullOrString(arguments[2])) || + (argumentCount > 1 && !util.isNullOrString(arguments[3])) || + (argumentCount == 5 && !util.isNullOrArray(arguments[4]))) { + LogError("Wrong parameters"); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch"); return NULL; - } -#endif + } + + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); Try { std::string operation = ""; std::string uri = ""; std::string mime = ""; + std::string appId = ""; std::vector serviceData; - if ((argumentCount > 4) && (argumentCount < 1)) { - ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Wrong ApplicationService argumentCount"); + operation = converter->toString(arguments[0]); + // TODO: Should I check null ??? + if ((argumentCount > 1) && !JSValueIsNull(context, arguments[1])) { + uri = converter->toString(arguments[1]); + } + if ((argumentCount > 2) && !JSValueIsNull(context, arguments[2])) { + mime = converter->toString(arguments[2]); } - if (!JSValueIsNull(context, arguments[0]) && JSValueIsString(context, arguments[0])) { - operation = converter->toString(arguments[0]); + if ((argumentCount > 3) && !JSValueIsNull(context, arguments[3])) { + appId = converter->toString(arguments[3]); } - if ((argumentCount >= 2) && !JSValueIsUndefined(context, arguments[1])) { - if (!JSValueIsNull(context, arguments[1]) && JSValueIsString(context, arguments[1])) { - uri = converter->toString(arguments[1]); - } - } - if ((argumentCount >= 3) && !JSValueIsUndefined(context, arguments[2])) { - if (!JSValueIsNull(context, arguments[2]) && JSValueIsString(context, arguments[2])) { - mime = converter->toString(arguments[2]); - } - } - if ((argumentCount == 4) && !JSValueIsUndefined(context, arguments[3]) && !JSValueIsNull(context, arguments[3])) { - serviceData = converter->toApplicationServiceDataArray(arguments[3]); + if ((argumentCount > 4) && !JSValueIsNull(context, arguments[4])) { + serviceData = converter->toApplicationServiceDataArray(arguments[4]); } - ApplicationServicePtr appsvc = ApplicationServicePtr(new ApplicationService(operation, uri, mime, serviceData)); + ApplicationServicePtr appsvc = ApplicationServicePtr(new ApplicationService(operation, uri, mime, appId, serviceData)); if (!appsvc) { - Throw(WrtDeviceApis::Commons::NullPointerException); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, "unknow error on constructor"); + return NULL; } + return createJSObject(context, appsvc); + } Catch (WrtDeviceApis::Commons::InvalidArgumentException) { - LogError("Exception: " << _rethrown_exception.GetMessage()); - *exception = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject(context,TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch"); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, "invalid value error"); return NULL; + } } @@ -215,59 +218,140 @@ bool JSApplicationService::isObjectOfClass(JSContextRef context, JSValueRef valu return JSValueIsObjectOfClass(context, value, getClassRef()); } -JSValueRef JSApplicationService::getProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) + +JSValueRef JSApplicationService::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { - LogDebug("Enter"); - JSApplicationServicePriv *priv = - static_cast(JSObjectGetPrivate(object)); + JSApplicationServicePriv *priv = static_cast(JSObjectGetPrivate(object)); assert(priv && "Private object not set."); - Try { + Try { ApplicationServicePtr appsvc = priv->getObject(); ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_SERVICE_OPERATION)) { - LogDebug( - "JSApplicationService::getProperty::operation " << - appsvc->getOperation()); + LogDebug("JSApplicationService::getProperty::operation " << appsvc->getOperation()); return converter->toJSValueRef(appsvc->getOperation()); - }else if (JSStringIsEqualToUTF8CString(propertyName, - APPLICATION_SERVICE_URI)) { - LogDebug( - "JSApplicationService::getProperty ::uri " << - appsvc->getUri()); + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_SERVICE_URI)) { + LogDebug("JSApplicationService::getProperty ::uri " << appsvc->getUri()); return converter->toJSValueRef(appsvc->getUri()); - }else if (JSStringIsEqualToUTF8CString(propertyName, - APPLICATION_SERVICE_MIME)) { - LogDebug( - "JSApplicationService::getProperty ::mime " << - appsvc->getMime()); + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_SERVICE_MIME)) { + LogDebug("JSApplicationService::getProperty ::mime " << appsvc->getMime()); return converter->toJSValueRef(appsvc->getMime()); - }else if (JSStringIsEqualToUTF8CString(propertyName, - APPLICATION_SERVICE_DATA)) { - LogDebug( - "JSApplicationService::getProperty ::extraData "); + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_SERVICE_APPLICATION_ID)) { + LogDebug("JSApplicationService::getProperty ::appId "); + return converter->toJSValueRef(appsvc->getAppId()); + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_SERVICE_DATA)) { + LogDebug("JSApplicationService::getProperty ::extraData "); return converter->toJSValueRef(appsvc->getServiceDataArray()); } - } - Catch(WrtDeviceApis::Commons::Exception) { + } Catch(WrtDeviceApis::Commons::Exception) { LogError("Exception: " << _rethrown_exception.GetMessage()); return JSDOMExceptionFactory::UnknownException.make(context, exception); } - return JSValueMakeUndefined(context); + + /* do not return undefined object to find method */ + return NULL; } -bool JSApplicationService::hasInstance(JSContextRef context, - JSObjectRef constructor, - JSValueRef possibleInstance, - JSValueRef* exception) +bool JSApplicationService::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) { return JSValueIsObjectOfClass(context, possibleInstance, getClassRef()); } + +JSValueRef JSApplicationService::replyResult(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + return JSTizenExceptionFactory::postException(context, exception,JSTizenException::NOT_SUPPORTED_ERROR, "Not yet supported"); +#if 0 + LogInfo(">> replyResult()"); + JSApplicationServicePriv *priv = static_cast(JSObjectGetPrivate(thisObject)); + assert(priv && "Invalid private pointer."); + + //AceSecurityStatus status = APPLICATION_CHECK_ACCESS(priv->getContext(), APPLICATION_FUNCTION_API_REPLY_RESULT); + //TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + ApplicationUtil util(context, exception); + if (argumentCount > 1 || + (argumentCount == 1 && !util.isNullOrObject(arguments[0]))) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } + + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + + Try { + std::vector resultArray; + if (argumentCount == 1 && util.isObject(arguments[0])) { + resultArray = converter->toApplicationServiceDataArray(arguments[0]); + } + ApplicationServicePtr appsvc = priv->getObject(); + appsvc->replyResult(resultArray); + + } 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::NullPointerException) { + return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } Catch (WrtDeviceApis::Commons::Exception) { + LogError("Exception: " << _rethrown_exception.GetMessage() << " Code: " << _rethrown_exception.getCode()); + return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } + + return JSValueMakeUndefined(context); +#endif +} + +JSValueRef JSApplicationService::replyFailure(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + return JSTizenExceptionFactory::postException(context, exception,JSTizenException::NOT_SUPPORTED_ERROR, "Not yet supported"); +#if 0 + LogInfo(">> replyFailure()"); + JSApplicationServicePriv *priv = static_cast(JSObjectGetPrivate(thisObject)); + assert(priv && "Invalid private pointer."); + + //AceSecurityStatus status = APPLICATION_CHECK_ACCESS(priv->getContext(), APPLICATION_FUNCTION_API_REPLY_RESULT); + //TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + if (argumentCount != 0) { + LogError("Wrong parameters"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Type mistmatch error"); + } + + Try { + ApplicationServicePtr appsvc = priv->getObject(); + appsvc->replyFailure(); + + } 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::NullPointerException) { + return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } Catch (WrtDeviceApis::Commons::Exception) { + LogError("Exception: " << _rethrown_exception.GetMessage() << " Code: " << _rethrown_exception.getCode()); + return JSTizenExceptionFactory::postException(context, exception,JSTizenException::UNKNOWN_ERROR, "Unknown error"); + } + + return JSValueMakeUndefined(context); +#endif +} + + } // } //TizenApis } diff --git a/src/standards/Tizen/Application/JSApplicationService.h b/src/standards/Tizen/Application/JSApplicationService.h index 83336f8..eed15d1 100755 --- a/src/standards/Tizen/Application/JSApplicationService.h +++ b/src/standards/Tizen/Application/JSApplicationService.h @@ -103,6 +103,12 @@ private: */ static JSStaticValue m_property[]; + /** + * This structure describes a statically declared function property. + */ + static JSStaticFunction m_function[]; + + static JSClassRef m_jsClassRef; }; diff --git a/src/standards/Tizen/Application/JSApplicationServiceData.cpp b/src/standards/Tizen/Application/JSApplicationServiceData.cpp index 89fc7ca..1182fb7 100755 --- a/src/standards/Tizen/Application/JSApplicationServiceData.cpp +++ b/src/standards/Tizen/Application/JSApplicationServiceData.cpp @@ -18,22 +18,26 @@ #include #include #include +#include +#include + #include "JSApplicationServiceData.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 { -using namespace Api::Application; -using namespace WrtDeviceApis; -using namespace WrtDeviceApis::CommonsJavaScript; - - -//namespace { -// const char* APPLICATION_SERVICE_DATA_KEY = "key"; -// const char* APPLICATION_SERVICE_DATA_VALUE = "value"; -//} +namespace { +const char* APPLICATION_SERVICE_DATA_KEY = "key"; +const char* APPLICATION_SERVICE_DATA_VALUE = "value"; +} JSClassRef JSApplicationServiceData::m_classRef = NULL; @@ -48,8 +52,8 @@ JSClassDefinition JSApplicationServiceData::m_classInfo = initialize, finalize, NULL, //hasProperty, - NULL, //GetProperty, - NULL, //SetProperty, + getProperty, //GetProperty, + setProperty, //SetProperty, NULL, //DeleteProperty, NULL, //getPropertyNames, NULL, @@ -59,8 +63,10 @@ JSClassDefinition JSApplicationServiceData::m_classInfo = }; JSStaticValue JSApplicationServiceData::m_property[] = { - { "key", getDataKey, setDataKey, kJSPropertyAttributeNone }, - { "value", getDataValue, setDataValue, kJSPropertyAttributeNone }, +// { APPLICATION_SERVICE_DATA_KEY, getDataKey, setDataKey, kJSPropertyAttributeNone }, +// { APPLICATION_SERVICE_DATA_VALUE, getDataValue, setDataValue, kJSPropertyAttributeNone }, + { APPLICATION_SERVICE_DATA_KEY, getProperty, setProperty, kJSPropertyAttributeNone }, + { APPLICATION_SERVICE_DATA_VALUE, getProperty, setProperty, kJSPropertyAttributeNone }, { 0, 0, 0, 0 } }; @@ -85,35 +91,43 @@ JSValueRef JSApplicationServiceData::createJSObject(JSContextRef context, privateData->setKey(key); privateData->setValue(value); JSApplicationServiceDataPriv *priv = new JSApplicationServiceDataPriv(context, privateData); + JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); if (NULL == jsValueRef) { LogError("object creation error"); return JSValueMakeUndefined(context); } + return jsValueRef; } JSObjectRef JSApplicationServiceData::constructor(JSContextRef context, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - - if ((argumentCount == 2) && JSValueIsString(context, arguments[0]) && JSIsArrayValue(context, arguments[1])) { - return JSValueToObject(context, createJSObject(context, converter->toString(arguments[0]), converter->toVectorOfStrings(arguments[1])), exception); - } else { - // throw exception + ApplicationUtil util(context, exception); + + if (argumentCount != 2 || + !util.isString(arguments[0]) || !util.isArray(arguments[1])) { + LogError("Wrong parameters"); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Type Mismatch"); return NULL; } + + ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); + return JSValueToObject(context, createJSObject(context, converter->toString(arguments[0]), converter->toVectorOfStrings(arguments[1])), exception); } void JSApplicationServiceData::initialize(JSContextRef context, JSObjectRef object) { - //assert(NULL != JSObjectGetPrivate(object)); + LogInfo(">> initialize"); } void JSApplicationServiceData::finalize(JSObjectRef object) { - // TODO : check - //delete (JSObjectGetPrivate(object)); + LogInfo(">> finalize"); + JSApplicationServiceDataPriv* priv = static_cast(JSObjectGetPrivate(object)); + JSObjectSetPrivate(object, NULL); + LogDebug("Deleting ApplicationService object"); + delete priv; } bool JSApplicationServiceData::isObjectOfClass(JSContextRef context, JSValueRef value) @@ -126,11 +140,11 @@ ApplicationServiceDataPtr JSApplicationServiceData::getPrivData(JSObjectRef obje LogDebug("entered"); JSApplicationServiceDataPriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { - ThrowMsg(Commons::NullPointerException, "Private object is null"); + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); } ApplicationServiceDataPtr result = priv->getObject(); if (!result) { - ThrowMsg(Commons::NullPointerException, "Private object is null"); + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); } return result; } @@ -138,95 +152,69 @@ ApplicationServiceDataPtr JSApplicationServiceData::getPrivData(JSObjectRef obje ApplicationServiceDataPtr JSApplicationServiceData::getApplicationServiceData(JSContextRef context, JSValueRef value) { if (!isObjectOfClass(context, value)) { - Throw(Commons::InvalidArgumentException); + Throw(WrtDeviceApis::Commons::InvalidArgumentException); } JSObjectRef object = JSValueToObject(context, value, NULL); if (!object) { - Throw(Commons::InvalidArgumentException); + Throw(WrtDeviceApis::Commons::InvalidArgumentException); } JSApplicationServiceDataPriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { - Throw(Commons::NullPointerException); + Throw(WrtDeviceApis::Commons::NullPointerException); } return priv->getObject(); } -JSValueRef JSApplicationServiceData::getDataKey(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - Try - { - CommonsJavaScript::Converter converter(context); - ApplicationServiceDataPtr privateData = getPrivData(object); - return converter.toJSValueRef(privateData->getKey()); - } - Catch(Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - return JSValueMakeUndefined(context); -} -bool JSApplicationServiceData::setDataKey(JSContextRef context, +JSValueRef JSApplicationServiceData::getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, - JSValueRef key, JSValueRef* exception) { - Try - { - ApplicationServiceDataPtr privateData = getPrivData(object); - CommonsJavaScript::Converter converter(context); - privateData->setKey(converter.toString(key)); - return true; - } - Catch(Commons::Exception) - { - LogWarning("trying to set incorrect value"); - } - JSDOMExceptionFactory::TypeMismatchException.make(context, exception); - return false; -} - -JSValueRef JSApplicationServiceData::getDataValue(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - Try - { + Try { WrtDeviceApis::CommonsJavaScript::Converter converter(context); ApplicationServiceDataPtr privateData = getPrivData(object); - - return converter.toJSValueRef(privateData->getValue()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } + + if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_SERVICE_DATA_KEY)) { + //LogDebug("JSApplicationServiceData::getProperty::key " << privateData->getKey()); + return converter.toJSValueRef(privateData->getKey()); + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_SERVICE_DATA_VALUE)) { + //LogDebug("JSApplicationServiceData::getProperty::value " << privateData->getValue()); + return converter.toJSValueRef(privateData->getValue()); + } + } Catch(WrtDeviceApis::Commons::Exception) { + LogError("Exception: " << _rethrown_exception.GetMessage()); + return JSDOMExceptionFactory::UnknownException.make(context, exception); + } + return JSValueMakeUndefined(context); } -bool JSApplicationServiceData::setDataValue(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) + +bool JSApplicationServiceData::setProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef value, + JSValueRef* exception) { - Try - { - ApplicationServiceDataPtr privateData = getPrivData(object); + Try { WrtDeviceApis::CommonsJavaScript::Converter converter(context); - privateData->setValue(converter.toVectorOfStrings(value)); - return true; - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to set incorrect value"); - } - JSDOMExceptionFactory::TypeMismatchException.make(context, exception); + ApplicationServiceDataPtr privateData = getPrivData(object); + + if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_SERVICE_DATA_KEY)) { + //LogDebug("JSApplicationServiceData::getProperty::key " << privateData->getKey()); + privateData->setKey(converter.toString(value)); + return true; + } else if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_SERVICE_DATA_VALUE)) { + //LogDebug("JSApplicationServiceData::getProperty::value " << privateData->getValue()); + privateData->setValue(converter.toVectorOfStrings(value)); + return true; + } + } Catch(WrtDeviceApis::Commons::Exception) { + LogError("Exception: " << _rethrown_exception.GetMessage()); + JSDOMExceptionFactory::UnknownException.make(context, exception); + } + return false; } diff --git a/src/standards/Tizen/Application/JSApplicationServiceData.h b/src/standards/Tizen/Application/JSApplicationServiceData.h index d9f9a52..2bbf591 100755 --- a/src/standards/Tizen/Application/JSApplicationServiceData.h +++ b/src/standards/Tizen/Application/JSApplicationServiceData.h @@ -82,23 +82,12 @@ private: static Api::Application::ApplicationServiceDataPtr getPrivData(JSObjectRef object); - static JSValueRef getDataKey(JSContextRef context, + static JSValueRef getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); - static bool setDataKey(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef key, - JSValueRef* exception); - - static JSValueRef getDataValue(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - static bool setDataValue(JSContextRef context, + static bool setProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, diff --git a/src/standards/Tizen/Application/JSApplicationServiceExtraData.cpp b/src/standards/Tizen/Application/JSApplicationServiceExtraData.cpp deleted file mode 100755 index b65ee2c..0000000 --- a/src/standards/Tizen/Application/JSApplicationServiceExtraData.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include "JSApplicationServiceExtraData.h" - -namespace TizenApis { -namespace Tizen1_0 { -namespace Application { - -using namespace Api::Application; -using namespace WrtDeviceApis; -using namespace WrtDeviceApis::CommonsJavaScript; - - -namespace { - const char* APPLICATION_SERVICE_EXTRA_DATA_KEY = "key"; - const char* APPLICATION_SERVICE_EXTRA_DATA_VALUE = "value"; -} - -JSClassRef JSApplicationServiceExtraData::m_classRef = NULL; - -JSClassDefinition JSApplicationServiceExtraData::m_classInfo = -{ - 0, - kJSClassAttributeNone, - "ApplicationServiceExtraData", - NULL, - m_property, - m_functions, - initialize, - finalize, - NULL, //hasProperty, - NULL, //GetProperty, - NULL, //SetProperty, - NULL, //DeleteProperty, - NULL, //getPropertyNames, - NULL, - NULL, - NULL, - NULL, //ConvertToType, -}; - -JSStaticValue JSApplicationServiceExtraData::m_property[] = { - { APPLICATION_SERVICE_EXTRA_DATA_KEY, getExtraDataKey, setExtraDataKey, kJSPropertyAttributeNone }, - { APPLICATION_SERVICE_EXTRA_DATA_VALUE, getExtraDataValue, setExtraDataValue, kJSPropertyAttributeNone }, - { 0, 0, 0, 0 } -}; - -JSStaticFunction JSApplicationServiceExtraData::m_functions[] = -{ - { 0, 0, 0 } -}; - -JSClassRef JSApplicationServiceExtraData::getClassRef() { - if (!m_classRef) { - m_classRef = JSClassCreate(&m_classInfo); - } - return m_classRef; -} - -JSValueRef JSApplicationServiceExtraData::createJSObject(JSContextRef context, - const std::string &key, - const std::string &value) -{ - ApplicationServiceExtraDataPtr privateData = ApplicationServiceExtraDataPtr(new ApplicationServiceExtraData()); - - privateData->setKey(key); - privateData->setValue(value); - JSApplicationServiceExtraDataPriv *priv = new JSApplicationServiceExtraDataPriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; -} - -void JSApplicationServiceExtraData::initialize(JSContextRef context, JSObjectRef object) -{ - assert(NULL != JSObjectGetPrivate(object)); -} - -void JSApplicationServiceExtraData::finalize(JSObjectRef object) -{ - //delete (JSObjectGetPrivate(object)); -} - -bool JSApplicationServiceExtraData::isObjectOfClass(JSContextRef context, JSValueRef value) -{ - return JSValueIsObjectOfClass(context, value, getClassRef()); -} - -ApplicationServiceExtraDataPtr JSApplicationServiceExtraData::getPrivData(JSObjectRef object) -{ - LogDebug("entered"); - JSApplicationServiceExtraDataPriv *priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - ThrowMsg(Commons::NullPointerException, "Private object is null"); - } - ApplicationServiceExtraDataPtr result = priv->getObject(); - if (!result) { - ThrowMsg(Commons::NullPointerException, "Private object is null"); - } - return result; -} - -ApplicationServiceExtraDataPtr - JSApplicationServiceExtraData::getApplicationServiceExtraData(JSContextRef context, JSValueRef value) -{ - if (!isObjectOfClass(context, value)) { - Throw(Commons::InvalidArgumentException); - } - JSObjectRef object = JSValueToObject(context, value, NULL); - if (!object) { - Throw(Commons::InvalidArgumentException); - } - JSApplicationServiceExtraDataPriv *priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(Commons::NullPointerException); - } - return priv->getObject(); -} - -JSValueRef JSApplicationServiceExtraData::getExtraDataKey(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - LogDebug("entered"); - Try - { - CommonsJavaScript::Converter converter(context); - ApplicationServiceExtraDataPtr privateData = getPrivData(object); - return converter.toJSValueRef(privateData->getKey()); - } - Catch(Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - return JSValueMakeUndefined(context); -} - -bool JSApplicationServiceExtraData::setExtraDataKey(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef key, - JSValueRef* exception) -{ - Try - { - ApplicationServiceExtraDataPtr privateData = getPrivData(object); - CommonsJavaScript::Converter converter(context); - privateData->setKey(converter.toString(key)); - return true; - } - Catch(Commons::Exception) - { - LogWarning("trying to set incorrect value"); - } - JSDOMExceptionFactory::TypeMismatchException.make(context, exception); - return false; -} - -JSValueRef JSApplicationServiceExtraData::getExtraDataValue(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - LogDebug("entered"); - Try - { - WrtDeviceApis::CommonsJavaScript::Converter converter(context); - ApplicationServiceExtraDataPtr privateData = getPrivData(object); - return converter.toJSValueRef(privateData->getValue()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - return JSValueMakeUndefined(context); -} - -bool JSApplicationServiceExtraData::setExtraDataValue(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ApplicationServiceExtraDataPtr privateData = getPrivData(object); - WrtDeviceApis::CommonsJavaScript::Converter converter(context); - privateData->setValue(converter.toString(value)); - return true; - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to set incorrect value"); - } - JSDOMExceptionFactory::TypeMismatchException.make(context, exception); - return false; -} - -} -} -} diff --git a/src/standards/Tizen/Application/JSApplicationServiceExtraDataArray.cpp b/src/standards/Tizen/Application/JSApplicationServiceExtraDataArray.cpp deleted file mode 100755 index 6b6e29b..0000000 --- a/src/standards/Tizen/Application/JSApplicationServiceExtraDataArray.cpp +++ /dev/null @@ -1,575 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include "JSApplicationServiceExtraDataArray.h" -#include "ApplicationConverter.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 { -namespace Application { - -using namespace Api::Application; -using namespace WrtDeviceApis; -using namespace WrtDeviceApis::CommonsJavaScript; - - -JSClassDefinition JSApplicationServiceExtraDataArray::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 JSApplicationServiceExtraDataArray::m_property[] = { - { ATTRIBUTE_LENGTH, getLength, NULL, kJSPropertyAttributeReadOnly }, - { 0, 0, 0, 0 } -}; - -JSStaticFunction JSApplicationServiceExtraDataArray::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 } -}; - -JSClassRef JSApplicationServiceExtraDataArray::m_jsClassRef = JSClassCreate( - JSApplicationServiceExtraDataArray::getClassInfo()); - -JSValueRef JSApplicationServiceExtraDataArray::getLength(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - LogDebug("enter"); - Try - { - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(Commons::NullPointerException); - } - ApplicationServiceExtraDataArrayPtr privateDatas = priv->getObject(); - if (privateDatas) { - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - return converter->toJSValueRef(privateDatas->size()); - } - } - Catch(Commons::Exception) - { - LogError("invalid conversion"); - } - return JSValueMakeUndefined(context); -} - -JSObjectRef JSApplicationServiceExtraDataArray::createArray(JSContextRef context, - const ApplicationServiceExtraDataArrayPtr &privateDatas) -{ - JSApplicationServiceExtraDataArrayPriv *priv = new JSApplicationServiceExtraDataArrayPriv(context, privateDatas); - return JSObjectMake(context, getClassRef(), priv); -} - -const JSClassDefinition* JSApplicationServiceExtraDataArray::getClassInfo() -{ - return &(m_classInfo); -} - -JSClassRef JSApplicationServiceExtraDataArray::getClassRef() -{ - if (!m_jsClassRef) { - m_jsClassRef = JSClassCreate(&m_classInfo); - } - return m_jsClassRef; -} - -bool JSApplicationServiceExtraDataArray::isObjectOfClass(JSContextRef context, JSValueRef value) -{ - return JSValueIsObjectOfClass(context, value, getClassRef()); -} - -ApplicationServiceExtraDataArrayPtr - JSApplicationServiceExtraDataArray::getApplicationServiceExtraDataArray(JSContextRef context, JSValueRef value) -{ - if (!isObjectOfClass(context, value)) { - Throw(Commons::InvalidArgumentException); - } - JSObjectRef object = JSValueToObject(context, value, NULL); - if (!object) { - Throw(Commons::InvalidArgumentException); - } - JSApplicationServiceExtraDataArrayPriv *priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(Commons::NullPointerException); - } - return priv->getObject(); -} - -void JSApplicationServiceExtraDataArray::initialize(JSContextRef context, - JSObjectRef object) -{ - LogDebug("enter"); -} - -void JSApplicationServiceExtraDataArray::finalize(JSObjectRef object) -{ - LogDebug("enter"); - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(object)); - delete priv; - JSObjectSetPrivate(object, NULL); -} - -bool JSApplicationServiceExtraDataArray::hasProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName) -{ - LogDebug("enter"); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - Try - { - size_t index = converter->toSizeT(propertyName); - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(Commons::NullPointerException); - } - ApplicationServiceExtraDataArrayPtr privateDatas = priv->getObject(); - if (index < privateDatas->size()) { - return true; - } - } - Catch(Commons::Exception) - { - //not reporting error is intended - } - return false; -} - -JSValueRef JSApplicationServiceExtraDataArray::getProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - LogDebug("enter"); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - Try - { - size_t index = converter->toSizeT(propertyName); - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(Commons::NullPointerException); - } - ApplicationServiceExtraDataArrayPtr privateDatas = priv->getObject(); - if (index < privateDatas->size()) { - ApplicationServiceExtraDataPtr result = privateDatas->at(index); - if (result) { - return converter->toJSValueRef(result); - } - } - } - Catch(Commons::Exception) - { - LogError("invalid property"); - } - return JSValueMakeUndefined(context); -} - -bool JSApplicationServiceExtraDataArray::setProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - LogDebug("enter"); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); -// CommonsJavaScript::Converter converter(context); - Try - { - size_t index = converter->toSizeT(propertyName); - ApplicationServiceExtraDataPtr privateData; - if (!JSValueIsUndefined(context, value)) { - privateData = converter->toApplicationServiceExtraData(value); - } - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(Commons::NullPointerException); - } - ApplicationServiceExtraDataArrayPtr privateDatas = priv->getObject(); - if (!privateDatas) { - Throw(Commons::NullPointerException); - } - if (privateDatas->size() <= index) { - privateDatas->resize(index + 1); - } - (*privateDatas)[index] = privateData; - return true; - } - Catch(Commons::Exception) - { - LogError("error occured"); - JSDOMExceptionFactory::TypeMismatchException.make(context, exception); - } - return false; -} - -JSValueRef JSApplicationServiceExtraDataArray::concat(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("enter"); - Try - { - ApplicationServiceExtraDataArrayPtr privateDatas = ApplicationServiceExtraDataArrayPtr(new ApplicationServiceExtraDataArray()); - JSApplicationServiceExtraDataArrayPriv *newPrivateObject = new JSApplicationServiceExtraDataArrayPriv(context, privateDatas); - JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject); - - //copy current privateDatas - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(thisObject)); - ApplicationServiceExtraDataArrayPtr currentApplicationServiceExtraDatas = priv->getObject(); - for (size_t i = 0; i < currentApplicationServiceExtraDatas->size(); ++i) { - privateDatas->push_back(currentApplicationServiceExtraDatas->at(i)); - } - - //copy submitted arrays - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - for (size_t i = 0; i < argumentCount; ++i) { - if (!JSIsArrayValue(context, arguments[i])) { - Throw(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); - privateDatas->push_back(converter->toApplicationServiceExtraData(att)); - } - } - return result; - } - Catch(Commons::Exception) - { - LogError("error occured"); - } - return JSDOMExceptionFactory::TypeMismatchException.make(context, exception); -} - -JSValueRef JSApplicationServiceExtraDataArray::join(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - Try - { - std::string result; - std::string separator(","); - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(thisObject)); - ApplicationServiceExtraDataArrayPtr currentApplicationServiceExtraDatas = priv->getObject(); - if (argumentCount > 0 && JSValueIsString(context, arguments[0])) { - separator = converter->toString(arguments[0]); - } - for (size_t i = 0; i < currentApplicationServiceExtraDatas->size(); ++i) { - if (i != 0) { - result += separator; - } - //FIXME : to be changed to support join - //result += currentApplicationServiceExtraDatas->at(i); - } - return converter->toJSValueRef(result); - } - Catch(Commons::Exception) - { - LogError("error occured"); - } - return JSDOMExceptionFactory::TypeMismatchException.make(context, exception); -} - -JSValueRef JSApplicationServiceExtraDataArray::pop(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - Try - { - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(thisObject)); - ApplicationServiceExtraDataArrayPtr currentApplicationServiceExtraDatas = priv->getObject(); - if (currentApplicationServiceExtraDatas->size() > 0) { - ApplicationServiceExtraDataPtr result = currentApplicationServiceExtraDatas->at( - currentApplicationServiceExtraDatas->size() - 1); - currentApplicationServiceExtraDatas->pop_back(); - return converter->toJSValueRef(result); - } - } - Catch(Commons::Exception) - { - LogError("error occured"); - } - return JSValueMakeUndefined(context); -} - -JSValueRef JSApplicationServiceExtraDataArray::push(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - Try - { - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(thisObject)); - ApplicationServiceExtraDataArrayPtr currentApplicationServiceExtraDatas = priv->getObject(); - for (size_t i = 0; i < argumentCount; ++i) { - currentApplicationServiceExtraDatas->push_back(converter->toApplicationServiceExtraData(arguments[i])); - } - return converter->toJSValueRef(currentApplicationServiceExtraDatas->size()); - } - Catch(Commons::Exception) - { - LogError("error occured"); - } - return JSDOMExceptionFactory::TypeMismatchException.make(context, exception); -} - -JSValueRef JSApplicationServiceExtraDataArray::reverse(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - Try - { - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(thisObject)); - ApplicationServiceExtraDataArrayPtr currentApplicationServiceExtraDatas = priv->getObject(); - std::reverse(currentApplicationServiceExtraDatas->begin(), currentApplicationServiceExtraDatas->end()); - return thisObject; - } - Catch(Commons::Exception) - { - LogError("error occured"); - } - return JSValueMakeUndefined(context); -} - -JSValueRef JSApplicationServiceExtraDataArray::shift(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - Try - { - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(thisObject)); - ApplicationServiceExtraDataArrayPtr currentApplicationServiceExtraDatas = priv->getObject(); - if (currentApplicationServiceExtraDatas->size() > 0) { - ApplicationServiceExtraDataPtr result = currentApplicationServiceExtraDatas->at(0); - currentApplicationServiceExtraDatas->erase(currentApplicationServiceExtraDatas->begin()); - return converter->toJSValueRef(result); - } - } - Catch(Commons::Exception) - { - LogError("error occured"); - } - return JSValueMakeUndefined(context); -} - -JSValueRef JSApplicationServiceExtraDataArray::slice(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("enter"); - Try - { - if (argumentCount < 1) { - return JSValueMakeUndefined(context); - } - ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - ApplicationServiceExtraDataArrayPtr privateDatas = ApplicationServiceExtraDataArrayPtr(new ApplicationServiceExtraDataArray()); - JSApplicationServiceExtraDataArrayPriv *newPrivateObject = new JSApplicationServiceExtraDataArrayPriv( - context, - privateDatas); - JSValueRef result = JSObjectMake(context, - getClassRef(), newPrivateObject); - - //copy current privateDatas - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(thisObject)); - ApplicationServiceExtraDataArrayPtr currentApplicationServiceExtraDatas = priv->getObject(); - std::size_t first = converter->toSizeT(arguments[0]); - std::size_t last = currentApplicationServiceExtraDatas->size() - 1; - if (argumentCount > 1) { - last = converter->toSizeT(arguments[1]); - if (last >= currentApplicationServiceExtraDatas->size()) { - last = currentApplicationServiceExtraDatas->size() - 1; - } - } - if (first < 0) { - first = 0; - } - for (size_t i = first; i <= last; ++i) { - privateDatas->push_back(currentApplicationServiceExtraDatas->at(i)); - } - - return result; - } - Catch(Commons::Exception) - { - LogError("error occured"); - } - return JSDOMExceptionFactory::TypeMismatchException.make(context, exception); -} - -JSValueRef JSApplicationServiceExtraDataArray::sort(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - Try - { - //ApplicationConverterFactory::ConverterType converter = ApplicationConverterFactory::getConverter(context); - JSApplicationServiceExtraDataArrayPriv* priv = - static_cast(JSObjectGetPrivate(thisObject)); - ApplicationServiceExtraDataArrayPtr currentApplicationServiceExtraDatas = priv->getObject(); - std::sort(currentApplicationServiceExtraDatas->begin(), currentApplicationServiceExtraDatas->end()); - return thisObject; - } - Catch(Commons::Exception) - { - LogError("error occured"); - } - return JSValueMakeUndefined(context); -} - -JSValueRef JSApplicationServiceExtraDataArray::splice(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - return JSValueMakeUndefined(context); -} - -JSValueRef JSApplicationServiceExtraDataArray::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 JSApplicationServiceExtraDataArray::unshift(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - return JSValueMakeUndefined(context); -} - -JSValueRef JSApplicationServiceExtraDataArray::valueOf(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("entered"); - return JSValueMakeUndefined(context); -} -} -} -} diff --git a/src/standards/Tizen/Application/JSApplicationServiceExtraDataArray.h b/src/standards/Tizen/Application/JSApplicationServiceExtraDataArray.h deleted file mode 100755 index 6141fb0..0000000 --- a/src/standards/Tizen/Application/JSApplicationServiceExtraDataArray.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_SERVICE_EXTRA_DATA_ARRAY_H_ -#define TIZENAPIS_TIZEN_JS_APPLICATION_SERVICE_EXTRA_DATA_ARRAY_H_ - -#include -#include -#include - -namespace TizenApis { -namespace Tizen1_0 { -namespace Application { - -typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT::Type JSApplicationServiceExtraDataArrayPriv; - -class JSApplicationServiceExtraDataArray -{ - public: - - static const JSClassDefinition* getClassInfo(); - - static JSClassRef getClassRef(); - - static JSObjectRef createArray(JSContextRef context, - const Api::Application::ApplicationServiceExtraDataArrayPtr &extraDataArray); - - static bool isObjectOfClass(JSContextRef context, JSValueRef value); - - static Api::Application::ApplicationServiceExtraDataArrayPtr - getApplicationServiceExtraDataArray(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 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/Application/JSApplicationServiceReply.cpp b/src/standards/Tizen/Application/JSApplicationServiceReply.cpp deleted file mode 100755 index ed51755..0000000 --- a/src/standards/Tizen/Application/JSApplicationServiceReply.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include "JSApplicationServiceReply.h" - -namespace TizenApis { -namespace Tizen1_0 { -namespace Application { -using namespace WrtDeviceApis; -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; -using namespace Api::Application; - -namespace { -const char* APPLICATION_SERVICE_REPLY_SUCCESS = "isSucceed"; -const char* APPLICATION_SERVICE_EXTRADATA = "extraData"; - - -} //private namespace - -JSClassRef JSApplicationServiceReply::m_jsClassRef = NULL; - -JSClassDefinition JSApplicationServiceReply::m_classInfo = { - 0, - kJSClassAttributeNone, - "ApplicationServiceReply", - 0, - m_property, - 0, - initialize, - finalize, - NULL, //HasProperty, - NULL, - NULL, //SetProperty, - NULL, //DeleteProperty, - NULL, //GetPropertyNames, - NULL, //CallAsFunction, - NULL, //CallAsConstructor, - hasInstance, - NULL, //ConvertToType -}; - -JSStaticValue JSApplicationServiceReply::m_property[] = { - { APPLICATION_SERVICE_REPLY_SUCCESS, getIsSucceed, NULL, kJSPropertyAttributeReadOnly }, - { APPLICATION_SERVICE_EXTRADATA, getExtraData, NULL, kJSPropertyAttributeReadOnly }, - { 0, 0, 0, 0 } -}; - -const JSClassDefinition* JSApplicationServiceReply::getClassInfo() -{ - return &m_classInfo; -} - -const JSClassRef JSApplicationServiceReply::getClassRef() -{ - if (!m_jsClassRef) { - m_jsClassRef = JSClassCreate(&m_classInfo); - } - return m_jsClassRef; -} - -JSObjectRef JSApplicationServiceReply::createJSObject(JSContextRef context, - const ApplicationServiceReplyPtr &appsvc) -{ - ApplicationServiceReplyPtr privateData(new ApplicationServiceReply()); - JSApplicationServiceReplyPriv *priv = new JSApplicationServiceReplyPriv(context, privateData); - - if (!priv) { - ThrowMsg(Commons::NullPointerException, "Can not new an object"); - } - return JSObjectMake(context, getClassRef(), priv); -} - -ApplicationServiceReplyPtr JSApplicationServiceReply::getApplicationServiceReply(JSContextRef context, JSValueRef value) -{ - if (!isObjectOfClass(context, value)) { - Throw(Commons::InvalidArgumentException); - } - JSObjectRef object = JSValueToObject(context, value, NULL); - if (!object) { - Throw(Commons::InvalidArgumentException); - } - JSApplicationServiceReplyPriv *priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(Commons::NullPointerException); - } - return priv->getObject(); -} - -ApplicationServiceReplyPtr JSApplicationServiceReply::getPrivateData(JSObjectRef object) -{ - JSApplicationServiceReplyPriv* priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(Commons::NullPointerException); - } - return priv->getObject(); -} - - - -void JSApplicationServiceReply::initialize(JSContextRef context,JSObjectRef object) -{ - LogDebug("Entered. Nothing to do."); -} - -void JSApplicationServiceReply::finalize(JSObjectRef object) -{ - LogDebug("Entered"); - JSApplicationServiceReplyPriv* priv = - static_cast(JSObjectGetPrivate(object)); - JSObjectSetPrivate(object, NULL); - LogDebug("Deleting ApplicationServiceReply object"); - delete priv; -} - -bool JSApplicationServiceReply::isObjectOfClass(JSContextRef context, JSValueRef value) -{ - return JSValueIsObjectOfClass(context, value, getClassRef()); -} - -JSValueRef JSApplicationServiceReply::getIsSucceed(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - LogDebug("Enter"); - JSApplicationServiceReplyPriv *priv = - static_cast(JSObjectGetPrivate(object)); - assert(priv && "Private object not set."); - - Try { - ApplicationServiceReplyPtr appsvc = priv->getObject(); - CommonsJavaScript::Converter converter(context); - - if (JSStringIsEqualToUTF8CString(propertyName,APPLICATION_SERVICE_REPLY_SUCCESS)) { - LogDebug( - "JSApplicationServiceReply::getProperty ::success "); - - bool isSucceed = appsvc->getIsSucceed(); - return converter.toJSValueRef(isSucceed); - } - - } - Catch(Commons::Exception) { - LogError("Exception: " << _rethrown_exception.GetMessage()); - return JSDOMExceptionFactory::UnknownException.make(context, exception); - } - return JSValueMakeUndefined(context); -} - -JSValueRef JSApplicationServiceReply::getExtraData(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - LogDebug("Enter"); - JSApplicationServiceReplyPriv *priv = - static_cast(JSObjectGetPrivate(object)); - assert(priv && "Private object not set."); - - Try { - ApplicationServiceReplyPtr appsvc = priv->getObject(); - CommonsJavaScript::Converter convert(context); - - if (JSStringIsEqualToUTF8CString(propertyName,APPLICATION_SERVICE_EXTRADATA)) { - LogDebug( - "JSApplicationServiceReply::getProperty ::extraData "); - - JSObjectRef result = JSApplicationServiceExtraDataArray::createArray(context, appsvc->getExtraDataArray()); - - return result; - } - } - Catch(Commons::Exception) { - LogError("Exception: " << _rethrown_exception.GetMessage()); - return JSDOMExceptionFactory::UnknownException.make(context, exception); - } - return JSValueMakeUndefined(context); -} - -bool JSApplicationServiceReply::hasInstance(JSContextRef context, - JSObjectRef constructor, - JSValueRef possibleInstance, - JSValueRef* exception) -{ - return JSValueIsObjectOfClass(context, possibleInstance, getClassRef()); -} -} // -} //TizenApis -} diff --git a/src/standards/Tizen/Application/JSApplicationServiceReply.h b/src/standards/Tizen/Application/JSApplicationServiceReply.h deleted file mode 100755 index 6e6dc72..0000000 --- a/src/standards/Tizen/Application/JSApplicationServiceReply.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_SERVICE_REPLY_H_ -#define TIZENAPIS_TIZEN_JS_APPLICATION_SERVICE_REPLY_H_ - -#include -#include -#include -#include "JSApplicationServiceExtraDataArray.h" - -namespace TizenApis { -namespace Tizen1_0 { -namespace Application { - -typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT::Type JSApplicationServiceReplyPriv; - -class JSApplicationServiceReply { -public: - static const JSClassDefinition* getClassInfo(); - - static const JSClassRef getClassRef(); - - /** - * create an JSObject for callback function(onAnswerReceived). - */ - static JSObjectRef createJSObject(JSContextRef context, - const Api::Application::ApplicationServiceReplyPtr &appsvc); - - static bool isObjectOfClass(JSContextRef context, JSValueRef value); - - static Api::Application::ApplicationServiceReplyPtr getApplicationServiceReply(JSContextRef context, JSValueRef value); - /** - * return private data - */ - static Api::Application::ApplicationServiceReplyPtr 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); - - /** - * The callback invoked when getting a success property's value. - */ - static JSValueRef getIsSucceed(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - /** - * The callback invoked when getting a extraData property's value. - */ - static JSValueRef getExtraData(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/Application/JSApplicationServiceRequest.cpp b/src/standards/Tizen/Application/JSApplicationServiceRequest.cpp deleted file mode 100755 index 320930b..0000000 --- a/src/standards/Tizen/Application/JSApplicationServiceRequest.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include "JSApplicationServiceRequest.h" - -namespace TizenApis { -namespace Tizen1_0 { -namespace Application { -using namespace WrtDeviceApis; -using namespace WrtDeviceApis::CommonsJavaScript; - -using namespace Api::Application; - -namespace { -const char* APPLICATION_SERVICE_OPERATION = "operation"; -const char* APPLICATION_SERVICE_URI = "uri"; -const char* APPLICATION_SERVICE_MIME = "mime"; -const char* APPLICATION_SERVICE_PACKAGE = "package"; -const char* APPLICATION_SERVICE_EXTRADATA = "extraData"; - - -} //private namespace - -JSClassRef JSApplicationServiceRequest::m_jsClassRef = NULL; - -JSClassDefinition JSApplicationServiceRequest::m_classInfo = { - 0, - kJSClassAttributeNone, - "ApplicationServiceRequest", - 0, - m_property, - 0, - initialize, - finalize, - NULL, //HasProperty, - getProperty, - NULL, //SetProperty, - NULL, //DeleteProperty, - NULL, //GetPropertyNames, - NULL, //CallAsFunction, - NULL, //CallAsConstructor, - hasInstance, - NULL, //ConvertToType -}; - -JSStaticValue JSApplicationServiceRequest::m_property[] = { - { APPLICATION_SERVICE_OPERATION, getProperty, NULL, kJSPropertyAttributeReadOnly }, - { APPLICATION_SERVICE_URI, getProperty, NULL, kJSPropertyAttributeReadOnly }, - { APPLICATION_SERVICE_MIME, getProperty, NULL, kJSPropertyAttributeReadOnly }, - { APPLICATION_SERVICE_PACKAGE, getProperty, NULL, kJSPropertyAttributeReadOnly }, - { APPLICATION_SERVICE_EXTRADATA, getProperty, NULL, kJSPropertyAttributeReadOnly }, - { 0, 0, 0, 0 } -}; - -const JSClassDefinition* JSApplicationServiceRequest::getClassInfo() -{ - return &m_classInfo; -} - -const JSClassRef JSApplicationServiceRequest::getClassRef() -{ - if (!m_jsClassRef) { - m_jsClassRef = JSClassCreate(&m_classInfo); - } - return m_jsClassRef; -} - -//JSClassRef JSApplicationServiceRequest::m_jsClassRef = JSClassCreate( -// JSApplicationServiceRequest::getClassInfo()); - -JSObjectRef JSApplicationServiceRequest::createJSObject(JSContextRef context, - const ApplicationServiceRequestPtr &appsvc) -{ - ApplicationServiceRequestPtr privateData(new ApplicationServiceRequest()); - JSApplicationServiceRequestPriv *priv = new JSApplicationServiceRequestPriv(context, privateData); - - if (!priv) { - ThrowMsg(Commons::NullPointerException, "Can not new an object"); - } - return JSObjectMake(context, getClassRef(), priv); -} - -ApplicationServiceRequestPtr JSApplicationServiceRequest::getApplicationServiceRequest(JSContextRef context, JSValueRef value) -{ - if (!isObjectOfClass(context, value)) { - Throw(Commons::InvalidArgumentException); - } - JSObjectRef object = JSValueToObject(context, value, NULL); - if (!object) { - Throw(Commons::InvalidArgumentException); - } - JSApplicationServiceRequestPriv *priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(Commons::NullPointerException); - } - return priv->getObject(); -} - -ApplicationServiceRequestPtr JSApplicationServiceRequest::getPrivateData(JSObjectRef object) -{ - JSApplicationServiceRequestPriv* priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(Commons::NullPointerException); - } - return priv->getObject(); -} - - - -void JSApplicationServiceRequest::initialize(JSContextRef context,JSObjectRef object) -{ - LogDebug("Entered. Nothing to do."); -} - -void JSApplicationServiceRequest::finalize(JSObjectRef object) -{ - LogDebug("Entered"); - JSApplicationServiceRequestPriv* priv = - static_cast(JSObjectGetPrivate(object)); - JSObjectSetPrivate(object, NULL); - LogDebug("Deleting ApplicationServiceRequest object"); - delete priv; -} - -bool JSApplicationServiceRequest::isObjectOfClass(JSContextRef context, JSValueRef value) -{ - return JSValueIsObjectOfClass(context, value, getClassRef()); -} - -JSValueRef JSApplicationServiceRequest::getProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - LogDebug("Enter"); - JSApplicationServiceRequestPriv *priv = - static_cast(JSObjectGetPrivate(object)); - assert(priv && "Private object not set."); - - Try { - ApplicationServiceRequestPtr appsvc = priv->getObject(); - CommonsJavaScript::Converter convert(context); - - if (JSStringIsEqualToUTF8CString(propertyName, APPLICATION_SERVICE_OPERATION)) { - LogDebug( - "JSApplicationServiceRequest::getProperty::operation " << - appsvc->getOperation()); - return convert.toJSValueRef(appsvc->getOperation()); - }else if (JSStringIsEqualToUTF8CString(propertyName, - APPLICATION_SERVICE_URI)) { - LogDebug( - "JSApplicationServiceRequest::getProperty ::uri " << - appsvc->getUri()); - return convert.toJSValueRef(appsvc->getUri()); - }else if (JSStringIsEqualToUTF8CString(propertyName, - APPLICATION_SERVICE_MIME)) { - LogDebug( - "JSApplicationServiceRequest::getProperty ::mime " << - appsvc->getMime()); - return convert.toJSValueRef(appsvc->getMime()); - }else if (JSStringIsEqualToUTF8CString(propertyName, - APPLICATION_SERVICE_PACKAGE)) { - LogDebug( - "JSApplicationServiceRequest::getProperty ::package " << - appsvc->getPackage()); - return convert.toJSValueRef(appsvc->getPackage()); - } - else if (JSStringIsEqualToUTF8CString(propertyName, - APPLICATION_SERVICE_EXTRADATA)) { - LogDebug( - "JSApplicationServiceRequest::getProperty ::extraData "); - JSObjectRef result = JSApplicationServiceExtraDataArray::createArray(context, appsvc->getExtraDataArray()); - - return result; - } - - } - Catch(Commons::Exception) { - LogError("Exception: " << _rethrown_exception.GetMessage()); - return JSDOMExceptionFactory::UnknownException.make(context, exception); - } - return JSValueMakeUndefined(context); -} - -bool JSApplicationServiceRequest::hasInstance(JSContextRef context, - JSObjectRef constructor, - JSValueRef possibleInstance, - JSValueRef* exception) -{ - return JSValueIsObjectOfClass(context, possibleInstance, getClassRef()); -} -} // -} //TizenApis -} diff --git a/src/standards/Tizen/Application/JSApplicationServiceRequest.h b/src/standards/Tizen/Application/JSApplicationServiceRequest.h deleted file mode 100755 index 1c14755..0000000 --- a/src/standards/Tizen/Application/JSApplicationServiceRequest.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_SERVICE_REQUEST_H_ -#define TIZENAPIS_TIZEN_JS_APPLICATION_SERVICE_REQUEST_H_ - -#include -#include -#include -#include "JSApplicationServiceExtraDataArray.h" - -namespace TizenApis { -namespace Tizen1_0 { -namespace Application { - -typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT::Type JSApplicationServiceRequestPriv; - -class JSApplicationServiceRequest { -public: - static const JSClassDefinition* getClassInfo(); - - static const JSClassRef getClassRef(); - - /** - * create an JSObject for callback function(onAnswerReceived). - */ - static JSObjectRef createJSObject(JSContextRef context, - const Api::Application::ApplicationServiceRequestPtr &appsvc); - - static bool isObjectOfClass(JSContextRef context, JSValueRef value); - - static Api::Application::ApplicationServiceRequestPtr getApplicationServiceRequest(JSContextRef context, JSValueRef value); - /** - * return private data - */ - static Api::Application::ApplicationServiceRequestPtr 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); - - /** - * 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; - -}; - -} // -} //TizenApis -} -#endif diff --git a/src/standards/Tizen/Application/config.xml b/src/standards/Tizen/Application/config.xml index 45646ff..086e017 100755 --- a/src/standards/Tizen/Application/config.xml +++ b/src/standards/Tizen/Application/config.xml @@ -10,17 +10,24 @@ http://tizen.org/api/application - application.manager - application.service + application.launch + application.kill + application.read - http://tizen.org/api/application.manager - application.manager + http://tizen.org/api/application.launch + application.launch + - http://tizen.org/api/application.service - application.service + http://tizen.org/api/application.kill + application.kill + + + + http://tizen.org/api/application.read + application.read diff --git a/src/standards/Tizen/Application/plugin_config.cpp b/src/standards/Tizen/Application/plugin_config.cpp index b811e3f..e81972d 100755 --- a/src/standards/Tizen/Application/plugin_config.cpp +++ b/src/standards/Tizen/Application/plugin_config.cpp @@ -24,12 +24,14 @@ #include "plugin_config.h" -#define APPLICATION_FEATURE_API "http://tizen.org/api/application" -#define APPLICATION_FEATURE_API_MANAGER "http://tizen.org/api/application.manager" -#define APPLICATION_FEATURE_API_SERVICE "http://tizen.org/api/application.service" +#define APPLICATION_FEATURE_API "http://tizen.org/api/application" +#define APPLICATION_FEATURE_API_LAUNCH "http://tizen.org/api/application.launch" +#define APPLICATION_FEATURE_API_KILL "http://tizen.org/api/application.kill" +#define APPLICATION_FEATURE_API_READ "http://tizen.org/api/application.read" -#define APPLICATION_DEVICE_CAP_MANAGER "application.manager" -#define APPLICATION_DEVICE_CAP_SERVICE "application.service" +#define APPLICATION_DEVICE_CAP_LAUNCH "application.launch" +#define APPLICATION_DEVICE_CAP_KILL "application.kill" +#define APPLICATION_DEVICE_CAP_READ "application.read" using namespace WrtDeviceApis::Commons; @@ -49,40 +51,43 @@ static FunctionMapping createApplicationFunctions() /** * Device capabilities */ - ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_MANAGER, APPLICATION_DEVICE_CAP_MANAGER); - ACE_CREATE_DEVICE_CAP(DEVICE_CAP_APPLICATION_SERVICE, APPLICATION_DEVICE_CAP_SERVICE); + 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_CAPS_LIST(EMPTY_DEVICE_LIST); - ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_MANAGER); - ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_APPLICATION_SERVICE); - ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_MANAGER, DEVICE_CAP_APPLICATION_MANAGER); - ACE_ADD_DEVICE_CAP(DEVICE_LIST_APPLICATION_SERVICE, DEVICE_CAP_APPLICATION_SERVICE); + 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_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); /** * Api Features */ - ACE_CREATE_FEATURE(FEATURE_APPLICATION, APPLICATION_FEATURE_API); - ACE_CREATE_FEATURE(FEATURE_APPLICATION_MANAGER, APPLICATION_FEATURE_API_MANAGER); - ACE_CREATE_FEATURE(FEATURE_APPLICATION_SERVICE, APPLICATION_FEATURE_API_SERVICE); + ACE_CREATE_FEATURE(FEATURE_APPLICATION, APPLICATION_FEATURE_API); + 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_LIST(APPLICATION_FEATURES_APPLICATION_MANAGER); - ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_MANAGER, FEATURE_APPLICATION); - ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_MANAGER, FEATURE_APPLICATION_MANAGER); + ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_LAUNCH); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_LAUNCH, FEATURE_APPLICATION); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_LAUNCH, FEATURE_APPLICATION_LAUNCH); - ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_SERVICE); - ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_SERVICE, FEATURE_APPLICATION); - ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_SERVICE, FEATURE_APPLICATION_SERVICE); + ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_KILL); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_KILL, FEATURE_APPLICATION); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_KILL, FEATURE_APPLICATION_KILL); - ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES); - ACE_ADD_API_FEATURE(APPLICATION_FEATURES, FEATURE_APPLICATION); + ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION_READ); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_READ, FEATURE_APPLICATION); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_LAUNCH, FEATURE_APPLICATION_LAUNCH); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_KILL, FEATURE_APPLICATION_KILL); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_READ, FEATURE_APPLICATION_READ); - ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_MANAGER); - ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_MANAGER, FEATURE_APPLICATION_MANAGER); - - ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_SERVICE); - ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION_SERVICE, FEATURE_APPLICATION_SERVICE); - + ACE_CREATE_FEATURE_LIST(APPLICATION_FEATURES_APPLICATION); + ACE_ADD_API_FEATURE(APPLICATION_FEATURES_APPLICATION, FEATURE_APPLICATION); /** * Functions @@ -93,136 +98,163 @@ static FunctionMapping createApplicationFunctions() AceFunction launchFunc = ACE_CREATE_FUNCTION( FUNCTION_LAUNCH, APPLICATION_FUNCTION_API_LAUNCH, - APPLICATION_FEATURES_APPLICATION_MANAGER, - DEVICE_LIST_APPLICATION_MANAGER); + APPLICATION_FEATURES_APPLICATION_LAUNCH, + DEVICE_LIST_APPLICATION_LAUNCH); applicationMapping.insert(std::make_pair( APPLICATION_FUNCTION_API_LAUNCH, launchFunc)); + // launchService + AceFunction launchServiceFunc = ACE_CREATE_FUNCTION( + FUNCTION_LAUNCH_SERVICE, + APPLICATION_FUNCTION_API_LAUNCH_SERVICE, + APPLICATION_FEATURES_APPLICATION_LAUNCH, + DEVICE_LIST_APPLICATION_LAUNCH); + + applicationMapping.insert(std::make_pair( + APPLICATION_FUNCTION_API_LAUNCH_SERVICE, + launchServiceFunc)); + + // getApplicationService + AceFunction getAppServiceFunc = ACE_CREATE_FUNCTION( + FUNCTION_GET_APPLICATION_SERVICE, + APPLICATION_FUNCTION_API_GET_APP_SERVICE, + APPLICATION_FEATURES_APPLICATION_LAUNCH, + DEVICE_LIST_APPLICATION_LAUNCH); + + applicationMapping.insert(std::make_pair( + APPLICATION_FUNCTION_API_GET_APP_SERVICE, + getAppServiceFunc)); + + // replyResult + AceFunction replyResultFunc = ACE_CREATE_FUNCTION( + FUNCTION_REPLY_RESULT, + APPLICATION_FUNCTION_API_REPLY_RESULT, + APPLICATION_FEATURES_APPLICATION_LAUNCH, + DEVICE_LIST_APPLICATION_LAUNCH); + + 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_LAUNCH, + DEVICE_LIST_APPLICATION_LAUNCH); + + applicationMapping.insert(std::make_pair( + APPLICATION_FUNCTION_API_REPLY_FAILURE, + replyFailureFunc)); + // kill AceFunction killFunc = ACE_CREATE_FUNCTION( FUNCTION_KILL, APPLICATION_FUNCTION_API_KILL, - APPLICATION_FEATURES_APPLICATION_MANAGER, - DEVICE_LIST_APPLICATION_MANAGER); + APPLICATION_FEATURES_APPLICATION_KILL, + DEVICE_LIST_APPLICATION_KILL); applicationMapping.insert(std::make_pair( APPLICATION_FUNCTION_API_KILL, killFunc)); - // exit - AceFunction exitFunc = ACE_CREATE_FUNCTION( - FUNCTION_EXIT, - APPLICATION_FUNCTION_API_EXIT, - APPLICATION_FEATURES_APPLICATION_MANAGER, - DEVICE_LIST_APPLICATION_MANAGER); - - 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_MANAGER, - DEVICE_LIST_APPLICATION_MANAGER); - - applicationMapping.insert(std::make_pair( - APPLICATION_FUNCTION_API_HIDE, - hideFunc)); - // getApplicationInformations - AceFunction getApplicationInformationsFunc = ACE_CREATE_FUNCTION( + // getApplicationsInformation + AceFunction getAppsInfoFunc = ACE_CREATE_FUNCTION( FUNCTION_GET_APPLICATION_INFORMATIONS, - APPLICATION_FUNCTION_API_GET_APPLICATION_INFORMATIONS, - APPLICATION_FEATURES_APPLICATION_MANAGER, - DEVICE_LIST_APPLICATION_MANAGER); + APPLICATION_FUNCTION_API_GET_APPS_INFO, + APPLICATION_FEATURES_APPLICATION_READ, + DEVICE_LIST_APPLICATION_READ); applicationMapping.insert(std::make_pair( - APPLICATION_FUNCTION_API_GET_APPLICATION_INFORMATIONS, - getApplicationInformationsFunc)); + APPLICATION_FUNCTION_API_GET_APPS_INFO, + getAppsInfoFunc)); // getApplicationInformation - AceFunction getApplicationInformationFunc = ACE_CREATE_FUNCTION( + AceFunction getAppInfoFunc = ACE_CREATE_FUNCTION( FUNCTION_GET_APPLICATION_INFORMATION, - APPLICATION_FUNCTION_API_GET_APPLICATION_INFORMATION, - APPLICATION_FEATURES_APPLICATION_MANAGER, - DEVICE_LIST_APPLICATION_MANAGER); + APPLICATION_FUNCTION_API_GET_APP_INFO, + APPLICATION_FEATURES_APPLICATION_READ, + DEVICE_LIST_APPLICATION_READ); applicationMapping.insert(std::make_pair( - APPLICATION_FUNCTION_API_GET_APPLICATION_INFORMATION, - getApplicationInformationFunc)); + APPLICATION_FUNCTION_API_GET_APP_INFO, + getAppInfoFunc)); - // getRunningApplicationContexts - AceFunction getRunningApplicationContextsFunc = ACE_CREATE_FUNCTION( + // getRunningApplicationsContext + AceFunction getRunningAppsContextFunc = ACE_CREATE_FUNCTION( FUNCTION_GET_RUNNING_APPLICATION_CONTEXTS, - APPLICATION_FUNCTION_API_GET_RUNNING_APPLICATION_CONTEXTS, - APPLICATION_FEATURES_APPLICATION_MANAGER, - DEVICE_LIST_APPLICATION_MANAGER); + APPLICATION_FUNCTION_API_GET_RUNNING_APPS_CONTEXT, + APPLICATION_FEATURES_APPLICATION_READ, + DEVICE_LIST_APPLICATION_READ); applicationMapping.insert(std::make_pair( - APPLICATION_FUNCTION_API_GET_RUNNING_APPLICATION_CONTEXTS, - getRunningApplicationContextsFunc)); + APPLICATION_FUNCTION_API_GET_RUNNING_APPS_CONTEXT, + getRunningAppsContextFunc)); // getCurrentApplicationContext - AceFunction getCurrentApplicationContextFunc = ACE_CREATE_FUNCTION( + AceFunction getCurrentAppContextFunc = ACE_CREATE_FUNCTION( FUNCTION_GET_CURRENT_APPLICATION_CONTEXT, - APPLICATION_FUNCTION_API_GET_CURRENT_APPLICATION_CONTEXT, - APPLICATION_FEATURES_APPLICATION_MANAGER, - DEVICE_LIST_APPLICATION_MANAGER); + APPLICATION_FUNCTION_API_GET_CURRENT_APP_CONTEXT, + APPLICATION_FEATURES_APPLICATION_READ, + DEVICE_LIST_APPLICATION_READ); applicationMapping.insert(std::make_pair( - APPLICATION_FUNCTION_API_GET_CURRENT_APPLICATION_CONTEXT, - getCurrentApplicationContextFunc)); + APPLICATION_FUNCTION_API_GET_CURRENT_APP_CONTEXT, + getCurrentAppContextFunc)); // addApplicationInformationEventListener - AceFunction addApplicationInformationEventListenerFunc = ACE_CREATE_FUNCTION( + AceFunction addAppInfoEventListenerFunc = ACE_CREATE_FUNCTION( FUNCTION_ADD_APPLICATION_INFORMATION_EVENT_LISTENER, - APPLICATION_FUNCTION_API_ADD_APPLICATION_INFORMATION_EVENT_LISTENER, - APPLICATION_FEATURES_APPLICATION_MANAGER, - DEVICE_LIST_APPLICATION_MANAGER); + 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_APPLICATION_INFORMATION_EVENT_LISTENER, - addApplicationInformationEventListenerFunc)); + APPLICATION_FUNCTION_API_ADD_APP_INFO_EVENT_LISTENER, + addAppInfoEventListenerFunc)); // removeApplicationInformationEventListener - AceFunction removeApplicationInformationEventListenerFunc = ACE_CREATE_FUNCTION( + AceFunction removeAppInfoEventListenerFunc = ACE_CREATE_FUNCTION( FUNCTION_REMOVE_APPLICATION_INFORMATION_EVENT_LISTENER, - APPLICATION_FUNCTION_API_REMOVE_APPLICATION_INFORMATION_EVENT_LISTENER, - APPLICATION_FEATURES_APPLICATION_MANAGER, - DEVICE_LIST_APPLICATION_MANAGER); + 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_APPLICATION_INFORMATION_EVENT_LISTENER, - removeApplicationInformationEventListenerFunc)); + APPLICATION_FUNCTION_API_REMOVE_APP_INFO_EVENT_LISTENER, + removeAppInfoEventListenerFunc)); - // launchService - AceFunction launchServiceFunc = ACE_CREATE_FUNCTION( - FUNCTION_LAUNCH_SERVICE, - APPLICATION_FUNCTION_API_LAUNCH_SERVICE, - APPLICATION_FEATURES_APPLICATION_SERVICE, - DEVICE_LIST_APPLICATION_SERVICE); + // 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_LAUNCH_SERVICE, - launchServiceFunc)); + APPLICATION_FUNCTION_API_EXIT, + exitFunc)); - // getApplicationService - AceFunction getApplicationServiceFunc = ACE_CREATE_FUNCTION( - FUNCTION_GET_APPLICATION_SERVICE, - APPLICATION_FUNCTION_API_GET_APPLICATION_SERVICE, - APPLICATION_FEATURES_APPLICATION_SERVICE, - DEVICE_LIST_APPLICATION_SERVICE); +#if 0 + // 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_GET_APPLICATION_SERVICE, - getApplicationServiceFunc)); + APPLICATION_FUNCTION_API_HIDE, + hideFunc)); +#endif + + return applicationMapping; + - return applicationMapping; } } diff --git a/src/standards/Tizen/Application/plugin_config.h b/src/standards/Tizen/Application/plugin_config.h index ebf6174..6494d95 100755 --- a/src/standards/Tizen/Application/plugin_config.h +++ b/src/standards/Tizen/Application/plugin_config.h @@ -21,22 +21,25 @@ #include #include -#define APPLICATION_FUNCTION_API_LAUNCH "launch" -#define APPLICATION_FUNCTION_API_KILL "kill" -#define APPLICATION_FUNCTION_API_EXIT "exit" -#define APPLICATION_FUNCTION_API_HIDE "hide" - -#define APPLICATION_FUNCTION_API_GET_APPLICATION_INFORMATIONS "getApplicationInformations" -#define APPLICATION_FUNCTION_API_GET_APPLICATION_INFORMATION "getApplicationInformation" - -#define APPLICATION_FUNCTION_API_GET_RUNNING_APPLICATION_CONTEXTS "getRunningApplicationContexts" -#define APPLICATION_FUNCTION_API_GET_CURRENT_APPLICATION_CONTEXT "getCurrentApplicationContext" - -#define APPLICATION_FUNCTION_API_ADD_APPLICATION_INFORMATION_EVENT_LISTENER "addApplicationInformationEventListener" -#define APPLICATION_FUNCTION_API_REMOVE_APPLICATION_INFORMATION_EVENT_LISTENER "removeApplicationInformationEventListener" - -#define APPLICATION_FUNCTION_API_LAUNCH_SERVICE "launchService" -#define APPLICATION_FUNCTION_API_GET_APPLICATION_SERVICE "getApplicationService" +// feature : manage +#define APPLICATION_FUNCTION_API_LAUNCH "launch" +#define APPLICATION_FUNCTION_API_LAUNCH_SERVICE "launchService" +#define APPLICATION_FUNCTION_API_GET_APP_SERVICE "getApplicationService" +#define APPLICATION_FUNCTION_API_REPLY_RESULT "replyResult" +#define APPLICATION_FUNCTION_API_REPLY_FAILURE "replyFailure" +#define APPLICATION_FUNCTION_API_KILL "kill" + +// feature : read +#define APPLICATION_FUNCTION_API_GET_APPS_INFO "getApplicationsInformation" +#define APPLICATION_FUNCTION_API_GET_APP_INFO "getApplicationInformation" +#define APPLICATION_FUNCTION_API_GET_RUNNING_APPS_CONTEXT "getRunningApplicationsContext" +#define APPLICATION_FUNCTION_API_GET_CURRENT_APP_CONTEXT "getCurrentApplicationContext" +#define APPLICATION_FUNCTION_API_ADD_APP_INFO_EVENT_LISTENER "addApplicationInformationEventListener" +#define APPLICATION_FUNCTION_API_REMOVE_APP_INFO_EVENT_LISTENER "removeApplicationInformationEventListener" +#define APPLICATION_FUNCTION_API_EXIT "exit" +#if 0 +#define APPLICATION_FUNCTION_API_HIDE "hide" +#endif namespace TizenApis { namespace Tizen1_0 { diff --git a/src/standards/Tizen/Bluetooth/BluetoothAdapterListener.cpp b/src/standards/Tizen/Bluetooth/BluetoothAdapterListener.cpp index 5bb9a85..4094faf 100644 --- a/src/standards/Tizen/Bluetooth/BluetoothAdapterListener.cpp +++ b/src/standards/Tizen/Bluetooth/BluetoothAdapterListener.cpp @@ -77,13 +77,16 @@ void BluetoothAdapterListener::MakeErrorJSCallBack(JSCallbackManagerPtr cbm, JSC { case ExceptionCodes::SecurityException: err = JSTizenExceptionFactory::makeErrorObject(globalContext, - JSTizenException::PERMISSION_DENIED_ERROR, "permission denied error"); - + 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::UnknownException: default: err = JSTizenExceptionFactory::makeErrorObject(globalContext, diff --git a/src/standards/Tizen/Bluetooth/BluetoothConverter.cpp b/src/standards/Tizen/Bluetooth/BluetoothConverter.cpp index abcc4a9..9a94700 100644 --- a/src/standards/Tizen/Bluetooth/BluetoothConverter.cpp +++ b/src/standards/Tizen/Bluetooth/BluetoothConverter.cpp @@ -100,9 +100,10 @@ EventBTOnDiscoveryDevicesPrivateDataPtr errorCalback = toFunctionOrNull(errorParam); - result.onSuccess = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, "onSuccess"); - result.onFound = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, "onFound"); - result.onFinished = JSUtils::getJSPropertyOrUndefined(m_context, objectCallbacks, "onFinish"); + 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.isNullOrUndefined(result.onSuccess) && !validator.isCallback(result.onSuccess)) || (!validator.isNullOrUndefined(result.onFound) && !validator.isCallback(result.onFound)) || diff --git a/src/standards/Tizen/Bluetooth/BluetoothDeviceManagerListener.cpp b/src/standards/Tizen/Bluetooth/BluetoothDeviceManagerListener.cpp index 496599a..44c2a3b 100644 --- a/src/standards/Tizen/Bluetooth/BluetoothDeviceManagerListener.cpp +++ b/src/standards/Tizen/Bluetooth/BluetoothDeviceManagerListener.cpp @@ -60,9 +60,14 @@ void BluetoothDeviceManagerListener::OnAnswerReceived(const EventBTConnectToServ JSObjectRef adapterObject = JSBluetoothSocket::createJSObject(callbackManager->getContext(), socketData); callbackManager->callOnSuccess(adapterObject); } - else + else if (event->getExceptionCode() == ExceptionCodes::NotFoundException) + { + callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(callbackManager->getContext(), + JSTizenException::UNKNOWN_ERROR, "service search failed")); + + } + else { - callbackManager->callOnError(JSTizenExceptionFactory::makeErrorObject(callbackManager->getContext(), JSTizenException::UNKNOWN_ERROR, "unknown error")); } diff --git a/src/standards/Tizen/Bluetooth/CMakeLists.txt b/src/standards/Tizen/Bluetooth/CMakeLists.txt index 59253e3..928409d 100644 --- a/src/standards/Tizen/Bluetooth/CMakeLists.txt +++ b/src/standards/Tizen/Bluetooth/CMakeLists.txt @@ -10,9 +10,6 @@ include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_BLUETOOTH}) set(SRCS ${SRCS_PLATFORM_IMPLEMENTATION_BLUETOOTH} ${SRCS_PLATFORM_API_BLUETOOTH} - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp plugin_initializer.cpp plugin_config.cpp BluetoothAdapterListener.cpp diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothAdapter.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothAdapter.cpp index e6717e5..85533c3 100644 --- a/src/standards/Tizen/Bluetooth/JSBluetoothAdapter.cpp +++ b/src/standards/Tizen/Bluetooth/JSBluetoothAdapter.cpp @@ -116,14 +116,21 @@ JSValueRef JSBluetoothAdapter::getName(JSContextRef context, Catch (WrtDeviceApis::Commons::ConversionException) { LogError("ConversionException"); - return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::INVALID_VALUES_ERROR, "invalid value error"); + 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 parameter error"); + 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::Exception) { @@ -216,9 +223,14 @@ JSValueRef JSBluetoothAdapter::setName(JSContextRef context, JSObjectRef object, { LogError("InvalidArgumentException"); return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error"); - + 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::Exception) { LogError("UnkownException"); @@ -252,17 +264,22 @@ JSValueRef JSBluetoothAdapter::getAddress(JSContextRef context, Catch (WrtDeviceApis::Commons::ConversionException) { LogError("ConversionException"); - return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::INVALID_VALUES_ERROR, "invalid value error"); + 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 parameter error"); - + 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::Exception) { LogError("UnkownException"); @@ -299,15 +316,21 @@ JSValueRef JSBluetoothAdapter::getVisible(JSContextRef context, { LogError("ConversionException"); return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::INVALID_VALUES_ERROR, "invalid value error"); + JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error"); - } + } Catch (WrtDeviceApis::Commons::InvalidArgumentException) { LogError("InvalidArgumentException"); - return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error"); + 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::Exception) { LogError("UnkownException"); @@ -415,16 +438,21 @@ JSValueRef JSBluetoothAdapter::getPowered(JSContextRef context, { LogError("ConversionException"); return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::INVALID_VALUES_ERROR, "invalid value error"); + JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error"); - } + } Catch (WrtDeviceApis::Commons::InvalidArgumentException) { LogError("InvalidArgumentException"); - return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error"); - + 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::Exception) { LogError("UnkownException"); @@ -519,14 +547,20 @@ JSValueRef JSBluetoothAdapter::setPowered(JSContextRef context, JSObjectRef obje 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 parameter error"); - + 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::Exception) { LogError("Exception"); @@ -640,14 +674,19 @@ JSValueRef JSBluetoothAdapter::setVisible(JSContextRef context, JSObjectRef obje 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 parameter error"); - + 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::Exception) { LogError("Exception"); @@ -713,21 +752,26 @@ JSValueRef JSBluetoothAdapter::discoveryDevices(JSContextRef context, JSObjectRe return JSValueMakeNull(context); - } + } 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 parameter error"); - + 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::Exception) { LogError("Exception"); @@ -805,14 +849,19 @@ JSValueRef JSBluetoothAdapter::stopDiscovery(JSContextRef context, JSObjectRef o 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 parameter error"); - + 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::Exception) { LogError("Exception"); @@ -898,14 +947,19 @@ JSValueRef JSBluetoothAdapter::getKnownDevices(JSContextRef context, JSObjectRef 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 parameter error"); - + 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::Exception) { LogError("Exception"); @@ -989,14 +1043,19 @@ JSValueRef JSBluetoothAdapter::getDevice(JSContextRef context, JSObjectRef objec 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 parameter error"); - + 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::Exception) { LogError("Exception"); @@ -1085,14 +1144,19 @@ JSValueRef JSBluetoothAdapter::createBonding(JSContextRef context, JSObjectRef o 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 parameter error"); - + 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::Exception) { LogError("Exception"); @@ -1179,14 +1243,19 @@ JSValueRef JSBluetoothAdapter::destroyBonding(JSContextRef context, JSObjectRef 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 parameter error"); - + 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::Exception) { LogError("Exception"); @@ -1292,21 +1361,19 @@ JSValueRef JSBluetoothAdapter::registerRFCOMMServiceByUUID(JSContextRef context, 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 parameter error"); - + return JSTizenExceptionFactory::postException(context, exception, + JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error"); } - Catch (WrtDeviceApis::Commons::UnsupportedException) + Catch(WrtDeviceApis::Commons::UnsupportedException) { - LogError("NotsupportedException"); - return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::NOT_SUPPORTED_ERROR, "not support error"); - - } + LogError("UnsupportException"); + return JSTizenExceptionFactory::postException(context, exception, + JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception"); + } Catch (WrtDeviceApis::Commons::Exception) { LogError("Exception"); diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothDevice.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothDevice.cpp index 13eb7be..ac0de97 100644 --- a/src/standards/Tizen/Bluetooth/JSBluetoothDevice.cpp +++ b/src/standards/Tizen/Bluetooth/JSBluetoothDevice.cpp @@ -175,16 +175,23 @@ JSValueRef JSBluetoothDevice::getName(JSContextRef context, } Catch (WrtDeviceApis::Commons::ConversionException) { - LogError("WrtDeviceApis::Commons::ConversionException"); - return JSTizenExceptionFactory::postException(context, - exception, JSTizenException::INVALID_VALUES_ERROR, "invalid value error"); + 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 parameter error"); + 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::Exception) { LogError("hasInstance Exception"); @@ -219,16 +226,23 @@ JSValueRef JSBluetoothDevice::getAddress(JSContextRef context, } Catch (WrtDeviceApis::Commons::ConversionException) { - LogError("ConversationException"); + LogError("ConversionException"); return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::INVALID_VALUES_ERROR, "invalid value error"); + JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error"); + } Catch (WrtDeviceApis::Commons::InvalidArgumentException) { LogError("InvalidArgumentException"); - return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error"); + 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::Exception) { LogError("hasInstance Exception"); @@ -262,16 +276,23 @@ JSValueRef JSBluetoothDevice::getDeviceClass(JSContextRef context, } Catch (WrtDeviceApis::Commons::ConversionException) { - LogError("ConversationException"); - return JSTizenExceptionFactory::postException(context, - exception, JSTizenException::INVALID_VALUES_ERROR, "invalid value error"); + 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 parameter error"); + 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::Exception) { LogError("hasInstance Exception"); @@ -307,16 +328,23 @@ JSValueRef JSBluetoothDevice::getBondProperty(JSContextRef context, } Catch (WrtDeviceApis::Commons::ConversionException) { - LogError("ConversationException"); - return JSTizenExceptionFactory::postException(context, - exception, JSTizenException::INVALID_VALUES_ERROR, "invalid value error");; + 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 parameter error"); + 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::Exception) { LogError("hasInstance Exception"); @@ -350,16 +378,23 @@ JSValueRef JSBluetoothDevice::getTrustProperty(JSContextRef context, } Catch (WrtDeviceApis::Commons::ConversionException) { - LogError("ConversationException"); - return JSTizenExceptionFactory::postException(context, - exception, JSTizenException::INVALID_VALUES_ERROR, "invalid value error");; + 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 parameter error"); + 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::Exception) { LogError("hasInstance Exception"); @@ -392,16 +427,23 @@ JSValueRef JSBluetoothDevice::getConnectProperty(JSContextRef context, } Catch (WrtDeviceApis::Commons::ConversionException) { - LogError("ConversationException"); - return JSTizenExceptionFactory::postException(context, - exception, JSTizenException::INVALID_VALUES_ERROR, "invalid value error");; + 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 parameter error"); + 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::Exception) { LogError("hasInstance Exception"); @@ -453,16 +495,23 @@ JSValueRef JSBluetoothDevice::getUuids(JSContextRef context, } Catch (WrtDeviceApis::Commons::ConversionException) { - LogError("ConversationException"); - return JSTizenExceptionFactory::postException(context, - exception, JSTizenException::INVALID_VALUES_ERROR, "invalid value error");; + 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 parameter error"); + 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::Exception) { LogError("hasInstance Exception"); @@ -587,34 +636,30 @@ JSValueRef JSBluetoothDevice::connectToServiceByUUID(JSContextRef context, JSObj return JSValueMakeNull(context); } - - Catch (WrtDeviceApis::Commons::UnsupportedException) - { - LogError("UnsupportedException"); - return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::NOT_SUPPORTED_ERROR, "not support error"); - - } 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 parameter error"); - + 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::Exception) { LogError("Exception"); return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "unknown error"); - } return JSValueMakeUndefined(context); diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothManager.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothManager.cpp index 00a3e78..1a1f735 100644 --- a/src/standards/Tizen/Bluetooth/JSBluetoothManager.cpp +++ b/src/standards/Tizen/Bluetooth/JSBluetoothManager.cpp @@ -22,8 +22,11 @@ #include #include #include +#include +#include #include #include "JSBluetoothManager.h" +#include "JSBluetoothAdapter.h" #include "JSBluetoothClassDeviceMajor.h" #include "JSBluetoothClassDeviceMinor.h" #include "JSBluetoothClassDeviceService.h" @@ -46,7 +49,7 @@ JSClassDefinition JSBluetoothManager::m_classInfo = "BluetoothManager", NULL, m_properties, - NULL, + m_function, initialize, finalize, NULL, @@ -61,6 +64,11 @@ JSClassDefinition JSBluetoothManager::m_classInfo = }; +JSStaticFunction JSBluetoothManager::m_function[] = +{ + { "getDefaultAdapter", getDefaultAdapter, kJSPropertyAttributeNone }, + { 0, 0, 0 } +}; JSStaticValue JSBluetoothManager::m_properties[] = @@ -87,6 +95,48 @@ const JSClassRef JSBluetoothManager::getClassRef() return m_jsClassRef; } +JSValueRef JSBluetoothManager::getDefaultAdapter(JSContextRef context, JSObjectRef object, + JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], + JSValueRef* exception) +{ + JSBluetoothManagerPriv* priv = static_cast(JSObjectGetPrivate(thisObject)); + + Try + { + if (priv == NULL) + { + Throw(UnknownException); + } + JSContextRef globalContext = priv->getContext(); + + return JSBluetoothAdapter::createJSObject(globalContext); + } + 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::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"); + } + return JSValueMakeUndefined(context); +} void JSBluetoothManager::getPropertyNames(JSContextRef context, JSObjectRef object, @@ -143,13 +193,13 @@ JSValueRef JSBluetoothManager::getProperty(JSContextRef context, { LogError("ConversionException"); return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::INVALID_VALUES_ERROR, "invalid value error"); + JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error"); } Catch (WrtDeviceApis::Commons::InvalidArgumentException) { LogError("InvalidArgumentException"); return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error"); + JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error"); } Catch(WrtDeviceApis::Commons::Exception) { diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothManager.h b/src/standards/Tizen/Bluetooth/JSBluetoothManager.h index aad79e4..4c40810 100644 --- a/src/standards/Tizen/Bluetooth/JSBluetoothManager.h +++ b/src/standards/Tizen/Bluetooth/JSBluetoothManager.h @@ -38,9 +38,13 @@ 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; }; diff --git a/src/standards/Tizen/Bluetooth/JSBluetoothSocket.cpp b/src/standards/Tizen/Bluetooth/JSBluetoothSocket.cpp index 7602a6b..c0b58b2 100644 --- a/src/standards/Tizen/Bluetooth/JSBluetoothSocket.cpp +++ b/src/standards/Tizen/Bluetooth/JSBluetoothSocket.cpp @@ -390,30 +390,31 @@ JSValueRef JSBluetoothSocket::writeData(JSContextRef context, JSObjectRef object 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"); + 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 parameter error"); + JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error"); } - Catch (WrtDeviceApis::Commons::UnknownException) + Catch(WrtDeviceApis::Commons::UnsupportedException) { + LogError("UnsupportException"); return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::UNKNOWN_ERROR, "Unkown error"); - } - Catch(WrtDeviceApis::Commons::Exception) + JSTizenException::NOT_SUPPORTED_ERROR, "Unsupport Exception"); + } + Catch (WrtDeviceApis::Commons::Exception) { - LogError("UnkownException"); - return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::UNKNOWN_ERROR, "Unkown error"); + LogError("Exception"); + return JSTizenExceptionFactory::postException(context, exception, + JSTizenException::UNKNOWN_ERROR, "unknown error"); } return converter.toJSValueRef(0); @@ -460,26 +461,32 @@ JSValueRef JSBluetoothSocket::readData(JSContextRef context, JSObjectRef object, 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"); + 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 parameter error"); + JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error"); } - Catch(WrtDeviceApis::Commons::Exception) + Catch(WrtDeviceApis::Commons::UnsupportedException) { - LogError("UnkownException"); + LogError("UnsupportException"); return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::UNKNOWN_ERROR, "Unkown error"); - } + 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); } @@ -512,28 +519,33 @@ JSValueRef JSBluetoothSocket::close(JSContextRef context, JSObjectRef object, 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"); + 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 parameter error"); + JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error"); } - Catch(WrtDeviceApis::Commons::Exception) + Catch(WrtDeviceApis::Commons::UnsupportedException) { - LogError("UnkownException"); + LogError("UnsupportException"); return JSTizenExceptionFactory::postException(context, exception, - JSTizenException::UNKNOWN_ERROR, "Unkown error"); - } - - + 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); } diff --git a/src/standards/Tizen/Bluetooth/plugin_initializer.cpp b/src/standards/Tizen/Bluetooth/plugin_initializer.cpp index 772998f..1be8a15 100644 --- a/src/standards/Tizen/Bluetooth/plugin_initializer.cpp +++ b/src/standards/Tizen/Bluetooth/plugin_initializer.cpp @@ -52,12 +52,12 @@ PLUGIN_ON_WIDGET_START(on_widget_start_callback) PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback) #define BLUETOOTH "bluetooth" -#define BLUETOOTH_ADAPTER "adapter" +//#define BLUETOOTH_ADAPTER "adapter" PLUGIN_CLASS_MAP_BEGIN PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, BLUETOOTH, TizenApis::Tizen1_0::JSBluetoothManager::getClassRef(),NULL) -PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN "." BLUETOOTH,BLUETOOTH_ADAPTER, - TizenApis::Tizen1_0::JSBluetoothAdapter::getClassRef(),NULL) +//PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN "." BLUETOOTH,BLUETOOTH_ADAPTER, +// TizenApis::Tizen1_0::JSBluetoothAdapter::getClassRef(),NULL) PLUGIN_CLASS_MAP_END diff --git a/src/standards/Tizen/CMakeLists.txt b/src/standards/Tizen/CMakeLists.txt index 24a1ee2..ca5e183 100755 --- a/src/standards/Tizen/CMakeLists.txt +++ b/src/standards/Tizen/CMakeLists.txt @@ -4,6 +4,23 @@ SET( CMAKE_INSTALL_RPATH 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-1.0-common") +set(COMMON_DESTINATION_NAME "tizen-1.0-tizen") + +set(CMAKE_INSTALL_RPATH + ${CMAKE_INSTALL_RPATH} + ${CMAKE_INSTALL_PREFIX}/${COMMON_DESTINATION_NAME} +) + +add_subdir(Common) + +set(LIBS_COMMON + ${LIBS_COMMON} + ${COMMON_TARGET_NAME} +) +### tizen common module end + add_subdir(Tizen) add_subdir(Mediacontent) add_subdir(Calendar) @@ -19,6 +36,7 @@ add_subdir(NFC) add_subdir(Sensors) add_subdir(Log) add_subdir(Filesystem) +add_subdir(Alarm) #add_subdir(Account) #add_subdir(DeviceInteraction) @@ -29,3 +47,4 @@ add_subdir(Filesystem) #add_subdir(Magnetic) #add_subdir(Proximity) #add_subdir(AlarmManager) + diff --git a/src/standards/Tizen/Calendar/CMakeLists.txt b/src/standards/Tizen/Calendar/CMakeLists.txt index bc40509..1d6e930 100755 --- a/src/standards/Tizen/Calendar/CMakeLists.txt +++ b/src/standards/Tizen/Calendar/CMakeLists.txt @@ -1,8 +1,14 @@ set(TARGET_NAME "wrt-plugins-tizen-1.0-calendar") set(DESTINATION_NAME "tizen-1.0-calendar") + +set(CMAKE_INSTALL_RPATH + ${CMAKE_INSTALL_RPATH} + ${CMAKE_INSTALL_PREFIX}/tizen-1.0-tizen + ${CMAKE_INSTALL_PREFIX}/tizen-1.0-time +) + set(SRCS ${SRCS_PLATFORM_API_CALENDAR} - ${SRCS_PLATFORM_API_FILTER} ${SRCS_PLATFORM_IMPLEMENTATION_CALENDAR} CalendarResponseDispatcher.cpp CalendarConverter.cpp @@ -19,23 +25,6 @@ set(SRCS JSCalendarItemGeo.cpp plugin_initializer.cpp plugin_config.cpp - ../Tizen/FilterConverter.cpp - ../Tizen/JSAttributeFilter.cpp - ../Tizen/JSAttributeRangeFilter.cpp - ../Tizen/JSCompositeFilter.cpp - ../Tizen/JSAbstractFilterArray.cpp - ../Tizen/JSSortMode.cpp - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp - ../Common/JSGlobalContextFactory.cpp - ${SRCS_PLATFORM_API_TIMEUTIL} - ${SRCS_PLATFORM_IMPLEMENTATION_TIMEUTIL} - ../TimeUtil/JSTimeUtil.cpp - ../TimeUtil/JSTZDate.cpp - ../TimeUtil/JSTimeDuration.cpp - ../TimeUtil/TimeUtilConverter.cpp - ../TimeUtil/plugin_config.cpp ) include_directories( @@ -46,6 +35,8 @@ add_library(${TARGET_NAME} SHARED ${SRCS}) target_link_libraries(${TARGET_NAME} ${LIBS_COMMON} ${LIBS_PLATFORM_IMPLEMENTATION_CALENDAR} + wrt-plugins-tizen-1.0-tizen-impl + wrt-plugins-tizen-1.0-time-impl ) INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_NAME}) diff --git a/src/standards/Tizen/Calendar/CalendarConverter.cpp b/src/standards/Tizen/Calendar/CalendarConverter.cpp index 7d76c41..8423b86 100755 --- a/src/standards/Tizen/Calendar/CalendarConverter.cpp +++ b/src/standards/Tizen/Calendar/CalendarConverter.cpp @@ -703,7 +703,7 @@ EventAttendeePtr CalendarConverter::toAttendee(JSValueRef attendee) result->setDelegateURI(toString(delegateURIData)); } if (!JSValueIsUndefined(m_context, contactRefData)) { - result->setPersonId(toString(contactRefData)); + result->setContactId(toString(contactRefData)); } return result; diff --git a/src/standards/Tizen/Calendar/JSAttendee.cpp b/src/standards/Tizen/Calendar/JSAttendee.cpp deleted file mode 100755 index 56cb3e9..0000000 --- a/src/standards/Tizen/Calendar/JSAttendee.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include "JSAttendee.h" -#include -#include -#include -#include -#include "CalendarConverter.h" - -using namespace TizenApis::Api::Calendar; -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; - -namespace TizenApis { -namespace Tizen1_0 { -namespace Calendar { - -#define TIZEN_ATTENDEE_ATTRIBUTENAME "Attendee" - -JSClassDefinition JSAttendee::m_classInfo = { - 0, - kJSClassAttributeNone, - TIZEN_ATTENDEE_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 JSAttendee::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_UID, getProperty, setProperty, kJSPropertyAttributeNone }, - - { 0, 0, 0, 0 } -}; - -JSClassRef JSAttendee::m_jsClassRef = JSClassCreate( - JSAttendee::getClassInfo()); - -const JSClassDefinition* JSAttendee::getClassInfo() -{ - return &(m_classInfo); -} - -JSClassRef JSAttendee::getClassRef() -{ - if (!m_jsClassRef) { - m_jsClassRef = JSClassCreate(&m_classInfo); - } - return m_jsClassRef; -} - -JSObjectRef JSAttendee::createJSAttendee(JSContextRef context, EventAttendeePtr attendee) -{ - AttendeePrivateObject *priv = new AttendeePrivateObject(context, attendee); - return JSObjectMake(context, getClassRef(), priv); -} - -void JSAttendee::initialize(JSContextRef context, - JSObjectRef object) -{ - LogDebug("enter"); -} - -void JSAttendee::finalize(JSObjectRef object) -{ - LogDebug("enter"); - AttendeePrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - delete priv; - JSObjectSetPrivate(object, NULL); -} - -JSValueRef JSAttendee::getProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - LogDebug("enter"); - CalendarConverterFactory::ConverterType converter = - CalendarConverterFactory::getConverter(context); - Try - { - AttendeePrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(NullPointerException); - } - 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_UID)) { - return converter->toJSValueRef(attendee->getPersonId()); - } - } - Catch(Exception) - { - LogError("invalid property"); - } - return JSValueMakeUndefined(context); -} - -bool JSAttendee::setProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - LogDebug("entered"); - CalendarConverterFactory::ConverterType converter = - CalendarConverterFactory::getConverter(context); - Try - { - AttendeePrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(NullPointerException); - } - EventAttendeePtr attendee = priv->getObject(); - - if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_NAME)) { - if (!JSValueIsString(context, value)) { - Throw(InvalidArgumentException); - } - std::string name = converter->toString(value); - attendee->setName(name); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_URI)) { - if (!JSValueIsString(context, value)) { - Throw(InvalidArgumentException); - } - std::string uri = converter->toString(value); - attendee->setURI(uri); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_ROLE)) { - if (!JSValueIsString(context, value)) { - Throw(InvalidArgumentException); - } - std::string role = converter->toString(value); - attendee->setRole(converter->toEventAttendeeRole(role)); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_STATUS)) { - if (!JSValueIsString(context, value)) { - Throw(InvalidArgumentException); - } - std::string status = converter->toString(value); - attendee->setStatus(converter->toEventAttendeeStatus(status)); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_RSVP)) { - if (!JSValueIsBoolean(context, value)) { - Throw(InvalidArgumentException); - } - bool RSVP = converter->toBool(value); - attendee->setRSVP(RSVP); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_TYPE)) { - if (!JSValueIsString(context, value)) { - Throw(InvalidArgumentException); - } - std::string type = converter->toString(value); - attendee->setType(converter->toEventAttendeeType(type)); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_GROUP)) { - if (!JSValueIsString(context, value)) { - Throw(InvalidArgumentException); - } - std::string group = converter->toString(value); - attendee->setGroup(group); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_DELEGATORURI)) { - if (!JSValueIsString(context, value)) { - Throw(InvalidArgumentException); - } - std::string delegatorURI = converter->toString(value); - attendee->setDelegatorURI(delegatorURI); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_DELEGATEURI)) { - if (!JSValueIsString(context, value)) { - Throw(InvalidArgumentException); - } - std::string delegateURI = converter->toString(value); - attendee->setDelegateURI(delegateURI); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_UID)) { - if (!JSValueIsString(context, value)) { - Throw(InvalidArgumentException); - } - std::string uid = converter->toString(value); - attendee->setPersonId(uid); - 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/Calendar/JSAttendee.h b/src/standards/Tizen/Calendar/JSAttendee.h deleted file mode 100755 index f75ec0a..0000000 --- a/src/standards/Tizen/Calendar/JSAttendee.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_ATTENDEE_H_ -#define _JS_ATTENDEE_H_ - -#include -#include -#include -#include -#include -#include - -using namespace TizenApis::Api::Calendar; -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; - -namespace TizenApis { -namespace Tizen1_0 { -namespace Calendar { - -#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_UID "uid" - -typedef PrivateObject AttendeePrivateObject; - -class JSAttendee -{ - public: - - static const JSClassDefinition* getClassInfo(); - - static JSClassRef getClassRef(); - - static JSObjectRef createJSAttendee(JSContextRef context, Api::Calendar::EventAttendeePtr event); - - 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 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_ATTENDEE_H_ */ diff --git a/src/standards/Tizen/Calendar/JSCalendarAttendee.cpp b/src/standards/Tizen/Calendar/JSCalendarAttendee.cpp index 464be60..ce9c803 100755 --- a/src/standards/Tizen/Calendar/JSCalendarAttendee.cpp +++ b/src/standards/Tizen/Calendar/JSCalendarAttendee.cpp @@ -242,7 +242,7 @@ JSValueRef JSCalendarAttendee::getProperty(JSContextRef context, } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_DELEGATEURI)) { return converter->toJSValueRef(attendee->getDelegateURI()); } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_ATTENDEE_CONTACT_REF)) { - return converter->toJSValueRef(attendee->getPersonId()); + return converter->toJSValueRef(attendee->getContactId()); } } Catch(Exception) @@ -338,7 +338,7 @@ bool JSCalendarAttendee::setProperty(JSContextRef context, Throw(InvalidArgumentException); } std::string uid = converter->toString(value); - attendee->setPersonId(uid); + attendee->setContactId(uid); return true; } } diff --git a/src/standards/Tizen/Calendar/JSEventAlarm.cpp b/src/standards/Tizen/Calendar/JSEventAlarm.cpp deleted file mode 100755 index 1d0509c..0000000 --- a/src/standards/Tizen/Calendar/JSEventAlarm.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include "JSEventAlarm.h" -#include "CalendarConverter.h" -#include -#include -#include -#include -#include -#include -#include - -using namespace TizenApis::Api::Calendar; -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; - -namespace TizenApis { -namespace Tizen1_0 { -namespace Calendar { - -#define TIZEN_CALENDAR_ALARM_ATTRIBUTENAME "CalendarAlarm" - -JSClassDefinition JSEventAlarm::m_classInfo = { - 0, - kJSClassAttributeNone, - TIZEN_CALENDAR_ALARM_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 JSEventAlarm::m_property[] = { - { TIZEN_CALENDAR_ALARM_ABSOLUTE_DATE, getProperty, setProperty, kJSPropertyAttributeNone }, - { TIZEN_CALENDAR_ALARM_BEFORE, getProperty, setProperty, kJSPropertyAttributeNone }, - { TIZEN_CALENDAR_ALARM_METHODS, getProperty, setProperty, kJSPropertyAttributeNone }, - { 0, 0, 0, 0 } -}; - -JSClassRef JSEventAlarm::m_jsClassRef = JSClassCreate( - JSEventAlarm::getClassInfo()); - -const JSClassDefinition* JSEventAlarm::getClassInfo() -{ - return &(m_classInfo); -} - -JSClassRef JSEventAlarm::getClassRef() -{ - if (!m_jsClassRef) { - m_jsClassRef = JSClassCreate(&m_classInfo); - } - return m_jsClassRef; -} - -JSObjectRef JSEventAlarm::createJSObject(JSContextRef context, EventAlarmPtr alarm) -{ - EventAlarmPrivateObject *priv = new EventAlarmPrivateObject(context, alarm); - return JSObjectMake(context, getClassRef(), priv); -} - -EventAlarmPtr JSEventAlarm::getAlarm(JSObjectRef object) -{ - LogDebug("entered"); - EventAlarmPrivateObject *priv = - static_cast(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 JSEventAlarm::initialize(JSContextRef context, - JSObjectRef object) -{ - LogDebug("enter"); -} - -void JSEventAlarm::finalize(JSObjectRef object) -{ - LogDebug("enter"); - EventAlarmPrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - delete priv; - JSObjectSetPrivate(object, NULL); -} - -JSValueRef JSEventAlarm::getProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - LogDebug("enter"); - WrtDeviceApis::CommonsJavaScript::Converter converter(context); - Try - { - EventAlarmPrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(WrtDeviceApis::Commons::NullPointerException); - } - EventAlarmPtr alarm = priv->getObject(); - - if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_ABSOLUTE_DATE)) { - if (!alarm) { - Throw(WrtDeviceApis::Commons::NullPointerException); - } - if (alarm->getAbsoluteDate() != 0) { - // Use the global context saved in the event struct. - return JSTZDate::createJSObject(priv->getContext(), alarm->getAbsoluteDate(), alarm->getTimeZone()); - } else { - return JSValueMakeUndefined(context); - } - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_BEFORE)) { - return JSTimeDuration::createJSObject(priv->getContext(), alarm->getDuration()); - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_METHODS)) { - std::vector result; - std::vector methods = alarm->getMethods(); - for(std::vector::iterator i = methods.begin(); i != methods.end(); i++) - result.push_back(converter.toJSValueRef(*i)); - return converter.toJSValueRef(result); - } - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogError("invalid property"); - } - return JSValueMakeUndefined(context); -} - -bool JSEventAlarm::setProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - LogDebug("entered"); - CalendarConverter converter(context); - Try - { - EventAlarmPrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(WrtDeviceApis::Commons::NullPointerException); - } - EventAlarmPtr alarm = priv->getObject(); - - if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_ABSOLUTE_DATE)) { - if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) { - Throw(InvalidArgumentException); - } - TimeUtilConverter timeConverter(context); - std::time_t absoluteDate = timeConverter.toTZDateTimeT(value); - 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())) { - Throw(InvalidArgumentException); - } - TimeUtilConverter timeConverter(context); - alarm->setDuration(timeConverter.getDurationPropertis(value)); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_CALENDAR_ALARM_METHODS)) { - std::vector methods = converter.toVectorOfStrings(value); - std::vector convertedMethods; - for (unsigned int i=0; isetMethods(convertedMethods); - return true; - } - } - Catch(WrtDeviceApis::Commons::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/Calendar/JSEventAlarm.h b/src/standards/Tizen/Calendar/JSEventAlarm.h deleted file mode 100755 index 8ec3078..0000000 --- a/src/standards/Tizen/Calendar/JSEventAlarm.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_EVENT_ALARM_H_ -#define _JS_EVENT_ALARM_H_ - -#include -#include -#include - -using namespace TizenApis::Api::Calendar; - -namespace TizenApis { -namespace Tizen1_0 { -namespace Calendar { - -#define TIZEN_CALENDAR_ALARM_ABSOLUTE_DATE "absoluteDate" -#define TIZEN_CALENDAR_ALARM_BEFORE "before" -#define TIZEN_CALENDAR_ALARM_METHODS "methods" - -typedef WrtDeviceApis::CommonsJavaScript::PrivateObject EventAlarmPrivateObject; - -class JSEventAlarm -{ - public: - - static const JSClassDefinition* getClassInfo(); - - static JSClassRef getClassRef(); - - static JSObjectRef createJSObject(JSContextRef context, EventAlarmPtr alarm); - - static EventAlarmPtr getAlarm(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 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_EVENT_ALARM_H_ */ diff --git a/src/standards/Tizen/Calendar/JSEventId.cpp b/src/standards/Tizen/Calendar/JSEventId.cpp deleted file mode 100755 index c35e8e6..0000000 --- a/src/standards/Tizen/Calendar/JSEventId.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include "JSEventId.h" -#include -#include -#include -#include -#include -#include - -using namespace TizenApis::Api::Calendar; -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; - -namespace TizenApis { -namespace Tizen1_0 { -namespace Calendar { - -#define TIZEN_EVENTID_ATTRIBUTENAME "EventId" - -JSClassDefinition JSEventId::m_classInfo = { - 0, - kJSClassAttributeNone, - TIZEN_EVENTID_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 JSEventId::m_property[] = { - { TIZEN_EVENTID_UID, getProperty, setProperty, kJSPropertyAttributeNone }, - { TIZEN_EVENTID_RECURRENCEID, getProperty, setProperty, kJSPropertyAttributeNone }, - { 0, 0, 0, 0 } -}; - -JSClassRef JSEventId::m_jsClassRef = JSClassCreate( - JSEventId::getClassInfo()); - -const JSClassDefinition* JSEventId::getClassInfo() -{ - return &(m_classInfo); -} - -JSClassRef JSEventId::getClassRef() -{ - if (!m_jsClassRef) { - m_jsClassRef = JSClassCreate(&m_classInfo); - } - return m_jsClassRef; -} - -EventIdPtr JSEventId::getEventId(JSObjectRef object) -{ - LogDebug("entered"); - EventIdPrivateObject *priv = - static_cast(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 JSEventId::initialize(JSContextRef context, - JSObjectRef object) -{ - LogDebug("enter"); -} - -void JSEventId::finalize(JSObjectRef object) -{ - LogDebug("enter"); - EventIdPrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - delete priv; - JSObjectSetPrivate(object, NULL); -} - -JSValueRef JSEventId::getProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - LogDebug("enter"); - Converter converter(context); - Try - { - EventIdPrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(NullPointerException); - } - EventIdPtr eventId = priv->getObject(); - - if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_EVENTID_UID)) { - return converter.toJSValueRef(eventId->getUId()); - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_EVENTID_RECURRENCEID)) { - if (!eventId) { - Throw(NullPointerException); - } - if (eventId->getRecurrenceId() != 0) { - // Use the global context saved in the event struct. - return JSTZDate::createJSObject(priv->getContext(), eventId->getRecurrenceId(), eventId->getTimeZone()); - } else { - return JSValueMakeUndefined(context); - } - } - } - Catch(Exception) - { - LogError("invalid property"); - } - return JSValueMakeUndefined(context); -} - -bool JSEventId::setProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - LogDebug("entered"); - Converter converter(context); - Try - { - EventIdPrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(NullPointerException); - } - EventIdPtr eventId = priv->getObject(); - - if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_EVENTID_UID)) { - if (!JSValueIsString(context, value)) { - Throw(InvalidArgumentException); - } - std::string uid = converter.toString(value); - eventId->setUId(uid); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_EVENTID_RECURRENCEID)) { - if (!JSValueIsObjectOfClass(context, value, JSTZDate::getClassRef())) { - Throw(InvalidArgumentException); - } - TimeUtilConverter timeConverter(context); - std::time_t recurrenceId = timeConverter.toTZDateTimeT(value); - eventId->setRecurrenceId(recurrenceId); - - if( eventId->getTimeZone().empty() ) { - std::string timeZone = timeConverter.getPropertiesInTZDate(value).timezone; - eventId->setTimeZone(timeZone); - } - 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/Calendar/JSEventId.h b/src/standards/Tizen/Calendar/JSEventId.h deleted file mode 100755 index 1dd6faf..0000000 --- a/src/standards/Tizen/Calendar/JSEventId.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_EVENT_ID_H_ -#define _JS_EVENT_ID_H_ - -#include -#include -#include - -namespace TizenApis { -namespace Tizen1_0 { -namespace Calendar { - -#define TIZEN_EVENTID_UID "uid" -#define TIZEN_EVENTID_RECURRENCEID "recurrenceId" - -typedef WrtDeviceApis::CommonsJavaScript::PrivateObject EventIdPrivateObject; - -class JSEventId -{ - public: - - static const JSClassDefinition* getClassInfo(); - - static JSClassRef getClassRef(); - - static TizenApis::Api::Calendar::EventIdPtr getEventId(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 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_EVENT_ID_H_ */ diff --git a/src/standards/Tizen/Calendar/JSRecurrenceRule.cpp b/src/standards/Tizen/Calendar/JSRecurrenceRule.cpp deleted file mode 100755 index 91315b9..0000000 --- a/src/standards/Tizen/Calendar/JSRecurrenceRule.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include "JSRecurrenceRule.h" -#include -#include -#include -#include -#include "CalendarConverter.h" -#include -#include - -using namespace TizenApis::Api::Calendar; -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; - -namespace TizenApis { -namespace Tizen1_0 { -namespace Calendar { - -#define TIZEN_RECURRENCE_RULE_ATTRIBUTENAME "RecurrenceRule" - -JSClassDefinition JSRecurrenceRule::m_classInfo = { - 0, - kJSClassAttributeNone, - TIZEN_RECURRENCE_RULE_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 JSRecurrenceRule::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_POSITION, getProperty, setProperty, kJSPropertyAttributeNone }, - { TIZEN_RECURRENCE_RULE_EXCEPTIONS, getProperty, setProperty, kJSPropertyAttributeNone }, - - { 0, 0, 0, 0 } -}; - -JSClassRef JSRecurrenceRule::m_jsClassRef = JSClassCreate( - JSRecurrenceRule::getClassInfo()); - -const JSClassDefinition* JSRecurrenceRule::getClassInfo() -{ - return &(m_classInfo); -} - -JSClassRef JSRecurrenceRule::getClassRef() -{ - if (!m_jsClassRef) { - m_jsClassRef = JSClassCreate(&m_classInfo); - } - return m_jsClassRef; -} - -JSObjectRef JSRecurrenceRule::createJSRecurrenceRule(JSContextRef context, EventRecurrenceRulePtr rule) -{ - RecurrenceRulePrivateObject *priv = new RecurrenceRulePrivateObject(context, rule); - return JSObjectMake(context, getClassRef(), priv); -} - -void JSRecurrenceRule::initialize(JSContextRef context, JSObjectRef object) -{ - LogDebug("enter"); -} - -void JSRecurrenceRule::finalize(JSObjectRef object) -{ - LogDebug("enter"); - RecurrenceRulePrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - delete priv; - JSObjectSetPrivate(object, NULL); -} - -JSValueRef JSRecurrenceRule::getProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - LogDebug("enter"); - CalendarConverterFactory::ConverterType converter = - CalendarConverterFactory::getConverter(context); - Try - { - RecurrenceRulePrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(NullPointerException); - } - EventRecurrenceRulePtr rrule = priv->getObject(); - - 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 (!rrule) { - Throw(NullPointerException); - } - if (rrule->getEndDate() != 0) { - // Use the global context saved in the event struct. - return JSTZDate::createJSObject(priv->getContext(), rrule->getEndDate(), rrule->getTimeZone()); - } else { - return JSValueMakeUndefined(context); - } - } 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_POSITION)) { - return converter->toJSValueRef(rrule->getSetPosition()); - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_EXCEPTIONS)) { - JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL); - if (NULL == jsResult) { - LogError("Could not create js array object."); - ThrowMsg(NullPointerException, "Could not create js array object"); - } - - for (std::size_t i = 0; i < rrule->getExceptions().size(); ++i) { - JSValueRef tmpVal = JSTZDate::createJSObject(priv->getContext(), rrule->getExceptions().at(i), rrule->getTimeZone()); - if (!JSSetArrayElement(context, jsResult, i, tmpVal)) { - LogError("Could not insert value into js array."); - ThrowMsg(UnknownException, "Could not insert value into js array"); - } - } - - return jsResult; - } - } - Catch(Exception) - { - LogError("invalid property"); - } - return JSValueMakeUndefined(context); -} - -bool JSRecurrenceRule::setProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - LogDebug("entered"); - CalendarConverterFactory::ConverterType converter = - CalendarConverterFactory::getConverter(context); - Try - { - RecurrenceRulePrivateObject* priv = - static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(NullPointerException); - } - EventRecurrenceRulePtr rrule = priv->getObject(); - - if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_FREQUENCY)) { - if (!JSValueIsString(context, value)) { - Throw(InvalidArgumentException); - } - std::string frequency = converter->toString(value); - rrule->setFrequency(converter->toRecurrenceFrequency(frequency)); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_INTERVAL)) { - if (!JSValueIsNumber(context, value)) { - Throw(InvalidArgumentException); - } - 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())) { - Throw(InvalidArgumentException); - } - TimeUtilConverter timeConverter(context); - std::time_t untilDate = timeConverter.toTZDateTimeT(value); - 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)) { - if (!JSValueIsNumber(context, value)) { - Throw(InvalidArgumentException); - } - long occurrenceCount = converter->toLong(value); - rrule->setOccurrenceCount(occurrenceCount); - return true; - /*} else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_DAYS_OF_THE_MONTH)) { - std::vector daysOfTheMonth = converter->toVectorOfInts(value); - rrule->setDaysOfTheMonth(daysOfTheMonth); - return true;*/ - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_DAYS_OF_THE_WEEK)) { - std::vector daysOfTheWeek = converter->toVectorOfStrings(value); - rrule->setDaysOfTheWeek(daysOfTheWeek); - return true; - /*} else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_DAYS_OF_THE_YEAR)) { - std::vector daysOfTheYear = converter->toVectorOfInts(value); - rrule->setDaysOfTheYear(daysOfTheYear); - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_WEEKS_OF_THE_YEAR)) { - std::vector weekOfTheYear = converter->toVectorOfInts(value); - rrule->setWeeksOfTheYear(weekOfTheYear); - return true;*/ - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_SET_POSITION)) { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::NOT_SUPPORTED_ERROR); - /* - bool setPosition = converter->toBool(value); - rrule->setSetPosition(setPosition);*/ - return true; - } else if (JSStringIsEqualToUTF8CString(propertyName, TIZEN_RECURRENCE_RULE_EXCEPTIONS)) { - // Only save the converted time info. - rrule->setExceptions(converter->toVectorOfTimeTFromTZDate(value)); - 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/Calendar/JSRecurrenceRule.h b/src/standards/Tizen/Calendar/JSRecurrenceRule.h deleted file mode 100755 index df22093..0000000 --- a/src/standards/Tizen/Calendar/JSRecurrenceRule.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_RECURRENCE_RULE_H_ -#define _JS_RECURRENCE_RULE_H_ - -#include -#include -#include -#include -#include -#include - -using namespace TizenApis::Api::Calendar; -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; - -namespace TizenApis { -namespace Tizen1_0 { -namespace Calendar { - -#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_POSITION "setPositions" -#define TIZEN_RECURRENCE_RULE_EXCEPTIONS "exceptions" - -typedef PrivateObject RecurrenceRulePrivateObject; - -class JSRecurrenceRule -{ - public: - - static const JSClassDefinition* getClassInfo(); - - static JSClassRef getClassRef(); - - static JSObjectRef createJSRecurrenceRule(JSContextRef context, Api::Calendar::EventRecurrenceRulePtr rule); - - 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 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_RECURRENCE_RULE_H_ */ diff --git a/src/standards/Tizen/Call/CMakeLists.txt b/src/standards/Tizen/Call/CMakeLists.txt index 89d1000..85837c1 100755 --- a/src/standards/Tizen/Call/CMakeLists.txt +++ b/src/standards/Tizen/Call/CMakeLists.txt @@ -2,10 +2,15 @@ set(TARGET_NAME "wrt-plugins-tizen-1.0-call") include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_CALL}) +set(CMAKE_INSTALL_RPATH + ${CMAKE_INSTALL_RPATH} + ${CMAKE_INSTALL_PREFIX}/tizen-1.0-tizen + #${CMAKE_INSTALL_PREFIX}/tizen-1.0-account +) + set(SRCS ${SRCS_PLATFORM_API_CALL} ${SRCS_PLATFORM_IMPLEMENTATION_CALL} - ${SRCS_PLATFORM_API_FILTER} CallMultiCallback.cpp CallStaticController.cpp Converter.cpp @@ -18,6 +23,8 @@ set(SRCS plugin_config.cpp plugin_initializer.cpp ResponseDispatcher.cpp + + # To be removed after account module activated ${SRCS_PLATFORM_API_ACCOUNT} ${SRCS_PLATFORM_IMPLEMENTATION_ACCOUNT} ../Account/JSAccount.cpp @@ -29,20 +36,12 @@ set(SRCS ../Account/AccountConverter.cpp ../Account/plugin_config.cpp ../Account/ResponseDispatcher.cpp - ../Tizen/FilterConverter.cpp - ../Tizen/JSAttributeFilter.cpp - ../Tizen/JSAttributeRangeFilter.cpp - ../Tizen/JSCompositeFilter.cpp - ../Tizen/JSAbstractFilterArray.cpp - ../Tizen/JSSortMode.cpp - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp - ../Common/JSGlobalContextFactory.cpp ) add_library(${TARGET_NAME} SHARED ${SRCS}) target_link_libraries(${TARGET_NAME} + wrt-plugins-tizen-1.0-tizen-impl + #wrt-plugins-tizen-1.0-account-impl ${LIBS_COMMON} ${LIBS_PLATFORM_IMPLEMENTATION_CALL} ) diff --git a/src/standards/Tizen/Call/JSCallApi.cpp b/src/standards/Tizen/Call/JSCallApi.cpp deleted file mode 100755 index 2fc4dff..0000000 --- a/src/standards/Tizen/Call/JSCallApi.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include - -#include -#include -#include -#include -#include - -#include "JSCallApi.h" -#include "JSCallHistory.h" -#include "Converter.h" - -using namespace std; -using namespace DPL; -using namespace WrtDeviceApis; -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; - -namespace TizenApis { -namespace Tizen1_0 { - -JSClassRef JSCallApi::m_jsClassRef = NULL; - -JSClassDefinition JSCallApi::m_classInfo = -{ - 0, - kJSClassAttributeNone, - "call", - NULL, - m_property, - NULL, - initialize, - finalize, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - hasInstance, - NULL -}; - -JSStaticValue JSCallApi::m_property[] = { - { "history", getProperty, NULL, kJSPropertyAttributeReadOnly }, - { 0, 0, 0, 0 } -}; - -const JSClassRef JSCallApi::getClassRef() { - if (!m_jsClassRef) { - m_jsClassRef = JSClassCreate(&m_classInfo); - } - return m_jsClassRef; -} - -const JSClassDefinition* JSCallApi::getClassInfo(){ - return &m_classInfo; -} - -void JSCallApi::initialize(JSContextRef context, JSObjectRef object) { - JSCallApiPriv *priv = static_cast(JSObjectGetPrivate(object)); - - if (priv == NULL) { - priv = new JSCallApiPriv(context); - - if(!JSObjectSetPrivate(object, static_cast(priv))) { - LogError("Object can't store private data."); - delete priv; - } - } -} - -void JSCallApi::finalize(JSObjectRef object) { - JSCallApiPriv* priv = static_cast(JSObjectGetPrivate(object)); - - if (priv != NULL) { - JSObjectSetPrivate(object, NULL); - delete priv; - } -} - -JSValueRef JSCallApi::getProperty(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - JSCallApiPriv *priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - return JSValueMakeUndefined(context); - } - - JSContextRef globalContext = priv->getContext(); - - try { - Converter convert(context); - if(JSStringIsEqualToUTF8CString(propertyName, "history")) { - return TizenApis::Tizen1_0::JSCallHistory::createJSObject(globalContext, object); - } - } catch(Commons::Exception) { - LogWarning("trying to get incorrect value"); - } - return JSValueMakeUndefined(context); -} - -bool JSCallApi::hasInstance(JSContextRef context, JSObjectRef constructor, - JSValueRef possibleInstance, JSValueRef* exception) { - return JSValueIsObjectOfClass(context, possibleInstance, getClassRef()); -} - -} -} - diff --git a/src/standards/Tizen/Call/JSCallApi.h b/src/standards/Tizen/Call/JSCallApi.h deleted file mode 100755 index c5c1c75..0000000 --- a/src/standards/Tizen/Call/JSCallApi.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES 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_CALLAPI_H_ -#define TIZEN_APIS_JS_CALLAPI_H_ - -#include -#include - -namespace TizenApis { -namespace Tizen1_0 { - -typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT::Type JSCallApiPriv; - -class JSCallApi -{ -public: - static const JSClassDefinition* getClassInfo(); - - static const JSClassRef getClassRef(); - -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/Common/CMakeLists.txt b/src/standards/Tizen/Common/CMakeLists.txt new file mode 100755 index 0000000..849ea56 --- /dev/null +++ b/src/standards/Tizen/Common/CMakeLists.txt @@ -0,0 +1,16 @@ +set(SRCS + JSTizenException.cpp + TizenExceptionData.cpp + JSTizenExceptionFactory.cpp + JSGlobalContextFactory.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/Contact/AddressBookController.cpp b/src/standards/Tizen/Contact/AddressBookController.cpp index 7d1a963..78f757f 100755 --- a/src/standards/Tizen/Contact/AddressBookController.cpp +++ b/src/standards/Tizen/Contact/AddressBookController.cpp @@ -37,7 +37,7 @@ using namespace TizenApis::Api::Contact; using namespace WrtDeviceApis::Commons; using namespace WrtDeviceApis::CommonsJavaScript; -AddressBookController::AddressBookController(JSContextRef context, IAddressBookPtr addressBook) : +AddressBookController::AddressBookController(JSContextRef context, AddressBookPtr addressBook) : EventAddressBookAddBatchEventAnswerReceiver(ThreadEnum::NULL_THREAD), EventAddressBookUpdateBatchEventAnswerReceiver(ThreadEnum::NULL_THREAD), EventAddressBookRemoveBatchEventAnswerReceiver(ThreadEnum::NULL_THREAD), @@ -56,6 +56,7 @@ AddressBookController::~AddressBookController() void AddressBookAsyncAnswerHandler::addBatch(const EventAddressBookAddBatchPtr &event) { + LogDebug("entered"); JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast(event->getPrivateData()); if (!callbackManager) { @@ -110,6 +111,7 @@ void AddressBookAsyncAnswerHandler::addBatch(const EventAddressBookAddBatchPtr & void AddressBookAsyncAnswerHandler::updateBatch(const EventAddressBookUpdateBatchPtr &event) { + LogDebug("entered"); JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast(event->getPrivateData()); if (!callbackManager) { @@ -150,6 +152,7 @@ void AddressBookAsyncAnswerHandler::updateBatch(const EventAddressBookUpdateBatc void AddressBookAsyncAnswerHandler::removeBatch(const EventAddressBookRemoveBatchPtr &event) { + LogDebug("entered"); JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast(event->getPrivateData()); if (!callbackManager) { @@ -189,6 +192,7 @@ void AddressBookAsyncAnswerHandler::removeBatch(const EventAddressBookRemoveBatc void AddressBookAsyncAnswerHandler::find(const EventAddressBookFindPtr &event) { + LogDebug("entered"); JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast(event->getPrivateData()); if (!callbackManager) @@ -244,6 +248,7 @@ void AddressBookAsyncAnswerHandler::find(const EventAddressBookFindPtr &event) void AddressBookAsyncAnswerHandler::changeListenerError(const EventAddressBookChangeListenerPtr &event) { + LogDebug("entered"); JSValueRef errorObject; JSCallbackManagerPtr cbm = DPL::StaticPointerCast(event->getPrivateData()); @@ -265,6 +270,7 @@ void AddressBookAsyncAnswerHandler::changeListenerError(const EventAddressBookCh void AddressBookAsyncAnswerHandler::changeListenerContactAdded(const EventAddressBookChangeListenerPtr &event) { + LogDebug("entered"); JSAddressBookChangeCallbackManagerPtr cbm = DPL::StaticPointerCast(event->getPrivateData()); if (!cbm) @@ -304,6 +310,7 @@ void AddressBookAsyncAnswerHandler::changeListenerContactAdded(const EventAddres void AddressBookAsyncAnswerHandler::changeListenerContactUpdated(const EventAddressBookChangeListenerPtr &event) { + LogDebug("entered"); JSAddressBookChangeCallbackManagerPtr cbm = DPL::StaticPointerCast(event->getPrivateData()); if (!cbm) @@ -343,6 +350,7 @@ void AddressBookAsyncAnswerHandler::changeListenerContactUpdated(const EventAddr void AddressBookAsyncAnswerHandler::changeListenerContactRemoved(const EventAddressBookChangeListenerPtr &event) { + LogDebug("entered"); JSAddressBookChangeCallbackManagerPtr cbm = DPL::StaticPointerCast(event->getPrivateData()); if (!cbm) @@ -381,6 +389,7 @@ void AddressBookAsyncAnswerHandler::changeListenerContactRemoved(const EventAddr void AddressBookAsyncAnswerHandler::changeListenerAddressBookReset(const EventAddressBookChangeListenerPtr &event) { + LogDebug("entered"); JSAddressBookChangeCallbackManagerPtr cbm = DPL::StaticPointerCast(event->getPrivateData()); if (!cbm) diff --git a/src/standards/Tizen/Contact/AddressBookController.h b/src/standards/Tizen/Contact/AddressBookController.h index 8419b8b..bb08382 100755 --- a/src/standards/Tizen/Contact/AddressBookController.h +++ b/src/standards/Tizen/Contact/AddressBookController.h @@ -37,7 +37,7 @@ namespace TizenApis { namespace Tizen1_0 { namespace Contact { -typedef WrtDeviceApis::CommonsJavaScript::PrivateObject AddressBookPrivObject; typedef WrtDeviceApis::Commons::EventAnswerReceiver EventAddressBookAddBatchEventAnswerReceiver; @@ -56,7 +56,7 @@ class AddressBookController : { public: AddressBookController(JSContextRef context, - TizenApis::Api::Contact::IAddressBookPtr addressBook); + TizenApis::Api::Contact::AddressBookPtr addressBook); virtual ~AddressBookController(); protected: void OnAnswerReceived(const TizenApis::Api::Contact::EventAddressBookAddBatchPtr &event); diff --git a/src/standards/Tizen/Contact/CMakeLists.txt b/src/standards/Tizen/Contact/CMakeLists.txt index 51ae014..65a9403 100755 --- a/src/standards/Tizen/Contact/CMakeLists.txt +++ b/src/standards/Tizen/Contact/CMakeLists.txt @@ -1,23 +1,34 @@ set(TARGET_NAME "wrt-plugins-tizen-1.0-contact") -set(DESTINATION_NAME "tizen-1.0-contact") -set(SRCS +set(DESTINATION_NAME "tizen-1.0-contact") +set(TARGET_IMPL_NAME "wrt-plugins-tizen-1.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-1.0-tizen +) + +set(SRCS_IMPL ${SRCS_PLATFORM_API_CONTACT} - ${SRCS_PLATFORM_API_FILTER} ${SRCS_PLATFORM_IMPLEMENTATION_CONTACT} AddressBookController.cpp ContactConverter.cpp ContactManagerController.cpp JSContact.cpp JSContactArray.cpp - JSContactProperties.cpp JSAddressBook.cpp JSAddressBookChangeCallbackManager.cpp JSAddressBookArray.cpp + JSContactRef.cpp JSContactName.cpp JSContactAccount.cpp JSContactAnniversary.cpp JSContactAnniversaryArray.cpp - JSAttributesOfInterestArray.cpp + #JSAttributesOfInterestArray.cpp JSContactAddress.cpp JSContactAddressArray.cpp JSContactAddressTypeArray.cpp @@ -33,29 +44,24 @@ set(SRCS JSStringArray.cpp JSContactWebSite.cpp JSContactWebSiteArray.cpp - plugin_initializer.cpp plugin_config.cpp - ../Tizen/JSAttributeFilter.cpp - ../Tizen/JSAttributeRangeFilter.cpp - ../Tizen/JSCompositeFilter.cpp - ../Tizen/JSAbstractFilterArray.cpp - ../Tizen/JSSortMode.cpp - ../Tizen/FilterConverter.cpp - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp - ../Common/JSGlobalContextFactory.cpp ) -include_directories( - ${INCLUDES_PLATFORM_IMPLEMENTATION_CONTACT} +add_library(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL}) +target_link_libraries(${TARGET_IMPL_NAME} + wrt-plugins-tizen-1.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} - ${LIBS_PLATFORM_IMPLEMENTATION_CONTACT} - ${LIBS_COMMON} + ${TARGET_IMPL_NAME} ) -INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_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/ContactConverter.cpp b/src/standards/Tizen/Contact/ContactConverter.cpp index 722ae55..259d4b8 100755 --- a/src/standards/Tizen/Contact/ContactConverter.cpp +++ b/src/standards/Tizen/Contact/ContactConverter.cpp @@ -21,20 +21,22 @@ * @brief */ +#include #include #include #include #include #include +#include #include "ContactConverter.h" #include "AddressBookController.h" #include "JSAddressBook.h" #include "JSAddressBookArray.h" -#include "JSAttributesOfInterestArray.h" +//#include "JSAttributesOfInterestArray.h" #include "JSContact.h" +#include "JSContactRef.h" #include "JSContactArray.h" -#include "JSContactProperties.h" #include "JSContactName.h" #include "JSContactAccount.h" #include "JSContactAnniversary.h" @@ -56,11 +58,11 @@ #include "JSStringArray.h" #define CONTACT_ATTRIBUTE_ACCOUNT "account" -#define CONTACT_ATTRIBUTE_ACCOUNT_ID "accountId" +#define CONTACT_ATTRIBUTE_ACCOUNT_SERVICE_ID "accountServiceId" #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_ATTRIBUTES_OF_INTEREST "attributesOfInterest" #define CONTACT_ATTRIBUTE_BIRTHDAY "birthday" #define CONTACT_ATTRIBUTE_CATEGORIES "categories" #define CONTACT_ATTRIBUTE_CITY "city" @@ -138,274 +140,29 @@ using namespace TizenApis::Api::Contact; using namespace WrtDeviceApis::Commons; using namespace WrtDeviceApis::CommonsJavaScript; -std::vector ContactConverter::m_allowedAddressBookProperties; -std::vector ContactConverter::m_allowedContactProperties; -std::vector ContactConverter::m_allowedContactPropertiesProperties; -std::vector ContactConverter::m_allowedContactNameProperties; -std::vector ContactConverter::m_allowedContactAccountProperties; -std::vector ContactConverter::m_allowedContactOrganizationProperties; -std::vector ContactConverter::m_allowedContactWebSiteProperties; -std::vector ContactConverter::m_allowedContactAnniversaryProperties; -std::vector ContactConverter::m_allowedContactAddressProperties; -std::vector ContactConverter::m_allowedContactPhoneNumberProperties; -std::vector ContactConverter::m_allowedContactEmailAddressProperties; +std::vector ContactConverter::m_allowedContactInit; +std::vector ContactConverter::m_allowedContactNameInit; +std::vector ContactConverter::m_allowedContactOrganizationInit; +std::vector ContactConverter::m_allowedContactAddressInit; ContactConverter::ContactConverter(JSContextRef context) : Converter(context) { -// //LogDebug("entered"); - static bool init = initializeAllowedProperties(); - (void) init; + static bool init = initializeAllowedProperties(); + (void) init; } ContactConverter::~ContactConverter() { -// //LogDebug("entered"); } -StringArrayPtr ContactConverter::toStringArray(const JSValueRef &jsValue) -{ - if(JSStringArray::isObjectOfClass(m_context, jsValue)) - return JSStringArray::getStringArray(m_context, jsValue); - - 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); -} - -// types converters -ContactEmailAddressType ContactConverter::toContactEmailAddressType(const std::string &arg) -{ -// //LogDebug("entered"); - if (arg == STR_CONTACT_EMAIL_TYPE_WORK) { - return CONTACT_EMAIL_TYPE_WORK; - } else if (arg == STR_CONTACT_EMAIL_TYPE_PREF) { - return CONTACT_EMAIL_TYPE_PREF; - } else if (arg == STR_CONTACT_EMAIL_TYPE_HOME) { - return CONTACT_EMAIL_TYPE_HOME; - } else { - Throw(WrtDeviceApis::Commons::ConversionException); - } - return CONTACT_EMAIL_TYPE_PREF; -} - -std::string ContactConverter::toContactEmailAddressTypeStr(ContactEmailAddressType arg) -{ -// //LogDebug("entered"); - 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; - } else { - Throw(WrtDeviceApis::Commons::ConversionException); - } - return STR_CONTACT_EMAIL_TYPE_PREF; -} - -ContactEmailAddressType ContactConverter::toContactEmailAddressType(const JSValueRef &value) -{ - return toContactEmailAddressType(toString(value)); -} - -JSValueRef ContactConverter::toJSValueRef(ContactEmailAddressType arg) -{ - return toJSValueRef(toContactEmailAddressTypeStr(arg)); -} - -ContactPhoneNumberType ContactConverter::toContactPhoneNumberType(const std::string &arg) -{ -// //LogDebug("entered"); - if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_WORK) { - return CONTACT_PHONE_NUMBER_TYPE_WORK; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_PREF) { - return CONTACT_PHONE_NUMBER_TYPE_PREF; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_HOME) { - return CONTACT_PHONE_NUMBER_TYPE_HOME; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_VOICE) { - return CONTACT_PHONE_NUMBER_TYPE_VOICE; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_FAX) { - return CONTACT_PHONE_NUMBER_TYPE_FAX; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_MSG) { - return CONTACT_PHONE_NUMBER_TYPE_MSG; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_CELL) { - return CONTACT_PHONE_NUMBER_TYPE_CELL; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_PAGER) { - return CONTACT_PHONE_NUMBER_TYPE_PAGER; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_BBS) { - return CONTACT_PHONE_NUMBER_TYPE_BBS; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_MODEM) { - return CONTACT_PHONE_NUMBER_TYPE_MODEM; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_CAR) { - return CONTACT_PHONE_NUMBER_TYPE_CAR; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_ISDN) { - return CONTACT_PHONE_NUMBER_TYPE_ISDN; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_VIDEO) { - return CONTACT_PHONE_NUMBER_TYPE_VIDEO; - } else if (arg == STR_CONTACT_PHONE_NUMBER_TYPE_PCS) { - return CONTACT_PHONE_NUMBER_TYPE_PCS; - } else { - Throw(WrtDeviceApis::Commons::ConversionException); - } - return CONTACT_PHONE_NUMBER_TYPE_WORK; -} - -std::string ContactConverter::toContactPhoneNumberTypeStr(ContactPhoneNumberType arg) -{ -// //LogDebug("entered"); - 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; - } else { - Throw(WrtDeviceApis::Commons::ConversionException); - } - return STR_CONTACT_PHONE_NUMBER_TYPE_WORK; -} - -ContactPhoneNumberType ContactConverter::toContactPhoneNumberType(const JSValueRef &value) -{ - return toContactPhoneNumberType(toString(value)); -} - -JSValueRef ContactConverter::toJSValueRef(ContactPhoneNumberType arg) -{ - return toJSValueRef(toContactPhoneNumberTypeStr(arg)); -} - -ContactAddressType ContactConverter::toContactAddressType(const std::string &arg) -{ -// //LogDebug("entered"); - if (arg == STR_CONTACT_ADDRESS_TYPE_WORK) { - return CONTACT_ADDRESS_TYPE_WORK; - } else if (arg == STR_CONTACT_ADDRESS_TYPE_PREF) { - return CONTACT_ADDRESS_TYPE_PREF; - } else if (arg == STR_CONTACT_ADDRESS_TYPE_HOME) { - return CONTACT_ADDRESS_TYPE_HOME; - } else { - Throw(WrtDeviceApis::Commons::ConversionException); - } - return CONTACT_ADDRESS_TYPE_PREF; -} -std::string ContactConverter::toContactAddressTypeStr(ContactAddressType arg) +JSValueRef ContactConverter::toJSValueRef(const AddressBookPtr &arg) { -// //LogDebug("entered"); - 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; - } else { - Throw(WrtDeviceApis::Commons::ConversionException); - } - return STR_CONTACT_ADDRESS_TYPE_PREF; -} - -ContactAddressType ContactConverter::toContactAddressType(const JSValueRef &value) -{ - return toContactAddressType(toString(value)); -} - -JSValueRef ContactConverter::toJSValueRef(ContactAddressType arg) -{ - return toJSValueRef(toContactAddressTypeStr(arg)); -} - -ContactWebSiteType ContactConverter::toContactWebSiteType(const std::string &arg) -{ - //LogDebug("entered"); - if (arg == STR_WEBSITE_TYPE_HOMEPAGE) { - return WEBSITE_TYPE_HOMEPAGE; - } else if (arg == STR_WEBSITE_TYPE_BLOG) { - return WEBSITE_TYPE_BLOG; - } else { - Throw(WrtDeviceApis::Commons::ConversionException); - } - return WEBSITE_TYPE_HOMEPAGE; -} - -std::string ContactConverter::toContactWebSiteTypeStr(ContactWebSiteType arg) -{ - //LogDebug("entered"); - if (arg == WEBSITE_TYPE_HOMEPAGE) { - return STR_WEBSITE_TYPE_HOMEPAGE; - } else if (arg == WEBSITE_TYPE_BLOG) { - return STR_WEBSITE_TYPE_BLOG; - } else { - Throw(WrtDeviceApis::Commons::ConversionException); - } - return STR_WEBSITE_TYPE_HOMEPAGE; -} - -ContactWebSiteType ContactConverter::toContactWebSiteType(const JSValueRef &value) -{ - return toContactWebSiteType(toString(value)); -} - -JSValueRef ContactConverter::toJSValueRef(ContactWebSiteType arg) -{ - return toJSValueRef(toContactWebSiteTypeStr(arg)); -} - -ContactCapabilityType ContactConverter::toContactCapabilityType(const JSValueRef &value) -{ - int result = toInt(value); - if(HAS_VIDEO_CAPABILITY != result && - HAS_VOICE_CAPABILITY != result && - HAS_CAMERA_CAPABILITY != result) - Throw(WrtDeviceApis::Commons::ConversionException); - - return static_cast(result); -} - -std::string ContactConverter::toAttributesOfInterest(const JSValueRef &value) -{ - // TODO validate - return toString(value); -} - -JSValueRef ContactConverter::toJSValueRef(const IAddressBookPtr &arg) -{ - //LogDebug("entered"); + // It may not used AddressBookController *priv = new AddressBookController(m_context, arg); return JSObjectMake(m_context, JSAddressBook::getClassRef(), priv); } -IAddressBookPtr ContactConverter::toAddressBook(const JSValueRef &jsValue) +AddressBookPtr ContactConverter::toAddressBook(const JSValueRef &jsValue) { if(!JSAddressBook::isObjectOfClass(m_context, jsValue)) ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); @@ -413,11 +170,10 @@ IAddressBookPtr ContactConverter::toAddressBook(const JSValueRef &jsValue) return JSAddressBook::getAddressBook(m_context, jsValue); } -JSValueRef ContactConverter::toJSValueRef(const IAddressBookArrayPtr &arg) +JSValueRef ContactConverter::toJSValueRef(const AddressBookArrayPtr &arg) { + // TODO Check it is right? not a platform object right? int size = arg->size(); - if(size == 0) - return JSValueMakeNull(m_context); JSObjectRef resultObject = JSCreateArrayObject(m_context, 0, NULL); if (!resultObject) @@ -433,12 +189,15 @@ JSValueRef ContactConverter::toJSValueRef(const IAddressBookArrayPtr &arg) return static_cast(resultObject); } -IAddressBookArrayPtr ContactConverter::toAddressBookArray(const JSValueRef &jsValue) +AddressBookArrayPtr ContactConverter::toAddressBookArray(const JSValueRef &jsValue) { if(JSAddressBookArray::isObjectOfClass(m_context, jsValue)) return JSAddressBookArray::getAddressBookArray(m_context, jsValue); - IAddressBookArrayPtr result(new IAddressBookArray()); + 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) { @@ -450,53 +209,36 @@ IAddressBookArrayPtr ContactConverter::toAddressBookArray(const JSValueRef &jsVa JSValueRef ContactConverter::toJSValueRef(const ContactPtr &arg) { - //LogDebug("entered"); 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); } -JSValueRef ContactConverter::toJSValueRef(const ContactArrayPtr &arg) -{ - //LogDebug("entered"); - return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactArray::getClassRef(), arg); -} - -ContactArrayPtr ContactConverter::toContactArray(const JSValueRef &jsValue) -{ - if(JSContactArray::isObjectOfClass(m_context, jsValue)) - return JSContactArray::getContactArray(m_context, jsValue); - - 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 ContactPropertiesPtr &arg) +ContactPtr ContactConverter::toContactFromInit(const JSValueRef &jsValue) { - // TODO make user object - return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactProperties::getClassRef(), arg); -} + // from ContactInit to Contact + Validator validator(m_context); + if (validator.isNullOrUndefined(jsValue)) { + LogError("ContactInit object is null"); + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); + } -ContactPropertiesPtr ContactConverter::toContactProperties(const JSValueRef &jsValue) -{ - if(JSContactProperties::isObjectOfClass(m_context, jsValue)) - return JSContactProperties::getContactProperties(m_context, jsValue); + if (!JSValueIsObject(m_context, jsValue) || JSIsArrayValue(m_context, jsValue)) { + LogError("ContactInit object is not object"); + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); + } - Validator validator(m_context); - if (!validator.checkArrayKeys(m_allowedContactPropertiesProperties, jsValue)) { - LogError("invalid properties in contact object"); + if (!validator.checkArrayKeys(m_allowedContactInit, jsValue)) { + LogError("invalid properties in ContactInit object"); ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); } @@ -547,77 +289,85 @@ ContactPropertiesPtr ContactConverter::toContactProperties(const JSValueRef &jsV std::string ringtoneURI; StringArrayPtr categories; - ContactPropertiesPtr result = ContactPropertiesPtr(new ContactProperties()); + ContactPtr result = ContactFactory::getInstance().createContact(); if (!result) { - Throw(WrtDeviceApis::Commons::ConversionException); + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Cannot create Contact object"); } - if (!JSValueIsUndefined(m_context, nameData)) { + if (!validator.isNullOrUndefined(nameData)) { name = toContactName(nameData); result->setName(name); } - if (!JSValueIsUndefined(m_context, accountData)) { + if (!validator.isNullOrUndefined(accountData)) { account = toContactAccount(accountData); result->setAccount(account); } - if (!JSValueIsUndefined(m_context, addressesData)) { + if (!validator.isNullOrUndefined(addressesData)) { addresses = toContactAddressArray(addressesData); result->setAddresses(addresses); } - if (!JSValueIsUndefined(m_context, photoURIData)) { + if (!validator.isNullOrUndefined(photoURIData)) { + if(!JSValueIsString(m_context, photoURIData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "photoURI is not string"); photoURI = toString(photoURIData); result->setPhotoURI(photoURI); } - if (!JSValueIsUndefined(m_context, phoneNumbersData)) { + if (!validator.isNullOrUndefined(phoneNumbersData)) { phoneNumbers = toContactPhoneNumberArray(phoneNumbersData); result->setPhoneNumbers(phoneNumbers); } - if (!JSValueIsUndefined(m_context, emailsData)) { + if (!validator.isNullOrUndefined(emailsData)) { emails = toContactEmailAddressArray(emailsData); result->setEmails(emails); } - if (!JSValueIsUndefined(m_context, birthdayData)) { + if (!validator.isNullOrUndefined(birthdayData)) { + if(!validator.isDate(birthdayData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "birthday is not Date"); birthday = toDateTm(birthdayData); result->setBirthday(birthday); } - if (!JSValueIsUndefined(m_context, anniversariesData)) { + if (!validator.isNullOrUndefined(anniversariesData)) { anniversaries = toContactAnniversaryArray(anniversariesData); result->setAnniversaries(anniversaries); } - if (!JSValueIsUndefined(m_context, organizationData)) { + if (!validator.isNullOrUndefined(organizationData)) { organization = toContactOrganization(organizationData); result->setOrganization(organization); } - if (!JSValueIsUndefined(m_context, notesData)) { + if (!validator.isNullOrUndefined(notesData)) { notes = toStringArray(notesData); result->setNotes(notes); } - if (!JSValueIsUndefined(m_context, urlsData)) { + if (!validator.isNullOrUndefined(urlsData)) { urls = toContactWebSiteArray(urlsData); result->setUrls(urls); } - if (!JSValueIsUndefined(m_context, isFavoriteData)) { + if (!validator.isNullOrUndefined(isFavoriteData)) { + if(!JSValueIsBoolean(m_context, isFavoriteData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "isFavorite is not boolean"); isFavorite = toBool(isFavoriteData); result->setIsFavorite(isFavorite); } - if (!JSValueIsUndefined(m_context, ringtoneURIData)) { + if (!validator.isNullOrUndefined(ringtoneURIData)) { + if(!JSValueIsString(m_context, ringtoneURIData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ringtoneURI is not string"); ringtoneURI = toString(ringtoneURIData); result->setRingtoneURI(ringtoneURI); } - if (!JSValueIsUndefined(m_context, categoriesData)) { + if (!validator.isNullOrUndefined(categoriesData)) { categories = toStringArray(categoriesData); result->setCategories(categories); } @@ -625,12 +375,10 @@ ContactPropertiesPtr ContactConverter::toContactProperties(const JSValueRef &jsV return result; } -JSValueRef ContactConverter::toJSValueRef(const ContactPropertiesArrayPtr &arg) +JSValueRef ContactConverter::toJSValueRef(const ContactArrayPtr &arg) { - //LogDebug("entered"); + // TODO Check it is right? not a platform object right? int size = arg->size(); - if(size == 0) - return JSValueMakeNull(m_context); JSObjectRef resultObject = JSCreateArrayObject(m_context, 0, NULL); if (!resultObject) @@ -640,38 +388,79 @@ JSValueRef ContactConverter::toJSValueRef(const ContactPropertiesArrayPtr &arg) { JSValueRef jsvalue = toJSValueRef(arg->at(i)); if (!JSSetArrayElement(m_context, resultObject, i, jsvalue)) - ThrowMsg(ConversionException, "Can not fill contact properties array."); + ThrowMsg(ConversionException, "Can not fill contact array."); } return static_cast(resultObject); } -ContactPropertiesArrayPtr ContactConverter::toContactPropertiesArray(const JSValueRef &jsValue) +ContactArrayPtr ContactConverter::toContactArray(const JSValueRef &jsValue) { - ContactPropertiesArrayPtr result = ContactPropertiesArrayPtr(new ContactPropertiesArray()); +// // 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(toContactProperties(element)); + result->push_back(toContact(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) { - // TODO make user object return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactName::getClassRef(), arg); } ContactNamePtr ContactConverter::toContactName(const JSValueRef &jsValue) { - if(JSContactName::isObjectOfClass(m_context, jsValue)) - return JSContactName::getContactName(m_context, 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.checkArrayKeys(m_allowedContactNameProperties, jsValue)) { - LogError("invalid properties in contact object"); + 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"); } @@ -703,40 +492,52 @@ ContactNamePtr ContactConverter::toContactName(const JSValueRef &jsValue) ContactNamePtr result = ContactNamePtr(new ContactName()); if (!result) { - Throw(WrtDeviceApis::Commons::ConversionException); + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Cannot create ContactName object"); } - if (!JSValueIsUndefined(m_context, prefixData)) { + if (!validator.isNullOrUndefined(prefixData)) { + if(!JSValueIsString(m_context, prefixData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "prefix is not string"); prefix = toString(prefixData); result->setPrefix(prefix); } - if (!JSValueIsUndefined(m_context, firstNameData)) { + if (!validator.isNullOrUndefined(firstNameData)) { + if(!JSValueIsString(m_context, firstNameData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "firstName is not string"); firstName = toString(firstNameData); result->setFirstName(firstName); } - if (!JSValueIsUndefined(m_context, middleNameData)) { + if (!validator.isNullOrUndefined(middleNameData)) { + if(!JSValueIsString(m_context, middleNameData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "middleName is not string"); middleName = toString(middleNameData); result->setMiddleName(middleName); } - if (!JSValueIsUndefined(m_context, lastNameData)) { + if (!validator.isNullOrUndefined(lastNameData)) { + if(!JSValueIsString(m_context, lastNameData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "lastName is not string"); lastName = toString(lastNameData); result->setLastName(lastName); } - if (!JSValueIsUndefined(m_context, nicknamesData)) { + if (!validator.isNullOrUndefined(nicknamesData)) { nicknames = toStringArray(nicknamesData); result->setNicknames(nicknames); } - if (!JSValueIsUndefined(m_context, phoneticNameData)) { + if (!validator.isNullOrUndefined(phoneticNameData)) { + if(!JSValueIsString(m_context, phoneticNameData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "phoneticName is not string"); phoneticName = toString(phoneticNameData); result->setPhoneticName(phoneticName); } - if (!JSValueIsUndefined(m_context, displayNameData)) { + if (!validator.isNullOrUndefined(displayNameData)) { + if(!JSValueIsString(m_context, displayNameData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "displayName is not string"); displayName = toString(displayNameData); result->setDisplayName(displayName); } @@ -744,101 +545,174 @@ ContactNamePtr ContactConverter::toContactName(const JSValueRef &jsValue) return result; } -JSValueRef ContactConverter::toJSValueRef(const ContactAccountPtr &arg) +JSValueRef ContactConverter::toJSValueRef(const ContactOrganizationPtr &arg) { - //LogDebug("entered"); - return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAccount::getClassRef(), arg); + return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactOrganization::getClassRef(), arg); } -ContactAccountPtr ContactConverter::toContactAccount(const JSValueRef &jsValue) +ContactOrganizationPtr ContactConverter::toContactOrganization(const JSValueRef &jsValue) { - if(JSContactAccount::isObjectOfClass(m_context, jsValue)) - return JSContactAccount::getContactAccount(m_context, 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.checkArrayKeys(m_allowedContactAccountProperties, jsValue)) { - LogError("invalid properties in contact object"); + if (validator.isNullOrUndefined(jsValue)) { + LogError("ContactOrganizationInit object is null"); ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); } - const ScopedJSStringRef accountIdStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_ACCOUNT_ID)); - const ScopedJSStringRef contactURIStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_CONTACT_URI)); - + 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"); + } + + 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 accountIdData = JSObjectGetProperty(m_context, jsObject, accountIdStr.get(), NULL); - JSValueRef contactURIData = JSObjectGetProperty(m_context, jsObject, contactURIStr.get(), NULL); + 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 accountId; - std::string contactURI; + std::string name; + std::string department; + std::string title; + std::string role; - ContactAccountPtr result(new ContactAccount()); + ContactOrganizationPtr result(new ContactOrganization()); if (!result) { - Throw(WrtDeviceApis::Commons::ConversionException); + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Cannot create ContactOrganization object"); } - if (!JSValueIsUndefined(m_context, accountIdData)) { - accountId = toString(accountIdData); - result->setAccountId(accountId); + if (!validator.isNullOrUndefined(nameData)) { + if(!JSValueIsString(m_context, nameData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "name is not string"); + name = toString(nameData); + result->setName(name); } - if (!JSValueIsUndefined(m_context, contactURIData)) { - contactURI = toString(contactURIData); - result->setContactURI(contactURI); + 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 ContactAnniversaryPtr &arg) +JSValueRef ContactConverter::toJSValueRef(const ContactOrganizationArrayPtr &arg) { - //LogDebug("entered"); - return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAnniversary::getClassRef(), arg); + return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactOrganizationArray::getClassRef(), arg); } -ContactAnniversaryPtr ContactConverter::toContactAnniversary(const JSValueRef &jsValue) +ContactOrganizationArrayPtr ContactConverter::toContactOrganizationArray(const JSValueRef &jsValue) { - if(JSContactAnniversary::isObjectOfClass(m_context, jsValue)) - return JSContactAnniversary::getContactAnniversary(m_context, jsValue); + if(JSContactOrganizationArray::isObjectOfClass(m_context, jsValue)) + return JSContactOrganizationArray::getContactOrganizationArray(m_context, jsValue); - Validator validator(m_context); - if (!validator.checkArrayKeys(m_allowedContactAnniversaryProperties, jsValue)) { - LogError("invalid properties in contact object"); + 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"); } - const ScopedJSStringRef dateStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_DATE)); - const ScopedJSStringRef labelStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_LABEL)); + return JSContactWebSite::getContactWebSite(m_context, jsValue); +} - JSObjectRef jsObject = toJSObjectRef(jsValue); +JSValueRef ContactConverter::toJSValueRef(const ContactWebSiteArrayPtr &arg) +{ + return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactWebSiteArray::getClassRef(), arg); +} - JSValueRef dateData = JSObjectGetProperty(m_context, jsObject, dateStr.get(), NULL); - JSValueRef labelData = JSObjectGetProperty(m_context, jsObject, labelStr.get(), NULL); +ContactWebSiteArrayPtr ContactConverter::toContactWebSiteArray(const JSValueRef &jsValue) +{ + if(JSContactWebSiteArray::isObjectOfClass(m_context, jsValue)) + return JSContactWebSiteArray::getContactWebSiteArray(m_context, jsValue); - std::tm date; - std::string label; + if(!JSIsArrayValue(m_context, jsValue)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactWebSiteArray is not array."); - ContactAnniversaryPtr result(new ContactAnniversary()); - if (!result) { - Throw(WrtDeviceApis::Commons::ConversionException); - } + ContactWebSiteArrayPtr result(new ContactWebSiteArray()); - if (!JSValueIsUndefined(m_context, dateData)) { - date = toDateTm(dateData); - result->setDate(date); - } + 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); +} - if (!JSValueIsUndefined(m_context, labelData)) { - label = toString(labelData); - result->setLabel(label); +ContactAnniversaryPtr ContactConverter::toContactAnniversary(const JSValueRef &jsValue) +{ + if(!JSContactAnniversary::isObjectOfClass(m_context, jsValue)) + { + LogError("Not a ContactAnniversary object"); + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); } - return result; + return JSContactAnniversary::getContactAnniversary(m_context, jsValue); } JSValueRef ContactConverter::toJSValueRef(const ContactAnniversaryArrayPtr &arg) { - //LogDebug("entered"); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAnniversaryArray::getClassRef(), arg); } @@ -847,6 +721,9 @@ ContactAnniversaryArrayPtr ContactConverter::toContactAnniversaryArray(const JSV 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); @@ -857,41 +734,54 @@ ContactAnniversaryArrayPtr ContactConverter::toContactAnniversaryArray(const JSV return result; } -JSValueRef ContactConverter::toJSValueRefAttributesOfInterestArray(const AttributesOfInterestArrayPtr &arg) +JSValueRef ContactConverter::toJSValueRef(const ContactAccountPtr &arg) { - //LogDebug("entered"); - return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSAttributesOfInterestArray::getClassRef(), arg); + return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAccount::getClassRef(), arg); } -AttributesOfInterestArrayPtr ContactConverter::toAttributesOfInterestArray(const JSValueRef &jsValue) +ContactAccountPtr ContactConverter::toContactAccount(const JSValueRef &jsValue) { - if(JSAttributesOfInterestArray::isObjectOfClass(m_context, jsValue)) - return JSAttributesOfInterestArray::getAttributesOfInterestArray(m_context, jsValue); - - AttributesOfInterestArrayPtr result(new AttributesOfInterestArray()); + if(!JSContactAccount::isObjectOfClass(m_context, jsValue)) + { + LogError("Not a ContactAccount object"); + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); + } - 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; + return JSContactAccount::getContactAccount(m_context, jsValue); } JSValueRef ContactConverter::toJSValueRef(const ContactAddressPtr &arg) { - //LogDebug("entered"); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAddress::getClassRef(), arg); } ContactAddressPtr ContactConverter::toContactAddress(const JSValueRef &jsValue) { - if(JSContactAddress::isObjectOfClass(m_context, jsValue)) - return JSContactAddress::getContactAddress(m_context, 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.checkArrayKeys(m_allowedContactAddressProperties, jsValue)) { - LogError("invalid properties in contact object"); + 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"); } @@ -923,40 +813,52 @@ ContactAddressPtr ContactConverter::toContactAddress(const JSValueRef &jsValue) ContactAddressPtr result(new ContactAddress()); if (!result) { - Throw(WrtDeviceApis::Commons::ConversionException); + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Cannot make ContactAddress"); } - if (!JSValueIsUndefined(m_context, countryData)) { + if (!validator.isNullOrUndefined(countryData)) { + if(!JSValueIsString(m_context, countryData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "country is not string"); country = toString(countryData); result->setCountry(country); } - if (!JSValueIsUndefined(m_context, regionData)) { + if (!validator.isNullOrUndefined(regionData)) { + if(!JSValueIsString(m_context, regionData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "region is not string"); region = toString(regionData); result->setRegion(region); } - if (!JSValueIsUndefined(m_context, cityData)) { + if (!validator.isNullOrUndefined(cityData)) { + if(!JSValueIsString(m_context, cityData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "city is not string"); city = toString(cityData); result->setCity(city); } - if (!JSValueIsUndefined(m_context, streetAddressData)) { + if (!validator.isNullOrUndefined(streetAddressData)) { + if(!JSValueIsString(m_context, streetAddressData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "streetAddress is not string"); streetAddress = toString(streetAddressData); result->setStreetAddress(streetAddress); } - if (!JSValueIsUndefined(m_context, additionalInformationData)) { + if (!validator.isNullOrUndefined(additionalInformationData)) { + if(!JSValueIsString(m_context, additionalInformationData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "additionalInformation is not string"); additionalInformation = toString(additionalInformationData); result->setAdditionalInformation(additionalInformation); } - if (!JSValueIsUndefined(m_context, postalCodeData)) { + if (!validator.isNullOrUndefined(postalCodeData)) { + if(!JSValueIsString(m_context, postalCodeData)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "postalCode is not string"); postalCode = toString(postalCodeData); result->setPostalCode(postalCode); } - if (!JSValueIsUndefined(m_context, typesData)) { + if (!validator.isNullOrUndefined(typesData)) { types = toContactAddressTypeArray(typesData); result->setTypes(types); } @@ -966,7 +868,6 @@ ContactAddressPtr ContactConverter::toContactAddress(const JSValueRef &jsValue) JSValueRef ContactConverter::toJSValueRef(const ContactAddressArrayPtr &arg) { - //LogDebug("entered"); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAddressArray::getClassRef(), arg); } @@ -975,6 +876,9 @@ ContactAddressArrayPtr ContactConverter::toContactAddressArray(const JSValueRef 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); @@ -985,99 +889,24 @@ ContactAddressArrayPtr ContactConverter::toContactAddressArray(const JSValueRef return result; } -JSValueRef ContactConverter::toJSValueRef(const ContactAddressTypeArrayPtr &arg) -{ - //LogDebug("entered"); - 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); - - 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; -} - -//JSValueRef ContactConverter::toJSValueRef(const ContactCapabilityTypeArrayPtr &arg) -//{ -// //LogDebug("entered"); -// return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactCapabilityTypeArray::getClassRef(), arg); -//} -// -//ContactCapabilityTypeArrayPtr ContactConverter::toContactCapabilityTypeArray(const JSValueRef &jsValue) -//{ -// if(JSContactCapabilityTypeArray::isObjectOfClass(m_context, jsValue)) -// return JSContactCapabilityTypeArray::getContactCapabilityTypeArray(m_context, jsValue); -// -// ContactCapabilityTypeArrayPtr result(new ContactCapabilityTypeArray()); -// -// 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(toContactCapabilityType(element)); -// } -// return result; -//} - JSValueRef ContactConverter::toJSValueRef(const ContactPhoneNumberPtr &arg) { - //LogDebug("entered"); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactPhoneNumber::getClassRef(), arg); } ContactPhoneNumberPtr ContactConverter::toContactPhoneNumber(const JSValueRef &jsValue) { - if(JSContactPhoneNumber::isObjectOfClass(m_context, jsValue)) - return JSContactPhoneNumber::getContactPhoneNumber(m_context, jsValue); - - Validator validator(m_context); - if (!validator.checkArrayKeys(m_allowedContactPhoneNumberProperties, jsValue)) { - LogError("invalid properties in contact object"); + if(!JSContactPhoneNumber::isObjectOfClass(m_context, jsValue)) + { + LogError("Not a ContactPhoneNumber object"); ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); } - const ScopedJSStringRef numberStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_NUMBER)); - const ScopedJSStringRef typesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_TYPES)); - - JSObjectRef jsObject = toJSObjectRef(jsValue); - - JSValueRef numberData = JSObjectGetProperty(m_context, jsObject, numberStr.get(), NULL); - JSValueRef typesData = JSObjectGetProperty(m_context, jsObject, typesStr.get(), NULL); - - std::string number; - StringArrayPtr types; - - ContactPhoneNumberPtr result(new ContactPhoneNumber()); - if (!result) { - Throw(WrtDeviceApis::Commons::ConversionException); - } - - if (!JSValueIsUndefined(m_context, numberData)) { - number = toString(numberData); - result->setNumber(number); - } - - if (!JSValueIsUndefined(m_context, typesData)) { - types = toStringArray(typesData); - result->setTypes(types); - } else { - result->addType("VOICE"); - } - - return result; + return JSContactPhoneNumber::getContactPhoneNumber(m_context, jsValue); } JSValueRef ContactConverter::toJSValueRef(const ContactPhoneNumberArrayPtr &arg) { - //LogDebug("entered"); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactPhoneNumberArray::getClassRef(), arg); } @@ -1086,6 +915,9 @@ ContactPhoneNumberArrayPtr ContactConverter::toContactPhoneNumberArray(const JSV 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); @@ -1096,79 +928,24 @@ ContactPhoneNumberArrayPtr ContactConverter::toContactPhoneNumberArray(const JSV return result; } -JSValueRef ContactConverter::toJSValueRef(const ContactPhoneNumberTypeArrayPtr &arg) -{ - //LogDebug("entered"); - 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); - - 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); - result->push_back(toContactPhoneNumberType(element)); - } - return result; -} - JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressPtr &arg) { - //LogDebug("entered"); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactEmailAddress::getClassRef(), arg); } ContactEmailAddressPtr ContactConverter::toContactEmailAddress(const JSValueRef &jsValue) { - if(JSContactEmailAddress::isObjectOfClass(m_context, jsValue)) - return JSContactEmailAddress::getContactEmailAddress(m_context, jsValue); - - Validator validator(m_context); - if (!validator.checkArrayKeys(m_allowedContactEmailAddressProperties, jsValue)) { - LogError("invalid properties in contact object"); + if(!JSContactEmailAddress::isObjectOfClass(m_context, jsValue)) + { + LogError("Not a ContactEmailAddress object"); ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); } - const ScopedJSStringRef emailStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_EMAIL)); - const ScopedJSStringRef typesStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_TYPES)); - - JSObjectRef jsObject = toJSObjectRef(jsValue); - - - JSValueRef emailData = JSObjectGetProperty(m_context, jsObject, emailStr.get(), NULL); - JSValueRef typesData = JSObjectGetProperty(m_context, jsObject, typesStr.get(), NULL); - - - std::string email; - ContactEmailAddressTypeArrayPtr types; - - ContactEmailAddressPtr result(new ContactEmailAddress()); - if (!result) { - Throw(WrtDeviceApis::Commons::ConversionException); - } - - if (!JSValueIsUndefined(m_context, emailData)) { - email = toString(emailData); - result->setEmail(email); - } - - if (!JSValueIsUndefined(m_context, typesData)) { - types = toContactEmailAddressTypeArray(typesData); - result->setTypes(types); - } else { - result->addType(CONTACT_EMAIL_TYPE_PREF); - } - return result; + return JSContactEmailAddress::getContactEmailAddress(m_context, jsValue); } JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressArrayPtr &arg) { - //LogDebug("entered"); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactEmailAddressArray::getClassRef(), arg); } @@ -1177,6 +954,9 @@ ContactEmailAddressArrayPtr ContactConverter::toContactEmailAddressArray(const J 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); @@ -1187,251 +967,380 @@ ContactEmailAddressArrayPtr ContactConverter::toContactEmailAddressArray(const J return result; } -JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressTypeArrayPtr &arg) +ContactWebSiteType ContactConverter::toContactWebSiteType(const std::string &arg) { - //LogDebug("entered"); - return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactEmailAddressTypeArray::getClassRef(), 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; + } else { + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactWebSiteType : " << arg); + } + return WEBSITE_TYPE_HOMEPAGE; } -ContactEmailAddressTypeArrayPtr ContactConverter::toContactEmailAddressTypeArray(const JSValueRef &jsValue) +std::string ContactConverter::toContactWebSiteTypeStr(ContactWebSiteType arg) { - if(JSContactEmailAddressTypeArray::isObjectOfClass(m_context, jsValue)) - return JSContactEmailAddressTypeArray::getContactEmailAddressTypeArray(m_context, jsValue); + if (arg == WEBSITE_TYPE_HOMEPAGE) { + return STR_WEBSITE_TYPE_HOMEPAGE; + } else if (arg == WEBSITE_TYPE_BLOG) { + return STR_WEBSITE_TYPE_BLOG; + } else { + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactWebSiteType : " << arg); + } + return STR_WEBSITE_TYPE_HOMEPAGE; +} - ContactEmailAddressTypeArrayPtr result(new ContactEmailAddressTypeArray()); +ContactWebSiteType ContactConverter::toContactWebSiteType(const JSValueRef &value) +{ + if(!JSValueIsString(m_context, value)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactWebSiteType is not string."); - 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(toContactEmailAddressType(element)); - } - return result; + return toContactWebSiteType(toString(value)); } -JSValueRef ContactConverter::toJSValueRef(const ContactOrganizationPtr &arg) +JSValueRef ContactConverter::toJSValueRef(ContactWebSiteType arg) { - //LogDebug("entered"); - return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactOrganization::getClassRef(), arg); + return toJSValueRef(toContactWebSiteTypeStr(arg)); } -ContactOrganizationPtr ContactConverter::toContactOrganization(const JSValueRef &jsValue) +ContactAddressType ContactConverter::toContactAddressType(const std::string &arg) { - if(JSContactOrganization::isObjectOfClass(m_context, jsValue)) - return JSContactOrganization::getContactOrganization(m_context, jsValue); + std::string argUpper; + std::transform(arg.begin(), arg.end(), std::back_inserter(argUpper), ::toupper); - Validator validator(m_context); - if (!validator.checkArrayKeys(m_allowedContactOrganizationProperties, jsValue)) { - LogError("invalid properties in contact object"); - ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); + 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; + } else { + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactAddressType : " << arg); } + return CONTACT_ADDRESS_TYPE_PREF; +} +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; + } else { + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactAddressType : " << arg); + } + return STR_CONTACT_ADDRESS_TYPE_PREF; +} - 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)); +ContactAddressType ContactConverter::toContactAddressType(const JSValueRef &value) +{ + if(!JSValueIsString(m_context, value)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactAddressType is not string."); - JSObjectRef jsObject = toJSObjectRef(jsValue); + return toContactAddressType(toString(value)); +} - 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); +JSValueRef ContactConverter::toJSValueRef(ContactAddressType arg) +{ + return toJSValueRef(toContactAddressTypeStr(arg)); +} - std::string name; - std::string department; - std::string title; - std::string role; +JSValueRef ContactConverter::toJSValueRef(const ContactAddressTypeArrayPtr &arg) +{ + return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactAddressTypeArray::getClassRef(), arg); +} - ContactOrganizationPtr result(new ContactOrganization()); - if (!result) { - Throw(WrtDeviceApis::Commons::ConversionException); - } +ContactAddressTypeArrayPtr ContactConverter::toContactAddressTypeArray(const JSValueRef &jsValue) +{ + if(JSContactAddressTypeArray::isObjectOfClass(m_context, jsValue)) + return JSContactAddressTypeArray::getContactAddressTypeArray(m_context, jsValue); - if (!JSValueIsUndefined(m_context, nameData)) { - name = toString(nameData); - result->setName(name); - } + if(!JSIsArrayValue(m_context, jsValue)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactAddressTypeArray is not array."); - if (!JSValueIsUndefined(m_context, departmentData)) { - department = toString(departmentData); - result->setDepartment(department); - } + ContactAddressTypeArrayPtr result(new ContactAddressTypeArray()); - if (!JSValueIsUndefined(m_context, titleData)) { - title = toString(titleData); - result->setTitle(title); + 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; + } else { + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactPhoneNumverType : " << arg); } + return CONTACT_PHONE_NUMBER_TYPE_WORK; +} - if (!JSValueIsUndefined(m_context, roleData)) { - role = toString(roleData); - result->setRole(role); +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; + } else { + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactPhoneNumverType : " << arg); } + return STR_CONTACT_PHONE_NUMBER_TYPE_WORK; +} - return result; +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(const ContactOrganizationArrayPtr &arg) +JSValueRef ContactConverter::toJSValueRef(ContactPhoneNumberType arg) { - //LogDebug("entered"); - return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactOrganizationArray::getClassRef(), arg); + return toJSValueRef(toContactPhoneNumberTypeStr(arg)); } -ContactOrganizationArrayPtr ContactConverter::toContactOrganizationArray(const JSValueRef &jsValue) +JSValueRef ContactConverter::toJSValueRef(const ContactPhoneNumberTypeArrayPtr &arg) { - if(JSContactOrganizationArray::isObjectOfClass(m_context, jsValue)) - return JSContactOrganizationArray::getContactOrganizationArray(m_context, jsValue); + return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactPhoneNumberTypeArray::getClassRef(), arg); +} - ContactOrganizationArrayPtr result(new ContactOrganizationArray()); +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); - result->push_back(toContactOrganization(element)); + result->push_back(toContactPhoneNumberType(element)); } return result; } -JSValueRef ContactConverter::toJSValueRef(const ContactWebSitePtr &arg) +ContactEmailAddressType ContactConverter::toContactEmailAddressType(const std::string &arg) { - //LogDebug("entered"); - return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactWebSite::getClassRef(), 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; + } else { + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactEmailAddressType : " << arg); + } + return CONTACT_EMAIL_TYPE_PREF; } -ContactWebSitePtr ContactConverter::toContactWebSite(const JSValueRef &jsValue) +std::string ContactConverter::toContactEmailAddressTypeStr(ContactEmailAddressType arg) { - if(JSContactWebSite::isObjectOfClass(m_context, jsValue)) - return JSContactWebSite::getContactWebSite(m_context, jsValue); - - Validator validator(m_context); - if (!validator.checkArrayKeys(m_allowedContactWebSiteProperties, jsValue)) { - LogError("invalid properties in contact object"); - ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); + 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; + } else { + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Invalid ContactEmailAddressType : " << arg); } + return STR_CONTACT_EMAIL_TYPE_PREF; +} - const ScopedJSStringRef urlStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_URL)); - const ScopedJSStringRef typeStr(JSStringCreateWithUTF8CString(CONTACT_ATTRIBUTE_TYPE)); - - JSObjectRef jsObject = toJSObjectRef(jsValue); +ContactEmailAddressType ContactConverter::toContactEmailAddressType(const JSValueRef &value) +{ + if(!JSValueIsString(m_context, value)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactEmailAddressType is not string."); - JSValueRef urlData = JSObjectGetProperty(m_context, jsObject, urlStr.get(), NULL); - JSValueRef typeData = JSObjectGetProperty(m_context, jsObject, typeStr.get(), NULL); + return toContactEmailAddressType(toString(value)); +} - std::string url; - ContactWebSiteType type; +JSValueRef ContactConverter::toJSValueRef(ContactEmailAddressType arg) +{ + return toJSValueRef(toContactEmailAddressTypeStr(arg)); +} - ContactWebSitePtr result(new ContactWebSite()); - if (!result) { - Throw(WrtDeviceApis::Commons::ConversionException); - } +JSValueRef ContactConverter::toJSValueRef(const ContactEmailAddressTypeArrayPtr &arg) +{ + return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactEmailAddressTypeArray::getClassRef(), arg); +} - if (!JSValueIsUndefined(m_context, urlData)) { - url = toString(urlData); - result->setUrl(url); - } +ContactEmailAddressTypeArrayPtr ContactConverter::toContactEmailAddressTypeArray(const JSValueRef &jsValue) +{ + if(JSContactEmailAddressTypeArray::isObjectOfClass(m_context, jsValue)) + return JSContactEmailAddressTypeArray::getContactEmailAddressTypeArray(m_context, jsValue); - if (!JSValueIsUndefined(m_context, typeData)) { - type = toContactWebSiteType(typeData); - result->setType(type); - } + if(!JSIsArrayValue(m_context, jsValue)) + ThrowMsg(WrtDeviceApis::Commons::ConversionException, "ContactEmailAddressTypeArray is not array."); - return result; -} + ContactEmailAddressTypeArrayPtr result(new ContactEmailAddressTypeArray()); -JSValueRef ContactConverter::toJSValueRef(const ContactWebSiteArrayPtr &arg) -{ - //LogDebug("entered"); - return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSContactWebSiteArray::getClassRef(), arg); + 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(toContactEmailAddressType(element)); + } + return result; } -ContactWebSiteArrayPtr ContactConverter::toContactWebSiteArray(const JSValueRef &jsValue) +StringArrayPtr ContactConverter::toStringArray(const JSValueRef &jsValue) { - if(JSContactWebSiteArray::isObjectOfClass(m_context, jsValue)) - return JSContactWebSiteArray::getContactWebSiteArray(m_context, jsValue); + if(JSStringArray::isObjectOfClass(m_context, jsValue)) + return JSStringArray::getStringArray(m_context, jsValue); - ContactWebSiteArrayPtr result(new ContactWebSiteArray()); + 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(toContactWebSite(element)); + 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_allowedAddressBookProperties.push_back(CONTACT_ATTRIBUTE_NAME); - - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_ID); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_READ_ONLY); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_LAST_UPDATED); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_NAME); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_ACCOUNT); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_ADDRESSES); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_PHOTO_URI ); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_PHONE_NUMBERS); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_EMAILS); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_BIRTHDAY); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_ANNIVERSARIES); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_ORGANIZATION); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_NOTES); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_URLS); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_IS_FAVORITE); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_RINGTONE_URI); - m_allowedContactProperties.push_back(CONTACT_ATTRIBUTE_CATEGORIES); - - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_NAME); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_ACCOUNT); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_ADDRESSES); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_PHOTO_URI ); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_PHONE_NUMBERS); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_EMAILS); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_BIRTHDAY); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_ANNIVERSARIES); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_ORGANIZATION); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_NOTES); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_URLS); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_IS_FAVORITE); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_RINGTONE_URI); - m_allowedContactPropertiesProperties.push_back(CONTACT_ATTRIBUTE_CATEGORIES); - - m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_PREFIX); - m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_FIRST_NAME); - m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_MIDDLE_NAME); - m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_LAST_NAME); - m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_NICKNAMES); - m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_PHONETIC_NAME); - m_allowedContactNameProperties.push_back(CONTACT_ATTRIBUTE_DISPLAY_NAME); - - m_allowedContactAccountProperties.push_back(CONTACT_ATTRIBUTE_ACCOUNT_ID); - m_allowedContactAccountProperties.push_back(CONTACT_ATTRIBUTE_CONTACT_URI); - - m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_NAME); - m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_DEPARTMENT); - m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_OFFICE); - m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_TITLE); - m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_ROLE); - m_allowedContactOrganizationProperties.push_back(CONTACT_ATTRIBUTE_LOGO_URI); - - m_allowedContactWebSiteProperties.push_back(CONTACT_ATTRIBUTE_URL); - m_allowedContactWebSiteProperties.push_back(CONTACT_ATTRIBUTE_TYPE); - - m_allowedContactAnniversaryProperties.push_back(CONTACT_ATTRIBUTE_DATE); - m_allowedContactAnniversaryProperties.push_back(CONTACT_ATTRIBUTE_LABEL); - - m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_COUNTRY); - m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_REGION); - m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_CITY); - m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_STREET_ADDRESS); - m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_ADDITIONAL_INFORMATION); - m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_POSTAL_CODE); - m_allowedContactAddressProperties.push_back(CONTACT_ATTRIBUTE_TYPES); - - m_allowedContactPhoneNumberProperties.push_back(CONTACT_ATTRIBUTE_NUMBER); - m_allowedContactPhoneNumberProperties.push_back(CONTACT_ATTRIBUTE_TYPES); - - m_allowedContactEmailAddressProperties.push_back(CONTACT_ATTRIBUTE_EMAIL); - m_allowedContactEmailAddressProperties.push_back(CONTACT_ATTRIBUTE_TYPES); + m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_NAME); + m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_ACCOUNT); + 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_ORGANIZATION); + m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_NOTES); + m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_URLS); + m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_IS_FAVORITE); + m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_RINGTONE_URI); + m_allowedContactInit.push_back(CONTACT_ATTRIBUTE_CATEGORIES); + + 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_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; } diff --git a/src/standards/Tizen/Contact/ContactConverter.h b/src/standards/Tizen/Contact/ContactConverter.h index 904c8a0..e04cd79 100755 --- a/src/standards/Tizen/Contact/ContactConverter.h +++ b/src/standards/Tizen/Contact/ContactConverter.h @@ -27,8 +27,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -51,58 +51,38 @@ public: explicit ContactConverter(JSContextRef context); virtual ~ContactConverter(); - TizenApis::Api::Contact::StringArrayPtr toStringArray(const JSValueRef &value); - JSValueRef toJSValueRef(const TizenApis::Api::Contact::StringArrayPtr &arg); - - 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); - - 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); - - 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); - - 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); + JSValueRef toJSValueRef(const TizenApis::Api::Contact::AddressBookPtr &arg); + TizenApis::Api::Contact::AddressBookPtr toAddressBook(const JSValueRef &jsValue); - TizenApis::Api::Contact::ContactCapabilityType toContactCapabilityType(const JSValueRef &value); -// JSValueRef toJSValueRef(TizenApis::Api::Contact::ContactCapabilityType arg); - -// JSValueRef toJSValueRef(const std::string &arg); - std::string toAttributesOfInterest(const JSValueRef &value); - - JSValueRef toJSValueRef(const TizenApis::Api::Contact::IAddressBookPtr &arg); - TizenApis::Api::Contact::IAddressBookPtr toAddressBook(const JSValueRef &jsValue); - - JSValueRef toJSValueRef(const TizenApis::Api::Contact::IAddressBookArrayPtr &arg); - TizenApis::Api::Contact::IAddressBookArrayPtr toAddressBookArray(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::ContactPropertiesPtr &arg); - TizenApis::Api::Contact::ContactPropertiesPtr toContactProperties(const JSValueRef &jsValue); - - JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactPropertiesArrayPtr &arg); - TizenApis::Api::Contact::ContactPropertiesArrayPtr toContactPropertiesArray(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::ContactAccountPtr &arg); - TizenApis::Api::Contact::ContactAccountPtr toContactAccount(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); @@ -110,64 +90,81 @@ public: JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactAnniversaryArrayPtr &arg); TizenApis::Api::Contact::ContactAnniversaryArrayPtr toContactAnniversaryArray(const JSValueRef &jsValue); - JSValueRef toJSValueRefAttributesOfInterestArray(const TizenApis::Api::Contact::AttributesOfInterestArrayPtr &arg); - TizenApis::Api::Contact::AttributesOfInterestArrayPtr toAttributesOfInterestArray(const JSValueRef &jsValue); + JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactAccountPtr &arg); + TizenApis::Api::Contact::ContactAccountPtr toContactAccount(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::ContactAddressTypeArrayPtr &arg); - TizenApis::Api::Contact::ContactAddressTypeArrayPtr toContactAddressTypeArray(const JSValueRef &jsValue); - -// JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactCapabilityTypeArrayPtr &arg); -// TizenApis::Api::Contact::ContactCapabilityTypeArrayPtr toContactCapabilityTypeArray(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::ContactPhoneNumberTypeArrayPtr &arg); - TizenApis::Api::Contact::ContactPhoneNumberTypeArrayPtr toContactPhoneNumberTypeArray(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); - JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactOrganizationPtr &arg); - TizenApis::Api::Contact::ContactOrganizationPtr toContactOrganization(const JSValueRef &jsValue); - - JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactOrganizationArrayPtr &arg); - TizenApis::Api::Contact::ContactOrganizationArrayPtr toContactOrganizationArray(const JSValueRef &jsValue); + // String Array + TizenApis::Api::Contact::StringArrayPtr toStringArray(const JSValueRef &value); + JSValueRef toJSValueRef(const TizenApis::Api::Contact::StringArrayPtr &arg); - JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactWebSitePtr &arg); - TizenApis::Api::Contact::ContactWebSitePtr toContactWebSite(const JSValueRef &jsValue); + // AttributesOfInterest Array - No more used +// JSValueRef toJSValueRefAttributesOfInterestArray(const TizenApis::Api::Contact::AttributesOfInterestArrayPtr &arg); +// TizenApis::Api::Contact::AttributesOfInterestArrayPtr toAttributesOfInterestArray(const JSValueRef &jsValue); - JSValueRef toJSValueRef(const TizenApis::Api::Contact::ContactWebSiteArrayPtr &arg); - TizenApis::Api::Contact::ContactWebSiteArrayPtr toContactWebSiteArray(const JSValueRef &jsValue); +// JSValueRef toJSValueRef(const std::string &arg); +// std::string toAttributesOfInterest(const JSValueRef &value); private: bool initializeAllowedProperties(); - static std::vector m_allowedAddressBookProperties; - static std::vector m_allowedContactProperties; - static std::vector m_allowedContactPropertiesProperties; - static std::vector m_allowedContactNameProperties; - static std::vector m_allowedContactAccountProperties; - static std::vector m_allowedContactOrganizationProperties; - static std::vector m_allowedContactWebSiteProperties; - static std::vector m_allowedContactAnniversaryProperties; - static std::vector m_allowedContactAddressProperties; - static std::vector m_allowedContactPhoneNumberProperties; - static std::vector m_allowedContactEmailAddressProperties; + static std::vector m_allowedContactInit; + static std::vector m_allowedContactNameInit; + static std::vector m_allowedContactOrganizationInit; + static std::vector m_allowedContactAddressInit; }; typedef WrtDeviceApis::CommonsJavaScript::ConverterFactory ContactConverterFactory; diff --git a/src/standards/Tizen/Contact/ContactManagerController.cpp b/src/standards/Tizen/Contact/ContactManagerController.cpp index 9a00ce2..835f68f 100755 --- a/src/standards/Tizen/Contact/ContactManagerController.cpp +++ b/src/standards/Tizen/Contact/ContactManagerController.cpp @@ -48,6 +48,7 @@ ContactManagerController::~ContactManagerController() void ContactManagerAsyncAnswerHandler::getAddressBooks(const EventContactManagerGetAddressBooksPtr &event) { + LogDebug("entered"); JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast(event->getPrivateData()); if (!callbackManager) { @@ -85,7 +86,7 @@ void ContactManagerAsyncAnswerHandler::getAddressBooks(const EventContactManager ThrowMsg(PlatformException, "No result."); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext); - IAddressBookArrayPtr addressBooks = event->getAddressBooks(); + AddressBookArrayPtr addressBooks = event->getAddressBooks(); JSValueRef result = converter->toJSValueRef(addressBooks); diff --git a/src/standards/Tizen/Contact/JSAddressBook.cpp b/src/standards/Tizen/Contact/JSAddressBook.cpp index 73e14ca..195ca28 100755 --- a/src/standards/Tizen/Contact/JSAddressBook.cpp +++ b/src/standards/Tizen/Contact/JSAddressBook.cpp @@ -48,8 +48,9 @@ using namespace std; -#define TIZEN_ADDRESS_BOOK_TYPE "type" -#define TIZEN_ADDRESS_BOOK_NAME "name" +#define TIZEN_ADDRESS_BOOK_ID "id" +#define TIZEN_ADDRESS_BOOK_NAME "name" +#define TIZEN_ADDRESS_BOOK_READ_ONLY "readOnly" #define TIZEN_ADDRESS_BOOK "AddressBook" @@ -64,8 +65,6 @@ using namespace TizenApis::Tizen1_0::Tizen; using namespace WrtDeviceApis::Commons; using namespace WrtDeviceApis::CommonsJavaScript; -using TizenApis::Api::Contact::Contact; - JSClassRef JSAddressBook::m_jsClassRef = NULL; JSClassDefinition JSAddressBook::m_classInfo = { @@ -89,14 +88,14 @@ JSClassDefinition JSAddressBook::m_classInfo = { }; JSStaticValue JSAddressBook::m_property[] = { - { TIZEN_ADDRESS_BOOK_TYPE, getProperty, NULL, kJSPropertyAttributeReadOnly }, - { TIZEN_ADDRESS_BOOK_NAME, getProperty, NULL, kJSPropertyAttributeReadOnly }, + { TIZEN_ADDRESS_BOOK_ID, getId, NULL, kJSPropertyAttributeReadOnly }, + { TIZEN_ADDRESS_BOOK_NAME, getName, NULL, kJSPropertyAttributeReadOnly }, + { TIZEN_ADDRESS_BOOK_READ_ONLY, getReadOnly, NULL, kJSPropertyAttributeReadOnly }, { 0, 0, 0, 0 } }; JSStaticFunction JSAddressBook::m_function[] = { - { "convertFromString", convertFromString, kJSPropertyAttributeNone }, - { "convertToString", convertToString, kJSPropertyAttributeNone }, + { "get", get, kJSPropertyAttributeNone }, { "add", add, kJSPropertyAttributeNone }, { "addBatch", addBatch, kJSPropertyAttributeNone }, { "update", update, kJSPropertyAttributeNone }, @@ -126,7 +125,6 @@ const JSClassRef JSAddressBook::getClassRef() void JSAddressBook::Initialize(JSContextRef context, JSObjectRef object) { - ////LogDebug("entered"); AddressBookController *priv = static_cast(JSObjectGetPrivate(object)); Assert(priv && "Private object not set."); @@ -134,7 +132,6 @@ void JSAddressBook::Initialize(JSContextRef context, void JSAddressBook::Finalize(JSObjectRef object) { - //LogDebug("entered"); } bool JSAddressBook::isObjectOfClass(JSContextRef context, JSValueRef value) @@ -142,7 +139,7 @@ bool JSAddressBook::isObjectOfClass(JSContextRef context, JSValueRef value) return JSValueIsObjectOfClass(context, value, getClassRef()); } -IAddressBookPtr JSAddressBook::getAddressBook(JSContextRef context, JSValueRef value) +AddressBookPtr JSAddressBook::getAddressBook(JSContextRef context, JSValueRef value) { if (!isObjectOfClass(context, value)) { Throw(InvalidArgumentException); @@ -158,7 +155,7 @@ IAddressBookPtr JSAddressBook::getAddressBook(JSContextRef context, JSValueRef v return priv->getObject(); } -IAddressBookPtr JSAddressBook::getPrivData(JSObjectRef object) +AddressBookPtr JSAddressBook::getPrivData(JSObjectRef object) { AddressBookController *priv = static_cast(JSObjectGetPrivate(object)); @@ -168,85 +165,66 @@ IAddressBookPtr JSAddressBook::getPrivData(JSObjectRef object) Throw(NullPointerException); } -JSValueRef JSAddressBook::convertFromString(JSContextRef context, +JSValueRef JSAddressBook::getId(JSContextRef context, JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], + JSStringRef propertyName, JSValueRef* exception) { - LogDebug("entered"); - IAddressBookPtr addressBook; - JSContextRef gContext; - AddressBookController *controller; - - Try { - controller = static_cast(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"); + Try + { + ContactConverterFactory::ConverterType converter = + ContactConverterFactory::getConverter(context); + AddressBookPtr addressBook = getPrivData(object); + return converter->toJSValueRef(addressBook->getId()); } - - AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_CONVERT_FROM_STRING); - TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - - BasicValidator validator = BasicValidatorFactory::getValidator(context, exception); - Try { - if (argumentCount != 2) - ThrowMsg(InvalidArgumentException, "Wrong arguments count."); - - if (!JSValueIsString(context, arguments[0])) - ThrowMsg(InvalidArgumentException, "1st argument is not string."); - - if (!JSValueIsString(context, arguments[1])) - ThrowMsg(InvalidArgumentException, "2nd argument is not string."); - } Catch(Exception ) { - LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); - return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + Catch(WrtDeviceApis::Commons::Exception) + { + LogWarning("trying to get incorrect value"); } + return JSValueMakeUndefined(context); +} - string vCardStr; - string format; - - ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); +JSValueRef JSAddressBook::getName(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ Try { - vCardStr = converter->toString(arguments[0]); - format = converter->toString(arguments[1]); + ContactConverterFactory::ConverterType converter = + ContactConverterFactory::getConverter(context); + AddressBookPtr addressBook = getPrivData(object); + return converter->toJSValueRef(addressBook->getName()); } - Catch(Exception) { - LogError("Error on conversion " << _rethrown_exception.GetMessage()); - return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + Catch(WrtDeviceApis::Commons::Exception) + { + LogWarning("trying to get incorrect value"); } - ContactPropertiesPtr contactProperties; - Try { - contactProperties = addressBook->convertFromString(vCardStr, format); - } Catch(UnsupportedException) { - LogError("Error on platform : " << _rethrown_exception.GetMessage()); - return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Unsupported format"); - } Catch(Exception) { - LogError("Error on platform : " << _rethrown_exception.GetMessage()); - return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error"); - } + return JSValueMakeUndefined(context); +} - JSValueRef result; - Try { - result = converter->toJSValueRef(contactProperties); - } Catch(Exception) { - LogError("Error on conversion"); - return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); +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 result; + return JSValueMakeUndefined(context); } -JSValueRef JSAddressBook::convertToString(JSContextRef context, +JSValueRef JSAddressBook::get(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, @@ -254,7 +232,7 @@ JSValueRef JSAddressBook::convertToString(JSContextRef context, JSValueRef* exception) { LogDebug("entered"); - IAddressBookPtr addressBook; + AddressBookPtr addressBook; JSContextRef gContext; AddressBookController *controller; @@ -275,34 +253,29 @@ JSValueRef JSAddressBook::convertToString(JSContextRef context, BasicValidator validator = BasicValidatorFactory::getValidator(context, exception); Try { - if (argumentCount != 2) + if (argumentCount != 1) ThrowMsg(InvalidArgumentException, "Wrong arguments count."); - if (!JSContact::isObjectOfClass(context, arguments[0])) - ThrowMsg(InvalidArgumentException, "1st argument is not contact object."); - - if (!JSValueIsString(context, arguments[1])) - ThrowMsg(InvalidArgumentException, "2nd argument is not string."); + if (!JSValueIsString(context, arguments[0])) + ThrowMsg(InvalidArgumentException, "1st argument is not string."); } Catch(Exception ) { LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); } - ContactPtr contact; - string format; + string id; ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try { - contact = converter->toContact(arguments[0]); - format = converter->toString(arguments[1]); + 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"); } - string vCard; + ContactPtr contact; Try { - vCard = addressBook->convertToString(contact, format); + contact = addressBook->get(id); } Catch(UnsupportedException) { LogError("Error on platform : " << _rethrown_exception.GetMessage()); return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Unsupported format"); @@ -313,7 +286,7 @@ JSValueRef JSAddressBook::convertToString(JSContextRef context, JSValueRef result; Try { - result = converter->toJSValueRef(vCard); + result = converter->toJSValueRef(contact); } Catch(Exception) { LogError("Error on conversion : " << _rethrown_exception.GetMessage()); return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); @@ -330,7 +303,7 @@ JSValueRef JSAddressBook::add(JSContextRef context, JSValueRef* exception) { LogDebug("entered"); - IAddressBookPtr addressBook; + AddressBookPtr addressBook; JSContextRef gContext; AddressBookController *controller; @@ -362,33 +335,33 @@ JSValueRef JSAddressBook::add(JSContextRef context, return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); } - ContactPropertiesPtr contactProperties; + ContactPtr contact; ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try { - contactProperties = converter->toContactProperties(arguments[0]); + contact = converter->toContact(arguments[0]); } Catch(Exception) { LogError("Error on conversion : " << _rethrown_exception.GetMessage()); return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); } - ContactPtr contact(NULL); Try { - contact = addressBook->add(contactProperties); + addressBook->add(contact); } 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(contact); - } Catch(Exception) { - LogError("Error on conversion : " << _rethrown_exception.GetMessage()); - return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); - } +// JSValueRef result; +// Try { +// result = converter->toJSValueRef(contact); +// } Catch(Exception) { +// LogError("Error on conversion : " << _rethrown_exception.GetMessage()); +// return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); +// } +// return result; - return result; + return JSValueMakeUndefined(context); } JSValueRef JSAddressBook::addBatch(JSContextRef context, @@ -399,7 +372,7 @@ JSValueRef JSAddressBook::addBatch(JSContextRef context, JSValueRef* exception) { LogDebug("entered"); - IAddressBookPtr addressBook; + AddressBookPtr addressBook; JSContextRef gContext; AddressBookController *controller; @@ -423,19 +396,19 @@ JSValueRef JSAddressBook::addBatch(JSContextRef context, if (argumentCount < 1 || argumentCount > 3) ThrowMsg(InvalidArgumentException, "Wrong arguments count."); - if (!JSIsArrayValue(context, arguments[0])) + if (!JSValueIsObject(context, arguments[0])) ThrowMsg(InvalidArgumentException, "1st argument is not array."); if (argumentCount >= 2) { - if (!validator->isCallback(arguments[1])) - ThrowMsg(InvalidArgumentException, "2nd argument is not function."); + if (!validator->isCallback(arguments[1]) && !JSValueIsNull(context, arguments[1])) + ThrowMsg(InvalidArgumentException, "2nd argument is neither function nor null."); } if (argumentCount >= 3) { - if (!validator->isCallback(arguments[2])) - ThrowMsg(InvalidArgumentException, "3rd argument is not function."); + if (!validator->isCallback(arguments[2]) && !JSValueIsNull(context, arguments[2])) + ThrowMsg(InvalidArgumentException, "3rd argument is neither function nor null."); } } Catch(Exception ) { @@ -448,14 +421,20 @@ JSValueRef JSAddressBook::addBatch(JSContextRef context, JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); if(argumentCount >= 2) - callbackManager->setOnSuccess(arguments[1]); + { + if(!JSValueIsNull(context, arguments[1])) + callbackManager->setOnSuccess(arguments[1]); + } if(argumentCount >= 3) - callbackManager->setOnError(arguments[2]); + { + if(!JSValueIsNull(context, arguments[2])) + callbackManager->setOnError(arguments[2]); + } EventAddressBookAddBatchPtr dplEvent(new EventAddressBookAddBatch()); Try { - dplEvent->setContactProperties(converter->toContactPropertiesArray(arguments[0])); + dplEvent->setContacts(converter->toContactArray(arguments[0])); } Catch(ConversionException) { LogError("Error on conversion : " << _rethrown_exception.GetMessage()); return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); @@ -487,7 +466,7 @@ JSValueRef JSAddressBook::update(JSContextRef context, JSValueRef* exception) { LogDebug("entered"); - IAddressBookPtr addressBook; + AddressBookPtr addressBook; JSContextRef gContext; AddressBookController *controller; @@ -548,7 +527,7 @@ JSValueRef JSAddressBook::updateBatch(JSContextRef context, JSValueRef* exception) { LogDebug("entered"); - IAddressBookPtr addressBook; + AddressBookPtr addressBook; JSContextRef gContext; AddressBookController *controller; @@ -572,20 +551,21 @@ JSValueRef JSAddressBook::updateBatch(JSContextRef context, if (argumentCount < 1 || argumentCount > 3) ThrowMsg(InvalidArgumentException, "Wrong arguments count."); - if (!JSIsArrayValue(context, arguments[0])) + if (!JSValueIsObject(context, arguments[0])) ThrowMsg(InvalidArgumentException, "1st argument is not array."); if (argumentCount >= 2) { - if (!validator->isCallback(arguments[1])) - ThrowMsg(InvalidArgumentException, "2nd argument is not function."); + if (!validator->isCallback(arguments[1]) && !JSValueIsNull(context, arguments[1])) + ThrowMsg(InvalidArgumentException, "2nd argument is neither function nor null."); } if (argumentCount >= 3) { - if (!validator->isCallback(arguments[2])) - ThrowMsg(InvalidArgumentException, "3rd argument is not function."); + if (!validator->isCallback(arguments[2]) && !JSValueIsNull(context, arguments[2])) + ThrowMsg(InvalidArgumentException, "3rd argument is neither function nor null."); } + } Catch(Exception ) { LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); @@ -596,10 +576,16 @@ JSValueRef JSAddressBook::updateBatch(JSContextRef context, JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); if(argumentCount >= 2) - callbackManager->setOnSuccess(arguments[1]); + { + if(!JSValueIsNull(context, arguments[1])) + callbackManager->setOnSuccess(arguments[1]); + } if(argumentCount >= 3) - callbackManager->setOnError(arguments[2]); + { + if(!JSValueIsNull(context, arguments[2])) + callbackManager->setOnError(arguments[2]); + } EventAddressBookUpdateBatchPtr dplEvent(new EventAddressBookUpdateBatch()); Try { @@ -635,7 +621,7 @@ JSValueRef JSAddressBook::remove(JSContextRef context, JSValueRef* exception) { LogDebug("entered"); - IAddressBookPtr addressBook; + AddressBookPtr addressBook; JSContextRef gContext; AddressBookController *controller; @@ -699,7 +685,7 @@ JSValueRef JSAddressBook::removeBatch(JSContextRef context, JSValueRef* exception) { LogDebug("entered"); - IAddressBookPtr addressBook; + AddressBookPtr addressBook; JSContextRef gContext; AddressBookController *controller; @@ -723,20 +709,21 @@ JSValueRef JSAddressBook::removeBatch(JSContextRef context, if (argumentCount < 1 || argumentCount > 3) ThrowMsg(InvalidArgumentException, "Wrong arguments count."); - if (!JSIsArrayValue(context, arguments[0])) + if (!JSValueIsObject(context, arguments[0])) ThrowMsg(InvalidArgumentException, "1st argument is not array."); if (argumentCount >= 2) { - if (!validator->isCallback(arguments[1])) - ThrowMsg(InvalidArgumentException, "2nd argument is not function."); + if (!validator->isCallback(arguments[1]) && !JSValueIsNull(context, arguments[1])) + ThrowMsg(InvalidArgumentException, "2nd argument is neither function nor null."); } if (argumentCount >= 3) { - if (!validator->isCallback(arguments[2])) - ThrowMsg(InvalidArgumentException, "3rd argument is not function."); + if (!validator->isCallback(arguments[2]) && !JSValueIsNull(context, arguments[2])) + ThrowMsg(InvalidArgumentException, "3rd argument is neither function nor null."); } + } Catch(Exception ) { LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); @@ -747,10 +734,16 @@ JSValueRef JSAddressBook::removeBatch(JSContextRef context, JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); if(argumentCount >= 2) - callbackManager->setOnSuccess(arguments[1]); + { + if(!JSValueIsNull(context, arguments[1])) + callbackManager->setOnSuccess(arguments[1]); + } if(argumentCount >= 3) - callbackManager->setOnError(arguments[2]); + { + if(!JSValueIsNull(context, arguments[2])) + callbackManager->setOnError(arguments[2]); + } EventAddressBookRemoveBatchPtr dplEvent(new EventAddressBookRemoveBatch()); Try { @@ -786,7 +779,7 @@ JSValueRef JSAddressBook::find(JSContextRef context, JSValueRef* exception) { LogDebug("entered"); - IAddressBookPtr addressBook; + AddressBookPtr addressBook; JSContextRef gContext; AddressBookController *controller; @@ -815,20 +808,20 @@ JSValueRef JSAddressBook::find(JSContextRef context, if (argumentCount >= 2) { - if (!validator->isCallback(arguments[1])) - ThrowMsg(InvalidArgumentException, "2nd argument is not function."); + if (!validator->isCallback(arguments[1]) && !JSValueIsNull(context, arguments[1])) + ThrowMsg(InvalidArgumentException, "2nd argument is neither function nor null."); } if (argumentCount >= 3) { if (!JSValueIsObject(context, arguments[2]) && !JSValueIsNull(context, arguments[2])) - ThrowMsg(InvalidArgumentException, "3rd argument is not object nor null."); + ThrowMsg(InvalidArgumentException, "3rd argument is neither object nor null."); } if (argumentCount >= 4) { if (!JSValueIsObject(context, arguments[3]) && !JSValueIsNull(context, arguments[3])) - ThrowMsg(InvalidArgumentException, "4th argument is not object nor null."); + ThrowMsg(InvalidArgumentException, "4th argument is neither object nor null."); } } Catch(Exception ) { LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); @@ -838,19 +831,30 @@ JSValueRef JSAddressBook::find(JSContextRef context, JSCallbackManagerPtr callbackManager = JSCallbackManager::createObject(gContext); callbackManager->setOnSuccess(arguments[0]); + if (argumentCount >= 2) - callbackManager->setOnError(arguments[1]); + { + if(!JSValueIsNull(context, arguments[1])) + callbackManager->setOnError(arguments[1]); + } ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); FilterConverterFactory::ConverterType filterConverter = FilterConverterFactory::getConverter(context); EventAddressBookFindPtr dplEvent(new EventAddressBookFind()); Try { - if (argumentCount >= 3 && !JSValueIsNull(context, arguments[2])) - dplEvent->setFilter(filterConverter->toFilter(arguments[2])); + if (argumentCount >= 3) + { + if(!JSValueIsNull(context, arguments[2])) + dplEvent->setFilter(filterConverter->toFilter(arguments[2])); + } + + if (argumentCount >= 4) + { + if(!JSValueIsNull(context, arguments[3])) + dplEvent->setSortMode(filterConverter->toSortMode(arguments[3])); + } - if (argumentCount >= 4 && !JSValueIsNull(context, arguments[3])) - dplEvent->setSortModes(filterConverter->toSortModeArray(arguments[3])); } Catch(Exception) { LogError("Error on conversion : " << _rethrown_exception.GetMessage()); return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); @@ -882,7 +886,7 @@ JSValueRef JSAddressBook::addChangeListener(JSContextRef context, JSValueRef* exception) { LogDebug("entered"); - IAddressBookPtr addressBook; + AddressBookPtr addressBook; JSContextRef gContext; AddressBookController *controller; @@ -911,9 +915,10 @@ JSValueRef JSAddressBook::addChangeListener(JSContextRef context, if (argumentCount >= 2) { - if (!validator->isCallback(arguments[1])) - ThrowMsg(InvalidArgumentException, "2nd argument is not function."); + if (!validator->isCallback(arguments[1]) && !JSValueIsNull(context, arguments[1])) + ThrowMsg(InvalidArgumentException, "2nd argument is neither function or null."); } + } Catch(Exception ) { LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); @@ -967,7 +972,10 @@ JSValueRef JSAddressBook::addChangeListener(JSContextRef context, callbackManager->setOnContactsDeleted(oncontactsdeleted); callbackManager->setOnAddressBookReset(onaddressbookreset); if(argumentCount >= 2) - callbackManager->setOnError(arguments[1]); + { + if(!JSValueIsNull(context, arguments[1])) + callbackManager->setOnError(arguments[1]); + } EventAddressBookChangeListenerEmitterPtr emitter(new EventAddressBookChangeListenerEmitter()); @@ -993,7 +1001,7 @@ JSValueRef JSAddressBook::removeChangeListener(JSContextRef context, JSValueRef* exception) { LogDebug("entered"); - IAddressBookPtr addressBook; + AddressBookPtr addressBook; JSContextRef gContext; AddressBookController *controller; @@ -1042,34 +1050,6 @@ JSValueRef JSAddressBook::removeChangeListener(JSContextRef context, return JSValueMakeUndefined(context); } -JSValueRef JSAddressBook::getProperty(JSContextRef context, - JSObjectRef object, - JSStringRef jsPropertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - Try - { - std::string propertyName = converter->toString(jsPropertyName); - IAddressBookPtr addressBook = getPrivData(object); - if (propertyName == TIZEN_ADDRESS_BOOK_TYPE) { - if (IAddressBook::SIMBook == addressBook->getType()) { - return converter->toJSValueRef(0); - } else { - return converter->toJSValueRef(1); - } - } else if (propertyName == TIZEN_ADDRESS_BOOK_NAME) { - return converter->toJSValueRef(addressBook->getName()); - } - } - Catch(Exception) - { - LogError("error during getting property"); - } - return JSValueMakeUndefined(context); -} - } // Contact } // Tizen1_0 } // TizenApis diff --git a/src/standards/Tizen/Contact/JSAddressBook.h b/src/standards/Tizen/Contact/JSAddressBook.h index 0971fe3..a110017 100755 --- a/src/standards/Tizen/Contact/JSAddressBook.h +++ b/src/standards/Tizen/Contact/JSAddressBook.h @@ -33,7 +33,7 @@ namespace Tizen1_0 { namespace Contact { typedef WrtDeviceApis::CommonsJavaScript::PrivateObject - JSAddressBookPriv; + JSAddressBookPriv; class JSAddressBook { @@ -45,7 +45,7 @@ public: static bool isObjectOfClass(JSContextRef context, JSValueRef value); - static TizenApis::Api::Contact::IAddressBookPtr getAddressBook(JSContextRef context, JSValueRef value); + static TizenApis::Api::Contact::AddressBookPtr getAddressBook(JSContextRef context, JSValueRef value); private: /** @@ -58,14 +58,6 @@ private: */ static void Finalize(JSObjectRef object); - /** - * Getter for all properties - */ - static JSValueRef getProperty(JSContextRef context, - JSObjectRef object, - JSStringRef jsPropertyName, - JSValueRef* exception); - static JSClassDefinition m_classInfo; static JSStaticFunction m_function[]; @@ -74,16 +66,24 @@ private: static JSClassRef m_jsClassRef; - static TizenApis::Api::Contact::IAddressBookPtr getPrivData(JSObjectRef object); + static TizenApis::Api::Contact::AddressBookPtr getPrivData(JSObjectRef object); - static JSValueRef convertFromString(JSContextRef context, + static JSValueRef getId(JSContextRef context, JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], + 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 convertToString(JSContextRef context, + static JSValueRef get(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, diff --git a/src/standards/Tizen/Contact/JSAddressBookArray.cpp b/src/standards/Tizen/Contact/JSAddressBookArray.cpp index 2de5b51..7fb106e 100755 --- a/src/standards/Tizen/Contact/JSAddressBookArray.cpp +++ b/src/standards/Tizen/Contact/JSAddressBookArray.cpp @@ -99,7 +99,6 @@ JSValueRef JSAddressBookArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); Try { JSAddressBookArrayPriv* priv = @@ -107,7 +106,7 @@ JSValueRef JSAddressBookArray::getLength(JSContextRef context, if (!priv) { Throw(WrtDeviceApis::Commons::NullPointerException); } - IAddressBookArrayPtr addressBooks = priv->getObject(); + AddressBookArrayPtr addressBooks = priv->getObject(); if (addressBooks) { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); @@ -122,7 +121,7 @@ JSValueRef JSAddressBookArray::getLength(JSContextRef context, } JSObjectRef JSAddressBookArray::createArray(JSContextRef context, - const IAddressBookArrayPtr &addressBooks) + const AddressBookArrayPtr &addressBooks) { JSAddressBookArrayPriv *priv = new JSAddressBookArrayPriv(context, addressBooks); return JSObjectMake(context, getClassRef(), priv); @@ -138,7 +137,7 @@ bool JSAddressBookArray::isObjectOfClass(JSContextRef context, JSValueRef value) return JSValueIsObjectOfClass(context, value, getClassRef()); } -IAddressBookArrayPtr JSAddressBookArray::getAddressBookArray(JSContextRef context, JSValueRef value) +AddressBookArrayPtr JSAddressBookArray::getAddressBookArray(JSContextRef context, JSValueRef value) { if (!isObjectOfClass(context, value)) { Throw(WrtDeviceApis::Commons::InvalidArgumentException); @@ -165,12 +164,10 @@ JSClassRef JSAddressBookArray::getClassRef() void JSAddressBookArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSAddressBookArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSAddressBookArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -181,7 +178,6 @@ bool JSAddressBookArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -192,7 +188,7 @@ bool JSAddressBookArray::hasProperty(JSContextRef context, if (!priv) { Throw(WrtDeviceApis::Commons::NullPointerException); } - IAddressBookArrayPtr addressBooks = priv->getObject(); + AddressBookArrayPtr addressBooks = priv->getObject(); if (index < addressBooks->size()) { return true; } @@ -209,7 +205,6 @@ JSValueRef JSAddressBookArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -220,9 +215,9 @@ JSValueRef JSAddressBookArray::getProperty(JSContextRef context, if (!priv) { Throw(WrtDeviceApis::Commons::NullPointerException); } - IAddressBookArrayPtr addressBooks = priv->getObject(); + AddressBookArrayPtr addressBooks = priv->getObject(); if (index < addressBooks->size()) { - IAddressBookPtr result = addressBooks->at(index); + AddressBookPtr result = addressBooks->at(index); if (result) { return converter->toJSValueRef(result); } @@ -241,13 +236,12 @@ bool JSAddressBookArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try { size_t index = converter->toSizeT(propertyName); - IAddressBookPtr addressBook; + AddressBookPtr addressBook; if (!JSValueIsUndefined(context, value)) { addressBook = converter->toAddressBook(value); } @@ -256,7 +250,7 @@ bool JSAddressBookArray::setProperty(JSContextRef context, if (!priv) { Throw(WrtDeviceApis::Commons::NullPointerException); } - IAddressBookArrayPtr addressBooks = priv->getObject(); + AddressBookArrayPtr addressBooks = priv->getObject(); if (!addressBooks) { Throw(WrtDeviceApis::Commons::NullPointerException); } @@ -281,17 +275,16 @@ JSValueRef JSAddressBookArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { - IAddressBookArrayPtr addressBooks = IAddressBookArrayPtr(new IAddressBookArray()); + AddressBookArrayPtr addressBooks = AddressBookArrayPtr(new AddressBookArray()); JSAddressBookArrayPriv *newPrivateObject = new JSAddressBookArrayPriv(context, addressBooks); JSValueRef result = JSObjectMake(context, getClassRef(), newPrivateObject); //copy current addressBooks JSAddressBookArrayPriv* priv = static_cast(JSObjectGetPrivate(thisObject)); - IAddressBookArrayPtr currentAddressBooks = priv->getObject(); + AddressBookArrayPtr currentAddressBooks = priv->getObject(); for (size_t i = 0; i < currentAddressBooks->size(); ++i) { addressBooks->push_back(currentAddressBooks->at(i)); } @@ -327,7 +320,6 @@ JSValueRef JSAddressBookArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -336,7 +328,7 @@ JSValueRef JSAddressBookArray::join(JSContextRef context, ContactConverterFactory::getConverter(context); JSAddressBookArrayPriv* priv = static_cast(JSObjectGetPrivate(thisObject)); - IAddressBookArrayPtr currentAddressBooks = priv->getObject(); + AddressBookArrayPtr currentAddressBooks = priv->getObject(); if (argumentCount > 0 && JSValueIsString(context, arguments[0])) { separator = converter->toString(arguments[0]); } @@ -363,16 +355,15 @@ JSValueRef JSAddressBookArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); JSAddressBookArrayPriv* priv = static_cast(JSObjectGetPrivate(thisObject)); - IAddressBookArrayPtr currentAddressBooks = priv->getObject(); + AddressBookArrayPtr currentAddressBooks = priv->getObject(); if (currentAddressBooks->size() > 0) { - IAddressBookPtr result = currentAddressBooks->at( + AddressBookPtr result = currentAddressBooks->at( currentAddressBooks->size() - 1); currentAddressBooks->pop_back(); return converter->toJSValueRef(result); @@ -392,14 +383,13 @@ JSValueRef JSAddressBookArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); JSAddressBookArrayPriv* priv = static_cast(JSObjectGetPrivate(thisObject)); - IAddressBookArrayPtr currentAddressBooks = priv->getObject(); + AddressBookArrayPtr currentAddressBooks = priv->getObject(); for (size_t i = 0; i < argumentCount; ++i) { currentAddressBooks->push_back(converter->toAddressBook(arguments[i])); } @@ -419,14 +409,13 @@ JSValueRef JSAddressBookArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); JSAddressBookArrayPriv* priv = static_cast(JSObjectGetPrivate(thisObject)); - IAddressBookArrayPtr currentAddressBooks = priv->getObject(); + AddressBookArrayPtr currentAddressBooks = priv->getObject(); std::reverse(currentAddressBooks->begin(), currentAddressBooks->end()); return thisObject; } @@ -444,16 +433,15 @@ JSValueRef JSAddressBookArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); JSAddressBookArrayPriv* priv = static_cast(JSObjectGetPrivate(thisObject)); - IAddressBookArrayPtr currentAddressBooks = priv->getObject(); + AddressBookArrayPtr currentAddressBooks = priv->getObject(); if (currentAddressBooks->size() > 0) { - IAddressBookPtr result = currentAddressBooks->at(0); + AddressBookPtr result = currentAddressBooks->at(0); currentAddressBooks->erase(currentAddressBooks->begin()); return converter->toJSValueRef(result); } @@ -472,7 +460,6 @@ JSValueRef JSAddressBookArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -480,7 +467,7 @@ JSValueRef JSAddressBookArray::slice(JSContextRef context, } ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - IAddressBookArrayPtr addressBooks = IAddressBookArrayPtr(new IAddressBookArray()); + AddressBookArrayPtr addressBooks = AddressBookArrayPtr(new AddressBookArray()); JSAddressBookArrayPriv *newPrivateObject = new JSAddressBookArrayPriv( context, addressBooks); @@ -490,7 +477,7 @@ JSValueRef JSAddressBookArray::slice(JSContextRef context, //copy current addressBooks JSAddressBookArrayPriv* priv = static_cast(JSObjectGetPrivate(thisObject)); - IAddressBookArrayPtr currentAddressBooks = priv->getObject(); + AddressBookArrayPtr currentAddressBooks = priv->getObject(); std::size_t first = converter->toSizeT(arguments[0]); std::size_t last = currentAddressBooks->size() - 1; if (argumentCount > 1) { @@ -522,14 +509,13 @@ JSValueRef JSAddressBookArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); JSAddressBookArrayPriv* priv = static_cast(JSObjectGetPrivate(thisObject)); - IAddressBookArrayPtr currentAddressBooks = priv->getObject(); + AddressBookArrayPtr currentAddressBooks = priv->getObject(); std::sort(currentAddressBooks->begin(), currentAddressBooks->end()); return thisObject; } @@ -547,7 +533,6 @@ JSValueRef JSAddressBookArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -558,7 +543,6 @@ JSValueRef JSAddressBookArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -569,7 +553,6 @@ JSValueRef JSAddressBookArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -580,7 +563,6 @@ JSValueRef JSAddressBookArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/JSAddressBookArray.h b/src/standards/Tizen/Contact/JSAddressBookArray.h index 3c635b9..cc5d779 100755 --- a/src/standards/Tizen/Contact/JSAddressBookArray.h +++ b/src/standards/Tizen/Contact/JSAddressBookArray.h @@ -32,7 +32,7 @@ namespace TizenApis { namespace Tizen1_0 { namespace Contact { -typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT::Type JSAddressBookArrayPriv; +typedef WrtDeviceApis::CommonsJavaScript::PrivateObjectT::Type JSAddressBookArrayPriv; class JSAddressBookArray { @@ -43,11 +43,11 @@ public: static JSClassRef getClassRef(); static JSObjectRef createArray(JSContextRef context, - const TizenApis::Api::Contact::IAddressBookArrayPtr &anniversaries); + const TizenApis::Api::Contact::AddressBookArrayPtr &anniversaries); static bool isObjectOfClass(JSContextRef context, JSValueRef value); - static TizenApis::Api::Contact::IAddressBookArrayPtr getAddressBookArray(JSContextRef context, JSValueRef value); + static TizenApis::Api::Contact::AddressBookArrayPtr getAddressBookArray(JSContextRef context, JSValueRef value); private: diff --git a/src/standards/Tizen/Contact/JSAddressBookChangeCallbackManager.cpp b/src/standards/Tizen/Contact/JSAddressBookChangeCallbackManager.cpp index 4fa99d6..ca2fbf4 100755 --- a/src/standards/Tizen/Contact/JSAddressBookChangeCallbackManager.cpp +++ b/src/standards/Tizen/Contact/JSAddressBookChangeCallbackManager.cpp @@ -30,8 +30,6 @@ namespace Contact { JSAddressBookChangeCallbackManagerPtr JSAddressBookChangeCallbackManager::createObject(JSContextRef context) { - ////LogDebug("entered"); - return JSAddressBookChangeCallbackManagerPtr( new JSAddressBookChangeCallbackManager(context) ); } @@ -49,8 +47,6 @@ JSAddressBookChangeCallbackManager::JSAddressBookChangeCallbackManager(JSContext m_context(context), m_object(NULL) { - //LogDebug("entered"); - setOnContactsAdded(onContactsAdded); setOnContactsUpdated(onContactsUpdated); setOnContactsDeleted(onContactsDeleted); @@ -60,8 +56,6 @@ JSAddressBookChangeCallbackManager::JSAddressBookChangeCallbackManager(JSContext JSAddressBookChangeCallbackManager::~JSAddressBookChangeCallbackManager() { - //LogDebug("entered"); - if(m_onContactsAdded) { JSValueUnprotect(m_context, m_onContactsAdded); @@ -90,7 +84,6 @@ JSAddressBookChangeCallbackManager::~JSAddressBookChangeCallbackManager() void JSAddressBookChangeCallbackManager::setOnContactsAdded( JSValueRef onContactsAdded ) { - //LogDebug("entered"); if (onContactsAdded) { if (m_onContactsAdded != NULL) @@ -109,13 +102,11 @@ void JSAddressBookChangeCallbackManager::setOnContactsAdded( JSValueRef onContac JSValueRef JSAddressBookChangeCallbackManager::getOnContactsAdded() const { - //LogDebug("entered"); return m_onContactsAdded; } void JSAddressBookChangeCallbackManager::setOnContactsUpdated( JSValueRef onContactsUpdated ) { - //LogDebug("entered"); if (onContactsUpdated) { if (m_onContactsUpdated != NULL) @@ -134,13 +125,11 @@ void JSAddressBookChangeCallbackManager::setOnContactsUpdated( JSValueRef onCont JSValueRef JSAddressBookChangeCallbackManager::getOnContactsUpdated() const { - //LogDebug("entered"); return m_onContactsUpdated; } void JSAddressBookChangeCallbackManager::setOnContactsDeleted( JSValueRef onContactsDeleted ) { - //LogDebug("entered"); if (onContactsDeleted) { if (m_onContactsDeleted != NULL) @@ -159,13 +148,11 @@ void JSAddressBookChangeCallbackManager::setOnContactsDeleted( JSValueRef onCont JSValueRef JSAddressBookChangeCallbackManager::getOnContactsDeleted() const { - //LogDebug("entered"); return m_onContactsDeleted; } void JSAddressBookChangeCallbackManager::setOnAddressBookReset( JSValueRef onAddressBookReset ) { - //LogDebug("entered"); if (onAddressBookReset) { if (m_onAddressBookReset != NULL) @@ -184,13 +171,11 @@ void JSAddressBookChangeCallbackManager::setOnAddressBookReset( JSValueRef onAdd JSValueRef JSAddressBookChangeCallbackManager::getOnAddressBookReset() const { - //LogDebug("entered"); return m_onAddressBookReset; } void JSAddressBookChangeCallbackManager::setOnError( JSValueRef onError ) { - //LogDebug("entered"); if (onError) { if (m_onError != NULL) @@ -209,31 +194,26 @@ void JSAddressBookChangeCallbackManager::setOnError( JSValueRef onError ) JSValueRef JSAddressBookChangeCallbackManager::getOnError() const { - //LogDebug("entered"); return m_onError; } void JSAddressBookChangeCallbackManager::setContext( JSContextRef context ) { - //LogDebug("entered"); m_context = context; } void JSAddressBookChangeCallbackManager::setObject( JSObjectRef object ) { - //LogDebug("entered"); m_object = object; } JSObjectRef JSAddressBookChangeCallbackManager::getObject() const { - //LogDebug("entered"); return m_object; } void JSAddressBookChangeCallbackManager::callOnContactsAdded( JSValueRef contacts ) { - //LogDebug("entered"); if ( m_onContactsAdded == NULL ) { //LogDebug("oncontactsadded callback is not set"); @@ -245,7 +225,6 @@ void JSAddressBookChangeCallbackManager::callOnContactsAdded( JSValueRef contact void JSAddressBookChangeCallbackManager::callOnContactsUpdated( JSValueRef contacts ) { - //LogDebug("entered"); if ( m_onContactsUpdated == NULL ) { //LogDebug("oncontactsupdated callback is not set"); @@ -257,7 +236,6 @@ void JSAddressBookChangeCallbackManager::callOnContactsUpdated( JSValueRef conta void JSAddressBookChangeCallbackManager::callOnContactsDeleted( JSValueRef contactIds ) { - //LogDebug("entered"); if ( m_onContactsDeleted == NULL ) { //LogDebug("oncontactsdeleted callback is not set"); @@ -269,7 +247,6 @@ void JSAddressBookChangeCallbackManager::callOnContactsDeleted( JSValueRef conta void JSAddressBookChangeCallbackManager::callOnAddressBookReset() { - //LogDebug("entered"); if ( m_onAddressBookReset == NULL ) { //LogDebug("onaddressbookreset callback is not set"); @@ -280,7 +257,6 @@ void JSAddressBookChangeCallbackManager::callOnAddressBookReset() void JSAddressBookChangeCallbackManager::callOnError( JSValueRef error ) { - //LogDebug("entered"); if ( m_onError == NULL ) { //LogDebug("Error callback is not set"); @@ -292,7 +268,6 @@ void JSAddressBookChangeCallbackManager::callOnError( JSValueRef error ) void JSAddressBookChangeCallbackManager::makeCallback(JSContextRef context, JSObjectRef object, JSObjectRef callback, const char *szName, JSValueRef argv[], unsigned argc) { - //LogDebug("entered"); if (callback == NULL) { diff --git a/src/standards/Tizen/Contact/JSContact.cpp b/src/standards/Tizen/Contact/JSContact.cpp index 9241c87..6fc935a 100755 --- a/src/standards/Tizen/Contact/JSContact.cpp +++ b/src/standards/Tizen/Contact/JSContact.cpp @@ -23,33 +23,52 @@ #include #include -#include +#include +#include +#include +#include +#include +//#include +#include "plugin_config.h" #include "ContactConverter.h" -#include "JSContactProperties.h" #include "JSContact.h" #define FILTER_CLASS_NAME "Contact" -#define CONTACT_ATTR_ID "id" -#define CONTACT_ATTR_READ_ONLY "readOnly" -#define CONTACT_ATTR_LAST_UPDATED "lastUpdated" +#define CONTACT_ATTR_ID "id" +#define CONTACT_ATTR_LAST_UPDATED "lastUpdated" +#define CONTACT_ATTR_NAME "name" +#define CONTACT_ATTR_ACCOUNT "account" +#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_ORGANIZATION "organization" +#define CONTACT_ATTR_NOTES "notes" +#define CONTACT_ATTR_URLS "urls" +#define CONTACT_ATTR_LAST_UPDATED "lastUpdated" +#define CONTACT_ATTR_IS_FAVORITE "isFavorite" +#define CONTACT_ATTR_RINGTONE_URI "ringtoneURI" +#define CONTACT_ATTR_CATEGORIES "categories" +#define CONTACT_FUNC_CONVERT_TO_STRING "convertToString" namespace TizenApis { namespace Tizen1_0 { namespace Contact { +using namespace TizenApis::Commons; using namespace TizenApis::Api::Contact; - -using TizenApis::Api::Contact::Contact; - -JSClassRef JSContact::m_classRef = NULL; +using namespace WrtDeviceApis::Commons; +using namespace WrtDeviceApis::CommonsJavaScript; JSClassDefinition JSContact::m_classInfo = { 0, kJSClassAttributeNone, FILTER_CLASS_NAME, - JSContactProperties::getClassRef(), + NULL, m_property, m_functions, Initialize, @@ -59,24 +78,40 @@ JSClassDefinition JSContact::m_classInfo = NULL, //SetProperty, NULL, //DeleteProperty, NULL, //getPropertyNames, - NULL, - NULL, - NULL, + NULL, //CallAsFunction, + constructor, //CallAsConstructor, + hasInstance, //HasInstance, NULL, //ConvertToType, }; JSStaticValue JSContact::m_property[] = { { CONTACT_ATTR_ID, getId, NULL, kJSPropertyAttributeReadOnly }, - { CONTACT_ATTR_READ_ONLY, getReadOnly, NULL, kJSPropertyAttributeReadOnly }, { CONTACT_ATTR_LAST_UPDATED, getLastUpdated, NULL, kJSPropertyAttributeReadOnly }, + { CONTACT_ATTR_NAME, getName, setName, kJSPropertyAttributeNone }, + { CONTACT_ATTR_ACCOUNT, getAccount, setAccount, 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_ORGANIZATION, getOrganization, setOrganization, kJSPropertyAttributeNone }, + { CONTACT_ATTR_NOTES, getNotes, setNotes, kJSPropertyAttributeNone }, + { CONTACT_ATTR_URLS, getUrls, setUrls, kJSPropertyAttributeNone }, + { CONTACT_ATTR_IS_FAVORITE, getIsFavorite, setIsFavorite, kJSPropertyAttributeNone }, + { CONTACT_ATTR_RINGTONE_URI, getRingtoneURI, setRingtoneURI, kJSPropertyAttributeNone }, + { CONTACT_ATTR_CATEGORIES, getCategories, setCategories, kJSPropertyAttributeNone }, { 0, 0, 0, 0 } }; JSStaticFunction JSContact::m_functions[] = { + { CONTACT_FUNC_CONVERT_TO_STRING, convertToString, kJSPropertyAttributeNone }, { 0, 0, 0 } }; +JSClassRef JSContact::m_classRef = JSClassCreate(&m_classInfo); + JSClassRef JSContact::getClassRef() { if (!m_classRef) { m_classRef = JSClassCreate(&m_classInfo); @@ -84,20 +119,6 @@ JSClassRef JSContact::getClassRef() { return m_classRef; } -JSValueRef JSContact::createJSObject(JSContextRef context - // FIXME - ) -{ - ContactPtr privateData = ContactPtr(new Contact()); - JSContactPriv *priv = new JSContactPriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; -} - bool JSContact::isObjectOfClass(JSContextRef context, JSValueRef value) { return JSValueIsObjectOfClass(context, value, getClassRef()); @@ -121,40 +142,158 @@ ContactPtr JSContact::getContact(JSContextRef context, JSValueRef value) void JSContact::Initialize(JSContextRef context, JSObjectRef object) { - assert(NULL != JSObjectGetPrivate(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) { - //delete (JSObjectGetPrivate(object)); + JSContactPriv *priv = static_cast(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(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; } ContactPtr JSContact::getPrivData(JSObjectRef object) { - LogDebug("entered"); JSContactPriv *priv = static_cast(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"); + 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"); + +// AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); +// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + JSContactPriv *priv = static_cast(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 > 2) + ThrowMsg(InvalidArgumentException, "Wrong arguments count."); + + if (argumentCount == 1) + { + if (!JSValueIsObject(gContext, arguments[0]) && !JSValueIsNull(gContext, arguments[0])) + ThrowMsg(InvalidArgumentException, "1st argument is not object."); + } + + if (argumentCount == 2) + { + if (!JSValueIsString(gContext, arguments[0])) + ThrowMsg(InvalidArgumentException, "1st argument is not object."); + + if (!JSValueIsString(gContext, arguments[1])) + ThrowMsg(InvalidArgumentException, "2nd argument is not object."); + } + + } Catch(Exception ) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + return NULL; + } + + ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext); + + ContactPtr contact(NULL); + Try { + if(argumentCount == 1) + { + if(JSValueIsObject(gContext, arguments[0])) + contact = converter->toContactFromInit(arguments[0]); + } + + if(argumentCount == 2) + { + std::string stringRepresentation; // vCard string + std::string format; + + stringRepresentation = converter->toString(arguments[0]); + format = converter->toString(arguments[1]); + + contact = ContactFactory::getInstance().createContact(stringRepresentation, format); + } + + if(contact == NULL) + contact = ContactFactory::getInstance().createContact(); + + } Catch(Exception) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + return NULL; + } + + JSObjectRef jsobject; + + Try { + jsobject = createJSObject(gContext, contact); + } Catch(Exception) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + 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) { - LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactPtr contact = getPrivData(object); - return converter->toJSValueRef(contact->getId()); + if(!contact->getIdIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contact->getId()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -163,39 +302,132 @@ JSValueRef JSContact::getId(JSContextRef context, return JSValueMakeUndefined(context); } -JSValueRef JSContact::getReadOnly(JSContextRef 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::getName(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { - LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactPtr contact = getPrivData(object); - return converter->toJSValueRef(contact->getReadOnly()); + if(!contact->getNameIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contact->getName()); } 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); + 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::getLastUpdated(JSContextRef context, +JSValueRef JSContact::getAccount(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + Try + { + ContactConverterFactory::ConverterType converter = + ContactConverterFactory::getConverter(context); + ContactPtr contact = getPrivData(object); + if(!contact->getAccountIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contact->getAccount()); + } + Catch(WrtDeviceApis::Commons::Exception) + { + LogWarning("trying to get incorrect value"); + } + + return JSValueMakeUndefined(context); +} + +bool JSContact::setAccount(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef value, + JSValueRef* exception) +{ + Try + { + ContactPtr contact = getPrivData(object); + ContactConverterFactory::ConverterType converter = + ContactConverterFactory::getConverter(context); + contact->setAccount(converter->toContactAccount(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) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactPtr contact = getPrivData(object); - return converter->toJSValueRef(contact->getLastUpdated()); + return converter->toJSValueRef(contact->getAddresses()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -205,6 +437,583 @@ JSValueRef JSContact::getLastUpdated(JSContextRef context, 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); + 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); + 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::getOrganization(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + Try + { + ContactConverterFactory::ConverterType converter = + ContactConverterFactory::getConverter(context); + ContactPtr contact = getPrivData(object); + if(!contact->getOrganizationIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contact->getOrganization()); + } + Catch(WrtDeviceApis::Commons::Exception) + { + LogWarning("trying to get incorrect value"); + } + + return JSValueMakeUndefined(context); +} + +bool JSContact::setOrganization(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef value, + JSValueRef* exception) +{ + Try + { + ContactPtr contact = getPrivData(object); + ContactConverterFactory::ConverterType converter = + ContactConverterFactory::getConverter(context); + contact->setOrganization(converter->toContactOrganization(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::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); +} + +bool JSContact::setIsFavorite(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef value, + JSValueRef* exception) +{ + Try + { + ContactPtr contact = getPrivData(object); + ContactConverterFactory::ConverterType converter = + ContactConverterFactory::getConverter(context); + contact->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 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); + 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::getCategories(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + Try + { + ContactConverterFactory::ConverterType converter = + ContactConverterFactory::getConverter(context); + ContactPtr contact = getPrivData(object); + return converter->toJSValueRef(contact->getCategories()); + } + Catch(WrtDeviceApis::Commons::Exception) + { + LogWarning("trying to get incorrect value"); + } + + return JSValueMakeUndefined(context); +} + +bool JSContact::setCategories(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef value, + JSValueRef* exception) +{ + Try + { + ContactPtr contact = getPrivData(object); + ContactConverterFactory::ConverterType converter = + ContactConverterFactory::getConverter(context); + contact->setCategories(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(context, CONTACT_FUNCTION_API_CONVERT_TO_STRING); +// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + BasicValidator validator = BasicValidatorFactory::getValidator(context, exception); + Try { + if (argumentCount != 1) + ThrowMsg(InvalidArgumentException, "Wrong arguments count."); + + if (!JSValueIsString(context, arguments[0])) + ThrowMsg(InvalidArgumentException, "1st argument is not string."); + } Catch(Exception ) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + } + + std::string format; + + ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); + Try { + format = converter->toString(arguments[0]); + } Catch(Exception) { + LogError("Error on conversion : " << _rethrown_exception.GetMessage()); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + } + + std::string vCard; + Try { + vCard = contact->convertToString(format); + } Catch(UnsupportedException) { + LogError("Error on platform : " << _rethrown_exception.GetMessage()); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, "Unsupported format"); + } 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::TYPE_MISMATCH_ERROR, "Wrong arguments"); + } + + return result; +} + } // Contact } // Tizen1_0 } // TizenApis diff --git a/src/standards/Tizen/Contact/JSContact.h b/src/standards/Tizen/Contact/JSContact.h index 07cd388..7b67c4a 100755 --- a/src/standards/Tizen/Contact/JSContact.h +++ b/src/standards/Tizen/Contact/JSContact.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace TizenApis { namespace Tizen1_0 { @@ -43,10 +43,6 @@ public: */ static JSClassRef getClassRef(); - static JSValueRef createJSObject(JSContextRef context - // FIXME fix this value - ); - static bool isObjectOfClass(JSContextRef context, JSValueRef value); static TizenApis::Api::Contact::ContactPtr getContact(JSContextRef context, JSValueRef value); @@ -80,21 +76,190 @@ private: 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 getReadOnly(JSContextRef context, + static JSValueRef getLastUpdated(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); - static JSValueRef getLastUpdated(JSContextRef context, + 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 getAccount(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + + static bool setAccount(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 getOrganization(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + + static bool setOrganization(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 getIsFavorite(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + + static bool setIsFavorite(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 getCategories(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + + static bool setCategories(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); }; diff --git a/src/standards/Tizen/Contact/JSContactAccount.cpp b/src/standards/Tizen/Contact/JSContactAccount.cpp index 50d7ab0..a89e181 100755 --- a/src/standards/Tizen/Contact/JSContactAccount.cpp +++ b/src/standards/Tizen/Contact/JSContactAccount.cpp @@ -22,16 +22,17 @@ */ #include -#include +#include #include #include +//#include #include "ContactConverter.h" #include "JSContactAccount.h" #define ORGANIZATION_CLASS_NAME "ContactAccount" -#define CONTACT_ATTR_ACCOUNT_ID "accountId" -#define CONTACT_ATTR_CONTACT_URI "contactUri" +#define CONTACT_ATTR_ACCOUNT_SERVICE_ID "accountServiceId" +#define CONTACT_ATTR_CONTACT_URI "contactURI" namespace TizenApis { namespace Tizen1_0 { @@ -39,8 +40,8 @@ namespace Contact { using namespace TizenApis::Commons; using namespace TizenApis::Api::Contact; - -JSClassRef JSContactAccount::m_classRef = NULL; +using namespace WrtDeviceApis::Commons; +using namespace WrtDeviceApis::CommonsJavaScript; JSClassDefinition JSContactAccount::m_classInfo = { @@ -57,14 +58,14 @@ JSClassDefinition JSContactAccount::m_classInfo = NULL, //SetProperty, NULL, //DeleteProperty, NULL, //getPropertyNames, - NULL, - NULL, - NULL, + NULL, //CallAsFunction, + constructor, //CallAsConstructor, + hasInstance, //HasInstance, NULL, //ConvertToType, }; JSStaticValue JSContactAccount::m_property[] = { - { CONTACT_ATTR_ACCOUNT_ID, getAccountId, setAccountId, kJSPropertyAttributeNone }, + { CONTACT_ATTR_ACCOUNT_SERVICE_ID, getAccountServiceId, setAccountServiceId, kJSPropertyAttributeNone }, { CONTACT_ATTR_CONTACT_URI, getContactURI, setContactURI, kJSPropertyAttributeNone }, { 0, 0, 0, 0 } }; @@ -74,6 +75,8 @@ JSStaticFunction JSContactAccount::m_functions[] = { 0, 0, 0 } }; +JSClassRef JSContactAccount::m_classRef = JSClassCreate(&m_classInfo); + JSClassRef JSContactAccount::getClassRef() { if (!m_classRef) { m_classRef = JSClassCreate(&m_classInfo); @@ -81,22 +84,6 @@ JSClassRef JSContactAccount::getClassRef() { return m_classRef; } -JSValueRef JSContactAccount::createJSObject(JSContextRef context, - const std::string& accountId, - const std::string& contactURI) -{ - ContactAccountPtr privateData = ContactAccountPtr(new ContactAccount()); - privateData->setAccountId(accountId); - privateData->setContactURI(contactURI); - JSContactAccountPriv *priv = new JSContactAccountPriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; -} - bool JSContactAccount::isObjectOfClass(JSContextRef context, JSValueRef value) { return JSValueIsObjectOfClass(context, value, getClassRef()); @@ -120,17 +107,37 @@ ContactAccountPtr JSContactAccount::getContactAccount(JSContextRef context, JSVa void JSContactAccount::Initialize(JSContextRef context, JSObjectRef object) { - assert(NULL != JSObjectGetPrivate(object)); + if (!JSObjectGetPrivate(object)) + { + ContactAccountPtr account(new ContactAccount()); + JSContactAccountPriv *priv = new JSContactAccountPriv(context, ContactAccountPtr(account)); + if (!JSObjectSetPrivate(object, priv)) { + delete priv; + } + } } void JSContactAccount::Finalize(JSObjectRef object) { - //delete (JSObjectGetPrivate(object)); + JSContactAccountPriv *priv = static_cast(JSObjectGetPrivate(object)); + + if (priv != NULL) + delete (priv); +} + +JSObjectRef JSContactAccount::createJSObject(JSContextRef context, const ContactAccountPtr contactAccount) +{ + JSContactAccountPriv *priv = new JSContactAccountPriv(context, contactAccount); + JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; } ContactAccountPtr JSContactAccount::getPrivData(JSObjectRef object) { - //LogDebug("entered"); JSContactAccountPriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); @@ -142,18 +149,106 @@ ContactAccountPtr JSContactAccount::getPrivData(JSObjectRef object) return result; } -JSValueRef JSContactAccount::getAccountId(JSContextRef context, +JSObjectRef JSContactAccount::constructor(JSContextRef context, + JSObjectRef constructor, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LogDebug("entered"); + +// AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); +// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + JSContactAccountPriv *priv = static_cast(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 || argumentCount > 2) + 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]) && !JSValueIsNull(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; + } + + ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext); + + std::string accountServiceId; + std::string contactURI; + + Try { + accountServiceId = 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(argumentCount >= 2) + { + if(JSValueIsString(gContext, arguments[1])) + contactURI = 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; + } + + ContactAccountPtr contactAccount(new ContactAccount()); + contactAccount->setAccountServiceId(accountServiceId); + contactAccount->setContactURI(contactURI); + + JSObjectRef jsobject; + + Try { + jsobject = createJSObject(gContext, contactAccount); + } Catch(Exception) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + return NULL; + } + + return jsobject; +} + +bool JSContactAccount::hasInstance(JSContextRef context, + JSObjectRef constructor, + JSValueRef possibleInstance, + JSValueRef* exception) +{ + return JSValueIsObjectOfClass(context, possibleInstance, getClassRef()); +} + +JSValueRef JSContactAccount::getAccountServiceId(JSContextRef context, JSObjectRef object, JSStringRef propertyAccountId, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactAccountPtr organization = getPrivData(object); - return converter->toJSValueRef(organization->getAccountId()); + return converter->toJSValueRef(organization->getAccountServiceId()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -162,7 +257,7 @@ JSValueRef JSContactAccount::getAccountId(JSContextRef context, return JSValueMakeUndefined(context); } -bool JSContactAccount::setAccountId(JSContextRef context, +bool JSContactAccount::setAccountServiceId(JSContextRef context, JSObjectRef object, JSStringRef propertyAccountId, JSValueRef value, @@ -173,7 +268,7 @@ bool JSContactAccount::setAccountId(JSContextRef context, ContactAccountPtr organization = getPrivData(object); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - organization->setAccountId(converter->toString(value)); + organization->setAccountServiceId(converter->toString(value)); return true; } Catch(WrtDeviceApis::Commons::Exception) @@ -189,7 +284,6 @@ JSValueRef JSContactAccount::getContactURI(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = diff --git a/src/standards/Tizen/Contact/JSContactAccount.h b/src/standards/Tizen/Contact/JSContactAccount.h index 2d89785..77d5281 100755 --- a/src/standards/Tizen/Contact/JSContactAccount.h +++ b/src/standards/Tizen/Contact/JSContactAccount.h @@ -43,10 +43,6 @@ public: */ static JSClassRef getClassRef(); - static JSValueRef createJSObject(JSContextRef context, - const std::string& accountId, - const std::string& contactURI); - static bool isObjectOfClass(JSContextRef context, JSValueRef value); static TizenApis::Api::Contact::ContactAccountPtr getContactAccount(JSContextRef context, JSValueRef value); @@ -80,14 +76,27 @@ private: static JSClassRef m_classRef; + static JSObjectRef createJSObject(JSContextRef context, const TizenApis::Api::Contact::ContactAccountPtr contactAccount); + static TizenApis::Api::Contact::ContactAccountPtr getPrivData(JSObjectRef object); - static JSValueRef getAccountId(JSContextRef context, + 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 getAccountServiceId(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); - static bool setAccountId(JSContextRef context, + static bool setAccountServiceId(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, diff --git a/src/standards/Tizen/Contact/JSContactAddress.cpp b/src/standards/Tizen/Contact/JSContactAddress.cpp index b5bff3d..7108335 100755 --- a/src/standards/Tizen/Contact/JSContactAddress.cpp +++ b/src/standards/Tizen/Contact/JSContactAddress.cpp @@ -22,9 +22,10 @@ */ #include -#include +#include #include #include +//#include #include "ContactConverter.h" #include "JSContactAddress.h" #include "JSContactAddressTypeArray.h" @@ -45,8 +46,8 @@ namespace Contact { using namespace TizenApis::Commons; using namespace TizenApis::Api::Contact; - -JSClassRef JSContactAddress::m_classRef = NULL; +using namespace WrtDeviceApis::Commons; +using namespace WrtDeviceApis::CommonsJavaScript; JSClassDefinition JSContactAddress::m_classInfo = { @@ -63,9 +64,9 @@ JSClassDefinition JSContactAddress::m_classInfo = NULL, //SetProperty, NULL, //DeleteProperty, NULL, //getPropertyNames, - NULL, - NULL, - NULL, + NULL, //CallAsFunction, + constructor, //CallAsConstructor, + hasInstance, //HasInstance, NULL, //ConvertToType, }; @@ -85,6 +86,8 @@ 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); @@ -92,35 +95,6 @@ JSClassRef JSContactAddress::getClassRef() { return m_classRef; } -JSValueRef JSContactAddress::createJSObject(JSContextRef context, - const std::string country, - const std::string region, - const std::string county, - const std::string city, - const std::string streetAddress, - const std::string additionalInformation, - const std::string postalCode, - const ContactAddressTypeArrayPtr types) -{ - ContactAddressPtr privateData = ContactAddressPtr(new ContactAddress()); - - privateData->setCountry(country); - privateData->setRegion(region); - privateData->setCity(city); - privateData->setStreetAddress(streetAddress); - privateData->setAdditionalInformation(additionalInformation); - privateData->setPostalCode(postalCode); - privateData->setTypes(types); - - JSContactAddressPriv *priv = new JSContactAddressPriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; -} - bool JSContactAddress::isObjectOfClass(JSContextRef context, JSValueRef value) { return JSValueIsObjectOfClass(context, value, getClassRef()); @@ -144,17 +118,37 @@ ContactAddressPtr JSContactAddress::getContactAddress(JSContextRef context, JSVa void JSContactAddress::Initialize(JSContextRef context, JSObjectRef object) { - assert(NULL != JSObjectGetPrivate(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) { - //delete (JSObjectGetPrivate(object)); + JSContactAddressPriv *priv = static_cast(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(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; } ContactAddressPtr JSContactAddress::getPrivData(JSObjectRef object) { - //LogDebug("entered"); JSContactAddressPriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); @@ -166,18 +160,90 @@ ContactAddressPtr JSContactAddress::getPrivData(JSObjectRef object) return result; } +JSObjectRef JSContactAddress::constructor(JSContextRef context, + JSObjectRef constructor, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LogDebug("entered"); + +// AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); +// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + JSContactAddressPriv *priv = static_cast(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 (argumentCount == 1) + { + if (!JSValueIsObject(gContext, arguments[0]) && !JSValueIsNull(gContext, arguments[0])) + ThrowMsg(InvalidArgumentException, "1st argument is not object."); + } + + } Catch(Exception ) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + return NULL; + } + + ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext); + + ContactAddressPtr contactEmailAddress(new ContactAddress()); + + Try { + if(argumentCount == 1 && !JSValueIsNull(gContext, arguments[0])) + contactEmailAddress = converter->toContactAddressFromInit(arguments[0]); + } Catch(Exception) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + return NULL; + } + + 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 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) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactAddressPtr contactAddress = getPrivData(object); - return converter->toJSValueRef(contactAddress->getCountry()); + if(!contactAddress->getCountryIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contactAddress->getCountry()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -214,13 +280,15 @@ JSValueRef JSContactAddress::getRegion(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactAddressPtr contactAddress = getPrivData(object); - return converter->toJSValueRef(contactAddress->getRegion()); + if(!contactAddress->getRegionIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contactAddress->getRegion()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -256,13 +324,15 @@ JSValueRef JSContactAddress::getCity(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactAddressPtr contactAddress = getPrivData(object); - return converter->toJSValueRef(contactAddress->getCity()); + if(!contactAddress->getCityIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contactAddress->getCity()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -299,13 +369,15 @@ JSValueRef JSContactAddress::getStreetAddress(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactAddressPtr contactAddress = getPrivData(object); - return converter->toJSValueRef(contactAddress->getStreetAddress()); + if(!contactAddress->getStreetAddressIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contactAddress->getStreetAddress()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -342,13 +414,15 @@ JSValueRef JSContactAddress::getAdditionalInformation(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactAddressPtr contactAddress = getPrivData(object); - return converter->toJSValueRef(contactAddress->getAdditionalInformation()); + if(!contactAddress->getAdditionalInformationIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contactAddress->getAdditionalInformation()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -385,13 +459,15 @@ JSValueRef JSContactAddress::getPostalCode(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactAddressPtr contactAddress = getPrivData(object); - return converter->toJSValueRef(contactAddress->getPostalCode()); + if(!contactAddress->getPostalCodeIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contactAddress->getPostalCode()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -428,13 +504,13 @@ JSValueRef JSContactAddress::getTypes(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactAddressPtr contactAddress = getPrivData(object); - return JSContactAddressTypeArray::createArray(context, contactAddress->getTypes()); + + return converter->toJSValueRef(contactAddress->getTypes()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -455,11 +531,7 @@ bool JSContactAddress::setTypes(JSContextRef context, ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - - if(JSContactAddressTypeArray::isObjectOfClass(context, value)) - contactAddress->setTypes(converter->toContactAddressTypeArray(value)); // TODO to implement this function on converter - else - contactAddress->setTypes(JSContactAddressTypeArray::getContactAddressTypeArray(context, value)); + contactAddress->setTypes(converter->toContactAddressTypeArray(value)); return true; } diff --git a/src/standards/Tizen/Contact/JSContactAddress.h b/src/standards/Tizen/Contact/JSContactAddress.h index 9788954..6745747 100755 --- a/src/standards/Tizen/Contact/JSContactAddress.h +++ b/src/standards/Tizen/Contact/JSContactAddress.h @@ -44,16 +44,6 @@ public: */ static JSClassRef getClassRef(); - static JSValueRef createJSObject(JSContextRef context, - const std::string country = "", - const std::string region = "", - const std::string county = "", - const std::string city = "", - const std::string streetAddress = "", - const std::string additionalInformation = "", - const std::string postalCode = "", - const TizenApis::Api::Contact::ContactAddressTypeArrayPtr types = TizenApis::Api::Contact::ContactAddressTypeArrayPtr(new TizenApis::Api::Contact::ContactAddressTypeArray())); - static bool isObjectOfClass(JSContextRef context, JSValueRef value); static TizenApis::Api::Contact::ContactAddressPtr getContactAddress(JSContextRef context, JSValueRef value); @@ -87,8 +77,21 @@ private: 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, diff --git a/src/standards/Tizen/Contact/JSContactAddressArray.cpp b/src/standards/Tizen/Contact/JSContactAddressArray.cpp index 280e38f..24e6c74 100755 --- a/src/standards/Tizen/Contact/JSContactAddressArray.cpp +++ b/src/standards/Tizen/Contact/JSContactAddressArray.cpp @@ -99,7 +99,6 @@ JSValueRef JSContactAddressArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); Try { JSContactAddressArrayPriv* priv = @@ -165,12 +164,10 @@ ContactAddressArrayPtr JSContactAddressArray::getContactAddressArray(JSContextRe void JSContactAddressArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSContactAddressArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSContactAddressArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -181,7 +178,6 @@ bool JSContactAddressArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -209,7 +205,6 @@ JSValueRef JSContactAddressArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -241,7 +236,6 @@ bool JSContactAddressArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -281,7 +275,6 @@ JSValueRef JSContactAddressArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { ContactAddressArrayPtr contactAddresses = ContactAddressArrayPtr(new ContactAddressArray()); @@ -327,7 +320,6 @@ JSValueRef JSContactAddressArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -363,7 +355,6 @@ JSValueRef JSContactAddressArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -392,7 +383,6 @@ JSValueRef JSContactAddressArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -419,7 +409,6 @@ JSValueRef JSContactAddressArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -444,7 +433,6 @@ JSValueRef JSContactAddressArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -472,7 +460,6 @@ JSValueRef JSContactAddressArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -522,7 +509,6 @@ JSValueRef JSContactAddressArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -547,7 +533,6 @@ JSValueRef JSContactAddressArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -558,7 +543,6 @@ JSValueRef JSContactAddressArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -569,7 +553,6 @@ JSValueRef JSContactAddressArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -580,7 +563,6 @@ JSValueRef JSContactAddressArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/JSContactAddressTypeArray.cpp b/src/standards/Tizen/Contact/JSContactAddressTypeArray.cpp index 84673d1..d2f4b4a 100755 --- a/src/standards/Tizen/Contact/JSContactAddressTypeArray.cpp +++ b/src/standards/Tizen/Contact/JSContactAddressTypeArray.cpp @@ -100,7 +100,6 @@ JSValueRef JSContactAddressTypeArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); Try { JSContactAddressTypeArrayPriv* priv = @@ -166,12 +165,10 @@ ContactAddressTypeArrayPtr JSContactAddressTypeArray::getContactAddressTypeArray void JSContactAddressTypeArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSContactAddressTypeArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSContactAddressTypeArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -182,7 +179,6 @@ bool JSContactAddressTypeArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); WrtDeviceApis::CommonsJavaScript::BasicConverter converter = WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context); Try @@ -210,7 +206,6 @@ JSValueRef JSContactAddressTypeArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -242,7 +237,6 @@ bool JSContactAddressTypeArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -282,7 +276,6 @@ JSValueRef JSContactAddressTypeArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { ContactAddressTypeArrayPtr typeArray = ContactAddressTypeArrayPtr(new ContactAddressTypeArray()); @@ -331,7 +324,6 @@ JSValueRef JSContactAddressTypeArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -366,7 +358,6 @@ JSValueRef JSContactAddressTypeArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -394,7 +385,6 @@ JSValueRef JSContactAddressTypeArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -421,7 +411,6 @@ JSValueRef JSContactAddressTypeArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { WrtDeviceApis::CommonsJavaScript::BasicConverter converter = @@ -446,7 +435,6 @@ JSValueRef JSContactAddressTypeArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -474,7 +462,6 @@ JSValueRef JSContactAddressTypeArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -524,7 +511,6 @@ JSValueRef JSContactAddressTypeArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { WrtDeviceApis::CommonsJavaScript::BasicConverter converter = @@ -549,7 +535,6 @@ JSValueRef JSContactAddressTypeArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -560,7 +545,6 @@ JSValueRef JSContactAddressTypeArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -571,7 +555,6 @@ JSValueRef JSContactAddressTypeArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -582,7 +565,6 @@ JSValueRef JSContactAddressTypeArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/JSContactAnniversary.cpp b/src/standards/Tizen/Contact/JSContactAnniversary.cpp index dff4fea..403c52f 100755 --- a/src/standards/Tizen/Contact/JSContactAnniversary.cpp +++ b/src/standards/Tizen/Contact/JSContactAnniversary.cpp @@ -22,9 +22,10 @@ */ #include -#include +#include #include #include +//#include #include "ContactConverter.h" #include "JSContactAnniversary.h" @@ -38,8 +39,8 @@ namespace Contact { using namespace TizenApis::Commons; using namespace TizenApis::Api::Contact; - -JSClassRef JSContactAnniversary::m_classRef = NULL; +using namespace WrtDeviceApis::Commons; +using namespace WrtDeviceApis::CommonsJavaScript; JSClassDefinition JSContactAnniversary::m_classInfo = { @@ -56,15 +57,15 @@ JSClassDefinition JSContactAnniversary::m_classInfo = NULL, //SetProperty, NULL, //DeleteProperty, NULL, //getPropertyNames, - NULL, - NULL, - NULL, + NULL, //CallAsFunction, + constructor, //CallAsConstructor, + hasInstance, //HasInstance, NULL, //ConvertToType, }; JSStaticValue JSContactAnniversary::m_property[] = { { CONTACT_ATTR_DATE, getDate, setDate, kJSPropertyAttributeNone }, - //{ CONTACT_ATTR_LABEL, getLabel, setLabel, kJSPropertyAttributeNone }, + { CONTACT_ATTR_LABEL, getLabel, setLabel, kJSPropertyAttributeNone }, { 0, 0, 0, 0 } }; @@ -73,6 +74,8 @@ 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); @@ -80,22 +83,6 @@ JSClassRef JSContactAnniversary::getClassRef() { return m_classRef; } -JSValueRef JSContactAnniversary::createJSObject(JSContextRef context, - const std::tm &date, - const std::string& label) -{ - ContactAnniversaryPtr privateData = ContactAnniversaryPtr(new ContactAnniversary()); - privateData->setDate(date); - //privateData->setLabel(label); - JSContactAnniversaryPriv *priv = new JSContactAnniversaryPriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; -} - bool JSContactAnniversary::isObjectOfClass(JSContextRef context, JSValueRef value) { return JSValueIsObjectOfClass(context, value, getClassRef()); @@ -119,17 +106,37 @@ ContactAnniversaryPtr JSContactAnniversary::getContactAnniversary(JSContextRef c void JSContactAnniversary::Initialize(JSContextRef context, JSObjectRef object) { - assert(NULL != JSObjectGetPrivate(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) { - //delete (JSObjectGetPrivate(object)); + JSContactAnniversaryPriv *priv = static_cast(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(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; } ContactAnniversaryPtr JSContactAnniversary::getPrivData(JSObjectRef object) { - //LogDebug("entered"); JSContactAnniversaryPriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); @@ -141,12 +148,105 @@ ContactAnniversaryPtr JSContactAnniversary::getPrivData(JSObjectRef object) return result; } +JSObjectRef JSContactAnniversary::constructor(JSContextRef context, + JSObjectRef constructor, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LogDebug("entered"); + +// AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); +// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + JSContactAnniversaryPriv *priv = static_cast(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 || argumentCount > 2) + ThrowMsg(InvalidArgumentException, "Wrong arguments count."); + + if (!JSValueIsObject(gContext, arguments[0])) + ThrowMsg(InvalidArgumentException, "1st argument is not object."); + + if (argumentCount >= 2) + { + if (!JSValueIsString(gContext, arguments[1]) && !JSValueIsNull(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; + } + + ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext); + + std::tm date; + std::string label; + bool labelIsSet = false; + + Try { + date = converter->toDateTm(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(argumentCount >= 2) + { + if(!JSValueIsNull(gContext, arguments[1])) + { + label = converter->toString(arguments[1]); + labelIsSet = true; + } + } + } 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(labelIsSet) + 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) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -188,13 +288,15 @@ JSValueRef JSContactAnniversary::getLabel(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactAnniversaryPtr anniversary = getPrivData(object); - return converter->toJSValueRef(anniversary->getLabel()); + if(!anniversary->getLabelIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(anniversary->getLabel()); } Catch(WrtDeviceApis::Commons::Exception) { diff --git a/src/standards/Tizen/Contact/JSContactAnniversary.h b/src/standards/Tizen/Contact/JSContactAnniversary.h index 279c145..2caf838 100755 --- a/src/standards/Tizen/Contact/JSContactAnniversary.h +++ b/src/standards/Tizen/Contact/JSContactAnniversary.h @@ -43,10 +43,6 @@ public: */ static JSClassRef getClassRef(); - static JSValueRef createJSObject(JSContextRef context, - const std::tm &date, - const std::string& label = ""); - static bool isObjectOfClass(JSContextRef context, JSValueRef value); static TizenApis::Api::Contact::ContactAnniversaryPtr getContactAnniversary(JSContextRef context, JSValueRef value); @@ -80,8 +76,21 @@ private: 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, diff --git a/src/standards/Tizen/Contact/JSContactAnniversaryArray.cpp b/src/standards/Tizen/Contact/JSContactAnniversaryArray.cpp index cd4b14f..86434ae 100755 --- a/src/standards/Tizen/Contact/JSContactAnniversaryArray.cpp +++ b/src/standards/Tizen/Contact/JSContactAnniversaryArray.cpp @@ -99,7 +99,6 @@ JSValueRef JSContactAnniversaryArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - ////LogDebug("enter"); Try { JSContactAnniversaryArrayPriv* priv = @@ -165,12 +164,10 @@ JSClassRef JSContactAnniversaryArray::getClassRef() void JSContactAnniversaryArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSContactAnniversaryArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSContactAnniversaryArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -181,7 +178,6 @@ bool JSContactAnniversaryArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -209,7 +205,6 @@ JSValueRef JSContactAnniversaryArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -241,7 +236,6 @@ bool JSContactAnniversaryArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -281,7 +275,6 @@ JSValueRef JSContactAnniversaryArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { ContactAnniversaryArrayPtr anniversaries = ContactAnniversaryArrayPtr(new ContactAnniversaryArray()); @@ -327,7 +320,6 @@ JSValueRef JSContactAnniversaryArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -363,7 +355,6 @@ JSValueRef JSContactAnniversaryArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -392,7 +383,6 @@ JSValueRef JSContactAnniversaryArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -419,7 +409,6 @@ JSValueRef JSContactAnniversaryArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -444,7 +433,6 @@ JSValueRef JSContactAnniversaryArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -472,7 +460,6 @@ JSValueRef JSContactAnniversaryArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -522,7 +509,6 @@ JSValueRef JSContactAnniversaryArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -547,7 +533,6 @@ JSValueRef JSContactAnniversaryArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -558,7 +543,6 @@ JSValueRef JSContactAnniversaryArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -569,7 +553,6 @@ JSValueRef JSContactAnniversaryArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -580,7 +563,6 @@ JSValueRef JSContactAnniversaryArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/JSContactArray.cpp b/src/standards/Tizen/Contact/JSContactArray.cpp index 3535774..4dbf4cf 100755 --- a/src/standards/Tizen/Contact/JSContactArray.cpp +++ b/src/standards/Tizen/Contact/JSContactArray.cpp @@ -99,7 +99,6 @@ JSValueRef JSContactArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); Try { JSContactArrayPriv* priv = @@ -165,12 +164,10 @@ ContactArrayPtr JSContactArray::getContactArray(JSContextRef context, JSValueRef void JSContactArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSContactArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSContactArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -181,7 +178,6 @@ bool JSContactArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -209,7 +205,6 @@ JSValueRef JSContactArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -241,7 +236,6 @@ bool JSContactArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -281,7 +275,6 @@ JSValueRef JSContactArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { ContactArrayPtr contacts = ContactArrayPtr(new ContactArray()); @@ -327,7 +320,6 @@ JSValueRef JSContactArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -363,7 +355,6 @@ JSValueRef JSContactArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -392,7 +383,6 @@ JSValueRef JSContactArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -419,7 +409,6 @@ JSValueRef JSContactArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -444,7 +433,6 @@ JSValueRef JSContactArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -472,7 +460,6 @@ JSValueRef JSContactArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -522,7 +509,6 @@ JSValueRef JSContactArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -547,7 +533,6 @@ JSValueRef JSContactArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -558,7 +543,6 @@ JSValueRef JSContactArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -569,7 +553,6 @@ JSValueRef JSContactArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -580,7 +563,6 @@ JSValueRef JSContactArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/JSContactArray.h b/src/standards/Tizen/Contact/JSContactArray.h index b6323d2..91c8f0c 100755 --- a/src/standards/Tizen/Contact/JSContactArray.h +++ b/src/standards/Tizen/Contact/JSContactArray.h @@ -26,7 +26,7 @@ #include #include -#include +#include namespace TizenApis { namespace Tizen1_0 { diff --git a/src/standards/Tizen/Contact/JSContactEmailAddress.cpp b/src/standards/Tizen/Contact/JSContactEmailAddress.cpp index 00c9d4a..8aea395 100755 --- a/src/standards/Tizen/Contact/JSContactEmailAddress.cpp +++ b/src/standards/Tizen/Contact/JSContactEmailAddress.cpp @@ -22,9 +22,10 @@ */ #include -#include +#include #include #include +//#include #include "ContactConverter.h" #include "JSContactEmailAddressTypeArray.h" #include "JSContactEmailAddress.h" @@ -40,8 +41,8 @@ namespace Contact { using namespace TizenApis::Commons; using namespace TizenApis::Api::Contact; - -JSClassRef JSContactEmailAddress::m_classRef = NULL; +using namespace WrtDeviceApis::Commons; +using namespace WrtDeviceApis::CommonsJavaScript; JSClassDefinition JSContactEmailAddress::m_classInfo = { @@ -58,9 +59,9 @@ JSClassDefinition JSContactEmailAddress::m_classInfo = NULL, //SetProperty, NULL, //DeleteProperty, NULL, //getPropertyNames, - NULL, - NULL, - NULL, + NULL, //CallAsFunction, + constructor, //CallAsConstructor, + hasInstance, //HasInstance, NULL, //ConvertToType, }; @@ -75,6 +76,8 @@ 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); @@ -82,24 +85,6 @@ JSClassRef JSContactEmailAddress::getClassRef() { return m_classRef; } -JSValueRef JSContactEmailAddress::createJSObject(JSContextRef context, - const std::string email, - const ContactEmailAddressTypeArrayPtr types) -{ - ContactEmailAddressPtr privateData = ContactEmailAddressPtr(new ContactEmailAddress()); - - privateData->setEmail(email); - privateData->setTypes(types); - - JSContactEmailAddressPriv *priv = new JSContactEmailAddressPriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; -} - bool JSContactEmailAddress::isObjectOfClass(JSContextRef context, JSValueRef value) { return JSValueIsObjectOfClass(context, value, getClassRef()); @@ -123,17 +108,38 @@ ContactEmailAddressPtr JSContactEmailAddress::getContactEmailAddress(JSContextRe void JSContactEmailAddress::Initialize(JSContextRef context, JSObjectRef object) { - assert(NULL != JSObjectGetPrivate(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) { - //delete (JSObjectGetPrivate(object)); + JSContactEmailAddressPriv *priv = static_cast(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(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; } ContactEmailAddressPtr JSContactEmailAddress::getPrivData(JSObjectRef object) { - //LogDebug("entered"); JSContactEmailAddressPriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); @@ -145,12 +151,101 @@ ContactEmailAddressPtr JSContactEmailAddress::getPrivData(JSObjectRef object) return result; } +JSObjectRef JSContactEmailAddress::constructor(JSContextRef context, + JSObjectRef constructor, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LogDebug("entered"); + +// AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); +// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + JSContactEmailAddressPriv *priv = static_cast(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 || argumentCount > 2) + ThrowMsg(InvalidArgumentException, "Wrong arguments count."); + + if (!JSValueIsString(gContext, arguments[0])) + ThrowMsg(InvalidArgumentException, "1st argument is not string."); + + if (argumentCount >= 2) + { + if (!JSIsArrayValue(gContext, arguments[1]) && !JSValueIsNull(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; + } + + ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext); + + std::string email; + ContactEmailAddressTypeArrayPtr types(NULL); + + Try { + email = 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(argumentCount >= 2) + { + if(JSIsArrayValue(gContext, arguments[1])) + types = converter->toContactEmailAddressTypeArray(arguments[1]); + } + } 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); + if(types != NULL) + contactEmailAddress->setTypes(types); + + 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) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -193,7 +288,6 @@ JSValueRef JSContactEmailAddress::getTypes(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -221,7 +315,7 @@ bool JSContactEmailAddress::setTypes(JSContextRef context, ContactConverterFactory::getConverter(context); if(JSContactEmailAddressTypeArray::isObjectOfClass(context, value)) - emailAddress->setTypes(converter->toContactEmailAddressTypeArray(value)); // TODO to implement this function on converter + emailAddress->setTypes(converter->toContactEmailAddressTypeArray(value)); else emailAddress->setTypes(JSContactEmailAddressTypeArray::getContactEmailAddressTypeArray(context, value)); diff --git a/src/standards/Tizen/Contact/JSContactEmailAddress.h b/src/standards/Tizen/Contact/JSContactEmailAddress.h index dfd860c..1e19f1d 100755 --- a/src/standards/Tizen/Contact/JSContactEmailAddress.h +++ b/src/standards/Tizen/Contact/JSContactEmailAddress.h @@ -43,10 +43,6 @@ public: */ static JSClassRef getClassRef(); - static JSValueRef createJSObject(JSContextRef context, - const std::string email = "", - const TizenApis::Api::Contact::ContactEmailAddressTypeArrayPtr types = TizenApis::Api::Contact::ContactEmailAddressTypeArrayPtr(new TizenApis::Api::Contact::ContactEmailAddressTypeArray())); - static bool isObjectOfClass(JSContextRef context, JSValueRef value); static TizenApis::Api::Contact::ContactEmailAddressPtr getContactEmailAddress(JSContextRef context, JSValueRef value); @@ -80,8 +76,21 @@ private: 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, diff --git a/src/standards/Tizen/Contact/JSContactEmailAddressArray.cpp b/src/standards/Tizen/Contact/JSContactEmailAddressArray.cpp index e49a4d8..96c9da9 100755 --- a/src/standards/Tizen/Contact/JSContactEmailAddressArray.cpp +++ b/src/standards/Tizen/Contact/JSContactEmailAddressArray.cpp @@ -99,7 +99,6 @@ JSValueRef JSContactEmailAddressArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); Try { JSContactEmailAddressArrayPriv* priv = @@ -165,12 +164,10 @@ JSClassRef JSContactEmailAddressArray::getClassRef() void JSContactEmailAddressArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSContactEmailAddressArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSContactEmailAddressArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -181,7 +178,6 @@ bool JSContactEmailAddressArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -209,7 +205,6 @@ JSValueRef JSContactEmailAddressArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -241,7 +236,6 @@ bool JSContactEmailAddressArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -281,7 +275,6 @@ JSValueRef JSContactEmailAddressArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { ContactEmailAddressArrayPtr emailAddresses = ContactEmailAddressArrayPtr(new ContactEmailAddressArray()); @@ -327,7 +320,6 @@ JSValueRef JSContactEmailAddressArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -363,7 +355,6 @@ JSValueRef JSContactEmailAddressArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -392,7 +383,6 @@ JSValueRef JSContactEmailAddressArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -419,7 +409,6 @@ JSValueRef JSContactEmailAddressArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -444,7 +433,6 @@ JSValueRef JSContactEmailAddressArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -472,7 +460,6 @@ JSValueRef JSContactEmailAddressArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -522,7 +509,6 @@ JSValueRef JSContactEmailAddressArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -547,7 +533,6 @@ JSValueRef JSContactEmailAddressArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -558,7 +543,6 @@ JSValueRef JSContactEmailAddressArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -569,7 +553,6 @@ JSValueRef JSContactEmailAddressArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -580,7 +563,6 @@ JSValueRef JSContactEmailAddressArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/JSContactEmailAddressTypeArray.cpp b/src/standards/Tizen/Contact/JSContactEmailAddressTypeArray.cpp index 3137b42..a0eb615 100755 --- a/src/standards/Tizen/Contact/JSContactEmailAddressTypeArray.cpp +++ b/src/standards/Tizen/Contact/JSContactEmailAddressTypeArray.cpp @@ -102,7 +102,6 @@ JSValueRef JSContactEmailAddressTypeArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); Try { JSContactEmailAddressTypeArrayPriv* priv = @@ -167,12 +166,10 @@ JSClassRef JSContactEmailAddressTypeArray::getClassRef() void JSContactEmailAddressTypeArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSContactEmailAddressTypeArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSContactEmailAddressTypeArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -183,7 +180,6 @@ bool JSContactEmailAddressTypeArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); BasicConverter converter = BasicConverterFactory::getConverter(context); Try { @@ -210,7 +206,6 @@ JSValueRef JSContactEmailAddressTypeArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -242,7 +237,6 @@ bool JSContactEmailAddressTypeArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -282,7 +276,6 @@ JSValueRef JSContactEmailAddressTypeArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { ContactEmailAddressTypeArrayPtr typeArray = ContactEmailAddressTypeArrayPtr(new ContactEmailAddressTypeArray()); @@ -331,7 +324,6 @@ JSValueRef JSContactEmailAddressTypeArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -365,7 +357,6 @@ JSValueRef JSContactEmailAddressTypeArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -393,7 +384,6 @@ JSValueRef JSContactEmailAddressTypeArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -420,7 +410,6 @@ JSValueRef JSContactEmailAddressTypeArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { Converter converter(context); @@ -444,7 +433,6 @@ JSValueRef JSContactEmailAddressTypeArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -472,7 +460,6 @@ JSValueRef JSContactEmailAddressTypeArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -521,7 +508,6 @@ JSValueRef JSContactEmailAddressTypeArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { BasicConverter converter = BasicConverterFactory::getConverter(context); @@ -545,7 +531,6 @@ JSValueRef JSContactEmailAddressTypeArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -556,7 +541,6 @@ JSValueRef JSContactEmailAddressTypeArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -567,7 +551,6 @@ JSValueRef JSContactEmailAddressTypeArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -578,7 +561,6 @@ JSValueRef JSContactEmailAddressTypeArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/JSContactManager.cpp b/src/standards/Tizen/Contact/JSContactManager.cpp index 566efa2..1a4aa98 100755 --- a/src/standards/Tizen/Contact/JSContactManager.cpp +++ b/src/standards/Tizen/Contact/JSContactManager.cpp @@ -76,14 +76,15 @@ const JSClassDefinition* JSContactManager::getClassInfo() } JSStaticValue JSContactManager::m_property[] = { - { TIZEN_CONTACT_MANAGER_DEVICE_ADDRESS_BOOK, getConstProperty, NULL, kJSPropertyAttributeReadOnly }, - { TIZEN_CONTACT_MANAGER_PHONE_ADDRESS_BOOK, getConstProperty, NULL, kJSPropertyAttributeReadOnly }, + //{ TIZEN_CONTACT_MANAGER_DEVICE_ADDRESS_BOOK, getConstProperty, NULL, kJSPropertyAttributeReadOnly }, + //{ TIZEN_CONTACT_MANAGER_PHONE_ADDRESS_BOOK, getConstProperty, NULL, kJSPropertyAttributeReadOnly }, { 0, 0, 0, 0 } }; JSStaticFunction JSContactManager::m_function[] = { { "getAddressBooks", getAddressBooks, kJSPropertyAttributeNone }, { "getDefaultAddressBook", getDefaultAddressBook, kJSPropertyAttributeNone }, + { "getAddressBook", getAddressBook, kJSPropertyAttributeNone }, { 0, 0, 0 } }; @@ -121,6 +122,7 @@ JSValueRef JSContactManager::getConstProperty(JSContextRef context, JSStringRef jsPropertyName, JSValueRef* exception) { + LogDebug("Entered"); BasicConverter converter = BasicConverterFactory::getConverter(context); Try { @@ -143,6 +145,7 @@ JSValueRef JSContactManager::getAddressBooks(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { + LogDebug("Entered"); IContactManagerPtr contactManager; JSContextRef gContext; ContactManagerController *controller; @@ -215,6 +218,7 @@ JSValueRef JSContactManager::getDefaultAddressBook(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { + LogDebug("Entered"); ContactManagerController *priv = static_cast(JSObjectGetPrivate(thisObject)); if (!priv) { @@ -242,7 +246,7 @@ JSValueRef JSContactManager::getDefaultAddressBook(JSContextRef context, return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); } - IAddressBookPtr defaultAddressBook; + AddressBookPtr defaultAddressBook; Try { defaultAddressBook = contactManager->getDefaultAddressBook(); } Catch(Exception){ @@ -262,6 +266,82 @@ JSValueRef JSContactManager::getDefaultAddressBook(JSContextRef context, 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(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(priv->getContext(), CONTACT_FUNCTION_API_GET_ADDRESS_BOOK); + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + IContactManagerPtr 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"); + } + + BasicValidator validator = BasicValidatorFactory::getValidator(context, exception); + if (argumentCount != 1) { + /* Argument count must be 1. */ + LogError("TypeMismatchException!"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + } + if (!JSValueIsString(context, arguments[0])) { + /* Argument count must be string. */ + LogError("TypeMismatchException!"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + } + + ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext); + + std::string addressBookId; + Try + { + addressBookId = converter->toString(arguments[0]); + if(addressBookId == "") + ThrowMsg(InvalidArgumentException, "Address book ID is empty string."); + } + Catch(Exception) { + LogError("Error on conversion " << _rethrown_exception.GetMessage()); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + } + + AddressBookPtr addressBook; + Try { + addressBook = contactManager->getAddressBook(addressBookId); + } Catch(NotFoundException) { + LogError("No AddressBook id(" << addressBookId << ")"); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_FOUND_ERROR, "Internal error"); + } Catch(Exception){ + LogError("Internal error."); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error"); + } + + JSValueRef resultValue; + Try { + resultValue = converter->toJSValueRef(addressBook); + } Catch(Exception){ + LogError("Conversion error."); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, "Internal error"); + } + + return resultValue; +} + } // Contact } // Tizen1_0 } // TizenApis diff --git a/src/standards/Tizen/Contact/JSContactManager.h b/src/standards/Tizen/Contact/JSContactManager.h index 414770d..95a34d6 100755 --- a/src/standards/Tizen/Contact/JSContactManager.h +++ b/src/standards/Tizen/Contact/JSContactManager.h @@ -83,6 +83,16 @@ private: JSValueRef* exception); /** + * Get Default Address Books. + */ + static JSValueRef getAddressBook(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception); + + /** * This structure describes a statically declared value property. */ static JSStaticValue m_property[]; diff --git a/src/standards/Tizen/Contact/JSContactName.cpp b/src/standards/Tizen/Contact/JSContactName.cpp index 2fe693d..19e0879 100755 --- a/src/standards/Tizen/Contact/JSContactName.cpp +++ b/src/standards/Tizen/Contact/JSContactName.cpp @@ -23,9 +23,10 @@ #include #include -#include +#include #include #include +//#include #include "ContactConverter.h" #include "JSContactName.h" @@ -44,8 +45,8 @@ namespace Contact { using namespace TizenApis::Commons; using namespace TizenApis::Api::Contact; - -JSClassRef JSContactName::m_classRef = NULL; +using namespace WrtDeviceApis::Commons; +using namespace WrtDeviceApis::CommonsJavaScript; JSClassDefinition JSContactName::m_classInfo = { @@ -62,9 +63,9 @@ JSClassDefinition JSContactName::m_classInfo = NULL, //SetProperty, NULL, //DeleteProperty, NULL, //getPropertyNames, - NULL, - NULL, - NULL, + NULL, //CallAsFunction, + constructor, //CallAsConstructor, + hasInstance, //HasInstance, NULL, //ConvertToType, }; @@ -84,6 +85,8 @@ JSStaticFunction JSContactName::m_functions[] = { 0, 0, 0 } }; +JSClassRef JSContactName::m_classRef = JSClassCreate(&m_classInfo); + JSClassRef JSContactName::getClassRef() { if (!m_classRef) { @@ -92,33 +95,6 @@ JSClassRef JSContactName::getClassRef() return m_classRef; } -JSValueRef JSContactName::createJSObject(JSContextRef context, - const std::string& prefix, - const std::string& firstName, - const std::string& middleName, - const std::string& lastName, - const StringArrayPtr& nicknames, - const std::string& phoneticName, - const std::string& displayName) -{ - ContactNamePtr privateData = ContactNamePtr(new ContactName()); - privateData->setPrefix(prefix); - privateData->setFirstName(firstName); - privateData->setMiddleName(middleName); - privateData->setLastName(lastName); - privateData->setNicknames(nicknames); - privateData->setPhoneticName(phoneticName); - privateData->setDisplayName(displayName); - JSContactNamePriv *priv = new JSContactNamePriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) - { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; -} - bool JSContactName::isObjectOfClass(JSContextRef context, JSValueRef value) { return JSValueIsObjectOfClass(context, value, getClassRef()); @@ -145,17 +121,38 @@ ContactNamePtr JSContactName::getContactName(JSContextRef context, JSValueRef va void JSContactName::Initialize(JSContextRef context, JSObjectRef object) { - assert(NULL != JSObjectGetPrivate(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) { - //delete (JSObjectGetPrivate(object)); + JSContactNamePriv *priv = static_cast(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(priv)); + if (NULL == jsObjectRef) + { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; } ContactNamePtr JSContactName::getPrivData(JSObjectRef object) { - //LogDebug("entered"); JSContactNamePriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); @@ -169,18 +166,96 @@ ContactNamePtr JSContactName::getPrivData(JSObjectRef object) return result; } +JSObjectRef JSContactName::constructor(JSContextRef context, + JSObjectRef constructor, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LogDebug("entered"); + +// AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); +// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + JSContactNamePriv *priv = static_cast(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 (argumentCount == 1) + { + if (!JSValueIsObject(gContext, arguments[0]) && !JSValueIsNull(gContext, arguments[0])) + ThrowMsg(InvalidArgumentException, "1st argument is not object."); + } + + } Catch(Exception ) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + return NULL; + } + + ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext); + + ContactNamePtr contactName(NULL); + Try { + if(argumentCount == 1) + { + if(JSValueIsObject(gContext, arguments[0])) + contactName = converter->toContactNameFromInit(arguments[0]); + } + + if(contactName == NULL) + contactName = ContactNamePtr(new ContactName()); + + } Catch(Exception) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + return NULL; + } + + JSObjectRef jsobject; + + Try { + jsobject = createJSObject(gContext, contactName); + } Catch(Exception) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + 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) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - ContactNamePtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getPrefix()); + ContactNamePtr contactName = getPrivData(object); + if(!contactName->getPrefixIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contactName->getPrefix()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -198,10 +273,10 @@ bool JSContactName::setPrefix(JSContextRef context, { Try { - ContactNamePtr contactProperties = getPrivData(object); + ContactNamePtr contactName = getPrivData(object); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - contactProperties->setPrefix(converter->toString(value)); + contactName->setPrefix(converter->toString(value)); return true; } Catch(WrtDeviceApis::Commons::Exception) @@ -218,13 +293,15 @@ JSValueRef JSContactName::getFirstName(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - ContactNamePtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getFirstName()); + ContactNamePtr contactName = getPrivData(object); + if(!contactName->getFirstNameIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contactName->getFirstName()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -242,10 +319,10 @@ bool JSContactName::setFirstName(JSContextRef context, { Try { - ContactNamePtr contactProperties = getPrivData(object); + ContactNamePtr contactName = getPrivData(object); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - contactProperties->setFirstName(converter->toString(value)); + contactName->setFirstName(converter->toString(value)); return true; } Catch(WrtDeviceApis::Commons::Exception) @@ -262,13 +339,15 @@ JSValueRef JSContactName::getMiddleName(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - ContactNamePtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getMiddleName()); + ContactNamePtr contactName = getPrivData(object); + if(!contactName->getMiddleNameIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contactName->getMiddleName()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -286,10 +365,10 @@ bool JSContactName::setMiddleName(JSContextRef context, { Try { - ContactNamePtr contactProperties = getPrivData(object); + ContactNamePtr contactName = getPrivData(object); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - contactProperties->setMiddleName(converter->toString(value)); + contactName->setMiddleName(converter->toString(value)); return true; } Catch(WrtDeviceApis::Commons::Exception) @@ -306,13 +385,15 @@ JSValueRef JSContactName::getLastName(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - ContactNamePtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getLastName()); + ContactNamePtr contactName = getPrivData(object); + if(!contactName->getLastNameIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contactName->getLastName()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -330,10 +411,10 @@ bool JSContactName::setLastName(JSContextRef context, { Try { - ContactNamePtr contactProperties = getPrivData(object); + ContactNamePtr contactName = getPrivData(object); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - contactProperties->setLastName(converter->toString(value)); + contactName->setLastName(converter->toString(value)); return true; } Catch(WrtDeviceApis::Commons::Exception) @@ -350,13 +431,12 @@ JSValueRef JSContactName::getNicknames(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - ContactNamePtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getNicknames()); + ContactNamePtr contactName = getPrivData(object); + return converter->toJSValueRef(contactName->getNicknames()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -374,10 +454,10 @@ bool JSContactName::setNicknames(JSContextRef context, { Try { - ContactNamePtr contactProperties = getPrivData(object); + ContactNamePtr contactName = getPrivData(object); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - contactProperties->setNicknames(converter->toStringArray(value)); + contactName->setNicknames(converter->toStringArray(value)); return true; } Catch(WrtDeviceApis::Commons::Exception) @@ -394,13 +474,15 @@ JSValueRef JSContactName::getPhoneticName(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - ContactNamePtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getPhoneticName()); + ContactNamePtr contactName = getPrivData(object); + if(!contactName->getPhoneticNameIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(contactName->getPhoneticName()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -418,10 +500,10 @@ bool JSContactName::setPhoneticName(JSContextRef context, { Try { - ContactNamePtr contactProperties = getPrivData(object); + ContactNamePtr contactName = getPrivData(object); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - contactProperties->setPhoneticName(converter->toString(value)); + contactName->setPhoneticName(converter->toString(value)); return true; } Catch(WrtDeviceApis::Commons::Exception) @@ -438,13 +520,15 @@ JSValueRef JSContactName::getDisplayName(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - ContactNamePtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getDisplayName()); + 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"); @@ -460,10 +544,10 @@ bool JSContactName::setDisplayName(JSContextRef context, { Try { - ContactNamePtr contactProperties = getPrivData(object); + ContactNamePtr contactName = getPrivData(object); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - contactProperties->setDisplayName(converter->toString(value)); + contactName->setDisplayName(converter->toString(value)); return true; } Catch(WrtDeviceApis::Commons::Exception) diff --git a/src/standards/Tizen/Contact/JSContactName.h b/src/standards/Tizen/Contact/JSContactName.h index 697063b..eb8506e 100755 --- a/src/standards/Tizen/Contact/JSContactName.h +++ b/src/standards/Tizen/Contact/JSContactName.h @@ -43,15 +43,6 @@ public: */ static JSClassRef getClassRef(); - static JSValueRef createJSObject(JSContextRef context, - const std::string& prefix, - const std::string& firstName, - const std::string& middleName, - const std::string& lastName, - const TizenApis::Api::Contact::StringArrayPtr& nicknames, - const std::string& phoneticName, - const std::string& displayName); - static bool isObjectOfClass(JSContextRef context, JSValueRef value); static TizenApis::Api::Contact::ContactNamePtr getContactName(JSContextRef context, JSValueRef value); @@ -85,8 +76,21 @@ private: 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, diff --git a/src/standards/Tizen/Contact/JSContactOrganization.cpp b/src/standards/Tizen/Contact/JSContactOrganization.cpp index 33262dd..462d2b7 100755 --- a/src/standards/Tizen/Contact/JSContactOrganization.cpp +++ b/src/standards/Tizen/Contact/JSContactOrganization.cpp @@ -23,9 +23,10 @@ #include "JSContactOrganization.h" #include +#include #include #include -#include +//#include #include "ContactConverter.h" #define ORGANIZATION_CLASS_NAME "ContactOrganization" @@ -43,8 +44,8 @@ namespace Contact { using namespace TizenApis::Commons; using namespace TizenApis::Api::Contact; - -JSClassRef JSContactOrganization::m_classRef = NULL; +using namespace WrtDeviceApis::Commons; +using namespace WrtDeviceApis::CommonsJavaScript; JSClassDefinition JSContactOrganization::m_classInfo = { @@ -61,9 +62,9 @@ JSClassDefinition JSContactOrganization::m_classInfo = NULL, //SetProperty, NULL, //DeleteProperty, NULL, //getPropertyNames, - NULL, - NULL, - NULL, + NULL, //CallAsFunction, + constructor, //CallAsConstructor, + hasInstance, //HasInstance, NULL, //ConvertToType, }; @@ -82,6 +83,8 @@ 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); @@ -89,30 +92,6 @@ JSClassRef JSContactOrganization::getClassRef() { return m_classRef; } -JSValueRef JSContactOrganization::createJSObject(JSContextRef context, - const std::string& name, - const std::string& department, - const std::string& office, - const std::string& title, - const std::string& role, - const std::string& logoURI) -{ - ContactOrganizationPtr privateData = ContactOrganizationPtr(new ContactOrganization()); - privateData->setName(name); - privateData->setDepartment(department); - privateData->setOffice(office); - privateData->setTitle(title); - privateData->setRole(role); - privateData->setLogoURI(logoURI); - JSContactOrganizationPriv *priv = new JSContactOrganizationPriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; -} - bool JSContactOrganization::isObjectOfClass(JSContextRef context, JSValueRef value) { return JSValueIsObjectOfClass(context, value, getClassRef()); @@ -136,17 +115,37 @@ ContactOrganizationPtr JSContactOrganization::getContactOrganization(JSContextRe void JSContactOrganization::Initialize(JSContextRef context, JSObjectRef object) { - assert(NULL != JSObjectGetPrivate(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) { - //delete (JSObjectGetPrivate(object)); + JSContactOrganizationPriv *priv = static_cast(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(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; } ContactOrganizationPtr JSContactOrganization::getPrivData(JSObjectRef object) { - //LogDebug("entered"); JSContactOrganizationPriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); @@ -158,18 +157,96 @@ ContactOrganizationPtr JSContactOrganization::getPrivData(JSObjectRef object) return result; } +JSObjectRef JSContactOrganization::constructor(JSContextRef context, + JSObjectRef constructor, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LogDebug("entered"); + +// AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); +// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + JSContactOrganizationPriv *priv = static_cast(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 (argumentCount == 1) + { + if (!JSValueIsObject(gContext, arguments[0]) && !JSValueIsNull(gContext, arguments[0])) + ThrowMsg(InvalidArgumentException, "2nd argument is not object."); + } + + } Catch(Exception ) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + return NULL; + } + + ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext); + + ContactOrganizationPtr contactOrganization(NULL); + Try { + if(argumentCount == 1) + { + if(JSValueIsObject(gContext, arguments[0])) + contactOrganization = converter->toContactOrganizationFromInit(arguments[0]); + } + + if(contactOrganization == NULL) + contactOrganization = ContactOrganizationPtr(new ContactOrganization()); + + } Catch(Exception) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + return NULL; + } + + JSObjectRef jsobject; + + Try { + jsobject = createJSObject(gContext, contactOrganization); + } Catch(Exception) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + 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) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactOrganizationPtr organization = getPrivData(object); - return converter->toJSValueRef(organization->getName()); + if(!organization->getNameIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(organization->getName()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -206,13 +283,15 @@ JSValueRef JSContactOrganization::getDepartment(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactOrganizationPtr organization = getPrivData(object); - return converter->toJSValueRef(organization->getDepartment()); + if(!organization->getDepartmentIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(organization->getDepartment()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -248,13 +327,15 @@ JSValueRef JSContactOrganization::getOffice(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactOrganizationPtr organization = getPrivData(object); - return converter->toJSValueRef(organization->getOffice()); + if(!organization->getOfficeIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(organization->getOffice()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -290,13 +371,15 @@ JSValueRef JSContactOrganization::getTitle(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactOrganizationPtr organization = getPrivData(object); - return converter->toJSValueRef(organization->getTitle()); + if(!organization->getTitleIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(organization->getTitle()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -332,13 +415,15 @@ JSValueRef JSContactOrganization::getRole(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactOrganizationPtr organization = getPrivData(object); - return converter->toJSValueRef(organization->getRole()); + if(!organization->getRoleIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(organization->getRole()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -374,13 +459,15 @@ JSValueRef JSContactOrganization::getLogoURI(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactOrganizationPtr organization = getPrivData(object); - return converter->toJSValueRef(organization->getLogoURI()); + if(!organization->getLogoURIIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(organization->getLogoURI()); } Catch(WrtDeviceApis::Commons::Exception) { diff --git a/src/standards/Tizen/Contact/JSContactOrganization.h b/src/standards/Tizen/Contact/JSContactOrganization.h index 0aa8092..2ecfc5d 100755 --- a/src/standards/Tizen/Contact/JSContactOrganization.h +++ b/src/standards/Tizen/Contact/JSContactOrganization.h @@ -43,14 +43,6 @@ public: */ static JSClassRef getClassRef(); - static JSValueRef createJSObject(JSContextRef context, - const std::string& name, - const std::string& department, - const std::string& office, - const std::string& title, - const std::string& role, - const std::string& logoURI); - static bool isObjectOfClass(JSContextRef context, JSValueRef value); static TizenApis::Api::Contact::ContactOrganizationPtr getContactOrganization(JSContextRef context, JSValueRef value); @@ -84,8 +76,21 @@ private: 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, diff --git a/src/standards/Tizen/Contact/JSContactOrganizationArray.cpp b/src/standards/Tizen/Contact/JSContactOrganizationArray.cpp index 83aa7a6..a11fe0b 100755 --- a/src/standards/Tizen/Contact/JSContactOrganizationArray.cpp +++ b/src/standards/Tizen/Contact/JSContactOrganizationArray.cpp @@ -99,7 +99,6 @@ JSValueRef JSContactOrganizationArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); Try { JSContactOrganizationArrayPriv* priv = @@ -164,12 +163,10 @@ JSClassRef JSContactOrganizationArray::getClassRef() void JSContactOrganizationArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSContactOrganizationArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSContactOrganizationArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -180,7 +177,6 @@ bool JSContactOrganizationArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -208,7 +204,6 @@ JSValueRef JSContactOrganizationArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -240,7 +235,6 @@ bool JSContactOrganizationArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -280,7 +274,6 @@ JSValueRef JSContactOrganizationArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { ContactOrganizationArrayPtr organizations = ContactOrganizationArrayPtr(new ContactOrganizationArray()); @@ -326,7 +319,6 @@ JSValueRef JSContactOrganizationArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -362,7 +354,6 @@ JSValueRef JSContactOrganizationArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -391,7 +382,6 @@ JSValueRef JSContactOrganizationArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -418,7 +408,6 @@ JSValueRef JSContactOrganizationArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -443,7 +432,6 @@ JSValueRef JSContactOrganizationArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -471,7 +459,6 @@ JSValueRef JSContactOrganizationArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -521,7 +508,6 @@ JSValueRef JSContactOrganizationArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -546,7 +532,6 @@ JSValueRef JSContactOrganizationArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -557,7 +542,6 @@ JSValueRef JSContactOrganizationArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -568,7 +552,6 @@ JSValueRef JSContactOrganizationArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -579,7 +562,6 @@ JSValueRef JSContactOrganizationArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/JSContactPhoneNumber.cpp b/src/standards/Tizen/Contact/JSContactPhoneNumber.cpp index 50cd1e8..b17f12b 100755 --- a/src/standards/Tizen/Contact/JSContactPhoneNumber.cpp +++ b/src/standards/Tizen/Contact/JSContactPhoneNumber.cpp @@ -23,9 +23,10 @@ #include #include -#include +#include #include #include +//#include #include "ContactConverter.h" #include "JSContactPhoneNumberTypeArray.h" #include "JSContactPhoneNumber.h" @@ -41,8 +42,8 @@ namespace Contact { using namespace TizenApis::Commons; using namespace TizenApis::Api::Contact; - -JSClassRef JSContactPhoneNumber::m_classRef = NULL; +using namespace WrtDeviceApis::Commons; +using namespace WrtDeviceApis::CommonsJavaScript; JSClassDefinition JSContactPhoneNumber::m_classInfo = { @@ -59,9 +60,9 @@ JSClassDefinition JSContactPhoneNumber::m_classInfo = NULL, //SetProperty, NULL, //DeleteProperty, NULL, //getPropertyNames, - NULL, - NULL, - NULL, + NULL, //CallAsFunction, + constructor, //CallAsConstructor, + hasInstance, //HasInstance, NULL, //ConvertToType, }; @@ -76,6 +77,8 @@ 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); @@ -83,20 +86,6 @@ JSClassRef JSContactPhoneNumber::getClassRef() { return m_classRef; } -JSValueRef JSContactPhoneNumber::createJSObject(JSContextRef context - // FIXME - ) -{ - ContactPhoneNumberPtr privateData = ContactPhoneNumberPtr(new ContactPhoneNumber()); - JSContactPhoneNumberPriv *priv = new JSContactPhoneNumberPriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; -} - bool JSContactPhoneNumber::isObjectOfClass(JSContextRef context, JSValueRef value) { return JSValueIsObjectOfClass(context, value, getClassRef()); @@ -120,17 +109,37 @@ ContactPhoneNumberPtr JSContactPhoneNumber::getContactPhoneNumber(JSContextRef c void JSContactPhoneNumber::Initialize(JSContextRef context, JSObjectRef object) { - assert(NULL != JSObjectGetPrivate(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) { - //delete (JSObjectGetPrivate(object)); + JSContactPhoneNumberPriv *priv = static_cast(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(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; } ContactPhoneNumberPtr JSContactPhoneNumber::getPrivData(JSObjectRef object) { - //LogDebug("entered"); JSContactPhoneNumberPriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); @@ -142,12 +151,95 @@ ContactPhoneNumberPtr JSContactPhoneNumber::getPrivData(JSObjectRef object) return result; } +JSObjectRef JSContactPhoneNumber::constructor(JSContextRef context, + JSObjectRef constructor, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LogDebug("entered"); + +// AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); +// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + JSContactPhoneNumberPriv *priv = static_cast(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 != 2) + ThrowMsg(InvalidArgumentException, "Wrong arguments count."); + + if (!JSValueIsString(gContext, arguments[0])) + ThrowMsg(InvalidArgumentException, "1st argument is not string."); + + if (!JSIsArrayValue(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; + } + + ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext); + + std::string number; + ContactPhoneNumberTypeArrayPtr types; + + Try { + number = 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 { + types = converter->toContactPhoneNumberTypeArray(arguments[1]); + 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; + } + + ContactPhoneNumberPtr contactPhoneNumber(new ContactPhoneNumber()); + contactPhoneNumber->setNumber(number); + contactPhoneNumber->setTypes(types); + + 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) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -190,13 +282,12 @@ JSValueRef JSContactPhoneNumber::getTypes(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactPhoneNumberPtr contactPhoneNumber = getPrivData(object); - //return JSContactPhoneNumberTypeArray::createArray(context, contactPhoneNumber->getTypes()); + return converter->toJSValueRef(contactPhoneNumber->getTypes()); } Catch(WrtDeviceApis::Commons::Exception) @@ -218,13 +309,7 @@ bool JSContactPhoneNumber::setTypes(JSContextRef context, ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); - if(JSContactPhoneNumberTypeArray::isObjectOfClass(context, value)) { - contactPhoneNumber->setTypes(converter->toStringArray(value)); - //contactPhoneNumber->setTypes(converter->toContactPhoneNumberTypeArray(value)); // TODO to implement this function on converter - } else { - contactPhoneNumber->setTypes(converter->toStringArray(value)); -// contactPhoneNumber->setTypes(JSContactPhoneNumberTypeArray::getContactPhoneNumberTypeArray(context, value)); - } + contactPhoneNumber->setTypes(converter->toContactPhoneNumberTypeArray(value)); return true; } diff --git a/src/standards/Tizen/Contact/JSContactPhoneNumber.h b/src/standards/Tizen/Contact/JSContactPhoneNumber.h index 8e8abf0..56f210f 100755 --- a/src/standards/Tizen/Contact/JSContactPhoneNumber.h +++ b/src/standards/Tizen/Contact/JSContactPhoneNumber.h @@ -43,10 +43,6 @@ public: */ static JSClassRef getClassRef(); - static JSValueRef createJSObject(JSContextRef context - // FIXME fix this value - ); - static bool isObjectOfClass(JSContextRef context, JSValueRef value); static TizenApis::Api::Contact::ContactPhoneNumberPtr getContactPhoneNumber(JSContextRef context, JSValueRef value); @@ -80,8 +76,21 @@ private: 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, diff --git a/src/standards/Tizen/Contact/JSContactPhoneNumberArray.cpp b/src/standards/Tizen/Contact/JSContactPhoneNumberArray.cpp index b75fb5d..9e50142 100755 --- a/src/standards/Tizen/Contact/JSContactPhoneNumberArray.cpp +++ b/src/standards/Tizen/Contact/JSContactPhoneNumberArray.cpp @@ -99,7 +99,6 @@ JSValueRef JSContactPhoneNumberArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); Try { JSContactPhoneNumberArrayPriv* priv = @@ -165,12 +164,10 @@ ContactPhoneNumberArrayPtr JSContactPhoneNumberArray::getContactPhoneNumberArray void JSContactPhoneNumberArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSContactPhoneNumberArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSContactPhoneNumberArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -181,7 +178,6 @@ bool JSContactPhoneNumberArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -209,7 +205,6 @@ JSValueRef JSContactPhoneNumberArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -241,7 +236,6 @@ bool JSContactPhoneNumberArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -281,7 +275,6 @@ JSValueRef JSContactPhoneNumberArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { ContactPhoneNumberArrayPtr contactPhoneNumbers = ContactPhoneNumberArrayPtr(new ContactPhoneNumberArray()); @@ -327,7 +320,6 @@ JSValueRef JSContactPhoneNumberArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -363,7 +355,6 @@ JSValueRef JSContactPhoneNumberArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -392,7 +383,6 @@ JSValueRef JSContactPhoneNumberArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -419,7 +409,6 @@ JSValueRef JSContactPhoneNumberArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -444,7 +433,6 @@ JSValueRef JSContactPhoneNumberArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -472,7 +460,6 @@ JSValueRef JSContactPhoneNumberArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -522,7 +509,6 @@ JSValueRef JSContactPhoneNumberArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -547,7 +533,6 @@ JSValueRef JSContactPhoneNumberArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -558,7 +543,6 @@ JSValueRef JSContactPhoneNumberArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -569,7 +553,6 @@ JSValueRef JSContactPhoneNumberArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -580,7 +563,6 @@ JSValueRef JSContactPhoneNumberArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/JSContactPhoneNumberTypeArray.cpp b/src/standards/Tizen/Contact/JSContactPhoneNumberTypeArray.cpp index d14cc17..4ae2939 100755 --- a/src/standards/Tizen/Contact/JSContactPhoneNumberTypeArray.cpp +++ b/src/standards/Tizen/Contact/JSContactPhoneNumberTypeArray.cpp @@ -100,7 +100,6 @@ JSValueRef JSContactPhoneNumberTypeArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); Try { JSContactPhoneNumberTypeArrayPriv* priv = @@ -166,12 +165,10 @@ ContactPhoneNumberTypeArrayPtr JSContactPhoneNumberTypeArray::getContactPhoneNum void JSContactPhoneNumberTypeArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSContactPhoneNumberTypeArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSContactPhoneNumberTypeArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -182,7 +179,6 @@ bool JSContactPhoneNumberTypeArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); WrtDeviceApis::CommonsJavaScript::BasicConverter converter = WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context); Try @@ -210,7 +206,6 @@ JSValueRef JSContactPhoneNumberTypeArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try { @@ -241,7 +236,6 @@ bool JSContactPhoneNumberTypeArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try { @@ -280,7 +274,6 @@ JSValueRef JSContactPhoneNumberTypeArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { ContactPhoneNumberTypeArrayPtr typeArray = ContactPhoneNumberTypeArrayPtr(new ContactPhoneNumberTypeArray()); @@ -329,7 +322,6 @@ JSValueRef JSContactPhoneNumberTypeArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -363,7 +355,6 @@ JSValueRef JSContactPhoneNumberTypeArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -392,7 +383,6 @@ JSValueRef JSContactPhoneNumberTypeArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -419,7 +409,6 @@ JSValueRef JSContactPhoneNumberTypeArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { WrtDeviceApis::CommonsJavaScript::Converter converter(context); @@ -443,7 +432,6 @@ JSValueRef JSContactPhoneNumberTypeArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); @@ -470,7 +458,6 @@ JSValueRef JSContactPhoneNumberTypeArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -519,7 +506,6 @@ JSValueRef JSContactPhoneNumberTypeArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { WrtDeviceApis::CommonsJavaScript::Converter converter(context); @@ -543,7 +529,6 @@ JSValueRef JSContactPhoneNumberTypeArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -554,7 +539,6 @@ JSValueRef JSContactPhoneNumberTypeArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -565,7 +549,6 @@ JSValueRef JSContactPhoneNumberTypeArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -576,7 +559,6 @@ JSValueRef JSContactPhoneNumberTypeArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/JSContactProperties.cpp b/src/standards/Tizen/Contact/JSContactProperties.cpp deleted file mode 100755 index 7710e88..0000000 --- a/src/standards/Tizen/Contact/JSContactProperties.cpp +++ /dev/null @@ -1,799 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file JSContactProperties.cpp - * @author Kisub Song (kisubs.song@samsung.com) - * @version 0.1 - * @brief Implementation of the JSContactProperties class - */ - -#include -#include -#include -#include -#include -#include "ContactConverter.h" -#include "JSContactProperties.h" - -#define CONTACT_CLASS_NAME "ContactProperties" -#define CONTACT_PROP_ATTR_NAME "name" -#define CONTACT_PROP_ATTR_ACCOUNT "account" -#define CONTACT_PROP_ATTR_ADDRESSES "addresses" -#define CONTACT_PROP_ATTR_PHOTO_URI "photoURI" -#define CONTACT_PROP_ATTR_PHONE_NUMBERS "phoneNumbers" -#define CONTACT_PROP_ATTR_EMAILS "emails" -#define CONTACT_PROP_ATTR_BIRTHDAY "birthday" -#define CONTACT_PROP_ATTR_ANNIVERSARIES "anniversaries" -#define CONTACT_PROP_ATTR_ORGANIZATION "organization" -#define CONTACT_PROP_ATTR_NOTES "notes" -#define CONTACT_PROP_ATTR_URLS "urls" -#define CONTACT_PROP_ATTR_LAST_UPDATED "lastUpdated" -#define CONTACT_PROP_ATTR_IS_FAVORITE "isFavorite" -#define CONTACT_PROP_ATTR_RINGTONE_URI "ringtoneURI" -#define CONTACT_PROP_ATTR_CATEGORIES "categories" - -namespace TizenApis { -namespace Tizen1_0 { -namespace Contact { - -using namespace TizenApis::Commons; -using namespace TizenApis::Api::Contact; - -JSClassRef JSContactProperties::m_classRef = NULL; - -JSClassDefinition JSContactProperties::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, - NULL, - NULL, - NULL, //ConvertToType, -}; - -JSStaticValue JSContactProperties::m_property[] = { - { CONTACT_PROP_ATTR_NAME, getName, setName, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_ACCOUNT, getAccount, setAccount, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_ADDRESSES, getAddresses, setAddresses, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_PHOTO_URI, getPhotoURI, setPhotoURI, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_PHONE_NUMBERS, getPhoneNumbers, setPhoneNumbers, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_EMAILS, getEmails, setEmails, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_BIRTHDAY, getBirthday, setBirthday, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_ANNIVERSARIES, getAnniversaries, setAnniversaries, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_ORGANIZATION, getOrganization, setOrganization, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_NOTES, getNotes, setNotes, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_URLS, getUrls, setUrls, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_IS_FAVORITE, getIsFavorite, setIsFavorite, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_RINGTONE_URI, getRingtoneURI, setRingtoneURI, kJSPropertyAttributeNone }, - { CONTACT_PROP_ATTR_CATEGORIES, getCategories, setCategories, kJSPropertyAttributeNone }, - { 0, 0, 0, 0 } -}; - -JSStaticFunction JSContactProperties::m_functions[] = -{ - { 0, 0, 0 } -}; - -JSClassRef JSContactProperties::getClassRef() -{ - if (!m_classRef) { - m_classRef = JSClassCreate(&m_classInfo); - } - return m_classRef; -} - -JSValueRef JSContactProperties::createJSObject(JSContextRef context -// FIXME - ) -{ - ContactPropertiesPtr privateData = ContactPropertiesPtr(new ContactProperties()); - JSContactPropertiesPriv *priv = new JSContactPropertiesPriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) - { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; -} - -bool JSContactProperties::isObjectOfClass(JSContextRef context, JSValueRef value) -{ - return JSValueIsObjectOfClass(context, value, getClassRef()); -} - -ContactPropertiesPtr JSContactProperties::getContactProperties(JSContextRef context, JSValueRef value) -{ - if (!isObjectOfClass(context, value)) { - Throw(WrtDeviceApis::Commons::InvalidArgumentException); - } - - JSObjectRef object = JSValueToObject(context, value, NULL); - if (!object) { - Throw(WrtDeviceApis::Commons::InvalidArgumentException); - } - - JSContactPropertiesPriv *priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - Throw(WrtDeviceApis::Commons::NullPointerException); - } - - return priv->getObject(); -} - -void JSContactProperties::Initialize(JSContextRef context, JSObjectRef object) -{ - assert(NULL != JSObjectGetPrivate(object)); -} - -void JSContactProperties::Finalize(JSObjectRef object) -{ - //delete (JSObjectGetPrivate(object)); -} - -ContactPropertiesPtr JSContactProperties::getPrivData(JSObjectRef object) -{ - //LogDebug("entered"); - JSContactPropertiesPriv *priv = static_cast(JSObjectGetPrivate(object)); - if (!priv) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - - ContactPropertiesPtr result = priv->getObject(); - if (!result) { - ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); - } - - return result; -} - -JSValueRef JSContactProperties::getName(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getName()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setName(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->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 JSContactProperties::getAccount(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getAccount()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setAccount(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->setAccount(converter->toContactAccount(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 JSContactProperties::getAddresses(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getAddresses()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setAddresses(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->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 JSContactProperties::getPhotoURI(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getPhotoURI()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setPhotoURI(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->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 JSContactProperties::getPhoneNumbers(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getPhoneNumbers()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setPhoneNumbers(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->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 JSContactProperties::getEmails(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getEmails()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setEmails(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->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 JSContactProperties::getBirthday(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - if(contactProperties->getBirthdayIsSet()) - return converter->toJSValueRef(contactProperties->getBirthday()); - else - return JSValueMakeNull(context); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setBirthday(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->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 JSContactProperties::getAnniversaries(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getAnniversaries()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setAnniversaries(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->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 JSContactProperties::getOrganization(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getOrganization()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setOrganization(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->setOrganization(converter->toContactOrganization(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 JSContactProperties::getNotes(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getNotes()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setNotes(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->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 JSContactProperties::getUrls(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getUrls()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setUrls(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->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 JSContactProperties::getIsFavorite(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getIsFavorite()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setIsFavorite(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->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 JSContactProperties::getRingtoneURI(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getRingtoneURI()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setRingtoneURI(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->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 JSContactProperties::getCategories(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception) -{ - //LogDebug("entered"); - Try - { - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - ContactPropertiesPtr contactProperties = getPrivData(object); - return converter->toJSValueRef(contactProperties->getCategories()); - } - Catch(WrtDeviceApis::Commons::Exception) - { - LogWarning("trying to get incorrect value"); - } - - return JSValueMakeUndefined(context); -} - -bool JSContactProperties::setCategories(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception) -{ - Try - { - ContactPropertiesPtr contactProperties = getPrivData(object); - ContactConverterFactory::ConverterType converter = - ContactConverterFactory::getConverter(context); - contactProperties->setCategories(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; -} - -} // Contact -} // Tizen1_0 -} // TizenApis diff --git a/src/standards/Tizen/Contact/JSContactProperties.h b/src/standards/Tizen/Contact/JSContactProperties.h deleted file mode 100755 index d8ccbdf..0000000 --- a/src/standards/Tizen/Contact/JSContactProperties.h +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file JSContactProperties.h - * @author Kisub Song (kisubs.song@samsung.com) - * @version 0.1 - * @brief Declaration of the JSContactProperties class - */ - -#ifndef _TIZEN_CONTACT_JS_CONTACT_PROPERTIES_H_ -#define _TIZEN_CONTACT_JS_CONTACT_PROPERTIES_H_ - -#include -#include -#include -#include -#include - -namespace TizenApis { -namespace Tizen1_0 { -namespace Contact { - -typedef WrtDeviceApis::CommonsJavaScript::PrivateObject JSContactPropertiesPriv; - -class JSContactProperties { -public: - /* - * This initializes this JS class in the JS Engine. - */ - static JSClassRef getClassRef(); - - static JSValueRef createJSObject(JSContextRef context); - - static bool isObjectOfClass(JSContextRef context, JSValueRef value); - - static TizenApis::Api::Contact::ContactPropertiesPtr getContactProperties(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 TizenApis::Api::Contact::ContactPropertiesPtr getPrivData(JSObjectRef object); - - 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 getAccount(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - static bool setAccount(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 getOrganization(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - static bool setOrganization(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 getIsFavorite(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - static bool setIsFavorite(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 getCategories(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef* exception); - - static bool setCategories(JSContextRef context, - JSObjectRef object, - JSStringRef propertyName, - JSValueRef value, - JSValueRef* exception); -}; - -} // Contact -} // Tizen1_0 -} // TizenApis - -#endif // _TIZEN_CONTACT_JS_CONTACT_PROPERTIES_H_ diff --git a/src/standards/Tizen/Contact/JSContactRef.cpp b/src/standards/Tizen/Contact/JSContactRef.cpp new file mode 100755 index 0000000..f6cd766 --- /dev/null +++ b/src/standards/Tizen/Contact/JSContactRef.cpp @@ -0,0 +1,329 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES 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 +#include +#include +#include +#include +//#include +#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(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(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(priv)); + if (NULL == jsObjectRef) + { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; +} + +ContactRefPtr JSContactRef::getPrivData(JSObjectRef object) +{ + JSContactRefPriv *priv = static_cast(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"); + +// AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); +// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + JSContactRefPriv *priv = static_cast(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 != 2) + ThrowMsg(InvalidArgumentException, "Wrong arguments count."); + + if (!JSValueIsString(gContext, arguments[0])) + ThrowMsg(InvalidArgumentException, "1st argument is not string."); + + if (!JSValueIsString(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; + } + + 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/Application/JSApplicationServiceExtraData.h b/src/standards/Tizen/Contact/JSContactRef.h similarity index 56% rename from src/standards/Tizen/Application/JSApplicationServiceExtraData.h rename to src/standards/Tizen/Contact/JSContactRef.h index 02f5688..25293af 100755 --- a/src/standards/Tizen/Application/JSApplicationServiceExtraData.h +++ b/src/standards/Tizen/Contact/JSContactRef.h @@ -14,47 +14,49 @@ * limitations under the License. */ -#ifndef TIZENAPIS_TIZEN_JS_APPLICATION_SERVICE_EXTRA_DATA_H_ -#define TIZENAPIS_TIZEN_JS_APPLICATION_SERVICE_EXTRA_DATA_H_ +/** + * @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 #include #include #include -#include +#include namespace TizenApis { namespace Tizen1_0 { -namespace Application { +namespace Contact { -typedef WrtDeviceApis::CommonsJavaScript::PrivateObject JSApplicationServiceExtraDataPriv; +typedef WrtDeviceApis::CommonsJavaScript::PrivateObject JSContactRefPriv; -class JSApplicationServiceExtraData { +class JSContactRef { public: /* * This initializes this JS class in the JS Engine. */ static JSClassRef getClassRef(); - static JSValueRef createJSObject(JSContextRef context, - const std::string &key, - const std::string &value); - static bool isObjectOfClass(JSContextRef context, JSValueRef value); - static Api::Application::ApplicationServiceExtraDataPtr - getApplicationServiceExtraData(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); + static void Initialize(JSContextRef context, JSObjectRef object); /** * The callback invoked when an object is finalized. */ - static void finalize(JSObjectRef object); + static void Finalize(JSObjectRef object); /** * This structure contains properties and callbacks that define a type of object. @@ -74,25 +76,38 @@ private: static JSClassRef m_classRef; - static Api::Application::ApplicationServiceExtraDataPtr getPrivData(JSObjectRef object); + static JSObjectRef createJSObject(JSContextRef context, TizenApis::Api::Contact::ContactRefPtr contactName); - static JSValueRef getExtraDataKey(JSContextRef context, + 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 setExtraDataKey(JSContextRef context, + static bool setAddressBookId(JSContextRef context, JSObjectRef object, JSStringRef propertyName, - JSValueRef key, + JSValueRef value, JSValueRef* exception); - static JSValueRef getExtraDataValue(JSContextRef context, + static JSValueRef getContactId(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); - static bool setExtraDataValue(JSContextRef context, + static bool setContactId(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, @@ -100,8 +115,8 @@ private: }; -} -} -} -#endif +} // 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 index e8530d5..45f9917 100755 --- a/src/standards/Tizen/Contact/JSContactWebSite.cpp +++ b/src/standards/Tizen/Contact/JSContactWebSite.cpp @@ -22,9 +22,10 @@ */ #include -#include +#include #include #include +//#include #include "ContactConverter.h" #include "JSContactWebSite.h" @@ -39,8 +40,8 @@ namespace Contact { using namespace TizenApis::Commons; using namespace TizenApis::Api::Contact; - -JSClassRef JSContactWebSite::m_classRef = NULL; +using namespace WrtDeviceApis::Commons; +using namespace WrtDeviceApis::CommonsJavaScript; JSClassDefinition JSContactWebSite::m_classInfo = { @@ -57,9 +58,9 @@ JSClassDefinition JSContactWebSite::m_classInfo = NULL, //SetProperty, NULL, //DeleteProperty, NULL, //getPropertyNames, - NULL, - NULL, - NULL, + NULL, //CallAsFunction, + constructor, //CallAsConstructor, + hasInstance, //HasInstance, NULL, //ConvertToType, }; @@ -74,6 +75,8 @@ 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); @@ -81,25 +84,6 @@ JSClassRef JSContactWebSite::getClassRef() { return m_classRef; } -JSValueRef JSContactWebSite::createJSObject(JSContextRef context, - const std::string url, - const ContactWebSiteType type) -{ - ContactWebSitePtr privateData = ContactWebSitePtr(new ContactWebSite()); - if(url != "") - { - privateData->setUrl(url); - privateData->setType(type); - } - JSContactWebSitePriv *priv = new JSContactWebSitePriv(context, privateData); - JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsValueRef) { - LogError("object creation error"); - return JSValueMakeUndefined(context); - } - return jsValueRef; -} - bool JSContactWebSite::isObjectOfClass(JSContextRef context, JSValueRef value) { return JSValueIsObjectOfClass(context, value, getClassRef()); @@ -123,17 +107,37 @@ ContactWebSitePtr JSContactWebSite::getContactWebSite(JSContextRef context, JSVa void JSContactWebSite::Initialize(JSContextRef context, JSObjectRef object) { - assert(NULL != JSObjectGetPrivate(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) { - //delete (JSObjectGetPrivate(object)); + JSContactWebSitePriv *priv = static_cast(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(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; } ContactWebSitePtr JSContactWebSite::getPrivData(JSObjectRef object) { - //LogDebug("entered"); JSContactWebSitePriv *priv = static_cast(JSObjectGetPrivate(object)); if (!priv) { ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); @@ -145,12 +149,105 @@ ContactWebSitePtr JSContactWebSite::getPrivData(JSObjectRef object) return result; } +JSObjectRef JSContactWebSite::constructor(JSContextRef context, + JSObjectRef constructor, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) +{ + LogDebug("entered"); + +// AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); +// TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + JSContactWebSitePriv *priv = static_cast(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 || argumentCount > 2) + 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]) && !JSValueIsNull(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; + } + + ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(gContext); + + std::string url; + ContactWebSiteType type = WEBSITE_TYPE_HOMEPAGE; + bool typeIsSet = false; + + Try { + url = 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(argumentCount >= 2) + { + if(JSValueIsString(gContext, arguments[1])) + { + type = converter->toContactWebSiteType(arguments[1]); + typeIsSet = true; + } + } + } Catch(Exception) { + LogError("Argument type mismatch : " << _rethrown_exception.GetMessage()); + *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, "Wrong arguments"); + return NULL; + } + + ContactWebSitePtr contactWebSite(new ContactWebSite()); + contactWebSite->setUrl(url); + if(typeIsSet) + 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) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -193,14 +290,16 @@ JSValueRef JSContactWebSite::getType(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); ContactWebSitePtr webSite = getPrivData(object); std::string ret = converter->toContactWebSiteTypeStr(webSite->getType()); - return converter->toJSValueRef(ret); + if(!webSite->getTypeIsSet()) + return JSValueMakeNull(context); + else + return converter->toJSValueRef(ret); } Catch(WrtDeviceApis::Commons::Exception) { diff --git a/src/standards/Tizen/Contact/JSContactWebSite.h b/src/standards/Tizen/Contact/JSContactWebSite.h index d53d641..3e6f9d1 100755 --- a/src/standards/Tizen/Contact/JSContactWebSite.h +++ b/src/standards/Tizen/Contact/JSContactWebSite.h @@ -43,10 +43,6 @@ public: */ static JSClassRef getClassRef(); - static JSValueRef createJSObject(JSContextRef context, - const std::string url = "", - const TizenApis::Api::Contact::ContactWebSiteType type = TizenApis::Api::Contact::WEBSITE_TYPE_HOMEPAGE); - static bool isObjectOfClass(JSContextRef context, JSValueRef value); static TizenApis::Api::Contact::ContactWebSitePtr getContactWebSite(JSContextRef context, JSValueRef value); @@ -80,8 +76,21 @@ private: 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, diff --git a/src/standards/Tizen/Contact/JSContactWebSiteArray.cpp b/src/standards/Tizen/Contact/JSContactWebSiteArray.cpp index a34068f..b9de705 100755 --- a/src/standards/Tizen/Contact/JSContactWebSiteArray.cpp +++ b/src/standards/Tizen/Contact/JSContactWebSiteArray.cpp @@ -99,7 +99,6 @@ JSValueRef JSContactWebSiteArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); Try { JSContactWebSiteArrayPriv* priv = @@ -165,12 +164,10 @@ JSClassRef JSContactWebSiteArray::getClassRef() void JSContactWebSiteArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSContactWebSiteArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSContactWebSiteArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -181,7 +178,6 @@ bool JSContactWebSiteArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -209,7 +205,6 @@ JSValueRef JSContactWebSiteArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -241,7 +236,6 @@ bool JSContactWebSiteArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); ContactConverterFactory::ConverterType converter = ContactConverterFactory::getConverter(context); Try @@ -281,7 +275,6 @@ JSValueRef JSContactWebSiteArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { ContactWebSiteArrayPtr webSites = ContactWebSiteArrayPtr(new ContactWebSiteArray()); @@ -327,7 +320,6 @@ JSValueRef JSContactWebSiteArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -363,7 +355,6 @@ JSValueRef JSContactWebSiteArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -392,7 +383,6 @@ JSValueRef JSContactWebSiteArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -419,7 +409,6 @@ JSValueRef JSContactWebSiteArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -444,7 +433,6 @@ JSValueRef JSContactWebSiteArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -472,7 +460,6 @@ JSValueRef JSContactWebSiteArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -522,7 +509,6 @@ JSValueRef JSContactWebSiteArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { ContactConverterFactory::ConverterType converter = @@ -547,7 +533,6 @@ JSValueRef JSContactWebSiteArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -558,7 +543,6 @@ JSValueRef JSContactWebSiteArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -569,7 +553,6 @@ JSValueRef JSContactWebSiteArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -580,7 +563,6 @@ JSValueRef JSContactWebSiteArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/JSStringArray.cpp b/src/standards/Tizen/Contact/JSStringArray.cpp index 24e1f7c..60bf549 100755 --- a/src/standards/Tizen/Contact/JSStringArray.cpp +++ b/src/standards/Tizen/Contact/JSStringArray.cpp @@ -99,7 +99,6 @@ JSValueRef JSStringArray::getLength(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); Try { JSStringArrayPriv* priv = @@ -165,12 +164,10 @@ StringArrayPtr JSStringArray::getStringArray(JSContextRef context, JSValueRef va void JSStringArray::initialize(JSContextRef context, JSObjectRef object) { - //LogDebug("enter"); } void JSStringArray::finalize(JSObjectRef object) { - //LogDebug("enter"); JSStringArrayPriv* priv = static_cast(JSObjectGetPrivate(object)); delete priv; @@ -181,7 +178,6 @@ bool JSStringArray::hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName) { - //LogDebug("enter"); WrtDeviceApis::CommonsJavaScript::BasicConverter converter = WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context); Try @@ -209,7 +205,6 @@ JSValueRef JSStringArray::getProperty(JSContextRef context, JSStringRef propertyName, JSValueRef* exception) { - //LogDebug("enter"); WrtDeviceApis::CommonsJavaScript::BasicConverter converter = WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context); Try @@ -241,7 +236,6 @@ bool JSStringArray::setProperty(JSContextRef context, JSValueRef value, JSValueRef* exception) { - //LogDebug("enter"); WrtDeviceApis::CommonsJavaScript::BasicConverter converter = WrtDeviceApis::CommonsJavaScript::BasicConverterFactory::getConverter(context); Try @@ -281,7 +275,6 @@ JSValueRef JSStringArray::concat(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { StringArrayPtr strs = StringArrayPtr(new StringArray()); @@ -330,7 +323,6 @@ JSValueRef JSStringArray::join(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { std::string result; @@ -365,7 +357,6 @@ JSValueRef JSStringArray::pop(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { WrtDeviceApis::CommonsJavaScript::BasicConverter converter = @@ -394,7 +385,6 @@ JSValueRef JSStringArray::push(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { WrtDeviceApis::CommonsJavaScript::BasicConverter converter = @@ -421,7 +411,6 @@ JSValueRef JSStringArray::reverse(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { WrtDeviceApis::CommonsJavaScript::BasicConverter converter = @@ -446,7 +435,6 @@ JSValueRef JSStringArray::shift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { WrtDeviceApis::CommonsJavaScript::BasicConverter converter = @@ -474,7 +462,6 @@ JSValueRef JSStringArray::slice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("enter"); Try { if (argumentCount < 1) { @@ -524,7 +511,6 @@ JSValueRef JSStringArray::sort(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); Try { WrtDeviceApis::CommonsJavaScript::BasicConverter converter = @@ -549,7 +535,6 @@ JSValueRef JSStringArray::splice(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -560,7 +545,6 @@ JSValueRef JSStringArray::toString(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return join(context, function, thisObject, 0, arguments, exception); } @@ -571,7 +555,6 @@ JSValueRef JSStringArray::unshift(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } @@ -582,7 +565,6 @@ JSValueRef JSStringArray::valueOf(JSContextRef context, const JSValueRef arguments[], JSValueRef* exception) { - //LogDebug("entered"); return JSValueMakeUndefined(context); } diff --git a/src/standards/Tizen/Contact/plugin_config.cpp b/src/standards/Tizen/Contact/plugin_config.cpp index adff30c..c6aa6f1 100755 --- a/src/standards/Tizen/Contact/plugin_config.cpp +++ b/src/standards/Tizen/Contact/plugin_config.cpp @@ -104,7 +104,7 @@ static FunctionMapping createContactFunctions() //getAddressBooks AceFunction getAddressBooksFunc = ACE_CREATE_FUNCTION( - FUNCTION_GET_CONTACTS, + FUNCTION_GET_ADDRESS_BOOKS, CONTACT_FUNCTION_API_GET_ADDRESS_BOOKS, CONTACT_FEATURES_CONTACT_READ_WRITE, DEVICE_LIST_CONTACT_READ); @@ -115,7 +115,7 @@ static FunctionMapping createContactFunctions() //getDefaultAddressBook AceFunction getDefaultAddressBookFunc = ACE_CREATE_FUNCTION( - FUNCTION_GET_DEFAULT_CONTACT, + FUNCTION_GET_DEFAULT_ADDRESS_BOOK, CONTACT_FUNCTION_API_GET_DEFAULT_ADDRESS_BOOK, CONTACT_FEATURES_CONTACT_READ_WRITE, DEVICE_LIST_CONTACT_READ); @@ -124,21 +124,32 @@ static FunctionMapping createContactFunctions() CONTACT_FUNCTION_API_GET_DEFAULT_ADDRESS_BOOK, getDefaultAddressBookFunc)); - - //convertFromString - AceFunction convertFromStringFunc = ACE_CREATE_FUNCTION( - FUNCTION_CREATE_EVENT_FROM_STRING, - CONTACT_FUNCTION_API_CONVERT_FROM_STRING, + //getAddressBook + AceFunction getAddressBookFunc = ACE_CREATE_FUNCTION( + FUNCTION_GET_ADDRESS_BOOK, + CONTACT_FUNCTION_API_GET_ADDRESS_BOOK, CONTACT_FEATURES_CONTACT_READ_WRITE, DEVICE_LIST_CONTACT_READ); contactMapping.insert(std::make_pair( - CONTACT_FUNCTION_API_CONVERT_FROM_STRING, - convertFromStringFunc)); + CONTACT_FUNCTION_API_GET_ADDRESS_BOOK, + getAddressBookFunc)); + + +// //convertFromString +// AceFunction convertFromStringFunc = ACE_CREATE_FUNCTION( +// FUNCTION_CONVERT_CONTACT_FROM_STRING, +// CONTACT_FUNCTION_API_CONVERT_FROM_STRING, +// CONTACT_FEATURES_CONTACT_READ_WRITE, +// DEVICE_LIST_CONTACT_READ); +// +// contactMapping.insert(std::make_pair( +// CONTACT_FUNCTION_API_CONVERT_FROM_STRING, +// convertFromStringFunc)); //convertToString AceFunction convertToStringFunc = ACE_CREATE_FUNCTION( - FUNCTION_EXPORT_EVENT_TO_STRING, + FUNCTION_CONVERT_CONTACT_TO_STRING, CONTACT_FUNCTION_API_CONVERT_TO_STRING, CONTACT_FEATURES_CONTACT_READ_WRITE, DEVICE_LIST_CONTACT_READ); @@ -149,7 +160,7 @@ static FunctionMapping createContactFunctions() //add AceFunction addFunc = ACE_CREATE_FUNCTION( - FUNCTION_ADD_EVENT, + FUNCTION_ADD_CONTACT, CONTACT_FUNCTION_API_ADD, CONTACT_FEATURES_CONTACT_WRITE, DEVICE_LIST_CONTACT_WRITE); @@ -160,7 +171,7 @@ static FunctionMapping createContactFunctions() //addBatch AceFunction addBatchFunc = ACE_CREATE_FUNCTION( - FUNCTION_ADD_EVENTS, + FUNCTION_ADD_CONTACTS, CONTACT_FUNCTION_API_ADD_BATCH, CONTACT_FEATURES_CONTACT_WRITE, DEVICE_LIST_CONTACT_WRITE); @@ -171,7 +182,7 @@ static FunctionMapping createContactFunctions() //update AceFunction updateFunc = ACE_CREATE_FUNCTION( - FUNCTION_UPDATE_EVENT, + FUNCTION_UPDATE_CONTACT, CONTACT_FUNCTION_API_UPDATE, CONTACT_FEATURES_CONTACT_WRITE, DEVICE_LIST_CONTACT_WRITE); @@ -182,7 +193,7 @@ static FunctionMapping createContactFunctions() //updateBatch AceFunction updateBatchFunc = ACE_CREATE_FUNCTION( - FUNCTION_UPDATE_EVENTS, + FUNCTION_UPDATE_CONTACTS, CONTACT_FUNCTION_API_UPDATE_BATCH, CONTACT_FEATURES_CONTACT_WRITE, DEVICE_LIST_CONTACT_WRITE); @@ -193,7 +204,7 @@ static FunctionMapping createContactFunctions() //remove AceFunction removeFunc = ACE_CREATE_FUNCTION( - FUNCTION_DELETE_EVENT, + FUNCTION_DELETE_CONTACT, CONTACT_FUNCTION_API_REMOVE, CONTACT_FEATURES_CONTACT_WRITE, DEVICE_LIST_CONTACT_WRITE); @@ -204,7 +215,7 @@ static FunctionMapping createContactFunctions() //removeBatch AceFunction removeBatchFunc = ACE_CREATE_FUNCTION( - FUNCTION_DELETE_EVENTS, + FUNCTION_DELETE_CONTACTS, CONTACT_FUNCTION_API_REMOVE_BATCH, CONTACT_FEATURES_CONTACT_WRITE, DEVICE_LIST_CONTACT_WRITE); @@ -215,7 +226,7 @@ static FunctionMapping createContactFunctions() //find AceFunction findFunc = ACE_CREATE_FUNCTION( - FUNCTION_FIND_EVENTS, + FUNCTION_FIND_CONTACTS, CONTACT_FUNCTION_API_FIND, CONTACT_FEATURES_CONTACT_READ, DEVICE_LIST_CONTACT_READ); diff --git a/src/standards/Tizen/Contact/plugin_config.h b/src/standards/Tizen/Contact/plugin_config.h index 5a6c94b..11441b4 100755 --- a/src/standards/Tizen/Contact/plugin_config.h +++ b/src/standards/Tizen/Contact/plugin_config.h @@ -27,7 +27,8 @@ namespace Contact { #define CONTACT_FUNCTION_API_GET_ADDRESS_BOOKS "getAddressBooks" #define CONTACT_FUNCTION_API_GET_DEFAULT_ADDRESS_BOOK "getDefaultAddressBook" -#define CONTACT_FUNCTION_API_CONVERT_FROM_STRING "convertFromString" +#define CONTACT_FUNCTION_API_GET_ADDRESS_BOOK "getAddressBook" +//#define CONTACT_FUNCTION_API_CONVERT_FROM_STRING "convertFromString" #define CONTACT_FUNCTION_API_CONVERT_TO_STRING "convertToString" #define CONTACT_FUNCTION_API_ADD "add" #define CONTACT_FUNCTION_API_ADD_BATCH "addBatch" diff --git a/src/standards/Tizen/Contact/plugin_initializer.cpp b/src/standards/Tizen/Contact/plugin_initializer.cpp index 4493294..0840b76 100755 --- a/src/standards/Tizen/Contact/plugin_initializer.cpp +++ b/src/standards/Tizen/Contact/plugin_initializer.cpp @@ -26,6 +26,16 @@ #include #include #include "JSContactManager.h" +#include "JSContact.h" +#include "JSContactRef.h" +#include "JSContactName.h" +#include "JSContactOrganization.h" +#include "JSContactWebSite.h" +#include "JSContactAnniversary.h" +#include "JSContactAccount.h" +#include "JSContactAddress.h" +#include "JSContactPhoneNumber.h" +#include "JSContactEmailAddress.h" void on_widget_start_callback(int widgetId, JavaScriptContext context, @@ -66,4 +76,44 @@ PLUGIN_CLASS_MAP_BEGIN "contact", TizenApis::Tizen1_0::Contact::JSContactManager::getClassRef(), NULL) + PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "Contact", + TizenApis::Tizen1_0::Contact::JSContact::getClassRef(), + NULL) + PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "ContactRef", + TizenApis::Tizen1_0::Contact::JSContactRef::getClassRef(), + NULL) + PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "ContactName", + TizenApis::Tizen1_0::Contact::JSContactName::getClassRef(), + NULL) + PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "ContactOrganization", + TizenApis::Tizen1_0::Contact::JSContactOrganization::getClassRef(), + NULL) + PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "ContactWebSite", + TizenApis::Tizen1_0::Contact::JSContactWebSite::getClassRef(), + NULL) + PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "ContactAnniversary", + TizenApis::Tizen1_0::Contact::JSContactAnniversary::getClassRef(), + NULL) + PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "ContactAccount", + TizenApis::Tizen1_0::Contact::JSContactAccount::getClassRef(), + NULL) + PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "ContactAddress", + TizenApis::Tizen1_0::Contact::JSContactAddress::getClassRef(), + NULL) + PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "ContactPhoneNumber", + TizenApis::Tizen1_0::Contact::JSContactPhoneNumber::getClassRef(), + NULL) + PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN, + "ContactEmailAddress", + TizenApis::Tizen1_0::Contact::JSContactEmailAddress::getClassRef(), + NULL) PLUGIN_CLASS_MAP_END diff --git a/src/standards/Tizen/Filesystem/CMakeLists.txt b/src/standards/Tizen/Filesystem/CMakeLists.txt index 5a3b7b1..edb93b0 100755 --- a/src/standards/Tizen/Filesystem/CMakeLists.txt +++ b/src/standards/Tizen/Filesystem/CMakeLists.txt @@ -1,9 +1,15 @@ set(TARGET_NAME "wrt-plugins-tizen-1.0-filesystem") set(DESTINATION_NAME "tizen-1.0-filesystem") +set(TARGET_IMPL_NAME "wrt-plugins-tizen-1.0-filesystem-impl") include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_FILESYSTEM}) -set(SRCS +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 @@ -12,24 +18,29 @@ set(SRCS JSStorage.cpp Converter.cpp EventGetNodeData.cpp - plugin_initializer.cpp plugin_config.cpp Encodings.cpp StorageStaticController.cpp FilesystemUtils.cpp ResponseDispatcher.cpp - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp ) -add_library(${TARGET_NAME} SHARED ${SRCS}) -target_link_libraries(${TARGET_NAME} - wrt-plugins-tizen-1.0-tizen +add_library(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL}) +target_link_libraries(${TARGET_IMPL_NAME} + wrt-plugins-tizen-1.0-tizen-impl ${LIBS_COMMON} ${LIBS_WIDGETDB} ${LIBS_PLATFORM_IMPLEMENTATION_FILESYSTEM} ) -INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${DESTINATION_NAME}) +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 index c42370b..e46e381 100755 --- a/src/standards/Tizen/Filesystem/Converter.cpp +++ b/src/standards/Tizen/Filesystem/Converter.cpp @@ -72,6 +72,7 @@ JSValueRef Converter::toJSValueRef( 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: @@ -107,6 +108,7 @@ JSValueRef Converter::toJSValueRef( 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: @@ -245,21 +247,21 @@ std::string Converter::toEncoding(const JSValueRef& arg) } ThrowMsg(Commons::InvalidArgumentException, "Invalid encoding"); } -JSValueRef Converter::toStorageType(const short type) +JSValueRef Converter::toStorageState(const short type) { switch (type) { - case Api::Filesystem::StorageProperties::STATE_MOUNTED: + case JSStorage::STATE_MOUNTED: return toJSValueRef(STORAGE_TYPE_STATE_MOUNTED); - case Api::Filesystem::StorageProperties::STATE_REMOVED: + case JSStorage::STATE_REMOVED: return toJSValueRef(STORAGE_TYPE_STATE_REMOVED); - case Api::Filesystem::StorageProperties::STATE_UNMOUNTABLE: + case JSStorage::STATE_UNMOUNTABLE: return toJSValueRef(STORAGE_TYPE_STATE_UNMOUNTABLE); } ThrowMsg(Commons::InvalidArgumentException, "Invalid storage type"); } -JSValueRef Converter::toStorageState(const short state) +JSValueRef Converter::toStorageType(const short state) { switch (state) { diff --git a/src/standards/Tizen/Filesystem/FilesystemUtils.cpp b/src/standards/Tizen/Filesystem/FilesystemUtils.cpp index 38fdac1..b3d6386 100755 --- a/src/standards/Tizen/Filesystem/FilesystemUtils.cpp +++ b/src/standards/Tizen/Filesystem/FilesystemUtils.cpp @@ -78,8 +78,8 @@ const PathToRootMap& getPathToRootMap() IPathPtr fromVirtualPath(JSContextRef context, const std::string& arg) { - IWrtWrapperPtr wrt = WrtWrappersMgr::getInstance().getWrtWrapper(context); - Assert(wrt && "WrtWrapper not found, not a GLOBAL context supplied?"); +/* IWrtWrapperPtr wrt = WrtWrappersMgr::getInstance().getWrtWrapper(context); + Assert(wrt && "WrtWrapper not found, not a GLOBAL context supplied?");*/ if (!isPathValid(arg)) { ThrowMsg(Commons::NotFoundException, "Not found path component."); @@ -95,13 +95,13 @@ IPathPtr fromVirtualPath(JSContextRef context, root = arg; } - WidgetDB::Api::IWidgetDBPtr widgetDB = - WidgetDB::Api::getWidgetDB(wrt->getWidgetId()); +/* WidgetDB::Api::IWidgetDBPtr widgetDB = + WidgetDB::Api::getWidgetDB(wrt->getWidgetId());*/ RootToPathMap rootToPath = getRootToPathMap(); - rootToPath["wgt-package"] = widgetDB->getWidgetInstallationPath(); +/* rootToPath["wgt-package"] = widgetDB->getWidgetInstallationPath(); rootToPath["wgt-private"] = widgetDB->getWidgetPersistentStoragePath(); - rootToPath["wgt-private-tmp"] = widgetDB->getWidgetTemporaryStoragePath(); + rootToPath["wgt-private-tmp"] = widgetDB->getWidgetTemporaryStoragePath();*/ RootToPathMapIterator it = rootToPath.find(root); if (it == rootToPath.end()) { ThrowMsg(Commons::NotFoundException, "Location not found."); diff --git a/src/standards/Tizen/Filesystem/JSFile.cpp b/src/standards/Tizen/Filesystem/JSFile.cpp index 6554b41..64d7a76 100755 --- a/src/standards/Tizen/Filesystem/JSFile.cpp +++ b/src/standards/Tizen/Filesystem/JSFile.cpp @@ -810,7 +810,7 @@ JSValueRef JSFile::deleteDirectory(JSContextRef context, Converter converter(context); IPathPtr path = Utils::fromVirtualPath(globalContext, converter.toString(argv[0])); - bool recursive = recursive = converter.toBool(argv[1]); + bool recursive = converter.toBool(argv[1]); if (*privateObject->getObject()->getPath() != path->getPath()) { return JSTizenExceptionFactory::postException(context, exception, JSTizenException::IO_ERROR, "IO error"); diff --git a/src/standards/Tizen/Filesystem/JSFilesystemManager.cpp b/src/standards/Tizen/Filesystem/JSFilesystemManager.cpp index 63b0e30..76231f7 100755 --- a/src/standards/Tizen/Filesystem/JSFilesystemManager.cpp +++ b/src/standards/Tizen/Filesystem/JSFilesystemManager.cpp @@ -33,6 +33,9 @@ #include #include #include +#include +#include +#include #include "JSFile.h" #include "FilesystemUtils.h" @@ -45,6 +48,8 @@ using namespace WrtDeviceApis::Commons; using namespace WrtDeviceApis::CommonsJavaScript; using namespace TizenApis::Commons; +using namespace WrtDeviceApis; +using namespace TizenApis::Api::Filesystem; namespace { @@ -135,6 +140,22 @@ void JSFilesystemManager::initialize(JSContextRef context, if (!JSObjectSetPrivate(object, privateObject)) { delete privateObject; } + else { + IWrtWrapperPtr wrt = WrtWrappersMgr::getInstance().getWrtWrapper(context); + WidgetDB::Api::IWidgetDBPtr widgetDB = WidgetDB::Api::getWidgetDB(wrt->getWidgetId()); + + Assert(wrt && "WrtWrapper not found, not a GLOBAL context supplied?"); + + 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) diff --git a/src/standards/Tizen/Filesystem/JSStorage.cpp b/src/standards/Tizen/Filesystem/JSStorage.cpp index c43aa84..21dbb4c 100755 --- a/src/standards/Tizen/Filesystem/JSStorage.cpp +++ b/src/standards/Tizen/Filesystem/JSStorage.cpp @@ -37,11 +37,11 @@ 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_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"; +const char* STR_STATE_UNMOUNTABLE = "UNMOUNTABLE";*/ } //private namespace JSClassDefinition JSStorage::m_classInfo = { diff --git a/src/standards/Tizen/Geocoder/CMakeLists.txt b/src/standards/Tizen/Geocoder/CMakeLists.txt index ee5238c..526f453 100755 --- a/src/standards/Tizen/Geocoder/CMakeLists.txt +++ b/src/standards/Tizen/Geocoder/CMakeLists.txt @@ -11,9 +11,6 @@ set(SRCS GeocoderController.cpp plugin_initializer.cpp plugin_config.cpp - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp ) add_library(${TARGET_NAME} SHARED ${SRCS}) diff --git a/src/standards/Tizen/Mediacontent/CMakeLists.txt b/src/standards/Tizen/Mediacontent/CMakeLists.txt index 216e70d..5237ea5 100755 --- a/src/standards/Tizen/Mediacontent/CMakeLists.txt +++ b/src/standards/Tizen/Mediacontent/CMakeLists.txt @@ -2,21 +2,15 @@ set(TARGET_NAME "wrt-plugins-tizen-1.0-mediacontent") set(DESTINATION_NAME "tizen-1.0-mediacontent") include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_MEDIACONTENT}) +set(CMAKE_INSTALL_RPATH + ${CMAKE_INSTALL_RPATH} + ${CMAKE_INSTALL_PREFIX}/tizen-1.0-tizen +) + set(SRCS ${SRCS_PLATFORM_API_MEDIACONTENT} ${SRCS_PLATFORM_IMPLEMENTATION_MEDIACONTENT} ${SRCS_PLATFORM_API_WRT_WRAPPER} - ${SRCS_PLATFORM_API_FILTER} - ../Tizen/FilterConverter.cpp - ../Tizen/JSAttributeFilter.cpp - ../Tizen/JSAttributeRangeFilter.cpp - ../Tizen/JSCompositeFilter.cpp - ../Tizen/JSAbstractFilterArray.cpp - ../Tizen/JSSortMode.cpp - ../Common/JSGlobalContextFactory.cpp - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp JSMediacontent.cpp JSFolder.cpp JSMedia.cpp @@ -27,11 +21,13 @@ set(SRCS JSMediacontentManager.cpp MediacontentController.cpp plugin_initializer.cpp + plugin_config.cpp MediaConverter.cpp ) add_library(${TARGET_NAME} SHARED ${SRCS}) target_link_libraries(${TARGET_NAME} + wrt-plugins-tizen-1.0-tizen-impl ${LIBS_PLATFORM_IMPLEMENTATION_MEDIACONTENT} ${LIBS_COMMON} ) diff --git a/src/standards/Tizen/Mediacontent/JSAudio.cpp b/src/standards/Tizen/Mediacontent/JSAudio.cpp index af87666..9e43e05 100644 --- a/src/standards/Tizen/Mediacontent/JSAudio.cpp +++ b/src/standards/Tizen/Mediacontent/JSAudio.cpp @@ -264,7 +264,6 @@ JSValueRef JSAudio::getPropertyLyrics( //MediaConverter converter(globalContext); MediacontentAudioPtr event = getAudioObject(object); - //Todo. Lyrics return converter->toJSValueRef(event->getAudioLyrics()); } Catch(Exception) diff --git a/src/standards/Tizen/Mediacontent/JSFolder.cpp b/src/standards/Tizen/Mediacontent/JSFolder.cpp index 7d43980..920daba 100644 --- a/src/standards/Tizen/Mediacontent/JSFolder.cpp +++ b/src/standards/Tizen/Mediacontent/JSFolder.cpp @@ -42,7 +42,6 @@ namespace Mediacontent { #define TIZEN_MEDIACONTENT_FOLDER_PATH "folderUrl" #define TIZEN_MEDIACONTENT_FOLDER_STORAGE_TYPE "storageType" #define TIZEN_MEDIACONTENT_FOLDER_MODIFIEDDATE "modifiedDate" -#define TIZEN_MEDIACONTENT_FOLDER_MEDIAID "mediaItems" JSClassDefinition JSFolder::m_classInfo = @@ -74,8 +73,7 @@ JSStaticValue JSFolder::m_property[] = { TIZEN_MEDIACONTENT_FOLDER_PATH, getPropertyPath, NULL, kJSPropertyAttributeReadOnly}, { TIZEN_MEDIACONTENT_FOLDER_STORAGE_TYPE, getPropertyStorageType, NULL, kJSPropertyAttributeReadOnly}, { TIZEN_MEDIACONTENT_FOLDER_MODIFIEDDATE, getPropertyModifiedDate, NULL, kJSPropertyAttributeReadOnly}, - { TIZEN_MEDIACONTENT_FOLDER_MEDIAID, getPropertyMediaId, NULL, kJSPropertyAttributeReadOnly}, - { 0, 0, 0, 0 } + { 0, 0, 0, 0 } }; JSStaticFunction JSFolder::m_function[] = @@ -294,73 +292,6 @@ JSValueRef JSFolder::getPropertyMediaId( } -/* -JSValueRef JSFolder::findMedia( - JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception ) -{ - FolderPrivObject *privFolder = static_cast(JSObjectGetPrivate(thisObject)); - - LogDebug("JSFolder::FolderfindMedia entered" << getClassInfo()); - - assert(privFolder); - - JSCallbackManagerPtr cbm(NULL); - Try - { - IMediacontentPtr mediacontent = Api::MediacontentFactory::getInstance().createMediacontentObject(); - - if (argumentCount < 1) - { - LogError("No callback parameters"); - return JSExceptionFactory::TypeMismatchException.make(context, exception); - } - JSValueRef onError = (argumentCount > 1 ? getFunctionOrNull(context, arguments[1]) : NULL); - JSContextRef globalContext = privFolder->getContext(); - JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError); - Commons::Validator validator(context); - if (validator.isCallback(arguments[0])) - { - cbm->setOnSuccess(arguments[0]); - } - else if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0])) - { - cbm->callOnError(JSExceptionFactory::InvalidValuesException.make(context)); - return JSValueMakeUndefined(context); - } - else - { - return JSExceptionFactory::TypeMismatchException.make(context, exception); - } - IEventFolderFindMediaPtr dplEvent(new IEventFolderFindMedia()); - MediacontentFolderPtr folder = getFolderObject(thisObject); - dplEvent->setFolder(folder); - dplEvent->setPrivateData( DPL::StaticPointerCast (cbm)); - dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance()); - mediacontent->folderFindMedia(dplEvent); - - return Utils::makePendingOperation(cbm->getContext(), dplEvent); - } - Catch(Commons::InvalidArgumentException) - { - LogError("Invalid argument"); - return JSExceptionFactory::TypeMismatchException.make(context, exception); - } - Catch(Commons::Exception) - { - LogError("unknow error occured"); - } - if (NULL != cbm) { - cbm->callOnError(JSExceptionFactory::UnknownException.make(privFolder->getContext())); - } - return JSValueMakeUndefined(context); - -} -*/ } } diff --git a/src/standards/Tizen/Mediacontent/JSImage.cpp b/src/standards/Tizen/Mediacontent/JSImage.cpp index 30c59ed..6443119 100644 --- a/src/standards/Tizen/Mediacontent/JSImage.cpp +++ b/src/standards/Tizen/Mediacontent/JSImage.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "JSMediacontent.h" #include "JSImage.h" @@ -31,7 +32,7 @@ #define TIZEN_MEDIACONTENT_IMAGE_HEIGHT "height" #define TIZEN_MEDIACONTENT_IMAGE_ORIENTATION "orientation" - +using namespace TizenApis::Tizen1_0::Tizen; namespace TizenApis { namespace Tizen1_0 { @@ -137,8 +138,12 @@ JSValueRef JSImage::getPropertyGeoLocation( Converter converter(context); MediacontentImagePtr event = getImageObject(object); - //Todo. change to getPropertyGeoLocation - return converter.toJSValueRef(event->getImageLongitude()); + LogDebug("lati :" << event->getImageLatitude()); + LogDebug("longi :" << event->getImageLongitude()); + SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(event->getImageLatitude(),event->getImageLongitude())); + return JSSimpleCoordinates::createJSObject(context,geoPtr); + //return converter.toJSValueRef(event->getImageWidth()); + } Catch(Exception) { @@ -148,7 +153,6 @@ JSValueRef JSImage::getPropertyGeoLocation( } - JSValueRef JSImage::getPropertyWidth( JSContextRef context, JSObjectRef object, diff --git a/src/standards/Tizen/Mediacontent/JSImage.h b/src/standards/Tizen/Mediacontent/JSImage.h index f407244..6488542 100644 --- a/src/standards/Tizen/Mediacontent/JSImage.h +++ b/src/standards/Tizen/Mediacontent/JSImage.h @@ -22,6 +22,8 @@ #include #include #include +#include + #include "JSMedia.h" diff --git a/src/standards/Tizen/Mediacontent/JSMedia.cpp b/src/standards/Tizen/Mediacontent/JSMedia.cpp index 449e5c4..8a037fa 100644 --- a/src/standards/Tizen/Mediacontent/JSMedia.cpp +++ b/src/standards/Tizen/Mediacontent/JSMedia.cpp @@ -42,6 +42,8 @@ namespace Mediacontent { #define TIZEN_MEDIACONTENT_MEDIA_MODIFIEDDATE "modifiedDate" #define TIZEN_MEDIACONTENT_MEDIA_DESCRIPTION "description" #define TIZEN_MEDIACONTENT_MEDIA_RATING "rating" +#define TIZEN_MEDIACONTENT_MEDIA_EDIABLEATTR "editableAttibutes" + JSClassDefinition JSMedia::m_classInfo = @@ -79,6 +81,7 @@ JSStaticValue JSMedia::m_property[] = { TIZEN_MEDIACONTENT_MEDIA_RELEASEDDATE, getPropertyReleasedDate, NULL, kJSPropertyAttributeReadOnly}, { TIZEN_MEDIACONTENT_MEDIA_MODIFIEDDATE, getPropertyModifiedDate, NULL, kJSPropertyAttributeReadOnly}, { TIZEN_MEDIACONTENT_MEDIA_DESCRIPTION, getPropertyDescription, NULL, kJSPropertyAttributeReadOnly}, + { TIZEN_MEDIACONTENT_MEDIA_EDIABLEATTR, getPropertyEditableAttr, NULL, kJSPropertyAttributeReadOnly}, { TIZEN_MEDIACONTENT_MEDIA_RATING, getPropertyFavorite, setPropertyFavorite, kJSPropertyAttributeNone}, { 0, 0, 0, 0 } }; @@ -373,6 +376,44 @@ JSValueRef JSMedia::getPropertyType( return JSValueMakeUndefined(context); } +JSValueRef JSMedia::getPropertyEditableAttr( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + Try + { + Converter converter(context); + MediacontentMediaPtr event = getMediaObject(object); + EditableAttributeListPtr editableAttrPtr = event->getEditableAttr(); + JSObjectRef jsResult = JSCreateArrayObject(context, 0, NULL); + + if(editableAttrPtr) + { + if (NULL == jsResult) + { + ThrowMsg(NullPointerException, "Could not create js array object"); + } + for(unsigned int i=0; isize(); i++) + { + JSValueRef val = converter.toJSValueRef(editableAttrPtr->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::setPropertyFavorite( JSContextRef context, diff --git a/src/standards/Tizen/Mediacontent/JSMedia.h b/src/standards/Tizen/Mediacontent/JSMedia.h index 2ec6789..0035f9f 100644 --- a/src/standards/Tizen/Mediacontent/JSMedia.h +++ b/src/standards/Tizen/Mediacontent/JSMedia.h @@ -145,7 +145,13 @@ class JSMedia JSContextRef context, JSObjectRef object, JSStringRef propertyName, - JSValueRef* exception); + JSValueRef* exception); + static JSValueRef getPropertyEditableAttr( + JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception); + static bool setPropertyFavorite( JSContextRef context, diff --git a/src/standards/Tizen/Mediacontent/JSMediacontent.cpp b/src/standards/Tizen/Mediacontent/JSMediacontent.cpp index e6597f2..3829db3 100644 --- a/src/standards/Tizen/Mediacontent/JSMediacontent.cpp +++ b/src/standards/Tizen/Mediacontent/JSMediacontent.cpp @@ -28,14 +28,16 @@ #include #include - - #include #include "MediacontentController.h" #include "JSMediacontent.h" #include "JSMediacontentManager.h" #include "JSMedia.h" #include "MediaConverter.h" +#include "plugin_config.h" + + + using namespace TizenApis::Commons; using namespace TizenApis::Api::Tizen; @@ -96,8 +98,10 @@ JSStaticValue JSMediacontent::m_property[] = JSStaticFunction JSMediacontent::m_function[] = { { "findItems", findMedia, kJSPropertyAttributeNone }, - { "findFolders", findFolders, kJSPropertyAttributeNone }, - { "updateItem", updateItem, kJSPropertyAttributeNone }, + { "getFolders", getFolders, kJSPropertyAttributeNone }, + { "browseFolder", browseFolder, kJSPropertyAttributeNone }, + { "updateItem", updateItem, kJSPropertyAttributeNone }, + { "updateItemsBatch", updateItemsBatch, kJSPropertyAttributeNone }, { 0, 0, 0 } }; @@ -159,6 +163,10 @@ JSValueRef JSMediacontent::findMedia( MediacontentPrivObject *privateObject = static_cast( JSObjectGetPrivate( thisObject ) ) ; assert(privateObject); + + AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(privateObject->getContext(), MEDIACONTENT_FUNCTION_API_FIND_ITEMS); + + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); JSContextRef globalContext = privateObject->getContext(); @@ -174,11 +182,7 @@ JSValueRef JSMediacontent::findMedia( { if (argumentCount == 0 || (!validator.isCallback(arguments[0])) || - (argumentCount >= 2 && (!validator.isCallback(arguments[1]))) //|| -// (argumentCount >= 3 && (!JSValueIsObject(context, arguments[2]) /*&& !validator.isNullOrUndefined(arguments[2])*/)) -// (argumentCount >= 4 && (!JSValueIsObject(context, arguments[3]) /*&& !validator.isNullOrUndefined(arguments[3])*/)) || -// (argumentCount >= 5 && (!JSValueIsObject(context, arguments[4]) /*&& !validator.isNullOrUndefined(arguments[4]))*/)) || - /*(argumentCount >= 6 && (!JSValueIsObject(context, arguments[5]) && !validator.isNullOrUndefined(arguments[4]))))*/) + (argumentCount >= 2 && (!validator.isCallback(arguments[1]))) ) { LogDebug("Argument type mismatch"); Throw(InvalidArgumentException); @@ -206,9 +210,11 @@ JSValueRef JSMediacontent::findMedia( } if (argumentCount >= 4 && !validator.isNullOrUndefined(arguments[3])) { - SortModeArrayPtr sortModes(new SortModeArray()); - sortModes->push_back(filterConverter->toSortMode(arguments[3])); - dplEvent->setSortModes(sortModes); + // 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); + } if (argumentCount >= 5 && !validator.isNullOrUndefined(arguments[4])) { @@ -242,7 +248,7 @@ JSValueRef JSMediacontent::findMedia( } -JSValueRef JSMediacontent::findFolders( +JSValueRef JSMediacontent::getFolders( JSContextRef context, JSObjectRef object, JSObjectRef thisObject, @@ -257,9 +263,10 @@ JSValueRef JSMediacontent::findFolders( assert(privateObject); - //TODO. - //AceSecurityStatus status = CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_FIND); - //TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(privateObject->getContext(), MEDIACONTENT_FUNCTION_API_GET_FOLDERS); + + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + JSContextRef globalContext = privateObject->getContext(); Validator validator(context); @@ -274,16 +281,11 @@ JSValueRef JSMediacontent::findFolders( Try { - if (argumentCount == 0 || - (!validator.isCallback(arguments[0])) || + if ((!validator.isCallback(arguments[0])) || (argumentCount >= 2 && (!validator.isCallback(arguments[1]))) || - (argumentCount >= 3 && (!JSValueIsObject(context, arguments[2]) /*&& !validator.isNullOrUndefined(arguments[2])*/)) -// (argumentCount >= 4 && (!JSValueIsObject(context, arguments[3]) /*&& !validator.isNullOrUndefined(arguments[3])*/)) || -// (argumentCount >= 5 && (!JSValueIsObject(context, arguments[4]) /*&& !validator.isNullOrUndefined(arguments[4]))*/)) || - /*(argumentCount >= 6 && (!JSValueIsObject(context, arguments[5]) && !validator.isNullOrUndefined(arguments[4]))))*/) - { - LogDebug("Argument type mismatch"); - Throw(InvalidArgumentException); + (argumentCount >= 3 && (!JSValueIsObject(context, arguments[2]) && !validator.isNullOrUndefined(arguments[2])))) + { + ThrowMsg(ConversionException, "Wrong parameter type."); } if (cbm) @@ -294,6 +296,10 @@ JSValueRef JSMediacontent::findFolders( { onErrorForCbm = arguments[1]; } + if (argumentCount >= 3) + { + onErrorForCbm = arguments[2]; + } cbm->setOnSuccess(onSuccessForCbm); cbm->setOnError(onErrorForCbm); } @@ -302,27 +308,6 @@ JSValueRef JSMediacontent::findFolders( dplEvent->setPrivateData( DPL::StaticPointerCast (cbm)); dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance()); - if (argumentCount >= 3 && !validator.isNullOrUndefined(arguments[2])) - { - dplEvent->setFilter(filterConverter->toFilter(arguments[2])); - } - if (argumentCount >= 4 && !validator.isNullOrUndefined(arguments[3])) - { - SortModeArrayPtr sortModes(new SortModeArray()); - sortModes->push_back(filterConverter->toSortMode(arguments[3])); - dplEvent->setSortModes(sortModes); - } - if (argumentCount >= 5 && !validator.isNullOrUndefined(arguments[4])) - { - long limit = filterConverter->toLong(arguments[4]); - dplEvent->setLimit(limit); - } - if (argumentCount >= 6 && !validator.isNullOrUndefined(arguments[5])) - { - long offset = filterConverter->toLong(arguments[5]); - dplEvent->setOffset(offset); - - } mediacontent->findFolder(dplEvent); } @@ -344,132 +329,198 @@ JSValueRef JSMediacontent::findFolders( } -JSValueRef JSMediacontent::updateItem( - JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) +JSValueRef JSMediacontent::browseFolder( + JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception ) { - LogDebug("updateItem::entered"); - - MediacontentPrivObject *privateObject = static_cast( JSObjectGetPrivate( thisObject ) ) ; - assert(privateObject); + LogDebug("JSMediacontent::browseFolder entered"); - //AceSecurityStatus - //TIZEN_SYNC_ACCESS_HANDLER - Validator validator(context); - IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception); + MediacontentPrivObject *privateObject = static_cast( JSObjectGetPrivate( thisObject ) ) ; + assert(privateObject); - Try - { - if (argumentCount == 0 || - (!JSValueIsObject(context, arguments[0])) || - (argumentCount >= 2 && (!validator.isNullOrUndefined(arguments[1]) && (!validator.isCallback(arguments[1])))) || - (argumentCount >= 3 && (!validator.isNullOrUndefined(arguments[2]) && (!validator.isCallback(arguments[2])))) ) - { - LogDebug("Argument type mismatch"); - Throw(InvalidArgumentException); - } - - JSObjectRef arg = JSValueToObject(context, arguments[0], exception); - MediacontentMediaPtr event = JSMedia::getMediaObject(arg); - IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia()); - dplEvent->setMediaItem(event); - dplEvent->setForSynchronousCall(); + AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(privateObject->getContext(), MEDIACONTENT_FUNCTION_API_BROWSE_FOLDER); - mediacontent->updateMedia(dplEvent); - if (dplEvent->getResult()) - { - return JSValueMakeNull(context); - } - else - { - ThrowMsg(UnknownException, "Updating failed by unkown reason."); - } + 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); + + IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception); + + Try + { + + if (argumentCount == 0 || + (!validator.isCallback(arguments[1])) || + (argumentCount >= 3 && (!validator.isCallback(arguments[2]))) || + (argumentCount >= 4 && (!JSValueIsObject(context, arguments[3]) )) ) + { + LogDebug("Argument type mismatch"); + Throw(InvalidArgumentException); + } + + if (cbm) + { + JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL; + onSuccessForCbm = arguments[1]; + if (argumentCount >= 3) + { + onErrorForCbm = arguments[2]; + } + cbm->setOnSuccess(onSuccessForCbm); + cbm->setOnError(onErrorForCbm); } - Catch(InvalidArgumentException) + + IEventBrowseFolderPtr dplEvent(new IEventBrowseFolder()); + dplEvent->setFolderID(mediaConverter.toString(arguments[0])); + dplEvent->setPrivateData( DPL::StaticPointerCast (cbm)); + dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance()); + + if (argumentCount >= 4 && !validator.isNullOrUndefined(arguments[3])) + { + dplEvent->setFilter(filterConverter->toFilter(arguments[3])); + } + if (argumentCount >= 5 && !validator.isNullOrUndefined(arguments[4])) { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR); + TizenApis::Api::Tizen::SortModeArrayPtr sortModes(new TizenApis::Api::Tizen::SortModeArray()); + sortModes->push_back(filterConverter->toSortMode(arguments[3])); + dplEvent->setSortModes(sortModes); + } - Catch(ConversionException) + if (argumentCount >= 6 && !validator.isNullOrUndefined(arguments[5])) { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR); + long limit = filterConverter->toLong(arguments[5]); + dplEvent->setLimit(limit); } - Catch(Exception) + if (argumentCount >= 7 && !validator.isNullOrUndefined(arguments[6])) { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR); - } + long offset = filterConverter->toLong(arguments[6]); + dplEvent->setOffset(offset); + } + + mediacontent->browseFolder(dplEvent); + } + Catch(InvalidArgumentException) + { + return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR); + } + Catch(ConversionException) + { + return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR); + } + Catch(Exception) + { + return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR); + } + + return JSValueMakeNull(context); - return JSValueMakeNull(context); } -/* -JSValueRef JSMediacontent::findPlaylist( - JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception ) +JSValueRef JSMediacontent::updateItemsBatch(JSContextRef context, + JSObjectRef object, + JSObjectRef thisObject, + size_t argumentCount, + const JSValueRef arguments[], + JSValueRef* exception) { - LogDebug("JSMediacontent::findMedia entered"); + LogDebug("entered"); MediacontentPrivObject *privateObject = static_cast( JSObjectGetPrivate( thisObject ) ) ; assert(privateObject); + JSContextRef globalContext = privateObject->getContext(); + AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(globalContext, MEDIACONTENT_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); + + IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception); + Try { - IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception); - if (argumentCount < 1) - { - LogError("No callback parameters"); - Throw(InvalidArgumentException); + + if (argumentCount>4 || argumentCount<1) { + ThrowMsg(InvalidArgumentException, "Wrong number of parameters."); } - JSValueRef onError = (argumentCount > 1 ? getFunctionOrNull(context, arguments[1]) : NULL); - JSContextRef globalContext = privateObject->getContext(); - JSCallbackManagerPtr cbm = JSCallbackManager::createObject(globalContext, NULL, onError); - - Validator validator(context); - if (validator.isCallback(arguments[0])) - { - cbm->setOnSuccess(arguments[0]); - } - else if (JSValueIsNull(context, arguments[0]) || JSValueIsUndefined(context, arguments[0])) - { - Throw(InvalidArgumentException); + if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) { + ThrowMsg(ConversionException, "Wrong parameter type."); } - - //dy.kim-todo:Filter - - IEventFindPlaylistPtr dplEvent(new IEventFindPlaylist()); - dplEvent->setPrivateData( DPL::StaticPointerCast (cbm)); - dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance()); - mediacontent->findPlaylist(dplEvent); - + MediacontentMediaListPtr events; + + events = converter->toVectorOfEvents(arguments[0]); + if (!events) { + ThrowMsg(ConversionException, "Parameter conversion failed."); + } + if(cbm) + { + JSValueRef onSuccessForCbm = NULL, onErrorForCbm = NULL; + if((argumentCount >= 2) && validator.isCallback(arguments[1])) + { + onSuccessForCbm = arguments[1]; + } + + if((argumentCount >= 3) && validator.isCallback(arguments[2])) + { + onErrorForCbm = arguments[2]; + } + cbm->setOnSuccess(onSuccessForCbm); + cbm->setOnError(onErrorForCbm); + } + IEventUpdateMediaItemsPtr dplEvent(new IEventUpdateMediaItems()); + dplEvent->setMediaItems(events); + dplEvent->setPrivateData(DPL::StaticPointerCast(cbm)); + + dplEvent->setForAsynchronousCall(&MediacontentManagerController::getInstance()); + mediacontent->updateMediaItems(dplEvent); + } + Catch(UnsupportedException) + { + LogWarning("Exception: "<<_rethrown_exception.GetMessage()); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage()); } Catch(InvalidArgumentException) { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR); + LogWarning("Exception: "<<_rethrown_exception.GetMessage()); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage()); } Catch(ConversionException) { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR); + 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) { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR); + LogWarning("Exception: "<<_rethrown_exception.GetMessage()); + return JSTizenExceptionFactory::postException(context, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage()); } return JSValueMakeNull(context); @@ -477,8 +528,7 @@ JSValueRef JSMediacontent::findPlaylist( - -JSValueRef JSMediacontent::deletePlaylist( +JSValueRef JSMediacontent::updateItem( JSContextRef context, JSObjectRef object, JSObjectRef thisObject, @@ -486,204 +536,62 @@ JSValueRef JSMediacontent::deletePlaylist( const JSValueRef arguments[], JSValueRef* exception) { - LogDebug("deletePlaylist::entered"); + LogDebug("updateItem::entered"); + MediacontentPrivObject *privateObject = static_cast( JSObjectGetPrivate( thisObject ) ) ; assert(privateObject); - - //CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD_EVENT); - + + AceSecurityStatus status = MEDIACONTENT_CHECK_ACCESS(privateObject->getContext(), MEDIACONTENT_FUNCTION_API_UPDATE_ITEM); + + TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); + + Validator validator(context); + IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception); + Try - { - IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception); - if (argumentCount != 1) - { - LogError("Wrong number of parameters."); - Throw(InvalidArgumentException); - } - - if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) - { - Throw(InvalidArgumentException); - //return JSValueMakeNull(context); - } - - MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context); - string playlistID = converter->toString(arguments[0]); - - LogDebug("deletePlaylist::entered" << playlistID); - IEventDeletePlaylistPtr dplEvent(new IEventDeletePlaylist()); - LogDebug("deletePlaylist::entered11"); - dplEvent->setPlaylistId(playlistID); - LogDebug("deletePlaylist::entered22"); + { + if (argumentCount == 0 || + (!JSValueIsObject(context, arguments[0])) || + (argumentCount >= 2 && (!validator.isNullOrUndefined(arguments[1]) && (!validator.isCallback(arguments[1])))) || + (argumentCount >= 3 && (!validator.isNullOrUndefined(arguments[2]) && (!validator.isCallback(arguments[2])))) ) + { + LogDebug("Argument type mismatch"); + Throw(InvalidArgumentException); + } + JSObjectRef arg = JSValueToObject(context, arguments[0], exception); + MediacontentMediaPtr event = JSMedia::getMediaObject(arg); + + IEventUpdateMediaPtr dplEvent(new IEventUpdateMedia()); + dplEvent->setMediaItem(event); dplEvent->setForSynchronousCall(); - LogDebug("deletePlaylist::entered33"); - mediacontent->deletePlaylist(dplEvent); - LogDebug("deletePlaylist::entered44"); - - if (dplEvent->getResult()) - {; -// return converter->toJSValueRef(dplEvent->getPlaylist()->getPlaylistId()); - } else - { - Throw(InvalidArgumentException); - } + mediacontent->updateMedia(dplEvent); + if (dplEvent->getResult()) + { + return JSValueMakeNull(context); + } + else + { + ThrowMsg(UnknownException, "Updating failed by unkown reason."); + } } Catch(InvalidArgumentException) { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR); + return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR); } Catch(ConversionException) { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR); + return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR); } Catch(Exception) { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR); + return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR); } - return JSValueMakeNull(context); -} - - - -JSValueRef JSMediacontent::addAudioToPlaylist( - JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("addAudioToPlaylist::entered"); - - MediacontentPrivObject *privateObject = static_cast( JSObjectGetPrivate( thisObject ) ) ; - assert(privateObject); - - //CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD_EVENT); - - Try - { - IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception); - if (argumentCount != 2) - { - LogError("Wrong number of parameters."); - Throw(InvalidArgumentException); - } - - if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) - { - Throw(InvalidArgumentException); - //return JSValueMakeNull(context); - } - - MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context); - string playlistID = converter->toString(arguments[0]); - string mediaUID = converter->toString(arguments[1]); - - IEventAddAudioToPlaylistPtr dplEvent(new IEventAddAudioToPlaylist()); - dplEvent->setPlaylistId(playlistID); - dplEvent->setMediaUID(mediaUID); - dplEvent->setForSynchronousCall(); - mediacontent->addAudioToPlaylist(dplEvent); - - if (dplEvent->getResult()) - { - ; -// return converter->toJSValueRef(dplEvent->getPlaylist()->getPlaylistId()); - } else - { - Throw(InvalidArgumentException); - } - } - Catch(InvalidArgumentException) - { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR); - } - Catch(ConversionException) - { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR); - } - Catch (NotFoundException) - { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::NOT_FOUND_ERROR); - } - Catch(Exception) - { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR); - } - - return JSValueMakeNull(context); - -} - -JSValueRef JSMediacontent::deleteAudioToPlaylist( - JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) -{ - LogDebug("deleteAudioToPlaylist::entered"); - - MediacontentPrivObject *privateObject = static_cast( JSObjectGetPrivate( thisObject ) ) ; - assert(privateObject); - - //CALENDAR_CHECK_ACCESS(privateObject->getContext(), CALENDAR_FUNCTION_API_ADD_EVENT); - - Try - { - IMediacontentPtr mediacontent = getMediacontentObject(context, thisObject, exception); - if (argumentCount != 2) - { - LogError("Wrong number of parameters."); - Throw(InvalidArgumentException); - } - - if (JSValueIsUndefined(context, arguments[0]) || JSValueIsNull(context, arguments[0])) - { - Throw(InvalidArgumentException); - //return JSValueMakeNull(context); - } - - MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context); - string playlistID = converter->toString(arguments[0]); - string mediaUID = converter->toString(arguments[1]); - - IEventDeleteAudioToPlaylistPtr dplEvent(new IEventDeleteAudioToPlaylist()); - dplEvent->setPlaylistId(playlistID); - dplEvent->setMediaUID(mediaUID); - dplEvent->setForSynchronousCall(); - mediacontent->deleteAudioToPlaylist(dplEvent); - - if (dplEvent->getResult()) - {; - // return converter->toJSValueRef(dplEvent->getPlaylist()->getPlaylistId()); - } else - { - Throw(NotFoundException); - } - } - Catch(InvalidArgumentException) - { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::TYPE_MISMATCH_ERROR); - } - Catch(ConversionException) - { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::INVALID_VALUES_ERROR); - } - Catch(Exception) - { - return TizenApis::Commons::JSTizenExceptionFactory::postException(context, exception, TizenApis::Commons::JSTizenException::UNKNOWN_ERROR); - } - - return JSValueMakeNull(context); - + return JSValueMakeNull(context); } -*/ diff --git a/src/standards/Tizen/Mediacontent/JSMediacontent.h b/src/standards/Tizen/Mediacontent/JSMediacontent.h index ba0f4ac..167e51d 100644 --- a/src/standards/Tizen/Mediacontent/JSMediacontent.h +++ b/src/standards/Tizen/Mediacontent/JSMediacontent.h @@ -89,7 +89,7 @@ class JSMediacontent const JSValueRef arguments[], JSValueRef* exception); - static JSValueRef findFolders( + static JSValueRef getFolders( JSContextRef context, JSObjectRef object, JSObjectRef thisObject, @@ -104,50 +104,25 @@ class JSMediacontent size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); - -/* - static JSValueRef findPlaylist( - JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception ); - - - static JSValueRef addPlaylist( - JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception); - static JSValueRef deletePlaylist( + static JSValueRef updateItemsBatch( JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); + - static JSValueRef addAudioToPlaylist( - JSContextRef context, + static JSValueRef browseFolder( + JSContextRef context, JSObjectRef object, - JSObjectRef thisObject, + JSObjectRef thisObject, size_t argumentCount, - const JSValueRef arguments[], + const JSValueRef arguments[], JSValueRef* exception); + - static JSValueRef deleteAudioToPlaylist( - JSContextRef context, - JSObjectRef object, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception); - -*/ }; } diff --git a/src/standards/Tizen/Mediacontent/JSVideo.cpp b/src/standards/Tizen/Mediacontent/JSVideo.cpp index 9f7e55c..e3e0e4d 100644 --- a/src/standards/Tizen/Mediacontent/JSVideo.cpp +++ b/src/standards/Tizen/Mediacontent/JSVideo.cpp @@ -22,6 +22,8 @@ #include #include #include +#include + #include "JSMediacontent.h" #include "JSVideo.h" @@ -36,10 +38,7 @@ #define TIZEN_MEDIACONTENT_VIDEO_WIDTH "width" #define TIZEN_MEDIACONTENT_VIDEO_HEIGHT "height" -using namespace WrtDeviceApis::Commons; -using namespace WrtDeviceApis::CommonsJavaScript; -using namespace TizenApis::Api::Mediacontent; - +using namespace TizenApis::Tizen1_0::Tizen; namespace TizenApis { namespace Tizen1_0 { @@ -151,8 +150,9 @@ JSValueRef JSVideo::getPropertyGeoLocation( { Converter converter(context); MediacontentVideoPtr event = getVideoObject(object); - //Todo - return converter.toJSValueRef(event->getVideoLongitude()); + SimpleCoordinatesPtr geoPtr(new SimpleCoordinates(event->getVideoLatitude(),event->getVideoLongitude())); + return JSSimpleCoordinates::createJSObject(context,geoPtr); + //return converter.toJSValueRef(event->getVideoLongitude()); } Catch(Exception) { diff --git a/src/standards/Tizen/Mediacontent/MediaConverter.cpp b/src/standards/Tizen/Mediacontent/MediaConverter.cpp index 0372f91..724cbf5 100644 --- a/src/standards/Tizen/Mediacontent/MediaConverter.cpp +++ b/src/standards/Tizen/Mediacontent/MediaConverter.cpp @@ -109,6 +109,27 @@ JSValueRef MediaConverter::toJSValueRef(const MediacontentLyricsPtr &arg) } + +MediacontentMediaListPtr MediaConverter::toVectorOfEvents(JSValueRef events) +{ + LogDebug("entered"); + MediacontentMediaListPtr result(new MediacontentMediaList()); + + std::vector resultVector; + JSObjectRef objArg = toJSObjectRef(events); + LogDebug("array length "< &arg); JSValueRef toJSValueRef(const std::vector &arg); JSValueRef toJSValueRef(const MediacontentLyricsPtr &arg); - //MediacontentLyricsPtr - static std::vector m_allowedMediaAttributes; - static std::vector m_allowedFolderAttributes; + + + MediacontentMediaListPtr toVectorOfEvents(JSValueRef events); }; diff --git a/src/standards/Tizen/Mediacontent/MediacontentController.cpp b/src/standards/Tizen/Mediacontent/MediacontentController.cpp index 8062349..f982c98 100644 --- a/src/standards/Tizen/Mediacontent/MediacontentController.cpp +++ b/src/standards/Tizen/Mediacontent/MediacontentController.cpp @@ -35,9 +35,10 @@ MediacontentManagerController& MediacontentManagerController::getInstance() return instance; } - MediacontentManagerController::MediacontentManagerController(): EventFindMediaAnswerReceiver(ThreadEnum::NULL_THREAD), + EventBrowseFolderAnswerReceiver(ThreadEnum::NULL_THREAD), + EventUpdateMediaItemsAnswerReceiver(ThreadEnum::NULL_THREAD), EventFindFolderAnswerReceiver(ThreadEnum::NULL_THREAD) { LogDebug("create a MediacontentManagerController"); @@ -79,6 +80,68 @@ void MediacontentManagerController::OnAnswerReceived(const IEventFindMediaPtr &e JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject( cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR); cbm->callOnError(errorObject); +} + +void MediacontentManagerController::OnAnswerReceived(const IEventUpdateMediaItemsPtr &event) +{ + + LogDebug("MediacontentManagerController::IEventUpdateMediaItemsPtr:entered"); + + JSCallbackManagerPtr cbm = DPL::StaticPointerCast(event->getPrivateData()); + if(!cbm) + { + LogError("no callback manager"); + return; + } + Try + { + if (event->getResult()) + { + cbm->callOnSuccess(); + } + else + { + JSValueRef errorObject = TizenApis::Commons::JSTizenExceptionFactory::makeErrorObject( + cbm->getContext(), TizenApis::Commons::JSTizenException::UNKNOWN_ERROR); + cbm->callOnError(errorObject); + } + } + Catch(Exception) + { + LogError("error during processing answer"); + } +} + + +void MediacontentManagerController::OnAnswerReceived(const IEventBrowseFolderPtr &event) +{ + + LogDebug("MediacontentManagerController::OnAnswerReceived:entered"); + + JSCallbackManagerPtr cbm = DPL::StaticPointerCast(event->getPrivateData()); + if (!cbm) + { + LogError("no callback manager"); + return; + } + Try + { + if (event->getResult()) + { + MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(cbm->getContext()); + const std::vector &results = event->getMedia(); + 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); } diff --git a/src/standards/Tizen/Mediacontent/MediacontentController.h b/src/standards/Tizen/Mediacontent/MediacontentController.h index 210bb25..2953cc6 100644 --- a/src/standards/Tizen/Mediacontent/MediacontentController.h +++ b/src/standards/Tizen/Mediacontent/MediacontentController.h @@ -21,6 +21,8 @@ #include #include #include +#include +#include //#include using namespace TizenApis::Api::Mediacontent; @@ -33,10 +35,13 @@ namespace Mediacontent { typedef EventAnswerReceiver EventFindMediaAnswerReceiver; typedef EventAnswerReceiver EventFindFolderAnswerReceiver; - +typedef EventAnswerReceiver EventBrowseFolderAnswerReceiver; +typedef EventAnswerReceiver EventUpdateMediaItemsAnswerReceiver; class MediacontentManagerController : public EventFindMediaAnswerReceiver, + public EventBrowseFolderAnswerReceiver, + public EventUpdateMediaItemsAnswerReceiver, public EventFindFolderAnswerReceiver { public: @@ -45,6 +50,8 @@ class MediacontentManagerController : protected: void OnAnswerReceived(const IEventFindMediaPtr &event); void OnAnswerReceived(const IEventFindFolderPtr &event); + void OnAnswerReceived(const IEventBrowseFolderPtr &event); + void OnAnswerReceived(const IEventUpdateMediaItemsPtr &event); private: MediacontentManagerController(); diff --git a/src/standards/Tizen/Mediacontent/config.xml b/src/standards/Tizen/Mediacontent/config.xml index 67415d2..333323c 100644 --- a/src/standards/Tizen/Mediacontent/config.xml +++ b/src/standards/Tizen/Mediacontent/config.xml @@ -9,19 +9,12 @@ http://tizen.org/api/mediacontent - mediacontent - - - - + mediacontent.read + mediacontent.write + - http://tizen.org/api/mediacontent - mediacontent - - - - - - + http://tizen.org/api/mediacontent.read + mediacontent.read + diff --git a/src/standards/Tizen/Mediacontent/plugin_config.cpp b/src/standards/Tizen/Mediacontent/plugin_config.cpp new file mode 100755 index 0000000..7361475 --- /dev/null +++ b/src/standards/Tizen/Mediacontent/plugin_config.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include +#include + +#include "plugin_config.h" + +#define MEDIACONTENT_FEATURE_API "http://tizen.org/api/mediacontent" +#define MEDIACONTENT_FEATURE_API_READ "http://tizen.org/api/mediacontent.read" +#define MEDIACONTENT_FEATURE_API_WRITE "http://tizen.org/api/mediacontent.write" + +#define MEDIACONTENT_DEVICE_CAP_READ "mediacontent.read" +#define MEDIACONTENT_DEVICE_CAP_WRITE "mediacontent.write" + +using namespace WrtDeviceApis::Commons; + +namespace TizenApis { +namespace Tizen1_0 { +namespace Mediacontent { + +static FunctionMapping createMediacontentFunctions(); + +static FunctionMapping MediacontentFunctions = createMediacontentFunctions(); + +DEFINE_FUNCTION_GETTER(Mediacontent, MediacontentFunctions); + +static FunctionMapping createMediacontentFunctions() +{ + /** + * Device capabilities + */ + ACE_CREATE_DEVICE_CAP(DEVICE_CAP_MEDIACONTENT_READ, MEDIACONTENT_DEVICE_CAP_READ); + ACE_CREATE_DEVICE_CAP(DEVICE_CAP_MEDIACONTENT_WRITE, MEDIACONTENT_DEVICE_CAP_WRITE); + + ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_MEDIACONTENT_READ); + ACE_ADD_DEVICE_CAP(DEVICE_LIST_MEDIACONTENT_READ, DEVICE_CAP_MEDIACONTENT_READ); + + ACE_CREATE_DEVICE_CAPS_LIST(DEVICE_LIST_MEDIACONTENT_WRITE); + ACE_ADD_DEVICE_CAP(DEVICE_LIST_MEDIACONTENT_WRITE, DEVICE_CAP_MEDIACONTENT_WRITE); + + /** + * Api Features + */ + ACE_CREATE_FEATURE(FEATURE_MEDIACONTENT, MEDIACONTENT_FEATURE_API); + ACE_CREATE_FEATURE(FEATURE_MEDIACONTENT_READ, MEDIACONTENT_FEATURE_API_READ); + ACE_CREATE_FEATURE(FEATURE_MEDIACONTENT_WRITE, MEDIACONTENT_FEATURE_API_WRITE); + + ACE_CREATE_FEATURE_LIST(MEDIACONTENT_FEATURES_MEDIACONTENT_READ_WRITE); + ACE_ADD_API_FEATURE(MEDIACONTENT_FEATURES_MEDIACONTENT_READ_WRITE, FEATURE_MEDIACONTENT); + ACE_ADD_API_FEATURE(MEDIACONTENT_FEATURES_MEDIACONTENT_READ_WRITE, FEATURE_MEDIACONTENT_READ); + ACE_ADD_API_FEATURE(MEDIACONTENT_FEATURES_MEDIACONTENT_READ_WRITE, FEATURE_MEDIACONTENT_WRITE); + + ACE_CREATE_FEATURE_LIST(MEDIACONTENT_FEATURES_MEDIACONTENT_READ); + //ACE_ADD_API_FEATURE(MEDIACONTENT_FEATURES_MEDIACONTENT_READ, FEATURE_MEDIACONTENT); + ACE_ADD_API_FEATURE(MEDIACONTENT_FEATURES_MEDIACONTENT_READ, FEATURE_MEDIACONTENT_READ); + + ACE_CREATE_FEATURE_LIST(MEDIACONTENT_FEATURES_MEDIACONTENT_WRITE); + //ACE_ADD_API_FEATURE(MEDIACONTENT_FEATURES_MEDIACONTENT_WRITE, FEATURE_MEDIACONTENT); + ACE_ADD_API_FEATURE(MEDIACONTENT_FEATURES_MEDIACONTENT_WRITE, FEATURE_MEDIACONTENT_WRITE); + + /** + * Functions + */ + FunctionMapping mediacontentMapping; + + //"getLocalMediaSource" + AceFunction getLocalMediaSourceFunc = ACE_CREATE_FUNCTION( + FUNCTION_GET_LOCAL_MEDIA_SOURCE, + MEDIACONTENT_FUNCTION_API_GET_LOCAL_MEDIASOURCE, + MEDIACONTENT_FEATURES_MEDIACONTENT_READ_WRITE, + DEVICE_LIST_MEDIACONTENT_READ); + + mediacontentMapping.insert(std::make_pair( + MEDIACONTENT_FUNCTION_API_GET_LOCAL_MEDIASOURCE, + getLocalMediaSourceFunc)); + + + //findItems + AceFunction findItemsFunc = ACE_CREATE_FUNCTION( + FUNCTION_FIND_ITEMS, + MEDIACONTENT_FUNCTION_API_FIND_ITEMS, + MEDIACONTENT_FEATURES_MEDIACONTENT_READ, + DEVICE_LIST_MEDIACONTENT_READ); + + mediacontentMapping.insert(std::make_pair( + MEDIACONTENT_FUNCTION_API_FIND_ITEMS, + findItemsFunc)); + + //getFolders + AceFunction getFoldersFunc = ACE_CREATE_FUNCTION( + FUNCTION_GET_FOLDERS, + MEDIACONTENT_FUNCTION_API_GET_FOLDERS, + MEDIACONTENT_FEATURES_MEDIACONTENT_READ, + DEVICE_LIST_MEDIACONTENT_READ); + + mediacontentMapping.insert(std::make_pair( + MEDIACONTENT_FUNCTION_API_GET_FOLDERS, + getFoldersFunc)); + + //browseFolder + AceFunction browseFolderFunc = ACE_CREATE_FUNCTION( + FUNCTION_BROWSE_FOLDER, + MEDIACONTENT_FUNCTION_API_BROWSE_FOLDER, + MEDIACONTENT_FEATURES_MEDIACONTENT_READ, + DEVICE_LIST_MEDIACONTENT_READ); + + mediacontentMapping.insert(std::make_pair( + MEDIACONTENT_FUNCTION_API_BROWSE_FOLDER, + browseFolderFunc)); + + //updateItem + AceFunction updateItemFunc = ACE_CREATE_FUNCTION( + FUNCTION_UPDATE_ITEM, + MEDIACONTENT_FUNCTION_API_UPDATE_ITEM, + MEDIACONTENT_FEATURES_MEDIACONTENT_WRITE, + DEVICE_LIST_MEDIACONTENT_WRITE); + + mediacontentMapping.insert(std::make_pair( + MEDIACONTENT_FUNCTION_API_UPDATE_ITEM, + updateItemFunc)); + + //updateItemsBatch + AceFunction updateItemsBatchFunc = ACE_CREATE_FUNCTION( + FUNCTION_UPDATE_ITEMS_BATCH, + MEDIACONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, + MEDIACONTENT_FEATURES_MEDIACONTENT_WRITE, + DEVICE_LIST_MEDIACONTENT_WRITE); + + mediacontentMapping.insert(std::make_pair( + MEDIACONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH, + updateItemsBatchFunc)); + + return mediacontentMapping; +} + +} +} +} diff --git a/src/standards/Tizen/Mediacontent/plugin_config.h b/src/standards/Tizen/Mediacontent/plugin_config.h new file mode 100755 index 0000000..cf7ce5d --- /dev/null +++ b/src/standards/Tizen/Mediacontent/plugin_config.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef _MEDIACONTENT_PLUGIN_CONFIG_H_ +#define _MEDIACONTENT_PLUGIN_CONFIG_H_ + +#include +#include + +namespace TizenApis { +namespace Tizen1_0 { +namespace Mediacontent { + +// Functions from mediacontent manager +#define MEDIACONTENT_FUNCTION_API_GET_LOCAL_MEDIASOURCE "getLocalMediaSource" + +// Functions from mediacontent +#define MEDIACONTENT_FUNCTION_API_FIND_ITEMS "findItems" +#define MEDIACONTENT_FUNCTION_API_GET_FOLDERS "getFolders" +#define MEDIACONTENT_FUNCTION_API_BROWSE_FOLDER "browseFolder" +#define MEDIACONTENT_FUNCTION_API_UPDATE_ITEM "updateItem" +#define MEDIACONTENT_FUNCTION_API_UPDATE_ITEMS_BATCH "updateItemsBatch" + +DECLARE_FUNCTION_GETTER(Mediacontent); + +#define MEDIACONTENT_CHECK_ACCESS(globalContext, functionName) \ + aceCheckAccess >( \ + globalContext, \ + getMediacontentFunctionData, \ + functionName) + +} +} +} + +#endif // _MEDIACONTENT_PLUGIN_CONFIG_H_ \ No newline at end of file diff --git a/src/standards/Tizen/Messaging/CMakeLists.txt b/src/standards/Tizen/Messaging/CMakeLists.txt index 82b5909..8d12faa 100755 --- a/src/standards/Tizen/Messaging/CMakeLists.txt +++ b/src/standards/Tizen/Messaging/CMakeLists.txt @@ -2,14 +2,14 @@ set(TARGET_NAME "wrt-plugins-tizen-1.0-messaging") set(DESTINATION_NAME "tizen-1.0-messaging") include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_MESSAGING}) + set(SRCS_MESSAGING #${SRCS_PLATFORM_API_FILESYSTEM} #${SRCS_PLATFORM_IMPLEMENTATION_FILESYSTEM} - ${SRCS_PLATFORM_API_FILTER} JSMessagingServiceManager.cpp JSMessagingService.cpp JSMessagingStorage.cpp - JSMessagingListener.cpp + MessagingListener.cpp MessagingController.cpp MessagingStorageMultiCallback.cpp ConverterMessage.cpp @@ -30,18 +30,6 @@ set(SRCS_MESSAGING #../Filesystem/JSStorage.cpp #../Filesystem/Encodings.cpp #../Filesystem/FilesystemUtils.cpp - - ../Tizen/FilterConverter.cpp - ../Tizen/JSAttributeFilter.cpp - ../Tizen/JSAttributeRangeFilter.cpp - ../Tizen/JSCompositeFilter.cpp - ../Tizen/JSAbstractFilterArray.cpp - ../Tizen/JSSortMode.cpp - - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp - ../Common/JSGlobalContextFactory.cpp plugin_config.cpp plugin_initializer.cpp @@ -50,6 +38,7 @@ set(SRCS_MESSAGING set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${wrt-deviceapis-filesystem_LIBRARY_DIRS} + ${CMAKE_INSTALL_PREFIX}/tizen-1.0-tizen ) set(SRCS @@ -67,6 +56,7 @@ add_library(${TARGET_NAME} SHARED ${SRCS}) target_link_libraries(${TARGET_NAME} ${LIBS_PLATFORM_IMPLEMENTATION_MESSAGING} ${LIBS_PLATFORM_IMPLEMENTATION_FILESYSTEM} + wrt-plugins-tizen-1.0-tizen-impl ${wrt-deviceapis-filesystem_LDFLAGS} ${LIBS_COMMON} ${LIBS_WIDGETDB} diff --git a/src/standards/Tizen/Messaging/ConverterMessage.cpp b/src/standards/Tizen/Messaging/ConverterMessage.cpp index 3697464..1bc83dd 100755 --- a/src/standards/Tizen/Messaging/ConverterMessage.cpp +++ b/src/standards/Tizen/Messaging/ConverterMessage.cpp @@ -34,7 +34,7 @@ #include "JSMessage.h" #include "JSMessagePrivateObject.h" #include "JSRecipientArray.h" -#include "JSMessagingListener.h" +#include "MessagingListener.h" #include #include "JSMessageAttachment.h" #include "JSConversation.h" diff --git a/src/standards/Tizen/Messaging/JSMessage.cpp b/src/standards/Tizen/Messaging/JSMessage.cpp index d9d5069..b71c4f1 100755 --- a/src/standards/Tizen/Messaging/JSMessage.cpp +++ b/src/standards/Tizen/Messaging/JSMessage.cpp @@ -34,7 +34,7 @@ #include "JSMessage.h" #include "JSRecipientArray.h" #include "JSMessagePrivateObject.h" -#include "JSMessagingListener.h" +#include "MessagingListener.h" #include #include diff --git a/src/standards/Tizen/Messaging/JSMessagingService.cpp b/src/standards/Tizen/Messaging/JSMessagingService.cpp index a9092d9..455a9db 100755 --- a/src/standards/Tizen/Messaging/JSMessagingService.cpp +++ b/src/standards/Tizen/Messaging/JSMessagingService.cpp @@ -39,7 +39,7 @@ #include "MessagingErrorMsg.h" #include "ConverterMessage.h" -#include "JSMessagingListener.h" +#include "MessagingListener.h" #include "JSMessagingStorage.h" #include "JSMessage.h" #include "EventSendMessagePrivateData.h" //for send message diff --git a/src/standards/Tizen/Messaging/JSMessagingStorage.cpp b/src/standards/Tizen/Messaging/JSMessagingStorage.cpp index efbb1e2..ef14996 100755 --- a/src/standards/Tizen/Messaging/JSMessagingStorage.cpp +++ b/src/standards/Tizen/Messaging/JSMessagingStorage.cpp @@ -23,7 +23,7 @@ */ #include "JSMessagingStorage.h" -#include "JSMessagingListener.h" +#include "MessagingListener.h" #include "ConverterMessage.h" #include "MessagingStorageMultiCallback.h" #include @@ -105,7 +105,7 @@ namespace Tizen1_0 { void JSMessagingStorage::initialize(JSContextRef context, JSObjectRef object) { LogDebug("creation messaging instance"); - JSMessagingListener* priv = new JSMessagingListener(context); + MessagingListener* priv = new MessagingListener(context); JSObjectSetPrivate(object, static_cast(priv)); LogDebug("global context=" << priv->getContext()); @@ -113,8 +113,8 @@ namespace Tizen1_0 { void JSMessagingStorage::finalize(JSObjectRef object) { LogDebug("enter"); - JSMessagingListener* priv = - static_cast(JSObjectGetPrivate(object)); + MessagingListener* priv = + static_cast(JSObjectGetPrivate(object)); if (priv) { // deregister from incoming message notifications priv->deregisterMessageReceivedEmitter(); @@ -170,7 +170,7 @@ namespace Tizen1_0 { LogDebug("<<<"); - JSMessagingListener* priv = static_cast + MessagingListener* priv = static_cast (JSObjectGetPrivate(thisObject)); if (!priv) { @@ -255,7 +255,7 @@ namespace Tizen1_0 { LogDebug("<<<"); - JSMessagingListener* priv = static_cast + MessagingListener* priv = static_cast (JSObjectGetPrivate(thisObject)); if (!priv) { @@ -358,7 +358,7 @@ namespace Tizen1_0 { LogDebug("enter"); - JSMessagingListener* priv = static_cast + MessagingListener* priv = static_cast (JSObjectGetPrivate(thisObject)); if (!priv) { @@ -446,7 +446,7 @@ namespace Tizen1_0 { LogDebug("enter"); - JSMessagingListener* priv = static_cast + MessagingListener* priv = static_cast (JSObjectGetPrivate(thisObject)); if (!priv) { @@ -540,7 +540,7 @@ namespace Tizen1_0 { LogDebug("<<<"); - JSMessagingListener* priv = static_cast + MessagingListener* priv = static_cast (JSObjectGetPrivate(thisObject)); if (!priv) { @@ -650,7 +650,7 @@ namespace Tizen1_0 { { LogDebug("enter"); - JSMessagingListener* priv = static_cast(JSObjectGetPrivate(thisObject)); + MessagingListener* priv = static_cast(JSObjectGetPrivate(thisObject)); if (!priv) { LogError("Null pointer"); @@ -729,7 +729,7 @@ namespace Tizen1_0 { LogDebug("enter"); - JSMessagingListener* priv = static_cast(JSObjectGetPrivate(thisObject)); + MessagingListener* priv = static_cast(JSObjectGetPrivate(thisObject)); if (!priv) { LogError("Null pointer"); @@ -810,7 +810,7 @@ namespace Tizen1_0 { LogInfo("<<<"); LogDebug("arumentConunt:" << argumentCount); - JSMessagingListener* priv = static_cast + MessagingListener* priv = static_cast (JSObjectGetPrivate(thisObject)); if (!priv) { @@ -828,8 +828,8 @@ namespace Tizen1_0 { JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT); } - JSMessagingListener* listener = - static_cast(JSObjectGetPrivate(thisObject)); + MessagingListener* listener = + static_cast(JSObjectGetPrivate(thisObject)); if (!listener) { LogError("no private object"); return JSValueMakeUndefined(context); @@ -910,7 +910,7 @@ namespace Tizen1_0 { LogInfo("<<<"); LogDebug("arumentConunt:" << argumentCount); - JSMessagingListener* priv = static_cast + MessagingListener* priv = static_cast (JSObjectGetPrivate(thisObject)); if (!priv) { @@ -928,8 +928,8 @@ namespace Tizen1_0 { JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT); } - JSMessagingListener* listener = - static_cast(JSObjectGetPrivate(thisObject)); + MessagingListener* listener = + static_cast(JSObjectGetPrivate(thisObject)); if (!listener) { LogError("no private object"); return JSValueMakeUndefined(context); @@ -1011,7 +1011,7 @@ namespace Tizen1_0 { LogInfo("<<<"); LogDebug("arumentConunt:" << argumentCount); - JSMessagingListener* priv = static_cast + MessagingListener* priv = static_cast (JSObjectGetPrivate(thisObject)); if (!priv) { @@ -1029,8 +1029,8 @@ namespace Tizen1_0 { JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT); } - JSMessagingListener* listener = - static_cast(JSObjectGetPrivate(thisObject)); + MessagingListener* listener = + static_cast(JSObjectGetPrivate(thisObject)); if (!listener) { LogError("no private object"); return JSValueMakeUndefined(context); @@ -1114,7 +1114,7 @@ namespace Tizen1_0 { { LogInfo("entered"); - JSMessagingListener* priv = static_cast + MessagingListener* priv = static_cast (JSObjectGetPrivate(thisObject)); if (!priv) { @@ -1137,8 +1137,8 @@ namespace Tizen1_0 { TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); - JSMessagingListener* listener = - static_cast(JSObjectGetPrivate(thisObject)); + MessagingListener* listener = + static_cast(JSObjectGetPrivate(thisObject)); if (!listener) { LogError("no private object"); return JSValueMakeUndefined(context); diff --git a/src/standards/Tizen/Messaging/JSMessagingListener.cpp b/src/standards/Tizen/Messaging/MessagingListener.cpp similarity index 96% rename from src/standards/Tizen/Messaging/JSMessagingListener.cpp rename to src/standards/Tizen/Messaging/MessagingListener.cpp index 8aab02c..24452ed 100755 --- a/src/standards/Tizen/Messaging/JSMessagingListener.cpp +++ b/src/standards/Tizen/Messaging/MessagingListener.cpp @@ -15,7 +15,7 @@ */ /** - * @file JSMessagingListener.cpp + * @file MessagingListener.cpp * @author Pawel Misiak (p.misiak@samsung.com) * @version 0.1 * @brief @@ -37,7 +37,7 @@ #include "JSMessagingStorage.h" #include "ConverterMessage.h" #include "EventSendMessagePrivateData.h" -#include "JSMessagingListener.h" +#include "MessagingListener.h" using namespace std; @@ -51,7 +51,7 @@ using namespace TizenApis::Api::Messaging; using namespace TizenApis::Commons; -JSMessagingListener::JSMessagingListener(JSContextRef context) : +MessagingListener::MessagingListener(JSContextRef context) : WrtDeviceApis::CommonsJavaScript::PrivateObjectT::Type(context), EventAddDraftMessageAnswerReceiver(ThreadEnum::NULL_THREAD), EventSendMessageAnswerReceiver(ThreadEnum::NULL_THREAD), @@ -70,7 +70,7 @@ JSMessagingListener::JSMessagingListener(JSContextRef context) : { } -void JSMessagingListener::OnAnswerReceived( +void MessagingListener::OnAnswerReceived( const Api::Messaging::EventAddDraftMessagePtr& event) { WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = @@ -116,7 +116,7 @@ void JSMessagingListener::OnAnswerReceived( } -void JSMessagingListener::OnAnswerReceived( +void MessagingListener::OnAnswerReceived( const Api::Messaging::EventSendMessagePtr& event) { LogDebug("ENTER"); @@ -162,7 +162,7 @@ void JSMessagingListener::OnAnswerReceived( } } -void JSMessagingListener::OnAnswerReceived( +void MessagingListener::OnAnswerReceived( const Api::Messaging::EventQueryMessagesPtr& event) { WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = @@ -219,7 +219,7 @@ void JSMessagingListener::OnAnswerReceived( } } -void JSMessagingListener::OnAnswerReceived( +void MessagingListener::OnAnswerReceived( const Api::Messaging::EventDeleteMessagesPtr& event) { WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = @@ -264,7 +264,7 @@ void JSMessagingListener::OnAnswerReceived( } -void JSMessagingListener::OnAnswerReceived( +void MessagingListener::OnAnswerReceived( const Api::Messaging::EventUpdateMessagesPtr& event) { WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = @@ -309,7 +309,7 @@ void JSMessagingListener::OnAnswerReceived( } -void JSMessagingListener::OnAnswerReceived( +void MessagingListener::OnAnswerReceived( const DPL::SharedPtr &event) { WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = @@ -355,7 +355,7 @@ void JSMessagingListener::OnAnswerReceived( } } -void JSMessagingListener::OnAnswerReceived(const Api::Messaging::EventQueryConversationsPtr& event) +void MessagingListener::OnAnswerReceived(const Api::Messaging::EventQueryConversationsPtr& event) { LogDebug("enter"); @@ -414,7 +414,7 @@ void JSMessagingListener::OnAnswerReceived(const Api::Messaging::EventQueryConve } -void JSMessagingListener::OnAnswerReceived(const Api::Messaging::EventDeleteConversationsPtr& event) +void MessagingListener::OnAnswerReceived(const Api::Messaging::EventDeleteConversationsPtr& event) { LogDebug("enter"); WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr callbackManager = DPL::StaticPointerCast(event->getPrivateData()); @@ -458,7 +458,7 @@ void JSMessagingListener::OnAnswerReceived(const Api::Messaging::EventDeleteConv } } -void JSMessagingListener::OnAnswerReceived(const Api::Messaging::EventQueryFoldersPtr& event) +void MessagingListener::OnAnswerReceived(const Api::Messaging::EventQueryFoldersPtr& event) { LogDebug("enter"); @@ -519,7 +519,7 @@ void JSMessagingListener::OnAnswerReceived(const Api::Messaging::EventQueryFolde } -void JSMessagingListener::onAnswerReceived( +void MessagingListener::onAnswerReceived( const Api::Messaging::EventMessageReceivedPtr& event) { LogDebug("<<<"); @@ -677,7 +677,7 @@ void JSMessagingListener::onAnswerReceived( } } -long JSMessagingListener::addIncomingMsgCallback(const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& cbManager, int funtionIndex) +long MessagingListener::addIncomingMsgCallback(const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& cbManager, int funtionIndex) { IncomingMsgCB* callbacks = NULL; long handle = 0; @@ -725,7 +725,7 @@ long JSMessagingListener::addIncomingMsgCallback(const WrtDeviceApis::CommonsJav return handle; } -void JSMessagingListener::removeIncomingMsgCallback(long handle) +void MessagingListener::removeIncomingMsgCallback(long handle) { size_t msgRemoved = 0; size_t convRemoved = 0; @@ -756,7 +756,7 @@ void JSMessagingListener::removeIncomingMsgCallback(long handle) } -void JSMessagingListener::registerMessageReceivedEmitter(EventOnMessagingStorageChangesPrivateDataPtr privData) +void MessagingListener::registerMessageReceivedEmitter(EventOnMessagingStorageChangesPrivateDataPtr privData) { if(privData->getFunctionIndex() == MESSAGES_MULTI_FUNCTION) @@ -787,7 +787,7 @@ void JSMessagingListener::registerMessageReceivedEmitter(EventOnMessagingStorage } -void JSMessagingListener::deregisterMessageReceivedEmitter() +void MessagingListener::deregisterMessageReceivedEmitter() { LogDebug("enter"); if (m_emiterMsgId.size() > 0) { diff --git a/src/standards/Tizen/Messaging/JSMessagingListener.h b/src/standards/Tizen/Messaging/MessagingListener.h similarity index 92% rename from src/standards/Tizen/Messaging/JSMessagingListener.h rename to src/standards/Tizen/Messaging/MessagingListener.h index 5a3f602..85d96d2 100755 --- a/src/standards/Tizen/Messaging/JSMessagingListener.h +++ b/src/standards/Tizen/Messaging/MessagingListener.h @@ -15,14 +15,14 @@ */ /** - * @file JSMessagingListener.h + * @file MessagingListener.h * @author Pawel Misiak (p.misiak@samsung.com) * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com) * @version 0.1 * @brief */ -#ifndef JSMESSAGINGLISTENER_H -#define JSMESSAGINGLISTENER_H +#ifndef MESSAGINGLISTENER_H +#define MESSAGINGLISTENER_H #include #include @@ -57,7 +57,7 @@ EventDeleteConversationsAnswerReceiver; typedef WrtDeviceApis::Commons::EventAnswerReceiver EventQueryFoldersAnswerReceiver; -class JSMessagingListener : public WrtDeviceApis::CommonsJavaScript::PrivateObjectT::Type, +class MessagingListener : public WrtDeviceApis::CommonsJavaScript::PrivateObjectT::Type, public EventAddDraftMessageAnswerReceiver, public EventSendMessageAnswerReceiver, public EventQueryMessagesAnswerReceiver, @@ -70,7 +70,7 @@ class JSMessagingListener : public WrtDeviceApis::CommonsJavaScript::PrivateObje public EventQueryFoldersAnswerReceiver { public: - explicit JSMessagingListener(JSContextRef context); + explicit MessagingListener(JSContextRef context); long addIncomingMsgCallback(const WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr& cbManager, int funtionIndex); void removeIncomingMsgCallback(long handle); @@ -106,8 +106,8 @@ class JSMessagingListener : public WrtDeviceApis::CommonsJavaScript::PrivateObje std::vector m_emiterFolderId; }; -typedef DPL::SharedPtr JSMessagingListenerPtr; +typedef DPL::SharedPtr MessagingListenerPtr; } } -#endif // JSMESSAGINGLISTENER_H +#endif // MessagingListener_H diff --git a/src/standards/Tizen/Messaging/plugin_initializer.cpp b/src/standards/Tizen/Messaging/plugin_initializer.cpp index d7f2fff..1d88089 100755 --- a/src/standards/Tizen/Messaging/plugin_initializer.cpp +++ b/src/standards/Tizen/Messaging/plugin_initializer.cpp @@ -19,6 +19,7 @@ #include "JSMessagingServiceManager.h" #include "JSMessagingStorage.h" #include "JSMessage.h" +#include "JSMessageAttachment.h" #define WRT_JS_EXTENSION_OBJECT_TIZEN "tizen" #define OBJECT_MESSAGING ".messaging" @@ -54,4 +55,10 @@ PLUGIN_CLASS_MAP_BEGIN TizenApis::Tizen1_0::JSMessage::getClassRef(), NULL) + PLUGIN_CLASS_MAP_ADD_CLASS( + WRT_JS_EXTENSION_OBJECT_TIZEN, + "MessageAttachment", + 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 index 93fedb6..5b55d00 100755 --- a/src/standards/Tizen/NFC/CMakeLists.txt +++ b/src/standards/Tizen/NFC/CMakeLists.txt @@ -23,9 +23,6 @@ set(SRCS ResponseDispatcher.cpp plugin_initializer.cpp plugin_config.cpp -../Common/JSTizenException.cpp -../Common/TizenExceptionData.cpp -../Common/JSTizenExceptionFactory.cpp ) add_library(${TARGET_NAME} SHARED ${SRCS}) diff --git a/src/standards/Tizen/Systeminfo/CMakeLists.txt b/src/standards/Tizen/Systeminfo/CMakeLists.txt index f70323d..02ef287 100755 --- a/src/standards/Tizen/Systeminfo/CMakeLists.txt +++ b/src/standards/Tizen/Systeminfo/CMakeLists.txt @@ -16,9 +16,6 @@ set(SRCS JSSysteminfo.cpp plugin_initializer.cpp plugin_config.cpp - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp ) add_library(${TARGET_NAME} SHARED ${SRCS}) diff --git a/src/standards/Tizen/TimeUtil/CMakeLists.txt b/src/standards/Tizen/TimeUtil/CMakeLists.txt index 5ec6fce..607070e 100755 --- a/src/standards/Tizen/TimeUtil/CMakeLists.txt +++ b/src/standards/Tizen/TimeUtil/CMakeLists.txt @@ -1,27 +1,39 @@ set(TARGET_NAME "wrt-plugins-tizen-1.0-time") +set(DESTINATION_NAME "tizen-1.0-time") +set(TARGET_IMPL_NAME "wrt-plugins-tizen-1.0-time-impl") include_directories(${INCLUDES_PLATFORM_IMPLEMENTATION_TIMEUTIL}) -set(SRCS +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 - plugin_initializer.cpp - plugin_config.cpp -../Common/JSTizenException.cpp -../Common/TizenExceptionData.cpp -../Common/JSTizenExceptionFactory.cpp + JSTZDate.cpp + JSTimeDuration.cpp + TimeUtilConverter.cpp + plugin_config.cpp ) -add_library(${TARGET_NAME} SHARED ${SRCS}) -target_link_libraries(${TARGET_NAME} - wrt-plugins-tizen-1.0-tizen +add_library(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL}) + +target_link_libraries(${TARGET_IMPL_NAME} ${LIBS_COMMON} ${LIBS_PLATFORM_IMPLEMENTATION_TIMEUTIL} ) -INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION tizen-1.0-time) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION tizen-1.0-time) +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/CMakeLists.txt b/src/standards/Tizen/Tizen/CMakeLists.txt index b41a720..faee11d 100755 --- a/src/standards/Tizen/Tizen/CMakeLists.txt +++ b/src/standards/Tizen/Tizen/CMakeLists.txt @@ -1,5 +1,6 @@ set(TARGET_NAME "wrt-plugins-tizen-1.0-tizen") set(DESTINATION_NAME "tizen-1.0-tizen") +set(TARGET_IMPL_NAME "wrt-plugins-tizen-1.0-tizen-impl") pkg_search_module(wrt-plugins-plugin-manager REQUIRED wrt-plugins-plugin-manager) @@ -7,7 +8,12 @@ include_directories( ${wrt-plugins-plugin-manager_INCLUDE_DIRS} ) -set(SRCS +set(CMAKE_INSTALL_RPATH + ${CMAKE_INSTALL_RPATH} + ${CMAKE_INSTALL_PREFIX}/${DESTINATION_NAME} +) + +set(SRCS_IMPL ${SRCS_PLATFORM_API_FILTER} JSTizen.cpp JSAttributeFilter.cpp @@ -19,21 +25,27 @@ set(SRCS JSSimpleCoordinates.cpp JSFeature.cpp JSFeatureParam.cpp - plugin_initializer.cpp plugin_config.cpp PluginOnDemandPriv.cpp - ../Common/JSTizenException.cpp - ../Common/TizenExceptionData.cpp - ../Common/JSTizenExceptionFactory.cpp - ../Common/JSGlobalContextFactory.cpp ) -add_library(${TARGET_NAME} SHARED ${SRCS}) +add_library(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL}) -target_link_libraries(${TARGET_NAME} +target_link_libraries(${TARGET_IMPL_NAME} ${LIBS_WIDGETDB} ${LIBS_COMMON} - ${wrt-plugins-plugin-manager_LIBRARIES}) + ${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} LIBRARY DESTINATION ${DESTINATION_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 index e6c978a..d510727 100755 --- a/src/standards/Tizen/Tizen/FilterConverter.cpp +++ b/src/standards/Tizen/Tizen/FilterConverter.cpp @@ -110,39 +110,6 @@ FilterPtr FilterConverter::toFilter(const JSValueRef& arg) ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); return FilterPtr(NULL); - -#if 0 // User object will not be given any more. - if(arg == NULL) - ThrowMsg(NullPointerException, "JSValueRef is NULL."); - - if(!JSValueIsObject(m_context, arg)) - ThrowMsg(InvalidArgumentException, "Filter is not object."); - - JSObjectRef jsObject = toJSObjectRef(arg); - if(jsObject == NULL) - ThrowMsg(InvalidArgumentException, "Filter is not object."); - - BasicValidator validator = ValidatorFactory::getValidator(m_context); - - if(validator->checkArrayKeys(m_compositeFilterAttrs, arg)) - { - CompositeFilterPtr compositeFilter = toCompositeFilter(arg); - return DPL::StaticPointerCast(compositeFilter); - } - else if(validator->checkArrayKeys(m_attributeFilterAttrs, arg)) - { - AttributeFilterPtr attributeFilter = toAttributeFilter(arg); - return DPL::StaticPointerCast(attributeFilter); - } - else if(validator->checkArrayKeys(m_attributeRangeFilterAttrs, arg)) - { - AttributeRangeFilterPtr attributeRangeFilter = toAttributeRangeFilter(arg); - return DPL::StaticPointerCast(attributeRangeFilter); - } - - ThrowMsg(InvalidArgumentException, "Not a Filter."); - return FilterPtr(NULL); -#endif } JSValueRef FilterConverter::toJSValueRef(const FilterArrayPtr& arg) @@ -151,26 +118,6 @@ JSValueRef FilterConverter::toJSValueRef(const FilterArrayPtr& arg) ThrowMsg(NullPointerException, "FilterArray is NULL."); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSAbstractFilterArray::getClassRef(), arg); - -#if 0 // User object will not be given any more. - if(arg == NULL) - ThrowMsg(NullPointerException, "FilterArray 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 filter array."); - } - - return static_cast(resultObject); -#endif } FilterArrayPtr FilterConverter::toFilterArray(const JSValueRef& arg) @@ -217,35 +164,6 @@ JSValueRef FilterConverter::toJSValueRef(const CompositeFilterPtr& arg) ThrowMsg(NullPointerException, "CompositeFilter is NULL."); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSCompositeFilter::getClassRef(), arg); - -#if 0 // User object will not be given any more. - JSObjectRef resultObject = JSObjectMake(m_context, NULL, NULL); - - ScopedJSStringRef typeStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_TYPE)); - FilterType filterType = arg->getFilterType(); - string type; - if(filterType == UNION_FILTER) - type = "UNION"; - else if(filterType == INTERSECTION_FILTER) - type = "INTERSECTION"; - else - ThrowMsg(ConversionException, "Invalid FilterType."); - - ScopedJSStringRef typeValue(JSStringCreateWithUTF8CString(type.c_str())); - JSObjectSetProperty(m_context, resultObject, - typeStr.get(), - JSValueMakeString(m_context, typeValue.get()), - kJSPropertyAttributeNone, NULL); - - ScopedJSStringRef filtersStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_FILTERS)); - JSValueRef filters = toJSValueRef(arg->getFilters()); - JSObjectSetProperty(m_context, resultObject, - filtersStr.get(), - filters, - kJSPropertyAttributeNone, NULL); - - return static_cast(resultObject); -#endif } CompositeFilterPtr FilterConverter::toCompositeFilter(const JSValueRef& arg) @@ -257,39 +175,6 @@ CompositeFilterPtr FilterConverter::toCompositeFilter(const JSValueRef& arg) ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); return JSCompositeFilter::getCompositeFilter(m_context, arg); - -#if 0 // User object will not be given any more. - // If arg is platform object - if(JSCompositeFilter::isObjectOfClass(m_context, arg)) - return JSCompositeFilter::getCompositeFilter(m_context, arg); - - // If arg is use object - JSObjectRef jsObject = toJSObjectRef(arg); - - ScopedJSStringRef typeStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_TYPE)); - JSValueRef typeValue = JSObjectGetProperty(m_context, jsObject, typeStr.get(), NULL); - if(!JSValueIsString(m_context, typeValue)) - ThrowMsg(InvalidArgumentException, "CompositeFilter.type is not an string."); - string type = toString(typeValue); - FilterType filterType; - - if(type == "INTERSECTION") - filterType = INTERSECTION_FILTER; - else if(type == "UNION") - filterType = UNION_FILTER; - else - ThrowMsg(InvalidArgumentException, "CompositeFilter.type is wrong."); - - ScopedJSStringRef filtersStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_FILTERS)); - JSValueRef filtersValue = JSObjectGetProperty(m_context, jsObject, filtersStr.get(), NULL); - if(!JSIsArrayValue(m_context, filtersValue)) - ThrowMsg(InvalidArgumentException, "CompositeFilter.filters is not an array."); - FilterArrayPtr filters = toFilterArray(filtersValue); - if(filters->size() == 0) - ThrowMsg(InvalidArgumentException, "CompositeFilter.filters array size is 0."); - - return CompositeFilterPtr(new CompositeFilter(filterType, filters)); -#endif } JSValueRef FilterConverter::toJSValueRef(const AttributeFilterPtr& arg) @@ -298,36 +183,6 @@ JSValueRef FilterConverter::toJSValueRef(const AttributeFilterPtr& arg) ThrowMsg(NullPointerException, "AttributeFilter is NULL."); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSAttributeFilter::getClassRef(), arg); - -#if 0 // User object will not be given any more. - AnyTypeConverterFactory::ConverterType converter = - AnyTypeConverterFactory::getConverter(m_context); - - JSObjectRef resultObject = JSObjectMake(m_context, NULL, NULL); - - ScopedJSStringRef attributeNameStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ATTRIBUTE_NAME)); - ScopedJSStringRef attributeNameValue(JSStringCreateWithUTF8CString(arg->getAttributeName().c_str())); - JSObjectSetProperty(m_context, resultObject, - attributeNameStr.get(), - JSValueMakeString(m_context, attributeNameValue.get()), - kJSPropertyAttributeNone, NULL); - - ScopedJSStringRef matchFlagStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_MATCH_FLAG)); - JSValueRef matchFlagValue = toJSValueRef(arg->getMatchFlag()); - JSObjectSetProperty(m_context, resultObject, - matchFlagStr.get(), - matchFlagValue, - kJSPropertyAttributeNone, NULL); - - ScopedJSStringRef matchValuesStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_MATCH_VALUES)); - JSValueRef matchValuesValue = toJSValueRef(arg->getMatchValues()); - JSObjectSetProperty(m_context, resultObject, - matchValuesStr.get(), - matchValuesValue, - kJSPropertyAttributeNone, NULL); - - return static_cast(resultObject); -#endif } AttributeFilterPtr FilterConverter::toAttributeFilter(const JSValueRef& arg) @@ -339,50 +194,6 @@ AttributeFilterPtr FilterConverter::toAttributeFilter(const JSValueRef& arg) ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); return JSAttributeFilter::getAttributeFilter(m_context, arg); - -#if 0 // User object will not be given any more. - // If arg is platform object - if(JSAttributeFilter::isObjectOfClass(m_context, arg)) - return JSAttributeFilter::getAttributeFilter(m_context, arg); - - // If arg is user object - JSObjectRef jsObject = toJSObjectRef(arg); - - ScopedJSStringRef attributeNameStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ATTRIBUTE_NAME)); - JSValueRef attributeNameValue = JSObjectGetProperty(m_context, jsObject, attributeNameStr.get(), NULL); - if(!JSValueIsString(m_context, attributeNameValue)) - ThrowMsg(InvalidArgumentException, "AttributeFilter.attributeName is not an string."); - string attributeName = toString(attributeNameValue); - if(attributeName == "") - ThrowMsg(InvalidArgumentException, "AttributeFilter.attributeName is empty string."); - - ScopedJSStringRef matchFlagStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_MATCH_FLAG)); - JSValueRef matchFlagValue = JSObjectGetProperty(m_context, jsObject, matchFlagStr.get(), NULL); - MatchFlag matchFlag; - if(JSValueIsUndefined(m_context, matchFlagValue)) { - matchFlag = MATCH_EXACTLY; - } else if(!JSValueIsString(m_context, matchFlagValue)) { - ThrowMsg(InvalidArgumentException, "AttributeFilter.matchFlag is not string."); - } else { - matchFlag = toMatchFlag(matchFlagValue); - } - - ScopedJSStringRef matchValuesStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_MATCH_VALUES)); - JSValueRef matchValuesValue = JSObjectGetProperty(m_context, jsObject, matchValuesStr.get(), NULL); - AnyArrayPtr matchValues(NULL); - - if(matchFlag == MATCH_EXISTS) { - //matchValues = AnyArrayPtr(NULL); - } else if(JSValueIsUndefined(m_context, matchValuesValue)) { - ThrowMsg(InvalidArgumentException, "AttributeFilter.matchValues is undefined."); - } else if(!JSIsArrayValue(m_context, matchValuesValue)) { - ThrowMsg(InvalidArgumentException, "AttributeFilter.matchValues is not an array."); - } else { - matchValues = toAnyArray(matchValuesValue); - } - - return AttributeFilterPtr(new AttributeFilter(attributeName, matchFlag, matchValues)); -#endif } JSValueRef FilterConverter::toJSValueRef(const AttributeRangeFilterPtr& arg) @@ -391,36 +202,6 @@ JSValueRef FilterConverter::toJSValueRef(const AttributeRangeFilterPtr& arg) ThrowMsg(NullPointerException, "AttributeRangeFilter is NULL."); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSAttributeRangeFilter::getClassRef(), arg); - -#if 0 // User object will not be given any more. - AnyTypeConverterFactory::ConverterType converter = - AnyTypeConverterFactory::getConverter(m_context); - - JSObjectRef resultObject = JSObjectMake(m_context, NULL, NULL); - - ScopedJSStringRef attributeNameStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ATTRIBUTE_NAME)); - ScopedJSStringRef attributeNameValue(JSStringCreateWithUTF8CString(arg->getAttributeName().c_str())); - JSObjectSetProperty(m_context, resultObject, - attributeNameStr.get(), - JSValueMakeString(m_context, attributeNameValue.get()), - kJSPropertyAttributeNone, NULL); - - ScopedJSStringRef initialValueStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_INITIAL_VALUE)); - JSValueRef initialValueValue = converter->toJSValueRef(arg->getInitialValue()); - JSObjectSetProperty(m_context, resultObject, - initialValueStr.get(), - initialValueValue, - kJSPropertyAttributeNone, NULL); - - ScopedJSStringRef endValueStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_END_VALUE)); - JSValueRef endValueValue = converter->toJSValueRef(arg->getEndValue()); - JSObjectSetProperty(m_context, resultObject, - endValueStr.get(), - endValueValue, - kJSPropertyAttributeNone, NULL); - - return static_cast(resultObject); -#endif } AttributeRangeFilterPtr FilterConverter::toAttributeRangeFilter(const JSValueRef& arg) @@ -432,41 +213,6 @@ AttributeRangeFilterPtr FilterConverter::toAttributeRangeFilter(const JSValueRef ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); return JSAttributeRangeFilter::getAttributeRangeFilter(m_context, arg); -#if 0 // User object will not be given any more. - // If arg is platform object - if(JSAttributeRangeFilter::isObjectOfClass(m_context, arg)) - return JSAttributeRangeFilter::getAttributeRangeFilter(m_context, arg); - - // If arg is user object - AnyTypeConverterFactory::ConverterType converter = - AnyTypeConverterFactory::getConverter(m_context); - - JSObjectRef jsObject = toJSObjectRef(arg); - - ScopedJSStringRef attributeNameStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ATTRIBUTE_NAME)); - JSValueRef attributeNameValue = JSObjectGetProperty(m_context, jsObject, attributeNameStr.get(), NULL); - if(!JSValueIsString(m_context, attributeNameValue)) - ThrowMsg(InvalidArgumentException, "AttributeRangeFilter.attributeName is not an string."); - string attributeName = toString(attributeNameValue); - if(attributeName == "") - ThrowMsg(InvalidArgumentException, "AttributeRangeFilter.attributeName is empty string."); - - ScopedJSStringRef initialValueStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_INITIAL_VALUE)); - JSValueRef initialValueValue = JSObjectGetProperty(m_context, jsObject, initialValueStr.get(), NULL); - AnyPtr initialValue(NULL); - if(!JSValueIsUndefined(m_context, initialValueValue) && !JSValueIsNull(m_context, initialValueValue)) { - initialValue = converter->toAny(initialValueValue); - } - - ScopedJSStringRef endValueStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_END_VALUE)); - JSValueRef endValueValue = JSObjectGetProperty(m_context, jsObject, endValueStr.get(), NULL); - AnyPtr endValue(NULL); - if(!JSValueIsUndefined(m_context, endValueValue) && !JSValueIsNull(m_context, endValueValue)) { - endValue = converter->toAny(endValueValue); - } - - return AttributeRangeFilterPtr(new AttributeRangeFilter(attributeName, initialValue, endValue)); -#endif } JSValueRef FilterConverter::toJSValueRef(const SortModePtr& arg) @@ -475,38 +221,6 @@ JSValueRef FilterConverter::toJSValueRef(const SortModePtr& arg) ThrowMsg(NullPointerException, "SortMode is NULL."); return WrtDeviceApis::CommonsJavaScript::JSUtils::makeObject(m_context, JSSortMode::getClassRef(), arg); - -#if 0 // User object will not be given any more. - if(arg == NULL) - ThrowMsg(NullPointerException, "SortMode is NULL."); - - JSObjectRef resultObject = JSObjectMake(m_context, NULL, NULL); - - ScopedJSStringRef attributeNameStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ATTRIBUTE_NAME)); - ScopedJSStringRef attributeNameValue(JSStringCreateWithUTF8CString(arg->getAttributeName().c_str())); - JSObjectSetProperty(m_context, resultObject, - attributeNameStr.get(), - JSValueMakeString(m_context, attributeNameValue.get()), - kJSPropertyAttributeNone, NULL); - - ScopedJSStringRef orderStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ORDER)); - SortOrder sortOrder = arg->getOrder(); - string order; - if(sortOrder == ASCENDING_SORT_ORDER) - order = "ASC"; - else if(sortOrder == DESCENDING_SORT_ORDER) - order = "DESC"; - else - ThrowMsg(ConversionException, "Invalid SortMode."); - - ScopedJSStringRef orderValue(JSStringCreateWithUTF8CString(order.c_str())); - JSObjectSetProperty(m_context, resultObject, - orderStr.get(), - JSValueMakeString(m_context, orderValue.get()), - kJSPropertyAttributeNone, NULL); - - return static_cast(resultObject); -#endif } SortModePtr FilterConverter::toSortMode(const JSValueRef& arg) @@ -518,42 +232,6 @@ SortModePtr FilterConverter::toSortMode(const JSValueRef& arg) ThrowMsg(WrtDeviceApis::Commons::ConversionException, "Wrong attribute"); return JSSortMode::getSortMode(m_context, arg); -#if 0 // User object will not be given any more. - if(arg == NULL) - ThrowMsg(NullPointerException, "JSValueRef is NULL."); - - BasicValidator validator = ValidatorFactory::getValidator(m_context); - - if(validator->checkArrayKeys(m_compositeFilterAttrs, arg)) { - ThrowMsg(InvalidArgumentException, "Not SortMode."); - } - - JSObjectRef jsObject = toJSObjectRef(arg); - - ScopedJSStringRef orderStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ORDER)); - JSValueRef orderValue = JSObjectGetProperty(m_context, jsObject, orderStr.get(), NULL); - if(!JSValueIsString(m_context, orderValue)) - ThrowMsg(InvalidArgumentException, "SortMode.order is not an string."); - string order = toString(orderValue); - SortOrder sortOrder; - - if(order == "ASC") - sortOrder = ASCENDING_SORT_ORDER; - else if(order == "DESC") - sortOrder = DESCENDING_SORT_ORDER; - else - ThrowMsg(InvalidArgumentException, "SortMode.order is wrong."); - - ScopedJSStringRef attributeNameStr(JSStringCreateWithUTF8CString(TIZEN_FILTER_CONVERTER_ATTRIBUTE_ATTRIBUTE_NAME)); - JSValueRef attributeNameValue = JSObjectGetProperty(m_context, jsObject, attributeNameStr.get(), NULL); - if(!JSValueIsString(m_context, attributeNameValue)) - ThrowMsg(InvalidArgumentException, "SortMode.attributeName is not an string."); - string attributeName = toString(attributeNameValue); - if(attributeName == "") - ThrowMsg(InvalidArgumentException, "SortMode.attributeName is empty string."); - - return SortModePtr(new SortMode(attributeName, sortOrder)); -#endif } JSValueRef FilterConverter::toJSValueRef(const SortModeArrayPtr& arg) diff --git a/src/standards/Tizen/Tizen/JSAttributeFilter.cpp b/src/standards/Tizen/Tizen/JSAttributeFilter.cpp index e09b675..314ed16 100755 --- a/src/standards/Tizen/Tizen/JSAttributeFilter.cpp +++ b/src/standards/Tizen/Tizen/JSAttributeFilter.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include "FilterConverter.h" #include "JSAttributeFilter.h" @@ -37,7 +36,7 @@ #define ATTRIBUTE_FILTER_ATTR_ATTRIBUTE_NAME "attributeName" #define ATTRIBUTE_FILTER_ATTR_MATCH_FLAG "matchFlag" -#define ATTRIBUTE_FILTER_ATTR_MATCH_VALUES "matchValues" +#define ATTRIBUTE_FILTER_ATTR_MATCH_VALUE "matchValue" namespace TizenApis { namespace Tizen1_0 { @@ -74,7 +73,7 @@ JSClassDefinition JSAttributeFilter::m_classInfo = JSStaticValue JSAttributeFilter::m_property[] = { { ATTRIBUTE_FILTER_ATTR_ATTRIBUTE_NAME, getAttributeName, setAttributeName, kJSPropertyAttributeNone }, { ATTRIBUTE_FILTER_ATTR_MATCH_FLAG, getMatchFlag, setMatchFlag, kJSPropertyAttributeNone }, - { ATTRIBUTE_FILTER_ATTR_MATCH_VALUES, getMatchValues, setMatchValues, kJSPropertyAttributeNone }, + { ATTRIBUTE_FILTER_ATTR_MATCH_VALUE, getMatchValue, setMatchValue, kJSPropertyAttributeNone }, { 0, 0, 0, 0 } }; @@ -111,16 +110,27 @@ AttributeFilterPtr JSAttributeFilter::getAttributeFilter(JSContextRef context, J return priv->getObject(); } +JSObjectRef JSAttributeFilter::createJSObject(JSContextRef context, AttributeFilterPtr privateData) +{ + JSAttributeFilterPriv *priv = new JSAttributeFilterPriv(context, privateData); + JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; +} + void JSAttributeFilter::Initialize(JSContextRef context, JSObjectRef object) { -// if (!JSObjectGetPrivate(object)) -// { -// AttributeFilterPtr coord(new AttributeFilter("")); -// JSAttributeFilterPriv *priv = new JSAttributeFilterPriv(context, AttributeFilterPtr(coord)); -// if (!JSObjectSetPrivate(object, priv)) { -// delete priv; -// } -// } + 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) @@ -135,17 +145,6 @@ void JSAttributeFilter::Finalize(JSObjectRef object) priv = NULL; } -JSObjectRef JSAttributeFilter::createJSObject(JSContextRef context, AttributeFilterPtr privateData) -{ - JSAttributeFilterPriv *priv = new JSAttributeFilterPriv(context, privateData); - JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsObjectRef) { - LogError("object creation error"); - return NULL; - } - return jsObjectRef; -} - AttributeFilterPtr JSAttributeFilter::getPrivData(JSObjectRef object) { LogDebug("entered"); @@ -171,13 +170,13 @@ JSObjectRef JSAttributeFilter::constructor(JSContextRef context, // AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); -// JSAttributeFilterPriv *priv = static_cast(JSObjectGetPrivate(constructor)); -// if (!priv) { -// ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); -// } -// JSContextRef gContext = priv->getContext(); + JSAttributeFilterPriv *priv = static_cast(JSObjectGetPrivate(constructor)); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + JSContextRef gContext = priv->getContext(); - JSContextRef gContext = JSGlobalContextFactory::getInstance()->get(); +// JSContextRef gContext = JSGlobalContextFactory::getInstance()->get(); BasicValidator validator = BasicValidatorFactory::getValidator(context, exception); Try { @@ -205,7 +204,7 @@ JSObjectRef JSAttributeFilter::constructor(JSContextRef context, std::string attributeName; MatchFlag matchFlag; - AnyArrayPtr matchValues; + AnyPtr matchValue; Try { attributeName = converter->toString(arguments[0]); @@ -232,18 +231,13 @@ JSObjectRef JSAttributeFilter::constructor(JSContextRef context, if(argumentCount >= 3) { if(JSValueIsNull(gContext, arguments[2])) - matchValues = AnyArrayPtr(new AnyArray()); - else if(JSIsArrayValue(gContext, arguments[2])) - matchValues = converter->toAnyArray(arguments[2]); + matchValue = AnyPtr(new Any()); else - { - matchValues = AnyArrayPtr(new AnyArray()); - matchValues->push_back(converter->toAny(arguments[2])); - } + matchValue = converter->toAny(arguments[2]); } else { - matchValues = AnyArrayPtr(new AnyArray()); + matchValue = AnyPtr(new Any()); } } Catch(Exception) { @@ -252,7 +246,7 @@ JSObjectRef JSAttributeFilter::constructor(JSContextRef context, return NULL; } - AttributeFilterPtr attributeFilter(new AttributeFilter(attributeName, matchFlag, matchValues)); + AttributeFilterPtr attributeFilter(new AttributeFilter(attributeName, matchFlag, matchValue)); JSObjectRef jsobject; @@ -353,7 +347,7 @@ bool JSAttributeFilter::setMatchFlag(JSContextRef context, return false; } -JSValueRef JSAttributeFilter::getMatchValues(JSContextRef context, +JSValueRef JSAttributeFilter::getMatchValue(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) @@ -364,7 +358,7 @@ JSValueRef JSAttributeFilter::getMatchValues(JSContextRef context, FilterConverterFactory::ConverterType converter = FilterConverterFactory::getConverter(context); AttributeFilterPtr attributeFilter = getPrivData(object); - return converter->toJSValueRef(attributeFilter->getMatchValues()); + return converter->toJSValueRef(attributeFilter->getMatchValue()); } Catch(WrtDeviceApis::Commons::Exception) { @@ -374,7 +368,7 @@ JSValueRef JSAttributeFilter::getMatchValues(JSContextRef context, return JSValueMakeUndefined(context); } -bool JSAttributeFilter::setMatchValues(JSContextRef context, +bool JSAttributeFilter::setMatchValue(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, @@ -385,7 +379,7 @@ bool JSAttributeFilter::setMatchValues(JSContextRef context, AttributeFilterPtr attributeFilter = getPrivData(object); FilterConverterFactory::ConverterType converter = FilterConverterFactory::getConverter(context); - attributeFilter->setMatchValues(converter->toAnyArray(value)); + attributeFilter->setMatchValue(converter->toAny(value)); return true; } Catch(WrtDeviceApis::Commons::Exception) diff --git a/src/standards/Tizen/Tizen/JSAttributeFilter.h b/src/standards/Tizen/Tizen/JSAttributeFilter.h index 5ada992..9d5ec27 100755 --- a/src/standards/Tizen/Tizen/JSAttributeFilter.h +++ b/src/standards/Tizen/Tizen/JSAttributeFilter.h @@ -47,6 +47,8 @@ public: 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. @@ -76,8 +78,6 @@ private: static JSClassRef m_classRef; - static JSObjectRef createJSObject(JSContextRef context, TizenApis::Api::Tizen::AttributeFilterPtr privateData); - static TizenApis::Api::Tizen::AttributeFilterPtr getPrivData(JSObjectRef object); static JSObjectRef constructor(JSContextRef context, @@ -108,12 +108,12 @@ private: JSValueRef value, JSValueRef* exception); - static JSValueRef getMatchValues(JSContextRef context, + static JSValueRef getMatchValue(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); - static bool setMatchValues(JSContextRef context, + static bool setMatchValue(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, diff --git a/src/standards/Tizen/Tizen/JSAttributeRangeFilter.cpp b/src/standards/Tizen/Tizen/JSAttributeRangeFilter.cpp index f7a5ee7..dfd8fc1 100755 --- a/src/standards/Tizen/Tizen/JSAttributeRangeFilter.cpp +++ b/src/standards/Tizen/Tizen/JSAttributeRangeFilter.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include "FilterConverter.h" #include "JSAttributeRangeFilter.h" @@ -110,16 +109,27 @@ AttributeRangeFilterPtr JSAttributeRangeFilter::getAttributeRangeFilter(JSContex return priv->getObject(); } +JSObjectRef JSAttributeRangeFilter::createJSObject(JSContextRef context, AttributeRangeFilterPtr privateData) +{ + JSAttributeRangeFilterPriv *priv = new JSAttributeRangeFilterPriv(context, privateData); + JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; +} + void JSAttributeRangeFilter::Initialize(JSContextRef context, JSObjectRef object) { -// if (!JSObjectGetPrivate(object)) -// { -// AttributeRangeFilterPtr coord(new AttributeRangeFilter("")); -// JSAttributeRangeFilterPriv *priv = new JSAttributeRangeFilterPriv(context, AttributeRangeFilterPtr(coord)); -// if (!JSObjectSetPrivate(object, priv)) { -// delete priv; -// } -// } + 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) @@ -134,17 +144,6 @@ void JSAttributeRangeFilter::Finalize(JSObjectRef object) priv = NULL; } -JSObjectRef JSAttributeRangeFilter::createJSObject(JSContextRef context, AttributeRangeFilterPtr privateData) -{ - JSAttributeRangeFilterPriv *priv = new JSAttributeRangeFilterPriv(context, privateData); - JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsObjectRef) { - LogError("object creation error"); - return NULL; - } - return jsObjectRef; -} - AttributeRangeFilterPtr JSAttributeRangeFilter::getPrivData(JSObjectRef object) { LogDebug("entered"); @@ -170,13 +169,13 @@ JSObjectRef JSAttributeRangeFilter::constructor(JSContextRef context, // AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); -// JSAttributeRangeFilterPriv *priv = static_cast(JSObjectGetPrivate(constructor)); -// if (!priv) { -// ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); -// } -// JSContextRef gContext = priv->getContext(); + JSAttributeRangeFilterPriv *priv = static_cast(JSObjectGetPrivate(constructor)); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + JSContextRef gContext = priv->getContext(); - JSContextRef gContext = JSGlobalContextFactory::getInstance()->get(); +// JSContextRef gContext = JSGlobalContextFactory::getInstance()->get(); BasicValidator validator = BasicValidatorFactory::getValidator(gContext, exception); Try { diff --git a/src/standards/Tizen/Tizen/JSAttributeRangeFilter.h b/src/standards/Tizen/Tizen/JSAttributeRangeFilter.h index 2f38883..cd7dc8f 100755 --- a/src/standards/Tizen/Tizen/JSAttributeRangeFilter.h +++ b/src/standards/Tizen/Tizen/JSAttributeRangeFilter.h @@ -47,6 +47,9 @@ public: 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. @@ -76,9 +79,6 @@ private: static JSClassRef m_classRef; - static JSObjectRef createJSObject(JSContextRef context, - TizenApis::Api::Tizen::AttributeRangeFilterPtr privateData); - static TizenApis::Api::Tizen::AttributeRangeFilterPtr getPrivData(JSObjectRef object); static JSObjectRef constructor(JSContextRef context, diff --git a/src/standards/Tizen/Tizen/JSCompositeFilter.cpp b/src/standards/Tizen/Tizen/JSCompositeFilter.cpp index 20ce956..2cad942 100755 --- a/src/standards/Tizen/Tizen/JSCompositeFilter.cpp +++ b/src/standards/Tizen/Tizen/JSCompositeFilter.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include "FilterConverter.h" #include "JSAbstractFilterArray.h" #include "JSCompositeFilter.h" @@ -110,16 +109,27 @@ CompositeFilterPtr JSCompositeFilter::getCompositeFilter(JSContextRef context, J return priv->getObject(); } +JSObjectRef JSCompositeFilter::createJSObject(JSContextRef context, CompositeFilterPtr privateData) +{ + JSCompositeFilterPriv *priv = new JSCompositeFilterPriv(context, privateData); + JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; +} + void JSCompositeFilter::Initialize(JSContextRef context, JSObjectRef object) { -// if (!JSObjectGetPrivate(object)) -// { -// CompositeFilterPtr coord(new CompositeFilter("")); -// JSCompositeFilterPriv *priv = new JSCompositeFilterPriv(context, CompositeFilterPtr(coord)); -// if (!JSObjectSetPrivate(object, priv)) { -// delete priv; -// } -// } + 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) @@ -134,17 +144,6 @@ void JSCompositeFilter::Finalize(JSObjectRef object) priv = NULL; } -JSObjectRef JSCompositeFilter::createJSObject(JSContextRef context, CompositeFilterPtr privateData) -{ - JSCompositeFilterPriv *priv = new JSCompositeFilterPriv(context, privateData); - JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsObjectRef) { - LogError("object creation error"); - return NULL; - } - return jsObjectRef; -} - CompositeFilterPtr JSCompositeFilter::getPrivData(JSObjectRef object) { LogDebug("entered"); @@ -170,13 +169,13 @@ JSObjectRef JSCompositeFilter::constructor(JSContextRef context, // AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); -// JSCompositeFilterPriv *priv = static_cast(JSObjectGetPrivate(constructor)); -// if (!priv) { -// ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); -// } -// JSContextRef gContext = priv->getContext(); + JSCompositeFilterPriv *priv = static_cast(JSObjectGetPrivate(constructor)); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + JSContextRef gContext = priv->getContext(); - JSContextRef gContext = JSGlobalContextFactory::getInstance()->get(); +// JSContextRef gContext = JSGlobalContextFactory::getInstance()->get(); BasicValidator validator = BasicValidatorFactory::getValidator(gContext, exception); Try { diff --git a/src/standards/Tizen/Tizen/JSCompositeFilter.h b/src/standards/Tizen/Tizen/JSCompositeFilter.h index 8acb0d6..a8797e0 100755 --- a/src/standards/Tizen/Tizen/JSCompositeFilter.h +++ b/src/standards/Tizen/Tizen/JSCompositeFilter.h @@ -47,6 +47,8 @@ public: 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. @@ -76,8 +78,6 @@ private: static JSClassRef m_classRef; - static JSObjectRef createJSObject(JSContextRef context, TizenApis::Api::Tizen::CompositeFilterPtr privateData); - static TizenApis::Api::Tizen::CompositeFilterPtr getPrivData(JSObjectRef object); static JSObjectRef constructor(JSContextRef context, diff --git a/src/standards/Tizen/Tizen/JSSimpleCoordinates.cpp b/src/standards/Tizen/Tizen/JSSimpleCoordinates.cpp index 5764384..17eb49d 100755 --- a/src/standards/Tizen/Tizen/JSSimpleCoordinates.cpp +++ b/src/standards/Tizen/Tizen/JSSimpleCoordinates.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include "FilterConverter.h" #include "JSSimpleCoordinates.h" @@ -109,6 +108,17 @@ SimpleCoordinatesPtr JSSimpleCoordinates::getSimpleCoordinates(JSContextRef cont return priv->getObject(); } +JSObjectRef JSSimpleCoordinates::createJSObject(JSContextRef context, SimpleCoordinatesPtr privateData) +{ + JSSimpleCoordinatesPriv *priv = new JSSimpleCoordinatesPriv(context, privateData); + JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; +} + void JSSimpleCoordinates::Initialize(JSContextRef context, JSObjectRef object) { if (!JSObjectGetPrivate(object)) @@ -124,7 +134,6 @@ void JSSimpleCoordinates::Initialize(JSContextRef context, JSObjectRef object) void JSSimpleCoordinates::Finalize(JSObjectRef object) { JSSimpleCoordinatesPriv *priv = static_cast(JSObjectGetPrivate(object)); - printf("JSSimpleCoordinates::Finalize\n"); if (priv != NULL) { @@ -134,17 +143,6 @@ void JSSimpleCoordinates::Finalize(JSObjectRef object) priv = NULL; } -JSObjectRef JSSimpleCoordinates::createJSObject(JSContextRef context, SimpleCoordinatesPtr privateData) -{ - JSSimpleCoordinatesPriv *priv = new JSSimpleCoordinatesPriv(context, privateData); - JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsObjectRef) { - LogError("object creation error"); - return NULL; - } - return jsObjectRef; -} - SimpleCoordinatesPtr JSSimpleCoordinates::getPrivData(JSObjectRef object) { LogDebug("entered"); @@ -167,8 +165,6 @@ JSObjectRef JSSimpleCoordinates::constructor(JSContextRef context, { LogDebug("entered"); - printf("context : 0x%08x\n", (unsigned int)context); - // AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); @@ -178,9 +174,7 @@ JSObjectRef JSSimpleCoordinates::constructor(JSContextRef context, } JSContextRef gContext = priv->getContext(); - printf("tContaxt : 0x%08x\n", (unsigned int)priv->getContext()); - //JSGlobalContextRef gContext = JSGlobalContextFactory::getInstance()->get(); - printf("gContext : 0x%08x\n", (unsigned int)gContext); +// JSGlobalContextRef gContext = JSGlobalContextFactory::getInstance()->get(); BasicValidator validator = BasicValidatorFactory::getValidator(gContext, exception); Try { diff --git a/src/standards/Tizen/Tizen/JSSimpleCoordinates.h b/src/standards/Tizen/Tizen/JSSimpleCoordinates.h index d619036..f462204 100755 --- a/src/standards/Tizen/Tizen/JSSimpleCoordinates.h +++ b/src/standards/Tizen/Tizen/JSSimpleCoordinates.h @@ -47,6 +47,8 @@ public: 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. @@ -76,8 +78,6 @@ private: static JSClassRef m_classRef; - static JSObjectRef createJSObject(JSContextRef context, TizenApis::Api::Tizen::SimpleCoordinatesPtr privateData); - static TizenApis::Api::Tizen::SimpleCoordinatesPtr getPrivData(JSObjectRef object); static JSObjectRef constructor(JSContextRef context, diff --git a/src/standards/Tizen/Tizen/JSSortMode.cpp b/src/standards/Tizen/Tizen/JSSortMode.cpp index 26746bb..6e029cc 100755 --- a/src/standards/Tizen/Tizen/JSSortMode.cpp +++ b/src/standards/Tizen/Tizen/JSSortMode.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include "FilterConverter.h" #include "JSSortMode.h" @@ -109,16 +108,27 @@ SortModePtr JSSortMode::getSortMode(JSContextRef context, JSValueRef value) return priv->getObject(); } +JSObjectRef JSSortMode::createJSObject(JSContextRef context, SortModePtr privateData) +{ + JSSortModePriv *priv = new JSSortModePriv(context, privateData); + JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); + if (NULL == jsObjectRef) { + LogError("object creation error"); + return NULL; + } + return jsObjectRef; +} + void JSSortMode::Initialize(JSContextRef context, JSObjectRef object) { -// if (!JSObjectGetPrivate(object)) -// { -// SortModePtr coord(new SortMode("")); -// JSSortModePriv *priv = new JSSortModePriv(context, SortModePtr(coord)); -// if (!JSObjectSetPrivate(object, priv)) { -// delete priv; -// } -// } + 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) @@ -133,17 +143,6 @@ void JSSortMode::Finalize(JSObjectRef object) priv = NULL; } -JSObjectRef JSSortMode::createJSObject(JSContextRef context, SortModePtr privateData) -{ - JSSortModePriv *priv = new JSSortModePriv(context, privateData); - JSObjectRef jsObjectRef = JSObjectMake(context, getClassRef(), static_cast(priv)); - if (NULL == jsObjectRef) { - LogError("object creation error"); - return NULL; - } - return jsObjectRef; -} - SortModePtr JSSortMode::getPrivData(JSObjectRef object) { LogDebug("entered"); @@ -169,13 +168,13 @@ JSObjectRef JSSortMode::constructor(JSContextRef context, // AceSecurityStatus status = CONTACT_CHECK_ACCESS(controller->getContext(), CONTACT_FUNCTION_API_ADD); // TIZEN_SYNC_ACCESS_HANDLER(status, context, exception); -// JSSortModePriv *priv = static_cast(JSObjectGetPrivate(constructor)); -// if (!priv) { -// ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); -// } -// JSContextRef gContext = priv->getContext(); + JSSortModePriv *priv = static_cast(JSObjectGetPrivate(constructor)); + if (!priv) { + ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Private object is null"); + } + JSContextRef gContext = priv->getContext(); - JSContextRef gContext = JSGlobalContextFactory::getInstance()->get(); +// JSContextRef gContext = JSGlobalContextFactory::getInstance()->get(); BasicValidator validator = BasicValidatorFactory::getValidator(gContext, exception); Try { diff --git a/src/standards/Tizen/Tizen/JSSortMode.h b/src/standards/Tizen/Tizen/JSSortMode.h index eda44bc..231f7bd 100755 --- a/src/standards/Tizen/Tizen/JSSortMode.h +++ b/src/standards/Tizen/Tizen/JSSortMode.h @@ -47,6 +47,8 @@ public: 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. @@ -76,8 +78,6 @@ private: static JSClassRef m_classRef; - static JSObjectRef createJSObject(JSContextRef context, TizenApis::Api::Tizen::SortModePtr privateData); - static TizenApis::Api::Tizen::SortModePtr getPrivData(JSObjectRef object); static JSObjectRef constructor(JSContextRef context, -- 2.7.4