1 /* testgmodule.c - test program for GMODULE
2 * Copyright (C) 1998 Tim Janik
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
26 g_print ("GModule: Hello global clash\n");
29 typedef void (*SimpleFunc) (void);
30 typedef void (*GModuleFunc) (GModule *);
32 SimpleFunc gplugin_clash_func;
38 GModule *module_self, *module_a, *module_b;
40 gchar *plugin_a, *plugin_b;
41 SimpleFunc f_a, f_b, f_self;
44 string = g_get_current_dir ();
45 g_print ("testgmodule (%s):\n", string);
48 plugin_a = g_strconcat (string, "\\libgplugin_a.dll", NULL);
49 plugin_b = g_strconcat (string, "\\libgplugin_b.dll", NULL);
50 #else /* !NATIVE_WIN32 */
51 plugin_a = g_strconcat (string, "/.libs/", "libgplugin_a.so", NULL);
52 plugin_b = g_strconcat (string, "/.libs/", "libgplugin_b.so", NULL);
53 #endif /* NATIVE_WIN32 */
58 g_print ("get main module handle\n");
59 module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
62 g_print ("error: %s\n", g_module_error ());
65 g_print ("load plugin from \"%s\"\n", plugin_a);
66 module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
69 g_print ("error: %s\n", g_module_error ());
72 g_print ("load plugin from \"%s\"\n", plugin_b);
73 module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY);
76 g_print ("error: %s\n", g_module_error ());
80 /* get plugin specific symbols and call them
82 string = "gplugin_a_func";
83 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
84 if (!g_module_symbol (module_a, string, (gpointer) &f_a))
86 g_print ("error: %s\n", g_module_error ());
89 string = "gplugin_b_func";
90 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
91 if (!g_module_symbol (module_b, string, (gpointer) &f_b))
93 g_print ("error: %s\n", g_module_error ());
96 g_print ("call plugin function(%p) A: ", f_a);
98 g_print ("call plugin function(%p) B: ", f_b);
101 /* get and call globally clashing functions
103 string = "g_clash_func";
104 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_self)));
105 if (!g_module_symbol (module_self, string, (gpointer) &f_self))
107 g_print ("error: %s\n", g_module_error ());
110 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
111 if (!g_module_symbol (module_a, string, (gpointer) &f_a))
113 g_print ("error: %s\n", g_module_error ());
116 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
117 if (!g_module_symbol (module_b, string, (gpointer) &f_b))
119 g_print ("error: %s\n", g_module_error ());
122 g_print ("call plugin function(%p) self: ", f_self);
124 g_print ("call plugin function(%p) A: ", f_a);
126 g_print ("call plugin function(%p) B: ", f_b);
129 /* get and call clashing plugin functions
131 string = "gplugin_clash_func";
132 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
133 if (!g_module_symbol (module_a, string, (gpointer) &f_a))
135 g_print ("error: %s\n", g_module_error ());
138 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
139 if (!g_module_symbol (module_b, string, (gpointer) &f_b))
141 g_print ("error: %s\n", g_module_error ());
144 g_print ("call plugin function(%p) A: ", f_a);
145 gplugin_clash_func = f_a;
146 gplugin_clash_func ();
147 g_print ("call plugin function(%p) B: ", f_b);
148 gplugin_clash_func = f_b;
149 gplugin_clash_func ();
151 /* call gmodule function form A
153 string = "gplugin_a_module_func";
154 g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
155 if (!g_module_symbol (module_a, string, (gpointer) &gmod_f))
157 g_print ("error: %s\n", g_module_error ());
160 g_print ("call plugin A's module function(%p):\n{\n", gmod_f);
167 g_print ("unload plugin A:\n");
168 if (!g_module_close (module_a))
169 g_print ("error: %s\n", g_module_error ());
170 g_print ("unload plugin B:\n");
171 if (!g_module_close (module_b))
172 g_print ("error: %s\n", g_module_error ());
175 g_log_set_fatal_mask ("GModule", G_LOG_FATAL_MASK|G_LOG_LEVEL_WARNING);
176 g_module_symbol (0, 0, 0);
178 g_on_error_query (".libs/testgmodule");