summaryrefslogtreecommitdiff
path: root/src/include/mf-ug-search.h
blob: 88064c79d741021a0698acd81ac75d04a2a4eed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
 * Copyright 2012          Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://floralicense.org/license/
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */






#ifndef _MF_SEARCH_H_
#define _MF_SEARCH_H_

/*+++++++++++++++++++++++ Definitions and Types +++++++++++++++++++++++*/

/**
 * Handle type for mf_search
 **/
typedef unsigned int mf_search_handle;

/**
 * Handle type for search result
 **/
typedef unsigned int mf_search_result;

/**
 * Enumerations of search option
 **/

typedef enum _mf_search_option mf_search_option;

enum _mf_search_option {
	MF_SEARCH_OPT_NONE = (1 << 0),
	MF_SEARCH_OPT_HIDDEN = (1 << 1),
	MF_SEARCH_OPT_DIR = (1 << 2),
	MF_SEARCH_OPT_FILE = (1 << 3),
	MF_SEARCH_OPT_EXT = (1 << 4),
};

typedef enum _mf_search_pipe_msg_type mf_search_pipe_msg_type;
enum _mf_search_pipe_msg_type {
	MF_SEARCH_PIPE_MSG_NONE = 0,
	MF_SEARCH_PIPE_MSG_ROOT_CHANGE,
	MF_SEARCH_PIPE_MSG_RESULT_REPORT,
	MF_SEARCH_PIPE_MSG_FINISHED,
	MF_SEARCH_PIPE_MSG_MAX,
};

typedef enum _mf_search_state mf_search_state;
enum _mf_search_state {
	MF_SEARCH_STATE_NONE = 0,
	MF_SEARCH_STATE_INIT,
	MF_SEARCH_STATE_SEARCH,
	MF_SEARCH_STATE_MAX,
};

typedef struct _mf_search_result_t mf_search_result_t;
struct _mf_search_result_t {
	GList *dir_list;
	GList *file_list;
	gchar *current_dir;
	guint total_count;
	gboolean is_end;
};

typedef struct _ms_args_t ms_args_t;
struct _ms_args_t {
	GList *root_path;
	gchar *needle;
	mf_search_option option;
	void *user_data;
} ;

typedef struct _ms_handle_t ms_handle_t;
struct _ms_handle_t {
	mf_search_state state;
	GMutex *cmd_lock;
	ms_args_t *args;

	GThread *thread_h;
	GMutex *thread_mutex;
	/* critical section */
	gboolean is_stop;
	mf_search_result_t *result;
	/* critical section */
};

typedef struct _mf_search_pipe_msg mf_search_pipe_msg;
struct _mf_search_pipe_msg {
	mf_search_pipe_msg_type mf_sp_msg_type;
	void *report_result;
	gchar *current_path;
};

/**
 * mf_Search_Cb:
 * @result: the handle of result, use util APIs to get detail result with this handle.
 * @user_data: user data specified when installing the function, in mf_ug_search_start()
 **/
typedef void (*mf_Search_Cb) (mf_search_pipe_msg_type type, mf_search_result result, void *user_data);

/**
 * Definition of error code
 **/
#define MF_SEARCH_ERROR_NONE		(0)
#define MF_SEARCH_ERROR_INTERNAL	(-(1))	/* Internal error */
#define MF_SEARCH_ERROR_INVAL_P		(-(2))	/* Invalid params */
#define MF_SEARCH_ERROR_INVAL_S		(-(3))	/* Invalid status */
#define MF_SEARCH_ERROR_ALLOC		(-(4))	/* Memory allocation failed */
#define MF_SEARCH_ERROR_FS		(-(5))	/* File system error */

/*+++++++++++++++++++++++ APIs +++++++++++++++++++++++*/

/**
 * mf_ug_search_init:
 * @handle: the handle of mf_search
 * Creates a new @handle for search. If success,
 * #mf_search state is changed from MF_SEARCH_STATE_NONE to MF_SEARCH_STATE_INIT
 * Return value: This function returns zero on success, or negative value.
 **/
int mf_ug_search_init(mf_search_handle *handle);

/**
 * mf_ug_search_start:
 * @handle: the handle of mf_search
 * @root_path: array of the root path for search
 * @path_num: the number of the root path for search
 * @needle: the key string for search
 * @option :  bitfield of mf_search_option flags
 * @user_data: user data
 * Start searching in given @root_path with @needle,
 * every each idle time, @callback will be called with #mf_search_result_t and @user_data.
 * If success, #mf_search state is changed from MF_SEARCH_STATE_INIT to MF_SEARCH_STATE_SEARCH
 * Return value: This function returns zero on success, or negative value.
 **/
int mf_ug_search_start(mf_search_handle handle, const char **root_path, unsigned int path_num, const char *needle, mf_search_option option,
		    void *user_data);
/**
 * mf_ug_search_stop:
 * @handle: the handle of mf_search
 * Stops search
 * If success, #mf_search state is changed from MF_SEARCH_STATE_SEARCH to MF_SEARCH_STATE_INIT
 * Return value: This function returns zero on success, or negative value.
 **/
int mf_ug_search_stop(mf_search_handle handle);

/**
 * mf_ug_search_stop:
 * @handle: the handle of mf_search
 * Finalizes search @handle
 * #mf_search state is changed from MF_SEARCH_STATE_INIT to MF_SEARCH_STATE_NONE
 **/
void mf_ug_search_finalize(mf_search_handle *handle);


/*+++++++++++++++++++++++ UTIL APIs +++++++++++++++++++++++*/

/**
 * mf_ug_search_result_dir_get:
 * @result: the handle of search result
 * Gets one of directory name in given search @result
 * Return value: a directory name which is a newly-allocated string that must be freed after use
 * or NULL if no more result for directory.
 **/
char *mf_ug_search_result_dir_get(mf_search_result_t *result);

/**
 * mf_ug_search_result_file_get:
 * @result: the handle of search result
 * Gets one of file name given search @result
 * Return value: a file name which is a newly-allocated string that must be freed after use
 * or NULL if no more result for directory.
 **/
char *mf_ug_search_result_file_get(mf_search_result_t *result);

/**
 * mf_ug_search_result_current_dir_get:
 * @result: the handle of search result
 * Gets current searching directory name in given search @result
 * Return value: current searching directory name which is a newly-allocated string that must be freed after use
 * or NULL if fail to get current searching directory name.
 **/
char *mf_ug_search_result_current_dir_get(mf_search_result_t *result);

/**
 * mf_ug_search_result_is_end:
 * @result: the handle of search result
 * @is_end : If @result is last result handle, set it to a non-zero value, if not set it to zero.
 * Tests if given search @result is the last one or not
 * Return value: This function returns zero on success, or negative value.
 **/
int mf_ug_search_result_is_end(mf_search_result_t *result, int *is_end);

/**
 * mf_ug_search_result_total_count_get:
 * @result: the handle of search result
 * @count: the items(which is explored directories and files) count.
 * Gets current explored items(this is not result count)
 * Return value: This function returns zero on success, or negative value.
 **/
int mf_ug_search_result_total_count_get(mf_search_result_t *result, unsigned int *count);

void mf_ug_search_view_item_append(void *data, void *user_data);

#endif