From 44c3bcb24c35fd22f88775194b0fa3576f62386a Mon Sep 17 00:00:00 2001 From: Kyeonghun Lee Date: Fri, 13 Jan 2017 12:01:06 +0900 Subject: [PATCH] clone Tizen.Messaging from spin Change-Id: Id04e88de77c5124a88f2b60a0085fe2a21154d79 Signed-off-by: Kyeonghun Lee --- .gitignore | 7 + LICENSE | 202 ++++++++++++++ Tizen.Messaging/Interop/Interop.Email.cs | 70 +++++ Tizen.Messaging/Interop/Interop.Libraries.cs | 24 ++ Tizen.Messaging/Interop/Interop.Messages.cs | 124 +++++++++ Tizen.Messaging/Properties/AssemblyInfo.cs | 36 +++ .../Tizen.Messaging.Email/EmailAttachment.cs | 29 ++ .../Tizen.Messaging.Email/EmailEnumerations.cs | 34 +++ .../Tizen.Messaging.Email/EmailErrorFactory.cs | 96 +++++++ .../Tizen.Messaging.Email/EmailMessage.cs | 234 ++++++++++++++++ .../Tizen.Messaging.Email/EmailRecipient.cs | 29 ++ .../Tizen.Messaging.Email/EmailSender.cs | 72 +++++ .../Tizen.Messaging.Messages/CBMessage.cs | 30 ++ .../Tizen.Messaging.Messages/Message.cs | 304 +++++++++++++++++++++ .../MessageReceivedEventArgs.cs | 38 +++ .../Tizen.Messaging.Messages/MessagesAddress.cs | 42 +++ .../Tizen.Messaging.Messages/MessagesAttachment.cs | 39 +++ .../MessagesEnumerations.cs | 152 +++++++++++ .../MessagesErrorFactory.cs | 73 +++++ .../Tizen.Messaging.Messages/MessagesEvent.cs | 125 +++++++++ .../Tizen.Messaging.Messages/MessagesManager.cs | 72 +++++ .../MessagesManagerImpl.cs | 233 ++++++++++++++++ .../MessagesSearchFilter.cs | 29 ++ .../Tizen.Messaging.Messages/MmsMessage.cs | 147 ++++++++++ .../Tizen.Messaging.Messages/PushMessage.cs | 30 ++ .../Tizen.Messaging.Messages/SmsMessage.cs | 46 ++++ Tizen.Messaging/Tizen.Messaging.csproj | 99 +++++++ Tizen.Messaging/Tizen.Messaging.nuspec | 21 ++ Tizen.Messaging/Tizen.Messaging.project.json | 9 + Tizen.Messaging/Tizen.Messaging.sln | 22 ++ Tizen.Messaging/Tizen.Messaging.snk | Bin 0 -> 596 bytes packaging/csapi-messaging.manifest | 5 + packaging/csapi-messaging.spec | 78 ++++++ 33 files changed, 2551 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100755 Tizen.Messaging/Interop/Interop.Email.cs create mode 100644 Tizen.Messaging/Interop/Interop.Libraries.cs create mode 100755 Tizen.Messaging/Interop/Interop.Messages.cs create mode 100755 Tizen.Messaging/Properties/AssemblyInfo.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Email/EmailAttachment.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Email/EmailEnumerations.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Email/EmailErrorFactory.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Email/EmailMessage.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Email/EmailRecipient.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Email/EmailSender.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/CBMessage.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/Message.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/MessageReceivedEventArgs.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/MessagesAddress.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/MessagesAttachment.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/MessagesEnumerations.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/MessagesErrorFactory.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/MessagesEvent.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/MessagesManager.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/MessagesManagerImpl.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/MessagesSearchFilter.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/MmsMessage.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/PushMessage.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.Messages/SmsMessage.cs create mode 100755 Tizen.Messaging/Tizen.Messaging.csproj create mode 100644 Tizen.Messaging/Tizen.Messaging.nuspec create mode 100755 Tizen.Messaging/Tizen.Messaging.project.json create mode 100755 Tizen.Messaging/Tizen.Messaging.sln create mode 100755 Tizen.Messaging/Tizen.Messaging.snk create mode 100644 packaging/csapi-messaging.manifest create mode 100644 packaging/csapi-messaging.spec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..46619d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +bin/ +obj/ +*.exe +*.dll +*.csproj.user +*.lock.json +.vs/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -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/Tizen.Messaging/Interop/Interop.Email.cs b/Tizen.Messaging/Interop/Interop.Email.cs new file mode 100755 index 0000000..f5c5d82 --- /dev/null +++ b/Tizen.Messaging/Interop/Interop.Email.cs @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal enum EmailRecipientType + { + To = 1, + Cc = 2, + Bcc = 3 + } + + internal static partial class Email + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void EmailSentCallback(IntPtr handle, int result, IntPtr userData); + + [DllImport(Libraries.Email, EntryPoint = "email_create_message")] + internal static extern int CreateEmail(out IntPtr EmailHandle); + + [DllImport(Libraries.Email, EntryPoint = "email_destroy_message")] + internal static extern int DestroyEmail(IntPtr EmailHandle); + + [DllImport(Libraries.Email, EntryPoint = "email_set_subject")] + internal static extern int SetSubject(IntPtr EmailHandle, string text); + + [DllImport(Libraries.Email, EntryPoint = "email_set_body")] + internal static extern int SetBody(IntPtr EmailHandle, string text); + + [DllImport(Libraries.Email, EntryPoint = "email_add_recipient")] + internal static extern int AddRecipient(IntPtr EmailHandle, int type, string text); + + [DllImport(Libraries.Email, EntryPoint = "email_remove_all_recipient")] + internal static extern int RemoveRecipient(IntPtr EmailHandle); + + [DllImport(Libraries.Email, EntryPoint = "email_add_attach")] + internal static extern int AddAttachment(IntPtr EmailHandle, string text); + + [DllImport(Libraries.Email, EntryPoint = "email_remove_all_attachments")] + internal static extern int RemoveAttachments(IntPtr EmailHandle); + + [DllImport(Libraries.Email, EntryPoint = "email_save_message")] + internal static extern int SaveEmail(IntPtr EmailHandle); + + [DllImport(Libraries.Email, EntryPoint = "email_send_message")] + internal static extern int SendEmail(IntPtr EmailHandle, bool SaveToSentBox); + + [DllImport(Libraries.Email, EntryPoint = "email_set_message_sent_cb")] + internal static extern int SetCb(IntPtr EmailHandle, EmailSentCallback Cb, IntPtr UserData); + + [DllImport(Libraries.Email, EntryPoint = "email_unset_message_sent_cb")] + internal static extern int UnsetCb(IntPtr EmailHandle); + } +} diff --git a/Tizen.Messaging/Interop/Interop.Libraries.cs b/Tizen.Messaging/Interop/Interop.Libraries.cs new file mode 100644 index 0000000..64170be --- /dev/null +++ b/Tizen.Messaging/Interop/Interop.Libraries.cs @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +internal static partial class Interop +{ + internal static partial class Libraries + { + public const string Messages = "libcapi-messaging-messages.so.0"; + public const string Email = "libcapi-messaging-email.so.0"; + } +} diff --git a/Tizen.Messaging/Interop/Interop.Messages.cs b/Tizen.Messaging/Interop/Interop.Messages.cs new file mode 100755 index 0000000..7697262 --- /dev/null +++ b/Tizen.Messaging/Interop/Interop.Messages.cs @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Messages + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void MessageIncomingCallback(IntPtr messageHandle, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void MessageSentCallback(int result, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool MessageSearchCallback(IntPtr messageHandle, int index, int resultCount, int totalCount, IntPtr userData); + + [DllImport(Libraries.Messages, EntryPoint = "messages_open_service")] + internal static extern int OpenService(out IntPtr serviceHandle); + + [DllImport(Libraries.Messages, EntryPoint = "messages_close_service")] + internal static extern int CloseService(IntPtr serviceHandle); + + [DllImport(Libraries.Messages, EntryPoint = "messages_create_message")] + internal static extern int CreateMessage(int type, out IntPtr messageHandle); + + [DllImport(Libraries.Messages, EntryPoint = "messages_destroy_message")] + internal static extern int DestroyMessage(IntPtr messageHandle); + + [DllImport(Libraries.Messages, EntryPoint = "messages_get_message_id")] + internal static extern int GetMessageId(IntPtr messageHandle, out int messageId); + + [DllImport(Libraries.Messages, EntryPoint = "messages_set_sim_id")] + internal static extern int SetSimId(IntPtr messageHandle, int simId); + + [DllImport(Libraries.Messages, EntryPoint = "messages_get_sim_id")] + internal static extern int GetSimId(IntPtr messageHandle, out int simId); + + [DllImport(Libraries.Messages, EntryPoint = "messages_set_mbox_type")] + internal static extern int SetMboxType(IntPtr messageHandle, int mboxType); + + [DllImport(Libraries.Messages, EntryPoint = "messages_get_mbox_type")] + internal static extern int GetMboxType(IntPtr messageHandle, out int mboxType); + + [DllImport(Libraries.Messages, EntryPoint = "messages_get_message_port")] + internal static extern int GetMessagePort(IntPtr messageHandle, out int messagePort); + + [DllImport(Libraries.Messages, EntryPoint = "messages_get_message_type")] + internal static extern int GetMessageType(IntPtr messageHandle, out int messageType); + + [DllImport(Libraries.Messages, EntryPoint = "messages_set_text")] + internal static extern int SetText(IntPtr messageHandle, string text); + + [DllImport(Libraries.Messages, EntryPoint = "messages_get_text")] + internal static extern int GetText(IntPtr messageHandle, out string text); + + [DllImport(Libraries.Messages, EntryPoint = "messages_set_time")] + internal static extern int SetTime(IntPtr messageHandle, int time); + + [DllImport(Libraries.Messages, EntryPoint = "messages_get_time")] + internal static extern int GetTime(IntPtr messageHandle, out int time); + + [DllImport(Libraries.Messages, EntryPoint = "messages_mms_set_subject")] + internal static extern int SetSubject(IntPtr messageHandle, string subject); + + [DllImport(Libraries.Messages, EntryPoint = "messages_mms_get_subject")] + internal static extern int GetSubject(IntPtr messageHandle, out string subject); + + [DllImport(Libraries.Messages, EntryPoint = "messages_add_address")] + internal static extern int AddAddress(IntPtr messageHandle, string address, int type); + + [DllImport(Libraries.Messages, EntryPoint = "messages_get_address_count")] + internal static extern int GetAddressCount(IntPtr messageHandle, out int count); + + [DllImport(Libraries.Messages, EntryPoint = "messages_get_address")] + internal static extern int GetAddress(IntPtr messageHandle, int index, out string address, out int type); + + [DllImport(Libraries.Messages, EntryPoint = "messages_remove_all_addresses")] + internal static extern int RemoveAllAddress(IntPtr messageHandle); + + [DllImport(Libraries.Messages, EntryPoint = "messages_mms_add_attachment")] + internal static extern int AddAttachment(IntPtr messageHandle, int type, string path); + + [DllImport(Libraries.Messages, EntryPoint = "messages_mms_get_attachment_count")] + internal static extern int GetAttachmentCount(IntPtr messageHandle, out int count); + + [DllImport(Libraries.Messages, EntryPoint = "messages_mms_get_attachment")] + internal static extern int GetAttachment(IntPtr messageHandle, int index, out int type, out string path); + + [DllImport(Libraries.Messages, EntryPoint = "messages_mms_remove_all_attachments")] + internal static extern int RemoveAllAttachment(IntPtr messageHandle); + + [DllImport(Libraries.Messages, EntryPoint = "messages_set_message_incoming_cb")] + internal static extern int SetMessageIncomingCb(IntPtr serviceHandle, MessageIncomingCallback cb, IntPtr userData); + + [DllImport(Libraries.Messages, EntryPoint = "messages_unset_message_incoming_cb")] + internal static extern int UnsetMessageIncomingCb(IntPtr serviceHandle); + + [DllImport(Libraries.Messages, EntryPoint = "messages_send_message")] + internal static extern int SendMessage(IntPtr serviceHandle, IntPtr messageHandle, bool saveToSentbox, MessageSentCallback cb, IntPtr userData); + + [DllImport(Libraries.Messages, EntryPoint = "messages_search_message_by_id")] + internal static extern int GetMessageById(IntPtr serviceHandle, int msgId, out IntPtr messageHandle); + + [DllImport(Libraries.Messages, EntryPoint = "messages_foreach_message")] + internal static extern int SearchMessage(IntPtr serviceHandle, int mbox, int messageType, string textKeyword, string addressKeyword, int offset, int limit, MessageSearchCallback cb, IntPtr userData); + + } +} diff --git a/Tizen.Messaging/Properties/AssemblyInfo.cs b/Tizen.Messaging/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..e5d98c4 --- /dev/null +++ b/Tizen.Messaging/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tizen.Messaging")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Samsung Electronics")] +[assembly: AssemblyProduct("Tizen.Messaging")] +[assembly: AssemblyCopyright("Copyright (c) 2016 Samsung Electronics Co., Ltd")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1f097c95-dedf-47f2-bc90-eef737fee686")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Tizen.Messaging/Tizen.Messaging.Email/EmailAttachment.cs b/Tizen.Messaging/Tizen.Messaging.Email/EmailAttachment.cs new file mode 100755 index 0000000..9c54ec7 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Email/EmailAttachment.cs @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Messaging.Email +{ + /// + /// Represents an email attachment + /// + public class EmailAttachment + { + /// + /// The absolute full path of the file to be attached + /// + public string FilePath { get; set; } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Email/EmailEnumerations.cs b/Tizen.Messaging/Tizen.Messaging.Email/EmailEnumerations.cs new file mode 100755 index 0000000..fdeaa37 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Email/EmailEnumerations.cs @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +namespace Tizen.Messaging.Email +{ + /// + /// Result of sending the email + /// + public enum EmailSendResult + { + /// + /// Failed to send the message + /// + Failure = -1, + + /// + /// email sent successfully + /// + Success = 0 + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Email/EmailErrorFactory.cs b/Tizen.Messaging/Tizen.Messaging.Email/EmailErrorFactory.cs new file mode 100755 index 0000000..90dbe54 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Email/EmailErrorFactory.cs @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.IO; +using Tizen.Internals.Errors; + +namespace Tizen.Messaging.Email +{ + internal enum EmailError + { + None = ErrorCode.None, + OutOfMemory = ErrorCode.OutOfMemory, + InvalidParameter = ErrorCode.InvalidParameter, + ServerNotReady = -0x01710000 | 0x501, + CommunicationWithServerFailed = -0x01710000 | 0x502, + OutOfRange = -0x01710000 | 0x503, + SendingFailed = -0x01710000 | 0x504, + OperationFailed = -0x01710000 | 0x505, + NoSimCard = -0x01710000 | 0x506, + NoData = -0x01710000 | 0x507, + PermissionDenied = ErrorCode.PermissionDenied, + NotSupported = ErrorCode.NotSupported + } + + internal static class EmailErrorFactory + { + internal const string LogTag = "Tizen.Messaging.Email"; + + internal static Exception GetException(int err) + { + EmailError error = (EmailError)err; + if (error == EmailError.OutOfMemory) + { + return new OutOfMemoryException("Out of memory"); + } + else if (error == EmailError.InvalidParameter) + { + return new ArgumentException("Invalid parameter"); + } + else if (error == EmailError.ServerNotReady) + { + return new IOException("Server not ready yet"); ; + } + else if (error == EmailError.NoData) + { + return new InvalidDataException("No data found"); + } + else if (error == EmailError.CommunicationWithServerFailed) + { + return new TimeoutException("timed out"); + } + else if (error == EmailError.PermissionDenied) + { + return new UnauthorizedAccessException("Permission denied"); + } + else if (error == EmailError.NotSupported) + { + return new NotSupportedException("Not supported"); + } + else if (error == EmailError.OutOfRange) + { + return new IndexOutOfRangeException("Out of range"); + } + else if (error == EmailError.SendingFailed) + { + return new Exception("Sending failed"); + } + else if (error == EmailError.OperationFailed) + { + return new InvalidOperationException("operation failed"); + } + else if (error == EmailError.NoSimCard) + { + return new Exception("No sim card found"); + } + else + { + return new Exception("System operation"); + } + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Email/EmailMessage.cs b/Tizen.Messaging/Tizen.Messaging.Email/EmailMessage.cs new file mode 100755 index 0000000..8755f16 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Email/EmailMessage.cs @@ -0,0 +1,234 @@ +/* +* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace Tizen.Messaging.Email +{ + /// + /// The class contains Messaging API to support sending email messages. + /// + public class EmailMessage : IDisposable + { + internal IntPtr _emailHandle = IntPtr.Zero; + private bool _disposed = false; + private String _subject; + private String _body; + private IList _attachments = new List(); + private ICollection _to = new Collection(); + private ICollection _cc = new Collection(); + private ICollection _bcc = new Collection(); + + /// + /// The constructor + /// + public EmailMessage() + { + int ret = Interop.Email.CreateEmail(out _emailHandle); + if (ret != (int)EmailError.None) + { + Log.Error(EmailErrorFactory.LogTag, "Failed to create message handle, Error code: " + (EmailError)ret); + throw EmailErrorFactory.GetException(ret); + } + } + + /// + /// Subject of the email message + /// + public string Subject + { + set + { + _subject = value; + int ret = Interop.Email.SetSubject(_emailHandle, _subject); + if (ret != (int)EmailError.None) + { + Log.Error(EmailErrorFactory.LogTag, "Failed to set subject, Error code: " + (EmailError)ret); + throw EmailErrorFactory.GetException(ret); + } + } + get + { + return _subject; + } + + } + + /// + /// Body of the email message + /// + public string Body + { + set + { + _body = value; + int ret = Interop.Email.SetBody(_emailHandle, _body); + if (ret != (int)EmailError.None) + { + Log.Error(EmailErrorFactory.LogTag, "Failed to set body, Error code: " + (EmailError)ret); + throw EmailErrorFactory.GetException(ret); + } + } + get + { + return _body; + } + } + + /// + /// List of file attachments + /// + /// + /// The maximum attachment file size is 10 MB. + /// + public IList Attachments + { + get + { + return _attachments; + } + } + + /// + /// Collection of normal email recipients + /// + /// + /// Email address should be in standard format (as described in Internet standards RFC 5321 and RFC 5322). + /// + public ICollection To + { + get + { + return _to; + } + } + + /// + /// Collection of CC(carbon copy) email recipients + /// + /// + /// Email address should be in standard format (as described in Internet standards RFC 5321 and RFC 5322). + /// + public ICollection Cc + { + get + { + return _cc; + } + } + + /// + /// Collection of BCC(blind carbon copy) email recipients + /// + /// + /// Email address should be in standard format (as described in Internet standards RFC 5321 and RFC 5322). + /// + public ICollection Bcc + { + get + { + return _bcc; + } + } + + /// + /// Saves the email message + /// + public void Save() + { + int ret; + FillHandle(); + + ret = Interop.Email.SaveEmail(_emailHandle); + if (ret != (int)EmailError.None) + { + Log.Error(EmailErrorFactory.LogTag, "Failed to save email, Error code: " + (EmailError)ret); + throw EmailErrorFactory.GetException(ret); + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (_disposed) + return; + + if (disposing) + { + + } + + if (_emailHandle != IntPtr.Zero) + { + Interop.Email.DestroyEmail(_emailHandle); + _emailHandle = IntPtr.Zero; + } + _disposed = true; + } + + internal void FillHandle() + { + int ret = (int)EmailError.None; + foreach (EmailAttachment it in Attachments) + { + Console.WriteLine(it.FilePath); + ret = Interop.Email.AddAttachment(_emailHandle, it.FilePath); + if (ret != (int)EmailError.None) + { + Log.Error(EmailErrorFactory.LogTag, "Failed to add attachment, Error code: " + (EmailError)ret); + throw EmailErrorFactory.GetException(ret); + } + } + + foreach (EmailRecipient it in To) + { + ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.To, it.Address); + if (ret != (int)EmailError.None) + { + Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret); + throw EmailErrorFactory.GetException(ret); + } + } + + foreach (EmailRecipient it in Cc) + { + ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.Cc, it.Address); + if (ret != (int)EmailError.None) + { + Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret); + throw EmailErrorFactory.GetException(ret); + } + } + + foreach (EmailRecipient it in Bcc) + { + ret = Interop.Email.AddRecipient(_emailHandle, (int)Interop.EmailRecipientType.Bcc, it.Address); + if (ret != (int)EmailError.None) + { + Log.Error(EmailErrorFactory.LogTag, "Failed to add recipients, Error code: " + (EmailError)ret); + throw EmailErrorFactory.GetException(ret); + } + } + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Email/EmailRecipient.cs b/Tizen.Messaging/Tizen.Messaging.Email/EmailRecipient.cs new file mode 100755 index 0000000..1a8288d --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Email/EmailRecipient.cs @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Messaging.Email +{ + /// + /// The class represents recipients of an email + /// + public class EmailRecipient + { + /// + /// The email address of the recipient + /// + public string Address { get; set; } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Email/EmailSender.cs b/Tizen.Messaging/Tizen.Messaging.Email/EmailSender.cs new file mode 100755 index 0000000..81def53 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Email/EmailSender.cs @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Threading.Tasks; + +namespace Tizen.Messaging.Email +{ + /// + /// The class to send email messages. + /// + public static class EmailSender + { + /// + /// Sends the email message. + /// + /// The email message + /// true to save the message in the sentbox + /// Failure if email sending failed otherwise Success + public static async Task SendAsync(EmailMessage email, bool saveToSentBox) + { + var task = new TaskCompletionSource(); + int ret = (int)EmailError.None; + + email.FillHandle(); + email.Save(); + + Interop.Email.EmailSentCallback _emailSendingCallback = (IntPtr handle, int result, IntPtr userData) => + { + task.SetResult((EmailSendResult)result); + }; + + ret = Interop.Email.SetCb(email._emailHandle, _emailSendingCallback, IntPtr.Zero); + if (ret != (int)EmailError.None) + { + Log.Error(EmailErrorFactory.LogTag, "Failed to set email incoming callback, Error code: " + (EmailError)ret); + throw EmailErrorFactory.GetException(ret); + } + + ret = Interop.Email.SendEmail(email._emailHandle, saveToSentBox); + if (ret != (int)EmailError.None) + { + Log.Error(EmailErrorFactory.LogTag, "Failed to send email, Error code: " + (EmailError)ret); + throw EmailErrorFactory.GetException(ret); + } + + var sendResult = await task.Task; + + ret = Interop.Email.UnsetCb(email._emailHandle); + if (ret != (int)EmailError.None) + { + Log.Error(EmailErrorFactory.LogTag, "Failed to set email incoming callback, Error code: " + (EmailError)ret); + throw EmailErrorFactory.GetException(ret); + } + + return sendResult; + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/CBMessage.cs b/Tizen.Messaging/Tizen.Messaging.Messages/CBMessage.cs new file mode 100755 index 0000000..949a1c8 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/CBMessage.cs @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Messaging.Messages +{ + /// + /// A class to represent cell broadcast messages. + /// + public class CBMessage : Message + { + internal CBMessage(IntPtr messageHandle) : base(messageHandle) + { + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/Message.cs b/Tizen.Messaging/Tizen.Messaging.Messages/Message.cs new file mode 100755 index 0000000..c2a13bd --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/Message.cs @@ -0,0 +1,304 @@ +/* +* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace Tizen.Messaging.Messages +{ + /// + /// A class to represent all messages. + /// + public abstract class Message : IDisposable + { + protected IntPtr _messageHandle = IntPtr.Zero; + private bool disposed = false; + + private MessagesAddress _from = null; + protected ICollection _to = new Collection(); + protected ICollection _cc = new Collection(); + protected ICollection _bcc = new Collection(); + + protected Message(MessageType type) + { + int ret = Interop.Messages.CreateMessage((int)type, out _messageHandle); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to create message handle, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret); + } + } + + protected Message(IntPtr messageHandle) + { + _messageHandle = messageHandle; + GetAllAddresses(); + } + + internal void FillHandle() + { + SetAddresses(); + (this as MmsMessage)?.SetAttachments(); + } + + ~Message() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + // Free managed objects + } + + // Free unmanaged objects + if (_messageHandle != IntPtr.Zero) + { + Interop.Messages.DestroyMessage(_messageHandle); + _messageHandle = IntPtr.Zero; + } + disposed = true; + } + + internal IntPtr GetHandle() + { + return _messageHandle; + } + + private void SetAddresses() + { + foreach (var it in _to) + { + AddAddress(it); + } + + foreach (var it in _cc) + { + AddAddress(it); + } + + foreach (var it in _bcc) + { + AddAddress(it); + } + } + + private void AddAddress(MessagesAddress address) + { + int ret = Interop.Messages.AddAddress(_messageHandle, address.Number, (int)address.Type); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to add address, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle); + } + } + + private void GetAllAddresses() + { + int count; + + int ret = Interop.Messages.GetAddressCount(_messageHandle, out count); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get address count, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle); + } + + string number; + int type; + var To = new Collection(); + var Cc = new Collection(); + var Bcc = new Collection(); + + for (int i = 0; i < count; i++) + { + ret = Interop.Messages.GetAddress(_messageHandle, i, out number, out type); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get address, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle); + } + + var addressItem = new MessagesAddress((RecipientType)type, number); + switch ((RecipientType)type) + { + case RecipientType.To: + To.Add(addressItem); + break; + case RecipientType.Cc: + Cc.Add(addressItem); + break; + case RecipientType.Bcc: + Bcc.Add(addressItem); + break; + default: + _from = addressItem; + break; + } + } + + _to = To; + _cc = Cc; + _bcc = Bcc; + } + + public int Id + { + get + { + int id = 0; + int ret = Interop.Messages.GetMessageId(_messageHandle, out id); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get message id, Error - " + (MessagesError)ret); + } + + return id; + } + } + + public int Port + { + get + { + int port = 0; + int ret = Interop.Messages.GetMessagePort(_messageHandle, out port); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get message port, Error - " + (MessagesError)ret); + } + + return port; + } + } + + public MessageBoxType BoxType + { + get + { + int boxType = (int)MessageBoxType.All; + int ret = Interop.Messages.GetMboxType(_messageHandle, out boxType); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get message box type, Error - " + (MessagesError)ret); + } + + return (MessageBoxType)boxType; + } + set + { + int ret = Interop.Messages.SetMboxType(_messageHandle, (int)value); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to set message box type, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle); + } + } + } + + public string Text + { + get + { + string text = null; + int ret = Interop.Messages.GetText(_messageHandle, out text); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get text, Error - " + (MessagesError)ret); + } + + return text; + } + set + { + int ret = Interop.Messages.SetText(_messageHandle, value); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to set text, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle); + } + } + } + + public DateTime Time + { + get + { + int time = 0; + int ret = Interop.Messages.GetTime(_messageHandle, out time); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get time, Error - " + (MessagesError)ret); + } + + return (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(time).ToLocalTime(); + } + set + { + int ret = Interop.Messages.SetTime(_messageHandle, (int)(value.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds)); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to set time, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle); + } + } + } + + public SimSlotId SimId + { + get + { + int simId = (int)SimSlotId.Unknown; + int ret = Interop.Messages.GetSimId(_messageHandle, out simId); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get simId, Error - " + (MessagesError)ret); + } + + return (SimSlotId)simId; + } + set + { + int ret = Interop.Messages.SetSimId(_messageHandle, (int)value); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to set simId, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle); + } + } + } + + public MessagesAddress From + { + get + { + return _from; + } + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/MessageReceivedEventArgs.cs b/Tizen.Messaging/Tizen.Messaging.Messages/MessageReceivedEventArgs.cs new file mode 100755 index 0000000..bbc3ba1 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/MessageReceivedEventArgs.cs @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Messaging.Messages +{ + public class MessageReceivedEventArgs : EventArgs + { + private Message _message; + + internal MessageReceivedEventArgs(Message message) + { + _message = message; + } + + public Message ReceivedMessage + { + get + { + return _message; + } + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/MessagesAddress.cs b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesAddress.cs new file mode 100755 index 0000000..1a27cd1 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesAddress.cs @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Messaging.Messages +{ + /// + /// A class to manage informations of message address. + /// + public class MessagesAddress + { + internal RecipientType Type; + public string Number { get; } + + /// + /// Creates a message address. + /// + /// The recipient's address to receive a message + public MessagesAddress(string number) + { + Number = number; + } + + internal MessagesAddress(RecipientType type, string number) + { + Type = type; + Number = number; + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/MessagesAttachment.cs b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesAttachment.cs new file mode 100755 index 0000000..fc8dae7 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesAttachment.cs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Messaging.Messages +{ + /// + /// A class to manage informations of message attachment. + /// + public class MessagesAttachment + { + public MediaType Type { get; } + + public string FilePath { get; } + + /// + /// Creates an attachment. + /// + /// The attachment's type + /// The file path to attach + public MessagesAttachment(MediaType type, string filePath) + { + Type = type; + FilePath = filePath; + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/MessagesEnumerations.cs b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesEnumerations.cs new file mode 100755 index 0000000..892cc4b --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesEnumerations.cs @@ -0,0 +1,152 @@ +/* +* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the License); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an AS IS BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +namespace Tizen.Messaging.Messages +{ + /// + /// Enumeration for the result of sending a message. + /// + public enum SentResult + { + /// + /// Message sending failed + /// + Failed = -1, + /// + /// Message sending succeeded + /// + Success = 0 + } + + /// + /// Enumeration for the message type. + /// + public enum MessageType + { + /// + /// Unknown type + /// + Unknown = 0, + /// + /// SMS type + /// + Sms = 1, + /// + /// MMS type + /// + Mms = 2, + /// + /// CB(Cell Broadcast) type + /// + CellBroadcast = Sms | 1 << 4, + /// + /// WAP Push type + /// + Push = Mms | 10 << 4 + } + + /// + /// Enumeration for the message box type. + /// + public enum MessageBoxType + { + /// + /// All message box type + /// + All = 0, + /// + /// Inbox type + /// + Inbox = 1, + /// + /// Outbox type + /// + Outbox = 2, + /// + /// Sentbox type + /// + Sentbox = 3, + /// + /// Draft type + /// + Draft = 4 + } + + /// + /// Enumeration for the SIM slot index of a message + /// + public enum SimSlotId + { + /// + /// Unknown SIM Slot + /// + Unknown = 0, + /// + /// SIM Slot 1 + /// + SimSlotId1 = 1, + /// + /// SIM Slot 2 + /// + SimSlotId2 = 2 + } + + /// + /// Enumeration for the recipient type of a message + /// + internal enum RecipientType + { + /// + /// Unknown + /// + Unknown = 0, + /// + /// 'To' recipient + /// + To = 1, + /// + /// 'Cc' (carbon copy) recipient + /// + Cc = 2, + /// + /// 'Bcc' (blind carbon copy) recipient + /// + Bcc = 3 + } + + /// + /// Enumeration for the attachment tyoe for MMS messaging. + /// + public enum MediaType + { + /// + /// Unknown + /// + Unknown = 0, + /// + /// The image + /// + Image = 1, + /// + /// The audio + /// + Audio = 2, + /// + /// The video + /// + Video = 3 + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/MessagesErrorFactory.cs b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesErrorFactory.cs new file mode 100755 index 0000000..1006097 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesErrorFactory.cs @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using Tizen.Internals.Errors; + +namespace Tizen.Messaging.Messages +{ + internal enum MessagesError + { + None = ErrorCode.None, + OutOfMemory = ErrorCode.OutOfMemory, + InvalidParameter = ErrorCode.InvalidParameter, + ServerNotReady = -0x01710000 | 0x501, + CommunicationWithServerFailed = -0x01710000 | 0x502, + OutOfRange = -0x01710000 | 0x503, + SendingFailed = -0x01710000 | 0x504, + OperationFailed = -0x01710000 | 0x505, + NoSimCard = -0x01710000 | 0x506, + NoData = -0x01710000 | 0x507, + PermissionDenied = ErrorCode.PermissionDenied, + NotSupported = ErrorCode.NotSupported + } + + internal static class MessagesErrorFactory + { + static internal void ThrowMessagesException(int e) + { + ThrowException(e, false); + } + + static internal void ThrowMessagesException(int e, IntPtr handle) + { + ThrowException(e, (handle == IntPtr.Zero)); + } + + static private void ThrowException(int e, bool isHandleNull) + { + MessagesError err = (MessagesError)e; + + if (isHandleNull) + { + throw new InvalidOperationException("Invalid instance (object may have been disposed or release)"); + } + + if (err == MessagesError.InvalidParameter) + { + throw new ArgumentException(err.ToString()); + } + else if (err == MessagesError.NotSupported) + { + throw new NotSupportedException("Not supported"); + } + else + { + throw new InvalidOperationException(err.ToString()); + } + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/MessagesEvent.cs b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesEvent.cs new file mode 100755 index 0000000..dd0d616 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesEvent.cs @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Messaging.Messages +{ + internal partial class MessagesManagerImpl + { + private event EventHandler _messageReceived; + + private Interop.Messages.MessageIncomingCallback _messageReceivedCallback; + + internal event EventHandler _MessageReceived + { + add + { + if (_messageReceived == null) + { + RegisterMessageReceivedEvent(); + } + _messageReceived += value; + } + remove + { + _messageReceived -= value; + if (_messageReceived == null) + { + UnregisterMessageReceivedEvent(); + } + } + } + + private void RegisterMessageReceivedEvent() + { + _messageReceivedCallback = (IntPtr messageHandle, IntPtr userData) => + { + try + { + IntPtr duplicatedMessageHandle = IntPtr.Zero; + + DuplicateMessageHandle(messageHandle, out duplicatedMessageHandle); + if (duplicatedMessageHandle != IntPtr.Zero) + { + int type = (int)MessageType.Unknown; + int result = Interop.Messages.GetMessageType(duplicatedMessageHandle, out type); + if (result != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get message type, Error - " + (MessagesError)result); + } + + switch ((MessageType)type) + { + case MessageType.Sms: + { + var receivedMessage = new SmsMessage(duplicatedMessageHandle); + MessageReceivedEventArgs args = new MessageReceivedEventArgs(receivedMessage); + _messageReceived?.Invoke(null, args); + break; + } + case MessageType.Mms: + { + var receivedMessage = new MmsMessage(duplicatedMessageHandle); + MessageReceivedEventArgs args = new MessageReceivedEventArgs(receivedMessage); + _messageReceived?.Invoke(null, args); + break; + } + case MessageType.CellBroadcast: + { + var receivedMessage = new CBMessage(duplicatedMessageHandle); + MessageReceivedEventArgs args = new MessageReceivedEventArgs(receivedMessage); + _messageReceived?.Invoke(null, args); + break; + } + case MessageType.Push: + { + var receivedMessage = new PushMessage(duplicatedMessageHandle); + MessageReceivedEventArgs args = new MessageReceivedEventArgs(receivedMessage); + _messageReceived?.Invoke(null, args); + break; + } + default: + { + Log.Error(Globals.LogTag, "Invaild message type - " + type); + break; + } + } + } + } + catch + { + Log.Error(Globals.LogTag, "Exception in Callback"); + } + }; + + int ret = Interop.Messages.SetMessageIncomingCb(_MessageServiceHandle, _messageReceivedCallback, IntPtr.Zero); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to set message incoming callback, Error - " + (MessagesError)ret); + } + } + + private void UnregisterMessageReceivedEvent() + { + int ret = Interop.Messages.UnsetMessageIncomingCb(_MessageServiceHandle); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to unset message incoming callback, Error - " + (MessagesError)ret); + } + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/MessagesManager.cs b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesManager.cs new file mode 100755 index 0000000..7be07ea --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesManager.cs @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Tizen.Messaging.Messages +{ + /// + /// A class for message management. It allows applications to use message service. + /// + public static class MessagesManager + { + /// + /// Sends a message. + /// + /// http://tizen.org/privilege/message.write + /// The message to be sent + /// The boolean variable to indicate sent message should be saved in sentbox or not + /// A task contains the result of message sending + /// Thrown when method failed due to invalid operation + /// Thrown when message service is not supported + /// Thrown when input coordinates are invalid + public static Task SendMessageAsync(Message message, bool saveToSentbox) + { + return MessagesManagerImpl.Instance.SendMessageAsync(message, saveToSentbox); + } + + /// + /// Searches for messages. + /// + /// http://tizen.org/privilege/message.read + /// The search filter for searching messages + /// A task contains the messages which fit with search filter + /// Thrown when method failed due to invalid operation + /// Thrown when message service is not supported + /// Thrown when input coordinates are invalid + public static Task> SearchMessageAsync(MessagesSearchFilter filter) + { + return MessagesManagerImpl.Instance.SearchMessageAsync(filter); + } + + /// + /// (event) MessageReceived is raised when receiving a message. + /// + static public event EventHandler MessageReceived + { + add + { + MessagesManagerImpl.Instance._MessageReceived += value; + } + remove + { + MessagesManagerImpl.Instance._MessageReceived -= value; + } + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/MessagesManagerImpl.cs b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesManagerImpl.cs new file mode 100755 index 0000000..63cd9fc --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesManagerImpl.cs @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Tizen.Messaging.Messages +{ + static internal class Globals + { + internal const string LogTag = "Tizen.Messaging.Messages"; + } + + internal partial class MessagesManagerImpl : IDisposable + { + private static readonly MessagesManagerImpl _instance = new MessagesManagerImpl(); + private bool disposed = false; + + private static IntPtr _MessageServiceHandle; + + private Interop.Messages.MessageSentCallback _messageSentCallback; + + internal static MessagesManagerImpl Instance + { + get + { + return _instance; + } + } + + private MessagesManagerImpl() + { + initialize(); + } + + ~MessagesManagerImpl() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + // Free managed objects + } + + // Free unmanaged objects + deinitialize(); + disposed = true; + } + + private void initialize() + { + int ret; + + ret = Interop.Messages.OpenService(out _MessageServiceHandle); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to open service, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret); + } + } + + private void deinitialize() + { + if (_MessageServiceHandle != IntPtr.Zero) + { + int ret; + + ret = Interop.Messages.CloseService(_MessageServiceHandle); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to close service, Error - " + (MessagesError)ret); + } + + _MessageServiceHandle = IntPtr.Zero; + } + } + + internal Task SendMessageAsync(Message message, bool saveToSentbox) + { + var task = new TaskCompletionSource(); + + _messageSentCallback = (int result, IntPtr data) => + { + task.SetResult((SentResult)result); + }; + + message.FillHandle(); + + int ret; + IntPtr messageHandle = message.GetHandle(); + + ret = Interop.Messages.SendMessage(_MessageServiceHandle, messageHandle, saveToSentbox, _messageSentCallback, IntPtr.Zero); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to send message, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _MessageServiceHandle); + } + + return task.Task; + } + + internal Task> SearchMessageAsync(MessagesSearchFilter filter) + { + return Task.Run>(() => + { + List messageList = new List(); + int ret; + + Interop.Messages.MessageSearchCallback callback = (IntPtr messageHandle, int index, int resultCount, int totalCount, IntPtr userData) => + { + try + { + if (messageHandle != IntPtr.Zero) + { + IntPtr duplicatedMessageHandle = IntPtr.Zero; + + DuplicateMessageHandle(messageHandle, out duplicatedMessageHandle); + if (duplicatedMessageHandle != IntPtr.Zero) + { + int type = (int)MessageType.Unknown; + int result = Interop.Messages.GetMessageType(duplicatedMessageHandle, out type); + if (result != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get message type, Error - " + (MessagesError)result); + } + + switch ((MessageType)type) + { + case MessageType.Sms: + { + var messageItem = new SmsMessage(duplicatedMessageHandle); + messageList.Add(messageItem); + break; + } + case MessageType.Mms: + { + var messageItem = new MmsMessage(duplicatedMessageHandle); + messageList.Add(messageItem); + break; + } + case MessageType.CellBroadcast: + { + var messageItem = new CBMessage(duplicatedMessageHandle); + messageList.Add(messageItem); + break; + } + case MessageType.Push: + { + var messageItem = new PushMessage(duplicatedMessageHandle); + messageList.Add(messageItem); + break; + } + default: + { + Log.Error(Globals.LogTag, "Invaild message type - " + type); + break; + } + } + + return true; + } + } + } + catch + { + Log.Error(Globals.LogTag, "Exception in Callback"); + } + + return false; + }; + + ret = Interop.Messages.SearchMessage(_MessageServiceHandle, (int)filter.MessageBoxType, (int)filter.MessageType, filter.TextKeyword, filter.AddressKeyword, 0, 0, callback, IntPtr.Zero); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to search message, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _MessageServiceHandle); + } + + return messageList; + }); + } + + private void DuplicateMessageHandle(IntPtr sourceHandle, out IntPtr clonedHandle) + { + int msgId; + IntPtr returnedHandle = IntPtr.Zero; + + int ret = Interop.Messages.GetMessageId(sourceHandle, out msgId); + if (ret == (int)MessagesError.None) + { + ret = Interop.Messages.GetMessageById(_MessageServiceHandle, msgId, out returnedHandle); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get message by id, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _MessageServiceHandle); + } + } + else + { + Log.Error(Globals.LogTag, "Failed to get message id, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _MessageServiceHandle); + } + + clonedHandle = returnedHandle; + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/MessagesSearchFilter.cs b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesSearchFilter.cs new file mode 100755 index 0000000..53a40c7 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/MessagesSearchFilter.cs @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Tizen.Messaging.Messages +{ + /// + /// A class to represent message search filters. + /// + public class MessagesSearchFilter + { + public MessageBoxType MessageBoxType { get; set; } + public MessageType MessageType { get; set; } + public string TextKeyword { get; set; } + public string AddressKeyword { get; set; } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/MmsMessage.cs b/Tizen.Messaging/Tizen.Messaging.Messages/MmsMessage.cs new file mode 100755 index 0000000..d22199c --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/MmsMessage.cs @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; + +namespace Tizen.Messaging.Messages +{ + /// + /// A class to represent multimedia messages. + /// + public class MmsMessage : Message + { + private IList _attachment = new List(); + + /// + /// Creates a multimedia message. + /// + public MmsMessage() : base(MessageType.Mms) + { + } + + internal MmsMessage(IntPtr messageHandle) : base(messageHandle) + { + GetAllAttachments(); + } + + public string Subject + { + get + { + string subject = null; + int ret = Interop.Messages.GetSubject(_messageHandle, out subject); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get subject, Error - " + (MessagesError)ret); + } + + return subject; + } + set + { + int ret = Interop.Messages.SetSubject(_messageHandle, value); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to set subject, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle); + } + } + } + + public ICollection To + { + get + { + return _to; + } + } + + public ICollection Cc + { + get + { + return _cc; + } + } + + public ICollection Bcc + { + get + { + return _bcc; + } + } + + public IList Attachments + { + get + { + return _attachment; + } + } + + internal void SetAttachments() + { + foreach (var it in _attachment) + { + AddAttachment(it); + } + } + + private void AddAttachment(MessagesAttachment attach) + { + int ret = Interop.Messages.AddAttachment(_messageHandle, (int)attach.Type, attach.FilePath); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to add attachment, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle); + } + } + + private void GetAllAttachments() + { + int count; + + int ret = Interop.Messages.GetAttachmentCount(_messageHandle, out count); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get attachment count, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle); + } + + string path; + int type; + var attachmentList = new List(); + + for (int i = 0; i < count; i++) + { + ret = Interop.Messages.GetAttachment(_messageHandle, i, out type, out path); + if (ret != (int)MessagesError.None) + { + Log.Error(Globals.LogTag, "Failed to get attachment, Error - " + (MessagesError)ret); + MessagesErrorFactory.ThrowMessagesException(ret, _messageHandle); + } + + var attachmentItem = new MessagesAttachment((MediaType)type, path); + attachmentList.Add(attachmentItem); + } + + _attachment = attachmentList; + } + + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/PushMessage.cs b/Tizen.Messaging/Tizen.Messaging.Messages/PushMessage.cs new file mode 100755 index 0000000..667e7ff --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/PushMessage.cs @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Messaging.Messages +{ + /// + /// A class to represent WAP push messages. + /// + public class PushMessage : Message + { + internal PushMessage(IntPtr messageHandle) : base(messageHandle) + { + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.Messages/SmsMessage.cs b/Tizen.Messaging/Tizen.Messaging.Messages/SmsMessage.cs new file mode 100755 index 0000000..4fe0380 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.Messages/SmsMessage.cs @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; + +namespace Tizen.Messaging.Messages +{ + /// + /// A class to represent short text messages. + /// + public class SmsMessage : Message + { + /// + /// Creates a short text message. + /// + public SmsMessage() : base(MessageType.Sms) + { + } + + internal SmsMessage(IntPtr messageHandle) : base(messageHandle) + { + } + + public ICollection To + { + get + { + return _to; + } + } + } +} diff --git a/Tizen.Messaging/Tizen.Messaging.csproj b/Tizen.Messaging/Tizen.Messaging.csproj new file mode 100755 index 0000000..ad751e5 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.csproj @@ -0,0 +1,99 @@ + + + + 14.0 + Debug + AnyCPU + 8.0.30703 + 2.0 + {1F097C95-DEDF-47F2-BC90-EEF737FEE686} + Library + Properties + Tizen.Messaging + Tizen.Messaging + 512 + en-US + + + .NETStandard + v1.3 + .NETStandard,Version=v1.3 + false + true + $(NoWarn);1701 + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + + + Tizen.Messaging.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) + <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) + true + + \ No newline at end of file diff --git a/Tizen.Messaging/Tizen.Messaging.nuspec b/Tizen.Messaging/Tizen.Messaging.nuspec new file mode 100644 index 0000000..549ef4e --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.nuspec @@ -0,0 +1,21 @@ + + + + Tizen.Messaging + $version$ + Samsung Electronics + false + https://www.apache.org/licenses/LICENSE-2.0 + https://www.tizen.org/ + https://developer.tizen.org/sites/default/files/images/tizen-pinwheel-on-light-rgb_64_64.png + © Samsung Electronics Co., Ltd All Rights Reserved + Provides the Messaging APIs for Tizen.Messaging + + + + + + + + + diff --git a/Tizen.Messaging/Tizen.Messaging.project.json b/Tizen.Messaging/Tizen.Messaging.project.json new file mode 100755 index 0000000..b3ee524 --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.project.json @@ -0,0 +1,9 @@ +{ + "dependencies": { + "NETStandard.Library": "1.6.0", + "Tizen": "1.0.1" + }, + "frameworks": { + "netstandard1.3": {} + } +} \ No newline at end of file diff --git a/Tizen.Messaging/Tizen.Messaging.sln b/Tizen.Messaging/Tizen.Messaging.sln new file mode 100755 index 0000000..e02fc2c --- /dev/null +++ b/Tizen.Messaging/Tizen.Messaging.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Messaging", "Tizen.Messaging.csproj", "{1F097C95-DEDF-47F2-BC90-EEF737FEE686}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1F097C95-DEDF-47F2-BC90-EEF737FEE686}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F097C95-DEDF-47F2-BC90-EEF737FEE686}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F097C95-DEDF-47F2-BC90-EEF737FEE686}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F097C95-DEDF-47F2-BC90-EEF737FEE686}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Tizen.Messaging/Tizen.Messaging.snk b/Tizen.Messaging/Tizen.Messaging.snk new file mode 100755 index 0000000000000000000000000000000000000000..869444284e8e44c14adc7c218fd636f73f1a004c GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50098!F3{AAFJ7G`@i;h_gE5c2{!q&&&-|3q zq9S3JS&ZRx`nqY9TqKxof!KX0SPX)S>5ae+*SJOGHCGJDzxi=(o4vL)9ipu#y=?y& zjYzU_KlqpNMoE$u3$Gc^h#56!8eI5%pWQ5eLN(p7R5At2{KyK2K>p~X-Oaxnf$NK*@8=%& zYDp?SwI4QqqE`2W%W<%*>}PTsw5PtQpnB}ulEvqg8NO%L*dl31*gkz7xK3a84*@AD z$tB?3+V5mvHH!Ss6zH^$gqhMzY$BepZle z*a6PNSrNYB$YEPa@AGk2OA9cSc6s`653SWT!d5QggsPCJ%*6QlR4`s^r0?hvN=Z9M zEdf}U!M(W18J}||>a41@CJgnSFM#GJ++cnA?_WutnvF{XEIUdSGj6mjQ5S5EbiMDp ijYPx+YRB372GDF+#M1YcVcJ~&ovoJBZX&8VDTp>}O)s?o literal 0 HcmV?d00001 diff --git a/packaging/csapi-messaging.manifest b/packaging/csapi-messaging.manifest new file mode 100644 index 0000000..75b0fa5 --- /dev/null +++ b/packaging/csapi-messaging.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/csapi-messaging.spec b/packaging/csapi-messaging.spec new file mode 100644 index 0000000..965d2de --- /dev/null +++ b/packaging/csapi-messaging.spec @@ -0,0 +1,78 @@ +%{!?dotnet_assembly_path: %define dotnet_assembly_path /opt/usr/share/dotnet.tizen/framework} +%{!?dotnet_core_path: %define dotnet_core_path %{_datadir}/tizen.net/ref} + +%if 0%{?tizen_build_devel_mode} +%define BUILDCONF Debug +%else +%define BUILDCONF Release +%endif + +Name: csapi-messaging +Summary: Tizen Messaging API for C# +Version: 1.0.0 +Release: 1 +Group: Development/Libraries +License: Apache-2.0 +URL: https://www.tizen.org +Source0: %{name}-%{version}.tar.gz +Source1: %{name}.manifest + +AutoReqProv: no + +BuildRequires: mono-compiler +BuildRequires: mono-devel + +BuildRequires: dotnet-build-tools + +# C# API Requires +BuildRequires: csapi-tizen-nuget + +%description +Tizen Messaging API for C# + +%prep +%setup -q +cp %{SOURCE1} . + +%define Assemblies Tizen.Messaging + +%build +for ASM in %{Assemblies}; do +# NuGet Restore +find $ASM/*.project.json -exec nuget restore {} \; +# Build +find $ASM/*.csproj -exec xbuild {} /p:Configuration=%{BUILDCONF} \; +# NuGet Pack +nuget pack $ASM/$ASM.nuspec -Version %{version} -Properties Configuration=%{BUILDCONF} + +done + +%install +# Runtime Binary +mkdir -p %{buildroot}%{dotnet_assembly_path} +for ASM in %{Assemblies}; do +%if 0%{?_with_corefx} + install -p -m 644 $ASM/bin/%{BUILDCONF}/$ASM.dll %{buildroot}%{dotnet_assembly_path} +%else + install -p -m 644 $ASM/bin/%{BUILDCONF}/Net45/$ASM.dll %{buildroot}%{dotnet_assembly_path} +%endif +done + +# NuGet +mkdir -p %{buildroot}/nuget +install -p -m 644 *.nupkg %{buildroot}/nuget + +%files +%manifest %{name}.manifest +%license LICENSE +%attr(644,root,root) %{dotnet_assembly_path}/*.dll + +%package nuget +Summary: NuGet package for %{name} +Group: Development/Libraries + +%description nuget +NuGet package for %{name} + +%files nuget +/nuget/*.nupkg -- 2.7.4