Tizen 2.1 base
[apps/home/myfiles.git] / src / common / file-operation / mf-cancel.c
1 /*
2  * Copyright 2013         Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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
18
19
20 #include <glib.h>
21 #include "mf-cancel.h"
22
23
24
25 mf_cancel *mf_cancel_new(void)
26 {
27         mf_cancel *cancel = NULL;
28
29         cancel = g_new0(mf_cancel, 1);
30         if (cancel) {
31                 cancel->is_cancel = FALSE;
32                 cancel->do_cancel = FALSE;
33                 g_static_mutex_init(&cancel->s_mutex);
34         }
35         return cancel;
36 }
37
38 void mf_cancel_free(mf_cancel *cancel)
39 {
40         if (cancel) {
41                 cancel->is_cancel = FALSE;
42                 g_static_mutex_free(&cancel->s_mutex);
43         }
44         return;
45 }
46
47 void mf_cancel_do_cancel(mf_cancel *cancel)
48 {
49         if (cancel) {
50                 g_static_mutex_lock(&cancel->s_mutex);
51                 cancel->do_cancel = TRUE;
52                 g_static_mutex_unlock(&cancel->s_mutex);
53         }
54         return;
55 }
56
57 gboolean mf_cancel_check_cancel(mf_cancel *cancel)
58 {
59         gboolean do_cancel = FALSE;
60         if (cancel) {
61                 g_static_mutex_lock(&cancel->s_mutex);
62                 if (cancel->do_cancel)
63                         do_cancel = TRUE;
64                 g_static_mutex_unlock(&cancel->s_mutex);
65         }
66         return do_cancel;
67 }
68
69
70 void mf_cancel_set_cancelled(mf_cancel *cancel)
71 {
72         if (cancel) {
73                 g_static_mutex_lock(&cancel->s_mutex);
74                 cancel->is_cancel = TRUE;
75                 g_static_mutex_unlock(&cancel->s_mutex);
76         }
77         return;
78 }
79
80 gboolean mf_cancel_is_cancelled(mf_cancel *cancel)
81 {
82         gboolean is_cancelled = FALSE;
83         if (cancel) {
84                 g_static_mutex_lock(&cancel->s_mutex);
85                 if (cancel->is_cancel)
86                         is_cancelled = TRUE;
87                 g_static_mutex_unlock(&cancel->s_mutex);
88         }
89         return is_cancelled;
90 }