2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
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>
40 enum MessagingServiceSyncType
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,
49 class MailSync : private DPL::Event::EventListener<DBus::MessageEvent>
52 static MailSync& getInstance();
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);
65 void OnEventReceived(const DBus::MessageEvent& event);
69 struct SyncBodyDownloadRequestData
72 Api::Messaging::IEmailPtr mail; //mail
74 explicit SyncBodyDownloadRequestData(const Api::Messaging::IEmailPtr& mail) :
81 struct SyncRequestData
85 Api::Messaging::IEmailPtr mail; //mail
86 Api::Messaging::IAttachmentPtr attachment; //attachment
87 Api::Messaging::IMessagingServicePtr messagingService; //MessagingService
89 // std::string folderName; //Folder
92 explicit SyncRequestData (
95 const Api::Messaging::IEmailPtr& mail,
96 const Api::Messaging::IAttachmentPtr& attachment,
97 const Api::Messaging::IMessagingServicePtr& messagingService,
99 // std::string& folderName
104 attachment(attachment),
105 messagingService(messagingService),
107 // folderName(folderName)
111 explicit SyncRequestData (
114 const Api::Messaging::IMessagingServicePtr& messagingService) :
117 messagingService(messagingService)
121 explicit SyncRequestData (
124 const Api::Messaging::IMessagingServicePtr& messagingService,
126 // const std::string& folderName
130 messagingService(messagingService),
132 // folderName(folderName)
136 explicit SyncRequestData (
139 const Api::Messaging::IEmailPtr& mail) :
145 explicit SyncRequestData (
148 const Api::Messaging::IEmailPtr& mail,
149 const Api::Messaging::IAttachmentPtr& attachment
154 attachment(attachment)
160 typedef std::map<int, SyncRequestData> SyncRequests;
161 typedef SyncRequests::iterator SyncRequestIterator;
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 );
172 void cancelEmailJobInternal(int accountId, int handle);
174 //void cancelDownloadAttachmentInternal( const SyncAttachmentDownloadRequests& data );
177 DPL::ScopedPtr<DPL::Thread> m_dbusThread;
178 DBus::ConnectionPtr m_dbus;
180 SyncRequests m_SyncRequests;
181 int m_default_slot_size; //slot size