Git init
[profile/ivi/isf.git] / ism / src / scim_imengine_module.cpp
1 /* ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable. */
2
3 /*
4  * Smart Common Input Method
5  *
6  * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
7  *
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this program; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22  * Boston, MA  02111-1307  USA
23  *
24  * $Id: scim_imengine_module.cpp,v 1.3 2005/01/10 08:30:54 suzhe Exp $
25  *
26  */
27
28 #define Uses_SCIM_IMENGINE_MODULE
29 #define Uses_SCIM_MODULE
30 #include "scim_private.h"
31 #include "scim.h"
32
33 namespace scim {
34
35 IMEngineModule::IMEngineModule ()
36     : m_imengine_init (0),
37       m_imengine_create_factory (0),
38       m_number_of_factories (0)
39 {
40 }
41
42 IMEngineModule::IMEngineModule (const String &name, const ConfigPointer &config)
43     : m_imengine_init (0),
44       m_imengine_create_factory (0),
45       m_number_of_factories (0)
46 {
47     load (name, config);
48 }
49
50 bool
51 IMEngineModule::load (const String &name, const ConfigPointer &config)
52 {
53     m_module_name = name;
54     try {
55         if (!m_module.load (name, "IMEngine"))
56             return false;
57
58         m_imengine_init =
59             (IMEngineModuleInitFunc) m_module.symbol ("scim_imengine_module_init");
60
61         m_imengine_create_factory =
62             (IMEngineModuleCreateFactoryFunc) m_module.symbol ("scim_imengine_module_create_factory");
63
64         if (!m_imengine_init || !m_imengine_create_factory) {
65             m_module.unload ();
66             m_imengine_init = 0;
67             m_imengine_create_factory = 0;
68             m_number_of_factories = 0;
69             return false;
70         }
71
72         m_number_of_factories = m_imengine_init (config);
73     } catch (...) {
74         m_module.unload ();
75         m_imengine_init = 0;
76         m_imengine_create_factory = 0;
77         m_number_of_factories = 0;
78         return false;
79     }
80
81     return true;
82 }
83
84 bool
85 IMEngineModule::unload ()
86 {
87     return m_module.unload ();
88 }
89
90 bool
91 IMEngineModule::valid () const
92 {
93     return (m_module.valid () && m_imengine_init &&
94             m_imengine_create_factory && m_number_of_factories > 0);
95 }
96
97 IMEngineFactoryPointer
98 IMEngineModule::create_factory (unsigned int engine) const
99 {
100     if (valid () && engine < m_number_of_factories )
101         return m_imengine_create_factory (engine);
102
103     return IMEngineFactoryPointer (0);
104 }
105
106 unsigned int
107 IMEngineModule::number_of_factories ()
108 {
109     if (m_module_name == "socket")
110         m_number_of_factories = m_imengine_init (NULL);
111     return m_number_of_factories ;
112 }
113
114 String
115 IMEngineModule::get_module_name () const
116 {
117     return m_module_name;
118 }
119
120 int scim_get_imengine_module_list (std::vector <String>& engine_list)
121 {
122     return scim_get_module_list (engine_list, "IMEngine");
123 }
124
125
126 } // namespace scim
127
128 /*
129 vi:ts=4:nowrap:ai:expandtab
130 */