1 /***************************************************************************
2  *   Copyright (C) 2010~2010 by CSSlayer                                   *
3  *   wengxt@gmail.com                                                      *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
19  ***************************************************************************/
20 
21 /**
22  * @addtogroup Fcitx
23  * @{
24  */
25 
26 #ifndef __FCITX_INSTANCE_H__
27 #define __FCITX_INSTANCE_H__
28 
29 #include <pthread.h>
30 #include <semaphore.h>
31 #include <sys/select.h>
32 #include <fcitx/ui.h>
33 #include <fcitx-utils/utarray.h>
34 #include <fcitx/configfile.h>
35 #include <fcitx/profile.h>
36 #include <fcitx/addon.h>
37 #include <fcitx/ime.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43     struct _FcitxInputContext;
44 
45     /**
46      * Fcitx Instance, including all global settings
47      **/
48     typedef struct _FcitxInstance FcitxInstance;
49 
50     typedef void (*FcitxTimeoutCallback)(void* arg);
51 
52     /**
53      * create new fcitx instance
54      *
55      * @param sem semaphore to notify the instance is end
56      * @param argc argc
57      * @param argv argv
58      * @return FcitxInstance*
59      **/
60     FcitxInstance* FcitxInstanceCreate(sem_t *sem, int argc, char* argv[]);
61 
62 
63     /**
64      * create new fcitx instance
65      *
66      * @param sem semaphore to notify the instance is end
67      * @param argc argc
68      * @param argv argv
69      * @param signal fd
70      * @return FcitxInstance*
71      *
72      * @see FcitxInstanceCreate
73      *
74      * @since 4.2.5
75      **/
76     FcitxInstance* FcitxInstanceCreateWithFD(sem_t *sem, int argc, char* argv[], int fd);
77 
78     /**
79      * create new fcitx instance, but don't run it.
80      *
81      * @param sem semaphore to notify the instance is end
82      * @param argc argc
83      * @param argv argv
84      * @param signal fd
85      * @return FcitxInstance*
86      *
87      * @see FcitxInstanceCreate
88      *
89      * @since 4.2.5
90      **/
91     FcitxInstance* FcitxInstanceCreatePause(sem_t *sem, int argc, char* argv[], int fd);
92 
93     /**
94      * start a paused instance
95      *
96      * @param instance instance
97      * @return void
98      **/
99     void FcitxInstanceStart(FcitxInstance* instance);
100 
101     /**
102      * replace existing fcitx instance
103      *
104      * @param instance fcitx instance
105      * @return boolean
106      **/
107     boolean FcitxInstanceIsTryReplace(FcitxInstance* instance);
108 
109     /**
110      * replace existing fcitx instance
111      *
112      * @param instance fcitx instance
113      * @return bool
114      **/
115     void FcitxInstanceResetTryReplace(FcitxInstance* instance);
116 
117 
118     /**
119      * some event maybe sync to the buffer, set this flag to force recheck
120      *
121      * @param instance fcitx instance
122      * @return void
123      **/
124     void FcitxInstanceSetRecheckEvent(FcitxInstance* instance);
125 
126     /**
127      * lock the instance
128      *
129      * @param instance fcitx instance
130      * @return int
131      **/
132     int FcitxInstanceLock(FcitxInstance* instance);
133 
134     /**
135      * lock the instance
136      *
137      * @param instance fcitx instance
138      * @return int
139      **/
140     int FcitxInstanceUnlock(FcitxInstance* instance);
141 
142     /**
143      * notify the instance is end
144      *
145      * @param instance fcitx instance
146      * @return void
147      **/
148     void FcitxInstanceEnd(FcitxInstance* instance);
149 
150     /**
151      * check whether FcitxInstanceEnd is called or not
152      *
153      * @param instance fcitx instance
154      * @return boolean
155      *
156      * @since 4.2.7
157      **/
158     boolean FcitxInstanceGetIsDestroying(FcitxInstance* instance);
159 
160     /**
161      * Get Current Input Context
162      *
163      * @param instance
164      * @return FcitxInputContext*
165      **/
166     FcitxInputContext* FcitxInstanceGetCurrentIC(struct _FcitxInstance* instance);
167 
168     /**
169      * Set Current Input Context
170      *
171      * @param instance
172      * @param ic new input context
173      * @return current ic changed
174      **/
175     boolean FcitxInstanceSetCurrentIC(struct _FcitxInstance* instance, FcitxInputContext* ic);
176 
177     /**
178      * Get Addons From Instance
179      *
180      * @param instance fcitx instance
181      * @return UT_array*
182      **/
183     UT_array* FcitxInstanceGetAddons(FcitxInstance* instance);
184 
185     UT_array* FcitxInstanceGetUIMenus(FcitxInstance* instance);
186 
187     UT_array* FcitxInstanceGetUIStats(FcitxInstance* instance);
188 
189     UT_array* FcitxInstanceGetUIComplexStats(FcitxInstance* instance);
190 
191     UT_array* FcitxInstanceGetIMEs(FcitxInstance* instance);
192 
193     UT_array* FcitxInstanceGetAvailIMEs(FcitxInstance* instance);
194 
195     fd_set* FcitxInstanceGetReadFDSet(FcitxInstance* instance);
196 
197     fd_set* FcitxInstanceGetWriteFDSet(FcitxInstance* instance);
198 
199     fd_set* FcitxInstanceGetExceptFDSet(FcitxInstance* instance);
200 
201     struct _FcitxAddon* FcitxInstanceGetCurrentUI(FcitxInstance* instance);
202 
203     int FcitxInstanceGetMaxFD(FcitxInstance* instance);
204 
205     void FcitxInstanceSetMaxFD(FcitxInstance* instance, int maxfd);
206 
207     FcitxGlobalConfig* FcitxInstanceGetGlobalConfig(FcitxInstance* instance);
208 
209     FcitxProfile* FcitxInstanceGetProfile(FcitxInstance* instance);
210 
211     FcitxInputState* FcitxInstanceGetInputState(FcitxInstance* instance);
212 
213     /**
214      * add a timeout function
215      *
216      * @param instance fcitx instance
217      * @param milli milli seconds
218      * @param callback callback function
219      * @param arg argument
220      * @return callback id
221      **/
222     uint64_t FcitxInstanceAddTimeout(FcitxInstance* instance, long int milli, FcitxTimeoutCallback callback , void* arg);
223 
224     /**
225      * check if there is a timeout already exists
226      *
227      * @param instance fcitx instance
228      * @param callback callback function
229      * @return boolean
230      **/
231     boolean FcitxInstanceCheckTimeoutByFunc(FcitxInstance* instance, FcitxTimeoutCallback callback);
232 
233     /**
234      * check if an callback id is not called
235      *
236      * @param instance ...
237      * @param id ...
238      * @return boolean
239      **/
240     boolean FcitxInstanceCheckTimeoutById(FcitxInstance *instance, uint64_t id);
241 
242     /**
243      * remove one timeout function matched by provided callback
244      *
245      * @param instance instance
246      * @param callback callback function
247      * @return true if there is a callback removed
248      **/
249     boolean FcitxInstanceRemoveTimeoutByFunc(FcitxInstance* instance, FcitxTimeoutCallback callback);
250 
251     /**
252      * remove one timeout function by id
253      *
254      * @param instance ...
255      * @param id ...
256      * @return boolean
257      **/
258     boolean FcitxInstanceRemoveTimeoutById(FcitxInstance* instance, uint64_t id);
259 
260     /**
261      * wait for instance to end, it simple join with a started fcitx thread
262      *
263      * @param instance instance
264      * @return int
265      **/
266     int FcitxInstanceWaitForEnd(FcitxInstance* instance);
267 
268     /**
269      * run a fcitx instance in current thread, this function will not return until fcitx finishes.
270      *
271      * @param argc argument number
272      * @param argv argument vector
273      * @param fd outside file descriptor
274      * @return true if there some error happened during loading
275      *
276      * @since 4.2.8
277      **/
278     boolean FcitxInstanceRun(int argc, char* argv[], int fd);
279 
280     void FcitxInstanceRestart(FcitxInstance *instance);
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 
286 #endif
287 /**
288  * @}
289  */
290 // kate: indent-mode cstyle; space-indent on; indent-width 0;
291