Git init
[framework/uifw/isf.git] / ism / src / scim_frontend_module.cpp
1 /*
2  * Smart Common Input Method
3  *
4  * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
5  *
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this program; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA  02111-1307  USA
21  *
22  * $Id: scim_frontend_module.cpp,v 1.13 2005/01/10 08:30:54 suzhe Exp $
23  *
24  */
25
26 #define Uses_SCIM_FRONTEND_MODULE
27 #include "scim_private.h"
28 #include "scim.h"
29
30 namespace scim {
31
32 FrontEndModule::FrontEndModule ()
33     : m_frontend_init (0),
34       m_frontend_run (0)
35 {
36 }
37
38 FrontEndModule::FrontEndModule (const String &name,
39                                 const BackEndPointer &backend,
40                                 const ConfigPointer &config,
41                                 int argc,
42                                 char **argv)
43     : m_frontend_init (0),
44       m_frontend_run (0)
45 {
46     load (name, backend, config, argc, argv);
47 }
48
49 bool
50 FrontEndModule::load (const String &name,
51                         const BackEndPointer &backend,
52                         const ConfigPointer &config,
53                         int argc,
54                         char **argv)
55 {
56     try {
57         if (!m_module.load (name, "FrontEnd"))
58             return false;
59
60         m_frontend_init = (FrontEndModuleInitFunc) m_module.symbol ("scim_frontend_module_init");
61         m_frontend_run =  (FrontEndModuleRunFunc) m_module.symbol ("scim_frontend_module_run");
62
63         if (!m_frontend_init || !m_frontend_run) {
64             m_module.unload ();
65             m_frontend_init = 0;
66             m_frontend_run = 0;
67             return false;
68         }
69
70         m_frontend_init (backend, config, argc, argv);
71     } catch (...) {
72         m_module.unload ();
73         m_frontend_init = 0;
74         m_frontend_run = 0;
75         return false;
76     }
77
78     return true;
79 }
80
81 bool
82 FrontEndModule::valid () const
83 {
84     return (m_module.valid () && m_frontend_init && m_frontend_run);
85 }
86
87 void
88 FrontEndModule::run () const
89 {
90     if (valid ())
91         m_frontend_run ();
92 }
93
94 int scim_get_frontend_module_list (std::vector <String>& mod_list)
95 {
96     return scim_get_module_list (mod_list, "FrontEnd");
97 }
98
99 } // namespace scim
100
101 /*
102 vi:ts=4:nowrap:ai:expandtab
103 */