tizen beta release
[framework/web/wrt-plugins-common.git] / src / modules / tizen / Messaging / StorageChangeMessage.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  * @file   StorageChangeMessage.cpp
18  * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19  */
20
21 #include <Commons/Exception.h>
22 #include "StorageChangeMessage.h"
23
24 namespace {
25 const char* DBUS_INTERFACE_STORAGE_CHANGE = "User.Email.StorageChange";
26 const int DBUS_MESSAGE_PARAMETERS_NUMBER = 5;
27 }
28
29 namespace WrtDeviceApis {
30 namespace Messaging {
31
32 StorageChangeMessage::StorageChangeMessage()
33     : m_accountId(0),
34       m_mailId(0),
35       m_extra(0)
36 { }
37
38 StorageChangeMessage StorageChangeMessage::parse(const DBus::MessagePtr& message)
39 {
40     Assert(message.Get() != NULL && "Empty message.");
41     Assert(message->getInterface() == DBUS_INTERFACE_STORAGE_CHANGE);
42
43     StorageChangeMessage result;
44
45     DBus::Message::ReadIterator it = message->getReadIterator();
46     for (int i = 0; i < DBUS_MESSAGE_PARAMETERS_NUMBER; it->next(), ++i)
47     {
48         if (!it->isValid())
49         {
50             ThrowMsg(Commons::PlatformException, "Missing some properties.");
51         }
52
53         switch (i)
54         {
55         case 0:
56             result.m_type = it->getInt();
57             break;
58         case 1:
59             result.m_accountId = it->getInt();
60             break;
61         case 2:
62             result.m_mailId = it->getInt();
63             break;
64         case 3:
65             result.m_folderName = it->getString();
66             break;
67         case 4:
68             result.m_extra = it->getInt();
69             break;
70         }
71     }
72
73     return result;
74 }
75
76 int StorageChangeMessage::getType() const
77 {
78     return m_type;
79 }
80
81 int StorageChangeMessage::getAccountId() const
82 {
83     return m_accountId;
84 }
85
86 int StorageChangeMessage::getMailId() const
87 {
88     return m_mailId;
89 }
90
91 std::string StorageChangeMessage::getFolderName() const
92 {
93     return m_folderName;
94 }
95
96 int StorageChangeMessage::getExtra() const
97 {
98     return m_extra;
99 }
100
101 }
102 }