2 * Copyright 2013 Samsung Electronics Co., Ltd
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
8 * http://floralicense.org/license/
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.
24 /*+++++++++++++++++++++++ Definitions and Types +++++++++++++++++++++++*/
27 * Handle type for mf_search
29 typedef unsigned int mf_search_handle;
32 * Handle type for search result
34 typedef unsigned int mf_search_result;
36 typedef int (*mf_search_filter_cb) (const char *);
40 * Enumerations of search option
43 typedef enum _mf_search_option mf_search_option;
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),
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,
61 typedef enum _mf_search_state mf_search_state;
62 enum _mf_search_state {
63 MF_SEARCH_STATE_NONE = 0,
65 MF_SEARCH_STATE_SEARCH,
69 typedef struct _mf_search_result_t mf_search_result_t;
70 struct _mf_search_result_t {
78 typedef struct _ms_args_t ms_args_t;
82 mf_search_option option;
84 mf_search_filter_cb func;
88 typedef struct _ms_handle_t ms_handle_t;
90 mf_search_state state;
96 /* critical section */
98 mf_search_result_t *result;
99 /* critical section */
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;
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()
114 typedef void (*mf_Search_Cb) (mf_search_pipe_msg_type type, mf_search_result result, void *user_data);
117 * Definition of error code
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 */
126 /*+++++++++++++++++++++++ APIs +++++++++++++++++++++++*/
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.
135 int mf_search_init(mf_search_handle *handle);
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.
150 int mf_search_start(mf_search_handle handle,
151 const char **root_path,
152 unsigned int path_num,
154 mf_search_option option,
156 mf_search_filter_cb func,
160 * @handle: the handle of mf_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.
165 int mf_search_stop(mf_search_handle handle);
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
173 void mf_search_finalize(mf_search_handle *handle);
176 /*+++++++++++++++++++++++ UTIL APIs +++++++++++++++++++++++*/
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.
185 char *mf_search_result_dir_get(mf_search_result_t *result);
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.
194 char *mf_search_result_file_get(mf_search_result_t *result);
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.
203 char *mf_search_result_current_dir_get(mf_search_result_t *result);
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.
212 int mf_search_result_is_end(mf_search_result_t *result, int *is_end);
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.
221 int mf_search_result_total_count_get(mf_search_result_t *result, unsigned int *count);
223 void mf_search_bar_item_append(void *data, void *user_data);