Tizen 2.0 Release
[apps/core/preloaded/myfiles.git] / src / include / mf-search.h
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
21 #ifndef _MF_SEARCH_H_
22 #define _MF_SEARCH_H_
23
24 /*+++++++++++++++++++++++ Definitions and Types +++++++++++++++++++++++*/
25
26 /**
27  * Handle type for mf_search
28  **/
29 typedef unsigned int mf_search_handle;
30
31 /**
32  * Handle type for search result
33  **/
34 typedef unsigned int mf_search_result;
35
36 typedef int (*mf_search_filter_cb) (const char *);
37
38
39 /**
40  * Enumerations of search option
41  **/
42
43 typedef enum _mf_search_option mf_search_option;
44
45 enum _mf_search_option {
46         MF_SEARCH_OPT_NONE = (1 << 0),
47         MF_SEARCH_OPT_HIDDEN = (1 << 1),
48         MF_SEARCH_OPT_DIR = (1 << 2),
49         MF_SEARCH_OPT_FILE = (1 << 3),
50 };
51
52 typedef enum _mf_search_pipe_msg_type mf_search_pipe_msg_type;
53 enum _mf_search_pipe_msg_type {
54         MF_SEARCH_PIPE_MSG_NONE = 0,
55         MF_SEARCH_PIPE_MSG_ROOT_CHANGE,
56         MF_SEARCH_PIPE_MSG_RESULT_REPORT,
57         MF_SEARCH_PIPE_MSG_FINISHED,
58         MF_SEARCH_PIPE_MSG_MAX,
59 };
60
61 typedef enum _mf_search_state mf_search_state;
62 enum _mf_search_state {
63         MF_SEARCH_STATE_NONE = 0,
64         MF_SEARCH_STATE_INIT,
65         MF_SEARCH_STATE_SEARCH,
66         MF_SEARCH_STATE_MAX,
67 };
68
69 typedef struct _mf_search_result_t mf_search_result_t;
70 struct _mf_search_result_t {
71         GList *dir_list;
72         GList *file_list;
73         gchar *current_dir;
74         guint total_count;
75         gboolean is_end;
76 };
77
78 typedef struct _ms_args_t ms_args_t;
79 struct _ms_args_t {
80         GList *root_path;
81         gchar *needle;
82         mf_search_option option;
83         void *user_data;
84         mf_search_filter_cb func;
85         int category;
86 } ;
87
88 typedef struct _ms_handle_t ms_handle_t;
89 struct _ms_handle_t {
90         mf_search_state state;
91         GMutex *cmd_lock;
92         ms_args_t *args;
93
94         GThread *thread_h;
95         GMutex *thread_mutex;
96         /* critical section */
97         gboolean is_stop;
98         mf_search_result_t *result;
99         /* critical section */
100 };
101
102 typedef struct _mf_search_pipe_msg mf_search_pipe_msg;
103 struct _mf_search_pipe_msg {
104         mf_search_pipe_msg_type mf_sp_msg_type;
105         void *report_result;
106         gchar *current_path;
107 };
108
109 /**
110  * mf_Search_Cb:
111  * @result: the handle of result, use util APIs to get detail result with this handle.
112  * @user_data: user data specified when installing the function, in mf_search_start()
113  **/
114 typedef void (*mf_Search_Cb) (mf_search_pipe_msg_type type, mf_search_result result, void *user_data);
115
116 /**
117  * Definition of error code
118  **/
119 #define MF_SEARCH_ERROR_NONE            (0)
120 #define MF_SEARCH_ERROR_INTERNAL        (-(1))  /* Internal error */
121 #define MF_SEARCH_ERROR_INVAL_P         (-(2))  /* Invalid params */
122 #define MF_SEARCH_ERROR_INVAL_S         (-(3))  /* Invalid status */
123 #define MF_SEARCH_ERROR_ALLOC           (-(4))  /* Memory allocation failed */
124 #define MF_SEARCH_ERROR_FS              (-(5))  /* File system error */
125
126 /*+++++++++++++++++++++++ APIs +++++++++++++++++++++++*/
127
128 /**
129  * mf_search_init:
130  * @handle: the handle of mf_search
131  * Creates a new @handle for search. If success,
132  * #mf_search state is changed from MF_SEARCH_STATE_NONE to MF_SEARCH_STATE_INIT
133  * Return value: This function returns zero on success, or negative value.
134  **/
135 int mf_search_init(mf_search_handle *handle);
136
137 /**
138  * mf_search_start:
139  * @handle: the handle of mf_search
140  * @root_path: array of the root path for search
141  * @path_num: the number of the root path for search
142  * @needle: the key string for search
143  * @option :  bitfield of mf_search_option flags
144  * @user_data: user data
145  * Start searching in given @root_path with @needle,
146  * every each idle time, @callback will be called with #mf_search_result_t and @user_data.
147  * If success, #mf_search state is changed from MF_SEARCH_STATE_INIT to MF_SEARCH_STATE_SEARCH
148  * Return value: This function returns zero on success, or negative value.
149  **/
150 int mf_search_start(mf_search_handle handle,
151                     const char **root_path,
152                     unsigned int path_num,
153                     const char *needle,
154                     mf_search_option option,
155                     void *user_data,
156                     mf_search_filter_cb func,
157                     int category);
158 /**
159  * mf_search_stop:
160  * @handle: the handle of mf_search
161  * Stops search
162  * If success, #mf_search state is changed from MF_SEARCH_STATE_SEARCH to MF_SEARCH_STATE_INIT
163  * Return value: This function returns zero on success, or negative value.
164  **/
165 int mf_search_stop(mf_search_handle handle);
166
167 /**
168  * mf_search_stop:
169  * @handle: the handle of mf_search
170  * Finalizes search @handle
171  * #mf_search state is changed from MF_SEARCH_STATE_INIT to MF_SEARCH_STATE_NONE
172  **/
173 void mf_search_finalize(mf_search_handle *handle);
174
175
176 /*+++++++++++++++++++++++ UTIL APIs +++++++++++++++++++++++*/
177
178 /**
179  * mf_search_result_dir_get:
180  * @result: the handle of search result
181  * Gets one of directory name in given search @result
182  * Return value: a directory name which is a newly-allocated string that must be freed after use
183  * or NULL if no more result for directory.
184  **/
185 char *mf_search_result_dir_get(mf_search_result_t *result);
186
187 /**
188  * mf_search_result_file_get:
189  * @result: the handle of search result
190  * Gets one of file name given search @result
191  * Return value: a file name which is a newly-allocated string that must be freed after use
192  * or NULL if no more result for directory.
193  **/
194 char *mf_search_result_file_get(mf_search_result_t *result);
195
196 /**
197  * mf_search_result_current_dir_get:
198  * @result: the handle of search result
199  * Gets current searching directory name in given search @result
200  * Return value: current searching directory name which is a newly-allocated string that must be freed after use
201  * or NULL if fail to get current searching directory name.
202  **/
203 char *mf_search_result_current_dir_get(mf_search_result_t *result);
204
205 /**
206  * mf_search_result_is_end:
207  * @result: the handle of search result
208  * @is_end : If @result is last result handle, set it to a non-zero value, if not set it to zero.
209  * Tests if given search @result is the last one or not
210  * Return value: This function returns zero on success, or negative value.
211  **/
212 int mf_search_result_is_end(mf_search_result_t *result, int *is_end);
213
214 /**
215  * mf_search_result_total_count_get:
216  * @result: the handle of search result
217  * @count: the items(which is explored directories and files) count.
218  * Gets current explored items(this is not result count)
219  * Return value: This function returns zero on success, or negative value.
220  **/
221 int mf_search_result_total_count_get(mf_search_result_t *result, unsigned int *count);
222
223 void mf_search_bar_item_append(void *data, void *user_data);
224
225 #endif