Update change log and spec for wrt-plugins-tizen_0.4.13
[framework/web/wrt-plugins-tizen.git] / src / Contact / ContactQueue.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2013 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 "ContactQueue.h"
19 #include <dpl/singleton_impl.h>
20
21 using namespace DPL;
22
23 IMPLEMENT_SINGLETON(DeviceAPI::Contact::ContactQueueManager)
24
25 int count = 0;
26 int mapIndex = 0;
27 int currentIndex = 0;
28
29 namespace DeviceAPI {
30 namespace Contact {
31
32 bool ContactQueueManager::empty()
33 {
34         LogDebug("count : " << count);
35
36         if(count > 0)
37                 return false;
38         else
39                 return true;
40 }
41
42 void ContactQueueManager::increaseQueueList()
43 {
44         count++;
45         LogDebug("count : " << count);
46 }
47
48 void ContactQueueManager::decreaseQueueList()
49 {
50         if(count > 0)
51                 count--;
52         LogDebug("count : " << count);
53 }
54
55 void ContactQueueManager::push(operationType type, AddressBook *addressBook, const EventAddressBookAddBatchPtr &event)
56 {
57         LogDebug("push type : " << type);
58
59         queueProperties properties;
60         properties.addressBook = addressBook;
61         properties.addEvent = event;
62         properties.managertype = TYPEADDRESSBOOK;
63
64         switch(type)
65         {
66                 case ADDBATCH:
67                         properties.operation = ADDBATCH;
68                         break;
69                 case UPATEBATCH:
70                         properties.operation = UPATEBATCH;
71                         break;
72                 case DELETEBATCH:
73                         properties.operation = DELETEBATCH;
74                         break;
75                 default:
76                         return;
77         }
78
79         mapIndex++;
80         LogDebug("mapIndex : " << mapIndex);
81         m_addressBookQueueMap.insert(std::make_pair(mapIndex, properties));
82 }
83
84 void ContactQueueManager::push(operationType type, AddressBook *addressBook, const EventAddressBookUpdateBatchPtr &event)
85 {
86         LogDebug("push type : " << type);
87
88         queueProperties properties;
89         properties.addressBook = addressBook;
90         properties.updateEvent = event;
91         properties.managertype = TYPEADDRESSBOOK;
92
93         switch(type)
94         {
95                 case ADDBATCH:
96                         properties.operation = ADDBATCH;
97                         break;
98                 case UPATEBATCH:
99                         properties.operation = UPATEBATCH;
100                         break;
101                 case DELETEBATCH:
102                         properties.operation = DELETEBATCH;
103                         break;
104                 default:
105                         return;
106         }
107
108         mapIndex++;
109         LogDebug("mapIndex : " << mapIndex);
110         m_addressBookQueueMap.insert(std::make_pair(mapIndex, properties));
111 }
112
113 void ContactQueueManager::push(operationType type, AddressBook *addressBook, const EventAddressBookRemoveBatchPtr &event)
114 {
115         LogDebug("push type : " << type);
116
117         queueProperties properties;
118         properties.addressBook = addressBook;
119         properties.removeEvent = event;
120         properties.managertype = TYPEADDRESSBOOK;
121
122         switch(type)
123         {
124                 case ADDBATCH:
125                         properties.operation = ADDBATCH;
126                         break;
127                 case UPATEBATCH:
128                         properties.operation = UPATEBATCH;
129                         break;
130                 case DELETEBATCH:
131                         properties.operation = DELETEBATCH;
132                         break;
133                 default:
134                         return;
135         }
136
137         mapIndex++;
138         LogDebug("mapIndex : " << mapIndex);
139         m_addressBookQueueMap.insert(std::make_pair(mapIndex, properties));
140 }
141
142 void ContactQueueManager::push(operationType type, ContactManager *contactManager, const EventContactManagerUpdateBatchPtr &event)
143 {
144         LogDebug("push type : " << type);
145
146         queueProperties properties;
147         properties.contactManager = contactManager;
148         properties.personUpdateEvent = event;
149         properties.managertype = TYPECONTACTMANAGER;
150
151         switch(type)
152         {
153                 case UPATEBATCH:
154                         properties.operation = UPATEBATCH;
155                         break;
156                 case DELETEBATCH:
157                         properties.operation = DELETEBATCH;
158                         break;
159                 default:
160                         return;
161         }
162
163         mapIndex++;
164         LogDebug("mapIndex : " << mapIndex);
165         m_addressBookQueueMap.insert(std::make_pair(mapIndex, properties));
166 }
167
168 void ContactQueueManager::push(operationType type, ContactManager *contactManager, const EventContactManagerRemoveBatchPtr &event)
169 {
170         LogDebug("push type : " << type);
171
172         queueProperties properties;
173         properties.contactManager = contactManager;
174         properties.personRemoveEvent = event;
175         properties.managertype = TYPECONTACTMANAGER;
176
177         switch(type)
178         {
179                 case UPATEBATCH:
180                         properties.operation = UPATEBATCH;
181                         break;
182                 case DELETEBATCH:
183                         properties.operation = DELETEBATCH;
184                         break;
185                 default:
186                         return;
187         }
188
189         mapIndex++;
190         LogDebug("mapIndex : " << mapIndex);
191         m_addressBookQueueMap.insert(std::make_pair(mapIndex, properties));
192 }
193
194 void ContactQueueManager::pop()
195 {
196         currentIndex++;
197         LogDebug("currentIndex : " << currentIndex << " / mapIndex : " << mapIndex);
198
199         AddressBookQueueMap::iterator iter = m_addressBookQueueMap.find(currentIndex);
200         queueProperties properties = iter->second;
201
202         if(properties.managertype == TYPEADDRESSBOOK){
203                 switch(properties.operation){
204                         case ADDBATCH:
205                         {
206                                 properties.addressBook->AddressBookAddBatch(properties.addEvent);
207                         }
208                                 break;
209                         case UPATEBATCH:
210                         {
211                                 properties.addressBook->AddressBookUpdateBatch(properties.updateEvent);
212                         }
213                                 break;
214                         case DELETEBATCH:
215                         {
216                                 properties.addressBook->AddressBookRemoveBatch(properties.removeEvent);
217                         }
218                                 break;
219                         default:
220                                 break;
221                 }
222         }else if(properties.managertype == TYPECONTACTMANAGER){
223                 switch(properties.operation){
224                         case UPATEBATCH:
225                         {
226                                 properties.contactManager->managerUpdateBatch(properties.personUpdateEvent);
227                         }
228                                 break;
229                         case DELETEBATCH:
230                         {
231                                 properties.contactManager->managerRemoveBatch(properties.personRemoveEvent);
232                         }
233                                 break;
234                         default:
235                                 break;
236                 }
237         }
238
239         m_addressBookQueueMap.erase(iter);
240         if(currentIndex == mapIndex){
241                 currentIndex = 0;
242                 mapIndex = 0;
243         }
244 }
245
246 } // Contact
247 } // DeviceAPI
248