Debian Codegraph @

src/af/xap/gtk/xap_UnixModule.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 2001 Dom Lachowicz <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include "xap_UnixModule.h"
21 #include "ut_string.h"
22
23 XAP_UnixModule::XAP_UnixModule ()
24 : m_bLoaded(false), m_szname (NULL), m_module (NULL)
25 {
26 }
27
28 XAP_UnixModule::~XAP_UnixModule (void)
29 {
30 if (m_bLoaded && m_module)
31 unload ();
32 FREEP(m_szname);
33 }
34
35 bool XAP_UnixModule::getModuleName (char ** dest) const
36 {
37 if (m_szname)
38 {
39 *dest = static_cast<char *>(g_strdup (m_szname));
40 return true;
41 }
42 return false;
43 }
44
45 bool XAP_UnixModule::load (const char * name)
46 {
47 if (m_bLoaded)
48 return false;
49
50 m_module = g_module_open (name, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY|G_MODULE_BIND_LOCAL));
51
52 if (m_module)
53 {
54 m_bLoaded = true;
55 return true;
56 }
57 else
58 return false;
59 }
60
61 bool XAP_UnixModule::unload (void)
62 {
63 if (m_bLoaded && m_module)
64 {
65 if (g_module_close (m_module))
66 {
67 m_bLoaded = false;
68 return true;
69 }
70 }
71 return false;
72 }
73
74 bool XAP_UnixModule::resolveSymbol (const char * symbol_name, void ** symbol)
75 {
76 return (g_module_symbol (m_module, symbol_name, symbol) ? true : false);
77 }
78
79 bool XAP_UnixModule::getErrorMsg (char ** dest) const
80 {
81 *dest = static_cast<char *>(g_strdup (g_module_error ()));
82 return true;
83 }