update for beta universally
[framework/messaging/email-service.git] / ipc / stub / ipc-queue.cpp
1 /*
2 *  email-service
3 *
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
7
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 */
21
22
23 #include <stdio.h>
24 #include "ipc-queue.h"
25 #include "ipc-library-build.h"
26 #include "emf-dbglog.h"
27
28 ipcEmailQueue::ipcEmailQueue()
29 {
30         m_pHead = NULL;
31         m_pTail = NULL;
32         m_nCount = 0;
33 }
34
35 ipcEmailQueue::~ipcEmailQueue()
36 {
37 }
38
39 void* ipcEmailQueue::Pop()
40 {
41         if(m_pHead) {
42                 ipcEmailQueueItem *pPopped = m_pHead;
43                 void* pData = pPopped->Get();
44
45                 if(pPopped->m_pNext) {
46                         m_pHead = pPopped->m_pNext;
47                 } else {
48                         m_pHead = m_pTail = NULL;
49                 }
50
51                 delete pPopped;
52                 pPopped = NULL;
53                 m_nCount = (m_nCount <= 0)? 0 : m_nCount-1;
54
55                 return pData;
56         }
57         return NULL;
58 }
59
60 bool ipcEmailQueue::Push(void* a_pData)
61 {
62         /* EM_DEBUG_FUNC_BEGIN(); */
63         if(!a_pData) {
64                 EM_DEBUG_EXCEPTION("[IPCLib] ipcEmailQueue::Push - invalid input \n");
65                 return false;
66         }
67
68         ipcEmailQueueItem *pItem = new ipcEmailQueueItem(a_pData);
69         if(m_pTail) {
70                 m_pTail->m_pNext = pItem;
71                 m_pTail = pItem;
72         } else {
73                 m_pHead = m_pTail = pItem;
74         }
75
76         m_nCount++;
77         pItem->m_pNext = NULL;
78         return true;
79 }
80
81 int ipcEmailQueue::GetCount()
82 {
83         return m_nCount;
84 }
85
86
87
88
89 ipcEmailQueueItem::ipcEmailQueueItem()
90 {
91         m_pData = NULL;
92         m_pNext = NULL;
93 }
94
95 ipcEmailQueueItem::ipcEmailQueueItem(void* a_pData)
96 {
97         m_pData = a_pData;
98         m_pNext = NULL;
99 }
100
101 ipcEmailQueueItem::~ipcEmailQueueItem()
102 {
103 }
104
105 void* ipcEmailQueueItem::Get()
106 {
107         return m_pData;
108 }
109
110 void ipcEmailQueueItem::Set(void* a_pData)
111 {
112         m_pData = a_pData;
113 }
114