From 029e68a58c06e5a0ab07e297a078f53e95c722b5 Mon Sep 17 00:00:00 2001 From: Sehong Na Date: Sat, 31 May 2014 12:56:44 +0900 Subject: [PATCH 1/1] Initialize Tizen 2.3 --- CMakeLists.txt | 140 ++ LICENSE.APLv2 | 202 +++ NOTICE | 3 + inc/FMessaging.h | 77 + inc/FMsgCbsChannel.h | 190 +++ inc/FMsgCbsMessage.h | 211 +++ inc/FMsgDetailedEmailMessage.h | 647 +++++++ inc/FMsgEmailAttachment.h | 250 +++ inc/FMsgEmailManager.h | 182 ++ inc/FMsgEmailMessage.h | 227 +++ inc/FMsgEtwsPrimaryNotification.h | 188 +++ inc/FMsgICbsMessageEventListener.h | 81 + inc/FMsgIEmailListener.h | 91 + inc/FMsgIEtwsPrimaryNotificationEventListener.h | 85 + inc/FMsgIMmsListener.h | 96 ++ inc/FMsgIPushEventListener.h | 84 + inc/FMsgIPushManagerListener.h | 137 ++ inc/FMsgISmsEventListener.h | 94 ++ inc/FMsgISmsListener.h | 90 + inc/FMsgISmsMessageEventListener.h | 88 + inc/FMsgIWapPushEventListener.h | 84 + inc/FMsgMmsManager.h | 193 +++ inc/FMsgMmsMessage.h | 228 +++ inc/FMsgPushManager.h | 365 ++++ inc/FMsgPushMessage.h | 189 +++ inc/FMsgRecipientList.h | 227 +++ inc/FMsgSmsManager.h | 608 +++++++ inc/FMsgSmsMessage.h | 283 ++++ inc/FMsgTypes.h | 121 ++ inc/FMsgWapPushManager.h | 194 +++ inc/FMsgWapPushMessage.h | 164 ++ osp-messaging.manifest | 5 + osp-messaging.pc.in | 14 + packaging/osp-messaging.spec | 114 ++ src/FMsgCbsChannel.cpp | 174 ++ src/FMsgCbsMessage.cpp | 171 ++ src/FMsgDetailedEmailMessage.cpp | 514 ++++++ src/FMsgEmailAttachment.cpp | 200 +++ src/FMsgEmailManager.cpp | 125 ++ src/FMsgEmailMessage.cpp | 249 +++ src/FMsgEtwsPrimaryNotification.cpp | 202 +++ src/FMsgMmsManager.cpp | 146 ++ src/FMsgMmsMessage.cpp | 232 +++ src/FMsgPushManager.cpp | 210 +++ src/FMsgPushMessage.cpp | 131 ++ src/FMsgRecipientList.cpp | 205 +++ src/FMsgSmsManager.cpp | 768 +++++++++ src/FMsgSmsMessage.cpp | 308 ++++ src/FMsgWapPushManager.cpp | 178 ++ src/FMsgWapPushMessage.cpp | 148 ++ src/FMsg_CbsChannelImpl.cpp | 207 +++ src/FMsg_CbsChannelImpl.h | 286 ++++ src/FMsg_CbsMessageImpl.cpp | 293 ++++ src/FMsg_CbsMessageImpl.h | 329 ++++ src/FMsg_ComposerEvent.cpp | 72 + src/FMsg_ComposerEvent.h | 75 + src/FMsg_ComposerEventArg.cpp | 51 + src/FMsg_ComposerEventArg.h | 97 ++ src/FMsg_DetailedEmailMessageImpl.cpp | 1422 ++++++++++++++++ src/FMsg_DetailedEmailMessageImpl.h | 801 +++++++++ src/FMsg_EmailAttachmentImpl.cpp | 270 +++ src/FMsg_EmailAttachmentImpl.h | 363 ++++ src/FMsg_EmailEvent.cpp | 64 + src/FMsg_EmailEvent.h | 76 + src/FMsg_EmailEventArg.cpp | 55 + src/FMsg_EmailEventArg.h | 90 + src/FMsg_EmailManagerImpl.cpp | 277 +++ src/FMsg_EmailManagerImpl.h | 164 ++ src/FMsg_EmailMessageImpl.cpp | 541 ++++++ src/FMsg_EmailMessageImpl.h | 216 +++ src/FMsg_EtwsPrimaryNotificationImpl.cpp | 361 ++++ src/FMsg_EtwsPrimaryNotificationImpl.h | 284 ++++ src/FMsg_MessagingIpcProxy.cpp | 568 +++++++ src/FMsg_MessagingIpcProxy.h | 88 + src/FMsg_MessagingMessageTypes.cpp | 45 + src/FMsg_MmsEvent.cpp | 63 + src/FMsg_MmsEvent.h | 77 + src/FMsg_MmsEventArg.cpp | 48 + src/FMsg_MmsEventArg.h | 90 + src/FMsg_MmsManagerImpl.cpp | 241 +++ src/FMsg_MmsManagerImpl.h | 149 ++ src/FMsg_MmsMessageImpl.cpp | 598 +++++++ src/FMsg_MmsMessageImpl.h | 250 +++ src/FMsg_MsgUtil.cpp | 2041 +++++++++++++++++++++++ src/FMsg_MsgUtil.h | 83 + src/FMsg_PushEvent.cpp | 75 + src/FMsg_PushEvent.h | 68 + src/FMsg_PushEventArg.cpp | 91 + src/FMsg_PushEventArg.h | 77 + src/FMsg_PushManagerImpl.cpp | 1919 +++++++++++++++++++++ src/FMsg_PushManagerImpl.h | 240 +++ src/FMsg_PushMessageImpl.cpp | 349 ++++ src/FMsg_PushMessageImpl.h | 158 ++ src/FMsg_PushRequest.cpp | 82 + src/FMsg_PushRequest.h | 68 + src/FMsg_PushSendListener.cpp | 295 ++++ src/FMsg_PushSendListener.h | 83 + src/FMsg_PushUrlRequestListener.cpp | 234 +++ src/FMsg_PushUrlRequestListener.h | 85 + src/FMsg_RecipientListImpl.cpp | 947 +++++++++++ src/FMsg_RecipientListImpl.h | 244 +++ src/FMsg_SmsEvent.cpp | 205 +++ src/FMsg_SmsEvent.h | 99 ++ src/FMsg_SmsEventArg.cpp | 294 ++++ src/FMsg_SmsEventArg.h | 253 +++ src/FMsg_SmsManagerImpl.cpp | 1128 +++++++++++++ src/FMsg_SmsManagerImpl.h | 389 +++++ src/FMsg_SmsMessageImpl.cpp | 269 +++ src/FMsg_SmsMessageImpl.h | 293 ++++ src/FMsg_SmsMmsCallbackHandler.cpp | 573 +++++++ src/FMsg_SmsMmsCallbackHandler.h | 196 +++ src/FMsg_WapPushManagerImpl.cpp | 215 +++ src/FMsg_WapPushManagerImpl.h | 214 +++ src/FMsg_WapPushMessageImpl.cpp | 188 +++ src/FMsg_WapPushMessageImpl.h | 207 +++ src/inc/FMsg_IComposerListener.h | 62 + src/inc/FMsg_MessagingMessageTypes.h | 68 + src/inc/FMsg_Types.h | 113 ++ 118 files changed, 30429 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 LICENSE.APLv2 create mode 100644 NOTICE create mode 100644 inc/FMessaging.h create mode 100755 inc/FMsgCbsChannel.h create mode 100755 inc/FMsgCbsMessage.h create mode 100755 inc/FMsgDetailedEmailMessage.h create mode 100644 inc/FMsgEmailAttachment.h create mode 100755 inc/FMsgEmailManager.h create mode 100755 inc/FMsgEmailMessage.h create mode 100755 inc/FMsgEtwsPrimaryNotification.h create mode 100755 inc/FMsgICbsMessageEventListener.h create mode 100755 inc/FMsgIEmailListener.h create mode 100755 inc/FMsgIEtwsPrimaryNotificationEventListener.h create mode 100755 inc/FMsgIMmsListener.h create mode 100755 inc/FMsgIPushEventListener.h create mode 100755 inc/FMsgIPushManagerListener.h create mode 100755 inc/FMsgISmsEventListener.h create mode 100755 inc/FMsgISmsListener.h create mode 100755 inc/FMsgISmsMessageEventListener.h create mode 100755 inc/FMsgIWapPushEventListener.h create mode 100755 inc/FMsgMmsManager.h create mode 100755 inc/FMsgMmsMessage.h create mode 100755 inc/FMsgPushManager.h create mode 100755 inc/FMsgPushMessage.h create mode 100755 inc/FMsgRecipientList.h create mode 100755 inc/FMsgSmsManager.h create mode 100755 inc/FMsgSmsMessage.h create mode 100755 inc/FMsgTypes.h create mode 100755 inc/FMsgWapPushManager.h create mode 100755 inc/FMsgWapPushMessage.h create mode 100644 osp-messaging.manifest create mode 100755 osp-messaging.pc.in create mode 100644 packaging/osp-messaging.spec create mode 100644 src/FMsgCbsChannel.cpp create mode 100644 src/FMsgCbsMessage.cpp create mode 100644 src/FMsgDetailedEmailMessage.cpp create mode 100644 src/FMsgEmailAttachment.cpp create mode 100755 src/FMsgEmailManager.cpp create mode 100644 src/FMsgEmailMessage.cpp create mode 100644 src/FMsgEtwsPrimaryNotification.cpp create mode 100755 src/FMsgMmsManager.cpp create mode 100644 src/FMsgMmsMessage.cpp create mode 100755 src/FMsgPushManager.cpp create mode 100644 src/FMsgPushMessage.cpp create mode 100644 src/FMsgRecipientList.cpp create mode 100755 src/FMsgSmsManager.cpp create mode 100755 src/FMsgSmsMessage.cpp create mode 100644 src/FMsgWapPushManager.cpp create mode 100644 src/FMsgWapPushMessage.cpp create mode 100644 src/FMsg_CbsChannelImpl.cpp create mode 100644 src/FMsg_CbsChannelImpl.h create mode 100644 src/FMsg_CbsMessageImpl.cpp create mode 100644 src/FMsg_CbsMessageImpl.h create mode 100644 src/FMsg_ComposerEvent.cpp create mode 100644 src/FMsg_ComposerEvent.h create mode 100644 src/FMsg_ComposerEventArg.cpp create mode 100644 src/FMsg_ComposerEventArg.h create mode 100755 src/FMsg_DetailedEmailMessageImpl.cpp create mode 100644 src/FMsg_DetailedEmailMessageImpl.h create mode 100644 src/FMsg_EmailAttachmentImpl.cpp create mode 100644 src/FMsg_EmailAttachmentImpl.h create mode 100644 src/FMsg_EmailEvent.cpp create mode 100644 src/FMsg_EmailEvent.h create mode 100644 src/FMsg_EmailEventArg.cpp create mode 100644 src/FMsg_EmailEventArg.h create mode 100644 src/FMsg_EmailManagerImpl.cpp create mode 100644 src/FMsg_EmailManagerImpl.h create mode 100644 src/FMsg_EmailMessageImpl.cpp create mode 100644 src/FMsg_EmailMessageImpl.h create mode 100644 src/FMsg_EtwsPrimaryNotificationImpl.cpp create mode 100644 src/FMsg_EtwsPrimaryNotificationImpl.h create mode 100644 src/FMsg_MessagingIpcProxy.cpp create mode 100644 src/FMsg_MessagingIpcProxy.h create mode 100644 src/FMsg_MessagingMessageTypes.cpp create mode 100644 src/FMsg_MmsEvent.cpp create mode 100644 src/FMsg_MmsEvent.h create mode 100644 src/FMsg_MmsEventArg.cpp create mode 100644 src/FMsg_MmsEventArg.h create mode 100644 src/FMsg_MmsManagerImpl.cpp create mode 100644 src/FMsg_MmsManagerImpl.h create mode 100644 src/FMsg_MmsMessageImpl.cpp create mode 100644 src/FMsg_MmsMessageImpl.h create mode 100644 src/FMsg_MsgUtil.cpp create mode 100644 src/FMsg_MsgUtil.h create mode 100644 src/FMsg_PushEvent.cpp create mode 100644 src/FMsg_PushEvent.h create mode 100644 src/FMsg_PushEventArg.cpp create mode 100644 src/FMsg_PushEventArg.h create mode 100755 src/FMsg_PushManagerImpl.cpp create mode 100755 src/FMsg_PushManagerImpl.h create mode 100755 src/FMsg_PushMessageImpl.cpp create mode 100644 src/FMsg_PushMessageImpl.h create mode 100755 src/FMsg_PushRequest.cpp create mode 100755 src/FMsg_PushRequest.h create mode 100755 src/FMsg_PushSendListener.cpp create mode 100755 src/FMsg_PushSendListener.h create mode 100755 src/FMsg_PushUrlRequestListener.cpp create mode 100755 src/FMsg_PushUrlRequestListener.h create mode 100644 src/FMsg_RecipientListImpl.cpp create mode 100644 src/FMsg_RecipientListImpl.h create mode 100644 src/FMsg_SmsEvent.cpp create mode 100644 src/FMsg_SmsEvent.h create mode 100644 src/FMsg_SmsEventArg.cpp create mode 100644 src/FMsg_SmsEventArg.h create mode 100644 src/FMsg_SmsManagerImpl.cpp create mode 100644 src/FMsg_SmsManagerImpl.h create mode 100644 src/FMsg_SmsMessageImpl.cpp create mode 100644 src/FMsg_SmsMessageImpl.h create mode 100644 src/FMsg_SmsMmsCallbackHandler.cpp create mode 100644 src/FMsg_SmsMmsCallbackHandler.h create mode 100644 src/FMsg_WapPushManagerImpl.cpp create mode 100644 src/FMsg_WapPushManagerImpl.h create mode 100644 src/FMsg_WapPushMessageImpl.cpp create mode 100644 src/FMsg_WapPushMessageImpl.h create mode 100644 src/inc/FMsg_IComposerListener.h create mode 100644 src/inc/FMsg_MessagingMessageTypes.h create mode 100644 src/inc/FMsg_Types.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7b751ed --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,140 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +SET (this_target osp-messaging) + +SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/cmake_build_tmp/output) + +INCLUDE_DIRECTORIES( + inc + src + src/inc + /usr/include/chromium + /usr/include/appfw + /usr/include/glib-2.0 + /usr/lib/glib-2.0/include + /usr/include/osp + /usr/include/osp/app + /usr/include/osp/base + /usr/include/osp/security + /usr/include/osp/system + /usr/include/msg-service + /usr/include/dbus-1.0 + /usr/lib/dbus-1.0/include + /usr/include/email-service + /usr/include/libxml2 + /usr/include/osp/io + ) + +SET (${this_target}_SOURCE_FILES + src/FMsgEmailManager.cpp + src/FMsgEmailMessage.cpp + src/FMsgEmailAttachment.cpp + src/FMsgDetailedEmailMessage.cpp + src/FMsgMmsManager.cpp + src/FMsgMmsMessage.cpp + src/FMsgPushManager.cpp + src/FMsgPushMessage.cpp + src/FMsgWapPushManager.cpp + src/FMsgWapPushMessage.cpp + src/FMsgRecipientList.cpp + src/FMsgSmsManager.cpp + src/FMsgSmsMessage.cpp + src/FMsgCbsChannel.cpp + src/FMsgCbsMessage.cpp + src/FMsgEtwsPrimaryNotification.cpp + src/FMsg_EmailEvent.cpp + src/FMsg_EmailEventArg.cpp + src/FMsg_EmailManagerImpl.cpp + src/FMsg_EmailMessageImpl.cpp + src/FMsg_EmailAttachmentImpl.cpp + src/FMsg_DetailedEmailMessageImpl.cpp + src/FMsg_MmsEvent.cpp + src/FMsg_MmsEventArg.cpp + src/FMsg_MmsManagerImpl.cpp + src/FMsg_MmsMessageImpl.cpp + src/FMsg_PushEvent.cpp + src/FMsg_PushEventArg.cpp + src/FMsg_PushManagerImpl.cpp + src/FMsg_PushMessageImpl.cpp + src/FMsg_PushRequest.cpp + src/FMsg_PushSendListener.cpp + src/FMsg_PushUrlRequestListener.cpp + src/FMsg_WapPushManagerImpl.cpp + src/FMsg_WapPushMessageImpl.cpp + src/FMsg_ComposerEvent.cpp + src/FMsg_ComposerEventArg.cpp + src/FMsg_RecipientListImpl.cpp + src/FMsg_SmsEvent.cpp + src/FMsg_SmsEventArg.cpp + src/FMsg_SmsManagerImpl.cpp + src/FMsg_SmsMessageImpl.cpp + src/FMsg_CbsChannelImpl.cpp + src/FMsg_CbsMessageImpl.cpp + src/FMsg_EtwsPrimaryNotificationImpl.cpp + src/FMsg_MsgUtil.cpp + src/FMsg_SmsMmsCallbackHandler.cpp + src/FMsg_MessagingMessageTypes.cpp + src/FMsg_MessagingIpcProxy.cpp +) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall" ) + +## SET C COMPILER FLAGS +SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}") + +## SET CPP COMPILER FLAGS +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") +SET(CMAKE_CXX_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}") + +## Create Library +ADD_LIBRARY (${this_target} SHARED ${${this_target}_SOURCE_FILES}) + +## SET LINKER FLAGS +SET(CMAKE_SHARED_LINKER_FLAGS -Wl,--no-undefined) + +TARGET_LINK_LIBRARIES(${this_target} "-lchromium" ) +TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp -losp-appfw -losp-json -losp-net -losp-shell-core" ) +TARGET_LINK_LIBRARIES(${this_target} "-lcapi-appfw-application" ) +TARGET_LINK_LIBRARIES(${this_target} "-ldbus-1" ) +TARGET_LINK_LIBRARIES(${this_target} "-ldbus-glib-1" ) +TARGET_LINK_LIBRARIES(${this_target} "-lemail-api" ) +TARGET_LINK_LIBRARIES(${this_target} "-lmsg_mapi" ) +TARGET_LINK_LIBRARIES(${this_target} "-lpush" ) + + +SET_TARGET_PROPERTIES(${this_target} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 + ) + +ADD_CUSTOM_COMMAND(TARGET ${this_target} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${FULLVER} + COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${FULLVER} ${LIBRARY_OUTPUT_PATH}/debug/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX}.${MAJORVER} + COMMAND ${CMAKE_STRIP} --strip-unneeded ${LIBRARY_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}${this_target}${CMAKE_SHARED_LIBRARY_SUFFIX} + COMMENT "strip ${this_target}" + ) + +INSTALL(DIRECTORY ${LIBRARY_OUTPUT_PATH}/ DESTINATION lib/osp + FILES_MATCHING PATTERN "*.so*" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ + GROUP_EXECUTE GROUP_READ + WORLD_EXECUTE WORLD_READ) +INSTALL(DIRECTORY ${LIBRARY_OUTPUT_PATH}/debug/ DESTINATION lib/osp/debug + FILES_MATCHING PATTERN "*.so*" + PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ + GROUP_EXECUTE GROUP_READ + WORLD_EXECUTE WORLD_READ) + +INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/inc/ DESTINATION include/osp FILES_MATCHING PATTERN "*.h") +INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/src/inc/ DESTINATION include/osp/messaging FILES_MATCHING PATTERN "*.h") + +SET(PC_NAME ${this_target}) +SET(VERSION ${FULLVER}) +SET(PC_LDFLAGS -l${this_target}) + +# pkgconfig file +CONFIGURE_FILE(${this_target}.pc.in ${CMAKE_SOURCE_DIR}/${this_target}.pc @ONLY) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/${this_target}.pc DESTINATION lib/pkgconfig) diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE.APLv2 @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..cbdf92f --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE.APLv2 file for Apache License terms and conditions. diff --git a/inc/FMessaging.h b/inc/FMessaging.h new file mode 100644 index 0000000..dca338c --- /dev/null +++ b/inc/FMessaging.h @@ -0,0 +1,77 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMessaging.h + * @brief This is the header file for the %Messaging namespace. + * + * This header file contains the declarations and descriptions of the %Messaging namespace. + */ + +#ifndef _FMESSAGING_H_ +#define _FMESSAGING_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * @namespace Tizen::Messaging + * @brief This namespace contains classes and interfaces for messaging services. + * @since 2.0 + * + * @remarks @b Header @b %file: @b \#include @b @n + * @b Library: @b osp-messaging + * + * The %Messaging namespace accesses the messaging capabilities of the device. @n + * It provides classes and interfaces for the following: @n + * - SMS: create, send, receive, and retrieve + * - MMS: create and send + * - email: create and send + * - push: receive + * + * For more information on the %Messaging namespace features, see Messaging Guide. + * + * The following diagram illustrates the relationships between the classes belonging to the %Messaging namespace. + * @image html messaging_using_the_apis_classdiagram.png + * + */ +namespace Tizen +{ + namespace Messaging + { + + }; +}; // Tizen::Messaging + +#endif // _FMESSAGING_H_ diff --git a/inc/FMsgCbsChannel.h b/inc/FMsgCbsChannel.h new file mode 100755 index 0000000..2653f32 --- /dev/null +++ b/inc/FMsgCbsChannel.h @@ -0,0 +1,190 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgCbsChannel.h + * @brief This is the header file for the %CbsChannel class. + * + * This header file contains the declarations of the %CbsChannel class. + */ + +#ifndef _FMSG_CBS_CHANNEL_H_ +#define _FMSG_CBS_CHANNEL_H_ + +namespace Tizen { namespace Base +{ +class String; +} } + +#include + +namespace Tizen { namespace Messaging +{ +class _CbsChannelImpl; + +/** + * @class CbsChannel + * @brief This class provides methods for handling a Cell Broadcast Service (CBS) channel. + * + * @since 2.0 + * + * @final This class is not intended for extension. + * + * The %CbsChannel class provides methods for handling a CBS channel. It allows the user to get and set the CBS channel information. + */ +class _OSP_EXPORT_ CbsChannel + : public Tizen::Base::Object +{ +public: + + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~CbsChannel(void); + + /** + * Gets the range of a CBS channel. + * + * @since 2.0 + * + * @return An error code + * @param[out] from The starting index of the message ID of the channel + * @param[out] to The last index of the message ID of the channel + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_STATE The range has not been set as yet. + * @exception E_SYSTEM A system error has occurred. + * @remarks In case of an error, this method sets negative values for @c from and @c to. For example, @c -1. + */ + result GetRange(int& from, int& to) const; + + /** + * Gets the name of a CBS channel. + * + * @since 2.0 + * + * @return The name of the channel @n + * The name can be an empty string. + */ + Tizen::Base::String GetName(void) const; + + /** + * Checks whether a CBS channel is activated. + * + * @since 2.0 + * + * @return @c true if the CBS channel is activated, @n + * else @c false + */ + bool IsActivated(void) const; + + /** + * Activates the status of a CBS channel. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + * + * @return An error code + * @exception E_SUCCESS The method is successful. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to activate the CBS channel's status. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + */ + result Activate(void); + + /** + * Deactivates the status of a CBS channel. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + * + * @return An error code + * @exception E_SUCCESS The method is successful. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to activate the CBS channel's status. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + */ + result Deactivate(void); + + /** + * Updates the name of a CBS channel. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + + * @return An error code + * @param[in] name The name of the CBS channel to update + * @exception E_SUCCESS The method is successful. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to update the CBS channel's name. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + */ + result UpdateName(const Tizen::Base::String& name); + +private: + /** + * This default constructor is intentionally declared as private so that only the platform can create an instance. + * + * @since 2.0 + */ + CbsChannel(void); + + /** + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] rhs An instance of %CbsChannel + */ + CbsChannel(const CbsChannel& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] rhs An instance of %CbsChannel + */ + CbsChannel& operator =(const CbsChannel& rhs); + + /** + * Initializes this instance of %CbsChannel with the specified parameters. + * + * @since 2.0 + * + * @return An error code + * @param[in] from The starting index of the message ID of the channel + * @param[in] to The last index of the message ID of the channel + * @param[in] name The name of the channel (can be an empty string) + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c to parameter is smaller than @c from. + * - The specified @c to or @c from parameter is a negative value. + * - The specified @c to parameter exceeds the limit (0xFFFF). + * - The range (@c to - @c from) exceeds the limit (0xFFFF). + * - The specified @c name string length is greater than @c 32. + * @exception E_SYSTEM A system error has occurred. + */ + result Construct(int from, int to, const Tizen::Base::String& name); + +private: + _CbsChannelImpl* __pCbsChannelImpl; + + friend class _CbsChannelImpl; +}; // CbsChannel + +} } // Tizen::Messaging +#endif // _FMSG_CBS_CHANNEL_H_ diff --git a/inc/FMsgCbsMessage.h b/inc/FMsgCbsMessage.h new file mode 100755 index 0000000..d1a8804 --- /dev/null +++ b/inc/FMsgCbsMessage.h @@ -0,0 +1,211 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgCbsMessage.h + * @brief This is the header file for the %CbsMessage class. + * + * This header file contains the declarations of the %CbsMessage class. + */ + +#ifndef _FMSG_CBS_MESSAGE_H_ +#define _FMSG_CBS_MESSAGE_H_ + +namespace Tizen { namespace Base +{ +class ByteBuffer; +class String; +class DateTime; +} } + +#include +#include + +namespace Tizen { namespace Messaging +{ + +class _CbsMessageImpl; + +/** + * @class CbsMessage + * + * @brief This class provides methods for handling a CBS message. + * + * @since 2.0 + * + * @final This class is not intended for extension. + * + * The %CbsMessage class provides methods for handling a CBS message (including a ETWS secondary notification). It allows the user to get the serial number, + * message ID, body text, and received time of a CBS message. + */ +class _OSP_EXPORT_ CbsMessage + : public Tizen::Base::Object +{ +public: + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~CbsMessage(void); + + /** + * Compares the specified instance with the current instance. + * + * @since 2.0 + * + * @return @c true if the specified instance of Tizen::Base::Object is equal to the caurrent %CbsMessage instance, @n + * else @c false + * @param[in] obj An instance of Tizen::Base::Object to compare + * @see Tizen::Base::Object::Equals() + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Copies the instance of this class. + * + * @since 2.0 + * + * @return An instance of %CbsMessage, @n + * else @c null in case of an error + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + CbsMessage* CloneN(void) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + /** + * Checks whether this message is an ETWS notification. + * + * @since 2.0 + * + * @return @c true if this message is an ETWS notification, @n + * else @c false + * @remarks If the return value is @c true, the message is an ETWS secondary notification. + */ + bool IsEtwsNotification(void) const; + + /** + * Gets the serial number of a CBS message. + * + * @since 2.0 + * + * @return The serial number of the CBS message, @n + * else @c null in case of an error + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* GetSerialNumberN(void) const; + + /** + * Gets the message ID of a CBS message. + * + * @since 2.0 + * + * @return The message ID of the CBS message + */ + int GetMessageId(void) const; + + /** + * Gets the body of a message. + * + * @since 2.0 + * + * @return The body of the message + */ + Tizen::Base::String GetText(void) const; + + /** + * Gets the date and time (UTC time) of a message when it is received. + * + * @since 2.0 + * + * @return The date and time (UTC time) when the message is received + */ + Tizen::Base::DateTime GetReceivedTime(void) const; + + /** + * Gets the Data Coding Scheme of a CBS message. + * + * @since 2.0 + * + * @return The Data Coding Scheme of the CBS message, @n + * else @c null in case of an error + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks + * - The specific error code can be accessed using the GetLastResult() method. + * - The alphabet/coding and language applied to CBS messages are defined in 3GPP TS 23.038. + */ + byte GetDataCodingScheme(void) const; + + /** + * Gets the language type of a message. + * + * @since 2.1 + * + * @return The language type of the message + */ + Tizen::Base::String GetLanguageType(void) const; + +private: + /** + * This default constructor is intentionally declared as private so that only the platform can create an instance. + * + * @since 2.0 + */ + CbsMessage(void); + + /** + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @since 2.0 + * + * @param[in] rhs An instance of %CbsMessage + */ + CbsMessage(const CbsMessage& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. @n + * - Use CloneN() to get an exact copy of the instance. + * - Use Equals() to compare the contents of one instance with the other. + * + * @since 2.0 + * + * @return A reference to this instance + * @param[in] rhs An instance of %CbsMessage + */ + CbsMessage& operator =(const CbsMessage& rhs); + +private: + _CbsMessageImpl* __pCbsMessageImpl; + + friend class _CbsMessageImpl; +}; // CbsMessage + +} } // Tizen::Messaging +#endif // _FMSG_CBS_MESSAGE_H_ diff --git a/inc/FMsgDetailedEmailMessage.h b/inc/FMsgDetailedEmailMessage.h new file mode 100755 index 0000000..b470a90 --- /dev/null +++ b/inc/FMsgDetailedEmailMessage.h @@ -0,0 +1,647 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgDetailedEmailMessage.h + * @brief This is the header file for the %DetailedEmailMessage class. + * + * This header file contains the declarations of the %DetailedEmailMessage class. + */ + +#ifndef _FMSG_DETAILED_EMAIL_MESSAGE_H_ +#define _FMSG_DETAILED_EMAIL_MESSAGE_H_ + +namespace Tizen { namespace Base +{ +class String; +class DateTime; +namespace Collection +{ + class IList; +} +} } + +#include +#include + +namespace Tizen { namespace Messaging +{ + /** + * @enum EmailMessageClass + * + * Defines the classes of an email message. + * + * @since 2.0 + * + */ + enum EmailMessageClass + { + EMAIL_MESSAGE_CLASS_UNSPECIFIED = 0, /**< Unspecified */ + EMAIL_MESSAGE_CLASS_UNKNOWN, /**< Unknown */ + EMAIL_MESSAGE_CLASS_NOTE, /**< Normal email message */ + EMAIL_MESSAGE_CLASS_NOTE_RULES_OOF_TEMPLATE_MICROSOFT, /**< Out-of-office template */ + EMAIL_MESSAGE_CLASS_NOTE_SMIME, /**< The message is encrypted and can also be signed */ + EMAIL_MESSAGE_CLASS_NOTE_SMIME_MULTIPART_SIGNED, /**< The message is clear signed */ + EMAIL_MESSAGE_CLASS_NOTIFICATION_MEETING, /**< Meeting notification */ + EMAIL_MESSAGE_CLASS_OCTEL_VOICE, /**< Octel voice message */ + EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_REQUEST, /**< Meeting request */ + EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_CANCELLED, /**< Meeting cancelled */ + EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_POSITIVE_RESPONSE, /**< Positive meeting response */ + EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_TENTATIVE_RESPONSE, /**< Tentative meeting response */ + EMAIL_MESSAGE_CLASS_SCHEDULE_MEETING_NEGATIVE_RESPONSE, /**< Negative meeting response */ + EMAIL_MESSAGE_CLASS_POST, /**< Post */ + EMAIL_MESSAGE_CLASS_INFO_PATH_FORM, /**< An InfoPath form */ + EMAIL_MESSAGE_CLASS_VOICE_NOTES, /**< Electronic voice notes */ + EMAIL_MESSAGE_CLASS_SHARING, /**< Shared message */ + //EMAIL_MESSAGE_CLASS_NOTE_EXCHANGE_ACTIVE_SYNC_REMOTE_WIPE_CONFIRMATION, // should be added + EMAIL_MESSAGE_CLASS_VOICE_MAIL, /**< Voice mail */ + //EMAIL_MESSAGE_CLASS_SMS, + //EMAIL_MESSAGE_CLASS_SMART_REPLY = 0x01000000, + //EMAIL_MESSAGE_CLASS_SMART_FORWARD = 0x02000000, + EMAIL_MESSAGE_CLASS_REPORT_NOT_READ_REPORT = 0x10000000, /**< Not read report for a standard message */ + EMAIL_MESSAGE_CLASS_REPORT_READ_REPORT = 0x20000000, /**< Read report for a standard message */ + EMAIL_MESSAGE_CLASS_REPORT_NON_DELIVERY_RECEIPT = 0x40000000, /**< Non-delivery receipt for a standard message */ + EMAIL_MESSAGE_CLASS_REPORT_DELIVERY_RECEIPT = 0x80000000 /**< Delivery receipt for a standard message */ + }; + + /** + * @enum EmailDigestType + * + * Defines the digest types of an email message. + * + * @since 2.0 + */ + enum EmailDigestType + { + EMAIL_DIGEST_TYPE_MD5 = 0, /**< The MD5 type */ + EMAIL_DIGEST_TYPE_SHA1 /**< The SHA-1 type */ + }; + + /** + * @enum EmailSmimeType + * + * Defines the S/MIME types of an email message. + * + * @since 2.0 + */ + enum EmailSmimeType + { + EMAIL_SMIME_TYPE_NONE = 0, /**< The undefined type */ + EMAIL_SMIME_TYPE_SIGNED, /**< The signed type */ + EMAIL_SMIME_TYPE_ENCRYPTED, /**< The encrypted type */ + EMAIL_SMIME_TYPE_SIGNED_AND_ENCRYPTED /**< Both signed and encrypted type */ + }; + + /** + * @enum EmailReturnReceiptType + * + * Defines the return receipt types for an email message. + * + * @since 2.0 + */ + enum EmailReturnReceiptType + { + EMAIL_RETURN_RECEIPT_TYPE_NONE = 0x00, /**< Normal Mail */ + EMAIL_RETURN_RECEIPT_TYPE_REQUEST = 0x03, /**< MDN-requesting mail */ // should be deprecated + EMAIL_RETURN_RECEIPT_TYPE_DSN = 0x04, /**< Delivery Status Notification (DSN - Delivery Status Mail) */ + EMAIL_RETURN_RECEIPT_TYPE_MDN = 0x08, /**< Message Disposition Notification (MDN - Read Status Mail) */ + //EMAIL_RETURN_RECEIPT_TYPE_REQUEST_DSN = 0x10, + //EMAIL_RETURN_RECEIPT_TYPE_REQUEST_MDN = 0x20, + }; + + /** + * @enum EmailMessageBodyType + * + * Defines the types of an email message body. + * + * @since 2.0 + */ + enum EmailMessageBodyType + { + EMAIL_MESSAGE_BODY_TYPE_PLAIN_TEXT = 0, /**< The plain text type */ + EMAIL_MESSAGE_BODY_TYPE_HTML, /**< The HTML type */ + EMAIL_MESSAGE_BODY_TYPE_MIME /**< The MIME type */ + }; + + + // forward declaration + class _DetailedEmailMessageImpl; + + /** + * @class DetailedEmailMessage + * @brief This class provides methods for handling detailed email messages. + * + * @since 2.0 + * + * The %DetailedEmailMessage class provides methods for handling detailed email messages. + */ + class _OSP_EXPORT_ DetailedEmailMessage + : public Tizen::Base::Object + { + // Life cycle + public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + DetailedEmailMessage(void); + + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~DetailedEmailMessage(void); + + /** + * This is the copy constructor for the %DetailedEmailMessage class. @n + * Copying of objects using this copy constructor is allowed. + * + * @since 2.0 + * + * @param[in] rhs An instance of %DetailedEmailMessage to copy + */ + DetailedEmailMessage(const DetailedEmailMessage& rhs); + + + public: + /** + * Assigns the value of the specified instance to the current instance of %DetailedEmailMessage. @n + * Copying of objects using this copy assignment operator is allowed. + * + * @since 2.0 + * + * @return A reference of this instance + * @param[in] rhs An instance of %DetailedEmailMessage to copy + */ + DetailedEmailMessage& operator =(const DetailedEmailMessage& rhs); + + /** + * Compares the specified instance with the current instance. + * + * @since 2.0 + * + * @return @c true if the specified instance of Tizen::Base::Object is equal to the current %DetailedEmailMessage instance, @n + * else @c false + * @param[in] obj An instance of Tizen::Base::Object to compare + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + // Operation + public: + /////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////// + /** + * Gets the message ID. + * + * @since 2.0 + * + * @return The message ID + * @see SetMessageId() + */ + Tizen::Base::String GetMessageId(void) const; + + /** + * Gets the subject of an email message. + * + * @since 2.0 + * + * @return The subject of the email message + * @see SetSubject() + */ + Tizen::Base::String GetSubject(void) const; + + /** + * Gets the time when an email message is created. + * + * @since 2.0 + * + * @return The time when the email message is created + * @remarks The creation time may be updated by the mail server when an email is sent. + * @see SetCreationTime() + */ + Tizen::Base::DateTime GetCreationTime(void) const; + + /** + * Gets the email address of the specified recipient type. + * + * @since 2.0 + * + * @return The email address of the specified recipient type @n + * The values for the various recipients can be a string with multiple email addresses separated by semi-colons(;). + * @param[in] type The recipient type @n + * This value contains @c RECIPIENT_TYPE_TO, @c RECIPIENT_TYPE_CC or @c RECIPIENT_TYPE_BCC. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see SetAddress() + * + */ + Tizen::Base::String GetAddress(RecipientType type) const; + + /** + * Gets the email address of an author. + * + * @since 2.0 + * + * @return The email address of the author + * @see SetFromAddress() + */ + Tizen::Base::String GetFromAddress(void) const; + + /** + * Gets the email address used to reply to a message. + * + * @since 2.0 + * + * @return The email address used to reply to the message + * @see SetReplyToAddress() + */ + Tizen::Base::String GetReplyToAddress(void) const; + + /** + * Gets the return path. + * + * @since 2.0 + * + * @return The return path + * @see SetReturnPath() + */ + Tizen::Base::String GetReturnPath(void) const; + + /** + * Gets the file path of the specified message body type. + * + * @since 2.0 + * + * @return The file path of the message body type + * @param[in] type The message body type + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see SetFilePath() + */ + Tizen::Base::String GetFilePath(EmailMessageBodyType type) const; + + /** + * Gets the priority of a message. + * + * @since 2.0 + * + * @return The priority of the message + * @see SetPriority() + */ + EmailMessagePriority GetPriority(void) const; + + /** + * Gets the return receipt type of a message. + * + * @since 2.0 + * + * @return The return receipt type of the message + * @see SetReturnReceiptType() + */ + EmailReturnReceiptType GetReturnReceiptType(void) const; + + /** + * Gets the inline content count of a message. + * + * @since 2.0 + * + * @return The inline content count of the message + * @see SetInlineContentCount() + */ + int GetInlineContentCount(void) const; + + /** + * Gets the class of a message. + * + * @since 2.0 + * + * @return The class of the message + * @see SetClass() + */ + EmailMessageClass GetClass(void) const; + + /** + * Gets the digest type of a message. + * + * @since 2.0 + * + * @return The digest type of the message + * @see SetDigestType() + */ + EmailDigestType GetDigestType(void) const; + + /** + * Gets the S/MIME type of a message. + * + * @since 2.0 + * + * @return The S/MIME type of the message + * @see SetSmimeType() + */ + EmailSmimeType GetSmimeType(void) const; + + /** + * Gets the attachment list of this message. + * + * @since 2.0 + * + * @return A pointer to the attachment list + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks + * - The specific error code can be accessed using the GetLastResult() method. + * - After using the attachment list, the user can call Tizen::Base::Collection::IList::RemoveAll(true) to clean up items from the list. + * @see EmailAttachment + * @see SetAttachmentList() + */ + Tizen::Base::Collection::IList* GetAttachmentListN(void); + + + public: + /////////////////////////////////////////////////////////////// + // Setters + /////////////////////////////////////////////////////////////// + /** + * Sets the message ID. + * + * @since 2.0 + * + * @return An error code + * @param[in] messageId The message ID + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The length of the specified @c messageId is @c 0. + * @remarks + * - The message ID is an automatically generated field. + * - It is used to prevent multiple delivery and is used as a reference in In-Reply-To. + * @see GetMessageId() + */ + result SetMessageId(const Tizen::Base::String& messageId); + + /** + * Sets the subject of an email message. + * + * @since 2.0 + * + * @return An error code + * @param[in] subject The subject of the email message + * @exception E_SUCCESS The method is successful. + * @exception E_MAX_EXCEEDED The subject length of the message exceeds the maximum limit (Maximum 256 characters). + * @see GetSubject() + */ + result SetSubject(const Tizen::Base::String& subject); + + /** + * Sets the time when an email message is created. + * + * @since 2.0 + * + * @return An error code + * @param[in] dateTime The time when the email message is created + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c dateTime is invalid. @n + * The valid range of the time can be from "January 1 1900 00:00:00" to "December 31 2100 23:59:59". + * @see GetCreationTime() + */ + result SetCreationTime(const Tizen::Base::DateTime& dateTime); + + /** + * Sets the recipient list of the specified recipient type. + * + * @since 2.0 + * + * @return An error code + * @param[in] type The recipient type @n + * The value contains @c RECIPIENT_TYPE_TO, @c RECIPIENT_TYPE_CC or @c RECIPIENT_TYPE_BCC. + * @param[in] recipients The recipients string @n + * The values for the various recipients can be a string with multiple email addresses separated by semi-colons(;). + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c type is invalid. + * - The specified @c recipients string length is too short (< 5). + * @see GetAddress() + */ + result SetAddress(RecipientType type, const Tizen::Base::String& recipients); + + /** + * Sets the email address of an author. + * + * @since 2.0 + * + * @return An error code + * @param[in] address The email address of the author + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c address string length is too short (< 5). + * @see GetFromAddress() + */ + result SetFromAddress(const Tizen::Base::String& address); + + /** + * Sets the email address used to reply to a message. + * + * @since 2.0 + * + * @return An error code + * @param[in] address The email address used to reply to the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c address string length is too short (< 5). + * @see GetReplyToAddress() + */ + result SetReplyToAddress(const Tizen::Base::String& address); + + /** + * Sets the return path. + * + * @since 2.0 + * + * @return An error code + * @param[in] address The return path + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c address string length is too short (< 5). + * @see GetReturnPath() + * + */ + result SetReturnPath(const Tizen::Base::String& address); + + /** + * Sets the file path of the specified message body type. + * + * @since 2.0 + * + * @return An error code + * @param[in] type The message body type + * @param[in] filePath The file path of the message body + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c type is invalid. + * - The length of the specified @c filePath is either too long or @c 0. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @see GetFilePath() + * + */ + result SetFilePath(EmailMessageBodyType type, const Tizen::Base::String& filePath); + + /** + * Sets the priority of a message. + * + * @since 2.0 + * + * @return An error code + * @param[in] priority The priority of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c priority is invalid. + * @see GetPriority() + */ + result SetPriority(EmailMessagePriority priority); + + /** + * Sets the return receipt type of a message. + * + * @since 2.0 + * + * @return An error code + * @param[in] type The return receipt type of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @see GetReturnReceiptType() + */ + result SetReturnReceiptType(EmailReturnReceiptType type); + + /** + * Sets the inline content count of a message. + * + * @since 2.0 + * + * @return An error code + * @param[in] count The inline content count of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c count is less than @c 0. + * @see GetInlineContentCount() + */ + result SetInlineContentCount(int count); + + /** + * Sets the class of a message. + * + * @since 2.0 + * + * @return An error code + * @param[in] messageClass The class of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c messageClass is invalid. + * @see GetClass() + */ + result SetClass(EmailMessageClass messageClass); + + /** + * Sets the digest type of a message. + * + * @since 2.0 + * + * @return An error code + * @param[in] type The digest type of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @see GetDigestType() + */ + result SetDigestType(EmailDigestType type); + + /** + * Sets the S/MIME type of a message. + * + * @since 2.0 + * + * @return An error code + * @param[in] type The S/MIME type of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @see GetSmimeType() + */ + result SetSmimeType(EmailSmimeType type); + + /** + * Sets the attachment list for this message. + * + * @since 2.0 + * + * @return An error code + * @param[in] pList The list of EmailAttachment + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The list is not made of EmailAttachment. + * @see GetAttachmentListN() + */ + result SetAttachmentList(const Tizen::Base::Collection::IList* pList); + + + /////////////////////////////////////////////////////////////// + // static methods + /////////////////////////////////////////////////////////////// + /** + * Parses the MIME file to %DetailedEmailMessage format. + * + * @since 2.0 + * + * @return An error code + * @param[in] filePath The MIME file path to parse + * @param[out] message The parsed message + * @exception E_SUCCESS The method is successful. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @exception E_PARSING_FAILED The method has failed to parse the MIME file. + * @exception E_SYSTEM A system error has occurred. + * @see WriteToMimeFile() + */ + static result ParseMimeFile(const Tizen::Base::String& filePath, DetailedEmailMessage& message); + + /** + * Writes to the MIME file from %DetailedEmailMessage. + * + * @since 2.0 + * + * @return An error code + * @param[in] message The message to read + * @param[in] filePath The file path of the MIME file to write + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The value of the specified @c message is invalid. @n + * (The subject, body, recipients and from address field of the message are all empty.) + * @exception E_ILLEGAL_ACCESS The specified @c filePath is inaccessible as per the Tizen platform policy. + * @exception E_FILE_ALREADY_EXIST The specified file already exists. + * @exception E_SYSTEM A system error has occurred. + * @see ParseMimeFile() + */ + static result WriteToMimeFile(const DetailedEmailMessage& message, const Tizen::Base::String& filePath); + + private: + _DetailedEmailMessageImpl* __pImpl; + + // friend class + friend class _DetailedEmailMessageImpl; + }; // DetailedEmailMessage +} } // Tizen::Messaging + +#endif // _FMSG_DETAILED_EMAIL_MESSAGE_H_ diff --git a/inc/FMsgEmailAttachment.h b/inc/FMsgEmailAttachment.h new file mode 100644 index 0000000..c18ebdb --- /dev/null +++ b/inc/FMsgEmailAttachment.h @@ -0,0 +1,250 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgEmailAttachment.h + * @brief This is the header file for the %EmailAttachment class. + * + * This header file contains the declarations of the %EmailAttachment class. + */ + +#ifndef _FMSG_EMAIL_ATTACHMENT_H_ +#define _FMSG_EMAIL_ATTACHMENT_H_ + +namespace Tizen { namespace Base +{ +class String; +} } + +#include +#include + +namespace Tizen { namespace Messaging +{ + // forward declaration + class _EmailAttachmentImpl; + + /** + * @class EmailAttachment + * @brief This class provides methods for handling email attachments. + * + * @since 2.0 + * + * The %EmailAttachment class provides methods for handling email attachments. + */ + class _OSP_EXPORT_ EmailAttachment + : public Tizen::Base::Object + { + // Life cycle + public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + EmailAttachment(void); + + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~EmailAttachment(void); + + /** + * This is the copy constructor for the %EmailAttachment class. @n + * Copying of objects using this copy constructor is allowed. + * + * @since 2.0 + * + * @param[in] rhs An instance of %EmailAttachment to copy + */ + EmailAttachment(const EmailAttachment& rhs); + + public: + /** + * Assigns the value of the specified instance to the current instance of %EmailAttachment. @n + * Copying of objects using this copy assignment operator is allowed. + * + * @since 2.0 + * + * @return A reference of this instance + * @param[in] rhs An instance of %EmailAttachment to copy + */ + EmailAttachment& operator =(const EmailAttachment& rhs); + + /** + * Compares the specified instance with the current instance. + * + * @since 2.0 + * + * @return @c true if the specified instance of Tizen::Base::Object is equal to the current %EmailAttachment instance, @n + * else @c false + * @param[in] obj An instance of Tizen::Base::Object to compare + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + // Operation + public: + /////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////// + /** + * Gets the name of an email attachment. + * + * @since 2.0 + * + * @return The name of the email attachment + * @see SetName() + */ + Tizen::Base::String GetName(void) const; + + /** + * Gets the file path of an email attachment. + * + * @since 2.0 + * + * @return The file path of the email attachment + * @see SetFilePath() + */ + Tizen::Base::String GetFilePath(void) const; + + /** + * Gets the size of an email attachment. + * + * @since 2.0 + * + * @return The size of the email attachment + */ + int GetSize(void) const; + + /** + * Gets the inline-content status of an email attachment. + * + * @since 2.0 + * + * @return @c true if the email attachment has inline-content(s), @n + * else @c false + * @see SetInlineContentStatus() + */ + bool GetInlineContentStatus(void) const; + + /** + * Gets the DRM status of an email attachment. + * + * @since 2.0 + * + * @return @c true if the email attachment contains DRM, @n + * else @c false + * @see SetDrmStatus() + */ + bool GetDrmStatus(void) const; + + /** + * Gets the MIME type of an email attachment. + * + * @since 2.0 + * + * @return The MIME type of the email attachment + * @see SetMimeType() + */ + Tizen::Base::String GetMimeType(void) const; + + + public: + /////////////////////////////////////////////////////////////// + // Setters + /////////////////////////////////////////////////////////////// + /** + * Sets the name of an email attachment. + * + * @since 2.0 + * + * @return An error code + * @param[in] name The name of the email attachment + * @exception E_SUCCESS The method is successful. + * @exception E_MAX_EXCEEDED The length of the name exceeds the maximum limit (Maximum 256 characters). + * @see GetName() + */ + result SetName(const Tizen::Base::String& name); + + /** + * Sets the file path of an email attachment. + * + * @since 2.0 + * + * @return An error code + * @param[in] filePath The file path of the email attachment + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The length of the specified @c filePath is either too long or @c 0. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @see GetFilePath() + */ + result SetFilePath(const Tizen::Base::String& filePath); + + /** + * Sets the inline-content status of an email attachment. + * + * @since 2.0 + * + * @param[in] status Set to @c true to change the inline-content status of the attachment to true, @n + * else @c false + * @see GetInlineContentStatus() + */ + void SetInlineContentStatus(bool status); + + /** + * Sets the DRM status of an email attachment. + * + * @since 2.0 + * + * @param[in] status Set to @c true to change the DRM status of the attachment to true, @n + * else @c false + * @see GetDrmStatus() + */ + void SetDrmStatus(bool status); + + /** + * Sets the MIME type of an email attachment. + * + * @since 2.0 + * + * @return An error code + * @param[in] type The MIME type of the email attachment + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The length of the specified @c type is @c 0. + * @see GetMimeType() + */ + result SetMimeType(const Tizen::Base::String& type); + + private: + _EmailAttachmentImpl* __pImpl; + + // friend class + friend class _EmailAttachmentImpl; + }; // EmailAttachment +} } // Tizen::Messaging + +#endif // _FMSG_EMAIL_ATTACHMENT_H_ diff --git a/inc/FMsgEmailManager.h b/inc/FMsgEmailManager.h new file mode 100755 index 0000000..abaa070 --- /dev/null +++ b/inc/FMsgEmailManager.h @@ -0,0 +1,182 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgEmailManager.h + * @brief This is the header file for the %EmailManager class. + * + * This header file contains the declarations of the %EmailManager class. + */ + +#ifndef _FMSG_EMAIL_MANAGER_H_ +#define _FMSG_EMAIL_MANAGER_H_ + +#include +#include +#include +#include + +namespace Tizen { namespace Messaging +{ + // forward declaration for class extension + class _EmailManagerImpl; + + /** + * @class EmailManager + * @brief This class provides methods to use the email messaging service. + * + * @since 2.0 + * + * The %EmailManager class is used to send email messages. + * + * For more information on the class features, see Messaging Guide. + * + * The following example demonstrates how to use the %EmailManager class. + * + * @code + * + // Creates a listener to override the OnEmailMessageSent() method of IEmailListener + // in order to be notified of a change in the state of the message being sent. + + class EmailListener + : public IEmailListener + , public Object + { + public: + void OnEmailMessageSent(result r); + }; + + void + EmailListener::OnEmailMessageSent(result r) + { + // Do something + } + + class SendEmailMessage + : public Object + { + public: + void EmailTest(void); + }; + + void + SendEmailMessage::EmailTest(void) + { + result r = E_SUCCESS; + + // Creates an EmailListener instance. + EmailListener* pListener = new EmailListener(); + + // Creates an %EmailManager instance with the listener as the callback to check the status of the message being sent. + EmailManager* pEmailManager = new EmailManager(); + r = pEmailManager->Construct(*pListener); + + // Creates a recipient list instance and adds recipients. + RecipientList recipient; + r = recipient.Add (RECIPIENT_TYPE_TO, L"test10@tizen.org"); + r = recipient.Add (RECIPIENT_TYPE_CC, L"test09@tizen.org"); + r = recipient.Add (RECIPIENT_TYPE_BCC, L"test08@tizen.org"); + + // Creates a email message instance. + EmailMessage emailMessage; + r = emailMessage.SetSubject(L"Subject!!!"); + r = emailMessage.SetText(L"Hello, World"); + r = emailMessage.AddAttachment(L"/opt/usr/media/testfile.dat"); + + // Sends the message, and sets the @c saveToSentbox parameter to true if the message should be saved in the Sentbox; otherwise, set to false. + // EmailListener callback is called once the message is completely sent. + r = pEmailManager->Send(emailMessage, recipient, true); + } + * + * @endcode + */ + class _OSP_EXPORT_ EmailManager + : public Tizen::Base::Object + { + // Life cycle + public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + EmailManager(void); + + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~EmailManager(void); + + private: + EmailManager(const EmailManager& value); + EmailManager& operator =(const EmailManager& rhs); + + // Operation + public: + /** + * Initializes this instance of %EmailManager with the specified parameter. + * + * @since 2.0 + * + * @return An error code + * @param[in] listener The listener to receive the sent result asynchronously + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + */ + result Construct(IEmailListener& listener); + + /** + * Sends the email message. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.write @n + * (%http://tizen.org/privilege/messaging.email is deprecated.) + * + * @return An error code + * @param[in] message The message to send + * @param[in] recipientList The list of recipients + * @param[in] saveToSentbox Set to @c true to save the message in the Sentbox, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM The method cannot proceed due to a severe system error. + * @exception E_ON_INITIALIZING The mailbox is not completely loaded as yet. + * @exception E_STORAGE_FULL The storage is full. + * @exception E_DEVICE_UNAVAILABLE The device is unavailable. + * @exception E_NETWORK_UNAVAILABLE The network is unavailable. + * @exception E_INVALID_ACCOUNT The email account is not set. + * @exception E_INVALID_CONDITION The profile is not set. + * @exception E_INVALID_ADDRESS The address is invalid. + * @exception E_FDN_MODE The FDN mode has been activated. + * @exception E_INVALID_ARG The number of recipients is @c 0. + * @exception E_MAX_EXCEEDED The number of recipients has crossed the maximum limit (Maximum 20). + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @see IEmailListener::OnEmailMessageSent() + */ + result Send(const EmailMessage& message, const RecipientList& recipientList, bool saveToSentbox); + + private: + _EmailManagerImpl* __pImpl; + + // friend class + friend class _EmailManagerImpl; + }; // EmailManager +} } // Tizen::Messaging + +#endif // _FMSG_EMAIL_MANAGER_H_ diff --git a/inc/FMsgEmailMessage.h b/inc/FMsgEmailMessage.h new file mode 100755 index 0000000..a8c2a40 --- /dev/null +++ b/inc/FMsgEmailMessage.h @@ -0,0 +1,227 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgEmailMessage.h + * @brief This is the header file for the %EmailMessage class. + * + * This header file contains the declarations of the %EmailMessage class. + */ + +#ifndef _FMSG_EMAIL_MESSAGE_H_ +#define _FMSG_EMAIL_MESSAGE_H_ + +#include + +namespace Tizen { namespace Messaging +{ + class _EmailMessageImpl; + + /** + * @class EmailMessage + * @brief This class provides methods for handling email messages. + * + * @since 2.0 + * + * The %EmailMessage class provides methods for handling email messages. + * It allows the user to set the subject and body text of an email message, + * and add or remove the files sent as email attachments. + * + * For more information on the class features, see Messaging Guide. + */ + class _OSP_EXPORT_ EmailMessage + : public Tizen::Base::Object + { + // Life cycle + public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + EmailMessage(void); + + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~EmailMessage(void); + + /** + * This is the copy constructor for the %EmailMessage class. + * + * @since 2.0 + * + * @param[in] value An instance of %EmailMessage to copy + */ + EmailMessage(const EmailMessage& value); + + + public: + /** + * This assignment operator copies an email message from the specified instance of %EmailMessage to the current instance of %EmailMessage. + * + * @since 2.0 + * + * @return A reference of this instance + * @param[in] rhs A reference to the %EmailMessage instance to copy + */ + EmailMessage& operator =(const EmailMessage& rhs); + + /** + * Compares the specified instance with the current instance. + * + * @since 2.0 + * + * @return @c true if the specified instance of Tizen::Base::Object is equal to the current %EmailMessage instance, @n + * else @c false + * @param[in] obj The object to compare + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + // Operation + public: + /** + * Sets the subject of an email. + * + * @since 2.0 + * + * @return An error code + * @param[in] subject The subject of the message + * @exception E_SUCCESS The method is successful. + * @exception E_MAX_EXCEEDED Either of the following conditions has occurred: + * - The subject length of the message exceeds the maximum limit (Maximum 256 characters). + * - The total size of the subject, body, and attachment(s) exceeds the maximum limit (5MB). + * @see GetSubject() + */ + result SetSubject(const Tizen::Base::String& subject); + + /** + * Sets the body of a message. + * + * @since 2.0 + * + * @return An error code + * @param[in] text The body of the message + * @exception E_SUCCESS The method is successful. + * @exception E_MAX_EXCEEDED Either of the following conditions has occurred: + * - The body length of the message exceeds the maximum limit (Maximum 2000 characters). + * - The total size of the subject, body, and attachment(s) exceeds the maximum limit (5MB). + * @see GetText() + */ + result SetText(const Tizen::Base::String& text); + + /** + * Adds a file attachment to an email. + * + * @if OSPCOMPAT + * @brief [Compatibility] + * @endif + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return An error code + * @param[in] filePath The path of the file to attach + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The length of the specified @c filePath is either too long or @c 0. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @exception E_FILE_ALREADY_EXIST The file is already attached. + * @exception E_MAX_EXCEEDED Either of the following conditions has occurred: + * - The total size of the subject, body, and attachment(s) exceeds the maximum limit (5MB). @n + * The total size of the attachments must not exceed 5MB. + * - The total number of attachments exceeds the maximum limit (20 files). @n + * The total number of attached files must not exceed 20 files. + * @see GetAttachmentListN() + */ + result AddAttachment(const Tizen::Base::String& filePath); + + + /** + * Removes an attachment from an email. + * + * @if OSPCOMPAT + * @brief [Compatibility] + * @endif + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return An error code + * @param[in] filePath The path of the file to remove + * @exception E_SUCCESS The method is successful. + * @exception E_FILE_NOT_FOUND The file with the corresponding format is not found. + * @see AddAttachment() + * @see GetAttachmentListN() + */ + result RemoveAttachment(const Tizen::Base::String& filePath); + + /** + * Gets the subject of a message. + * + * @since 2.0 + * + * @return The subject of the message + * @see SetSubject() + */ + Tizen::Base::String GetSubject(void) const; + + /** + * Gets the body of a message. + * + * @since 2.0 + * + * @return The body of the message + * @see SetText() + */ + Tizen::Base::String GetText(void) const; + + /** + * Gets the list of attachments for an email. + * + * @since 2.0 + * + * @return The list of attached files + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see AddAttachment() + */ + Tizen::Base::Collection::IList* GetAttachmentListN(void) const; + + private: + _EmailMessageImpl* __pImpl; + + // friend class + friend class _EmailMessageImpl; + }; // EmailMessage +} } // Tizen::Messaging + +#endif // _FMSG_EMAIL_MESSAGE_H_ diff --git a/inc/FMsgEtwsPrimaryNotification.h b/inc/FMsgEtwsPrimaryNotification.h new file mode 100755 index 0000000..9a5c169 --- /dev/null +++ b/inc/FMsgEtwsPrimaryNotification.h @@ -0,0 +1,188 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgEtwsPrimaryNotification.h + * @brief This is the header file for the %EtwsPrimaryNotification class. + * + * This header file contains the declarations of the %EtwsPrimaryNotification class. + */ + +#ifndef _FMSG_ETWS_PRIMARY_NOTIFICATION_H_ +#define _FMSG_ETWS_PRIMARY_NOTIFICATION_H_ + +namespace Tizen { namespace Base +{ +class DateTime; +class ByteBuffer; +} } + +#include +#include + +namespace Tizen { namespace Messaging +{ + +class _EtwsPrimaryNotificationImpl; + +/** + * @class EtwsPrimaryNotification + * + * @brief This class provides methods for handling an ETWS primary notification. + * + * @since 2.0 + * + * @final This class is not intended for extension. + * + * The %EtwsPrimaryNotification class provides methods for handling an ETWS primary notification. It allows the user to get the serial number, + * message ID, warning type, warning security info, and received time of an ETWS primary notification. + */ +class _OSP_EXPORT_ EtwsPrimaryNotification + : public Tizen::Base::Object +{ +public: + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~EtwsPrimaryNotification(void); + + /** + * Compares the specified instance of %EtwsPrimaryNotification with the current instance. + * + * @since 2.0 + * + * @return @c true if the values match, @n + * else @c false + * @param[in] obj The other Tizen::Base::Object to compare + * @see Tizen::Base::Object::Equals() + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the copied instance of this class. + * + * @since 2.0 + * + * @return An instance of %EtwsPrimaryNotification, @n + * else @c null in case of an error + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + EtwsPrimaryNotification* CloneN(void) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + /** + * Gets the date and time (UTC time) of a message when it is received. + * + * @since 2.0 + * + * @return The date and time (UTC time) when the message is received + */ + Tizen::Base::DateTime GetReceivedTime(void) const; + + /** + * Gets the serial number of an ETWS primary notification. + * + * @since 2.0 + * + * @return The serial number of the ETWS primary notification, @n + * else @c null in case of an error + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* GetSerialNumberN(void) const; + + /** + * Gets the message ID of an ETWS primary notification. + * + * @since 2.0 + * + * @return The message ID of the ETWS primary notification + */ + int GetMessageId(void) const; + + /** + * Gets the warning type of a message. + * + * @since 2.0 + * + * @return The ETWS warning type of the message + */ + Tizen::Base::ByteBuffer* GetWarningTypeN(void) const; + + /** + * Gets the warning security information of an ETWS primary notification. + * + * @since 2.0 + * + * @return The warning security information of the ETWS primary notification, @n + * else @c null in case of an error + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* GetWarningSecurityInfoN(void) const; + +private: + /** + * This default constructor is intentionally declared as private so that only the platform can create an instance. + * + * @since 2.0 + */ + EtwsPrimaryNotification(void); + + /** + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @since 2.0 + * + * @param[in] rhs An instance of EtwsPrimaryNotification + */ + EtwsPrimaryNotification(const EtwsPrimaryNotification& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. @n + * - Use CloneN() to get an exact copy of the instance. + * - Use Equals() to compare the contents of one instance with the other. + * + * @since 2.0 + * + * @return A reference to this instance + * @param[in] rhs An instance of EtwsPrimaryNotification + */ + EtwsPrimaryNotification& operator =(const EtwsPrimaryNotification& rhs); + +private: + _EtwsPrimaryNotificationImpl* __pEtwsPrimaryNotificationImpl; + + friend class _EtwsPrimaryNotificationImpl; +}; // EtwsPrimaryNotification + +} } // Tizen::Messaging +#endif // _FMSG_ETWS_PRIMARY_NOTIFICATION_H_ diff --git a/inc/FMsgICbsMessageEventListener.h b/inc/FMsgICbsMessageEventListener.h new file mode 100755 index 0000000..25ad3fb --- /dev/null +++ b/inc/FMsgICbsMessageEventListener.h @@ -0,0 +1,81 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgICbsMessageEventListener.h + * @brief This is the header file for the %ICbsMessageEventListener interface. + * + * This header file contains the declarations of the %ICbsMessageEventListener interface. + */ + +#ifndef _FMSG_ICBS_MESSAGE_EVENT_LISTENER_H_ +#define _FMSG_ICBS_MESSAGE_EVENT_LISTENER_H_ + +namespace Tizen { namespace Messaging +{ + class CbsMessage; + + /** + * @interface ICbsMessageEventListener + * @brief This interface is the listener interface for receiving CBS messages. + * + * @since 2.0 + * + * The %ICbsMessageEventListener interface must be implemented to handle incoming CBS messages. An application must register this interface using the %SmsManager::SetCbsMessageEventListener() method. + */ + class _OSP_EXPORT_ ICbsMessageEventListener + : virtual public Tizen::Base::Runtime::IEventListener + { + public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * @since 2.0 + */ + virtual ~ICbsMessageEventListener(void) {} + + /** + * Called when a CBS message is received. + * + * @since 2.0 + * + * @param[in] message The message that is received + * @see SmsManager::SetCbsMessageEventListener() + */ + virtual void OnCbsMessageReceived(const CbsMessage& message) = 0; + + protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void ICbsMessageEventListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void ICbsMessageEventListener_Reserved2(void) {} + }; // ICbsMessageEventListener +} } // Tizen::Messaging +#endif // _FMSG_ICBS_MESSAGE_EVENT_LISTENER_H_ diff --git a/inc/FMsgIEmailListener.h b/inc/FMsgIEmailListener.h new file mode 100755 index 0000000..b4dab4d --- /dev/null +++ b/inc/FMsgIEmailListener.h @@ -0,0 +1,91 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgIEmailListener.h + * @brief This is the header file for the %IEmailListener interface. + * + * This header file contains the declarations of the %IEmailListener interface. + */ + +#ifndef _FMSG_IEMAIL_EVENT_LISTENER_H_ +#define _FMSG_IEMAIL_EVENT_LISTENER_H_ + +// Includes +#include +#include + +namespace Tizen { namespace Messaging +{ + + /** + * @interface IEmailListener + * @brief This interface is the listener interface for receiving the status of a sent email. + * + * @since 2.0 + * + * The %IEmailListener interface must be implemented to receive the status of sent email messages asynchronously. An application must register this interface using the %EmailManager::Construct() method. + * + * For more information on the class features, see Messaging Guide. + */ + class _OSP_EXPORT_ IEmailListener + : virtual public Tizen::Base::Runtime::IEventListener + { + // Lifecycle + public: + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~IEmailListener(void) {} + + // Operation + public: + /** + * Called when an email message is sent. + * + * @since 2.0 + * + * @param[in] r The result of sending the email message + * @exception E_SUCCESS The method is successful. + * @exception E_FAILURE The method has failed to send the message. + * @see EmailManager::Send() + */ + virtual void OnEmailMessageSent(result r) = 0; + + protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IEmailListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IEmailListener_Reserved2(void) {} + }; // IEmailListener +} } // Tizen::Messaging + +#endif // _FMSG_IEMAIL_EVENT_LISTENER_H_ diff --git a/inc/FMsgIEtwsPrimaryNotificationEventListener.h b/inc/FMsgIEtwsPrimaryNotificationEventListener.h new file mode 100755 index 0000000..758cc1e --- /dev/null +++ b/inc/FMsgIEtwsPrimaryNotificationEventListener.h @@ -0,0 +1,85 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgIEtwsPrimaryNotificationEventListener.h + * @brief This is the header file for the %IEtwsPrimaryNotificationEventListener interface. + * + * This header file contains the declarations of the %IEtwsPrimaryNotificationEventListener interface. + */ + +#ifndef _FMSG_IETWS_PRIMARY_NOTIFICATION_EVENT_LISTENER_H_ +#define _FMSG_IETWS_PRIMARY_NOTIFICATION_EVENT_LISTENER_H_ + +#include + +namespace Tizen { namespace Messaging +{ + class EtwsPrimaryNotification; + + /** + * @interface IEtwsPrimaryNotificationEventListener + * @brief This interface is the listener interface for receiving an ETWS primary notification. + * + * @since 2.0 + * + * The %IEtwsPrimaryNotificationEventListener interface must be implemented to handle an incoming ETWS primary notification. @n + * An application must register this interface using the SmsManager::SetEtwsPrimaryNotificationEventListener() method. + */ + class _OSP_EXPORT_ IEtwsPrimaryNotificationEventListener + : virtual public Tizen::Messaging::ICbsMessageEventListener + { + public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * + * @since 2.0 + */ + virtual ~IEtwsPrimaryNotificationEventListener(void) {} + + /** + * Called when an ETWS primary notification is received. + * + * @since 2.0 + * + * @param[in] message The ETWS primary notification that is received + * @see SmsManager::SetEtwsPrimaryNotificationEventListener() + */ + virtual void OnEtwsPrimaryNotificationReceived(const EtwsPrimaryNotification& message) = 0; + + protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IEtwsPrimaryNotificationEventListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IEtwsPrimaryNotificationEventListener_Reserved2(void) {} + }; // IEtwsPrimaryNotificationEventListener +} } // Tizen::Messaging +#endif // _FMSG_IETWS_PRIMARY_NOTIFICATION_EVENT_LISTENER_H_ diff --git a/inc/FMsgIMmsListener.h b/inc/FMsgIMmsListener.h new file mode 100755 index 0000000..4890880 --- /dev/null +++ b/inc/FMsgIMmsListener.h @@ -0,0 +1,96 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgIMmsListener.h + * @brief This is the header file for the %IMmsListener interface. + * + * This header file contains the declarations of the %IMmsListener interface. + */ + +#ifndef _FMSG_IMMS_LISTENER_H_ +#define _FMSG_IMMS_LISTENER_H_ + +// Includes +#include +#include + +namespace Tizen { namespace Messaging +{ + + + /** + * @interface IMmsListener + * @brief This interface is the listener interface for receiving the status of a sent MMS. + * + * @since 2.0 + * + * The %IMmsListener interface must be implemented to receive the status of sent MMS messages asynchronously. An application must register this interface using the %MmsManager::Construct() method. + * + * For more information on the class features, see Messaging Guide. + */ + class _OSP_EXPORT_ IMmsListener + : virtual public Tizen::Base::Runtime::IEventListener + { + // Lifecycle + public: + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~IMmsListener(void) {} + + // Operation + public: + /** + * Called when a Multimedia Messaging Service(MMS) message is sent. + * + * @since 2.0 + * + * @param[in] r The result of sending the MMS message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_CONTENT The content is invalid. + * @exception E_NETWORK_UNAVAILABLE The network has a problem. + * @exception E_SERVICE_UNAVAILABLE The service is unavailable. + * @exception E_INVALID_ADDRESS The address is invalid. + * @exception E_FAILURE The method has failed to send the message. + * @see MmsManager::Send() + */ + virtual void OnMmsMessageSent(result r) = 0; + + protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IMmsListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IMmsListener_Reserved2(void) {} + }; // IMmsListener +} } // Tizen::Messaging + +#endif // _FMSG_IMMS_LISTENER_H_ diff --git a/inc/FMsgIPushEventListener.h b/inc/FMsgIPushEventListener.h new file mode 100755 index 0000000..9918720 --- /dev/null +++ b/inc/FMsgIPushEventListener.h @@ -0,0 +1,84 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgIPushEventListener.h + * @brief This is the header file for the %IPushEventListener interface. + * + * This header file contains the declaration of the %IPushEventListener interface. + */ + +#ifndef _FMSG_IPUSH_EVENT_LISTENER_H_ +#define _FMSG_IPUSH_EVENT_LISTENER_H_ + +#include +#include + +namespace Tizen { namespace Messaging +{ +/** + * @interface IPushEventListener + * @brief This interface is the listener interface for receiving push messages. + * + * @since 2.0 + * + * The %IPushEventListener interface must be implemented to receive push messages. @n + * An application must register this interface using the PushManager::Construct() method. + */ +class _OSP_EXPORT_ IPushEventListener + : virtual public Tizen::Base::Runtime::IEventListener +{ +public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * @since 2.0 + */ + virtual ~IPushEventListener(void) {} + +public: + /** + * Called when a push message is received from the server. + * + * @since 2.0 + * + * @param[in] message The push message that is received + */ + virtual void OnPushMessageReceived(const PushMessage& message) = 0; + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IPushEventListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IPushEventListener_Reserved2(void) {} +}; // IPushEventListener + +} } // Tizen::Messaging +#endif // _FMSG_IPUSH_EVENT_LISTENER_H_ diff --git a/inc/FMsgIPushManagerListener.h b/inc/FMsgIPushManagerListener.h new file mode 100755 index 0000000..e2a1594 --- /dev/null +++ b/inc/FMsgIPushManagerListener.h @@ -0,0 +1,137 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgIPushManagerListener.h + * @brief This is the header file for the %IPushManagerListener interface. + * + * This header file contains the declarations of the %IPushManagerListener interface. + */ + +#ifndef _FMSG_IPUSH_MANAGER_LISTENER_H_ +#define _FMSG_IPUSH_MANAGER_LISTENER_H_ + +#include + +namespace Tizen { namespace Messaging +{ +/** + * @interface IPushManagerListener + * @brief This interface is the listener interface that receives a registration result. + * + * @since 2.0 + * + * The %IPushManagerListener interface must be implemented to receive the results of a push event registration. @n + * An application must register this interface using the PushManager::Construct() method. + */ +class _OSP_EXPORT_ IPushManagerListener + : virtual public Tizen::Base::Runtime::IEventListener +{ +public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * @since 2.0 + */ + virtual ~IPushManagerListener(void) {} + +public: + /** + * Called when the result is received from PushManager::RegisterPushService(). + * + * @since 2.0 + * + * @param[in] reqId The request ID + * @param[in] registrationId The registration ID of the device @n + * The application must deliver this ID to the application server. + * @param[in] r The result of the request + * @param[in] errorCode The error code from the server + * @param[in] errorMsg The error message from the server + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM An unknown operating system error has occurred. + * @exception E_CONNECTION_FAILED The network connection has failed. + * @exception E_SERVER An error has occurred on the server side. + * @exception E_SERVICE_UNAVAILABLE The service is unavailable. @n + * Check whether the push service registration is completed. @n + * For more information, see Push Messaging Guide. + * @see PushManager::RegisterPushService() + */ + virtual void OnPushServiceRegistered(RequestId reqId, const Tizen::Base::String& registrationId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg) = 0; + + /** + * Called when the result is received from PushManager::UnregisterPushService(). + * + * @since 2.0 + * + * @param[in] reqId The request ID + * @param[in] r The result of the request + * @param[in] errorCode The error code from the server + * @param[in] errorMsg The error message from the server + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM An unknown operating system error has occurred. + * @exception E_CONNECTION_FAILED The network connection has failed. + * @exception E_SERVER An error has occurred on the server side. + * @see PushManager::UnregisterPushService() + */ + virtual void OnPushServiceUnregistered(RequestId reqId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg) = 0; + + /** + * Called when the result is received from PushManager::SendPushMessage(). + * + * @since 2.0 + * + * @param[in] reqId The request ID + * @param[in] registrationId The registration ID of the recipient + * @param[in] r The result of the request, @n + * The following exceptions may be given through this parameter. + * @param[in] errorCode The error code from the server + * @param[in] errorMsg The error message from the server + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_DATA Invalid data is received from the server. + * @exception E_CONNECTION_FAILED The network connection has failed. + * @exception E_REMOTE_DEVICE_NOT_FOUND The registration ID is invalid, so the recipient is not found. + * @exception E_AUTHENTICATION The appSecret is invalid, so the application authentication has failed. + * @exception E_SERVER An error has occurred on the server side. + * @exception E_SERVICE_UNAVAILABLE The service is unavailable. @n + * Check whether the push service registration is completed. @n + * For more information, see Push Messaging Guide. + * @see PushManager::SendPushMessage() + */ + virtual void OnPushMessageSent(RequestId reqId, const Tizen::Base::String& registrationId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg) {} + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IPushManagerListener_Reserved2(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IPushManagerListener_Reserved3(void) {} +}; // IPushManagerListener + +} } // Tizen::Messaging +#endif // _FMSG_IPUSH_MANAGER_LISTENER_H_ diff --git a/inc/FMsgISmsEventListener.h b/inc/FMsgISmsEventListener.h new file mode 100755 index 0000000..0f207f9 --- /dev/null +++ b/inc/FMsgISmsEventListener.h @@ -0,0 +1,94 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgISmsEventListener.h + * @brief This is the header file for the %ISmsEventListener interface. + * + * This header file contains the declarations of the %ISmsEventListener interface. + */ + +#ifndef _FMSG_ISMS_EVENT_LISTENER_H_ +#define _FMSG_ISMS_EVENT_LISTENER_H_ + +#include + +namespace Tizen { namespace Messaging +{ + + class SmsMessage; + + + /** + * @interface ISmsEventListener + * @brief This interface is the listener interface for receiving SMS messages. + * + * @since 2.0 + * + * The %ISmsEventListener interface is the listener interface for receiving SMS messages via a specific port. @n + * An application implements this interface and registers it using the SmsManager::AddSmsEventListener() method to receive SMS messages. + * + * For more information on the class features, see Messaging Guide. + */ + class _OSP_EXPORT_ ISmsEventListener + : virtual public Tizen::Base::Runtime::IEventListener + { + // Lifecycle + public: + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~ISmsEventListener(void) {} + + // Operations + public: + /** + * Called when an SMS message is received. + * + * @since 2.0 + * + * @param[in] port The port number + * @param[in] dateTime The date and time when the message is received + * @param[in] message The message that is received + * @see SmsManager::AddSmsEventListener() + * @see SmsManager::RemoveSmsEventListener() + */ + virtual void OnSmsMessageReceived(int port, const Tizen::Base::DateTime& dateTime, const SmsMessage& message) = 0; + + protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void ISmsEventListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void ISmsEventListener_Reserved2(void) {} + }; // ISmsEventListener + +} } // Tizen::Messaging +#endif // _FMSG_ISMS_EVENT_LISTENER_H_ diff --git a/inc/FMsgISmsListener.h b/inc/FMsgISmsListener.h new file mode 100755 index 0000000..cad2ccb --- /dev/null +++ b/inc/FMsgISmsListener.h @@ -0,0 +1,90 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgISmsListener.h + * @brief This is the header file for the %ISmsListener interface. + * + * This header file contains the declarations of the %ISmsListener interface. + */ + +#ifndef _FMSG_ISMS_LISTENER_H_ +#define _FMSG_ISMS_LISTENER_H_ + +// Includes +#include +#include + +namespace Tizen { namespace Messaging +{ + /** + * @interface ISmsListener + * @brief This interface is the listener interface for receiving the status of a sent SMS. + * + * @since 2.0 + * + * The %ISmsListener interface must be implemented and registered using the SmsManager::Construct() method to receive the status of sent SMS messages asynchronously. + * + * For more information on the class features, see Messaging Guide. + */ + class _OSP_EXPORT_ ISmsListener + : virtual public Tizen::Base::Runtime::IEventListener + { + // Lifecycle + public: + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~ISmsListener(void) {} + + // Operation + public: + /** + * Called when an SMS message is sent. + * + * @since 2.0 + * + * @param[in] r The result of sending the SMS message + * @exception E_SUCCESS The method is successful. + * @exception E_FAILURE The method has failed to send the message. + * @see SmsManager::Send() + */ + virtual void OnSmsMessageSent(result r) = 0; + + protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void ISmsListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void ISmsListener_Reserved2(void) {} + }; // ISmsListener + +} } // Tizen::Messaging +#endif // _FMSG_ISMS_LISTENER_H_ diff --git a/inc/FMsgISmsMessageEventListener.h b/inc/FMsgISmsMessageEventListener.h new file mode 100755 index 0000000..20d3163 --- /dev/null +++ b/inc/FMsgISmsMessageEventListener.h @@ -0,0 +1,88 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgISmsMessageEventListener.h + * @brief This is the header file for the %ISmsMessageEventListener interface. + * + * This header file contains the declarations of the %ISmsMessageEventListener interface. + */ + +#ifndef _FMSG_ISMS_MESSAGE_EVENT_LISTENER_H_ +#define _FMSG_ISMS_MESSAGE_EVENT_LISTENER_H_ + +#include + +namespace Tizen { namespace Messaging +{ + class SmsMessage; + + /** + * @interface ISmsMessageEventListener + * @brief This interface is the listener interface for receiving SMS messages. + * + * @since 2.0 + * + * The %ISmsMessageEventListener interface must be implemented and registered using the SmsManager::AddSmsMessageEventListener() method to handle incoming SMS messages. + * + * For more information on the class features, see Messaging Guide. + */ + class _OSP_EXPORT_ ISmsMessageEventListener + : virtual public Tizen::Base::Runtime::IEventListener + { + // Lifecycle + public: + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~ISmsMessageEventListener(void) {} + + // Operations + public: + /** + * Called when an SMS message is received. + * + * @since 2.0 + * + * @param[in] message The message that is received + * @see SmsManager::AddSmsMessageEventListener() + * @see SmsManager::RemoveSmsMessageEventListener() + */ + virtual void OnSmsMessageReceived(const SmsMessage& message) = 0; + + protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void ISmsMessageEventListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void ISmsMessageEventListener_Reserved2(void) {} + }; // ISmsMessageEventListener +} } // Tizen::Messaging +#endif // _FMSG_ISMS_MESSAGE_EVENT_LISTENER_H_ diff --git a/inc/FMsgIWapPushEventListener.h b/inc/FMsgIWapPushEventListener.h new file mode 100755 index 0000000..64ac77b --- /dev/null +++ b/inc/FMsgIWapPushEventListener.h @@ -0,0 +1,84 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgIWapPushEventListener.h + * @brief This is the header file for the %IWapPushEventListener interface. + * + * This header file contains the declarations of the %IWapPushEventListener interface. + */ + +#ifndef _FMSG_IWAP_PUSH_EVENT_LISTENER_H_ +#define _FMSG_IWAP_PUSH_EVENT_LISTENER_H_ + +#include +#include + +namespace Tizen { namespace Messaging +{ +/** + * @interface IWapPushEventListener + * @brief This interface is the listener interface for receiving WAP Push messages. + * + * @since 2.0 + * + * The %IWapPushEventListener interface must be implemented to receive WAP Push messages. + * An application must register this interface using the WapPushManager::AddWapPushEventListener() method. + */ +class _OSP_EXPORT_ IWapPushEventListener + : virtual public Tizen::Base::Runtime::IEventListener +{ +public: + /** + * This polymorphic destructor should be overridden if required. @n + * This way, the destructors of the derived classes are called when the destructor of this interface is called. + * + * @since 2.0 + */ + virtual ~IWapPushEventListener(void) {} + +public: + /** + * Called when a WAP Push message is received. + * + * @since 2.0 + * + * @param[in] message The WAP push message + */ + virtual void OnWapPushMessageReceived(const WapPushMessage& message) = 0; + +protected: + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IWapPushEventListener_Reserved1(void) {} + + // + // This method is for internal use only. Using this method can cause behavioral, security-related, and consistency-related issues in the application. + // + // This method is reserved and may change its name at any time without prior notice. + // + // @since 2.0 + // + virtual void IWapPushEventListener_Reserved2(void) {} +}; // IWapPushEventListener + +} } // Tizen::Messaging +#endif // _FMSG_IWAP_PUSH_EVENT_LISTENER_H_ diff --git a/inc/FMsgMmsManager.h b/inc/FMsgMmsManager.h new file mode 100755 index 0000000..38b6bed --- /dev/null +++ b/inc/FMsgMmsManager.h @@ -0,0 +1,193 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgMmsManager.h + * @brief This is the header file for the %MmsManager class. + * + * This header file contains the declarations of the %MmsManager class. + */ + + +#ifndef _FMSG_MMS_MANAGER_H_ +#define _FMSG_MMS_MANAGER_H_ + +// Includes +#include +#include +#include +#include + +namespace Tizen { namespace Messaging +{ + + // forward declaration for class extension + class _MmsManagerImpl; + + /** + * @class MmsManager + * @brief This class provides methods to use the Multimedia Messaging Service. + * + * @since 2.0 + * + * The %MmsManager class is used to send Multimedia Messaging Service. + * + * For more information on the class features, see Messaging Guide. + * + * The following example demonstrates how to use the %MmsManager class. + * + * @code + * + // Creates a listener to override the OnMmsMessageSent() method of IMmsListener + // in order to be notified of a change in the state of the message being sent. + + class MmsListener + : public IMmsListener + , public Object + { + public: + void OnMmsMessageSent(result r); + }; + void MmsListener::OnMmsMessageSent(result r) + { + // Do something. + } + + class SendMmsMessage + : public Object + { + public: + void MmsTest(void); + }; + + void + SendMmsMessage::MmsTest(void) + { + result r = E_SUCCESS; + + // Creates an MmsListener instance. + MmsListener* pListener = new MmsListener(); + + // Creates an MMS manager instance with the listener as the callback to check the status of the message being sent. + MmsManager* pMmsManager = new MmsManager(); + r = pMmsManager->Construct(*pListener); + + // Creates a recipient list instance and add recipients. + RecipientList recipient; + r = recipient.Add (RECIPIENT_TYPE_TO, L"01012345678"); + r = recipient.Add (RECIPIENT_TYPE_CC, L"01012345679"); + r = recipient.Add (RECIPIENT_TYPE_BCC, L"01012345670"); + + // Creates an MMS message instance. + MmsMessage mmsMessage; + r = mmsMessage.SetSubject(L"Subject!!!"); + r = mmsMessage.SetText(L"Hello, World"); + r = mmsMessage.AddAttachment(MMS_IMAGE, L"/opt/usr/media/image.jpg"); + r = mmsMessage.AddAttachment(MMS_AUDIO, L"/opt/usr/media/audio.wav"); + + // Sends the message, and set the saveToSentbox parameter to true if the message should be saved in the Sentbox; otherwise, set to false. + // MmsListener callback is called once the message has been completely sent. + r = pMmsManager->Send(mmsMessage, recipient, true); + } + * + * @endcode + */ + class _OSP_EXPORT_ MmsManager + : public Tizen::Base::Object + { + // Life cycle + public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + MmsManager(void); + + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~MmsManager(void); + + private: + MmsManager(const MmsManager& value); + MmsManager& operator =(const MmsManager& rhs); + + // Operation + public: + /** + * Initializes this instance of %MmsManager with the specified parameter. + * + * @since 2.0 + * + * @feature %http://tizen.org/feature/network.telephony.mms + * @return An error code + * @param[in] listener The listener to receive the sent result asynchronously + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + */ + result Construct(IMmsListener &listener); + + /** + * Sends the specified MMS message. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.write @n + * (%http://tizen.org/privilege/messaging.mms is deprecated.) + * + * @return An error code + * @param[in] message The message to send + * @param[in] recipientList The list of recipients + * @param[in] saveToSentbox Set to @c true to save the message in the Sentbox, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM The method cannot proceed due to a severe system error. + * @exception E_ON_INITIALIZING The mailbox is not completely loaded as yet. + * @exception E_STORAGE_FULL The storage is full. + * @exception E_DEVICE_UNAVAILABLE The device is unavailable. + * @exception E_NETWORK_UNAVAILABLE The network is unavailable. + * @exception E_INVALID_CONDITION The profile is not set. + * @exception E_INVALID_ADDRESS The address is invalid. + * @exception E_FDN_MODE The FDN mode has been activated. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The number of recipients is @c 0. + * - The message is empty. + * @exception E_MAX_EXCEEDED The number of recipients has crossed the maximum limit (Maximum 10). + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks + * - Some service providers may not support sending MMS messages with an empty subject or body. @n + * In this case, the result of the status report is the @c E_FAILURE exception. + * - The CC and BCC recipients in the @c recipientList are merged with the TO recipients when sending an MMS message. + * @see IMmsListener::OnMmsMessageSent() + */ + result Send(const MmsMessage& message, const RecipientList& recipientList, bool saveToSentbox); + + private: + _MmsManagerImpl* __pImpl; + + // friend class + friend class _MmsManagerImpl; + }; // MmsManager +} } // Tizen::Messaging +#endif // _FMSG_MMS_MANAGER_H_ diff --git a/inc/FMsgMmsMessage.h b/inc/FMsgMmsMessage.h new file mode 100755 index 0000000..7e94fa0 --- /dev/null +++ b/inc/FMsgMmsMessage.h @@ -0,0 +1,228 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgMmsMessage.h + * @brief This is the header file for the %MmsMessage class. + * + * This header file contains the declarations of the %MmsMessage class. + */ + +#ifndef _FMSG_MMS_MESSAGE_H_ +#define _FMSG_MMS_MESSAGE_H_ + +// Includes +#include +#include + +namespace Tizen { namespace Messaging +{ + + // forward declaration + class _MmsMessageImpl; + /** + * @class MmsMessage + * @brief This class provides methods for handling an MMS message. + * + * @since 2.0 + * + * The %MmsMessage class provides methods for handling MMS messages. It allows the user to set + * the subject and body text of an MMS message, and add or remove the files sent as MMS attachments. + * + * For more information on the class features, see Messaging Guide. + */ + class _OSP_EXPORT_ MmsMessage + : public Tizen::Base::Object + { + // Life cycle + public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + MmsMessage(void); + + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~MmsMessage(void); + + /** + * This is the copy constructor for the %MmsMessage class. + * + * @since 2.0 + * + * @param[in] value An instance of %MmsMessage to copy + */ + MmsMessage(const MmsMessage& value); + + /** + * This assignment operator copies the MMS message from the specified instance of %MmsMessage to the current instance of %MmsMessage. + * + * @since 2.0 + * + * @return A reference to the %MmsMessage instance + * @param[in] rhs A reference to the %MmsMessage instance to copy + */ + MmsMessage& operator =(const MmsMessage& rhs); + + /** + * Compares the specified instance with the current instance. + * + * @since 2.0 + * + * @return @c true if the specified instance of Tizen::Base::Object is equal to the current %MmsMessage instance, @n + * else @c false + * @param[in] obj The object to compare + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + // Operation + public: + /** + * Sets the subject of an MMS message. + * + * @since 2.0 + * + * @return An error code + * @param[in] subject The subject of the MMS message + * @exception E_SUCCESS The method is successful. + * @exception E_MAX_EXCEEDED Either of the following conditions has occurred: + * - The subject length of the message exceeds the maximum limit (Maximum 40 characters). + * - The total size of the subject, body, and attachment(s) exceeds the maximum limit (295KB). + * @see GetSubject() + */ + result SetSubject(const Tizen::Base::String& subject); + + /** + * Sets the body of an MMS message. + * + * @since 2.0 + * + * @return An error code + * @param[in] text The body of the MMS message + * @exception E_SUCCESS The method is successful. + * @exception E_MAX_EXCEEDED Either of the following conditions has occurred: + * - The body length of the message exceeds the maximum limit (Maximum 1000 characters). + * - The total size of the subject, body, and attachment(s) exceeds the maximum limit (295KB). + * @see GetText() + */ + result SetText(const Tizen::Base::String& text); + + /** + * Adds the attachment of the specified type. + * + * @if OSPCOMPAT + * @brief [Compatibility] + * @endif + * @since 2.0 + * @if OSPCOMPAT + * @compatibility This method has compatibility issues with OSP compatible applications. @n + * For more information, see @ref CompIoPathPage "here". + * @endif + * + * @return An error code + * @param[in] format The format of the attachment + * @param[in] filePath The path of the file to attach + * @exception E_SUCCESS The method is successful. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The length of the specified @c filePath is either too long or @c 0. + * - The specified file format is already attached. + * - The specified @c format is invalid. + * - The specified file contains invalid data. + * - The media is not supported. + * - The specified file format cannot be attached. + * (An MMS attachment may contain either an image, audio, video, vCard, or a vCalendar file or a combination of an image, audio, vCard, and vCalendar file. @n + * MMS attachments cannot contain a video file in combination with an image or audio file.) + * @exception E_MAX_EXCEEDED Either of the following conditions has occurred: + * - The size of the file exceeds the maximum limit (Maximum 295KB). + * - The total size of the subject, body, and attachment(s) exceeds the maximum limit (295KB). + * @see GetAttachment() + */ + result AddAttachment(MmsAttachmentFormat format, const Tizen::Base::String& filePath); + + /** + * Gets the subject of an MMS message. + * + * @since 2.0 + * + * @return The subject of the MMS message + * @see SetSubject() + */ + Tizen::Base::String GetSubject(void) const; + + /** + * Gets the body of an MMS message. + * + * @since 2.0 + * + * @return The body of the MMS message + * @see SetText() + */ + Tizen::Base::String GetText(void) const; + + /** + * Gets the attachment file of the specified type. + * + * @since 2.0 + * + * @return The path of the attached file + * @param[in] format The format of the attachment + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_CONDITION The file is not attached. + * @exception E_INVALID_ARG The specified @c format is invalid. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see AddAttachment() + */ + Tizen::Base::String GetAttachment(MmsAttachmentFormat format) const; + + /** + * Removes the attachment of the specified type. + * + * @since 2.0 + * + * @return An error code + * @param[in] format The format of the attachment to remove + * @exception E_SUCCESS The method is successful. + * @exception E_FILE_NOT_FOUND The file with the corresponding format is not found. + * @exception E_INVALID_ARG The specified @c format is invalid. + * @see AddAttachment() + * @see GetAttachment() + */ + result RemoveAttachment(MmsAttachmentFormat format); + + private: + _MmsMessageImpl* __pImpl; + + // friend class + friend class _MmsMessageImpl; + }; // MmsMessage +} } // Tizen::Messaging + +#endif // _FMSG_MMS_MESSAGE_H_ diff --git a/inc/FMsgPushManager.h b/inc/FMsgPushManager.h new file mode 100755 index 0000000..5b405d0 --- /dev/null +++ b/inc/FMsgPushManager.h @@ -0,0 +1,365 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgPushManager.h + * @brief This is the header file for the %PushManager class. + * + * This header file contains the declarations of the %PushManager class. + */ + +#ifndef _FMSG_PUSH_MANAGER_H_ +#define _FMSG_PUSH_MANAGER_H_ + +#include +#include +#include + +namespace Tizen { namespace Messaging +{ +class _PushManagerImpl; + +/** + * @class PushManager + * @brief This class provides methods to use the push messaging service. + * + * @since 2.0 + * + * @remarks If an application package contains multiple applications, only one application can use the push messaging service at a time. + * + * @pre For information on how to use the push messaging service, see Push Messaging Guide. + * + * + * The %PushManager class provides methods to register, unregister, and use the push messaging service. + * + * For more information on the class features, see Messaging Guide. + * + * @see Tizen::Shell::NotificationManager + * + * The following example demonstrates how to use the %PushManager class. + * + * @code + * + #include + #include + + using namespace Tizen::Base; + using namespace Tizen::Messaging; + + // Creates a listener to override the methods of IPushManagerListener and IPushEventListener. + class MyClass + : public Object + , public IPushEventListener + , public IPushManagerListener + { + public: + MyClass(void) {} + ~MyClass(void) {} + + //IPushManagerListener and IPushEventListener + void OnPushServiceRegistered(RequestId reqId, const String& registrationId, result r, const String& errorCode, const String& errorMsg); + void OnPushServiceUnregistered(RequestId reqId, result r, const String& errorCode, const String& errorMsg); + void OnPushMessageReceived(const PushMessage& message); + + void Initialize(void); + void EnablePushService(void); + void DisablePushService(void); + + private: + PushManager* pPushManager; + }; + + void + MyClass::OnPushServiceRegistered(RequestId reqId, const String& registrationId, result r, const String& errorCode, const String& errorMsg) + { + if (E_SUCCESS == r) + { + // The application must send registrationId to the application server. + } + else + { + // Error + } + } + + void + MyClass::OnPushServiceUnregistered(RequestId reqId, result r, const String& errorCode, const String& errorMsg) + { + // Do something + } + + void + MyClass::OnPushMessageReceived(const PushMessage& message) + { + // Do something + } + + void + MyClass::Initialize(void) + { + // Creates a PushManager instance. + pPushManager = new PushManager(); + pPushManager->Construct(*this, *this); + } + + void + MyClass::EnablePushService(void) + { + RequestId reqId; + result r = E_SUCCESS; + + r = pPushManager->RegisterPushService(reqId); + if (IsFailed(r)) + { + return; + } + + // The result of registration will be notified by IPushManagerListener::OnPushServiceRegistered(). + } + + void + MyClass::DisablePushService(void) + { + // The application must notify the application server to stop sending push messages for this device. + + RequestId reqId; + result r = E_SUCCESS; + + r = pPushManager->UnregisterPushService(reqId); + if (IsFailed(r)) + { + return; + } + + // The result of unregistration will be notified by IPushManagerListener::OnPushServiceUnregistered(). + } + + * + * @endcode + */ +class _OSP_EXPORT_ PushManager + : public Tizen::Base::Object +{ +public: + /** + * The object is not fully constructed after this constructor is called. @n + * For full construction, the Construct() method must be called right after calling this constructor. + * + * @since 2.0 + */ + PushManager(void); + + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~PushManager(void); + +public: + /** + * Initializes this instance of %PushManager with the specified parameters. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/push + * + * @pre For information on how to use the push messaging service, see Push Messaging Guide. + * @feature %http://tizen.org/feature/network.push + * @return An error code + * @param[in] managerListener The listener to receive the result of the %PushManager + * class asynchronous methods + * @param[in] eventListener The listener to receive the incoming push messages + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + */ + result Construct(IPushManagerListener& managerListener, IPushEventListener& eventListener); + + /** + * Registers the push messaging service for the current application. @n + * The %RegisterPushService() method is asynchronous. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/push + * + * @pre For information on how to use the push messaging service, see Push Messaging Guide. + * + * @return An error code + * @param[out] reqId The request ID + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @see IPushManagerListener::OnPushServiceRegistered() + */ + result RegisterPushService(RequestId& reqId); + + /** + * Unregisters the push messaging service for the current application. @n + * The %UnregisterPushService() method is asynchronous. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/push + * + * @pre For information on how to use the push messaging service, see Push Messaging Guide. + * + * @return An error code + * @param[out] reqId The request ID + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @see IPushManagerListener::OnPushServiceUnregistered() + */ + result UnregisterPushService(RequestId& reqId); + + /** + * Checks whether the push messaging service is registered for the current application. + * + * @since 2.0 + * + * @pre For information on how to use the push messaging service, see Push Messaging Guide. + * + * @return @c true if the registration is completed, @n + * else @c false + */ + bool IsPushServiceRegistered(void) const; + + /** + * Gets the unread push messages. @n + * If an application receives unread messages with the %GetUnreadMessagesN() method, the messages are removed from the system. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/push + * + * @pre For information on how to use the push messaging service, see Push Messaging Guide. + * + * @return A pointer to the list that contains unread push messages + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks + * - The specific error code can be accessed using the GetLastResult() method. + * - If the user launches the application using a ticker or a quick panel, the push message related to the + * notification is delivered to the application as a launch argument. + * - The launch arguments are the input parameters for Tizen::App::IAppControlProviderEventListener::OnAppControlRequestReceivedN(). + * - This method returns all the unread messages including the message delivered as a launch argument. + * @see Tizen::App::IAppControlProviderEventListener + */ + Tizen::Base::Collection::IList* GetUnreadMessagesN(void); + + /** + * Sends the specified push message to a single recipient. @n + * The %SendPushMessage() method is asynchronous. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/push and %http://tizen.org/privilege/http @n + * Both the privileges are required. + * + * @pre For information on how to use the push messaging service, see Push Messaging Guide. + * + * @return An error code + * @param[in] message The push message + * @param[in] registrationId The registration ID of the recipient + * @param[in] appSecret The secret code of the application issued by the push server to authenticate the application + * @param[out] reqId The request ID + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG A specified input parameter is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @see IPushManagerListener::OnPushMessageSent() + */ + result SendPushMessage(const PushMessage& message, const Tizen::Base::String& registrationId, const Tizen::Base::String& appSecret, RequestId& reqId); + + + /** + * Sends the specified push message to multiple recipients. @n + * The %SendPushMessage() method is asynchronous. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/push and %http://tizen.org/privilege/http @n + * Both the privileges are required. + * + * @pre For information on how to use the push messaging service, see Push Messaging Guide. + * + * @return An error code + * @param[in] message The push message + * @param[in] registrationIdList The list of registration IDs of the recipients + * @param[in] appSecret The secret code of the application issued by the push server to authenticate the application + * @param[out] reqId The request ID + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG A specified input parameter is invalid. + * @exception E_MAX_EXCEEDED The number of registration IDs has crossed the maximum limit. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks The maximum limit can be checked by using GetMaxRecipientCount(). + * @see IPushManagerListener::OnPushMessageSent() + */ + result SendPushMessage(const PushMessage& message, const Tizen::Base::Collection::IList& registrationIdList, const Tizen::Base::String& appSecret, RequestId& reqId); + + /** + * Gets the maximum number of recipients for push messages sent by the multiple SendPushMessage() method. + * + * @since 2.0 + * + * @return The maximum number of recipients + */ + static int GetMaxRecipientCount(void); + +private: + /** + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] rhs An instance of PushManager + */ + PushManager(const PushManager& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. + * + * @return A reference to this instance + * @param[in] rhs An instance of PushManager + */ + PushManager& operator =(const PushManager& rhs); + +private: + _PushManagerImpl* __pPushManagerImpl; + + friend class _PushManagerImpl; +}; // PushManager + +} } // Tizen::Messaging +#endif // _FMSG_PUSH_MANAGER_H_ diff --git a/inc/FMsgPushMessage.h b/inc/FMsgPushMessage.h new file mode 100755 index 0000000..b996848 --- /dev/null +++ b/inc/FMsgPushMessage.h @@ -0,0 +1,189 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgPushMessage.h + * @brief This is the header file for the %PushMessage class. + * + * This header file contains the declarations of the %PushMessage class. + */ + +#ifndef _FMSG_PUSH_MESSAGE_H_ +#define _FMSG_PUSH_MESSAGE_H_ + +#include +#include +#include + +namespace Tizen { namespace Messaging +{ +class _PushMessageImpl; + +/** + * @class PushMessage + * @brief This class provides methods for handling a push message. + * + * @since 2.0 + * + * The %PushMessage class provides methods for handling a push message. It allows the user to get the body text and + * the received time of a push message. + * + * For more information on the class features, see Messaging Guide. + */ +class _OSP_EXPORT_ PushMessage + : public Tizen::Base::Object +{ +public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + PushMessage(void); + + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~PushMessage(void); + +public: + /** + * Gets the date and time (UTC time) of a message when it is received. + * + * @since 2.0 + * + * @return The date and time (UTC time) when the message is received + */ + Tizen::Base::DateTime GetReceivedTime(void) const; + + /** + * @if OSPDEPREC + * Gets the body of a message. + * + * @brief [Deprecated] + * @deprecated This method is deprecated. Instead of using this method, use the Tizen::Shell::NotificationRequest::GetAppMessage() method. + * + * @since 2.0 + * + * @return The body of the message + * @endif + */ + Tizen::Base::String GetText(void) const; + + /** + * Sets the specified action of a push message. + * + * @since 2.0 + * + * @return An error code + * @param[in] action The action of the push message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified input parameter is invalid. + */ + result SetAction(PushAction action); + + /** + * Gets the action of the push message. + * + * @since 2.0 + * + * @return The action of the push message + */ + PushAction GetAction(void) const; + + /** + * Sets the specified notification of a push message. + * + * @since 2.0 + * + * @return An error code + * @param[in] notificationRequest The notification request + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified input parameter is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks PushMessage only supports setting the alert text of the NotificationRequest instance, and ignores others. + */ + result SetNotification(const Tizen::Shell::NotificationRequest& notificationRequest); + + /** + * Gets the notification of the push message. + * + * @since 2.0 + * + * @return The notification request + * @remarks PushMessage only supports getting the alert text of the NotificationRequest instance, and ignores others. + */ + Tizen::Shell::NotificationRequest GetNotification(void) const; + + /** + * Copying of objects using this copy constructor is allowed. + * + * @since 2.0 + * + * @param[in] rhs An instance of %PushMessage to copy + */ + PushMessage(const PushMessage& rhs); + + /** + * Copying of objects using this copy assignment operator is allowed. + * + * @since 2.0 + * + * @return A reference to this instance + * @param[in] rhs An instance of %PushMessage to copy + */ + PushMessage& operator =(const PushMessage& rhs); + + /** + * Compares the specified instance with the current instance. + * + * @since 2.0 + * + * @return @c true if the specified instance of Tizen::Base::Object is equal to the current %PushMessage instance, @n + * else @c false + * @param[in] obj The other Tizen::Base::Object to compare + * @see Tizen::Base::Object::Equals() + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + +private: + /** + * This constructor is intentionally declared as private so that only the platform can create an instance. + * + * @param[in] dateTime The date and time (UTC time) when the message is received + * @param[in] text The message body text + */ + PushMessage(const Tizen::Base::DateTime& dateTime, const Tizen::Base::String& text); + +private: + _PushMessageImpl* __pPushMessageImpl; + + friend class _PushMessageImpl; +}; // PushMessage + +} } // Tizen::Messaging +#endif // _FMSG_PUSH_MESSAGE_H_ diff --git a/inc/FMsgRecipientList.h b/inc/FMsgRecipientList.h new file mode 100755 index 0000000..ccad970 --- /dev/null +++ b/inc/FMsgRecipientList.h @@ -0,0 +1,227 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgRecipientList.h + * @brief This is the header file for the %RecipientList class. + * + * This header file contains the declarations of the %RecipientList class. + */ + +#ifndef _FMSG_RECIPIENT_LIST_H_ +#define _FMSG_RECIPIENT_LIST_H_ + +// Includes +#include +#include + +namespace Tizen { namespace Messaging +{ + + // forward declaration + class _RecipientListImpl; + /** + * @class RecipientList + * @brief This class provides the abstract data type and methods for handling recipients. + * + * @since 2.0 + * + * The %RecipientList class provides methods for handling message recipients. It allows the user to add, remove, set, + * and get the list of recipients. A recipient is an email address for an email message or a telephone number + * for an SMS or MMS message. + * + * For more information on the class features, see Messaging Guide. + * + */ + class _OSP_EXPORT_ RecipientList + : public Tizen::Base::Object + { + // Life cycle + public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + RecipientList(void); + + /** + * This is the copy constructor for the %RecipientList class. + * + * @since 2.0 + * + * @param[in] value An instance of %RecipientList to copy + */ + RecipientList(const RecipientList& value); + + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~RecipientList(void); + + //Operator + public: + /** + * This is the assignment operator for this class. @n + * Copies the recipient list from the specified instance of %RecipientList to the current instance of %RecipientList. + * + * @since 2.0 + * + * @param[in] rhs A reference to the %RecipientList instance to copy + */ + RecipientList& operator =(const RecipientList& rhs); + + /** + * This operator compares the two recipient lists. + * + * @since 2.0 + * + * @return @c true if both the instances are equal, @n + * else @c false + * @param[in] rhs A reference to the %RecipientList instance on the right-hand side of the operator + */ + bool operator ==(const RecipientList& rhs) const; + + /** + * This operator compares the specified instance with the current instance for inequality. + * + * @since 2.0 + * + * @return @c true if both the instances are not equal, @n + * else @c false + * @param[in] rhs A reference to the %RecipientList instance on the right-hand side of the operator + */ + bool operator !=(const RecipientList& rhs) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + * @remarks + * - Two equal instances should return the same hash value. + * - For better performance, the hash function must generate a random distribution for all the inputs. + */ + virtual int GetHashCode(void) const; + + // Operation + public: + /** + * Compares the specified instance with the current instance. + * + * @since 2.0 + * + * @return @c true if the specified instance of Tizen::Base::Object is equal to the current %RecipientList instance, @n + * else @c false + * @param[in] value An instance of %RecipientList + */ + virtual bool Equals(const Tizen::Base::Object& value) const; + + /** + * Adds the specified recipient string. + * + * @since 2.0 + * + * @return An error code + * @param[in] type The recipient type + * @param[in] recipient The recipient string + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OBJ_ALREADY_EXIST The specified @c recipient is already added. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c recipient string length is too short (< 3) or too long (> 320). + * - The specified @c type is invalid. + * @remarks + * - The limit of the number of recipients is not checked in this method. This is done in the SmsManager::Send(), + * MmsManager::Send(), and EmailManager::Send() methods. + * - The minimum length of a recipient is @c 3 for a phone number and @c 5 for an email address. + * - The maximum length of a recipient is @c 41 for a phone number and @c 320 for an email address. + * @see Set() + * @see GetListN() + */ + result Add(RecipientType type, const Tizen::Base::String& recipient); + + /** + * Removes the specified recipient. + * + * @since 2.0 + * + * @return An error code + * @param[in] type The recipient type + * @param[in] recipient The recipient string + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c recipient string length is too short (< 3) or too long (> 320). + * - The specified @c type is invalid. + * @exception E_OBJ_NOT_FOUND The specified @c recipient does not exist. + * @see Add() + */ + result Remove(RecipientType type, const Tizen::Base::String& recipient); + + + /** + * Sets the specified recipient list. + * + * @since 2.0 + * + * @return An error code + * @param[in] type The recipient type + * @param[in] list The list of recipient strings + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The length of one of the recipients in the list is too short (< 3) or too long (> 320). + * - The specified @c type is invalid. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OBJ_ALREADY_EXIST A duplicate recipient exists in the recipient list. + * @remarks The limit of the recipients is not checked in this method. + * This is done in the SmsManager::Send(), MmsManager::Send(), and EmailManager::Send() methods. + * @see Add() + * @see GetListN() + */ + result Set(RecipientType type, const Tizen::Base::Collection::IList& list); + + /** + * Gets the recipient list of the specified recipient type. + * + * @since 2.0 + * + * @return A pointer to the list of recipient type + * @param[in] type The recipient type + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @remarks + * - The recipient is an email address for an email message or a telephone number for an SMS or MMS message. + * - The specified @c type contains @c RECIPIENT_TYPE_TO, @c RECIPIENT_TYPE_CC or @c RECIPIENT_TYPE_BCC. + * - The specific error code can be accessed using the GetLastResult() method. + * @see Add() + * @see Set() + */ + Tizen::Base::Collection::IList* GetListN(RecipientType type) const; + + private: + _RecipientListImpl* __pImpl; + + // friend class + friend class _RecipientListImpl; + }; // RecipientList + +} } // Tizen::Messaging + +#endif // _FMSG_RECIPIENT_LIST_H_ diff --git a/inc/FMsgSmsManager.h b/inc/FMsgSmsManager.h new file mode 100755 index 0000000..877a5fd --- /dev/null +++ b/inc/FMsgSmsManager.h @@ -0,0 +1,608 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgSmsManager.h + * @brief This is the header file for the %SmsManager class. + * + * This header file contains the declarations of the %SmsManager class. + */ + +#ifndef _FMSG_SMS_MANAGER_H_ +#define _FMSG_SMS_MANAGER_H_ + +// Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Tizen { namespace Messaging +{ + + // forward declaration + class _SmsManagerImpl; + + /** + * @class SmsManager + * @brief This class provides methods to use the Short Message Service. + * + * @since 2.0 + * + * The %SmsManager class is used to send, receive, and retrieve SMS messages. + * + * For more information on the class features, see Messaging Guide. + * + * The following example demonstrates how to use the %SmsManager class. + * + * @code + * + // Creates a listener to override the OnSmsMessageSent() method of ISmsListener + // in order to be notified of a change in the state of the message being sent. + + class SmsListener + : public ISmsListener + , public Object + { + public: + void OnSmsMessageSent(result r); + }; + + void + SmsListener::OnSmsMessageSent(result r) + { + // Do something + } + + class SendSmsMessage + : public Object + { + public: + void SmsTest(void); + }; + + void + SendSmsMessage::SmsTest(void) + { + result r = E_SUCCESS; + + // Creates an SmsListener instance. + SmsListener* pListener = new SmsListener(); + + // Creates a SMS manager instance with the listener as the callback to check the status of the message being sent. + SmsManager* pSmsManager = new SmsManager(); + r = pSmsManager->Construct(*pListener); + + // Creates a recipient list instance and adds recipients. + RecipientList recipient; + r = recipient.Add (RECIPIENT_TYPE_TO, L"01012345678"); + r = recipient.Add (RECIPIENT_TYPE_TO, L"01078901234"); + + // Creates an SMS message instance. + SmsMessage smsMessage; + r = smsMessage.SetText(L"Hello, World"); + + // Sends the message, and sets the saveToSentbox parameter to true if the message should be saved in the Sentbox; else, set to false. + // SmsListener callback is called once the message has been completely sent. + r = pSmsManager->Send(smsMessage, recipient, true); + } + * + * @endcode + */ + class _OSP_EXPORT_ SmsManager + : public Tizen::Base::Object + { + // Life cycle + public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + SmsManager(void); + + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~SmsManager(void); + + private: + SmsManager(const SmsManager& value); + SmsManager& operator =(const SmsManager& rhs); + + + // Operation + public: + /** + * Initializes this instance of %SmsManager with the specified parameter. + * + * @since 2.0 + * + * @feature %http://tizen.org/feature/network.telephony + * @return An error code + * @param[in] listener The listener to receive a sent result asynchronously + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + */ + result Construct(ISmsListener& listener); + + /** + * Adds the specified event listener for receiving SMS messages. + * + * @since 2.0 + * @privlevel partner + * @privilege %http://tizen.org/privilege/smstrigger + * + * @return An error code + * @param[in] port The port number + * @param[in] eventListener The listener to receive SMS messages + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OBJ_ALREADY_EXIST Either of the following conditions has occurred: + * - The specified port number is already registered. + * - The listener already exists. + * @exception E_FAILURE The specified port number is already used in other applications. + * @exception E_INVALID_ARG The specified @c port is invalid. @n + * The port number ranges from @c 1 to @c 9999 (1 <= port <= 9999). + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @see RemoveSmsEventListener() + */ + result AddSmsEventListener(int port, ISmsEventListener& eventListener); + + /** + * Removes the specified event listener for receiving SMS messages. + * + * @since 2.0 + * @privlevel partner + * @privilege %http://tizen.org/privilege/smstrigger + * + * @return An error code + * @param[in] port The port number + * @param[in] eventListener The listener to receive SMS messages + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OBJ_NOT_FOUND The listener is not found. + * @exception E_SYSTEM A system error has occurred. + * @exception E_INVALID_ARG The specified @c port is invalid. @n + * The port number ranges from @c 1 to @c 9999 (1 <= port <= 9999). + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @see AddSmsEventListener() + */ + result RemoveSmsEventListener(int port, ISmsEventListener& eventListener); + + /** + * Adds the specified event listener for receiving SMS messages. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return An error code + * @param[in] eventListener The listener to receive SMS messages + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OBJ_ALREADY_EXIST The listener already exists. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @see RemoveSmsMessageEventListener() + */ + result AddSmsMessageEventListener(ISmsMessageEventListener& eventListener); + + /** + * Removes the specified event listener for receiving SMS messages. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return An error code + * @param[in] eventListener The listener to receive SMS messages + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_OBJ_NOT_FOUND The listener is not found. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @see AddSmsMessageEventListener() + */ + result RemoveSmsMessageEventListener(ISmsMessageEventListener& eventListener); + + /** + * Sends the specified SMS message. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.write + * + * @return An error code + * @param[in] message The message to send + * @param[in] recipientList The list of recipients + * @param[in] saveToSentbox Set to @c true to save the message in the Sentbox, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM The method cannot proceed due to a severe system error. + * @exception E_ON_INITIALIZING The mailbox is not completely loaded as yet. + * @exception E_STORAGE_FULL The storage is full. + * @exception E_DEVICE_UNAVAILABLE The device is unavailable. + * @exception E_NETWORK_UNAVAILABLE The network is unavailable. + * @exception E_INVALID_ADDRESS The address is invalid. + * @exception E_FDN_MODE The FDN mode has been activated. + * @exception E_INVALID_ARG The number of recipients is @c 0. + * @exception E_MAX_EXCEEDED The number of recipients has crossed the maximum limit (Maximum 10). + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks The CC and BCC recipients in the @c recipientList are ignored while sending an SMS message. + * @see ISmsListener::OnSmsMessageSent() + */ + result Send(const SmsMessage& message, const RecipientList& recipientList, bool saveToSentbox); + + /** + * Gets the total number of SMS messages in the specified message box. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return The total number of SMS messages in the specified message box + * @param[in] type The message box type + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks + * - In case of an error, this method returns a negative value. For example, @c -1. + * - The specific error code can be accessed using the GetLastResult() method. + */ + int GetTotalMessageCount(SmsMessageBoxType type) const; + + /** + * Searches the SMS messages by keyword and/or sender address in the Inbox. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return A pointer to the list of SmsMessage instances + * @param[in] pKeyword A part of the body text as a keyword (partial match) @n + * In case of @c null or an empty string, this method searches all the SMS messages in the Inbox regardless of the keyword. + * @param[in] pSenderAddress A telephone number as a sender address (exact match) @n + * In case of @c null or an empty string, this method searches all the SMS messages in the Inbox regardless of the sender address. + * @param[in] startIndex The starting index (base 0) + * @param[in] count The count of SMS messages to search + * @param[out] totalResultCount The total count of the searched result + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c pKeyword string length is less than @c 2. + * - The specified @c pKeyword string length is greater than @c 30. + * - The specified @c pSenderAddress string length is less than @c 3. + * - The specified @c pSenderAddress string length is greater than @c 41. + * - The specified @c startIndex value is less than @c 0. + * - The specified @c count value is less than @c 0. + * - The specified @c count value is greater than @c 20. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks + * - The specific error code can be accessed using the GetLastResult() method. + * - The search with the specified keywords uses only the first 50 characters of the body text. + * - The SMS messages in the searched result contain only @c 160 bytes for the body text. + * - To check whether there is additional text, use the SmsMessage::HasMoreText() method. + * - To get the full body text, use GetFullText() with its message ID. + * @see GetFullText() + */ + Tizen::Base::Collection::IList* SearchInboxN(const Tizen::Base::String* pKeyword, const Tizen::Base::String* pSenderAddress, int startIndex, int count, int& totalResultCount) const; + + /** + * Searches the SMS messages by keyword in the specified message box. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return A pointer to the list of SmsMessage instances + * @param[in] type The type of message box + * @param[in] pKeyword A part of the body text as a keyword (partial match) @n + * In case of @c null or an empty string, this method searches all the SMS messages in the specified message box. + * @param[in] startIndex The start index (base 0) + * @param[in] count The count of SMS messages to search + * @param[out] totalResultCount The total count of the searched result + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c type is invalid. + * - The specified @c pKeyword string length is less than @c 2. + * - The specified @c pKeyword string length is greater than @c 30. + * - The specified @c startIndex value is less than @c 0. + * - The specified @c count value is less than @c 0. + * - The specified @c count value is greater than @c 20. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks + * - The specific error code can be accessed using the GetLastResult() method. + * - The search with the specified keywords uses only the first 50 characters of the body text. + * - The SMS messages in the searched result contain only @c 160 bytes for the body text. + * - To check whether there is additional text, use the SmsMessage::HasMoreText() method. + * - To get the full body text, use the GetFullText() method with the message ID. + * @see GetFullText() + */ + Tizen::Base::Collection::IList* SearchMessageBoxN(SmsMessageBoxType type, const Tizen::Base::String* pKeyword, int startIndex, int count, int& totalResultCount) const; + + /** + * Gets the full text of the SMS message in the message box using the message ID. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return The full text of the specified SMS message, @n + * else an empty string if an error occurs + * @param[in] messageId The unique ID of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c messageId is invalid. + * - The specified @c messageId is greater than or equal to @c 0. + * @exception E_OBJ_NOT_FOUND The SMS message with the specified @c messageId is not found. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see SmsMessage::HasMoreText() + */ + Tizen::Base::String GetFullText(int messageId) const; + + /** + * Sets the specified event listener for receiving CB messages. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + * + * @feature %http://tizen.org/feature/network.telephony.sms.cbs + * @return An error code + * @param[in] pListener The listener to receive CB messages + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + */ + result SetCbsMessageEventListener(ICbsMessageEventListener* pListener); + + /** + * Sets the specified event listener for receiving ETWS primary notifications. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + * + * @feature %http://tizen.org/feature/network.telephony.sms.cbs + * @return An error code + * @param[in] pListener The listener to receive ETWS primary notifications + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + */ + result SetEtwsPrimaryNotificationEventListener(IEtwsPrimaryNotificationEventListener* pListener); + + /** + * Enables or disables the save option for a CBS message to the CbsBox. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + * + * @feature %http://tizen.org/feature/network.telephony.sms.cbs + * @return An error code + * @param[in] enable Set to @c true to save the message in the CbsBox, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + */ + result SetSavingToCbsBoxEnabled(bool enable); + + /** + * Checks whether the CB service is enabled. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + * + * @return @c true if the CB service is enabled, @n + * else @c false + * @see SetCbsEnabled() + */ + bool IsCbsEnabled(void) const; + + /** + * Enables or disables the CB service. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + * + * @feature %http://tizen.org/feature/network.telephony.sms.cbs + * @return An error code + * @param[in] enable Set to @c true to enable the CB service, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + * @see IsCbsEnabled() + */ + result SetCbsEnabled(bool enable); + + /** + * Adds the CBS channel with the specified parameters. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + * + * @feature %http://tizen.org/feature/network.telephony.sms.cbs + * @return An error code + * @param[in] from The starting index of the message ID of the channel + * @param[in] to The last index of the message ID of the channel + * @param[in] name The name of the channel. @n + * This can be an empty string. + * @param[in] activate Set to @c true to activate the channel, @n + * else @c false. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c to is smaller than @c from. + * - The specified @c to or @c from is negative. + * - The specified @c to exceeds the limit (0xFFFF). + * - The range (@c to - @c from) exceeds the limit (0xFFFF). + * - The specified @c name string length is greater than @c 32. + * @exception E_ALREADY_SET The channel range (@c from ~ @c to) is already set. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to add the CBS channel. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + * @see RemoveCbsChannel() + */ + result AddCbsChannel(int from, int to, Tizen::Base::String& name, bool activate = true); + + /** + * Removes the CBS channel with the specified parameters. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + * + * @feature %http://tizen.org/feature/network.telephony.sms.cbs + * @return An error code + * @param[in] from The starting index of the message ID of the channel + * @param[in] to The last index of the message ID of the channel + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c to is smaller than @c from. + * - The specified @c to or @c from is negative. + * - The specified @c to exceeds the limit (0xFFFF). + * - The range (@c to - @c from) exceeds the limit (0xFFFF). + * @exception E_OBJ_NOT_FOUND The channel range (@c from ~ @c to) is not found. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to remove the CBS channel. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + * @see AddCbsChannel() + */ + result RemoveCbsChannel(int from, int to); + + /** + * Gets the CBS channel with the specified range. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + * + * @feature %http://tizen.org/feature/network.telephony.sms.cbs + * @return A pointer to the CBS channel with the specified range + * @param[in] from The starting index of the message ID of the channel + * @param[in] to The last index of the message ID of the channel + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c to is smaller than @c from. + * - The specified @c to or @c from is negative. + * - The specified @c to exceeds the limit (0xFFFF). + * - The range (@c to - @c from) exceeds the limit (0xFFFF). + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks + * - Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + * - The specific error code can be accessed using the GetLastResult() method. + * @see AddCbsChannel() + * @see RemoveCbsChannel() + */ + CbsChannel* GetCbsChannelN(int from, int to) const; + + /** + * Gets the CBS channel list. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/cellbroadcast + * + * @feature %http://tizen.org/feature/network.telephony.sms.cbs + * + * @return A pointer to the list of CBS channels + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks + * - Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + * - The specific error code can be accessed using the GetLastResult() method. + * @see AddCbsChannel() + * @see RemoveCbsChannel() + * @see CbsChannel + */ + Tizen::Base::Collection::IList* GetCbsChannelListN(void); + + private: + _SmsManagerImpl* __pImpl; + + // friend class + friend class _SmsManagerImpl; + }; // SmsManager +} } // Tizen::Messaging + +#endif // _FMSG_SMS_MANAGER_H_ diff --git a/inc/FMsgSmsMessage.h b/inc/FMsgSmsMessage.h new file mode 100755 index 0000000..444e55a --- /dev/null +++ b/inc/FMsgSmsMessage.h @@ -0,0 +1,283 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgSmsMessage.h + * @brief This is the header file for the %SmsMessage class. + * + * This header file contains the declarations of the %SmsMessage class. + */ + +#ifndef _FMSG_SMS_MESSAGE_H_ +#define _FMSG_SMS_MESSAGE_H_ + +namespace Tizen { namespace Base +{ +class String; +class DateTime; +} } + +#include +#include + +namespace Tizen { namespace Messaging +{ + // forward declaration for class extension + class _SmsMessageImpl; + class RecipientList; + + /** + * @class SmsMessage + * @brief This class provides methods for handling an SMS message. + * + * @since 2.0 + * + * The %SmsMessage class provides methods for handling SMS messages. It allows the user to set and get the body text of an SMS message. + * + * For more information on the class features, see Messaging Guide. + */ + class _OSP_EXPORT_ SmsMessage + : public Tizen::Base::Object + { + // Life cycle + public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + SmsMessage(void); + + /** + * This is the destructor for this class. + * + * @since 2.0 + */ + virtual ~SmsMessage(void); + + /** + * This is the copy constructor for the %SmsMessage class. + * + * @since 2.0 + * + * @param[in] value An instance of %SmsMessage to copy + */ + SmsMessage(const SmsMessage& value); + + public: + + /** + * This assignment operator copies an SMS message from the specified instance of %SmsMessage to the current instance of %SmsMessage. + * + * @since 2.0 + * + * @return A reference to the %SmsMessage instance + * @param[in] rhs A reference to the %SmsMessage instance to copy + */ + SmsMessage& operator =(const SmsMessage& rhs); + + /** + * Compares the specified instance with the current instance. + * + * @since 2.0 + * + * @return @c true if the specified instance of Tizen::Base::Object is equal to the current %SmsMessage instance, @n + * else @c false + * @param[in] obj The object to compare + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + // Operation + public: + /** + * Sets the body of an SMS message. + * + * @since 2.0 + * + * @return An error code + * @param[in] text The body of the SMS message + * @exception E_SUCCESS The method is successful. + * @exception E_MAX_EXCEEDED The body length of the message exceeds the maximum limit (Maximum 80 characters). + * @see GetText() + */ + result SetText(const Tizen::Base::String& text); + + /** + * Gets the body of an SMS message. + * + * @since 2.0 + * + * @return The body of the SMS message + * @remarks + * - If the message is from the Inbox, Sentbox, or Outbox, it may contain only @c 160 bytes for the body text. + * - To check whether the message contains more than @c 160 bytes for the body text, use the HasMoreText() method. + * - To get the full body text, use the SmsManager::GetFullText() method with its message ID. + * @see SetText() + * @see HasMoreText() + * @see GetId() + */ + Tizen::Base::String GetText(void) const; + + + /** + * Gets the sender address of an SMS message. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return The sender address of the SMS message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_OPERATION Either of the following conditions has occurred: + * - This operation is only allowed to the incoming message. + * - This operation is only allowed to the message from the Inbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::String GetSenderAddress(void) const; + + /** + * Gets the received time of an SMS message. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return The received time of the SMS message @n + * The value is 00:00:00, January 1, 1 in case of an error. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_OPERATION Either of the following conditions has occurred: + * - This operation is only allowed to the incoming message. + * - This operation is only allowed to the message from the Inbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::DateTime GetReceivedTime(void) const; + + /** + * Gets the unique ID of an SMS message. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return The unique ID of the SMS message @n + * The value is a negative value in case of an error. For example, @c -1. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_OPERATION This operation is allowed only when the message is from the Inbox, Sentbox, or Outbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + int GetId(void) const; + + /** + * Gets the sent time of an SMS message. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return The sent time of the SMS message @n + * The value is 00:00:00, January 1, 1 in case of an error. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_OPERATION This operation is allowed only when the message is from the Sentbox or Outbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::DateTime GetSentTime(void) const; + + /** + * Gets the type of an SMS message box. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return The type of the SMS message box @n + * The value is @c SMS_MESSAGE_BOX_TYPE_NONE in case of an error. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_OPERATION This operation is allowed only when the message is from the Inbox, Sentbox, or Outbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + SmsMessageBoxType GetMessageBoxType(void) const; + + /** + * Gets the list of recipients. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return The list of recipients + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_OPERATION This operation is allowed only when the message is from the Sentbox or Outbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + RecipientList GetRecipientList(void) const; + + /** + * Checks whether the SMS message contains more than @c 160 bytes for the body text. + * + * @since 2.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/messaging.read @n + * (%http://tizen.org/privilege/messaging.sms is deprecated.) + * + * @return @c true if this SMS message contains more than @c 160 bytes for the body text, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_OPERATION This operation is allowed only when the message is from the Inbox, Sentbox, or Outbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_USER_NOT_CONSENTED The user has blocked the application from calling this method. @b Since: @b 2.1 + * @remarks + * - If the return value is @c true, the SMS message contains more than @c 160 bytes for the body text. + * - To get the full body text, use SmsManager::GetFullText(). + * - The specific error code can be accessed using the GetLastResult() method. + */ + bool HasMoreText(void) const; + + private: + _SmsMessageImpl* __pImpl; + + // friend class + friend class _SmsMessageImpl; + }; // SmsMessage +} } // Tizen::Messaging + +#endif // _FMSG_SMS_MESSAGE_H_ diff --git a/inc/FMsgTypes.h b/inc/FMsgTypes.h new file mode 100755 index 0000000..972f44f --- /dev/null +++ b/inc/FMsgTypes.h @@ -0,0 +1,121 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgTypes.h + * @brief This is the header file for the enumerations of the %Messaging namespace. + * + * This header file contains the type declarations of the Messaging namespace. + */ + +#ifndef _FMSG_TYPES_H_ +#define _FMSG_TYPES_H_ + +namespace Tizen { namespace Messaging +{ + /** + * @enum RecipientType + * + * Defines the recipient type for a Short Message Service(SMS), Multimedia %Messaging Service(MMS), and email messages. + * + * @since 2.0 + */ + enum RecipientType + { + RECIPIENT_TYPE_TO = 0, /**< The recipient is in the 'To' list */ + RECIPIENT_TYPE_CC, /**< The recipient is in the 'Cc' list */ + RECIPIENT_TYPE_BCC /**< The recipient is in the 'Bcc' list */ + }; + + /** + * @enum AddressType + * + * Defines the type of an address. @n + * All recipient addresses must be either in a phone or an email format. + * + * @since 2.0 + */ + enum AddressType + { + ADDRESS_TYPE_PHONE = 0, /**< The phone number type */ + ADDRESS_TYPE_EMAIL /**< The email type */ + }; + + /** + * @enum MmsAttachmentFormat + * + * Defines the attachment type for Multimedia %Messaging Service (MMS) messages. + * + * @since 2.0 + */ + enum MmsAttachmentFormat + { + MMS_IMAGE = 0, /**< The image type */ + MMS_AUDIO, /**< The audio type */ + MMS_VIDEO, /**< The video type */ + MMS_VCARD, /**< The vCard type */ + MMS_VCALENDAR /**< The vCalendar type */ + }; + + /** + * @enum SmsMessageBoxType + * + * Defines the message box type for Short Message Service(SMS) messages. + * + * @since 2.0 + */ + enum SmsMessageBoxType + { + SMS_MESSAGE_BOX_TYPE_NONE = -1, /**< None */ + SMS_MESSAGE_BOX_TYPE_INBOX = 0, /**< The Inbox type */ + SMS_MESSAGE_BOX_TYPE_SENTBOX = 1, /**< The Sentbox type */ + SMS_MESSAGE_BOX_TYPE_OUTBOX = 2, /**< The Outbox type */ + SMS_MESSAGE_BOX_TYPE_ALL = 10 /**< All message boxes type */ + }; + + /** + * @enum EmailMessagePriority + * + * Defines the priority level for an email. + * + * @since 2.0 + */ + enum EmailMessagePriority + { + EMAIL_MESSAGE_PRIORITY_HIGH = 1, /**< High priority */ + EMAIL_MESSAGE_PRIORITY_NORMAL = 3, /**< Normal priority */ + EMAIL_MESSAGE_PRIORITY_LOW = 5 /**< Low priority */ + }; + + /** + * @enum PushAction + * + * Defines the push action. @n + * This action is performed when the application is not running. + * + * @since 2.0 + */ + enum PushAction + { + PUSH_ACTION_SILENT = 0, /**< Store the message without alerting the user */ + PUSH_ACTION_DISCARD, /**< Discard the message */ + PUSH_ACTION_ALERT, /**< Store the message and alert the user */ + PUSH_ACTION_LAUNCH /**< Launch the application @b Since: @b 2.1 */ + }; + +} } // Tizen::Messaging + +#endif // _FMSG_TYPES_H_ diff --git a/inc/FMsgWapPushManager.h b/inc/FMsgWapPushManager.h new file mode 100755 index 0000000..a6258a9 --- /dev/null +++ b/inc/FMsgWapPushManager.h @@ -0,0 +1,194 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 3.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-3.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgWapPushManager.h + * @brief This is the header file for the %WapPushManager class. + * + * This header file contains the declarations of the %WapPushManager class. + */ + +#ifndef _FMSG_WAP_PUSH_MANAGER_H_ +#define _FMSG_WAP_PUSH_MANAGER_H_ + +namespace Tizen { namespace Base +{ +class String; +} } + +#include + +namespace Tizen { namespace Messaging +{ +class _WapPushManagerImpl; + +/** + * @class WapPushManager + * @brief This class provides methods to use the WAP Push messaging service. + * + * @since 2.0 + * + * @final This class is not intended for extension. + * + * The %WapPushManager class provides methods to use the WAP Push messaging service. + */ +class _OSP_EXPORT_ WapPushManager + : public Tizen::Base::Object +{ +public: + /** + * This is the default constructor for this class. + * + * @since 2.0 + */ + WapPushManager(void); + + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~WapPushManager(void); + +public: + /** + * Adds the event listener for receiving WAP Push messages for the specified WAP Push application ID. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/wappush + * + * @feature %http://tizen.org/feature/network.telephony + * @return An error code + * @param[in] wapApplicationId The X-Wap-Application-Id that indicates the WAP Push application ID + * @param[in] listener The listener for receiving the incoming WAP Push messages + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_ALREADY_EXIST Either of the following conditions has occurred: + * - The specified @c wapApplicationId is already registered. + * - A listener already exists. + * @exception E_INVALID_ARG The specified @c wapApplicationId is invalid. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + * @see RemoveWapPushEventListener() + */ + result AddWapPushEventListener(const Tizen::Base::String& wapApplicationId, IWapPushEventListener& listener); + + /** + * Removes the event listener for receiving WAP Push messages for the specified WAP Push application ID. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/wappush + * + * @feature %http://tizen.org/feature/network.telephony + * @return An error code + * @param[in] wapApplicationId The X-Wap-Application-Id that indicates the WAP Push application ID + * @param[in] listener The listener for receiving the incoming WAP Push messages + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_NOT_FOUND Either of the following conditions has occurred: + * - The specified @c wapApplicationId is not registered. + * - The specified @c listener is not found. + * @exception E_INVALID_ARG The specified @c wapApplicationId is invalid. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + * @see AddWapPushEventListener() + */ + result RemoveWapPushEventListener(const Tizen::Base::String& wapApplicationId, IWapPushEventListener& listener); + + /** + * Registers a condition to receive a WAP Push message. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/wappush + * + * @feature %http://tizen.org/feature/network.telephony + * @return An error code + * @param[in] wapApplicationId The X-Wap-Application-Id that indicates the WAP push application ID + * @param[in] contentType The MIME content type of the content + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c contentType is invalid. + * - The specified @c wapApplicationId is invalid. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to register the conditions. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @exception E_ALREADY_SET The condition is already registered. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + * @see UnregisterCondition() + */ + result RegisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType); + + /** + * Unregisters a condition to receive a WAP push message. + * + * @since 2.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/wappush + * + * @feature %http://tizen.org/feature/network.telephony + * @return An error code + * @param[in] wapApplicationId The X-Wap-Application-Id that indicates the WAP push application ID + * @param[in] contentType The MIME content type of the content + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: + * - The specified @c contentType is invalid. + * - The specified @c wapApplicationId is invalid. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to unregister the conditions. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @exception E_UNSUPPORTED_OPERATION The Emulator or target device does not support the required feature. @b Since: @b 2.1 + * For more information, see Application Filtering. + * @remarks Before calling this method, check whether the feature is supported by + * Tizen::System::SystemInfo::GetValue(const Tizen::Base::String&, bool&). + * @see RegisterCondition() + */ + result UnregisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType); + +private: + /** + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] rhs An instance of WapPushManager + */ + WapPushManager(const WapPushManager& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] rhs An instance of WapPushManager + */ + WapPushManager& operator =(const WapPushManager& rhs); + +private: + _WapPushManagerImpl* __pWapPushManagerImpl; + + friend class _WapPushManagerImpl; +}; // WapPushManager + +} } // Tizen::Messaging +#endif // _FMSG_WAP_PUSH_MANAGER_H_ diff --git a/inc/FMsgWapPushMessage.h b/inc/FMsgWapPushMessage.h new file mode 100755 index 0000000..dd4a72c --- /dev/null +++ b/inc/FMsgWapPushMessage.h @@ -0,0 +1,164 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgWapPushMessage.h + * @brief This is the header file for the %WapPushMessage class. + * + * This header file contains the declarations of the %WapPushMessage class. + */ + +#ifndef _FMSG_WAP_PUSH_MESSAGE_H_ +#define _FMSG_WAP_PUSH_MESSAGE_H_ + +namespace Tizen { namespace Base +{ +class String; +class ByteBuffer; +} } + +#include + +namespace Tizen { namespace Messaging +{ +class _WapPushMessageImpl; + +/** + * @class WapPushMessage + * @brief This class provides methods for handling a WAP Push message. + * + * @since 2.0 + * + * @final This class is not intended for extension. + * + * The %WapPushMessage class provides methods for handling a WAP Push message. @n + * The methods of this class fetch the header and body of a WAP Push message. + */ +class _OSP_EXPORT_ WapPushMessage + : public Tizen::Base::Object +{ +public: + /** + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.0 + */ + virtual ~WapPushMessage(void); + +public: + + /** + * Gets the header of a message. + * + * @since 2.0 + * + * @return The header of the message @n + * The header has the X-Wap-Application-Id and Content-Type fields. + */ + Tizen::Base::String GetHeader(void) const; + + /** + * Gets the body of a message. + * + * @since 2.0 + * + * @return The body of the message, @n + * else @c null in case of an error + * @remarks + * - The message body can be any MIME content-type. + * - The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::ByteBuffer* GetBodyN(void) const; + + /** + * Compares the specified instance with the current instance. + * + * @since 2.0 + * + * @return @c true if the specified instance of Tizen::Base::Object is equal to the current %WapPushMessage instance, @n + * else @c false + * @param[in] obj An instance of Tizen::Base::Object to compare + * @see Tizen::Base::Object::Equals() + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * Gets the hash value of the current instance. + * + * @since 2.0 + * + * @return The hash value of the current instance + */ + virtual int GetHashCode(void) const; + + /** + * Gets the copied instance of this class. + * + * @since 2.0 + * + * @return An instance of %WapPushMessage, @n + * else @c null in case of an error + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + WapPushMessage* CloneN(void) const; + +private: + /** + * This default constructor is intentionally declared as private so that only the platform can create an instance. + * + * @since 2.0 + */ + WapPushMessage(void); + + /** + * This is the copy constructor for the %WapPushMessage class. @n + * Copying of objects using this copy constructor is allowed. + * + * @since 2.0 + * + * @param[in] rhs An instance of %WapPushMessage + */ + WapPushMessage(const WapPushMessage& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. @n + * - Use CloneN() to get an exact copy of the instance. + * - Use Equals() to compare the contents of one instance with the other. + * + * @return A reference to this instance + * + * @param[in] rhs An instance of %WapPushMessage + */ + WapPushMessage& operator =(const WapPushMessage& rhs); + + /** + * This constructor is intentionally declared as private so that only the platform can create an instance. + * + * @param[in] header The header of the received WAP Push message + * @param[in] body The body of the received WAP Push message + */ + WapPushMessage(const Tizen::Base::String& header, const Tizen::Base::ByteBuffer& body); + +private: + _WapPushMessageImpl* __pWapPushMessageImpl; + + friend class _WapPushMessageImpl; +}; // WapPushMessage + +} } // Tizen::Messaging +#endif // _FMSG_WAP_PUSH_MESSAGE_H_ diff --git a/osp-messaging.manifest b/osp-messaging.manifest new file mode 100644 index 0000000..ae3e6f7 --- /dev/null +++ b/osp-messaging.manifest @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/osp-messaging.pc.in b/osp-messaging.pc.in new file mode 100755 index 0000000..eb6c3b7 --- /dev/null +++ b/osp-messaging.pc.in @@ -0,0 +1,14 @@ +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib/osp +includedir=/usr/include/osp + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} + diff --git a/packaging/osp-messaging.spec b/packaging/osp-messaging.spec new file mode 100644 index 0000000..9fd2d79 --- /dev/null +++ b/packaging/osp-messaging.spec @@ -0,0 +1,114 @@ +%define debug_package %{nil} +%define __strip /bin/true + +Name: osp-messaging +Summary: osp messaging library +Version: 1.2.2.0 +Release: 2 +Group: System/Libraries +License: Apache License, Version 2.0 +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(chromium) +BuildRequires: pkgconfig(capi-appfw-application) +BuildRequires: pkgconfig(msg-service) +BuildRequires: pkgconfig(push) +BuildRequires: pkgconfig(dbus-1) +BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(email-service) +BuildRequires: pkgconfig(pkgmgr) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(libwbxml2) +BuildRequires: pkgconfig(osp-appfw) +BuildRequires: osp-appfw-internal-devel +BuildRequires: pkgconfig(osp-net) +BuildRequires: osp-net-internal-devel +BuildRequires: pkgconfig(osp-bluetooth) +BuildRequires: pkgconfig(osp-nfc) +BuildRequires: pkgconfig(osp-json) +BuildRequires: pkgconfig(osp-shell) + +# runtime requires +Requires: osp-appfw +Requires: osp-bluetooth +Requires: osp-nfc +Requires: osp-json +Requires: osp-shell + +%description +osp messaging library + +%package devel +Summary: osp messaging library (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description devel +osp messaging library (DEV) + +%package internal-devel +Summary: osp messaging library (Internal) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description internal-devel +osp messaging library (Internal-DEV) + +%package debug +Summary: osp messaging library (Development) +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description debug +osp messaging library (DEV) + +%prep +%setup -q + +%build +%if 0%{?tizen_build_binary_release_type_eng} +CXXFLAGS="$CXXFLAGS -D_SECURE_LOG" +%endif +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +%ifarch %{ix86} +%if 0%{?simulator} +CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ -D_OSP_EMUL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%else +CXXFLAGS="$CXXFLAGS -D_OSP_DEBUG_ -D_OSP_X86_ " cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%endif +%else +%if 0%{?tizen_build_binary_release_type_eng} +CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_SECURE_LOG -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%else +CXXFLAGS="-O2 -g -pipe -Wall -fno-exceptions -Wformat -Wformat-security -Wl,--as-needed -fmessage-length=0 -march=armv7-a -mtune=cortex-a8 -mlittle-endian -mfpu=neon -mfloat-abi=softfp -D__SOFTFP__ -mthumb -Wa,-mimplicit-it=thumb -funwind-tables -D_OSP_DEBUG_ -D_OSP_ARMEL_" cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DFULLVER=%{version} -DMAJORVER=${MAJORVER} +%endif +%endif + +# Call make instruction with smp support +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/usr/share/license +cp %{_builddir}/%{name}-%{version}/LICENSE.APLv2 %{buildroot}/usr/share/license/%{name} + +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%manifest osp-messaging.manifest +/usr/share/license/%{name} +%{_libdir}/osp/*.so* + +%files devel +%{_includedir}/osp/*.h +%{_libdir}/pkgconfig/osp-messaging.pc + +%files internal-devel +%{_includedir}/osp/messaging/*.h + +%files debug +%{_libdir}/osp/debug/*.so* diff --git a/src/FMsgCbsChannel.cpp b/src/FMsgCbsChannel.cpp new file mode 100644 index 0000000..fda2bea --- /dev/null +++ b/src/FMsgCbsChannel.cpp @@ -0,0 +1,174 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @if VISPARTNER-OPERATOR + * + * @file FMsgCbsChannel.cpp + * @brief This is the implementation file for the %CbsChannel class. + * + * @visibility partner-operator + * + * This file contains the implementation of the %CbsChannel class. + * + * @endif +*/ + +#include +#include +#include +#include "FMsg_Types.h" +#include "FMsg_CbsChannelImpl.h" +#include "FMsg_MessagingIpcProxy.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ + +CbsChannel::CbsChannel(void) +{ + __pCbsChannelImpl = new (std::nothrow) _CbsChannelImpl(); + SysTryReturnVoidResult(NID_MSG, __pCbsChannelImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed."); +} + +CbsChannel::CbsChannel(const CbsChannel& value) +{ + __pCbsChannelImpl = new (std::nothrow) _CbsChannelImpl(*(value.__pCbsChannelImpl)); + SysTryReturnVoidResult(NID_MSG, __pCbsChannelImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed."); +} + +CbsChannel::~CbsChannel(void) +{ + if (__pCbsChannelImpl) + { + delete __pCbsChannelImpl; + } + __pCbsChannelImpl = null; +} + +CbsChannel& +CbsChannel::operator =(const CbsChannel& rhs) +{ + if (this != &rhs) + { + *__pCbsChannelImpl = *(rhs.__pCbsChannelImpl); + } + + return (*this); +} + +result +CbsChannel::Construct(int from, int to, const Tizen::Base::String& name) +{ + result r = E_SUCCESS; + + SysAssertf(__pCbsChannelImpl != null, "The CbsChannel instance is not constructed yet."); + + // argument check + SysTryReturnResult(NID_MSG, name.GetLength() <= MAX_CBS_CHANNEL_NAME_LENGTH, E_INVALID_ARG, + "The length (%d) of channel name is too long.", name.GetLength()); + + SysTryReturnResult(NID_MSG, + ((to >= 0) && (from >= 0) && (to >= from) && (to <= MAX_CBS_CHANNEL_LIMIT) && ((to - from) <= MAX_CBS_CHANNEL_RANGE)), + E_INVALID_ARG, "Failed to add construct channel, invalid arguments. to:[%d], from:[%d]", to , from); + + r = __pCbsChannelImpl->Construct(from, to, name); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_INVALID_ARG, "Failed to construct CbsChannel"); + + return r; +} + +result +CbsChannel::UpdateName(const Tizen::Base::String& name) +{ + result r = E_SUCCESS; + + SysAssertf(__pCbsChannelImpl != null, "The CbsChannel instance is not constructed yet."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagating."); + + // argument check + SysTryReturn(NID_MSG, name.GetLength() <= MAX_CBS_CHANNEL_NAME_LENGTH, E_INVALID_ARG, r = E_INVALID_ARG, + "[E_INVALID_ARG] invalid channel name."); + + r = __pCbsChannelImpl->UpdateName(name); + + return r; +} + +result +CbsChannel::Deactivate(void) +{ + result r = E_SUCCESS; + + SysAssertf(__pCbsChannelImpl != null, "The CbsChannel instance is not constructed yet."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagating."); + + r = __pCbsChannelImpl->Deactivate(); + return r; +} + +result +CbsChannel::Activate(void) +{ + result r = E_SUCCESS; + + SysAssertf(__pCbsChannelImpl != null, "The CbsChannel instance is not constructed yet."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagating."); + + return __pCbsChannelImpl->Activate(); +} + +bool +CbsChannel::IsActivated(void) const +{ + SysAssertf(__pCbsChannelImpl != null, "The CbsChannel instance is not constructed yet."); + + return(__pCbsChannelImpl->IsActivated()); +} + +Tizen::Base::String +CbsChannel::GetName(void) const +{ + SysAssertf(__pCbsChannelImpl != null, "The CbsChannel instance is not constructed yet."); + + return(__pCbsChannelImpl->GetName()); +} + +result +CbsChannel::GetRange(int& from, int& to) const +{ + result r = E_SUCCESS; + + SysAssertf(__pCbsChannelImpl != null, "The CbsChannel instance is not constructed yet."); + + r = __pCbsChannelImpl->GetRange(from, to); + + return r; +} + +} } // Tizen::Messaging diff --git a/src/FMsgCbsMessage.cpp b/src/FMsgCbsMessage.cpp new file mode 100644 index 0000000..ddf0a07 --- /dev/null +++ b/src/FMsgCbsMessage.cpp @@ -0,0 +1,171 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgCbsMessage.cpp + * @brief This is the implementation file for the %CbsMessage class. + * + * This file contains the implementation of the %CbsMessage class. + */ + +#include +#include +#include +#include "FMsg_Types.h" +#include "FMsg_CbsMessageImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ + +CbsMessage::CbsMessage(void) +{ + __pCbsMessageImpl = new (std::nothrow) _CbsMessageImpl(); + SysTryReturnVoidResult(NID_MSG, __pCbsMessageImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +CbsMessage::CbsMessage(const CbsMessage& value) +{ + __pCbsMessageImpl = new (std::nothrow) _CbsMessageImpl(*(value.__pCbsMessageImpl)); + SysTryReturnVoidResult(NID_MSG, __pCbsMessageImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +CbsMessage::~CbsMessage(void) +{ + if (__pCbsMessageImpl) + { + delete __pCbsMessageImpl; + } + __pCbsMessageImpl = null; +} + +CbsMessage& +CbsMessage::operator =(const CbsMessage& rhs) +{ + if (this != &rhs) + { + *__pCbsMessageImpl = *(rhs.__pCbsMessageImpl); + } + + return (*this); +} + +CbsMessage* +CbsMessage::CloneN() const +{ + return __pCbsMessageImpl->CloneN(); +} + +bool +CbsMessage::Equals(const Tizen::Base::Object& obj) const +{ + const CbsMessage* pCbsMessage = dynamic_cast(&obj); + if (!pCbsMessage) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + return __pCbsMessageImpl->Equals(*(pCbsMessage->__pCbsMessageImpl)); +} + +int +CbsMessage::GetHashCode(void) const +{ + return __pCbsMessageImpl->GetHashCode(); +} + +Tizen::Base::ByteBuffer* +CbsMessage::GetSerialNumberN(void) const +{ + result r = E_SUCCESS; + Tizen::Base::ByteBuffer* pSerialnumber = null; + ClearLastResult(); + + SysAssertf(__pCbsMessageImpl != null, "The CbsChannel instance is not constructed yet."); + + pSerialnumber = __pCbsMessageImpl->GetSerialNumberN(); + + r = GetLastResult(); + SetLastResult(r); + + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "failed to get cbs message SerialNumber ."); + + return pSerialnumber; + +CATCH: + SetLastResult(GetLastResult()); + + if (pSerialnumber) + { + delete pSerialnumber; + pSerialnumber = null; + } + return null; +} + +Tizen::Base::DateTime +CbsMessage::GetReceivedTime(void) const +{ + SysAssertf(__pCbsMessageImpl != null, "The CbsChannel instance is not constructed yet."); + + return (__pCbsMessageImpl->GetReceivedTime()); +} + +Tizen::Base::String +CbsMessage::GetText(void) const +{ + SysAssertf(__pCbsMessageImpl != null, "The CbsChannel instance is not constructed yet."); + + return (__pCbsMessageImpl->GetText()); +} + +int +CbsMessage::GetMessageId(void) const +{ + SysAssertf(__pCbsMessageImpl != null, "The CbsChannel instance is not constructed yet."); + + return (__pCbsMessageImpl->GetMessageId()); +} + +bool +CbsMessage::IsEtwsNotification(void) const +{ + SysAssertf(__pCbsMessageImpl != null, "The CbsChannel instance is not constructed yet."); + + return (__pCbsMessageImpl->IsEtwsNotification()); +} + +byte +CbsMessage::GetDataCodingScheme(void) const +{ + SysAssertf(__pCbsMessageImpl != null, "The CbsChannel instance is not constructed yet."); + + return (__pCbsMessageImpl->GetDataCodingScheme()); +} + +Tizen::Base::String +CbsMessage::GetLanguageType(void) const +{ + SysAssertf(__pCbsMessageImpl != null, "The CbsChannel instance is not constructed yet."); + + return (__pCbsMessageImpl->GetLanguageType()); +} + +} } // Tizen::Messaging diff --git a/src/FMsgDetailedEmailMessage.cpp b/src/FMsgDetailedEmailMessage.cpp new file mode 100644 index 0000000..248da2b --- /dev/null +++ b/src/FMsgDetailedEmailMessage.cpp @@ -0,0 +1,514 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgDetailedEmailMessage.cpp + * @brief This is the implementation file for the %DetailedEmailMessage class. + * + * This file contains the implementation of the %DetailedEmailMessage class. + */ + +#include +#include +#include +#include +#include +#include +#include "FMsg_DetailedEmailMessageImpl.h" +#include "FMsg_Types.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +namespace Tizen { namespace Messaging +{ + +DetailedEmailMessage::DetailedEmailMessage(void) +{ + __pImpl = new (std::nothrow) _DetailedEmailMessageImpl(); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +DetailedEmailMessage::DetailedEmailMessage(const DetailedEmailMessage& value) +{ + __pImpl = new (std::nothrow) _DetailedEmailMessageImpl(*(value.__pImpl)); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +DetailedEmailMessage::~DetailedEmailMessage(void) +{ + if (__pImpl) + { + delete __pImpl; + __pImpl = null; + } +} + +DetailedEmailMessage& +DetailedEmailMessage::operator =(const DetailedEmailMessage& rhs) +{ + if (this != &rhs) + { + *__pImpl = *(rhs.__pImpl); + } + + return (*this); +} + +bool +DetailedEmailMessage::Equals(const Tizen::Base::Object& obj) const +{ + const DetailedEmailMessage* pDetailedEmailMessage = dynamic_cast(&obj); + if (!pDetailedEmailMessage) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + return __pImpl->Equals(*(pDetailedEmailMessage->__pImpl)); +} + +int +DetailedEmailMessage::GetHashCode(void) const +{ + return __pImpl->GetHashCode(); +} + +Tizen::Base::String +DetailedEmailMessage::GetMessageId(void) const +{ + return(__pImpl->GetMessageId()); +} + +String +DetailedEmailMessage::GetSubject(void) const +{ + return(__pImpl->GetSubject()); +} + +Tizen::Base::DateTime +DetailedEmailMessage::GetCreationTime(void) const +{ + return(__pImpl->GetCreationTime()); +} + +Tizen::Base::String +DetailedEmailMessage::GetAddress(RecipientType type) const +{ + return(__pImpl->GetAddress(type)); +} + +Tizen::Base::String +DetailedEmailMessage::GetFromAddress() const +{ + return(__pImpl->GetFromAddress()); +} + +Tizen::Base::String +DetailedEmailMessage::GetReplyToAddress() const +{ + return(__pImpl->GetReplyToAddress()); +} + +Tizen::Base::String +DetailedEmailMessage::GetReturnPath() const +{ + return(__pImpl->GetReturnPath()); +} + +Tizen::Base::String +DetailedEmailMessage::GetFilePath(EmailMessageBodyType type) const +{ + return(__pImpl->GetFilePath(type)); +} + +EmailMessagePriority +DetailedEmailMessage::GetPriority(void) const +{ + return (__pImpl->GetPriority()); +} + +EmailReturnReceiptType +DetailedEmailMessage::GetReturnReceiptType(void) const +{ + return (__pImpl->GetReturnReceiptType()); +} + +int +DetailedEmailMessage::GetInlineContentCount(void) const +{ + return(__pImpl->GetInlineContentCount()); +} + +EmailMessageClass +DetailedEmailMessage::GetClass(void) const +{ + return (__pImpl->GetClass()); +} + +EmailDigestType +DetailedEmailMessage::GetDigestType(void) const +{ + return (__pImpl->GetDigestType()); +} + +EmailSmimeType +DetailedEmailMessage::GetSmimeType(void) const +{ + return (__pImpl->GetSmimeType()); +} + +Tizen::Base::Collection::IList* +DetailedEmailMessage::GetAttachmentListN(void) +{ + result r = E_SUCCESS; + IList* pAttachmentList = null; + + ClearLastResult(); + + pAttachmentList = __pImpl->GetAttachmentListN(); + + r = GetLastResult(); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "Failed to get the attachment list."); + + return pAttachmentList; + +CATCH: + SetLastResult(GetLastResult()); + + if (pAttachmentList) + { + if (pAttachmentList->GetCount() > 0) + { + pAttachmentList->RemoveAll(true); + } + delete pAttachmentList; + pAttachmentList = null; + } + + return null; +} + +result +DetailedEmailMessage::SetMessageId(const Tizen::Base::String& messageId) +{ + result r = E_SUCCESS; + ClearLastResult(); + + //Argument Check + SysTryReturn(NID_MSG, + messageId.GetLength() != 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of message id is invalid."); + + r = __pImpl->SetMessageId(messageId); + + return r; +} + +result +DetailedEmailMessage::SetSubject(const Tizen::Base::String& subject) +{ + result r = E_SUCCESS; + ClearLastResult(); + + SysTryReturn(NID_MSG, + subject.GetLength() <= MAX_EMAIL_SUBJECT_LENGTH, E_MAX_EXCEEDED, r = E_MAX_EXCEEDED, "The length of msg subject is invalid."); + + r = __pImpl->SetSubject(subject); + + return r; +} + +result +DetailedEmailMessage::SetCreationTime(const Tizen::Base::DateTime& dateTime) +{ + result r = E_SUCCESS; + ClearLastResult(); + + DateTime minDateTime; + DateTime maxDateTime; + + minDateTime.SetValue(1900, 1, 1); + maxDateTime.SetValue(2100, 12, 31, 23, 59, 59); + + SysTryReturn(NID_MSG, + ((dateTime <= maxDateTime) && (dateTime >= minDateTime)), E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] Propagating."); + + r = __pImpl->SetCreationTime(dateTime); + + return r; +} + +result +DetailedEmailMessage::SetAddress(RecipientType type, const Tizen::Base::String& recipients) +{ + result r = E_SUCCESS; + ClearLastResult(); + + SysTryReturn(NID_MSG, + type >= 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email msg Recipient type"); + SysTryReturn(NID_MSG, + type < MAX_EMAIL_MESSAGE_RECEIPT_TYPE, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email msg body type"); + SysTryReturn(NID_MSG, + recipients.GetLength() >= MIN_LENGTH_EMAIL, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of address is invalid."); + + r = __pImpl->SetAddress(type, recipients); + + return r; +} + +result +DetailedEmailMessage::SetFromAddress(const Tizen::Base::String& address) +{ + result r = E_SUCCESS; + ClearLastResult(); + + SysTryReturn(NID_MSG, + address.GetLength() >= MIN_LENGTH_EMAIL, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of from address is invalid."); + + r = __pImpl->SetFromAddress(address); + + return r; +} + +result +DetailedEmailMessage::SetReplyToAddress(const Tizen::Base::String& address) +{ + result r = E_SUCCESS; + ClearLastResult(); + + SysTryReturn(NID_MSG, + address.GetLength() >= MIN_LENGTH_EMAIL, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of reply address is invalid."); + + r = __pImpl->SetReplyToAddress(address); + + return r; +} + +result +DetailedEmailMessage::SetReturnPath(const Tizen::Base::String& address) +{ + result r = E_SUCCESS; + ClearLastResult(); + + SysTryReturn(NID_MSG, + address.GetLength() >= MIN_LENGTH_EMAIL, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of return path is invalid."); + + r = __pImpl->SetReturnPath(address); + + return r; +} + +result +DetailedEmailMessage::SetFilePath(EmailMessageBodyType type, const Tizen::Base::String& filePath) +{ + result r = E_SUCCESS; + bool isFileExist = false; + ClearLastResult(); + + //Argument Check + SysTryReturn(NID_MSG, + type >= 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email msg body type"); + SysTryReturn(NID_MSG, + type < MAX_EMAIL_MESSAGE_BODY_TYPE, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email msg body type"); + SysTryReturnResult(NID_MSG, filePath.GetLength() > 0, E_INVALID_ARG, "[E_INVALID_ARG] The file path is empty."); + SysTryReturnResult(NID_MSG, filePath.GetLength() <= PATH_MAX, E_INVALID_ARG, "[E_INVALID_ARG] The file path is too long."); + + isFileExist = File::IsFileExist(filePath); + + r = GetLastResult(); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_INVALID_ARG , E_INVALID_ARG, "[E_INVALID_ARG] Propagating."); + SysTryCatch(NID_MSG, isFileExist == true, r = E_FILE_NOT_FOUND , E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] Propagating."); + + r = __pImpl->SetFilePath(type, filePath); + return r; + +CATCH: + SetLastResult(GetLastResult()); + return r; +} + +result +DetailedEmailMessage::SetPriority(EmailMessagePriority priority) +{ + result r = E_SUCCESS; + ClearLastResult(); + + //Argument Check + SysTryReturn(NID_MSG, + priority >= 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email msg priority"); + SysTryReturn(NID_MSG, + priority < MAX_EMAIL_MESSAGE_PRIORITY, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email msg body type"); + + r = __pImpl->SetPriority(priority); + + return r; +} + +result +DetailedEmailMessage::SetReturnReceiptType(EmailReturnReceiptType type) +{ + result r = E_SUCCESS; + ClearLastResult(); + + //Argument Check + SysTryReturn(NID_MSG, + type >= 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email Return Receipt Type"); + SysTryReturn(NID_MSG, + type < MAX_EMAIL_MESSAGE_RETURN_RECEIPT_TYPE, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email msg body type"); + + r = __pImpl->SetReturnReceiptType(type); + + return r; +} + +result +DetailedEmailMessage::SetInlineContentCount(int count) +{ + result r = E_SUCCESS; + ClearLastResult(); + + //Argument Check + SysTryReturn(NID_MSG, + count >= 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email Inline Content Count"); + + r = __pImpl->SetInlineContentCount(count); + + return r; +} + +result +DetailedEmailMessage::SetClass(EmailMessageClass messageClass) +{ + result r = E_SUCCESS; + ClearLastResult(); + + //Argument Check + SysTryReturn(NID_MSG, + messageClass >= 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email message Class"); + SysTryReturn(NID_MSG, + messageClass < MAX_EMAIL_MESSAGE_CLASS, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email msg body type"); + + r = __pImpl->SetClass(messageClass); + + return r; +} + +result +DetailedEmailMessage::SetDigestType(EmailDigestType type) +{ + result r = E_SUCCESS; + ClearLastResult(); + + //Argument Check + SysTryReturn(NID_MSG, + type >= 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email Digest Type"); + SysTryReturn(NID_MSG, + type < MAX_EMAIL_MESSAGE_DIGEST_TYPE, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email msg body type"); + + r = __pImpl->SetDigestType(type); + + return r; +} + +result +DetailedEmailMessage::SetSmimeType(EmailSmimeType type) +{ + result r = E_SUCCESS; + ClearLastResult(); + + //Argument Check + SysTryReturn(NID_MSG, + type >= 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email Smime Type"); + SysTryReturn(NID_MSG, + type < MAX_EMAIL_MESSAGE_SMIME_TYPE, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid email msg body type"); + + r = __pImpl->SetSmimeType(type); + + return r; +} + +result +DetailedEmailMessage::SetAttachmentList(const Tizen::Base::Collection::IList* pList) +{ + result r = E_SUCCESS; + ClearLastResult(); + + SysTryReturn(NID_MSG, pList != null, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] Propagating."); + + //Argument check + for (int index = 0; index < pList->GetCount(); index++) + { + const EmailAttachment* pEmailAttachment = dynamic_cast (pList->GetAt(index)); + SysTryReturn(NID_MSG, pEmailAttachment != null, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] Propagating."); + } + + r = __pImpl->SetAttachmentList(pList); + return r; +} + +result +DetailedEmailMessage::ParseMimeFile(const Tizen::Base::String& filePath, DetailedEmailMessage& message) +{ + result r = E_SUCCESS; + bool isFileExist = false; + ClearLastResult(); + + //Argument check + SysTryReturnResult(NID_MSG, filePath.GetLength() > 0, E_INVALID_ARG, "[E_INVALID_ARG] The file path is empty."); + SysTryReturnResult(NID_MSG, filePath.GetLength() <= PATH_MAX, E_INVALID_ARG, "[E_INVALID_ARG] The file path is too long."); + + isFileExist = File::IsFileExist(filePath); + + r = GetLastResult(); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_INVALID_ARG , E_INVALID_ARG, "[E_INVALID_ARG] Propagating."); + SysTryCatch(NID_MSG, isFileExist == true, r = E_FILE_NOT_FOUND , E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] Propagating."); + + r = _DetailedEmailMessageImpl::ParseMimeFile(filePath, message); + return r; + +CATCH: + SetLastResult(GetLastResult()); + return r; +} + +result +DetailedEmailMessage::WriteToMimeFile(const DetailedEmailMessage& message, const Tizen::Base::String& filePath) +{ + result r = E_SUCCESS; + bool isFileExist = false; + ClearLastResult(); + + //Argument check + SysTryReturnResult(NID_MSG, filePath.GetLength() > 0, E_INVALID_ARG, "[E_INVALID_ARG] The file path is empty."); + SysTryReturnResult(NID_MSG, filePath.GetLength() <= PATH_MAX, E_INVALID_ARG, "[E_INVALID_ARG] The file path is too long."); + + isFileExist = File::IsFileExist(filePath); + + r = GetLastResult(); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_INVALID_ARG , E_INVALID_ARG, "[E_INVALID_ARG] Propagating."); + SysTryCatch(NID_MSG, isFileExist == false, r = E_FILE_ALREADY_EXIST , E_FILE_ALREADY_EXIST, "[E_FILE_ALREADY_EXIST] Propagating."); + + r = _DetailedEmailMessageImpl::WriteToMimeFile(message, filePath); + return r; + +CATCH: + SetLastResult(GetLastResult()); + return r; +} + +} } // Tizen::Messaging diff --git a/src/FMsgEmailAttachment.cpp b/src/FMsgEmailAttachment.cpp new file mode 100644 index 0000000..5113543 --- /dev/null +++ b/src/FMsgEmailAttachment.cpp @@ -0,0 +1,200 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgEmailAttachment.cpp + * @brief This is the implementation file for the %EmailAttachment class. + * + * This file contains the implementation of the %EmailAttachment class. + */ + +#include +#include +#include +#include +#include +#include +#include "FMsg_EmailAttachmentImpl.h" +#include "FMsg_Types.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; +using namespace Tizen::Security; +using namespace Tizen::Io; + +namespace Tizen { namespace Messaging +{ + +EmailAttachment::EmailAttachment(void) +{ + __pImpl = new (std::nothrow) _EmailAttachmentImpl(); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +EmailAttachment::EmailAttachment(const EmailAttachment& value) +{ + __pImpl = new (std::nothrow) _EmailAttachmentImpl(*(value.__pImpl)); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + + +EmailAttachment::~EmailAttachment(void) +{ + if (__pImpl) + { + delete __pImpl; + __pImpl = null; + } +} + +EmailAttachment& +EmailAttachment::operator =(const EmailAttachment& rhs) +{ + if (this != &rhs) + { + *__pImpl = *(rhs.__pImpl); + } + + return (*this); +} + +bool +EmailAttachment::Equals(const Tizen::Base::Object& obj) const +{ + const EmailAttachment* pEmailAttachment = dynamic_cast(&obj); + if (!pEmailAttachment) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + return __pImpl->Equals(*(pEmailAttachment->__pImpl)); +} + +int +EmailAttachment::GetHashCode(void) const +{ + return __pImpl->GetHashCode(); +} + +Tizen::Base::String +EmailAttachment::GetName(void) const +{ + return(__pImpl->GetName()); +} + +Tizen::Base::String +EmailAttachment::GetFilePath(void) const +{ + return(__pImpl->GetFilePath()); +} + +int +EmailAttachment::GetSize(void) const +{ + return(__pImpl->GetSize()); +} + +bool +EmailAttachment::GetInlineContentStatus(void) const +{ + return(__pImpl->GetInlineContentStatus()); +} + +bool +EmailAttachment::GetDrmStatus(void) const +{ + return(__pImpl->GetDrmStatus()); +} + +Tizen::Base::String +EmailAttachment::GetMimeType(void) const +{ + return(__pImpl->GetMimeType()); +} + +result +EmailAttachment::SetName(const Tizen::Base::String& name) +{ + result r = E_SUCCESS; + ClearLastResult(); + + //Argument Check + SysTryReturn(NID_MSG, + name.GetLength() != 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of file name is invalid."); + SysTryReturn(NID_MSG, + name.GetLength() <= MAX_EMAIL_SUBJECT_LENGTH, E_MAX_EXCEEDED, r = E_MAX_EXCEEDED, "The length of file name is invalid."); + + r = __pImpl->SetName(name); + + return r; +} + +result +EmailAttachment::SetFilePath(const Tizen::Base::String& filePath) +{ + result r = E_SUCCESS; + bool isFileExist = false; + ClearLastResult(); + + //Argument Check + SysTryReturnResult(NID_MSG, filePath.GetLength() > 0, E_INVALID_ARG, "[E_INVALID_ARG] The file path is empty."); + SysTryReturnResult(NID_MSG, filePath.GetLength() <= PATH_MAX, E_INVALID_ARG, "[E_INVALID_ARG] The file path is too long."); + + isFileExist = File::IsFileExist(filePath); + + r = GetLastResult(); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_INVALID_ARG , E_INVALID_ARG,"[E_INVALID_ARG] Propagating."); + SysTryCatch(NID_MSG, isFileExist == true, r = E_FILE_NOT_FOUND , E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] Propagating."); + + r = __pImpl->SetFilePath(filePath); + + return r; + +CATCH: + SetLastResult(GetLastResult()); + return r; +} + +void +EmailAttachment::SetInlineContentStatus(bool status) +{ + __pImpl->SetInlineContentStatus(status); +} + +void +EmailAttachment::SetDrmStatus(bool status) +{ + __pImpl->SetDrmStatus(status); +} + +result +EmailAttachment::SetMimeType(const Tizen::Base::String& type) +{ + result r = E_SUCCESS; + ClearLastResult(); + + //Argument Check + SysTryReturn(NID_MSG, + type.GetLength() != 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of mime type is invalid."); + + r = __pImpl->SetMimeType(type); + + return r; +} + +} } // Tizen::Messaging diff --git a/src/FMsgEmailManager.cpp b/src/FMsgEmailManager.cpp new file mode 100755 index 0000000..9a18f4d --- /dev/null +++ b/src/FMsgEmailManager.cpp @@ -0,0 +1,125 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgEmailManager.cpp + * @brief This is the implementation file for the %EmailManager class. + * + * This file contains the implementation of the %EmailManager class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_EmailManagerImpl.h" +#include "FMsg_MsgUtil.h" +#include "FMsg_RecipientListImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ + +EmailManager::EmailManager(void) + : __pImpl(null) +{ +} + +EmailManager::~EmailManager(void) +{ + if (__pImpl) + { + delete __pImpl; + __pImpl = null; + } +} + +result +EmailManager::Construct(IEmailListener& listener) +{ + // method return code + result r = E_SUCCESS; + + SysAssertf(__pImpl == null, "The EmailManager instance is already constructed."); + + // create an _EmailManagerImpl instance + __pImpl = new (std::nothrow) _EmailManagerImpl(); + SysTryReturnResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); + + r = __pImpl->Construct(listener); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to Construct an instance.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +result +EmailManager::Send(const EmailMessage& message, const RecipientList& recipientList, bool saveToSentBox) +{ + result r = E_SUCCESS; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_EMAIL, _PRV_MESSAGING_WRITE); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "The application is not permitted to call this method."); + + + SysAssertf(__pImpl != null, "The EmailManager instance is not constructed yet."); + SysTryReturnResult(NID_MSG, + MAX_EMAIL_RECIPIENT_COUNT >= _RecipientListImpl::GetInstance(recipientList)->GetTotalRecipientCount(), E_MAX_EXCEEDED, + "[E_MAX_EXCEEDED] The number of recipients (%d) exceeds the limit (%d).", + _RecipientListImpl::GetInstance(recipientList)->GetTotalRecipientCount(), MAX_EMAIL_RECIPIENT_COUNT); + SysTryReturnResult(NID_MSG, + 0 != _RecipientListImpl::GetInstance(recipientList)->GetTotalRecipientCount(), E_INVALID_ARG, + "[E_INVALID_ARG] The number of recipients is 0."); + + // email address validity check + r = _MsgUtil::CheckEmailAddressValidity(recipientList); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] There is an invalid email address in the recipient list.", GetErrorMessage(r)); + goto CATCH; + } + + // send an email message + r = __pImpl->Send(message, recipientList, saveToSentBox); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to send the email message.", GetErrorMessage(r)); + goto CATCH; + } + + return E_SUCCESS; + +CATCH: + return r; +} + +} } // Tizen::Messaging diff --git a/src/FMsgEmailMessage.cpp b/src/FMsgEmailMessage.cpp new file mode 100644 index 0000000..6a5e24a --- /dev/null +++ b/src/FMsgEmailMessage.cpp @@ -0,0 +1,249 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgEmailMessage.cpp + * @brief This is the implementation file for the %EmailMessage class. + * + * This file contains the implementation of the %EmailMessage class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_EmailMessageImpl.h" +#include "FMsg_Types.h" +#include "FMsg_MsgUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +namespace Tizen { namespace Messaging +{ + +EmailMessage::EmailMessage(void) +{ + __pImpl = new (std::nothrow) _EmailMessageImpl(); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +EmailMessage::EmailMessage(const EmailMessage& value) +{ + __pImpl = new (std::nothrow) _EmailMessageImpl(*(value.__pImpl)); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +EmailMessage::~EmailMessage(void) +{ + if (__pImpl) + { + delete __pImpl; + __pImpl = null; + } +} + +EmailMessage& +EmailMessage::operator =(const EmailMessage& rhs) +{ + if (this != &rhs) + { + *__pImpl = *(rhs.__pImpl); + } + + return (*this); +} + +bool +EmailMessage::Equals(const Tizen::Base::Object& obj) const +{ + const EmailMessage* pEmailMessage = dynamic_cast(&obj); + if (!pEmailMessage) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + return __pImpl->Equals(*(pEmailMessage->__pImpl));} + +int +EmailMessage::GetHashCode(void) const +{ + return __pImpl->GetHashCode(); +} + +result +EmailMessage::SetSubject(const String& subject) +{ + result r = E_SUCCESS; + + if (subject.GetLength() > MAX_EMAIL_SUBJECT_LENGTH) + { + r = E_MAX_EXCEEDED; + SysLogException(NID_MSG, r, "The length of subject exceeds the limit."); + goto CATCH; + } + + // set subject + r = __pImpl->SetSubject(subject); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to set the subject.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +String +EmailMessage::GetSubject(void) const +{ + return __pImpl->GetSubject(); +} + +result +EmailMessage::SetText(const String& text) +{ + result r = E_SUCCESS; + + if (text.GetLength() > MAX_EMAIL_BODY_TEXT_LENGTH) + { + r = E_MAX_EXCEEDED; + SysLogException(NID_MSG, r, "The length of body text exceeds the limit."); + goto CATCH; + } + + r = __pImpl->SetText(text); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to set the body text.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +String +EmailMessage::GetText(void) const +{ + return __pImpl->GetText(); +} + +result +EmailMessage::AddAttachment(const String& filePath) +{ + SysTryReturnResult(NID_MSG, filePath.GetLength() > 0, E_INVALID_ARG, "[E_INVALID_ARG] The file path is empty."); + SysTryReturnResult(NID_MSG, filePath.GetLength() <= PATH_MAX, E_INVALID_ARG, "[E_INVALID_ARG] The file path is too long."); + + result r = E_SUCCESS; + + // check file existence + if (File::IsFileExist(filePath) == false) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] File not found."); + goto CATCH; + } + + r = __pImpl->AddAttachment(filePath); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add the attachment.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +result +EmailMessage::RemoveAttachment(const Tizen::Base::String& filePath) +{ + SysTryReturnResult(NID_MSG, filePath.GetLength() > 0, E_INVALID_ARG, "[E_INVALID_ARG] The file path is empty."); + SysTryReturnResult(NID_MSG, filePath.GetLength() <= PATH_MAX, E_INVALID_ARG, "[E_INVALID_ARG] The file path is too long."); + + result r = E_SUCCESS; + + // check file existence + if (File::IsFileExist(filePath) == false) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] File not exist."); + goto CATCH; + } + + r = __pImpl->RemoveAttachment(filePath); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to remove the attachment.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +IList* +EmailMessage::GetAttachmentListN(void) const +{ + result r = E_SUCCESS; + IList* pAttachmentList = null; + + ClearLastResult(); + + pAttachmentList = __pImpl->GetAttachmentListN(); + r = GetLastResult(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to get the attachment list.", GetErrorMessage(r)); + SetLastResult(r); + goto CATCH; + } + + return pAttachmentList; + +CATCH: + if (pAttachmentList) + { + if (pAttachmentList->GetCount() > 0) + { + pAttachmentList->RemoveAll(true); + } + delete pAttachmentList; + pAttachmentList = null; + } + + return null; +} + +} } // Tizen::Messaging diff --git a/src/FMsgEtwsPrimaryNotification.cpp b/src/FMsgEtwsPrimaryNotification.cpp new file mode 100644 index 0000000..be0be7a --- /dev/null +++ b/src/FMsgEtwsPrimaryNotification.cpp @@ -0,0 +1,202 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgEtwsPrimaryNotification.cpp + * @brief This is the implementation file for the %EtwsPrimaryNotification class. + * + * This file contains the implementation of the %EtwsPrimaryNotification class. + */ + +#include +#include +#include +#include +#include +#include +#include "FMsg_Types.h" +#include "FMsg_EtwsPrimaryNotificationImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ + +EtwsPrimaryNotification::EtwsPrimaryNotification(void) +{ + __pEtwsPrimaryNotificationImpl = new (std::nothrow) _EtwsPrimaryNotificationImpl(); + SysTryReturnVoidResult(NID_MSG, __pEtwsPrimaryNotificationImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +EtwsPrimaryNotification::EtwsPrimaryNotification(const EtwsPrimaryNotification& value) +{ + __pEtwsPrimaryNotificationImpl = new (std::nothrow) _EtwsPrimaryNotificationImpl(*(value.__pEtwsPrimaryNotificationImpl)); + SysTryReturnVoidResult(NID_MSG, __pEtwsPrimaryNotificationImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +EtwsPrimaryNotification::~EtwsPrimaryNotification(void) +{ + if (__pEtwsPrimaryNotificationImpl) + { + delete __pEtwsPrimaryNotificationImpl; + } + __pEtwsPrimaryNotificationImpl = null; +} + +EtwsPrimaryNotification& +EtwsPrimaryNotification::operator =(const EtwsPrimaryNotification& rhs) +{ + if (this != &rhs) + { + *__pEtwsPrimaryNotificationImpl = *(rhs.__pEtwsPrimaryNotificationImpl); + } + + return (*this); +} + +EtwsPrimaryNotification* +EtwsPrimaryNotification::CloneN() const +{ + return __pEtwsPrimaryNotificationImpl->CloneN(); +} + +bool +EtwsPrimaryNotification::Equals(const Tizen::Base::Object& obj) const +{ + const EtwsPrimaryNotification* pEtwsPrimaryNotification = dynamic_cast(&obj); + if (!pEtwsPrimaryNotification) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + return __pEtwsPrimaryNotificationImpl->Equals(*(pEtwsPrimaryNotification->__pEtwsPrimaryNotificationImpl)); +} + +int +EtwsPrimaryNotification::GetHashCode(void) const +{ + return __pEtwsPrimaryNotificationImpl->GetHashCode(); +} + +Tizen::Base::ByteBuffer* +EtwsPrimaryNotification::GetSerialNumberN(void) const +{ + result r = E_SUCCESS; + Tizen::Base::ByteBuffer* pSerialnumber = null; + ClearLastResult(); + + SysAssertf(__pEtwsPrimaryNotificationImpl != null, "The CbsChannel instance is not constructed yet."); + + pSerialnumber = __pEtwsPrimaryNotificationImpl->GetSerialNumberN(); + + r = GetLastResult(); + SetLastResult(r); + + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "failed to get cbs message SerialNumber ."); + + return pSerialnumber; + +CATCH: + SetLastResult(GetLastResult()); + + if (pSerialnumber) + { + delete pSerialnumber; + pSerialnumber = null; + } + return null; +} + +Tizen::Base::DateTime +EtwsPrimaryNotification::GetReceivedTime(void) const +{ + SysAssertf(__pEtwsPrimaryNotificationImpl != null, "The CbsChannel instance is not constructed yet."); + + return (__pEtwsPrimaryNotificationImpl->GetReceivedTime()); +} + +Tizen::Base::ByteBuffer* +EtwsPrimaryNotification::GetWarningSecurityInfoN(void) const +{ + result r = E_SUCCESS; + Tizen::Base::ByteBuffer* pSecurityInfo = null; + ClearLastResult(); + + SysAssertf(__pEtwsPrimaryNotificationImpl != null, "The CbsChannel instance is not constructed yet."); + + pSecurityInfo = __pEtwsPrimaryNotificationImpl->GetWarningSecurityInfoN(); + + r = GetLastResult(); + SetLastResult(r); + + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "failed to get cbs message SerialNumber ."); + + return pSecurityInfo; + +CATCH: + SetLastResult(GetLastResult()); + + if (pSecurityInfo) + { + delete pSecurityInfo; + pSecurityInfo = null; + } + return null; +} + +int +EtwsPrimaryNotification::GetMessageId(void) const +{ + SysAssertf(__pEtwsPrimaryNotificationImpl != null, "The CbsChannel instance is not constructed yet."); + + return (__pEtwsPrimaryNotificationImpl->GetMessageId()); +} + +Tizen::Base::ByteBuffer* +EtwsPrimaryNotification::GetWarningTypeN(void) const +{ + SysAssertf(__pEtwsPrimaryNotificationImpl != null, "The CbsChannel instance is not constructed yet."); + + result r = E_SUCCESS; + Tizen::Base::ByteBuffer* pWarningType = null; + ClearLastResult(); + + SysAssertf(__pEtwsPrimaryNotificationImpl != null, "The CbsChannel instance is not constructed yet."); + + pWarningType = __pEtwsPrimaryNotificationImpl->GetWarningTypeN(); + + r = GetLastResult(); + SetLastResult(r); + + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "failed to get cbs Warning type ."); + + return pWarningType; + +CATCH: + SetLastResult(GetLastResult()); + + if (pWarningType) + { + delete pWarningType; + pWarningType = null; + } + return null; +} + +} } // Tizen::Messaging diff --git a/src/FMsgMmsManager.cpp b/src/FMsgMmsManager.cpp new file mode 100755 index 0000000..115812e --- /dev/null +++ b/src/FMsgMmsManager.cpp @@ -0,0 +1,146 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgMmsManager.cpp + * @brief This is the implementation file for the %MmsManager class. + * + * This file contains the implementation of the %MmsManager class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_Types.h" +#include "FMsg_MmsEvent.h" +#include "FMsg_MsgUtil.h" +#include "FMsg_MmsManagerImpl.h" +#include "FMsg_RecipientListImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ + +MmsManager::MmsManager(void) + : __pImpl(null) +{ +} + +MmsManager::~MmsManager(void) +{ + if (__pImpl) + { + delete __pImpl; + __pImpl = null; + } +} + +result +MmsManager::Construct(IMmsListener& listener) +{ + // method return code + result r = E_SUCCESS; + bool isMmsSupported = false; + + SysAssertf(__pImpl == null, "The MmsManager instance is already constructed."); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony.mms", isMmsSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isMmsSupported == true), E_UNSUPPORTED_OPERATION, " MMS is not supported."); + + // create an _MmsManagerImpl instance + __pImpl = new (std::nothrow) _MmsManagerImpl(); + SysTryReturn(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "Failed to allocate memory"); + + r = __pImpl->Construct(listener); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct an instance.", GetErrorMessage(r)); + + return r; + +CATCH: + if (__pImpl) + { + delete __pImpl; + __pImpl = null; + } + + return r; +} + +result +MmsManager::Send(const MmsMessage& message, const RecipientList& recipientList, bool saveToSentBox) +{ + result r = E_SUCCESS; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_MMS, _PRV_MESSAGING_WRITE); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "The application is not permitted to call this method."); + + SysAssertf(__pImpl != null, "The MmsManager instance is not constructed yet."); + SysTryReturnResult(NID_MSG, + MAX_MMS_RECIPIENT_COUNT >= _RecipientListImpl::GetInstance(recipientList)->GetTotalRecipientCount(), E_MAX_EXCEEDED, + "The number of recipients exceeds the limit (%d).", MAX_MMS_RECIPIENT_COUNT); + SysTryReturnResult(NID_MSG, + 0 != _RecipientListImpl::GetInstance(recipientList)->GetTotalRecipientCount(), E_INVALID_ARG, + "[E_INVALID_ARG] The number of recipients is 0."); + + //////////////////////////////////////////////////////////////////////////////// + // address-check will be done in SHP layer. + //////////////////////////////////////////////////////////////////////////////// + + // mms address validity check + r = _MsgUtil::CheckPhoneNumberValidity(_MSG_MMS, recipientList); + + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] There is an invalid phone number in the recipient list.", GetErrorMessage(r)); + goto CATCH; + } + + // not allow the empty message. + if (message.GetSubject().IsEmpty() && message.GetText().IsEmpty() && message.GetAttachment(MMS_IMAGE).IsEmpty() && + message.GetAttachment(MMS_AUDIO).IsEmpty() && message.GetAttachment(MMS_VIDEO).IsEmpty()) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The message is empty."); + return E_INVALID_ARG; + } + + // send an MMS message + r = __pImpl->Send(message, recipientList, saveToSentBox); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to send the MMS message.", GetErrorMessage(r)); + goto CATCH; + } + + return E_SUCCESS; + +CATCH: + return r; +} +} } // Tizen::Messaging diff --git a/src/FMsgMmsMessage.cpp b/src/FMsgMmsMessage.cpp new file mode 100644 index 0000000..037a2e5 --- /dev/null +++ b/src/FMsgMmsMessage.cpp @@ -0,0 +1,232 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgMmsMessage.cpp + * @brief This is the implementation file for the %MmsMessage class. + * + * This file contains the implementation of the %MmsMessage class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_MmsMessageImpl.h" +#include "FMsg_Types.h" +#include "FMsg_MsgUtil.h" + +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +namespace Tizen { namespace Messaging +{ + +MmsMessage::MmsMessage(void) +{ + __pImpl = new (std::nothrow) _MmsMessageImpl(); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +MmsMessage::MmsMessage(const MmsMessage& value) +{ + __pImpl = new (std::nothrow) _MmsMessageImpl(*(value.__pImpl)); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +MmsMessage::~MmsMessage(void) +{ + if (__pImpl) + { + delete __pImpl; + __pImpl = null; + } +} + +MmsMessage& +MmsMessage::operator =(const MmsMessage& rhs) +{ + if (this != &rhs) + { + *__pImpl = *(rhs.__pImpl); + } + + return (*this); +} + +bool +MmsMessage::Equals(const Tizen::Base::Object& obj) const +{ + const MmsMessage* pMmsMessage = dynamic_cast(&obj); + if (!pMmsMessage) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + return __pImpl->Equals(*(pMmsMessage->__pImpl)); +} + +int +MmsMessage::GetHashCode(void) const +{ + return __pImpl->GetHashCode(); +} + +result +MmsMessage::SetSubject(const String& subject) +{ + result r = E_SUCCESS; + + if (subject.GetLength() > MAX_MMS_SUBJECT_LENGTH) + { + r = E_MAX_EXCEEDED; + SysLogException(NID_MSG, r, "The length of subject exceeds the limit."); + goto CATCH; + } + + // set subject + r = __pImpl->SetSubject(subject); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to set the subject.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +String +MmsMessage::GetSubject(void) const +{ + return __pImpl->GetSubject(); +} + +result +MmsMessage::SetText(const String& text) +{ + result r = E_SUCCESS; + + if (text.GetLength() > MAX_MMS_BODY_TEXT_LENGTH) + { + r = E_MAX_EXCEEDED; + SysLogException(NID_MSG, r, "The length of body text exceeds the limit."); + goto CATCH; + } + + // set subject + r = __pImpl->SetText(text); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to set the text.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +String +MmsMessage::GetText(void) const +{ + return __pImpl->GetText(); +} + +result +MmsMessage::AddAttachment(MmsAttachmentFormat format, const Tizen::Base::String& filePath) +{ + result r = E_SUCCESS; + + // firstly, argument check + SysTryReturn(NID_MSG, (format >= MMS_IMAGE && format <= MMS_VCALENDAR), E_INVALID_ARG, r = E_INVALID_ARG, + "[E_INVALID_ARG] invalid MmsAttachmentFormat[%d] arguments.", (int) format); + + SysTryReturn(NID_MSG, filePath.GetLength() > 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The file path is empty."); + SysTryReturn(NID_MSG, filePath.GetLength() <= PATH_MAX, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The file path is too long."); + + r = __pImpl->AddAttachment(format, filePath); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add an attachment.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +result +MmsMessage::RemoveAttachment(MmsAttachmentFormat format) +{ + result r = E_SUCCESS; + + // firstly, argument check + SysTryReturn(NID_MSG, (format >= MMS_IMAGE && format <= MMS_VCALENDAR), E_INVALID_ARG, r = E_INVALID_ARG, + "[E_INVALID_ARG] invalid MmsAttachmentFormat[%d] arguments.", (int) format); + + r = __pImpl->RemoveAttachment(format); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to remove an attachment.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +String +MmsMessage::GetAttachment(MmsAttachmentFormat format) const +{ + String returnValue; + + ClearLastResult(); + + // firstly, argument check + + if (format < MMS_IMAGE || format > MMS_VCALENDAR) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] invalid MmsAttachmentFormat[%d] arguments.", (int) format); + returnValue = L""; + return returnValue; + } + + // get attachment + returnValue = __pImpl->GetAttachment(format); + SetLastResult(GetLastResult()); + + return returnValue; +} +} } // Tizen::Messaging diff --git a/src/FMsgPushManager.cpp b/src/FMsgPushManager.cpp new file mode 100755 index 0000000..6c3dae3 --- /dev/null +++ b/src/FMsgPushManager.cpp @@ -0,0 +1,210 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** +* @file FMsgPushManager.cpp +* @brief This is the implementation file for the %PushManager class. +* +* This file contains the implementation of the %PushManager class. +*/ + +#include +#include +#include +#include +#include "FMsg_PushManagerImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Security; +using namespace Tizen::System; + +namespace Tizen { namespace Messaging +{ + +PushManager::PushManager(void) + : __pPushManagerImpl(null) +{ +} + +PushManager::~PushManager(void) +{ + delete __pPushManagerImpl; + __pPushManagerImpl = null; +} + +result +PushManager::Construct(IPushManagerListener& managerListener, IPushEventListener& eventListener) +{ + static const wchar_t _PUSH[] = L"http://tizen.org/feature/network.push"; + + result r = E_SUCCESS; + + r = _AccessController::CheckUserPrivilege(_PRV_PUSH); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "The application is not permitted to call this method."); + + + bool isPushSupported = false; + + r = _SystemInfoImpl::GetSysInfo(_PUSH, isPushSupported); + SysTryReturnResult(NID_NET, r == E_SUCCESS && isPushSupported, E_UNSUPPORTED_OPERATION, "Push messaging is not supported."); + + SysAssertf(__pPushManagerImpl == null, + "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); + + __pPushManagerImpl = new (std::nothrow) _PushManagerImpl(); + SysTryReturnResult(NID_MSG, __pPushManagerImpl != null, E_OUT_OF_MEMORY, "Insufficient memory."); + + r = __pPushManagerImpl->Construct(managerListener, eventListener); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Propagating.", GetErrorMessage(r)); + + delete __pPushManagerImpl; + __pPushManagerImpl = null; + } + + return r; +} + +result +PushManager::RegisterPushService(RequestId& reqId) +{ + result r = E_SUCCESS; + + r = _AccessController::CheckUserPrivilege(_PRV_PUSH); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "The application is not permitted to call this method."); + + + SysAssertf(__pPushManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + r = __pPushManagerImpl->RegisterPushService(reqId); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Propagating.", GetErrorMessage(r)); + } + + return r; +} + +result +PushManager::UnregisterPushService(RequestId& reqId) +{ + result r = E_SUCCESS; + + r = _AccessController::CheckUserPrivilege(_PRV_PUSH); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "The application is not permitted to call this method."); + + + SysAssertf(__pPushManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + r = __pPushManagerImpl->UnregisterPushService(reqId); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Propagating.", GetErrorMessage(r)); + } + + return r; +} + +bool +PushManager::IsPushServiceRegistered(void) const +{ + bool isRegistered = false; + + ClearLastResult(); + + SysAssertf(__pPushManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + isRegistered = __pPushManagerImpl->IsPushServiceRegistered(); + + return isRegistered; +} + +IList* +PushManager::GetUnreadMessagesN(void) +{ + result r = E_SUCCESS; + IList* pList = null; + + ClearLastResult(); + + r = _AccessController::CheckUserPrivilege(_PRV_PUSH); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturn(NID_MSG, r == E_SUCCESS, null, r, "The application is not permitted to call this method."); + + SysAssertf(__pPushManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + pList = __pPushManagerImpl->GetUnreadMessagesN(); + r = GetLastResult(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Propagating.", GetErrorMessage(r)); + } + + return pList; +} + +result +PushManager::SendPushMessage(const PushMessage& message, const String& registrationId, const Tizen::Base::String& appSecret, RequestId& reqId) +{ + result r = E_SUCCESS; + + r = _AccessController::CheckUserPrivilege(_PRV_PUSH); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "The application is not permitted to call this method."); + + SysAssertf(__pPushManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + r = __pPushManagerImpl->SendPushMessage(message, registrationId, appSecret, reqId); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Propagating.", GetErrorMessage(r)); + } + + return r; +} + +result +PushManager::SendPushMessage(const PushMessage& message, const IList& registrationIdList, const Tizen::Base::String& appSecret, RequestId& reqId) +{ + result r = E_SUCCESS; + + r = _AccessController::CheckUserPrivilege(_PRV_PUSH); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "The application is not permitted to call this method."); + + SysAssertf(__pPushManagerImpl != null, "Not yet constructed. Construct() should be called before use."); + + r = __pPushManagerImpl->SendPushMessage(message, registrationIdList, appSecret, reqId); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Propagating.", GetErrorMessage(r)); + } + + return r; +} + +int +PushManager::GetMaxRecipientCount(void) +{ + return _PushManagerImpl::GetMaxRecipientCount(); +} + +} } // Tizen::Messaging diff --git a/src/FMsgPushMessage.cpp b/src/FMsgPushMessage.cpp new file mode 100644 index 0000000..f7d3a97 --- /dev/null +++ b/src/FMsgPushMessage.cpp @@ -0,0 +1,131 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** +* @file FMsgPushMessage.cpp +* @brief This is the implementation file for the %PushMessage class. +* +* This file contains the implementation of the %PushMessage class. +*/ + +#include +#include +#include "FMsg_PushMessageImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Shell; + +namespace Tizen { namespace Messaging +{ + +PushMessage::PushMessage(void) +{ + __pPushMessageImpl = new (std::nothrow) _PushMessageImpl(); + SysTryReturnVoidResult(NID_MSG, __pPushMessageImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory."); +} + +PushMessage::PushMessage(const DateTime& dateTime, const String& text) +{ + __pPushMessageImpl = new (std::nothrow) _PushMessageImpl(dateTime, text); + SysTryReturnVoidResult(NID_MSG, __pPushMessageImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory."); +} + +PushMessage::~PushMessage(void) +{ + delete __pPushMessageImpl; + __pPushMessageImpl = null; +} + +PushMessage::PushMessage(const PushMessage& rhs) +{ + __pPushMessageImpl = new (std::nothrow) _PushMessageImpl(*(rhs.__pPushMessageImpl)); + SysTryReturnVoidResult(NID_MSG, __pPushMessageImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory."); +} + +PushMessage& +PushMessage::operator =(const PushMessage& rhs) +{ + if (this == &rhs) + { + return *this; + } + + *__pPushMessageImpl = *rhs.__pPushMessageImpl; + + return *this; +} + +bool +PushMessage::Equals(const Object& obj) const +{ + const PushMessage* pRhs = dynamic_cast(&obj); + if (pRhs == null) + { + return false; + } + + const _PushMessageImpl* pRhsImpl = _PushMessageImpl::GetInstance(*pRhs); + if (pRhsImpl == null) + { + return false; + } + + return __pPushMessageImpl->Equals(*pRhsImpl); +} + +int +PushMessage::GetHashCode(void) const +{ + return __pPushMessageImpl->GetHashCode(); +} + +DateTime +PushMessage::GetReceivedTime(void) const +{ + return __pPushMessageImpl->GetReceivedTime(); +} + +String +PushMessage::GetText(void) const +{ + return __pPushMessageImpl->GetText(); +} + +result +PushMessage::SetAction(PushAction action) +{ + return __pPushMessageImpl->SetAction(action); +} + +PushAction +PushMessage::GetAction(void) const +{ + return __pPushMessageImpl->GetAction(); +} + +result +PushMessage::SetNotification(const NotificationRequest& notificationRequest) +{ + return __pPushMessageImpl->SetNotification(notificationRequest); +} + +NotificationRequest +PushMessage::GetNotification(void) const +{ + return __pPushMessageImpl->GetNotification(); +} + +} } // Tizen::Messaging diff --git a/src/FMsgRecipientList.cpp b/src/FMsgRecipientList.cpp new file mode 100644 index 0000000..ef34078 --- /dev/null +++ b/src/FMsgRecipientList.cpp @@ -0,0 +1,205 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgRecipientList.cpp + * @brief This is the implementation file for the %RecipientList class. + * + * This file contains the implementation of the %RecipientList class. + */ + +#include +#include +#include "FMsg_RecipientListImpl.h" +#include "FMsg_Types.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +namespace Tizen { namespace Messaging +{ + +RecipientList::RecipientList(void) +{ + __pImpl = new (std::nothrow) _RecipientListImpl(); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +RecipientList::~RecipientList(void) +{ + if (__pImpl) + { + delete __pImpl; + __pImpl = null; + } +} + +RecipientList::RecipientList(const RecipientList& value) +{ + __pImpl = new (std::nothrow) _RecipientListImpl(*(value.__pImpl)); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +RecipientList& +RecipientList::operator =(const RecipientList& value) +{ + if (this != &value) + { + *__pImpl = *(value.__pImpl); + } + + return (*this); +} + +bool +RecipientList::operator ==(const RecipientList& rhs) const +{ + return (Equals(rhs)); +} + +bool +RecipientList::operator !=(const RecipientList& rhs) const +{ + return (!Equals(rhs)); +} + +bool +RecipientList::Equals(const Tizen::Base::Object& value) const +{ + const RecipientList* pRecipientList = dynamic_cast(&value); + if (!pRecipientList) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + return __pImpl->Equals(*(pRecipientList->__pImpl)); +} + +int +RecipientList::GetHashCode(void) const +{ + return __pImpl->GetHashCode(); +} + +result +RecipientList::Add(RecipientType type, const String& recipient) +{ + result r = E_SUCCESS; + + SysTryReturn(NID_MSG, (type >= RECIPIENT_TYPE_TO && type <= RECIPIENT_TYPE_BCC), E_INVALID_ARG, r = E_INVALID_ARG, + "[E_INVALID_ARG] Invalid RecipientType [%d] argument.", + (int) type); + SysTryReturn(NID_MSG, (recipient.GetLength() >= MIN_LENGTH_PHONE) && (recipient.GetLength() <= MAX_LENGTH_EMAIL), E_INVALID_ARG, + r = E_INVALID_ARG, "[E_INVALID_ARG] The length (%d) of the phone number or email address is too short or too long.", recipient.GetLength()); + + r = __pImpl->Add(type, recipient); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add the recipient.", GetErrorMessage(r)); + goto CATCH; + } + + return E_SUCCESS; + +CATCH: + return r; +} + +result +RecipientList::Remove(RecipientType type, const Tizen::Base::String& recipient) +{ + result r = E_SUCCESS; + + SysTryReturn(NID_MSG, (type >= RECIPIENT_TYPE_TO && type <= RECIPIENT_TYPE_BCC), E_INVALID_ARG, r = E_INVALID_ARG, + "[E_INVALID_ARG] Invalid RecipientType [%d] argument.", + (int) type); + SysTryReturn(NID_MSG, (recipient.GetLength() >= MIN_LENGTH_PHONE) && (recipient.GetLength() <= MAX_LENGTH_EMAIL), E_INVALID_ARG, + r = E_INVALID_ARG, "[E_INVALID_ARG] The length (%d) of the phone number or email address is too short or too long.", recipient.GetLength()); + + r = __pImpl->Remove(type, recipient); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to remove the recipient.", GetErrorMessage(r)); + goto CATCH; + } + + return E_SUCCESS; + +CATCH: + return r; +} + +result +RecipientList::Set(RecipientType type, const Tizen::Base::Collection::IList& list) +{ + result r = E_SUCCESS; + + SysTryReturn(NID_MSG, (type >= RECIPIENT_TYPE_TO && type <= RECIPIENT_TYPE_BCC), E_INVALID_ARG, + r = E_INVALID_ARG, "[E_INVALID_ARG] Invalid RecipientType [%d] argument.", + (int) type); + + if (list.GetCount() == 0) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The input list has no item."); + goto CATCH; + } + + for (int index = 0; index < list.GetCount(); index++) + { + String* pItem = (String*) (list.GetAt(index)); + if (pItem->GetLength() < MIN_LENGTH_PHONE || pItem->GetLength() > MAX_LENGTH_EMAIL) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The length of a recipient in the input list is invalid (too short or too long)."); + goto CATCH; + } + } + + r = __pImpl->Set(type, list); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to set the corresponding recipient list.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +Tizen::Base::Collection::IList* +RecipientList::GetListN(RecipientType type) const +{ + //ArrayList* pRetRecipient = null; + ClearLastResult(); + IList* pRetRecipient = null; + + if (type < RECIPIENT_TYPE_TO || type > RECIPIENT_TYPE_BCC) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] Invalid RecipientType argument."); + return null; + } + + pRetRecipient = __pImpl->GetListN(type); + SetLastResult(GetLastResult()); + + return pRetRecipient; +} +} } // Tizen::Messaging diff --git a/src/FMsgSmsManager.cpp b/src/FMsgSmsManager.cpp new file mode 100755 index 0000000..93578db --- /dev/null +++ b/src/FMsgSmsManager.cpp @@ -0,0 +1,768 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgSmsManager.cpp + * @brief This is the implementation file for the %SmsManager class. + * + * This file contains the implementation of the %SmsManager class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_SmsManagerImpl.h" +#include "FMsg_Types.h" +#include "FMsg_SmsEvent.h" +#include "FMsg_MsgUtil.h" +#include "FMsg_RecipientListImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ + +SmsManager::SmsManager(void) + : __pImpl(null) +{ +} + +SmsManager::~SmsManager(void) +{ + if (__pImpl) + { + delete __pImpl; + __pImpl = null; + } +} + +result +SmsManager::Construct(ISmsListener& listener) +{ + // method return code + result r = E_SUCCESS; + bool isSmsSupported = false; + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony", isSmsSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isSmsSupported == true), E_UNSUPPORTED_OPERATION, " SMS is not supported."); + + SysAssertf(__pImpl == null, "The SmsManager instance is already constructed."); + + // create an _SmsManagerImpl instance + __pImpl = new (std::nothrow) _SmsManagerImpl(); + SysTryReturnResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); + + r = __pImpl->Construct(listener); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct an instance.", GetErrorMessage(r)); + + return r; + +CATCH: + return r; +} + +result +SmsManager::AddSmsEventListener(int port, ISmsEventListener& eventListener) +{ + result r = E_SUCCESS; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_SMSTRIGGER); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagated."); + + // checking conditions + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + // checking argument + SysTryReturn(NID_MSG, (port >= 1 && port <= 9999), E_INVALID_ARG, r = E_INVALID_ARG, + "[E_INVALID_ARG] The port number should range from 1 to 9999 (1 <= port <= 9999)."); + + r = __pImpl->AddSmsEventListener(port, eventListener); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to register the event listener with port [%d].", GetErrorMessage(r), port); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +result +SmsManager::RemoveSmsEventListener(int port, ISmsEventListener& eventListener) +{ + result r = E_SUCCESS; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_SMSTRIGGER); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagating."); + + // checking conditions + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + // checking argument + SysTryReturn(NID_MSG, (port >= 1 && port <= 9999), E_INVALID_ARG, r = E_INVALID_ARG, + "[E_INVALID_ARG] The port number should range from 1 to 9999 (1 <= port <= 9999)."); + + r = __pImpl->RemoveSmsEventListener(port, eventListener); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to unregister the event listener.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +result +SmsManager::AddSmsMessageEventListener(ISmsMessageEventListener& eventListener) +{ + result r = E_SUCCESS; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "The application is not permitted to call this method."); + + // checking conditions + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + // add listener + r = __pImpl->AddSmsMessageEventListener(eventListener); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add a listener.", GetErrorMessage(r)); + goto CATCH; + } + + + return E_SUCCESS; + +CATCH: + return r; +} + +result +SmsManager::RemoveSmsMessageEventListener(ISmsMessageEventListener& eventListener) +{ + result r = E_SUCCESS; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "The application is not permitted to call this method."); + + // checking conditions + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + r = __pImpl->RemoveSmsMessageEventListener(eventListener); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to remove a listener.", GetErrorMessage(r)); + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +int +SmsManager::GetTotalMessageCount(SmsMessageBoxType type) const +{ + result r = E_SUCCESS; + int count = 0; + ClearLastResult(); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturn(NID_MSG, r == E_SUCCESS, -1, r, "The application is not permitted to call this method."); + + // checking condition + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + // checking argument + if (type <= SMS_MESSAGE_BOX_TYPE_NONE || type > SMS_MESSAGE_BOX_TYPE_ALL) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] Invalid SmsMessageBoxType argument."); + return -1; + } + if (type > SMS_MESSAGE_BOX_TYPE_OUTBOX && type < SMS_MESSAGE_BOX_TYPE_ALL) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] Invalid SmsMessageBoxType argument."); + return -1; + } + + count = __pImpl->GetTotalMessageCount(type); + r = GetLastResult(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] exception occurred. Failed to get SMS total count. type:[%d].", GetErrorMessage(r), (int) type); + SetLastResult(r); + return -1; + } + + return count; +} + +Tizen::Base::Collection::IList* +SmsManager::SearchInboxN(const Tizen::Base::String* pKeyword, const Tizen::Base::String* pSenderAddress, int startIndex, int count, + int& totalResultCount) const +{ + IList* pList = null; + result r = E_SUCCESS; + + ClearLastResult(); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryCatch(NID_MSG, r == E_SUCCESS, ,r, "The application is not permitted to call this method."); + + // checking condition + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + // checking arguments + if (pKeyword) + { + if (pKeyword->GetLength() == MIN_KEYWORD_LENGTH || pKeyword->GetLength() > MAX_KEYWORD_LENGTH) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] The specified keyword string length [%d] is smaller than 2 or greater than 30.", + pKeyword->GetLength()); + goto CATCH; + } + } + + if (pSenderAddress) + { + if (!pSenderAddress->IsEmpty()) + { + if (pSenderAddress->GetLength() < MIN_LENGTH_PHONE || pSenderAddress->GetLength() > MAX_LENGTH_PHONE) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), + "[E_INVALID_ARG] The length of the given sender address should be greater than 3 and less than 41."); + goto CATCH; + } + else if (_MsgUtil::IsValidPhoneNumber(*pSenderAddress) != true) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] The sender address may contain non-digit characters."); + goto CATCH; + } + } + } + + if (startIndex < 0) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] The start index [%d] should be equal to or greater than 0.", startIndex); + goto CATCH; + } + + if (count < 0 || count > 20) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] The count value [%d] is too small (< 0) or too big (> 20).", count); + goto CATCH; + } + + + if (count == 0) + { + SetLastResult(E_SUCCESS); + totalResultCount = 0; + return null; + } + + // searching... + pList = __pImpl->SearchInboxN(pKeyword, pSenderAddress, startIndex, count, totalResultCount); + r = GetLastResult(); + if (IsFailed(r) || !pList) + { + SetLastResult(r); + SysLogException(NID_MSG, r, "[%s] Failed to search.", GetErrorMessage(r)); + goto CATCH; + } + + return pList; + +CATCH: + if (pList) + { + if (pList->GetCount() > 0) + { + pList->RemoveAll(true); + } + delete pList; + pList = null; + } + return null; +} + +Tizen::Base::Collection::IList* +SmsManager::SearchMessageBoxN(SmsMessageBoxType type, const Tizen::Base::String* pKeyword, int startIndex, int count, + int& totalResultCount) const +{ + IList* pList = null; + result r = E_SUCCESS; + + ClearLastResult(); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryCatch(NID_MSG, r == E_SUCCESS, ,r, "The application is not permitted to call this method."); + + // checking condition + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + // checking sms message box type argument + if (type <= SMS_MESSAGE_BOX_TYPE_NONE || type > SMS_MESSAGE_BOX_TYPE_ALL) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] The SmsMessageBoxType value [%d] is invalid.", (int) type); + goto CATCH; + } + + if (type > SMS_MESSAGE_BOX_TYPE_OUTBOX && type < SMS_MESSAGE_BOX_TYPE_ALL) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] The SmsMessageBoxType value [%d] is invalid.", (int) type); + goto CATCH; + } + + // checking keyword arguments + if (pKeyword) + { + if (pKeyword->GetLength() == MIN_KEYWORD_LENGTH || pKeyword->GetLength() > MAX_KEYWORD_LENGTH) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] The specified keyword string length [%d] is smaller than 2 or greater than 30.", + pKeyword->GetLength()); + goto CATCH; + } + } + + // checking start index argument + if (startIndex < 0) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] The start index [%d] should be equal to or greater than 0.", startIndex); + goto CATCH; + } + + // checking count argument + if (count < 0 || count > 20) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] The count value [%d] is too small (< 0) or too big (> 20).", count); + goto CATCH; + } + + if (count == 0) + { + SetLastResult(E_SUCCESS); + totalResultCount = 0; + return null; + } + + // searching... + pList = __pImpl->SearchMessageBoxN(type, pKeyword, startIndex, count, totalResultCount); + r = GetLastResult(); + if (IsFailed(r) || !pList) + { + SetLastResult(r); + SysLogException(NID_MSG, r, "[%s] Failed to search.", GetErrorMessage(r)); + goto CATCH; + } + + return pList; + +CATCH: + if (pList) + { + if (pList->GetCount() > 0) + { + pList->RemoveAll(true); + } + delete pList; + pList = null; + } + return null; +} + +Tizen::Base::String +SmsManager::GetFullText(int messageId) const +{ + result r = E_SUCCESS; + String fullText; + + ClearLastResult(); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "The application is not permitted to call this method."); + + // checking condition + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + // checking argument + if (messageId < 0) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[%s] exception occurred. The value [%d] of message ID is invalid.", GetErrorMessage(r), messageId); + goto CATCH; + } + + fullText = __pImpl->GetFullText(messageId); + r = GetLastResult(); + if (IsFailed(r)) + { + SetLastResult(r); + SysLogException(NID_MSG, r, "[%s] exception occurred. Failed to get SMS message using message ID [%d].", GetErrorMessage( + r), messageId); + goto CATCH; + } + + SysLog(NID_MSG, "Returned Full Text : [%ls]", fullText.GetPointer()); + + return fullText; + +CATCH: + return L""; +} + +result +SmsManager::Send(const SmsMessage& message, const RecipientList& recipientList, bool saveToSentBox) +{ + result r = E_SUCCESS; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_WRITE); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "The application is not permitted to call this method."); + + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + SysTryReturnResult(NID_MSG, + MAX_SMS_RECIPIENT_COUNT >= _RecipientListImpl::GetInstance(recipientList)->GetTotalRecipientCount(), E_MAX_EXCEEDED, + "[E_MAX_EXCEEDED] The number of recipients exceeds the limit (%d).", MAX_SMS_RECIPIENT_COUNT); + SysTryReturnResult(NID_MSG, + 0 < _RecipientListImpl::GetInstance(recipientList)->GetTotalRecipientCount(), E_INVALID_ARG, "[E_INVALID_ARG] The number of recipients is 0."); + + // check the validity of the phone number in recipient list + r = _MsgUtil::CheckPhoneNumberValidity(_MSG_SMS, recipientList); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] There is an invalid phone number in the recipient list.", GetErrorMessage(r)); + goto CATCH; + } + + // send an SMS message + r = __pImpl->Send(message, recipientList, saveToSentBox); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to send the SMS message.", GetErrorMessage(r)); + goto CATCH; + } + + return E_SUCCESS; + +CATCH: + return r; +} + +result +SmsManager::SetCbsMessageEventListener(ICbsMessageEventListener* pListener) +{ + result r = E_SUCCESS; + bool isCbsSupported = false; + + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony.sms.cbs", isCbsSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isCbsSupported == true), E_UNSUPPORTED_OPERATION, " CBS is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagated."); + + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + // add listener + r = __pImpl->SetCbsMessageEventListener(pListener); + + return r; +} + +result +SmsManager::SetEtwsPrimaryNotificationEventListener(IEtwsPrimaryNotificationEventListener* pListener) +{ + result r = E_SUCCESS; + bool isCbsSupported = false; + + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony.sms.cbs", isCbsSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isCbsSupported == true), E_UNSUPPORTED_OPERATION, " CBS is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagated."); + + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + // add listener + r = __pImpl->SetEtwsPrimaryNotificationEventListener(pListener); + + return r; +} + +result +SmsManager::SetSavingToCbsBoxEnabled(bool enable) +{ + result r = E_SUCCESS; + bool isCbsSupported = false; + + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony.sms.cbs", isCbsSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isCbsSupported == true), E_UNSUPPORTED_OPERATION, " CBS is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagated."); + + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + r = __pImpl->SetSavingToCbsBoxEnabled(enable); + + return r; +} + +bool +SmsManager::IsCbsEnabled(void) const +{ + result r = E_SUCCESS; + bool isCbsEnabled = false; + + ClearLastResult(); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagated."); + + + // checking conditions + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + + + isCbsEnabled = __pImpl->IsCbsEnabled(); + + r = GetLastResult(); + SetLastResult(r); + + return isCbsEnabled; + +CATCH: + SetLastResult(r); + return isCbsEnabled; +} + +result +SmsManager::SetCbsEnabled(bool enable) +{ + result r = E_SUCCESS; + bool isCbsSupported = false; + + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony.sms.cbs", isCbsSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isCbsSupported == true), E_UNSUPPORTED_OPERATION, " CBS is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagated."); + + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + r = __pImpl->SetCbsEnabled(enable); + + return r; +} + +result +SmsManager::AddCbsChannel(int from, int to, Tizen::Base::String& name, bool activate) +{ + result r = E_SUCCESS; + bool isCbsSupported = false; + + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony.sms.cbs", isCbsSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isCbsSupported == true), E_UNSUPPORTED_OPERATION, " CBS is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagated."); + + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + // argument check + SysTryReturn(NID_MSG, + name.GetLength() <= MAX_CBS_CHANNEL_NAME_LENGTH, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] invalid channel name."); + SysTryReturn(NID_MSG, + ((to >= 0) && (from >= 0) && (to >= from) && (to <= MAX_CBS_CHANNEL_LIMIT) && ((to - from) <= MAX_CBS_CHANNEL_RANGE)), + E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] Failed to add construct channel, invalid arguments."); + + r = __pImpl->AddCbsChannel(from, to, name, activate); + + return r; +} + +result +SmsManager::RemoveCbsChannel(int from, int to) +{ + result r = E_SUCCESS; + bool isCbsSupported = false; + + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony.sms.cbs", isCbsSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isCbsSupported == true), E_UNSUPPORTED_OPERATION, " CBS is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagated."); + + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + SysTryReturn(NID_MSG, + ((to >= 0) && (from >= 0) && (to >= from) && (to <= MAX_CBS_CHANNEL_LIMIT) && ((to - from) <= MAX_CBS_CHANNEL_RANGE)), + E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] Failed to add construct channel, invalid arguments."); + + r = __pImpl->RemoveCbsChannel(from, to); + + return r; +} + +CbsChannel* +SmsManager::GetCbsChannelN(int from, int to) const +{ + result r = E_SUCCESS; + CbsChannel* pCbsChannel = null; + bool isCbsSupported = false; + + ClearLastResult(); + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony.sms.cbs", isCbsSupported); + SysTryReturn(NID_MSG, (r == E_SUCCESS) && (isCbsSupported == true), null, E_UNSUPPORTED_OPERATION, " CBS is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_PRIVILEGE_DENIED, r, "[E_PRIVILEGE_DENIED] Propagated."); + + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + SysTryCatch(NID_MSG, + ((to >= 0) && (from >= 0) && (to >= from) && (to <= MAX_CBS_CHANNEL_LIMIT) && ((to - from) <= MAX_CBS_CHANNEL_RANGE)), + r = E_INVALID_ARG, r, "[E_INVALID_ARG] Failed to add construct channel, invalid arguments."); + + pCbsChannel = __pImpl->GetCbsChannelN(from, to); + + r = GetLastResult(); + SetLastResult(r); + + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to get Cbs channel", GetErrorMessage(r)); + + return pCbsChannel; + +CATCH: + SetLastResult(r); + + if (pCbsChannel) + { + delete pCbsChannel; + pCbsChannel = null; + } + return null; +} + +Tizen::Base::Collection::IList* +SmsManager::GetCbsChannelListN(void) +{ + result r = E_SUCCESS; + IList* pList = null; + bool isCbsSupported = false; + + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony.sms.cbs", isCbsSupported); + SysTryReturn(NID_MSG, (r == E_SUCCESS) && (isCbsSupported == true), null, E_UNSUPPORTED_OPERATION, " CBS is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_CELLBROADCAST); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_PRIVILEGE_DENIED, r, "[E_PRIVILEGE_DENIED] Propagated."); + + SysAssertf(__pImpl != null, "The SmsManager instance is not constructed yet."); + + pList = __pImpl->GetCbsChannelListN(); + + r = GetLastResult(); + SetLastResult(r); + + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to get Cbs channel list", GetErrorMessage(r)); + + return pList; + +CATCH: + SetLastResult(r); + if (pList) + { + if (pList->GetCount() > 0) + { + pList->RemoveAll(true); + } + delete pList; + pList = null; + } + return null; +} + +} } // Tizen::Messaging diff --git a/src/FMsgSmsMessage.cpp b/src/FMsgSmsMessage.cpp new file mode 100755 index 0000000..cc313f0 --- /dev/null +++ b/src/FMsgSmsMessage.cpp @@ -0,0 +1,308 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgSmsMessage.cpp + * @brief This is the implementation file for the %SmsMessage class. + * + * This file contains the implementation of the %SmsMessage class. + */ + +#include +#include +#include +#include "FMsg_Types.h" +#include "FMsg_SmsMessageImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ +SmsMessage::SmsMessage(void) +{ + __pImpl = new (std::nothrow) _SmsMessageImpl(); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +SmsMessage::SmsMessage(const SmsMessage& value) +{ + __pImpl = new (std::nothrow) _SmsMessageImpl(*(value.__pImpl)); + SysTryReturnVoidResult(NID_MSG, __pImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +SmsMessage::~SmsMessage(void) +{ + if (__pImpl) + { + delete __pImpl; + } + __pImpl = null; +} + +SmsMessage& +SmsMessage::operator =(const SmsMessage& rhs) +{ + if (this != &rhs) + { + *__pImpl = *(rhs.__pImpl); + } + + return (*this); +} + +bool +SmsMessage::Equals(const Tizen::Base::Object& obj) const +{ + const SmsMessage* pSmsMessage = dynamic_cast(&obj); + if (!pSmsMessage) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + return __pImpl->Equals(*(pSmsMessage->__pImpl)); +} + +int +SmsMessage::GetHashCode(void) const +{ + return __pImpl->GetHashCode(); +} + +result +SmsMessage::SetText(const Tizen::Base::String& text) +{ + result r = E_SUCCESS; + + if (text.GetLength() > MAX_SMS_BODY_TEXT_LENGTH) + { + r = E_MAX_EXCEEDED; + SysLogException(NID_MSG, r, "The length of body text exceeds the limit."); + goto CATCH; + } + + r = __pImpl->SetText(text); + + return r; + +CATCH: + return r; +} + +String +SmsMessage::GetText(void) const +{ + return __pImpl->GetText(); +} + +String +SmsMessage::GetSenderAddress(void) const +{ + ClearLastResult(); + result r = E_SUCCESS; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturn(NID_MSG, r == E_SUCCESS, L"", r, "The application is not permitted to call this method."); + + if (__pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_SENTBOX || __pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_OUTBOX || + __pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_ALL) + { + SetLastResult(E_INVALID_OPERATION); + SysLogException(NID_MSG, GetLastResult(), + "[%s] exception occurred. The sender address can is valid when the message is incoming message or is from the Inbox. Not valid to the message from Sentbox or Outbox. [%d]", + GetErrorMessage(r), (int) __pImpl->__messageBoxType); + + return L""; + } + + return __pImpl->GetSenderAddress(); +} + +DateTime +SmsMessage::GetReceivedTime(void) const +{ + ClearLastResult(); + result r = E_SUCCESS; + DateTime dt; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "The application is not permitted to call this method."); + + // argument check + if (__pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_SENTBOX || __pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_OUTBOX || + __pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_ALL) + { + SetLastResult(E_INVALID_OPERATION); + SysLogException(NID_MSG, GetLastResult(), + "[%s] exception occurred. The received time is valid when the message is incoming message or is from the Inbox. Not valid to the message from Sentbox or Outbox. [%d]", + GetErrorMessage(r), __pImpl->__messageBoxType); + + dt.SetValue(1, 1, 1, 0, 0, 0); + + return dt; + } + + return __pImpl->GetReceivedTime(); + +CATCH: + dt.SetValue(1, 1, 1, 0, 0, 0); + return dt; + +} + +Tizen::Base::DateTime +SmsMessage::GetSentTime(void) const +{ + ClearLastResult(); + result r = E_SUCCESS; + DateTime dt; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "The application is not permitted to call this method."); + + // argument check + if (__pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_INBOX || __pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_NONE || + __pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_ALL) + { + SetLastResult(E_INVALID_OPERATION); + SysLogException(NID_MSG, GetLastResult(), + "[%s] exception occurred. The sent time is valid when the message is from the Sentbox or Outbox. Not valid to the message from Inbox or an incoming message. [%d]", + GetErrorMessage(r), __pImpl->__messageBoxType); + + dt.SetValue(1, 1, 1, 0, 0, 0); + + return dt; + } + + return __pImpl->GetSentTime(); + + +CATCH: + dt.SetValue(1, 1, 1, 0, 0, 0); + return dt; + +} + +int +SmsMessage::GetId(void) const +{ + ClearLastResult(); + result r = E_SUCCESS; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturn(NID_MSG, r == E_SUCCESS, -1, r, "The application is not permitted to call this method."); + + + // argument check + if (__pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_NONE || __pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_ALL) + { + SetLastResult(E_INVALID_OPERATION); + SysLogException(NID_MSG, GetLastResult(), + "[%s] exception occurred. The incoming message does not have message ID. Or the value of MessageBoxType is invalid. [%d]", + GetErrorMessage(r), __pImpl->__messageBoxType); + + return -1; + } + + return __pImpl->GetId(); +} + +SmsMessageBoxType +SmsMessage::GetMessageBoxType(void) const +{ + ClearLastResult(); + result r = E_SUCCESS; + DateTime dt; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturn(NID_MSG, r == E_SUCCESS, SMS_MESSAGE_BOX_TYPE_NONE, r, "The application is not permitted to call this method."); + + // argument check + if (__pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_ALL) + { + SetLastResult(E_INVALID_OPERATION); + SysLogException(NID_MSG, GetLastResult(), "[%s] exception occurred. Internal error!! The SmsMessageBoxType value is invalid. [%d]", + GetErrorMessage(r), __pImpl->__messageBoxType); + + return SMS_MESSAGE_BOX_TYPE_NONE; + } + + return __pImpl->GetMessageBoxType(); +} + +RecipientList +SmsMessage::GetRecipientList(void) const +{ + ClearLastResult(); + result r = E_SUCCESS; + RecipientList recipients; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturn(NID_MSG, r == E_SUCCESS, recipients, r, "The application is not permitted to call this method."); + + // argument check + if (__pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_INBOX || __pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_NONE || + __pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_ALL) + { + SetLastResult(E_INVALID_OPERATION); + SysLogException(NID_MSG, GetLastResult(), + "[%s] exception occurred. The incoming message or the message in the inbox does not have recipient list. Or the value of SmsMessageBoxType is invalid. [%d]", + GetErrorMessage(r), __pImpl->__messageBoxType); + + return recipients; + } + + return __pImpl->GetRecipientList(); +} + +bool +SmsMessage::HasMoreText(void) const +{ + ClearLastResult(); + result r = E_SUCCESS; + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_MESSAGING_SMS, _PRV_MESSAGING_READ); + r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); + SysTryReturn(NID_MSG, r == E_SUCCESS, false, r, "The application is not permitted to call this method."); + + // argument check + if (__pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_NONE || __pImpl->__messageBoxType == SMS_MESSAGE_BOX_TYPE_ALL) + { + SetLastResult(E_INVALID_OPERATION); + SysLogException(NID_MSG, GetLastResult(), "[%s] exception occurred. The value of SmsMessageBoxType is invalid. [%d]", GetErrorMessage(r), + __pImpl->__messageBoxType); + + return false; + } + + return __pImpl->HasMoreText(); +} +} } // Tizen::Messaging diff --git a/src/FMsgWapPushManager.cpp b/src/FMsgWapPushManager.cpp new file mode 100644 index 0000000..4a5fc55 --- /dev/null +++ b/src/FMsgWapPushManager.cpp @@ -0,0 +1,178 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgWapPushManger.cpp + * @brief This is the implementation file for the %WapPushManger class. + * + * This file contains the implementation of the %WapPushManger class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_Types.h" +#include "FMsg_WapPushManagerImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ + +WapPushManager::WapPushManager(void) +{ + __pWapPushManagerImpl = new (std::nothrow) _WapPushManagerImpl(); + SysTryReturnVoidResult(NID_MSG, __pWapPushManagerImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +WapPushManager::WapPushManager(const WapPushManager& value) +{ + __pWapPushManagerImpl = new (std::nothrow) _WapPushManagerImpl(*(value.__pWapPushManagerImpl)); + SysTryReturnVoidResult(NID_MSG, __pWapPushManagerImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +WapPushManager::~WapPushManager(void) +{ + if (__pWapPushManagerImpl) + { + delete __pWapPushManagerImpl; + } + __pWapPushManagerImpl = null; +} + +WapPushManager& +WapPushManager::operator =(const WapPushManager& rhs) +{ + if (this != &rhs) + { + *__pWapPushManagerImpl = *(rhs.__pWapPushManagerImpl); + } + + return (*this); +} + +result +WapPushManager::AddWapPushEventListener(const Tizen::Base::String& wapApplicationId, IWapPushEventListener& listener) +{ + result r = E_SUCCESS; + bool isWapPushSupported = false; + + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony", isWapPushSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isWapPushSupported == true), E_UNSUPPORTED_OPERATION, " Wap Push is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_WAPPUSH); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagating."); + + SysAssertf(__pWapPushManagerImpl != null, "The WapPushManager instance is not constructed yet."); + + // argument check + SysTryReturn(NID_MSG, + wapApplicationId.GetLength() != 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of wapApplicationId is 0."); + + r = __pWapPushManagerImpl->AddWapPushEventListener(wapApplicationId, listener); + + return r; +} + +result +WapPushManager::RemoveWapPushEventListener(const Tizen::Base::String& wapApplicationId, IWapPushEventListener& listener) +{ + result r = E_SUCCESS; + bool isWapPushSupported = false; + + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony", isWapPushSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isWapPushSupported == true), E_UNSUPPORTED_OPERATION, " Wap Push is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_WAPPUSH); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagating."); + + SysAssertf(__pWapPushManagerImpl != null, "The WapPushManager instance is not constructed yet."); + + // argument check + SysTryReturn(NID_MSG, + wapApplicationId.GetLength() != 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of wapApplicationId is 0."); + + r = __pWapPushManagerImpl->RemoveWapPushEventListener(wapApplicationId, listener); + return r; +} + +result +WapPushManager::RegisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType) +{ + result r = E_SUCCESS; + bool isWapPushSupported = false; + + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony", isWapPushSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isWapPushSupported == true), E_UNSUPPORTED_OPERATION, " Wap Push is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_WAPPUSH); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagating."); + + SysAssertf(__pWapPushManagerImpl != null, "The WapPushManager instance is not constructed yet."); + + // argument check + SysTryReturn(NID_MSG, + wapApplicationId.GetLength() != 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of wapApplicationId is 0."); + SysTryReturn(NID_MSG, + contentType.GetLength() != 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of contentType is 0."); + + r = __pWapPushManagerImpl->RegisterCondition(wapApplicationId, contentType); + return r; +} + +result +WapPushManager::UnregisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType) +{ + result r = E_SUCCESS; + bool isWapPushSupported = false; + + ClearLastResult(); + + r = Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.telephony", isWapPushSupported); + SysTryReturnResult(NID_MSG, (r == E_SUCCESS) && (isWapPushSupported == true), E_UNSUPPORTED_OPERATION, " Wap Push is not supported."); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_WAPPUSH); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_PRIVILEGE_DENIED, r = E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagating."); + + SysAssertf(__pWapPushManagerImpl != null, "The WapPushManager instance is not constructed yet."); + + // argument check + SysTryReturn(NID_MSG, + wapApplicationId.GetLength() != 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of wapApplicationId is 0."); + SysTryReturn(NID_MSG, + contentType.GetLength() != 0, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] The length of contentType is 0."); + + r = __pWapPushManagerImpl->UnregisterCondition(wapApplicationId, contentType); + return r; +} + +} } // Tizen::Messaging diff --git a/src/FMsgWapPushMessage.cpp b/src/FMsgWapPushMessage.cpp new file mode 100644 index 0000000..a9eec29 --- /dev/null +++ b/src/FMsgWapPushMessage.cpp @@ -0,0 +1,148 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsgWapPushMessage.cpp + * @brief This is the implementation file for the %WapPushMessage class. + * + * This file contains the implementation of the %WapPushMessage class. + */ + +#include +#include +#include +#include +#include +#include +#include "FMsg_Types.h" +#include "FMsg_WapPushMessageImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ + +WapPushMessage::WapPushMessage(void) +{ + __pWapPushMessageImpl = new (std::nothrow) _WapPushMessageImpl(); + SysTryReturnVoidResult(NID_MSG, __pWapPushMessageImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +WapPushMessage::WapPushMessage(const WapPushMessage& value) +{ + __pWapPushMessageImpl = new (std::nothrow) _WapPushMessageImpl(*(value.__pWapPushMessageImpl)); + SysTryReturnVoidResult(NID_MSG, __pWapPushMessageImpl != null, E_OUT_OF_MEMORY, "memory allocation failed."); +} + +WapPushMessage::~WapPushMessage(void) +{ + if (__pWapPushMessageImpl) + { + delete __pWapPushMessageImpl; + } + __pWapPushMessageImpl = null; +} + +WapPushMessage& +WapPushMessage::operator =(const WapPushMessage& rhs) +{ + if (this != &rhs) + { + *__pWapPushMessageImpl = *(rhs.__pWapPushMessageImpl); + } + + return (*this); +} + +WapPushMessage::WapPushMessage(const Tizen::Base::String& header, const Tizen::Base::ByteBuffer& body) +{ + __pWapPushMessageImpl = new (std::nothrow) _WapPushMessageImpl(header, body); +} + +bool +WapPushMessage::Equals(const Tizen::Base::Object& obj) const +{ + const WapPushMessage* pWapPushMessage = dynamic_cast(&obj); + if (!pWapPushMessage) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + return __pWapPushMessageImpl->Equals(*(pWapPushMessage->__pWapPushMessageImpl)); +} + +WapPushMessage* +WapPushMessage::CloneN() const +{ + return __pWapPushMessageImpl->CloneN(); +} + +int +WapPushMessage::GetHashCode(void) const +{ + return __pWapPushMessageImpl->GetHashCode(); +} + +Tizen::Base::ByteBuffer* +WapPushMessage::GetBodyN(void) const +{ + result r = E_SUCCESS; + Tizen::Base::ByteBuffer* pMsgBody = null; + + ClearLastResult(); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_WAPPUSH); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagating."); + + pMsgBody = __pWapPushMessageImpl->GetBodyN(); + SysTryCatch(NID_MSG, pMsgBody != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + + + SetLastResult(GetLastResult()); + return pMsgBody; + +CATCH: + SetLastResult(GetLastResult()); + return pMsgBody; +} + +Tizen::Base::String +WapPushMessage::GetHeader(void) const +{ + result r = E_SUCCESS; + Tizen::Base::String msgHeader; + + ClearLastResult(); + + // checking privilege + r = _AccessController::CheckUserPrivilege(_PRV_WAPPUSH); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] Propagating."); + + msgHeader = __pWapPushMessageImpl->GetHeader(); + + SetLastResult(GetLastResult()); + return msgHeader; + +CATCH: + SetLastResult(GetLastResult()); + return msgHeader; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_CbsChannelImpl.cpp b/src/FMsg_CbsChannelImpl.cpp new file mode 100644 index 0000000..6746094 --- /dev/null +++ b/src/FMsg_CbsChannelImpl.cpp @@ -0,0 +1,207 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @if VISPARTNER-OPERATOR + * + * @file FMsg_CbsChannelImpl.cpp + * @brief This is the implementation file for the %_CbsChannelImpl class. + * + * @visibility partner-operator + * + * This file contains the implementation of the %_CbsChannelImpl class. + * + * @endif + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_Types.h" +#include "FMsg_CbsChannelImpl.h" +#include "FMsg_SmsMmsCallbackHandler.h" +#include "FMsg_MessagingIpcProxy.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ + +_CbsChannelImpl::_CbsChannelImpl(void) + : __fromId(-1) + , __toId(-1) + , __channelName(L"") + , __isChannelEnable(false) +{ +} + +_CbsChannelImpl::_CbsChannelImpl(const _CbsChannelImpl& value) +{ + __fromId = value.__fromId; + __toId = value.__toId; + __channelName = value.__channelName; + __isChannelEnable = value.__isChannelEnable; +} + +_CbsChannelImpl::~_CbsChannelImpl(void) +{ +} + +_CbsChannelImpl& +_CbsChannelImpl::operator =(const _CbsChannelImpl& rhs) +{ + if (this != &rhs) + { + __fromId = rhs.__fromId; + __toId = rhs.__toId; + __channelName = rhs.__channelName; + __isChannelEnable = rhs.__isChannelEnable; + } + + return (*this); +} + +result +_CbsChannelImpl::Construct(int from, int to, const Tizen::Base::String& name) +{ + __fromId = from; + __toId = to; + __channelName = name; + __isChannelEnable = false; + + return E_SUCCESS; +} + +CbsChannel* +_CbsChannelImpl::GetCbsChannelN(int from, int to, const Tizen::Base::String& name) +{ + result r = E_SUCCESS; + CbsChannel* pCbsChannel = null; + + pCbsChannel = new (std::nothrow) CbsChannel(); + SysTryCatch(NID_MSG, pCbsChannel != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + r = pCbsChannel->Construct(from, to, name); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "failed to construct channel."); + + SetLastResult(GetLastResult()); + return pCbsChannel; + +CATCH: + SetLastResult(GetLastResult()); + + if(pCbsChannel) + { + delete pCbsChannel; + pCbsChannel = null; + } + + return null; +} + +_CbsChannelImpl* +_CbsChannelImpl::GetInstance(CbsChannel& cbsChannel) +{ + return cbsChannel.__pCbsChannelImpl; +} + +result +_CbsChannelImpl::UpdateName(const Tizen::Base::String& name) +{ + result r = E_SUCCESS; + ClearLastResult(); + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, E_OUT_OF_MEMORY,"Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->UpdateCbsChannel(__fromId, __toId, name, __isChannelEnable); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "Failed to update cbs channel."); + + __channelName = name; + + return r; +} + +result +_CbsChannelImpl::Deactivate(void) +{ + result r = E_SUCCESS; + ClearLastResult(); + + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, E_OUT_OF_MEMORY,"Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->UpdateCbsChannel(__fromId, __toId, __channelName, false); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "Failed to save the setting."); + + __isChannelEnable = false; + + return r; +} + +result +_CbsChannelImpl::Activate(void) +{ + result r = E_SUCCESS; + ClearLastResult(); + + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->UpdateCbsChannel(__fromId, __toId, __channelName, true); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "Failed to save the setting."); + + __isChannelEnable = true; + + return r; +} + +bool +_CbsChannelImpl::IsActivated(void) const +{ + return __isChannelEnable; +} + +Tizen::Base::String +_CbsChannelImpl::GetName(void) const +{ + return __channelName; +} + +result +_CbsChannelImpl::GetRange(int& from, int& to) const +{ + result r = E_SUCCESS; + + from = __fromId; + to = __toId; + + return r; +} + +void +_CbsChannelImpl::SetCbsChannelName(Tizen::Base::String channelName) +{ + __channelName = channelName; +} + +void +_CbsChannelImpl::SetCbsChannelState(bool isChannelEnable) +{ + __isChannelEnable = isChannelEnable; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_CbsChannelImpl.h b/src/FMsg_CbsChannelImpl.h new file mode 100644 index 0000000..befb781 --- /dev/null +++ b/src/FMsg_CbsChannelImpl.h @@ -0,0 +1,286 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @if VISPARTNER-OPERATOR + * + * @file FMsg_CbsChannelImpl.h + * @brief This is the header file for the _CbsChannelImpl class. + * + * @visibility partner-operator + * + * This header file contains the declarations of the _CbsChannelImpl class. + * + * @endif + */ + +#ifndef _FMSG_INTERNAL_CBS_CHANNEL_IMPL_H_ +#define _FMSG_INTERNAL_CBS_CHANNEL_IMPL_H_ + +namespace Tizen { namespace Messaging +{ + +/** +* @if VISPARTNER-OPERATOR +* +* @class _CbsChannelImpl +* @brief This class provides methods for handling a Cell Broadcast Service (CBS) channel. +* +* @since 2.1 +* +* @final This class is not intended for extension. +* +* @visibility partner-operator +* +* The %_CbsChannelImpl class provides methods for handling a CBS channel. @n +* It allows you to get and set the CBS channel information. +* +* @endif +*/ + +class _CbsChannelImpl + : public Tizen::Base::Object +{ +public: + + /** + * @if VISPARTNER-OPERATOR + * + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.1 + * + * @visibility partner-operator + * + * @endif + */ + virtual ~_CbsChannelImpl(void); + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the range of the channel + * + * @since 2.1 + * + * @visibility partner-operator + * + * @privlevel user + * @privilege http://tizen.org/privilege/cellbroadcast + * + * + * @return An error code + * @param[out] from The starting index of the message ID of the channel. + * @param[out] to The last index of the message ID of the channel. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_STATE The range has not been set as yet. + * @exception E_SYSTEM A system error has occurred. + * @remarks In case of an error, this method sets the negative values for @c from and @c to. For example, @c -1. + * + * @endif + */ + result GetRange(int& from, int& to) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the name of the channel. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @privlevel user + * @privilege http://tizen.org/privilege/cellbroadcast + * + * @return The name of the channel + * + * @remark The name can be an empty string. + * + * @endif + */ + Tizen::Base::String GetName(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the activation status of the channel. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @privlevel user + * @privilege http://tizen.org/privilege/cellbroadcast + * + * @return @c true if the channel is activated, + * else @c false + * + * @endif + */ + bool IsActivated(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Activates the channel status . + * + * @since 2.1 + * + * @visibility partner-operator + * + * @privlevel user + * @privilege http://tizen.org/privilege/cellbroadcast + * + * @return An error code + * @exception E_SUCCESS The method is successful. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to activate the CBS channel status. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * + * @endif + */ + result Activate(void); + + /** + * @if VISPARTNER-OPERATOR + * + * Deactivates the channel status + * + * @privlevel user + * @privilege http://tizen.org/privilege/cellbroadcast + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @exception E_SUCCESS The method is successful. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to activate the CBS channel status. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * + * @endif + */ + result Deactivate(void); + + /** + * @if VISPARTNER-OPERATOR + * + * Updates the name of the channel. + * + * @privlevel user + * @privilege http://tizen.org/privilege/cellbroadcast + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] name The name of the CBS channel to update + * @exception E_SUCCESS The method is successful. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to update the CBS channel name. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * + * @endif + */ + result UpdateName(const Tizen::Base::String& name); + + /** + * Sets the cbs channel name to CbsChannelImpl object. + * + * @since 2.1 + * @param[in] channelName An Cbs Channel Name + */ + void SetCbsChannelName(Tizen::Base::String channelName); + + /** + * Sets the cbs Channel State to CbsChannelImpl object. + * + * @since 2.1 + * @param[in] isChannelEnable CBS on/off flag + */ + void SetCbsChannelState(bool isChannelEnable); + +public: + /** + * Gets the instance of CbsChannel + * + * @since 2.1 + */ + static CbsChannel* GetCbsChannelN(int from, int to, const Tizen::Base::String& name); + + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _CbsChannelImpl + * @param[in] CbsChannel An instance of CbsChannel + */ + static _CbsChannelImpl* GetInstance(CbsChannel& cbsChannel); + +public: + /** + * This default constructor is intentionally declared as private so that only the platform can create an instance. + * + * @since 2.1 + */ + _CbsChannelImpl(void); + + /** + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] rhs An instance of _CbsChannelImpl + */ + _CbsChannelImpl(const _CbsChannelImpl& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] rhs An instance of _CbsChannelImpl + */ + _CbsChannelImpl& operator =(const _CbsChannelImpl& rhs); + + /** + * Initializes this instance of %_CbsChannelImpl with the specified parameter. + * + * @since 2.1 + * + * @return An error code + * @param[in] from The starting index of the message ID of the channel. + * @param[in] to The last index of the message ID of the channel. + * @param[in] name The name of the channel. (can be an empty string) + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c to parameter is smaller than @c from. @n + * The specified @c to or @c from parameter is a negative value. @n + * The specified @c to parameter exceeds the limit (0xFFFF). @n + * The range (@c to - @c from) exceeds the limit (0xFFFF). + * The specified @c name string length is greater than @c 32. @n + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + */ + result Construct(int from, int to, const Tizen::Base::String& name); + +private: + int __fromId; + int __toId; + Tizen::Base::String __channelName; + bool __isChannelEnable; +}; // _CbsChannelImpl + +} } // Tizen::Messaging +#endif // _FMSG_INTERNAL_CBS_CHANNEL_IMPL_H_ diff --git a/src/FMsg_CbsMessageImpl.cpp b/src/FMsg_CbsMessageImpl.cpp new file mode 100644 index 0000000..92f3542 --- /dev/null +++ b/src/FMsg_CbsMessageImpl.cpp @@ -0,0 +1,293 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_CbsMessageImpl.cpp + * @brief This is the implementation file for the %_CbsMessageImpl class. + * + * This file contains the implementation of the %_CbsMessageImpl class. + */ + +#include +#include +#include +#include "FMsg_Types.h" +#include "FMsg_CbsMessageImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; + +namespace Tizen { namespace Messaging +{ + +_CbsMessageImpl::_CbsMessageImpl(void) + : __cbsMsgTime() + , __pCbsSerialNumber(null) + , __cbsSenderMsg(L"") + , __cbslanguageType(L"") + , __cbsMessageId(0) + , __isEtwsNotification(false) + , __dataCodingScheme() +{ + __pCbsSerialNumber = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_MSG, __pCbsSerialNumber != null, E_OUT_OF_MEMORY, "memory allocation failed"); + __pCbsSerialNumber->Construct(0); + __pCbsSerialNumber->SetPosition(0); +} + +_CbsMessageImpl::_CbsMessageImpl(const _CbsMessageImpl& value) +{ + result r = E_SUCCESS; + __cbsMsgTime = value.__cbsMsgTime; + __cbsMessageId = value.__cbsMessageId; + __cbsSenderMsg = value.__cbsSenderMsg; + __isEtwsNotification = value.__isEtwsNotification; + __dataCodingScheme = value.__dataCodingScheme; + __cbslanguageType = value.__cbslanguageType; + + r = __pCbsSerialNumber->SetArray(value.__pCbsSerialNumber->GetPointer(), 0, value.__pCbsSerialNumber->GetLimit()); + SysTryReturnVoidResult(NID_MSG, r == E_SUCCESS, r, "Failed to set array"); + __pCbsSerialNumber->SetPosition(0); +} + +result +_CbsMessageImpl::SetCbsMessageImpl(const Tizen::Base::DateTime& dateTime, const Tizen::Base::ByteBuffer& cbsSerialNumber, const Tizen::Base::String& text, int cbsMessageId, bool isEtwsNotification, byte dataCodingScheme, const Tizen::Base::String& languageType) +{ + result r = E_SUCCESS; + + __cbsMsgTime = dateTime; + __cbsMessageId = cbsMessageId; + __cbsSenderMsg = text; + __isEtwsNotification = isEtwsNotification; + __dataCodingScheme = dataCodingScheme; + __cbslanguageType = languageType; + + __pCbsSerialNumber = new (std::nothrow) ByteBuffer(); + SysTryReturn(NID_MSG, __pCbsSerialNumber != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed"); + + r = __pCbsSerialNumber->Construct(cbsSerialNumber); + r = __pCbsSerialNumber->SetPosition(0); + + return r; +} + +_CbsMessageImpl::~_CbsMessageImpl(void) +{ + if (__pCbsSerialNumber) + { + delete __pCbsSerialNumber; + __pCbsSerialNumber = null; + } +} + +_CbsMessageImpl& +_CbsMessageImpl::operator =(const _CbsMessageImpl& rhs) +{ + result r = E_SUCCESS; + + if (this != &rhs) + { + __cbsMsgTime = rhs.__cbsMsgTime; + __cbsMessageId = rhs.__cbsMessageId; + __cbsSenderMsg = rhs.__cbsSenderMsg; + __isEtwsNotification = rhs.__isEtwsNotification; + __dataCodingScheme = rhs.__dataCodingScheme; + __cbslanguageType = rhs.__cbslanguageType; + + r = __pCbsSerialNumber->SetArray(rhs.__pCbsSerialNumber->GetPointer(), 0, rhs.__pCbsSerialNumber->GetLimit()); + if (r == E_SUCCESS) + { + __pCbsSerialNumber->SetPosition(0); + } + } + + return (*this); +} + +CbsMessage* +_CbsMessageImpl::CloneN() const +{ + CbsMessage* pCbsMsg = null; + result r = E_SUCCESS; + + pCbsMsg = _CbsMessageImpl::GetCbsMessageN(); + SysTryCatch(NID_MSG, pCbsMsg != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + r = _CbsMessageImpl::GetInstance(*pCbsMsg)->SetCbsMessageImpl(__cbsMsgTime, *(__pCbsSerialNumber), __cbsSenderMsg, __cbsMessageId, __isEtwsNotification, __dataCodingScheme, __cbslanguageType); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "cbsimpl message construct failed"); + + SetLastResult(GetLastResult()); + return pCbsMsg; + +CATCH: + SetLastResult(GetLastResult()); + if (pCbsMsg) + { + delete pCbsMsg; + pCbsMsg = null; + } + return null; +} + +bool +_CbsMessageImpl::Equals(const Tizen::Base::Object& obj) const +{ + const _CbsMessageImpl* pCbsMessageImpl = dynamic_cast(&obj); + + if (!pCbsMessageImpl) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + // sender time + if (__cbsMsgTime != pCbsMessageImpl->__cbsMsgTime) + { + return false; + } + + // sender address + if (__pCbsSerialNumber != pCbsMessageImpl->__pCbsSerialNumber) + { + return false; + } + + // sender msg + if (__cbsSenderMsg != pCbsMessageImpl->__cbsSenderMsg) + { + return false; + } + + // cbs message id + if (__cbsMessageId != pCbsMessageImpl->__cbsMessageId) + { + return false; + } + + // Etws Notification + if (__isEtwsNotification != pCbsMessageImpl->__isEtwsNotification) + { + return false; + } + + // Etws Notification + if (__dataCodingScheme != pCbsMessageImpl->__dataCodingScheme) + { + return false; + } + + // language type + if (__cbslanguageType != pCbsMessageImpl->__cbslanguageType) + { + return false; + } + + return true; +} + +int +_CbsMessageImpl::GetHashCode(void) const +{ + int hash = 0; + + hash = __cbsSenderMsg.GetHashCode() + __pCbsSerialNumber->GetHashCode() + __cbsMsgTime.GetHashCode() + __cbsMessageId + (__isEtwsNotification ? 1 : 0); + + return hash; +} + +CbsMessage* +_CbsMessageImpl::GetCbsMessageN() +{ + result r = E_SUCCESS; + CbsMessage* pCbsMsg = null; + + pCbsMsg = new (std::nothrow) CbsMessage(); + SysTryCatch(NID_MSG, pCbsMsg != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + return pCbsMsg; + +CATCH: + return null; +} + +_CbsMessageImpl* +_CbsMessageImpl::GetInstance(CbsMessage& cbsMessage) +{ + return cbsMessage.__pCbsMessageImpl; +} + + +Tizen::Base::ByteBuffer* +_CbsMessageImpl::GetSerialNumberN(void) const +{ + result r = E_SUCCESS; + Tizen::Base::ByteBuffer* pCbsSerialNumber = null; + + ClearLastResult(); + + pCbsSerialNumber = new (std::nothrow) ByteBuffer(); + SysTryCatch(NID_MSG, pCbsSerialNumber != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + r = pCbsSerialNumber->Construct(*__pCbsSerialNumber); + r = pCbsSerialNumber->SetPosition(0); + + SetLastResult(r); + + return pCbsSerialNumber; + +CATCH: + SetLastResult(r); + + return null; +} + +Tizen::Base::DateTime +_CbsMessageImpl::GetReceivedTime(void) const +{ + return __cbsMsgTime; +} + +Tizen::Base::String +_CbsMessageImpl::GetText(void) const +{ + return __cbsSenderMsg; +} + +int +_CbsMessageImpl::GetMessageId(void) const +{ + return __cbsMessageId; +} + +bool +_CbsMessageImpl::IsEtwsNotification(void) const +{ + return __isEtwsNotification; +} + +byte +_CbsMessageImpl::GetDataCodingScheme(void) const +{ + return __dataCodingScheme; +} + +Tizen::Base::String +_CbsMessageImpl::GetLanguageType(void) const +{ + return __cbslanguageType; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_CbsMessageImpl.h b/src/FMsg_CbsMessageImpl.h new file mode 100644 index 0000000..87c307e --- /dev/null +++ b/src/FMsg_CbsMessageImpl.h @@ -0,0 +1,329 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @if VISPARTNER-OPERATOR + * + * @file FMsg_CbsMessageImpl.h + * @brief This is the header file for the _CbsMessageImpl class. + * + * @visibility partner-operator + * + * This header file contains the declarations of the _CbsMessageImpl class. + * + * @endif + */ + +#ifndef _FMSG_INTERNAL_CBS_MESSAGE_IMPL_H_ +#define _FMSG_INTERNAL_CBS_MESSAGE_IMPL_H_ + +namespace Tizen { namespace Base +{ +class ByteBuffer; +class String; +class DateTime; +} } + +#include + +namespace Tizen { namespace Messaging +{ + +class CbsMessage; + +/** +* @if VISPARTNER-OPERATOR +* +* @class _CbsMessageImpl +* +* @brief This class provides methods for handling a CBS message. +* +* @since 2.1 +* +* @final This class is not intended for extension. +* +* @visibility partner-operator +* +* The %_CbsMessageImpl class provides methods for handling a CBS message. It allows you to get the body text, +* received time, and sender address of a CBS message. +* +* @endif +*/ + +class _CbsMessageImpl + : public Tizen::Base::Object +{ +public: + /** + * @if VISPARTNER-OPERATOR + * + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.1 + * + * @visibility partner-operator + * + * @endif + */ + virtual ~_CbsMessageImpl(void); + + /** + * @if VISPARTNER-OPERATOR + * + * Compares the specified instance of %_CbsMessageImpl with the calling instance. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return @c true, if the values match @n + * @c false, otherwise + * @param[in] obj The other Object to be compared + * @see Object::Equals() + * + * @endif + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the copied instance of the class. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An instance of %_CbsMessageImpl + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * + * @remarks In case of error, this method returns @c null. @n + * The specific error code can be accessed using the GetLastResult() method. + * + * @endif + */ + CbsMessage* CloneN(void) const; + + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the hash value of the current instance. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The current instance's hash value + * + * @endif + */ + virtual int GetHashCode(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Checks whether this message is an ETWS notification. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return @c true if this message is an ETWS notification, @n + * else @c false + * @remarks If the return value is @c true, the message is ETWS secondary notification. + * + * @endif + */ + bool IsEtwsNotification(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the serial number of the CBS message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The serial number of the CBS message + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. @n + * In case of an error, this method returns null. + * + * @endif + */ + Tizen::Base::ByteBuffer* GetSerialNumberN(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the message ID of the CBS message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The the message ID of the CBS message + * + * @endif + */ + int GetMessageId(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the body of the message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The body of the message + * + * @endif + */ + Tizen::Base::String GetText(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the date and time (UTC time) of the message when it is received. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The date and time (UTC time) when the message is received + * + * @endif + */ + Tizen::Base::DateTime GetReceivedTime(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the Data Coding Scheme of the CBS message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The Data Coding Scheme of the CBS message + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. @n + * In case of an error, this method returns null. @n + * The alphabet/coding and the language applied to CBS messages are defined in 3GPP TS 23.038 + * + * @endif + */ + byte GetDataCodingScheme(void) const; + + /** + + * @if VISPARTNER-OPERATOR + * + * Gets the language type of a message. + * + + * @since 2.1 + * + * @visibility partner-operator + * + * @return The language type of a message + * + * @endif + */ + Tizen::Base::String GetLanguageType(void) const; + +public: + /** + * Gets the instance of CbsChannel + * + * @since 2.1 + */ + static CbsMessage* GetCbsMessageN(); + + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _CbsMessageImpl + * @param[in] CbsMessage An instance of CbsMessage + */ + static _CbsMessageImpl* GetInstance(CbsMessage& cbsMessage); + +public: + /** + * This default constructor is intentionally declared as private so that only the platform can create an instance. + * + * @since 2.1 + */ + _CbsMessageImpl(void); + + /** + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @since 2.1 + * + * @param[in] rhs An instance of _CbsMessageImpl + */ + _CbsMessageImpl(const _CbsMessageImpl& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. @n + * - Use CloneN() to get an exact copy of the instance. + * - Use Equals() to compare the contents of one instance with the other. + * + * @since 2.1 + * + * @return A reference to this instance + * @param[in] rhs An instance of _CbsMessageImpl + */ + _CbsMessageImpl& operator =(const _CbsMessageImpl& rhs); + + /** + * Initializes this instance of %_CbsChannelImpl with the specified parameter. + * + * @since 2.1 + * + * @param[in] dateTime The date and time (UTC time) when the message is received + * @param[in] cbsSerialNumber The cbsSerialNumber of the CBS message + * @param[in] text The cbs message body text + * @param[in] cbsMessageId The cbsMessageId of the CBS message + * @param[in] isEtwsnotification The Etws notification of the CBS message + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + */ + result SetCbsMessageImpl(const Tizen::Base::DateTime& dateTime, const Tizen::Base::ByteBuffer& cbsSerialNumber, const Tizen::Base::String& text, int cbsMessageId, bool isEtwsNotification, byte dataCodingScheme, const Tizen::Base::String& languageType); + +private: + Tizen::Base::DateTime __cbsMsgTime; + Tizen::Base::ByteBuffer* __pCbsSerialNumber; + Tizen::Base::String __cbsSenderMsg; + Tizen::Base::String __cbslanguageType; + int __cbsMessageId; + bool __isEtwsNotification; + byte __dataCodingScheme; +}; // _CbsMessageImpl + +} } // Tizen::Messaging + +#endif // _FMSG_INTERNAL_CBS_MESSAGE_IMPL_H_ diff --git a/src/FMsg_ComposerEvent.cpp b/src/FMsg_ComposerEvent.cpp new file mode 100644 index 0000000..ab3037a --- /dev/null +++ b/src/FMsg_ComposerEvent.cpp @@ -0,0 +1,72 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_ComposerEvent.cpp + * @brief This is the implementation file for the %_ComposerEvent class. + * + * This file contains the implementation of the %_ComposerEvent class. + */ + +#include +#include "FMsg_IComposerListener.h" +#include "FMsg_ComposerEvent.h" +#include "FMsg_ComposerEventArg.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Runtime; + +namespace Tizen { namespace Messaging +{ + +_ComposerEvent::_ComposerEvent(void) +{ +} + +result +_ComposerEvent::Construct(void) +{ + return _Event::Initialize(); +} + +void +_ComposerEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) +{ + result r = E_SUCCESS; + + _IComposerListener* pComposerListener = dynamic_cast <_IComposerListener*>(&listener); + SysTryReturnVoidResult(NID_MSG, pComposerListener != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + IEventArg* pEventArg = const_cast (&arg); + _ComposerEventArg* pComposerEventArg = dynamic_cast <_ComposerEventArg*>(pEventArg); + SysTryReturnVoidResult(NID_MSG, pComposerEventArg != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + // get error result + pComposerEventArg->GetErrorResult(r); + + if (pComposerEventArg->IsTerminateEvent() == false) + { + // Fire + pComposerListener->OnComposerInitialized(r); + } + else + { + // Fire + pComposerListener->OnComposerTerminated(r); + } +} + +} } diff --git a/src/FMsg_ComposerEvent.h b/src/FMsg_ComposerEvent.h new file mode 100644 index 0000000..04b68fe --- /dev/null +++ b/src/FMsg_ComposerEvent.h @@ -0,0 +1,75 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_ComposerEvent.h + * @brief This is the header file for _ComposerEvent class. + * + * This header file contains the declarations of _ComposerEvent class. + */ + +#ifndef _FMSG_INTERNAL_COMPOSER_EVENT_H_ +#define _FMSG_INTERNAL_COMPOSER_EVENT_H_ + +// Includes +#include + +namespace Tizen { namespace Messaging +{ + +// +// @class _ComposerEvent +// @brief This class provides the event for message composer +// @since 1.0 +// +// @see _IComposerEventListener, ComposerEventArg +// + +class _ComposerEvent + : public Tizen::Base::Runtime::_Event +{ +// Life cycle +public: + /** + * This is the constructor. + * + */ + _ComposerEvent(void); + + /** + * This is the class destructor. + * + */ + virtual ~_ComposerEvent(void) {}; + + /** + * Initializes a new instance of the class + * + */ + result Construct(void); + + +//Operations +protected: + void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg); + +private: + _ComposerEvent(const _ComposerEvent& _ComposerEvent); + _ComposerEvent& operator =(const _ComposerEvent& value); +}; // _ComposerEvent +} } + +#endif // _FMSG_INTERNAL_COMPOSER_EVENT_H_ diff --git a/src/FMsg_ComposerEventArg.cpp b/src/FMsg_ComposerEventArg.cpp new file mode 100644 index 0000000..3d0c17f --- /dev/null +++ b/src/FMsg_ComposerEventArg.cpp @@ -0,0 +1,51 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_ComposerEventArg.cpp + * @brief This is the implementation file for the %_ComposerEventArg class. + * + * This file contains the implementation of the %_ComposerEventArg class. + */ + +#include "FMsg_ComposerEventArg.h" + +using namespace Tizen::Base; + +namespace Tizen { namespace Messaging +{ + +_ComposerEventArg::_ComposerEventArg(void) : __result(E_SUCCESS), __isTerminateEvent(false) +{ +} + +_ComposerEventArg::_ComposerEventArg(result r, bool isTerminateEvent) : __result(r), __isTerminateEvent(isTerminateEvent) +{ +} + +void +_ComposerEventArg::GetErrorResult(result& r) const +{ + r = __result; +} + +bool +_ComposerEventArg::IsTerminateEvent(void) +{ + return __isTerminateEvent; +} + +} } diff --git a/src/FMsg_ComposerEventArg.h b/src/FMsg_ComposerEventArg.h new file mode 100644 index 0000000..488585d --- /dev/null +++ b/src/FMsg_ComposerEventArg.h @@ -0,0 +1,97 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_ComposerEventArg.h + * @brief This is the header file for _ComposerEventArg class. + * + * This header file contains the declarations of _ComposerEventArg class. + */ + +#ifndef _FMSG_INTERNAL_COMPOSER_EVENT_ARG_H_ +#define _FMSG_INTERNAL_COMPOSER_EVENT_ARG_H_ + +// Includes +#include +#include +#include + +namespace Tizen { namespace Messaging +{ + +// +// @class _ComposerEventArg +// @brief This class provides methods for getting data from message composer event +// @since 1.0 +// + +class _ComposerEventArg + : public Tizen::Base::Object + , public Tizen::Base::Runtime::IEventArg +{ + // Life cycle +public: + /** + * This is the constructor. + * + */ + _ComposerEventArg(void); + + /** + * This is the constructor. + * + * @param[in] r - the message composer result + * @param[in] isTerminateEvent - @c true on terminate event @n + * @c false, otherwise + */ + _ComposerEventArg(const result r, bool isTerminateEvent = false); + + /** + * This is class destructor. + * + */ + virtual ~_ComposerEventArg(void) {}; + + // Access +public: + /** + * Gets the error result of composer event + * This synchronous method retrieves information about the message composer + * + * @param[out] r - the message composer result + * @exception E_SUCCESS - operation is successful + * @exception E_OUT_OF_MEMORY - failed to allocate required/requested memory + * @exception E_SYSTEM - the system has an error. + */ + void GetErrorResult(result& r) const; + + /** + * Check the event is terminating-event or not + */ + bool IsTerminateEvent(void); + +private: + _ComposerEventArg(const _ComposerEventArg& eventArg); + _ComposerEventArg& operator =(const _ComposerEventArg& value); + +private: + result __result; + bool __isTerminateEvent; +}; // _ComposerEventArg + +} } + +#endif // _FMSG_INTERNAL_COMPOSER_EVENT_ARG_H_ diff --git a/src/FMsg_DetailedEmailMessageImpl.cpp b/src/FMsg_DetailedEmailMessageImpl.cpp new file mode 100755 index 0000000..5408d9e --- /dev/null +++ b/src/FMsg_DetailedEmailMessageImpl.cpp @@ -0,0 +1,1422 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_DetailedEmailMessageImpl.cpp + * @brief This is the implementation file for the %_DetailedEmailMessageImpl class. + * + * This file contains the implementation of the %_DetailedEmailMessageImpl class. + */ + +#include +#include +#include +#include +#include +#include +#include "FMsg_DetailedEmailMessageImpl.h" +#include "FMsg_EmailAttachmentImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +namespace Tizen { namespace Messaging +{ + +_DetailedEmailMessageImpl::_DetailedEmailMessageImpl(void) + : __messageId(L"") + , __subject(L"") + , __dateTime() + , __toAddress(L"") + , __ccAddress(L"") + , __bccAddress(L"") + , __fromAddress(L"") + , __replyToAddress(L"") + , __returnPath(L"") + , __filePathBody(L"") + , __filePathHtmlBody(L"") + , __filePathMimeEntity(L"") + , __mailSize(0) + , __priority((EmailMessagePriority) -1) + , __returnReceiptType((EmailReturnReceiptType) -1) + , __attachmentCount(0) + , __inlineContentCount(0) + , __messageClass((EmailMessageClass) -1) + , __digestType((EmailDigestType) -1) + , __smimeType((EmailSmimeType) -1) + , __pAttachmentList(null) +{ +} + +_DetailedEmailMessageImpl::_DetailedEmailMessageImpl(const _DetailedEmailMessageImpl& value) +{ + int count = 0; + ArrayList* pList = null; + + __messageId = value.__messageId; + __subject = value.__subject; + __dateTime = value.__dateTime; + __toAddress = value.__toAddress; + __ccAddress = value.__ccAddress; + __bccAddress = value.__bccAddress; + __fromAddress = value.__fromAddress; + __replyToAddress = value.__replyToAddress; + __returnPath = value.__returnPath; + __filePathBody = value.__filePathBody; + __filePathHtmlBody = value.__filePathHtmlBody; + __filePathMimeEntity = value.__filePathMimeEntity; + __mailSize = value.__mailSize; + __priority = value.__priority; + __returnReceiptType = value.__returnReceiptType; + __attachmentCount = value.__attachmentCount; + __inlineContentCount = value.__inlineContentCount; + __messageClass = value.__messageClass; + __digestType = value.__digestType; + __smimeType = value.__smimeType; + __pAttachmentList = null; + + if (value.__pAttachmentList) + { + pList = new (std::nothrow) ArrayList(); + SysTryReturnVoidResult(NID_MSG, pList != null, E_OUT_OF_MEMORY, "memory allocation failed."); + + pList->Construct(); + __pAttachmentList = pList; + + count = value.__pAttachmentList->GetCount(); + + for (int index = 0; index < count; index++) + { + EmailAttachment* pEmailAttachmentItem = dynamic_cast (value.__pAttachmentList->GetAt(index)); + SysTryReturnVoidResult(NID_MSG, pEmailAttachmentItem != null, E_OUT_OF_MEMORY, "memory allocation failed."); + + EmailAttachment* pEmailAttachment = null; + + pEmailAttachment = new (std::nothrow) EmailAttachment(); + if (!pEmailAttachment) + { + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "memory allocation failed."); + __pAttachmentList->RemoveAll(true); + delete __pAttachmentList; + __pAttachmentList = null; + SetLastResult(E_OUT_OF_MEMORY); + return; + } + + pEmailAttachment->SetName(pEmailAttachmentItem->GetName()); + pEmailAttachment->SetFilePath(pEmailAttachmentItem->GetFilePath()); + pEmailAttachment->SetInlineContentStatus(pEmailAttachmentItem->GetInlineContentStatus()); + pEmailAttachment->SetDrmStatus(pEmailAttachmentItem->GetDrmStatus()); + pEmailAttachment->SetMimeType(pEmailAttachmentItem->GetMimeType()); + + pList->Add(*pEmailAttachment); + } + } +} + +_DetailedEmailMessageImpl::~_DetailedEmailMessageImpl(void) +{ + if (__pAttachmentList) + { + if (__pAttachmentList->GetCount() > 0) + { + __pAttachmentList->RemoveAll(true); + } + delete __pAttachmentList; + __pAttachmentList = null; + } +} + +_DetailedEmailMessageImpl& +_DetailedEmailMessageImpl::operator =(const _DetailedEmailMessageImpl& rhs) +{ + if (this != &rhs) + { + int count = 0; + ArrayList* pList = null; + + __messageId = rhs.__messageId; + __subject = rhs.__subject; + __dateTime = rhs.__dateTime; + __toAddress = rhs.__toAddress; + __ccAddress = rhs.__ccAddress; + __bccAddress = rhs.__bccAddress; + __fromAddress = rhs.__fromAddress; + __replyToAddress = rhs.__replyToAddress; + __returnPath = rhs.__returnPath; + __filePathBody = rhs.__filePathBody; + __filePathHtmlBody = rhs.__filePathHtmlBody; + __filePathMimeEntity = rhs.__filePathMimeEntity; + __mailSize = rhs.__mailSize; + __priority = rhs.__priority; + __returnReceiptType = rhs.__returnReceiptType; + __attachmentCount = rhs.__attachmentCount; + __inlineContentCount = rhs.__inlineContentCount; + __messageClass = rhs.__messageClass; + __digestType = rhs.__digestType; + __smimeType = rhs.__smimeType; + + if (__pAttachmentList) + { + if (__pAttachmentList->GetCount() > 0) + { + __pAttachmentList->RemoveAll(true); + } + delete __pAttachmentList; + __pAttachmentList = null; + } + + + if (rhs.__pAttachmentList) + { + pList = new (std::nothrow) ArrayList(); + if (!pList) + { + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "memory allocation failed."); + SetLastResult(E_OUT_OF_MEMORY); + return (*this); + } + + pList->Construct(); + __pAttachmentList = pList; + + count = rhs.__pAttachmentList->GetCount(); + for (int index = 0; index < count; index++) + { + EmailAttachment* pEmailAttachmentItem = dynamic_cast (rhs.__pAttachmentList->GetAt(index)); + if (!pEmailAttachmentItem) + { + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "memory allocation failed."); + __pAttachmentList->RemoveAll(true); + delete __pAttachmentList; + __pAttachmentList = null; + SetLastResult(E_OUT_OF_MEMORY); + return (*this); + } + + EmailAttachment* pEmailAttachment = null; + pEmailAttachment = new (std::nothrow) EmailAttachment(); + if (!pEmailAttachment) + { + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "memory allocation failed."); + __pAttachmentList->RemoveAll(true); + delete __pAttachmentList; + __pAttachmentList = null; + SetLastResult(E_OUT_OF_MEMORY); + return (*this); + } + + pEmailAttachment->SetName(pEmailAttachmentItem->GetName()); + pEmailAttachment->SetFilePath(pEmailAttachmentItem->GetFilePath()); + pEmailAttachment->SetInlineContentStatus(pEmailAttachmentItem->GetInlineContentStatus()); + pEmailAttachment->SetDrmStatus(pEmailAttachmentItem->GetDrmStatus()); + pEmailAttachment->SetMimeType(pEmailAttachmentItem->GetMimeType()); + + pList->Add(*pEmailAttachment); + } + } + } + + return (*this); +} + +bool +_DetailedEmailMessageImpl::Equals(const Tizen::Base::Object& value) const +{ + const _DetailedEmailMessageImpl* pDetailedEmailMessageImpl = dynamic_cast(&value); + if (!pDetailedEmailMessageImpl) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + // attach id + if (__messageId != pDetailedEmailMessageImpl->__messageId) + { + return false; + } + + // msg subject + if (__subject != pDetailedEmailMessageImpl->__subject) + { + return false; + } + + // msg sent/recevie time + if (__dateTime != pDetailedEmailMessageImpl->__dateTime) + { + return false; + } + + // msg to address + if (__toAddress != pDetailedEmailMessageImpl->__toAddress) + { + return false; + } + + // msg cc address + if (__ccAddress != pDetailedEmailMessageImpl->__ccAddress) + { + return false; + } + + // msg bcc address + if (__bccAddress != pDetailedEmailMessageImpl->__bccAddress) + { + return false; + } + // msg from address + if (__fromAddress != pDetailedEmailMessageImpl->__fromAddress) + { + return false; + } + + // msg replay address + if (__replyToAddress != pDetailedEmailMessageImpl->__replyToAddress) + { + return false; + } + + // msg return path + if (__returnPath != pDetailedEmailMessageImpl->__returnPath) + { + return false; + } + // body file path + if (__filePathBody != pDetailedEmailMessageImpl->__filePathBody) + { + return false; + } + + // html body file path + if (__filePathHtmlBody != pDetailedEmailMessageImpl->__filePathHtmlBody) + { + return false; + } + + // msg mime entity + if (__filePathMimeEntity != pDetailedEmailMessageImpl->__filePathMimeEntity) + { + return false; + } + + // msg size + if (__mailSize != pDetailedEmailMessageImpl->__mailSize) + { + return false; + } + + // msg priority + if (__priority != pDetailedEmailMessageImpl->__priority) + { + return false; + } + // msg recepient type + if (__returnReceiptType != pDetailedEmailMessageImpl->__returnReceiptType) + { + return false; + } + + // msg attachment count + if (__attachmentCount != pDetailedEmailMessageImpl->__attachmentCount) + { + return false; + } + + // msg inline content count + if (__inlineContentCount != pDetailedEmailMessageImpl->__inlineContentCount) + { + return false; + } + // msg class + if (__messageClass != pDetailedEmailMessageImpl->__messageClass) + { + return false; + } + + // msg digest type + if (__digestType != pDetailedEmailMessageImpl->__digestType) + { + return false; + } + + // msg mime type + if (__smimeType != pDetailedEmailMessageImpl->__smimeType) + { + return false; + } + + // attachment list + if (__pAttachmentList) + { + if (!__pAttachmentList->Equals(*(pDetailedEmailMessageImpl->__pAttachmentList))) + { + return false; + } + } + else + { + if (pDetailedEmailMessageImpl->__pAttachmentList) + { + return false; + } + } + + return true; +} + +int +_DetailedEmailMessageImpl::GetHashCode(void) const +{ + int hash = 0; + + hash = __messageId.GetHashCode() + __subject.GetHashCode() + __dateTime.GetHashCode() + __toAddress.GetHashCode() + + __ccAddress.GetHashCode() + __bccAddress.GetHashCode() + __fromAddress.GetHashCode() + __replyToAddress.GetHashCode() + + __returnPath.GetHashCode() + __filePathBody.GetHashCode() + __filePathHtmlBody.GetHashCode() + + __filePathMimeEntity.GetHashCode() + __mailSize + (int)__priority + (int)__returnReceiptType + __attachmentCount + + __inlineContentCount + (int)__messageClass + (int)__digestType + (int)__smimeType; + + if (__pAttachmentList) + { + hash += __pAttachmentList->GetHashCode(); + } + + return hash; +} + +Tizen::Base::String +_DetailedEmailMessageImpl::GetMessageId(void) const +{ + return __messageId; +} + +Tizen::Base::String +_DetailedEmailMessageImpl::GetSubject(void) const +{ + return __subject; +} + +Tizen::Base::DateTime +_DetailedEmailMessageImpl::GetCreationTime(void) const +{ + return __dateTime; +} + +Tizen::Base::String +_DetailedEmailMessageImpl::GetAddress(RecipientType type) const +{ + if (type == RECIPIENT_TYPE_TO) + { + return __toAddress; + } + else if (type == RECIPIENT_TYPE_CC) + { + return __ccAddress; + } + else if (type == RECIPIENT_TYPE_BCC) + { + return __bccAddress; + } + else + { + return ""; + } +} + +Tizen::Base::String +_DetailedEmailMessageImpl::GetFromAddress(void) const +{ + return __fromAddress; +} + +Tizen::Base::String +_DetailedEmailMessageImpl::GetReplyToAddress(void) const +{ + return __replyToAddress; +} + +Tizen::Base::String +_DetailedEmailMessageImpl::GetReturnPath(void) const +{ + return __returnPath; +} + +Tizen::Base::String +_DetailedEmailMessageImpl::GetFilePath(EmailMessageBodyType type) const +{ + if (type == EMAIL_MESSAGE_BODY_TYPE_PLAIN_TEXT) + { + return __filePathBody; + } + else if (type == EMAIL_MESSAGE_BODY_TYPE_HTML) + { + return __filePathHtmlBody; + } + else if (type == EMAIL_MESSAGE_BODY_TYPE_MIME) + { + return __filePathMimeEntity; + } + else + { + return ""; + } +} + +EmailMessagePriority +_DetailedEmailMessageImpl::GetPriority(void) const +{ + return __priority; +} + +EmailReturnReceiptType +_DetailedEmailMessageImpl::GetReturnReceiptType(void) const +{ + return __returnReceiptType; +} + +int +_DetailedEmailMessageImpl::GetInlineContentCount(void) const +{ + return __inlineContentCount; +} + +EmailMessageClass +_DetailedEmailMessageImpl::GetClass(void) const +{ + return __messageClass; +} + +EmailDigestType +_DetailedEmailMessageImpl::GetDigestType(void) const +{ + return __digestType; +} + +EmailSmimeType +_DetailedEmailMessageImpl::GetSmimeType(void) const +{ + return __smimeType; +} + +Tizen::Base::Collection::IList* +_DetailedEmailMessageImpl::GetAttachmentListN(void) +{ + result r = E_SUCCESS; + ArrayList* pAttachmentList = null; + int count = 0; + + ClearLastResult(); + + // get total count of attached files + if (__pAttachmentList) + { + count = __pAttachmentList->GetCount(); + } + + pAttachmentList = new (std::nothrow) ArrayList(); + SysTryCatch(NID_MSG, pAttachmentList != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + + r = pAttachmentList->Construct(); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Failed to construct attachment list.", GetErrorMessage(r)); + + + for (int index = 0; index < count; index++) + { + EmailAttachment* pEmailAttachmentItem = dynamic_cast (__pAttachmentList->GetAt(index)); + SysTryCatch(NID_MSG, pEmailAttachmentItem != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + + EmailAttachment* pEmailAttachment = null; + + pEmailAttachment = new (std::nothrow) EmailAttachment(); + SysTryCatch(NID_MSG, pEmailAttachment != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + + pEmailAttachment->SetName(pEmailAttachmentItem->GetName()); + pEmailAttachment->SetFilePath(pEmailAttachmentItem->GetFilePath()); + pEmailAttachment->SetInlineContentStatus(pEmailAttachmentItem->GetInlineContentStatus()); + pEmailAttachment->SetDrmStatus(pEmailAttachmentItem->GetDrmStatus()); + pEmailAttachment->SetMimeType(pEmailAttachmentItem->GetMimeType()); + + r = pAttachmentList->Add(*pEmailAttachment); + } + + SetLastResult(r); + return pAttachmentList; + +CATCH: + SetLastResult(r); + if (pAttachmentList) + { + if (pAttachmentList->GetCount() > 0) + { + pAttachmentList->RemoveAll(true); + } + delete pAttachmentList; + pAttachmentList = null; + } + + return null; +} + +result +_DetailedEmailMessageImpl::SetMessageId(const Tizen::Base::String& messageId) +{ + result r = E_SUCCESS; + + __messageId = messageId; + + return r; +} + +result +_DetailedEmailMessageImpl::SetSubject(const Tizen::Base::String& subject) +{ + result r = E_SUCCESS; + + __subject = subject; + + return r; +} + +result +_DetailedEmailMessageImpl::SetCreationTime(const Tizen::Base::DateTime& dateTime) +{ + result r = E_SUCCESS; + + __dateTime = dateTime; + + return r; +} + +result +_DetailedEmailMessageImpl::SetAddress(RecipientType type, const Tizen::Base::String& recipients) +{ + result r = E_SUCCESS; + + if (type == RECIPIENT_TYPE_TO) + { + __toAddress = recipients; + } + else if (type == RECIPIENT_TYPE_CC) + { + __ccAddress = recipients; + } + else if (type == RECIPIENT_TYPE_BCC) + { + __bccAddress = recipients; + } + else + { + } + + return r; +} + +result +_DetailedEmailMessageImpl::SetFromAddress(const Tizen::Base::String& address) +{ + result r = E_SUCCESS; + + __fromAddress = address; + + return r; +} + +result +_DetailedEmailMessageImpl::SetReplyToAddress(const Tizen::Base::String& address) +{ + result r = E_SUCCESS; + + __replyToAddress = address; + + return r; +} + +result +_DetailedEmailMessageImpl::SetReturnPath(const Tizen::Base::String& address) +{ + result r = E_SUCCESS; + + __returnPath = address; + + return r; +} + +result +_DetailedEmailMessageImpl::SetFilePath(EmailMessageBodyType type, const Tizen::Base::String& filePath) +{ + result r = E_SUCCESS; + + if (type == EMAIL_MESSAGE_BODY_TYPE_PLAIN_TEXT) + { + __filePathBody = filePath; + } + else if (type == EMAIL_MESSAGE_BODY_TYPE_HTML) + { + __filePathHtmlBody = filePath; + } + else if (type == EMAIL_MESSAGE_BODY_TYPE_MIME) + { + __filePathMimeEntity = filePath; + } + else + { + } + + return r; +} + +result +_DetailedEmailMessageImpl::SetPriority(EmailMessagePriority priority) +{ + result r = E_SUCCESS; + + __priority = priority; + + return r; +} + +result +_DetailedEmailMessageImpl::SetReturnReceiptType(EmailReturnReceiptType type) +{ + result r = E_SUCCESS; + + __returnReceiptType = type; + + return r; +} + +result +_DetailedEmailMessageImpl::SetInlineContentCount(int count) +{ + result r = E_SUCCESS; + + __inlineContentCount = count; + + return r; +} + +result +_DetailedEmailMessageImpl::SetClass(EmailMessageClass messageClass) +{ + result r = E_SUCCESS; + + __messageClass = messageClass; + + return r; +} + +result +_DetailedEmailMessageImpl::SetDigestType(EmailDigestType type) +{ + result r = E_SUCCESS; + + __digestType = type; + + return r; +} + +result +_DetailedEmailMessageImpl::SetSmimeType(EmailSmimeType type) +{ + result r = E_SUCCESS; + + __smimeType = type; + + return r; +} + +result +_DetailedEmailMessageImpl::SetAttachmentList(const Tizen::Base::Collection::IList* pList) +{ + result r = E_SUCCESS; + Tizen::Base::Collection::IList* pTempList = null; + ClearLastResult(); + + pTempList = const_cast (pList); + SysTryReturn(NID_MSG, pTempList != null, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] Propagating."); + + if (__pAttachmentList) + { + if (__pAttachmentList->GetCount() > 0) + { + __pAttachmentList->RemoveAll(true); + } + delete __pAttachmentList; + __pAttachmentList = null; + } + + __pAttachmentList = new (std::nothrow) ArrayList(); + SysTryReturn(NID_MSG, __pAttachmentList != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed."); + + r = __pAttachmentList->Construct(); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed."); + + for (int index = 0; index < pTempList->GetCount(); index++) + { + EmailAttachment* pEmailAttachmentItem = dynamic_cast (pTempList->GetAt(index)); + SysTryReturn(NID_MSG, pEmailAttachmentItem != null, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] Propagating."); + + EmailAttachment* pEmailAttachment = null; + + pEmailAttachment = new (std::nothrow) EmailAttachment(); + SysTryReturn(NID_MSG, pEmailAttachment != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed."); + + pEmailAttachment->SetName(pEmailAttachmentItem->GetName()); + pEmailAttachment->SetFilePath(pEmailAttachmentItem->GetFilePath()); + pEmailAttachment->SetInlineContentStatus(pEmailAttachmentItem->GetInlineContentStatus()); + pEmailAttachment->SetDrmStatus(pEmailAttachmentItem->GetDrmStatus()); + pEmailAttachment->SetMimeType(pEmailAttachmentItem->GetMimeType()); + + r = __pAttachmentList->Add(*pEmailAttachment); + } + + return r; +} + +result +_DetailedEmailMessageImpl::ParseMimeFile(const Tizen::Base::String& filePath, DetailedEmailMessage& message) +{ + result r = E_SUCCESS; + int err = EMAIL_ERROR_NONE; + char* pEmlFilePath = null; + email_mail_data_t* pMailData = null; + email_attachment_data_t* pAttachmentData = null; + DateTime msgDateTime; + int attachmentCount = 0; + + ClearLastResult(); + pEmlFilePath = _StringConverter::CopyToCharArrayN(filePath); + SysTryCatch(NID_MSG, pEmlFilePath != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed."); + + err = email_parse_mime_file(pEmlFilePath, &pMailData, &pAttachmentData, &attachmentCount); + + r = _DetailedEmailMessageImpl::ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to parse the email message.", GetErrorMessage(r)); + + r = _DetailedEmailMessageImpl::FillDetailedEmailMessage(message, pMailData, pAttachmentData); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to Fill Detailed EmailMessage.", GetErrorMessage(r)); + + if (pEmlFilePath) + { + delete[] pEmlFilePath; + pEmlFilePath = null; + } + + if (pMailData) + { + email_delete_parsed_data(pMailData); + email_free_mail_data(&pMailData, 1); + } + + if (pAttachmentData) + { + email_free_attachment_data(&pAttachmentData, attachmentCount); + } + + return r; + +CATCH: + + SetLastResult(GetLastResult()); + + if (pEmlFilePath) + { + delete[] pEmlFilePath; + pEmlFilePath = null; + } + + if (pMailData) + { + email_delete_parsed_data(pMailData); + email_free_mail_data(&pMailData, 1); + } + + if (pAttachmentData) + { + email_free_attachment_data(&pAttachmentData, attachmentCount); + } + + return r; +} + +result +_DetailedEmailMessageImpl::WriteToMimeFile(const DetailedEmailMessage& message, const Tizen::Base::String& filePath) +{ + bool isEmptyEmailMessage = _DetailedEmailMessageImpl::IsEmtpyEmailMessage(message); + SysTryReturnResult(NID_MSG, isEmptyEmailMessage == false, E_INVALID_ARG, + "The subject, body, recipients, and from address field of the message are all empty."); + + result r = E_SUCCESS; + int err = EMAIL_ERROR_NONE; + char* pEmlFilePath = null; + email_mail_data_t* pMailData = null; + email_attachment_data_t* pAttachmentData = null; + email_attachment_data_t* pTempAttachmentData = null; + int attachmentCount = 0; + Tizen::Base::Collection::IList* pTempList = null; + char* pAttachName = null; + char* pAttachFilePath = null; + char* pAttachMimeType = null; + + ClearLastResult(); + + email_service_begin(); + pEmlFilePath = _StringConverter::CopyToCharArrayN(filePath); + SysTryCatch(NID_MSG, pEmlFilePath != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed."); + + pTempList = (const_cast (message)).GetAttachmentListN(); + SysTryCatch(NID_MSG, pTempList != null, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Propagating."); + + attachmentCount = pTempList->GetCount(); + + pMailData = (email_mail_data_t*) malloc(sizeof(email_mail_data_t)); + SysTryCatch(NID_MSG, pMailData != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + memset(pMailData, 0x00, sizeof(email_mail_data_t)); + + if (attachmentCount >= 1) + { + pAttachmentData = (email_attachment_data_t*) malloc(sizeof(email_attachment_data_t)* attachmentCount); + SysTryCatch(NID_MSG, pAttachmentData != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + memset(pAttachmentData, 0x00, (sizeof(email_attachment_data_t)* attachmentCount)); + pTempAttachmentData = pAttachmentData; + + for (int index = 0; index < attachmentCount; index++) + { + EmailAttachment* pEmailAttachmentItem = dynamic_cast (pTempList->GetAt(index)); + SysTryCatch(NID_MSG, pEmailAttachmentItem != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + + pAttachName = _StringConverter::CopyToCharArrayN(pEmailAttachmentItem->GetName()); + SysTryCatch(NID_MSG, pAttachName != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + pTempAttachmentData->attachment_name = strdup(pAttachName); + if (pAttachName) + { + delete[] pAttachName; + pAttachName = null; + } + + pAttachFilePath = _StringConverter::CopyToCharArrayN(pEmailAttachmentItem->GetFilePath()); + SysTryCatch(NID_MSG, pAttachFilePath != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + pTempAttachmentData->attachment_path = strdup(pAttachFilePath); + if (pAttachFilePath) + { + delete[] pAttachFilePath; + pAttachFilePath = null; + } + + pTempAttachmentData->inline_content_status = (int) pEmailAttachmentItem->GetInlineContentStatus(); + pTempAttachmentData->drm_status = (int) pEmailAttachmentItem->GetDrmStatus(); + + pAttachMimeType = _StringConverter::CopyToCharArrayN(pEmailAttachmentItem->GetMimeType()); + SysTryCatch(NID_MSG, pAttachMimeType != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + pTempAttachmentData->attachment_mime_type = strdup(pAttachMimeType); + if (pAttachMimeType) + { + delete[] pAttachMimeType; + pAttachMimeType = null; + } + + pTempAttachmentData++; + } + } + + r = _DetailedEmailMessageImpl::FillEmailData(message, &pMailData); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to Fill email data.", GetErrorMessage(r)); + + err = email_write_mime_file(pMailData, pAttachmentData, attachmentCount, &pEmlFilePath); + + r = _DetailedEmailMessageImpl::ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to write email message to file.", GetErrorMessage(r)); + + if (pEmlFilePath) + { + delete[] pEmlFilePath; + pEmlFilePath = null; + } + + if (pMailData) + { + email_free_mail_data(&pMailData, 1); + } + + if (pAttachmentData) + { + email_free_attachment_data(&pAttachmentData, attachmentCount); + } + + if (pTempList) + { + if (pTempList->GetCount() > 0) + { + pTempList->RemoveAll(true); + } + delete pTempList; + pTempList = null; + } + + return r; + +CATCH: + + SetLastResult(GetLastResult()); + + if (pEmlFilePath) + { + delete[] pEmlFilePath; + pEmlFilePath = null; + } + + if (pAttachName) + { + delete[] pAttachName; + pAttachName = null; + } + + if (pAttachFilePath) + { + delete[] pAttachFilePath; + pAttachFilePath = null; + } + + if (pAttachMimeType) + { + delete[] pAttachMimeType; + pAttachMimeType = null; + } + + if (pMailData) + { + email_free_mail_data(&pMailData, 1); + } + + if (pAttachmentData) + { + email_free_attachment_data(&pAttachmentData, attachmentCount); + } + + if (pTempList) + { + if (pTempList->GetCount() > 0) + { + pTempList->RemoveAll(true); + } + delete pTempList; + pTempList = null; + } + + return r; +} + +result +_DetailedEmailMessageImpl::ConvertException(int err) +{ + result r = E_SUCCESS; + + switch (err) + { + case EMAIL_ERROR_NONE: + r = E_SUCCESS; + break; + + case EMAIL_ERROR_INVALID_ADDRESS: + r = E_INVALID_ADDRESS; + break; + + case EMAIL_ERROR_INVALID_PARAM: + case EMAIL_ERROR_INVALID_ATTACHMENT: + case EMAIL_ERROR_ATTACHMENT_NOT_FOUND: + case EMAIL_ERROR_FILE_NOT_FOUND: + r = E_INVALID_ARG; + break; + + case EMAIL_ERROR_ACCOUNT_NOT_FOUND: + case EMAIL_ERROR_INVALID_ACCOUNT: + r = E_INVALID_ACCOUNT; + break; + + case EMAIL_ERROR_ALREADY_EXISTS: + r = E_FILE_ALREADY_EXIST; + break; + + case EMAIL_ERROR_XML_PARSER_FAILURE: + case EMAIL_ERROR_ON_PARSING: + case EMAIL_ERROR_INVALID_DATA: + r = E_PARSING_FAILED; + break; + + case EMAIL_ERROR_DB_FAILURE: + case EMAIL_ERROR_OUT_OF_MEMORY: + r = E_STORAGE_FULL; + break; + + default: + r = E_SYSTEM; + break; + } + + return r; +} + +result +_DetailedEmailMessageImpl::FillDetailedEmailMessage(DetailedEmailMessage& message, email_mail_data_t* pMailData, email_attachment_data_t* pAttachmentData) +{ + result r = E_SUCCESS; + ArrayList* pList = null; + + ClearLastResult(); + + SysTryReturn(NID_MSG, pMailData != null, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] Propagating."); + SysTryReturn(NID_MSG, pAttachmentData != null, E_INVALID_ARG, r = E_INVALID_ARG, "[E_INVALID_ARG] Propagating."); + + String messageId(pMailData->message_id); + message.SetMessageId(messageId); + + String msgSubject(pMailData->subject); + message.SetSubject(msgSubject); + + struct tm* pTempTime = null; + time_t time = pMailData->date_time; + pTempTime = gmtime(&time); + DateTime msgDateTime; + + if (pTempTime) + { + msgDateTime.SetValue(pTempTime->tm_year + 1900, pTempTime->tm_mon + 1, pTempTime->tm_mday, pTempTime->tm_hour + 1, pTempTime->tm_min, pTempTime->tm_sec); + } + message.SetCreationTime(msgDateTime); + + String toAddr(pMailData->full_address_to); + String ccAddr(pMailData->full_address_cc); + String bccAddr(pMailData->full_address_bcc); + + message.SetAddress(RECIPIENT_TYPE_TO, toAddr); + message.SetAddress(RECIPIENT_TYPE_CC, ccAddr); + message.SetAddress(RECIPIENT_TYPE_BCC, bccAddr); + + String fromAddress(pMailData->full_address_from); + message.SetFromAddress(fromAddress); + + String replayToAddress(pMailData->full_address_reply); + message.SetReplyToAddress(replayToAddress); + + String returnAddrPath(pMailData->full_address_return); + message.SetReturnPath(returnAddrPath); + + String filePathPlain(pMailData->file_path_plain); + String filePathHtml(pMailData->file_path_html); + String filePathMime(pMailData->file_path_mime_entity); + + message.SetFilePath(EMAIL_MESSAGE_BODY_TYPE_PLAIN_TEXT, filePathPlain); + message.SetFilePath(EMAIL_MESSAGE_BODY_TYPE_HTML, filePathHtml); + message.SetFilePath(EMAIL_MESSAGE_BODY_TYPE_MIME, filePathMime); + + message.SetPriority((EmailMessagePriority) pMailData->priority); + message.SetReturnReceiptType((EmailReturnReceiptType) pMailData->report_status); + message.SetInlineContentCount(pMailData->inline_content_count); + message.SetClass((EmailMessageClass) pMailData->message_class); + message.SetDigestType((EmailDigestType) pMailData->digest_type); + message.SetSmimeType((EmailSmimeType) pMailData->smime_type); + + pList = new (std::nothrow) ArrayList(); + SysTryCatch(NID_MSG, pList != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + + r = pList->Construct(); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct attachment list.", GetErrorMessage(r)); + + for (int index = 0; index < pMailData->attachment_count; index++) + { + EmailAttachment* pEmailAttachment = null; + pEmailAttachment = new (std::nothrow) EmailAttachment(); + SysTryCatch(NID_MSG, pEmailAttachment != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + + String attachName(pAttachmentData[index].attachment_name); + pEmailAttachment->SetName(attachName); + String attachPath(pAttachmentData[index].attachment_path); + pEmailAttachment->SetFilePath(attachPath); + pEmailAttachment->SetInlineContentStatus((bool) pAttachmentData[index].inline_content_status); + pEmailAttachment->SetDrmStatus((bool) pAttachmentData[index].drm_status); + String attachMimeType(pAttachmentData[index].attachment_mime_type); + pEmailAttachment->SetMimeType(attachMimeType); + + r = pList->Add(*pEmailAttachment); + } + + r = message.SetAttachmentList(pList); + + if (pList) + { + if (pList->GetCount() > 0) + { + pList->RemoveAll(true); + } + delete pList; + pList = null; + } + + return r; + +CATCH: + SetLastResult(GetLastResult()); + + if (pList) + { + if (pList->GetCount() > 0) + { + pList->RemoveAll(true); + } + delete pList; + pList = null; + } + return r; +} + +result +_DetailedEmailMessageImpl::FillEmailData(const DetailedEmailMessage& message, email_mail_data_t** pMailData) +{ + result r = E_SUCCESS; + char* pMessageId = null; + char* pMessageSubject = null; + char* pToAddr = null; + char* pCcAddr = null; + char* pBccAddr = null; + char* pFromAddr = null; + char* pReplayToAddr = null; + char* pReturnPath = null; + char* pFilePathPlain = null; + char* pFilePathHtml = null; + char* pFilePathMime = null; + time_t time = 0; + struct tm timeinfo; + DateTime msgDateTime; + + ClearLastResult(); + + pMessageId = _StringConverter::CopyToCharArrayN(message.GetMessageId()); + SysTryCatch(NID_MSG, pMessageId != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + (*pMailData)->message_id = strdup(pMessageId); + + pMessageSubject = _StringConverter::CopyToCharArrayN(message.GetSubject()); + SysTryCatch(NID_MSG, pMessageSubject != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + (*pMailData)->subject = strdup(pMessageSubject); + + msgDateTime = message.GetCreationTime(); + timeinfo.tm_year = msgDateTime.GetYear(); + timeinfo.tm_mon = msgDateTime.GetMonth(); + timeinfo.tm_mday = msgDateTime.GetDay(); + timeinfo.tm_hour = msgDateTime.GetHour(); + timeinfo.tm_min = msgDateTime.GetMinute(); + timeinfo.tm_sec = msgDateTime.GetSecond(); + + time = mktime(&timeinfo); + (*pMailData)->date_time = time; + + pToAddr = _StringConverter::CopyToCharArrayN(message.GetAddress(RECIPIENT_TYPE_TO)); + SysTryCatch(NID_MSG, pToAddr != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + (*pMailData)->full_address_to = strdup(pToAddr); + + pCcAddr = _StringConverter::CopyToCharArrayN(message.GetAddress(RECIPIENT_TYPE_CC)); + SysTryCatch(NID_MSG, pCcAddr != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + (*pMailData)->full_address_cc = strdup(pCcAddr); + + pBccAddr = _StringConverter::CopyToCharArrayN(message.GetAddress(RECIPIENT_TYPE_BCC)); + SysTryCatch(NID_MSG, pBccAddr != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + (*pMailData)->full_address_bcc = strdup(pBccAddr); + + pFromAddr = _StringConverter::CopyToCharArrayN(message.GetFromAddress()); + SysTryCatch(NID_MSG, pFromAddr != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + (*pMailData)->full_address_from = strdup(pFromAddr); + + pReplayToAddr = _StringConverter::CopyToCharArrayN(message.GetReplyToAddress()); + SysTryCatch(NID_MSG, pReplayToAddr != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + (*pMailData)->full_address_reply = strdup(pReplayToAddr); + + pReturnPath = _StringConverter::CopyToCharArrayN(message.GetReturnPath()); + SysTryCatch(NID_MSG, pReturnPath != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + (*pMailData)->full_address_return = strdup(pReturnPath); + + pFilePathPlain = _StringConverter::CopyToCharArrayN(message.GetFilePath(EMAIL_MESSAGE_BODY_TYPE_PLAIN_TEXT)); + SysTryCatch(NID_MSG, pFilePathPlain != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + (*pMailData)->full_address_return = strdup(pFilePathPlain); + + pFilePathHtml = _StringConverter::CopyToCharArrayN(message.GetFilePath(EMAIL_MESSAGE_BODY_TYPE_HTML)); + SysTryCatch(NID_MSG, pFilePathHtml != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + (*pMailData)->full_address_return = strdup(pFilePathHtml); + + pFilePathMime = _StringConverter::CopyToCharArrayN(message.GetFilePath(EMAIL_MESSAGE_BODY_TYPE_MIME)); + SysTryCatch(NID_MSG, pFilePathMime != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + (*pMailData)->full_address_return = strdup(pFilePathMime); + + (*pMailData)->priority = (email_mail_priority_t)message.GetPriority(); + (*pMailData)->report_status = (email_mail_report_t)message.GetReturnReceiptType(); + (*pMailData)->inline_content_count = message.GetInlineContentCount(); + (*pMailData)->message_class = (email_message_class)message.GetClass(); + (*pMailData)->digest_type = (email_digest_type)message.GetDigestType(); + (*pMailData)->smime_type = (email_smime_type)message.GetSmimeType(); + (*pMailData)->body_download_status = 1; + + SetLastResult(GetLastResult()); + + if (pMessageId) + { + delete[] pMessageId; + pMessageId = null; + } + + if (pMessageSubject) + { + delete[] pMessageSubject; + pMessageSubject = null; + } + + if (pToAddr) + { + delete[] pToAddr; + pToAddr = null; + } + + if (pCcAddr) + { + delete[] pCcAddr; + pCcAddr = null; + } + + if (pBccAddr) + { + delete[] pBccAddr; + pBccAddr = null; + } + + if (pFromAddr) + { + delete[] pFromAddr; + pFromAddr = null; + } + + if (pReplayToAddr) + { + delete[] pReplayToAddr; + pReplayToAddr = null; + } + + if (pReturnPath) + { + delete[] pReturnPath; + pReturnPath = null; + } + + if (pFilePathPlain) + { + delete[] pFilePathPlain; + pFilePathPlain = null; + } + + if (pFilePathHtml) + { + delete[] pFilePathHtml; + pFilePathHtml = null; + } + + if (pFilePathMime) + { + delete[] pFilePathMime; + pFilePathMime = null; + } + + return r; + +CATCH: + SetLastResult(GetLastResult()); + + if (pMessageId) + { + delete[] pMessageId; + pMessageId = null; + } + + if (pMessageSubject) + { + delete[] pMessageSubject; + pMessageSubject = null; + } + + if (pToAddr) + { + delete[] pToAddr; + pToAddr = null; + } + + if (pCcAddr) + { + delete[] pCcAddr; + pCcAddr = null; + } + + if (pBccAddr) + { + delete[] pBccAddr; + pBccAddr = null; + } + + if (pFromAddr) + { + delete[] pFromAddr; + pFromAddr = null; + } + + if (pReplayToAddr) + { + delete[] pReplayToAddr; + pReplayToAddr = null; + } + + if (pReturnPath) + { + delete[] pReturnPath; + pReturnPath = null; + } + + if (pFilePathPlain) + { + delete[] pFilePathPlain; + pFilePathPlain = null; + } + + if (pFilePathHtml) + { + delete[] pFilePathHtml; + pFilePathHtml = null; + } + + return r; +} + +bool +_DetailedEmailMessageImpl::IsEmtpyEmailMessage(const DetailedEmailMessage& message) +{ + bool isSubjectEmpty= message.GetSubject().IsEmpty(); + bool isBodyEmpty = message.GetFilePath(EMAIL_MESSAGE_BODY_TYPE_PLAIN_TEXT).IsEmpty() + && message.GetFilePath(EMAIL_MESSAGE_BODY_TYPE_HTML).IsEmpty() + && message.GetFilePath(EMAIL_MESSAGE_BODY_TYPE_MIME).IsEmpty(); + bool isRecipientEmpty = message.GetAddress(RECIPIENT_TYPE_TO).IsEmpty() + && message.GetAddress(RECIPIENT_TYPE_CC).IsEmpty() + && message.GetAddress(RECIPIENT_TYPE_BCC).IsEmpty(); + bool isFromAddressEmpty = message.GetFromAddress().IsEmpty(); + + return (isSubjectEmpty && isBodyEmpty && isRecipientEmpty && isFromAddressEmpty); +} + +} } // Tizen::Messaging diff --git a/src/FMsg_DetailedEmailMessageImpl.h b/src/FMsg_DetailedEmailMessageImpl.h new file mode 100644 index 0000000..e3287ba --- /dev/null +++ b/src/FMsg_DetailedEmailMessageImpl.h @@ -0,0 +1,801 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** +* @if VISPARTNER-OPERATOR +* +* @file FMsg_DetailedEmailMessageImpl.h +* @brief This is the header file for the %_DetailedEmailMessageImpl class. +* +* @visibility partner-operator +* +* This header file contains the declarations of the %_DetailedEmailMessageImpl class. +* +* @endif +*/ + +#ifndef _FMSG_INTERNAL_DETAILED_EMAIL_MESSAGE_IMPL_H_ +#define _FMSG_INTERNAL_DETAILED_EMAIL_MESSAGE_IMPL_H_ + +namespace Tizen { namespace Messaging +{ + /** + * @if VISPARTNER-OPERATOR + * + * @class _DetailedEmailMessageImpl + * @brief This class provides methods for handling detailed email messages. + * + * @since 2.1 + * + * @visibility partner-operator + * + * The %_DetailedEmailMessageImpl class provides methods for handling detailed email messages. + * + * @endif + */ + class _DetailedEmailMessageImpl + : public Tizen::Base::Object + { + // Life cycle + public: + /** + * @if VISPARTNER-OPERATOR + * + * This is the default constructor for this class. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @endif + */ + _DetailedEmailMessageImpl(void); + + /** + * @if VISPARTNER-OPERATOR + * + * This is the destructor for this class. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @endif + */ + virtual ~_DetailedEmailMessageImpl(void); + + /** + * @if VISPARTNER-OPERATOR + * + * This is the copy constructor for the %_DetailedEmailMessageImpl class. @n + * Copying of objects using this copy constructor is allowed. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @param[in] rhs An instance of %_DetailedEmailMessageImpl + * + * @endif + */ + _DetailedEmailMessageImpl(const _DetailedEmailMessageImpl& rhs); + + + public: + /** + * @if VISPARTNER-OPERATOR + * + * This assignment operator copies an email message from the specified instance of %_DetailedEmailMessageImpl to the calling instance of %_DetailedEmailMessageImpl. @n + * Copying of objects using this copy assignment operator is allowed. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The reference of this instance + * @param[in] rhs A reference to the %_DetailedEmailMessageImpl instance to be copied + * + * @endif + */ + _DetailedEmailMessageImpl& operator =(const _DetailedEmailMessageImpl& rhs); + + /** + * @if VISPARTNER-OPERATOR + * + * Compares the calling instance with the specified instance. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return @c true if the specified instance of Object is equal to the calling %_DetailedEmailMessageImpl instance, @n + * else @c false + * @param[in] obj The object to compare + * + * @endif + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the hash value of the current instance. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The hash value of the current instance + * + * @endif + */ + virtual int GetHashCode(void) const; + + // Operation + public: + /////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////// + /** + * @if VISPARTNER-OPERATOR + * + * Gets the Message-ID of the message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The Message-ID of the message. + * @see SetMessageId() + * + * @endif + */ + Tizen::Base::String GetMessageId(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the subject of the message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The subject of the email message + * @see SetSubject() + * + * @endif + */ + Tizen::Base::String GetSubject(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the time when the email message was created. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The time when the email message was created + * @see SetCreationTime() + * @remark The creation time may be changed by mail server on sending. + * + * @endif + */ + Tizen::Base::DateTime GetCreationTime(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the recipients of the specific recipient type. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The email address of specified recipient type + * @param[in] type The type of recipient + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @remarks The values for the various recipients can be a string with multiple email addresses separated by semi-colons.(;). @n + * The specified @c type contains RECIPIENT_TYPE_TO, RECIPIENT_TYPE_CC, RECIPIENT_TYPE_BCC. @n + * The specific error code can be accessed using the GetLastResult() method. + * @see SetAddress() + * + * @endif + */ + Tizen::Base::String GetAddress(RecipientType type) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the email address of the author. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The email address of the author + * @see SetFromAddress() + * + * @endif + */ + Tizen::Base::String GetFromAddress(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the email address which used to reply to the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The email address which used to reply to the message + * @see SetReplyToAddress() + * + * @endif + */ + Tizen::Base::String GetReplyToAddress(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the return-path + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The return-path + * @see SetReturnPath() + * + * @endif + */ + Tizen::Base::String GetReturnPath(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the file path of the speicified message body type. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The file path of the message body + * @param[in] type The type of message body + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see SetFilePath() + * + * @endif + */ + Tizen::Base::String GetFilePath(EmailMessageBodyType type) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the priority of the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The priority of the message + * @see SetPriority() + * + * @endif + */ + EmailMessagePriority GetPriority(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the return receipt type of the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The return receipt type of the message + * @see SetReturnReceiptType() + * + * @endif + */ + EmailReturnReceiptType GetReturnReceiptType(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the inline content count of the message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The inline content count of the message + * @see SetInlineContentCount() + * + * @endif + */ + int GetInlineContentCount(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the class of the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The class of the message + * @see SetClass() + * + * @endif + */ + EmailMessageClass GetClass(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the digest type of the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The digest type of the message + * @see SetDigestType() + * + * @endif + */ + EmailDigestType GetDigestType(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the S/MIME type of the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The S/MIME type of the message + * @see SetSmimeType() + * + * @endif + */ + EmailSmimeType GetSmimeType(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the attachment list of the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return A pointer to the list of attachment + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. @n + * After using the attachment list, you can call Tizen::Base::Collection::IList::RemoveAll(true) to clean up items in the list. + * @see EmailAttachment, SetAttachmentList() + * + * @endif + */ + Tizen::Base::Collection::IList* GetAttachmentListN(void); + + + public: + /////////////////////////////////////////////////////////////// + // Setters + /////////////////////////////////////////////////////////////// + /** + * @if VISPARTNER-OPERATOR + * + * Sets the Message-ID of the message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] messageId The Message-ID of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The length of the specified @c messageId is @c 0. + * @remarks The Message ID is an automatically generated field. @n + * It is used to prevent multiple delivery and for reference in In-Reply-To. + * @see GetMessageId() + * + * @endif + */ + result SetMessageId(const Tizen::Base::String& messageId); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the subject of the email. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] subject The subject of the email message + * @exception E_SUCCESS The method is successful. + * @exception E_MAX_EXCEEDED The subject length of the message exceeds the maximum limit (Maximum 256 characters) + * @see GetSubject() + * + * @endif + */ + result SetSubject(const Tizen::Base::String& subject); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the time when the email message was created. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] dateTime The time when the email message was created + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c dateTime is invalid. @n + * The valid range of the time can be from "January 1 1900 00:00:00" to "December 31 2100 23:59:59" + * @see GetCreationTime() + * + * @endif + */ + result SetCreationTime(const Tizen::Base::DateTime& dateTime); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the recipient list of the specific recipient type. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] type The type of recipient + * @param[in] recipients The recipients string + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. @n + * The specified @c recipients string length is too short (< 5). + * @remarks The values for the various recipients can be a string with multiple email addresses separated by semi-colons.(;).@n + * The specified @c type contains RECIPIENT_TYPE_TO, RECIPIENT_TYPE_CC, RECIPIENT_TYPE_BCC. @n + * @see GetAddress() + * + * @endif + */ + result SetAddress(RecipientType type, const Tizen::Base::String& recipients); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the email address of the author. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] address The email address of the author + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c address string length is too short (< 5). + * @see GetFromAddress() + * + * @endif + */ + result SetFromAddress(const Tizen::Base::String& address); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the email address which used to reply to the message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] address The email address which used to reply to the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c address string length is too short (< 5). + * @see GetReplyToAddress() + * + * @endif + */ + result SetReplyToAddress(const Tizen::Base::String& address); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the return-path + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] address The return-path + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c address string length is too short (< 5). + * @see GetReturnPath() + * + * @endif + */ + result SetReturnPath(const Tizen::Base::String& address); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the file path of the speicified message body type. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] type The type of message body + * @param[in] filePath The file path of the message body + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. @n + * The length of the specified @c filePath is too long or @c 0. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @see GetFilePath() + * + * @endif + */ + result SetFilePath(EmailMessageBodyType type, const Tizen::Base::String& filePath); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the prioirity of the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] priority The prioirity of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c priority is invalid. + * @see GetPriority() + * + * @endif + */ + result SetPriority(EmailMessagePriority priority); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the return receipt type of the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] type The return receipt type of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @see GetReturnReceiptType() + * + * @endif + */ + result SetReturnReceiptType(EmailReturnReceiptType type); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the inline content count of the message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] count The inline content count of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c count is less than 0. + * @see GetInlineContentCount() + * + * @endif + */ + result SetInlineContentCount(int count); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the class of the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] messageClass The class of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c messageClass is invalid. + * @see GetClass() + * + * @endif + */ + result SetClass(EmailMessageClass messageClass); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the digest type of the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] type The digest type of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @see GetDigestType() + * + * @endif + */ + result SetDigestType(EmailDigestType type); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the S/MIME type of the message + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] type The S/MIME type of the message + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c type is invalid. + * @see GetSmimeType() + * + * @endif + */ + result SetSmimeType(EmailSmimeType type); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets a attachment list for this message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] pList A list of %EmailAttachment + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The list is not made of %EmailAttachment + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @see EmailAttachment, GetAttachmentListN() + * + * @endif + */ + result SetAttachmentList(const Tizen::Base::Collection::IList* pList); + +public: + /////////////////////////////////////////////////////////////// + // static methods + /////////////////////////////////////////////////////////////// + /** + * @if VISPARTNER-OPERATOR + * + * Parses the MIME file to %_DetailedEmailMessageImpl format + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] filePath The MIME file path to be parsed + * @param[out] message The parsed message + * @exception E_SUCCESS The method is successful. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_PARSING_FAILED The method has failed to parse the MIME file. + * @exception E_SYSTEM A system error has occurred. + * @see WriteToMimeFile() + * + * @endif + */ + static result ParseMimeFile(const Tizen::Base::String& filePath, DetailedEmailMessage& message); + + /** + * @if VISPARTNER-OPERATOR + * + * Write to the MIME file from %_DetailedEmailMessageImpl + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] message The message to be read + * @param[in] filePath The file path of the MIME file to be written + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The value of @c message is invalid + * @exception E_ILLEGAL_ACCESS The specified @c filePath is inaccessible as per the Tizen platform policy. + * @exception E_FILE_ALREADY_EXIST The specified file already exists. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @see ParseMimeFile() + * + * @endif + */ + static result WriteToMimeFile(const DetailedEmailMessage& message, const Tizen::Base::String& filePath); + + + public: + static result ConvertException(int err); + + static result FillDetailedEmailMessage(DetailedEmailMessage& message, email_mail_data_t* pMailData, email_attachment_data_t* pAttachmentData); + + static result FillEmailData(const DetailedEmailMessage& message, email_mail_data_t** pMailData); + + static bool IsEmtpyEmailMessage(const DetailedEmailMessage& message); + + + private: + Tizen::Base::String __messageId; // message ID (not a unique number of a mail), defined in RFC2392, time and date stamp along with the local host's domain name, e.g., 950124.162336@XIson.com. + Tizen::Base::String __subject; // email subject + Tizen::Base::DateTime __dateTime; // sent/received time + + // full address + Tizen::Base::String __toAddress; + Tizen::Base::String __ccAddress; + Tizen::Base::String __bccAddress; + Tizen::Base::String __fromAddress; + Tizen::Base::String __replyToAddress; // Address that should be used to reply to the message. + Tizen::Base::String __returnPath; + + // file path + Tizen::Base::String __filePathBody; + Tizen::Base::String __filePathHtmlBody; + Tizen::Base::String __filePathMimeEntity; + + int __mailSize; + EmailMessagePriority __priority; + EmailReturnReceiptType __returnReceiptType; // email_mail_report_t + int __attachmentCount; + int __inlineContentCount; // inline content => for example, embeded image in html + EmailMessageClass __messageClass; + EmailDigestType __digestType; + EmailSmimeType __smimeType; + + Tizen::Base::Collection::ArrayList* __pAttachmentList; + }; // DetailedEmailMessage +} } // Tizen::Messaging + +#endif // _FMSG_INTERNAL_DETAILED_EMAIL_MESSAGE_IMPL_H_ diff --git a/src/FMsg_EmailAttachmentImpl.cpp b/src/FMsg_EmailAttachmentImpl.cpp new file mode 100644 index 0000000..d2e8edd --- /dev/null +++ b/src/FMsg_EmailAttachmentImpl.cpp @@ -0,0 +1,270 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_EmailAttachmentImpl.cpp + * @brief This is the implementation file for the %_EmailAttachmentImpl class. + * + * This file contains the implementation of the %_EmailAttachmentImpl class. + */ + +#include +#include +#include +#include +#include +#include "FMsg_EmailAttachmentImpl.h" +#include "FMsg_DetailedEmailMessageImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +namespace Tizen { namespace Messaging +{ + +_EmailAttachmentImpl::_EmailAttachmentImpl(void) + : __id(0) + , __name(L"") + , __path(L"") + , __size(0) + , __mailId(0) + , __accountId(0) + , __mailboxName(L"") + , __saveStatus(false) + , __drmStatus(false) + , __inlineContentStatus(false) + , __attachmentMimeType(L"") +{ +} + +_EmailAttachmentImpl::~_EmailAttachmentImpl(void) +{ +} + +_EmailAttachmentImpl::_EmailAttachmentImpl(const _EmailAttachmentImpl& value) +{ + __id = value.__id; + __name = value.__name; + __path = value.__path; + __size = value.__size; + __mailId = value.__mailId; + __accountId = value.__accountId; + __mailboxName = value.__mailboxName; + __saveStatus = value.__saveStatus; + __drmStatus = value.__drmStatus; + __inlineContentStatus = value.__inlineContentStatus; + __attachmentMimeType = value.__attachmentMimeType; +} + +_EmailAttachmentImpl& +_EmailAttachmentImpl::operator =(const _EmailAttachmentImpl& rhs) +{ + if (this != &rhs) + { + __id = rhs.__id; + __name = rhs.__name; + __path = rhs.__path; + __size = rhs.__size; + __mailId = rhs.__mailId; + __accountId = rhs.__accountId; + __mailboxName = rhs.__mailboxName; + __saveStatus = rhs.__saveStatus; + __drmStatus = rhs.__drmStatus; + __inlineContentStatus = rhs.__inlineContentStatus; + __attachmentMimeType = rhs.__attachmentMimeType; + } + + return (*this); +} + +bool +_EmailAttachmentImpl::Equals(const Tizen::Base::Object& obj) const +{ + const _EmailAttachmentImpl* pEmailAttachmentImpl = dynamic_cast(&obj); + + if (!pEmailAttachmentImpl) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + // attach id + if (__id != pEmailAttachmentImpl->__id) + { + return false; + } + + // attach name + if (__name != pEmailAttachmentImpl->__name) + { + return false; + } + + // attach path + if (__path != pEmailAttachmentImpl->__path) + { + return false; + } + + // attach size + if (__size != pEmailAttachmentImpl->__size) + { + return false; + } + + // attach mailid + if (__mailId != pEmailAttachmentImpl->__mailId) + { + return false; + } + + // attach accountid + if (__accountId != pEmailAttachmentImpl->__accountId) + { + return false; + } + // attach id + if (__mailboxName != pEmailAttachmentImpl->__mailboxName) + { + return false; + } + + // attach save status + if (__saveStatus != pEmailAttachmentImpl->__saveStatus) + { + return false; + } + + // attach drm status + if (__drmStatus != pEmailAttachmentImpl->__drmStatus) + { + return false; + } + // attach inline content status + if (__inlineContentStatus != pEmailAttachmentImpl->__inlineContentStatus) + { + return false; + } + + // attach mime type + if (__attachmentMimeType != pEmailAttachmentImpl->__attachmentMimeType) + { + return false; + } + return true; +} + +int +_EmailAttachmentImpl::GetHashCode(void) const +{ + int hash = 0; + + hash = __id + __name.GetHashCode() + __path.GetHashCode() + __size + __mailId + __accountId + + __mailboxName.GetHashCode() + (__saveStatus ? 1 : 0) + (__drmStatus ? 1 : 0) + (__inlineContentStatus ? 1 : 0) + + __attachmentMimeType.GetHashCode(); + + return hash; +} + +Tizen::Base::String +_EmailAttachmentImpl::GetName(void) const +{ + return __name; +} + +Tizen::Base::String +_EmailAttachmentImpl::GetFilePath(void) const +{ + return __path; +} + +int +_EmailAttachmentImpl::GetSize(void) const +{ + FileAttributes fileDetails; + int fileSize = 0; + + if (File::GetAttributes(__path, fileDetails) == E_SUCCESS) + { + fileSize = fileDetails.GetFileSize(); + } + + return fileSize; +} + +bool +_EmailAttachmentImpl::GetInlineContentStatus(void) const +{ + return __inlineContentStatus; +} + +bool +_EmailAttachmentImpl::GetDrmStatus(void) const +{ + return __drmStatus; +} + +Tizen::Base::String +_EmailAttachmentImpl::GetMimeType(void) const +{ + return __attachmentMimeType; +} + +result +_EmailAttachmentImpl::SetName(const Tizen::Base::String& name) +{ + result r = E_SUCCESS; + ClearLastResult(); + + __name = name; + + return r; +} + +result +_EmailAttachmentImpl::SetFilePath(const Tizen::Base::String& filePath) +{ + result r = E_SUCCESS; + ClearLastResult(); + + __path = filePath; + + return r; +} + +void +_EmailAttachmentImpl::SetInlineContentStatus(bool status) +{ + __inlineContentStatus = status; +} + +void +_EmailAttachmentImpl::SetDrmStatus(bool status) +{ + __drmStatus = status; +} + +result +_EmailAttachmentImpl::SetMimeType(const Tizen::Base::String& type) +{ + result r = E_SUCCESS; + ClearLastResult(); + + __attachmentMimeType = type; + + return r; +} +} } // Tizen::Messaging diff --git a/src/FMsg_EmailAttachmentImpl.h b/src/FMsg_EmailAttachmentImpl.h new file mode 100644 index 0000000..3373b52 --- /dev/null +++ b/src/FMsg_EmailAttachmentImpl.h @@ -0,0 +1,363 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** +* @if VISPARTNER-OPERATOR +* +* @file FMsg_EmailAttachmentImpl.h +* @brief This is the header file for the %_EmailAttachmentImpl class. +* +* @visibility partner-operator +* +* This header file contains the declarations of the %_EmailAttachmentImpl class. +* +* @endif +*/ + +#ifndef _FMSG_INTERNAL_EMAIL_ATTACHMENT_IMPL_H_ +#define _FMSG_INTERNAL_EMAIL_ATTACHMENT_IMPL_H_ + +namespace Tizen { namespace Messaging +{ + /** + * @if VISPARTNER-OPERATOR + * + * @class _EmailAttachmentImpl + * @brief This class provides methods for handling email attachments. + * + * @since 2.1 + * + * @visibility partner-operator + * + * The %_EmailAttachmentImpl class provides methods for handling email attachments. + * + * @endif + */ + class _EmailAttachmentImpl + : public Tizen::Base::Object + { + // Life cycle + public: + /** + * @if VISPARTNER-OPERATOR + * + * This is the default constructor for this class. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @endif + */ + _EmailAttachmentImpl(void); + + /** + * @if VISPARTNER-OPERATOR + * + * This is the destructor for this class. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @endif + */ + virtual ~_EmailAttachmentImpl(void); + + /** + * @if VISPARTNER-OPERATOR + * + * This is the copy constructor for the %_EmailAttachmentImpl class. @n + * Copying of objects using this copy constructor is allowed. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @param[in] rhs An instance of %_EmailAttachmentImpl + * + * @endif + */ + _EmailAttachmentImpl(const _EmailAttachmentImpl& rhs); + + + public: + /** + * @if VISPARTNER-OPERATOR + * + * This assignment operator copies an email message from the specified instance of %_EmailAttachmentImpl to the calling instance of %_EmailAttachmentImpl. @n + * Copying of objects using this copy assignment operator is allowed. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The reference of this instance + * @param[in] rhs A reference to the %_EmailAttachmentImpl instance to be copied + * + * @endif + */ + _EmailAttachmentImpl& operator =(const _EmailAttachmentImpl& rhs); + + /** + * @if VISPARTNER-OPERATOR + * + * Compares the calling instance with the specified instance. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return @c true if the specified instance of Object is equal to the calling %_EmailAttachmentImpl instance, @n + * else @c false + * @param[in] obj The object to compare + * + * @endif + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the hash value of the current instance. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The hash value of the current instance + * + * @endif + */ + virtual int GetHashCode(void) const; + + // Operation + public: + /////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////// + /** + * @if VISPARTNER-OPERATOR + * + * Gets the name of the attachment. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The name of the email attachment + * @see SetName() + * + * @endif + */ + Tizen::Base::String GetName(void) const; + + /** + * + * @if VISPARTNER-OPERATOR + * + * Gets the file path of the attachment. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The file path of the attachment + * @see SetFilePath() + * + * @endif + */ + Tizen::Base::String GetFilePath(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the size of the attachment. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The size of the attachment + * + * @endif + */ + int GetSize(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the inline-content status of the attachment + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return @c true if the attachment has inline-content(s), @n + * else @c false + * @see SetInlineContentStatus() + * + * @endif + */ + bool GetInlineContentStatus(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the DRM status of the attachment + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return @c true if the attachment contains DRM, @n + * else @c false + * @see SetDrmStatus() + * + * @endif + */ + bool GetDrmStatus(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the MIME type of the attachment. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The MIME type of the email attachment + * @see SetMimeType() + * + * @endif + */ + Tizen::Base::String GetMimeType(void) const; + + + public: + /////////////////////////////////////////////////////////////// + // Setters + /////////////////////////////////////////////////////////////// + /** + * @if VISPARTNER-OPERATOR + * + * Sets the name of the attachment. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] name The name of the attachment + * @exception E_SUCCESS The method is successful. + * @exception E_MAX_EXCEEDED The length of the name exceeds the maximum limit (Maximum 256 characters) + * @see GetName() + * + * @endif + */ + result SetName(const Tizen::Base::String& name); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the file path of the attachment. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] filePath The file path of the attachment + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The length of the specified @c filePath is too long or @c 0. + * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed. + * @see GetFilePath() + * + * @endif + */ + result SetFilePath(const Tizen::Base::String& filePath); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the inline-content status of the attachment + * + * @since 2.1 + * + * @visibility partner-operator + * + * @param[in] status Set to @c true to change the inline-content status of the attachment to true, @n + * else @c false + * @see GetInlineContentStatus() + * + * @endif + */ + void SetInlineContentStatus(bool status); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the DRM status of the attachment + * + * @since 2.1 + * + * @visibility partner-operator + * + * @param[in] status Set to @c true to change the DRM status of the attachment to true, @n + * else @c false + * @see GetDrmStatus() + * + * @endif + */ + void SetDrmStatus(bool status); + + /** + * @if VISPARTNER-OPERATOR + * + * Sets the MIME type of the attachment. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An error code + * @param[in] type The MIME type of the attachment + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The length of the specified @c type is @c 0. + * @see GetMimeType() + * + * @endif + */ + result SetMimeType(const Tizen::Base::String& type); + + private: + int __id; + Tizen::Base::String __name; + Tizen::Base::String __path; + int __size; + int __mailId; + int __accountId; + Tizen::Base::String __mailboxName; + bool __saveStatus; + bool __drmStatus; + bool __inlineContentStatus; + Tizen::Base::String __attachmentMimeType; /**< Specifies the context mime type.*/ + + }; // _EmailAttachmentImpl +} } // Tizen::Messaging + +#endif // _FMSG_INTERNAL_EMAIL_ATTACHMENT_IMPL_H_ diff --git a/src/FMsg_EmailEvent.cpp b/src/FMsg_EmailEvent.cpp new file mode 100644 index 0000000..ab32181 --- /dev/null +++ b/src/FMsg_EmailEvent.cpp @@ -0,0 +1,64 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_EmailEvent.cpp + * @brief This is the implementation file for the %_EmailEvent class. + * + * This file contains the implementation of the %_EmailEvent class. + */ + +#include +#include +#include "FMsg_EmailEvent.h" +#include "FMsg_EmailEventArg.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Runtime; + +namespace Tizen { namespace Messaging +{ + +_EmailEvent::_EmailEvent(void) +{ +} + +result +_EmailEvent::Construct(void) +{ + return _Event::Initialize(); +} + +void +_EmailEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) +{ + result r = E_SUCCESS; + + IEmailListener* pEmailListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_MSG, pEmailListener != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + IEventArg* pEventArg = const_cast (&arg); + _EmailEventArg* pEmailEventArg = dynamic_cast <_EmailEventArg*>(pEventArg); + SysTryReturnVoidResult(NID_MSG, pEmailEventArg != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + // get error result + pEmailEventArg->GetErrorResult(r); + + // Fire + pEmailListener->OnEmailMessageSent(r); +} + +} } diff --git a/src/FMsg_EmailEvent.h b/src/FMsg_EmailEvent.h new file mode 100644 index 0000000..128c947 --- /dev/null +++ b/src/FMsg_EmailEvent.h @@ -0,0 +1,76 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_EmailEvent.h + * @brief This is the header file for _EmailEvent class. + * + * This header file contains the declarations of _EmailEvent class. + */ + +#ifndef _FMSG_INTERNAL_EMAIL_EVENT_H_ +#define _FMSG_INTERNAL_EMAIL_EVENT_H_ + +// Includes +#include + +namespace Tizen { namespace Messaging +{ + +// +// @class _EmailEvent +// @brief This class provides the event for Email message. +// @since 1.0 +// +// @see IEmailEventListener, EmailEventArg +// + +class _EmailEvent + : public Tizen::Base::Runtime::_Event +{ + // Life cycle +public: + /** + * This is the constructor. + * + */ + _EmailEvent(void); + + /** + * This is the class destructor. + * + */ + virtual ~_EmailEvent(void) {}; + + /** + * Initializes a new instance of the class + * + */ + result Construct(void); + + //Operations +protected: + void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg); + + // Lifecycle +private: + _EmailEvent(const _EmailEvent& emailEvent); + _EmailEvent& operator =(const _EmailEvent& value); +}; // _EmailEvent + +} } + +#endif // _FMSG_INTERNAL_EMAIL_EVENT_H_ diff --git a/src/FMsg_EmailEventArg.cpp b/src/FMsg_EmailEventArg.cpp new file mode 100644 index 0000000..b012775 --- /dev/null +++ b/src/FMsg_EmailEventArg.cpp @@ -0,0 +1,55 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_EmailEventArg.cpp + * @brief This is the implementation file for the %_EmailEventArg class. + * + * This file contains the implementation of the %_EmailEventArg class. + */ + +#include +#include "FMsg_EmailEventArg.h" + +using namespace Tizen::Base; + +namespace Tizen { namespace Messaging +{ + +_EmailEventArg::_EmailEventArg(void) +{ + __result = E_SUCCESS; +} + +_EmailEventArg::_EmailEventArg(result r) +{ + if (IsFailed(r)) + { + __result = E_FAILURE; + } + else + { + __result = r; // E_SUCCESS + } +} + +void +_EmailEventArg::GetErrorResult(result& r) const +{ + r = __result; +} + +} } diff --git a/src/FMsg_EmailEventArg.h b/src/FMsg_EmailEventArg.h new file mode 100644 index 0000000..5e1db76 --- /dev/null +++ b/src/FMsg_EmailEventArg.h @@ -0,0 +1,90 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_EmailEventArg.h + * @brief This is the header file for _EmailEventArg class. + * + * This header file contains the declarations of _EmailEventArg class. + */ + + +#ifndef _FMSG_INTERNAL_EMAIL_EVENT_ARG_H_ +#define _FMSG_INTERNAL_EMAIL_EVENT_ARG_H_ + +// Includes +#include +#include +#include + +namespace Tizen { namespace Messaging +{ + +// +// @class _EmailEventArg +// @brief This class provides methods for getting data from Email event +// @since 1.0 +// + +class _EmailEventArg + : public Tizen::Base::Object + , public Tizen::Base::Runtime::IEventArg +{ + // Life cycle +public: + /** + * This is the constructor. + * + */ + _EmailEventArg(void); + + /** + * This is the constructor. + * + * @param[in] r - the message composer result + * + */ + _EmailEventArg(result r); + + /** + * This is class destructor. + * + */ + virtual ~_EmailEventArg(void) {}; + + // Access +public: + /** + * Gets the error result of Email event + * + * @param[out] r - the message composer result + * @exception E_SUCCESS - operation is successful + * @exception E_OUT_OF_MEMORY - failed to allocate required/requested memory + * @exception E_SYSTEM - the system has an error. + */ + void GetErrorResult(result& r) const; + + // Lifecycle +private: + _EmailEventArg(const _EmailEventArg& emailEventArg); + _EmailEventArg& operator =(const _EmailEventArg& value); + +private: + result __result; +}; // _EmailEventArg +} } + +#endif // _FMSG_INTERNAL_EMAIL_EVENT_ARG_H_ diff --git a/src/FMsg_EmailManagerImpl.cpp b/src/FMsg_EmailManagerImpl.cpp new file mode 100644 index 0000000..fd4dad5 --- /dev/null +++ b/src/FMsg_EmailManagerImpl.cpp @@ -0,0 +1,277 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_EmailManagerImpl.cpp + * @brief This is the implementation file for the %_EmailManagerImpl class. + * + * This file contains the implementation of the %_EmailManagerImpl class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_EmailEvent.h" +#include "FMsg_EmailEventArg.h" +#include "FMsg_EmailManagerImpl.h" +#include "FMsg_Types.h" +#include "FMsg_MsgUtil.h" +#include "FMsg_RecipientListImpl.h" + +using namespace std; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +namespace Tizen { namespace Messaging +{ + + ArrayListT<_EmailAsyncData*>* _EmailManagerImpl::__pEmailAsyncData = null; + Tizen::Base::Runtime::Mutex * _EmailManagerImpl::__pMutex = null; + +_EmailManagerImpl::_EmailManagerImpl(void) + : __pEmailEvent(null) + , __isConstructed(false) +{ +} + +_EmailManagerImpl::~_EmailManagerImpl(void) +{ + __isConstructed = false; +} + +result +_EmailManagerImpl::Construct(IEmailListener& listener) +{ + SysAssertf(__isConstructed == false, "_EmailManagerImpl instance is already constructed."); + + result r = E_SUCCESS; + + // set event + unique_ptr<_EmailEvent> pEmailEvent(new (std::nothrow) _EmailEvent()); + SysTryReturn(NID_MSG, pEmailEvent != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed"); + + // event construction + r = pEmailEvent->Construct(); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to construct an instance"); + + // add listener + r = pEmailEvent->AddListener(listener, true); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to add a listener"); + + __pEmailEvent = move(pEmailEvent); + __isConstructed = true; + + return r; +} + +void +_EmailManagerImpl::SentEmailStatusCallback(int msgId, email_noti_on_network_event status, int errorCode ) +{ + result r = E_SUCCESS; + + switch (status) + { + case NOTI_SEND_FAIL: + { + r = E_FAILURE; + _EmailEvent* pEmailEvent = null; + _EmailAsyncData *pEmailAsyncData = null; + + for( int i=0; i < _EmailManagerImpl::__pEmailAsyncData->GetCount(); i++) + { + _EmailManagerImpl::__pMutex->Acquire(); + _EmailManagerImpl::__pEmailAsyncData->GetAt(i, pEmailAsyncData); + if ( null == pEmailAsyncData) + { + _EmailManagerImpl::__pMutex->Release(); + break; + + } + if ( msgId == pEmailAsyncData->msgId ) + { + _EmailManagerImpl::__pEmailAsyncData->RemoveAt(i); + } + _EmailManagerImpl::__pMutex->Release(); + + + if (msgId == pEmailAsyncData->msgId) + { + _EmailEventArg* pEmailEventArg = null; + pEmailEvent = pEmailAsyncData->pEventData; + + if (pEmailEvent) + { + pEmailEventArg = new (std::nothrow) _EmailEventArg(r); + if (pEmailEventArg) + { + pEmailEvent->Fire(*pEmailEventArg); + } + } + if (pEmailAsyncData) + { + delete []pEmailAsyncData; + pEmailAsyncData = null; + + } + + break; + } + } + + + } + break; + + case NOTI_SEND_FINISH: + { + r = E_SUCCESS; + _EmailEvent* pEmailEvent = null; + _EmailAsyncData *pEmailAsyncData = null; + + for( int i=0; i < _EmailManagerImpl::__pEmailAsyncData->GetCount(); i++) + { + _EmailManagerImpl::__pMutex->Acquire(); + _EmailManagerImpl::__pEmailAsyncData->GetAt(i, pEmailAsyncData); + if ( null == pEmailAsyncData) + { + _EmailManagerImpl::__pMutex->Release(); + break; + + } + if ( msgId == pEmailAsyncData->msgId ) + { + _EmailManagerImpl::__pEmailAsyncData->RemoveAt(i); + } + _EmailManagerImpl::__pMutex->Release(); + + + if (msgId == pEmailAsyncData->msgId) + { + _EmailEventArg* pEmailEventArg = null; + pEmailEvent = pEmailAsyncData->pEventData; + + if (pEmailEvent) + { + pEmailEventArg = new (std::nothrow) _EmailEventArg(r); + if (pEmailEventArg) + { + pEmailEvent->Fire(*pEmailEventArg); + } + } + + if (pEmailAsyncData) + { + delete []pEmailAsyncData; + pEmailAsyncData = null; + + } + + break; + } + } + + + } + break; + + default: + r = E_FAILURE; + break; + } +} + + +result +_EmailManagerImpl::Send(const EmailMessage& message, const RecipientList& recipientList, bool saveToSentBox) +{ + result r = E_SUCCESS; + int msgId = -1; + int requestId = 0; + _EmailAsyncData *pTemp=null; + + SysAssertf(__isConstructed == true, "The _EmailManagerImpl instance is not constructed yet."); + SysLog(NID_MSG, "sending an email message."); + + r = _MsgUtil::SendEmail(message, recipientList, msgId, requestId, saveToSentBox); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to send the email message.", GetErrorMessage(r)); + + pTemp = new (std::nothrow) _EmailAsyncData(); + SysTryCatch(NID_MSG, pTemp != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Failed to allocate memory."); + + pTemp->requestId = requestId; + pTemp->msgId = msgId; + pTemp->pEventData = __pEmailEvent.get(); + + if(null ==__pEmailAsyncData) + + { + __pEmailAsyncData = new (std::nothrow) ArrayListT<_EmailAsyncData*> ; + SysTryCatch(NID_MSG, __pEmailAsyncData != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Failed to allocate memory."); + __pEmailAsyncData->Construct(); + + } + + __pEmailAsyncData->Add(pTemp); + + + if ( null == __pMutex) + { + __pMutex = new (std::nothrow) Tizen::Base::Runtime::Mutex(); + SysTryCatch(NID_MSG, __pMutex != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] Failed to allocate memory."); + __pMutex->Create(); + + } + + return r; + +CATCH: + + if (pTemp) + { + if (__pEmailAsyncData->Contains(pTemp)) + { + __pEmailAsyncData->Remove(pTemp); + + } + delete pTemp; + pTemp = null; + + } + + return r; +} + + +_EmailManagerImpl* +_EmailManagerImpl::GetInstance(EmailManager& emailManager) +{ + return emailManager.__pImpl; +} + +const _EmailManagerImpl* +_EmailManagerImpl::GetInstance(const EmailManager& emailManager) +{ + return emailManager.__pImpl; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_EmailManagerImpl.h b/src/FMsg_EmailManagerImpl.h new file mode 100644 index 0000000..3a06077 --- /dev/null +++ b/src/FMsg_EmailManagerImpl.h @@ -0,0 +1,164 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_EmailManagerImpl.h + * @brief This is the header file for _EmailManagerImpl class. + * + * This header file contains the declarations of _EmailManagerImpl class. + */ + + +#ifndef _FMSG_INTERNAL_EMAIL_MANAGER_IMPL_H_ +#define _FMSG_INTERNAL_EMAIL_MANAGER_IMPL_H_ + +#include "FMsg_Types.h" + +namespace Tizen { namespace Messaging +{ +// forward declaration +class EmailManager; +class IEmailListener; +class EmailMessage; +class RecipientList; +class _EmailEvent; + + +class _EmailAsyncData +{ +public: + int requestId; + int msgId; + _EmailEvent *pEventData; + +}; + + +/** +* @class _EmailManagerImpl +* @brief This class provides methods to use the email messaging service. +* @since 1.0 +* +* This class provides methods to use the email messaging service. @n +* +* The sample code below demonstrates how to send an email message. +*/ +class _EmailManagerImpl + : public Tizen::Base::Object +{ + // Life cycle +public: + /** + * This is the default constructor for this class. + * + * @since 1.0 + */ + _EmailManagerImpl(void); + + /** + * This is the destructor for this class. + * + * @since 1.0 + */ + virtual ~_EmailManagerImpl(void); + +private: + _EmailManagerImpl(const _EmailManagerImpl& value); + _EmailManagerImpl& operator =(const _EmailManagerImpl& rhs); + + // Operation +public: + /** + * Initializes this instance of _EmailManagerImpl with the specified listener. + * + * @since 1.0 + * @return An error code + * @param[in] listener The listener to receive a send result asynchronously + * @exception E_SUCCESS The method was successful. + */ + result Construct(IEmailListener& listener); + + /** + * Sends the email message. + * + * @since 1.0 + * @privlevel SYSTEM + * @privgroup http://tizen.org/privilege/messaging.email + * + * @return An error code + * @param[in] message The message to be sent + * @param[in] recipientList The list of recipients + * @param[in] saveToSentBox Set to @c true to save the message in the Sentbox, @n + * else @c false + * @exception E_SUCCESS The method was successful. + * @exception E_ON_INITIALIZING The mailbox is not completely loaded yet. + * @exception E_STORAGE_FULL The storage is full. + * @exception E_DEVICE_UNAVAILABLE The device is unavailable. + * @exception E_NETWORK_UNAVAILABLE The network is unavailable. + * @exception E_INVALID_ACCOUNT The account is not set. + * @exception E_INVALID_CONDITION The profile is not set. + * @exception E_INVALID_ADDRESS The address is invalid. + * @exception E_FDN_MODE The FDN mode has been activated. + * @exception E_INVALID_ARG The number of recipients is @c 0. + * @exception E_MAX_EXCEEDED The number of recipients crossed the limit (Maximum 20). + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @remarks The value of the flag, @c saveToSentbox, is fixed to @c false in the emulator. + * @see IEmailListener::OnEmailMessageSent() + */ + result Send(const EmailMessage& message, const RecipientList& recipientList, bool saveToSentBox); + +public: + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _EmailManagerImpl + * @param[in] emailManager An instance of EmailManager + */ + static _EmailManagerImpl* GetInstance(EmailManager& emailManager); + + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _EmailManagerImpl + * @param[in] emailManager An instance of EmailManager + */ + static const _EmailManagerImpl* GetInstance(const EmailManager& emailManager); + + + + /** + * Call back for sent message + * + * @param[in] msgId The msg Id + * @param[in] status The sent message status. + * @param[in] errorCode The error code. + * + */ + static void SentEmailStatusCallback(int msgId, email_noti_on_network_event status, int errorCode ); + + +private: + std::unique_ptr<_EmailEvent> __pEmailEvent; + bool __isConstructed; + static Tizen::Base::Collection::ArrayListT<_EmailAsyncData*>*__pEmailAsyncData; + static Tizen::Base::Runtime::Mutex *__pMutex; + +}; // _EmailManagerImpl +} } // Tizen::Messaging + +#endif // _FMSG_INTERNAL_EMAIL_MANAGER_IMPL_H_ diff --git a/src/FMsg_EmailMessageImpl.cpp b/src/FMsg_EmailMessageImpl.cpp new file mode 100644 index 0000000..6eaa6cc --- /dev/null +++ b/src/FMsg_EmailMessageImpl.cpp @@ -0,0 +1,541 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_EmailMessageImpl.cpp + * @brief This is the implementation file for the %_EmailMessageImpl class. + * + * This file contains the implementation of the %_EmailMessageImpl class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_MsgUtil.h" +#include "FMsg_EmailMessageImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +namespace Tizen { namespace Messaging +{ + +_EmailMessageImpl::_EmailMessageImpl(void) + : __pAttachmentList(null) + , __totalFileSize(0) +{ +} + +_EmailMessageImpl::_EmailMessageImpl(const _EmailMessageImpl& value) +{ + int count = 0; + String* pTemp = null; + + __subject = value.__subject; + __text = value.__text; + __totalFileSize = value.__totalFileSize; + __pAttachmentList = null; + + if (value.__pAttachmentList) + { + __pAttachmentList = new (std::nothrow) ArrayList(); + SysTryReturnVoidResult(NID_MSG, __pAttachmentList != null, E_OUT_OF_MEMORY, "memory allocation failed."); + + __pAttachmentList->Construct(); + count = value.__pAttachmentList->GetCount(); + for (int index = 0; index < count; index++) + { + pTemp = static_cast (value.__pAttachmentList->GetAt(index)); + String* pFilePath = new (std::nothrow) String(*pTemp); + if (!pFilePath) + { + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "memory allocation failed."); + __pAttachmentList->RemoveAll(true); + delete __pAttachmentList; + __pAttachmentList = null; + SetLastResult(E_OUT_OF_MEMORY); + return; + } + __pAttachmentList->Add(*pFilePath); + } + } +} + +_EmailMessageImpl::~_EmailMessageImpl(void) +{ + if (__pAttachmentList) + { + __pAttachmentList->RemoveAll(true); // if true, deallocate object + delete __pAttachmentList; + __pAttachmentList = null; + } + __totalFileSize = 0; +} + +_EmailMessageImpl& +_EmailMessageImpl::operator =(const _EmailMessageImpl& rhs) +{ + if (this != &rhs) + { + int count = 0; + String* pTemp = null; + + __subject = rhs.__subject; + __text = rhs.__text; + __totalFileSize = rhs.__totalFileSize; + if (__pAttachmentList) + { + if (__pAttachmentList->GetCount() > 0) + { + __pAttachmentList->RemoveAll(true); + } + delete __pAttachmentList; + __pAttachmentList = null; + } + + + if (rhs.__pAttachmentList) + { + __pAttachmentList = new (std::nothrow) ArrayList(); + if (!__pAttachmentList) + { + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "memory allocation failed."); + SetLastResult(E_OUT_OF_MEMORY); + return (*this); + } + + __pAttachmentList->Construct(); + count = rhs.__pAttachmentList->GetCount(); + for (int index = 0; index < count; index++) + { + pTemp = static_cast (rhs.__pAttachmentList->GetAt(index)); + String* pFilePath = new (std::nothrow) String(*pTemp); + if (!pFilePath) + { + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "memory allocation failed."); + __pAttachmentList->RemoveAll(true); + delete __pAttachmentList; + __pAttachmentList = null; + SetLastResult(E_OUT_OF_MEMORY); + return (*this); + } + __pAttachmentList->Add(*pFilePath); + } + } + } + + return (*this); +} + +bool +_EmailMessageImpl::Equals(const Tizen::Base::Object& value) const +{ + const _EmailMessageImpl* pEmailMessageImpl = dynamic_cast(&value); + if (!pEmailMessageImpl) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + // subject + if (__subject != pEmailMessageImpl->__subject) + { + return false; + } + + // text + if (__text != __text) + { + return false; + } + + // attachment list + if (__pAttachmentList) + { + if (!__pAttachmentList->Equals(*(pEmailMessageImpl->__pAttachmentList))) + { + return false; + } + } + else + { + if (pEmailMessageImpl->__pAttachmentList) + { + return false; + } + } + + // total file size + if (__totalFileSize != pEmailMessageImpl->__totalFileSize) + { + return false; + } + + return true; +} + +int +_EmailMessageImpl::GetHashCode(void) const +{ + int hash = 0; + + hash = __subject.GetHashCode() + __text.GetHashCode() + __totalFileSize; + if (__pAttachmentList) + { + hash += __pAttachmentList->GetHashCode(); + } + + return hash; +} + +result +_EmailMessageImpl::SetSubject(const String& subject) +{ + result r = E_SUCCESS; + + if ((subject.GetLength() * 2 + __totalFileSize) > MAX_EMAIL_FILE_SIZE) + { + SysLogException(NID_MSG, E_MAX_EXCEEDED, "Unable to add file. The total size exceeds the limit."); + r = E_MAX_EXCEEDED; + goto CATCH; + } + + __totalFileSize += subject.GetLength() * 2; + __subject = subject; + + return r; + +CATCH: + return r; +} + +String +_EmailMessageImpl::GetSubject(void) const +{ + return __subject; +} + +result +_EmailMessageImpl::SetText(const String& text) +{ + result r = E_SUCCESS; + + if ((text.GetLength() * 2 + __totalFileSize) > MAX_EMAIL_FILE_SIZE) + { + SysLogException(NID_MSG, E_MAX_EXCEEDED, "Unable to add file. The total size exceeds the limit."); + r = E_MAX_EXCEEDED; + goto CATCH; + } + + __totalFileSize += text.GetLength() * 2; + __text = text; + + return r; + +CATCH: + return r; +} + +String +_EmailMessageImpl::GetText(void) const +{ + return __text; +} + +result +_EmailMessageImpl::AddAttachment(const String& filePath) +{ + result r = E_SUCCESS; + long fileSize = 0L; + FileAttributes fileAttributes; + String* pItem = null; + String* pFilePath = null; + int index = 0; + int count = 0; + + // get max value of attachments + if (__pAttachmentList) + { + count = __pAttachmentList->GetCount(); + if (count >= MAX_EMAIL_ATTACHMENT_COUNT) + { + SysLogException(NID_MSG, E_MAX_EXCEEDED, "The number of attachments exceeds the limit."); + r = E_MAX_EXCEEDED; + goto CATCH; + } + } + + // check there is a same file + for (index = 0; index < count; index++) + { + pItem = static_cast (__pAttachmentList->GetAt(index)); + if (pItem->Equals(filePath)) + { + SysLogException(NID_MSG, E_FILE_ALREADY_EXIST, "[E_FILE_ALREADY_EXIST] The file is already attached."); + r = E_FILE_ALREADY_EXIST; + goto CATCH; + } + } + + // get file attributes + r = File::GetAttributes(filePath, fileAttributes); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to get the file attributes.", GetErrorMessage(r)); + goto CATCH; + } + + // get file size + fileSize = (long) fileAttributes.GetFileSize(); + if ((fileSize + __totalFileSize) > MAX_EMAIL_FILE_SIZE) + { + r = E_MAX_EXCEEDED; + SysLogException(NID_MSG, E_MAX_EXCEEDED, "Unable to add file. The file size exceeds the limit."); + goto CATCH; + } + __totalFileSize += fileSize; + + // Construct attachment list + if (!__pAttachmentList) + { + __pAttachmentList = new (std::nothrow) ArrayList(); + if (!__pAttachmentList) + { + r = E_OUT_OF_MEMORY; + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "memory allocation failed."); + goto CATCH; + } + r = __pAttachmentList->Construct(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to construct an ArrayList.", GetErrorMessage(r)); + delete __pAttachmentList; + __pAttachmentList = null; + goto CATCH; + } + } + + // add file + pFilePath = new (std::nothrow) String(filePath); + if (!pFilePath) + { + r = E_OUT_OF_MEMORY; + SysLogException(NID_MSG, r, "memory allocation failed."); + goto CATCH; + } + + r = __pAttachmentList->Add(*pFilePath); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add file.", GetErrorMessage(r)); + delete pFilePath; + pFilePath = null; + goto CATCH; + } + + return r; + +CATCH: + return r; +} + +result +_EmailMessageImpl::RemoveAttachment(const Tizen::Base::String& filePath) +{ + SysTryReturnResult(NID_MSG, filePath.GetLength() > 0, E_INVALID_ARG, "[E_INVALID_ARG] The file path is empty."); + SysTryReturnResult(NID_MSG, filePath.GetLength() <= PATH_MAX, E_INVALID_ARG, "[E_INVALID_ARG] The file path is too long."); + + result r = E_SUCCESS; + long fileSize = 0L; + FileAttributes fileAttributes; + String* pItem = null; + int index = 0; + + // get there is attachment file + if (!__pAttachmentList) + { + SysLogException(NID_MSG, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] There is no attached file. So cannot remove such file."); + r = E_FILE_NOT_FOUND; + goto CATCH; + } + + // get there is attachment file + if (__pAttachmentList->GetCount() == 0) + { + SysLogException(NID_MSG, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] There is no attached file. So cannot remove such file."); + r = E_FILE_NOT_FOUND; + goto CATCH; + } + + // check file existence + if (File::IsFileExist(filePath) == false) + { + SysLogException(NID_MSG, E_FILE_NOT_FOUND, "[E_FILE_NOT_FOUND] File not exist."); + r = E_FILE_NOT_FOUND; + goto CATCH; + } + + // get file attributes + r = File::GetAttributes(filePath, fileAttributes); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to get the file attributes.", GetErrorMessage(r)); + goto CATCH; + } + + // get file size + fileSize = (long) fileAttributes.GetFileSize(); + + // find the file + for (index = 0; index < __pAttachmentList->GetCount(); index++) + { + pItem = static_cast (__pAttachmentList->GetAt(index)); + if (pItem->Equals(filePath)) + { + r = __pAttachmentList->RemoveAt(index, true); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to remove file from the list.", GetErrorMessage(r)); + goto CATCH; + } + // decrease the total file size + __totalFileSize -= fileSize; + break; + } + } + + return r; + +CATCH: + return r; +} + +IList* +_EmailMessageImpl::GetAttachmentListN(void) const +{ + result r = E_SUCCESS; + ArrayList* pAttachmentList = null; + int count = 0; + String* pItem = null; + String* pElement = null; + + ClearLastResult(); + + pAttachmentList = new (std::nothrow) ArrayList(); + if (!pAttachmentList) + { + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "memory allocation failed."); + SetLastResult(E_OUT_OF_MEMORY); + goto CATCH; + } + r = pAttachmentList->Construct(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to construct an ArrayList.", GetErrorMessage(r)); + SetLastResult(r); + goto CATCH; + } + + // there is no attachment + if (!__pAttachmentList) + { + SysLog(NID_MSG, "There is no attachment."); + // return null + return pAttachmentList; + } + + // get total count of attached files + count = __pAttachmentList->GetCount(); + + // abnormal.. but anyway.. there is no attachment + if (count == 0) + { + SysLog(NID_MSG, "There is no attachment."); + return pAttachmentList; + } + + + for (int index = 0; index < count; index++) + { + pItem = static_cast (__pAttachmentList->GetAt(index)); + if (!pItem) + { + SysLog(NID_MSG, "Failed to get a file from ArrayList"); + SetLastResult(GetLastResult()); + goto CATCH; + } + + // make an element + pElement = new (std::nothrow) String(*pItem); + if (!pElement) + { + r = E_OUT_OF_MEMORY; + SysLogException(NID_MSG, r, "memory allocation failed."); + goto CATCH; + } + + // add a element to a new list + r = pAttachmentList->Add(*pElement); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add item to the list.", GetErrorMessage(r)); + SetLastResult(r); + goto CATCH; + } + } + + return pAttachmentList; + +CATCH: + if (pAttachmentList) + { + if (pAttachmentList->GetCount() > 0) + { + pAttachmentList->RemoveAll(true); + } + delete pAttachmentList; + pAttachmentList = null; + } + if (pElement) + { + delete pElement; + pElement = null; + } + + return null; +} + +_EmailMessageImpl* +_EmailMessageImpl::GetInstance(EmailMessage& emailMessage) +{ + return emailMessage.__pImpl; +} + +const _EmailMessageImpl* +_EmailMessageImpl::GetInstance(const EmailMessage& emailMessage) +{ + return emailMessage.__pImpl; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_EmailMessageImpl.h b/src/FMsg_EmailMessageImpl.h new file mode 100644 index 0000000..aa73792 --- /dev/null +++ b/src/FMsg_EmailMessageImpl.h @@ -0,0 +1,216 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_EmailMessageImpl.h + * @brief This is the header file for _EmailMessageImpl class. + * + * This header file contains the declarations of _EmailMessageImpl class. + */ + + +#ifndef _FMSG_INTERNAL_EMAIL_MESSAGE_IMPL_H_ +#define _FMSG_INTERNAL_EMAIL_MESSAGE_IMPL_H_ + +#include +#include + +namespace Tizen { namespace Messaging +{ +// forward declaration +class EmailMessage; + +/** +* @class _EmailMessageImpl +* @brief This class provides methods for handling email messages. +* @since 1.0 +* +* This class provides methods for handling email messages. @n +* A user can set and get the subject and body text of an email, @n +* and can also add, remove, and receive attachments. +*/ +class _EmailMessageImpl + : public Tizen::Base::Object +{ + // Life cycle +public: + /** + * This is the default constructor for this class. + * + * @since 1.0 + */ + _EmailMessageImpl(void); + + /** + * This is the destructor for this class. + * + * @since 1.0 + */ + virtual ~_EmailMessageImpl(void); + + /** + * This is the copy constructor for this class. + * + * @since 1.0 + * @param[in] value An instance of _EmailMessageImpl + */ + _EmailMessageImpl(const _EmailMessageImpl& value); + +public: + /** + * This assignment operator copies email message from the specified instance of _EmailMessageImpl to the calling instance of _EmailMessageImpl. + * + * @since 1.0 + * @return The reference of this instance + * @param[in] rhs A reference to the _EmailMessageImpl instance to be copied + */ + _EmailMessageImpl& operator =(const _EmailMessageImpl& rhs); + +public: + /** + * Gets the hash value of the current instance. + * + * @since 1.0 + * @return The hash value of the current instance + * @remarks Two equal instances should return the same hash value. For better performance, + * the used hash function must generate a random distribution for all inputs. + */ + virtual int GetHashCode(void) const; + + /** + * Compares the specified instance with the calling instance. + * + * @since 1.0 + * @return @c true if both instances are equal @n + * @c false, otherwise + * @param[in] value An instance of _EmailMessageImpl + */ + virtual bool Equals(const Tizen::Base::Object& value) const; + + // Operation +public: + /** + * Sets the subject of the email. + * + * @since 1.0 + * @return An error code + * @param[in] subject The subject of the message + * @exception E_SUCCESS The method was successful. + * @exception E_MAX_EXCEEDED The subject length of the message is exceeding the maximum limit (Maximum 256 characters). @n + * The total size of the subject, body, and attachment(s) is exceeding the maximum limit (5MB). + * @see GetSubject() + */ + result SetSubject(const Tizen::Base::String& subject); + + /** + * Sets the body of the message. + * + * @since 1.0 + * @return An error code + * @param[in] text The body text of the message + * @exception E_SUCCESS The method was successful. + * @exception E_MAX_EXCEEDED The body length of the message is exceeding the maximum limit (Maximum 2000 characters). @n + * The total size of the subject, body, and attachment(s) is exceeding the maximum limit (5MB). + * @see GetText() + */ + result SetText(const Tizen::Base::String& text); + + /** + * Adds a file attachment to the email. + * + * @since 1.0 + * @return An error code + * @param[in] filePath The path of the file to attach + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG The length of the specified @c filePath is too long or @c 0. + * @exception E_FILE_NOT_FOUND The specified file could not be found or accessed. + * @exception E_FILE_ALREADY_EXIST The file is already attached. + * @exception E_MAX_EXCEEDED Attachment is constrained to a maximum of 5MB and 20 files. @n + * The total size of the subject, body, and attachment(s) is exceeding the maximum limit (5MB). + * @see GetAttachmentListN() + */ + result AddAttachment(const Tizen::Base::String& filePath); + + /** + * Removes an attachment from an email. + * + * @since 1.0 + * @return An error code + * @param[in] filePath The path of the file to remove + * @exception E_SUCCESS The method was successful. + * @exception E_FILE_NOT_FOUND The corresponding format file was not found. + * @see AddAttachment(), GetAttachmentListN() + */ + result RemoveAttachment(const Tizen::Base::String& filePath); + + /** + * Gets the subject of the message. + * + * @since 1.0 + * @return The subject of the message + * @see SetSubject() + */ + Tizen::Base::String GetSubject(void) const; + + /** + * Gets the body text of the message. + * + * @since 1.0 + * @return The body text of the message + * @see SetText() + */ + Tizen::Base::String GetText(void) const; + + /** + * Gets the list of attachments for the email. + * + * @since 1.0 + * @return The list of the attached files + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see AddAttachment() + */ + Tizen::Base::Collection::IList* GetAttachmentListN(void) const; + +public: + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _EmailMessageImpl + * @param[in] emailMessage An instance of EmailMessage + */ + static _EmailMessageImpl* GetInstance(EmailMessage& emailMessage); + + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _EmailMessageImpl + * @param[in] emailMessage An instance of EmailMessage + */ + static const _EmailMessageImpl* GetInstance(const EmailMessage& emailMessage); + +private: + Tizen::Base::String __subject; + Tizen::Base::String __text; + Tizen::Base::Collection::ArrayList* __pAttachmentList; + long __totalFileSize; +}; // _EmailMessageImpl +} } // Tizen::Messaging + +#endif // _FMSG_INTERNAL_EMAIL_MESSAGE_IMPL_H_ diff --git a/src/FMsg_EtwsPrimaryNotificationImpl.cpp b/src/FMsg_EtwsPrimaryNotificationImpl.cpp new file mode 100644 index 0000000..f761e6e --- /dev/null +++ b/src/FMsg_EtwsPrimaryNotificationImpl.cpp @@ -0,0 +1,361 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_EtwsPrimaryNotificationImpl.cpp + * @brief This is the implementation file for the %_EtwsPrimaryNotificationImpl class. + * + * This file contains the implementation of the %_EtwsPrimaryNotificationImpl class. + */ + +#include +#include +#include +#include +#include +#include +#include "FMsg_Types.h" +#include "FMsg_EtwsPrimaryNotificationImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ + +_EtwsPrimaryNotificationImpl::_EtwsPrimaryNotificationImpl(void) + : __etwsMsgTime() + , __pEtwsSerialNumber(null) + , __pEtwsSecurityInfo(null) + , __etwsMessageId(0) + , __pEtwsWarningType(null) +{ + __pEtwsSerialNumber = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_MSG, __pEtwsSerialNumber != null, E_OUT_OF_MEMORY, "memory allocation failed"); + __pEtwsSerialNumber->Construct(0); + __pEtwsSerialNumber->SetPosition(0); + + __pEtwsSecurityInfo = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_MSG, __pEtwsSecurityInfo != null, E_OUT_OF_MEMORY, "memory allocation failed"); + __pEtwsSecurityInfo->Construct(0); + __pEtwsSecurityInfo->SetPosition(0); + + __pEtwsWarningType = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_MSG, __pEtwsWarningType != null, E_OUT_OF_MEMORY, "memory allocation failed"); + __pEtwsWarningType->Construct(0); + __pEtwsWarningType->SetPosition(0); +} + +_EtwsPrimaryNotificationImpl::_EtwsPrimaryNotificationImpl(const _EtwsPrimaryNotificationImpl& value) +{ + result r = E_SUCCESS; + __etwsMsgTime = value.__etwsMsgTime; + __etwsMessageId = value.__etwsMessageId; + + r = __pEtwsSerialNumber->SetArray(value.__pEtwsSerialNumber->GetPointer(), 0, value.__pEtwsSerialNumber->GetLimit()); + SysTryReturnVoidResult(NID_MSG, r == E_SUCCESS, r, "Failed to set array"); + __pEtwsSerialNumber->SetPosition(0); + + r = __pEtwsSecurityInfo->SetArray(value.__pEtwsSecurityInfo->GetPointer(), 0, value.__pEtwsSecurityInfo->GetLimit()); + SysTryReturnVoidResult(NID_MSG, r == E_SUCCESS, r, "Failed to set array"); + __pEtwsSecurityInfo->SetPosition(0); + + r = __pEtwsWarningType->SetArray(value.__pEtwsWarningType->GetPointer(), 0, value.__pEtwsWarningType->GetLimit()); + SysTryReturnVoidResult(NID_MSG, r == E_SUCCESS, r, "Failed to set array"); + __pEtwsWarningType->SetPosition(0); +} + +result +_EtwsPrimaryNotificationImpl::SetEtwsMessageImpl(const Tizen::Base::DateTime& dateTime, const Tizen::Base::ByteBuffer& etwsSerialNumber, const Tizen::Base::ByteBuffer& + etwsSecurityInfo, int etwsMessageId, const Tizen::Base::ByteBuffer& etwsWarningType) +{ + result r = E_SUCCESS; + + __etwsMsgTime = dateTime; + __etwsMessageId = etwsMessageId; + + __pEtwsSerialNumber = new (std::nothrow) ByteBuffer(); + SysTryReturn(NID_MSG, __pEtwsSerialNumber != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed"); + r = __pEtwsSerialNumber->Construct(etwsSerialNumber); + r = __pEtwsSerialNumber->SetPosition(0); + + __pEtwsSecurityInfo = new (std::nothrow) ByteBuffer(); + SysTryCatch(NID_MSG, __pEtwsSecurityInfo != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + r = __pEtwsSecurityInfo->Construct(etwsSecurityInfo); + r = __pEtwsSecurityInfo->SetPosition(0); + + __pEtwsWarningType = new (std::nothrow) ByteBuffer(); + SysTryCatch(NID_MSG, __pEtwsWarningType != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + r = __pEtwsWarningType->Construct(etwsWarningType); + r = __pEtwsWarningType->SetPosition(0); + + return r; + +CATCH: + SetLastResult(GetLastResult()); + if (__pEtwsSerialNumber) + { + delete __pEtwsSerialNumber; + __pEtwsSerialNumber = null; + } + + if (__pEtwsSecurityInfo) + { + delete __pEtwsSecurityInfo; + __pEtwsSecurityInfo = null; + } + return r; +} + +_EtwsPrimaryNotificationImpl::~_EtwsPrimaryNotificationImpl(void) +{ + if (__pEtwsSerialNumber) + { + delete __pEtwsSerialNumber; + __pEtwsSerialNumber = null; + } + + if (__pEtwsSecurityInfo) + { + delete __pEtwsSecurityInfo; + __pEtwsSecurityInfo = null; + } + + if (__pEtwsWarningType) + { + delete __pEtwsWarningType; + __pEtwsWarningType = null; + } +} + +_EtwsPrimaryNotificationImpl& +_EtwsPrimaryNotificationImpl::operator =(const _EtwsPrimaryNotificationImpl& rhs) +{ + result r = E_SUCCESS; + if (this != &rhs) + { + __etwsMsgTime = rhs.__etwsMsgTime; + __etwsMessageId = rhs.__etwsMessageId; + + r = __pEtwsSerialNumber->SetArray(rhs.__pEtwsSerialNumber->GetPointer(), 0, rhs.__pEtwsSerialNumber->GetLimit()); + if (r == E_SUCCESS) + { + __pEtwsSerialNumber->SetPosition(0); + } + + r = __pEtwsSecurityInfo->SetArray(rhs.__pEtwsSecurityInfo->GetPointer(), 0, rhs.__pEtwsSecurityInfo->GetLimit()); + if (r == E_SUCCESS) + { + __pEtwsSecurityInfo->SetPosition(0); + } + + r = __pEtwsWarningType->SetArray(rhs.__pEtwsWarningType->GetPointer(), 0, rhs.__pEtwsWarningType->GetLimit()); + if (r == E_SUCCESS) + { + __pEtwsWarningType->SetPosition(0); + } + } + + return (*this); +} + +EtwsPrimaryNotification* +_EtwsPrimaryNotificationImpl::CloneN() const +{ + EtwsPrimaryNotification* pEtwsMsg = null; + result r = E_SUCCESS; + + pEtwsMsg = _EtwsPrimaryNotificationImpl::GetEtwsPrimaryNotificationN(); + SysTryCatch(NID_MSG, pEtwsMsg != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + r = _EtwsPrimaryNotificationImpl::GetInstance(*pEtwsMsg)->SetEtwsMessageImpl(__etwsMsgTime, *(__pEtwsSerialNumber), *(__pEtwsSecurityInfo), __etwsMessageId, *(__pEtwsWarningType)); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "etwsimpl message construct failed"); + + SetLastResult(GetLastResult()); + return pEtwsMsg; + +CATCH: + SetLastResult(GetLastResult()); + if (pEtwsMsg) + { + delete pEtwsMsg; + pEtwsMsg = null; + } + return null; +} + +bool +_EtwsPrimaryNotificationImpl::Equals(const Tizen::Base::Object& obj) const +{ + const _EtwsPrimaryNotificationImpl* pEtwsPrimaryNotificationImpl = dynamic_cast(&obj); + + if (!pEtwsPrimaryNotificationImpl) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + // sender time + if (__etwsMsgTime != pEtwsPrimaryNotificationImpl->__etwsMsgTime) + { + return false; + } + + // etws serial number + if (__pEtwsSerialNumber != pEtwsPrimaryNotificationImpl->__pEtwsSerialNumber) + { + return false; + } + + // etws security info + if (__pEtwsSecurityInfo != pEtwsPrimaryNotificationImpl->__pEtwsSecurityInfo) + { + return false; + } + + // cbs message id + if (__etwsMessageId != pEtwsPrimaryNotificationImpl->__etwsMessageId) + { + return false; + } + + // Etws warning type + if (__pEtwsWarningType != pEtwsPrimaryNotificationImpl->__pEtwsWarningType) + { + return false; + } + + return true; +} + +int +_EtwsPrimaryNotificationImpl::GetHashCode(void) const +{ + int hash = 0; + + hash = __etwsMsgTime.GetHashCode() + __pEtwsSerialNumber->GetHashCode() + __pEtwsSecurityInfo->GetHashCode() + __etwsMessageId + __pEtwsWarningType->GetHashCode(); + + return hash; +} + +EtwsPrimaryNotification* +_EtwsPrimaryNotificationImpl::GetEtwsPrimaryNotificationN() +{ + result r = E_SUCCESS; + EtwsPrimaryNotification* pEtwsMsg = null; + + pEtwsMsg = new (std::nothrow) EtwsPrimaryNotification(); + SysTryCatch(NID_MSG, pEtwsMsg != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + return pEtwsMsg; + +CATCH: + return null; +} + +_EtwsPrimaryNotificationImpl* +_EtwsPrimaryNotificationImpl::GetInstance(EtwsPrimaryNotification& etwsMessage) +{ + return etwsMessage.__pEtwsPrimaryNotificationImpl; +} + + +Tizen::Base::ByteBuffer* +_EtwsPrimaryNotificationImpl::GetSerialNumberN(void) const +{ + result r = E_SUCCESS; + Tizen::Base::ByteBuffer* pEtwsSerialNumber = null; + + ClearLastResult(); + + pEtwsSerialNumber = new (std::nothrow) ByteBuffer(); + SysTryCatch(NID_MSG, pEtwsSerialNumber != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + r = pEtwsSerialNumber->Construct(*__pEtwsSerialNumber); + r = pEtwsSerialNumber->SetPosition(0); + + SetLastResult(r); + + return pEtwsSerialNumber; + +CATCH: + SetLastResult(r); + + return null; +} + +Tizen::Base::DateTime +_EtwsPrimaryNotificationImpl::GetReceivedTime(void) const +{ + return __etwsMsgTime; +} + +Tizen::Base::ByteBuffer* +_EtwsPrimaryNotificationImpl::GetWarningSecurityInfoN(void) const +{ + result r = E_SUCCESS; + Tizen::Base::ByteBuffer* pEtwsSecurityInfo = null; + + ClearLastResult(); + + pEtwsSecurityInfo = new (std::nothrow) ByteBuffer(); + SysTryCatch(NID_MSG, pEtwsSecurityInfo != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + r = pEtwsSecurityInfo->Construct(*__pEtwsSecurityInfo); + r = pEtwsSecurityInfo->SetPosition(0); + + SetLastResult(r); + + return pEtwsSecurityInfo; + +CATCH: + SetLastResult(r); + + return null; +} + +int +_EtwsPrimaryNotificationImpl::GetMessageId(void) const +{ + return __etwsMessageId; +} + +Tizen::Base::ByteBuffer* +_EtwsPrimaryNotificationImpl::GetWarningTypeN(void) const +{ + result r = E_SUCCESS; + Tizen::Base::ByteBuffer* pEtwsWarningType = null; + + ClearLastResult(); + + pEtwsWarningType = new (std::nothrow) ByteBuffer(); + SysTryCatch(NID_MSG, pEtwsWarningType != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + r = pEtwsWarningType->Construct(*__pEtwsWarningType); + r = pEtwsWarningType->SetPosition(0); + + SetLastResult(r); + + return pEtwsWarningType; + +CATCH: + SetLastResult(r); + + return null; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_EtwsPrimaryNotificationImpl.h b/src/FMsg_EtwsPrimaryNotificationImpl.h new file mode 100644 index 0000000..02f4894 --- /dev/null +++ b/src/FMsg_EtwsPrimaryNotificationImpl.h @@ -0,0 +1,284 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** +* @if VISPARTNER-OPERATOR +* +* @file FMsg_EtwsPrimaryNotificationImpl.h +* @brief This is the header file for the %_EtwsPrimaryNotificationImpl class. +* +* @visibility partner-operator +* +* This header file contains the declarations of the %_EtwsPrimaryNotificationImpl class. +* +* @endif +*/ + +#ifndef _FMSG_INTERNAL_ETWS_PRIMARY_NOTIFICATION_IMPL_H_ +#define _FMSG_INTERNAL_ETWS_PRIMARY_NOTIFICATION_IMPL_H_ + +#include +#include + +namespace Tizen { namespace Messaging +{ + +class EtwsPrimaryNotification; + +/** +* @if VISPARTNER-OPERATOR +* +* @class _EtwsPrimaryNotificationImpl +* +* @brief This class provides methods for handling an ETWS primary notification. +* +* @since 2.1 +* +* @final This class is not intended for extension. +* +* @visibility partner-operator +* +* The %_EtwsPrimaryNotificationImpl class provides methods for handling an ETWS primary notification. It allows you to get the serial number, +* message ID, warning type, warning security info, and received time of an ETWS primary notification. +* +* @endif +*/ + +class _EtwsPrimaryNotificationImpl + : public Tizen::Base::Object +{ +public: + /** + * @if VISPARTNER-OPERATOR + * + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.1 + * + * @visibility partner-operator + * + * @endif + */ + virtual ~_EtwsPrimaryNotificationImpl(void); + + /** + * @if VISPARTNER-OPERATOR + * + * Compares the specified instance of %_EtwsPrimaryNotificationImpl with the calling instance. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return @c true, if the values match @n + * @c false, otherwise + * @param[in] obj The other Object to be compared + * @see Object::Equals() + * + * @endif + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the copied instance of the class. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An instance of %_EtwsPrimaryNotificationImpl + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * + * @remarks In case of error, this method returns @c null. @n + * The specific error code can be accessed using the GetLastResult() method. + * + * @endif + */ + EtwsPrimaryNotification* CloneN(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the hash value of the current instance. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The current instance's hash value + * + * @endif + */ + virtual int GetHashCode(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the date and time (UTC time) of the message when it is received. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The date and time (UTC time) when the message is received + * + * @endif + */ + Tizen::Base::DateTime GetReceivedTime(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the serial number of the ETWS primary notification. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The serial number of the ETWS primary notification + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. @n + * In case of an error, this method returns null. + * + * @endif + */ + Tizen::Base::ByteBuffer* GetSerialNumberN(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the message ID of the ETWS primary notification. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The the message ID of the ETWS primary notification + * + * @endif + */ + int GetMessageId(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the warning type. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The ETWS warning type of the message + * + * @endif + */ + Tizen::Base::ByteBuffer* GetWarningTypeN(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the warning security information of the ETWS primary notification. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The warning security information of the ETWS primary notification + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @remarks The specific error code can be accessed using the GetLastResult() method. @n + * In case of an error, this method returns null. + * @endif + */ + Tizen::Base::ByteBuffer* GetWarningSecurityInfoN(void) const; + +public: + /** + * Gets the instance of CbsChannel + * + * @since 2.1 + */ + static EtwsPrimaryNotification* GetEtwsPrimaryNotificationN(); + + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _EtwsPrimaryNotificationImpl + * @param[in] etwsMessage An instance of EtwsPrimaryNotification + */ + static _EtwsPrimaryNotificationImpl* GetInstance(EtwsPrimaryNotification& etwsMessage); + +public: + /** + * This default constructor is intentionally declared as private so that only the platform can create an instance. + * + * @since 2.1 + */ + _EtwsPrimaryNotificationImpl(void); + + /** + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @since 2.1 + * + * @param[in] rhs An instance of _EtwsPrimaryNotificationImpl + */ + _EtwsPrimaryNotificationImpl(const _EtwsPrimaryNotificationImpl& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. @n + * - Use CloneN() to get an exact copy of the instance. + * - Use Equals() to compare the contents of one instance with the other. + * + * @since 2.1 + * + * @return A reference to this instance + * @param[in] rhs An instance of _EtwsPrimaryNotificationImpl + */ + _EtwsPrimaryNotificationImpl& operator =(const _EtwsPrimaryNotificationImpl& rhs); + + /** + * Initializes this instance of %_EtwsPrimaryNotificationImpl with the specified parameter. + * + * @since 2.1 + * + * @param[in] dateTime The date and time (UTC time) when the message is received + * @param[in] etwsSerialNumber The etwsSerialNumber of the CBS message + * @param[in] etwsSecurityInfo The etwsSecurityInfo body text + * @param[in] etwsMessageId The etwsMessageId of the CBS message + * @param[in] etwsWarningType The Etws warning type + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + */ + result SetEtwsMessageImpl(const Tizen::Base::DateTime& dateTime, const Tizen::Base::ByteBuffer& etwsSerialNumber, const Tizen::Base::ByteBuffer& etwsSecurityInfo, + int etwsMessageId, const Tizen::Base::ByteBuffer& etwsWarningType); + +private: + Tizen::Base::DateTime __etwsMsgTime; + Tizen::Base::ByteBuffer* __pEtwsSerialNumber; + Tizen::Base::ByteBuffer* __pEtwsSecurityInfo; + int __etwsMessageId; + Tizen::Base::ByteBuffer* __pEtwsWarningType; +}; // _EtwsPrimaryNotificationImpl + +} } // Tizen::Messaging +#endif // _FMSG_INTERNAL_ETWS_PRIMARY_NOTIFICATION_IMPL_H_ diff --git a/src/FMsg_MessagingIpcProxy.cpp b/src/FMsg_MessagingIpcProxy.cpp new file mode 100644 index 0000000..c39c6c7 --- /dev/null +++ b/src/FMsg_MessagingIpcProxy.cpp @@ -0,0 +1,568 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MessagingIpcProxy.cpp + * @brief This is the implementation file for the %_MessagingProxy class. + * + * This file contains the implementation of the %_MessagingProxy class. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_MessagingMessageTypes.h" +#include "FMsg_MessagingIpcProxy.h" +#include "FMsg_SmsEvent.h" +#include "FMsg_SmsEventArg.h" +#include "FMsg_MsgUtil.h" +#include "FMsg_SmsMmsCallbackHandler.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Io; + +namespace Tizen { namespace Messaging +{ + +_MessagingProxy* _MessagingProxy::__pSelf = null; + +_MessagingProxy::_MessagingProxy(void) + : __pIpcClient(null) + ,__pWapPushListener(null) + ,__pSmsListenerList(null) + ,__pCbsListenerEvent(null) + ,__pEtwsListenerEvent(null) + +{ +} + + +_MessagingProxy::~_MessagingProxy(void) +{ + if(__pIpcClient) + { + delete __pIpcClient; + } + +} +result +_MessagingProxy::Construct(void) +{ + + + __pIpcClient = new (std::nothrow) _IpcClient(); + SysTryReturnResult(NID_MSG, __pIpcClient != null, E_OUT_OF_MEMORY, "_IpcClient creation failed."); + + result r = __pIpcClient->Construct(MESSAGING_IPC_SERVER_NAME, this); + SysTryReturnResult(NID_MSG, !IsFailed(r), r, "_IpcClient constructing faliied."); + std::atexit(DestroyInstance); + + return r; +} + + +_MessagingProxy* +_MessagingProxy::GetInstance(void) +{ + if(_MessagingProxy::__pSelf == null) + { + _MessagingProxy::__pSelf = new (std::nothrow)_MessagingProxy(); + SysTryCatch(NID_MSG, __pSelf != null, , E_OUT_OF_MEMORY, "_IpcClient creation failed."); + + result r = _MessagingProxy::__pSelf->Construct(); + SysTryCatch(NID_MSG, !IsFailed(r), , r, "_IpcClient creation failed."); + + } + return _MessagingProxy::__pSelf; + +CATCH: + if(_MessagingProxy::__pSelf) + { + delete _MessagingProxy::__pSelf; + _MessagingProxy::__pSelf = null; + } + return null; +} + +void +_MessagingProxy::DestroyInstance(void) +{ + if(_MessagingProxy::__pSelf) + { + delete _MessagingProxy::__pSelf ; + _MessagingProxy::__pSelf = null; + + } + +} + +void +_MessagingProxy::OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message) +{ + IPC_BEGIN_MESSAGE_MAP(_MessagingProxy, message) + IPC_MESSAGE_HANDLER(MessagingMsgStart_wapPushEventCallBack, OnWapPushEventCallBack, &client) + IPC_MESSAGE_HANDLER(MessagingMsgStart_incomingEtwsCallback, OnIncomingEtwsCallback, &client) + IPC_MESSAGE_HANDLER(MessagingMsgStart_incomingCbsCallback, OnIncomingCbsCallback, &client) + IPC_MESSAGE_HANDLER(MessagingMsgStart_incomingSmsCallback, OnIncomingSmsCallback, &client) + IPC_END_MESSAGE_MAP() +} + + +result +_MessagingProxy::AddWapPushEventListener(const Tizen::Base::String& wapApplicationId, _SmsEvent* pListener) +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + SysTryReturnResult(NID_MSG, pListener != null, E_SYSTEM, "A system error occurred."); + __pWapPushListener = pListener; + + pMessage = new (std::nothrow) MessagingMsgStart_addWapPushEventListener(wapApplicationId, &ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; + +} + + +void +_MessagingProxy::OnWapPushEventCallBack(const Tizen::Base::String &header, const Tizen::Base::ByteBuffer &body, int bodyLength) +{ + + SysLog(NID_MSG, "push msg body: [%s]", body.GetPointer()); + SysLog(NID_MSG, "push msg header: [%ls]", header.GetPointer()); + SysLog(NID_MSG, "push body length: [%d]", bodyLength); + + if (__pWapPushListener) + { + _SmsEventArg* pSmsEventArg = null; + pSmsEventArg = new (std::nothrow) _SmsEventArg(header, body, _SMS_EVENT_TYPE_WAP_PUSH_RECEIVE_RESULT); + SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed."); + __pWapPushListener->Fire(*pSmsEventArg); + } + +} + + +/* +result +_MessagingProxy::RemoveWapPushEventListener(const Tizen::Base::String& wapApplicationId) +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + + pMessage = new (std::nothrow) MessagingMsgStart_removeWapPushEventListener(wapApplicationId, &ret); + SysTryReturn(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturn(NID_MSG, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; + +} +*/ +result +_MessagingProxy::RegisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType) +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + + pMessage = new (std::nothrow) MessagingMsgStart_registerCondition(wapApplicationId, contentType, &ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; + +} + +result +_MessagingProxy::UnregisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType) +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + + pMessage = new (std::nothrow) MessagingMsgStart_unregisterCondition(wapApplicationId, contentType, &ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; + +} + +result +_MessagingProxy::OpenMsgHandle() +{ + + result r = 0; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + + pMessage = new (std::nothrow) MessagingMsgStart_openMsgHandle(&ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; + +} + + +result +_MessagingProxy::OpenCbsHandle() +{ + + result r = 0; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + + pMessage = new (std::nothrow) MessagingMsgStart_openCbsHandle(&ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; + +} + + +result +_MessagingProxy::AddSmsEventListener(int port, Tizen::Base::Collection::ArrayList* pListenerList) +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + SysTryReturnResult(NID_MSG, pListenerList != null, E_SYSTEM, "A system error occurred."); + __pSmsListenerList = pListenerList; + + pMessage = new (std::nothrow) MessagingMsgStart_addSmsEventListener(port, &ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; + +} + +void +_MessagingProxy::OnIncomingSmsCallback(int port, int displayTime, const Tizen::Base::String &message, const Tizen::Base::String &senderAddress) +{ + + DateTime receivedTime = _MsgUtil::ConvertTime((time_t *) &displayTime); + if (_SmsMmsCallbackHandler::GetInstance()->GetInComingSmsCallback() && __pSmsListenerList->GetCount() > 0) + { + for( int i = 0; i < __pSmsListenerList->GetCount(); i++) + { + _SmsEvent* pSmsEvent = static_cast <_SmsEvent*>(__pSmsListenerList->GetAt(i)); + + if (pSmsEvent) + { + if (pSmsEvent->GetPort() == port) + { + _SmsEventArg* pSmsEventArg = null; + pSmsEventArg = new (std::nothrow) _SmsEventArg(port, receivedTime, message, senderAddress); + SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed."); + + pSmsEvent->Fire(*pSmsEventArg); + break; + } + } + } + } + +} + +result +_MessagingProxy::AddCbsEtwsEventListener(bool enabled) +{ + result r = E_SUCCESS; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + pMessage = new (std::nothrow) MessagingMsgStart_addCbsEtwsEventListener(enabled, &ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; + +} + +void +_MessagingProxy::OnIncomingEtwsCallback(int tempReceivedTime, const Tizen::Base::ByteBuffer &msgSerialNumber, const Tizen::Base::ByteBuffer &msgSecurityInfo, int messgeId, const Tizen::Base::ByteBuffer &etwsMsgWarningType) +{ + + _SmsEventArg* pSmsEventArg = null; + DateTime receivedTime; + receivedTime = _MsgUtil::ConvertTime((time_t *) &tempReceivedTime); + SysLog(NID_MSG, "Etws In Handle[%d]", __pEtwsListenerEvent); + + if (__pEtwsListenerEvent) + { + pSmsEventArg = new (std::nothrow) _SmsEventArg(receivedTime, msgSerialNumber, msgSecurityInfo, messgeId, + etwsMsgWarningType, _SMS_EVENT_TYPE_ETWS_RECEIVE_RESULT); + SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed."); + __pEtwsListenerEvent->Fire(*pSmsEventArg); + } + + + +} + +void +_MessagingProxy::OnIncomingCbsCallback(const Tizen::Base::String &message, const Tizen::Base::ByteBuffer &msgSerialNumber, int tempReceivedTime, int messgeId, int dataCodingScheme, const Tizen::Base::String &messageLanguage) +{ + + _SmsEventArg* pSmsEventArg = null; + DateTime receivedTime = _MsgUtil::ConvertTime((time_t *) &tempReceivedTime); + Tizen::Base::Integer dataCodingSchemeTemp(dataCodingScheme); + SysLog(NID_MSG, "CBS In Handle[%d]", __pCbsListenerEvent); + + if (__pCbsListenerEvent) + { + pSmsEventArg = new (std::nothrow) _SmsEventArg(message, msgSerialNumber, receivedTime, messgeId, false, + ((byte) dataCodingSchemeTemp.ToChar()),messageLanguage, _SMS_EVENT_TYPE_CBS_RECEIVE_RESULT); + SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed."); + __pCbsListenerEvent->Fire(*pSmsEventArg); + } + +} + +void +_MessagingProxy::SetCbsAndEtwsUserEvent(_MessageType msgType, _SmsEvent* pEvent) +{ + if (msgType == _MSG_CBS) + { + __pCbsListenerEvent = pEvent; + } + else + { + __pEtwsListenerEvent = pEvent; + } +} + + +result +_MessagingProxy::SetSavingToCbsBoxEnabled(bool enable) +{ + + result r = 0; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + + pMessage = new (std::nothrow) MessagingMsgStart_setSavingToCbsBoxEnabled(enable, &ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; +} +result +_MessagingProxy::IsCbsEnabled(bool* isCbsEnabled) +{ + + result r = 0; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + SysTryReturnResult(NID_MSG, isCbsEnabled != null, E_SYSTEM, "isCbsEnabled is null."); + + pMessage = new (std::nothrow) MessagingMsgStart_isCbsEnabled(isCbsEnabled, &ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d. isCbsEnabled = %d", ret, *isCbsEnabled ); + + return ret; +} + + +result +_MessagingProxy::SetCbsEnabled(bool enable) +{ + + result r = 0; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + + pMessage = new (std::nothrow) MessagingMsgStart_setCbsEnabled(enable, &ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; +} + +result +_MessagingProxy::AddCbsChannel(int from, int to, Tizen::Base::String& name, bool activate) +{ + + result r = 0; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + pMessage = new (std::nothrow) MessagingMsgStart_addCbsChannel(from, to, name, activate, &ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; +} +result +_MessagingProxy::RemoveCbsChannel(int from, int to) +{ + + result r = 0; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + + pMessage = new (std::nothrow) MessagingMsgStart_removeCbsChannel(from, to, &ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; +} + +result +_MessagingProxy::GetCbsChannelN(int from, int to, bool &isActive, String &channelName) +{ + + result r = 0; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + + pMessage = new (std::nothrow) MessagingMsgStart_getCbsChannelN(from, to, &isActive, &channelName,&ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; + +} + +result +_MessagingProxy::GetCbsChannelListN(Tizen::Base::Collection::ArrayList &pCbsList) +{ + result r = 0; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + + pMessage = new (std::nothrow) MessagingMsgStart_getCbsChannelListN(&pCbsList,&ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; +} + +result +_MessagingProxy::UpdateCbsChannel(int from, int to, Tizen::Base::String name, bool isChannelEnable) +{ + + result r = 0; + IPC::Message* pMessage = null; + unsigned long ret = 0; + + pMessage = new (std::nothrow) MessagingMsgStart_updateCbsChannel(from, to, name, isChannelEnable, &ret); + SysTryReturnResult(NID_MSG, pMessage != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + r = __pIpcClient->SendRequest(*pMessage); + delete pMessage; + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A system error occurred."); + + SysLog(NID_MSG, "The result of checking through IPC is %d.", ret); + + return ret; +} + + +} } diff --git a/src/FMsg_MessagingIpcProxy.h b/src/FMsg_MessagingIpcProxy.h new file mode 100644 index 0000000..798b4c7 --- /dev/null +++ b/src/FMsg_MessagingIpcProxy.h @@ -0,0 +1,88 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + + +#ifndef _FMSG_MESSAGING_PROXY_H_ +#define _FMSG_MESSAGING_PROXY_H_ + +#include +#include +#include +#include "FMsg_Types.h" + +namespace Tizen { namespace Base { +class String; +} } + +namespace Tizen { namespace Io { +class _IpcClient; +} } +namespace Tizen { namespace Messaging +{ + +class _SmsEvent; +class CbsChannel; +class _MessagingProxy + : public Tizen::Base::Object + , public Tizen::Io::_IIpcClientEventListener +{ + +public: + result Construct(void); + result AddWapPushEventListener(const Tizen::Base::String& wapApplicationId, _SmsEvent* pListener); + //result RemoveWapPushEventListener(const Tizen::Base::String& wapApplicationId); + result RegisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType); + result UnregisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType); + + result OpenMsgHandle(); + result OpenCbsHandle(); + result AddSmsEventListener(int port, Tizen::Base::Collection::ArrayList* pListenerList); + result AddCbsEtwsEventListener(bool enabled); + result SetSavingToCbsBoxEnabled(bool enable); + result IsCbsEnabled(bool* isCbsEnabled); + result SetCbsEnabled(bool enable); + result AddCbsChannel(int from, int to, Tizen::Base::String& name, bool activate); + result RemoveCbsChannel(int from, int to); + result UpdateCbsChannel(int from, int to, Tizen::Base::String name, bool isChannelEnable); + result GetCbsChannelN(int from, int to, bool &isActive, Tizen::Base::String &channelName); + result GetCbsChannelListN(Tizen::Base::Collection::ArrayList &pCbsList); + + static _MessagingProxy* GetInstance(void); + static void DestroyInstance(void); + + void OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message); + void OnWapPushEventCallBack(const Tizen::Base::String &header, const Tizen::Base::ByteBuffer &body, int bodyLength); + void OnIncomingEtwsCallback(int tempReceivedTime, const Tizen::Base::ByteBuffer &msgSerialNumber,const Tizen::Base::ByteBuffer &msgSecurityInfo, int messgeId, const Tizen::Base::ByteBuffer &etwsMsgWarningType); + void OnIncomingCbsCallback(const Tizen::Base::String &message, const Tizen::Base::ByteBuffer &msgSerialNumber, int tempReceivedTime, int messgeId, int dataCodingScheme, const Tizen::Base::String &messageLanguage); + void OnIncomingSmsCallback(int port, int displayTime, const Tizen::Base::String &message, const Tizen::Base::String &senderAddress); + void SetCbsAndEtwsUserEvent(_MessageType msgType, _SmsEvent* pEvent); + +private: + _MessagingProxy(void); + virtual ~_MessagingProxy(void); + +private: + Tizen::Io::_IpcClient* __pIpcClient; + static _MessagingProxy *__pSelf; + _SmsEvent* __pWapPushListener; + Tizen::Base::Collection::ArrayList* __pSmsListenerList; + _SmsEvent* __pCbsListenerEvent; + _SmsEvent* __pEtwsListenerEvent; +}; // _MessagingProxy + +} } // Tizen::Messaging +#endif // _FMSG_MESSAGING_PROXY_H_ \ No newline at end of file diff --git a/src/FMsg_MessagingMessageTypes.cpp b/src/FMsg_MessagingMessageTypes.cpp new file mode 100644 index 0000000..385966d --- /dev/null +++ b/src/FMsg_MessagingMessageTypes.cpp @@ -0,0 +1,45 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +/** + * @file FMsg_MessagingMessageTypes.cpp + * @brief This is the generator of IPC messages for the wap push. + */ + +#define IPC_MESSAGE_IMPL +#include "FMsg_MessagingMessageTypes.h" + +// Generate constructors. +#include +#include "FMsg_MessagingMessageTypes.h" + +// Generate destructors. +#include +#include "FMsg_MessagingMessageTypes.h" + +// Generate param traits write methods. +#include +namespace IPC { +#include "FMsg_MessagingMessageTypes.h" +} // namespace IPC + +// Generate param traits read methods. +#include +namespace IPC { +#include "FMsg_MessagingMessageTypes.h" +} // namespace IPC + diff --git a/src/FMsg_MmsEvent.cpp b/src/FMsg_MmsEvent.cpp new file mode 100644 index 0000000..b941dd2 --- /dev/null +++ b/src/FMsg_MmsEvent.cpp @@ -0,0 +1,63 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MmsEvent.cpp + * @brief This is the implementation file for the %_MmsEvent class. + * + * This file contains the implementation of the %_MmsEvent class. + */ + +#include +#include +#include "FMsg_MmsEvent.h" +#include "FMsg_MmsEventArg.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Runtime; + +namespace Tizen { namespace Messaging +{ + +_MmsEvent::_MmsEvent(void) +{ +} + +result +_MmsEvent::Construct(void) +{ + return _Event::Initialize(); +} + +void +_MmsEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) +{ + result r = E_SUCCESS; + IMmsListener* pMmsListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_MSG, pMmsListener != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + IEventArg* pEventArg = const_cast (&arg); + _MmsEventArg* pMmsEventArg = dynamic_cast <_MmsEventArg*>(pEventArg); + SysTryReturnVoidResult(NID_MSG, pMmsEventArg != null, E_SYSTEM, "[E_SYSTEM] A failure occurred from the underlying system."); + + // get error result + pMmsEventArg->GetErrorResult(r); + + // Fire + pMmsListener->OnMmsMessageSent(r); +} + +} } diff --git a/src/FMsg_MmsEvent.h b/src/FMsg_MmsEvent.h new file mode 100644 index 0000000..e1dad18 --- /dev/null +++ b/src/FMsg_MmsEvent.h @@ -0,0 +1,77 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MmsEvent.h + * @brief This is the header file for _MmsEvent class. + * + * This header file contains the declarations of _MmsEvent class. + */ + + +#ifndef _FMSG_INTERNAL_MMS_EVENT_H_ +#define _FMSG_INTERNAL_MMS_EVENT_H_ + +// Includes +#include + +namespace Tizen { namespace Messaging +{ + +// +// @class _MmsEvent +// @brief This class provides the event for MMS message. +// @since 1.0 +// +// @see IMmsEventListener, _MmsEventArg +// + +class _MmsEvent + : public Tizen::Base::Runtime::_Event +{ +// Life cycle +public: + /** + * This is the constructor. + * + */ + _MmsEvent(void); + + /** + * This is the class destructor. + * + */ + virtual ~_MmsEvent(void) {}; + + /** + * Initializes a new instance of the class + * + */ + result Construct(void); + + //Operations +protected: + void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg); + + // Lifecycle +private: + _MmsEvent(const _MmsEvent& mmsEvent); + _MmsEvent& operator =(const _MmsEvent& value); +}; // _MmsEvent + +} } + +#endif // _FMSG_INTERNAL_MMS_EVENT_H_ diff --git a/src/FMsg_MmsEventArg.cpp b/src/FMsg_MmsEventArg.cpp new file mode 100644 index 0000000..366e4c6 --- /dev/null +++ b/src/FMsg_MmsEventArg.cpp @@ -0,0 +1,48 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MmsEventArg.cpp + * @brief This is the implementation file for the %_MmsEventArg class. + * + * This file contains the implementation of the %_MmsEventArg class. + */ + +#include +#include "FMsg_MmsEventArg.h" + +using namespace Tizen::Base; + +namespace Tizen { namespace Messaging +{ + +_MmsEventArg::_MmsEventArg(void) +{ + __result = E_SUCCESS; +} + +_MmsEventArg::_MmsEventArg(const result r) +{ + __result = r; +} + +void +_MmsEventArg::GetErrorResult(result& r) const +{ + r = __result; +} + +} } diff --git a/src/FMsg_MmsEventArg.h b/src/FMsg_MmsEventArg.h new file mode 100644 index 0000000..79206d7 --- /dev/null +++ b/src/FMsg_MmsEventArg.h @@ -0,0 +1,90 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MmsEventArg.h + * @brief This is the header file for _MmsEventArg class. + * + * This header file contains the declarations of _MmsEventArg class. + */ + + +#ifndef _FMSG_INTERNAL_MMS_EVENT_ARG_H_ +#define _FMSG_INTERNAL_MMS_EVENT_ARG_H_ + +// Includes +#include +#include +#include + +namespace Tizen { namespace Messaging +{ + +// +// @class _MmsEventArg +// @brief This class provides methods for getting data from MMS event +// @since 1.0 +// + +class _MmsEventArg + : public Tizen::Base::Object + , public Tizen::Base::Runtime::IEventArg +{ + // Life cycle +public: + /** + * This is the constructor. + * + */ + _MmsEventArg(void); + + /** + * This is the constructor. + * + * @param[in] r - the message composer result + * + */ + _MmsEventArg(const result r); + + /** + * This is class destructor. + * + */ + virtual ~_MmsEventArg(void) {}; + + // Access +public: + /** + * Gets the error result of MMS event + * + * @param[out] r - the message composer result + * @exception E_SUCCESS - operation is successful + * @exception E_OUT_OF_MEMORY - failed to allocate required/requested memory + * @exception E_SYSTEM - the system has an error. + */ + void GetErrorResult(result& r) const; + + // Lifecycle +private: + _MmsEventArg(const _MmsEventArg& value); + _MmsEventArg& operator =(const _MmsEventArg& rhs); + +private: + result __result; +}; // _MmsEventArg +} } + +#endif // _FMSG_INTERNAL_MMS_EVENT_ARG_H_ diff --git a/src/FMsg_MmsManagerImpl.cpp b/src/FMsg_MmsManagerImpl.cpp new file mode 100644 index 0000000..ad53cc4 --- /dev/null +++ b/src/FMsg_MmsManagerImpl.cpp @@ -0,0 +1,241 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MmsManagerImpl.cpp + * @brief This is the implementation file for the %_MmsManagerImpl class. + * + * This file contains the implementation of the %_MmsManagerImpl class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FBase_StringConverter.h" +#include "FMsg_SmsMmsCallbackHandler.h" +#include "FMsg_MmsManagerImpl.h" +#include "FMsg_MmsEvent.h" +#include "FMsg_MmsEventArg.h" +#include "FMsg_MsgUtil.h" + +using namespace std; +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +namespace Tizen { namespace Messaging +{ + +_MmsManagerImpl::_MmsManagerImpl(void) + : __pMmsEvent(null) + , __isConstructed(false) + , __msgHandle(0) +{ +} + +_MmsManagerImpl::~_MmsManagerImpl(void) +{ + result r = E_SUCCESS; + int err = MSG_SUCCESS; + + if (_SmsMmsCallbackHandler::GetInstance()) + { + err = _SmsMmsCallbackHandler::GetInstance()->CloseMessageHandle(); + } + + if (err != MSG_SUCCESS) + { + r = ConvertException(err); + SysLogException(NID_MSG, r, "[%s] Failed to close message handle.", GetErrorMessage(r)); + + } + __isConstructed = false; +} + +result +_MmsManagerImpl::Construct(IMmsListener& listener) +{ + result r = E_SUCCESS; + int err = MSG_SUCCESS; + + SysAssertf(__isConstructed == false, "_MmsManagerImpl instance is already constructed."); + + // set event + unique_ptr<_MmsEvent> pMmsEvent(new (std::nothrow) _MmsEvent()); + SysTryReturn(NID_MSG, pMmsEvent != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed"); + + // event construction + r = pMmsEvent->Construct(); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to construct an instance"); + + // add listener + r = pMmsEvent->AddListener(listener, true); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to add a listener"); + + SysTryReturnResult(NID_MSG, _SmsMmsCallbackHandler::GetInstance() != NULL, E_SYSTEM, "Failed to constructSmsMmsCallbackHandler"); + + // open message handle + err = _SmsMmsCallbackHandler::GetInstance()->OpenMessageHandle(__msgHandle); + SysLog(NID_MSG, "value of __msgHandle is [%d]", __msgHandle); + + r = ConvertException(err); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to open messageHandle"); + + // check value of msg handle + SysTryReturnResult(NID_MSG, __msgHandle > 0, E_SYSTEM, "msgHandle is invalid."); + + __pMmsEvent = move(pMmsEvent); + __isConstructed = true; + + return r; +} + +result +_MmsManagerImpl::Send(const MmsMessage& message, const RecipientList& recipientList, bool saveToSentBox) +{ + SysAssertf(__isConstructed == true, "_MmsManagerImpl instance is not constructed yet."); + + result r = E_SUCCESS; + int err = MSG_SUCCESS; + int msgReqId = -1; + msg_struct_t msgOption = NULL; + + SysLog(NID_MSG, "sending an mms message"); + + msg_struct_t msgReq = msg_create_struct(MSG_STRUCT_REQUEST_INFO); + msg_struct_t msgInfo = msg_create_struct(MSG_STRUCT_MESSAGE_INFO); + msg_struct_t msgSendOpt = msg_create_struct(MSG_STRUCT_SENDOPT); + + msg_set_bool_value(msgSendOpt, MSG_SEND_OPT_SETTING_BOOL, true); + msg_set_bool_value(msgSendOpt, MSG_SEND_OPT_DELIVER_REQ_BOOL, false); + msg_set_bool_value(msgSendOpt, MSG_SEND_OPT_KEEPCOPY_BOOL, saveToSentBox); + + msg_get_struct_handle(msgSendOpt, MSG_SEND_OPT_MMS_OPT_HND, &msgOption); + msg_set_bool_value(msgOption, MSG_MMS_SENDOPTION_READ_REQUEST_BOOL, false); + msg_set_int_value(msgOption, MSG_MMS_SENDOPTION_PRIORITY_INT, MSG_MESSAGE_PRIORITY_NORMAL); + msg_set_int_value(msgOption, MSG_MMS_SENDOPTION_EXPIRY_TIME_INT, MSG_EXPIRY_TIME_MAXIMUM); + msg_set_int_value(msgOption, MSG_MMS_SENDOPTION_DELIVERY_TIME_INT, MSG_DELIVERY_TIME_IMMEDIATLY); + + err = _MsgUtil::GetMmsMessage(msgInfo, message, recipientList); + + r = ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to generate the MMS message.", GetErrorMessage(r)); + + msg_set_struct_handle(msgReq, MSG_REQUEST_MESSAGE_HND, msgInfo); + msg_set_struct_handle(msgReq, MSG_REQUEST_SENDOPT_HND, msgSendOpt); + + if (err == MSG_SUCCESS) + { + err = msg_mms_send_message(__msgHandle, msgReq); + } + + r = ConvertException(err); + + if (r == E_SUCCESS) + { + if (_SmsMmsCallbackHandler::GetInstance()) + { + msg_get_int_value(msgReq, MSG_REQUEST_REQUESTID_INT, &msgReqId); + r = _SmsMmsCallbackHandler::GetInstance()->AddToMessageMap(msgReqId, _MSG_MMS, __pMmsEvent.get()); + } + else + { + r = E_SYSTEM; + } + } + + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to send the MMS message.", GetErrorMessage(r)); + + //release message + msg_release_struct(&msgReq); + SysLog(NID_MSG, "sending an mms message success"); + return r; + +CATCH: + //release message + msg_release_struct(&msgReq); + return r; +} + +_MmsManagerImpl* +_MmsManagerImpl::GetInstance(MmsManager& mmsManager) +{ + return mmsManager.__pImpl; +} + +const _MmsManagerImpl* +_MmsManagerImpl::GetInstance(const MmsManager& mmsManager) +{ + return mmsManager.__pImpl; +} + +result +_MmsManagerImpl::ConvertException(int err) const +{ + result r = E_SUCCESS; + + switch (err) + { + case MSG_SUCCESS: + r = E_SUCCESS; + break; + + case MSG_ERR_INVALID_PARAMETER: + case MSG_ERR_INVALID_MESSAGE: + case MSG_ERR_NULL_POINTER: + case MSG_ERR_NULL_MESSAGE: + r = E_INVALID_ARG; + break; + + case MSG_ERR_MEMORY_ERROR: + r = E_OUT_OF_MEMORY; + break; + + case MSG_ERR_STORAGE_ERROR: + r = E_STORAGE_FULL; + break; + + case MSG_ERR_SERVER_NOT_READY: + case MSG_ERR_TRANSPORT_ERROR: + case MSG_ERR_COMMUNICATION_ERROR: + r = E_NETWORK_UNAVAILABLE; + break; + + case MSG_ERR_NO_SIM: + r = E_DEVICE_UNAVAILABLE; + break; + + case MSG_ERR_PLUGIN_TAPI_FAILED: + r = E_FAILURE; + break; + + default: + r = E_SYSTEM; + break; + } + + return r; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_MmsManagerImpl.h b/src/FMsg_MmsManagerImpl.h new file mode 100644 index 0000000..75e08d0 --- /dev/null +++ b/src/FMsg_MmsManagerImpl.h @@ -0,0 +1,149 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MmsManagerImpl.h + * @brief This is the header file for the _MmsManagerImpl class. + * + * This header file contains the declarations of the _MmsManagerImpl class. + */ + +#ifndef _FMSG_INTERNAL_MMS_MANAGER_IMPL_H_ +#define _FMSG_INTERNAL_MMS_MANAGER_IMPL_H_ + +// Includes +#include +#include "FMsg_Types.h" + +namespace Tizen { namespace Messaging +{ + +// forward declaration +class MmsManager; +class IMmsListener; +class MmsMessage; +class RecipientList; +class _MmsEvent; + +/** +* @class _MmsManagerImpl +* @brief This class provides methods to use the MMS messaging service. +* @since 1.0 +* +* This class provides methods to use the MMS messaging service. @n +*/ +class _MmsManagerImpl + : public Tizen::Base::Object +{ + // Life cycle +public: + /** + * This is the default constructor for this class. + * + * @since 1.0 + */ + _MmsManagerImpl(void); + + /** + * This is the destructor for this class. + * + * @since 1.0 + */ + virtual ~_MmsManagerImpl(void); + +private: + _MmsManagerImpl(const _MmsManagerImpl& value); + _MmsManagerImpl& operator =(const _MmsManagerImpl& rhs); + + // Operation +public: + /** + * Initializes this instance of _MmsManagerImpl with the specified listener. + * + * @since 1.0 + * @return An error code + * @param[in] listener The listener to receive a send result asynchronously + * @exception E_SUCCESS The method was successful. + */ + result Construct(IMmsListener& listener); + + /** + * Sends the MMS message. + * + * @since 1.0 + * @privlevel SYSTEM + * @privgroup http://tizen.org/privilege/messaging.mms + * + * @return An error code + * @param[in] message The message to be sent + * @param[in] recipientList The list of recipients + * @param[in] saveToSentBox Set to @c true to save the message in the Sentbox, @n + * else @c false + * @exception E_SUCCESS The method was successful. + * @exception E_ON_INITIALIZING The mailbox is not completely loaded yet. + * @exception E_STORAGE_FULL The storage is full. + * @exception E_DEVICE_UNAVAILABLE The device is unavailable. + * @exception E_NETWORK_UNAVAILABLE The network is unavailable. + * @exception E_INVALID_CONDITION The profile is not set. + * @exception E_INVALID_ADDRESS The address is invalid. + * @exception E_FDN_MODE The FDN mode has been activated. + * @exception E_INVALID_ARG The number of recipients is @c 0 or the message is empty. @n + * @exception E_MAX_EXCEEDED The number of recipients crossed the limit (Maximum 10). + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @remarks Some service providers may not support sending MMS messages with an empty subject or body. @n + * In this case, the result of the status report will be the E_FAILURE exception. + * @see IMmsListener::OnMmsMessageSent() + */ + result Send(const MmsMessage& message, const RecipientList& recipientList, bool saveToSentBox); + +public: + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _MmsManagerImpl + * @param[in] mmsManager An instance of MmsManager + */ + static _MmsManagerImpl* GetInstance(MmsManager& mmsManager); + + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _MmsManagerImpl + * @param[in] mmsManager An instance of MmsManager + */ + static const _MmsManagerImpl* GetInstance(const MmsManager& mmsManager); + + //utility +private: + /** + * Converts platform error codes + * + * @return An error code + * @param[in] err The error to convert + * + */ + result ConvertException(int err) const; + +private: + std::unique_ptr<_MmsEvent> __pMmsEvent; + bool __isConstructed; + msg_handle_t __msgHandle; +}; // _MmsManagerImpl +} } + +#endif // _FMSG_INTERNAL_MMS_MANAGER_IMPL_H_ diff --git a/src/FMsg_MmsMessageImpl.cpp b/src/FMsg_MmsMessageImpl.cpp new file mode 100644 index 0000000..e28a57d --- /dev/null +++ b/src/FMsg_MmsMessageImpl.cpp @@ -0,0 +1,598 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MmsMessageImpl.cpp + * @brief This is the implementation file for the %_MmsMessageImpl class. + * + * This file contains the implementation of the %_MmsMessageImpl class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_MsgUtil.h" +#include "FMsg_MmsMessageImpl.h" + +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; +using namespace Tizen::Io; + +namespace Tizen { namespace Messaging +{ + +_MmsMessageImpl::_MmsMessageImpl(void) + : __remainMsgSize(MAX_MMS_FILE_SIZE) +{ +} + +_MmsMessageImpl::_MmsMessageImpl(const _MmsMessageImpl& value) +{ + __subject = value.__subject; + __text = value.__text; + __imageFilePath = value.__imageFilePath; + __audioFilePath = value.__audioFilePath; + __videoFilePath = value.__videoFilePath; + __vCalendarFilePath = value.__vCalendarFilePath; + __vCardFilePath = value.__vCardFilePath; + __remainMsgSize = value.__remainMsgSize; +} + +_MmsMessageImpl::~_MmsMessageImpl(void) +{ + __remainMsgSize = MAX_MMS_FILE_SIZE; +} + +_MmsMessageImpl& +_MmsMessageImpl::operator =(const _MmsMessageImpl& rhs) +{ + if (this != &rhs) + { + __subject = rhs.__subject; + __text = rhs.__text; + __imageFilePath = rhs.__imageFilePath; + __audioFilePath = rhs.__audioFilePath; + __videoFilePath = rhs.__videoFilePath; + __vCalendarFilePath = rhs.__vCalendarFilePath; + __vCardFilePath = rhs.__vCardFilePath; + __remainMsgSize = rhs.__remainMsgSize; + } + + return (*this); +} + +bool +_MmsMessageImpl::Equals(const Tizen::Base::Object& value) const +{ + const _MmsMessageImpl* pMmsMessageImpl = dynamic_cast(&value); + if (!pMmsMessageImpl) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + // subject + if (__subject != pMmsMessageImpl->__subject) + { + return false; + } + + // text + if (__text != pMmsMessageImpl->__text) + { + return false; + } + + // image + if (__imageFilePath != pMmsMessageImpl->__imageFilePath) + { + return false; + } + + // audio + if (__audioFilePath != pMmsMessageImpl->__audioFilePath) + { + return false; + } + + // video + if (__videoFilePath != pMmsMessageImpl->__videoFilePath) + { + return false; + } + + // vcard + if (__vCalendarFilePath != pMmsMessageImpl->__vCalendarFilePath) + { + return false; + } + + // vcal + if (__vCardFilePath != pMmsMessageImpl->__vCardFilePath) + { + return false; + } + + // remain size + if (__remainMsgSize != pMmsMessageImpl->__remainMsgSize) + { + return false; + } + + return true; +} + +int +_MmsMessageImpl::GetHashCode(void) const +{ + int hash = 0; + + hash = __subject.GetHashCode() + __text.GetHashCode() + __imageFilePath.GetHashCode() + __audioFilePath.GetHashCode() + __videoFilePath.GetHashCode() + __remainMsgSize + __vCalendarFilePath.GetHashCode() + __vCardFilePath.GetHashCode(); + + return hash; +} + +result +_MmsMessageImpl::SetSubject(const String& subject) +{ + result r = E_SUCCESS; + + // get subject size + if (subject.GetLength() * 2 > __remainMsgSize) + { + r = E_MAX_EXCEEDED; + SysLogException(NID_MSG, r, "[E_MAX_EXCEEDED] Unable to add file. The size of the subject exceeds the maximum message size."); + goto CATCH; + } + __remainMsgSize -= subject.GetLength() * 2; + + __subject = subject; + + return r; + +CATCH: + return r; +} + +String +_MmsMessageImpl::GetSubject(void) const +{ + return __subject; +} + +result +_MmsMessageImpl::SetText(const String& text) +{ + result r = E_SUCCESS; + + // get subject size + if (text.GetLength() * 2 > __remainMsgSize) + { + r = E_MAX_EXCEEDED; + SysLogException(NID_MSG, r, "[E_MAX_EXCEEDED] Unable to add file. The size of the body text exceeds the maximum message size."); + goto CATCH; + } + __remainMsgSize -= text.GetLength() * 2; + + __text = text; + + return r; + +CATCH: + return r; +} + +String +_MmsMessageImpl::GetText(void) const +{ + return __text; +} + +result +_MmsMessageImpl::AddAttachment(MmsAttachmentFormat format, const Tizen::Base::String& filePath) +{ + result r = E_SUCCESS; + long fileSize = 0; + FileAttributes fileAttributes; + + // check file existence + if (File::IsFileExist(filePath) == false) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] Cannot find corresponding file."); + goto CATCH; + } + + // get file attributes + r = File::GetAttributes(filePath, fileAttributes); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to get the file attributes.", GetErrorMessage(r)); + goto CATCH; + } + + // get file size + fileSize = (long) fileAttributes.GetFileSize(); + if (fileSize > __remainMsgSize) + { + r = E_MAX_EXCEEDED; + SysLogException(NID_MSG, r, "[E_MAX_EXCEEDED] Unable to add file. The size of the file exceeds the maximum message size."); + goto CATCH; + } + + // Attachment Format check + r = CheckPreviousAttachment(format); + + if (r != E_SUCCESS) + { + SysLogException(NID_MSG, r, "[%s] Corresponding format file is already attached. Format: %d.", GetErrorMessage(r), (int) format); + goto CATCH; + } + + if (_MsgUtil::CheckMediaFormat(format, filePath) == false) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] Specified file contains invalid or unsupported media."); + goto CATCH; + } + + // Set the attachment filePath. + r = SetAttachmentPath(format, filePath); + + if (r != E_SUCCESS) + { + SysLogException(NID_MSG, r, "[%s] Failed to add file. Format: [%d].", GetErrorMessage(r), (int) format); + goto CATCH; + } + + __remainMsgSize -= fileSize; + + return r; + +CATCH: + return r; +} + +result +_MmsMessageImpl::RemoveAttachment(MmsAttachmentFormat format) +{ + FileAttributes fileAttribute; + long fileSize = 0; + result r = E_SUCCESS; + + switch (format) + { + case MMS_IMAGE: + if (__imageFilePath.GetLength() <= 0) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] Cannot find corresponding file."); + goto CATCH; + } + r = File::GetAttributes(__imageFilePath, fileAttribute); + if (IsFailed(r)) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] Failed to get the file attributes."); + goto CATCH; + } + fileSize = (long) fileAttribute.GetFileSize(); + __imageFilePath.Clear(); + break; + + case MMS_AUDIO: + if (__audioFilePath.GetLength() <= 0) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] The length of the file name is smaller than 0."); + goto CATCH; + } + r = File::GetAttributes(__audioFilePath, fileAttribute); + if (IsFailed(r)) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] Failed to get the file attributes."); + goto CATCH; + } + fileSize = (long) fileAttribute.GetFileSize(); + __audioFilePath.Clear(); + break; + + case MMS_VIDEO: + if (__videoFilePath.GetLength() <= 0) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] The length of the file name is smaller than 0."); + goto CATCH; + } + r = File::GetAttributes(__videoFilePath, fileAttribute); + if (IsFailed(r)) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] Failed to get the file attributes."); + goto CATCH; + } + fileSize = (long) fileAttribute.GetFileSize(); + __videoFilePath.Clear(); + break; + + case MMS_VCARD: + if (__vCardFilePath.GetLength() <= 0) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] The length of the file name is smaller than 0."); + goto CATCH; + } + r = File::GetAttributes(__vCardFilePath, fileAttribute); + if (IsFailed(r)) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] Failed to get the file attributes."); + goto CATCH; + } + fileSize = (long) fileAttribute.GetFileSize(); + __vCardFilePath.Clear(); + break; + + case MMS_VCALENDAR: + if (__vCalendarFilePath.GetLength() <= 0) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] The length of the file name is smaller than 0."); + goto CATCH; + } + r = File::GetAttributes(__vCalendarFilePath, fileAttribute); + if (IsFailed(r)) + { + r = E_FILE_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_FILE_NOT_FOUND] Failed to get the file attributes."); + goto CATCH; + } + fileSize = (long) fileAttribute.GetFileSize(); + __vCalendarFilePath.Clear(); + break; + } + + __remainMsgSize += fileSize; + + return r; + +CATCH: + return r; +} + +String +_MmsMessageImpl::GetAttachment(MmsAttachmentFormat format) const +{ + String returnValue; + ClearLastResult(); + + if (__imageFilePath.GetLength() <= 0 && __audioFilePath.GetLength() <= 0 && __videoFilePath.GetLength() <= 0 && + __vCalendarFilePath.GetLength() <= 0 && __vCardFilePath.GetLength() <= 0) + { + SetLastResult(E_INVALID_CONDITION); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_CONDITION] The file path is Empty."); + returnValue = L""; + return returnValue; + } + + switch (format) + { + case MMS_IMAGE: + if (__imageFilePath.GetLength() <= 0) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] There is no image file."); + } + returnValue = __imageFilePath; + break; + + case MMS_VIDEO: + if (__videoFilePath.GetLength() <= 0) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] There is no video file."); + } + returnValue = __videoFilePath; + break; + + case MMS_AUDIO: + if (__audioFilePath.GetLength() <= 0) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] There is no audio file."); + } + returnValue = __audioFilePath; + break; + + case MMS_VCARD: + if (__vCardFilePath.GetLength() <= 0) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] There is no vCard file."); + } + returnValue = __vCardFilePath; + break; + + case MMS_VCALENDAR: + if (__vCalendarFilePath.GetLength() <= 0) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] There is no vCalendar file."); + } + returnValue = __vCalendarFilePath; + break; + + default: + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, GetLastResult(), "[E_INVALID_ARG] Invalid MMS format arguments."); + returnValue = L""; + break; + } + + return returnValue; +} + +_MmsMessageImpl* +_MmsMessageImpl::GetInstance(MmsMessage& mmsMessage) +{ + return mmsMessage.__pImpl; +} + +const _MmsMessageImpl* +_MmsMessageImpl::GetInstance(const MmsMessage& mmsMessage) +{ + return mmsMessage.__pImpl; +} + +////////////////////////////////////////////////////////////////////////// +// private +////////////////////////////////////////////////////////////////////////// +result +_MmsMessageImpl::CheckPreviousAttachment(MmsAttachmentFormat format) +{ + result r = E_SUCCESS; + + SysTryReturn(NID_MSG, (format >= MMS_IMAGE && format <= MMS_VCALENDAR), r = E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] Invalid MmsAttachmentFormat arguments."); + + // Attachment Format check + switch (format) + { + case MMS_IMAGE: + if (!__imageFilePath.IsEmpty()) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The image file is already attached."); + goto CATCH; + } + else if (!__videoFilePath.IsEmpty()) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The image and video file cannot be attached simultaneously."); + goto CATCH; + } + break; + + case MMS_VIDEO: + if (!__videoFilePath.IsEmpty()) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The video file is already attached."); + goto CATCH; + } + else if (!__imageFilePath.IsEmpty()) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The image and video file cannot be attached simultaneously."); + goto CATCH; + } + else if (!__audioFilePath.IsEmpty()) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The video and audio file cannot be attached simultaneously."); + goto CATCH; + } + break; + + case MMS_AUDIO: + if (!__audioFilePath.IsEmpty()) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The audio file is already attached."); + goto CATCH; + } + else if (!__videoFilePath.IsEmpty()) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The video and audio file cannot be attached simultaneously."); + goto CATCH; + } + break; + + case MMS_VCARD: + if (!__vCardFilePath.IsEmpty()) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The vCard file is already attached."); + goto CATCH; + } + break; + + case MMS_VCALENDAR: + if (!__vCalendarFilePath.IsEmpty()) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The vCalendar file is already attached."); + goto CATCH; + } + break; + } + + return r; + +CATCH: + return r; +} + +result +_MmsMessageImpl::SetAttachmentPath(const MmsAttachmentFormat format, const String& filePath) +{ + result r = E_SUCCESS; + + SysTryReturn(NID_MSG, (format >= MMS_IMAGE && format <= MMS_VCALENDAR), r = E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] Invalid MmsAttachmentFormat arguments."); + SysTryReturn(NID_MSG, filePath.GetLength() > 0, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The file path is empty."); + SysTryReturn(NID_MSG, filePath.GetLength() <= PATH_MAX, r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The file path is too long."); + + switch (format) + { + case MMS_IMAGE: + __imageFilePath = filePath; + break; + + case MMS_VIDEO: + __videoFilePath = filePath; + break; + + case MMS_AUDIO: + __audioFilePath = filePath; + break; + + case MMS_VCARD: + __vCardFilePath = filePath; + break; + + case MMS_VCALENDAR: + __vCalendarFilePath = filePath; + break; + } + + return E_SUCCESS; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_MmsMessageImpl.h b/src/FMsg_MmsMessageImpl.h new file mode 100644 index 0000000..cfed5de --- /dev/null +++ b/src/FMsg_MmsMessageImpl.h @@ -0,0 +1,250 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MmsMessageImpl.h + * @brief This is the header file for _MmsMessageImpl class. + * + * This header file contains the declarations of _MmsMessageImpl class. + */ + + +#ifndef _FMSG_INTERNAL_MMS_MESSAGE_H_ +#define _FMSG_INTERNAL_MMS_MESSAGE_H_ + +namespace Tizen { namespace Messaging +{ +// forward declaration +class MmsMessage; + +/** +* @class _MmsMessageImpl +* @brief This class provides methods for handling an MMS message. +* @since 1.0 +* +* This class provides methods for handling MMS messages. @n +* A user can set and get the subject and body text of an MMS, @n +* and can also add, remove, and receive attachments. +*/ +class _MmsMessageImpl + : public Tizen::Base::Object +{ + // Life cycle +public: + /** + * This is the default constructor for this class. + * + * @since 1.0 + */ + _MmsMessageImpl(void); + + /** + * This is the destructor for this class. + * + * @since 1.0 + */ + virtual ~_MmsMessageImpl(void); + + /** + * This is the copy constructor for this class. + * + * @since 1.0 + * @param[in] value An instance of _MmsMessageImpl + */ + _MmsMessageImpl(const _MmsMessageImpl& value); + + /** + * This assignment operator copies an MMS message from the specified instance of _MmsMessageImpl to the calling instance of _MmsMessageImpl. + * + * @since 1.0 + * @return A reference to this instance + * @param[in] rhs A reference to the _MmsMessageImpl instance to be copied + */ + _MmsMessageImpl& operator =(const _MmsMessageImpl& rhs); + +public: + /** + * Gets the hash value of the current instance. + * + * @since 1.0 + * @return The hash value of the current instance + * @remarks Two equal instances should return the same hash value. For better performance, + * the used hash function must generate a random distribution for all inputs. + */ + virtual int GetHashCode(void) const; + + /** + * Compares the specified instance with the calling instance. + * + * @since 1.0 + * @return @c true if both instances are equal @n + * @c false, otherwise + * @param[in] value An instance of _MmsMessageImpl + */ + virtual bool Equals(const Tizen::Base::Object& value) const; + + // Operation +public: + /** + * Sets the subject of the MMS. + * + * @since 1.0 + * @return An error code + * @param[in] subject The subject of the message + * @exception E_SUCCESS The method was successful. + * @exception E_MAX_EXCEEDED The subject length of the message is exceeding the maximum limit (Maximum 40 characters). @n + * The total size of the subject, body, and attachment(s) is exceeding the maximum limit (295KB). + * @see GetSubject() + */ + result SetSubject(const Tizen::Base::String& subject); + + /** + * Sets the text body of the message. + * + * @since 1.0 + * @return An error code + * @param[in] text The body text of the message + * @exception E_SUCCESS The method was successful. + * @exception E_MAX_EXCEEDED The body length of the message is exceeding the maximum limit (Maximum 1000 characters). @n + * The total size of the subject, body, and attachment(s) is exceeding the maximum limit (295KB). + * @see GetText() + */ + result SetText(const Tizen::Base::String& text); + + /** + * Adds the attachment of the specific type. + * + * @since 1.0 + * @return An error code + * @param[in] format The format of the attachment + * @param[in] filePath The path of the file to attach + * @exception E_SUCCESS The method was successful. + * @exception E_FILE_NOT_FOUND The specified file could not be found or accessed. + * @exception E_INVALID_ARG The length of the specified @c filePath is too long or @c 0. @n + * The specified file format is already attached. @n + * The value of the specified @c format is invalid. @n + * The specified file contains invalid or unsupported media. @n + * The specified file format cannot be attached. @n + * (An MMS attachment may contain either an image, an audio, a video, a vCard, or a vCalendar or a combination of an image, an audio, a vCard, and a vCalendar file. @n + * MMS attachments cannot contain a video file in combination with an image or audio file.) + * @exception E_MAX_EXCEEDED The size of the file is exceeding the maximum limit (Maximum 295KB). @n + * The total size of the subject, body, and attachment(s) is exceeding the maximum limit (295KB). + * @see GetAttachment() + */ + result AddAttachment(MmsAttachmentFormat format, const Tizen::Base::String& filePath); + + /** + * Gets the subject of the message. + * + * @since 1.0 + * @return The subject of the message + * @see SetSubject() + */ + Tizen::Base::String GetSubject(void) const; + + /** + * Gets the body text of the message. + * + * @since 1.0 + * @return The body text of the message + * @see SetText() + */ + Tizen::Base::String GetText(void) const; + + /** + * Gets the attachment file of the specific type. + * + * @since 1.0 + * @return The path of the attached file + * @param[in] format The format of the attachment + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_CONDITION No file is attached. + * @exception E_INVALID_ARG There is no file of the specified @c format. @n + * The value of the specified @c format is invalid. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see AddAttachment() + */ + Tizen::Base::String GetAttachment(MmsAttachmentFormat format) const; + + /** + * Removes the attachment of the specific type + * + * @since 1.0 + * @return An error code + * @param[in] format The format of the attachment to remove + * @exception E_SUCCESS The method was successful. + * @exception E_FILE_NOT_FOUND The corresponding format file was not found. + * @exception E_INVALID_ARG The value of the specified @c format is invalid. + * @see AddAttachment(), GetAttachment() + */ + result RemoveAttachment(MmsAttachmentFormat format); + +private: + /** + * Checks the existence of the previous attachment file according to the file format. + * + * @return An error code + * @param[in] format The format of the attachment + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG A specified input parameter is invalid. + */ + result CheckPreviousAttachment(MmsAttachmentFormat format); + + + /** + * Sets the file path to the attachment file path according to the format. + * + * @return An error code + * @param[in] format The format of the attachment + * @param[in] filePath The Input file path + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG A specified input parameter is invalid. + */ + result SetAttachmentPath(const MmsAttachmentFormat format, const Tizen::Base::String& filePath); + +public: + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _MmsMessageImpl + * @param[in] mmsMessage An instance of MmsMessage + */ + static _MmsMessageImpl* GetInstance(MmsMessage& mmsMessage); + + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _MmsMessageImpl + * @param[in] mmsMessage An instance of MmsMessage + */ + static const _MmsMessageImpl* GetInstance(const MmsMessage& mmsMessage); + +private: + Tizen::Base::String __subject; + Tizen::Base::String __text; + Tizen::Base::String __imageFilePath; + Tizen::Base::String __audioFilePath; + Tizen::Base::String __videoFilePath; + Tizen::Base::String __vCalendarFilePath; + Tizen::Base::String __vCardFilePath; + int __remainMsgSize; +}; // _MmsMessageImpl + +} } + +#endif // _FMSG_INTERNAL_MMS_MESSAGE_H_ diff --git a/src/FMsg_MsgUtil.cpp b/src/FMsg_MsgUtil.cpp new file mode 100644 index 0000000..26e62a6 --- /dev/null +++ b/src/FMsg_MsgUtil.cpp @@ -0,0 +1,2041 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MsgUtil.cpp + * @brief This is the implementation file for the %_MsgUtil class. + * + * This file contains the implementation of the %_MsgUtil class. + */ + +// includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_SmsMessageImpl.h" +#include "FMsg_EmailManagerImpl.h" +#include "FMsg_MsgUtil.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::Io; + +static const char* BODY_TEXT_FILE_NAME = "/opt/usr/media/mmsbodytext.txt"; + +namespace Tizen { namespace Messaging +{ + +result +_MsgUtil::CheckAddressValidity(const Tizen::Base::String& address, _MessageType type) +{ + result r = E_SUCCESS; + int addressLen = 0; + + switch (type) + { + case _MSG_SMS: + // fall through + case _MSG_MMS: + { + addressLen = address.GetLength(); + if (address[0] == L'+') + { + addressLen--; + } + + if (addressLen < MIN_LENGTH_PHONE || addressLen > MAX_LENGTH_PHONE) + { + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The Address length (%d) is too short or too long.", addressLen); + r = E_INVALID_ADDRESS; + goto CATCH; + } + + for (int index = 0; index < addressLen; index++) + { + if (address[0] == L'+') + { + if (!Character::IsDigit(address[index + 1])) + { + r = E_INVALID_ADDRESS; + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The phone number contains a non-digit string."); + goto CATCH; + } + } + else + { + if (!Character::IsDigit(address[index])) + { + r = E_INVALID_ADDRESS; + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The phone number contains a non-digit string."); + goto CATCH; + } + } + } + + break; + } + + case _MSG_EMAIL: + { + addressLen = address.GetLength(); + + // size check + if (addressLen < 5 || addressLen > MAX_LENGTH_EMAIL) // "a@a.a" + { + r = E_INVALID_ADDRESS; + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The length (%d) of email address is too short or too long.", addressLen); + goto CATCH; + } + + // check number of '@' char and '@' position + int pos = 0; + int posByLast = 0; + + r = address.IndexOf(L'@', 0, pos); + r = address.LastIndexOf(L'@', addressLen - 1, posByLast); + + if (pos <= 0 || pos != posByLast) + { + r = E_INVALID_ADDRESS; + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] There is not a @ character or there are multiple @ characters."); + goto CATCH; + } + + break; + } + + default: + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] There is not a such type of address (%d).", type); + return r; + } + + return E_SUCCESS; + +CATCH: + return r; +} + +result +_MsgUtil::CheckEmailAddressValidity(const RecipientList& recipientList) +{ + result r = E_SUCCESS; + RecipientList* pRecipientList = null; + IList* pToList = null; + IList* pCcList = null; + IList* pBccList = null; + int count = 0; + int index = 0; + String* pItem = null; + + pRecipientList = const_cast< RecipientList* >(&recipientList); + + // TO + count = 0; // initialize the count value + pToList = pRecipientList->GetListN(RECIPIENT_TYPE_TO); + if (!pToList) + { + r = GetLastResult(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to get TO list.", GetErrorMessage(r)); + goto CATCH; + } + else + { + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in TO list is not valid."); + SysLog( + NID_MSG, + "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_TO) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS."); + r = E_INVALID_ADDRESS; + goto CATCH; + } + } + else + { + count = pToList->GetCount(); + } + + if (count > 0) + { + for (index = 0; index < count; index++) + { + pItem = dynamic_cast< String* >(pToList->GetAt(index)); + if (pItem != null) + { + r = CheckAddressValidity(*pItem, _MSG_EMAIL); + } + else + { + r = E_INVALID_ADDRESS; + + } + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] There is invalid email address in TO list. Please check the RecipientList first.", + GetErrorMessage( + r)); + goto CATCH; + } + } + } + + // CC + count = 0; // initialize the count value + pCcList = pRecipientList->GetListN(RECIPIENT_TYPE_CC); + if (!pCcList) + { + r = GetLastResult(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to get CC list.", GetErrorMessage(r)); + goto CATCH; + } + else + { + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in CC list is not valid."); + SysLog( + NID_MSG, + "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_CC) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS."); + r = E_INVALID_ADDRESS; + goto CATCH; + } + } + else + { + count = pCcList->GetCount(); + } + + if (count > 0) + { + for (index = 0; index < count; index++) + { + pItem = dynamic_cast< String* >(pCcList->GetAt(index)); + if (pItem != null) + { + r = CheckAddressValidity(*pItem, _MSG_EMAIL); + } + else + { + r = E_INVALID_ADDRESS; + + } + + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] There is invalid email address in CC list. Please check the RecipientList first.", + GetErrorMessage( + r)); + goto CATCH; + } + } + } + + // BCC + count = 0; // initialize the count value + pBccList = pRecipientList->GetListN(RECIPIENT_TYPE_BCC); + if (!pBccList) + { + r = GetLastResult(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to get BCC list.", GetErrorMessage(r)); + goto CATCH; + } + else + { + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in BCC list is not valid."); + SysLog( + NID_MSG, + "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_BCC) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS."); + r = E_INVALID_ADDRESS; + goto CATCH; + } + } + else + { + count = pBccList->GetCount(); + } + + if (count > 0) + { + for (index = 0; index < count; index++) + { + pItem = dynamic_cast< String* >(pBccList->GetAt(index)); + if (pItem != null) + { + r = CheckAddressValidity(*pItem, _MSG_EMAIL); + } + else + { + r = E_INVALID_ADDRESS; + + } + + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] There is invalid email address in BCC list. Please check the RecipientList first.", + GetErrorMessage( + r)); + goto CATCH; + } + } + } + + // free the memories + if (pToList) + { + if (pToList->GetCount() > 0) + { + pToList->RemoveAll(true); + } + delete pToList; + pToList = null; + } + if (pCcList) + { + if (pCcList->GetCount() > 0) + { + pCcList->RemoveAll(true); + } + delete pCcList; + pCcList = null; + } + if (pBccList) + { + if (pBccList->GetCount() > 0) + { + pBccList->RemoveAll(true); + } + delete pBccList; + pBccList = null; + } + + return E_SUCCESS; + +CATCH: + if (pToList) + { + if (pToList->GetCount() > 0) + { + pToList->RemoveAll(true); + } + delete pToList; + pToList = null; + } + if (pCcList) + { + if (pCcList->GetCount() > 0) + { + pCcList->RemoveAll(true); + } + delete pCcList; + pCcList = null; + } + if (pBccList) + { + if (pBccList->GetCount() > 0) + { + pBccList->RemoveAll(true); + } + delete pBccList; + pBccList = null; + } + + return r; +} + +result +_MsgUtil::CheckPhoneNumberValidity(_MessageType type, const RecipientList& recipientList) +{ + result r = E_SUCCESS; + RecipientList* pRecipientList = null; + IList* pToList = null; + IList* pCcList = null; + IList* pBccList = null; + int count = 0; + int index = 0; + String* pItem = null; + int addressLen = 0; + + pRecipientList = const_cast< RecipientList* >(&recipientList); + + // TO + count = 0; // initialize the count value + pToList = pRecipientList->GetListN(RECIPIENT_TYPE_TO); + if (!pToList) + { + r = GetLastResult(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to get TO list.", GetErrorMessage(r)); + goto CATCH; + } + else + { + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in TO list is not valid."); + SysLog( + NID_MSG, + "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_TO) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS."); + r = E_INVALID_ADDRESS; + goto CATCH; + } + } + else + { + count = pToList->GetCount(); + } + + if (count > 0) + { + for (index = 0; index < count; index++) + { + pItem = dynamic_cast< String* >(pToList->GetAt(index)); + SysTryCatch(NID_MSG, pItem != null, r = E_INVALID_ADDRESS, r, "To List Null"); + r = CheckAddressValidity(*pItem, type); + + if (type == _MSG_MMS && r != E_SUCCESS) //Check If MMS might have email address + { + addressLen = pItem->GetLength(); + + // size check + if (addressLen < 5 || addressLen > MAX_LENGTH_EMAIL) // "a@a.a" + { + r = E_INVALID_ADDRESS; + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The length (%d) of email address is too short or too long.", addressLen); + goto CATCH; + } + + // check number of '@' char and '@' position + int pos = 0; + int posByLast = 0; + + r = pItem->IndexOf(L'@', 0, pos); + r = pItem->LastIndexOf(L'@', addressLen - 1, posByLast); + + if (pos <= 0 || pos != posByLast) + { + r = E_INVALID_ADDRESS; + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] There is not a @ character or there are multiple @ characters."); + goto CATCH; + } + } + + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] There is invalid phone number in TO list. Please check the RecipientList first.", + GetErrorMessage( + r)); + goto CATCH; + } + } + } + + // CC + count = 0; // initialize the count value + pCcList = pRecipientList->GetListN(RECIPIENT_TYPE_CC); + if (!pCcList) + { + r = GetLastResult(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to get CC list.", GetErrorMessage(r)); + goto CATCH; + } + else + { + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in CC list is not valid."); + SysLog( + NID_MSG, + "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_CC) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS."); + r = E_INVALID_ADDRESS; + goto CATCH; + } + } + else + { + count = pCcList->GetCount(); + } + + if (count > 0) + { + for (index = 0; index < count; index++) + { + pItem = dynamic_cast< String* >(pCcList->GetAt(index)); + SysTryCatch(NID_MSG, pItem != null, r = E_INVALID_ADDRESS, r, "To List Null"); + r = CheckAddressValidity(*pItem, type); + + + if (type == _MSG_MMS && r != E_SUCCESS) //Check If MMS might have email address + { + addressLen = pItem->GetLength(); + + // size check + if (addressLen < 5 || addressLen > MAX_LENGTH_EMAIL) // "a@a.a" + { + r = E_INVALID_ADDRESS; + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The length (%d) of email address is too short or too long.", addressLen); + goto CATCH; + } + + // check number of '@' char and '@' position + int pos = 0; + int posByLast = 0; + + r = pItem->IndexOf(L'@', 0, pos); + r = pItem->LastIndexOf(L'@', addressLen - 1, posByLast); + + if (pos <= 0 || pos != posByLast) + { + r = E_INVALID_ADDRESS; + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] There is not a @ character or there are multiple @ characters."); + goto CATCH; + } + } + + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] There is invalid phone number in CC list. Please check the RecipientList first.", + GetErrorMessage( + r)); + goto CATCH; + } + } + } + + // BCC + count = 0; // initialize the count value + pBccList = pRecipientList->GetListN(RECIPIENT_TYPE_BCC); + if (!pBccList) + { + r = GetLastResult(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to get BCC list.", GetErrorMessage(r)); + goto CATCH; + } + else + { + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in BCC list is not valid."); + SysLog( + NID_MSG, + "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_BCC) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS."); + r = E_INVALID_ADDRESS; + goto CATCH; + } + } + else + { + count = pBccList->GetCount(); + } + + if (count > 0) + { + for (index = 0; index < count; index++) + { + pItem = dynamic_cast< String* >(pBccList->GetAt(index)); + SysTryCatch(NID_MSG, pItem != null, r = E_INVALID_ADDRESS, r, "To List Null"); + r = CheckAddressValidity(*pItem, type); + + + if (type == _MSG_MMS && r != E_SUCCESS) //Check If MMS might have email address + { + addressLen = pItem->GetLength(); + + // size check + if (addressLen < 5 || addressLen > MAX_LENGTH_EMAIL) // "a@a.a" + { + r = E_INVALID_ADDRESS; + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The length (%d) of email address is too short or too long.", addressLen); + goto CATCH; + } + + // check number of '@' char and '@' position + int pos = 0; + int posByLast = 0; + + r = pItem->IndexOf(L'@', 0, pos); + r = pItem->LastIndexOf(L'@', addressLen - 1, posByLast); + + if (pos <= 0 || pos != posByLast) + { + r = E_INVALID_ADDRESS; + SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] There is not a @ character or there are multiple @ characters."); + goto CATCH; + } + } + + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] There is invalid phone number in BCC list. Please check the RecipientList first.", + GetErrorMessage( + r)); + goto CATCH; + } + } + } + + // free the memories + if (pToList) + { + if (pToList->GetCount() > 0) + { + pToList->RemoveAll(true); + } + delete pToList; + pToList = null; + } + if (pCcList) + { + if (pCcList->GetCount() > 0) + { + pCcList->RemoveAll(true); + } + delete pCcList; + pCcList = null; + } + if (pBccList) + { + if (pBccList->GetCount() > 0) + { + pBccList->RemoveAll(true); + } + delete pBccList; + pBccList = null; + } + + return E_SUCCESS; + +CATCH: + if (pToList) + { + if (pToList->GetCount() > 0) + { + pToList->RemoveAll(true); + } + delete pToList; + pToList = null; + } + if (pCcList) + { + if (pCcList->GetCount() > 0) + { + pCcList->RemoveAll(true); + } + delete pCcList; + pCcList = null; + } + if (pBccList) + { + if (pBccList->GetCount() > 0) + { + pBccList->RemoveAll(true); + } + delete pBccList; + pBccList = null; + } + + return r; +} + +bool +_MsgUtil::IsValidImageFile(const String& filePath) +{ + bool isValid = false; + + String delimiter(L";"); + String fileExtensionTable(L"jpg;jpeg;gif;png;bmp;wbmp;tif;tiff;swf;svg;svgz"); + String fileExtension = Tizen::Io::File::GetFileExtension(filePath); + Tizen::Base::Utility::StringTokenizer strTok(fileExtensionTable, delimiter); + String token; + + while (strTok.HasMoreTokens()) + { + strTok.GetNextToken(token); + if (token.Equals(fileExtension, false)) + { + isValid = true; + break; + } + } + + return isValid; +} + +bool +_MsgUtil::IsValidAudioFile(const String& filePath) +{ + bool isValid = false; + + String delimiter(L";"); + String fileExtensionTable(L"mid;midi;spm;imy;amr;mmf;xmf;mxmf;3gp;3gpp;mp4;asf;ra;ram;rv;rm;mp3;aac;wav;3ga;m4a;wma"); + String fileExtension = Tizen::Io::File::GetFileExtension(filePath); + Tizen::Base::Utility::StringTokenizer strTok(fileExtensionTable, delimiter); + String token; + + while (strTok.HasMoreTokens()) + { + strTok.GetNextToken(token); + if (token.Equals(fileExtension, false)) + { + isValid = true; + break; + } + } + + return isValid; +} + +bool +_MsgUtil::IsValidVideoFile(const String& filePath) +{ + + bool isValid = false; + + String delimiter(L";"); + String fileExtensionTable(L"3gp;3gpp;mp4;asf;wmv;ra;ram;rv;rm"); + String fileExtension = Tizen::Io::File::GetFileExtension(filePath); + Tizen::Base::Utility::StringTokenizer strTok(fileExtensionTable, delimiter); + String token; + + while (strTok.HasMoreTokens()) + { + strTok.GetNextToken(token); + if (token.Equals(fileExtension, false)) + { + isValid = true; + break; + } + } + + return isValid; +} + + +bool +_MsgUtil::IsValidVcardFile(const String& filePath) +{ + bool isValid = false; + String fileExtension = Tizen::Io::File::GetFileExtension(filePath); + + if (fileExtension.Equals(L"vcf", false)) + { + isValid = true; + } + + return isValid; +} + +bool +_MsgUtil::IsValidVcalendarFile(const String& filePath) +{ + bool isValid = false; + String fileExtension = Tizen::Io::File::GetFileExtension(filePath); + + if (fileExtension.Equals(L"vcs", false)) + { + isValid = true; + } + + return isValid; +} + +bool +_MsgUtil::CheckMediaFormat(const MmsAttachmentFormat format, const String& filePath) +{ + bool isValid = false; + switch (format) + { + case MMS_IMAGE: + isValid = IsValidImageFile(filePath); + break; + + case MMS_AUDIO: + isValid = IsValidAudioFile(filePath); + break; + + case MMS_VIDEO: + isValid = IsValidVideoFile(filePath); + break; + + case MMS_VCARD: + isValid = IsValidVcardFile(filePath); + break; + + case MMS_VCALENDAR: + isValid = IsValidVcalendarFile(filePath); + break; + + default: + break; + } + return isValid; +} + +bool +_MsgUtil::IsValidPhoneNumber(const Tizen::Base::String& phoneNumber) +{ + int length = 0; + + length = phoneNumber.GetLength(); + if (phoneNumber[0] == L'+') + { + length--; + } + + if (length < MIN_LENGTH_PHONE || length > MAX_LENGTH_PHONE) + { + SysLog(NID_MSG, "The length of the phone number (%d) is too short or too long.", length); + return false; + } + + for (int index = 0; index < length; index++) + { + if (phoneNumber[0] == L'+') + { + if (!Character::IsDigit(phoneNumber[index + 1])) + { + SysLog(NID_MSG, "The phone number contains a non-digit string."); + return false; + } + } + else + { + if (!Character::IsDigit(phoneNumber[index])) + { + SysLog(NID_MSG, "The phone number contains a non-digit string."); + return false; + } + } + } + + return true; +} + +SmsMessageBoxType +_MsgUtil::GetSmsMessageBoxType(_MSG_FOLDER_ID_E folderId) +{ + SmsMessageBoxType type = SMS_MESSAGE_BOX_TYPE_NONE; + switch (folderId) + { + case MSG_INBOX_ID: + type = SMS_MESSAGE_BOX_TYPE_INBOX; + break; + + case MSG_OUTBOX_ID: + type = SMS_MESSAGE_BOX_TYPE_OUTBOX; + break; + + case MSG_SENTBOX_ID: + type = SMS_MESSAGE_BOX_TYPE_SENTBOX; + break; + +// case MSG_ALLBOX_ID: +// type = SMS_MESSAGE_BOX_TYPE_ALL; +// break; + + default: + type = SMS_MESSAGE_BOX_TYPE_NONE; + break; + } + + return type; +} + +_MSG_FOLDER_ID_E +_MsgUtil::GetMsgFolderId(const SmsMessageBoxType& type) +{ + _MSG_FOLDER_ID_E folderId; + + switch (type) + { + case SMS_MESSAGE_BOX_TYPE_INBOX: + folderId = MSG_INBOX_ID; + break; + + case SMS_MESSAGE_BOX_TYPE_OUTBOX: + folderId = MSG_OUTBOX_ID; + break; + + case SMS_MESSAGE_BOX_TYPE_SENTBOX: + folderId = MSG_SENTBOX_ID; + break; + + case SMS_MESSAGE_BOX_TYPE_ALL: + folderId = MSG_ALLBOX_ID; + break; + + default: + folderId = MSG_MAX_FOLDER_ID; + break; + } + + return folderId; +} + +SmsMessageBoxType +_MsgUtil::GetMsgBoxType(const _MSG_FOLDER_ID_E& folderId) +{ + SmsMessageBoxType type; + + switch (folderId) + { + case MSG_INBOX_ID: + type = SMS_MESSAGE_BOX_TYPE_INBOX; + break; + + case MSG_OUTBOX_ID: + type = SMS_MESSAGE_BOX_TYPE_OUTBOX; + break; + + case MSG_SENTBOX_ID: + type = SMS_MESSAGE_BOX_TYPE_SENTBOX; + break; + + case MSG_ALLBOX_ID: + type = SMS_MESSAGE_BOX_TYPE_ALL; + break; + + default: + type = SMS_MESSAGE_BOX_TYPE_NONE; + break; + } + + return type; +} + +int +_MsgUtil::GetSmsMessage(msg_struct_t& msgInfo, const SmsMessage& message, const RecipientList& recipientList) +{ + int err = MSG_SUCCESS; + char* pMsgBody = null; + result r = E_SUCCESS; + + if (message.GetText().GetLength() == 0) + { + Tizen::Base::String emptyText(L" "); + pMsgBody = _StringConverter::CopyToCharArrayN(emptyText); + } + else + { + pMsgBody = _StringConverter::CopyToCharArrayN(message.GetText()); + } + + SysTryCatch(NID_MSG, pMsgBody != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + + err = msg_set_int_value(msgInfo, MSG_MESSAGE_TYPE_INT, MSG_TYPE_SMS); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Set Message Type error"); + + err = msg_set_str_value(msgInfo, MSG_MESSAGE_SMS_DATA_STR, pMsgBody, strlen(pMsgBody)); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Set Message body error"); + + err = AddMessageAddress(recipientList, RECIPIENT_TYPE_TO, msgInfo, MSG_RECIPIENTS_TYPE_TO); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Message add address error"); + + delete[] pMsgBody; + pMsgBody = null; + + return err; + +CATCH: + SetLastResult(r); + + if (pMsgBody) + { + delete[] pMsgBody; + pMsgBody = null; + } + + return err; +} + +int +_MsgUtil::GetMmsMessage(msg_struct_t& msgInfo, const MmsMessage& message, const RecipientList& recipientList) +{ + int err = MSG_SUCCESS; + result r = E_SUCCESS; + char* pSubject = null; + + pSubject = _StringConverter::CopyToCharArrayN(message.GetSubject()); + SysTryCatch(NID_MSG, pSubject != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + + //create new message + err = msg_set_int_value(msgInfo, MSG_MESSAGE_TYPE_INT, MSG_TYPE_MMS); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Set Message Type error"); + + err = msg_set_str_value(msgInfo, MSG_MESSAGE_SUBJECT_STR, pSubject, strlen(pSubject)); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Set Message body error"); + + err = AddMessageAddress(recipientList, RECIPIENT_TYPE_TO, msgInfo, MSG_RECIPIENTS_TYPE_TO); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "failed to add To address"); + + err = AddMessageAddress(recipientList, RECIPIENT_TYPE_CC, msgInfo, MSG_RECIPIENTS_TYPE_CC); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "failed to add Cc address"); + + err = AddMessageAddress(recipientList, RECIPIENT_TYPE_BCC, msgInfo, MSG_RECIPIENTS_TYPE_BCC); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "failed to add Bcc address"); + + err = PopulateMmsContent(message, msgInfo); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "failed to generate MMS message"); + + delete[] pSubject; + pSubject = null; + + return err; + +CATCH: + SetLastResult(r); + + if (pSubject) + { + delete[] pSubject; + pSubject = null; + } + + return err; +} + +int +_MsgUtil::PopulateMmsContent(const MmsMessage& message, msg_struct_t& msgData) +{ + int err = MSG_SUCCESS; + result r = E_SUCCESS; + String filePath; + char* pFilePath = null; + bool isImage = false; + bool isAudio = false; + bool isText = false; + + msg_struct_t mmsData = NULL; + msg_struct_t region = NULL; + msg_struct_t page = NULL; + msg_struct_t media = NULL; + msg_struct_t smilText = NULL; + msg_struct_t mmsAttach = NULL; + + //create a temp file for body text + Tizen::Base::String bodyText = message.GetText(); + Tizen::Base::String bodyTextFilePath(BODY_TEXT_FILE_NAME); + Tizen::Io::File file; + r = file.Construct(bodyTextFilePath, L"w+"); + err = MSG_ERR_MEMORY_ERROR; + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + mmsData = msg_create_struct(MSG_STRUCT_MMS); + + if (bodyText.GetLength()) + { + isText = true; + //write text to file + r = file.Write(bodyText); + err = MSG_ERR_MEMORY_ERROR; + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + } + + filePath = message.GetAttachment(MMS_IMAGE); + if (filePath.GetLength()) + { + isImage = true; + } + + filePath = message.GetAttachment(MMS_VIDEO); + if (filePath.GetLength()) + { + isImage = true; + } + + filePath = message.GetAttachment(MMS_AUDIO); + if (filePath.GetLength()) + { + isAudio = true; + } + + // Layout Setting + msg_set_int_value(mmsData, MSG_MMS_ROOTLAYOUT_WIDTH_INT, 100); + msg_set_int_value(mmsData, MSG_MMS_ROOTLAYOUT_HEIGHT_INT, 100); + msg_set_int_value(mmsData, MSG_MMS_ROOTLAYOUT_BGCOLOR_INT, 0xffffff); + msg_set_bool_value(mmsData, MSG_MMS_ROOTLAYOUT_WIDTH_PERCENT_BOOL, true); + msg_set_bool_value(mmsData, MSG_MMS_ROOTLAYOUT_HEIGHT_PERCENT_BOOL, true); + + if (!isImage) + { + msg_mms_add_item(mmsData, MSG_STRUCT_MMS_REGION, ®ion); + msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"Text", 4); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_LEFT_INT, 0); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_TOP_INT, 0); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_WIDTH_INT, 100); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, 100); + msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff); + } + else if (!isText) + { + msg_mms_add_item(mmsData, MSG_STRUCT_MMS_REGION, ®ion); + msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"Image", 5); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_LEFT_INT, 0); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_TOP_INT, 0); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_WIDTH_INT, 100); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, 100); + msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff); + } + else + { + msg_mms_add_item(mmsData, MSG_STRUCT_MMS_REGION, ®ion); + msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"Image", 5); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_LEFT_INT, 0); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_TOP_INT, 0); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_WIDTH_INT, 100); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, 50); + msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff); + + msg_mms_add_item(mmsData, MSG_STRUCT_MMS_REGION, ®ion); + msg_set_str_value(region, MSG_MMS_REGION_ID_STR, (char *)"Text", 4); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_LEFT_INT, 0); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_TOP_INT, 50); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_WIDTH_INT, 100); + msg_set_int_value(region, MSG_MMS_REGION_LENGTH_HEIGHT_INT, 50); + msg_set_int_value(region, MSG_MMS_REGION_BGCOLOR_INT, 0xffffff); + } + + // Add Media + msg_mms_add_item(mmsData, MSG_STRUCT_MMS_PAGE, &page); + msg_set_int_value(page, MSG_MMS_PAGE_PAGE_DURATION_INT, 5440); + + if (isImage) + { + filePath = message.GetAttachment(MMS_IMAGE); + if (filePath.GetLength()) + { + pFilePath = _StringConverter::CopyToCharArrayN(filePath); + err = MSG_ERR_MEMORY_ERROR; + SysTryCatch(NID_MSG, pFilePath != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); + msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_IMG); + msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, (char *)"Image", 5); + msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, pFilePath, MSG_FILEPATH_LEN_MAX); + + delete[] pFilePath; + pFilePath = null; + } + + filePath = message.GetAttachment(MMS_VIDEO); + if (filePath.GetLength()) + { + pFilePath = _StringConverter::CopyToCharArrayN(filePath); + err = MSG_ERR_MEMORY_ERROR; + SysTryCatch(NID_MSG, pFilePath != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); + msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_VIDEO); + msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, (char *)"Image", 5); + msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, pFilePath, MSG_FILEPATH_LEN_MAX); + + delete[] pFilePath; + pFilePath = null; + } + } + + if (isAudio) + { + filePath = message.GetAttachment(MMS_AUDIO); + if (filePath.GetLength()) + { + pFilePath = _StringConverter::CopyToCharArrayN(filePath); + err = MSG_ERR_MEMORY_ERROR; + SysTryCatch(NID_MSG, pFilePath != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); + msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_AUDIO); + msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, (char *)"Audio", 5); + msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, pFilePath, MSG_FILEPATH_LEN_MAX); + + delete[] pFilePath; + pFilePath = null; + } + } + + if (isText) + { + pFilePath = _StringConverter::CopyToCharArrayN(bodyTextFilePath); + err = MSG_ERR_MEMORY_ERROR; + SysTryCatch(NID_MSG, pFilePath != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + + msg_mms_add_item(page, MSG_STRUCT_MMS_MEDIA, &media); + msg_set_int_value(media, MSG_MMS_MEDIA_TYPE_INT, MMS_SMIL_MEDIA_TEXT); + msg_set_str_value(media, MSG_MMS_MEDIA_REGION_ID_STR, (char *)"Text", 4); + msg_set_str_value(media, MSG_MMS_MEDIA_FILEPATH_STR, pFilePath, MSG_FILEPATH_LEN_MAX); + + msg_get_struct_handle(media, MSG_MMS_MEDIA_SMIL_TEXT_HND, &smilText); + msg_set_int_value(smilText, MSG_MMS_SMIL_TEXT_COLOR_INT, 0x000000); + msg_set_int_value(smilText, MSG_MMS_SMIL_TEXT_SIZE_INT, MMS_SMIL_FONT_SIZE_NORMAL); + msg_set_bool_value(smilText, MSG_MMS_SMIL_TEXT_BOLD_BOOL, false); + + delete[] pFilePath; + pFilePath = null; + } + + //vcard attachment + filePath = message.GetAttachment(MMS_VCARD); + if (filePath.GetLength()) + { + pFilePath = _StringConverter::CopyToCharArrayN(filePath); + err = MSG_ERR_MEMORY_ERROR; + SysTryCatch(NID_MSG, pFilePath != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + msg_mms_add_item(mmsData, MSG_STRUCT_MMS_ATTACH, &mmsAttach); + msg_set_str_value(mmsAttach, MSG_MMS_ATTACH_FILEPATH_STR, pFilePath, MSG_FILEPATH_LEN_MAX); + delete[] pFilePath; + pFilePath = null; + } + + //calander attachment + filePath = message.GetAttachment(MMS_VCALENDAR); + if (filePath.GetLength()) + { + pFilePath = _StringConverter::CopyToCharArrayN(filePath); + err = MSG_ERR_MEMORY_ERROR; + SysTryCatch(NID_MSG, pFilePath != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + msg_mms_add_item(mmsData, MSG_STRUCT_MMS_ATTACH, &mmsAttach); + msg_set_str_value(mmsAttach, MSG_MMS_ATTACH_FILEPATH_STR, pFilePath, MSG_FILEPATH_LEN_MAX); + delete[] pFilePath; + pFilePath = null; + } + + err = msg_set_mms_struct(msgData, mmsData); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "failed to set message contents"); + + msg_release_struct(&mmsData); + return err; + +CATCH: + if (mmsData) + { + msg_release_struct(&mmsData); + } + return err; +} + +result +_MsgUtil::AddEmailMessageAddress(const RecipientList& recipientList, RecipientType type, email_mail_data_t *pMail) +{ + String tempRecipient = null; + IList* pRecipientList = null; + int count = 0; + int index = 0; + const int zero = 0; + String *pRecipient = null; + result r = E_SUCCESS; + + pRecipientList = (const_cast< RecipientList& >(recipientList)).GetListN(type); + SysTryCatch(NID_MSG, pRecipientList != null, r = GetLastResult(), r, "[%s] Failed to get recipient list", GetErrorMessage(r)); + + count = pRecipientList->GetCount(); + SysTryCatch(NID_MSG, count != zero, r = E_SUCCESS , r, "Type[%d] Recipient is empty",type); + + pRecipient = dynamic_cast< String* >(pRecipientList->GetAt(index)); + SysTryCatch(NID_MSG, pRecipient != null, r = GetLastResult(), r, "[%s] Failed to get recipient", GetErrorMessage(r)); + + tempRecipient.Append(L"<" + *(pRecipient) + L">"); + index++; + + for (; index < count; index++) + { + pRecipient = dynamic_cast< String* >(pRecipientList->GetAt(index)); + SysTryCatch(NID_MSG, pRecipient != null, r = GetLastResult(), r, "[%s] Failed to get recipient", GetErrorMessage(r)); + tempRecipient.Append(L";<" + *pRecipient + L">"); + + } + if(RECIPIENT_TYPE_TO == type) + { + pMail->full_address_to = _StringConverter::CopyToCharArrayN(tempRecipient); + } + else if(RECIPIENT_TYPE_CC == type) + { + pMail->full_address_cc = _StringConverter::CopyToCharArrayN(tempRecipient); + + } + else if( RECIPIENT_TYPE_BCC == type) + { + pMail->full_address_bcc = _StringConverter::CopyToCharArrayN(tempRecipient); + } + else + { + SysLog(NID_MSG, "[%d] Wrong recipeint type", type); + r = E_INVALID_ARG; + goto CATCH; + } + + if (pRecipientList->GetCount() > 0) + { + pRecipientList->RemoveAll(true); + } + delete pRecipientList; + pRecipientList = null; + + return r; + +CATCH: + if (pRecipientList->GetCount() > 0) + { + pRecipientList->RemoveAll(true); + } + delete pRecipientList; + pRecipientList = null; + + return r; + +} + +int +_MsgUtil::AddMessageAddress(const RecipientList& recipientList, RecipientType type, msg_struct_t& messageMsg, _MSG_RECIPIENT_TYPE_E recipientType) +{ + String* pTempRecipient = null; + IList* pRecipientList = null; + char* pPhoneNum = null; + int count = 0; + int msgType = -1; + int err = MSG_SUCCESS; + result r = E_SUCCESS; + + pRecipientList = (const_cast< RecipientList& >(recipientList)).GetListN(type); + if (!pRecipientList) + { + r = GetLastResult(); + SysLogException(NID_MSG, r, "[%s] Failed to get recipient list", GetErrorMessage(r)); + goto CATCH; + } + + err = msg_get_int_value(messageMsg, MSG_MESSAGE_TYPE_INT, &msgType); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "failed to get message type"); + + count = pRecipientList->GetCount(); + for (int index = 0; index < count; index++) + { + pTempRecipient = dynamic_cast< String* >(pRecipientList->GetAt(index)); + if (!pTempRecipient) + { + r = GetLastResult(); + err = MSG_ERR_NULL_POINTER; + SysLogException(NID_MSG, r, "[%s] Failed to get a recipient", GetErrorMessage(r)); + goto CATCH; + } + + pPhoneNum = _StringConverter::CopyToCharArrayN(*pTempRecipient); + SysTryCatch(NID_MSG, pPhoneNum != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed."); + + msg_struct_list_s *pAddrList = NULL; + msg_struct_t addrInfo = NULL; + + err = msg_get_list_handle(messageMsg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&pAddrList); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "failed to get message address handle"); + + addrInfo = pAddrList->msg_struct_info[pAddrList->nCount]; + + if (msgType == MSG_TYPE_SMS) + { + msg_set_int_value(addrInfo, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, recipientType); + } + else if (msgType == MSG_TYPE_MMS) + { + if (strchr(pPhoneNum, '@') == NULL) + { + msg_set_int_value(addrInfo, MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_PLMN); + } + else + { + msg_set_int_value(addrInfo, MSG_ADDRESS_INFO_ADDRESS_TYPE_INT, MSG_ADDRESS_TYPE_EMAIL); + } + msg_set_int_value(addrInfo, MSG_ADDRESS_INFO_RECIPIENT_TYPE_INT, recipientType); + } + + err = msg_set_str_value(addrInfo, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, pPhoneNum, strlen(pPhoneNum)); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, E_SYSTEM, "failed to set message address"); + + pAddrList->nCount++; + + delete[] pPhoneNum; + pPhoneNum = null; + } + + // deallocate + if (pRecipientList->GetCount() > 0) + { + pRecipientList->RemoveAll(true); + } + delete pRecipientList; + pRecipientList = null; + + return err; + +CATCH: + SetLastResult(r); + if (pRecipientList) + { + if (pRecipientList->GetCount() > 0) + { + pRecipientList->RemoveAll(true); + } + delete pRecipientList; + pRecipientList = null; + } + + if (pPhoneNum) + { + delete[] pPhoneNum; + pPhoneNum = null; + } + return err; +} + +Tizen::Base::String +_MsgUtil::GetConcatenatedRecipientListString(const RecipientList& recipientList, RecipientType type, + const Tizen::Base::String& delim) +{ + String concatenatedString; + String* pTempRecipient = null; + IList* pRecipientList = null; + int count = 0; + result r = E_SUCCESS; + + ClearLastResult(); + + pRecipientList = (const_cast< RecipientList& >(recipientList)).GetListN(type); + if (!pRecipientList) + { + r = GetLastResult(); + SysLogException(NID_MSG, r, "[%s] Failed to get recipient list", GetErrorMessage(r)); + goto CATCH; + } + + concatenatedString.Clear(); + + count = pRecipientList->GetCount(); + for (int index = 0; index < count; index++) + { + pTempRecipient = dynamic_cast< String* >(pRecipientList->GetAt(index)); + if (!pTempRecipient) + { + r = GetLastResult(); + SysLogException(NID_MSG, r, "[%s] Failed to get a recipient", GetErrorMessage(r)); + goto CATCH; + } + + concatenatedString.Append(*pTempRecipient); + if (index < count - 1) + { + concatenatedString.Append(delim); + } + } + + // deallocate + if (pRecipientList->GetCount() > 0) + { + pRecipientList->RemoveAll(true); + } + delete pRecipientList; + pRecipientList = null; + + return concatenatedString; + +CATCH: + SetLastResult(r); + // deallocate + if (pRecipientList) + { + if (pRecipientList->GetCount() > 0) + { + pRecipientList->RemoveAll(true); + } + delete pRecipientList; + pRecipientList = null; + } + + return concatenatedString; +} + +Tizen::Base::DateTime +_MsgUtil::ConvertTime(time_t* pTime) +{ + DateTime dateTime; + struct tm* pTempTime = null; + + pTempTime = gmtime(pTime); + if (pTempTime) + { + dateTime.SetValue(pTempTime->tm_year + 1900, pTempTime->tm_mon + 1, pTempTime->tm_mday, pTempTime->tm_hour, pTempTime->tm_min, pTempTime->tm_sec); + } + return dateTime; +} + +SmsMessage* +_MsgUtil::ConvertSmsMessageN(const SmsMessageBoxType& type, msg_struct_t& msg) +{ + result r = E_SUCCESS; + int err = MSG_SUCCESS; + SmsMessage* pSmsMessage = null; + DateTime time; + int msgTime = -1; + bool hasMoreText = false; + int messageId; + String body; + const int msgBodyLength = 160; + int originalTextLength = 0; + + pSmsMessage = new (std::nothrow) SmsMessage(); + SysTryCatch(NID_MSG, pSmsMessage != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + // message ID + err = msg_get_int_value(msg, MSG_MESSAGE_ID_INT, &messageId); + + // body text + char msgText[MAX_MSG_TEXT_LEN]; + err = msg_get_str_value(msg, MSG_MESSAGE_SMS_DATA_STR, msgText, MAX_MSG_TEXT_LEN); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, r, "sms get message body failed"); + + originalTextLength = strlen(msgText); + if (originalTextLength > msgBodyLength) + { + char msgBodyText[msgBodyLength + 1]; + memset(msgText, 0, msgBodyLength + 1); + strncpy(msgBodyText, msgText, msgBodyLength); + body = msgBodyText; + hasMoreText = true; + } + else + { + body = msgText; + } + + // received/sent time + err = msg_get_int_value(msg, MSG_MESSAGE_DISPLAY_TIME_INT, &msgTime); + time = _MsgUtil::ConvertTime((time_t*) &msgTime); + + switch (type) + { + case SMS_MESSAGE_BOX_TYPE_INBOX: + { + // sender address + char address[MAX_ADDRESS_VAL_LEN] = {0, }; + msg_struct_list_s* pAddrList = NULL; + msg_struct_t addrInfo = NULL; + err = msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&pAddrList); + addrInfo = pAddrList->msg_struct_info[0]; + err = msg_get_str_value(addrInfo, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, address, MAX_ADDRESS_VAL_LEN); + String senderAddress(address); + + _SmsMessageImpl::GetInstance(*pSmsMessage)->SetInboxMessage(messageId, body, hasMoreText, senderAddress, time); + break; + } + + case SMS_MESSAGE_BOX_TYPE_SENTBOX: + { + // recipient list + char address[MAX_ADDRESS_VAL_LEN] = {0, }; + msg_struct_list_s* pAddrList = NULL; + msg_struct_t addrInfo = NULL; + err = msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&pAddrList); + addrInfo = pAddrList->msg_struct_info[0]; + int recipient_count = pAddrList->nCount; + RecipientList recipients; + + for (int index = 0; index < recipient_count; index++) + { + addrInfo = pAddrList->msg_struct_info[index]; + err = msg_get_str_value(addrInfo, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, address, MAX_ADDRESS_VAL_LEN); + String senderAddress(address); + r = recipients.Add(RECIPIENT_TYPE_TO, senderAddress); + } + + _SmsMessageImpl::GetInstance(*pSmsMessage)->SetSentboxMessage(messageId, body, hasMoreText, recipients, time); + break; + } + + case SMS_MESSAGE_BOX_TYPE_OUTBOX: + { + // recipient list + char address[MAX_ADDRESS_VAL_LEN] = {0, }; + msg_struct_list_s* pAddrList = NULL; + msg_struct_t addrInfo = NULL; + err = msg_get_list_handle(msg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&pAddrList); + addrInfo = pAddrList->msg_struct_info[0]; + int recipient_count = pAddrList->nCount; + RecipientList recipients; + + for (int index = 0; index < recipient_count; index++) + { + addrInfo = pAddrList->msg_struct_info[index]; + err = msg_get_str_value(addrInfo, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, address, MAX_ADDRESS_VAL_LEN); + String senderAddress(address); + } + + _SmsMessageImpl::GetInstance(*pSmsMessage)->SetOutboxMessage(messageId, body, hasMoreText, recipients, time); + break; + } + + default: + break; + } + + return pSmsMessage; + +CATCH: + if (pSmsMessage) + { + delete pSmsMessage; + } + + return NULL; +} +result +_MsgUtil::SendEmail(const EmailMessage& message, const RecipientList& recipientList, int &mailId, int &requestId, bool saveToSentBox) +{ + + email_account_t* pAccount = NULL; + email_mail_data_t *pMail = null; + email_mailbox_t *pMailbox = null; + email_attachment_data_t **pAttach=null; + int tmpSaveToSentBox = -1; + int accountId = 0; + int err = EMAIL_ERROR_NONE; + result r = E_SUCCESS; + String fromAddr; + + email_service_begin(); + + pMail = (email_mail_data_t *)calloc(1,sizeof(email_mail_data_t)); + SysTryCatch(NID_MSG, pMail != null, r = E_OUT_OF_MEMORY, r, "Insufficient memory"); + + pMailbox = (email_mailbox_t *)calloc(1,sizeof(email_mailbox_t)); + SysTryCatch(NID_MSG, pMailbox != null, r = E_OUT_OF_MEMORY, r, "Insufficient memory"); + + err = email_load_default_account_id(&accountId); + SysTryCatch(NID_MSG, err == EMAIL_ERROR_NONE, r = E_INVALID_ACCOUNT, r, "Account Load is Failed."); + + err = email_get_account(accountId, GET_FULL_DATA, &pAccount); + SysTryCatch(NID_MSG, err == EMAIL_ERROR_NONE, r = E_INVALID_ACCOUNT, r, "Account is Failed."); + SysLog(NID_MSG, "keep %d, save %d" , pAccount->options.keep_local_copy, saveToSentBox); + + tmpSaveToSentBox = pAccount->options.keep_local_copy; + pAccount->options.keep_local_copy = saveToSentBox; + + email_update_account(accountId, pAccount); + SysTryCatch(NID_MSG, err == EMAIL_ERROR_NONE, r = E_INVALID_ACCOUNT, r, "Account update is Failed."); + + fromAddr.Append(L'\"'); + fromAddr.Append(pAccount->incoming_server_user_name); + fromAddr.Append(L"\"<"); + fromAddr.Append(pAccount->user_email_address); + fromAddr.Append(L'>'); + pMail->full_address_from = _StringConverter::CopyToCharArrayN(fromAddr); + + err = email_get_mailbox_by_mailbox_type(accountId, EMAIL_MAILBOX_TYPE_OUTBOX, &pMailbox); + SysTryCatch(NID_MSG, err == EMAIL_ERROR_NONE, r = E_STORAGE_FULL, r, "To get the info of mailbox data is failed."); + + //info + pMail->account_id = pAccount->account_id; + pMail->flags_draft_field = 1; + pMail->flags_seen_field = 1; + pMail->priority = EMAIL_MAIL_PRIORITY_NORMAL; + pMail->mailbox_id = pMailbox->mailbox_id; + pMail->mailbox_type = pMailbox->mailbox_type; + pMail->attachment_count = 0; + pMail->subject = _StringConverter::CopyToCharArrayN(message.GetSubject()); + + r = AddEmailMessageBody(pMail,_StringConverter::CopyToCharArrayN(message.GetText())); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] email add body failed", GetErrorMessage(r)); + r = AddEmailMessageAddress(recipientList, RECIPIENT_TYPE_TO, pMail); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] email add recipient failed", GetErrorMessage(r)); + r = AddEmailMessageAddress(recipientList, RECIPIENT_TYPE_CC, pMail); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] email add recipient failed", GetErrorMessage(r)); + r = AddEmailMessageAddress(recipientList, RECIPIENT_TYPE_BCC, pMail); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] email add recipient failed", GetErrorMessage(r)); + + + r = AddEmailMessageAttachment(message, &pAttach, pMail); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] email add recipient failed", GetErrorMessage(r)); + + + if( null != pAttach) + { + err=email_add_mail(pMail,*pAttach, pMail->attachment_count, NULL, 0); + } + else + { + err=email_add_mail(pMail,null, pMail->attachment_count, NULL, 0); + } + + r = _MsgUtil::EmailConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] To make email body is failed.", GetErrorMessage(r)); + + err = email_send_mail(pMail->mail_id, &requestId); + r = _MsgUtil::EmailConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] The sent mail is failed.", GetErrorMessage(r)); + + mailId = pMail->mail_id; + + r = AddEmailCallBackToDbus(); + + if (-1 != tmpSaveToSentBox) + { + pAccount->options.keep_local_copy = (bool)tmpSaveToSentBox; + email_update_account(accountId, pAccount); + } + + + if (pAttach) + { + if (*pAttach) + { + for(int i=0 ; i < pMail->attachment_count ; i++) + { + if(pAttach[i]) + { + if(pAttach[i]->attachment_name) + { + free(pAttach[i]->attachment_name); + } + if(pAttach[i]->attachment_path) + { + free(pAttach[i]->attachment_path); + } + } + + } + free(*pAttach); + } + free( pAttach); + + } + email_free_mail_data(&pMail, 1); + email_free_mailbox(&pMailbox, 1); + email_free_account(&pAccount, 1); + email_service_end(); + return r; + +CATCH: + + if (-1 != tmpSaveToSentBox) + { + pAccount->options.keep_local_copy = (bool)tmpSaveToSentBox; + email_update_account(accountId, pAccount); + } + + + if (pAttach) + { + if (*pAttach) + { + for(int i=0 ; i < pMail->attachment_count ; i++) + { + if(pAttach[i]) + { + if(pAttach[i]->attachment_name) + { + free(pAttach[i]->attachment_name); + } + if(pAttach[i]->attachment_path) + { + free(pAttach[i]->attachment_path); + } + } + + } + free(*pAttach); + } + free( pAttach); + } + email_free_mail_data(&pMail, 1); + email_free_mailbox(&pMailbox, 1); + email_free_account(&pAccount, 1); + email_service_end(); + return r; +} + +result +_MsgUtil::AddEmailMessageBody(email_mail_data_t *pMail, char * pBody) +{ + + String fileName(L"/opt/usr/media/mail.txt"); + File file; + result r = E_SUCCESS; + int bodyLen = 0; + r = file.Construct(fileName, L"w"); + if(IsFailed(r)) + { + return E_STORAGE_FULL; + + } + if (pBody) + { + bodyLen = strlen(pBody); + if (bodyLen) + { + r = file.Write(pBody, bodyLen); + if(IsFailed(r)) + { + return E_STORAGE_FULL; + } + } + } + + pMail->file_path_plain = _StringConverter::CopyToCharArrayN(fileName); + + return E_SUCCESS; + +} + +result +_MsgUtil::AddEmailMessageAttachment(const EmailMessage& message, email_attachment_data_t ***pAttach, email_mail_data_t *pMail) +{ + Tizen::Base::Collection::IList* pAttachmentList = null; + result r = E_SUCCESS; + int attachNum = 0 ; + email_attachment_data_t *getMemory=null; + + SysTryCatch(NID_MSG, pAttach != null, r = E_OUT_OF_MEMORY, r, "Insufficient memory"); + + pAttachmentList = message.GetAttachmentListN(); + SysTryCatch(NID_MSG, null != pAttachmentList, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] email add attachment failed"); + + attachNum = pAttachmentList->GetCount(); + SysTryCatch(NID_MSG, attachNum > 0, r = E_SUCCESS, E_SUCCESS, "email attachment file does not exist."); + + + (*pAttach) = (email_attachment_data_t **)calloc( attachNum,sizeof(email_attachment_data_t*)); + SysTryCatch(NID_MSG, *pAttach != null, r = E_OUT_OF_MEMORY, r, "Insufficient memory"); + + getMemory = (email_attachment_data_t *)calloc(attachNum,sizeof(email_attachment_data_t)); + SysTryCatch(NID_MSG, getMemory != null, r = E_OUT_OF_MEMORY, r, "Insufficient memory"); + + for( int index = 0; index < attachNum ; index ++) + { + int startIndex = 0; + int findIndex = 0; + String* pAttachPath = null; + String tempString = null; + File file; + FileAttributes attr; + + pAttachPath = dynamic_cast< String* >(pAttachmentList->GetAt(index)); + SysTryCatch(NID_MSG, pAttachPath != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] email add attachment failed"); + + startIndex = pAttachPath->GetLength()-1; + if( E_SUCCESS == pAttachPath->LastIndexOf( L"/", startIndex, findIndex)) + { + pAttachPath->SubString(findIndex+1, tempString); + } + else + { + tempString = *pAttachPath; + } + + (*pAttach)[index] = getMemory + index; + memset((*pAttach)[index], 0 , sizeof(email_attachment_data_t)); + + r = File::GetAttributes(*pAttachPath, attr); + SysTryCatch(NID_MSG, r == E_SUCCESS , r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] email add attachment failed"); + + (*pAttach)[index]->attachment_name = _StringConverter::CopyToCharArrayN(tempString); + (*pAttach)[index]->attachment_path = _StringConverter::CopyToCharArrayN(*pAttachPath); + (*pAttach)[index]->attachment_size = attr.GetFileSize(); + (*pAttach)[index]->save_status = 1; + pMail->attachment_count = index+1; + } + + if (pAttachmentList->GetCount() > 0) + { + pAttachmentList->RemoveAll(true); + } + delete pAttachmentList; + pAttachmentList = null; + + return r; + +CATCH: + + if (pAttachmentList) + { + if (pAttachmentList->GetCount() > 0) + { + pAttachmentList->RemoveAll(true); + } + delete pAttachmentList; + pAttachmentList = null; + } + + return r; + +} + +result +_MsgUtil::AddEmailCallBackToDbus(void) +{ + DBusConnection* pConnection=NULL; + DBusError error = {0}; + result r = E_SUCCESS; + static bool registerDbus = false; + + SysTryCatch(NID_MSG, false == registerDbus ,, E_SUCCESS, "Dbus was already registered"); + + dbus_error_init(&error); + + pConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error); + SysTryCatch(NID_MSG, pConnection != null, r = E_STORAGE_FULL, r, "dbus handler is null"); + + dbus_connection_setup_with_g_main(pConnection, null); + dbus_bus_add_match(pConnection, "path='/User/Email/NetworkStatus',type='signal',interface='User.Email.NetworkStatus'", &error); + SysTryCatch(NID_MSG, !dbus_error_is_set(&error) ,dbus_error_free(&error);r = E_STORAGE_FULL, E_STORAGE_FULL, "[E_STORAGE_FULL] Fail to add match : %s",error.message); + SysTryCatch(NID_MSG, FALSE != dbus_connection_add_filter(pConnection, EmailNetworkCallBack, NULL, NULL) ,dbus_error_free(&error);r = E_STORAGE_FULL, E_STORAGE_FULL, "[E_STORAGE_FULL] Fail to add match : %s",error.message); + + if (false == registerDbus) + { + registerDbus = true; + SysLog(NID_MSG, "Now. Dbus was registered"); + + } + + + return r; + +CATCH: + + return r; + +} + +DBusHandlerResult +_MsgUtil::EmailNetworkCallBack(DBusConnection* pConnection, DBusMessage* pMessage, void* pUserData) +{ + DBusError error ={0}; + + if(dbus_message_is_signal(pMessage, "User.Email.NetworkStatus", "email")) + { + dbus_error_init(&error); + int status=0; + int accountId=0; + char* fileId=NULL; + int mailId=0; + int errorCode=0; + unsigned int checkDbus; + checkDbus = dbus_message_get_args(pMessage, &error, + DBUS_TYPE_INT32, &status, + DBUS_TYPE_INT32, &accountId, + DBUS_TYPE_STRING, &fileId, + DBUS_TYPE_INT32, &mailId, + DBUS_TYPE_INT32, &errorCode, + DBUS_TYPE_INVALID); + SysLog(NID_MSG, "Dbus status [%d], msg [%d], err [%d]",status, mailId, errorCode); + + if(checkDbus) + { + switch (status) { + case NOTI_SEND_START: + break; + + case NOTI_SEND_FAIL: + + switch(errorCode) + { + case EMAIL_ERROR_NO_SIM_INSERTED: + case EMAIL_ERROR_FLIGHT_MODE: + case EMAIL_ERROR_SMTP_SEND_FAILURE: + case EMAIL_ERROR_NO_SUCH_HOST: + case EMAIL_ERROR_CONNECTION_FAILURE: + case EMAIL_ERROR_CONNECTION_BROKEN: + case EMAIL_ERROR_INVALID_SERVER: + case EMAIL_ERROR_NO_RESPONSE: + + break; + + default: + break; + } + _EmailManagerImpl::SentEmailStatusCallback(mailId, (email_noti_on_network_event)status, errorCode); + return DBUS_HANDLER_RESULT_HANDLED; + break; + + case NOTI_SEND_FINISH: + _EmailManagerImpl::SentEmailStatusCallback(mailId, (email_noti_on_network_event)status, errorCode); + return DBUS_HANDLER_RESULT_HANDLED; + break; + + default: + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + + } + } + else + { + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + + } + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + +} + +result +_MsgUtil::EmailConvertException(int err) +{ + result r = E_SUCCESS; + SysLog(NID_MSG,"Core Error [%d]", err); + + switch (err) + { + case EMAIL_ERROR_NONE: + r = E_SUCCESS; + break; + + case EMAIL_ERROR_INVALID_PARAM: + r = E_INVALID_ARG; + break; + + + case EMAIL_ERROR_INVALID_ACCOUNT: + case EMAIL_ERROR_ACCOUNT_NOT_FOUND: + r = E_INVALID_ACCOUNT; + break; + + case EMAIL_ERROR_NULL_VALUE: + case EMAIL_ERROR_IPC_SOCKET_FAILURE: + r = E_ON_INITIALIZING; + break; + + case EMAIL_ERROR_DB_FAILURE: + case EMAIL_ERROR_OUT_OF_MEMORY: + case EMAIL_ERROR_MAIL_MEMORY_FULL: + r = E_STORAGE_FULL; + break; + + default: + r = E_INVALID_CONDITION; + break; + } + + return r; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_MsgUtil.h b/src/FMsg_MsgUtil.h new file mode 100644 index 0000000..0a201f3 --- /dev/null +++ b/src/FMsg_MsgUtil.h @@ -0,0 +1,83 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MsgUtil.h + * @brief This is the header file for _MsgUtil class. + * + * This header file contains declarations of _MsgUtil class. + */ + +#ifndef _FMSG_INTERNAL_UTIL_H_ +#define _FMSG_INTERNAL_UTIL_H_ + +// Includes +#include +#include "FMsg_Types.h" + + +namespace Tizen { namespace Messaging +{ + +// forward declaration +class RecipientList; +class SmsMessage; +class MmsMessage; +class EmailMessage; + +/** +* @class _MsgUtil +* @brief This class defines utility functions for Messaging namespace. +*/ +class _MsgUtil +{ +public: + static result CheckAddressValidity(const Tizen::Base::String& address, _MessageType type); + static result CheckEmailAddressValidity(const RecipientList& recipientList); + static result CheckPhoneNumberValidity(_MessageType type, const RecipientList& recipientList); + static bool CheckMediaFormat(const MmsAttachmentFormat format, const Tizen::Base::String& filePath); + static bool IsValidImageFile(const Tizen::Base::String& filePath); + static bool IsValidAudioFile(const Tizen::Base::String& filePath); + static bool IsValidVideoFile(const Tizen::Base::String& filePath); + static bool IsValidVcardFile(const Tizen::Base::String& filePath); + static bool IsValidVcalendarFile(const Tizen::Base::String& filePath); + static bool IsValidPhoneNumber(const Tizen::Base::String& phoneNumber); + static SmsMessageBoxType GetSmsMessageBoxType(_MSG_FOLDER_ID_E folderId); + static _MSG_FOLDER_ID_E GetMsgFolderId(const SmsMessageBoxType& type); + static SmsMessageBoxType GetMsgBoxType(const _MSG_FOLDER_ID_E& folderId); + static int GetSmsMessage(msg_struct_t& msgInfo, const SmsMessage& message, const RecipientList& recipientList); + static Tizen::Base::String GetConcatenatedRecipientListString(const RecipientList& recipientList, RecipientType type, const Tizen::Base::String& delim); + static int GetMmsMessage(msg_struct_t& msgInfo, const MmsMessage& message, const RecipientList& recipientList); + static int PopulateMmsContent(const MmsMessage& message, msg_struct_t& msgData); + static Tizen::Base::DateTime ConvertTime(time_t* pTime); + static SmsMessage* ConvertSmsMessageN(const SmsMessageBoxType& type, msg_struct_t& msg); + static int AddMessageAddress(const RecipientList& recipientList, RecipientType type, msg_struct_t& messageMsg, _MSG_RECIPIENT_TYPE_E recipientType); + static result AddEmailMessageAddress(const RecipientList& recipientList, RecipientType type, email_mail_data_t *pMail); + static result SendEmail(const EmailMessage& message, const RecipientList& recipientList, int &mailboxId, int &requestId, bool saveToSentBox); + static result AddEmailMessageBody(email_mail_data_t *pMail, char * pBody); + static result AddEmailMessageAttachment(const EmailMessage& message, email_attachment_data_t ***pAttach, email_mail_data_t *pMail); + static result AddEmailCallBackToDbus(void); + static DBusHandlerResult EmailNetworkCallBack(DBusConnection* pConnection, DBusMessage* pMessage, void* pUserData); + static result EmailConvertException(int err); + +private: + _MsgUtil(void); + virtual ~_MsgUtil(void) {}; + _MsgUtil(const _MsgUtil& value); + _MsgUtil& operator =(const _MsgUtil& rhs); +}; // _MsgUtil +} } +#endif //_FMSG_INTERNAL_UTIL_H_ diff --git a/src/FMsg_PushEvent.cpp b/src/FMsg_PushEvent.cpp new file mode 100644 index 0000000..2282d8a --- /dev/null +++ b/src/FMsg_PushEvent.cpp @@ -0,0 +1,75 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushEvent.cpp + * @brief This is the implementation file for _PushEvent class. + * @version 3.0 + * + * This file contains the implementation of _PushEvent class. + */ + +// Includes +#include +#include "FMsg_PushManagerImpl.h" +#include "FMsg_PushEvent.h" +#include "FMsg_PushEventArg.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Runtime; + +namespace Tizen { namespace Messaging +{ + +_PushEvent::_PushEvent(_PushManagerImpl* pPushManager) + : __pPushManager(pPushManager) +{ + _Event::Initialize(); +} + +_PushEvent::~_PushEvent(void) +{ + __pPushManager = null; +} + +_PushManagerImpl* +_PushEvent::GetPushManager(void) const +{ + return __pPushManager; +} + +void +_PushEvent::FireImpl(IEventListener& listener, const IEventArg& arg) +{ + SysLog(NID_MSG, "Enter."); + + IEventArg* pEventArg = null; + _PushEventArg* pPushEventArg = null; + + pEventArg = const_cast (&arg); + pPushEventArg = dynamic_cast <_PushEventArg*>(pEventArg); + + if ((__pPushManager != null) && (pPushEventArg != null)) + { + __pPushManager->HandlePushEvent(*pPushEventArg); + } + + SysLog(NID_MSG, "Exit."); + + return; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_PushEvent.h b/src/FMsg_PushEvent.h new file mode 100644 index 0000000..1952c2a --- /dev/null +++ b/src/FMsg_PushEvent.h @@ -0,0 +1,68 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushEvent.h + * @brief This is the header file for _PushEvent class. + * @version 3.0 + * + * This header file contains the declarations of _PushEvent class. + * The _PushEvent class can call listener's method. So, when an event is occured, + * application can handle it appropriately. + */ + +#ifndef _FMSG_INTERNAL_PUSH_EVENT_H_ +#define _FMSG_INTERNAL_PUSH_EVENT_H_ + +#include +#include + +namespace Tizen { namespace Base { namespace Runtime +{ +class IEventListener; +class IEventArg; +} } } // Tizen::Base::Runtime + +namespace Tizen { namespace Messaging +{ + +class _PushManagerImpl; + +class _PushEvent + : public Tizen::Base::Runtime::_Event +{ +public: + _PushEvent(_PushManagerImpl* pPushManager); + virtual ~_PushEvent(void); + +public: + _PushManagerImpl* GetPushManager(void) const; + +protected: + virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg); + +private: + _PushEvent(void); + _PushEvent(const _PushEvent& rhs); + _PushEvent& operator =(const _PushEvent& rhs); + +private: + _PushManagerImpl* __pPushManager; + +}; // _PushEvent + +} } // Tizen::Messaging +#endif // _FMSG_INTERNAL_PUSH_EVENT_H_ diff --git a/src/FMsg_PushEventArg.cpp b/src/FMsg_PushEventArg.cpp new file mode 100644 index 0000000..25dd7c2 --- /dev/null +++ b/src/FMsg_PushEventArg.cpp @@ -0,0 +1,91 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushEventArg.cpp + * @brief This is the implementation file for _PushEventArg class. + * @version 3.0 + * + * This file contains the implementation of _PushEventArg class. + */ + +// Includes +#include +#include "FMsg_PushEventArg.h" + +using namespace Tizen::Base; + +namespace Tizen { namespace Messaging +{ + +_PushEventArg::_PushEventArg(_PushEventType type, RequestId reqId, const String& data, const String& message, result ret, const String& errorCode, const String& errorMsg) + : __type(type) + , __reqId(reqId) + , __data(data) + , __message(message) + , __ret(ret) + , __errorCode(errorCode) + , __errorMsg(errorMsg) +{ +} + +_PushEventArg::~_PushEventArg(void) +{ +} + +_PushEventType +_PushEventArg::GetType(void) const +{ + return __type; +} + +RequestId +_PushEventArg::GetRequestId(void) const +{ + return __reqId; +} + +String +_PushEventArg::GetData(void) const +{ + return __data; +} + +String +_PushEventArg::GetMessage(void) const +{ + return __message; +} + +result +_PushEventArg::GetResult(void) const +{ + return __ret; +} + +String +_PushEventArg::GetErrorCode(void) const +{ + return __errorCode; +} + +String +_PushEventArg::GetErrorMsg(void) const +{ + return __errorMsg; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_PushEventArg.h b/src/FMsg_PushEventArg.h new file mode 100644 index 0000000..d39842c --- /dev/null +++ b/src/FMsg_PushEventArg.h @@ -0,0 +1,77 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushEventArg.h + * @brief This is the header file for %_PushEventArg class. + * @version 3.0 + * + * This header file contains the declarations of %_PushEventArg class. + */ + +#ifndef _FMSG_INTERNAL_PUSH_EVENT_ARG_H_ +#define _FMSG_INTERNAL_PUSH_EVENT_ARG_H_ + +#include +#include +#include +#include + +namespace Tizen { namespace Messaging +{ + +enum _PushEventType +{ + _PUSH_EVENT_TYPE_REGISTRATION, + _PUSH_EVENT_TYPE_UNREGISTRATION, + _PUSH_EVENT_TYPE_NOTIFICATION, + _PUSH_EVENT_TYPE_SEND +}; + +class _PushEventArg + : public Tizen::Base::Object + , public Tizen::Base::Runtime::IEventArg +{ +public: + _PushEventArg(_PushEventType type, RequestId reqId, const Tizen::Base::String& data, const Tizen::Base::String& message, result ret, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg); + virtual ~_PushEventArg(void); + +public: + _PushEventType GetType(void) const; + RequestId GetRequestId(void) const; + Tizen::Base::String GetData(void) const; + Tizen::Base::String GetMessage(void) const; + result GetResult(void) const; + Tizen::Base::String GetErrorCode(void) const; + Tizen::Base::String GetErrorMsg(void) const; + +private: + _PushEventArg(void); + _PushEventArg(const _PushEventArg& rhs); + _PushEventArg& operator =(const _PushEventArg& rhs); + +private: + _PushEventType __type; + RequestId __reqId; + Tizen::Base::String __data; + Tizen::Base::String __message; + result __ret; + Tizen::Base::String __errorCode; + Tizen::Base::String __errorMsg; +}; // _PushEventArg + +} } // Tizen::Messaging +#endif // _FMSG_INTERNAL_PUSH_EVENT_ARG_H_ diff --git a/src/FMsg_PushManagerImpl.cpp b/src/FMsg_PushManagerImpl.cpp new file mode 100755 index 0000000..9672870 --- /dev/null +++ b/src/FMsg_PushManagerImpl.cpp @@ -0,0 +1,1919 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** +* @file FMsg_PushManagerImpl.cpp +* @brief This is the implementation file for the %_PushManagerImpl class. +* +* This file contains the implementation of the %_PushManagerImpl class. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_PushManagerImpl.h" +#include "FMsg_PushMessageImpl.h" +#include "FMsg_PushEvent.h" +#include "FMsg_PushEventArg.h" +#include "FMsg_PushRequest.h" + +using namespace std; +using namespace Tizen::App; +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::Io; +using namespace Tizen::Net::Http; +using namespace Tizen::Shell; +using namespace Tizen::System; +using namespace Tizen::Web::Json; + +namespace Tizen { namespace Messaging +{ + +static const int _MIN_PUSH_REQUEST_ID = 0; +static const int _MAX_PUSH_REQUEST_ID = 10000; +static const int _MAX_TRANSACTION_TIMEOUT = 60; // Secounds +static const wchar_t _INVALID_PUSH_REGISTRATION_ID[] = L""; +static const wchar_t _DEFAULT_NOTIFICATION_MESSAGE[] = L""; +static const wchar_t _DEFAULT_SERVER_ERROR_CODE[] = L""; +static const wchar_t _DEFAULT_SERVER_ERROR_MESSAGE[] = L""; +static const wchar_t _PUSH_STATUS_REGISTRY_FILE[] = L"data/.tizen_push.ini"; +static const wchar_t _PUSH_STATUS_REGISTRY_STATUS_SECTION[] = L"Status"; +static const wchar_t _PUSH_STATUS_REGISTRY_IS_REGISTERED_ENTRY[] = L"IsRegistered"; +static const wchar_t _PUSH_SERVER_REGISTRY_SERVER_SECTION[] = L"Server"; +static const wchar_t _PUSH_SERVER_REGISTRY_URL_ENTRY[] = L"Url"; +static const char _PUSH_SERVER_ERROR_APP_NOT_FOUND[] = "Failed to find application with given appId."; +static const int _MAX_RECIPIENT_COUNT = 20; + +static RequestId lastRequestId = 0; + +result +ConvertError(push_result_e res, const char* pServerError) +{ + if (pServerError != null) + { + SysLog(NID_MSG, "The current value of res is [%d], error is [%s].", res, pServerError); + } + else + { + SysLog(NID_MSG, "The current value of res is [%d].", res); + } + + result r = E_SUCCESS; + + if (res == PUSH_RESULT_SUCCESS) + { + r = E_SUCCESS; + } + else if (res == PUSH_RESULT_TIMEOUT) + { + r = E_CONNECTION_FAILED; + } + else if (res == PUSH_RESULT_SERVER_ERROR) + { + if (pServerError != null) + { + if (strcmp(pServerError, _PUSH_SERVER_ERROR_APP_NOT_FOUND) == 0) + { + r = E_SERVICE_UNAVAILABLE; + } + else + { + r = E_SERVER; + } + } + else + { + r = E_SERVER; + } + } + else + { + r = E_SYSTEM; + } + + SysLog(NID_MSG, "[%s] error has been occurred.", GetErrorMessage(r)); + + return r; +} + +void +PushStateEventCallback(push_state_e state, const char* pError, void* pUserData) +{ + SysLog(NID_MSG, "The PushStateEventCallback is entering with state[%d].", state); + + _PushManagerImpl* pManager = null; + char* pRegistrationId = null; + + pManager = (_PushManagerImpl*)pUserData; + SysTryReturnVoidResult(NID_MSG, pManager != null, E_OBJ_NOT_FOUND, "[%s] A _PushManagerImpl instance is NULL.", GetErrorMessage(E_OBJ_NOT_FOUND)); + + if (state == PUSH_STATE_REGISTERED) + { + // Registered + push_get_registration_id((push_connection_h)pManager->GetPushHandle(), &pRegistrationId); + if (pRegistrationId != null) + { + SysLog(NID_MSG, "Registered, regId[%s].", pRegistrationId); + pManager->SetPushStatus(true, String(pRegistrationId)); + free(pRegistrationId); + } + else + { + SysLog(NID_MSG, "Registered, but regId[NULL]."); + pManager->SetPushStatus(false, _INVALID_PUSH_REGISTRATION_ID); + } + } + else if (state == PUSH_STATE_UNREGISTERED) + { + // Not registered + SysLog(NID_MSG, "Not registered."); + pManager->SetPushStatus(false, _INVALID_PUSH_REGISTRATION_ID); + } + else + { + // Error + SysLog(NID_MSG, "Error: state[%d] error[%s]", state, pError); + + return; + } + + pManager->SetPushHandleReady(); + pManager->CheckNextRequest(); + + SysLog(NID_MSG, "The PushStateEventCallback is exiting."); + + return; +} + +void +PushNotiEventCallback(push_notification_h noti, void* pUserData) +{ + SysLog(NID_MSG, "The PushNotiEventCallback is entering."); + + _PushManagerImpl* pManager = null; + char* pAppData = null; + char* pNotiMessage = null; + String appData; + String notiMessage; + + pManager = (_PushManagerImpl*)pUserData; + SysTryCatch(NID_MSG, pManager != null, , E_OBJ_NOT_FOUND, "[%s] A _PushManagerImpl instance is NULL.", GetErrorMessage(E_OBJ_NOT_FOUND)); + + push_get_notification_data(noti, &pAppData); + SysTryCatch(NID_MSG, pAppData != null, , E_INVALID_ARG, "[%s] Invalid arguments is used. appData is NULL.", GetErrorMessage(E_INVALID_ARG)); + + push_get_notification_message(noti, &pNotiMessage); + + appData = String(pAppData); + free(pAppData); + + if (appData.GetLength() > MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH) + { + SysLog(NID_MSG, "AppData's length(%d) is too large, so set length(%d).", appData.GetLength(), MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH); + appData.SetLength(MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH); + } + + if (pNotiMessage != null) + { + notiMessage = String(pNotiMessage); + free(pNotiMessage); + } + + pManager->HandlePushMessage(notiMessage, appData); + + SysLog(NID_MSG, "The PushStateEventCallback is exiting."); + + return; + +CATCH: + return; +} + +void +PushResultEventCallback(push_result_e res, const char* pServerError, void* pUserData) +{ + SysLog(NID_MSG, "The PushResultEventCallback is entering with result[%d].", res); + + result r = E_SUCCESS; + _PushRequest* pRequest = null; + _PushManagerImpl* pManager = null; + char* pRegistrationId = null; + int ret = PUSH_ERROR_NONE; + + pRequest = (_PushRequest*)pUserData; + SysTryReturnVoidResult(NID_MSG, pRequest != null, E_OBJ_NOT_FOUND, "[%s] A _PushRequest instance is NULL.", GetErrorMessage(E_OBJ_NOT_FOUND)); + + pManager = pRequest->GetPushManager(); + SysTryReturnVoidResult(NID_MSG, pManager != null, E_OBJ_NOT_FOUND, "[%s] A _PushManagerImpl instance is NULL.", GetErrorMessage(E_OBJ_NOT_FOUND)); + + if (res == PUSH_RESULT_SUCCESS) + { + if (pRequest->GetType() == _PUSH_REQUEST_REGISTER) + { + push_get_registration_id((push_connection_h)pManager->GetPushHandle(), &pRegistrationId); + if (pRegistrationId != null) + { + SysLog(NID_MSG, "Registered, regId[%s].", pRegistrationId); + pManager->SetPushStatus(true, String(pRegistrationId)); + free(pRegistrationId); + } + else + { + if (ret == PUSH_ERROR_OUT_OF_MEMORY) + { + r = E_OUT_OF_MEMORY; + } + else + { + r = E_SYSTEM; + } + + SysLogException(NID_MSG, r, "[%s] Failed to get a registrationId.", GetErrorMessage(r)); + } + } + else + { + SysLog(NID_MSG, "Unregistered."); + pManager->SetPushStatus(false, _INVALID_PUSH_REGISTRATION_ID); + } + } + else + { + r = ConvertError(res, pServerError); + } + + if (pRequest->GetType() == _PUSH_REQUEST_REGISTER) + { + // Registration Request + pManager->HandlePushRegistrationResponse(pRequest->GetRequestId(), pManager->GetRegistrationId(), r); + } + else + { + // Unregistration Request + pManager->HandlePushUnregistrationResponse(pRequest->GetRequestId(), r); + } + + pManager->RemoveRequest(pRequest); + pManager->UpdateActiveRequest(false); + pManager->CheckNextRequest(); + + SysLog(NID_MSG, "The PushResultEventCallback is exiting."); + + return; +} + +_PushManagerImpl::_PushManagerImpl(void) + : __pManagerListener(null) + , __pEventListener(null) + , __pEvent(null) + , __pHeader(null) + , __pSession(null) + , __pRequest(null) + , __pTransaction(null) + , __pBody(null) + , __pListener(null) + , __pUrlListener(null) + , __isRegistered(false) + , __pRequestList(null) + , __hasActiveRequest(false) + , __pPushHandle(null) + , __isPushHandleReady(false) +{ + __appSecret.Clear(); + __registrationId.Clear(); +} + +_PushManagerImpl::~_PushManagerImpl(void) +{ + if (__pPushHandle != null) + { + push_disconnect((push_connection_h)__pPushHandle); + __pPushHandle = null; + } + + if (__pRequestList != null) + { + __pRequestList->RemoveAll(true); + delete __pRequestList; + __pRequestList = null; + } + + if (__pBody != null) + { + delete __pBody; + __pBody = null; + } + + if (__pSession != null) + { + delete __pSession; + __pSession = null; + } + + if (__pUrlListener != null) + { + delete __pUrlListener; + __pUrlListener = null; + } + + if (__pListener != null) + { + delete __pListener; + __pListener = null; + } + + if (__pEvent != null) + { + if (__pManagerListener != null) + { + __pEvent->RemoveListener(*__pManagerListener); + } + + delete __pEvent; + __pEvent = null; + } + + __pManagerListener = null; + __pEventListener = null; +} + +result +_PushManagerImpl::Construct(IPushManagerListener& managerListener, IPushEventListener& eventListener) +{ + SysLog(NID_MSG, "The Construct is entering."); + + result r = E_SUCCESS; + int ret = PUSH_ERROR_NONE; + push_connection_h pushHandle = null; + PackageId packageId; + char* pPackageId = null; + + SysTryReturnResult(NID_MSG, __pPushHandle == null, E_INVALID_STATE, "The __pPushHandle instance is already constructed."); + + unique_ptr<_PushEvent> pEvent; + unique_ptr<_PushSendListener> pListener; + unique_ptr<_PushUrlRequestListener> pUrlListener; + unique_ptr pRequestList; + + pEvent.reset(new (std::nothrow) _PushEvent(this)); + SysTryCatch(NID_MSG, pEvent != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + r = pEvent->AddListener(managerListener); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to add an event listener.", GetErrorMessage(r)); + + pListener.reset(new (std::nothrow) _PushSendListener()); + SysTryCatch(NID_MSG, pListener != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create push send listener."); + + pUrlListener.reset(new (std::nothrow) _PushUrlRequestListener()); + SysTryCatch(NID_MSG, pUrlListener != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create push send listener."); + + pRequestList.reset(new (std::nothrow) ArrayList()); + SysTryCatch(NID_MSG, pRequestList != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + packageId = _AppInfo::GetPackageId(); + SysLog(NID_MSG, "Package ID is [%ls].", packageId.GetPointer()); + + pPackageId = _StringConverter::CopyToCharArrayN(packageId); + SysTryCatch(NID_MSG, pPackageId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + ret = push_connect(pPackageId, PushStateEventCallback, PushNotiEventCallback, (void*)this, &pushHandle); + if (ret == PUSH_ERROR_NONE) + { + r = E_SUCCESS; + } + else if (ret == PUSH_ERROR_OUT_OF_MEMORY) + { + r = E_OUT_OF_MEMORY; + } + else + { + r = E_INVALID_STATE; + } + + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to connect to push daemon.", GetErrorMessage(r)); + + __pPushHandle = (void*)pushHandle; + + __pManagerListener = &managerListener; + __pEventListener = &eventListener; + + __isRegistered = GetLastPushStatus(); + + delete[] pPackageId; + pPackageId = null; + + __pRequestList = pRequestList.release(); + __pUrlListener = pUrlListener.release(); + __pListener = pListener.release(); + __pEvent = pEvent.release(); + + SysLog(NID_MSG, "The Construct is exiting with result[%s] isRegistered[%d].", GetErrorMessage(r), __isRegistered); + + return r; + +CATCH: + if (pPackageId != null) + { + delete[] pPackageId; + } + + return r; +} + +result +_PushManagerImpl::RegisterPushService(RequestId& reqId) +{ + SysLog(NID_MSG, "The RegisterPushService is entering."); + + result r = E_SUCCESS; + _PushRequest* pRequest = null; + + SysTryReturnResult(NID_MSG, __pPushHandle != null, E_INVALID_STATE, "The __pPushHandle instance is not constructed yet."); + + reqId = _PushManagerImpl::GetNextRequestId(); + + if ((HasPendingRequest() == true) || (IsPushHandleReady() == false)) + { + SysLog(NID_MSG, "PendingRequest[%d] IsPushHandleReady[%d], so add to the queue.", + HasPendingRequest(), IsPushHandleReady()); + + pRequest = AddRequest(reqId, _PUSH_REQUEST_REGISTER); + r = GetLastResult(); + SysTryReturn(NID_MSG, pRequest != null, r, r, "[%s] Failed to add to the queue.", GetErrorMessage(r)); + + return E_SUCCESS; + } + + if (GetPushStatus() == false) + { + // NOT Registered + pRequest = AddRequest(reqId, _PUSH_REQUEST_REGISTER); + r = GetLastResult(); + SysTryReturn(NID_MSG, pRequest != null, r, r, "[%s] Failed to add to the queue.", GetErrorMessage(r)); + + r = RequestPushRegistration(pRequest); + if (IsFailed(r)) + { + RemoveRequest(pRequest); + } + } + else + { + // Already registered + SysLog(NID_MSG, "Already registered. regId[%ls]", __registrationId.GetPointer()); + + HandlePushRegistrationResponse(reqId, __registrationId, E_SUCCESS); + } + + SysLog(NID_MSG, "The RegisterPushService is exiting with result[%s].", GetErrorMessage(r)); + + return r; +} + +result +_PushManagerImpl::UnregisterPushService(RequestId& reqId) +{ + SysLog(NID_MSG, "The UnregisterPushService is entering."); + + result r = E_SUCCESS; + _PushRequest* pRequest = null; + + SysTryReturnResult(NID_MSG, __pPushHandle != null, E_INVALID_STATE, "The __pPushHandle instance is not constructed yet."); + + reqId = _PushManagerImpl::GetNextRequestId(); + + if ((HasPendingRequest() == true) || (IsPushHandleReady() == false)) + { + SysLog(NID_MSG, "PendingRequest[%d] IsPushHandleReady[%d], so add to the queue.", + HasPendingRequest(), IsPushHandleReady()); + + pRequest = AddRequest(reqId, _PUSH_REQUEST_UNREGISTER); + r = GetLastResult(); + SysTryReturn(NID_MSG, pRequest != null, r, r, "[%s] Failed to add to the queue.", GetErrorMessage(r)); + + return E_SUCCESS; + } + + if (GetPushStatus() == true) + { + // Registered + pRequest = AddRequest(reqId, _PUSH_REQUEST_UNREGISTER); + r = GetLastResult(); + SysTryReturn(NID_MSG, pRequest != null, r, r, "[%s] Failed to add to the queue.", GetErrorMessage(r)); + + r = RequestPushUnregistration(pRequest); + if (IsFailed(r)) + { + RemoveRequest(pRequest); + } + } + else + { + // Already unregistered + SysLog(NID_MSG, "Already unregistered."); + + HandlePushUnregistrationResponse(reqId, E_SUCCESS); + } + + SysLog(NID_MSG, "The UnregisterPushService is exiting with result[%s].", GetErrorMessage(r)); + + return r; +} + +bool +_PushManagerImpl::IsPushServiceRegistered(void) const +{ + return GetPushStatus(); +} + +IList* +_PushManagerImpl::GetUnreadMessagesN(void) +{ + SysLog(NID_MSG, "The GetUnreadMessagesN is entering."); + + ClearLastResult(); + + IList* pList = null; + int ret = PUSH_ERROR_NONE; + push_notification_h notification; + + SysTryReturn(NID_MSG, __pPushHandle != null, null, E_INVALID_STATE, "[E_INVALID_STATE] The __pPushHandle instance is not constructed yet."); + + pList = new (std::nothrow) ArrayList; + SysTryReturn(NID_MSG, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + while (ret == PUSH_ERROR_NONE) + { + ret = push_get_unread_notification((push_connection_h)GetPushHandle(), ¬ification); + + if ((ret == PUSH_ERROR_NONE) && (notification != null)) + { + char* pNotiMessage = null; + char* pAppData = null; + long long int notiTime = 0; + DateTime receivedTime; + String appData; + String notiMessage; + PushMessage* pMessage = null; + + push_get_notification_message(notification, &pNotiMessage); + if (pNotiMessage != null) + { + SysLog(NID_MSG, "NotiMessage=[%s].", pNotiMessage); + notiMessage = String(pNotiMessage); + free(pNotiMessage); + } + else + { + SysLog(NID_MSG, "NotiMessage=NULL."); + } + + push_get_notification_time(notification, ¬iTime); + + push_get_notification_data(notification, &pAppData); + push_free_notification(notification); + if (pAppData != null) + { + SysLog(NID_MSG, "AppData=[%s].", pAppData); + appData = String(pAppData); + free(pAppData); + + if (appData.GetLength() > MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH) + { + SysLog(NID_MSG, "AppData's length(%d) is too large, so set length(%d).", appData.GetLength(), MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH); + appData.SetLength(MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH); + } + } + else + { + SysLog(NID_MSG, "AppData=NULL, so ignore this message."); + continue; + } + + receivedTime = _PushMessageImpl::ConvertTime(notiTime); + + pMessage = _PushMessageImpl::CreatePushMessageN(receivedTime, appData); + if (pMessage != null) + { + _PushMessageImpl::GetInstance(*pMessage)->ConvertMessageToNotification(notiMessage); + pList->Add(*pMessage); + } + } + else + { + SysLog(NID_MSG, "push_get_unread_notification() ret=[%d].", ret); + break; + } + } + + SysLog(NID_MSG, "The GetUnreadMessagesN is exiting with (%d) unread messages.", pList->GetCount()); + + return pList; +} + +result +_PushManagerImpl::SendPushMessage(const PushMessage& message, const String& registrationId, const String& appSecret, RequestId& reqId) +{ + SysLog(NID_MSG, "The SendPushMessage is entering."); + + result r = E_SUCCESS; + _PushRequest* pRequest = null; + + SysTryReturnResult(NID_MSG, __pPushHandle != null, E_INVALID_STATE, "The __pPushHandle instance is not constructed yet."); + + __appSecret = appSecret; + + reqId = _PushManagerImpl::GetNextRequestId(); + + pRequest = new (std::nothrow) _PushRequest(this, reqId, _PUSH_REQUEST_SEND); + SysTryReturn(NID_MSG, pRequest != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + r = RequestPushSendMessageSingle(pRequest, message, registrationId); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "[%s] Failed to send push message to single device.", GetErrorMessage(r)); + + SysLog(NID_MSG, "The SendPushMessage is exiting with result[%s].", GetErrorMessage(r)); + + return r; +} + +result +_PushManagerImpl::SendPushMessage(const PushMessage& message, const IList& registrationIdList, const String& appSecret, RequestId& reqId) +{ + SysLog(NID_MSG, "The SendPushMessage is entering."); + + result r = E_SUCCESS; + _PushRequest* pRequest = null; + int count = 0; + + SysTryReturnResult(NID_MSG, __pPushHandle != null, E_INVALID_STATE, "The __pPushHandle instance is not constructed yet."); + + count = registrationIdList.GetCount(); + SysTryReturnResult(NID_MSG, count > 0, E_INVALID_ARG, "The list of registration IDs is empty."); + + __appSecret = appSecret; + + reqId = _PushManagerImpl::GetNextRequestId(); + + pRequest = new (std::nothrow) _PushRequest(this, reqId, _PUSH_REQUEST_SEND); + SysTryReturn(NID_MSG, pRequest != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + r = RequestPushSendMessageMultiple(pRequest, message, registrationIdList); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "[%s] Failed to send push message to multiple devices.", GetErrorMessage(r)); + + SysLog(NID_MSG, "The SendPushMessage is exiting with result[%s].", GetErrorMessage(r)); + + return r; +} + +int +_PushManagerImpl::GetMaxRecipientCount(void) +{ + return _MAX_RECIPIENT_COUNT; +} + +_PushManagerImpl* +_PushManagerImpl::GetInstance(PushManager& pushManager) +{ + return pushManager.__pPushManagerImpl; +} + +const _PushManagerImpl* +_PushManagerImpl::GetInstance(const PushManager& pushManager) +{ + return pushManager.__pPushManagerImpl; +} + +void +_PushManagerImpl::HandlePushEvent(_PushEventArg& eventArg) +{ + SysLog(NID_MSG, "The HandlePushEvent is entering with type(%d).", eventArg.GetType()); + + result r = E_SUCCESS; + DateTime time; + PushMessage* pMessage = null; + + switch (eventArg.GetType()) + { + case _PUSH_EVENT_TYPE_REGISTRATION: + if (__pManagerListener != null) + { + SysLog(NID_MSG, "Calling OnPushServiceRegistered()."); + + __pManagerListener->OnPushServiceRegistered(eventArg.GetRequestId(), eventArg.GetData(), eventArg.GetResult(), + _DEFAULT_SERVER_ERROR_CODE, _DEFAULT_SERVER_ERROR_MESSAGE); + + SysLog(NID_MSG, "Called OnPushServiceRegistered()."); + } + break; + + case _PUSH_EVENT_TYPE_UNREGISTRATION: + if (__pManagerListener != null) + { + SysLog(NID_MSG, "Calling OnPushServiceUnregistered()."); + + __pManagerListener->OnPushServiceUnregistered(eventArg.GetRequestId(), eventArg.GetResult(), + _DEFAULT_SERVER_ERROR_CODE, _DEFAULT_SERVER_ERROR_MESSAGE); + + SysLog(NID_MSG, "Called OnPushServiceUnregistered()."); + } + break; + + case _PUSH_EVENT_TYPE_NOTIFICATION: + r = SystemTime::GetCurrentTime(time); + if (r == E_SUCCESS) + { + pMessage = _PushMessageImpl::CreatePushMessageN(time, eventArg.GetData()); + if (pMessage != null) + { + _PushMessageImpl::GetInstance(*pMessage)->ConvertMessageToNotification(eventArg.GetMessage()); + if (__pEventListener != null) + { + SysLog(NID_MSG, "Calling OnPushMessageReceived()."); + + __pEventListener->OnPushMessageReceived(*pMessage); + + SysLog(NID_MSG, "Called OnPushMessageReceived()."); + } + + delete pMessage; + } + } + break; + + case _PUSH_EVENT_TYPE_SEND: + if (__pManagerListener != null) + { + SysLog(NID_MSG, "Calling OnPushMessageSent()."); + + __pManagerListener->OnPushMessageSent(eventArg.GetRequestId(), eventArg.GetData(), eventArg.GetResult(), + eventArg.GetErrorCode(), eventArg.GetErrorMsg()); + + SysLog(NID_MSG, "Called OnPushMessageSent()."); + } + break; + + default: + break; + } + + SysLog(NID_MSG, "The HandlePushEvent is exiting."); + + return; +} + +void +_PushManagerImpl::HandlePushRegistrationResponse(RequestId reqId, const String& registrationId, result r) +{ + SysLog(NID_MSG, "The HandlePushRegistrationResponse is entering with reqId[%d] result[%s] registrationId[%ls].", + reqId, GetErrorMessage(r), registrationId.GetPointer()); + + _PushEventArg* pEventArg = null; + + if ((__pManagerListener != null) && (__pEvent != null)) + { + pEventArg = new (std::nothrow) _PushEventArg(_PUSH_EVENT_TYPE_REGISTRATION, reqId, registrationId, _DEFAULT_NOTIFICATION_MESSAGE, r, _DEFAULT_SERVER_ERROR_CODE, _DEFAULT_SERVER_ERROR_MESSAGE); + if (pEventArg != null) + { + __pEvent->FireAsync(*pEventArg); + } + } + + SysLog(NID_MSG, "The HandlePushRegistrationResponse is exiting."); +} + +void +_PushManagerImpl::HandlePushUnregistrationResponse(RequestId reqId, result r) +{ + SysLog(NID_MSG, "The HandlePushUnregistrationResponse is entering with reqId[%d] result[%s].", reqId, GetErrorMessage(r)); + + _PushEventArg* pEventArg = null; + + if ((__pManagerListener != null) && (__pEvent != null)) + { + pEventArg = new (std::nothrow) _PushEventArg(_PUSH_EVENT_TYPE_UNREGISTRATION, reqId, _INVALID_PUSH_REGISTRATION_ID, _DEFAULT_NOTIFICATION_MESSAGE, r, _DEFAULT_SERVER_ERROR_CODE, _DEFAULT_SERVER_ERROR_MESSAGE); + if (pEventArg != null) + { + __pEvent->FireAsync(*pEventArg); + } + } + + SysLog(NID_MSG, "The HandlePushUnregistrationResponse is exiting."); +} + +void +_PushManagerImpl::HandlePushMessage(const String& notiMessage, const String& payload) +{ + SysLog(NID_MSG, "The HandlePushMessage is entering with notiMessage[%ls] payload[%ls].", + notiMessage.GetPointer(), payload.GetPointer()); + + _PushEventArg* pEventArg = null; + + if ((__pEventListener != null) && (__pEvent != null)) + { + pEventArg = new (std::nothrow) _PushEventArg(_PUSH_EVENT_TYPE_NOTIFICATION, INVALID_REQUEST_ID, payload, notiMessage, E_SUCCESS, _DEFAULT_SERVER_ERROR_CODE, _DEFAULT_SERVER_ERROR_MESSAGE); + if (pEventArg != null) + { + __pEvent->FireAsync(*pEventArg); + } + } + + SysLog(NID_MSG, "The HandlePushMessage is exiting."); +} + +void +_PushManagerImpl::HandlePushSendMessageResponse(RequestId reqId, const String& registrationId, result r, const String& errorCode, const String& errorMsg) +{ + SysLog(NID_MSG, "The HandlePushSendMessageResponse is entering with reqId[%d] registrationId[%ls] result[%s] errorCode[%ls] errorMsg[%ls].", + reqId, registrationId.GetPointer(), GetErrorMessage(r), errorCode.GetPointer(), errorMsg.GetPointer()); + + _PushEventArg* pEventArg = null; + + if ((__pEventListener != null) && (__pEvent != null)) + { + pEventArg = new (std::nothrow) _PushEventArg(_PUSH_EVENT_TYPE_SEND, reqId, registrationId, _DEFAULT_NOTIFICATION_MESSAGE, r, errorCode, errorMsg); + if (pEventArg != null) + { + __pEvent->FireAsync(*pEventArg); + } + } + + SysLog(NID_MSG, "The HandlePushSendMessageResponse is exiting."); +} + +void +_PushManagerImpl::SetPushStatus(bool isRegistered, const String& registrationId) +{ + if (isRegistered != __isRegistered) + { + UpdateLastPushStatus(isRegistered); + } + + __isRegistered = isRegistered; + __registrationId = registrationId; +} + +bool +_PushManagerImpl::GetPushStatus(void) const +{ + return __isRegistered; +} + +String +_PushManagerImpl::GetRegistrationId(void) const +{ + return __registrationId; +} + +void* +_PushManagerImpl::GetPushHandle(void) const +{ + return __pPushHandle; +} + +void +_PushManagerImpl::SetPushHandleReady(void) +{ + __isPushHandleReady = true; +} + +bool +_PushManagerImpl::IsPushHandleReady(void) const +{ + return __isPushHandleReady; +} + +_PushRequest* +_PushManagerImpl::AddRequest(RequestId reqId, _PushRequestType type) +{ + SysLog(NID_MSG, "The AddRequest is entering."); + + ClearLastResult(); + + result r = E_SUCCESS; + _PushRequest* pRequest = null; + + pRequest = new (std::nothrow) _PushRequest(this, reqId, type); + SysTryReturn(NID_MSG, pRequest != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + r = __pRequestList->Add(*pRequest); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add the request.", GetErrorMessage(r)); + + delete pRequest; + return null; + } + + SysLog(NID_MSG, "The AddRequest is exiting."); + + return pRequest; +} + +_PushRequest* +_PushManagerImpl::GetNextRequest(void) +{ + Object* pObject = null; + _PushRequest* pRequest = null; + + pObject = __pRequestList->GetAt(0); + if (pObject != null) + { + pRequest = dynamic_cast<_PushRequest*>(pObject); + } + + return pRequest; +} + +void +_PushManagerImpl::RemoveRequest(_PushRequest* pRequest) +{ + __pRequestList->Remove(*pRequest, true); + + return; +} + +bool +_PushManagerImpl::HasPendingRequest(void) const +{ + int count = 0; + bool ret = false; + + count = __pRequestList->GetCount(); + + if (count > 0) + { + ret = true; + } + else + { + ret = false; + } + + return ret; +} + +bool +_PushManagerImpl::HasActiveRequest(void) const +{ + return __hasActiveRequest; +} + +void +_PushManagerImpl::UpdateActiveRequest(bool hasActiveRequest) +{ + __hasActiveRequest = hasActiveRequest; +} + +void +_PushManagerImpl::CheckNextRequest(void) +{ + SysLog(NID_MSG, "The CheckNextRequest is entering."); + + result r = E_SUCCESS; + _PushRequest* pRequest = null; + + if (IsPushHandleReady() == false) + { + SysLog(NID_MSG, "PushHandle is NOT ready."); + return; + } + + if (HasActiveRequest() == true) + { + SysLog(NID_MSG, "ActiveRequest exists."); + return; + } + + pRequest = GetNextRequest(); + while (pRequest != null) + { + if (pRequest->GetType() == _PUSH_REQUEST_REGISTER) + { + // Register + if (GetPushStatus() == false) + { + // NOT Registered + r = RequestPushRegistration(pRequest); + if (IsFailed(r)) + { + HandlePushRegistrationResponse(pRequest->GetRequestId(), _INVALID_PUSH_REGISTRATION_ID, r); + } + else + { + // Send a request, so waiting the response. + return; + } + } + else + { // Already registered + SysLog(NID_MSG, "Already registered. regId[%ls]", __registrationId.GetPointer()); + + HandlePushRegistrationResponse(pRequest->GetRequestId(), __registrationId, E_SUCCESS); + } + } + else + { + // Unregister + if (GetPushStatus() == true) + { + // Registered + r = RequestPushUnregistration(pRequest); + if (IsFailed(r)) + { + HandlePushUnregistrationResponse(pRequest->GetRequestId(), r); + } + else + { + // Send a request, so waiting the response. + return; + } + } + else + { + // Already unregistered + SysLog(NID_MSG, "Already unregistered."); + + HandlePushUnregistrationResponse(pRequest->GetRequestId(), E_SUCCESS); + } + } + + RemoveRequest(pRequest); + pRequest = GetNextRequest(); + } + + SysLog(NID_MSG, "The CheckNextRequest is exiting."); +} + +String +_PushManagerImpl::GetAppSecret(void) const +{ + return __appSecret; +} + +result +_PushManagerImpl::GetUrlFromRegistrationId(const String& registrationId, _PushRequest* pRequest, const PushMessage& pushMessage, const IList& registrationIdList, String& url) +{ + SysLog(NID_MSG, "The GetUrlFromRegistrationId is entering."); + + result r = E_SUCCESS; + + String prefix(""); + + r = registrationId.SubString(0,2, prefix); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the prefix from registration ID", GetErrorMessage(r)); + + if (prefix.Equals("00", false)) + { + SysLog(NID_MSG, "Region : US East"); + url = "https://useast.push.samsungosp.com:8088/spp/pns/api/push"; + } + else if (prefix.Equals("01", false)) + { + SysLog(NID_MSG, "Region : US West"); + url = "https://uswest.push.samsungosp.com:8088/spp/pns/api/push"; + } + else if (prefix.Equals("02", false)) + { + SysLog(NID_MSG, "Region : Asia Pacific southeast"); + url = "https://apsoutheast.push.samsungosp.com:8088/spp/pns/api/push"; + } + else if (prefix.Equals("03", false)) + { + SysLog(NID_MSG, "Region : EU West"); + url = "https://euwest.push.samsungosp.com:8088/spp/pns/api/push"; + } + else if (prefix.Equals("04", false)) + { + SysLog(NID_MSG, "Region : Asia Pacific Northeast"); + url = "https://apnortheast.push.samsungosp.com:8088/spp/pns/api/push"; + } + else if (prefix.Equals("05", false)) + { + SysLog(NID_MSG, "Region : Korea"); + url = "https://apkorea.push.samsungosp.com:8088/spp/pns/api/push"; + } + else if (prefix.Equals("06", false)) + { + SysLog(NID_MSG, "Region : China"); + url = "https://apchina.push.samsungosp.com.cn:8088/spp/pns/api/push"; + } + + else if (prefix.Equals("7c", false)) + { + SysLog(NID_MSG, "Region : Staging"); + url = "https://175.41.248.50:8088/spp/pns/api/push"; + } + else + { + url = GetPushServerUrl(); + + if (url.IsEmpty() != true) + { + SysLog(NID_MSG, "Region : Get url from registry"); + } + else + { + SysLog(NID_MSG, "Region : Query url to server"); + + r = QueryServerUrl(prefix, pRequest, pushMessage, registrationIdList); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, r, "Failed to query server url by regionID."); + } + } + + SysLog(NID_MSG, "The GetUrlFromRegistrationId is exiting."); + + return r; +} + +result +_PushManagerImpl::QueryServerUrl(const String& prefix, _PushRequest* pRequest, const PushMessage& pushMessage, const IList& registrationIdList) +{ + SysLog(NID_MSG, "The QueryServerUrl is entering."); + + result r = E_SUCCESS; + + String url(L"https://gld.push.samsungosp.com:8089/spp/pns/dr/pushurl"); + Uri uri; + int timeout = _MAX_TRANSACTION_TIMEOUT; + HttpUrlEncodedEntity* pHttpUrlEncodedEntity = null; + PushMessage* pPushMessage = null; + ArrayList* pRegistrationIdList = null; + _UserData* pUserData = null; + int count = 0; + + r = uri.SetUri(url); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Invalid URL.", GetErrorMessage(r)); + + if(__pSession == null) + { + // Create Http session + __pSession = new (std::nothrow) HttpSession(); + SysTryCatch(NID_MSG, __pSession != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create the Http session."); + + r = __pSession->Construct(NET_HTTP_SESSION_MODE_MULTIPLE_HOST, null, L"", null); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct Http session.", GetErrorMessage(r)); + } + + __pTransaction = __pSession->OpenTransactionN(); + SysTryCatch(NID_MSG, __pTransaction != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create the Http transaction."); + + r = __pTransaction->SetTimeout(timeout); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set timeout.", GetErrorMessage(r)); + + pPushMessage = new (std::nothrow) PushMessage(pushMessage); + SysTryCatch(NID_MSG, pPushMessage != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create the pushMessage."); + + pRegistrationIdList = new (std::nothrow) ArrayList(); + SysTryCatch(NID_MSG, pRegistrationIdList != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create the registration Id list."); + + count = registrationIdList.GetCount(); + SysLog(NID_MSG, "Query url server count [%d]", count); + + r = pRegistrationIdList->Construct(count); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct registration Id list.", GetErrorMessage(r)); + + for(int i = 0; i < count; i++) + { + String* pTemStr = null; + pTemStr = new (std::nothrow) String(*(String*)((registrationIdList.GetAt(i)))); + SysTryCatch(NID_MSG, pTemStr != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create string."); + + pRegistrationIdList->Add(*pTemStr); + } + + r = __pTransaction->AddHttpTransactionListener(*__pUrlListener); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to add http transaction listener.", GetErrorMessage(r)); + + __pRequest = __pTransaction->GetRequest(); + + r = __pRequest->SetMethod(NET_HTTP_METHOD_POST); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set method into the http request.", GetErrorMessage(r)); + + r = __pRequest->SetUri(url); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to set uri into the http request.", GetErrorMessage(r)); + + // Create Http url encoded entity + pHttpUrlEncodedEntity = new (std::nothrow) HttpUrlEncodedEntity(); + SysTryCatch(NID_MSG, pHttpUrlEncodedEntity != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create the Http url encoded entity."); + + r = pHttpUrlEncodedEntity->Construct(); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct http url encoded entity.", GetErrorMessage(r)); + + r = pHttpUrlEncodedEntity->AddParameter(L"serverid", prefix); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add parameter into the http url encoded entity.", GetErrorMessage(r)); + + r = __pRequest->SetEntity(*pHttpUrlEncodedEntity); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set entity into the http url encoded entity.", GetErrorMessage(r)); + + pUserData = new (std::nothrow) _UserData(pHttpUrlEncodedEntity, pPushMessage, pRequest, pRegistrationIdList); + SysTryCatch(NID_MSG, pUserData != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + r = __pTransaction->SetUserObject(pUserData); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set user object the http transaction.", GetErrorMessage(r)); + + r = __pTransaction->Submit(); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to submit for http transaction.", GetErrorMessage(r)); + + SysLog(NID_MSG, "The QueryServerUrl is exiting with result[%s].", GetErrorMessage(r)); + + return r; + +CATCH: + + delete pHttpUrlEncodedEntity; + pHttpUrlEncodedEntity = null; + + delete pPushMessage; + pPushMessage = null; + + delete pRegistrationIdList; + pRegistrationIdList = null; + + delete pUserData; + pUserData = null; + + delete __pTransaction; + __pTransaction = null; + + delete __pSession; + __pSession = null; + + return r; +} + +result +_PushManagerImpl::SendHttpRequest(const String& url, _PushRequest* pRequest, const PushMessage& pushMessage, const IList& registrationIdList) +{ + SysLog(NID_MSG, "The SendHttpRequest is entering."); + + result r = E_SUCCESS; + + Uri uri; + int timeout = _MAX_TRANSACTION_TIMEOUT; + int length = 0; + String lengthAsString(L""); + PackageId packageId(L""); + String appSecret(L""); + _SendUserData* pUserData = null; + + r = uri.SetUri(url); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Invalid URL.", GetErrorMessage(r)); + + if(__pSession == null) + { + // Create Http session + __pSession = new (std::nothrow) HttpSession(); + SysTryCatch(NID_MSG, __pSession != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create the Http session."); + + r = __pSession->Construct(NET_HTTP_SESSION_MODE_MULTIPLE_HOST, null, L"", null); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct Http session.", GetErrorMessage(r)); + } + + __pTransaction = __pSession->OpenTransactionN(); + SysTryCatch(NID_MSG, __pTransaction != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create the Http transaction."); + + r = __pTransaction->SetTimeout(timeout); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set timeout.", GetErrorMessage(r)); + + r = __pTransaction->AddHttpTransactionListener(*__pListener); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to add http transaction listener.", GetErrorMessage(r)); + + __pRequest = __pTransaction->GetRequest(); + + r = __pRequest->SetMethod(NET_HTTP_METHOD_POST); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set method into the http request.", GetErrorMessage(r)); + + r = __pRequest->SetUri(url); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to set uri into the http request.", GetErrorMessage(r)); + + // Create Http Request Header + __pHeader = __pRequest->GetHeader(); + + packageId = _AppInfo::GetPackageId(); + + appSecret = GetAppSecret(); + + r = __pHeader->AddField(L"appID", packageId); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add appId field into the http header.", GetErrorMessage(r)); + + r = __pHeader->AddField(L"appSecret", appSecret); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add appSecret field into the http header.", GetErrorMessage(r)); + + r = __pHeader->AddField(L"content-Type", L"application/json"); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add content-type field into the http header.", GetErrorMessage(r)); + + // Create Http Request Body + __pBody = new (std::nothrow) ByteBuffer; + SysTryCatch(NID_MSG, __pBody != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to create the bytebuffer."); + + r = ComposeJsonObject(pRequest, pushMessage, registrationIdList, *__pBody); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to compose Json object.", GetErrorMessage(r)); + + length = __pBody->GetLimit(); + + lengthAsString.Append(length); + r = __pHeader->AddField(L"content-Length", lengthAsString); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add content-length field into the http header.", GetErrorMessage(r)); + + r = __pRequest->WriteBody(*__pBody); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to write body into the http request.", GetErrorMessage(r)); + + pUserData = new (std::nothrow) _SendUserData(pRequest); + SysTryCatch(NID_MSG, pUserData != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + + r = __pTransaction->SetUserObject(pUserData); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set user object the http transaction.", GetErrorMessage(r)); + + r = __pTransaction->Submit(); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to submit for http transaction.", GetErrorMessage(r)); + + SysLog(NID_MSG, "The SendHttpRequest is exiting with result[%s].", GetErrorMessage(r)); + + return r; + +CATCH: + if(pUserData) + { + delete pUserData; + pUserData = null; + } + if (__pBody) + { + delete __pBody; + __pBody = null; + } + + if (__pTransaction) + { + delete __pTransaction; + __pTransaction = null; + } + + if (__pSession) + { + delete __pSession; + __pSession = null; + } + + return r; +} + +result +_PushManagerImpl::ComposeJsonObject(const _PushRequest* pRequest, const PushMessage& pushMessage, const IList& registrationIdList, ByteBuffer& buffer) const +{ + SysLog(NID_MSG, "The ComposeJsonObject is entering."); + + result r = E_SUCCESS; + + int count = 0; + JsonObject* pJsonObj = null; + JsonArray* pJsonArray = null; + JsonString* pKey1 = null; + JsonString* pKey2 = null; + JsonString* pKey3 = null; + JsonString* pKey4 = null; + JsonString* pValue1 = null; + JsonString* pValue2 = null; + JsonString* pValue3 = null; + JsonString* pValue4 = null; + + String* pTempStr = null; + + String reqId(L""); + reqId.Append(pRequest->GetRequestId()); + + NotificationRequest notificationMessage; + String badgeOption(L""); + String badgeNumber(L""); + String action(L""); + String alertMessage(L""); + String message(L""); + + notificationMessage = pushMessage.GetNotification(); + + String appData = notificationMessage.GetAppMessage(); + + int pushBadgeNumber = notificationMessage.GetBadgeNumber(); + int pushBadgeOption = notificationMessage.GetBadgeOffset(); + + if (0 <= pushBadgeNumber) + { + badgeOption.Append("badgeOption=SET&"); + badgeNumber.Append("badgeNumber="); + badgeNumber.Append(pushBadgeNumber); + badgeNumber.Append("&"); + } + + if (0 < pushBadgeOption) + { + badgeOption.Append("badgeOption=INCREASE&"); + badgeNumber.Append("badgeNumber="); + badgeNumber.Append(pushBadgeOption); + badgeNumber.Append("&"); + } + else if (pushBadgeOption < 0) + { + badgeOption.Append("badgeOption=DECREASE&"); + badgeNumber.Append("badgeNumber="); + badgeNumber.Append(pushBadgeOption); + badgeNumber.Append("&"); + } + + PushAction pushAction = pushMessage.GetAction(); + if (pushAction == PUSH_ACTION_ALERT) + { + action.Append("action=ALERT"); + } + else if (pushAction == PUSH_ACTION_SILENT) + { + action.Append("action=SILENT"); + } + else if (pushAction == PUSH_ACTION_DISCARD) + { + action.Append("action=DISCARD"); + } + else if (pushAction == PUSH_ACTION_LAUNCH) + { + action.Append("action=LAUNCH"); + } + else + { + action.Append("action=SILENT"); + } + + String alertText1 = notificationMessage.GetAlertText(); + String alertText2; + if (alertText1.IsEmpty() != true) + { + r = UrlEncoder::Encode(alertText1, L"UTF-8", alertText2); + r = TransExceptionsExclusive(r, E_SYSTEM, E_OUT_OF_MEMORY); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to encode from UrlEncoder.", GetErrorMessage(r)); + + alertMessage.Append("&alertMessage="); + alertMessage.Append(alertText2); + } + + message.Append(badgeOption); + message.Append(badgeNumber); + message.Append(action); + message.Append(alertMessage); + + pJsonObj = new (std::nothrow) JsonObject(); + pJsonObj->Construct(); + + pKey1 = new (std::nothrow) JsonString(L"regID"); + pKey2 = new (std::nothrow) JsonString(L"requestID"); + pKey3 = new (std::nothrow) JsonString(L"message"); + pKey4 = new (std::nothrow) JsonString(L"appData"); + + SysLog(NID_MSG, "Address PushMessage [%x]", const_cast(&pushMessage)); + SysLog(NID_MSG, "Address RegistrationIdList [%x]", const_cast(®istrationIdList)); + + count = registrationIdList.GetCount(); + + if (count == 1) + { + pTempStr = (String*) (registrationIdList.GetAt(0)); + pValue1 = new (std::nothrow) JsonString(static_cast(pTempStr)->String::GetPointer()); + pJsonObj->Add(pKey1, pValue1); + + SysLog(NID_MSG, "####### JsonString %d #######", count); + } + else + { + pJsonArray = new (std::nothrow) JsonArray(); + pJsonArray->Construct(); + + for (int i = 0; i < count; i++) + { + pTempStr = (String*) (registrationIdList.GetAt(i)); + SysLog(NID_MSG, "pTempStr [%ls].", pTempStr->GetPointer()); + pValue1 = new (std::nothrow) JsonString(static_cast(pTempStr)->String::GetPointer()); + pJsonArray->Add(pValue1); + } + pJsonObj->Add(pKey1, pJsonArray); + + SysLog(NID_MSG, "####### JsonArray %d #######", count); + } + + pValue2 = new (std::nothrow) JsonString(reqId); + pValue3 = new (std::nothrow) JsonString(message); + pValue4 = new (std::nothrow) JsonString(appData); + + pJsonObj->Add(pKey2, pValue2); + pJsonObj->Add(pKey3, pValue3); + pJsonObj->Add(pKey4, pValue4); + + r = JsonWriter::Compose(pJsonObj, buffer); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to compose Json object.", GetErrorMessage(r)); + + SysLog(NID_MSG, "####### Request message : %s #######", buffer.GetPointer()); + + pJsonObj->RemoveAll(true); + delete pJsonObj; + + SysLog(NID_MSG, "The ComposeJsonObject is exiting with result[%s].", GetErrorMessage(r)); + + return r; + +CATCH: + if (pJsonObj) + { + pJsonObj->RemoveAll(true); + delete pJsonObj; + pJsonObj = null; + } + + return r; +} + +RequestId +_PushManagerImpl::GetNextRequestId(void) +{ + if (lastRequestId >= _MAX_PUSH_REQUEST_ID) + { + lastRequestId = _MIN_PUSH_REQUEST_ID; + } + + lastRequestId++; + + return lastRequestId; +} + +result +_PushManagerImpl::RequestPushRegistration(const _PushRequest* pRequest) +{ + SysLog(NID_MSG, "The RequestPushRegistration is entering."); + + result r = E_SUCCESS; + int ret = PUSH_ERROR_NONE; + char* pAppId = null; + service_h svc; + + ret = service_create(&svc); + SysTryReturnResult(NID_MSG, ret == SERVICE_ERROR_NONE, E_SYSTEM, "service_create() is failed[%d].", ret); + + AppId appId; + appId = _AppInfo::GetApplicationId(); + + pAppId = _StringConverter::CopyToCharArrayN(appId); + if (pAppId == null) + { + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "Memory allocation failed."); + service_destroy(svc); + + return E_OUT_OF_MEMORY; + } + + SysLog(NID_MSG, "AppId=[%s].", pAppId); + + ret = service_set_app_id(svc, pAppId); + delete[] pAppId; + if (ret != SERVICE_ERROR_NONE) + { + SysLogException(NID_MSG, E_SYSTEM, "[E_SYSTEM] service_set_package() is failed[%d].", ret); + service_destroy(svc); + + return E_SYSTEM; + } + + ret = push_register((push_connection_h)GetPushHandle(), svc, PushResultEventCallback, (void*)pRequest); + service_destroy(svc); + if (ret == PUSH_ERROR_NONE) + { + SysLog(NID_MSG, "push_register() is successful."); + UpdateActiveRequest(true); + } + else if (ret == PUSH_ERROR_OUT_OF_MEMORY) + { + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + r = E_OUT_OF_MEMORY; + } + else + { + SysLogException(NID_MSG, E_SYSTEM, "[E_SYSTEM] System error."); + r = E_SYSTEM; + } + + SysLog(NID_MSG, "The RequestPushRegistration is exiting with result[%s].", GetErrorMessage(r)); + + return r; +} + +result +_PushManagerImpl::RequestPushUnregistration(const _PushRequest* pRequest) +{ + SysLog(NID_MSG, "The RequestPushUnregistration is entering."); + + result r = E_SUCCESS; + int ret = PUSH_ERROR_NONE; + + ret = push_deregister((push_connection_h)GetPushHandle(), PushResultEventCallback, (void*)pRequest); + if (ret == PUSH_ERROR_NONE) + { + SysLog(NID_MSG, "push_deregister() is successful."); + UpdateActiveRequest(true); + } + else if (ret == PUSH_ERROR_OUT_OF_MEMORY) + { + SysLogException(NID_MSG, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + r = E_OUT_OF_MEMORY; + } + else + { + SysLogException(NID_MSG, E_SYSTEM, "[E_SYSTEM] System error."); + r = E_SYSTEM; + } + + SysLog(NID_MSG, "The RequestPushUnregistration is exiting with result[%s].", GetErrorMessage(r)); + + return r; +} + +result +_PushManagerImpl::RequestPushSendMessageSingle(_PushRequest* pRequest, const PushMessage& pushMessage, const String& registrationId) +{ + SysLog(NID_MSG, "The RequestPushSendMessageSingle is entering."); + + result r = E_SUCCESS; + String url(L""); + ArrayList registrationIdList; + + r = registrationIdList.Construct(); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "[%s] Failed to construct registration Id list.", GetErrorMessage(r)); + + registrationIdList.Add(registrationId); + + r = GetUrlFromRegistrationId(registrationId, pRequest, pushMessage, registrationIdList, url); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "[%s] Failed to get URL from registrionId.", GetErrorMessage(r)); + + if (url.IsEmpty() != true) + { + r = SendHttpRequest(url, pRequest, pushMessage, registrationIdList); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "[%s] Failed to submit http request.", GetErrorMessage(r)); + } + + SysLog(NID_MSG, "The RequestPushSendMessageSingle is exiting with result[%s].", GetErrorMessage(r)); + + return r; +} + +result +_PushManagerImpl::RequestPushSendMessageMultiple(_PushRequest* pRequest, const PushMessage& pushMessage, const IList& registrationIdList) +{ + SysLog(NID_MSG, "The RequestPushSendMessageMultiple is entering."); + + result r = E_SUCCESS; + + int count = 0; + int subCount = 0; + int num = 0; + String* pRegistrationId = null; + String url(L""); + String prefix(""); + ArrayList subRegistrationIdList; + + String* pKey = null; + Integer* pValue = null; + Object* pObj = null; + + MultiHashMap map; + map.Construct(); + + count = registrationIdList.GetCount(); + + for (int i = 0; i < count; i++) + { + pRegistrationId = (String*) (registrationIdList.GetAt(i)); + SysTryReturn(NID_MSG, pRegistrationId != null, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] A failure casting."); + + r = pRegistrationId->SubString(0,2, prefix); + SysTryReturn(NID_MSG, r == E_SUCCESS, E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the prefix from registration ID", GetErrorMessage(r)); + + r = map.Add(*(new String(prefix)), *(new Integer(i))); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A System error has occured."); + } + + IMapEnumerator* pMapEnum = map.GetMapEnumeratorN(); + while (pMapEnum->MoveNext() == E_SUCCESS) + { + pObj = pMapEnum->GetKey(); + pKey = static_cast (pMapEnum->GetKey()); + map.GetCount(*pObj, subCount); + + SysLog(NID_MSG, "Key : [%ls], subCount : [%d].", pKey->GetPointer(), subCount); + + r = subRegistrationIdList.Construct(); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "[%s] Failed to construct sub registration Id list.", GetErrorMessage(r)); + + IEnumerator* pEnum = map.GetValuesN(*pObj); + while (pEnum->MoveNext() == E_SUCCESS) + { + pValue = static_cast (pEnum->GetCurrent()); + + pRegistrationId = (String*) (registrationIdList.GetAt(pValue->ToInt())); + + SysLog(NID_MSG, "registrationId : [%ls].", pRegistrationId->GetPointer()); + + subRegistrationIdList.Add(*(registrationIdList.GetAt(pValue->ToInt()))); + + num++; + + SysLog(NID_MSG, "Key : [%ls], Value : [%d] Num : [%d].", pKey->GetPointer(), pValue->ToInt(), num); + } + delete pEnum; + + for(int j = 0; j < subCount - 1; j++) + { + r = pMapEnum->MoveNext(); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "A System error has occured."); + } + + pRegistrationId = (String*) (registrationIdList.GetAt(pValue->ToInt())); + r = GetUrlFromRegistrationId(*pRegistrationId, pRequest, pushMessage, subRegistrationIdList, url); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to get URL from registrionId.", GetErrorMessage(r)); + goto CATCH; + } + + if (url.IsEmpty() != true) + { + r = SendHttpRequest(url, pRequest, pushMessage, subRegistrationIdList); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to submit http request.", GetErrorMessage(r)); + goto CATCH; + } + } + + subRegistrationIdList.RemoveAll(); + + if (num >= count) + { + SysLog(NID_MSG, "Break num : [%d], count : [%d].", num, count); + break; + } + } + + delete pMapEnum; + + map.RemoveAll(true); + + SysLog(NID_MSG, "The RequestPushSendMessageMultiple is exiting with result[%s].", GetErrorMessage(r)); + + return r; + +CATCH: + return r; +} + +bool +_PushManagerImpl::GetLastPushStatus(void) const +{ + result r = E_SUCCESS; + Registry reg; + String regFile(Tizen::App::App::GetInstance()->GetAppRootPath() + _PUSH_STATUS_REGISTRY_FILE); + String section(_PUSH_STATUS_REGISTRY_STATUS_SECTION); + String entry(_PUSH_STATUS_REGISTRY_IS_REGISTERED_ENTRY); + int value = 0; + + if (true == File::IsFileExist(regFile)) + { + r = reg.Construct(regFile, false); + r = reg.GetValue(section, entry, value); + } + + return (bool)value; +} + +void +_PushManagerImpl::UpdateLastPushStatus(bool value) +{ + result r = E_SUCCESS; + Registry reg; + String regFile(Tizen::App::App::GetInstance()->GetAppRootPath() + _PUSH_STATUS_REGISTRY_FILE); + String section(_PUSH_STATUS_REGISTRY_STATUS_SECTION); + String entry(_PUSH_STATUS_REGISTRY_IS_REGISTERED_ENTRY); + + if (false == File::IsFileExist(regFile)) + { + r = reg.Construct(regFile, true); + r = reg.AddSection(section); + r = reg.AddValue(section, entry, (int)value); + r = reg.Flush(); + } + else + { + r = reg.Construct(regFile, false); + r = reg.SetValue(section, entry, (int)value); + if (r == E_SECTION_NOT_FOUND) + { + r = reg.AddSection(section); + r = reg.AddValue(section, entry, (int)value); + } + else if (r == E_KEY_NOT_FOUND) + { + r = reg.AddValue(section, entry, (int)value); + } + r = reg.Flush(); + } + + return; +} + +String +_PushManagerImpl::GetPushServerUrl(void) const +{ + result r = E_SUCCESS; + Registry reg; + String regFile(Tizen::App::App::GetInstance()->GetAppRootPath() + _PUSH_STATUS_REGISTRY_FILE); + String section(_PUSH_SERVER_REGISTRY_SERVER_SECTION); + String entry(_PUSH_SERVER_REGISTRY_URL_ENTRY); + String url(L""); + + if (true == File::IsFileExist(regFile)) + { + r = reg.Construct(regFile, false); + r = reg.GetValue(section, entry, url); + } + + return url; +} + +void +_PushManagerImpl::UpdatePushServerUrl(String& url) +{ + result r = E_SUCCESS; + Registry reg; + String regFile(Tizen::App::App::GetInstance()->GetAppRootPath() + _PUSH_STATUS_REGISTRY_FILE); + String section(_PUSH_SERVER_REGISTRY_SERVER_SECTION); + String entry(_PUSH_SERVER_REGISTRY_URL_ENTRY); + + if (false == File::IsFileExist(regFile)) + { + r = reg.Construct(regFile, true); + r = reg.AddSection(section); + r = reg.AddValue(section, entry, url); + r = reg.Flush(); + } + else + { + r = reg.Construct(regFile, false); + r = reg.SetValue(section, entry, url); + if (r == E_SECTION_NOT_FOUND) + { + r = reg.AddSection(section); + r = reg.AddValue(section, entry, url); + } + else if (r == E_KEY_NOT_FOUND) + { + r = reg.AddValue(section, entry, url); + } + r = reg.Flush(); + } +} +} } // Osp::Messaging diff --git a/src/FMsg_PushManagerImpl.h b/src/FMsg_PushManagerImpl.h new file mode 100755 index 0000000..0291c99 --- /dev/null +++ b/src/FMsg_PushManagerImpl.h @@ -0,0 +1,240 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushManagerImpl.h + * @brief This is the header file for the %_PushManagerImpl class. + * + * This header file contains the declarations of the %_PushManagerImpl class. + */ + +#ifndef _FMSG_INTERNAL_PUSH_MANAGER_IMPL_H_ +#define _FMSG_INTERNAL_PUSH_MANAGER_IMPL_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_PushRequest.h" +#include "FMsg_PushSendListener.h" +#include "FMsg_PushUrlRequestListener.h" + +namespace Tizen { namespace Base +{ +class String; +} } // Tizen::Base + +namespace Tizen { namespace Base { namespace Collection +{ +class IList; +} } } // Tizen::Base::Collection + +namespace Tizen { namespace Net { namespace Http +{ +class HttpHeader; +class HttpRequest; +class HttpSession; +class HttpTransaction; +} } } // Tizen::Net::Http + +namespace Tizen { namespace Messaging +{ +class PushManager; +class IPushManagerListener; +class IPushEventListener; +class _PushEvent; +class _PushEventArg; +class _PushRequest; + +/** + * @class _PushManagerImpl + * @brief This class represents an implementation of %PushManager class. + * + * @since 2.1 + * + * This class represents an implementation of %PushManager class. + * + * @see PushManager + */ +class _PushManagerImpl + : public Tizen::Base::Object +{ +public: + /** + * This is the default constructor for this class. + * + * @since 2.1 + * @remarks After creating an instance of this class, you must explicitly call the + * Construct() method to initialize the instance. + * @see Construct() + */ + _PushManagerImpl(void); + + /** + * This is the destructor for this class. + * + * @since 2.1 + */ + virtual ~_PushManagerImpl(void); + +public: + /** + * @see PushManager::Construct() + */ + result Construct(IPushManagerListener& managerListener, IPushEventListener& eventListener); + + /** + * @see PushManager::RegisterPushService() + */ + result RegisterPushService(RequestId& reqId); + + /** + * @see PushManager::UnregisterPushService() + */ + result UnregisterPushService(RequestId& reqId); + + /** + * @see PushManager::IsPushServiceRegistered() + */ + bool IsPushServiceRegistered(void) const; + + /** + * @see PushManager::GetUnreadMessagesN() + */ + Tizen::Base::Collection::IList* GetUnreadMessagesN(void); + + /** + * @see PushManager::SendPushMessage() + */ + result SendPushMessage(const PushMessage& message, const Tizen::Base::String& registrationId, const Tizen::Base::String& appSecret, RequestId& reqId); + + /** + * @see PushManager::SendPushMessage() + */ + result SendPushMessage(const PushMessage& message, const Tizen::Base::Collection::IList& registrationIdList, const Tizen::Base::String& appSecre, RequestId& reqId); + + /** + * @see PushManager::GetMaxRecipientCount() + */ + static int GetMaxRecipientCount(void); + +public: + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _PushManagerImpl + * @param[in] pushManager An instance of PushManager + */ + static _PushManagerImpl* GetInstance(PushManager& pushManager); + + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _PushManagerImpl + * @param[in] pushManager An instance of PushManager + */ + static const _PushManagerImpl* GetInstance(const PushManager& pushManager); + +public: + void HandlePushEvent(_PushEventArg& eventArg); + void HandlePushRegistrationResponse(RequestId reqId, const Tizen::Base::String& registrationId, result r); + void HandlePushUnregistrationResponse(RequestId reqId, result r); + void HandlePushMessage(const Tizen::Base::String& notiMessage, const Tizen::Base::String& payload); + void HandlePushSendMessageResponse(RequestId reqId, const Tizen::Base::String& registrationId, result r, const Tizen::Base::String& errorCode, const Tizen::Base::String& errorMsg); + + void SetPushStatus(bool isRegistered, const Tizen::Base::String& registrationId); + bool GetPushStatus(void) const; + Tizen::Base::String GetRegistrationId(void) const; + + void* GetPushHandle(void) const; + void SetPushHandleReady(void); + bool IsPushHandleReady(void) const; + + _PushRequest* AddRequest(RequestId reqId, _PushRequestType type); + _PushRequest* GetNextRequest(void); + void RemoveRequest(_PushRequest* pRequest); + bool HasPendingRequest(void) const; + bool HasActiveRequest(void) const; + void UpdateActiveRequest(bool hasActiveRequest); + void CheckNextRequest(void); + + Tizen::Base::String GetAppSecret(void) const; + result GetUrlFromRegistrationId(const Tizen::Base::String& registrationId, _PushRequest* pRequest, const PushMessage& pushMessage, const Tizen::Base::Collection::IList& registrationIdList, Tizen::Base::String& url); + result QueryServerUrl(const Tizen::Base::String& prefix, _PushRequest* pRequest, const PushMessage& pushMessage, const Tizen::Base::Collection::IList& registrationIdList); + result SendHttpRequest(const Tizen::Base::String& url, _PushRequest* pRequest, const PushMessage& pushMessage, const Tizen::Base::Collection::IList& registrationIdList); + result ComposeJsonObject(const _PushRequest* pRequest, const PushMessage& pushMessage, const Tizen::Base::Collection::IList& registrationIdList, Tizen::Base::ByteBuffer& buffer) const; + +private: + static RequestId GetNextRequestId(void); + +private: + result RequestPushRegistration(const _PushRequest* pRequest); + result RequestPushUnregistration(const _PushRequest* pRequest); + result RequestPushSendMessageSingle(_PushRequest* pRequest, const PushMessage& message, const Tizen::Base::String& registrationId); + result RequestPushSendMessageMultiple(_PushRequest* pRequest, const PushMessage& message, const Tizen::Base::Collection::IList& registrationIdList); + + bool GetLastPushStatus(void) const; + void UpdateLastPushStatus(bool value); + + Tizen::Base::String GetPushServerUrl(void) const; + void UpdatePushServerUrl(Tizen::Base::String& url); + +private: + /** + * This is the copy constructor for this class. + * + * @param[in] rhs An instance of _PushManagerImpl + */ + _PushManagerImpl(const _PushManagerImpl& rhs); + + /** + * This is the assignment operator. + * + * @param[in] rhs An instance of _PushManagerImpl + */ + _PushManagerImpl& operator =(const _PushManagerImpl& rhs); + +private: + IPushManagerListener* __pManagerListener; + IPushEventListener* __pEventListener; + _PushEvent* __pEvent; + Tizen::Net::Http::HttpHeader* __pHeader; + Tizen::Net::Http::HttpSession* __pSession; + Tizen::Net::Http::HttpRequest* __pRequest; + Tizen::Net::Http::HttpTransaction* __pTransaction; + Tizen::Base::ByteBuffer* __pBody; + _PushSendListener* __pListener; + _PushUrlRequestListener* __pUrlListener; + Tizen::Base::String __appSecret; + bool __isRegistered; + Tizen::Base::String __registrationId; + Tizen::Base::Collection::ArrayList* __pRequestList; + bool __hasActiveRequest; + void* __pPushHandle; + bool __isPushHandleReady; + + friend class _PushUrlRequestListener; +}; // _PushManagerImpl + +} } // Tizen::Messaging +#endif // _FMSG_INTERNAL_PUSH_MANAGER_IMPL_H_ diff --git a/src/FMsg_PushMessageImpl.cpp b/src/FMsg_PushMessageImpl.cpp new file mode 100755 index 0000000..10df019 --- /dev/null +++ b/src/FMsg_PushMessageImpl.cpp @@ -0,0 +1,349 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** +* @file FMsg_PushMessageImpl.cpp +* @brief This is the implementation file for the %_PushMessageImpl class. +* +* This file contains the implementation of the %_PushMessageImpl class. +*/ + +#include +#include +#include +#include +#include +#include "FMsg_PushMessageImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::Shell; + +static const int _HASH_CODE_INITIAL_VALUE = 17; +static const int _HASH_CODE_COEFFICIENT_VALUE = 37; +static const wchar_t _PUSH_MESSAGE_TOKEN_DELIMITER[] = L"&"; +static const wchar_t _PUSH_MESSAGE_KEY_VALUE_DELIMITER[] = L"="; +static const wchar_t _PUSH_MESSAGE_KEY_BADGE_OPTION[] = L"badgeOption"; +static const wchar_t _PUSH_MESSAGE_KEY_BADGE_NUMBER[] = L"badgeNumber"; +static const wchar_t _PUSH_MESSAGE_KEY_ACTION[] = L"action"; +static const wchar_t _PUSH_MESSAGE_KEY_ALERT_MESSAGE[] = L"alertMessage"; +static const wchar_t _PUSH_MESSAGE_VALUE_BADGE_SET[] = L"SET"; +static const wchar_t _PUSH_MESSAGE_VALUE_BADGE_INCREASE[] = L"INCREASE"; +static const wchar_t _PUSH_MESSAGE_VALUE_BADGE_DECREASE[] = L"DECREASE"; +static const wchar_t _PUSH_MESSAGE_VALUE_ACTION_SILENT[] = L"SILENT"; +static const wchar_t _PUSH_MESSAGE_VALUE_ACTION_DISCARD[] = L"DISCARD"; +static const wchar_t _PUSH_MESSAGE_VALUE_ACTION_ALERT[] = L"ALERT"; +static const wchar_t _PUSH_MESSAGE_VALUE_ACTION_LAUNCH[] = L"LAUNCH"; + + +namespace Tizen { namespace Messaging +{ + +_PushMessageImpl::_PushMessageImpl(void) + : __dateTime() + , __text(null) + , __pushAction(PUSH_ACTION_SILENT) + , __notiMessage() +{ +} + +_PushMessageImpl::_PushMessageImpl(const DateTime& dateTime, const String& text) + : __pushAction(PUSH_ACTION_SILENT) + , __notiMessage() +{ + __dateTime = dateTime; + __text = text; +} + +_PushMessageImpl::~_PushMessageImpl(void) +{ +} + +_PushMessageImpl::_PushMessageImpl(const _PushMessageImpl& rhs) +{ + __dateTime = rhs.__dateTime; + __text = rhs.__text; + __pushAction = rhs.__pushAction; + __notiMessage = rhs.__notiMessage; +} + +_PushMessageImpl& +_PushMessageImpl::operator =(const _PushMessageImpl& rhs) +{ + if (this == &rhs) + { + return *this; + } + + __dateTime = rhs.__dateTime; + __text = rhs.__text; + __pushAction = rhs.__pushAction; + __notiMessage = rhs.__notiMessage; + + return *this; +} + +bool +_PushMessageImpl::Equals(const Object& obj) const +{ + const _PushMessageImpl* pRhs = dynamic_cast(&obj); + + if (pRhs == null) + { + return false; + } + + if (__dateTime != pRhs->__dateTime) + { + return false; + } + + if (__text != pRhs->__text) + { + return false; + } + + if (__pushAction != pRhs->__pushAction) + { + return false; + } + + if (__notiMessage.Equals(pRhs->__notiMessage) != true) + { + return false; + } + + return true; +} + +int +_PushMessageImpl::GetHashCode(void) const +{ + int hashCode = _HASH_CODE_INITIAL_VALUE; + + hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __dateTime.GetHashCode(); + hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + Integer(__pushAction).GetHashCode(); + hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __notiMessage.GetHashCode(); + + return hashCode; +} + +DateTime +_PushMessageImpl::GetReceivedTime(void) const +{ + return __dateTime; +} + +String +_PushMessageImpl::GetText(void) const +{ + return __text; +} + +result +_PushMessageImpl::SetAction(PushAction action) +{ + result r = E_SUCCESS; + SysTryReturn(NID_NET_SOCK, (action >= PUSH_ACTION_SILENT && action <= PUSH_ACTION_LAUNCH), r = E_INVALID_ARG, E_INVALID_ARG, + "[E_INVALID_ARG] Invalid PushAction [%d] argument.", (int)action); + + __pushAction = action; + + return r; +} + +PushAction +_PushMessageImpl::GetAction(void) const +{ + return __pushAction; +} + +result +_PushMessageImpl::SetNotification(const NotificationRequest& notificationMessage) +{ + result r = E_SUCCESS; + + __notiMessage = notificationMessage; + __text = notificationMessage.GetAppMessage(); + + SysLog(NID_MSG, "Set NotificationRequest : action[%d]", __pushAction); + SysLog(NID_MSG, "Set NotificationRequest : badgeOffset[%d], badgeNumber[%d]", notificationMessage.GetBadgeOffset(), notificationMessage.GetBadgeNumber()); + SysLog(NID_MSG, "Set NotificationRequest : alertText[%ls], appMessage[%ls]", (notificationMessage.GetAlertText()).GetPointer(), (notificationMessage.GetAppMessage()).GetPointer()); + + return r; +} + +NotificationRequest +_PushMessageImpl::GetNotification(void) const +{ + return __notiMessage; +} + +PushMessage* +_PushMessageImpl::CreatePushMessageN(const DateTime& dateTime, const String& text) +{ + return new (std::nothrow) PushMessage(dateTime, text); +} + +DateTime +_PushMessageImpl::ConvertTime(long long int time) +{ + DateTime dateTime; + struct tm gmTime; + + gmtime_r((time_t*)&time, &gmTime); + dateTime.SetValue(gmTime.tm_year + 1900, gmTime.tm_mon + 1, gmTime.tm_mday, gmTime.tm_hour, gmTime.tm_min, gmTime.tm_sec); + + return dateTime; +} + +void +_PushMessageImpl::ConvertMessageToNotification(const String& message) +{ + result r = E_SUCCESS; + int badgeNumber = 0; + String badgeValue; + String alertText; + + SysLog(NID_MSG, "Set notification with message[%ls]", message.GetPointer()); + + r = __notiMessage.SetAppMessage(__text); + + StringTokenizer tokens(message, _PUSH_MESSAGE_TOKEN_DELIMITER); + + while (tokens.HasMoreTokens() == true) + { + String token; + String key; + String value; + int delimiterIndex; + + tokens.GetNextToken(token); + + r = token.IndexOf(_PUSH_MESSAGE_KEY_VALUE_DELIMITER, 0, delimiterIndex); + if(IsFailed(r)) + continue; + + r = token.SubString(0, delimiterIndex, key); + if (IsFailed(r)) + continue; + + r = token.SubString(delimiterIndex + 1, token.GetLength() - delimiterIndex - 1, value); + if (IsFailed(r)) + continue; + + if ((key.IsEmpty() == true) || (value.IsEmpty() == true)) + continue; + + if (key.Equals(_PUSH_MESSAGE_KEY_BADGE_OPTION, false) == true) + { + badgeValue = value; + } + else if (key.Equals(_PUSH_MESSAGE_KEY_BADGE_NUMBER, false) == true) + { + r = Integer::Parse(value, badgeNumber); + if (IsFailed(r)) + continue; + + if (badgeNumber < 0) + { + SysLog(NID_MSG, "badgeNumber[%d] is negative, so treat it as '0'", badgeNumber); + badgeNumber = 0; + } + + if (badgeNumber > MAX_NOTIFICATION_BADGE_NUMBER) + { + SysLog(NID_MSG, "badgeNumber[%d] is out of range, so treat it as '%d'", badgeNumber, MAX_NOTIFICATION_BADGE_NUMBER); + badgeNumber = MAX_NOTIFICATION_BADGE_NUMBER; + } + } + else if (key.Equals(_PUSH_MESSAGE_KEY_ACTION, false) == true) + { + if (value.Equals(_PUSH_MESSAGE_VALUE_ACTION_ALERT, false) == true) + { + __pushAction = PUSH_ACTION_ALERT; + } + else if (value.Equals(_PUSH_MESSAGE_VALUE_ACTION_SILENT, false) == true) + { + __pushAction = PUSH_ACTION_SILENT; + } + else if (value.Equals(_PUSH_MESSAGE_VALUE_ACTION_DISCARD, false) == true) + { + __pushAction = PUSH_ACTION_DISCARD; + } + else if (value.Equals(_PUSH_MESSAGE_VALUE_ACTION_LAUNCH, false) == true) + { + __pushAction = PUSH_ACTION_LAUNCH; + } + else + { + __pushAction = PUSH_ACTION_SILENT; + } + } + else if (key.Equals(_PUSH_MESSAGE_KEY_ALERT_MESSAGE, false) == true) + { + r = UrlDecoder::Decode(value, L"UTF-8", alertText); + if (IsFailed(r)) + continue; + + r = __notiMessage.SetAlertText(alertText); + if (IsFailed(r)) + continue; + + SysLog(NID_MSG, "AlertText - Original[%ls] Decoded[%ls] result[%s]", value.GetPointer(), alertText.GetPointer(), GetErrorMessage(r)); + } + else + { + SysLog(NID_MSG, "Ignore UnKnown option[%ls]", key.GetPointer()); + } + } + + + if (badgeValue.Equals(_PUSH_MESSAGE_VALUE_BADGE_SET, false) == true) + { + r = __notiMessage.SetBadgeNumber(badgeNumber); + SysLog(NID_MSG, "Set badgeNumber[%d] result[%s]", badgeNumber, GetErrorMessage(r)); + } + else if (badgeValue.Equals(_PUSH_MESSAGE_VALUE_BADGE_INCREASE, false) == true) + { + r = __notiMessage.SetBadgeOffset(badgeNumber); + SysLog(NID_MSG, "Set badgeOffset[%d] result[%s]", badgeNumber, GetErrorMessage(r)); + } + else if (badgeValue.Equals(_PUSH_MESSAGE_VALUE_BADGE_DECREASE, false) == true) + { + r = __notiMessage.SetBadgeOffset(-badgeNumber); + SysLog(NID_MSG, "Set badgeOffset[%d] result[%s]", badgeNumber, GetErrorMessage(r)); + } + + SysLog(NID_MSG, "The converted value of action is [%d].", __pushAction); + SysLog(NID_MSG, "The converted value of badgeOffset is [%d], badgeNumber is [%d].", __notiMessage.GetBadgeOffset(), __notiMessage.GetBadgeNumber()); + SysLog(NID_MSG, "The converted value of alertText is [%ls], appMessage is [%ls].", (__notiMessage.GetAlertText()).GetPointer(), (__notiMessage.GetAppMessage()).GetPointer()); +} + +_PushMessageImpl* +_PushMessageImpl::GetInstance(PushMessage& pushMessage) +{ + return pushMessage.__pPushMessageImpl; +} + +const _PushMessageImpl* +_PushMessageImpl::GetInstance(const PushMessage& pushMessage) +{ + return pushMessage.__pPushMessageImpl; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_PushMessageImpl.h b/src/FMsg_PushMessageImpl.h new file mode 100644 index 0000000..0746c64 --- /dev/null +++ b/src/FMsg_PushMessageImpl.h @@ -0,0 +1,158 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushMessageImpl.h + * @brief This is the header file for the %_PushMessageImpl class. + * + * This header file contains the declarations of the %_PushMessageImpl class. + */ + +#ifndef _FMSG_INTERNAL_PUSH_MESSAGE_IMPL_H_ +#define _FMSG_INTERNAL_PUSH_MESSAGE_IMPL_H_ + +#include +#include +#include +#include +#include + +namespace Tizen { namespace Messaging +{ +class PushMessage; + +/** + * @class _PushMessageImpl + * @brief This class represents an implementation of %PushMessage class. + * + * @since 2.1 + * + * This class represents an implementation of %PushMessage class. + * + * @see PushMessage + */ +class _PushMessageImpl + : public Tizen::Base::Object +{ +public: + /** + * This is the default constructor for this class. + * + * @since 2.1 + */ + _PushMessageImpl(void); + + /** + * This is the constructor for this class. + * + * @since 2.1 + */ + _PushMessageImpl(const Tizen::Base::DateTime& dateTime, const Tizen::Base::String& text); + + /** + * This is the destructor for this class. + * + * @since 2.1 + */ + virtual ~_PushMessageImpl(void); + + /** + * This is the copy constructor for this class. + * + * @param[in] rhs An instance of _PushMessageImpl + */ + _PushMessageImpl(const _PushMessageImpl& rhs); + + /** + * This is the assignment operator. + * + * @param[in] rhs An instance of _PushMessageImpl + */ + _PushMessageImpl& operator =(const _PushMessageImpl& rhs); + + /** + * @see PushMessage::Equals() + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * @see PushMessage::GetHashCode() + */ + virtual int GetHashCode(void) const; + +public: + /** + * @see PushMessage::GetReceivedTime() + */ + Tizen::Base::DateTime GetReceivedTime(void) const; + + /** + * @see PushMessage::GetText() + */ + Tizen::Base::String GetText(void) const; + + /** + * @see PushMessage::SetAction() + */ + result SetAction(PushAction action); + + /** + * @see PushMessage::GetAction() + */ + PushAction GetAction(void) const; + + /** + * @see PushMessage::SetNotification() + */ + result SetNotification(const Tizen::Shell::NotificationRequest& notificationMessage); + + /** + * @see PushMessage::GetNotification() + */ + Tizen::Shell::NotificationRequest GetNotification(void) const; + + static PushMessage* CreatePushMessageN(const Tizen::Base::DateTime& dateTime, const Tizen::Base::String& text); + static Tizen::Base::DateTime ConvertTime(long long int time); + void ConvertMessageToNotification(const Tizen::Base::String& message); + +public: + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _PushMessageImpl + * @param[in] pushMessage An instance of PushMessage + */ + static _PushMessageImpl* GetInstance(PushMessage& pushMessage); + + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _PushMessageImpl + * @param[in] pushMessage An instance of PushMessage + */ + static const _PushMessageImpl* GetInstance(const PushMessage& pushMessage); + +private: + Tizen::Base::DateTime __dateTime; + Tizen::Base::String __text; + PushAction __pushAction; + Tizen::Shell::NotificationRequest __notiMessage; +}; // _PushMessageImpl + +} } // Tizen::Messaging +#endif // _FMSG_INTERNAL_PUSH_MESSAGE_IMPL_H_ diff --git a/src/FMsg_PushRequest.cpp b/src/FMsg_PushRequest.cpp new file mode 100755 index 0000000..06e69ce --- /dev/null +++ b/src/FMsg_PushRequest.cpp @@ -0,0 +1,82 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushRequest.cpp + * @brief This is the implementation file for %_PushRequest class. + * + * This file contains implementation of _PushRequest class. + */ +#include +#include "FMsg_PushManagerImpl.h" +#include "FMsg_PushRequest.h" + +using namespace Tizen::Base; + +namespace Tizen { namespace Messaging +{ + +_PushRequest::_PushRequest(_PushManagerImpl* pPushManager, RequestId reqId, _PushRequestType type) + : __pPushManager(pPushManager) + , __reqId(reqId) + , __type(type) + , __refCount(0) +{ +} + +_PushRequest::~_PushRequest(void) +{ +} + +_PushManagerImpl* +_PushRequest::GetPushManager(void) const +{ + return __pPushManager; +} + +RequestId +_PushRequest::GetRequestId(void) const +{ + return __reqId; +} + +_PushRequestType +_PushRequest::GetType(void) const +{ + return __type; +} + +void +_PushRequest::AddRef(void) +{ + __refCount++; + SysLog(NID_MSG, "The reference count is %d", __refCount); +} + +void +_PushRequest::Release(void) +{ + __refCount--; + SysLog(NID_MSG, "The reference count is %d", __refCount); + + if(__refCount == 0) + { + SysLog(NID_MSG,"The reference count is 0, so delete _PushRequest"); + delete this; + } +} + +} } // Tizen::Messaging diff --git a/src/FMsg_PushRequest.h b/src/FMsg_PushRequest.h new file mode 100755 index 0000000..45f7c34 --- /dev/null +++ b/src/FMsg_PushRequest.h @@ -0,0 +1,68 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushRequest.h + * @brief This is the header file for %_PushRequest class. + * + * This file contains declarations of _PushRequest class. + */ + +#ifndef _FMSG_INTERNAL_PUSH_REQUEST_H_ +#define _FMSG_INTERNAL_PUSH_REQUEST_H_ + +#include +#include + +namespace Tizen { namespace Messaging +{ +enum _PushRequestType +{ + _PUSH_REQUEST_REGISTER = 0, + _PUSH_REQUEST_UNREGISTER, + _PUSH_REQUEST_SEND +}; + +class _PushManagerImpl; + +class _PushRequest + : public Tizen::Base::Object +{ +public: + _PushRequest(_PushManagerImpl* pPushManager, RequestId reqId, _PushRequestType type); + virtual ~_PushRequest(void); + + _PushManagerImpl* GetPushManager(void) const; + RequestId GetRequestId(void) const; + _PushRequestType GetType(void) const; + void AddRef(void); + void Release(void); + +private: + _PushRequest(void); + _PushRequest(const _PushRequest& rhs); + _PushRequest& operator =(const _PushRequest& rhs); + +private: + _PushManagerImpl* __pPushManager; + RequestId __reqId; + _PushRequestType __type; + int __refCount; +}; // _PushRequest + +} } // Tizen::Messaging + +#endif // _FMSG_INTERNAL_PUSH_REQUEST_H_ diff --git a/src/FMsg_PushSendListener.cpp b/src/FMsg_PushSendListener.cpp new file mode 100755 index 0000000..8c95d2b --- /dev/null +++ b/src/FMsg_PushSendListener.cpp @@ -0,0 +1,295 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushSendListener.cpp + * @brief This is the implementation file for %_PushSendListener class. + * + * This file contains implementation of _PushSendListener class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_PushSendListener.h" +#include "FMsg_PushManagerImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Net::Http; +using namespace Tizen::Web::Json; + +namespace Tizen { namespace Messaging +{ + +_PushSendListener::_PushSendListener(void) +{ +} + +_PushSendListener::~_PushSendListener(void) +{ + +} + +void +_PushSendListener::OnTransactionReadyToRead(HttpSession& httpSession, HttpTransaction& httpTransaction, int availableBodyLen) +{ + SysLog(NID_MSG, "####### OnTransactionReadyToRead! #######"); + +} + +void +_PushSendListener::OnTransactionAborted(HttpSession& httpSession, HttpTransaction& httpTransaction, result r) +{ + SysLog(NID_MSG, "####### OnTransactionAborted! (%s)#######", GetErrorMessage(r)); + + result res = E_CONNECTION_FAILED; + _PushManagerImpl* pManager = null; + String errorCode(L""); + String errorMsg(L""); + + _SendUserData* pUserData = dynamic_cast<_SendUserData*> (httpTransaction.GetUserObject()); + SysTryReturnVoidResult(NID_MSG, pUserData != null, E_SYSTEM, "[E_SYSTEM] Failed to cast user data."); + + pManager = (pUserData->GetPushRequest())->GetPushManager(); + SysTryReturnVoidResult(NID_MSG, pManager != null, E_SYSTEM, "[E_SYSTEM] A _PushManagerImpl is NULL."); + + if ((pUserData->GetPushRequest())->GetType() == _PUSH_REQUEST_SEND) + { + // Push Send Message Request + pManager->HandlePushSendMessageResponse((pUserData->GetPushRequest())->GetRequestId(), pManager->GetRegistrationId(), res, errorCode, errorMsg); + } + + delete pUserData; + delete &httpTransaction; +} + +void +_PushSendListener::OnTransactionReadyToWrite(HttpSession& httpSession, HttpTransaction& httpTransaction, int recommendedChunkSize) +{ + SysLog(NID_MSG, "####### OnTransactionReadyToWrite! #######"); +} + +void +_PushSendListener::OnTransactionHeaderCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction, int headerLen, bool rs) +{ + SysLog(NID_MSG, "####### OnTransactionHeaderCompleted! #######"); +} + +void +_PushSendListener::OnTransactionCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction) +{ + SysLog(NID_MSG, "####### OnTransactionCompleted! #######"); + + HttpResponse* pResponse = httpTransaction.GetResponse(); + SysTryReturnVoidResult(NID_MSG, pResponse != null, E_SYSTEM, "[E_SYSTEM] HttpResponse is invalid."); + + _SendUserData* pUserData = dynamic_cast<_SendUserData*> (httpTransaction.GetUserObject()); + SysTryReturnVoidResult(NID_MSG, pUserData != null, E_SYSTEM, "[E_SYSTEM] Failed to cast user data."); + + result r = E_SUCCESS; + _PushManagerImpl* pManager = null; + String registrationId(L""); + String errorCode(L""); + String errorMsg(L""); + ByteBuffer* pBody = null; + IJsonValue* pJsonVal = null; + IJsonValue* pRootValue = null; + IJsonValue* pEntryValue = null; + IJsonValue* pValue1 = null; + IJsonValue* pValue2 = null; + IJsonValue* pValue3 = null; + JsonObject* pJsonObj = null; + JsonObject* pJsonObj1 = null; + JsonArray* pJsonArr = null; + String key(L"results"); + String key1(L"regID"); + String key2(L"statusCode"); + String key3(L"statusMsg"); + JsonString* pStrValue1 = null; + JsonNumber* pNumValue2 = null; + JsonString* pStrValue3 = null; + String str1(L""); + String str2(L""); + String str3(L""); + int size = 0; + int listSize = 0; + + pBody = pResponse->ReadBodyN(); + SysTryCatch(NID_MSG, pBody != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to read body."); + + SysLog(NID_MSG, "####### Body message : [%s] #######", pBody->GetPointer()); + + size = pBody->GetLimit(); + SysLog(NID_MSG, "####### Body message size : [%d] #######", size); + + pJsonVal = JsonParser::ParseN(*pBody); + SysTryCatch(NID_MSG, pJsonVal != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to parse to json."); + + pJsonObj = static_cast(pJsonVal); + pJsonObj->GetValue(&key, pRootValue); + + pJsonArr = static_cast(pRootValue); + listSize = pJsonArr->GetCount(); + + SysLog(NID_MSG, "Response Json count : [%d] #######", listSize); + + for(int i = 0; i < listSize; i++) + { + pJsonArr->GetAt(i, pEntryValue); + + pJsonObj1 = static_cast(pEntryValue); + pJsonObj1->GetValue(&key1, pValue1); + pJsonObj1->GetValue(&key2, pValue2); + pJsonObj1->GetValue(&key3, pValue3); + + pStrValue1 = static_cast(pValue1); + pNumValue2 = static_cast(pValue2); + pStrValue3 = static_cast(pValue3); + + str1.Append(*((String*)pStrValue1)); + str2.Append(((Double*)pNumValue2)->ToInt()); + str3.Append(*((String*)pStrValue3)); + + registrationId = str1; + errorCode = str2; + errorMsg = str3; + + str1.Clear(); + str2.Clear(); + str3.Clear(); + + SysLog(NID_MSG, "The current value of registrationId is %ls.", registrationId.GetPointer()); + SysLog(NID_MSG, "The current value of errorCode is %ls.", errorCode.GetPointer()); + SysLog(NID_MSG, "The current value of errorMsg is %ls.", errorMsg.GetPointer()); + + pManager = (pUserData->GetPushRequest())->GetPushManager(); + SysTryCatch(NID_MSG, pManager != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A _PushManagerImpl is NULL."); + + if (pResponse->GetHttpStatusCode() != HTTP_STATUS_OK) + { + r = E_CONNECTION_FAILED; + SysLog(NID_MSG, "[E_CONNECTION_FAILED] HttpResponse status code is not OK."); + } + else + { + SysLog(NID_MSG, "[E_SUCCESS] HttpResponse status code is OK."); + + if (errorCode.Equals(L"1000", false)) + { + // Success + r = E_SUCCESS; + SysLog(NID_MSG, "[E_SUCCESS] Success."); + } + else if (errorCode.Equals(L"3008", false)) + { + // error of not registered regID + r = E_CONNECTION_FAILED; + SysLog(NID_MSG, "[E_HOST_NOT_FOUND] Error of not registered regID."); + } + else if (errorCode.Equals(L"3009", false)) + { + // error of not registered appID + r = E_SERVICE_UNAVAILABLE; + SysLog(NID_MSG, "[E_SERVICE_UNAVAILABLE] Error of not registered appID."); + } + else if (errorCode.Equals(L"3045", false)) + { + // error of application authentication failed + r = E_AUTHENTICATION; + SysLog(NID_MSG, "[E_AUTHENTICATION] Error of application authentication failed."); + } + else + { + // TODO : Convert Error Code from Server + r = E_SERVER; + SysLog(NID_MSG, "[E_SERVER] Error of something wrong."); + } + } + + if ((pUserData->GetPushRequest())->GetType() == _PUSH_REQUEST_SEND) + { + // Push Send Message Request + pManager->HandlePushSendMessageResponse((pUserData->GetPushRequest())->GetRequestId(), registrationId, r, errorCode, errorMsg); + + } + } + + delete pBody; + delete pJsonVal; + delete pUserData; + delete &httpTransaction; + + return; + +CATCH: + if (pBody) + { + delete pBody; + pBody = null; + } + + if (pJsonVal) + { + delete pJsonVal; + pJsonVal = null; + } + + if (pUserData) + { + delete pUserData; + pUserData = null; + } + + return; +} + +void +_PushSendListener::OnTransactionCertVerificationRequiredN(HttpSession& httpSession, HttpTransaction& httpTransaction, Tizen::Base::String* pCert) +{ + SysLog(NID_MSG, "####### OnTransactionCertVerificationRequiredN! #######"); + + result r = httpTransaction.Resume(); + SysTryReturnVoidResult(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, "[E_SYSTEM] http transaction resume."); + + delete pCert; + + return; +} + +_SendUserData::_SendUserData(_PushRequest* pPushRequest) + : __pPushRequest(pPushRequest) +{ + __pPushRequest->AddRef(); +} + +_SendUserData::~_SendUserData(void) +{ + __pPushRequest->Release(); +} + +_PushRequest* +_SendUserData::GetPushRequest(void) +{ + return __pPushRequest; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_PushSendListener.h b/src/FMsg_PushSendListener.h new file mode 100755 index 0000000..1b4dded --- /dev/null +++ b/src/FMsg_PushSendListener.h @@ -0,0 +1,83 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushSendListener.h + * @brief This is the header file for %_PushSendListener class. + * + * This file contains declarations of _PushSendListener class. + */ + +#ifndef _FMSG_INTERNAL_PUSH_SEND_LISTENER_H_ +#define _FMSG_INTERNAL_PUSH_SEND_LISTENER_H_ + + +#include +#include "FMsg_PushRequest.h" + +namespace Tizen { namespace Messaging +{ + +class _PushSendListener + : public Tizen::Net::Http::IHttpTransactionEventListener +{ + +public: + _PushSendListener(void); + virtual ~_PushSendListener(void); + +public: + + void OnTransactionReadyToRead(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction, int availableBodyLen); + + void OnTransactionAborted(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction, result r); + + void OnTransactionReadyToWrite(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction, int recommendedChunkSize); + + void OnTransactionHeaderCompleted(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction, int headerLen, bool rs); + + void OnTransactionCompleted(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction); + + void OnTransactionCertVerificationRequiredN(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction, Tizen::Base::String* pCert); + +private: + _PushSendListener(const _PushSendListener& rhs); + _PushSendListener& operator =(const _PushSendListener& rhs); + +}; + +// _PushSendListener +class _SendUserData + : public Tizen::Base::Object +{ +public: + _SendUserData(_PushRequest *pPushRequest); + virtual ~_SendUserData(void); + +public: + _PushRequest* GetPushRequest(void); + +private: + _SendUserData(const _SendUserData& rhs); + _SendUserData& operator =(const _SendUserData& rhs); + +private: + _PushRequest* __pPushRequest; + }; // _UserData + +} } // Tizen::Messaging + +#endif // _FMSG_INTERNAL_PUSH_SEND_LISTENER_H_ diff --git a/src/FMsg_PushUrlRequestListener.cpp b/src/FMsg_PushUrlRequestListener.cpp new file mode 100755 index 0000000..0d50b32 --- /dev/null +++ b/src/FMsg_PushUrlRequestListener.cpp @@ -0,0 +1,234 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushUrlRequestListener.cpp + * @brief This is the implementation file for %_PushUrlRequestListener class. + * + * This file contains implementation of _PushUrlRequestListener class. + */ + +#include +#include +#include +#include +#include +#include "FMsg_PushUrlRequestListener.h" +#include "FMsg_PushManagerImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Utility; +using namespace Tizen::Net::Http; + +namespace Tizen { namespace Messaging +{ + +_PushUrlRequestListener::_PushUrlRequestListener(void) +{ +} + +_PushUrlRequestListener::~_PushUrlRequestListener(void) +{ +} + +void +_PushUrlRequestListener::OnTransactionReadyToRead(HttpSession& httpSession, HttpTransaction& httpTransaction, int availableBodyLen) +{ + SysLog(NID_MSG, "####### OnTransactionReadyToRead! #######"); +} + +void +_PushUrlRequestListener::OnTransactionAborted(HttpSession& httpSession, HttpTransaction& httpTransaction, result r) +{ + SysLog(NID_MSG, "####### OnTransactionAborted! (%s)#######", GetErrorMessage(r)); + + _UserData* pUserData = dynamic_cast<_UserData*> (httpTransaction.GetUserObject()); + SysTryReturnVoidResult(NID_MSG, pUserData != null, E_SYSTEM, "[E_SYSTEM] Failed to cast user data."); + + delete pUserData; + + delete &httpTransaction; +} + +void +_PushUrlRequestListener::OnTransactionReadyToWrite(HttpSession& httpSession, HttpTransaction& httpTransaction, int recommendedChunkSize) +{ + SysLog(NID_MSG, "####### OnTransactionReadyToWrite! #######"); +} + +void +_PushUrlRequestListener::OnTransactionHeaderCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction, int headerLen, bool rs) +{ + SysLog(NID_MSG, "####### OnTransactionHeaderCompleted! #######"); +} + +void +_PushUrlRequestListener::OnTransactionCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction) +{ + SysLog(NID_MSG, "####### OnTransactionCompleted!#######"); + + HttpResponse* pResponse = httpTransaction.GetResponse(); + SysTryReturnVoidResult(NID_MSG, pResponse != null, E_SYSTEM, "[E_SYSTEM] HttpResponse is invalid."); + + result r = E_SUCCESS; + _PushManagerImpl* pManager = null; + String response; + ByteBuffer tempBuffer; + _UserData* pUserData = dynamic_cast<_UserData*> (httpTransaction.GetUserObject()); + SysTryReturnVoidResult(NID_MSG, pUserData != null, E_SYSTEM, "[E_SYSTEM] Failed to cast user data."); + + if (pResponse->GetHttpStatusCode() == HTTP_STATUS_OK) + { + ByteBuffer* pBody = pResponse->ReadBodyN(); + SysTryReturnVoidResult(NID_MSG, pBody != null, E_SYSTEM, "[E_SYSTEM] Failed to read body."); + + r = tempBuffer.Construct(pBody->GetRemaining() + 1); + SysTryReturnVoidResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Failed to construct byte buffer."); + + r = tempBuffer.CopyFrom(*pBody); + SysTryReturnVoidResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] Failed to copy from body."); + + SysLog(NID_MSG, "The read body is %s.", tempBuffer.GetPointer()); + + StringUtil::Utf8ToString((char*) tempBuffer.GetPointer(), response); + + SysLog(NID_MSG, "The read body response is %ls.", response.GetPointer()); + + StringTokenizer tokens(response, L"&"); + + while (tokens.HasMoreTokens() == true) + { + String token; + String key; + String value; + int delimiterIndex; + int resultValue; + String urlValue; + + tokens.GetNextToken(token); + + r = token.IndexOf(L"=", 0, delimiterIndex); + if(IsFailed(r)) + continue; + + r = token.SubString(0, delimiterIndex, key); + if (IsFailed(r)) + continue; + + r = token.SubString(delimiterIndex + 1, token.GetLength() - delimiterIndex - 1, value); + if (IsFailed(r)) + continue; + + if ((key.IsEmpty() == true) || (value.IsEmpty() == true)) + continue; + + if (key.Equals(L"resultcode", false) == true) + { + r = Integer::Parse(value, resultValue); + if (IsFailed(r)) + continue; + } + else if (key.Equals(L"url", false) == true) + { + urlValue = value; + urlValue.Append(L"/spp/pns/api/push"); + SysSecureLog(NID_MSG, "The read body url is %ls.", urlValue.GetPointer()); + + pManager = (pUserData->GetPushRequest())->GetPushManager(); + SysTryReturnVoidResult(NID_MSG, pManager != null, E_SYSTEM, "A _PushManagerImpl is NULL."); + pManager->UpdatePushServerUrl(urlValue); + r = pManager->SendHttpRequest(urlValue, pUserData->GetPushRequest(), *(pUserData->GetPushMessage()), *(pUserData->GetRegistrationIdList())); + SysTryReturnVoidResult(NID_MSG, r == E_SUCCESS, r, "[%s] Failed to submit http request.", GetErrorMessage(r)); + } + else + { + SysLog(NID_MSG, "Ignore UnKnown option[%ls]", key.GetPointer()); + } + } + + delete pBody; + } + + delete pUserData; + delete &httpTransaction; + +} + +void +_PushUrlRequestListener::OnTransactionCertVerificationRequiredN(HttpSession& httpSession, HttpTransaction& httpTransaction, String* pCert) +{ + SysLog(NID_MSG, "####### OnTransactionCertVerificationRequiredN! #######"); + + result r = httpTransaction.Resume(); + SysTryReturnVoidResult(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, "[E_SYSTEM] http transaction resume."); + + delete pCert; + + return; +} + +_UserData::_UserData(HttpUrlEncodedEntity* pHttpUrlEncodedEntity, PushMessage* pPushMessage, _PushRequest* pPushRequest, IList* pRegistrationIdList) + : __pHttpUrlEncodedEntity(pHttpUrlEncodedEntity), + __pPushMessage(pPushMessage), + __pPushRequest(pPushRequest), + __pRegistrationIdList(pRegistrationIdList) +{ + __pPushRequest->AddRef(); +} + +_UserData::~_UserData(void) +{ + __pPushRequest->Release(); + + if (__pHttpUrlEncodedEntity != null) + { + delete __pHttpUrlEncodedEntity; + __pHttpUrlEncodedEntity = null; + } + + if (__pPushMessage != null) + { + delete __pPushMessage; + __pPushMessage = null; + } + + if (__pRegistrationIdList != null) + { + delete __pRegistrationIdList; + __pRegistrationIdList = null; + } +} + +PushMessage* +_UserData::GetPushMessage(void) +{ + return __pPushMessage; +} + +_PushRequest* +_UserData::GetPushRequest(void) +{ + return __pPushRequest; +} + +IList* +_UserData::GetRegistrationIdList(void) +{ + return __pRegistrationIdList; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_PushUrlRequestListener.h b/src/FMsg_PushUrlRequestListener.h new file mode 100755 index 0000000..1547cc0 --- /dev/null +++ b/src/FMsg_PushUrlRequestListener.h @@ -0,0 +1,85 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_PushUrlRequestListener.h + * @brief This is the header file for %_PushUrlRequestListener class. + * + * This file contains declarations of _PushUrlRequestListener class. + */ + +#ifndef _FMSG_INTERNAL_PUSH_URL_REQUEST_LISTENER_H_ +#define _FMSG_INTERNAL_PUSH_URL_REQUEST_LISTENER_H_ + +#include +#include +#include +#include "FMsg_PushRequest.h" + +namespace Tizen { namespace Messaging +{ +class _PushUrlRequestListener + : public Tizen::Net::Http::IHttpTransactionEventListener +{ +public: + _PushUrlRequestListener(void); + virtual ~_PushUrlRequestListener(void); + +public: + + void OnTransactionReadyToRead(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction, int availableBodyLen); + + void OnTransactionAborted(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction, result r); + + void OnTransactionReadyToWrite(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction, int recommendedChunkSize); + + void OnTransactionHeaderCompleted(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction, int headerLen, bool rs); + + void OnTransactionCompleted(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction); + + void OnTransactionCertVerificationRequiredN(Tizen::Net::Http::HttpSession& httpSession, Tizen::Net::Http::HttpTransaction& httpTransaction, Tizen::Base::String* pCert); + +private: + _PushUrlRequestListener(const _PushUrlRequestListener& rhs); + _PushUrlRequestListener& operator =(const _PushUrlRequestListener& rhs); +}; // _PushUrlRequestListener + +class _UserData + : public Tizen::Base::Object +{ +public: + _UserData(Tizen::Net::Http::HttpUrlEncodedEntity* pHttpUrlEncodedEntity, PushMessage* pPushMessage, _PushRequest* pPushRequest, Tizen::Base::Collection::IList* pRegistrationIdList); + virtual ~_UserData(void); + +public: + PushMessage* GetPushMessage(void); + _PushRequest* GetPushRequest(void); + Tizen::Base::Collection::IList* GetRegistrationIdList(void); + +private: + _UserData(const _UserData& rhs); + _UserData& operator =(const _UserData& rhs); + +private: + Tizen::Net::Http::HttpUrlEncodedEntity* __pHttpUrlEncodedEntity; + PushMessage* __pPushMessage; + _PushRequest* __pPushRequest; + Tizen::Base::Collection::IList* __pRegistrationIdList; + }; // _UserData + +} } // Tizen::Messaging + +#endif // _FMSG_INTERNAL_PUSH_URL_REQUEST_LISTENER_H_ diff --git a/src/FMsg_RecipientListImpl.cpp b/src/FMsg_RecipientListImpl.cpp new file mode 100644 index 0000000..b02a5cb --- /dev/null +++ b/src/FMsg_RecipientListImpl.cpp @@ -0,0 +1,947 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_RecipientListImpl.cpp + * @brief This is the implementation file for the %_RecipientListImpl class. + * + * This file contains the implementation of the %_RecipientListImpl class. + */ + +#include +#include +#include +#include "FMsg_RecipientListImpl.h" +#include "FMsg_Types.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; + +namespace Tizen { namespace Messaging +{ + +_RecipientListImpl::_RecipientListImpl(void) + : __pRecipientList(null) + , __pRecipientCcList(null) + , __pRecipientBccList(null) +{ +} + +_RecipientListImpl::~_RecipientListImpl(void) +{ + if (__pRecipientList) + { + if (__pRecipientList->GetCount() > 0) + { + __pRecipientList->RemoveAll(true); // if true, deallocate object + } + delete __pRecipientList; + __pRecipientList = null; + } + + if (__pRecipientCcList) + { + if (__pRecipientCcList->GetCount() > 0) + { + __pRecipientCcList->RemoveAll(true); // if true, deallocate object + } + delete __pRecipientCcList; + __pRecipientCcList = null; + } + + if (__pRecipientBccList) + { + if (__pRecipientBccList->GetCount() > 0) + { + __pRecipientBccList->RemoveAll(true); // if true, deallocate object + } + delete __pRecipientBccList; + __pRecipientBccList = null; + } +} + +_RecipientListImpl::_RecipientListImpl(const _RecipientListImpl& value) +{ + __pRecipientList = null; + __pRecipientCcList = null; + __pRecipientBccList = null; + + int count = 0; + int index = 0; + String* pTmpStr = null; + + // TO + if (value.__pRecipientList) + { + __pRecipientList = new ArrayList(); + __pRecipientList->Construct(); + count = value.__pRecipientList->GetCount(); + for (index = 0; index < count; index++) + { + pTmpStr = static_cast (value.__pRecipientList->GetAt(index)); + String* pRecipient = new String(*pTmpStr); + __pRecipientList->Add(*pRecipient); + } + } + + // CC + if (value.__pRecipientCcList) + { + __pRecipientCcList = new ArrayList(); + __pRecipientCcList->Construct(); + count = value.__pRecipientCcList->GetCount(); + for (index = 0; index < count; index++) + { + pTmpStr = static_cast (value.__pRecipientCcList->GetAt(index)); + String* pRecipient = new String(*pTmpStr); + __pRecipientCcList->Add(*pRecipient); + } + } + + // BCC + if (value.__pRecipientBccList) + { + __pRecipientBccList = new ArrayList(); + __pRecipientBccList->Construct(); + count = value.__pRecipientBccList->GetCount(); + for (index = 0; index < count; index++) + { + pTmpStr = static_cast (value.__pRecipientBccList->GetAt(index)); + String* pRecipient = new String(*pTmpStr); + __pRecipientBccList->Add(*pRecipient); + } + } +} + +void +_RecipientListImpl::ClearRecipients(RecipientType type) +{ + if (type == RECIPIENT_TYPE_TO && __pRecipientList) + { + if (__pRecipientList->GetCount() > 0) + { + __pRecipientList->RemoveAll(true); // if true, deallocate object + } + delete __pRecipientList; + __pRecipientList = null; + } + + if (type == RECIPIENT_TYPE_CC && __pRecipientCcList) + { + if (__pRecipientCcList->GetCount() > 0) + { + __pRecipientCcList->RemoveAll(true); // if true, deallocate object + } + delete __pRecipientCcList; + __pRecipientCcList = null; + } + + if (type == RECIPIENT_TYPE_BCC && __pRecipientBccList) + { + if (__pRecipientBccList->GetCount() > 0) + { + __pRecipientBccList->RemoveAll(true); // if true, deallocate object + } + delete __pRecipientBccList; + __pRecipientBccList = null; + } +} + +void +_RecipientListImpl::ClearAllRecipients(void) +{ + if (__pRecipientList) + { + if (__pRecipientList->GetCount() > 0) + { + __pRecipientList->RemoveAll(true); // if true, deallocate object + } + delete __pRecipientList; + __pRecipientList = null; + } + + if (__pRecipientCcList) + { + if (__pRecipientCcList->GetCount() > 0) + { + __pRecipientCcList->RemoveAll(true); // if true, deallocate object + } + delete __pRecipientCcList; + __pRecipientCcList = null; + } + + if (__pRecipientBccList) + { + if (__pRecipientBccList->GetCount() > 0) + { + __pRecipientBccList->RemoveAll(true); // if true, deallocate object + } + delete __pRecipientBccList; + __pRecipientBccList = null; + } +} + +_RecipientListImpl& +_RecipientListImpl::operator =(const _RecipientListImpl& value) +{ + if (this != &value) + { + ClearAllRecipients(); + + int count = 0; + int index = 0; + String* pTmpStr = null; + + if (value.__pRecipientList) + { + __pRecipientList = new ArrayList(); + if (__pRecipientList) + { + __pRecipientList->Construct(); + count = value.__pRecipientList->GetCount(); + for (int index = 0; index < count; index++) + { + pTmpStr = static_cast (value.__pRecipientList->GetAt(index)); + String* pRecipient = new String(*pTmpStr); + __pRecipientList->Add(*pRecipient); + } + } + } + + if (value.__pRecipientCcList) + { + __pRecipientCcList = new ArrayList(); + if (__pRecipientCcList) + { + __pRecipientCcList->Construct(); + count = value.__pRecipientCcList->GetCount(); + for (index = 0; index < count; index++) + { + pTmpStr = static_cast (value.__pRecipientCcList->GetAt(index)); + String* pRecipient = new String(*pTmpStr); + __pRecipientCcList->Add(*pRecipient); + } + } + } + + if (value.__pRecipientBccList) + { + __pRecipientBccList = new ArrayList(); + if (__pRecipientBccList) + { + __pRecipientBccList->Construct(); + count = value.__pRecipientBccList->GetCount(); + for (index = 0; index < count; index++) + { + pTmpStr = static_cast (value.__pRecipientBccList->GetAt(index)); + String* pRecipient = new String(*pTmpStr); + __pRecipientBccList->Add(*pRecipient); + } + } + } + } + + return (*this); +} + +bool +_RecipientListImpl::operator ==(const _RecipientListImpl& rhs) const +{ + return (Equals(rhs)); +} + +bool +_RecipientListImpl::operator !=(const _RecipientListImpl& rhs) const +{ + return (!Equals(rhs)); +} + +bool +_RecipientListImpl::Equals(const Tizen::Base::Object& value) const +{ + const _RecipientListImpl* pList = dynamic_cast(&value); + int index = 0; + + if (!pList) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + String* pTempString1 = null; + String* pTempString2 = null; + int count = 0; + int valueCount = 0; + + // TO + if (__pRecipientList) + { + count = __pRecipientList->GetCount(); + } + else + { + count = 0; + } + + if (pList->__pRecipientList) + { + valueCount = pList->__pRecipientList->GetCount(); + } + else + { + valueCount = 0; + } + + if (count != valueCount) + { + return false; + } + + if (pList->__pRecipientList) + { + for (index = 0; index < count; index++) + { + pTempString1 = (String*) (__pRecipientList->GetAt(index)); + pTempString2 = (String*) (pList->__pRecipientList->GetAt(index)); + if (0 != pTempString1->CompareTo(*pTempString2)) + { + return false; + } + } + } + + + // CC + if (__pRecipientCcList) + { + count = __pRecipientCcList->GetCount(); + } + else + { + count = 0; + } + + if (pList->__pRecipientCcList) + { + valueCount = pList->__pRecipientCcList->GetCount(); + } + else + { + valueCount = 0; + } + + if (count != valueCount) + { + return false; + } + + if (pList->__pRecipientCcList) + { + for (index = 0; index < count; index++) + { + pTempString1 = (String*) (__pRecipientCcList->GetAt(index)); + pTempString2 = (String*) (pList->__pRecipientCcList->GetAt(index)); + if (0 != pTempString1->CompareTo(*pTempString2)) + { + return false; + } + } + } + + // BCC + if (__pRecipientBccList) + { + count = __pRecipientBccList->GetCount(); + } + else + { + count = 0; + } + + if (pList->__pRecipientBccList) + { + valueCount = pList->__pRecipientBccList->GetCount(); + } + else + { + valueCount = 0; + } + + if (count != valueCount) + { + return false; + } + + if (pList->__pRecipientBccList) + { + for (index = 0; index < count; index++) + { + pTempString1 = (String*) (__pRecipientBccList->GetAt(index)); + pTempString2 = (String*) (pList->__pRecipientBccList->GetAt(index)); + if (0 != pTempString1->CompareTo(*pTempString2)) + { + return false; + } + } + } + + return true; +} + +int +_RecipientListImpl::GetHashCode(void) const +{ + String* pTempString = null; + int count = 0; + int hash = 0; + int index = 0; + + if (__pRecipientList) + { + count = __pRecipientList->GetCount(); + for (index = 0; index < count; index++) + { + pTempString = static_cast (__pRecipientList->GetAt(index)); + hash += pTempString->GetHashCode(); + } + } + + if (__pRecipientCcList) + { + count = __pRecipientCcList->GetCount(); + for (index = 0; index < count; index++) + { + pTempString = static_cast (__pRecipientCcList->GetAt(index)); + hash += pTempString->GetHashCode(); + } + } + + if (__pRecipientBccList) + { + count = __pRecipientBccList->GetCount(); + for (index = 0; index < count; index++) + { + pTempString = static_cast (__pRecipientBccList->GetAt(index)); + hash += pTempString->GetHashCode(); + } + } + + return hash; +} + +int +_RecipientListImpl::GetTotalRecipientCount(void) const +{ + int totalCount = 0; + + if (__pRecipientList) + { + totalCount += __pRecipientList->GetCount(); + } + + if (__pRecipientCcList) + { + totalCount += __pRecipientCcList->GetCount(); + } + + if (__pRecipientBccList) + { + totalCount += __pRecipientBccList->GetCount(); + } + + return totalCount; +} + +result +_RecipientListImpl::Add(RecipientType type, const String& recipient) +{ + result r = E_SUCCESS; + String* pRecipient = null; + + // duplication check in TO list + if (__pRecipientList && __pRecipientList->Contains(recipient)) + { + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, "[E_OBJ_ALREADY_EXIST] The corresponding recipient is already added to TO list."); + goto CATCH; + } + + // duplication check in CC list + if (__pRecipientCcList && __pRecipientCcList->Contains(recipient)) + { + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, "[E_OBJ_ALREADY_EXIST] The corresponding recipient is already added to CC list."); + goto CATCH; + } + + // duplication check in BCC list + if (__pRecipientBccList && __pRecipientBccList->Contains(recipient)) + { + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, "[E_OBJ_ALREADY_EXIST] The corresponding recipient is already added to BCC list."); + goto CATCH; + } + + if (type == RECIPIENT_TYPE_TO ) + { + if (!__pRecipientList) + { + __pRecipientList = new ArrayList(); + r = __pRecipientList->Construct(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to construct a TO list.", GetErrorMessage(r)); + delete __pRecipientList; + __pRecipientList = null; + goto CATCH; + } + } + // add a recipient + pRecipient = new String(recipient); + r = __pRecipientList->Add(*pRecipient); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add the recipient to TO list.", GetErrorMessage(r)); + delete pRecipient; + pRecipient = null; + goto CATCH; + } + } + else if (type == RECIPIENT_TYPE_CC) + { + if (!__pRecipientCcList) + { + __pRecipientCcList = new ArrayList(); + r = __pRecipientCcList->Construct(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to construct a CC list.", GetErrorMessage(r)); + delete __pRecipientCcList; + __pRecipientCcList = null; + goto CATCH; + } + } + // add a recipient + pRecipient = new String(recipient); + r = __pRecipientCcList->Add(*pRecipient); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add the recipient to CC list.", GetErrorMessage(r)); + delete pRecipient; + pRecipient = null; + goto CATCH; + } + } + else if (type == RECIPIENT_TYPE_BCC) + { + if (!__pRecipientBccList) + { + __pRecipientBccList = new ArrayList(); + r = __pRecipientBccList->Construct(); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to construct a BCC list.", GetErrorMessage(r)); + delete __pRecipientBccList; + __pRecipientBccList = null; + goto CATCH; + } + } + // add a recipient + pRecipient = new String(recipient); + r = __pRecipientBccList->Add(*pRecipient); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add the recipient to BCC list.", GetErrorMessage(r)); + delete pRecipient; + pRecipient = null; + goto CATCH; + } + } + + return E_SUCCESS; + +CATCH: + return r; +} + +result +_RecipientListImpl::Remove(RecipientType type, const Tizen::Base::String& recipient) +{ + result r = E_SUCCESS; + + SysTryReturnResult(NID_MSG, (type >= RECIPIENT_TYPE_TO && type <= RECIPIENT_TYPE_BCC), E_INVALID_ARG, + "[E_INVALID_ARG] Invalid RecipientType argument."); + + if ((recipient.GetLength() < MIN_LENGTH_PHONE) || (recipient.GetLength() > MAX_LENGTH_EMAIL)) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The length of phone number or email address is too short or too long (%d).", + recipient.GetLength()); + goto CATCH; + } + + + if ((type == RECIPIENT_TYPE_TO && !__pRecipientList) || + (type == RECIPIENT_TYPE_CC && !__pRecipientCcList) || (type == RECIPIENT_TYPE_BCC && !__pRecipientBccList)) + { + r = E_OBJ_NOT_FOUND; + SysLogException(NID_MSG, r, "[E_OBJ_NOT_FOUND] There is not such type of recipient."); + goto CATCH; + } + + if (type == RECIPIENT_TYPE_TO) + { + r = __pRecipientList->Remove(recipient, true); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to remove the recipient from TO list.", GetErrorMessage(r)); + goto CATCH; + } + } + else if (type == RECIPIENT_TYPE_CC) + { + r = __pRecipientCcList->Remove(recipient, true); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to remove the recipient from CC list.", GetErrorMessage(r)); + goto CATCH; + } + } + else if (type == RECIPIENT_TYPE_BCC) + { + r = __pRecipientBccList->Remove(recipient, true); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to remove the recipient from BCC list.", GetErrorMessage(r)); + goto CATCH; + } + } + + return E_SUCCESS; + +CATCH: + return r; +} + +result +_RecipientListImpl::Set(RecipientType type, const Tizen::Base::Collection::IList& list) +{ + result r = E_SUCCESS; + int index = 0; + + if (list.GetCount() == 0) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The input list has no item."); + goto CATCH; + } + + for (index = 0; index < list.GetCount(); index++) + { + String* pItem = (String*) (list.GetAt(index)); + if (pItem->GetLength() < MIN_LENGTH_PHONE || pItem->GetLength() > MAX_LENGTH_EMAIL) + { + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] The length of a recipient in the input list is invalid (too short or too long)."); + goto CATCH; + } + } + + switch (type) + { + case RECIPIENT_TYPE_TO: + { + ClearRecipients(RECIPIENT_TYPE_TO); + __pRecipientList = new ArrayList(); + __pRecipientList->Construct(); + int count = 0; + String* pTmpStr = null; + count = list.GetCount(); + for (index = 0; index < count; index++) + { + pTmpStr = (String*) (list.GetAt(index)); + // duplication check in TO + if (__pRecipientList->Contains(*pTmpStr)) + { + ClearRecipients(RECIPIENT_TYPE_TO); + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, + "[E_OBJ_ALREADY_EXIST] There is a duplicate recipient in the input list. Please check the duplications."); + goto CATCH; + } + // duplication check in CC + if (__pRecipientCcList && __pRecipientCcList->Contains(*pTmpStr)) + { + ClearRecipients(RECIPIENT_TYPE_TO); + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, + "[E_OBJ_ALREADY_EXIST] There is a duplicate recipient in the input list comparing to the CC list. Please check the duplications."); + goto CATCH; + } + // duplication check in BCC + if (__pRecipientBccList && __pRecipientBccList->Contains(*pTmpStr)) + { + ClearRecipients(RECIPIENT_TYPE_TO); + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, + "[E_OBJ_ALREADY_EXIST] There is a duplicate recipient in the input list comparing to the BCC list. Please check the duplications."); + goto CATCH; + } + String* pRecipient = new String(*pTmpStr); + r = __pRecipientList->Add(*pRecipient); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add the recipient to the TO list.", GetErrorMessage(r)); + goto CATCH; + } + } + break; + } + + case RECIPIENT_TYPE_CC: + { + ClearRecipients(RECIPIENT_TYPE_CC); + __pRecipientCcList = new ArrayList(); + __pRecipientCcList->Construct(); + int count = 0; + String* pTmpStr = null; + count = list.GetCount(); + for (index = 0; index < count; index++) + { + pTmpStr = (String*) (list.GetAt(index)); + // duplication check in TO + if (__pRecipientList && __pRecipientList->Contains(*pTmpStr)) + { + ClearRecipients(RECIPIENT_TYPE_CC); + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, + "[E_OBJ_ALREADY_EXIST] There is a duplicate recipient in the input list comparing to the TO list. Please check the duplications."); + goto CATCH; + } + // duplication check in CC + if (__pRecipientCcList->Contains(*pTmpStr)) + { + ClearRecipients(RECIPIENT_TYPE_CC); + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, + "[E_OBJ_ALREADY_EXIST] There is a duplicate recipient in the input list. Please check the duplications."); + goto CATCH; + } + // duplication check in BCC + if (__pRecipientBccList && __pRecipientBccList->Contains(*pTmpStr)) + { + ClearRecipients(RECIPIENT_TYPE_CC); + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, + "[E_OBJ_ALREADY_EXIST] There is a duplicate recipient in the input list comparing to the BCC list. Please check the duplications."); + goto CATCH; + } + String* pRecipient = new String(*pTmpStr); + r = __pRecipientCcList->Add(*pRecipient); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add the recipient to the CC list.", GetErrorMessage(r)); + goto CATCH; + } + } + break; + } + + case RECIPIENT_TYPE_BCC: + { + ClearRecipients(RECIPIENT_TYPE_BCC); + __pRecipientBccList = new ArrayList(); + __pRecipientBccList->Construct(); + int count = 0; + String* pTmpStr = null; + count = list.GetCount(); + for (index = 0; index < count; index++) + { + pTmpStr = (String*) (list.GetAt(index)); + // duplication check in TO + if (__pRecipientList && __pRecipientList->Contains(*pTmpStr)) + { + ClearRecipients(RECIPIENT_TYPE_BCC); + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, + "[E_OBJ_ALREADY_EXIST] There is a duplicate recipient in the input list comparing to the TO list. Please check the duplications."); + goto CATCH; + } + // duplication check in CC + if (__pRecipientCcList && __pRecipientCcList->Contains(*pTmpStr)) + { + ClearRecipients(RECIPIENT_TYPE_BCC); + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, + "[E_OBJ_ALREADY_EXIST] There is a duplicate recipient in the input list comparing to the CC list. Please check the duplications."); + goto CATCH; + } + // duplication check in BCC + if (__pRecipientBccList->Contains(*pTmpStr)) + { + ClearRecipients(RECIPIENT_TYPE_BCC); + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, + "[E_OBJ_ALREADY_EXIST] There is a duplicate recipient in the input list. Please check the duplications."); + goto CATCH; + } + String* pRecipient = new String(*pTmpStr); + r = __pRecipientBccList->Add(*pRecipient); + if (IsFailed(r)) + { + SysLogException(NID_MSG, r, "[%s] Failed to add the recipient to the BCC list.", GetErrorMessage(r)); + goto CATCH; + } + } + break; + } + + default: + r = E_INVALID_ARG; + SysLogException(NID_MSG, r, "[E_INVALID_ARG] Invalid recipient type (%d).", type); + break; + } + + return r; + +CATCH: + return r; +} + +Tizen::Base::Collection::IList* +_RecipientListImpl::GetListN(RecipientType type) +{ + result r = E_SUCCESS; + ArrayList* pRetRecipient = null; + int index = 0; + + ClearLastResult(); + + if (type < RECIPIENT_TYPE_TO || type > RECIPIENT_TYPE_BCC) + { + SetLastResult(E_INVALID_ARG); + SysLogException(NID_MSG, r, "[E_INVALID_ARG] Invalid RecipientType argument."); + return null; + } + + pRetRecipient = new ArrayList(); + if (!pRetRecipient) + { + SetLastResult(E_OUT_OF_MEMORY); + SysLogException(NID_MSG, r, "memory allocation failed."); + return null; + } + r = pRetRecipient->Construct(); + if (IsFailed(r)) + { + SetLastResult(r); + SysLogException(NID_MSG, r, "[%s] Failed to construct an ArrayList.", GetErrorMessage(r)); + delete pRetRecipient; + pRetRecipient = null; + return null; + } + + switch (type) + { + case RECIPIENT_TYPE_TO: + { + int count = 0; + String* pTmpStr = null; + + if (__pRecipientList) + { + count = __pRecipientList->GetCount(); + } + if (count == 0) + { + SysLog(NID_MSG, "TO list has no recipient"); + return pRetRecipient; + } + + for (index = 0; index < count; index++) + { + pTmpStr = static_cast (__pRecipientList->GetAt(index)); + String* pRecipient = new String(*pTmpStr); + pRetRecipient->Add(*pRecipient); + } + break; + } + + case RECIPIENT_TYPE_CC: + { + int count = 0; + String* pTmpStr = null; + + if (__pRecipientCcList) + { + count = __pRecipientCcList->GetCount(); + } + if (count == 0) + { + SysLog(NID_MSG, "CC list has no recipient"); + return pRetRecipient; + } + + for (index = 0; index < count; index++) + { + pTmpStr = static_cast (__pRecipientCcList->GetAt(index)); + String* pRecipient = new String(*pTmpStr); + pRetRecipient->Add(*pRecipient); + } + break; + } + + case RECIPIENT_TYPE_BCC: + { + int count = 0; + String* pTmpStr = null; + + if (__pRecipientBccList) + { + count = __pRecipientBccList->GetCount(); + } + if (count == 0) + { + SysLog(NID_MSG, "BCC list has no recipient"); + return pRetRecipient; + } + + for (index = 0; index < count; index++) + { + pTmpStr = static_cast (__pRecipientBccList->GetAt(index)); + String* pRecipient = new String(*pTmpStr); + pRetRecipient->Add(*pRecipient); + } + break; + } + } + + return pRetRecipient; +} + +_RecipientListImpl* +_RecipientListImpl::GetInstance(RecipientList& recipientList) +{ + return recipientList.__pImpl; +} + +const _RecipientListImpl* +_RecipientListImpl::GetInstance(const RecipientList& recipientList) +{ + return recipientList.__pImpl; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_RecipientListImpl.h b/src/FMsg_RecipientListImpl.h new file mode 100644 index 0000000..fc36699 --- /dev/null +++ b/src/FMsg_RecipientListImpl.h @@ -0,0 +1,244 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_RecipientListImpl.h + * @brief This is the header file for _RecipientListImpl class. + * + * This header file contains the declarations of _RecipientListImpl class. + */ + +#ifndef _FMSG_INTERNAL_RECIPIENT_LIST_IMPL_H_ +#define _FMSG_INTERNAL_RECIPIENT_LIST_IMPL_H_ + +// Includes +#include +#include + +// forward declaration +namespace Tizen { namespace Base { namespace Collection +{ +class IList; +class ArrayList; +}}} + +namespace Tizen { namespace Messaging +{ + +// forward declarations +class RecipientList; + +/** +* @class _RecipientListImpl +* @brief This class provides the abstract data type and methods for handling recipients. +* @since 1.0 +* +* This class provides the method for handling message recipients. @n +* A user can add, remove, set, and get recipients using this class. @n +* The recipient is an email address for an email message and a telephone number for an SMS or MMS message. +*/ +class _RecipientListImpl + : public Tizen::Base::Object +{ + // Life cycle +public: + /** + * This is the default constructor for this class. + * + * @since 1.0 + */ + _RecipientListImpl(void); + + /** + * This is the copy constructor for this class. + * + * @since 1.0 + * @param[in] value An instance of _RecipientListImpl + */ + _RecipientListImpl(const _RecipientListImpl& value); + + /** + * This is the destructor for this class. + * + * @since 1.0 + */ + virtual ~_RecipientListImpl(void); + + //Operator +public: + /** + * This assignment operator copies recipient list from the specified instance of _RecipientListImpl to the calling instance of _RecipientListImpl. + * + * @since 1.0 + * @param[in] rhs The reference of this instance + */ + _RecipientListImpl& operator =(const _RecipientListImpl& rhs); + + /** + * This operator compares the two recipient list. + * + * @since 1.0 + * @return @c true if both instances are equal @n + * @c false, otherwise + * @param[in] rhs A reference to the _RecipientListImpl instance on the right-hand side of the operator + */ + bool operator ==(const _RecipientListImpl& rhs) const; + + /** + * This operator compares the specified instance with the calling instance for inequality. + * + * @since 2.1 + * @return @c true if both instances are not equal, @n + * else @c false + * @param[in] rhs A reference to the %RecipientList instance on the right-hand side of the operator + */ + bool operator !=(const _RecipientListImpl& rhs) const; + + /** + * Gets the hash value of the current instance. + * + * @since 1.0 + * @return The hash value of the current instance + * @remarks Two equal instances should return the same hash value. For better performance, + * the used hash function must generate a random distribution for all inputs. + */ + virtual int GetHashCode(void) const; + + // Operation +public: + /** + * Compares the specified instance with the calling instance. + * + * @since 1.0 + * @return @c true if both instances are equal @n + * @c false, otherwise + * @param[in] value An instance of _RecipientListImpl + */ + virtual bool Equals(const Tizen::Base::Object& value) const; + /** + * Adds a recipient string. + * + * @since 1.0 + * @return An error code + * @param[in] type The type of recipient + * @param[in] recipient The recipient + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @exception E_OBJ_ALREADY_EXIST The specified recipient is already added. + * @exception E_INVALID_ARG The specified @c recipient %string length is too @c short (< 3) or too @c long (> 320). @n + * The value of the specified @c type is invalid. + * @remarks The limit of the number of recipients is not checked in this method. This is done in the Send() method of each manager class (SmsManager, MmsManager, and EmailManager). @n + * The minimum length of a recipient is 3 for phone number and 5 for email address. @n + * The maximum length of a recipient is 41 for phone number and 320 for email address. + * @see Set(), GetListN(), SmsManager::Send(), MmsManager::Send(), EmailManager::Send() + */ + result Add(RecipientType type, const Tizen::Base::String& recipient); + + /** + * Remove a recipient. + * + * @since 1.0 + * @return An error code + * @param[in] type The type of recipient + * @param[in] recipient The recipient string + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG The specified @c recipient %string length is too @c short (< 3) or too @c long (> 320). @n + * The value of the specified @c type is invalid. + * @exception E_OBJ_NOT_FOUND There is no such recipient. + * @see Add() + */ + result Remove(RecipientType type, const Tizen::Base::String& recipient); + + + /** + * Sets a recipient list. + * + * @since 1.0 + * @return An error code + * @param[in] type The type of recipient + * @param[in] list A list of recipient strings + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG The length of one of the recipients in the list is too @c short (< 3) or too @c long (> 320). @n + * The value of the specified @c type is invalid. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @exception E_OBJ_ALREADY_EXIST There is a duplicate recipient in the recipient list. + * @remarks The limit of recipients is not checked in this method. @n + * This is done in Send() method of each manager class. (SmsManager, MmsManager, and EmailManager) + * @see Add(), GetListN() + */ + result Set(RecipientType type, const Tizen::Base::Collection::IList& list); + + /** + * Gets the recipient list of the specific recipient type. + * + * @since 1.0 + * @return The list of the recipient + * @param[in] type The type of recipient + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @exception E_INVALID_ARG The value of the specified @c type is invalid. + * @remarks The recipient is an email address for an email message and a telephone number for an SMS or MMS message. The type of the recipient is String. @n + * The specific error code can be accessed using the GetLastResult() method. + * @see Add(), Set() + */ + Tizen::Base::Collection::IList* GetListN(RecipientType type); + + /** + * Returns the number of recipients ( To + Cc + Bcc ). + * + * @return The number of total recipient count + */ + int GetTotalRecipientCount(void) const; + + /** + * Clear corresponding recipients ( To or Cc or Bcc ). + * + */ + void ClearRecipients(RecipientType type); + + /** + * Clear all recipients ( To + Cc + Bcc ). + * + */ + void ClearAllRecipients(void); + +public: + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _RecipientListImpl + * @param[in] recipientList An instance of RecipientList + */ + static _RecipientListImpl* GetInstance(RecipientList& recipientList); + + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _RecipientListImpl + * @param[in] recipientList An instance of RecipientList + */ + static const _RecipientListImpl* GetInstance(const RecipientList& recipientList); + +private: + Tizen::Base::Collection::ArrayList* __pRecipientList; + Tizen::Base::Collection::ArrayList* __pRecipientCcList; + Tizen::Base::Collection::ArrayList* __pRecipientBccList; +}; // _RecipientListImpl +} } // Tizen::Messaging + +#endif // _FMSG_INTERNAL_RECIPIENT_LIST_IMPL_H_ diff --git a/src/FMsg_SmsEvent.cpp b/src/FMsg_SmsEvent.cpp new file mode 100644 index 0000000..5b2333c --- /dev/null +++ b/src/FMsg_SmsEvent.cpp @@ -0,0 +1,205 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_SmsEvent.cpp + * @brief This is the implementation file for the %_SmsEvent class. + * + * This file contains the implementation of the %_SmsEvent class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_SmsEvent.h" +#include "FMsg_SmsEventArg.h" +#include "FMsg_SmsMessageImpl.h" +#include "FMsg_CbsMessageImpl.h" +#include "FMsg_WapPushMessageImpl.h" +#include "FMsg_EtwsPrimaryNotificationImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Runtime; + +namespace Tizen { namespace Messaging +{ + +_SmsEvent::_SmsEvent(void) + : __port(-1) + , __smsEventType(_SMS_EVENT_TYPE_NONE) +{ +} + +result +_SmsEvent::Construct(_SmsEventType type) +{ + __smsEventType = type; + + return _Event::Initialize(); +} + +result +_SmsEvent::Construct(int port) +{ + __smsEventType = _SMS_EVENT_TYPE_SMS_TRIGGER; + __port = port; + + return _Event::Initialize(); +} + +int +_SmsEvent::GetPort(void) const +{ + return __port; +} + +_SmsEventType +_SmsEvent::GetType(void) const +{ + return __smsEventType; +} + +void +_SmsEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg) +{ + result r = E_SUCCESS; + + ISmsListener* pSmsListener = null; + ISmsEventListener* pSmsEventListener = null; + ISmsMessageEventListener* pSmsMessageEventListener = null; + ICbsMessageEventListener* pCbsMessageEventListener = null; + IWapPushEventListener* pWapPushMessageEventListener = null; + IEtwsPrimaryNotificationEventListener* pEtwsNotificationMesssageEventListener = null; + + IEventArg* pEventArg = const_cast (&arg); + _SmsEventArg* pSmsEventArg = dynamic_cast <_SmsEventArg*>(pEventArg); + SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_SYSTEM, "A failure occurred from the underlying system."); + + SmsMessage message; + CbsMessage* pCbsMessage = null; + WapPushMessage* pWapPushMessage = null; + EtwsPrimaryNotification* pEtwsNotificationMessage = null; + DateTime dateTime; + int port = 0; + String sender; + + if (pSmsEventArg->GetEventType() == _SMS_EVENT_TYPE_SMS_SEND_RESULT) + { + pSmsListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_MSG, pSmsListener != null, E_SYSTEM, "A failure occurred from the underlying system."); + + // set result + pSmsEventArg->GetErrorResult(r); + + // Fire + pSmsListener->OnSmsMessageSent(r); + } + else if (pSmsEventArg->GetEventType() == _SMS_EVENT_TYPE_SMS_TRIGGER) + { + pSmsEventListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_MSG, pSmsEventListener != null, E_SYSTEM, "A failure occurred from the underlying system."); + + _SmsMessageImpl* pImpl = _SmsMessageImpl::GetInstance(message); + SysTryReturnVoidResult(NID_MSG, pImpl != null, E_SYSTEM, "A failure occurred from the underlying system."); + + // port + port = pSmsEventArg->GetPort(); + // received time + dateTime = pSmsEventArg->GetDateTime(); + // message + pImpl->SetIncomingMessage(pSmsEventArg->GetMessage(), pSmsEventArg->GetSenderAddress(), dateTime); + + // Fire + pSmsEventListener->OnSmsMessageReceived(port, dateTime, message); + } + else if (pSmsEventArg->GetEventType() == _SMS_EVENT_TYPE_SMS_RECEIVE_RESULT) + { + pSmsMessageEventListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_MSG, pSmsMessageEventListener != null, E_SYSTEM, "A failure occurred from the underlying system."); + + _SmsMessageImpl* pImpl = _SmsMessageImpl::GetInstance(message); + SysTryReturnVoidResult(NID_MSG, pImpl != null, E_SYSTEM, "A failure occurred from the underlying system."); + + // set message + pImpl->SetIncomingMessage(pSmsEventArg->GetMessage(), pSmsEventArg->GetSenderAddress(), pSmsEventArg->GetDateTime()); + + // Fire + pSmsMessageEventListener->OnSmsMessageReceived(message); + } + else if (pSmsEventArg->GetEventType() == _SMS_EVENT_TYPE_CBS_RECEIVE_RESULT) + { + pCbsMessageEventListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_MSG, pCbsMessageEventListener != null, E_SYSTEM, "A failure occurred from the underlying system."); + + pCbsMessage = _CbsMessageImpl::GetCbsMessageN(); + if (pCbsMessage) + { + _CbsMessageImpl::GetInstance(*pCbsMessage)->SetCbsMessageImpl(pSmsEventArg->GetDateTime(), *(pSmsEventArg->GetSerialNumber()), pSmsEventArg->GetMessage(), pSmsEventArg->GetMessageId(), pSmsEventArg->GetEtwsNotification(), pSmsEventArg->GetDataCodingScheme(), pSmsEventArg->GetCbsLanguageType()); + } + + // Fire + if (pCbsMessage) + { + pCbsMessageEventListener->OnCbsMessageReceived((*pCbsMessage)); + delete pCbsMessage; + pCbsMessage = null; + } + } + else if (pSmsEventArg->GetEventType() == _SMS_EVENT_TYPE_WAP_PUSH_RECEIVE_RESULT) + { + pWapPushMessageEventListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_MSG, pWapPushMessageEventListener != null, E_SYSTEM, "A failure occurred from the underlying system."); + + pWapPushMessage = _WapPushMessageImpl::GetWapPushMessageN(pSmsEventArg->GetMessage(), *(pSmsEventArg->GetWapPushBody())); + + // Fire + if (pWapPushMessage) + { + pWapPushMessageEventListener->OnWapPushMessageReceived((*pWapPushMessage)); + delete pWapPushMessage; + pWapPushMessage = null; + } + } + else if (pSmsEventArg->GetEventType() == _SMS_EVENT_TYPE_ETWS_RECEIVE_RESULT) + { + pEtwsNotificationMesssageEventListener = dynamic_cast (&listener); + SysTryReturnVoidResult(NID_MSG, pEtwsNotificationMesssageEventListener != null, E_SYSTEM, "A failure occurred from the underlying system."); + pEtwsNotificationMessage = _EtwsPrimaryNotificationImpl::GetEtwsPrimaryNotificationN(); + + if (pEtwsNotificationMessage) + { + _EtwsPrimaryNotificationImpl::GetInstance(*pEtwsNotificationMessage)->SetEtwsMessageImpl(pSmsEventArg->GetDateTime(), *(pSmsEventArg->GetSerialNumber()), *(pSmsEventArg->GetWarningSecurityInfo()), pSmsEventArg->GetMessageId(), *(pSmsEventArg->GetEtwsWarningType())); + } + // Fire + if (pEtwsNotificationMessage) + { + pEtwsNotificationMesssageEventListener->OnEtwsPrimaryNotificationReceived((*pEtwsNotificationMessage)); + delete pEtwsNotificationMessage; + pEtwsNotificationMessage = null; + } + } +} + +} } diff --git a/src/FMsg_SmsEvent.h b/src/FMsg_SmsEvent.h new file mode 100644 index 0000000..30616ac --- /dev/null +++ b/src/FMsg_SmsEvent.h @@ -0,0 +1,99 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_SmsEvent.h + * @brief This is the header file for _SmsEvent class. + * + * This header file contains the declarations of _SmsEvent class. + */ + + +#ifndef _FMSG_INTERNAL_SMS_EVENT_H_ +#define _FMSG_INTERNAL_SMS_EVENT_H_ + +// Includes +#include +#include "FMsg_Types.h" + +namespace Tizen { namespace Messaging +{ + +// +// @class _SmsEvent +// @brief This class provides the event for SMS message. +// @since 1.0 +// +// @see ISmsEventListener, _SmsEventArg +// + +class _SmsEvent + : public Tizen::Base::Runtime::_Event +{ +// Life cycle +public: + /** + * This is the constructor. + * + */ + _SmsEvent(void); + + /** + * This is the class destructor. + * + */ + virtual ~_SmsEvent(void) {}; + + /** + * Initializes a new instance of the class + * + */ + result Construct(_SmsEventType type); + + /** + * This is the overloaded Construct. (just for SMS Trigger) + * + */ + result Construct(int port); + + /** + * Get the corresponding port number (just for SMS trigger) + */ + int GetPort(void) const; + + /** + * Get the SMS event type + */ + _SmsEventType GetType(void) const; + + +//Operations +protected: + void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg); + +private: + _SmsEvent(const _SmsEvent& smsEvent); + _SmsEvent& operator =(const _SmsEvent& value); + + // Attributes +private: + int __port; + _SmsEventType __smsEventType; +}; // _SmsEvent + +} } + +#endif // _FMSG_INTERNAL_SMS_EVENT_H_ diff --git a/src/FMsg_SmsEventArg.cpp b/src/FMsg_SmsEventArg.cpp new file mode 100644 index 0000000..97e9119 --- /dev/null +++ b/src/FMsg_SmsEventArg.cpp @@ -0,0 +1,294 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_SmsEventArg.cpp + * @brief This is the implementation file for the %_SmsEventArg class. + * + * This file contains the implementation of the %_SmsEventArg class. + */ + +#include +#include +#include +#include "FMsg_SmsEventArg.h" + +using namespace Tizen::Base; + +namespace Tizen { namespace Messaging +{ + +_SmsEventArg::_SmsEventArg(void) + : __result(E_SUCCESS) + , __port(-1) + , __eventType(_SMS_EVENT_TYPE_NONE) + , __pPushMsgBody(null) + , __pMsgSerialNumber(null) + , __pMsgSecurityInfo(null) + , __pEtwsWarningType(null) +{ +} + +_SmsEventArg::_SmsEventArg(const result r) + : __port(-1) + , __eventType(_SMS_EVENT_TYPE_SMS_SEND_RESULT) + , __pPushMsgBody(null) + , __pMsgSerialNumber(null) + , __pMsgSecurityInfo(null) + , __pEtwsWarningType(null) +{ + if (IsFailed(r)) + { + __result = E_FAILURE; + } + else + { + __result = r; // E_SUCCESS + } +} + +_SmsEventArg::_SmsEventArg(int port, const DateTime& dateTime, const String& message, const String& senderAddress) + : __result(E_UNKNOWN) + , __message(message) + , __port(port) + , __sender(senderAddress) + , __dateTime(dateTime) + , __eventType(_SMS_EVENT_TYPE_SMS_TRIGGER) + , __pPushMsgBody(null) + , __pMsgSerialNumber(null) + , __pMsgSecurityInfo(null) + , __pEtwsWarningType(null) +{ +} + +_SmsEventArg::_SmsEventArg(const Tizen::Base::String& text, const Tizen::Base::String& senderAddress, const Tizen::Base::DateTime& receivedTime) + : __result(E_UNKNOWN) + , __message(text) + , __port(-1) + , __sender(senderAddress) + , __dateTime(receivedTime) + , __eventType(_SMS_EVENT_TYPE_SMS_RECEIVE_RESULT) + , __pPushMsgBody(null) + , __pMsgSerialNumber(null) + , __pMsgSecurityInfo(null) + , __pEtwsWarningType(null) +{ +} + +_SmsEventArg::_SmsEventArg(const Tizen::Base::String& text, const Tizen::Base::ByteBuffer& msgSerialNumber, const Tizen::Base::DateTime& receivedTime, int messageId, bool isEtwsNotification, byte dataCodingScheme, const Tizen::Base::String& languageType, _SmsEventType eventType) + : __result(E_UNKNOWN) + , __message(text) + , __port(-1) + , __dateTime(receivedTime) + , __eventType(eventType) //_SMS_EVENT_TYPE_CBS_RECEIVE_RESULT + , __pPushMsgBody(null) + , __pMsgSerialNumber(null) + , __pMsgSecurityInfo(null) + , __messageId(messageId) + , __isEtwsNotification(isEtwsNotification) + , __pEtwsWarningType(null) + , __dataCodingScheme(dataCodingScheme) + , __cbslanguageType(languageType) +{ + __pMsgSerialNumber = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_MSG, __pMsgSerialNumber != null, E_OUT_OF_MEMORY, "memory allocation failed"); + + __pMsgSerialNumber->Construct(msgSerialNumber); + __pMsgSerialNumber->SetPosition(0); +} + +_SmsEventArg::_SmsEventArg(const Tizen::Base::DateTime& receivedTime, const Tizen::Base::ByteBuffer& msgSerialNumber, const Tizen::Base::ByteBuffer& msgSecurityInfo, int messageId, const Tizen::Base::ByteBuffer& etwsWarningType, _SmsEventType eventType) + : __result(E_UNKNOWN) + , __port(-1) + , __dateTime(receivedTime) + , __eventType(eventType) //_SMS_EVENT_TYPE_ETWS_RECEIVE_RESULT + , __pPushMsgBody(null) + , __pMsgSerialNumber(null) + , __pMsgSecurityInfo(null) + , __messageId(messageId) + , __pEtwsWarningType(null) +{ + __pMsgSerialNumber = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_MSG, __pMsgSerialNumber != null, E_OUT_OF_MEMORY, "memory allocation failed"); + + __pMsgSerialNumber->Construct(msgSerialNumber); + __pMsgSerialNumber->SetPosition(0); + + __pMsgSecurityInfo = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_MSG, __pMsgSecurityInfo != null, E_OUT_OF_MEMORY, "memory allocation failed"); + + __pMsgSecurityInfo->Construct(msgSecurityInfo); + __pMsgSecurityInfo->SetPosition(0); + + __pEtwsWarningType = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_MSG, __pEtwsWarningType != null, E_OUT_OF_MEMORY, "memory allocation failed"); + + __pEtwsWarningType->Construct(etwsWarningType); + __pEtwsWarningType->SetPosition(0); +} + +_SmsEventArg::_SmsEventArg(const Tizen::Base::String& pushMsgHdr, const Tizen::Base::ByteBuffer& pushMsgBody, _SmsEventType eventType) + : __result(E_UNKNOWN) + , __message(pushMsgHdr) + , __port(-1) + , __eventType(eventType) //_SMS_EVENT_TYPE_WAP_PUSH_RECEIVE_RESULT + , __pMsgSerialNumber(null) + , __pMsgSecurityInfo(null) + , __pEtwsWarningType(null) +{ + __pPushMsgBody = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_MSG, __pPushMsgBody != null, E_OUT_OF_MEMORY, "memory allocation failed"); + + __pPushMsgBody->Construct(pushMsgBody); + __pPushMsgBody->SetPosition(0); +} + +_SmsEventArg::~_SmsEventArg(void) +{ + if (__pPushMsgBody) + { + delete __pPushMsgBody; + __pPushMsgBody = null; + } + + if (__pMsgSerialNumber) + { + delete __pMsgSerialNumber; + __pMsgSerialNumber = null; + } + + if (__pMsgSecurityInfo) + { + delete __pMsgSecurityInfo; + __pMsgSecurityInfo = null; + } + + if (__pEtwsWarningType) + { + delete __pEtwsWarningType; + __pEtwsWarningType = null; + } +} + +void +_SmsEventArg::GetErrorResult(result& r) const +{ + if (__eventType == _SMS_EVENT_TYPE_SMS_SEND_RESULT) + { + r = __result; + } + else + { + r = E_UNKNOWN; + } +} + +int +_SmsEventArg::GetPort(void) const +{ + if (__eventType == _SMS_EVENT_TYPE_SMS_SEND_RESULT || __eventType == _SMS_EVENT_TYPE_NONE) + { + return -1; + } + + return __port; +} + +DateTime +_SmsEventArg::GetDateTime(void) const +{ + if (__eventType == _SMS_EVENT_TYPE_SMS_SEND_RESULT || __eventType == _SMS_EVENT_TYPE_NONE) + { + DateTime dt; + dt.SetValue(9999, 12, 31); + return dt; + } + + return __dateTime; +} + +String +_SmsEventArg::GetMessage(void) const +{ + if (__eventType == _SMS_EVENT_TYPE_SMS_SEND_RESULT || __eventType == _SMS_EVENT_TYPE_NONE) + { + return L""; + } + + return __message; +} + +String +_SmsEventArg::GetSenderAddress(void) const +{ + return __sender; +} + +_SmsEventType +_SmsEventArg::GetEventType(void) const +{ + return __eventType; +} + +Tizen::Base::ByteBuffer* +_SmsEventArg::GetWapPushBody(void) const +{ + return __pPushMsgBody; +} + +int +_SmsEventArg::GetMessageId(void) const +{ + return __messageId; +} + +Tizen::Base::ByteBuffer* +_SmsEventArg::GetSerialNumber(void) const +{ + return __pMsgSerialNumber; +} + +Tizen::Base::ByteBuffer* +_SmsEventArg::GetWarningSecurityInfo(void) const +{ + return __pMsgSecurityInfo; +} + +Tizen::Base::ByteBuffer* +_SmsEventArg::GetEtwsWarningType(void) const +{ + return __pEtwsWarningType; +} + +bool +_SmsEventArg::GetEtwsNotification(void) const +{ + return __isEtwsNotification; +} + +byte +_SmsEventArg::GetDataCodingScheme(void) const +{ + return __dataCodingScheme; +} + +Tizen::Base::String +_SmsEventArg::GetCbsLanguageType(void) const +{ + return __cbslanguageType; +} + +} } diff --git a/src/FMsg_SmsEventArg.h b/src/FMsg_SmsEventArg.h new file mode 100644 index 0000000..8c6e690 --- /dev/null +++ b/src/FMsg_SmsEventArg.h @@ -0,0 +1,253 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_SmsEventArg.h + * @brief This is the header file for _SmsEventArg class. + * + * This header file contains the declarations of _SmsEventArg class. + */ + + +#ifndef _FMSG_INTERNAL_SMS_EVENT_ARG_H_ +#define _FMSG_INTERNAL_SMS_EVENT_ARG_H_ + +// Includes +#include +#include +#include +#include +#include +#include +#include "FMsg_Types.h" + +namespace Tizen { namespace Messaging +{ + +// +// @class _SmsEventArg +// @brief This class provides methods for getting data from SMS event +// @since 1.0 +// + +class _SmsEventArg + : public Tizen::Base::Object + , public Tizen::Base::Runtime::IEventArg +{ + // Life cycle +public: + /** + * This is the default constructor. + * + */ + _SmsEventArg(void); + + /** + * This is the constructor. + * + * @param[in] r - the result + */ + _SmsEventArg(const result r); + + /** + * This is the constructor. + * + * @param[in] port The port number + * @param[in] dateTime The received date time + * @param[in] message The received message + * @param[in] senderAddress The sender address of the message + */ + _SmsEventArg(int port, const Tizen::Base::DateTime& dateTime, const Tizen::Base::String& message, const Tizen::Base::String& senderAddress); + + /** + * This is the constructor. + * + * @param[in] text The body text of the message + * @param[in] senderAddress The sender address of the message + * @param[in] receivedTime The received time of the message + */ + _SmsEventArg(const Tizen::Base::String& text, const Tizen::Base::String& senderAddress, const Tizen::Base::DateTime& receivedTime); + + /** + * This is the constructor. + * + * @param[in] text The body text of the message + * @param[in] msgSerialNumber The msg SerialNumber of the message + * @param[in] receivedTime The received time of the message + * @param[in] messageId The messageId of the message + * @param[in] isEtwsNotification The Etws Notification + * @param[in] eventType The received event type of the message + */ + _SmsEventArg(const Tizen::Base::String& text, const Tizen::Base::ByteBuffer& msgSerialNumber, const Tizen::Base::DateTime& receivedTime, int messageId, bool isEtwsNotification, byte dataCodingScheme, const Tizen::Base::String& languageType, _SmsEventType eventType); + + /** + * This is the constructor. + * + * @param[in] receivedTime The received time of the message + * @param[in] msgSerialNumber The msg SerialNumber of the message + * @param[in] msgSecurityInfo The msg Security Info + * @param[in] messageId The messageId of the message + * @param[in] etwsWarningType The Etws Warning Type + * @param[in] eventType The received event type of the message + */ + _SmsEventArg(const Tizen::Base::DateTime& receivedTime, const Tizen::Base::ByteBuffer& msgSerialNumber, const Tizen::Base::ByteBuffer& msgSecurityInfo, int messageId, const Tizen::Base::ByteBuffer& etwsWarningType, _SmsEventType eventType); + + + /** + * This is the constructor. + * + * @param[in] pushMsgHdr The header of the message + * @param[in] pushMsgBody The body text of the message + * @param[in] eventType The received event type of the message + */ + _SmsEventArg(const Tizen::Base::String& pushMsgHdr, const Tizen::Base::ByteBuffer& pushMsgBody, _SmsEventType eventType); + + + /** + * This is class destructor. + * + */ + virtual ~_SmsEventArg(void); + + // Access +public: + /** + * Gets the error result of SMS sending + * + * @param[out] r - the message composer result + * @exception E_SUCCESS - operation is successful + * @exception E_OUT_OF_MEMORY - failed to allocate required/requested memory + * @exception E_SYSTEM - the system has an error. + */ + void GetErrorResult(result& r) const; + + /** + * Gets the port number + * + * @return the port number + */ + int GetPort(void) const; + + /** + * Gets the date time + * + * @return the date time + */ + Tizen::Base::DateTime GetDateTime(void) const; + + /** + * Gets the received message + * + * @return the received message + */ + Tizen::Base::String GetMessage(void) const; + + /** + * Gets the sender address + * + * @return the sender address + */ + Tizen::Base::String GetSenderAddress(void) const; + + /** + * Gets the serial number + * + * @return the serial number + */ + Tizen::Base::ByteBuffer* GetSerialNumber(void) const; + + /** + * Gets the security info + * + * @return the security info + */ + Tizen::Base::ByteBuffer* GetWarningSecurityInfo(void) const; + + /** + * Gets the mesage id + * + * @return the mesage id + */ + int GetMessageId(void) const; + + /** + * Gets the cbs message ETWS status + * + * @return ETWS status + */ + bool GetEtwsNotification(void) const; + + /** + * Gets the cbs message Data Coding Scheme + * + * @return Data Coding scheme + */ + byte GetDataCodingScheme(void) const; + + /** + * Gets the event type + * + * @return the event type + */ + _SmsEventType GetEventType(void) const; + + /** + * Gets the event type + * + * @return the event type + */ + Tizen::Base::ByteBuffer* GetEtwsWarningType(void) const; + + /** + * Gets the wap push body + * + * @return wap push body + */ + + Tizen::Base::ByteBuffer* GetWapPushBody(void) const; + + /** + * + * Gets the language type of a CB message. + * + * @return The language type of a message + */ + Tizen::Base::String GetCbsLanguageType(void) const; + +private: + _SmsEventArg(const _SmsEventArg& eventArg); + _SmsEventArg& operator =(const _SmsEventArg& value); + +private: + result __result; + Tizen::Base::String __message; + int __port; + Tizen::Base::String __sender; + Tizen::Base::DateTime __dateTime; + _SmsEventType __eventType; + Tizen::Base::ByteBuffer* __pPushMsgBody; + Tizen::Base::ByteBuffer* __pMsgSerialNumber; + Tizen::Base::ByteBuffer* __pMsgSecurityInfo; + int __messageId; + bool __isEtwsNotification; + Tizen::Base::ByteBuffer* __pEtwsWarningType; + byte __dataCodingScheme; + Tizen::Base::String __cbslanguageType; +}; // _SmsEventArg + +} } + +#endif // _FMSG_INTERNAL_SMS_EVENT_ARG_H_ diff --git a/src/FMsg_SmsManagerImpl.cpp b/src/FMsg_SmsManagerImpl.cpp new file mode 100644 index 0000000..715f671 --- /dev/null +++ b/src/FMsg_SmsManagerImpl.cpp @@ -0,0 +1,1128 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_SmsManagerImpl.cpp + * @brief This is the implementation file for the %_SmsManagerImpl class. + * + * This file contains the implementation of the %_SmsManagerImpl class. + */ + +// OAF headers +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_SmsManagerImpl.h" +#include "FMsg_SmsMessageImpl.h" +#include "FMsg_SmsEvent.h" +#include "FMsg_MsgUtil.h" +#include "FMsg_RecipientListImpl.h" +#include "FMsg_SmsMmsCallbackHandler.h" +#include "FMsg_CbsChannelImpl.h" +#include "FMsg_MessagingIpcProxy.h" + + +using namespace std; +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; + +namespace Tizen { namespace Messaging +{ + +_SmsManagerImpl::_SmsManagerImpl(void) + : __isConstructed(false) + , __isCbsSaveEnabled(true) + , __pSmsEvent(null) + , __pSmsReceiveEvent(null) + , __pCbsReceiveEvent(null) + , __pEtwsReceiveEvent(null) + , __pSmsTriggerEventList(null) + , __msgHandle(0) + , __pCbsListener(null) + , __pEtwsListener(null) + ,__isOpenCbsHandle(0) +{ +} + +_SmsManagerImpl::~_SmsManagerImpl(void) +{ + + if (__pSmsReceiveEvent) + { + delete __pSmsReceiveEvent; + __pSmsReceiveEvent = null; + } + + if (__pCbsReceiveEvent) + { + delete __pCbsReceiveEvent; + __pCbsReceiveEvent = null; + } + + if (__pEtwsReceiveEvent) + { + delete __pEtwsReceiveEvent; + __pEtwsReceiveEvent = null; + } + + if (__pSmsTriggerEventList) + { + if (__pSmsTriggerEventList->GetCount() > 0) + { + __pSmsTriggerEventList->RemoveAll(true); + } + delete __pSmsTriggerEventList; + __pSmsTriggerEventList = null; + } + + if (_SmsMmsCallbackHandler::GetInstance()) + { + _SmsMmsCallbackHandler::GetInstance()->CloseMessageHandle(); + } + + __isConstructed = false; +} + +result +_SmsManagerImpl::Construct(const ISmsListener& listener) +{ + // method return code + result r = E_SUCCESS; + int err = MSG_SUCCESS; + + SysAssertf(__isConstructed == false, "_SmsManagerImpl instance is already constructed."); + + // set event + unique_ptr<_SmsEvent> pSmsEvent(new (std::nothrow) _SmsEvent()); + SysTryReturn(NID_MSG, pSmsEvent != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed."); + + // event construction + r = pSmsEvent->Construct(_SMS_EVENT_TYPE_SMS_SEND_RESULT); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to construct an instance"); + + // add listener + r = pSmsEvent->AddListener(listener, true); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to add a listener"); + + SysTryReturnResult(NID_MSG, _SmsMmsCallbackHandler::GetInstance() != NULL, E_SYSTEM, "Failed to constructSmsMmsCallbackHandler."); + + // open message handle + err = _SmsMmsCallbackHandler::GetInstance()->OpenMessageHandle(__msgHandle); + SysLog(NID_MSG, "value of __msgHandle is [%d]", __msgHandle); + + r = ConvertException(err); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to open messageHandle."); + + // check value of msg handle + SysTryReturnResult(NID_MSG, __msgHandle > 0, E_SYSTEM, "msgHandle is invalid."); + + // register sent status callback + err = _SmsMmsCallbackHandler::GetInstance()->RegisterMessageCallback(); + + r = ConvertException(err); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to register sms,mms callback."); + + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->OpenMsgHandle(); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to open messageHandle."); + r = _MessagingProxy::GetInstance()->OpenCbsHandle(); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to open cbs Settings Handle"); + __isOpenCbsHandle = true; + + + __pSmsEvent = move(pSmsEvent); + __isConstructed = true; + + return r; +} + +result +_SmsManagerImpl::AddSmsEventListener(int port, ISmsEventListener& eventListener) +{ + // checking conditions + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + + result r = E_SUCCESS; + _SmsEvent* pSmsTriggerEvent = null; + + // check duplications + if (__pSmsTriggerEventList) + { + int listSize = __pSmsTriggerEventList->GetCount(); + for (int i = 0; i < listSize; i++) + { + _SmsEvent* pItem = static_cast <_SmsEvent*>(__pSmsTriggerEventList->GetAt(i)); + if (pItem->GetPort() == port) + { + r = E_OBJ_ALREADY_EXIST; + SysLogException(NID_MSG, r, "[%s] The specific port [%d] is already registered.", GetErrorMessage(r), port); + goto CATCH; + } + } + } + + // make an sms trigger event + pSmsTriggerEvent = new (std::nothrow) _SmsEvent(); + SysTryReturn(NID_MSG, pSmsTriggerEvent != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed"); + + // construct an sms trigger event + r = pSmsTriggerEvent->Construct(port); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct an instance.", GetErrorMessage(r)); + + // add corresponding listener to the event + r = pSmsTriggerEvent->AddListener(eventListener, true); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to add a listener.", GetErrorMessage(r)); + + // make a list for events + if (!__pSmsTriggerEventList) + { + __pSmsTriggerEventList = new (std::nothrow) ArrayList(); + SysTryReturnResult(NID_MSG, __pSmsTriggerEventList != null, E_OUT_OF_MEMORY, "memory allocation failed."); + + r = __pSmsTriggerEventList->Construct(); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to construct an instance.", GetErrorMessage(r)); + } + // add an event to the list + r = __pSmsTriggerEventList->Add(*pSmsTriggerEvent); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to add a listener.", GetErrorMessage(r)); + + SysTryCatch(NID_MSG, _MessagingProxy::GetInstance()!= null, ,E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->AddSmsEventListener(port, __pSmsTriggerEventList); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to add a listener.", GetErrorMessage(r)); + + return r; + +CATCH: + if (pSmsTriggerEvent) + { + __pSmsTriggerEventList->Remove(*pSmsTriggerEvent); + delete pSmsTriggerEvent; + } + + return r; +} + +result +_SmsManagerImpl::RemoveSmsEventListener(int port, ISmsEventListener& eventListener) +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + + result r = E_SUCCESS; + int index = -1; + int listSize = -1; + bool isFound = false; + + // find the SmsTriggerEvent using port + if (__pSmsTriggerEventList) + { + listSize = __pSmsTriggerEventList->GetCount(); + for (int i = 0; i < listSize; i++) + { + _SmsEvent* pItem = static_cast <_SmsEvent*>(__pSmsTriggerEventList->GetAt(i)); + if (pItem->GetPort() == port) + { + index = i; + isFound = true; + break; + } + } + } + + // if not found.. + SysTryReturn(NID_MSG, isFound, E_OBJ_NOT_FOUND, r = E_OBJ_NOT_FOUND, "Failed to find the SMS event listener"); + + // remove corresponding event from the list + r = __pSmsTriggerEventList->RemoveAt(index, true); + + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "Failed to remove the event listener"); + + return r; +} + +result +_SmsManagerImpl::AddSmsMessageEventListener(const ISmsMessageEventListener& eventListener) +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + + result r = E_SUCCESS; + int err = MSG_SUCCESS; + + // set event + if (!__pSmsReceiveEvent) + { + __pSmsReceiveEvent = new (std::nothrow) _SmsEvent(); + SysTryReturn(NID_MSG, __pSmsReceiveEvent != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed"); + + r = __pSmsReceiveEvent->Construct(_SMS_EVENT_TYPE_SMS_RECEIVE_RESULT); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "Failed to construct an instance"); + } + + // add listener + r = __pSmsReceiveEvent->AddListener(eventListener, true); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "Failed to add a listener"); + + err = _SmsMmsCallbackHandler::GetInstance()->RegisterIncomingMessageCallback(__pSmsReceiveEvent); + + r = ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to register for incoming sms callback.", GetErrorMessage(r)); + + if (_SmsMmsCallbackHandler::GetInstance()) + { + _SmsMmsCallbackHandler::GetInstance()->SetInComingSmsCallback(true); + } + + return E_SUCCESS; + +CATCH: + if (__pSmsReceiveEvent) + { + delete __pSmsReceiveEvent; + __pSmsReceiveEvent = null; + } + + return r; +} + +result +_SmsManagerImpl::RemoveSmsMessageEventListener(const ISmsMessageEventListener& eventListener) +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + + result r = E_SUCCESS; + + SysTryReturnResult(NID_MSG, __pSmsReceiveEvent != NULL, E_OBJ_NOT_FOUND, "Failed to remove a listener"); + + r = __pSmsReceiveEvent->RemoveListener(eventListener); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to remove a listener..", GetErrorMessage(r)); + + if (_SmsMmsCallbackHandler::GetInstance()) + { + _SmsMmsCallbackHandler::GetInstance()->SetInComingSmsCallback(false); + } + + if (__pSmsReceiveEvent) + { + delete __pSmsReceiveEvent; + __pSmsReceiveEvent = null; + } + + return r; + +CATCH: + return r; +} + +int +_SmsManagerImpl::GetTotalMessageCount(SmsMessageBoxType type) const +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + + int msgCount = 0; + msg_struct_t countInfo = NULL; + int err = MSG_SUCCESS; + _MSG_FOLDER_ID_E folderType = MSG_ALLBOX_ID; + result r = E_SUCCESS; + + ClearLastResult(); + + switch (type) + { + case SMS_MESSAGE_BOX_TYPE_INBOX: + folderType = MSG_INBOX_ID; + break; + case SMS_MESSAGE_BOX_TYPE_SENTBOX: + folderType = MSG_SENTBOX_ID; + break; + case SMS_MESSAGE_BOX_TYPE_OUTBOX: + folderType = MSG_OUTBOX_ID; + break; + case SMS_MESSAGE_BOX_TYPE_ALL: + { + int inbox = 0; + int outbox = 0; + int sentbox =0; + + + countInfo = msg_create_struct(MSG_STRUCT_COUNT_INFO); + + err = msg_count_message(__msgHandle, MSG_INBOX_ID , countInfo); + r = ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to get the message count of the message box (%d)", GetErrorMessage(r), (int) type); + msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &inbox); + + err = msg_count_message(__msgHandle, MSG_OUTBOX_ID , countInfo); + r = ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to get the message count of the message box (%d)", GetErrorMessage(r), (int) type); + msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &outbox); + + err = msg_count_message(__msgHandle, MSG_SENTBOX_ID , countInfo); + r = ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to get the message count of the message box (%d)", GetErrorMessage(r), (int) type); + msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &sentbox); + + msg_release_struct(&countInfo); + + msgCount = inbox + outbox + sentbox; + SysLog(NID_MSG, "Total count of messages is [%d] , inbox[%d], outbox[%d], sentbox[%d]",msgCount, inbox, outbox, sentbox); + + return msgCount; + } + break; + case SMS_MESSAGE_BOX_TYPE_NONE: // impossible case + break; + default: + break; + } + + // get the count of corresponding message box + countInfo = msg_create_struct(MSG_STRUCT_COUNT_INFO); + err = msg_count_message(__msgHandle, folderType, countInfo); + r = ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to get the message count of the message box (%d)", GetErrorMessage(r), (int) type); + + msg_get_int_value(countInfo, MSG_COUNT_INFO_SMS_INT, &msgCount); + msg_release_struct(&countInfo); + SysLog(NID_MSG, "Total count of messages is [%d]", msgCount); + + return msgCount; + + +CATCH: + + msg_release_struct(&countInfo); + return -1; + +} + +Tizen::Base::Collection::IList* +_SmsManagerImpl::SearchInboxN(const Tizen::Base::String* pKeyword, const Tizen::Base::String* pSenderAddress, int startIndex, + int count, + int& totalResultCount) const +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + + char* pSearchString = NULL; + char* pSenderAddressTemp = NULL; + ArrayList* pList = null; + int err = MSG_SUCCESS; + result r = E_SUCCESS; + msg_struct_list_s msgList = {0}; + msg_struct_t searchCon = NULL; + + ClearLastResult(); + + pList = new (std::nothrow) ArrayList(); + SysTryCatch(NID_MSG, pList != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + // make a list + r = pList->Construct(); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "Failed to construct an ArrayList"); + + // Set Condition + searchCon = msg_create_struct(MSG_STRUCT_SEARCH_CONDITION); + msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_FOLDERID_INT, MSG_INBOX_ID); + msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_MSGTYPE_INT, MSG_TYPE_SMS); + + // keyword + if (pKeyword) + { + pSearchString = _StringConverter::CopyToCharArrayN(*pKeyword); + SysTryCatch(NID_MSG, pSearchString != null, r = E_OUT_OF_MEMORY, r, "Memory allocation failed."); + msg_set_str_value(searchCon, MSG_SEARCH_CONDITION_SEARCH_VALUE_STR, pSearchString, strlen(pSearchString)); + } + + // sender address + if (pSenderAddress) + { + pSenderAddressTemp = _StringConverter::CopyToCharArrayN(*pSenderAddress); + SysTryCatch(NID_MSG, pSenderAddressTemp != null, r = E_OUT_OF_MEMORY, r, "Memory allocation failed."); + msg_set_str_value(searchCon, MSG_SEARCH_CONDITION_ADDRESS_VALUE_STR, pSenderAddressTemp, strlen(pSenderAddressTemp)); + } + + // Search + err = msg_search_message(__msgHandle, searchCon, startIndex, count, &msgList); + + r = ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] msg_search_message call failed.", GetErrorMessage(r)); + + totalResultCount = msgList.nCount; + + SysLog(NID_MSG, "Total Search count of messages is [%d]", totalResultCount); + + for (int index = 0; index < totalResultCount; index++) + { + // get SmsMessage instance + SmsMessage* pSmsMessage = _MsgUtil::ConvertSmsMessageN(SMS_MESSAGE_BOX_TYPE_INBOX, msgList.msg_struct_info[index]); + // add to the list + pList->Add(*pSmsMessage); + } + + if (pSearchString) + { + delete[] pSearchString; + pSearchString = NULL; + } + + if (pSenderAddressTemp) + { + delete[] pSenderAddressTemp; + pSenderAddressTemp = NULL; + } + + msg_release_struct(&searchCon); + msg_release_list_struct(&msgList); + + return pList; + +CATCH: + if (pSearchString) + { + delete[] pSearchString; + pSearchString = NULL; + } + + if (pSenderAddressTemp) + { + delete[] pSenderAddressTemp; + pSenderAddressTemp = NULL; + } + + if (pList) + { + if (pList->GetCount() > 0) + { + pList->RemoveAll(true); + } + delete pList; + pList = null; + } + + msg_release_struct(&searchCon); + msg_release_list_struct(&msgList); + + return null; +} + +Tizen::Base::Collection::IList* +_SmsManagerImpl::SearchMessageBoxN(SmsMessageBoxType type, const Tizen::Base::String* pKeyword, int startIndex, int count, + int& totalResultCount) const +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + + result r = E_SUCCESS; + int err = MSG_SUCCESS; + char* pSearchString = NULL; + int folderId = MSG_ALLBOX_ID; + ArrayList* pList = NULL; + msg_struct_list_s msgList = {0}; + msg_struct_t searchCon = NULL; + int tempCount = 0; + ClearLastResult(); + + pList = new (std::nothrow) ArrayList(); + SysTryCatch(NID_MSG, pList != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + // make a list + r = pList->Construct(); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "Failed to construct an ArrayList"); + + // type + folderId = _MsgUtil::GetMsgFolderId(type); + SysLog(NID_MSG, "box type [%d]", (int)type); + + // Set Condition + searchCon = msg_create_struct(MSG_STRUCT_SEARCH_CONDITION); + msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_FOLDERID_INT, folderId); + msg_set_int_value(searchCon, MSG_SEARCH_CONDITION_MSGTYPE_INT, MSG_TYPE_SMS); + + // keyword + if (pKeyword) + { + pSearchString = _StringConverter::CopyToCharArrayN(*pKeyword); + SysTryCatch(NID_MSG, pSearchString != null, r = E_OUT_OF_MEMORY, r, "Memory allocation failed."); + msg_set_str_value(searchCon, MSG_SEARCH_CONDITION_SEARCH_VALUE_STR, pSearchString, strlen(pSearchString)); + } + + // Search + err = msg_search_message(__msgHandle, searchCon, startIndex, count, &msgList); + + r = ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] msg_search_message call failed.", GetErrorMessage(r)); + + + for (int index = 0; index < msgList.nCount; index++) + { + SmsMessage* pSmsMessage = null; + + + if (type == SMS_MESSAGE_BOX_TYPE_ALL) + { + err = msg_get_int_value(msgList.msg_struct_info[index], MSG_MESSAGE_FOLDER_ID_INT, &folderId); + SysLog(NID_MSG, "Folder [%d]", folderId); + + switch (folderId) + { + case MSG_INBOX_ID: + pSmsMessage = _MsgUtil::ConvertSmsMessageN(SMS_MESSAGE_BOX_TYPE_INBOX, msgList.msg_struct_info[index]); + break; + + case MSG_OUTBOX_ID: + pSmsMessage = _MsgUtil::ConvertSmsMessageN(SMS_MESSAGE_BOX_TYPE_OUTBOX, msgList.msg_struct_info[index]); + break; + + case MSG_SENTBOX_ID: + pSmsMessage = _MsgUtil::ConvertSmsMessageN(SMS_MESSAGE_BOX_TYPE_SENTBOX, msgList.msg_struct_info[index]); + break; + + default: + break; + } + + if (pSmsMessage) + { + tempCount++; + pList->Add(*pSmsMessage); + } + } + else + { + pSmsMessage = _MsgUtil::ConvertSmsMessageN(type, msgList.msg_struct_info[index]); + if (pSmsMessage) + { + tempCount++; + pList->Add(*pSmsMessage); + } + + } + } + totalResultCount = tempCount; + SysLog(NID_MSG, "Total Search count of messages is [%d] original [%d]", totalResultCount , msgList.nCount ); + + if (pSearchString) + { + delete[] pSearchString; + pSearchString = NULL; + } + + msg_release_struct(&searchCon); + msg_release_list_struct(&msgList); + + return pList; + +CATCH: + if (pList) + { + if (pList->GetCount() > 0) + { + pList->RemoveAll(true); + } + delete pList; + pList = null; + } + + if (pSearchString) + { + delete[] pSearchString; + pSearchString = NULL; + } + + msg_release_struct(&searchCon); + msg_release_list_struct(&msgList); + totalResultCount = 0; + + return null; +} + +Tizen::Base::String +_SmsManagerImpl::GetFullText(int messageId) const +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + + result r = E_SUCCESS; + String fullText; + msg_struct_t smsMsg = null; + msg_struct_t sendOpt = null; + int err = MSG_SUCCESS; + char msgText[MAX_MSG_TEXT_LEN]; + + ClearLastResult(); + + // get SMS message + smsMsg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO); + sendOpt = msg_create_struct(MSG_STRUCT_SENDOPT); + err = msg_get_message(__msgHandle, messageId, smsMsg, sendOpt); + + r = ConvertException(err); + SetLastResult(r); + + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] msg_get_message by messageid failed.", GetErrorMessage(r)); + + // get text + err = msg_get_str_value(smsMsg, MSG_MESSAGE_SMS_DATA_STR, msgText, MAX_MSG_TEXT_LEN); + SysTryCatch(NID_MSG, err == MSG_SUCCESS, r = E_SYSTEM, r, "sms get message body failed"); + + fullText = msgText; + + SysLog(NID_MSG, "Returned Full Text : [%ls]", fullText.GetPointer()); + + msg_release_struct(&sendOpt); + msg_release_struct(&smsMsg); + + return fullText; + +CATCH: + msg_release_struct(&sendOpt); + msg_release_struct(&smsMsg); + + return L""; +} + +result +_SmsManagerImpl::Send(const SmsMessage& message, const RecipientList& recipientList, bool saveToSentbox) +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + + result r = E_SUCCESS; + int err = MSG_SUCCESS; + int msgReqId = -1; + bool saveMsgToSentbox = saveToSentbox; + + SysLog(NID_MSG, "sending an sms message"); + + msg_struct_t msgReq = msg_create_struct(MSG_STRUCT_REQUEST_INFO); + msg_struct_t msgInfo = msg_create_struct(MSG_STRUCT_MESSAGE_INFO);; + msg_struct_t msgSendOpt = msg_create_struct(MSG_STRUCT_SENDOPT); + + msg_set_bool_value(msgSendOpt, MSG_SEND_OPT_SETTING_BOOL, true); + msg_set_bool_value(msgSendOpt, MSG_SEND_OPT_DELIVER_REQ_BOOL, false); + msg_set_bool_value(msgSendOpt, MSG_SEND_OPT_KEEPCOPY_BOOL, saveMsgToSentbox); + + err = _MsgUtil::GetSmsMessage(msgInfo, message, recipientList); + + r = ConvertException(err); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to generate the SMS message.", GetErrorMessage(r)); + + msg_set_struct_handle(msgReq, MSG_REQUEST_MESSAGE_HND, msgInfo); + msg_set_struct_handle(msgReq, MSG_REQUEST_SENDOPT_HND, msgSendOpt); + + if (err == MSG_SUCCESS) + { + err = msg_sms_send_message(__msgHandle, msgReq); + } + + r = ConvertException(err); + + if (r == E_SUCCESS) + { + if (_SmsMmsCallbackHandler::GetInstance()) + { + msg_get_int_value(msgReq, MSG_REQUEST_REQUESTID_INT, &msgReqId); + r = _SmsMmsCallbackHandler::GetInstance()->AddToMessageMap(msgReqId, _MSG_SMS, __pSmsEvent.get()); + } + else + { + r = E_SYSTEM; + } + } + + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Failed to send the SMS message.", GetErrorMessage(r)); + + //release message + msg_release_struct(&msgReq); + SysLog(NID_MSG, "sending an sms message success"); + return r; + +CATCH: + //release message + msg_release_struct(&msgReq); + return r; +} + +result +_SmsManagerImpl::SetCbsMessageEventListener(ICbsMessageEventListener* pListener) +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + + result r = E_SUCCESS; + + if (!pListener) + { + if (__pCbsReceiveEvent) + { + r = __pCbsReceiveEvent->RemoveListener(*__pCbsListener); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "Failed to reset the cbs message event listener."); + + __pCbsListener = null; + } + return r; + } + + // set listener + __pCbsListener = pListener; + + // set event + if (!__pCbsReceiveEvent) + { + __pCbsReceiveEvent = new (std::nothrow) _SmsEvent(); + SysTryCatch(NID_MSG, __pCbsReceiveEvent != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + r = __pCbsReceiveEvent->Construct(_SMS_EVENT_TYPE_CBS_RECEIVE_RESULT); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to construct an cbs listener instance"); + } + + // add listener + r = __pCbsReceiveEvent->AddListener(*__pCbsListener, true); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to add cbs listner"); + + SysTryCatch(NID_MSG, _MessagingProxy::GetInstance()!= null, r = E_OUT_OF_MEMORY,E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->AddCbsEtwsEventListener(__isCbsSaveEnabled); + + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to set cbs incoming callback"); + + if (r == E_SUCCESS) + { + _MessagingProxy::GetInstance()->SetCbsAndEtwsUserEvent(_MSG_CBS, __pCbsReceiveEvent); + } + else + { + r = E_SYSTEM; + } + + return r; + +CATCH: + if (__pCbsReceiveEvent) + { + delete __pCbsReceiveEvent; + __pCbsReceiveEvent = null; + } + __pCbsListener = null; + + return r; +} + +result +_SmsManagerImpl::SetEtwsPrimaryNotificationEventListener(IEtwsPrimaryNotificationEventListener* pListener) +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + + result r = E_SUCCESS; + + if (!pListener) + { + if (__pEtwsReceiveEvent) + { + r = __pEtwsReceiveEvent->RemoveListener(*__pEtwsListener); + SysTryReturnResult(NID_MSG, r == E_SUCCESS, E_SYSTEM, "Failed to reset the etws primary notification event listener."); + + __pEtwsListener = null; + } + return r; + } + + // set listener + __pEtwsListener = pListener; + + // set event + if (!__pEtwsReceiveEvent) + { + __pEtwsReceiveEvent = new (std::nothrow) _SmsEvent(); + SysTryCatch(NID_MSG, __pEtwsReceiveEvent != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + r = __pEtwsReceiveEvent->Construct(_SMS_EVENT_TYPE_ETWS_RECEIVE_RESULT); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, + "Failed to construct an etws primary notification event listener instance"); + } + + // add listener + r = __pEtwsReceiveEvent->AddListener(*__pEtwsListener, true); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "Failed to add an etws primary notification event listener."); + + SysTryCatch(NID_MSG, _MessagingProxy::GetInstance()!= null, r = E_OUT_OF_MEMORY,E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->AddCbsEtwsEventListener(__isCbsSaveEnabled); + SysTryCatch(NID_MSG, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM,"Failed to add an etws primary notification event listener."); + + if (r == E_SUCCESS) + { + _MessagingProxy::GetInstance()->SetCbsAndEtwsUserEvent(_MSG_ETWS, __pEtwsReceiveEvent); + } + else + { + r = E_SYSTEM; + } + + + return r; + +CATCH: + if (__pEtwsReceiveEvent) + { + delete __pEtwsReceiveEvent; + __pEtwsReceiveEvent = null; + } + __pEtwsListener = null; + + return r; +} + +result +_SmsManagerImpl::SetSavingToCbsBoxEnabled(bool enable) +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + result r = E_SUCCESS; + SysTryReturnResult(NID_MSG, __isOpenCbsHandle == true, E_SYSTEM, "Cb handle is null"); + + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->SetSavingToCbsBoxEnabled(enable); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "[%s] Setting of CbsBoxEnabled Failed", GetErrorMessage(r)); + + __isCbsSaveEnabled = enable; + + return r; +} + +bool +_SmsManagerImpl::IsCbsEnabled(void) const +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + SysTryReturn(NID_MSG, __isOpenCbsHandle != false, false, E_SYSTEM, "Cb handle is null"); + + bool isCbsEnabled = false; + result r = E_SUCCESS; + + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, false, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->IsCbsEnabled(&isCbsEnabled); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "[%s] Geting the Cbs Status Failed ", GetErrorMessage(r)); + + return isCbsEnabled; +} + +result +_SmsManagerImpl::SetCbsEnabled(bool enable) +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + result r = E_SUCCESS; + SysTryReturnResult(NID_MSG, __isOpenCbsHandle != false, E_SYSTEM, "Cb handle is null"); + + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->SetCbsEnabled(enable); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "[%s] Set status failed", GetErrorMessage(r)); + + + return r; +} + +result +_SmsManagerImpl::AddCbsChannel(int from, int to, Tizen::Base::String& name, bool activate) +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + result r = E_SUCCESS; + SysTryReturnResult(NID_MSG, __isOpenCbsHandle != false, E_SYSTEM, "Cb handle is null"); + + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->AddCbsChannel(from, to, name, activate); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "[%s] adding channel Failed", GetErrorMessage(r)); + + return r; +} + +result +_SmsManagerImpl::RemoveCbsChannel(int from, int to) +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + SysTryReturnResult(NID_MSG, __isOpenCbsHandle != false, E_SYSTEM, "Cb handle is null"); + + result r = E_SUCCESS; + + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->RemoveCbsChannel(from, to); + SysTryReturn(NID_MSG, r == E_SUCCESS, r, r, "[%s] To remove channel Failed", GetErrorMessage(r)); + + + return r; +} + +CbsChannel* +_SmsManagerImpl::GetCbsChannelN(int from, int to) const +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + SysTryReturn(NID_MSG, __isOpenCbsHandle != null, null, E_SYSTEM, "Cb handle is null."); + + result r = E_SUCCESS; + bool isActive = false; + String channelName; + std::unique_ptr pCbsChannel; + + SysTryReturn(NID_MSG, _MessagingProxy::GetInstance()!= null, null, E_OUT_OF_MEMORY,"Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->GetCbsChannelN(from, to, isActive, channelName); + SysTryReturn(NID_MSG, r == E_SUCCESS, null, r, "Failed to get msg proxy instance"); + + // creates channel + pCbsChannel.reset(_CbsChannelImpl::GetCbsChannelN(from, to, channelName)); + + if (isActive) + { + _CbsChannelImpl::GetInstance(*pCbsChannel.get())->SetCbsChannelState(true); + + } + + return pCbsChannel.release(); +} + +Tizen::Base::Collection::IList* +_SmsManagerImpl::GetCbsChannelListN(void) +{ + SysAssertf(__isConstructed == true, "_SmsManagerImpl instance is not constructed yet."); + SysAssertf(__msgHandle > 0, "message handle is invalid."); + SysTryReturn(NID_MSG, __isOpenCbsHandle != null, null, E_SYSTEM, "Cb handle is null."); + + result r = E_SUCCESS; + unique_ptr pList; + int cbChannelCount = 0; + int fromId = 0; + int toId = 0; + int isActive = false; + String channelName; + std::unique_ptr pCbsChannel; + Tizen::Base::Collection::ArrayList pCbsList; + + ClearLastResult(); + + pList.reset(new (std::nothrow) ArrayList(SingleObjectDeleter)); + SysTryReturn(NID_MSG, pList != null, null, E_OUT_OF_MEMORY, "Memory allocation failed."); + + // make a list + r = pList->Construct(); + SysTryReturn(NID_MSG, r == E_SUCCESS, null, r, "Failed to construct array list."); + + + SysTryReturn(NID_MSG, _MessagingProxy::GetInstance()!= null, null, E_OUT_OF_MEMORY,"Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->GetCbsChannelListN(pCbsList); + SysTryReturn(NID_MSG, r == E_SUCCESS, null, r, "Failed to get msg proxy instance"); + + + cbChannelCount = pCbsList.GetCount(); + for (int index = 0; index < cbChannelCount; ) + { + + Integer::Parse(*static_cast (pCbsList.GetAt(index++)), fromId); + Integer::Parse(*static_cast (pCbsList.GetAt(index++)), toId); + channelName = *static_cast (pCbsList.GetAt(index++)); + Integer::Parse(*static_cast (pCbsList.GetAt(index++)),isActive); + SysLog(NID_MSG, "cbs %d, %d, %ls, %d",fromId, toId, channelName.GetPointer(),(bool)isActive); + + pCbsChannel.reset(_CbsChannelImpl::GetCbsChannelN(fromId, toId, channelName)); + if (isActive) + { + _CbsChannelImpl::GetInstance(*pCbsChannel.get())->SetCbsChannelState((bool)isActive); + + } + pList->Add(*pCbsChannel.release()); + } + pCbsList.RemoveAll(); + + return pList.release(); +} + +_SmsManagerImpl* +_SmsManagerImpl::GetInstance(SmsManager& smsManager) +{ + return smsManager.__pImpl; +} + +const _SmsManagerImpl* +_SmsManagerImpl::GetInstance(const SmsManager& smsManager) +{ + return smsManager.__pImpl; +} + +result +_SmsManagerImpl::ConvertException(int err) const +{ + result r = E_SUCCESS; + + switch (err) + { + case MSG_SUCCESS: + r = E_SUCCESS; + break; + + case MSG_ERR_INVALID_PARAMETER: + case MSG_ERR_INVALID_MESSAGE: + case MSG_ERR_NULL_POINTER: + case MSG_ERR_NULL_MESSAGE: + r = E_INVALID_ARG; + break; + + case MSG_ERR_MEMORY_ERROR: + r = E_OUT_OF_MEMORY; + break; + + case MSG_ERR_STORAGE_ERROR: + r = E_STORAGE_FULL; + break; + + case MSG_ERR_DB_STEP: + r = E_OBJ_NOT_FOUND; + break; + + case MSG_ERR_SERVER_NOT_READY: + case MSG_ERR_TRANSPORT_ERROR: + case MSG_ERR_COMMUNICATION_ERROR: + r = E_NETWORK_UNAVAILABLE; + break; + + case MSG_ERR_NO_SIM: + r = E_DEVICE_UNAVAILABLE; + break; + + case MSG_ERR_PLUGIN_TAPI_FAILED: + r = E_FAILURE; + break; + + default: + r = E_SYSTEM; + break; + } + + return r; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_SmsManagerImpl.h b/src/FMsg_SmsManagerImpl.h new file mode 100644 index 0000000..548cc04 --- /dev/null +++ b/src/FMsg_SmsManagerImpl.h @@ -0,0 +1,389 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_SmsManagerImpl.h + * @brief This is the header file for the _SmsManagerImpl class. + * + * This header file contains the declarations of the _SmsManagerImpl class. + */ + +#ifndef _FMSG_INTERNAL_SMS_MANAGER_IMPL_H_ +#define _FMSG_INTERNAL_SMS_MANAGER_IMPL_H_ + +#include "FMsg_Types.h" + +namespace Tizen { namespace Messaging +{ + +/** +* @class _SmsManagerImpl +* @brief This class provides methods to use the SMS messaging service. +* @since 1.0 +* +* This class provides methods to use the SMS messaging service. @n +*/ + +// forward declaration +class _SmsEvent; +class SmsManager; + +class _SmsManagerImpl + : public Tizen::Base::Object +{ + // Life cycle +public: + /** + * This is the default constructor for this class. + */ + _SmsManagerImpl(void); + + /** + * This is the destructor for this class. + */ + virtual ~_SmsManagerImpl(void); + +private: + _SmsManagerImpl(const _SmsManagerImpl& value); + _SmsManagerImpl& operator =(const _SmsManagerImpl& rhs); + + + // Operation +public: + /** + * Initializes this instance of _SmsManagerImpl with the specified listener. + * + * @return An error code + * @param[in] listener The listener to receive a send result asynchronously + * @exception E_SUCCESS The method was successful. + */ + result Construct(const ISmsListener& listener); + + /** + * Adds the event listener for receiving SMS messages. + * + * @return An error code + * @param[in] port A port number + * @param[in] eventListener The listener to receive SMS messages + * @exception E_SUCCESS The method was successful. + * @exception E_OBJ_ALREADY_EXIST The port number was already registered. + * @exception E_FAILURE The port number was already used in other applications. + * @exception E_INVALID_ARG The value of the specified @c port is invalid. @n + * The port number should range from 1 to 9999 (1 <= port <= 9999). + * @see ISmsEventListener, RemoveSmsEventListener() + */ + result AddSmsEventListener(int port, ISmsEventListener& eventListener); + + /** + * Removes the event listener for receiving SMS messages. + * + * @return An error code + * @param[in] port A port number + * @param[in] eventListener The listener to receive SMS messages + * @exception E_SUCCESS The method was successful. + * @exception E_OBJ_NOT_FOUND The listener was not found. + * @exception E_SYSTEM A system error occurred. + * @exception E_INVALID_ARG The value of the specified @c port is invalid. @n + * The port number should range from 1 to 9999 (1 <= port <= 9999). + * @see ISmsEventListener, AddSmsEventListener() + */ + result RemoveSmsEventListener(int port, ISmsEventListener& eventListener); + + /** + * Adds the event listener for receiving SMS messages. + * + * @return An error code + * @param[in] eventListener The listener to receive SMS messages + * @exception E_SUCCESS The method was successful. + * @exception E_OUT_OF_MEMORY Insufficient memory. + * @see ISmsMessageEventListener, RemoveSmsMessageEventListener() + */ + result AddSmsMessageEventListener(const ISmsMessageEventListener& eventListener); + + /** + * Removes the event listener for receiving SMS messages. + * + * @return An error code + * @param[in] eventListener The listener to receive SMS messages + * @exception E_SUCCESS The method was successful. + * @exception E_OBJ_NOT_FOUND The listener was not found. + * @exception E_SYSTEM A system error occurred. + * @see ISmsMessageEventListener, AddSmsMessageEventListener() + */ + result RemoveSmsMessageEventListener(const ISmsMessageEventListener& eventListener); + + /** + * Sends the SMS message. + * + * @return An error code + * @param[in] message The message to be sent + * @param[in] recipientList The list of recipients + * @param[in] saveToSentBox Set to @c true to save the message in the Sentbox, @n + * else @c false + * @exception E_SUCCESS The method was successful. + * @exception E_ON_INITIALIZING The mailbox is not completely loaded yet. + * @exception E_STORAGE_FULL The storage is full. + * @exception E_DEVICE_UNAVAILABLE The device is unavailable. + * @exception E_NETWORK_UNAVAILABLE The network is unavailable. + * @exception E_INVALID_ADDRESS The address is invalid. + * @exception E_FDN_MODE The FDN mode has been activated. + * @exception E_INVALID_ARG The number of recipients is @c 0. + * @exception E_MAX_EXCEEDED The number of recipients crossed the limit (Maximum 10). + * @see ISmsListener::OnSmsMessageSent() + */ + result Send(const SmsMessage& message, const RecipientList& recipientList, bool saveToSentBox); + + /** + * Gets the total number of SMS messages in the specified message box. + * + * @return The total number of SMS messages in the specified message box + * @param[in] type The type of message box + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG The value of specified @c type is invalid. + * @exception E_SYSTEM A system error occurred. + * @remarks In case of an error, this method returns the negative value (-1). + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + int GetTotalMessageCount(SmsMessageBoxType type) const; + + /** + * Searches the SMS messages by keyword and|or sender address in the Inbox. + * + * @return The list of the SmsMessage class instances + * @param[in] pKeyword A part of the body text as a keyword (partial match) @n + * In case of @c null or an empty string, this method searches all SMS messages in the Inbox regardless of the keyword. + * @param[in] pSenderAddress A telephone number as a sender address (exact match) @n + * In case of @c null or an empty string, this method searches all SMS messages in the Inbox regardless of the sender address. + * @param[in] startIndex The start index (base 0) + * @param[in] count The count of SMS messages to search + * @param[out] totalResultCount The total count of the searched result + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG Either of the following of the conditions has occurred: @n + * -- The specified @c pKeyword string length is less than @c 2 or greater than @c 30. @n + * -- The specified @c pSenderAddress string length is less than @c 3 or greater than @c 41. @n + * -- The specified @c startIndex value is less than @c o. @n + * -- The specified @c count value is less than @c 0 or greater than @c 20. + * @exception E_SYSTEM A system error occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. @n + * @remarks The search with the specified keywords searches using only the first 50 characters of the body text. + * @remarks The SMS messages in the searched result contain only 160 bytes for the body text. @n + * To check whether there is additional text, use the SmsMessage::HasMoreText() method. @n + * To get the full body text, use GetFullText() with its message ID. + * @see SmsMessage, GetFullText() + */ + Tizen::Base::Collection::IList* SearchInboxN(const Tizen::Base::String* pKeyword, const Tizen::Base::String* pSenderAddress, int startIndex, int count, int& totalResultCount) const; + + /** + * Searches the SMS messages by keyword in the specified message box. + * + * @return The list of the SmsMessage class instances + * @param[in] type The type of message box + * @param[in] pKeyword A part of the body text as a keyword (partial match) @n + * In case of @c null or an empty string, this method searches all SMS messages in the specified message box. + * @param[in] startIndex The start index (base 0) + * @param[in] count The count of SMS messages to search + * @param[out] totalResultCount The total count of the searched result + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG Either of the following conditions has occurred: @n + * -- The value of specified @c type is invalid. @n + * -- The specified @c pKeyword string length is less than @c 2 or greater than @c 30. @n + * -- The specified @c startIndex value is less than @c 0. @n + * -- The specified @c count value is less than @c 0 or greater than @c 20. + * @exception E_SYSTEM A system error occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. @n + * @remarks The search with the specified keywords searches using only the first 50 characters of the body text. + * @remarks The SMS messages in the searched result contain only 160 bytes for the body text. @n + * To check whether there is additional text, use the SmsMessage::HasMoreText() method. @n + * To get the full body text, use the GetFullText() method with its message ID. + * @see SmsMessage, GetFullText() + */ + Tizen::Base::Collection::IList* SearchMessageBoxN(SmsMessageBoxType type, const Tizen::Base::String* pKeyword, int startIndex, int count, int& totalResultCount) const; + + /** + * Gets the full text of the SMS message in the message box using the message ID. + * + * @return The full text of the specified SMS message + * @param[in] messageId The unique ID of the message + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG The value of the specified @c messageId is invalid, or @c messageId should be greater than or equal to @c 0. + * @exception E_OBJ_NOT_FOUND The SMS message with the specified @c messageId was not found. + * @exception E_SYSTEM A system error occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @remarks In case of an error, this method returns an empty string. + * @see SmsMessage::HasMoreText() + */ + Tizen::Base::String GetFullText(int messageId) const; + + /** + * Sets the event listener for receiving CB messages. + * + * @return An error code + * @param[in] pListener The listener to receive CB messages + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + * @see ICbsMessageEventListener + */ + result SetCbsMessageEventListener(ICbsMessageEventListener* pListener); + + /** + * Sets the event listener for receiving ETWS primary notification. + * + * @return An error code + * @param[in] pListener The listener to receive ETWS primary notification + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + * @see IEtwsPrimaryNotificationEventListener + */ + result SetEtwsPrimaryNotificationEventListener(IEtwsPrimaryNotificationEventListener* pListener); + + /** + * Enables or disables the save option for CBS message to the CbsBox + * + * @return An error code + * @param[in] enable Set to @c true to save the message in the CbsBox, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + */ + result SetSavingToCbsBoxEnabled(bool enable); + + /** + * Checks whether the CB service is enabled. + * + * @return @c true if the CB service is enabled, @n + * else @c false + * @see SetCbsEnabled() + */ + bool IsCbsEnabled(void) const; + + /** + * Enables or disables the CB service. + * + * @return An error code + * @param[in] enable Set to @c true to enable the CB service, @n + * else @c false + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + * @see IsCbsEnabled() + */ + result SetCbsEnabled(bool enable); + + /** + * Adds a CBS channel with specified parameters. + * + * @return An error code + * @param[in] from The starting index of the message ID of the channel. + * @param[in] to The last index of the message ID of the channel. + * @param[in] name The name of the channel. (can be an empty string) + * @param[in] activate Set to @c true to activate the channel, @n + * else @c false. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c to parameter is smaller than @c from. @n + * The specified @c to or @c from parameter is a negative value. @n + * The specified @c to parameter exceeds the limit (0xFFFF). @n + * The range (@c to - @c from) exceeds the limit (0xFFFF). + * The specified @c name string length is greater than @c 32. @n + * @exception E_ALREADY_SET The channel range (@c from ~ @c to) is already set. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to add the CBS channel. + * @exception E_SYSTEM A system error has occurred. + * @see RemoveCbsChannel() + */ + result AddCbsChannel(int from, int to, Tizen::Base::String& name, bool activate = true); + + /** + * Removes a CBS channel. + * + * @return An error code + * @param[in] from The starting index of the message ID of the channel. + * @param[in] to The last index of the message ID of the channel. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c to parameter is smaller than @c from. @n + * The specified @c to or @c from parameter is a negative value. @n + * The specified @c to parameter exceeds the limit (0xFFFF). @n + * The range (@c to - @c from) exceeds the limit (0xFFFF). + * @exception E_OBJ_NOT_FOUND The channel range (@c from ~ @c to) is not found. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to remove the CBS channel. + * @exception E_SYSTEM A system error has occurred. + * @see AddCbsChannel() + */ + result RemoveCbsChannel(int from, int to); + + /** + * Gets a CBS channel with specified range. + * + * @return A pointer to the CBS channel with specific range. + * @param[in] from The starting index of the message ID of the channel. + * @param[in] to The last index of the message ID of the channel. + * @exception E_SUCCESS The method is successful. + * @exception E_INVALID_ARG The specified @c to parameter is smaller than @c from. @n + * The specified @c to or @c from parameter is a negative value. @n + * The specified @c to parameter exceeds the limit (0xFFFF). @n + * The range (@c to - @c from) exceeds the limit (0xFFFF). + * @exception E_SYSTEM A system error has occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see AddCbsChannel(), RemoveCbsChannel() + */ + CbsChannel* GetCbsChannelN(int from, int to) const; + + /** + * Gets the CBS channel list. + * + * @return A pointer to the list of CBS channel + * @exception E_SUCCESS The method is successful. + * @exception E_SYSTEM A system error has occurred. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @see AddCbsChannel(), RemoveCbsChannel(), CbsChannel + */ + Tizen::Base::Collection::IList* GetCbsChannelListN(void); + +public: + /** + * Gets the Impl instance. + * + * @return The pointer to _SmsManagerImpl + * @param[in] smsManager An instance of SmsManager + */ + static _SmsManagerImpl* GetInstance(SmsManager& smsManager); + + /** + * Gets the Impl instance. + * + * @return The pointer to _SmsManagerImpl + * @param[in] smsManager An instance of SmsManager + */ + static const _SmsManagerImpl* GetInstance(const SmsManager& smsManager); + + // utility +private: + result ConvertException(int err) const; + +private: + bool __isConstructed; + bool __isCbsSaveEnabled; + std::unique_ptr<_SmsEvent> __pSmsEvent; + _SmsEvent* __pSmsReceiveEvent; + _SmsEvent* __pCbsReceiveEvent; + _SmsEvent* __pEtwsReceiveEvent; + Tizen::Base::Collection::ArrayList* __pSmsTriggerEventList; + msg_handle_t __msgHandle; + ICbsMessageEventListener* __pCbsListener; + IEtwsPrimaryNotificationEventListener* __pEtwsListener; + bool __isOpenCbsHandle; + +}; // _SmsManagerImpl +} } // Tizen::Messaging + +#endif // _FMSG_INTERNAL_SMS_MANAGER_IMPL_H_ diff --git a/src/FMsg_SmsMessageImpl.cpp b/src/FMsg_SmsMessageImpl.cpp new file mode 100644 index 0000000..89e1dd9 --- /dev/null +++ b/src/FMsg_SmsMessageImpl.cpp @@ -0,0 +1,269 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_SmsMessageImpl.cpp + * @brief This is the implementation file for the %_SmsMessageImpl class. + * + * This file contains the implementation of the %_SmsMessageImpl class. + */ + +#include +#include +#include "FMsg_SmsMessageImpl.h" +#include "FMsg_Types.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; + +namespace Tizen { namespace Messaging +{ + +_SmsMessageImpl::_SmsMessageImpl(void) + : __messageId(-1) + , __messageBoxType(SMS_MESSAGE_BOX_TYPE_NONE) + , __hasMoreText(false) +{ +} + +_SmsMessageImpl::_SmsMessageImpl(const _SmsMessageImpl& value) +{ + __messageBoxType = value.__messageBoxType; + __messageId = value.__messageId; + __text = value.__text; + __hasMoreText = value.__hasMoreText; + __senderAddress = value.__senderAddress; + __recipientList = value.__recipientList; + __time = value.__time; +} + +_SmsMessageImpl::~_SmsMessageImpl(void) +{ + __messageId = -1; + __messageBoxType = SMS_MESSAGE_BOX_TYPE_NONE; + __hasMoreText = false; +} + +_SmsMessageImpl& +_SmsMessageImpl::operator =(const _SmsMessageImpl& rhs) +{ + if (this != &rhs) + { + __messageBoxType = rhs.__messageBoxType; + __messageId = rhs.__messageId; + __text = rhs.__text; + __hasMoreText = rhs.__hasMoreText; + __senderAddress = rhs.__senderAddress; + __recipientList = rhs.__recipientList; + __time = rhs.__time; + } + + return (*this); +} + +bool +_SmsMessageImpl::Equals(const Tizen::Base::Object& value) const +{ + const _SmsMessageImpl* pSmsMessageImpl = dynamic_cast(&value); + if (!pSmsMessageImpl) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + // text + if (__text != pSmsMessageImpl->__text) + { + return false; + } + + // message ID + if (__messageId != pSmsMessageImpl->__messageId) + { + return false; + } + + // messageBoxType + if (__messageBoxType != pSmsMessageImpl->__messageBoxType) + { + return false; + } + + // time + if (__time != pSmsMessageImpl->__time) + { + return false; + } + + // senderAddress + if (__senderAddress != pSmsMessageImpl->__senderAddress) + { + return false; + } + + // RecipientList + if (!(__recipientList == pSmsMessageImpl->__recipientList)) + { + return false; + } + + // __hasMoreText + if (__hasMoreText != pSmsMessageImpl->__hasMoreText) + { + return false; + } + + return true; +} + +int +_SmsMessageImpl::GetHashCode(void) const +{ + int hash = 0; + + hash = __text.GetHashCode() + __messageId + (int)__messageBoxType + __time.GetHashCode() + __senderAddress.GetHashCode() + __recipientList.GetHashCode() + (__hasMoreText ? 1 : 0); + + return hash; +} + +result +_SmsMessageImpl::SetText(const Tizen::Base::String& text) +{ + __text = text; + + return E_SUCCESS; +} + +String +_SmsMessageImpl::GetText(void) const +{ + return __text; +} + +String +_SmsMessageImpl::GetSenderAddress(void) const +{ + return __senderAddress; +} + +DateTime +_SmsMessageImpl::GetReceivedTime(void) const +{ + return __time; +} + +Tizen::Base::DateTime +_SmsMessageImpl::GetSentTime(void) const +{ + return __time; +} + +int +_SmsMessageImpl::GetId(void) const +{ + return __messageId; +} + +SmsMessageBoxType +_SmsMessageImpl::GetMessageBoxType(void) const +{ + return __messageBoxType; +} + +RecipientList +_SmsMessageImpl::GetRecipientList(void) const +{ + return __recipientList; +} + +bool +_SmsMessageImpl::HasMoreText(void) const +{ + return __hasMoreText; +} + +_SmsMessageImpl* +_SmsMessageImpl::GetInstance(SmsMessage& smsMessage) +{ + return smsMessage.__pImpl; +} + +const _SmsMessageImpl* +_SmsMessageImpl::GetInstance(const SmsMessage& smsMessage) +{ + return smsMessage.__pImpl; +} + +// private - used only for the incoming message +void +_SmsMessageImpl::SetIncomingMessage(const Tizen::Base::String& text, const Tizen::Base::String& senderAddress, + const Tizen::Base::DateTime& receivedTime) +{ + __messageBoxType = SMS_MESSAGE_BOX_TYPE_NONE; + __messageId = -1; // message ID should not be available + __text = text; + __hasMoreText = false; + __senderAddress = senderAddress; +// __recipientList.GetImpl()->ClearAllRecipients(); // recipient list should be empty + __time = receivedTime; +} + +// private - used only for the messages in the inbox +void +_SmsMessageImpl::SetInboxMessage(int messageId, const Tizen::Base::String& text, bool hasMoreText, + const Tizen::Base::String& senderAddress, + const Tizen::Base::DateTime& receivedTime) +{ + __messageBoxType = SMS_MESSAGE_BOX_TYPE_INBOX; + __messageId = messageId; + __text = text; + __hasMoreText = hasMoreText; + __senderAddress = senderAddress; +// __recipientList.GetImpl()->ClearAllRecipients(); // recipient list should be empty + __time = receivedTime; +} + +// private - used for the messages in the sentbox +void +_SmsMessageImpl::SetSentboxMessage(int messageId, const Tizen::Base::String& text, bool hasMoreText, + const Tizen::Messaging::RecipientList& recipientList, + const Tizen::Base::DateTime& sentTime) +{ + __messageBoxType = SMS_MESSAGE_BOX_TYPE_SENTBOX; + __messageId = messageId; + __text = text; + __hasMoreText = hasMoreText; + __recipientList = recipientList; + __senderAddress.Clear(); // sender address should be empty + __time = sentTime; +} + +// private - used for the messages in the outbox +void +_SmsMessageImpl::SetOutboxMessage(int messageId, const Tizen::Base::String& text, bool hasMoreText, + const Tizen::Messaging::RecipientList& recipientList, + const Tizen::Base::DateTime& sentTime) +{ + __messageBoxType = SMS_MESSAGE_BOX_TYPE_OUTBOX; + __messageId = messageId; + __text = text; + __hasMoreText = hasMoreText; + __recipientList = recipientList; + __senderAddress.Clear(); // sender address should be empty + __time = sentTime; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_SmsMessageImpl.h b/src/FMsg_SmsMessageImpl.h new file mode 100644 index 0000000..6d004bd --- /dev/null +++ b/src/FMsg_SmsMessageImpl.h @@ -0,0 +1,293 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_SmsMessageImpl.h + * @brief This is the header file for _SmsMessageImpl class. + * + * This header file contains the declarations of _SmsMessageImpl class. + */ + + +#ifndef _FMSG_INTERNAL_SMS_MESSAGE_IMPL_H_ +#define _FMSG_INTERNAL_SMS_MESSAGE_IMPL_H_ + +// Includes +#include +#include +#include +#include +#include +#include "FMsg_Types.h" + +namespace Tizen { namespace Messaging +{ + +// forward declaration +class RecipientList; +class SmsMessage; + +/** +* @class _SmsMessageImpl +* @brief This class provides methods for handling an SMS message. +* @since 1.0 +* +* This class provides methods for handling SMS messages. @n +* A user can set and get an SMS body text. +*/ +class _SmsMessageImpl + : public Tizen::Base::Object +{ + // Life cycle +public: + /** + * This is the default constructor for this class. + * + * @since 1.0 + */ + _SmsMessageImpl(void); + + /** + * This is the destructor for this class. + * + * @since 1.0 + */ + virtual ~_SmsMessageImpl(void); + + /** + * This is the copy constructor for this class. + * + * @since 1.0 + * @param[in] value An instance of _SmsMessageImpl + */ + _SmsMessageImpl(const _SmsMessageImpl& value); + +public: + /** + * This assignment operator copies SMS message from the specified instance of _SmsMessageImpl to the calling instance of SmsMessage. + * + * @since 1.0 + * @return A reference to this instance + * @param[in] rhs A reference to the SmsMessage instance to be copied + */ + _SmsMessageImpl& operator =(const _SmsMessageImpl& rhs); + +public: + /** + * Gets the hash value of the current instance. + * + * @since 1.0 + * @return The hash value of the current instance + * @remarks Two equal instances should return the same hash value. For better performance, + * the used hash function must generate a random distribution for all inputs. + */ + virtual int GetHashCode(void) const; + + /** + * Compares the specified instance with the calling instance. + * + * @since 1.0 + * @return @c true if both instances are equal @n + * @c false, otherwise + * @param[in] value An instance of _SmsMessageImpl + */ + virtual bool Equals(const Tizen::Base::Object& value) const; + + // Operation +public: + /** + * Sets the body of the message. + * + * @since 1.0 + * @return An error code + * @param[in] text The body text of the message + * @exception E_SUCCESS The method was successful. + * @exception E_MAX_EXCEEDED The body length of the message is exceeding the maximum limit (Maximum 80 characters). + * @see GetText() + */ + result SetText(const Tizen::Base::String& text); + + /** + * Gets the body text of the message. + * + * @since 1.0 + * @return The body text of the message + * @remarks If the message is from the Inbox, Sentbox, or Outbox, it may contain only 160 bytes for the body text. @n + * To check whether the message contains more than 160 bytes for the body text, use the HasMoreText() method. + * To get the full body text, use the SmsManager::GetFullText() method with its message ID. + * @see SetText(), HasMoreText(), GetId(), SmsManager::GetFullText() + */ + Tizen::Base::String GetText(void) const; + + /** + * Gets the sender address of the message. + * + * @since 2.0 + * @privlevel SYSTEM + * @privgroup http://tizen.org/privilege/messaging.sms + * + * @return The sender address of the message + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_OPERATION This operation is only allowed to the incoming message or the message from the Inbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + Tizen::Base::String GetSenderAddress(void) const; + + /** + * Gets the received time of the message. + * + * @since 2.0 + * @privlevel SYSTEM + * @privgroup http://tizen.org/privilege/messaging.sms + * + * @return The received time of the message + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_OPERATION This operation is only allowed to the incoming message or the message from the Inbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @remarks In case of an error, this method returns the instance denoting 00:00:00, January 1, 1. + */ + Tizen::Base::DateTime GetReceivedTime(void) const; + + /** + * Gets the unique ID of the message. + * + * @since 2.0 + * @privlevel SYSTEM + * @privgroup http://tizen.org/privilege/messaging.sms + * + * @return The unique ID of the message + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_OPERATION This operation is allowed only when the message is from the Inbox, Sentbox, or Outbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @remarks In case of an error, this method returns the negative value (-1). + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + int GetId(void) const; + + /** + * Gets the sent time of the message. + * + * @since 2.0 + * @privlevel SYSTEM + * @privgroup http://tizen.org/privilege/messaging.sms + * + * @return The sent time of the message + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_OPERATION This operation is allowed only when the message is from the Sentbox or Outbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @remarks The specific error code can be accessed using the GetLastResult() method. + * @remarks In case of an error, this method returns the instance denoting 00:00:00, January 1, 1. + */ + Tizen::Base::DateTime GetSentTime(void) const; + + /** + * Gets the type of the message box. + * + * @since 2.0 + * @privlevel SYSTEM + * @privgroup http://tizen.org/privilege/messaging.sms + * + * @return The type of the message box + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_OPERATION This operation is allowed only when the message is from the Inbox, Sentbox, or Outbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @remarks In case of an error, this method returns the SMS_MESSAGE_BOX_TYPE_NONE value. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + SmsMessageBoxType GetMessageBoxType(void) const; + + /** + * Gets the list of the recipients. + * + * @since 2.0 + * @privlevel SYSTEM + * @privgroup http://tizen.org/privilege/messaging.sms + * + * @return The list of the recipient + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_OPERATION This operation is allowed only when the message is from the Sentbox or Outbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + RecipientList GetRecipientList(void) const; + + /** + * Checks whether the message contains more than 160 bytes for the body text. + * + * @since 2.0 + * + * @privlevel SYSTEM + * @privgroup http://tizen.org/privilege/messaging.sms + * + * @return @c true if this message contains more than 160 bytes for the body text, @n + * else @c false + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_OPERATION This operation is allowed only when the message is from the Inbox, Sentbox, or Outbox. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @remarks If the return value is @c true, the SMS message contains more than 160 bytes for the body text. To get the full body text, use SmsManager::GetFullText(). + * @remarks The specific error code can be accessed using the GetLastResult() method. + */ + bool HasMoreText(void) const; + +// private: + // private - used only for the incoming message + void SetIncomingMessage(const Tizen::Base::String& text, const Tizen::Base::String& senderAddress, const Tizen::Base::DateTime& receivedTime); + + // private - used only for the messages in the inbox + void SetInboxMessage(int messageId, const Tizen::Base::String& text, bool hasMoreText, const Tizen::Base::String& senderAddress, const Tizen::Base::DateTime& receivedTime); + + // private - used for the messages in the sentbox or outbox + void SetSentboxMessage(int messageId, const Tizen::Base::String& text, bool hasMoreText, const Tizen::Messaging::RecipientList& recipientList, const Tizen::Base::DateTime& sentTime); + + // private - used for the messages in the sentbox or outbox + void SetOutboxMessage(int messageId, const Tizen::Base::String& text, bool hasMoreText, const Tizen::Messaging::RecipientList& recipientList, const Tizen::Base::DateTime& sentTime); + +public: + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _SmsMessageImpl + * @param[in] smsMessage An instance of SmsMessage + */ + static _SmsMessageImpl* GetInstance(SmsMessage& smsMessage); + + /** + * Gets the Impl instance. + * + * @since 2.1 + * @return The pointer to _SmsMessageImpl + * @param[in] smsMessage An instance of SmsMessage + */ + static const _SmsMessageImpl* GetInstance(const SmsMessage& smsMessage); + + +private: + Tizen::Base::String __text; + int __messageId; + SmsMessageBoxType __messageBoxType; + Tizen::Base::DateTime __time; // received or sent time + Tizen::Base::String __senderAddress; // for receiving a message and retrieving an inbox + RecipientList __recipientList; // for retrieving sentbox and outbox + bool __hasMoreText; // for checking the SMS message has more text or not. (currently the size retrieved SMS message limited to 160 bytes) + + friend class SmsMessage; +}; // _SmsMessageImpl +} } + +#endif // _FMSG_INTERNAL_SMS_MESSAGE_IMPL_H_ diff --git a/src/FMsg_SmsMmsCallbackHandler.cpp b/src/FMsg_SmsMmsCallbackHandler.cpp new file mode 100644 index 0000000..00050c5 --- /dev/null +++ b/src/FMsg_SmsMmsCallbackHandler.cpp @@ -0,0 +1,573 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_SmsMmsCallbackHandler.cpp + * @brief This is the implementation file for the %_SmsMmsCallbackHandler class. + * + * This file contains the implementation of the %_SmsMmsCallbackHandler class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_SmsEvent.h" +#include "FMsg_SmsEventArg.h" +#include "FMsg_MmsEvent.h" +#include "FMsg_MmsEventArg.h" +#include "FMsg_MsgUtil.h" +#include "FMsg_SmsMmsCallbackHandler.h" +#include "FMsg_CbsChannelImpl.h" + +using namespace Tizen::Base; +using namespace Tizen::Base::Collection; +using namespace Tizen::Base::Runtime; + +namespace Tizen { namespace Messaging +{ + +_SmsMmsCallbackHandler* _SmsMmsCallbackHandler::__pMessageCallbackHandler = 0; +bool _SmsMmsCallbackHandler::__destroyed = false; + +_SmsMmsCallbackHandler::_SmsMmsCallbackHandler(void) + : __msgHandle(0) + , __callbackRegistered(false) + , __incomingSmsCallbackRegistered(true) + , __incomingCallbackRegistered(false) + , __pSmsIncomingEvent(null) +{ +} + +result +_SmsMmsCallbackHandler::Construct() +{ + result r = E_SUCCESS; + + r = __messageMap.Construct(); + + if (r == E_SUCCESS) + { + r = __msgMutex.Create(); + } + + std::atexit(CloseCbsSettingsHandle); + + return r; +} + +_SmsMmsCallbackHandler::~_SmsMmsCallbackHandler(void) +{ + + if (__msgHandle) + { + msg_close_msg_handle(&__msgHandle); + __msgHandle = 0; + } + + Tizen::Base::Collection::IList* pKeyList = null; + Integer* pKey = null; + Integer* pMsgType = null; + IEnumerator* pValueEnum = null; + int count = 0; + + __msgMutex.Acquire(); + + if (__messageMap.GetCount()) + { + pKeyList = __messageMap.GetKeysN(); + count = pKeyList->GetCount(); + } + + // Manually deleting key and value pairs + for (int index = 0; index < count; index++) + { + pKey = static_cast (pKeyList->GetAt(index)); + pValueEnum = __messageMap.GetValuesN(*pKey); + + if (pValueEnum) + { + if (pValueEnum->MoveNext() == E_SUCCESS) + { + pMsgType = static_cast (pValueEnum->GetCurrent()); + + if (pMsgType) + { + delete pMsgType; + pMsgType = null; + } + } + } + + if (pKey) + { + delete pKey; + pKey = null; + } + + if (pValueEnum) + { + delete pValueEnum; + pValueEnum = null; + } + } + + if (pKeyList) + { + delete pKeyList; + pKeyList = null; + } + + if (__messageMap.GetCount()) + { + __messageMap.RemoveAll(false); + } + + __msgMutex.Release(); + +} + +_SmsMmsCallbackHandler* +_SmsMmsCallbackHandler::GetInstance(void) +{ + SysTryReturn(NID_MSG, __destroyed == false, null, E_SYSTEM, "Instance Dead"); + + result r = E_SUCCESS; + + if (!__pMessageCallbackHandler) + { + __pMessageCallbackHandler = new (std::nothrow) _SmsMmsCallbackHandler(); + SysTryReturn(NID_MSG, __pMessageCallbackHandler != NULL, null, E_SYSTEM, "failed to create instance"); + + if (__pMessageCallbackHandler) + { + r = __pMessageCallbackHandler->Construct(); + + if (r != E_SUCCESS) + { + delete __pMessageCallbackHandler; + __pMessageCallbackHandler = 0; + } + } + } + + return __pMessageCallbackHandler; +} + +int +_SmsMmsCallbackHandler::OpenMessageHandle(msg_handle_t& messageHandle) +{ + int err = MSG_SUCCESS; + + if (!__msgHandle) + { + err = msg_open_msg_handle(&__msgHandle); + if ( err != MSG_SUCCESS ) + { + __msgHandle = null; + } + } + + messageHandle = __msgHandle; + return err; +} + +int +_SmsMmsCallbackHandler::RegisterMessageCallback() +{ + int err = MSG_SUCCESS; + + if (__msgHandle && !__callbackRegistered) + { + err = msg_reg_sent_status_callback(__msgHandle, &_SmsMmsCallbackHandler::SentMessageStatusCallback, null); + __callbackRegistered = true; + } + + return err; +} + +int +_SmsMmsCallbackHandler::RegisterIncomingMessageCallback(Tizen::Base::Object* pSmsIncomingEvent) +{ + int err = MSG_SUCCESS; + + __pSmsIncomingEvent = pSmsIncomingEvent; + + if (__msgHandle && !__incomingCallbackRegistered) + { + err = msg_reg_sms_message_callback(__msgHandle, &_SmsMmsCallbackHandler::IncomingSmsMessageCallback, 0, null); + __incomingCallbackRegistered = true; + } + + return err; +} + +int +_SmsMmsCallbackHandler::CloseMessageHandle() +{ + int err = MSG_SUCCESS; + + if (__msgHandle) + { + err = msg_close_msg_handle(&__msgHandle); + __msgHandle = 0; + __callbackRegistered = false; + } + + return err; +} + +void +_SmsMmsCallbackHandler::CloseCbsSettingsHandle() +{ + + if (__pMessageCallbackHandler) + { + delete __pMessageCallbackHandler; + __pMessageCallbackHandler = null; + } + __destroyed = true; + +} + +void +_SmsMmsCallbackHandler::SetInComingSmsCallback(bool incomingSmsCallbackRegistered) +{ + __incomingSmsCallbackRegistered = incomingSmsCallbackRegistered; +} +bool +_SmsMmsCallbackHandler::GetInComingSmsCallback() +{ + return __incomingSmsCallbackRegistered; +} + +result +_SmsMmsCallbackHandler::AddToMessageMap(int reqId, _MessageType msgType, Tizen::Base::Object* pEvent) +{ + result r = E_SUCCESS; + + Integer* pReqId = new (std::nothrow) Integer(reqId); + SysTryReturn(NID_MSG, pReqId != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed."); + Integer* pMsgType = new (std::nothrow) Integer(msgType); + SysTryReturn(NID_MSG, pMsgType != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed."); + + __msgMutex.Acquire(); + + r = __messageMap.Add(*pReqId, *pMsgType); + r = __messageMap.Add(*pReqId, *pEvent); + + __msgMutex.Release(); + + return r; +} + +result +_SmsMmsCallbackHandler::GetAndRemoveFromMessageMap(int reqId, _MessageType& msgType, Tizen::Base::Object** pUserEvent) +{ + result r = E_SUCCESS; + + Integer* pReqId = new (std::nothrow) Integer(reqId); + SysTryReturn(NID_MSG, pReqId != null, E_OUT_OF_MEMORY, r = E_OUT_OF_MEMORY, "memory allocation failed."); + Integer* pKey = null; + Integer* pMsgType = null; + Tizen::Base::Object* pEvent = null; + IEnumerator* pValueEnum = null; + IMapEnumerator* pMapEnum = null; + + __msgMutex.Acquire(); + + pValueEnum = __messageMap.GetValuesN(*pReqId); + + if (pValueEnum) + { + if (pValueEnum->MoveNext() == E_SUCCESS) + { + pMsgType = static_cast (pValueEnum->GetCurrent()); + + if (pValueEnum->MoveNext() == E_SUCCESS) + { + pEvent = static_cast (pValueEnum->GetCurrent()); + } + } + } + + *pUserEvent = pEvent; + + if (pMsgType) + { + if (pMsgType->ToInt() == _MSG_SMS) + { + msgType = _MSG_SMS; + } + else + { + msgType = _MSG_MMS; + } + } + + //Manually getting and deleting the key value + pMapEnum = __messageMap.GetMapEnumeratorN(); + + if (pMapEnum) + { + while (pMapEnum->MoveNext() == E_SUCCESS) + { + pKey = static_cast (pMapEnum->GetKey()); + if (pKey) + { + if (!(pKey->CompareTo(*pReqId))) + { + break; + } + } + } + } + + r = __messageMap.Remove(*pReqId, false); + + delete pMapEnum; + delete pValueEnum; + delete pMsgType; + delete pReqId; + delete pKey; + + __msgMutex.Release(); + + return r; +} + +void +_SmsMmsCallbackHandler::SentMessageStatusCallback(msg_handle_t hMsgHandle, msg_struct_t msgStatus, void* pUserParam) +{ + result r = E_SUCCESS; + _MessageType msgType = (_MessageType) -1; + Tizen::Base::Object* pUserEvent = null; + int status = MSG_NETWORK_SEND_FAIL; + int reqId = 0; + + msg_get_int_value(msgStatus, MSG_SENT_STATUS_REQUESTID_INT, &reqId); + msg_get_int_value(msgStatus, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status); + + _SmsMmsCallbackHandler::GetInstance()->GetAndRemoveFromMessageMap(reqId, msgType, &pUserEvent); + + SysLog(NID_MSG, "hMsgHandle[%d]", hMsgHandle); + SysLog(NID_MSG, "req[%d]", reqId); + SysLog(NID_MSG, "msgType[%d]", msgType); + SysLog(NID_MSG, "pUserEvent[%d]", pUserEvent); + + if (status == MSG_NETWORK_SEND_SUCCESS) + { + r = E_SUCCESS; + SysLog(NID_MSG, "Message is sent successfully"); + } + else + { + r = E_FAILURE; + SysLog(NID_MSG, "Failed to send the message. error cause: Message is not sending"); + } + + if (msgType == _MSG_SMS) + { + _SmsEvent* pSmsEvent = dynamic_cast <_SmsEvent*>(pUserEvent); + _SmsEventArg* pSmsEventArg = null; + + if (pSmsEvent) + { + pSmsEventArg = new (std::nothrow) _SmsEventArg(r); + if (pSmsEventArg) + { + pSmsEvent->Fire(*pSmsEventArg); + } + } + } + else + { + if (msgType == _MSG_MMS) + { + _MmsEvent* pMmsEvent = dynamic_cast <_MmsEvent*>(pUserEvent); + _MmsEventArg* pMmsEventArg = null; + + if (pMmsEvent) + { + pMmsEventArg = new (std::nothrow) _MmsEventArg(r); + if (pMmsEventArg) + { + pMmsEvent->Fire(*pMmsEventArg); + } + } + } + } + +} + +void +_SmsMmsCallbackHandler::IncomingSmsMessageCallback(msg_handle_t hMsgHandle, msg_struct_t newMsg, void* pUserParam) +{ + _SmsEvent* pSmsEvent = static_cast <_SmsEvent*>(_SmsMmsCallbackHandler::GetInstance()->__pSmsIncomingEvent); + _SmsEventArg* pSmsEventArg = null; + + int msgSize = 0; + msg_get_int_value(newMsg, MSG_MESSAGE_DATA_SIZE_INT, &msgSize); + char msgText[msgSize + 1]; + memset(msgText, 0, msgSize + 1); + msg_get_str_value(newMsg, MSG_MESSAGE_SMS_DATA_STR, msgText, msgSize); + String message(msgText); + + int port = -1; + msg_get_int_value(newMsg, MSG_MESSAGE_DEST_PORT_INT, &port); + + int displayTime = -1; + msg_get_int_value(newMsg, MSG_MESSAGE_DISPLAY_TIME_INT, &displayTime); + DateTime receivedTime = _MsgUtil::ConvertTime((time_t *) &displayTime); + + char address[MAX_ADDRESS_VAL_LEN] = {0, }; + msg_struct_list_s* pAddrList = NULL; + msg_struct_t addrInfo = NULL; + msg_get_list_handle(newMsg, MSG_MESSAGE_ADDR_LIST_STRUCT, (void **)&pAddrList); + addrInfo = pAddrList->msg_struct_info[0]; + msg_get_str_value(addrInfo, MSG_ADDRESS_INFO_ADDRESS_VALUE_STR, address, MAX_ADDRESS_VAL_LEN); + String senderAddress(address); + + SysLog(NID_MSG, "hMsgHandle: [%d]", hMsgHandle); + SysLog(NID_MSG, "msg_body: [%s]", msgText); + SysLog(NID_MSG, "port: [%d]", port); + //SysLog(NID_MSG, "received time: [%s]", ctime(pReceivedTime)); + + if (_SmsMmsCallbackHandler::GetInstance()->__incomingSmsCallbackRegistered) + { + if (pSmsEvent) + { + pSmsEventArg = new (std::nothrow) _SmsEventArg(message, senderAddress, receivedTime); + SysTryReturnVoidResult(NID_MSG, pSmsEventArg != null, E_OUT_OF_MEMORY, "memory allocation failed."); + pSmsEvent->Fire(*pSmsEventArg); + } + } +} + +Tizen::Base::String +_SmsMmsCallbackHandler::GetCbsLanguageType(byte codingScheme) +{ + String languageType(L""); + + switch(codingScheme) + { + case 0x00: + languageType = String(L"DE"); + break; + case 0x01: + languageType = String(L"EN"); + break; + case 0x02: + languageType = String(L"IT"); + break; + case 0x03: + languageType = String(L"FR"); + break; + case 0x04: + languageType = String(L"ES"); + break; + case 0x05: + languageType = String(L"NL"); + break; + case 0x06: + languageType = String(L"SV"); + break; + case 0x07: + languageType = String(L"DA"); + break; + case 0x08: + languageType = String(L"PT"); + break; + case 0x09: + languageType = String(L"FI"); + break; + case 0x0a: + languageType = String(L"NO"); + break; + case 0x0b: + languageType = String(L"EL"); + break; + case 0x0c: + languageType = String(L"TR"); + break; + case 0x0d: + languageType = String(L"HU"); + break; + case 0x0e: + languageType = String(L"PL"); + break; + case 0x0f: + languageType = String(L""); + SysLog(NID_MSG, "Language unspecified."); + break; + default: + break; + }; + + return languageType; +} + +result +_SmsMmsCallbackHandler::ConvertException(int err) const +{ + result r = E_SUCCESS; + + switch (err) + { + case MSG_SUCCESS: + r = E_SUCCESS; + break; + + case MSG_ERR_INVALID_PARAMETER: + case MSG_ERR_INVALID_MESSAGE: + case MSG_ERR_NULL_POINTER: + case MSG_ERR_NULL_MESSAGE: + r = E_INVALID_ARG; + break; + + case MSG_ERR_MEMORY_ERROR: + r = E_OUT_OF_MEMORY; + break; + + case MSG_ERR_SERVER_NOT_READY: + case MSG_ERR_TRANSPORT_ERROR: + case MSG_ERR_COMMUNICATION_ERROR: + r = E_NETWORK_UNAVAILABLE; + break; + + case MSG_ERR_NO_SIM: + r = E_DEVICE_UNAVAILABLE; + break; + + case MSG_ERR_PLUGIN_TAPI_FAILED: + r = E_FAILURE; + break; + + default: + r = E_SYSTEM; + break; + } + + return r; +} + +} } // Tizen::Messaging diff --git a/src/FMsg_SmsMmsCallbackHandler.h b/src/FMsg_SmsMmsCallbackHandler.h new file mode 100644 index 0000000..8eb687a --- /dev/null +++ b/src/FMsg_SmsMmsCallbackHandler.h @@ -0,0 +1,196 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_SmsMmsCallbackHandler.h + * @brief This is the header file for _SmsMmsCallbackHandler class. + * + * This header file contains declaration of _SmsMmsCallbackHandler class + */ + +#ifndef _FMSG_INTERNAL_SMS_MMS_CALLBACK_HANDLER_H_ +#define _FMSG_INTERNAL_SMS_MMS_CALLBACK_HANDLER_H_ + +// includes +#include +#include +#include "FMsg_Types.h" + +namespace Tizen { namespace Messaging +{ + +/** +* @class _SmsMmsCallbackHandler +* @brief This class provides methods to use the SMS/MMS call back Handler service +* @since 2.1 +* +* This class provides methods to use the SMS/MMS call back Handler service . @n +*/ + +// forward declaration + +class _SmsMmsCallbackHandler + : public Tizen::Base::Object +{ +public: + /** + * This is the destructor for this class. + * + * @since 2.1 + */ + virtual ~_SmsMmsCallbackHandler(void); + + /** + * Initializes the Messaging Hash Map table + * + * @since 3.0 + * @return An error code + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG Input parameter is NULL. + * @exception E_OUT_OF_MEMORY Memory error. + */ + result Construct(void); + + // Operation +public: + /** + * Gets the instance of SmsMmsCallbackHandler class. + * + * @since 2.1 + * @return instance of SmsMmsCallbackHandler class + */ + static _SmsMmsCallbackHandler* GetInstance(void); + + /** + * gets the Message Handle for SMS/MMS operation. + * + * @since 3.0 + * @return An error code + * @param[in] messageHandle message Handle + * @exception MSG_SUCCESS The method was successful. + * @exception MSG_ERR_NULL_POINTER Input parameter is NULL. + * @exception MSG_ERR_MEMORY_ERROR Memory error. + */ + int OpenMessageHandle(msg_handle_t& messageHandle); + + static void CloseCbsSettingsHandle(void); + + /** + * closes the Message Handle for SMS/MMS operation. + * + * @since 3.0 + * @return An error code + * @exception MSG_SUCCESS The method was successful. + * @exception MSG_ERR_NULL_POINTER Input parameter is NULL. + * @exception MSG_ERR_MEMORY_ERROR Memory error. + */ + int CloseMessageHandle(void); + + /** + * Registers the Message call back for SMS/MMS operation. + * + * @since 3.0 + * @return An error code + * @exception MSG_SUCCESS The method was successful. + * @exception MSG_ERR_NULL_POINTER Input parameter is NULL. + * @exception MSG_ERR_MEMORY_ERROR Memory error. + */ + int RegisterMessageCallback(void); + + /** + * Adds the message requestId/Message Type/Message Event to Message Hash Map table + * + * @since 3.0 + * @return An error code + * @param[in] reqId SMS/MMS message requestId + * @param[in] msgType message type + * @param[in] pEvent message Event + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG Input parameter is NULL. + * @exception E_OUT_OF_MEMORY Memory error. + */ + result AddToMessageMap(int reqId, _MessageType msgType, Tizen::Base::Object* pEvent); + + /** + * Gets the Message Type and Message Event based on the message requestId. Also removes the Hashmap elements for the requestId + * + * @since 3.0 + * @return An error code + * @param[in] reqId SMS/MMS message requestId + * @param[in] msgType message type + * @param[in] pEvent message Event + * @exception E_SUCCESS The method was successful. + * @exception E_INVALID_ARG Input parameter is NULL. + * @exception E_OUT_OF_MEMORY Memory error. + */ + result GetAndRemoveFromMessageMap(int reqId, _MessageType& msgType, Tizen::Base::Object** pEvent); + + /** + * Registers the Message call back for incoming SMS operation. + * + * @since 3.0 + * @return An error codea + * @param[in] pSmsIncomingEvent message Event + * @exception MSG_SUCCESS The method was successful. + * @exception MSG_ERR_NULL_POINTER Input parameter is NULL. + * @exception MSG_ERR_MEMORY_ERROR Memory error. + */ + int RegisterIncomingMessageCallback(Tizen::Base::Object* pSmsIncomingEvent); + + // for SMS and MMS sent status + static void SentMessageStatusCallback(msg_handle_t hMsgHandle, msg_struct_t msgStatus, void* pUserParam); + + // for incoming SMS + static void IncomingSmsMessageCallback(msg_handle_t hMsgHandle, msg_struct_t newMsg, void* pUserParam); + + /** + * Sets the __incomingSmsCallbackRegistered flag. + * + * @since 3.0 + * @param[in] incomingSmsCallbackRegistered SMS registered flag + */ + void SetInComingSmsCallback(bool incomingSmsCallbackRegistered); + bool GetInComingSmsCallback(); + + //get cb message language type + static Tizen::Base::String GetCbsLanguageType(byte codingScheme); + + // Life cycle +private: + /** + * This is the default constructor for this class. + * + * @since 2.1 + */ + _SmsMmsCallbackHandler(void); + + result ConvertException(int err) const; + +private: + static _SmsMmsCallbackHandler* __pMessageCallbackHandler; + msg_handle_t __msgHandle; + bool __callbackRegistered; + bool __incomingSmsCallbackRegistered; + bool __incomingCallbackRegistered; + Tizen::Base::Object* __pSmsIncomingEvent; + Tizen::Base::Collection::MultiHashMap __messageMap; + Tizen::Base::Runtime::Mutex __msgMutex; + static bool __destroyed; +}; // _SmsMmsCallbackHandler + +} } // Tizen::Messaging + +#endif // _FMSG_INTERNAL_SMS_MMS_CALLBACK_HANDLER_H_ diff --git a/src/FMsg_WapPushManagerImpl.cpp b/src/FMsg_WapPushManagerImpl.cpp new file mode 100644 index 0000000..1d68894 --- /dev/null +++ b/src/FMsg_WapPushManagerImpl.cpp @@ -0,0 +1,215 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_WapPushManagerImpl.cpp + * @brief This is the implementation file for the %_WapPushManagerImpl class. + * + * This file contains the implementation of the %_WapPushManagerImpl class. + */ + +// OAF headers +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_SmsEvent.h" +#include "FMsg_Types.h" +#include "FMsg_WapPushManagerImpl.h" +#include "FMsg_SmsMmsCallbackHandler.h" +#include "FMsg_MessagingIpcProxy.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Base::Collection; + +namespace Tizen { namespace Messaging +{ + +_WapPushManagerImpl::_WapPushManagerImpl(void) + : __msgHandle(0) + , __pWapPushReceiveEvent(null) +{ +} + +_WapPushManagerImpl::_WapPushManagerImpl(const _WapPushManagerImpl& value) +{ + __msgHandle = value.__msgHandle; + __pWapPushReceiveEvent = value.__pWapPushReceiveEvent; +} + +_WapPushManagerImpl::~_WapPushManagerImpl(void) +{ + if (__pWapPushReceiveEvent) + { + delete __pWapPushReceiveEvent; + __pWapPushReceiveEvent = null; + } +} + +_WapPushManagerImpl& +_WapPushManagerImpl::operator =(const _WapPushManagerImpl& rhs) +{ + if (this != &rhs) + { + __msgHandle = rhs.__msgHandle; + __pWapPushReceiveEvent = rhs.__pWapPushReceiveEvent; + } + + return (*this); +} + +result +_WapPushManagerImpl::AddWapPushEventListener(const Tizen::Base::String& wapApplicationId, const IWapPushEventListener& listener) +{ + result r = E_SUCCESS; + + ClearLastResult(); + // set event + if (!__pWapPushReceiveEvent) + { + __pWapPushReceiveEvent = new (std::nothrow) _SmsEvent(); + SysTryCatch(NID_MSG, __pWapPushReceiveEvent != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] memory allocation failed."); + + // event construction + r = __pWapPushReceiveEvent->Construct(_SMS_EVENT_TYPE_WAP_PUSH_RECEIVE_RESULT); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] failed to construct push event", GetErrorMessage(r)); + } + + // add listener + r = __pWapPushReceiveEvent->AddListener(listener, true); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] failed to add push listner.", GetErrorMessage(r)); + + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->AddWapPushEventListener(wapApplicationId, __pWapPushReceiveEvent); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); + + return r; + +CATCH: + + + if (__pWapPushReceiveEvent) + { + delete __pWapPushReceiveEvent; + __pWapPushReceiveEvent = null; + } + + return r; +} + +result +_WapPushManagerImpl::RemoveWapPushEventListener(const Tizen::Base::String& wapApplicationId, const IWapPushEventListener& listener) +{ + result r = E_SUCCESS; + ClearLastResult(); + + SysTryCatch(NID_MSG, __pWapPushReceiveEvent != null, r = E_OBJ_NOT_FOUND, r, "[E_OBJ_NOT_FOUND] listner not found"); + + r = __pWapPushReceiveEvent->RemoveListener(listener); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] listner remove failed", GetErrorMessage(r)); + + delete __pWapPushReceiveEvent; + __pWapPushReceiveEvent = null; + + return r; + +CATCH: + return r; +} + +result +_WapPushManagerImpl::RegisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType) +{ + result r = E_SUCCESS; + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->RegisterCondition(wapApplicationId,contentType); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); + + return r; + +CATCH: + return r; + +} + +result +_WapPushManagerImpl::UnregisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType) +{ + result r = E_SUCCESS; + SysTryReturnResult(NID_MSG, _MessagingProxy::GetInstance()!= null, E_OUT_OF_MEMORY, "Failed to get msg proxy instance"); + r = _MessagingProxy::GetInstance()->UnregisterCondition(wapApplicationId,contentType); + SysTryCatch(NID_MSG, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); + + return r; + +CATCH: + return r; + +} + +result +_WapPushManagerImpl::ConvertException(int err) const +{ + result r = E_SUCCESS; + + switch (err) + { + case MSG_SUCCESS: + r = E_SUCCESS; + break; + + case MSG_ERR_DB_ROW: + r = E_ALREADY_SET; + break; + + case MSG_ERR_INVALID_PARAMETER: + case MSG_ERR_INVALID_MESSAGE: + case MSG_ERR_NULL_POINTER: + case MSG_ERR_NULL_MESSAGE: + r = E_INVALID_ARG; + break; + + case MSG_ERR_MEMORY_ERROR: + r = E_OUT_OF_MEMORY; + break; + + case MSG_ERR_SERVER_NOT_READY: + case MSG_ERR_TRANSPORT_ERROR: + case MSG_ERR_COMMUNICATION_ERROR: + r = E_NETWORK_UNAVAILABLE; + break; + + case MSG_ERR_NO_SIM: + r = E_DEVICE_UNAVAILABLE; + break; + + case MSG_ERR_PLUGIN_TAPI_FAILED: + r = E_FAILURE; + break; + + default: + r = E_SYSTEM; + break; + } + + return r; +} + +} } diff --git a/src/FMsg_WapPushManagerImpl.h b/src/FMsg_WapPushManagerImpl.h new file mode 100644 index 0000000..afbc941 --- /dev/null +++ b/src/FMsg_WapPushManagerImpl.h @@ -0,0 +1,214 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** +* @if VISPARTNER-OPERATOR +* +* @file FMsg_WapPushManagerImpl.h +* @brief This is the header file for the _WapPushManagerImpl class. +* +* @visibility partner-operator +* +* This header file contains the declarations of the _WapPushManagerImpl class. +* +* @endif +*/ + +#ifndef _FMSG_INTERNAL_WAP_PUSH_MANAGER_IMPL_H_ +#define _FMSG_INTERNAL_WAP_PUSH_MANAGER_IMPL_H_ + +namespace Tizen { namespace Messaging +{ + +/** +* @if VISPARTNER-OPERATOR +* +* @class _WapPushManagerImpl +* @brief This class provides methods to use the WAP push messaging service. +* +* @since 2.1 +* +* @final This class is not intended for extension. +* +* @visibility partner-operator +* +* @endif +*/ + +// forward declaration +class _SmsEvent; + +class _WapPushManagerImpl + : public Tizen::Base::Object +{ +public: + /** + * @if VISPARTNER-OPERATOR + * + * This is the default constructor for this class. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @endif + */ + _WapPushManagerImpl(void); + + /** + * @if VISPARTNER-OPERATOR + * + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.1 + * + * @visibility partner-operator + * + * @endif + */ + virtual ~_WapPushManagerImpl(void); + +public: + /** + * @if VISPARTNER-OPERATOR + * + * Adds the event listener for receiving WAP push messages regarding specific WAP push application ID. + * + * @since 2.1 + * + * @visibility partner-operator + * @privlevel user + * @privilege http://tizen.org/privilege/wappush + * + * @return An error code + * @param[in] wapApplicationId The X-Wap-Application-Id indicating a WAP push application ID. + * @param[in] listener A listener that receives the incoming push messages + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_ALREADY_EXIST The specified @c wapApplicationId is already registered @n + * or the listener already exists. + * @exception E_INVALID_ARG The specified @c wapApplicationId is invalid. @n + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @see IWapPushEventListener, RemoveWapPushEventListener() + * + * @endif + */ + result AddWapPushEventListener(const Tizen::Base::String& wapApplicationId, const IWapPushEventListener& listener); + + /** + * @if VISPARTNER-OPERATOR + * + * Removes the event listener for receiving WAP push messages regarding specific WAP push application ID. + * + * @since 2.1 + * + * @visibility partner-operator + * @privlevel user + * @privilege http://tizen.org/privilege/wappush + * + * @return An error code + * @param[in] wapApplicationId The X-Wap-Application-Id indicating a WAP push application ID. + * @param[in] listener A listener that receives the incoming push messages + * @exception E_SUCCESS The method is successful. + * @exception E_OBJ_NOT_FOUND The specified @c wapApplicationId is not registered. @n + * The specified @c listener is not found. + * @exception E_INVALID_ARG The specified @c wapApplicationId is invalid. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @see IWapPushEventListener, AddWapPushEventListener() + * + * @endif + */ + result RemoveWapPushEventListener(const Tizen::Base::String& wapApplicationId, const IWapPushEventListener& listener); + + /** + * @if VISPARTNER-OPERATOR + * + * Registers a condition to receive WAP push message. + * + * @since 2.1 + * + * @visibility partner-operator + * @privlevel user + * @privilege http://tizen.org/privilege/wappush + * + * @return An error code + * @param[in] wapApplicationId The X-Wap-Application-Id indicating a WAP push application ID. + * @param[in] contentType The MIME content type of the content. + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_INVALID_ARG The specified @c contentType or @c wapApplicationId is invalid. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to register the conditions. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @see UnregisterCondition() + * + * @endif + */ + result RegisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType); + + /** + * @if VISPARTNER-OPERATOR + * + * Unregisters a condition to receive WAP push message. + * + * @since 2.1 + * + * @visibility partner-operator + * @privlevel user + * @privilege http://tizen.org/privilege/wappush + * + * @return An error code + * @param[in] wapApplicationId The X-Wap-Application-Id indicating a WAP push application ID. + * @param[in] contentType The MIME content type of the content. + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * @exception E_INVALID_ARG The specified @c contentType or @c wapApplicationId is invalid. + * @exception E_ILLEGAL_ACCESS The application does not have the permission to unregister the conditions. + * @exception E_SYSTEM A system error has occurred. + * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method. + * @see RegisterCondition() + * + * @endif + */ + result UnregisterCondition(const Tizen::Base::String& wapApplicationId, const Tizen::Base::String& contentType); + + result ConvertException(int err) const; + +public: + /** + * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] rhs An instance of _WapPushManagerImpl + */ + _WapPushManagerImpl(const _WapPushManagerImpl& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. + * + * @param[in] rhs An instance of _WapPushManagerImpl + */ + _WapPushManagerImpl& operator =(const _WapPushManagerImpl& rhs); + +private: + msg_handle_t __msgHandle; + _SmsEvent* __pWapPushReceiveEvent; + +}; // _WapPushManagerImpl + +} } // Tizen::Messaging +#endif // _FMSG_INTERNAL_WAP_PUSH_MANAGER_IMPL_H_ diff --git a/src/FMsg_WapPushMessageImpl.cpp b/src/FMsg_WapPushMessageImpl.cpp new file mode 100644 index 0000000..3d2a12f --- /dev/null +++ b/src/FMsg_WapPushMessageImpl.cpp @@ -0,0 +1,188 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_WapPushMessageImpl.cpp + * @brief This is the implementation file for the %_WapPushMessageImpl class. + * + * This file contains the implementation of the %__WapPushMessageImpl class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "FMsg_WapPushMessageImpl.h" +#include "FMsg_Types.h" + +using namespace Tizen::Base; +using namespace Tizen::Messaging; +using namespace Tizen::Security; + +namespace Tizen { namespace Messaging +{ + +_WapPushMessageImpl::_WapPushMessageImpl(void) + : __msgHeader(L"") + , __pMsgBody(null) +{ + __pMsgBody = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_MSG, __pMsgBody != null, E_OUT_OF_MEMORY, "memory allocation failed"); + __pMsgBody->Construct(0); + __pMsgBody->SetPosition(0); +} + +_WapPushMessageImpl::_WapPushMessageImpl(const _WapPushMessageImpl& value) +{ + result r = E_SUCCESS; + + r = __pMsgBody->SetArray(value.__pMsgBody->GetPointer(), 0, value.__pMsgBody->GetLimit()); + SysTryReturnVoidResult(NID_MSG, r == E_SUCCESS, r, "Failed to set array"); + __pMsgBody->SetPosition(0); + __msgHeader = value.__msgHeader; +} + +_WapPushMessageImpl::~_WapPushMessageImpl(void) +{ + if (__pMsgBody) + { + delete __pMsgBody; + __pMsgBody = null; + } +} + +_WapPushMessageImpl& +_WapPushMessageImpl::operator =(const _WapPushMessageImpl& rhs) +{ + result r = E_SUCCESS; + + if (this != &rhs) + { + r = __pMsgBody->SetArray(rhs.__pMsgBody->GetPointer(), 0, rhs.__pMsgBody->GetLimit()); + if (r == E_SUCCESS) + { + __pMsgBody->SetPosition(0); + __msgHeader = rhs.__msgHeader; + } + } + + return (*this); +} + +_WapPushMessageImpl::_WapPushMessageImpl(const Tizen::Base::String& header, const Tizen::Base::ByteBuffer& body) +{ + __pMsgBody = new (std::nothrow) ByteBuffer(); + SysTryReturnVoidResult(NID_MSG, __pMsgBody != null, E_OUT_OF_MEMORY, "memory allocation failed"); + __pMsgBody->Construct(body); + __pMsgBody->SetPosition(0); + __msgHeader = header; +} + +bool +_WapPushMessageImpl::Equals(const Tizen::Base::Object& obj) const +{ + const _WapPushMessageImpl* p_WapPushMessageImpl = dynamic_cast(&obj); + if (!p_WapPushMessageImpl) + { + SysLog(NID_MSG, "dynamic_cast is failed"); + return false; + } + + // msg header + if (__msgHeader != p_WapPushMessageImpl->__msgHeader) + { + return false; + } + + // msg body + if (__pMsgBody != p_WapPushMessageImpl->__pMsgBody) + { + return false; + } + + return true; +} + +WapPushMessage* +_WapPushMessageImpl::CloneN() const +{ + WapPushMessage* pWapPushMsg = null; + pWapPushMsg = _WapPushMessageImpl::GetWapPushMessageN(__msgHeader, *__pMsgBody); + + return pWapPushMsg; +} + +WapPushMessage* +_WapPushMessageImpl::GetWapPushMessageN(const Tizen::Base::String& pushMsgHdr, const Tizen::Base::ByteBuffer& pushMsgBody) +{ + WapPushMessage* pWapPushMsg = null; + result r = E_SUCCESS; + + pWapPushMsg = new (std::nothrow) WapPushMessage(pushMsgHdr, pushMsgBody); + SysTryCatch(NID_MSG, pWapPushMsg != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + SetLastResult(r); + + return pWapPushMsg; + +CATCH: + SetLastResult(r); + return null; +} + +int +_WapPushMessageImpl::GetHashCode(void) const +{ + int hash = 0; + + hash = __msgHeader.GetHashCode() + __pMsgBody->GetHashCode(); + + return hash; +} + +Tizen::Base::ByteBuffer* +_WapPushMessageImpl::GetBodyN(void) const +{ + result r = E_SUCCESS; + Tizen::Base::ByteBuffer* pMsgBuffer = null; + + ClearLastResult(); + + pMsgBuffer = new (std::nothrow) ByteBuffer(); + SysTryCatch(NID_MSG, pMsgBuffer != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed"); + + r = pMsgBuffer->Construct(*__pMsgBody); + r = pMsgBuffer->SetPosition(0); + + SetLastResult(r); + + return pMsgBuffer; + +CATCH: + SetLastResult(r); + + return null; +} + +Tizen::Base::String +_WapPushMessageImpl::GetHeader(void) const +{ + return __msgHeader; +} + +} } diff --git a/src/FMsg_WapPushMessageImpl.h b/src/FMsg_WapPushMessageImpl.h new file mode 100644 index 0000000..853cf12 --- /dev/null +++ b/src/FMsg_WapPushMessageImpl.h @@ -0,0 +1,207 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** +* @if VISPARTNER-OPERATOR +* +* @file FMsg_WapPushMessageImpl.h +* @brief This is the header file for the _WapPushMessageImpl class. +* +* @visibility partner-operator +* +* This header file contains the declarations of the _WapPushMessageImpl class. +* +* @endif +*/ + +#ifndef _FMSG_INTERNAL_WAP_PUSH_MESSAGE_IMPL_H_ +#define _FMSG_INTERNAL_WAP_PUSH_MESSAGE_IMPL_H_ + +namespace Tizen { namespace Messaging +{ + +/** +* @if VISPARTNER-OPERATOR +* +* @class _WapPushMessageImpl +* @brief This class provides methods for handling a WAP push message. +* +* @since 2.1 +* +* @final This class is not intended for extension. +* +* @visibility partner-operator +* +* The _WapPushMessageImpl class provides methods for handling a WAP push message. @n +* It allows you to get the header and the body of a WAP push message. +* +* @endif +*/ +class _WapPushMessageImpl + : public Tizen::Base::Object +{ +public: + /** + * @if VISPARTNER-OPERATOR + * + * This destructor overrides Tizen::Base::Object::~Object(). + * + * @since 2.1 + * + * @visibility partner-operator + * + * @endif + */ + virtual ~_WapPushMessageImpl(void); + +public: + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the header of the message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The header of the message + * @remarks The header has X-Wap-Application-Id and Content-Type fields. + * + * @endif + */ + Tizen::Base::String GetHeader(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the body of the message. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The body of the message + * @remarks The message body can be any MIME content-type. + * + * @endif + */ + Tizen::Base::ByteBuffer* GetBodyN(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Compares the specified instance of %_WapPushMessageImpl with this instance. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return @c true, if the values match @n + * @c false, otherwise + * @param[in] obj The other Object to be compared + * @see Object::Equals() + * + * @endif + */ + virtual bool Equals(const Tizen::Base::Object& obj) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the hash value of the current instance. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return The current instance's hash value + * + * @endif + */ + virtual int GetHashCode(void) const; + + /** + * @if VISPARTNER-OPERATOR + * + * Gets the copied instance of the class. + * + * @since 2.1 + * + * @visibility partner-operator + * + * @return An instance of %_WapPushMessageImpl + * @exception E_SUCCESS The method is successful. + * @exception E_OUT_OF_MEMORY The memory is insufficient. + * + * @remarks In case of error, this method returns @c null. @n + * The specific error code can be accessed using the GetLastResult() method. + * + * @endif + */ + WapPushMessage* CloneN(void) const; + + /** + * Gets the instance of WapPushMessage Class + * + * @since 2.1 + */ + static WapPushMessage* GetWapPushMessageN(const Tizen::Base::String& pushMsgHdr, const Tizen::Base::ByteBuffer& pushMsgBody); + +public: + /** + * This default constructor is intentionally declared as private so that only the platform can create an instance. + * + * @since 2.1 + */ + _WapPushMessageImpl(void); + + /** + * This is the copy constructor for the %_WapPushMessageImpl class. @n + * Copying of objects using this copy constructor is allowed. + * + * @since 2.1 + * + * @param[in] rhs An instance of _WapPushMessageImpl + */ + _WapPushMessageImpl(const _WapPushMessageImpl& rhs); + + /** + * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects. @n + * - Use CloneN() to get an exact copy of the instance. + * - Use Equals() to compare the contents of one instance with the other. + * + * @return A reference to this instance + * @param[in] rhs An instance of _WapPushMessageImpl + */ + _WapPushMessageImpl& operator =(const _WapPushMessageImpl& rhs); + + /** + * This constructor is intentionally declared as private so that only the platform can create an instance. + * + * @param[in] header The header of the received WAP push message + * @param[in] body The body of the received WAP push message + */ + _WapPushMessageImpl(const Tizen::Base::String& header, const Tizen::Base::ByteBuffer& body); + +private: + Tizen::Base::String __msgHeader; + Tizen::Base::ByteBuffer* __pMsgBody; + +}; // _WapPushMessageImpl + +} } // Tizen::Messaging +#endif // _FMSG_INTERNAL_WAP_PUSH_MESSAGE_IMPL_H_ diff --git a/src/inc/FMsg_IComposerListener.h b/src/inc/FMsg_IComposerListener.h new file mode 100644 index 0000000..21d9e1c --- /dev/null +++ b/src/inc/FMsg_IComposerListener.h @@ -0,0 +1,62 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_IComposerListener.h + * @brief This is the header file for the %_IComposerListener interface. + * + * This header file contains the declarations of the %_IComposerListener interface. + */ + +#ifndef _FMSG_INTERNAL_ICOMPOSER_LISTENER_H_ +#define _FMSG_INTERNAL_ICOMPOSER_LISTENER_H_ + +// Includes +#include +#include +#include + +namespace Tizen { namespace Messaging { + + /** + * @interface _IComposerListener + * @brief This interface implements a listener to respond to asynchronous composer callbacks. + * @since 1.0 + */ + class _OSP_EXPORT_ _IComposerListener : + public Tizen::Base::Runtime::IEventListener + { + // Operation + public: + /** + * Called when the message composer is initialized. + * + * @param[in] r The result of initializing a composer + */ + virtual void OnComposerInitialized(result r) = 0; + + /** + * Called when the message composer is terminated. + * + * @param[in] r The result of terminating a composer + */ + virtual void OnComposerTerminated(result r) = 0; + }; // _IComposerListener + +}; +}; + +#endif // _FMSG_INTERNAL_ICOMPOSER_LISTENER_H_ diff --git a/src/inc/FMsg_MessagingMessageTypes.h b/src/inc/FMsg_MessagingMessageTypes.h new file mode 100644 index 0000000..c990722 --- /dev/null +++ b/src/inc/FMsg_MessagingMessageTypes.h @@ -0,0 +1,68 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_MessagingMessageTypes.h + * @brief This is the header file for the Messaging's IPC messages. + * + * This header file contains the declarations of the IPC messages for the wap push. + */ + +#include +#include // must be modified. +#include +//#include "FMsg_MessagingIpcParamTraits.h" + +#ifndef MESSAGING_IPC_SERVER_NAME +#define MESSAGING_IPC_SERVER_NAME "osp.messaging.ipcserver.msg" +#endif +#define IPC_MESSAGE_START MessagingMsgStart +/* Sync */ + /* WapPush */ + IPC_SYNC_MESSAGE_CONTROL1_1(MessagingMsgStart_addWapPushEventListener, Tizen::Base::String /* wapApplicationId */, unsigned long /* result */) + //IPC_SYNC_MESSAGE_CONTROL1_1(MessagingMsgStart_removeWapPushEventListener, Tizen::Base::String /* wapApplicationId */, unsigned long /* result */) + IPC_SYNC_MESSAGE_CONTROL2_1(MessagingMsgStart_registerCondition, Tizen::Base::String /* wapApplicationId */, Tizen::Base::String /* contentType*/, unsigned long /* result */) + IPC_SYNC_MESSAGE_CONTROL2_1(MessagingMsgStart_unregisterCondition, Tizen::Base::String /* wapApplicationId */, Tizen::Base::String /* contentType*/, unsigned long /* result */) + + + /* etc control */ + IPC_SYNC_MESSAGE_CONTROL0_1(MessagingMsgStart_openCbsHandle, unsigned long /* result */); + IPC_SYNC_MESSAGE_CONTROL0_1(MessagingMsgStart_openMsgHandle, unsigned long /* result */); + + IPC_SYNC_MESSAGE_CONTROL1_1(MessagingMsgStart_addSmsEventListener, int /* port */, unsigned long /* result */) + IPC_SYNC_MESSAGE_CONTROL1_1(MessagingMsgStart_addCbsEtwsEventListener, bool /* enabled */, unsigned long /* result */) + + + IPC_SYNC_MESSAGE_CONTROL1_1(MessagingMsgStart_setSavingToCbsBoxEnabled, bool /* enable */, unsigned long /* result */); + IPC_SYNC_MESSAGE_CONTROL0_2(MessagingMsgStart_isCbsEnabled, bool /* isCbsEnabled */, unsigned long /* result */); + IPC_SYNC_MESSAGE_CONTROL1_1(MessagingMsgStart_setCbsEnabled, bool /* enable */, unsigned long /* result */); + IPC_SYNC_MESSAGE_CONTROL4_1(MessagingMsgStart_addCbsChannel , int /* from */, int /* to */, Tizen::Base::String /* name */, bool /* activate */, unsigned long /* result */) + IPC_SYNC_MESSAGE_CONTROL2_1(MessagingMsgStart_removeCbsChannel, int /* from */, int /* to */, unsigned long /* result */) + IPC_SYNC_MESSAGE_CONTROL2_3(MessagingMsgStart_getCbsChannelN, int /* from */, int /* to */,bool /* isActive */, Tizen::Base::String /* channelName */, unsigned long /* result */) + IPC_SYNC_MESSAGE_CONTROL0_2(MessagingMsgStart_getCbsChannelListN, Tizen::Base::Collection::ArrayList /*pCbsList*/, unsigned long /* result */) + IPC_SYNC_MESSAGE_CONTROL4_1(MessagingMsgStart_updateCbsChannel, int /* from */, int /* to */, Tizen::Base::String /* name */, bool /* isChannelEnable */, unsigned long /* result */) + + +/* Async */ + /* WapPush */ + IPC_MESSAGE_CONTROL3(MessagingMsgStart_wapPushEventCallBack, Tizen::Base::String /* header */, Tizen::Base::ByteBuffer /* body */, int /* bodyLength */) + /* Sms */ + IPC_MESSAGE_CONTROL4(MessagingMsgStart_incomingSmsCallback, int/* port */, int /* displayTime */, Tizen::Base::String /* message */, Tizen::Base::String/* senderAddress */) + IPC_MESSAGE_CONTROL5(MessagingMsgStart_incomingEtwsCallback, int /* tempReceivedTime */, Tizen::Base::ByteBuffer /* msgSerialNumber */, Tizen::Base::ByteBuffer /* msgSecurityInfo */, int /* messgeId */, Tizen::Base::ByteBuffer /* etwsMsgWarningType */) + IPC_MESSAGE_CONTROL6(MessagingMsgStart_incomingCbsCallback, Tizen::Base::String /* message */, Tizen::Base::ByteBuffer /* msgSerialNumber */, int /* tempReceivedTime */, int /* messgeId */, int /* dataCodingScheme */, Tizen::Base::String /* messageLanguage */) + + + diff --git a/src/inc/FMsg_Types.h b/src/inc/FMsg_Types.h new file mode 100644 index 0000000..7729c77 --- /dev/null +++ b/src/inc/FMsg_Types.h @@ -0,0 +1,113 @@ +// +// Open Service Platform +// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +/** + * @file FMsg_Types.h + * @brief This is the header file for Tizen::Messaging namespace. + * + * This header file contains the types and declarations for the Tizen::Messaging namespace. + */ + +#ifndef _FMSG_INTERNAL_TYPES_H_ +#define _FMSG_INTERNAL_TYPES_H_ + +#include +#include + +namespace Tizen { namespace Messaging +{ + +// recipient count +#define MAX_SMS_RECIPIENT_COUNT 10 +#define MAX_MMS_RECIPIENT_COUNT 10 +#define MAX_EMAIL_RECIPIENT_COUNT 20 + +// subject length +#define MAX_MMS_SUBJECT_LENGTH 40 +#define MAX_EMAIL_SUBJECT_LENGTH 256 + +// body text length +#define MAX_SMS_BODY_TEXT_LENGTH 80 +#define MAX_MMS_BODY_TEXT_LENGTH 1000 +#define MAX_EMAIL_BODY_TEXT_LENGTH 2000 + +// file size +#define MAX_MMS_FILE_SIZE (295 * 1024) // 295KB = 300KB - 4KB (MMS header margin) - 1KB (margin for local language size) +#define MAX_EMAIL_FILE_SIZE (5 * 1024 * 1024) // 5MB +#define MMS_1000K_FILE_SIZE (995 * 1024) + +// attachment count +#define MAX_EMAIL_ATTACHMENT_COUNT 20 + +// address length +#define MIN_LENGTH_PHONE 3 +#define MAX_LENGTH_PHONE 41 +#define MIN_LENGTH_EMAIL 5 // a@b.c +#define MAX_LENGTH_EMAIL (64 + 255 + 1) // RFC 2822 - Local(64) + Domain(255) + '@'(1) +#define MAX_SMS_LENGTH_PHONE 20 + +// keyword length for retrieving SMS inbox, sentbox, or outbox +#define MIN_KEYWORD_LENGTH 1 +#define MAX_KEYWORD_LENGTH 30 + +// Cbs channel name length +#define MAX_CBS_CHANNEL_NAME_LENGTH 32 +#define MAX_CBS_CHANNEL_RANGE 0xFFFF +#define MAX_CBS_CHANNEL_LIMIT 0xFFFF +#define MESSAGES_ETWS_WARNING_INFO_LEN 50 + + +//Detail email message +#define MAX_EMAIL_MESSAGE_RECEIPT_TYPE 3 +#define MAX_EMAIL_MESSAGE_BODY_TYPE 3 +#define MAX_EMAIL_MESSAGE_PRIORITY 6 +#define MAX_EMAIL_MESSAGE_RETURN_RECEIPT_TYPE 0x09 +#define MAX_EMAIL_MESSAGE_CLASS 22 +#define MAX_EMAIL_MESSAGE_DIGEST_TYPE 2 +#define MAX_EMAIL_MESSAGE_SMIME_TYPE 4 + +// +// @enum MessageType +// Message types for internal use +// +enum _MessageType +{ + _MSG_SMS = 0, /**