ad16674590ee882f3a50689dbe5d27ad11f323bb
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Messaging / NetworkStatus.cpp
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  * @author          Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
18  */
19
20 #include <dpl/assert.h>
21 #include <Commons/Exception.h>
22 #include "NetworkStatus.h"
23
24 namespace {
25 const char* DBUS_INTERFACE_NETWORK_STATUS = "User.Email.NetworkStatus";
26 const int DBUS_MESSAGE_PARAMETERS_NUMBER = 5;
27 }
28
29 namespace WrtDeviceApis {
30 namespace Messaging {
31 NetworkStatus::NetworkStatus(const DBus::MessagePtr& message)
32 {
33     Assert(message->getInterface() == DBUS_INTERFACE_NETWORK_STATUS);
34     initialize(message);
35 }
36
37 int NetworkStatus::getStatus() const
38 {
39     return m_status;
40 }
41
42 int NetworkStatus::getAccountId() const
43 {
44     return m_accountId;
45 }
46
47 std::string NetworkStatus::getSource() const
48 {
49     return m_source;
50 }
51
52 int NetworkStatus::getMailId() const
53 {
54     return m_mailId;
55 }
56
57 int NetworkStatus::getErrorCode() const
58 {
59     return m_errorCode;
60 }
61
62 void NetworkStatus::initialize(const DBus::MessagePtr& message)
63 {
64     DBus::Message::ReadIterator it = message->getReadIterator();
65     for (int i = 0; i < DBUS_MESSAGE_PARAMETERS_NUMBER; it->next(), ++i) {
66         if (!it->isValid()) {
67             ThrowMsg(Commons::PlatformException, "Missing some properties.");
68         }
69
70         switch (i) {
71         case 0: m_status = it->getInt();
72             break;
73         case 1: m_accountId = it->getInt();
74             break;
75         case 2: m_source = it->getString();
76             break;
77         case 3: m_mailId = it->getInt();
78             break;
79         case 4: m_errorCode = it->getInt();
80             break;
81         }
82     }
83 }
84 }
85 }