Git init
[framework/uifw/isf.git] / ism / src / scim_backend.h
1 /** @file scim_backend.h
2  *  @brief definition of scim::BackEnd class.
3  *
4  *  Class scim::BackEnd is used to load and manage IMEngine
5  *  modules and IMEngineFactories.
6  */
7
8 /* ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable. */
9
10 /*
11  * Smart Common Input Method
12  *
13  * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
14  *
15  *
16  * This library is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU Lesser General Public
18  * License as published by the Free Software Foundation; either
19  * version 2 of the License, or (at your option) any later version.
20  *
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public
27  * License along with this program; if not, write to the
28  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
29  * Boston, MA  02111-1307  USA
30  *
31  * $Id: scim_backend.h,v 1.26 2005/10/06 18:02:06 liuspider Exp $
32  */
33
34 #ifndef __SCIM_BACKEND_H
35 #define __SCIM_BACKEND_H
36
37 namespace scim {
38
39 /**
40  * @brief An exception class to hold BackEnd related errors.
41  *
42  * scim::BackEndBase and its derived classes must throw
43  * scim::BackEndError object when error.
44  */
45 class BackEndError: public Exception
46 {
47 public:
48     BackEndError (const String& what_arg)
49         : Exception (String("scim::BackEnd: ") + what_arg) { }
50 };
51
52 /**
53  * @brief The interface class to manage a set of IMEngineFactory
54  * and IMEngineInstance objects.
55  *
56  * This is mainly an accessory interface class used by scim::FrontEndBase.
57  * Its responsibility is to hold a set of IMEngineFactory instances
58  * and manage the locales list supported by them.
59  *
60  * Most developer should just use the default implementation
61  * scim::CommonBackEnd.
62  */
63 class BackEndBase : public ReferencedObject
64 {
65     class BackEndBaseImpl;
66
67     BackEndBaseImpl *m_impl;
68
69 protected:
70     /**
71      * @brief Default constructor.
72      *
73      * @param config  Config object to be used.
74      */
75     BackEndBase (const ConfigPointer &config);
76
77     virtual ~BackEndBase ();
78
79 public:
80     /**
81      * @brief Get a list of all locales supported by all IMEngineFactories.
82      * @return A comma separated locales list.
83      */
84     String get_all_locales () const;
85
86     /**
87      * @return Return the pointer of a Factory.
88      *
89      * @param uuid The uuid of the IMEngineFactory.
90      */
91     IMEngineFactoryPointer get_factory (const String &uuid) const;
92
93 public:
94     virtual void initialize (const ConfigPointer       &config,
95                              const std::vector<String> &modules,
96                              const bool                is_load_resource,
97                              const bool                is_load_info) = 0;
98
99     virtual int add_module (const ConfigPointer &config,
100                             const String         module,
101                             bool                 is_load_resource) = 0;
102
103     virtual void add_module_info (const ConfigPointer &config,
104                                   const String         module_name) = 0;
105
106     virtual void add_factory_by_uuid (const ConfigPointer &config,
107                                       const String uuid) = 0;
108
109     virtual void release_module (const std::vector<String> &use_uuids,
110                                  const String del_uuid) = 0;
111
112 public:
113     /**
114      * @name Methods to manipulate IMEngine Factories.
115      *
116      * @{
117      */
118
119     /**
120      * @brief Get the IMEngine factories list for specific encoding
121      *
122      * @param factories the vector to store the factories which
123      *                  support the encoding.
124      * @param encoding  the encoding to be queried. If empty,
125      *                  all IMEngine factories will be returned.
126      *
127      * @return the number of IMEngine factories found.
128      */
129     uint32 get_factories_for_encoding (std::vector<IMEngineFactoryPointer> &factories, const String &encoding = String ("")) const;
130
131     /**
132      * @brief Get the IMEngine factories list for specific language
133      *
134      * @param factories the vector to store the factories which
135      *                  support the encoding.
136      * @param language  the language to be queried. If empty,
137      *                  all IMEngine factories will be returned.
138      *
139      * @return the number of IMEngine factories found.
140      */
141     uint32 get_factories_for_language (std::vector<IMEngineFactoryPointer> &factories, const String &language = String ("")) const;
142
143     uint32 get_factory_list (std::vector<String> &uuids) const;
144
145     /**
146      * @brief Get the default IMEngineFactory for a specific language and encoding.
147      *
148      * @param language the language to be queried.
149      * @param encoding the encoding to be queried, if empty then don't match encoding.
150      *
151      * @return the pointer of the default IMEngineFactory for this language.
152      */
153     IMEngineFactoryPointer get_default_factory (const String &language, const String &encoding) const;
154
155     /**
156      * @brief Set the default IMEngineFactory for a specific language.
157      *
158      * @param language the language to be set.
159      * @param uuid the uuid of the default IMEngineFactory for this language.
160      */
161     void set_default_factory (const String &language, const String &uuid);
162
163     /**
164      * @brief Get the next IMEngineFactory for a specific language and encoding.
165      *
166      * @param language the language to be queried, if empty then don't match language.
167      * @param encoding the encoding to be queried, if empty then don't match encoding.
168      * @param cur_uuid the UUID of current IMEngineFactory.
169      *
170      * @return the pointer of the next IMEngineFactory for this language and encoding
171      *         corresponding to the current IMEngineFactory.
172      */
173     IMEngineFactoryPointer get_next_factory (const String &language, const String &encoding, const String &cur_uuid) const;
174
175     /**
176      * @brief Get the previous IMEngineFactory for a specific language and encoding.
177      *
178      * @param language the language to be queried, if empty then don't match language.
179      * @param encoding the encoding to be queried, if empty then don't match encoding.
180      * @param cur_uuid the UUID of current IMEngineFactory.
181      *
182      * @return the pointer of the previous IMEngineFactory for this language and encoding
183      *         corresponding to the current IMEngineFactory.
184      */
185     IMEngineFactoryPointer get_previous_factory (const String &language, const String &encoding, const String &cur_uuid) const;
186
187     /**
188      * @}
189      */
190
191 protected:
192
193     bool add_factory (const IMEngineFactoryPointer &factory);
194
195     void add_specific_factory (const String &uuid, const IMEngineFactoryPointer &factory);
196
197     void clear ();
198
199 public:
200     void dump_factories ();
201 };
202
203 /**
204  * @typedef typedef Pointer <BackEnd> BackEndPointer;
205  *
206  * A smart pointer for scim::BackEndBase and its derived classes.
207  */
208 typedef Pointer <BackEndBase> BackEndPointer;
209
210 /**
211  * @brief The default implementation of scim::BackEndBase interface.
212  */
213 class CommonBackEnd : public BackEndBase
214 {
215     class CommonBackEndImpl;
216     CommonBackEndImpl *m_impl;
217
218 public:
219     /**
220      * @brief Constructor
221      *
222      * @param config The pointer to the Config object.
223      * @param modules The list of the IMEngine modules to be loaded.
224      */
225     CommonBackEnd (const ConfigPointer       &config,
226                    const std::vector<String> &modules);
227     virtual ~CommonBackEnd ();
228
229     virtual void initialize (const ConfigPointer       &config,
230                              const std::vector<String> &modules,
231                              const bool                is_load_resource,
232                              const bool                is_load_info);
233
234     virtual int add_module (const ConfigPointer &config,
235                             const String         module,
236                             bool                 is_load_resource);
237
238     virtual void add_module_info (const ConfigPointer &config,
239                                   const String         module_name);
240
241     virtual void add_factory_by_uuid (const ConfigPointer &config,
242                                       const String uuid);
243
244     virtual void release_module (const std::vector<String> &use_uuids,
245                                  const String del_uuid);
246
247     void add_module_info_from_cache_file (const ConfigPointer &config,
248                                           std::vector<String> &modules);
249
250     void update_module_info (const ConfigPointer &config,
251                              std::vector<String> &current_modules,
252                              std::vector<String> &modules);
253
254     void add_imengine_module_info (const String module_name,
255                                    const ConfigPointer &config);
256
257 };
258
259 } /* namespace scim */
260
261 #endif /*__SCIM_BACKEND_H */
262
263 /*
264 vi:ts=4:nowrap:ai:expandtab
265 */