Change TCP transfer
[platform/core/multimedia/libmedia-thumbnail.git] / src / ipc / media-thumb-ipc.c
1 /*
2  * libmedia-thumbnail
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@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 #include "media-thumbnail.h"
23 #include "media-thumb-ipc.h"
24 #include "media-thumb-util.h"
25 #include "media-thumb-db.h"
26 #include "media-thumb-debug.h"
27 #include <glib.h>
28 #include <fcntl.h>
29 #include <string.h>
30 #include <errno.h>
31 #include <grp.h>
32 #include <pwd.h>
33
34 #define THUMB_SOCK_BLOCK_SIZE 10240
35 #define THUMB_IPC_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcreator.socket")
36
37 static GQueue *g_manage_queue = NULL;
38 static GQueue *g_manage_raw_queue = NULL;
39
40
41 typedef struct {
42         GIOChannel *channel;
43         int msg_type;
44         unsigned int request_id;
45         bool isCanceled;
46         bool isRequested;
47         int source_id;
48         uid_t uid;
49         char *path;
50         thumbUserData *userData;
51 } thumbReq;
52
53 typedef struct {
54         GIOChannel *channel;
55         int msg_type;
56         bool isCanceled;
57         bool isRequested;
58         int request_id;
59         int source_id;
60         int width;
61         int height;
62         uid_t uid;
63         char *path;
64         thumbRawUserData *userData;
65 } thumbRawReq;
66
67 static int _media_thumb_send_request();
68 static int _media_thumb_raw_data_send_request();
69
70
71 int _media_thumb_get_error()
72 {
73         if (errno == EWOULDBLOCK) {
74                 thumb_err("Timeout. Can't try any more");
75                 return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
76         } else {
77                 thumb_stderror("recvfrom failed");
78                 return MS_MEDIA_ERR_SOCKET_RECEIVE;
79         }
80 }
81
82 void __media_thumb_pop()
83 {
84         int len = 0;
85
86         if (g_manage_queue != NULL) {
87                 thumbReq *req = (thumbReq *)g_queue_pop_head(g_manage_queue);
88                 if (req != NULL) {
89                         GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
90
91                         g_io_channel_shutdown(req->channel, TRUE, NULL);
92                         g_io_channel_unref(req->channel);
93
94                         if (source_id != NULL) {
95                                 g_source_destroy(source_id);
96                         } else {
97                                 thumb_err("G_SOURCE_ID is NULL");
98                         }
99
100                         SAFE_FREE(req->path);
101                         SAFE_FREE(req->userData);
102                         SAFE_FREE(req);
103                 }
104
105                 /* Check manage queue */
106                 len = g_queue_get_length(g_manage_queue);
107                 if (len > 0)
108                         _media_thumb_send_request();
109         }
110 }
111
112 int __media_thumb_cancel(unsigned int request_id)
113 {
114         int len = 0, i;
115         bool flag = false;
116
117         if (g_manage_queue != NULL) {
118                 len = g_queue_get_length(g_manage_queue);
119
120                 for (i = 0; i < len; i++) {
121                         thumbReq *req = NULL;
122                         req = (thumbReq *)g_queue_peek_nth(g_manage_queue, i);
123                         if (req == NULL) continue;
124
125                         if (req->request_id == request_id) {
126                                 if (req->isRequested == true) {
127                                         req->isCanceled = true;
128                                 } else {
129                                         g_queue_pop_nth(g_manage_queue, i);
130
131                                         SAFE_FREE(req->path);
132                                         SAFE_FREE(req->userData);
133                                         SAFE_FREE(req);
134                                 }
135
136                                 flag = true;
137
138                                 break;
139                         }
140                 }
141         }
142
143         if (flag == false)
144                 return MS_MEDIA_ERR_INTERNAL;
145
146         return MS_MEDIA_ERR_NONE;
147 }
148
149 void __media_thumb_pop_raw_data()
150 {
151         int len = 0;
152
153         if (g_manage_raw_queue != NULL) {
154                 thumbRawReq *req = (thumbRawReq *)g_queue_pop_head(g_manage_raw_queue);
155                 if (req != NULL) {
156                         GSource *source_id = g_main_context_find_source_by_id(g_main_context_get_thread_default(), req->source_id);
157
158                         g_io_channel_shutdown(req->channel, TRUE, NULL);
159                         g_io_channel_unref(req->channel);
160
161                         if (source_id != NULL) {
162                                 g_source_destroy(source_id);
163                         } else {
164                                 thumb_err("G_SOURCE_ID is NULL");
165                         }
166
167                         SAFE_FREE(req->path);
168                         SAFE_FREE(req->userData);
169                         SAFE_FREE(req);
170                 }
171
172                 /* Check manage queue */
173                 len = g_queue_get_length(g_manage_raw_queue);
174                 if (len > 0)
175                         _media_thumb_raw_data_send_request();
176         }
177 }
178
179 int __media_thumb_cancel_raw_data(int request_id)
180 {
181         int len = 0, i;
182         bool flag = false;
183
184         if (g_manage_raw_queue != NULL) {
185                 len = g_queue_get_length(g_manage_raw_queue);
186
187                 for (i = 0; i < len; i++) {
188                         thumbRawReq *req = NULL;
189                         req = (thumbRawReq *)g_queue_peek_nth(g_manage_raw_queue, i);
190                         if (req == NULL) continue;
191
192                         if (req->request_id == request_id) {
193                                 if (req->isRequested == true) {
194                                         req->isCanceled = true;
195                                 } else {
196                                         g_queue_pop_nth(g_manage_raw_queue, i);
197
198                                         SAFE_FREE(req->path);
199                                         SAFE_FREE(req->userData);
200                                         SAFE_FREE(req);
201                                 }
202
203                                 flag = true;
204
205                                 break;
206                         }
207                 }
208         }
209
210         if (flag == false)
211                 return MS_MEDIA_ERR_INTERNAL;
212
213         return MS_MEDIA_ERR_NONE;
214
215 }
216
217 bool __media_thumb_check_cancel(void)
218 {
219         thumbReq *req = NULL;
220         req = (thumbReq *)g_queue_peek_head(g_manage_queue);
221
222         if (req == NULL) {
223                 return false;
224         } else {
225                 if (req->isCanceled)
226                         return false;
227                 else
228                         return true;
229         }
230 }
231
232 bool __media_thumb_check_cancel_for_raw(void)
233 {
234         thumbRawReq *req = NULL;
235         req = (thumbRawReq *)g_queue_peek_head(g_manage_raw_queue);
236
237         if (req == NULL) {
238                 return false;
239         } else {
240                 if (req->isCanceled)
241                         return false;
242                 else
243                         return true;
244         }
245 }
246
247 int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
248 {
249         int remain_size = 0;
250         int block_size = THUMB_SOCK_BLOCK_SIZE;
251         int recv_block = 0;
252         unsigned char *buf = NULL;
253         unsigned char *block_buf = NULL;
254
255         THUMB_MALLOC(buf, header_size);
256         THUMB_MALLOC(block_buf, THUMB_SOCK_BLOCK_SIZE);
257         if (buf == NULL || block_buf == NULL) {
258                 thumb_err("memory allocation failed");
259                 SAFE_FREE(buf);
260                 SAFE_FREE(block_buf);
261                 return MS_MEDIA_ERR_OUT_OF_MEMORY;
262         }
263
264         if (recv(sock, buf, header_size, 0) < 0) {
265                 thumb_stderror("recv failed");
266                 SAFE_FREE(buf);
267                 SAFE_FREE(block_buf);
268                 return _media_thumb_get_error();
269         }
270
271         memcpy(msg, buf, header_size);
272         SAFE_FREE(buf);
273
274         if (strlen(msg->org_path) == 0 || strlen(msg->org_path) >= MAX_FILEPATH_LEN) {
275                 thumb_err("org_path size is invalid %d", strlen(msg->org_path));
276                 SAFE_FREE(block_buf);
277                 return MS_MEDIA_ERR_SOCKET_RECEIVE;
278         }
279
280         /* it can be empty string */
281         if (strlen(msg->dst_path) >= MAX_FILEPATH_LEN) {
282                 thumb_err("dst_path size is invalid %d", strlen(msg->dst_path));
283                 SAFE_FREE(block_buf);
284                 return MS_MEDIA_ERR_SOCKET_RECEIVE;
285         }
286
287         if (msg->thumb_size < 0) {
288                 thumb_err("recv data is wrong");
289                 SAFE_FREE(block_buf);
290                 return MS_MEDIA_ERR_SOCKET_RECEIVE;
291         }
292
293         if (msg->thumb_size > 0) {
294                 remain_size = msg->thumb_size;
295                 THUMB_MALLOC(buf, remain_size);
296                 if (buf == NULL) {
297                         SAFE_FREE(block_buf);
298                         return MS_MEDIA_ERR_OUT_OF_MEMORY;
299                 }
300
301                 while (remain_size > 0) {
302                         if (remain_size < THUMB_SOCK_BLOCK_SIZE) {
303                                 block_size = remain_size;
304                         }
305                         if (recv(sock, block_buf, block_size, 0) < 0) {
306                                 thumb_stderror("recv failed");
307                                 SAFE_FREE(buf);
308                                 SAFE_FREE(block_buf);
309                                 return _media_thumb_get_error();
310                         }
311                         memcpy(buf+recv_block, block_buf, block_size);
312                         recv_block += block_size;
313                         remain_size -= block_size;
314                 }
315
316                 SAFE_FREE(msg->thumb_data);
317                 THUMB_MALLOC(msg->thumb_data, msg->thumb_size);
318                 if (msg->thumb_data != NULL) {
319                         memcpy(msg->thumb_data, buf, msg->thumb_size);
320                 } else {
321                         SAFE_FREE(buf);
322                         SAFE_FREE(block_buf);
323
324                         return MS_MEDIA_ERR_OUT_OF_MEMORY;
325                 }
326         }
327
328         SAFE_FREE(buf);
329         SAFE_FREE(block_buf);
330
331         return MS_MEDIA_ERR_NONE;
332 }
333
334 int _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
335 {
336         if (req_msg == NULL || buf == NULL)
337                 return MS_MEDIA_ERR_INVALID_PARAMETER;
338
339         int thumb_data_len = 0;
340         int size = 0;
341         int header_size = 0;
342
343         header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
344         thumb_data_len = req_msg->thumb_size;
345         if (thumb_data_len < 0)
346                 return MS_MEDIA_ERR_INVALID_PARAMETER;
347
348         //thumb_dbg("Basic Size[%d] org_path[%s] dst_path[%s] thumb_data_len[%d]", header_size, req_msg->org_path, req_msg->dst_path, thumb_data_len);
349
350         size = header_size + thumb_data_len;
351         THUMB_MALLOC(*buf, size);
352         if (*buf == NULL) {
353                 *buf_size = 0;
354                 return 0;
355         }
356         memcpy(*buf, req_msg, header_size);
357         if (thumb_data_len > 0)
358                 memcpy((*buf) + header_size, req_msg->thumb_data, thumb_data_len);
359
360         *buf_size = size;
361
362         return MS_MEDIA_ERR_NONE;
363 }
364
365 gboolean _media_thumb_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
366 {
367         thumbMsg recv_msg;
368         int header_size = 0;
369         int sock = 0;
370         int err = MS_MEDIA_ERR_NONE;
371
372         memset((void *)&recv_msg, 0, sizeof(thumbMsg));
373         sock = g_io_channel_unix_get_fd(src);
374
375         header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
376
377         thumb_err("_media_thumb_write_socket socket : %d", sock);
378
379         if ((err = _media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) {
380                 thumb_err("_media_thumb_recv_msg failed ");
381                 __media_thumb_pop();
382
383                 return FALSE;
384         }
385
386         if (recv_msg.status != MS_MEDIA_ERR_NONE) {
387                 err = recv_msg.status;
388                 thumb_err("Failed to make thumbnail (%d)", err);
389         }
390
391         if (__media_thumb_check_cancel()) {
392                 if (data) {
393                         thumbUserData* cb = (thumbUserData*)data;
394                         if (cb->func != NULL)
395                                 cb->func(err, recv_msg.dst_path, cb->user_data);
396                 }
397         }
398
399         __media_thumb_pop();
400
401         thumb_dbg("Done");
402
403         return FALSE;
404 }
405
406 gboolean _media_thumb_raw_data_write_socket(GIOChannel *src, GIOCondition condition, gpointer data)
407 {
408         thumbMsg recv_msg;
409         int header_size = 0;
410         int sock = 0;
411         int err = MS_MEDIA_ERR_NONE;
412
413         memset((void *)&recv_msg, 0, sizeof(thumbMsg));
414         sock = g_io_channel_unix_get_fd(src);
415
416         header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
417
418         thumb_err("_media_thumb_write_socket socket : %d", sock);
419
420         if ((err = _media_thumb_recv_msg(sock, header_size, &recv_msg)) < 0) {
421                 thumb_err("_media_thumb_recv_msg failed ");
422                 __media_thumb_pop_raw_data();
423
424                 return FALSE;
425         }
426
427         if (recv_msg.status != MS_MEDIA_ERR_NONE) {
428                 err = recv_msg.status;
429                 thumb_err("Failed to make thumbnail (%d)", err);
430         }
431
432         if (__media_thumb_check_cancel_for_raw()) {
433                 if (data) {
434                         thumbRawUserData* cb = (thumbRawUserData*)data;
435                         if (cb->func != NULL)
436                                 cb->func(err, recv_msg.request_id, recv_msg.org_path, recv_msg.thumb_width, recv_msg.thumb_height, recv_msg.thumb_data, recv_msg.thumb_size, cb->user_data);
437                 }
438         }
439
440         __media_thumb_pop_raw_data();
441
442         thumb_dbg("Done");
443
444         return FALSE;
445 }
446
447 static int _media_thumb_send_request()
448 {
449         int err = MS_MEDIA_ERR_NONE;
450         int sock = -1;
451         struct sockaddr_un serv_addr;
452         thumbReq *req_manager = NULL;
453         int pid;
454
455         err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock);
456         if (err != MS_MEDIA_ERR_NONE) {
457                 thumb_err("ms_ipc_create_client_socket failed");
458                 return err;
459         }
460
461         memset(&serv_addr, 0, sizeof(serv_addr));
462         serv_addr.sun_family = AF_UNIX;
463         SAFE_STRLCPY(serv_addr.sun_path, THUMB_IPC_PATH, sizeof(serv_addr.sun_path));
464
465         GIOChannel *channel = NULL;
466         channel = g_io_channel_unix_new(sock);
467         int source_id = -1;
468
469         /* Connecting to the thumbnail server */
470         if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
471                 thumb_stderror("connect");
472                 if (errno == EACCES)
473                         err = MS_MEDIA_ERR_PERMISSION_DENIED;
474                 else
475                         err = MS_MEDIA_ERR_SOCKET_CONN;
476
477                 g_io_channel_shutdown(channel, TRUE, NULL);
478                 g_io_channel_unref(channel);
479                 close(sock);
480
481                 return err;
482         }
483
484         req_manager = (thumbReq *)g_queue_peek_head(g_manage_queue);
485
486         if (req_manager == NULL) {
487                 thumb_err("queue peek fail");
488                 g_io_channel_shutdown(channel, TRUE, NULL);
489                 g_io_channel_unref(channel);
490                 close(sock);
491                 return MS_MEDIA_ERR_INVALID_PARAMETER;
492         }
493
494         GSource *source = NULL;
495         source = g_io_create_watch(channel, G_IO_IN);
496         g_source_set_callback(source, (GSourceFunc)_media_thumb_write_socket, req_manager->userData, NULL);
497         source_id = g_source_attach(source, g_main_context_get_thread_default());
498
499         thumbMsg req_msg;
500         memset((void *)&req_msg, 0, sizeof(thumbMsg));
501
502         pid = getpid();
503         req_msg.pid = pid;
504         req_msg.msg_type = req_manager->msg_type;
505         req_msg.request_id = 0;
506         req_msg.uid = req_manager->uid;
507         SAFE_STRLCPY(req_msg.org_path, req_manager->path, sizeof(req_msg.org_path));
508         req_msg.dst_path[0] = '\0';
509         req_msg.thumb_size = 0;
510
511         unsigned char *buf = NULL;
512         int buf_size = 0;
513         _media_thumb_set_buffer(&req_msg, &buf, &buf_size);
514
515         if (send(sock, buf, buf_size, 0) < 0) {
516                 thumb_err("send failed: %d", errno);
517                 SAFE_FREE(buf);
518                 g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), source_id));
519                 g_io_channel_shutdown(channel, TRUE, NULL);
520                 g_io_channel_unref(channel);
521                 close(sock);
522                 return MS_MEDIA_ERR_SOCKET_SEND;
523         }
524
525         SAFE_FREE(buf);
526         thumb_dbg("Sending msg to thumbnail daemon is successful");
527
528         if (req_manager->msg_type == THUMB_REQUEST_DB_INSERT) {
529                 req_manager->channel = channel;
530                 req_manager->source_id = source_id;
531                 req_manager->isRequested = true;
532         }
533
534         return err;
535 }
536
537 static int _media_thumb_raw_data_send_request()
538 {
539         int err = MS_MEDIA_ERR_NONE;
540         int sock = -1;
541         struct sockaddr_un serv_addr;
542         thumbRawReq *req_manager = NULL;
543         int pid;
544
545         err = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sock);
546         if (err != MS_MEDIA_ERR_NONE) {
547                 thumb_err("ms_ipc_create_client_socket failed");
548                 return err;
549         }
550
551         memset(&serv_addr, 0, sizeof(serv_addr));
552         serv_addr.sun_family = AF_UNIX;
553         SAFE_STRLCPY(serv_addr.sun_path, THUMB_IPC_PATH, sizeof(serv_addr.sun_path));
554
555         GIOChannel *channel = NULL;
556         channel = g_io_channel_unix_new(sock);
557         int source_id = -1;
558
559         /* Connecting to the thumbnail server */
560         if (connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
561                 thumb_stderror("connect error");
562                 if (errno == EACCES)
563                         err = MS_MEDIA_ERR_PERMISSION_DENIED;
564                 else
565                         err = MS_MEDIA_ERR_SOCKET_CONN;
566
567                 g_io_channel_shutdown(channel, TRUE, NULL);
568                 g_io_channel_unref(channel);
569                 close(sock);
570                 return err;
571         }
572
573         req_manager = (thumbRawReq *)g_queue_peek_head(g_manage_raw_queue);
574
575         if (req_manager == NULL) {
576                 thumb_err("queue peek fail");
577                 g_io_channel_shutdown(channel, TRUE, NULL);
578                 g_io_channel_unref(channel);
579                 close(sock);
580                 return MS_MEDIA_ERR_INVALID_PARAMETER;
581         }
582
583         GSource *source = NULL;
584         source = g_io_create_watch(channel, G_IO_IN);
585         g_source_set_callback(source, (GSourceFunc)_media_thumb_raw_data_write_socket, req_manager->userData, NULL);
586         source_id = g_source_attach(source, g_main_context_get_thread_default());
587
588         thumbMsg req_msg;
589         memset((void *)&req_msg, 0, sizeof(thumbMsg));
590
591         pid = getpid();
592         req_msg.pid = pid;
593         req_msg.msg_type = req_manager->msg_type;
594         req_msg.request_id = req_manager->request_id;
595         req_msg.thumb_width = req_manager->width;
596         req_msg.thumb_height = req_manager->height;
597         req_msg.uid = req_manager->uid;
598
599         SAFE_STRLCPY(req_msg.org_path, req_manager->path, sizeof(req_msg.org_path));
600         req_msg.dst_path[0] = '\0';
601         req_msg.thumb_size = 0;
602
603         unsigned char *buf = NULL;
604         int buf_size = 0;
605         _media_thumb_set_buffer(&req_msg, &buf, &buf_size);
606
607         if (send(sock, buf, buf_size, 0) < 0) {
608                 thumb_err("send failed: %d", errno);
609                 SAFE_FREE(buf);
610                 g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), source_id));
611                 g_io_channel_shutdown(channel, TRUE, NULL);
612                 g_io_channel_unref(channel);
613                 return MS_MEDIA_ERR_SOCKET_SEND;
614         }
615
616         SAFE_FREE(buf);
617
618         if (req_manager->msg_type == THUMB_REQUEST_RAW_DATA) {
619                 req_manager->channel = channel;
620                 req_manager->source_id = source_id;
621                 req_manager->isRequested = true;
622         }
623         return MS_MEDIA_ERR_NONE;
624 }
625
626 int _media_thumb_request_async(int msg_type, unsigned int request_id, const char *origin_path, thumbUserData *userData, uid_t uid)
627 {
628         int err = MS_MEDIA_ERR_NONE;
629         int len = 0;
630
631         if (msg_type == THUMB_REQUEST_CANCEL_MEDIA)
632                 return __media_thumb_cancel(request_id);
633
634         if (g_manage_queue == NULL)
635                 g_manage_queue = g_queue_new();
636
637         thumbReq *thumb_req = NULL;
638         THUMB_MALLOC(thumb_req, sizeof(thumbReq));
639         thumb_retvm_if(thumb_req == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Failed to create request element");
640
641         thumb_req->msg_type = msg_type;
642         thumb_req->path = g_strdup(origin_path);
643         thumb_req->userData = userData;
644         thumb_req->isCanceled = false;
645         thumb_req->isRequested = false;
646         thumb_req->request_id = request_id;
647         thumb_req->uid = uid;
648
649         len = g_queue_get_length(g_manage_queue);
650         g_queue_push_tail(g_manage_queue, (gpointer)thumb_req);
651
652         if (len == 0)
653                 err = _media_thumb_send_request();
654
655         return err;
656 }
657
658 int _media_thumb_request_raw_data_async(int msg_type, int request_id, const char *origin_path, int width, int height, thumbRawUserData *userData, uid_t uid)
659 {
660         int err = MS_MEDIA_ERR_NONE;
661         int len = 0;
662         thumbRawReq *thumb_req = NULL;
663
664         if (msg_type == THUMB_REQUEST_CANCEL_RAW_DATA)
665                 return __media_thumb_cancel_raw_data(request_id);
666
667         if (g_manage_raw_queue == NULL)
668                 g_manage_raw_queue = g_queue_new();
669
670         THUMB_MALLOC(thumb_req, sizeof(thumbRawReq));
671         if (thumb_req == NULL) {
672                 thumb_err("Failed to create request element");
673                 return MS_MEDIA_ERR_INVALID_PARAMETER;
674         }
675
676         thumb_req->msg_type = msg_type;
677         thumb_req->request_id = request_id;
678         thumb_req->path = g_strdup(origin_path);
679         thumb_req->width = width;
680         thumb_req->height = height;
681         thumb_req->userData = userData;
682         thumb_req->isCanceled = false;
683         thumb_req->isRequested = false;
684         thumb_req->uid = uid;
685
686         len = g_queue_get_length(g_manage_raw_queue);
687         g_queue_push_tail(g_manage_raw_queue, (gpointer)thumb_req);
688
689         if (len == 0)
690                 err = _media_thumb_raw_data_send_request();
691
692         return err;
693 }
694
695 int _media_thumb_request_cancel_all()
696 {
697         if (g_manage_raw_queue != NULL) {
698                 while (g_queue_get_length(g_manage_raw_queue) > 0) {
699                         thumbRawReq *req = (thumbRawReq *)g_queue_peek_tail(g_manage_raw_queue);
700                         if (req != NULL) {
701                                 if (req->isRequested == true) {
702                                         req->isCanceled = true;
703                                         thumb_dbg("Last item!!");
704
705                                         break;
706                                 } else {
707                                         g_queue_pop_tail(g_manage_raw_queue);
708
709                                         SAFE_FREE(req->path);
710                                         SAFE_FREE(req->userData);
711                                         SAFE_FREE(req);
712                                 }
713                         } else {
714                                 thumb_dbg("Queue is empty!!");
715                                 break;
716                         }
717                 }
718         }
719
720         return MS_MEDIA_ERR_NONE;
721 }