Update change log and spec for wrt-plugins-tizen_0.2.73
[profile/ivi/wrt-plugins-tizen.git] / src / platform / Tizen / Messaging / MailSync.h
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. 
15 */
16
17 /**
18  * @author          Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19  */
20
21 #ifndef MAILSYNC_H_
22 #define MAILSYNC_H_
23
24 #include <map>
25 #include <dpl/event/event_listener.h>
26 #include <dpl/thread.h>
27 #include <dpl/scoped_ptr.h>
28 #include <DBus/Connection.h>
29 #include <DBus/MessageEvent.h>
30 #include <API/Messaging/IEmail.h>
31 #include <API/Messaging/IAttachment.h>
32 #include <API/Messaging/IMessagingService.h>
33 #include <API/Messaging/IMessageFolder.h>
34
35
36 namespace TizenApis {
37 namespace Platform {
38 namespace Messaging {
39
40 enum MessagingServiceSyncType
41 {
42         MESSAGING_SERVICE_SYNC_TYPE_DOWNLOAD_BODY = 1,
43         MESSAGING_SERVICE_SYNC_TYPE_DOWNLOAD_ATTACHMENT,
44         MESSAGING_SERVICE_SYNC_TYPE_SYNC,
45         MESSAGING_SERVICE_SYNC_TYPE_SYNC_FOLDER,
46         MESSAGING_SERVICE_SYNC_TYPE_COUNT,
47 };
48
49 class MailSync : private DPL::Event::EventListener<DBus::MessageEvent>
50 {
51         public :
52                 static MailSync& getInstance();
53
54         public :
55                 int downloadBody(const Api::Messaging::IEmailPtr& mail);        //downloadBody
56                 void cancelDownloadBody(int handle);
57                 int downloadAttachment(const Api::Messaging::IEmailPtr& mail, const Api::Messaging::IAttachmentPtr& attachment);
58                 void cancelDownloadAttachment(int AttachmentId);
59                 int syncAccount(const Api::Messaging::IMessagingServicePtr& messagingService, const int limit);
60                 void syncAccountCancel(const int handle);
61                 int syncFolder(const Api::Messaging::IMessagingServicePtr& messagingService, const int folder_id, const int limit);
62                 void syncFolderCancel(const int handle);
63
64         protected:
65                 void OnEventReceived(const DBus::MessageEvent& event);
66         
67         private:
68                 
69                 struct SyncBodyDownloadRequestData
70                 {
71                         unsigned int handle;
72                         Api::Messaging::IEmailPtr mail;         //mail
73         
74                         explicit SyncBodyDownloadRequestData(const Api::Messaging::IEmailPtr& mail) :   
75                                 handle(0),
76                                 mail(mail)
77                         {
78                         }
79                 };
80
81                 struct SyncRequestData
82                 {       
83                         unsigned int handle;
84                         int syncType;
85                         Api::Messaging::IEmailPtr mail;                                 //mail
86                         Api::Messaging::IAttachmentPtr attachment;              //attachment
87                         Api::Messaging::IMessagingServicePtr messagingService; //MessagingService
88                         int folderId;
89 //                      std::string folderName;         //Folder
90                                                         //Type
91
92                         explicit SyncRequestData (
93                                         unsigned int handle,
94                                         int syncType, 
95                                         const Api::Messaging::IEmailPtr& mail,
96                                         const Api::Messaging::IAttachmentPtr& attachment, 
97                                         const Api::Messaging::IMessagingServicePtr& messagingService,
98                                         int folderId
99 //                                      std::string& folderName
100                                         ) :
101                                 handle(handle),
102                                 syncType(syncType),
103                                 mail(mail),
104                                 attachment(attachment),
105                                 messagingService(messagingService),
106                                 folderId(folderId)
107 //                              folderName(folderName)                          
108                         {
109                         }
110                         
111                         explicit SyncRequestData (
112                                         unsigned int handle,
113                                         int syncType,
114                                         const Api::Messaging::IMessagingServicePtr& messagingService) :
115                                 handle(handle),
116                                 syncType(syncType),
117                                 messagingService(messagingService)                      
118                         {
119                         }
120
121                         explicit SyncRequestData (
122                                         unsigned int handle,
123                                         int syncType,
124                                         const Api::Messaging::IMessagingServicePtr& messagingService,
125                                         int folderId
126 //                                      const std::string& folderName
127                                         ) :
128                                 handle(handle),
129                                 syncType(syncType),
130                                 messagingService(messagingService),
131                                 folderId(folderId)
132 //                              folderName(folderName)
133                         {
134                         }
135                                 
136                         explicit SyncRequestData (
137                                         unsigned int handle,
138                                         int syncType,
139                                         const Api::Messaging::IEmailPtr& mail) :
140                                 handle(handle),
141                                 syncType(syncType),
142                                 mail(mail)                      
143                         {
144                         }
145                         explicit SyncRequestData (
146                                         unsigned int handel,
147                                         int syncType,
148                                         const Api::Messaging::IEmailPtr& mail,
149                                         const Api::Messaging::IAttachmentPtr& attachment
150                                         ) :
151                                 handle(handle),
152                                 syncType(syncType),
153                                 mail(mail),
154                                 attachment(attachment)
155                         {
156                         }
157
158                 };
159
160                 typedef std::map<int, SyncRequestData> SyncRequests;
161                 typedef SyncRequests::iterator SyncRequestIterator;
162
163         private:
164                 MailSync();
165                 ~MailSync();
166
167         int syncAccountInternal(const Api::Messaging::IMessagingServicePtr& messagingService, const int limit);
168         int syncFolderInternal(const Api::Messaging::IMessagingServicePtr& messagingService, const int folder_id, const int limit);
169         int downloadBodyInternal( const Api::Messaging::IEmailPtr& mail, int account_id );
170         int downloadAttachmentInternal(const Api::Messaging::IEmailPtr& mail, int account_id, const Api::Messaging::IAttachmentPtr& attachment );
171         
172         void cancelEmailJobInternal(int accountId, int handle);
173
174         //void cancelDownloadAttachmentInternal( const SyncAttachmentDownloadRequests& data );  
175
176         private:
177                 DPL::ScopedPtr<DPL::Thread> m_dbusThread;
178                 DBus::ConnectionPtr m_dbus;
179                 
180                 SyncRequests m_SyncRequests;    
181                 int m_default_slot_size;                //slot size
182 };
183
184 }
185 }
186 }
187
188 #endif //MAILSYNC_H_