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.
17 * @file MailNotifier.cpp
18 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
22 #include <emf-types.h>
23 #include <Commons/ThreadPool.h>
24 #include "MailNotifier.h"
25 #include "StorageChangeMessage.h"
26 #include "NetworkStatus.h"
29 const std::string DBUS_INTERFACE_STORAGE_CHANGE = "User.Email.StorageChange";
30 const std::string DBUS_FILTER_STORAGE_CHANGE =
31 "type='signal',interface='" + DBUS_INTERFACE_STORAGE_CHANGE + "'";
34 namespace WrtDeviceApis {
37 MailNotifier::MailNotifier() : m_connection(new DBus::Connection())
39 m_connection->AddListener(this);
40 m_connection->addFilter(DBUS_FILTER_STORAGE_CHANGE);
41 m_connection->open(DBUS_BUS_SYSTEM);
44 MailNotifier::~MailNotifier()
46 m_connection->RemoveListener(this);
47 m_connection->close();
50 void MailNotifier::setWorkerThread(DPL::Thread* thread)
52 m_connection->SwitchListenerToThread(this, thread);
55 void MailNotifier::OnEventReceived(const DBus::MessageEvent& event)
58 DBus::MessagePtr message = event.GetArg0();
59 if (message->getInterface() == DBUS_INTERFACE_STORAGE_CHANGE)
61 onStorageChange(message);
65 void MailNotifier::onStorageChange(const DBus::MessagePtr& message)
68 StorageChangeMessage sc = StorageChangeMessage::parse(message);
69 int mailId = sc.getMailId();
73 LogDebug("NOTI_MAIL_ADD [mail id = " << mailId << "]");
74 m_incomming.push_back(mailId);
77 case NOTI_MAIL_UPDATE:
78 LogDebug("NOTI_MAIL_UPDATE [mail id: " << mailId << "]");
79 if (sc.getExtra() == UPDATE_PARTIAL_BODY_DOWNLOAD)
81 auto it = std::find(m_incomming.begin(), m_incomming.end(), mailId);
82 if (m_incomming.end() != it)
84 m_incomming.erase(it);
85 DPL::Event::EventSupport<EmailReceivedEvent>::EmitEvent(
86 EmailReceivedEvent(mailId));