Add systemd service file; create initscripts and db in %install
[framework/messaging/email-service.git] / email-ipc / email-stub / email-stub-queue.c
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 <malloc.h>
25
26 #include "email-stub-queue.h"
27 #include "email-ipc-build.h"
28
29 #include "email-debug-log.h"
30
31 static emipc_email_queue_item *head = NULL;
32 static emipc_email_queue_item *tail = NULL;
33 int count = 0;
34
35 EXPORT_API void *emipc_pop_in_queue()
36 {
37         void *data = NULL;
38
39         if (head) {
40                 emipc_email_queue_item *popped = head;
41                 data = popped->data;
42         
43                 if (popped->next) {
44                         head = popped->next;
45                 } else {
46                         head = tail = NULL;
47                 }
48                 
49                 EM_SAFE_FREE(popped);
50                 count = (count <= 0) ? 0 : count-1;
51                 
52                 return data;
53         }
54         return NULL;
55 }       
56
57 EXPORT_API bool emipc_push_in_queue(void *data)
58 {
59         emipc_email_queue_item *item = NULL;
60         if (!data) {
61                 EM_DEBUG_EXCEPTION("[IPCLib] emipc_push_in_queue - invalid input\n");
62                 return false;
63         }
64
65         item = (emipc_email_queue_item *)malloc(sizeof(emipc_email_queue_item));
66         if (item == NULL) {
67                 EM_DEBUG_EXCEPTION("Malloc failed.");
68                 return false;
69         }
70         memset(item, 0x00, sizeof(emipc_email_queue_item));
71
72         item->data = data;
73         item->next = NULL;
74         if (tail) {
75                 tail->next = item;
76                 tail = item;
77         } else {
78                 head = tail = item;
79         }
80
81         count++;
82         
83         return true;
84 }
85
86 EXPORT_API int emipc_get_count_of_item()
87 {
88         return count;
89 }