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.
20 * @author Pawel Misiak (p.misiak@samsung.com)
30 #include <dpl/atomic.h>
31 #include <dpl/thread.h>
35 #include <dpl/event/event_listener.h>
36 #include <API/Messaging/IMessaging.h>
37 #include <API/Messaging/IMessage.h>
38 #include <API/Messaging/EmailAccountInfo.h>
39 #include <Commons/Emitters.h>
40 #include <DBus/Connection.h>
41 #include <DBus/MessageEvent.h>
42 #include "MsgServiceHandleMgr.h"
43 #include "MailNotifier.h"
45 namespace WrtDeviceApis {
47 class Messaging : public Api::IMessaging,
48 private DPL::Event::EventListener<EmailReceivedEvent>
51 static Messaging& getInstance();
56 virtual void getNumberOfMessages(Api::MessageType msgType,
57 Api::FolderType folder,
61 virtual std::vector<Api::IMessagePtr> findMessages(
62 const std::vector<Api::MessageType>& msgTypes,
63 Api::FolderType folder,
64 const Api::MessageFilterPtr& filter);
66 virtual std::vector<Api::IMessagePtr> findMessages(
67 const std::vector<Api::MessageType>& msgTypes,
68 const std::string &folder,
69 const Api::MessageFilterPtr& filter);
71 virtual std::vector<std::string> getMessageIds(Api::MessageType msgType,
72 Api::FolderType folder);
74 virtual void createFolder(Api::MessageType msgType,
75 const std::string& userFolder);
77 virtual void deleteFolder(Api::MessageType msgType,
78 const std::string& userFolder);
80 virtual std::vector<std::string> getFolderNames(Api::MessageType msgType);
82 virtual std::vector<Api::EmailAccountInfo> getEmailAccounts() const;
84 int getEmailAccountId(const std::string& account);
86 void fetchEmailHeaders();
88 static int convertFolderToPlatform(const Api::FolderType folder);
91 * Gets folder id by given folder name.
92 * @return Folder id or 0 if not found
93 * @throw PlatformException on platform error.
95 static int convertFolderToPlatform(const std::string &folder);
97 void addOnMessageReceived(const Api::EmitterMessageReceivedPtr& emitter);
99 void removeOnMessageReceived(Api::EmitterMessageReceived::IdType id);
102 static int m_currentEmailAccountId;
104 static DPL::Atomic m_objCounter;
107 void OnEventReceived(const EmailReceivedEvent& event);
110 typedef Commons::Emitters<Api::EmitterMessageReceived> EmittersMessageReceived;
112 template<class MessageType>
113 struct MessageFilterMatcher
116 MessageFilterMatcher(const MessageType& message) : m_message(message)
120 bool operator()(const EmittersMessageReceived::EmitterPtrType& emitter)
126 if (!emitter->getFilter()) {
129 return emitter->getFilter()->compare(m_message);
133 MessageType m_message;
139 static void onSmsReceived(MSG_HANDLE_T handle,
142 static void onMmsReceived(MSG_HANDLE_T handle,
148 void getNumberOfEmails(Api::FolderType folder,
152 void getNumberOfSms(Api::FolderType folder,
156 void getNumberOfMms(Api::FolderType folder,
160 void getNumberOfSmsMms(Api::FolderType folder,
163 Api::MessageType msgType);
165 virtual std::vector<Api::IMessagePtr> findSms(Api::FolderType folder,
166 const Api::MessageFilterPtr& filter);
168 virtual std::vector<Api::IMessagePtr> findMms(Api::FolderType folder,
169 const Api::MessageFilterPtr& filter);
171 virtual std::vector<Api::IMessagePtr> findEmail(Api::FolderType folder,
172 const Api::MessageFilterPtr& filter);
174 virtual std::vector<Api::IMessagePtr> findEmail(const std::string &folder,
175 const Api::MessageFilterPtr& filter);
177 std::vector<std::string> getSmsIds(Api::FolderType folder);
179 std::vector<std::string> getMmsIds(Api::FolderType folder);
181 std::vector<std::string> getEmailIds(Api::FolderType folder);
183 void createMsgServiceFolder(const std::string& userFolder);
185 void createEmailFolder(const std::string& userFolder);
187 void deleteMsgServiceFolder(const std::string& userFolder);
189 void deleteEmailFolder(const std::string& userFolder);
191 std::vector<std::string> getFolderNamesMsgService();
193 std::vector<std::string> getFolderNamesEmail();
196 EmittersMessageReceived m_onMessageReceived;
197 MsgServiceHandleMgrPtr m_onMessageReceivedHandleMgr;
198 std::unique_ptr<MailNotifier> m_mailNotifier;