wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Messaging / SyncNetworkStatus.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <dpl/assert.h>
19 #include <Commons/Exception.h>
20 #include "SyncNetworkStatus.h"
21 #include <Logger.h>
22
23 namespace {
24 const char* DBUS_INTERFACE_NETWORK_STATUS = "User.Email.NetworkStatus";
25 const int DBUS_MESSAGE_PARAMETERS_NUMBER = 5;
26 }
27
28 namespace DeviceAPI {
29 namespace Messaging {
30
31 SyncNetworkStatus::SyncNetworkStatus(const DBus::MessagePtr& message)
32 {
33         LoggerD("enter : "  << message->getInterface());
34         Assert(message->getInterface() == DBUS_INTERFACE_NETWORK_STATUS);
35     initialize(message);
36 }
37
38 int SyncNetworkStatus::getStatus() const
39 {
40     return m_status;
41 }
42
43 int SyncNetworkStatus::getHandle() const
44 {
45     return m_handle;
46 }
47
48 std::string SyncNetworkStatus::getSource() const
49 {
50     return m_source;
51 }
52
53 int SyncNetworkStatus::getMailId() const
54 {
55     return m_mailId;
56 }
57
58 int SyncNetworkStatus::getErrorCode() const
59 {
60     return m_errorCode;
61 }
62
63 void SyncNetworkStatus::initialize(const DBus::MessagePtr& message)
64 {
65     DBus::Message::ReadIterator it = message->getReadIterator();
66     for (int i = 0; i < DBUS_MESSAGE_PARAMETERS_NUMBER; it->next(), ++i) {
67         if (!it->isValid()) {
68             ThrowMsg(WrtDeviceApis::Commons::PlatformException, "Missing some properties.");
69         }
70
71         switch (i) {
72         case 0: m_status = it->getInt();
73                  LoggerD("status :" << m_status);
74             break;
75         case 1: m_mailId = it->getInt();
76                  LoggerD("mail ID :" << m_mailId);
77             break;
78         case 2: m_source = it->getString();
79                  LoggerD("source :" << m_source);
80             break;
81         case 3: m_handle = it->getInt();
82                  LoggerD("handle :" << m_handle);
83             break;
84         case 4: m_errorCode = it->getInt();
85                  LoggerD("error Code :" << m_errorCode);
86             break;
87         }
88     }
89 }
90 }
91 }